From 76007cb7dbbca74f38d22b3f0dadcd2dff6b91c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien.villemot@ens.fr>
Date: Mon, 30 Jul 2012 17:01:20 +0200
Subject: [PATCH] Amend the workaround for ticket #35, so that
 shocks+endval+simul can looped over (cherry picked from commit
 5657dc8228d8583fe48fef5724f5ae606d325bfa)

---
 preprocessor/ComputingTasks.cc          | 3 +++
 preprocessor/NumericalInitialization.cc | 4 ++--
 preprocessor/Shocks.cc                  | 4 ++--
 preprocessor/Statement.cc               | 2 +-
 preprocessor/Statement.hh               | 8 +++++---
 5 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc
index d4ff1708c7..a3b260fe28 100644
--- a/preprocessor/ComputingTasks.cc
+++ b/preprocessor/ComputingTasks.cc
@@ -95,6 +95,9 @@ void
 SimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
 {
   mod_file_struct.simul_present = true;
+
+  // The following is necessary to allow shocks+endval+simul in a loop
+  mod_file_struct.shocks_present_but_simul_not_yet = false;
 }
 
 void
diff --git a/preprocessor/NumericalInitialization.cc b/preprocessor/NumericalInitialization.cc
index 63d1d73ae0..98327d6638 100644
--- a/preprocessor/NumericalInitialization.cc
+++ b/preprocessor/NumericalInitialization.cc
@@ -150,9 +150,9 @@ EndValStatement::EndValStatement(const init_values_t &init_values_arg,
 void
 EndValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
 {
-  if (mod_file_struct.shocks_present)
+  if (mod_file_struct.shocks_present_but_simul_not_yet)
     {
-      cerr << "ERROR: Putting a \"shocks\" block before an \"endval\" block is not permitted. Please swap the two blocks. This limitation will be removed in the next major release of Dynare." << endl;
+      cerr << "ERROR: Putting a \"shocks\" block before an \"endval\" block is not permitted. Please swap the two blocks. This limitation will be removed in a future release of Dynare." << endl;
       exit(EXIT_FAILURE);
     }
 }
diff --git a/preprocessor/Shocks.cc b/preprocessor/Shocks.cc
index 949ff5f198..3536053e18 100644
--- a/preprocessor/Shocks.cc
+++ b/preprocessor/Shocks.cc
@@ -196,7 +196,7 @@ void
 ShocksStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
 {
   // Workaround for trac ticket #35
-  mod_file_struct.shocks_present = true;
+  mod_file_struct.shocks_present_but_simul_not_yet = true;
 
   // Determine if there is a calibrated measurement error
   for (var_and_std_shocks_t::const_iterator it = var_shocks.begin();
@@ -245,7 +245,7 @@ void
 MShocksStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
 {
   // Workaround for trac ticket #35
-  mod_file_struct.shocks_present = true;
+  mod_file_struct.shocks_present_but_simul_not_yet = true;
 }
 
 ConditionalForecastPathsStatement::ConditionalForecastPathsStatement(const AbstractShocksStatement::det_shocks_t &paths_arg, const SymbolTable &symbol_table_arg) :
diff --git a/preprocessor/Statement.cc b/preprocessor/Statement.cc
index 4c890baffc..48abb3a984 100644
--- a/preprocessor/Statement.cc
+++ b/preprocessor/Statement.cc
@@ -37,7 +37,7 @@ ModFileStructure::ModFileStructure() :
   identification_present(false),
   estimation_analytic_derivation(false),
   partial_information(false),
-  shocks_present(false),
+  shocks_present_but_simul_not_yet(false),
   histval_present(false),
   k_order_solver(false),
   calibrated_measurement_errors(false),
diff --git a/preprocessor/Statement.hh b/preprocessor/Statement.hh
index 3847d3cccd..1c5c008299 100644
--- a/preprocessor/Statement.hh
+++ b/preprocessor/Statement.hh
@@ -69,9 +69,11 @@ public:
   bool estimation_analytic_derivation;
   //! Whether the option partial_information is given to stoch_simul/estimation/osr/ramsey_policy
   bool partial_information;
-  //! Whether a shocks or mshocks block is present
-  /*! Used for the workaround for trac ticket #35 */
-  bool shocks_present;
+  //! Whether a shocks or mshocks block has been parsed and no simul command yet run
+  /*! Used for the workaround for trac ticket #35. When a simul command is
+      seen, this flag is cleared in order to allow a sequence
+      shocks+endval+simul in a loop */
+  bool shocks_present_but_simul_not_yet;
   //! Whether a histval bloc is present
   /*! Used for the workaround for trac ticket #157 */
   bool histval_present;
-- 
GitLab