From 7c884bcae26ce66f6f5e7373e891eec37ce9382a Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 12 Sep 2017 14:01:25 +0200 Subject: [PATCH] preprocessor: remove size filed in Symbol Table class. closes #1380 --- SymbolTable.cc | 14 +++++++------- SymbolTable.hh | 15 ++++++--------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/SymbolTable.cc b/SymbolTable.cc index 7a2a3da4..dca0ea8f 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -38,7 +38,7 @@ AuxVarInfo::AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id_arg { } -SymbolTable::SymbolTable() : frozen(false), size(0) +SymbolTable::SymbolTable() : frozen(false) { } @@ -78,7 +78,7 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na else non_long_name_partition_exists = true; - int id = size++; + int id = symbol_table.size(); symbol_table[name] = id; type_table.push_back(type); @@ -110,7 +110,7 @@ SymbolTable::freeze() throw (FrozenException) frozen = true; - for (int i = 0; i < size; i++) + for (int i = 0; i < symbol_table.size(); i++) { int tsi; switch (getType(i)) @@ -156,7 +156,7 @@ SymbolTable::changeType(int id, SymbolType newtype) throw (UnknownSymbolIDExcept if (frozen) throw FrozenException(); - if (id < 0 || id >= size) + if (id < 0 || id > symbol_table.size()) throw UnknownSymbolIDException(id); type_table[id] = newtype; @@ -732,7 +732,7 @@ SymbolTable::getAuxiliaryVarsExprNode(int symb_id) const throw (SearchFailedExce void SymbolTable::markPredetermined(int symb_id) throw (UnknownSymbolIDException, FrozenException) { - if (symb_id < 0 || symb_id >= size) + if (symb_id < 0 || symb_id > symbol_table.size()) throw UnknownSymbolIDException(symb_id); if (frozen) throw FrozenException(); @@ -745,7 +745,7 @@ SymbolTable::markPredetermined(int symb_id) throw (UnknownSymbolIDException, Fro bool SymbolTable::isPredetermined(int symb_id) const throw (UnknownSymbolIDException) { - if (symb_id < 0 || symb_id >= size) + if (symb_id < 0 || symb_id > symbol_table.size()) throw UnknownSymbolIDException(symb_id); return (predetermined_variables.find(symb_id) != predetermined_variables.end()); @@ -760,7 +760,7 @@ SymbolTable::predeterminedNbr() const void SymbolTable::addObservedVariable(int symb_id) throw (UnknownSymbolIDException) { - if (symb_id < 0 || symb_id >= size) + if (symb_id < 0 || symb_id > symbol_table.size()) throw UnknownSymbolIDException(symb_id); assert(getType(symb_id) == eEndogenous); diff --git a/SymbolTable.hh b/SymbolTable.hh index fb9a54dd..20a7d573 100644 --- a/SymbolTable.hh +++ b/SymbolTable.hh @@ -111,9 +111,6 @@ private: //! Has method freeze() been called? bool frozen; - //! Number of symbols contained in the table - int size; - typedef map symbol_table_type; //! Maps strings to symbol IDs symbol_table_type symbol_table; @@ -375,7 +372,7 @@ SymbolTable::exists(const string &name) const inline string SymbolTable::getName(int id) const throw (UnknownSymbolIDException) { - if (id < 0 || id >= size) + if (id < 0 || id > symbol_table.size()) throw UnknownSymbolIDException(id); else return name_table[id]; @@ -384,7 +381,7 @@ SymbolTable::getName(int id) const throw (UnknownSymbolIDException) inline string SymbolTable::getTeXName(int id) const throw (UnknownSymbolIDException) { - if (id < 0 || id >= size) + if (id < 0 || id > symbol_table.size()) throw UnknownSymbolIDException(id); else return tex_name_table[id]; @@ -393,7 +390,7 @@ SymbolTable::getTeXName(int id) const throw (UnknownSymbolIDException) inline string SymbolTable::getLongName(int id) const throw (UnknownSymbolIDException) { - if (id < 0 || id >= size) + if (id < 0 || id > symbol_table.size()) throw UnknownSymbolIDException(id); else return long_name_table[id]; @@ -402,7 +399,7 @@ SymbolTable::getLongName(int id) const throw (UnknownSymbolIDException) inline SymbolType SymbolTable::getType(int id) const throw (UnknownSymbolIDException) { - if (id < 0 || id >= size) + if (id < 0 || id > symbol_table.size()) throw UnknownSymbolIDException(id); else return type_table[id]; @@ -430,7 +427,7 @@ SymbolTable::getTypeSpecificID(int id) const throw (UnknownSymbolIDException, No if (!frozen) throw NotYetFrozenException(); - if (id < 0 || id >= size) + if (id < 0 || id > symbol_table.size()) throw UnknownSymbolIDException(id); return type_specific_ids[id]; @@ -481,7 +478,7 @@ SymbolTable::param_nbr() const throw (NotYetFrozenException) inline int SymbolTable::maxID() { - return (size-1); + return symbol_table.size() - 1; } inline int