forked from qt-creator/qt-creator
		
	Introduced Document::CheckMode.
This commit is contained in:
		@@ -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();
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
 
 | 
			
		||||
@@ -610,10 +610,16 @@ public:
 | 
			
		||||
    void operator()(Document::Ptr doc)
 | 
			
		||||
    {
 | 
			
		||||
        _doc = doc;
 | 
			
		||||
        doc->parse();
 | 
			
		||||
        doc->check();
 | 
			
		||||
 | 
			
		||||
        if (_workingCopy.contains(doc->fileName())) {
 | 
			
		||||
        Document::CheckMode mode = Document::FastCheck;
 | 
			
		||||
 | 
			
		||||
        if (_workingCopy.contains(doc->fileName()))
 | 
			
		||||
            mode = Document::FullCheck;
 | 
			
		||||
 | 
			
		||||
        doc->parse();
 | 
			
		||||
        doc->check(mode);
 | 
			
		||||
 | 
			
		||||
        if (mode == Document::FullCheck) {
 | 
			
		||||
            // run the binding pass
 | 
			
		||||
            NamespaceBindingPtr ns = bind(doc, _snapshot);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -304,27 +304,29 @@ 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 (! 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");
 | 
			
		||||
            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);
 | 
			
		||||
 | 
			
		||||
        semantic()->check(ast->function_body, fun->members());
 | 
			
		||||
 | 
			
		||||
        semantic()->switchMethodKey(previousMethodKey);
 | 
			
		||||
        semantic()->switchVisibility(previousVisibility);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const int previousVisibility = semantic()->switchVisibility(Symbol::Public);
 | 
			
		||||
    const int previousMethodKey = semantic()->switchMethodKey(Function::NormalMethod);
 | 
			
		||||
 | 
			
		||||
    semantic()->check(ast->function_body, fun->members());
 | 
			
		||||
 | 
			
		||||
    semantic()->switchMethodKey(previousMethodKey);
 | 
			
		||||
    semantic()->switchVisibility(previousVisibility);
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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; }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user