everything is broken, but this is the good way ;-)
[ozulis.git] / src / ast / scope.cc
blobba29990d376583584ce8328016b3fb1daa8fc820
1 #include <core/assert.hh>
2 #include "scope.hh"
4 template class std::map<std::string, ast::Symbol>;
6 namespace ast
8 Scope::Scope()
9 : symbols_(),
10 parent_(0)
14 Symbol *
15 Scope::findSymbol(const std::string & name) const
17 symbols_t::const_iterator it = symbols_.find(name);
18 if (it == symbols_.end())
19 return parent_ ? parent_->findSymbol(name) : 0;
20 return it->second;
23 bool
24 Scope::addSymbol(Symbol * symbol)
26 assert(symbol);
27 assert(!symbol->name.empty());
28 assert(symbol->type);
29 assert(symbol->address);
30 if (symbols_.find(symbol->name) != symbols_.end())
31 assert_msg(false, "multiple definition of the same variable");
32 symbols_[symbol->name] = symbol;
33 return true;