diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-07-27 21:47:03 +0200 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-03 14:59:42 +0200 |
commit | d0457b70e33f1a090a91b0037e9254a0e14b8427 (patch) | |
tree | 2984b2db2129ba8cfefeac46d246a4a335b92150 /src/shared/cplusplus | |
parent | 88549a4b1dbbb16c7d63f176fd870ec8bdb61477 (diff) | |
download | qt-creator-d0457b70e33f1a090a91b0037e9254a0e14b8427.tar.gz |
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.
Diffstat (limited to 'src/shared/cplusplus')
-rw-r--r-- | src/shared/cplusplus/Array.h | 4 | ||||
-rw-r--r-- | src/shared/cplusplus/DiagnosticClient.h | 2 | ||||
-rw-r--r-- | src/shared/cplusplus/FullySpecifiedType.cpp | 52 | ||||
-rw-r--r-- | src/shared/cplusplus/FullySpecifiedType.h | 45 | ||||
-rw-r--r-- | src/shared/cplusplus/Lexer.cpp | 194 | ||||
-rw-r--r-- | src/shared/cplusplus/Lexer.h | 18 | ||||
-rw-r--r-- | src/shared/cplusplus/LiteralTable.h | 12 | ||||
-rw-r--r-- | src/shared/cplusplus/Literals.cpp | 46 | ||||
-rw-r--r-- | src/shared/cplusplus/Literals.h | 12 | ||||
-rw-r--r-- | src/shared/cplusplus/MemoryPool.cpp | 2 | ||||
-rw-r--r-- | src/shared/cplusplus/PrettyPrinter.cpp | 2 | ||||
-rw-r--r-- | src/shared/cplusplus/Scope.cpp | 2 | ||||
-rw-r--r-- | src/shared/cplusplus/Symbol.cpp | 2 | ||||
-rw-r--r-- | src/shared/cplusplus/Symbols.cpp | 30 | ||||
-rw-r--r-- | src/shared/cplusplus/Symbols.h | 18 | ||||
-rw-r--r-- | src/shared/cplusplus/Token.cpp | 4 | ||||
-rw-r--r-- | src/shared/cplusplus/Token.h | 38 | ||||
-rw-r--r-- | src/shared/cplusplus/TranslationUnit.cpp | 60 | ||||
-rw-r--r-- | src/shared/cplusplus/TranslationUnit.h | 19 |
19 files changed, 288 insertions, 274 deletions
diff --git a/src/shared/cplusplus/Array.h b/src/shared/cplusplus/Array.h index a3c66bd5ce..9fa7a657e9 100644 --- a/src/shared/cplusplus/Array.h +++ b/src/shared/cplusplus/Array.h @@ -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]; diff --git a/src/shared/cplusplus/DiagnosticClient.h b/src/shared/cplusplus/DiagnosticClient.h index 1df583fa8d..f37d5483ac 100644 --- a/src/shared/cplusplus/DiagnosticClient.h +++ b/src/shared/cplusplus/DiagnosticClient.h @@ -50,7 +50,7 @@ #define CPLUSPLUS_DIAGNOSTICCLIENT_H #include "CPlusPlusForwardDeclarations.h" -#include <cstdarg> +#include "stdarg.h" CPLUSPLUS_BEGIN_HEADER CPLUSPLUS_BEGIN_NAMESPACE diff --git a/src/shared/cplusplus/FullySpecifiedType.cpp b/src/shared/cplusplus/FullySpecifiedType.cpp index 5c97e8172b..da56804e85 100644 --- a/src/shared/cplusplus/FullySpecifiedType.cpp +++ b/src/shared/cplusplus/FullySpecifiedType.cpp @@ -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 { diff --git a/src/shared/cplusplus/FullySpecifiedType.h b/src/shared/cplusplus/FullySpecifiedType.h index ffe623c6b7..c150e594b2 100644 --- a/src/shared/cplusplus/FullySpecifiedType.h +++ b/src/shared/cplusplus/FullySpecifiedType.h @@ -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; }; }; diff --git a/src/shared/cplusplus/Lexer.cpp b/src/shared/cplusplus/Lexer.cpp index 5f727ef4af..d38aa036cd 100644 --- a/src/shared/cplusplus/Lexer.cpp +++ b/src/shared/cplusplus/Lexer.cpp @@ -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; + tok->f.kind = T_COLON_COLON; } else { - tok->kind = T_COLON; + tok->f.kind = T_COLON; } break; case '.': if (_yychar == '*') { yyinp(); - tok->kind = T_DOT_STAR; + tok->f.kind = T_DOT_STAR; } else if (_yychar == '.') { yyinp(); // ### assert(_yychar); if (_yychar == '.') { yyinp(); - tok->kind = T_DOT_DOT_DOT; + tok->f.kind = T_DOT_DOT_DOT; } else { - tok->kind = T_ERROR; + tok->f.kind = T_ERROR; } } else if (std::isdigit(_yychar)) { const char *yytext = _currentChar - 2; @@ -348,56 +350,56 @@ void Lexer::scan_helper(Token *tok) } } while (_yychar); int yylen = _currentChar - yytext; - tok->kind = T_NUMERIC_LITERAL; + tok->f.kind = T_NUMERIC_LITERAL; if (control()) tok->number = control()->findOrInsertNumericLiteral(yytext, yylen); } else { - tok->kind = T_DOT; + tok->f.kind = T_DOT; } break; case '?': - tok->kind = T_QUESTION; + tok->f.kind = T_QUESTION; break; case '+': if (_yychar == '+') { yyinp(); - tok->kind = T_PLUS_PLUS; + tok->f.kind = T_PLUS_PLUS; } else if (_yychar == '=') { yyinp(); - tok->kind = T_PLUS_EQUAL; + tok->f.kind = T_PLUS_EQUAL; } else { - tok->kind = T_PLUS; + tok->f.kind = T_PLUS; } break; case '-': if (_yychar == '-') { yyinp(); - tok->kind = T_MINUS_MINUS; + tok->f.kind = T_MINUS_MINUS; } else if (_yychar == '=') { yyinp(); - tok->kind = T_MINUS_EQUAL; + tok->f.kind = T_MINUS_EQUAL; } else if (_yychar == '>') { yyinp(); if (_yychar == '*') { yyinp(); - tok->kind = T_ARROW_STAR; + tok->f.kind = T_ARROW_STAR; } else { - tok->kind = T_ARROW; + tok->f.kind = T_ARROW; } } else { - tok->kind = T_MINUS; + tok->f.kind = T_MINUS; } break; case '*': if (_yychar == '=') { yyinp(); - tok->kind = T_STAR_EQUAL; + tok->f.kind = T_STAR_EQUAL; } else { - tok->kind = T_STAR; + tok->f.kind = T_STAR; } break; @@ -420,10 +422,10 @@ void Lexer::scan_helper(Token *tok) while (_yychar && _yychar != '\n') yyinp(); - if (! _scanCommentTokens) + if (! f._scanCommentTokens) goto _Lagain; - tok->kind = doxy ? T_DOXY_COMMENT : T_COMMENT; + tok->f.kind = doxy ? T_DOXY_COMMENT : T_COMMENT; } else if (_yychar == '*') { yyinp(); @@ -461,90 +463,90 @@ void Lexer::scan_helper(Token *tok) else _state = doxy ? State_MultiLineDoxyComment : State_MultiLineComment; - if (! _scanCommentTokens) + if (! f._scanCommentTokens) goto _Lagain; - tok->kind = doxy ? T_DOXY_COMMENT : T_COMMENT; + tok->f.kind = doxy ? T_DOXY_COMMENT : T_COMMENT; } else if (_yychar == '=') { yyinp(); - tok->kind = T_SLASH_EQUAL; + tok->f.kind = T_SLASH_EQUAL; } else { - tok->kind = T_SLASH; + tok->f.kind = T_SLASH; } break; case '%': if (_yychar == '=') { yyinp(); - tok->kind = T_PERCENT_EQUAL; + tok->f.kind = T_PERCENT_EQUAL; } else { - tok->kind = T_PERCENT; + tok->f.kind = T_PERCENT; } break; case '^': if (_yychar == '=') { yyinp(); - tok->kind = T_CARET_EQUAL; + tok->f.kind = T_CARET_EQUAL; } else { - tok->kind = T_CARET; + tok->f.kind = T_CARET; } break; case '&': if (_yychar == '&') { yyinp(); - tok->kind = T_AMPER_AMPER; + tok->f.kind = T_AMPER_AMPER; } else if (_yychar == '=') { yyinp(); - tok->kind = T_AMPER_EQUAL; + tok->f.kind = T_AMPER_EQUAL; } else { - tok->kind = T_AMPER; + tok->f.kind = T_AMPER; } break; case '|': if (_yychar == '|') { yyinp(); - tok->kind = T_PIPE_PIPE; + tok->f.kind = T_PIPE_PIPE; } else if (_yychar == '=') { yyinp(); - tok->kind = T_PIPE_EQUAL; + tok->f.kind = T_PIPE_EQUAL; } else { - tok->kind = T_PIPE; + tok->f.kind = T_PIPE; } break; case '~': if (_yychar == '=') { yyinp(); - tok->kind = T_TILDE_EQUAL; + tok->f.kind = T_TILDE_EQUAL; } else { - tok->kind = T_TILDE; + tok->f.kind = T_TILDE; } break; case '!': if (_yychar == '=') { yyinp(); - tok->kind = T_EXCLAIM_EQUAL; + tok->f.kind = T_EXCLAIM_EQUAL; } else { - tok->kind = T_EXCLAIM; + tok->f.kind = T_EXCLAIM; } break; case '=': if (_yychar == '=') { yyinp(); - tok->kind = T_EQUAL_EQUAL; + tok->f.kind = T_EQUAL_EQUAL; } else { - tok->kind = T_EQUAL; + tok->f.kind = T_EQUAL; } break; case '<': - if (_scanAngleStringLiteralTokens) { + if (f._scanAngleStringLiteralTokens) { const char *yytext = _currentChar; while (_yychar && _yychar != '>') yyinp(); @@ -554,19 +556,19 @@ void Lexer::scan_helper(Token *tok) yyinp(); if (control()) tok->string = control()->findOrInsertStringLiteral(yytext, yylen); - tok->kind = T_ANGLE_STRING_LITERAL; + tok->f.kind = T_ANGLE_STRING_LITERAL; } else if (_yychar == '<') { yyinp(); if (_yychar == '=') { yyinp(); - tok->kind = T_LESS_LESS_EQUAL; + tok->f.kind = T_LESS_LESS_EQUAL; } else - tok->kind = T_LESS_LESS; + tok->f.kind = T_LESS_LESS; } else if (_yychar == '=') { yyinp(); - tok->kind = T_LESS_EQUAL; + tok->f.kind = T_LESS_EQUAL; } else { - tok->kind = T_LESS; + tok->f.kind = T_LESS; } break; @@ -575,24 +577,24 @@ void Lexer::scan_helper(Token *tok) yyinp(); if (_yychar == '=') { yyinp(); - tok->kind = T_GREATER_GREATER_EQUAL; + tok->f.kind = T_GREATER_GREATER_EQUAL; } else - tok->kind = T_LESS_LESS; - tok->kind = T_GREATER_GREATER; + tok->f.kind = T_LESS_LESS; + tok->f.kind = T_GREATER_GREATER; } else if (_yychar == '=') { yyinp(); - tok->kind = T_GREATER_EQUAL; + tok->f.kind = T_GREATER_EQUAL; } else { - tok->kind = T_GREATER; + tok->f.kind = T_GREATER; } break; case ',': - tok->kind = T_COMMA; + tok->f.kind = T_COMMA; break; default: { - if (_objCEnabled) { + if (f._objCEnabled) { if (ch == '@' && _yychar >= 'a' && _yychar <= 'z') { const char *yytext = _currentChar; @@ -603,13 +605,13 @@ void Lexer::scan_helper(Token *tok) } while (_yychar); const int yylen = _currentChar - yytext; - tok->kind = classifyObjCAtKeyword(yytext, yylen); + tok->f.kind = classifyObjCAtKeyword(yytext, yylen); break; } else if (ch == '@' && _yychar == '"') { // objc @string literals ch = _yychar; yyinp(); - tok->kind = T_AT_STRING_LITERAL; + tok->f.kind = T_AT_STRING_LITERAL; const char *yytext = _currentChar; @@ -644,7 +646,7 @@ void Lexer::scan_helper(Token *tok) const char quote = ch; - tok->kind = quote == '"' + tok->f.kind = quote == '"' ? T_WIDE_STRING_LITERAL : T_WIDE_CHAR_LITERAL; @@ -674,13 +676,13 @@ void Lexer::scan_helper(Token *tok) while (std::isalnum(_yychar) || _yychar == '_') yyinp(); int yylen = _currentChar - yytext; - if (_scanKeywords) - tok->kind = classify(yytext, yylen, _qtMocRunEnabled); + if (f._scanKeywords) + tok->f.kind = classify(yytext, yylen, f._qtMocRunEnabled); else - tok->kind = T_IDENTIFIER; + tok->f.kind = T_IDENTIFIER; - if (tok->kind == T_IDENTIFIER) { - tok->kind = classifyOperator(yytext, yylen); + if (tok->f.kind == T_IDENTIFIER) { + tok->f.kind = classifyOperator(yytext, yylen); if (control()) tok->identifier = control()->findOrInsertIdentifier(yytext, yylen); @@ -702,12 +704,12 @@ void Lexer::scan_helper(Token *tok) } } int yylen = _currentChar - yytext; - tok->kind = T_NUMERIC_LITERAL; + tok->f.kind = T_NUMERIC_LITERAL; if (control()) tok->number = control()->findOrInsertNumericLiteral(yytext, yylen); break; } else { - tok->kind = T_ERROR; + tok->f.kind = T_ERROR; break; } } // default diff --git a/src/shared/cplusplus/Lexer.h b/src/shared/cplusplus/Lexer.h index f6ec63cfc2..2e6b48a233 100644 --- a/src/shared/cplusplus/Lexer.h +++ b/src/shared/cplusplus/Lexer.h @@ -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; }; diff --git a/src/shared/cplusplus/LiteralTable.h b/src/shared/cplusplus/LiteralTable.h index 06e55ebd03..370802faf6 100644 --- a/src/shared/cplusplus/LiteralTable.h +++ b/src/shared/cplusplus/LiteralTable.h @@ -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); diff --git a/src/shared/cplusplus/Literals.cpp b/src/shared/cplusplus/Literals.cpp index bf243373ec..07259ca2bb 100644 --- a/src/shared/cplusplus/Literals.cpp +++ b/src/shared/cplusplus/Literals.cpp @@ -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) diff --git a/src/shared/cplusplus/Literals.h b/src/shared/cplusplus/Literals.h index 78a8e3b62f..fdee505de9 100644 --- a/src/shared/cplusplus/Literals.h +++ b/src/shared/cplusplus/Literals.h @@ -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; }; }; diff --git a/src/shared/cplusplus/MemoryPool.cpp b/src/shared/cplusplus/MemoryPool.cpp index b05219e76c..7a36299320 100644 --- a/src/shared/cplusplus/MemoryPool.cpp +++ b/src/shared/cplusplus/MemoryPool.cpp @@ -53,6 +53,8 @@ CPLUSPLUS_BEGIN_NAMESPACE +using namespace std; + MemoryPool::MemoryPool() : _initializeAllocatedMemory(true), _blocks(0), diff --git a/src/shared/cplusplus/PrettyPrinter.cpp b/src/shared/cplusplus/PrettyPrinter.cpp index fd274c47d4..1c3ded6410 100644 --- a/src/shared/cplusplus/PrettyPrinter.cpp +++ b/src/shared/cplusplus/PrettyPrinter.cpp @@ -84,7 +84,7 @@ void PrettyPrinter::outToken(unsigned token) oss << ba.constData(); // Print the token itself - QByteArray tt(_contents.constData() + t.begin(), t.length); + QByteArray tt(_contents.constData() + t.begin(), t.f.length); oss << tt.constData(); QString stuff = QString::fromUtf8(oss.str().c_str()); diff --git a/src/shared/cplusplus/Scope.cpp b/src/shared/cplusplus/Scope.cpp index 50dd53da63..cabaeb023b 100644 --- a/src/shared/cplusplus/Scope.cpp +++ b/src/shared/cplusplus/Scope.cpp @@ -55,6 +55,8 @@ #include <cstring> #include <iostream> +using namespace std; + CPLUSPLUS_BEGIN_NAMESPACE Scope::Scope(ScopedSymbol *owner) diff --git a/src/shared/cplusplus/Symbol.cpp b/src/shared/cplusplus/Symbol.cpp index 37909bf98b..39f2b85b16 100644 --- a/src/shared/cplusplus/Symbol.cpp +++ b/src/shared/cplusplus/Symbol.cpp @@ -219,7 +219,7 @@ void Symbol::setSourceLocation(unsigned sourceLocation) const Token &tk = unit->tokenAt(sourceLocation); - _isGenerated = tk.generated; + _isGenerated = tk.f.generated; _sourceOffset = tk.offset; } } diff --git a/src/shared/cplusplus/Symbols.cpp b/src/shared/cplusplus/Symbols.cpp index d7446f9852..4946bb75f1 100644 --- a/src/shared/cplusplus/Symbols.cpp +++ b/src/shared/cplusplus/Symbols.cpp @@ -152,19 +152,19 @@ Function::~Function() } bool Function::isNormal() const -{ return _methodKey == NormalMethod; } +{ return f._methodKey == NormalMethod; } bool Function::isSignal() const -{ return _methodKey == SignalMethod; } +{ return f._methodKey == SignalMethod; } bool Function::isSlot() const -{ return _methodKey == SlotMethod; } +{ return f._methodKey == SlotMethod; } int Function::methodKey() const -{ return _methodKey; } +{ return f._methodKey; } void Function::setMethodKey(int key) -{ _methodKey = key; } +{ f._methodKey = key; } unsigned Function::templateParameterCount() const { @@ -249,34 +249,34 @@ bool Function::hasArguments() const } bool Function::isVariadic() const -{ return _isVariadic; } +{ return f._isVariadic; } void Function::setVariadic(bool isVariadic) -{ _isVariadic = isVariadic; } +{ f._isVariadic = isVariadic; } bool Function::isConst() const -{ return _isConst; } +{ return f._isConst; } void Function::setConst(bool isConst) -{ _isConst = isConst; } +{ f._isConst = isConst; } bool Function::isVolatile() const -{ return _isVolatile; } +{ return f._isVolatile; } void Function::setVolatile(bool isVolatile) -{ _isVolatile = isVolatile; } +{ f._isVolatile = isVolatile; } bool Function::isPureVirtual() const -{ return _isPureVirtual; } +{ return f._isPureVirtual; } void Function::setPureVirtual(bool isPureVirtual) -{ _isPureVirtual = isPureVirtual; } +{ f._isPureVirtual = isPureVirtual; } bool Function::isAmbiguous() const -{ return _isAmbiguous; } +{ return f._isAmbiguous; } void Function::setAmbiguous(bool isAmbiguous) -{ _isAmbiguous = isAmbiguous; } +{ f._isAmbiguous = isAmbiguous; } void Function::visitSymbol0(SymbolVisitor *visitor) { diff --git a/src/shared/cplusplus/Symbols.h b/src/shared/cplusplus/Symbols.h index a35dbf30b5..7bf8de0c89 100644 --- a/src/shared/cplusplus/Symbols.h +++ b/src/shared/cplusplus/Symbols.h @@ -338,17 +338,17 @@ protected: private: Scope *_templateParameters; FullySpecifiedType _returnType; + struct Flags { + unsigned _isVariadic: 1; + unsigned _isPureVirtual: 1; + unsigned _isConst: 1; + unsigned _isVolatile: 1; + unsigned _isAmbiguous: 1; + unsigned _methodKey: 3; + }; union { unsigned _flags; - - struct { - unsigned _isVariadic: 1; - unsigned _isPureVirtual: 1; - unsigned _isConst: 1; - unsigned _isVolatile: 1; - unsigned _isAmbiguous: 1; - unsigned _methodKey: 3; - }; + Flags f; }; Scope *_arguments; }; diff --git a/src/shared/cplusplus/Token.cpp b/src/shared/cplusplus/Token.cpp index 828da8da31..8f8a722aab 100644 --- a/src/shared/cplusplus/Token.cpp +++ b/src/shared/cplusplus/Token.cpp @@ -114,7 +114,7 @@ const char *Token::name(int kind) const char *Token::spell() const { - switch (kind) { + switch (f.kind) { case T_IDENTIFIER: return identifier->chars(); @@ -128,7 +128,7 @@ const char *Token::spell() const return literal->chars(); default: - return token_names[kind]; + return token_names[f.kind]; } // switch } diff --git a/src/shared/cplusplus/Token.h b/src/shared/cplusplus/Token.h index 6809468a1a..ab04dfc83c 100644 --- a/src/shared/cplusplus/Token.h +++ b/src/shared/cplusplus/Token.h @@ -276,8 +276,8 @@ public: Token(); ~Token(); - inline bool is(unsigned k) const { return kind == k; } - inline bool isNot(unsigned k) const { return kind != k; } + inline bool is(unsigned k) const { return f.kind == k; } + inline bool isNot(unsigned k) const { return f.kind != k; } const char *spell() const; void reset(); @@ -285,39 +285,39 @@ public: { return offset; } inline unsigned end() const - { return offset + length; } + { return offset + f.length; } 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 - { return kind >= T_FIRST_OPERATOR && kind <= T_LAST_OPERATOR; } + { return f.kind >= T_FIRST_OPERATOR && f.kind <= T_LAST_OPERATOR; } 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 - { return kind == T_COMMENT || kind == T_DOXY_COMMENT; } + { return f.kind == T_COMMENT || f.kind == T_DOXY_COMMENT; } 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); 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 { unsigned flags; - - 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; - }; + Flags f; }; unsigned offset; diff --git a/src/shared/cplusplus/TranslationUnit.cpp b/src/shared/cplusplus/TranslationUnit.cpp index 64145342b8..ff3b7e4fb7 100644 --- a/src/shared/cplusplus/TranslationUnit.cpp +++ b/src/shared/cplusplus/TranslationUnit.cpp @@ -59,6 +59,8 @@ #include <cstdarg> #include <algorithm> +using namespace std; + CPLUSPLUS_BEGIN_NAMESPACE TranslationUnit::TranslationUnit(Control *control, StringLiteral *fileId) @@ -83,16 +85,16 @@ TranslationUnit::~TranslationUnit() } bool TranslationUnit::qtMocRunEnabled() const -{ return _qtMocRunEnabled; } +{ return f._qtMocRunEnabled; } void TranslationUnit::setQtMocRunEnabled(bool onoff) -{ _qtMocRunEnabled = onoff; } +{ f._qtMocRunEnabled = onoff; } bool TranslationUnit::objCEnabled() const -{ return _objCEnabled; } +{ return f._objCEnabled; } void TranslationUnit::setObjCEnabled(bool onoff) -{ _objCEnabled = onoff; } +{ f._objCEnabled = onoff; } Control *TranslationUnit::control() const { return _control; } @@ -128,7 +130,7 @@ const Token &TranslationUnit::tokenAt(unsigned index) const { return _tokens->at(index); } int TranslationUnit::tokenKind(unsigned index) const -{ return _tokens->at(index).kind; } +{ return _tokens->at(index).f.kind; } const char *TranslationUnit::spell(unsigned index) const { @@ -160,21 +162,21 @@ AST *TranslationUnit::ast() const { return _ast; } bool TranslationUnit::isTokenized() const -{ return _tokenized; } +{ return f._tokenized; } bool TranslationUnit::isParsed() const -{ return _parsed; } +{ return f._parsed; } void TranslationUnit::tokenize() { if (isTokenized()) return; - _tokenized = true; + f._tokenized = true; Lexer lex(this); - lex.setQtMocRunEnabled(_qtMocRunEnabled); - lex.setObjCEnabled(_objCEnabled); + lex.setQtMocRunEnabled(f._qtMocRunEnabled); + lex.setObjCEnabled(f._objCEnabled); std::stack<unsigned> braces; _tokens->push_back(Token()); // the first token needs to be invalid! @@ -195,23 +197,23 @@ void TranslationUnit::tokenize() unsigned offset = tk.offset; 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. lex(&tk); - if (! tk.newline && tk.is(T_TRUE)) { + if (! tk.f.newline && tk.is(T_TRUE)) { lex(&tk); generated = true; } else { generated = false; } } else { - if (! tk.newline && tk.is(T_IDENTIFIER) && tk.identifier == lineId) + if (! tk.f.newline && tk.is(T_IDENTIFIER) && tk.identifier == lineId) 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); 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(), tk.string->size()); 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); goto _Lrecognize; - } else if (tk.kind == T_LBRACE) { + } else if (tk.f.kind == T_LBRACE) { 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(); braces.pop(); (*_tokens)[open_brace_index].close_brace = _tokens->size(); } - tk.generated = generated; + tk.f.generated = generated; _tokens->push_back(tk); - } while (tk.kind); + } while (tk.f.kind); for (; ! braces.empty(); braces.pop()) { unsigned open_brace_index = braces.top(); @@ -240,10 +242,10 @@ void TranslationUnit::tokenize() } bool TranslationUnit::skipFunctionBody() const -{ return _skipFunctionBody; } +{ return f._skipFunctionBody; } void TranslationUnit::setSkipFunctionBody(bool skipFunctionBody) -{ _skipFunctionBody = skipFunctionBody; } +{ f._skipFunctionBody = skipFunctionBody; } bool TranslationUnit::parse(ParseMode mode) { @@ -254,8 +256,8 @@ bool TranslationUnit::parse(ParseMode mode) tokenize(); Parser parser(this); - parser.setQtMocRunEnabled(_qtMocRunEnabled); - parser.setObjCEnabled(_objCEnabled); + parser.setQtMocRunEnabled(f._qtMocRunEnabled); + parser.setObjCEnabled(f._objCEnabled); bool parsed = false; @@ -375,14 +377,14 @@ void TranslationUnit::getPosition(unsigned tokenOffset, bool TranslationUnit::blockErrors(bool block) { - bool previous = _blockErrors; - _blockErrors = block; + bool previous = f._blockErrors; + f._blockErrors = block; return previous; } void TranslationUnit::warning(unsigned index, const char *format, ...) { - if (_blockErrors) + if (f._blockErrors) return; 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, ...) { - if (_blockErrors) + if (f._blockErrors) return; 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, ...) { - if (_blockErrors) + if (f._blockErrors) return; index = std::min(index, tokenCount() - 1); diff --git a/src/shared/cplusplus/TranslationUnit.h b/src/shared/cplusplus/TranslationUnit.h index 35f79480f0..112d142acb 100644 --- a/src/shared/cplusplus/TranslationUnit.h +++ b/src/shared/cplusplus/TranslationUnit.h @@ -53,7 +53,7 @@ #include "ASTfwd.h" #include "Token.h" #include "Array.h" -#include <cstdio> +#include <stdio.h> // for FILE* #include <vector> // ### remove me CPLUSPLUS_BEGIN_HEADER @@ -190,16 +190,17 @@ private: MemoryPool *_pool; AST *_ast; TranslationUnit *_previousTranslationUnit; + struct Flags { + unsigned _tokenized: 1; + unsigned _parsed: 1; + unsigned _blockErrors: 1; + unsigned _skipFunctionBody: 1; + unsigned _qtMocRunEnabled: 1; + unsigned _objCEnabled: 1; + }; union { unsigned _flags; - struct { - unsigned _tokenized: 1; - unsigned _parsed: 1; - unsigned _blockErrors: 1; - unsigned _skipFunctionBody: 1; - unsigned _qtMocRunEnabled: 1; - unsigned _objCEnabled: 1; - }; + Flags f; }; }; |