1 #include <boost/foreach.hpp>
3 #include <core/assert.hh>
4 #include "scope-builder-visitor.hh"
9 ScopeBuilderVisitor::ScopeBuilderVisitor()
14 ScopeBuilderVisitor::~ScopeBuilderVisitor()
19 ScopeBuilderVisitor::visit(File
& node
)
21 node
.scope
= new Scope();
22 node
.scope
->setParent(parent_
);
25 parent_
= node
.scope
->parent();
29 ScopeBuilderVisitor::visit(Function
& node
)
35 FunctionType
*ftype
= new FunctionType
;
36 ftype
->returnType
= node
.returnType
;
37 ftype
->argsType
= new std::vector
<Type
*> ();
38 BOOST_FOREACH (VarDecl
* varDecl
, *node
.args
)
39 ftype
->argsType
->push_back(varDecl
->type
);
41 Symbol
* symbol
= new Symbol
;
42 symbol
->name
= node
.name
;
44 symbol
->address
= new MemoryAddress
;
45 parent_
->addSymbol(symbol
);
47 node
.scope
= new Scope
;
48 node
.scope
->setParent(parent_
);
50 BOOST_FOREACH (VarDecl
* varDecl
, *node
.args
)
55 symbol
->name
= varDecl
->name
;
56 symbol
->type
= varDecl
->type
;
57 symbol
->address
= new MemoryAddress
;
58 node
.scope
->addSymbol(symbol
);
62 node
.block
->accept(*this);
63 parent_
= node
.scope
->parent();
67 ScopeBuilderVisitor::visit(Block
& node
)
70 node
.scope
= new Scope();
71 node
.scope
->setParent(parent_
);
74 /// @todo fill the scope with the declarated variables
75 assert(node
.varDecls
);
76 BOOST_FOREACH (VarDecl
* varDecl
, (*node
.varDecls
))
78 Symbol
* symbol
= new Symbol
;
81 symbol
->name
= varDecl
->name
;
82 symbol
->type
= varDecl
->type
;
83 symbol
->address
= new MemoryAddress
;
84 node
.scope
->addSymbol(symbol
);
88 parent_
= node
.scope
->parent();