Commit fd8cd69a authored by Roberto Raggi's avatar Roberto Raggi

Introduced Document::CheckMode.

parent 0b1bc40b
......@@ -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;
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);
......
......@@ -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;
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment