forked from qt-creator/qt-creator
Postpone the parsing of function definitions.
This commit is contained in:
@@ -85,6 +85,13 @@ void CheckDeclaration::check(DeclarationAST *declaration,
|
||||
(void) switchScope(previousScope);
|
||||
}
|
||||
|
||||
void CheckDeclaration::check(CtorInitializerAST *ast, Scope *scope)
|
||||
{
|
||||
Scope *previousScope = switchScope(scope);
|
||||
accept(ast);
|
||||
(void) switchScope(previousScope);
|
||||
}
|
||||
|
||||
DeclarationAST *CheckDeclaration::switchDeclaration(DeclarationAST *declaration)
|
||||
{
|
||||
DeclarationAST *previousDeclaration = _declaration;
|
||||
@@ -352,29 +359,8 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast)
|
||||
ast->symbol = fun;
|
||||
_scope->enterSymbol(fun);
|
||||
|
||||
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");
|
||||
}
|
||||
accept(ast->ctor_initializer);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
if (! semantic()->skipFunctionBodies())
|
||||
semantic()->checkFunctionDefinition(ast);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ public:
|
||||
virtual ~CheckDeclaration();
|
||||
|
||||
void check(DeclarationAST *declaration, Scope *scope, TemplateParameters *templateParameters);
|
||||
void check(CtorInitializerAST *ast, Scope *scope);
|
||||
|
||||
protected:
|
||||
DeclarationAST *switchDeclaration(DeclarationAST *declaration);
|
||||
|
||||
@@ -337,8 +337,13 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast)
|
||||
klass->setClassKey(Class::UnionKey);
|
||||
klass->setVisibility(semantic()->currentVisibility());
|
||||
_scope->enterSymbol(klass);
|
||||
|
||||
ClassSpecifierAST *previousClassSpecifier = semantic()->switchDeclaringClass(ast);
|
||||
|
||||
_fullySpecifiedType.setType(klass);
|
||||
|
||||
accept(ast->attribute_list);
|
||||
|
||||
if (_fullySpecifiedType.isDeprecated())
|
||||
klass->setDeprecated(true);
|
||||
|
||||
@@ -377,6 +382,8 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast)
|
||||
(void) semantic()->switchMethodKey(previousMethodKey);
|
||||
(void) semantic()->switchVisibility(previousVisibility);
|
||||
|
||||
(void) semantic()->switchDeclaringClass(previousClassSpecifier);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#include "Scope.h"
|
||||
#include "Symbols.h"
|
||||
#include "Token.h"
|
||||
#include "AST.h"
|
||||
#include "CheckSpecifier.h"
|
||||
#include "CheckDeclaration.h"
|
||||
#include "CheckDeclarator.h"
|
||||
@@ -61,6 +62,20 @@
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
SemanticClient::SemanticClient(Semantic *semantic)
|
||||
: _semantic(semantic)
|
||||
{
|
||||
}
|
||||
|
||||
SemanticClient::~SemanticClient()
|
||||
{
|
||||
}
|
||||
|
||||
Semantic *SemanticClient::semantic() const
|
||||
{
|
||||
return _semantic;
|
||||
}
|
||||
|
||||
class Semantic::Data
|
||||
{
|
||||
public:
|
||||
@@ -68,10 +83,12 @@ public:
|
||||
: semantic(semantic),
|
||||
translationUnit(translationUnit),
|
||||
control(translationUnit->control()),
|
||||
semanticClient(0),
|
||||
skipFunctionBodies(false),
|
||||
visibility(Symbol::Public),
|
||||
ojbcVisibility(Symbol::Protected),
|
||||
methodKey(Function::NormalMethod),
|
||||
declaringClass(0),
|
||||
checkSpecifier(0),
|
||||
checkDeclaration(0),
|
||||
checkDeclarator(0),
|
||||
@@ -93,16 +110,19 @@ public:
|
||||
Semantic *semantic;
|
||||
TranslationUnit *translationUnit;
|
||||
Control *control;
|
||||
SemanticClient *semanticClient;
|
||||
bool skipFunctionBodies;
|
||||
int visibility;
|
||||
int ojbcVisibility;
|
||||
int methodKey;
|
||||
ClassSpecifierAST *declaringClass;
|
||||
CheckSpecifier *checkSpecifier;
|
||||
CheckDeclaration *checkDeclaration;
|
||||
CheckDeclarator *checkDeclarator;
|
||||
CheckExpression *checkExpression;
|
||||
CheckStatement *checkStatement;
|
||||
CheckName *checkName;
|
||||
std::vector<FunctionDefinitionAST *> functionsToProcess;
|
||||
};
|
||||
|
||||
Semantic::Semantic(TranslationUnit *translationUnit)
|
||||
@@ -119,6 +139,12 @@ Semantic::Semantic(TranslationUnit *translationUnit)
|
||||
Semantic::~Semantic()
|
||||
{ delete d; }
|
||||
|
||||
SemanticClient *Semantic::semanticClient() const
|
||||
{ return d->semanticClient; }
|
||||
|
||||
void Semantic::setSemanticClient(SemanticClient *client)
|
||||
{ d->semanticClient = client; }
|
||||
|
||||
TranslationUnit *Semantic::translationUnit() const
|
||||
{ return d->translationUnit; }
|
||||
|
||||
@@ -162,6 +188,27 @@ const Name *Semantic::check(NameAST *name, Scope *scope)
|
||||
const Name *Semantic::check(NestedNameSpecifierListAST *name, Scope *scope)
|
||||
{ return d->checkName->check(name, scope); }
|
||||
|
||||
void Semantic::checkFunctionDefinition(FunctionDefinitionAST *ast)
|
||||
{
|
||||
if (d->declaringClass != 0)
|
||||
d->functionsToProcess.push_back(ast);
|
||||
else
|
||||
finishFunctionDefinition(ast);
|
||||
}
|
||||
|
||||
void Semantic::finishFunctionDefinition(FunctionDefinitionAST *ast)
|
||||
{
|
||||
const int previousVisibility = switchVisibility(Symbol::Public);
|
||||
const int previousMethodKey = switchMethodKey(Function::NormalMethod);
|
||||
|
||||
Function *fun = ast->symbol;
|
||||
d->checkDeclaration->check(ast->ctor_initializer, fun->scope());
|
||||
check(ast->function_body, fun->members());
|
||||
|
||||
switchMethodKey(previousMethodKey);
|
||||
switchVisibility(previousVisibility);
|
||||
}
|
||||
|
||||
bool Semantic::skipFunctionBodies() const
|
||||
{ return d->skipFunctionBodies; }
|
||||
|
||||
@@ -198,6 +245,25 @@ int Semantic::switchMethodKey(int methodKey)
|
||||
return previousMethodKey;
|
||||
}
|
||||
|
||||
ClassSpecifierAST *Semantic::declatingClass() const
|
||||
{ return d->declaringClass; }
|
||||
|
||||
ClassSpecifierAST *Semantic::switchDeclaringClass(ClassSpecifierAST *ast)
|
||||
{
|
||||
ClassSpecifierAST *previous = d->declaringClass;
|
||||
d->declaringClass = ast;
|
||||
|
||||
if (! ast && ! d->functionsToProcess.empty()) {
|
||||
const std::vector<FunctionDefinitionAST *> todo = d->functionsToProcess;
|
||||
d->functionsToProcess.clear();
|
||||
|
||||
for (std::vector<FunctionDefinitionAST *>::const_iterator it = todo.begin(); it != todo.end(); ++it)
|
||||
finishFunctionDefinition(*it);
|
||||
}
|
||||
|
||||
return previous;
|
||||
}
|
||||
|
||||
int Semantic::visibilityForAccessSpecifier(int tokenKind) const
|
||||
{
|
||||
switch (tokenKind) {
|
||||
|
||||
@@ -55,6 +55,22 @@
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
class CPLUSPLUS_EXPORT SemanticClient
|
||||
{
|
||||
SemanticClient(const SemanticClient &other);
|
||||
void operator = (const SemanticClient &other);
|
||||
|
||||
public:
|
||||
SemanticClient(Semantic *semantic);
|
||||
virtual ~SemanticClient();
|
||||
|
||||
Semantic *semantic() const;
|
||||
|
||||
private:
|
||||
Semantic *_semantic;
|
||||
};
|
||||
|
||||
|
||||
class CPLUSPLUS_EXPORT Semantic
|
||||
{
|
||||
Semantic(const Semantic &other);
|
||||
@@ -67,6 +83,9 @@ public:
|
||||
TranslationUnit *translationUnit() const;
|
||||
Control *control() const;
|
||||
|
||||
SemanticClient *semanticClient() const;
|
||||
void setSemanticClient(SemanticClient *client);
|
||||
|
||||
FullySpecifiedType check(SpecifierListAST *specifier, Scope *scope,
|
||||
const FullySpecifiedType &type = FullySpecifiedType());
|
||||
|
||||
@@ -93,6 +112,9 @@ public:
|
||||
|
||||
void check(ObjCMessageArgumentDeclarationAST *arg, Scope *scope);
|
||||
|
||||
void checkFunctionDefinition(FunctionDefinitionAST *ast);
|
||||
void finishFunctionDefinition(FunctionDefinitionAST *ast);
|
||||
|
||||
bool skipFunctionBodies() const;
|
||||
void setSkipFunctionBodies(bool skipFunctionBodies);
|
||||
|
||||
@@ -105,6 +127,9 @@ public:
|
||||
int currentMethodKey() const;
|
||||
int switchMethodKey(int methodKey);
|
||||
|
||||
ClassSpecifierAST *declatingClass() const;
|
||||
ClassSpecifierAST *switchDeclaringClass(ClassSpecifierAST *ast);
|
||||
|
||||
int visibilityForClassKey(int tokenKind) const;
|
||||
int visibilityForAccessSpecifier(int tokenKind) const;
|
||||
int visibilityForObjCAccessSpecifier(int tokenKind) const;
|
||||
|
||||
Reference in New Issue
Block a user