From 99c05089099d13f9af4f16d42d5162f3025391a9 Mon Sep 17 00:00:00 2001
From: Ferhat Mihoubi <ferhat.mihoubi@univ-evry.fr>
Date: Fri, 14 Oct 2011 14:35:32 +0200
Subject: [PATCH] Displays an error message when the model contains pound
 expressions and 'bytecode' or 'block' options are present

---
 preprocessor/DynamicModel.cc | 13 +++++++++++++
 preprocessor/DynamicModel.hh |  1 +
 preprocessor/ModFile.cc      |  7 +++++++
 3 files changed, 21 insertions(+)

diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc
index e80d0a126..d4d371568 100644
--- a/preprocessor/DynamicModel.cc
+++ b/preprocessor/DynamicModel.cc
@@ -4175,3 +4175,16 @@ DynamicModel::fillEvalContext(eval_context_t &eval_context) const
        it != trendVars.end(); it++)
     eval_context[*it] = 2;  //not <= 0 bc of log, not 1 bc of powers
 }
+
+bool 
+DynamicModel::isModelLocalVariableUsed() const
+{
+  set<int> used_local_vars;
+  size_t i = 0;
+  while (i < equations.size() && used_local_vars.size() == 0)
+    {
+      equations[i]->collectModelLocalVariables(used_local_vars);
+      i++;
+    }
+  return used_local_vars.size() > 0;
+}
diff --git a/preprocessor/DynamicModel.hh b/preprocessor/DynamicModel.hh
index 673ed862f..d95deae89 100644
--- a/preprocessor/DynamicModel.hh
+++ b/preprocessor/DynamicModel.hh
@@ -476,6 +476,7 @@ public:
     else
       return (-1);
   };
+  bool isModelLocalVariableUsed() const;
 };
 
 #endif
diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc
index c28f7d35a..e9bce2212 100644
--- a/preprocessor/ModFile.cc
+++ b/preprocessor/ModFile.cc
@@ -163,6 +163,13 @@ ModFile::checkPass()
       exit(EXIT_FAILURE);
     }
 
+  if (block || byte_code)
+    if (dynamic_model.isModelLocalVariableUsed())
+      {
+        cerr << "ERROR: In 'model' block, 'block' or 'bytecode' options are not yet compatible with pound expressions" << endl;
+        exit(EXIT_FAILURE);
+      }
+
   if ((stochastic_statement_present || mod_file_struct.check_present || mod_file_struct.steady_present) && no_static)
     {
       cerr << "ERROR: no_static option is incompatible with stoch_simul, estimation, osr, ramsey_policy, discretionary_policy, steady and check commands" << endl;
-- 
GitLab