diff --git a/ParsingDriver.cc b/ParsingDriver.cc index e551078b..c556220f 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -139,9 +139,9 @@ ParsingDriver::declare_symbol(const string *name, SymbolType type, const string mod_file->symbol_table.addSymbol(*name, type); else if (tex_name == NULL) - mod_file->symbol_table.createTexNameAndAddSymbolWithLongName(*name, type, *long_name); + mod_file->symbol_table.addSymbol(*name, type, "", *long_name); else if (long_name == NULL) - mod_file->symbol_table.addSymbol(*name, type, *tex_name); + mod_file->symbol_table.addSymbol(*name, type, *tex_name, ""); else mod_file->symbol_table.addSymbol(*name, type, *tex_name, *long_name); } diff --git a/SymbolTable.cc b/SymbolTable.cc index d9404d71..1c8652e5 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -52,49 +52,37 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na throw AlreadyDeclaredException(name, false); } + string final_tex_name = tex_name; + if (final_tex_name.empty()) + { + final_tex_name = name; + size_t pos = 0; + while ((pos = final_tex_name.find('_', pos)) != string::npos) + { + final_tex_name.insert(pos, "\\"); + pos += 2; + } + } + + string final_long_name = long_name; + if (final_long_name.empty()) + final_long_name = name; + int id = size++; symbol_table[name] = id; type_table.push_back(type); name_table.push_back(name); - tex_name_table.push_back(tex_name); - long_name_table.push_back(long_name); + tex_name_table.push_back(final_tex_name); + long_name_table.push_back(final_long_name); return id; } -int -SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_name) throw (AlreadyDeclaredException, FrozenException) -{ - return addSymbol(name, type, tex_name, name); -} - int SymbolTable::addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException) { - string tex_name; - return addSymbol(name, type, construct_tex_name(name, tex_name)); -} - -int -SymbolTable::createTexNameAndAddSymbolWithLongName(const string &name, SymbolType type, const string &long_name) throw (AlreadyDeclaredException, FrozenException) -{ - string tex_name; - return addSymbol(name, type, construct_tex_name(name, tex_name), long_name); -} - -string & -SymbolTable::construct_tex_name(const string &name, string &tex_name) -{ - // Construct "tex_name" by prepending an antislash to all underscores in "name" - tex_name = name; - size_t pos = 0; - while ((pos = tex_name.find('_', pos)) != string::npos) - { - tex_name.insert(pos, "\\"); - pos += 2; - } - return tex_name; + return addSymbol(name, type, "", ""); } void diff --git a/SymbolTable.hh b/SymbolTable.hh index e078f267..49c20855 100644 --- a/SymbolTable.hh +++ b/SymbolTable.hh @@ -185,18 +185,9 @@ public: //! Add a symbol /*! Returns the symbol ID */ int addSymbol(const string &name, SymbolType type, const string &tex_name, const string &long_name) throw (AlreadyDeclaredException, FrozenException); - //! Add a symbol without its long name (will be equal to its name) - /*! Returns the symbol ID */ - int addSymbol(const string &name, SymbolType type, const string &tex_name) throw (AlreadyDeclaredException, FrozenException); //! Add a symbol without its TeX name (will be equal to its name) /*! Returns the symbol ID */ int addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException); - //! Tmp addSymbol function that creates a tex_name and declares a symbol - //! when the name and long_name are passed - /*! Returns the symbol ID */ - int createTexNameAndAddSymbolWithLongName(const string &name, SymbolType type, const string &long_name) throw (AlreadyDeclaredException, FrozenException); - //! Create a tex_name based on the variable name - string &construct_tex_name(const string &name, string &tex_name); //! Adds an auxiliary variable for endogenous with lead >= 2 /*! \param[in] index Used to construct the variable name