From d3e115194b551f318c0c036b5a115086c0891dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Fri, 19 Feb 2021 17:45:02 +0100 Subject: [PATCH] Fix output write_latex_original_model for model-local variables Those variables were substituted out by early substitution methods (which are also called on the original model, for an unknown reason). Closes: #65 --- src/DynamicModel.cc | 7 +++++++ src/ExprNode.cc | 12 +++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index b3a7d690..2cb2c108 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -5579,6 +5579,13 @@ DynamicModel::substituteLeadLagInternal(AuxVarType type, bool deterministic_mode void DynamicModel::substituteAdl() { + /* Contrary to other substitution methods, we do the substitution in MLV + definitions here, instead of doing it at the ExprNode method level, + because otherwise this would substitute MLV in the original model (see + #65). */ + for (auto &[id, definition] : local_variables_table) + definition = definition->substituteAdl(); + for (auto &equation : equations) equation = dynamic_cast<BinaryOpNode *>(equation->substituteAdl()); } diff --git a/src/ExprNode.cc b/src/ExprNode.cc index 5d4180ca..9df220c2 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2007-2020 Dynare Team + * Copyright © 2007-2021 Dynare Team * * This file is part of Dynare. * @@ -1541,9 +1541,8 @@ VariableNode::VarMaxLag(const set<expr_t> &lhs_lag_equiv) const expr_t VariableNode::substituteAdl() const { - if (get_type() == SymbolType::modelLocalVariable) - return datatree.getLocalVariable(symb_id)->substituteAdl(); - + /* Do not recurse into model-local variables definition, rather do it at the + DynamicModel method level (see the comment there) */ return const_cast<VariableNode *>(this); } @@ -1988,9 +1987,8 @@ VariableNode::getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const expr_t VariableNode::replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const { - if (get_type() == SymbolType::modelLocalVariable) - return datatree.getLocalVariable(symb_id)->replaceVarsInEquation(table); - + /* Do not recurse into model-local variables definition, because otherwise + this would substitute MLV in the original model (see #65). */ for (auto &it : table) if (it.first->symb_id == symb_id) return it.second; -- GitLab