diff -r bc90dd4bbf4f -r f86d5d6bb04e util/symtable.cc --- a/util/symtable.cc Fri Dec 26 10:09:27 2014 +0000 +++ b/util/symtable.cc Fri Dec 26 12:43:13 2014 +0000 @@ -47,7 +47,7 @@ /* clear all entries... */ template -void symtable_c::reset(void) { +void symtable_c::clear(void) { _base.clear(); } @@ -142,25 +142,47 @@ template -typename symtable_c::iterator symtable_c::end(void) {return _base.end();} +int symtable_c::count(const char *identifier_str) {return _base.count(identifier_str)+((inner_scope == NULL)?0:inner_scope->count(identifier_str));} +template +int symtable_c::count(const std::string identifier_str) {return _base.count(identifier_str)+((inner_scope == NULL)?0:inner_scope->count(identifier_str));} + + +// in the operator[] we delegate to find(), since that method will also search in the inner scopes! +template +typename symtable_c::value_t symtable_c::operator[] (const char *identifier_str) {return find(identifier_str)->second;} +template +typename symtable_c::value_t symtable_c::operator[] (const std::string identifier_str) {return find(identifier_str)->second;} + + +template +typename symtable_c::iterator symtable_c::end (void) {return _base.end ();} + +template +typename symtable_c::iterator symtable_c::begin(void) {return _base.begin();} /* returns end() if not found! */ template -typename symtable_c::iterator symtable_c::find(const char *identifier_str) { - if (inner_scope != NULL) { - iterator i = inner_scope->find(identifier_str); - if (i != inner_scope->end()) // NOTE: must use the end() value of the inner scope! - /* found in the lower level */ - return i; - } - +typename symtable_c::iterator symtable_c::find(const char *identifier_str) { + iterator i; + if ((inner_scope != NULL) && ((i = inner_scope->find(identifier_str)) != inner_scope->end())) // NOTE: must use the end() value of the inner scope! + return i; // found in the lower level /* if no lower level, or not found in lower level... */ return _base.find(identifier_str); } template -typename symtable_c::iterator symtable_c::find(const symbol_c *symbol) { +typename symtable_c::iterator symtable_c::find(const std::string identifier_str) { + iterator i; + if ((inner_scope != NULL) && ((i = inner_scope->find(identifier_str)) != inner_scope->end())) // NOTE: must use the end() value of the inner scope! + return i; // found in the lower level + /* if no lower level, or not found in lower level... */ + return _base.find(identifier_str); +} + + +template +typename symtable_c::iterator symtable_c::find(const symbol_c *symbol) { const token_c *name = dynamic_cast(symbol); if (name == NULL) ERROR;