2 #include <boost/format.hpp>
4 #include <ozulis/compiler.hh>
5 #include <ozulis/core/assert.hh>
8 template class std::map
<std::string
, ozulis::ast::SymbolPtr
>;
9 template class std::map
<std::string
, ozulis::ast::TypePtr
>;
29 Scope::findSymbol(const std::string
& name
) const
31 symbols_t::const_iterator it
= symbols_
.find(name
);
32 if (it
== symbols_
.end())
33 return parent
? parent
->findSymbol(name
) : SymbolPtr(0);
38 Scope::addSymbol(SymbolPtr symbol
)
41 assert(!symbol
->name
.empty());
43 assert(symbol
->address
);
45 /* Check that the symbol is undefined */
46 if (symbols_
.find(symbol
->name
) != symbols_
.end())
47 Compiler::instance().error((boost::format(
48 _("multiple definition of the variable %1%")) %
51 symbols_
[symbol
->name
] = symbol
;
53 /* make the address */
54 if (symbol
->address
->nodeType
== MemoryAddress::nodeTypeId())
55 reinterpret_cast<MemoryAddress
*>(symbol
->address
.ptr())->address
=
56 prefix
+ symbol
->name
;
57 if (symbol
->address
->nodeType
== RegisterAddress::nodeTypeId())
58 reinterpret_cast<RegisterAddress
*>(symbol
->address
.ptr())->address
=
59 prefix
+ symbol
->name
;
63 Scope::findType(const std::string
& name
) const
65 types_t::const_iterator it
= types_
.find(name
);
66 if (it
== types_
.end())
67 return parent
? parent
->findType(name
) : TypePtr();
72 Scope::addType(const std::string
& name
, TypePtr type
)
75 assert(!name
.empty());
77 /* Check that the type is undefined */
78 if (types_
.find(name
) != types_
.end())
79 Compiler::instance().error((boost::format(
80 _("multiple definition of the type %1%")) % name
).str());
89 ss
<< "$scope$" << nextId_
++;