Commit cee87ece authored by Roberto Raggi's avatar Roberto Raggi

Added a way to bind TranslationUnitAST nodes.

parent 93bbd32c
...@@ -68,8 +68,6 @@ Bind::Bind(TranslationUnit *unit) ...@@ -68,8 +68,6 @@ Bind::Bind(TranslationUnit *unit)
_name(0), _name(0),
_declaratorId(0) _declaratorId(0)
{ {
if (unit->ast())
translationUnit(unit->ast()->asTranslationUnit());
} }
Scope *Bind::currentScope() const Scope *Bind::currentScope() const
...@@ -84,6 +82,13 @@ Scope *Bind::switchScope(Scope *scope) ...@@ -84,6 +82,13 @@ Scope *Bind::switchScope(Scope *scope)
return previousScope; return previousScope;
} }
void Bind::operator()(TranslationUnitAST *ast, Namespace *globalNamespace)
{
Scope *previousScope = switchScope(globalNamespace);
translationUnit(ast);
(void) switchScope(previousScope);
}
void Bind::statement(StatementAST *ast) void Bind::statement(StatementAST *ast)
{ {
accept(ast); accept(ast);
...@@ -703,12 +708,9 @@ void Bind::translationUnit(TranslationUnitAST *ast) ...@@ -703,12 +708,9 @@ void Bind::translationUnit(TranslationUnitAST *ast)
if (! ast) if (! ast)
return; return;
Namespace *globalNamespace = control()->newNamespace(0, 0);
Scope *previousScope = switchScope(globalNamespace);
for (DeclarationListAST *it = ast->declaration_list; it; it = it->next) { for (DeclarationListAST *it = ast->declaration_list; it; it = it->next) {
this->declaration(it->value); this->declaration(it->value);
} }
(void) switchScope(previousScope);
} }
bool Bind::visit(ObjCProtocolRefsAST *ast) bool Bind::visit(ObjCProtocolRefsAST *ast)
......
...@@ -59,6 +59,13 @@ class CPLUSPLUS_EXPORT Bind: protected ASTVisitor ...@@ -59,6 +59,13 @@ class CPLUSPLUS_EXPORT Bind: protected ASTVisitor
public: public:
Bind(TranslationUnit *unit); Bind(TranslationUnit *unit);
void operator()(TranslationUnitAST *ast, Namespace *globalNamespace);
protected:
using ASTVisitor::translationUnit;
static int visibilityForAccessSpecifier(int tokenKind);
typedef FullySpecifiedType ExpressionTy; typedef FullySpecifiedType ExpressionTy;
ExpressionTy expression(ExpressionAST *ast); ExpressionTy expression(ExpressionAST *ast);
...@@ -75,11 +82,6 @@ public: ...@@ -75,11 +82,6 @@ public:
Scope *currentScope() const; Scope *currentScope() const;
Scope *switchScope(Scope *scope); Scope *switchScope(Scope *scope);
protected:
using ASTVisitor::translationUnit;
static int visibilityForAccessSpecifier(int tokenKind);
const Name *objCSelectorArgument(ObjCSelectorArgumentAST *ast, bool *hasArg); const Name *objCSelectorArgument(ObjCSelectorArgumentAST *ast, bool *hasArg);
void attribute(AttributeAST *ast); void attribute(AttributeAST *ast);
FullySpecifiedType declarator(DeclaratorAST *ast, const FullySpecifiedType &init, DeclaratorIdAST **declaratorId); FullySpecifiedType declarator(DeclaratorAST *ast, const FullySpecifiedType &init, DeclaratorIdAST **declaratorId);
......
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