From 1165c2608bab8ab94c5027e7143372ac55456df1 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 12:49:15 +0200 Subject: [PATCH] preprocessor: take care of exos in options statements --- ComputingTasks.cc | 83 +++++++++++++++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 4 +++ 2 files changed, 87 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 9d1a93b7..4955fa1c 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -3391,6 +3391,23 @@ OptionsStatement::OptionsStatement(const string &name_arg, { } +Statement * +OptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + new_symbol_table->getID(name); + } + catch (...) + { + cerr << "ERROR: A variable in the options 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 OptionsStatement(name, subsample_name, options_list); +} + void OptionsStatement::writeOutput(ostream &output, const string &basename) const { @@ -3419,6 +3436,23 @@ StdOptionsStatement::StdOptionsStatement(const string &name_arg, { } +Statement * +StdOptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(name); + } + catch (...) + { + cerr << "ERROR: A variable in the std_options 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 StdOptionsStatement(name, subsample_name, options_list, *new_symbol_table); +} + void StdOptionsStatement::writeOutput(ostream &output, const string &basename) const { @@ -3474,6 +3508,24 @@ CorrOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol } } +Statement * +CorrOptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(name); + new_symbol_table->getID(name1); + } + catch (...) + { + cerr << "ERROR: A variable in the corr_options 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 CorrOptionsStatement(name, name1, subsample_name, options_list, *new_symbol_table); +} + void CorrOptionsStatement::writeOutput(ostream &output, const string &basename) const { @@ -3521,6 +3573,37 @@ OptionsEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso } } +Statement * +OptionsEqualStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(to_name1); + if (!to_name2.empty()) + new_symbol_table->getID(to_name2); + + new_symbol_table->getID(from_name1); + if (!from_name2.empty()) + new_symbol_table->getID(from_name2); + } + catch (...) + { + cerr << "ERROR: A variable in the options equal 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 OptionsEqualStatement(to_declaration_type, + to_name1, + to_name2, + to_subsample_name, + from_declaration_type, + from_name1, + from_name2, + from_subsample_name, + *new_symbol_table); +} + void OptionsEqualStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index b6625e81..3d3f07f5 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -850,6 +850,7 @@ public: OptionsStatement(const string &name_arg, const string &subsample_name_arg, const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class StdOptionsStatement : public BasicOptionsStatement @@ -863,6 +864,7 @@ public: const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class CorrOptionsStatement : public BasicOptionsStatement @@ -878,6 +880,7 @@ public: virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class OptionsEqualStatement : public Statement @@ -905,6 +908,7 @@ public: void get_base_name(const SymbolType symb_type, string &lhs_field) const; virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ModelDiagnosticsStatement : public Statement