forked from qt-creator/qt-creator
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.
This commit is contained in:
@@ -60,12 +60,12 @@ Macro::Macro()
|
|||||||
QString Macro::toString() const
|
QString Macro::toString() const
|
||||||
{
|
{
|
||||||
QString text;
|
QString text;
|
||||||
if (_hidden)
|
if (f._hidden)
|
||||||
text += QLatin1String("#undef ");
|
text += QLatin1String("#undef ");
|
||||||
else
|
else
|
||||||
text += QLatin1String("#define ");
|
text += QLatin1String("#define ");
|
||||||
text += QString::fromUtf8(_name.constData(), _name.size());
|
text += QString::fromUtf8(_name.constData(), _name.size());
|
||||||
if (_functionLike) {
|
if (f._functionLike) {
|
||||||
text += QLatin1Char('(');
|
text += QLatin1Char('(');
|
||||||
bool first = true;
|
bool first = true;
|
||||||
foreach (const QByteArray formal, _formals) {
|
foreach (const QByteArray formal, _formals) {
|
||||||
@@ -75,7 +75,7 @@ QString Macro::toString() const
|
|||||||
first = false;
|
first = false;
|
||||||
text += QString::fromUtf8(formal.constData(), formal.size());
|
text += QString::fromUtf8(formal.constData(), formal.size());
|
||||||
}
|
}
|
||||||
if (_variadic)
|
if (f._variadic)
|
||||||
text += QLatin1String("...");
|
text += QLatin1String("...");
|
||||||
text += QLatin1Char(')');
|
text += QLatin1Char(')');
|
||||||
}
|
}
|
||||||
|
@@ -93,22 +93,22 @@ public:
|
|||||||
{ _line = line; }
|
{ _line = line; }
|
||||||
|
|
||||||
bool isHidden() const
|
bool isHidden() const
|
||||||
{ return _hidden; }
|
{ return f._hidden; }
|
||||||
|
|
||||||
void setHidden(bool isHidden)
|
void setHidden(bool isHidden)
|
||||||
{ _hidden = isHidden; }
|
{ f._hidden = isHidden; }
|
||||||
|
|
||||||
bool isFunctionLike() const
|
bool isFunctionLike() const
|
||||||
{ return _functionLike; }
|
{ return f._functionLike; }
|
||||||
|
|
||||||
void setFunctionLike(bool isFunctionLike)
|
void setFunctionLike(bool isFunctionLike)
|
||||||
{ _functionLike = isFunctionLike; }
|
{ f._functionLike = isFunctionLike; }
|
||||||
|
|
||||||
bool isVariadic() const
|
bool isVariadic() const
|
||||||
{ return _variadic; }
|
{ return f._variadic; }
|
||||||
|
|
||||||
void setVariadic(bool isVariadic)
|
void setVariadic(bool isVariadic)
|
||||||
{ _variadic = isVariadic; }
|
{ f._variadic = isVariadic; }
|
||||||
|
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
|
|
||||||
@@ -117,6 +117,13 @@ public:
|
|||||||
unsigned _hashcode;
|
unsigned _hashcode;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct Flags
|
||||||
|
{
|
||||||
|
unsigned _hidden: 1;
|
||||||
|
unsigned _functionLike: 1;
|
||||||
|
unsigned _variadic: 1;
|
||||||
|
};
|
||||||
|
|
||||||
QByteArray _name;
|
QByteArray _name;
|
||||||
QByteArray _definition;
|
QByteArray _definition;
|
||||||
QVector<QByteArray> _formals;
|
QVector<QByteArray> _formals;
|
||||||
@@ -126,13 +133,7 @@ private:
|
|||||||
union
|
union
|
||||||
{
|
{
|
||||||
unsigned _state;
|
unsigned _state;
|
||||||
|
Flags f;
|
||||||
struct
|
|
||||||
{
|
|
||||||
unsigned _hidden: 1;
|
|
||||||
unsigned _functionLike: 1;
|
|
||||||
unsigned _variadic: 1;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -129,14 +129,14 @@ QList<SimpleToken> SimpleLexer::operator()(const QString &text, int state)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
SimpleToken simpleTk;
|
SimpleToken simpleTk;
|
||||||
simpleTk._kind = int(tk.kind);
|
simpleTk._kind = int(tk.f.kind);
|
||||||
simpleTk._position = int(lex.tokenOffset());
|
simpleTk._position = int(lex.tokenOffset());
|
||||||
simpleTk._length = int(lex.tokenLength());
|
simpleTk._length = int(lex.tokenLength());
|
||||||
simpleTk._text = text.midRef(simpleTk._position, simpleTk._length);
|
simpleTk._text = text.midRef(simpleTk._position, simpleTk._length);
|
||||||
|
|
||||||
lex.setScanAngleStringLiteralTokens(false);
|
lex.setScanAngleStringLiteralTokens(false);
|
||||||
|
|
||||||
if (tk.newline && tk.is(T_POUND))
|
if (tk.f.newline && tk.is(T_POUND))
|
||||||
inPreproc = true;
|
inPreproc = true;
|
||||||
else if (inPreproc && tokens.size() == 1 && simpleTk.is(T_IDENTIFIER) &&
|
else if (inPreproc && tokens.size() == 1 && simpleTk.is(T_IDENTIFIER) &&
|
||||||
simpleTk.text() == QLatin1String("include"))
|
simpleTk.text() == QLatin1String("include"))
|
||||||
|
@@ -64,7 +64,7 @@ struct Value
|
|||||||
{
|
{
|
||||||
enum Kind {
|
enum Kind {
|
||||||
Kind_Long,
|
Kind_Long,
|
||||||
Kind_ULong,
|
Kind_ULong
|
||||||
};
|
};
|
||||||
|
|
||||||
Kind kind;
|
Kind kind;
|
||||||
@@ -231,7 +231,7 @@ protected:
|
|||||||
QByteArray tokenSpell() const
|
QByteArray tokenSpell() const
|
||||||
{
|
{
|
||||||
const QByteArray text = QByteArray::fromRawData(source.constData() + (*_lex)->offset,
|
const QByteArray text = QByteArray::fromRawData(source.constData() + (*_lex)->offset,
|
||||||
(*_lex)->length);
|
(*_lex)->f.length);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -677,7 +677,7 @@ void Preprocessor::processSkippingBlocks(bool skippingBlocks,
|
|||||||
unsigned offset = start->offset;
|
unsigned offset = start->offset;
|
||||||
|
|
||||||
if (_skipping[iflevel]) {
|
if (_skipping[iflevel]) {
|
||||||
if (_dot->newline)
|
if (_dot->f.newline)
|
||||||
++offset;
|
++offset;
|
||||||
|
|
||||||
client->startSkippingBlocks(offset);
|
client->startSkippingBlocks(offset);
|
||||||
@@ -751,7 +751,7 @@ void Preprocessor::preprocess(const QString &fileName, const QByteArray &source,
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
if (_dot->joined)
|
if (_dot->f.joined)
|
||||||
out("\\");
|
out("\\");
|
||||||
|
|
||||||
processNewline();
|
processNewline();
|
||||||
@@ -759,13 +759,13 @@ void Preprocessor::preprocess(const QString &fileName, const QByteArray &source,
|
|||||||
if (_dot->is(T_EOF_SYMBOL)) {
|
if (_dot->is(T_EOF_SYMBOL)) {
|
||||||
break;
|
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
|
// handle the preprocessor directive
|
||||||
|
|
||||||
TokenIterator start = _dot;
|
TokenIterator start = _dot;
|
||||||
do {
|
do {
|
||||||
++_dot;
|
++_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];
|
const bool skippingBlocks = _skipping[iflevel];
|
||||||
|
|
||||||
@@ -777,11 +777,11 @@ void Preprocessor::preprocess(const QString &fileName, const QByteArray &source,
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
++_dot;
|
++_dot;
|
||||||
} while (_dot->isNot(T_EOF_SYMBOL) && (_dot->joined || ! _dot->newline));
|
} while (_dot->isNot(T_EOF_SYMBOL) && (_dot->f.joined || ! _dot->f.newline));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (_dot->whitespace) {
|
if (_dot->f.whitespace) {
|
||||||
unsigned endOfPreviousToken = 0;
|
unsigned endOfPreviousToken = 0;
|
||||||
|
|
||||||
if (_dot != _tokens.constBegin())
|
if (_dot != _tokens.constBegin())
|
||||||
@@ -1027,14 +1027,14 @@ const char *Preprocessor::endOfToken(const Token &token) const
|
|||||||
QByteArray Preprocessor::tokenSpell(const Token &token) const
|
QByteArray Preprocessor::tokenSpell(const Token &token) const
|
||||||
{
|
{
|
||||||
const QByteArray text = QByteArray::fromRawData(_source.constBegin() + token.offset,
|
const QByteArray text = QByteArray::fromRawData(_source.constBegin() + token.offset,
|
||||||
token.length);
|
token.f.length);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray Preprocessor::tokenText(const Token &token) const
|
QByteArray Preprocessor::tokenText(const Token &token) const
|
||||||
{
|
{
|
||||||
const QByteArray text(_source.constBegin() + token.offset,
|
const QByteArray text(_source.constBegin() + token.offset,
|
||||||
token.length);
|
token.f.length);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1179,7 +1179,7 @@ void Preprocessor::processDefine(TokenIterator firstToken, TokenIterator lastTok
|
|||||||
macro.setName(tokenText(*tk));
|
macro.setName(tokenText(*tk));
|
||||||
++tk; // skip T_IDENTIFIER
|
++tk; // skip T_IDENTIFIER
|
||||||
|
|
||||||
if (tk->is(T_LPAREN) && ! tk->whitespace) {
|
if (tk->is(T_LPAREN) && ! tk->f.whitespace) {
|
||||||
// a function-like macro definition
|
// a function-like macro definition
|
||||||
macro.setFunctionLike(true);
|
macro.setFunctionLike(true);
|
||||||
|
|
||||||
|
@@ -211,7 +211,7 @@ protected:
|
|||||||
unsigned line, col;
|
unsigned line, col;
|
||||||
getTokenStartPosition(index, &line, &col);
|
getTokenStartPosition(index, &line, &col);
|
||||||
QTextCursor tc = _textCursor;
|
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;
|
return tc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +284,7 @@ QTextCursor QuickFixOperation::cursor(unsigned index) const
|
|||||||
getTokenStartPosition(index, &line, &col);
|
getTokenStartPosition(index, &line, &col);
|
||||||
QTextCursor tc = _textCursor;
|
QTextCursor tc = _textCursor;
|
||||||
tc.setPosition(tc.document()->findBlockByNumber(line - 1).position() + col - 1);
|
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;
|
return tc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,7 +304,7 @@ QTextCursor QuickFixOperation::moveAtEndOfToken(unsigned index) const
|
|||||||
unsigned line, col;
|
unsigned line, col;
|
||||||
getTokenStartPosition(index, &line, &col);
|
getTokenStartPosition(index, &line, &col);
|
||||||
QTextCursor tc = _textCursor;
|
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;
|
return tc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -77,7 +77,7 @@ public:
|
|||||||
for (int index = 0; index <= _segmentCount; ++index) {
|
for (int index = 0; index <= _segmentCount; ++index) {
|
||||||
delete[] (_segments[index] + (index << SEGMENT_SHIFT));
|
delete[] (_segments[index] + (index << SEGMENT_SHIFT));
|
||||||
}
|
}
|
||||||
free(_segments);
|
std::free(_segments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ public:
|
|||||||
if (++_count == _allocatedElements) {
|
if (++_count == _allocatedElements) {
|
||||||
if (++_segmentCount == _allocatedSegments) {
|
if (++_segmentCount == _allocatedSegments) {
|
||||||
_allocatedSegments += 4;
|
_allocatedSegments += 4;
|
||||||
_segments = (_Tp **) realloc(_segments, _allocatedSegments * sizeof(_Tp *));
|
_segments = (_Tp **) std::realloc(_segments, _allocatedSegments * sizeof(_Tp *));
|
||||||
}
|
}
|
||||||
|
|
||||||
_Tp *segment = new _Tp[SEGMENT_SIZE];
|
_Tp *segment = new _Tp[SEGMENT_SIZE];
|
||||||
|
@@ -50,7 +50,7 @@
|
|||||||
#define CPLUSPLUS_DIAGNOSTICCLIENT_H
|
#define CPLUSPLUS_DIAGNOSTICCLIENT_H
|
||||||
|
|
||||||
#include "CPlusPlusForwardDeclarations.h"
|
#include "CPlusPlusForwardDeclarations.h"
|
||||||
#include <cstdarg>
|
#include "stdarg.h"
|
||||||
|
|
||||||
CPLUSPLUS_BEGIN_HEADER
|
CPLUSPLUS_BEGIN_HEADER
|
||||||
CPLUSPLUS_BEGIN_NAMESPACE
|
CPLUSPLUS_BEGIN_NAMESPACE
|
||||||
|
@@ -84,82 +84,82 @@ FullySpecifiedType FullySpecifiedType::qualifiedType() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool FullySpecifiedType::isConst() const
|
bool FullySpecifiedType::isConst() const
|
||||||
{ return _isConst; }
|
{ return f._isConst; }
|
||||||
|
|
||||||
void FullySpecifiedType::setConst(bool isConst)
|
void FullySpecifiedType::setConst(bool isConst)
|
||||||
{ _isConst = isConst; }
|
{ f._isConst = isConst; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isVolatile() const
|
bool FullySpecifiedType::isVolatile() const
|
||||||
{ return _isVolatile; }
|
{ return f._isVolatile; }
|
||||||
|
|
||||||
void FullySpecifiedType::setVolatile(bool isVolatile)
|
void FullySpecifiedType::setVolatile(bool isVolatile)
|
||||||
{ _isVolatile = isVolatile; }
|
{ f._isVolatile = isVolatile; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isSigned() const
|
bool FullySpecifiedType::isSigned() const
|
||||||
{ return _isSigned; }
|
{ return f._isSigned; }
|
||||||
|
|
||||||
void FullySpecifiedType::setSigned(bool isSigned)
|
void FullySpecifiedType::setSigned(bool isSigned)
|
||||||
{ _isSigned = isSigned; }
|
{ f._isSigned = isSigned; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isUnsigned() const
|
bool FullySpecifiedType::isUnsigned() const
|
||||||
{ return _isUnsigned; }
|
{ return f._isUnsigned; }
|
||||||
|
|
||||||
void FullySpecifiedType::setUnsigned(bool isUnsigned)
|
void FullySpecifiedType::setUnsigned(bool isUnsigned)
|
||||||
{ _isUnsigned = isUnsigned; }
|
{ f._isUnsigned = isUnsigned; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isFriend() const
|
bool FullySpecifiedType::isFriend() const
|
||||||
{ return _isFriend; }
|
{ return f._isFriend; }
|
||||||
|
|
||||||
void FullySpecifiedType::setFriend(bool isFriend)
|
void FullySpecifiedType::setFriend(bool isFriend)
|
||||||
{ _isFriend = isFriend; }
|
{ f._isFriend = isFriend; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isRegister() const
|
bool FullySpecifiedType::isRegister() const
|
||||||
{ return _isRegister; }
|
{ return f._isRegister; }
|
||||||
|
|
||||||
void FullySpecifiedType::setRegister(bool isRegister)
|
void FullySpecifiedType::setRegister(bool isRegister)
|
||||||
{ _isRegister = isRegister; }
|
{ f._isRegister = isRegister; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isStatic() const
|
bool FullySpecifiedType::isStatic() const
|
||||||
{ return _isStatic; }
|
{ return f._isStatic; }
|
||||||
|
|
||||||
void FullySpecifiedType::setStatic(bool isStatic)
|
void FullySpecifiedType::setStatic(bool isStatic)
|
||||||
{ _isStatic = isStatic; }
|
{ f._isStatic = isStatic; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isExtern() const
|
bool FullySpecifiedType::isExtern() const
|
||||||
{ return _isExtern; }
|
{ return f._isExtern; }
|
||||||
|
|
||||||
void FullySpecifiedType::setExtern(bool isExtern)
|
void FullySpecifiedType::setExtern(bool isExtern)
|
||||||
{ _isExtern = isExtern; }
|
{ f._isExtern = isExtern; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isMutable() const
|
bool FullySpecifiedType::isMutable() const
|
||||||
{ return _isMutable; }
|
{ return f._isMutable; }
|
||||||
|
|
||||||
void FullySpecifiedType::setMutable(bool isMutable)
|
void FullySpecifiedType::setMutable(bool isMutable)
|
||||||
{ _isMutable = isMutable; }
|
{ f._isMutable = isMutable; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isTypedef() const
|
bool FullySpecifiedType::isTypedef() const
|
||||||
{ return _isTypedef; }
|
{ return f._isTypedef; }
|
||||||
|
|
||||||
void FullySpecifiedType::setTypedef(bool isTypedef)
|
void FullySpecifiedType::setTypedef(bool isTypedef)
|
||||||
{ _isTypedef = isTypedef; }
|
{ f._isTypedef = isTypedef; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isInline() const
|
bool FullySpecifiedType::isInline() const
|
||||||
{ return _isInline; }
|
{ return f._isInline; }
|
||||||
|
|
||||||
void FullySpecifiedType::setInline(bool isInline)
|
void FullySpecifiedType::setInline(bool isInline)
|
||||||
{ _isInline = isInline; }
|
{ f._isInline = isInline; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isVirtual() const
|
bool FullySpecifiedType::isVirtual() const
|
||||||
{ return _isVirtual; }
|
{ return f._isVirtual; }
|
||||||
|
|
||||||
void FullySpecifiedType::setVirtual(bool isVirtual)
|
void FullySpecifiedType::setVirtual(bool isVirtual)
|
||||||
{ _isVirtual = isVirtual; }
|
{ f._isVirtual = isVirtual; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isExplicit() const
|
bool FullySpecifiedType::isExplicit() const
|
||||||
{ return _isExplicit; }
|
{ return f._isExplicit; }
|
||||||
|
|
||||||
void FullySpecifiedType::setExplicit(bool isExplicit)
|
void FullySpecifiedType::setExplicit(bool isExplicit)
|
||||||
{ _isExplicit = isExplicit; }
|
{ f._isExplicit = isExplicit; }
|
||||||
|
|
||||||
bool FullySpecifiedType::isEqualTo(const FullySpecifiedType &other) const
|
bool FullySpecifiedType::isEqualTo(const FullySpecifiedType &other) const
|
||||||
{
|
{
|
||||||
|
@@ -121,30 +121,31 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Type *_type;
|
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 {
|
union {
|
||||||
unsigned _flags;
|
unsigned _flags;
|
||||||
struct {
|
Flags f;
|
||||||
// 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;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -52,6 +52,8 @@
|
|||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
CPLUSPLUS_BEGIN_NAMESPACE
|
CPLUSPLUS_BEGIN_NAMESPACE
|
||||||
|
|
||||||
Lexer::Lexer(TranslationUnit *unit)
|
Lexer::Lexer(TranslationUnit *unit)
|
||||||
@@ -60,7 +62,7 @@ Lexer::Lexer(TranslationUnit *unit)
|
|||||||
_flags(0),
|
_flags(0),
|
||||||
_currentLine(1)
|
_currentLine(1)
|
||||||
{
|
{
|
||||||
_scanKeywords = true;
|
f._scanKeywords = true;
|
||||||
setSource(_translationUnit->firstSourceChar(),
|
setSource(_translationUnit->firstSourceChar(),
|
||||||
_translationUnit->lastSourceChar());
|
_translationUnit->lastSourceChar());
|
||||||
}
|
}
|
||||||
@@ -71,7 +73,7 @@ Lexer::Lexer(const char *firstChar, const char *lastChar)
|
|||||||
_flags(0),
|
_flags(0),
|
||||||
_currentLine(1)
|
_currentLine(1)
|
||||||
{
|
{
|
||||||
_scanKeywords = true;
|
f._scanKeywords = true;
|
||||||
setSource(firstChar, lastChar);
|
setSource(firstChar, lastChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,37 +115,37 @@ void Lexer::setState(int state)
|
|||||||
{ _state = state; }
|
{ _state = state; }
|
||||||
|
|
||||||
bool Lexer::qtMocRunEnabled() const
|
bool Lexer::qtMocRunEnabled() const
|
||||||
{ return _qtMocRunEnabled; }
|
{ return f._qtMocRunEnabled; }
|
||||||
|
|
||||||
void Lexer::setQtMocRunEnabled(bool onoff)
|
void Lexer::setQtMocRunEnabled(bool onoff)
|
||||||
{ _qtMocRunEnabled = onoff; }
|
{ f._qtMocRunEnabled = onoff; }
|
||||||
|
|
||||||
bool Lexer::objCEnabled() const
|
bool Lexer::objCEnabled() const
|
||||||
{ return _objCEnabled; }
|
{ return f._objCEnabled; }
|
||||||
|
|
||||||
void Lexer::setObjCEnabled(bool onoff)
|
void Lexer::setObjCEnabled(bool onoff)
|
||||||
{ _objCEnabled = onoff; }
|
{ f._objCEnabled = onoff; }
|
||||||
|
|
||||||
bool Lexer::isIncremental() const
|
bool Lexer::isIncremental() const
|
||||||
{ return _isIncremental; }
|
{ return f._isIncremental; }
|
||||||
|
|
||||||
void Lexer::setIncremental(bool isIncremental)
|
void Lexer::setIncremental(bool isIncremental)
|
||||||
{ _isIncremental = isIncremental; }
|
{ f._isIncremental = isIncremental; }
|
||||||
|
|
||||||
bool Lexer::scanCommentTokens() const
|
bool Lexer::scanCommentTokens() const
|
||||||
{ return _scanCommentTokens; }
|
{ return f._scanCommentTokens; }
|
||||||
|
|
||||||
void Lexer::setScanCommentTokens(bool onoff)
|
void Lexer::setScanCommentTokens(bool onoff)
|
||||||
{ _scanCommentTokens = onoff; }
|
{ f._scanCommentTokens = onoff; }
|
||||||
|
|
||||||
bool Lexer::scanKeywords() const
|
bool Lexer::scanKeywords() const
|
||||||
{ return _scanKeywords; }
|
{ return f._scanKeywords; }
|
||||||
|
|
||||||
void Lexer::setScanKeywords(bool onoff)
|
void Lexer::setScanKeywords(bool onoff)
|
||||||
{ _scanKeywords = onoff; }
|
{ f._scanKeywords = onoff; }
|
||||||
|
|
||||||
void Lexer::setScanAngleStringLiteralTokens(bool onoff)
|
void Lexer::setScanAngleStringLiteralTokens(bool onoff)
|
||||||
{ _scanAngleStringLiteralTokens = onoff; }
|
{ f._scanAngleStringLiteralTokens = onoff; }
|
||||||
|
|
||||||
void Lexer::pushLineStartOffset()
|
void Lexer::pushLineStartOffset()
|
||||||
{
|
{
|
||||||
@@ -172,7 +174,7 @@ void Lexer::scan(Token *tok)
|
|||||||
{
|
{
|
||||||
tok->reset();
|
tok->reset();
|
||||||
scan_helper(tok);
|
scan_helper(tok);
|
||||||
tok->length = _currentChar - _tokenStart;
|
tok->f.length = _currentChar - _tokenStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lexer::scan_helper(Token *tok)
|
void Lexer::scan_helper(Token *tok)
|
||||||
@@ -180,9 +182,9 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
_Lagain:
|
_Lagain:
|
||||||
while (_yychar && std::isspace(_yychar)) {
|
while (_yychar && std::isspace(_yychar)) {
|
||||||
if (_yychar == '\n')
|
if (_yychar == '\n')
|
||||||
tok->newline = true;
|
tok->f.newline = true;
|
||||||
else
|
else
|
||||||
tok->whitespace = true;
|
tok->f.whitespace = true;
|
||||||
yyinp();
|
yyinp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +198,7 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
const int originalState = _state;
|
const int originalState = _state;
|
||||||
|
|
||||||
if (! _yychar) {
|
if (! _yychar) {
|
||||||
tok->kind = T_EOF_SYMBOL;
|
tok->f.kind = T_EOF_SYMBOL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,18 +215,18 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! _scanCommentTokens)
|
if (! f._scanCommentTokens)
|
||||||
goto _Lagain;
|
goto _Lagain;
|
||||||
|
|
||||||
else if (originalState == State_MultiLineComment)
|
else if (originalState == State_MultiLineComment)
|
||||||
tok->kind = T_COMMENT;
|
tok->f.kind = T_COMMENT;
|
||||||
else
|
else
|
||||||
tok->kind = T_DOXY_COMMENT;
|
tok->f.kind = T_DOXY_COMMENT;
|
||||||
return; // done
|
return; // done
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! _yychar) {
|
if (! _yychar) {
|
||||||
tok->kind = T_EOF_SYMBOL;
|
tok->f.kind = T_EOF_SYMBOL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,8 +239,8 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
yyinp();
|
yyinp();
|
||||||
// ### assert(! _yychar || _yychar == '\n');
|
// ### assert(! _yychar || _yychar == '\n');
|
||||||
if (_yychar == '\n') {
|
if (_yychar == '\n') {
|
||||||
tok->joined = true;
|
tok->f.joined = true;
|
||||||
tok->newline = false;
|
tok->f.newline = false;
|
||||||
yyinp();
|
yyinp();
|
||||||
}
|
}
|
||||||
goto _Lagain;
|
goto _Lagain;
|
||||||
@@ -246,7 +248,7 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
case '"': case '\'': {
|
case '"': case '\'': {
|
||||||
const char quote = ch;
|
const char quote = ch;
|
||||||
|
|
||||||
tok->kind = quote == '"'
|
tok->f.kind = quote == '"'
|
||||||
? T_STRING_LITERAL
|
? T_STRING_LITERAL
|
||||||
: T_CHAR_LITERAL;
|
: T_CHAR_LITERAL;
|
||||||
|
|
||||||
@@ -274,63 +276,63 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case '{':
|
case '{':
|
||||||
tok->kind = T_LBRACE;
|
tok->f.kind = T_LBRACE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '}':
|
case '}':
|
||||||
tok->kind = T_RBRACE;
|
tok->f.kind = T_RBRACE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '[':
|
case '[':
|
||||||
tok->kind = T_LBRACKET;
|
tok->f.kind = T_LBRACKET;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ']':
|
case ']':
|
||||||
tok->kind = T_RBRACKET;
|
tok->f.kind = T_RBRACKET;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '#':
|
case '#':
|
||||||
if (_yychar == '#') {
|
if (_yychar == '#') {
|
||||||
tok->kind = T_POUND_POUND;
|
tok->f.kind = T_POUND_POUND;
|
||||||
yyinp();
|
yyinp();
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_POUND;
|
tok->f.kind = T_POUND;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '(':
|
case '(':
|
||||||
tok->kind = T_LPAREN;
|
tok->f.kind = T_LPAREN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ')':
|
case ')':
|
||||||
tok->kind = T_RPAREN;
|
tok->f.kind = T_RPAREN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ';':
|
case ';':
|
||||||
tok->kind = T_SEMICOLON;
|
tok->f.kind = T_SEMICOLON;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ':':
|
case ':':
|
||||||
if (_yychar == ':') {
|
if (_yychar == ':') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_COLON_COLON;
|
tok->f.kind = T_COLON_COLON;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_COLON;
|
tok->f.kind = T_COLON;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '.':
|
case '.':
|
||||||
if (_yychar == '*') {
|
if (_yychar == '*') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_DOT_STAR;
|
tok->f.kind = T_DOT_STAR;
|
||||||
} else if (_yychar == '.') {
|
} else if (_yychar == '.') {
|
||||||
yyinp();
|
yyinp();
|
||||||
// ### assert(_yychar);
|
// ### assert(_yychar);
|
||||||
if (_yychar == '.') {
|
if (_yychar == '.') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_DOT_DOT_DOT;
|
tok->f.kind = T_DOT_DOT_DOT;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_ERROR;
|
tok->f.kind = T_ERROR;
|
||||||
}
|
}
|
||||||
} else if (std::isdigit(_yychar)) {
|
} else if (std::isdigit(_yychar)) {
|
||||||
const char *yytext = _currentChar - 2;
|
const char *yytext = _currentChar - 2;
|
||||||
@@ -348,56 +350,56 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
}
|
}
|
||||||
} while (_yychar);
|
} while (_yychar);
|
||||||
int yylen = _currentChar - yytext;
|
int yylen = _currentChar - yytext;
|
||||||
tok->kind = T_NUMERIC_LITERAL;
|
tok->f.kind = T_NUMERIC_LITERAL;
|
||||||
if (control())
|
if (control())
|
||||||
tok->number = control()->findOrInsertNumericLiteral(yytext, yylen);
|
tok->number = control()->findOrInsertNumericLiteral(yytext, yylen);
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_DOT;
|
tok->f.kind = T_DOT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
tok->kind = T_QUESTION;
|
tok->f.kind = T_QUESTION;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '+':
|
case '+':
|
||||||
if (_yychar == '+') {
|
if (_yychar == '+') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_PLUS_PLUS;
|
tok->f.kind = T_PLUS_PLUS;
|
||||||
} else if (_yychar == '=') {
|
} else if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_PLUS_EQUAL;
|
tok->f.kind = T_PLUS_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_PLUS;
|
tok->f.kind = T_PLUS;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
if (_yychar == '-') {
|
if (_yychar == '-') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_MINUS_MINUS;
|
tok->f.kind = T_MINUS_MINUS;
|
||||||
} else if (_yychar == '=') {
|
} else if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_MINUS_EQUAL;
|
tok->f.kind = T_MINUS_EQUAL;
|
||||||
} else if (_yychar == '>') {
|
} else if (_yychar == '>') {
|
||||||
yyinp();
|
yyinp();
|
||||||
if (_yychar == '*') {
|
if (_yychar == '*') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_ARROW_STAR;
|
tok->f.kind = T_ARROW_STAR;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_ARROW;
|
tok->f.kind = T_ARROW;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_MINUS;
|
tok->f.kind = T_MINUS;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '*':
|
case '*':
|
||||||
if (_yychar == '=') {
|
if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_STAR_EQUAL;
|
tok->f.kind = T_STAR_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_STAR;
|
tok->f.kind = T_STAR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -420,10 +422,10 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
while (_yychar && _yychar != '\n')
|
while (_yychar && _yychar != '\n')
|
||||||
yyinp();
|
yyinp();
|
||||||
|
|
||||||
if (! _scanCommentTokens)
|
if (! f._scanCommentTokens)
|
||||||
goto _Lagain;
|
goto _Lagain;
|
||||||
|
|
||||||
tok->kind = doxy ? T_DOXY_COMMENT : T_COMMENT;
|
tok->f.kind = doxy ? T_DOXY_COMMENT : T_COMMENT;
|
||||||
|
|
||||||
} else if (_yychar == '*') {
|
} else if (_yychar == '*') {
|
||||||
yyinp();
|
yyinp();
|
||||||
@@ -461,90 +463,90 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
else
|
else
|
||||||
_state = doxy ? State_MultiLineDoxyComment : State_MultiLineComment;
|
_state = doxy ? State_MultiLineDoxyComment : State_MultiLineComment;
|
||||||
|
|
||||||
if (! _scanCommentTokens)
|
if (! f._scanCommentTokens)
|
||||||
goto _Lagain;
|
goto _Lagain;
|
||||||
|
|
||||||
tok->kind = doxy ? T_DOXY_COMMENT : T_COMMENT;
|
tok->f.kind = doxy ? T_DOXY_COMMENT : T_COMMENT;
|
||||||
|
|
||||||
} else if (_yychar == '=') {
|
} else if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_SLASH_EQUAL;
|
tok->f.kind = T_SLASH_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_SLASH;
|
tok->f.kind = T_SLASH;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '%':
|
case '%':
|
||||||
if (_yychar == '=') {
|
if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_PERCENT_EQUAL;
|
tok->f.kind = T_PERCENT_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_PERCENT;
|
tok->f.kind = T_PERCENT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '^':
|
case '^':
|
||||||
if (_yychar == '=') {
|
if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_CARET_EQUAL;
|
tok->f.kind = T_CARET_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_CARET;
|
tok->f.kind = T_CARET;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '&':
|
case '&':
|
||||||
if (_yychar == '&') {
|
if (_yychar == '&') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_AMPER_AMPER;
|
tok->f.kind = T_AMPER_AMPER;
|
||||||
} else if (_yychar == '=') {
|
} else if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_AMPER_EQUAL;
|
tok->f.kind = T_AMPER_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_AMPER;
|
tok->f.kind = T_AMPER;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '|':
|
case '|':
|
||||||
if (_yychar == '|') {
|
if (_yychar == '|') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_PIPE_PIPE;
|
tok->f.kind = T_PIPE_PIPE;
|
||||||
} else if (_yychar == '=') {
|
} else if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_PIPE_EQUAL;
|
tok->f.kind = T_PIPE_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_PIPE;
|
tok->f.kind = T_PIPE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '~':
|
case '~':
|
||||||
if (_yychar == '=') {
|
if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_TILDE_EQUAL;
|
tok->f.kind = T_TILDE_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_TILDE;
|
tok->f.kind = T_TILDE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '!':
|
case '!':
|
||||||
if (_yychar == '=') {
|
if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_EXCLAIM_EQUAL;
|
tok->f.kind = T_EXCLAIM_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_EXCLAIM;
|
tok->f.kind = T_EXCLAIM;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '=':
|
case '=':
|
||||||
if (_yychar == '=') {
|
if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_EQUAL_EQUAL;
|
tok->f.kind = T_EQUAL_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_EQUAL;
|
tok->f.kind = T_EQUAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '<':
|
case '<':
|
||||||
if (_scanAngleStringLiteralTokens) {
|
if (f._scanAngleStringLiteralTokens) {
|
||||||
const char *yytext = _currentChar;
|
const char *yytext = _currentChar;
|
||||||
while (_yychar && _yychar != '>')
|
while (_yychar && _yychar != '>')
|
||||||
yyinp();
|
yyinp();
|
||||||
@@ -554,19 +556,19 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
yyinp();
|
yyinp();
|
||||||
if (control())
|
if (control())
|
||||||
tok->string = control()->findOrInsertStringLiteral(yytext, yylen);
|
tok->string = control()->findOrInsertStringLiteral(yytext, yylen);
|
||||||
tok->kind = T_ANGLE_STRING_LITERAL;
|
tok->f.kind = T_ANGLE_STRING_LITERAL;
|
||||||
} else if (_yychar == '<') {
|
} else if (_yychar == '<') {
|
||||||
yyinp();
|
yyinp();
|
||||||
if (_yychar == '=') {
|
if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_LESS_LESS_EQUAL;
|
tok->f.kind = T_LESS_LESS_EQUAL;
|
||||||
} else
|
} else
|
||||||
tok->kind = T_LESS_LESS;
|
tok->f.kind = T_LESS_LESS;
|
||||||
} else if (_yychar == '=') {
|
} else if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_LESS_EQUAL;
|
tok->f.kind = T_LESS_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_LESS;
|
tok->f.kind = T_LESS;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -575,24 +577,24 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
yyinp();
|
yyinp();
|
||||||
if (_yychar == '=') {
|
if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_GREATER_GREATER_EQUAL;
|
tok->f.kind = T_GREATER_GREATER_EQUAL;
|
||||||
} else
|
} else
|
||||||
tok->kind = T_LESS_LESS;
|
tok->f.kind = T_LESS_LESS;
|
||||||
tok->kind = T_GREATER_GREATER;
|
tok->f.kind = T_GREATER_GREATER;
|
||||||
} else if (_yychar == '=') {
|
} else if (_yychar == '=') {
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_GREATER_EQUAL;
|
tok->f.kind = T_GREATER_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_GREATER;
|
tok->f.kind = T_GREATER;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ',':
|
case ',':
|
||||||
tok->kind = T_COMMA;
|
tok->f.kind = T_COMMA;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
if (_objCEnabled) {
|
if (f._objCEnabled) {
|
||||||
if (ch == '@' && _yychar >= 'a' && _yychar <= 'z') {
|
if (ch == '@' && _yychar >= 'a' && _yychar <= 'z') {
|
||||||
const char *yytext = _currentChar;
|
const char *yytext = _currentChar;
|
||||||
|
|
||||||
@@ -603,13 +605,13 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
} while (_yychar);
|
} while (_yychar);
|
||||||
|
|
||||||
const int yylen = _currentChar - yytext;
|
const int yylen = _currentChar - yytext;
|
||||||
tok->kind = classifyObjCAtKeyword(yytext, yylen);
|
tok->f.kind = classifyObjCAtKeyword(yytext, yylen);
|
||||||
break;
|
break;
|
||||||
} else if (ch == '@' && _yychar == '"') {
|
} else if (ch == '@' && _yychar == '"') {
|
||||||
// objc @string literals
|
// objc @string literals
|
||||||
ch = _yychar;
|
ch = _yychar;
|
||||||
yyinp();
|
yyinp();
|
||||||
tok->kind = T_AT_STRING_LITERAL;
|
tok->f.kind = T_AT_STRING_LITERAL;
|
||||||
|
|
||||||
const char *yytext = _currentChar;
|
const char *yytext = _currentChar;
|
||||||
|
|
||||||
@@ -644,7 +646,7 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
|
|
||||||
const char quote = ch;
|
const char quote = ch;
|
||||||
|
|
||||||
tok->kind = quote == '"'
|
tok->f.kind = quote == '"'
|
||||||
? T_WIDE_STRING_LITERAL
|
? T_WIDE_STRING_LITERAL
|
||||||
: T_WIDE_CHAR_LITERAL;
|
: T_WIDE_CHAR_LITERAL;
|
||||||
|
|
||||||
@@ -674,13 +676,13 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
while (std::isalnum(_yychar) || _yychar == '_')
|
while (std::isalnum(_yychar) || _yychar == '_')
|
||||||
yyinp();
|
yyinp();
|
||||||
int yylen = _currentChar - yytext;
|
int yylen = _currentChar - yytext;
|
||||||
if (_scanKeywords)
|
if (f._scanKeywords)
|
||||||
tok->kind = classify(yytext, yylen, _qtMocRunEnabled);
|
tok->f.kind = classify(yytext, yylen, f._qtMocRunEnabled);
|
||||||
else
|
else
|
||||||
tok->kind = T_IDENTIFIER;
|
tok->f.kind = T_IDENTIFIER;
|
||||||
|
|
||||||
if (tok->kind == T_IDENTIFIER) {
|
if (tok->f.kind == T_IDENTIFIER) {
|
||||||
tok->kind = classifyOperator(yytext, yylen);
|
tok->f.kind = classifyOperator(yytext, yylen);
|
||||||
|
|
||||||
if (control())
|
if (control())
|
||||||
tok->identifier = control()->findOrInsertIdentifier(yytext, yylen);
|
tok->identifier = control()->findOrInsertIdentifier(yytext, yylen);
|
||||||
@@ -702,12 +704,12 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
int yylen = _currentChar - yytext;
|
int yylen = _currentChar - yytext;
|
||||||
tok->kind = T_NUMERIC_LITERAL;
|
tok->f.kind = T_NUMERIC_LITERAL;
|
||||||
if (control())
|
if (control())
|
||||||
tok->number = control()->findOrInsertNumericLiteral(yytext, yylen);
|
tok->number = control()->findOrInsertNumericLiteral(yytext, yylen);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
tok->kind = T_ERROR;
|
tok->f.kind = T_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} // default
|
} // default
|
||||||
|
@@ -129,6 +129,15 @@ private:
|
|||||||
void pushLineStartOffset();
|
void pushLineStartOffset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct Flags {
|
||||||
|
unsigned _isIncremental: 1;
|
||||||
|
unsigned _scanCommentTokens: 1;
|
||||||
|
unsigned _scanKeywords: 1;
|
||||||
|
unsigned _scanAngleStringLiteralTokens: 1;
|
||||||
|
unsigned _qtMocRunEnabled: 1;
|
||||||
|
unsigned _objCEnabled: 1;
|
||||||
|
};
|
||||||
|
|
||||||
TranslationUnit *_translationUnit;
|
TranslationUnit *_translationUnit;
|
||||||
const char *_firstChar;
|
const char *_firstChar;
|
||||||
const char *_currentChar;
|
const char *_currentChar;
|
||||||
@@ -138,14 +147,7 @@ private:
|
|||||||
int _state;
|
int _state;
|
||||||
union {
|
union {
|
||||||
unsigned _flags;
|
unsigned _flags;
|
||||||
struct {
|
Flags f;
|
||||||
unsigned _isIncremental: 1;
|
|
||||||
unsigned _scanCommentTokens: 1;
|
|
||||||
unsigned _scanKeywords: 1;
|
|
||||||
unsigned _scanAngleStringLiteralTokens: 1;
|
|
||||||
unsigned _qtMocRunEnabled: 1;
|
|
||||||
unsigned _objCEnabled: 1;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
unsigned _currentLine;
|
unsigned _currentLine;
|
||||||
};
|
};
|
||||||
|
@@ -80,10 +80,10 @@ public:
|
|||||||
_Literal **lastLiteral = _literals + _literalCount + 1;
|
_Literal **lastLiteral = _literals + _literalCount + 1;
|
||||||
for (_Literal **it = _literals; it != lastLiteral; ++it)
|
for (_Literal **it = _literals; it != lastLiteral; ++it)
|
||||||
delete *it;
|
delete *it;
|
||||||
free(_literals);
|
std::free(_literals);
|
||||||
}
|
}
|
||||||
if (_buckets)
|
if (_buckets)
|
||||||
free(_buckets);
|
std::free(_buckets);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const
|
bool empty() const
|
||||||
@@ -107,7 +107,7 @@ public:
|
|||||||
unsigned h = _Literal::hashCode(chars, size);
|
unsigned h = _Literal::hashCode(chars, size);
|
||||||
_Literal *literal = _buckets[h % _allocatedBuckets];
|
_Literal *literal = _buckets[h % _allocatedBuckets];
|
||||||
for (; literal; literal = static_cast<_Literal *>(literal->_next)) {
|
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;
|
return literal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ public:
|
|||||||
if (! _allocatedLiterals)
|
if (! _allocatedLiterals)
|
||||||
_allocatedLiterals = 256;
|
_allocatedLiterals = 256;
|
||||||
|
|
||||||
_literals = (_Literal **) realloc(_literals, sizeof(_Literal *) * _allocatedLiterals);
|
_literals = (_Literal **) std::realloc(_literals, sizeof(_Literal *) * _allocatedLiterals);
|
||||||
}
|
}
|
||||||
|
|
||||||
_literals[_literalCount] = literal;
|
_literals[_literalCount] = literal;
|
||||||
@@ -140,14 +140,14 @@ protected:
|
|||||||
void rehash()
|
void rehash()
|
||||||
{
|
{
|
||||||
if (_buckets)
|
if (_buckets)
|
||||||
free(_buckets);
|
std::free(_buckets);
|
||||||
|
|
||||||
_allocatedBuckets <<= 1;
|
_allocatedBuckets <<= 1;
|
||||||
|
|
||||||
if (! _allocatedBuckets)
|
if (! _allocatedBuckets)
|
||||||
_allocatedBuckets = 256;
|
_allocatedBuckets = 256;
|
||||||
|
|
||||||
_buckets = (_Literal **) calloc(_allocatedBuckets, sizeof(_Literal *));
|
_buckets = (_Literal **) std::calloc(_allocatedBuckets, sizeof(_Literal *));
|
||||||
|
|
||||||
_Literal **lastLiteral = _literals + (_literalCount + 1);
|
_Literal **lastLiteral = _literals + (_literalCount + 1);
|
||||||
|
|
||||||
|
@@ -51,6 +51,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
CPLUSPLUS_BEGIN_NAMESPACE
|
CPLUSPLUS_BEGIN_NAMESPACE
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -113,20 +115,20 @@ enum {
|
|||||||
NumericLiteralIsDouble,
|
NumericLiteralIsDouble,
|
||||||
NumericLiteralIsLongDouble,
|
NumericLiteralIsLongDouble,
|
||||||
NumericLiteralIsLong,
|
NumericLiteralIsLong,
|
||||||
NumericLiteralIsLongLong,
|
NumericLiteralIsLongLong
|
||||||
};
|
};
|
||||||
|
|
||||||
NumericLiteral::NumericLiteral(const char *chars, unsigned size)
|
NumericLiteral::NumericLiteral(const char *chars, unsigned size)
|
||||||
: Literal(chars, size), _flags(0)
|
: Literal(chars, size), _flags(0)
|
||||||
{
|
{
|
||||||
_type = NumericLiteralIsInt;
|
f._type = NumericLiteralIsInt;
|
||||||
|
|
||||||
if (chars[0] == '\'') {
|
if (chars[0] == '\'') {
|
||||||
_type = NumericLiteralIsChar;
|
f._type = NumericLiteralIsChar;
|
||||||
} else if (size > 1 && chars[0] == 'L' && chars[1] == '\'') {
|
} 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')) {
|
} else if (size > 1 && chars[0] == '0' && (chars[1] == 'x' || chars[1] == 'X')) {
|
||||||
_isHex = true;
|
f._isHex = true;
|
||||||
} else {
|
} else {
|
||||||
const char *begin = chars;
|
const char *begin = chars;
|
||||||
const char *end = begin + size;
|
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) {
|
for (const char *dot = it; it != begin - 1; --it) {
|
||||||
if (*dot == '.')
|
if (*dot == '.')
|
||||||
_type = NumericLiteralIsDouble;
|
f._type = NumericLiteralIsDouble;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (++it; it != end; ++it) {
|
for (++it; it != end; ++it) {
|
||||||
if (*it == 'l' || *it == 'L') {
|
if (*it == 'l' || *it == 'L') {
|
||||||
if (_type == NumericLiteralIsDouble) {
|
if (f._type == NumericLiteralIsDouble) {
|
||||||
_type = NumericLiteralIsLongDouble;
|
f._type = NumericLiteralIsLongDouble;
|
||||||
} else if (it + 1 != end && (it[1] == 'l' || it[1] == 'L')) {
|
} else if (it + 1 != end && (it[1] == 'l' || it[1] == 'L')) {
|
||||||
++it;
|
++it;
|
||||||
_type = NumericLiteralIsLongLong;
|
f._type = NumericLiteralIsLongLong;
|
||||||
} else {
|
} else {
|
||||||
_type = NumericLiteralIsLong;
|
f._type = NumericLiteralIsLong;
|
||||||
}
|
}
|
||||||
} else if (*it == 'f' || *it == 'F') {
|
} else if (*it == 'f' || *it == 'F') {
|
||||||
_type = NumericLiteralIsFloat;
|
f._type = NumericLiteralIsFloat;
|
||||||
} else if (*it == 'u' || *it == 'U') {
|
} else if (*it == 'u' || *it == 'U') {
|
||||||
_isUnsigned = true;
|
f._isUnsigned = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,34 +177,34 @@ NumericLiteral::~NumericLiteral()
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool NumericLiteral::isHex() const
|
bool NumericLiteral::isHex() const
|
||||||
{ return _isHex; }
|
{ return f._isHex; }
|
||||||
|
|
||||||
bool NumericLiteral::isUnsigned() const
|
bool NumericLiteral::isUnsigned() const
|
||||||
{ return _isUnsigned; }
|
{ return f._isUnsigned; }
|
||||||
|
|
||||||
bool NumericLiteral::isChar() const
|
bool NumericLiteral::isChar() const
|
||||||
{ return _type == NumericLiteralIsChar; }
|
{ return f._type == NumericLiteralIsChar; }
|
||||||
|
|
||||||
bool NumericLiteral::isWideChar() const
|
bool NumericLiteral::isWideChar() const
|
||||||
{ return _type == NumericLiteralIsWideChar; }
|
{ return f._type == NumericLiteralIsWideChar; }
|
||||||
|
|
||||||
bool NumericLiteral::isInt() const
|
bool NumericLiteral::isInt() const
|
||||||
{ return _type == NumericLiteralIsInt; }
|
{ return f._type == NumericLiteralIsInt; }
|
||||||
|
|
||||||
bool NumericLiteral::isFloat() const
|
bool NumericLiteral::isFloat() const
|
||||||
{ return _type == NumericLiteralIsFloat; }
|
{ return f._type == NumericLiteralIsFloat; }
|
||||||
|
|
||||||
bool NumericLiteral::isDouble() const
|
bool NumericLiteral::isDouble() const
|
||||||
{ return _type == NumericLiteralIsDouble; }
|
{ return f._type == NumericLiteralIsDouble; }
|
||||||
|
|
||||||
bool NumericLiteral::isLongDouble() const
|
bool NumericLiteral::isLongDouble() const
|
||||||
{ return _type == NumericLiteralIsLongDouble; }
|
{ return f._type == NumericLiteralIsLongDouble; }
|
||||||
|
|
||||||
bool NumericLiteral::isLong() const
|
bool NumericLiteral::isLong() const
|
||||||
{ return _type == NumericLiteralIsLong; }
|
{ return f._type == NumericLiteralIsLong; }
|
||||||
|
|
||||||
bool NumericLiteral::isLongLong() const
|
bool NumericLiteral::isLongLong() const
|
||||||
{ return _type == NumericLiteralIsLongLong; }
|
{ return f._type == NumericLiteralIsLongLong; }
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Identifier::Identifier(const char *chars, unsigned size)
|
Identifier::Identifier(const char *chars, unsigned size)
|
||||||
|
@@ -115,14 +115,14 @@ public:
|
|||||||
bool isHex() const;
|
bool isHex() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct Flags {
|
||||||
|
unsigned _type : 8;
|
||||||
|
unsigned _isHex : 1;
|
||||||
|
unsigned _isUnsigned: 1;
|
||||||
|
};
|
||||||
union {
|
union {
|
||||||
unsigned _flags;
|
unsigned _flags;
|
||||||
|
Flags f;
|
||||||
struct {
|
|
||||||
unsigned _type : 8;
|
|
||||||
unsigned _isHex : 1;
|
|
||||||
unsigned _isUnsigned: 1;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -53,6 +53,8 @@
|
|||||||
|
|
||||||
CPLUSPLUS_BEGIN_NAMESPACE
|
CPLUSPLUS_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
MemoryPool::MemoryPool()
|
MemoryPool::MemoryPool()
|
||||||
: _initializeAllocatedMemory(true),
|
: _initializeAllocatedMemory(true),
|
||||||
_blocks(0),
|
_blocks(0),
|
||||||
|
@@ -84,7 +84,7 @@ void PrettyPrinter::outToken(unsigned token)
|
|||||||
oss << ba.constData();
|
oss << ba.constData();
|
||||||
|
|
||||||
// Print the token itself
|
// Print the token itself
|
||||||
QByteArray tt(_contents.constData() + t.begin(), t.length);
|
QByteArray tt(_contents.constData() + t.begin(), t.f.length);
|
||||||
oss << tt.constData();
|
oss << tt.constData();
|
||||||
|
|
||||||
QString stuff = QString::fromUtf8(oss.str().c_str());
|
QString stuff = QString::fromUtf8(oss.str().c_str());
|
||||||
|
@@ -55,6 +55,8 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
CPLUSPLUS_BEGIN_NAMESPACE
|
CPLUSPLUS_BEGIN_NAMESPACE
|
||||||
|
|
||||||
Scope::Scope(ScopedSymbol *owner)
|
Scope::Scope(ScopedSymbol *owner)
|
||||||
|
@@ -219,7 +219,7 @@ void Symbol::setSourceLocation(unsigned sourceLocation)
|
|||||||
|
|
||||||
const Token &tk = unit->tokenAt(sourceLocation);
|
const Token &tk = unit->tokenAt(sourceLocation);
|
||||||
|
|
||||||
_isGenerated = tk.generated;
|
_isGenerated = tk.f.generated;
|
||||||
_sourceOffset = tk.offset;
|
_sourceOffset = tk.offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -152,19 +152,19 @@ Function::~Function()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Function::isNormal() const
|
bool Function::isNormal() const
|
||||||
{ return _methodKey == NormalMethod; }
|
{ return f._methodKey == NormalMethod; }
|
||||||
|
|
||||||
bool Function::isSignal() const
|
bool Function::isSignal() const
|
||||||
{ return _methodKey == SignalMethod; }
|
{ return f._methodKey == SignalMethod; }
|
||||||
|
|
||||||
bool Function::isSlot() const
|
bool Function::isSlot() const
|
||||||
{ return _methodKey == SlotMethod; }
|
{ return f._methodKey == SlotMethod; }
|
||||||
|
|
||||||
int Function::methodKey() const
|
int Function::methodKey() const
|
||||||
{ return _methodKey; }
|
{ return f._methodKey; }
|
||||||
|
|
||||||
void Function::setMethodKey(int key)
|
void Function::setMethodKey(int key)
|
||||||
{ _methodKey = key; }
|
{ f._methodKey = key; }
|
||||||
|
|
||||||
unsigned Function::templateParameterCount() const
|
unsigned Function::templateParameterCount() const
|
||||||
{
|
{
|
||||||
@@ -249,34 +249,34 @@ bool Function::hasArguments() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Function::isVariadic() const
|
bool Function::isVariadic() const
|
||||||
{ return _isVariadic; }
|
{ return f._isVariadic; }
|
||||||
|
|
||||||
void Function::setVariadic(bool isVariadic)
|
void Function::setVariadic(bool isVariadic)
|
||||||
{ _isVariadic = isVariadic; }
|
{ f._isVariadic = isVariadic; }
|
||||||
|
|
||||||
bool Function::isConst() const
|
bool Function::isConst() const
|
||||||
{ return _isConst; }
|
{ return f._isConst; }
|
||||||
|
|
||||||
void Function::setConst(bool isConst)
|
void Function::setConst(bool isConst)
|
||||||
{ _isConst = isConst; }
|
{ f._isConst = isConst; }
|
||||||
|
|
||||||
bool Function::isVolatile() const
|
bool Function::isVolatile() const
|
||||||
{ return _isVolatile; }
|
{ return f._isVolatile; }
|
||||||
|
|
||||||
void Function::setVolatile(bool isVolatile)
|
void Function::setVolatile(bool isVolatile)
|
||||||
{ _isVolatile = isVolatile; }
|
{ f._isVolatile = isVolatile; }
|
||||||
|
|
||||||
bool Function::isPureVirtual() const
|
bool Function::isPureVirtual() const
|
||||||
{ return _isPureVirtual; }
|
{ return f._isPureVirtual; }
|
||||||
|
|
||||||
void Function::setPureVirtual(bool isPureVirtual)
|
void Function::setPureVirtual(bool isPureVirtual)
|
||||||
{ _isPureVirtual = isPureVirtual; }
|
{ f._isPureVirtual = isPureVirtual; }
|
||||||
|
|
||||||
bool Function::isAmbiguous() const
|
bool Function::isAmbiguous() const
|
||||||
{ return _isAmbiguous; }
|
{ return f._isAmbiguous; }
|
||||||
|
|
||||||
void Function::setAmbiguous(bool isAmbiguous)
|
void Function::setAmbiguous(bool isAmbiguous)
|
||||||
{ _isAmbiguous = isAmbiguous; }
|
{ f._isAmbiguous = isAmbiguous; }
|
||||||
|
|
||||||
void Function::visitSymbol0(SymbolVisitor *visitor)
|
void Function::visitSymbol0(SymbolVisitor *visitor)
|
||||||
{
|
{
|
||||||
|
@@ -338,17 +338,17 @@ protected:
|
|||||||
private:
|
private:
|
||||||
Scope *_templateParameters;
|
Scope *_templateParameters;
|
||||||
FullySpecifiedType _returnType;
|
FullySpecifiedType _returnType;
|
||||||
|
struct Flags {
|
||||||
|
unsigned _isVariadic: 1;
|
||||||
|
unsigned _isPureVirtual: 1;
|
||||||
|
unsigned _isConst: 1;
|
||||||
|
unsigned _isVolatile: 1;
|
||||||
|
unsigned _isAmbiguous: 1;
|
||||||
|
unsigned _methodKey: 3;
|
||||||
|
};
|
||||||
union {
|
union {
|
||||||
unsigned _flags;
|
unsigned _flags;
|
||||||
|
Flags f;
|
||||||
struct {
|
|
||||||
unsigned _isVariadic: 1;
|
|
||||||
unsigned _isPureVirtual: 1;
|
|
||||||
unsigned _isConst: 1;
|
|
||||||
unsigned _isVolatile: 1;
|
|
||||||
unsigned _isAmbiguous: 1;
|
|
||||||
unsigned _methodKey: 3;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
Scope *_arguments;
|
Scope *_arguments;
|
||||||
};
|
};
|
||||||
|
@@ -114,7 +114,7 @@ const char *Token::name(int kind)
|
|||||||
|
|
||||||
const char *Token::spell() const
|
const char *Token::spell() const
|
||||||
{
|
{
|
||||||
switch (kind) {
|
switch (f.kind) {
|
||||||
case T_IDENTIFIER:
|
case T_IDENTIFIER:
|
||||||
return identifier->chars();
|
return identifier->chars();
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ const char *Token::spell() const
|
|||||||
return literal->chars();
|
return literal->chars();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return token_names[kind];
|
return token_names[f.kind];
|
||||||
} // switch
|
} // switch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -276,8 +276,8 @@ public:
|
|||||||
Token();
|
Token();
|
||||||
~Token();
|
~Token();
|
||||||
|
|
||||||
inline bool is(unsigned k) const { return kind == k; }
|
inline bool is(unsigned k) const { return f.kind == k; }
|
||||||
inline bool isNot(unsigned k) const { return kind != k; }
|
inline bool isNot(unsigned k) const { return f.kind != k; }
|
||||||
const char *spell() const;
|
const char *spell() const;
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
@@ -285,39 +285,39 @@ public:
|
|||||||
{ return offset; }
|
{ return offset; }
|
||||||
|
|
||||||
inline unsigned end() const
|
inline unsigned end() const
|
||||||
{ return offset + length; }
|
{ return offset + f.length; }
|
||||||
|
|
||||||
inline bool isLiteral() const
|
inline bool isLiteral() const
|
||||||
{ return kind >= T_FIRST_LITERAL && kind <= T_LAST_LITERAL; }
|
{ return f.kind >= T_FIRST_LITERAL && f.kind <= T_LAST_LITERAL; }
|
||||||
|
|
||||||
inline bool isOperator() const
|
inline bool isOperator() const
|
||||||
{ return kind >= T_FIRST_OPERATOR && kind <= T_LAST_OPERATOR; }
|
{ return f.kind >= T_FIRST_OPERATOR && f.kind <= T_LAST_OPERATOR; }
|
||||||
|
|
||||||
inline bool isKeyword() const
|
inline bool isKeyword() const
|
||||||
{ return kind >= T_FIRST_KEYWORD && kind < T_FIRST_QT_KEYWORD; }
|
{ return f.kind >= T_FIRST_KEYWORD && f.kind < T_FIRST_QT_KEYWORD; }
|
||||||
|
|
||||||
inline bool isComment() const
|
inline bool isComment() const
|
||||||
{ return kind == T_COMMENT || kind == T_DOXY_COMMENT; }
|
{ return f.kind == T_COMMENT || f.kind == T_DOXY_COMMENT; }
|
||||||
|
|
||||||
inline bool isObjCAtKeyword() const
|
inline bool isObjCAtKeyword() const
|
||||||
{ return kind >= T_FIRST_OBJC_AT_KEYWORD && kind <= T_LAST_OBJC_AT_KEYWORD; }
|
{ return f.kind >= T_FIRST_OBJC_AT_KEYWORD && f.kind <= T_LAST_OBJC_AT_KEYWORD; }
|
||||||
|
|
||||||
static const char *name(int kind);
|
static const char *name(int kind);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
struct Flags {
|
||||||
|
unsigned kind : 8;
|
||||||
|
unsigned newline : 1;
|
||||||
|
unsigned whitespace : 1;
|
||||||
|
unsigned joined : 1;
|
||||||
|
unsigned expanded : 1;
|
||||||
|
unsigned generated : 1;
|
||||||
|
unsigned pad : 3;
|
||||||
|
unsigned length : 16;
|
||||||
|
};
|
||||||
union {
|
union {
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
|
Flags f;
|
||||||
struct {
|
|
||||||
unsigned kind : 8;
|
|
||||||
unsigned newline : 1;
|
|
||||||
unsigned whitespace : 1;
|
|
||||||
unsigned joined : 1;
|
|
||||||
unsigned expanded : 1;
|
|
||||||
unsigned generated : 1;
|
|
||||||
unsigned pad : 3;
|
|
||||||
unsigned length : 16;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned offset;
|
unsigned offset;
|
||||||
|
@@ -59,6 +59,8 @@
|
|||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
CPLUSPLUS_BEGIN_NAMESPACE
|
CPLUSPLUS_BEGIN_NAMESPACE
|
||||||
|
|
||||||
TranslationUnit::TranslationUnit(Control *control, StringLiteral *fileId)
|
TranslationUnit::TranslationUnit(Control *control, StringLiteral *fileId)
|
||||||
@@ -83,16 +85,16 @@ TranslationUnit::~TranslationUnit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool TranslationUnit::qtMocRunEnabled() const
|
bool TranslationUnit::qtMocRunEnabled() const
|
||||||
{ return _qtMocRunEnabled; }
|
{ return f._qtMocRunEnabled; }
|
||||||
|
|
||||||
void TranslationUnit::setQtMocRunEnabled(bool onoff)
|
void TranslationUnit::setQtMocRunEnabled(bool onoff)
|
||||||
{ _qtMocRunEnabled = onoff; }
|
{ f._qtMocRunEnabled = onoff; }
|
||||||
|
|
||||||
bool TranslationUnit::objCEnabled() const
|
bool TranslationUnit::objCEnabled() const
|
||||||
{ return _objCEnabled; }
|
{ return f._objCEnabled; }
|
||||||
|
|
||||||
void TranslationUnit::setObjCEnabled(bool onoff)
|
void TranslationUnit::setObjCEnabled(bool onoff)
|
||||||
{ _objCEnabled = onoff; }
|
{ f._objCEnabled = onoff; }
|
||||||
|
|
||||||
Control *TranslationUnit::control() const
|
Control *TranslationUnit::control() const
|
||||||
{ return _control; }
|
{ return _control; }
|
||||||
@@ -128,7 +130,7 @@ const Token &TranslationUnit::tokenAt(unsigned index) const
|
|||||||
{ return _tokens->at(index); }
|
{ return _tokens->at(index); }
|
||||||
|
|
||||||
int TranslationUnit::tokenKind(unsigned index) const
|
int TranslationUnit::tokenKind(unsigned index) const
|
||||||
{ return _tokens->at(index).kind; }
|
{ return _tokens->at(index).f.kind; }
|
||||||
|
|
||||||
const char *TranslationUnit::spell(unsigned index) const
|
const char *TranslationUnit::spell(unsigned index) const
|
||||||
{
|
{
|
||||||
@@ -160,21 +162,21 @@ AST *TranslationUnit::ast() const
|
|||||||
{ return _ast; }
|
{ return _ast; }
|
||||||
|
|
||||||
bool TranslationUnit::isTokenized() const
|
bool TranslationUnit::isTokenized() const
|
||||||
{ return _tokenized; }
|
{ return f._tokenized; }
|
||||||
|
|
||||||
bool TranslationUnit::isParsed() const
|
bool TranslationUnit::isParsed() const
|
||||||
{ return _parsed; }
|
{ return f._parsed; }
|
||||||
|
|
||||||
void TranslationUnit::tokenize()
|
void TranslationUnit::tokenize()
|
||||||
{
|
{
|
||||||
if (isTokenized())
|
if (isTokenized())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_tokenized = true;
|
f._tokenized = true;
|
||||||
|
|
||||||
Lexer lex(this);
|
Lexer lex(this);
|
||||||
lex.setQtMocRunEnabled(_qtMocRunEnabled);
|
lex.setQtMocRunEnabled(f._qtMocRunEnabled);
|
||||||
lex.setObjCEnabled(_objCEnabled);
|
lex.setObjCEnabled(f._objCEnabled);
|
||||||
|
|
||||||
std::stack<unsigned> braces;
|
std::stack<unsigned> braces;
|
||||||
_tokens->push_back(Token()); // the first token needs to be invalid!
|
_tokens->push_back(Token()); // the first token needs to be invalid!
|
||||||
@@ -195,23 +197,23 @@ void TranslationUnit::tokenize()
|
|||||||
unsigned offset = tk.offset;
|
unsigned offset = tk.offset;
|
||||||
lex(&tk);
|
lex(&tk);
|
||||||
|
|
||||||
if (! tk.newline && tk.is(T_IDENTIFIER) && tk.identifier == genId) {
|
if (! tk.f.newline && tk.is(T_IDENTIFIER) && tk.identifier == genId) {
|
||||||
// it's a gen directive.
|
// it's a gen directive.
|
||||||
lex(&tk);
|
lex(&tk);
|
||||||
|
|
||||||
if (! tk.newline && tk.is(T_TRUE)) {
|
if (! tk.f.newline && tk.is(T_TRUE)) {
|
||||||
lex(&tk);
|
lex(&tk);
|
||||||
generated = true;
|
generated = true;
|
||||||
} else {
|
} else {
|
||||||
generated = false;
|
generated = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (! tk.newline && tk.is(T_IDENTIFIER) && tk.identifier == lineId)
|
if (! tk.f.newline && tk.is(T_IDENTIFIER) && tk.identifier == lineId)
|
||||||
lex(&tk);
|
lex(&tk);
|
||||||
if (! tk.newline && tk.is(T_NUMERIC_LITERAL)) {
|
if (! tk.f.newline && tk.is(T_NUMERIC_LITERAL)) {
|
||||||
unsigned line = (unsigned) strtoul(tk.spell(), 0, 0);
|
unsigned line = (unsigned) strtoul(tk.spell(), 0, 0);
|
||||||
lex(&tk);
|
lex(&tk);
|
||||||
if (! tk.newline && tk.is(T_STRING_LITERAL)) {
|
if (! tk.f.newline && tk.is(T_STRING_LITERAL)) {
|
||||||
StringLiteral *fileName = control()->findOrInsertStringLiteral(tk.string->chars(),
|
StringLiteral *fileName = control()->findOrInsertStringLiteral(tk.string->chars(),
|
||||||
tk.string->size());
|
tk.string->size());
|
||||||
pushPreprocessorLine(offset, line, fileName);
|
pushPreprocessorLine(offset, line, fileName);
|
||||||
@@ -219,19 +221,19 @@ void TranslationUnit::tokenize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (tk.isNot(T_EOF_SYMBOL) && ! tk.newline)
|
while (tk.isNot(T_EOF_SYMBOL) && ! tk.f.newline)
|
||||||
lex(&tk);
|
lex(&tk);
|
||||||
goto _Lrecognize;
|
goto _Lrecognize;
|
||||||
} else if (tk.kind == T_LBRACE) {
|
} else if (tk.f.kind == T_LBRACE) {
|
||||||
braces.push(_tokens->size());
|
braces.push(_tokens->size());
|
||||||
} else if (tk.kind == T_RBRACE && ! braces.empty()) {
|
} else if (tk.f.kind == T_RBRACE && ! braces.empty()) {
|
||||||
const unsigned open_brace_index = braces.top();
|
const unsigned open_brace_index = braces.top();
|
||||||
braces.pop();
|
braces.pop();
|
||||||
(*_tokens)[open_brace_index].close_brace = _tokens->size();
|
(*_tokens)[open_brace_index].close_brace = _tokens->size();
|
||||||
}
|
}
|
||||||
tk.generated = generated;
|
tk.f.generated = generated;
|
||||||
_tokens->push_back(tk);
|
_tokens->push_back(tk);
|
||||||
} while (tk.kind);
|
} while (tk.f.kind);
|
||||||
|
|
||||||
for (; ! braces.empty(); braces.pop()) {
|
for (; ! braces.empty(); braces.pop()) {
|
||||||
unsigned open_brace_index = braces.top();
|
unsigned open_brace_index = braces.top();
|
||||||
@@ -240,10 +242,10 @@ void TranslationUnit::tokenize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool TranslationUnit::skipFunctionBody() const
|
bool TranslationUnit::skipFunctionBody() const
|
||||||
{ return _skipFunctionBody; }
|
{ return f._skipFunctionBody; }
|
||||||
|
|
||||||
void TranslationUnit::setSkipFunctionBody(bool skipFunctionBody)
|
void TranslationUnit::setSkipFunctionBody(bool skipFunctionBody)
|
||||||
{ _skipFunctionBody = skipFunctionBody; }
|
{ f._skipFunctionBody = skipFunctionBody; }
|
||||||
|
|
||||||
bool TranslationUnit::parse(ParseMode mode)
|
bool TranslationUnit::parse(ParseMode mode)
|
||||||
{
|
{
|
||||||
@@ -254,8 +256,8 @@ bool TranslationUnit::parse(ParseMode mode)
|
|||||||
tokenize();
|
tokenize();
|
||||||
|
|
||||||
Parser parser(this);
|
Parser parser(this);
|
||||||
parser.setQtMocRunEnabled(_qtMocRunEnabled);
|
parser.setQtMocRunEnabled(f._qtMocRunEnabled);
|
||||||
parser.setObjCEnabled(_objCEnabled);
|
parser.setObjCEnabled(f._objCEnabled);
|
||||||
|
|
||||||
bool parsed = false;
|
bool parsed = false;
|
||||||
|
|
||||||
@@ -375,14 +377,14 @@ void TranslationUnit::getPosition(unsigned tokenOffset,
|
|||||||
|
|
||||||
bool TranslationUnit::blockErrors(bool block)
|
bool TranslationUnit::blockErrors(bool block)
|
||||||
{
|
{
|
||||||
bool previous = _blockErrors;
|
bool previous = f._blockErrors;
|
||||||
_blockErrors = block;
|
f._blockErrors = block;
|
||||||
return previous;
|
return previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TranslationUnit::warning(unsigned index, const char *format, ...)
|
void TranslationUnit::warning(unsigned index, const char *format, ...)
|
||||||
{
|
{
|
||||||
if (_blockErrors)
|
if (f._blockErrors)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
index = std::min(index, tokenCount() - 1);
|
index = std::min(index, tokenCount() - 1);
|
||||||
@@ -413,7 +415,7 @@ void TranslationUnit::warning(unsigned index, const char *format, ...)
|
|||||||
|
|
||||||
void TranslationUnit::error(unsigned index, const char *format, ...)
|
void TranslationUnit::error(unsigned index, const char *format, ...)
|
||||||
{
|
{
|
||||||
if (_blockErrors)
|
if (f._blockErrors)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
index = std::min(index, tokenCount() - 1);
|
index = std::min(index, tokenCount() - 1);
|
||||||
@@ -444,7 +446,7 @@ void TranslationUnit::error(unsigned index, const char *format, ...)
|
|||||||
|
|
||||||
void TranslationUnit::fatal(unsigned index, const char *format, ...)
|
void TranslationUnit::fatal(unsigned index, const char *format, ...)
|
||||||
{
|
{
|
||||||
if (_blockErrors)
|
if (f._blockErrors)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
index = std::min(index, tokenCount() - 1);
|
index = std::min(index, tokenCount() - 1);
|
||||||
|
@@ -53,7 +53,7 @@
|
|||||||
#include "ASTfwd.h"
|
#include "ASTfwd.h"
|
||||||
#include "Token.h"
|
#include "Token.h"
|
||||||
#include "Array.h"
|
#include "Array.h"
|
||||||
#include <cstdio>
|
#include <stdio.h> // for FILE*
|
||||||
#include <vector> // ### remove me
|
#include <vector> // ### remove me
|
||||||
|
|
||||||
CPLUSPLUS_BEGIN_HEADER
|
CPLUSPLUS_BEGIN_HEADER
|
||||||
@@ -190,16 +190,17 @@ private:
|
|||||||
MemoryPool *_pool;
|
MemoryPool *_pool;
|
||||||
AST *_ast;
|
AST *_ast;
|
||||||
TranslationUnit *_previousTranslationUnit;
|
TranslationUnit *_previousTranslationUnit;
|
||||||
|
struct Flags {
|
||||||
|
unsigned _tokenized: 1;
|
||||||
|
unsigned _parsed: 1;
|
||||||
|
unsigned _blockErrors: 1;
|
||||||
|
unsigned _skipFunctionBody: 1;
|
||||||
|
unsigned _qtMocRunEnabled: 1;
|
||||||
|
unsigned _objCEnabled: 1;
|
||||||
|
};
|
||||||
union {
|
union {
|
||||||
unsigned _flags;
|
unsigned _flags;
|
||||||
struct {
|
Flags f;
|
||||||
unsigned _tokenized: 1;
|
|
||||||
unsigned _parsed: 1;
|
|
||||||
unsigned _blockErrors: 1;
|
|
||||||
unsigned _skipFunctionBody: 1;
|
|
||||||
unsigned _qtMocRunEnabled: 1;
|
|
||||||
unsigned _objCEnabled: 1;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user