From e7218bd26a2fe05c44cb444e0df1a4ba1d90853c Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Fri, 3 Apr 2015 16:20:11 +0200
Subject: [PATCH] preprocessor: take care of extra exos in observation_trends

---
 ComputingTasks.cc | 23 +++++++++++++++++++++++
 ComputingTasks.hh |  1 +
 2 files changed, 24 insertions(+)

diff --git a/ComputingTasks.cc b/ComputingTasks.cc
index 4b7b7c7e..9acdc06a 100644
--- a/ComputingTasks.cc
+++ b/ComputingTasks.cc
@@ -1181,6 +1181,29 @@ ObservationTrendsStatement::ObservationTrendsStatement(const trend_elements_t &t
 {
 }
 
+Statement *
+ObservationTrendsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table)
+{
+  SymbolTable *new_symbol_table =  dynamic_datatree.getSymbolTable();
+  map<string, expr_t> new_trend_elements;
+  try
+    {
+      for (map<string, expr_t>::const_iterator it = trend_elements.begin();
+             it != trend_elements.end(); it++)
+        {
+          new_symbol_table->getID(it->first);
+          new_trend_elements[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table);
+        }
+    }
+  catch (...)
+    {
+      cerr << "ERROR: A variable in the observation_trends statement was not found in the symbol table" << endl
+           << "       This likely means that you have declared a varexo that is not used in the model" << endl;
+      exit(EXIT_FAILURE);
+    }
+  return new ObservationTrendsStatement(new_trend_elements, *new_symbol_table);
+}
+
 void
 ObservationTrendsStatement::writeOutput(ostream &output, const string &basename) const
 {
diff --git a/ComputingTasks.hh b/ComputingTasks.hh
index 968fd5d9..3a4df94b 100644
--- a/ComputingTasks.hh
+++ b/ComputingTasks.hh
@@ -222,6 +222,7 @@ public:
   ObservationTrendsStatement(const trend_elements_t &trend_elements_arg,
                              const SymbolTable &symbol_table_arg);
   virtual void writeOutput(ostream &output, const string &basename) const;
+  virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table);
 };
 
 class OsrParamsStatement : public Statement
-- 
GitLab