Preprocessor: no longer crashes when some dynamic variables appear only in
unused model local variables (closes #101)time-shift
parent
45ebd1b3fb
commit
3068fbda8f
|
@ -1143,11 +1143,18 @@ ModelTree::compileTemporaryTerms(ostream &code_file, unsigned int &instruction_n
|
||||||
void
|
void
|
||||||
ModelTree::writeModelLocalVariables(ostream &output, ExprNodeOutputType output_type) const
|
ModelTree::writeModelLocalVariables(ostream &output, ExprNodeOutputType output_type) const
|
||||||
{
|
{
|
||||||
for (map<int, expr_t>::const_iterator it = local_variables_table.begin();
|
/* Collect all model local variables appearing in equations, and print only
|
||||||
it != local_variables_table.end(); it++)
|
them. Printing unused model local variables can lead to a crash (see
|
||||||
|
ticket #101). */
|
||||||
|
set<int> used_local_vars;
|
||||||
|
for (size_t i = 0; i < equations.size(); i++)
|
||||||
|
equations[i]->collectModelLocalVariables(used_local_vars);
|
||||||
|
|
||||||
|
for (set<int>::const_iterator it = used_local_vars.begin();
|
||||||
|
it != used_local_vars.end(); ++it)
|
||||||
{
|
{
|
||||||
int id = it->first;
|
int id = *it;
|
||||||
expr_t value = it->second;
|
expr_t value = local_variables_table.find(id)->second;
|
||||||
|
|
||||||
if (IS_C(output_type))
|
if (IS_C(output_type))
|
||||||
output << "double ";
|
output << "double ";
|
||||||
|
|
Loading…
Reference in New Issue