From 64364499611c9eb24eeeae6077dbf73b893bf75d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 6 Nov 2017 15:21:11 +0100 Subject: [PATCH] preprocessor: JSON: place local variables in one list. Closes #1495 --- ModelTree.cc | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/ModelTree.cc b/ModelTree.cc index cb3523a6..aea4f6b7 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1453,35 +1453,31 @@ ModelTree::writeJsonModelLocalVariables(ostream &output, deriv_node_temp_terms_t for (size_t i = 0; i < equations.size(); i++) equations[i]->collectVariables(eModelLocalVariable, used_local_vars); - output << "\"external_functions_model_local_variables\": ["; - for (set::const_iterator it = used_local_vars.begin(); - it != used_local_vars.end(); ++it) - { - vector efout; - expr_t value = local_variables_table.find(*it)->second; - value->writeJsonExternalFunctionOutput(efout, tt, tef_terms); - for (vector::const_iterator it1 = efout.begin(); it1 != efout.end(); it1++) - { - if (it1 != efout.begin()) - output << ", "; - output << *it1; - } - } - output << "]" - << ", \"model_local_variables\": ["; + output << "\"model_local_variables\": ["; bool printed = false; for (vector::const_iterator it = local_variables_vector.begin(); it != local_variables_vector.end(); it++) if (used_local_vars.find(*it) != used_local_vars.end()) { - int id = *it; - expr_t value = local_variables_table.find(id)->second; - if (printed) output << ", "; else printed = true; + int id = *it; + vector efout; + expr_t value = local_variables_table.find(id)->second; + value->writeJsonExternalFunctionOutput(efout, tt, tef_terms); + for (vector::const_iterator it1 = efout.begin(); it1 != efout.end(); it1++) + { + if (it1 != efout.begin()) + output << ", "; + output << *it1; + } + + if (!efout.empty()) + output << ", "; + /* We append underscores to avoid name clashes with "g1" or "oo_" (see also VariableNode::writeOutput) */ output << "{\"variable\": \"" << symbol_table.getName(id) << "__\""