From 7d1a467aa30427afeac638975a80fc4df58ba1d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 2 Mar 2020 17:09:09 +0100
Subject: [PATCH] Transform predetermined variables before computing original
 model leads/lags
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is necessary to correctly compute those original model leads/lags. In
particular, this is needed for correct interaction with “histval”.

Closes: #47
---
 src/ModFile.cc | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/ModFile.cc b/src/ModFile.cc
index 4b225a1f..a59a8ab0 100644
--- a/src/ModFile.cc
+++ b/src/ModFile.cc
@@ -386,6 +386,8 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, bool
      — except substituting out variables which we know are constant (they
        appear in an equation of the form: X = constant)
      — except adl operators which we always want expanded
+     — except predetermined variables (which must be handled before the call to
+       setLeadsLagsOrig(), see preprocessor#47)
      — except diff operators with a lead which have been expanded by
        DataTree:AddDiff()
   */
@@ -393,6 +395,8 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, bool
   dynamic_model.includeExcludeEquations(include_eqs, false);
   dynamic_model.simplifyEquations();
   dynamic_model.substituteAdl();
+  if (symbol_table.predeterminedNbr() > 0)
+    dynamic_model.transformPredeterminedVariables();
   dynamic_model.setLeadsLagsOrig();
   original_model = dynamic_model;
   dynamic_model.expandEqTags();
@@ -501,9 +505,6 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, bool
 
   dynamic_model.addEquationsForVar();
 
-  if (symbol_table.predeterminedNbr() > 0)
-    dynamic_model.transformPredeterminedVariables();
-
   // Create auxiliary vars for Expectation operator
   dynamic_model.substituteExpectation(mod_file_struct.partial_information);
 
-- 
GitLab