forked from qt-creator/qt-creator
Refactored the AST visitors.
Now, the ASTVisitor constructor takes a valid reference to a TranslationUnit.
This commit is contained in:
@@ -53,8 +53,8 @@
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
ASTVisitor::ASTVisitor(Control *control)
|
||||
: _control(control)
|
||||
ASTVisitor::ASTVisitor(TranslationUnit *translationUnit)
|
||||
: _translationUnit(translationUnit)
|
||||
{ }
|
||||
|
||||
ASTVisitor::~ASTVisitor()
|
||||
@@ -64,10 +64,18 @@ void ASTVisitor::accept(AST *ast)
|
||||
{ AST::accept(ast, this); }
|
||||
|
||||
Control *ASTVisitor::control() const
|
||||
{ return _control; }
|
||||
{
|
||||
if (_translationUnit)
|
||||
return _translationUnit->control();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
TranslationUnit *ASTVisitor::translationUnit() const
|
||||
{ return _control->translationUnit(); }
|
||||
{ return _translationUnit; }
|
||||
|
||||
void ASTVisitor::setTranslationUnit(TranslationUnit *translationUnit)
|
||||
{ _translationUnit = translationUnit; }
|
||||
|
||||
unsigned ASTVisitor::tokenCount() const
|
||||
{ return translationUnit()->tokenCount(); }
|
||||
|
||||
@@ -61,12 +61,13 @@ class CPLUSPLUS_EXPORT ASTVisitor
|
||||
void operator =(const ASTVisitor &other);
|
||||
|
||||
public:
|
||||
ASTVisitor(Control *control);
|
||||
ASTVisitor(TranslationUnit *unit);
|
||||
virtual ~ASTVisitor();
|
||||
|
||||
Control *control() const;
|
||||
TranslationUnit *translationUnit() const;
|
||||
void setTranslationUnit(TranslationUnit *translationUnit);
|
||||
|
||||
Control *control() const;
|
||||
unsigned tokenCount() const;
|
||||
const Token &tokenAt(unsigned index) const;
|
||||
int tokenKind(unsigned index) const;
|
||||
@@ -352,7 +353,7 @@ public:
|
||||
virtual void endVisit(ObjCSynchronizedStatementAST *) { }
|
||||
|
||||
private:
|
||||
Control *_control;
|
||||
TranslationUnit *_translationUnit;
|
||||
};
|
||||
|
||||
} // end of namespace CPlusPlus
|
||||
|
||||
@@ -64,9 +64,10 @@ using namespace CPlusPlus;
|
||||
class Semantic::Data
|
||||
{
|
||||
public:
|
||||
Data(Semantic *semantic, Control *control)
|
||||
Data(Semantic *semantic, TranslationUnit *translationUnit)
|
||||
: semantic(semantic),
|
||||
control(control),
|
||||
translationUnit(translationUnit),
|
||||
control(translationUnit->control()),
|
||||
skipFunctionBodies(false),
|
||||
visibility(Symbol::Public),
|
||||
ojbcVisibility(Symbol::Protected),
|
||||
@@ -90,6 +91,7 @@ public:
|
||||
}
|
||||
|
||||
Semantic *semantic;
|
||||
TranslationUnit *translationUnit;
|
||||
Control *control;
|
||||
bool skipFunctionBodies;
|
||||
int visibility;
|
||||
@@ -103,9 +105,9 @@ public:
|
||||
CheckName *checkName;
|
||||
};
|
||||
|
||||
Semantic::Semantic(Control *control)
|
||||
Semantic::Semantic(TranslationUnit *translationUnit)
|
||||
{
|
||||
d = new Data(this, control);
|
||||
d = new Data(this, translationUnit);
|
||||
d->checkSpecifier = new CheckSpecifier(this);
|
||||
d->checkDeclaration = new CheckDeclaration(this);
|
||||
d->checkDeclarator = new CheckDeclarator(this);
|
||||
@@ -117,6 +119,9 @@ Semantic::Semantic(Control *control)
|
||||
Semantic::~Semantic()
|
||||
{ delete d; }
|
||||
|
||||
TranslationUnit *Semantic::translationUnit() const
|
||||
{ return d->translationUnit; }
|
||||
|
||||
Control *Semantic::control() const
|
||||
{ return d->control; }
|
||||
|
||||
|
||||
@@ -61,9 +61,10 @@ class CPLUSPLUS_EXPORT Semantic
|
||||
void operator =(const Semantic &other);
|
||||
|
||||
public:
|
||||
Semantic(Control *control);
|
||||
Semantic(TranslationUnit *translationUnit);
|
||||
virtual ~Semantic();
|
||||
|
||||
TranslationUnit *translationUnit() const;
|
||||
Control *control() const;
|
||||
|
||||
FullySpecifiedType check(SpecifierListAST *specifier, Scope *scope);
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
using namespace CPlusPlus;
|
||||
|
||||
SemanticCheck::SemanticCheck(Semantic *semantic)
|
||||
: ASTVisitor(semantic->control()),
|
||||
: ASTVisitor(semantic->translationUnit()),
|
||||
_semantic(semantic)
|
||||
{ }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user