diff options
-rw-r--r-- | src/libs/cplusplus/CppDocument.cpp | 4 | ||||
-rw-r--r-- | src/libs/cplusplus/CppDocument.h | 7 | ||||
-rw-r--r-- | src/plugins/cpptools/cppmodelmanager.cpp | 10 | ||||
-rw-r--r-- | src/shared/cplusplus/CheckDeclaration.cpp | 34 | ||||
-rw-r--r-- | src/shared/cplusplus/Semantic.cpp | 8 | ||||
-rw-r--r-- | src/shared/cplusplus/Semantic.h | 3 |
6 files changed, 46 insertions, 20 deletions
diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp index ea6c0feb3a..49b09c3aca 100644 --- a/src/libs/cplusplus/CppDocument.cpp +++ b/src/libs/cplusplus/CppDocument.cpp @@ -314,11 +314,13 @@ bool Document::parse(ParseMode mode) return _translationUnit->parse(m); } -void Document::check() +void Document::check(CheckMode mode) { Q_ASSERT(!_globalNamespace); Semantic semantic(_control); + if (mode == FastCheck) + semantic.setSkipFunctionBodies(true); _globalNamespace = _control->newNamespace(0); Scope *globals = _globalNamespace->members(); diff --git a/src/libs/cplusplus/CppDocument.h b/src/libs/cplusplus/CppDocument.h index 3773971efc..486d6d7706 100644 --- a/src/libs/cplusplus/CppDocument.h +++ b/src/libs/cplusplus/CppDocument.h @@ -105,7 +105,12 @@ public: bool isParsed() const; bool parse(ParseMode mode = ParseTranlationUnit); - void check(); + enum CheckMode { + FullCheck, + FastCheck + }; + + void check(CheckMode mode = FullCheck); void releaseSource(); void releaseTranslationUnit(); diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index dc0e334d7f..7941df52c8 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -610,10 +610,16 @@ public: void operator()(Document::Ptr doc) { _doc = doc; + + Document::CheckMode mode = Document::FastCheck; + + if (_workingCopy.contains(doc->fileName())) + mode = Document::FullCheck; + doc->parse(); - doc->check(); + doc->check(mode); - if (_workingCopy.contains(doc->fileName())) { + if (mode == Document::FullCheck) { // run the binding pass NamespaceBindingPtr ns = bind(doc, _snapshot); diff --git a/src/shared/cplusplus/CheckDeclaration.cpp b/src/shared/cplusplus/CheckDeclaration.cpp index ef71c79809..038d70b9a4 100644 --- a/src/shared/cplusplus/CheckDeclaration.cpp +++ b/src/shared/cplusplus/CheckDeclaration.cpp @@ -304,26 +304,28 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast) ast->symbol = fun; _scope->enterSymbol(fun); - if (ast->ctor_initializer) { - bool looksLikeCtor = false; - if (ty.isValid() || ! fun->identity()) - looksLikeCtor = false; - else if (fun->identity()->isNameId() || fun->identity()->isTemplateNameId()) - looksLikeCtor = true; - - if (! looksLikeCtor) { - translationUnit()->error(ast->ctor_initializer->firstToken(), - "only constructors take base initializers"); + if (! semantic()->skipFunctionBodies()) { + if (ast->ctor_initializer) { + bool looksLikeCtor = false; + if (ty.isValid() || ! fun->identity()) + looksLikeCtor = false; + else if (fun->identity()->isNameId() || fun->identity()->isTemplateNameId()) + looksLikeCtor = true; + + if (! looksLikeCtor) { + translationUnit()->error(ast->ctor_initializer->firstToken(), + "only constructors take base initializers"); + } } - } - const int previousVisibility = semantic()->switchVisibility(Symbol::Public); - const int previousMethodKey = semantic()->switchMethodKey(Function::NormalMethod); + const int previousVisibility = semantic()->switchVisibility(Symbol::Public); + const int previousMethodKey = semantic()->switchMethodKey(Function::NormalMethod); - semantic()->check(ast->function_body, fun->members()); + semantic()->check(ast->function_body, fun->members()); - semantic()->switchMethodKey(previousMethodKey); - semantic()->switchVisibility(previousVisibility); + semantic()->switchMethodKey(previousMethodKey); + semantic()->switchVisibility(previousVisibility); + } return false; } diff --git a/src/shared/cplusplus/Semantic.cpp b/src/shared/cplusplus/Semantic.cpp index ff0fa418f8..9e7108bbc5 100644 --- a/src/shared/cplusplus/Semantic.cpp +++ b/src/shared/cplusplus/Semantic.cpp @@ -67,6 +67,7 @@ public: Data(Semantic *semantic, Control *control) : semantic(semantic), control(control), + skipFunctionBodies(false), visibility(Symbol::Public), methodKey(Function::NormalMethod), checkSpecifier(0), @@ -89,6 +90,7 @@ public: Semantic *semantic; Control *control; + bool skipFunctionBodies; int visibility; int methodKey; CheckSpecifier *checkSpecifier; @@ -142,6 +144,12 @@ Name *Semantic::check(NameAST *name, Scope *scope) Name *Semantic::check(NestedNameSpecifierAST *name, Scope *scope) { return d->checkName->check(name, scope); } +bool Semantic::skipFunctionBodies() const +{ return d->skipFunctionBodies; } + +void Semantic::setSkipFunctionBodies(bool skipFunctionBodies) +{ d->skipFunctionBodies = skipFunctionBodies; } + int Semantic::currentVisibility() const { return d->visibility; } diff --git a/src/shared/cplusplus/Semantic.h b/src/shared/cplusplus/Semantic.h index ef9753b092..9b9a4195be 100644 --- a/src/shared/cplusplus/Semantic.h +++ b/src/shared/cplusplus/Semantic.h @@ -84,6 +84,9 @@ public: Name *check(NestedNameSpecifierAST *name, Scope *scope); + bool skipFunctionBodies() const; + void setSkipFunctionBodies(bool skipFunctionBodies); + int currentVisibility() const; int switchVisibility(int visibility); |