diff options
author | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2014-11-19 12:07:29 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2014-11-19 16:10:56 +0100 |
commit | beac7b9539457fe721de1709b9a406cac2379851 (patch) | |
tree | 49d8d0ff08d024566f163228dfb317636019c88c /src/libs/3rdparty/cplusplus | |
parent | 687fda833a3088d45c0c1f9a38c7594eecaee254 (diff) |
C++: Fix highlighting after "invalid code"
For the semantic info document we do not expand function like macros and
because of that certain macro invocations lead to invalid code that we
need to handle, e.g.:
Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder)
class Foo {};
This change makes parsing Foo in the semantic info document successfully
again, which affects highlighting of that class.
Change-Id: I389265ac64d3f0b8b8f406d38fa58d78820b14ba
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
Diffstat (limited to 'src/libs/3rdparty/cplusplus')
-rw-r--r-- | src/libs/3rdparty/cplusplus/Parser.cpp | 9 | ||||
-rw-r--r-- | src/libs/3rdparty/cplusplus/Parser.h | 3 | ||||
-rw-r--r-- | src/libs/3rdparty/cplusplus/TranslationUnit.cpp | 5 | ||||
-rw-r--r-- | src/libs/3rdparty/cplusplus/TranslationUnit.h | 5 |
4 files changed, 14 insertions, 8 deletions
diff --git a/src/libs/3rdparty/cplusplus/Parser.cpp b/src/libs/3rdparty/cplusplus/Parser.cpp index 11656bd47f1..c98f92cc37b 100644 --- a/src/libs/3rdparty/cplusplus/Parser.cpp +++ b/src/libs/3rdparty/cplusplus/Parser.cpp @@ -66,8 +66,6 @@ public: int DebugRule::depth = 0; -const int declarationsInRowAllowedToFail = 2; - inline bool lookAtAssignmentOperator(int tokenKind) { switch (tokenKind) { @@ -267,12 +265,13 @@ inline void debugPrintCheckCache(bool) {} return true; \ } -Parser::Parser(TranslationUnit *unit) +Parser::Parser(TranslationUnit *unit, int retryParseDeclarationLimit) : _translationUnit(unit), _control(unit->control()), _pool(unit->memoryPool()), _languageFeatures(unit->languageFeatures()), _tokenIndex(1), + _retryParseDeclarationLimit(retryParseDeclarationLimit), _templateArguments(0), _inFunctionBody(false), _inExpressionStatement(false), @@ -657,7 +656,7 @@ bool Parser::parseTranslationUnit(TranslationUnitAST *&node) } else { error(start_declaration, "expected a declaration"); rewind(start_declaration + 1); - if (++declarationsInRowFailedToParse == declarationsInRowAllowedToFail) + if (++declarationsInRowFailedToParse == _retryParseDeclarationLimit) skipUntilAfterSemicolonOrRightBrace(); else skipUntilDeclaration(); @@ -825,7 +824,7 @@ bool Parser::parseLinkageBody(DeclarationAST *&node) } else { error(start_declaration, "expected a declaration"); rewind(start_declaration + 1); - if (++declarationsInRowFailedToParse == declarationsInRowAllowedToFail) + if (++declarationsInRowFailedToParse == _retryParseDeclarationLimit) skipUntilAfterSemicolonOrRightBrace(); else skipUntilDeclaration(); diff --git a/src/libs/3rdparty/cplusplus/Parser.h b/src/libs/3rdparty/cplusplus/Parser.h index 923b0c4dc82..5f0a182bd12 100644 --- a/src/libs/3rdparty/cplusplus/Parser.h +++ b/src/libs/3rdparty/cplusplus/Parser.h @@ -33,7 +33,7 @@ namespace CPlusPlus { class CPLUSPLUS_EXPORT Parser { public: - Parser(TranslationUnit *translationUnit); + Parser(TranslationUnit *translationUnit, int retryParseDeclarationLimit); ~Parser(); bool parseTranslationUnit(TranslationUnitAST *&node); @@ -317,6 +317,7 @@ private: MemoryPool *_pool; LanguageFeatures _languageFeatures; unsigned _tokenIndex; + int _retryParseDeclarationLimit; bool _templateArguments: 1; bool _inFunctionBody: 1; bool _inExpressionStatement: 1; diff --git a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp index ace6eda549a..86eb25f1e35 100644 --- a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp +++ b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp @@ -49,7 +49,8 @@ TranslationUnit::TranslationUnit(Control *control, const StringLiteral *fileId) _lastSourceChar(0), _pool(0), _ast(0), - _flags(0) + _flags(0), + _retryParseDeclarationLimit(defaultRetryParseDeclarationLimit()) { _tokens = new std::vector<Token>(); _comments = new std::vector<Token>(); @@ -299,7 +300,7 @@ bool TranslationUnit::parse(ParseMode mode) f._parsed = true; - Parser parser(this); + Parser parser(this, _retryParseDeclarationLimit); bool parsed = false; switch (mode) { diff --git a/src/libs/3rdparty/cplusplus/TranslationUnit.h b/src/libs/3rdparty/cplusplus/TranslationUnit.h index 94eb81666be..eb4e1f2e3a5 100644 --- a/src/libs/3rdparty/cplusplus/TranslationUnit.h +++ b/src/libs/3rdparty/cplusplus/TranslationUnit.h @@ -149,6 +149,9 @@ public: LanguageFeatures languageFeatures() const { return _languageFeatures; } void setLanguageFeatures(LanguageFeatures features) { _languageFeatures = features; } + static int defaultRetryParseDeclarationLimit() { return 2; } + void setRetryParseDeclarationLimit(int limit) { _retryParseDeclarationLimit = limit; } + private: struct PPLine { unsigned utf16charOffset; @@ -210,6 +213,8 @@ private: Flags f; }; LanguageFeatures _languageFeatures; + + int _retryParseDeclarationLimit; }; } // namespace CPlusPlus |