Commit d0457b70 authored by Thiago Macieira's avatar Thiago Macieira

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;
};
};
......
This diff is collapsed.
......@@ -129,6 +129,15 @@ private:
void pushLineStartOffset();
private:
struct Flags {
unsigned _isIncremental: 1;
unsigned _scanCommentTokens: 1;
unsigned _scanKeywords: 1;
unsigned _scanAngleStringLiteralTokens: 1;
unsigned _qtMocRunEnabled: 1;
unsigned _objCEnabled: 1;
};
TranslationUnit *_translationUnit;
const char *_firstChar;
const char *_currentChar;
......@@ -138,14 +147,7 @@ private:
int _state;
union {
unsigned _flags;
struct {
unsigned _isIncremental: 1;
unsigned _scanCommentTokens: 1;
unsigned _scanKeywords: 1;
unsigned _scanAngleStringLiteralTokens: 1;
unsigned _qtMocRunEnabled: 1;
unsigned _objCEnabled: 1;
};
Flags f;
};
unsigned _currentLine;
};
......
......@@ -80,10 +80,10 @@ public:
_Literal **lastLiteral = _literals + _literalCount + 1;
for (_Literal **it = _literals; it != lastLiteral; ++it)
delete *it;
free(_literals);
std::free(_literals);
}
if (_buckets)
free(_buckets);
std::free(_buckets);
}
bool empty() const
......@@ -107,7 +107,7 @@ public:
unsigned h = _Literal::hashCode(chars, size);
_Literal *literal = _buckets[h % _allocatedBuckets];
for (; literal; literal = static_cast<_Literal *>(literal->_next)) {
if (literal->size() == size && ! strncmp(literal->chars(), chars, size))
if (literal->size() == size && ! std::strncmp(literal->chars(), chars, size))
return literal;
}
}
......@@ -120,7 +120,7 @@ public:
if (! _allocatedLiterals)
_allocatedLiterals = 256;
_literals = (_Literal **) realloc(_literals, sizeof(_Literal *) * _allocatedLiterals);
_literals = (_Literal **) std::realloc(_literals, sizeof(_Literal *) * _allocatedLiterals);
}
_literals[_literalCount] = literal;
......@@ -140,14 +140,14 @@ protected:
void rehash()
{
if (_buckets)
free(_buckets);
std::free(_buckets);
_allocatedBuckets <<= 1;
if (! _allocatedBuckets)
_allocatedBuckets = 256;
_buckets = (_Literal **) calloc(_allocatedBuckets, sizeof(_Literal *));
_buckets = (_Literal **) std::calloc(_allocatedBuckets, sizeof(_Literal *));
_Literal **lastLiteral = _literals + (_literalCount + 1);
......
......@@ -51,6 +51,8 @@
#include <algorithm>
#include <iostream>
using namespace std;
CPLUSPLUS_BEGIN_NAMESPACE
////////////////////////////////////////////////////////////////////////////////
......@@ -113,20 +115,20 @@ enum {
NumericLiteralIsDouble,
NumericLiteralIsLongDouble,
NumericLiteralIsLong,
NumericLiteralIsLongLong,
NumericLiteralIsLongLong
};
NumericLiteral::NumericLiteral(const char *chars, unsigned size)
: Literal(chars, size), _flags(0)
{
_type = NumericLiteralIsInt;
f._type = NumericLiteralIsInt;
if (chars[0] == '\'') {
_type = NumericLiteralIsChar;
f._type = NumericLiteralIsChar;
} else if (size > 1 && chars[0] == 'L' && chars[1] == '\'') {
_type = NumericLiteralIsWideChar;
f._type = NumericLiteralIsWideChar;
} else if (size > 1 && chars[0] == '0' && (chars[1] == 'x' || chars[1] == 'X')) {
_isHex = true;
f._isHex = true;
} else {
const char *begin = chars;
const char *end = begin + size;
......@@ -149,23 +151,23 @@ NumericLiteral::NumericLiteral(const char *chars, unsigned size)
for (const char *dot = it; it != begin - 1; --it) {
if (*dot == '.')
_type = NumericLiteralIsDouble;
f._type = NumericLiteralIsDouble;
}
for (++it; it != end; ++it) {
if (*it == 'l' || *it == 'L') {
if (_type == NumericLiteralIsDouble) {
_type = NumericLiteralIsLongDouble;
if (f._type == NumericLiteralIsDouble) {
f._type = NumericLiteralIsLongDouble;
} else if (it + 1 != end && (it[1] == 'l' || it[1] == 'L')) {
++it;
_type = NumericLiteralIsLongLong;
f._type = NumericLiteralIsLongLong;
} else {
_type = NumericLiteralIsLong;
f._type = NumericLiteralIsLong;
}
} else if (*it == 'f' || *it == 'F') {
_type = NumericLiteralIsFloat;
f._type = NumericLiteralIsFloat;
} else if (*it == 'u' || *it == 'U') {
_isUnsigned = true;
f._isUnsigned = true;
}
}
}
......@@ -175,34 +177,34 @@ NumericLiteral::~NumericLiteral()
{ }
bool NumericLiteral::isHex() const
{ return _isHex; }
{ return f._isHex; }
bool NumericLiteral::isUnsigned() const
{ return _isUnsigned; }
{ return f._isUnsigned; }
bool NumericLiteral::isChar() const
{ return _type == NumericLiteralIsChar; }
{ return f._type == NumericLiteralIsChar; }
bool NumericLiteral::isWideChar() const
{ return _type == NumericLiteralIsWideChar; }
{ return f._type == NumericLiteralIsWideChar; }
bool NumericLiteral::isInt() const
{ return _type == NumericLiteralIsInt; }
{ return f._type == NumericLiteralIsInt; }
bool NumericLiteral::isFloat() const
{ return _type == NumericLiteralIsFloat; }
{ return f._type == NumericLiteralIsFloat; }
bool NumericLiteral::isDouble() const
{ return _type == NumericLiteralIsDouble; }
{ return f._type == NumericLiteralIsDouble; }
bool NumericLiteral::isLongDouble() const
{ return _type == NumericLiteralIsLongDouble; }
{ return f._type == NumericLiteralIsLongDouble; }
bool NumericLiteral::isLong() const
{ return _type == NumericLiteralIsLong; }
{ return f._type == NumericLiteralIsLong; }
bool NumericLiteral::isLongLong() const
{ return _type == NumericLiteralIsLongLong; }
{ return f._type == NumericLiteralIsLongLong; }
////////////////////////////////////////////////////////////////////////////////
Identifier::Identifier(const char *chars, unsigned size)
......
......@@ -115,14 +115,14 @@ public:
bool isHex() const;
private:
struct Flags {
unsigned _type : 8;
unsigned _isHex : 1;
unsigned _isUnsigned: 1;
};
union {
unsigned _flags;
struct {
unsigned _type : 8;
unsigned _isHex : 1;
unsigned _isUnsigned: 1;
};
Flags f;
};
};
......
......@@ -53,6 +53,8 @@
CPLUSPLUS_BEGIN_NAMESPACE
using namespace std;