Commit 11c04c9b authored by Houtan Bastani's avatar Houtan Bastani
Browse files

preprocessor: streamline addSymbol

parent 6a3e0da5
...@@ -139,9 +139,9 @@ ParsingDriver::declare_symbol(const string *name, SymbolType type, const string ...@@ -139,9 +139,9 @@ ParsingDriver::declare_symbol(const string *name, SymbolType type, const string
mod_file->symbol_table.addSymbol(*name, type); mod_file->symbol_table.addSymbol(*name, type);
else else
if (tex_name == NULL) 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) else if (long_name == NULL)
mod_file->symbol_table.addSymbol(*name, type, *tex_name); mod_file->symbol_table.addSymbol(*name, type, *tex_name, "");
else else
mod_file->symbol_table.addSymbol(*name, type, *tex_name, *long_name); mod_file->symbol_table.addSymbol(*name, type, *tex_name, *long_name);
} }
......
...@@ -52,49 +52,37 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na ...@@ -52,49 +52,37 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na
throw AlreadyDeclaredException(name, false); 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++; int id = size++;
symbol_table[name] = id; symbol_table[name] = id;
type_table.push_back(type); type_table.push_back(type);
name_table.push_back(name); name_table.push_back(name);
tex_name_table.push_back(tex_name); tex_name_table.push_back(final_tex_name);
long_name_table.push_back(long_name); long_name_table.push_back(final_long_name);
return id; 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 int
SymbolTable::addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException) SymbolTable::addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException)
{ {
string tex_name; return addSymbol(name, type, "", "");
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;
} }
void void
......
...@@ -185,18 +185,9 @@ public: ...@@ -185,18 +185,9 @@ public:
//! Add a symbol //! Add a symbol
/*! Returns the symbol ID */ /*! Returns the symbol ID */
int addSymbol(const string &name, SymbolType type, const string &tex_name, const string &long_name) throw (AlreadyDeclaredException, FrozenException); 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) //! Add a symbol without its TeX name (will be equal to its name)
/*! Returns the symbol ID */ /*! Returns the symbol ID */
int addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException); 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 //! Adds an auxiliary variable for endogenous with lead >= 2
/*! /*!
\param[in] index Used to construct the variable name \param[in] index Used to construct the variable name
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment