From 256efa87969d977ea0c76d0e3fa01e4a06aadda5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien.villemot@ens.fr>
Date: Wed, 14 Apr 2010 15:46:49 +0200
Subject: [PATCH] Preprocessor: check that variables in shocks block, in
 variance/covariance elements, are exogenous

---
 preprocessor/ParsingDriver.cc | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc
index 9e890aa039..4198b2d758 100644
--- a/preprocessor/ParsingDriver.cc
+++ b/preprocessor/ParsingDriver.cc
@@ -487,6 +487,10 @@ void
 ParsingDriver::add_stderr_shock(string *var, NodeID value)
 {
   check_symbol_existence(*var);
+
+  if (mod_file->symbol_table.getType(*var) != eExogenous)
+    error("shocks: stderr can only be set for an exogenous variable");
+
   if (var_shocks.find(*var) != var_shocks.end()
       || std_shocks.find(*var) != std_shocks.end())
     error("shocks: variance or stderr of shock on " + *var + " declared twice");
@@ -500,6 +504,10 @@ void
 ParsingDriver::add_var_shock(string *var, NodeID value)
 {
   check_symbol_existence(*var);
+
+  if (mod_file->symbol_table.getType(*var) != eExogenous)
+    error("shocks: variance can only be set for an exogenous variable");
+
   if (var_shocks.find(*var) != var_shocks.end()
       || std_shocks.find(*var) != std_shocks.end())
     error("shocks: variance or stderr of shock on " + *var + " declared twice");
@@ -515,6 +523,10 @@ ParsingDriver::add_covar_shock(string *var1, string *var2, NodeID value)
   check_symbol_existence(*var1);
   check_symbol_existence(*var2);
 
+  if (mod_file->symbol_table.getType(*var1) != eExogenous
+      || mod_file->symbol_table.getType(*var2) != eExogenous)
+    error("shocks: covariance can only be set for exogenous variables");
+
   pair<string, string> key(*var1, *var2), key_inv(*var2, *var1);
 
   if (covar_shocks.find(key) != covar_shocks.end()
@@ -536,6 +548,10 @@ ParsingDriver::add_correl_shock(string *var1, string *var2, NodeID value)
   check_symbol_existence(*var1);
   check_symbol_existence(*var2);
 
+  if (mod_file->symbol_table.getType(*var1) != eExogenous
+      || mod_file->symbol_table.getType(*var2) != eExogenous)
+    error("shocks: correlation can only be set for exogenous variables");
+
   pair<string, string> key(*var1, *var2), key_inv(*var2, *var1);
 
   if (covar_shocks.find(key) != covar_shocks.end()
-- 
GitLab