Commit d0457b70 authored by Thiago Macieira's avatar Thiago Macieira
Browse files

Compile the C++ parser library with Sun CC 5.9.

Things you mustn't do:
1) end an enum with a comma

2) #include <cxxxx> and not use std::

3) use anonymous structures

All three things are invalid C++. Anonymous structures inside
anonymous unions are allowed by GCC, but that doesn't mean it's valid.
parent 88549a4b
......@@ -60,12 +60,12 @@ Macro::Macro()
QString Macro::toString() const
{
QString text;
if (_hidden)
if (f._hidden)
text += QLatin1String("#undef ");
else
text += QLatin1String("#define ");
text += QString::fromUtf8(_name.constData(), _name.size());
if (_functionLike) {
if (f._functionLike) {
text += QLatin1Char('(');
bool first = true;
foreach (const QByteArray formal, _formals) {
......@@ -75,7 +75,7 @@ QString Macro::toString() const
first = false;
text += QString::fromUtf8(formal.constData(), formal.size());
}
if (_variadic)
if (f._variadic)
text += QLatin1String("...");
text += QLatin1Char(')');
}
......
......@@ -93,22 +93,22 @@ public:
{ _line = line; }
bool isHidden() const
{ return _hidden; }
{ return f._hidden; }
void setHidden(bool isHidden)
{ _hidden = isHidden; }
{ f._hidden = isHidden; }
bool isFunctionLike() const
{ return _functionLike; }
{ return f._functionLike; }
void setFunctionLike(bool isFunctionLike)
{ _functionLike = isFunctionLike; }
{ f._functionLike = isFunctionLike; }
bool isVariadic() const
{ return _variadic; }
{ return f._variadic; }
void setVariadic(bool isVariadic)
{ _variadic = isVariadic; }
{ f._variadic = isVariadic; }
QString toString() const;
......@@ -117,6 +117,13 @@ public:
unsigned _hashcode;
private:
struct Flags
{
unsigned _hidden: 1;
unsigned _functionLike: 1;
unsigned _variadic: 1;
};
QByteArray _name;
QByteArray _definition;
QVector<QByteArray> _formals;
......@@ -126,13 +133,7 @@ private:
union
{
unsigned _state;
struct
{
unsigned _hidden: 1;
unsigned _functionLike: 1;
unsigned _variadic: 1;
};
Flags f;
};
};
......
......@@ -129,14 +129,14 @@ QList<SimpleToken> SimpleLexer::operator()(const QString &text, int state)
break;
SimpleToken simpleTk;
simpleTk._kind = int(tk.kind);
simpleTk._kind = int(tk.f.kind);
simpleTk._position = int(lex.tokenOffset());
simpleTk._length = int(lex.tokenLength());
simpleTk._text = text.midRef(simpleTk._position, simpleTk._length);
lex.setScanAngleStringLiteralTokens(false);
if (tk.newline && tk.is(T_POUND))
if (tk.f.newline && tk.is(T_POUND))
inPreproc = true;
else if (inPreproc && tokens.size() == 1 && simpleTk.is(T_IDENTIFIER) &&
simpleTk.text() == QLatin1String("include"))
......
......@@ -64,7 +64,7 @@ struct Value
{
enum Kind {
Kind_Long,
Kind_ULong,
Kind_ULong
};
Kind kind;
......@@ -231,7 +231,7 @@ protected:
QByteArray tokenSpell() const
{
const QByteArray text = QByteArray::fromRawData(source.constData() + (*_lex)->offset,
(*_lex)->length);
(*_lex)->f.length);
return text;
}
......@@ -677,7 +677,7 @@ void Preprocessor::processSkippingBlocks(bool skippingBlocks,
unsigned offset = start->offset;
if (_skipping[iflevel]) {
if (_dot->newline)
if (_dot->f.newline)
++offset;
client->startSkippingBlocks(offset);
......@@ -751,7 +751,7 @@ void Preprocessor::preprocess(const QString &fileName, const QByteArray &source,
while (true) {
if (_dot->joined)
if (_dot->f.joined)
out("\\");
processNewline();
......@@ -759,13 +759,13 @@ void Preprocessor::preprocess(const QString &fileName, const QByteArray &source,
if (_dot->is(T_EOF_SYMBOL)) {
break;
} else if (_dot->is(T_POUND) && (! _dot->joined && _dot->newline)) {
} else if (_dot->is(T_POUND) && (! _dot->f.joined && _dot->f.newline)) {
// handle the preprocessor directive
TokenIterator start = _dot;
do {
++_dot;
} while (_dot->isNot(T_EOF_SYMBOL) && (_dot->joined || ! _dot->newline));
} while (_dot->isNot(T_EOF_SYMBOL) && (_dot->f.joined || ! _dot->f.newline));
const bool skippingBlocks = _skipping[iflevel];
......@@ -777,11 +777,11 @@ void Preprocessor::preprocess(const QString &fileName, const QByteArray &source,
do {
++_dot;
} while (_dot->isNot(T_EOF_SYMBOL) && (_dot->joined || ! _dot->newline));
} while (_dot->isNot(T_EOF_SYMBOL) && (_dot->f.joined || ! _dot->f.newline));
} else {
if (_dot->whitespace) {
if (_dot->f.whitespace) {
unsigned endOfPreviousToken = 0;
if (_dot != _tokens.constBegin())
......@@ -1027,14 +1027,14 @@ const char *Preprocessor::endOfToken(const Token &token) const
QByteArray Preprocessor::tokenSpell(const Token &token) const
{
const QByteArray text = QByteArray::fromRawData(_source.constBegin() + token.offset,
token.length);
token.f.length);
return text;
}
QByteArray Preprocessor::tokenText(const Token &token) const
{
const QByteArray text(_source.constBegin() + token.offset,
token.length);
token.f.length);
return text;
}
......@@ -1179,7 +1179,7 @@ void Preprocessor::processDefine(TokenIterator firstToken, TokenIterator lastTok
macro.setName(tokenText(*tk));
++tk; // skip T_IDENTIFIER
if (tk->is(T_LPAREN) && ! tk->whitespace) {
if (tk->is(T_LPAREN) && ! tk->f.whitespace) {
// a function-like macro definition
macro.setFunctionLike(true);
......
......@@ -211,7 +211,7 @@ protected:
unsigned line, col;
getTokenStartPosition(index, &line, &col);
QTextCursor tc = _textCursor;
tc.setPosition(tc.document()->findBlockByNumber(line - 1).position() + col + tk.length - 1);
tc.setPosition(tc.document()->findBlockByNumber(line - 1).position() + col + tk.f.length - 1);
return tc;
}
......@@ -284,7 +284,7 @@ QTextCursor QuickFixOperation::cursor(unsigned index) const
getTokenStartPosition(index, &line, &col);
QTextCursor tc = _textCursor;
tc.setPosition(tc.document()->findBlockByNumber(line - 1).position() + col - 1);
tc.setPosition(tc.position() + tk.length, QTextCursor::KeepAnchor);
tc.setPosition(tc.position() + tk.f.length, QTextCursor::KeepAnchor);
return tc;
}
......@@ -304,7 +304,7 @@ QTextCursor QuickFixOperation::moveAtEndOfToken(unsigned index) const
unsigned line, col;
getTokenStartPosition(index, &line, &col);
QTextCursor tc = _textCursor;
tc.setPosition(tc.document()->findBlockByNumber(line - 1).position() + col + tk.length - 1);
tc.setPosition(tc.document()->findBlockByNumber(line - 1).position() + col + tk.f.length - 1);
return tc;
}
......
......@@ -77,7 +77,7 @@ public:
for (int index = 0; index <= _segmentCount; ++index) {
delete[] (_segments[index] + (index << SEGMENT_SHIFT));
}
free(_segments);
std::free(_segments);
}
}
......@@ -101,7 +101,7 @@ public:
if (++_count == _allocatedElements) {
if (++_segmentCount == _allocatedSegments) {
_allocatedSegments += 4;
_segments = (_Tp **) realloc(_segments, _allocatedSegments * sizeof(_Tp *));
_segments = (_Tp **) std::realloc(_segments, _allocatedSegments * sizeof(_Tp *));
}
_Tp *segment = new _Tp[SEGMENT_SIZE];
......
......@@ -50,7 +50,7 @@
#define CPLUSPLUS_DIAGNOSTICCLIENT_H
#include "CPlusPlusForwardDeclarations.h"
#include <cstdarg>
#include "stdarg.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
......
......@@ -84,82 +84,82 @@ FullySpecifiedType FullySpecifiedType::qualifiedType() const
}
bool FullySpecifiedType::isConst() const
{ return _isConst; }
{ return f._isConst; }
void FullySpecifiedType::setConst(bool isConst)
{ _isConst = isConst; }
{ f._isConst = isConst; }
bool FullySpecifiedType::isVolatile() const
{ return _isVolatile; }
{ return f._isVolatile; }
void FullySpecifiedType::setVolatile(bool isVolatile)
{ _isVolatile = isVolatile; }
{ f._isVolatile = isVolatile; }
bool FullySpecifiedType::isSigned() const
{ return _isSigned; }
{ return f._isSigned; }
void FullySpecifiedType::setSigned(bool isSigned)
{ _isSigned = isSigned; }
{ f._isSigned = isSigned; }
bool FullySpecifiedType::isUnsigned() const
{ return _isUnsigned; }
{ return f._isUnsigned; }
void FullySpecifiedType::setUnsigned(bool isUnsigned)
{ _isUnsigned = isUnsigned; }
{ f._isUnsigned = isUnsigned; }
bool FullySpecifiedType::isFriend() const
{ return _isFriend; }
{ return f._isFriend; }
void FullySpecifiedType::setFriend(bool isFriend)
{ _isFriend = isFriend; }
{ f._isFriend = isFriend; }
bool FullySpecifiedType::isRegister() const
{ return _isRegister; }
{ return f._isRegister; }
void FullySpecifiedType::setRegister(bool isRegister)
{ _isRegister = isRegister; }
{ f._isRegister = isRegister; }
bool FullySpecifiedType::isStatic() const
{ return _isStatic; }
{ return f._isStatic; }
void FullySpecifiedType::setStatic(bool isStatic)
{ _isStatic = isStatic; }
{ f._isStatic = isStatic; }
bool FullySpecifiedType::isExtern() const
{ return _isExtern; }
{ return f._isExtern; }
void FullySpecifiedType::setExtern(bool isExtern)
{ _isExtern = isExtern; }
{ f._isExtern = isExtern; }
bool FullySpecifiedType::isMutable() const
{ return _isMutable; }
{ return f._isMutable; }
void FullySpecifiedType::setMutable(bool isMutable)
{ _isMutable = isMutable; }
{ f._isMutable = isMutable; }
bool FullySpecifiedType::isTypedef() const
{ return _isTypedef; }
{ return f._isTypedef; }
void FullySpecifiedType::setTypedef(bool isTypedef)
{ _isTypedef = isTypedef; }
{ f._isTypedef = isTypedef; }
bool FullySpecifiedType::isInline() const
{ return _isInline; }
{ return f._isInline; }
void FullySpecifiedType::setInline(bool isInline)
{ _isInline = isInline; }
{ f._isInline = isInline; }
bool FullySpecifiedType::isVirtual() const
{ return _isVirtual; }
{ return f._isVirtual; }
void FullySpecifiedType::setVirtual(bool isVirtual)
{ _isVirtual = isVirtual; }
{ f._isVirtual = isVirtual; }
bool FullySpecifiedType::isExplicit() const
{ return _isExplicit; }
{ return f._isExplicit; }
void FullySpecifiedType::setExplicit(bool isExplicit)
{ _isExplicit = isExplicit; }
{ f._isExplicit = isExplicit; }
bool FullySpecifiedType::isEqualTo(const FullySpecifiedType &other) const
{
......
......@@ -121,30 +121,31 @@ public:
private:
Type *_type;
struct Flags {
// cv qualifiers
unsigned _isConst: 1;
unsigned _isVolatile: 1;
// sign
unsigned _isSigned: 1;
unsigned _isUnsigned: 1;
// storage class specifiers
unsigned _isFriend: 1;
unsigned _isRegister: 1;
unsigned _isStatic: 1;
unsigned _isExtern: 1;
unsigned _isMutable: 1;
unsigned _isTypedef: 1;
// function specifiers
unsigned _isInline: 1;
unsigned _isVirtual: 1;
unsigned _isExplicit: 1;
};
union {
unsigned _flags;
struct {
// cv qualifiers
unsigned _isConst: 1;
unsigned _isVolatile: 1;
// sign
unsigned _isSigned: 1;
unsigned _isUnsigned: 1;
// storage class specifiers
unsigned _isFriend: 1;
unsigned _isRegister: 1;
unsigned _isStatic: 1;
unsigned _isExtern: 1;
unsigned _isMutable: 1;
unsigned _isTypedef: 1;
// function specifiers
unsigned _isInline: 1;
unsigned _isVirtual: 1;
unsigned _isExplicit: 1;
};
Flags f;
};
};
......
</
......@@ -52,6 +52,8 @@
#include <cctype>
#include <cassert>
using namespace std;
CPLUSPLUS_BEGIN_NAMESPACE
Lexer::Lexer(TranslationUnit *unit)
......@@ -60,7 +62,7 @@ Lexer::Lexer(TranslationUnit *unit)
_flags(0),
_currentLine(1)
{
_scanKeywords = true;
f._scanKeywords = true;
setSource(_translationUnit->firstSourceChar(),
_translationUnit->lastSourceChar());
}
......@@ -71,7 +73,7 @@ Lexer::Lexer(const char *firstChar, const char *lastChar)
_flags(0),
_currentLine(1)
{
_scanKeywords = true;
f._scanKeywords = true;
setSource(firstChar, lastChar);
}
......@@ -113,37 +115,37 @@ void Lexer::setState(int state)
{ _state = state; }
bool Lexer::qtMocRunEnabled() const
{ return _qtMocRunEnabled; }
{ return f._qtMocRunEnabled; }
void Lexer::setQtMocRunEnabled(bool onoff)
{ _qtMocRunEnabled = onoff; }
{ f._qtMocRunEnabled = onoff; }
bool Lexer::objCEnabled() const
{ return _objCEnabled; }
{ return f._objCEnabled; }
void Lexer::setObjCEnabled(bool onoff)
{ _objCEnabled = onoff; }
{ f._objCEnabled = onoff; }
bool Lexer::isIncremental() const
{ return _isIncremental; }
{ return f._isIncremental; }
void Lexer::setIncremental(bool isIncremental)
{ _isIncremental = isIncremental; }
{ f._isIncremental = isIncremental; }
bool Lexer::scanCommentTokens() const
{ return _scanCommentTokens; }
{ return f._scanCommentTokens; }
void Lexer::setScanCommentTokens(bool onoff)
{ _scanCommentTokens = onoff; }
{ f._scanCommentTokens = onoff; }
bool Lexer::scanKeywords() const
{ return _scanKeywords; }
{ return f._scanKeywords; }
void Lexer::setScanKeywords(bool onoff)
{ _scanKeywords = onoff; }
{ f._scanKeywords = onoff; }
void Lexer::setScanAngleStringLiteralTokens(bool onoff)
{ _scanAngleStringLiteralTokens = onoff; }
{ f._scanAngleStringLiteralTokens = onoff; }
void Lexer::pushLineStartOffset()
{
......@@ -172,7 +174,7 @@ void Lexer::scan(Token *tok)
{
tok->reset();
scan_helper(tok);
tok->length = _currentChar - _tokenStart;
tok->f.length = _currentChar - _tokenStart;
}
void Lexer::scan_helper(Token *tok)
......@@ -180,9 +182,9 @@ void Lexer::scan_helper(Token *tok)
_Lagain:
while (_yychar && std::isspace(_yychar)) {
if (_yychar == '\n')
tok->newline = true;
tok->f.newline = true;
else
tok->whitespace = true;
tok->f.whitespace = true;
yyinp();
}
......@@ -196,7 +198,7 @@ void Lexer::scan_helper(Token *tok)
const int originalState = _state;
if (! _yychar) {
tok->kind = T_EOF_SYMBOL;
tok->f.kind = T_EOF_SYMBOL;
return;
}
......@@ -213,18 +215,18 @@ void Lexer::scan_helper(Token *tok)
}
}
if (! _scanCommentTokens)
if (! f._scanCommentTokens)
goto _Lagain;
else if (originalState == State_MultiLineComment)
tok->kind = T_COMMENT;
tok->f.kind = T_COMMENT;
else
tok->kind = T_DOXY_COMMENT;
tok->f.kind = T_DOXY_COMMENT;
return; // done
}
if (! _yychar) {
tok->kind = T_EOF_SYMBOL;
tok->f.kind = T_EOF_SYMBOL;
return;
}
......@@ -237,8 +239,8 @@ void Lexer::scan_helper(Token *tok)
yyinp();
// ### assert(! _yychar || _yychar == '\n');
if (_yychar == '\n') {
tok->joined = true;
tok->newline = false;
tok->f.joined = true;
tok->f.newline = false;
yyinp();
}
goto _Lagain;
......@@ -246,7 +248,7 @@ void Lexer::scan_helper(Token *tok)
case '"': case '\'': {
const char quote = ch;
tok->kind = quote == '"'
tok->f.kind = quote == '"'
? T_STRING_LITERAL
: T_CHAR_LITERAL;
......@@ -274,63 +276,63 @@ void Lexer::scan_helper(Token *tok)
} break;
case '{':
tok->kind = T_LBRACE;
tok->f.kind = T_LBRACE;
break;
case '}':
tok->kind = T_RBRACE;
tok->f.kind = T_RBRACE;
break;
case '[':
tok->kind = T_LBRACKET;
tok->f.kind = T_LBRACKET;
break;
case ']':
tok->kind = T_RBRACKET;
tok->f.kind = T_RBRACKET;
break;
case '#':
if (_yychar == '#') {
tok->kind = T_POUND_POUND;
tok->f.kind = T_POUND_POUND;
yyinp();
} else {
tok->kind = T_POUND;
tok->f.kind = T_POUND;
}
break;
case '(':
tok->kind = T_LPAREN;
tok->f.kind = T_LPAREN;
break;
case ')':
tok->kind = T_RPAREN;
tok->f.kind = T_RPAREN;
break;
case ';':
tok->kind = T_SEMICOLON;
tok->f.kind = T_SEMICOLON;
break;
case ':':
if (_yychar == ':') {
yyinp();
tok->kind = T_COLON_COLON;