preprocessor: take care of expressions_tree and steady_state_model
parent
6905456cb3
commit
48014c3787
26
DataTree.cc
26
DataTree.cc
|
@ -50,6 +50,32 @@ DataTree::~DataTree()
|
||||||
delete *it;
|
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
|
void
|
||||||
DataTree::reindexExternalFunctions(SymbolTable &orig_symbol_table)
|
DataTree::reindexExternalFunctions(SymbolTable &orig_symbol_table)
|
||||||
{
|
{
|
||||||
|
|
|
@ -240,6 +240,8 @@ public:
|
||||||
void writePowerDeriv(ostream &output, bool use_dll) const;
|
void writePowerDeriv(ostream &output, bool use_dll) const;
|
||||||
//! reindex external functions
|
//! reindex external functions
|
||||||
void reindexExternalFunctions(SymbolTable &orig_symbol_table);
|
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
|
//! Thrown when trying to access an unknown variable by deriv_id
|
||||||
class UnknownDerivIDException
|
class UnknownDerivIDException
|
||||||
{
|
{
|
||||||
|
|
|
@ -315,6 +315,13 @@ ModFile::transformPass(bool nostrict)
|
||||||
symbol_table.rmExo(unusedExo);
|
symbol_table.rmExo(unusedExo);
|
||||||
dynamic_model.reindex(orig_symbol_table);
|
dynamic_model.reindex(orig_symbol_table);
|
||||||
dynamic_model.reindexStaticOnlyEquations(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;
|
vector<Statement *> orig_statements = statements;
|
||||||
statements.clear();
|
statements.clear();
|
||||||
for (vector<Statement *>::iterator it = orig_statements.begin(); it != orig_statements.end(); it++)
|
for (vector<Statement *>::iterator it = orig_statements.begin(); it != orig_statements.end(); it++)
|
||||||
|
|
17
ModelTree.cc
17
ModelTree.cc
|
@ -1416,30 +1416,15 @@ ModelTree::addAuxEquation(expr_t eq)
|
||||||
void
|
void
|
||||||
ModelTree::reindex(SymbolTable &orig_symbol_table)
|
ModelTree::reindex(SymbolTable &orig_symbol_table)
|
||||||
{
|
{
|
||||||
variable_node_map.clear();
|
DataTree::reindex(orig_symbol_table);
|
||||||
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();
|
|
||||||
|
|
||||||
reindexEquations(orig_symbol_table);
|
reindexEquations(orig_symbol_table);
|
||||||
reindexTrendSymbolsMap(orig_symbol_table);
|
reindexTrendSymbolsMap(orig_symbol_table);
|
||||||
reindexNonstationarySymbolsMap(orig_symbol_table);
|
reindexNonstationarySymbolsMap(orig_symbol_table);
|
||||||
reindexExternalFunctions(orig_symbol_table);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ModelTree::reindexEquations(SymbolTable &orig_symbol_table)
|
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;
|
vector<BinaryOpNode *>eqbak = equations;
|
||||||
equations.clear();
|
equations.clear();
|
||||||
for (size_t i = 0; i < eqbak.size(); i++)
|
for (size_t i = 0; i < eqbak.size(); i++)
|
||||||
|
|
|
@ -503,6 +503,25 @@ SymbolTable::rmExo(set<int> &unused) throw (FrozenException)
|
||||||
assert(size == symbol_table.size());
|
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
|
int
|
||||||
SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag) throw (FrozenException)
|
SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag) throw (FrozenException)
|
||||||
{
|
{
|
||||||
|
|
|
@ -305,6 +305,8 @@ public:
|
||||||
set <int> getOrigEndogenous() const;
|
set <int> getOrigEndogenous() const;
|
||||||
//! Remove exogenous variables contained in the set
|
//! Remove exogenous variables contained in the set
|
||||||
void rmExo(set<int> &unused) throw (FrozenException);
|
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
|
inline bool
|
||||||
|
|
Loading…
Reference in New Issue