Commit 5d7def6d authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Refactored the AST visitors.

Now, the ASTVisitor constructor takes a valid reference to a TranslationUnit.
parent 04a333ba
......@@ -32,8 +32,8 @@
using namespace CPlusPlus;
ASTParent::ASTParent(Control *control, AST *rootNode)
: ASTVisitor(control)
ASTParent::ASTParent(TranslationUnit *translationUnit, AST *rootNode)
: ASTVisitor(translationUnit)
{
accept(rootNode);
}
......
......@@ -39,7 +39,7 @@ namespace CPlusPlus {
class CPLUSPLUS_EXPORT ASTParent: protected ASTVisitor
{
public:
ASTParent(Control *control, AST *rootNode);
ASTParent(TranslationUnit *transaltionUnit, AST *rootNode);
virtual ~ASTParent();
AST *operator()(AST *ast) const;
......
......@@ -41,7 +41,7 @@ using namespace CPlusPlus;
CheckUndefinedSymbols::CheckUndefinedSymbols(Document::Ptr doc)
: ASTVisitor(doc->control()), _doc(doc)
: ASTVisitor(doc->translationUnit()), _doc(doc)
{ }
CheckUndefinedSymbols::~CheckUndefinedSymbols()
......
......@@ -404,7 +404,7 @@ void Document::check(CheckMode mode)
if (! isParsed())
parse();
Semantic semantic(_control);
Semantic semantic(_translationUnit);
if (mode == FastCheck)
semantic.setSkipFunctionBodies(true);
......
......@@ -41,12 +41,12 @@
using namespace CPlusPlus;
FindUsages::FindUsages(Document::Ptr doc, const Snapshot &snapshot, QFutureInterface<Usage> *future)
: ASTVisitor(doc->control()),
: ASTVisitor(doc->translationUnit()),
_future(future),
_doc(doc),
_snapshot(snapshot),
_source(_doc->source()),
_sem(doc->control()),
_sem(doc->translationUnit()),
_inSimpleDeclaration(0)
{
_snapshot.insert(_doc);
......
......@@ -72,9 +72,9 @@ static QList<_Tp> removeDuplicates(const QList<_Tp> &results)
// ResolveExpression
/////////////////////////////////////////////////////////////////////
ResolveExpression::ResolveExpression(const LookupContext &context)
: ASTVisitor(context.expressionDocument()->control()),
: ASTVisitor(context.expressionDocument()->translationUnit()),
_context(context),
sem(_context.control())
sem(context.expressionDocument()->translationUnit())
{ }
ResolveExpression::~ResolveExpression()
......
......@@ -191,8 +191,8 @@ class FindUses: protected ASTVisitor
FindScope findScope;
public:
FindUses(Control *control)
: ASTVisitor(control)
FindUses(TranslationUnit *translationUnit)
: ASTVisitor(translationUnit)
{ }
// local and external uses.
......@@ -382,8 +382,8 @@ class FunctionDefinitionUnderCursor: protected ASTVisitor
FunctionDefinitionAST *_functionDefinition;
public:
FunctionDefinitionUnderCursor(Control *control)
: ASTVisitor(control),
FunctionDefinitionUnderCursor(TranslationUnit *translationUnit)
: ASTVisitor(translationUnit),
_line(0), _column(0)
{ }
......@@ -427,8 +427,9 @@ class ProcessDeclarators: protected ASTVisitor
bool _visitFunctionDeclarator;
public:
ProcessDeclarators(Control *control)
: ASTVisitor(control), _visitFunctionDeclarator(true)
ProcessDeclarators(TranslationUnit *translationUnit)
: ASTVisitor(translationUnit),
_visitFunctionDeclarator(true)
{ }
QList<DeclaratorIdAST *> operator()(FunctionDefinitionAST *ast)
......@@ -2030,14 +2031,13 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
doc->check();
}
Control *control = doc->control();
TranslationUnit *translationUnit = doc->translationUnit();
AST *ast = translationUnit->ast();
FunctionDefinitionUnderCursor functionDefinitionUnderCursor(control);
FunctionDefinitionUnderCursor functionDefinitionUnderCursor(translationUnit);
FunctionDefinitionAST *currentFunctionDefinition = functionDefinitionUnderCursor(ast, source.line, source.column);
FindUses useTable(control);
FindUses useTable(translationUnit);
useTable(currentFunctionDefinition);
SemanticInfo semanticInfo;
......
......@@ -54,7 +54,9 @@ class ASTPath: public ASTVisitor
public:
ASTPath(Document::Ptr doc)
: ASTVisitor(doc->control()), _doc(doc), _line(0), _column(0) {}
: ASTVisitor(doc->translationUnit()),
_doc(doc), _line(0), _column(0)
{}
QList<AST *> operator()(const QTextCursor &cursor)
{
......
......@@ -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)
{ }
......
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