preprocessor: take care of expressions_tree and steady_state_model

issue#70
Houtan Bastani 2015-04-21 15:06:56 +02:00
parent 6905456cb3
commit 48014c3787
6 changed files with 57 additions and 16 deletions

View File

@ -50,6 +50,32 @@ DataTree::~DataTree()
delete *it;
}
void
DataTree::reindex(SymbolTable &orig_symbol_table)
{
variable_node_map.clear();
unary_op_node_map.clear();
binary_op_node_map.clear();
trinary_op_node_map.clear();
external_function_node_map.clear();
first_deriv_external_function_node_map.clear();
second_deriv_external_function_node_map.clear();
reindexExternalFunctions(orig_symbol_table);
reindexLocalVars(orig_symbol_table);
}
void
DataTree::reindexLocalVars(SymbolTable &orig_symbol_table)
{
map<int, expr_t> orig_local_variables_table = local_variables_table;
local_variables_table.clear();
for (map<int, expr_t>::const_iterator it = orig_local_variables_table.begin();
it != orig_local_variables_table.end(); it++)
AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)),
it->second->cloneDynamicReindex(*this, orig_symbol_table));
}
void
DataTree::reindexExternalFunctions(SymbolTable &orig_symbol_table)
{

View File

@ -240,6 +240,8 @@ public:
void writePowerDeriv(ostream &output, bool use_dll) const;
//! reindex external functions
void reindexExternalFunctions(SymbolTable &orig_symbol_table);
void reindex(SymbolTable &orig_symbol_table);
void reindexLocalVars(SymbolTable &orig_symbol_table);
//! Thrown when trying to access an unknown variable by deriv_id
class UnknownDerivIDException
{

View File

@ -315,6 +315,13 @@ ModFile::transformPass(bool nostrict)
symbol_table.rmExo(unusedExo);
dynamic_model.reindex(orig_symbol_table);
dynamic_model.reindexStaticOnlyEquations(orig_symbol_table);
SymbolTable *exp_tree_symbol_table = expressions_tree.getSymbolTable();
exp_tree_symbol_table->rmExo(unusedExo, orig_symbol_table);
SymbolTable *ssm_tree_symbol_table = steady_state_model.getSymbolTable();
ssm_tree_symbol_table->rmExo(unusedExo, orig_symbol_table);
vector<Statement *> orig_statements = statements;
statements.clear();
for (vector<Statement *>::iterator it = orig_statements.begin(); it != orig_statements.end(); it++)

View File

@ -1416,30 +1416,15 @@ ModelTree::addAuxEquation(expr_t eq)
void
ModelTree::reindex(SymbolTable &orig_symbol_table)
{
variable_node_map.clear();
unary_op_node_map.clear();
binary_op_node_map.clear();
trinary_op_node_map.clear();
external_function_node_map.clear();
first_deriv_external_function_node_map.clear();
second_deriv_external_function_node_map.clear();
DataTree::reindex(orig_symbol_table);
reindexEquations(orig_symbol_table);
reindexTrendSymbolsMap(orig_symbol_table);
reindexNonstationarySymbolsMap(orig_symbol_table);
reindexExternalFunctions(orig_symbol_table);
}
void
ModelTree::reindexEquations(SymbolTable &orig_symbol_table)
{
map<int, expr_t> orig_local_variables_table = local_variables_table;
local_variables_table.clear();
for (map<int, expr_t>::const_iterator it = orig_local_variables_table.begin();
it != orig_local_variables_table.end(); it++)
AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)),
it->second->cloneDynamicReindex(*this, orig_symbol_table));
vector<BinaryOpNode *>eqbak = equations;
equations.clear();
for (size_t i = 0; i < eqbak.size(); i++)

View File

@ -503,6 +503,25 @@ SymbolTable::rmExo(set<int> &unused) throw (FrozenException)
assert(size == symbol_table.size());
}
void
SymbolTable::rmExo(set<int> &unused, SymbolTable &orig_symbol_table) throw (FrozenException)
{
if (frozen)
throw FrozenException();
for (set<int>::const_iterator it = unused.begin(); it != unused.end(); it++)
try
{
string name = orig_symbol_table.getName(*it);
int symbid = getID(name);
cerr << "ERROR: " << name << "used in expression but not found in model block" << endl;
exit(EXIT_FAILURE);
}
catch (...)
{
}
}
int
SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag) throw (FrozenException)
{

View File

@ -305,6 +305,8 @@ public:
set <int> getOrigEndogenous() const;
//! Remove exogenous variables contained in the set
void rmExo(set<int> &unused) throw (FrozenException);
//! Remove exogenous variables contained in the set from the orig_symbol_table. If found, quit
void rmExo(set<int> &unused, SymbolTable &orig_symbol_table) throw (FrozenException);
};
inline bool