template<class ElemType> int StringAssocTable<ElemType>::addElement (const char* _name, ElemType *_meu, Position& _pos) { if (finalized) { assert (!"StringAssocTable: Cannot add new elements after the configuration was finalized."); return (NO_MAPPING); } StringAssocMap::iterator it = find(_name); if (it == end() || !strictCheck) // new name { int id = nextId++; if (it==end()) insert(StringAssocMap::value_type(_name, id)); else it->second = id; _meu->setNameAndPosition (_name, _pos); elements.evector->push_back (_meu); return (id); } else // name is already in the table and strictCheck is set { haveErrors += 1; ElemType *meu = (*elements.evector)[it->second]; fprintf(stderr, "Error %d (%d, %d): Identifier '%s' has been defined before at (%d,%d)\n", haveErrors, _pos.Line(), _pos.Column(), _name, meu->getPosition().Line(), meu->getPosition().Column() ); return (it->second); } }
template<class ElemType> int StringAssocTable<ElemType>::getMappingForName(const char* _name, Position& _pos) { StringAssocMap::iterator it = find(_name); if (it == end()) // new name { haveErrors += 1; fprintf(stderr, "Error %d (%d, %d): Identifier '%s' is used but was not defined.\n", haveErrors, _pos.Line(), _pos.Column(), _name); return (NO_MAPPING); } else // name is already in the table { return (it->second); } }