Commit 6a9f2c47 authored by sebastien's avatar sebastien
Browse files

v4 preprocessor:

* renamed TmpSymbolTable to SymbolList (with some clean up by the way)
* removed unused mechanism of alternative variable names in tmp_var_list
* OptionsList: fixed memory leak and bug in clear()


git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1785 ac1d8469-bf42-47a9-8791-bf33cf982152
parent f63c2c09
......@@ -138,9 +138,9 @@ SimulSparseStatement::writeOutput(ostream &output, const string &basename) const
}
}
StochSimulStatement::StochSimulStatement(const TmpSymbolTable &tmp_symbol_table_arg,
StochSimulStatement::StochSimulStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg) :
tmp_symbol_table(tmp_symbol_table_arg),
symbol_list(symbol_list_arg),
options_list(options_list_arg)
{
}
......@@ -160,13 +160,13 @@ void
StochSimulStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output);
symbol_list.writeOutput("var_list_", output);
output << "info = stoch_simul(var_list_);\n";
}
RamseyPolicyStatement::RamseyPolicyStatement(const TmpSymbolTable &tmp_symbol_table_arg,
RamseyPolicyStatement::RamseyPolicyStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg) :
tmp_symbol_table(tmp_symbol_table_arg),
symbol_list(symbol_list_arg),
options_list(options_list_arg)
{
}
......@@ -188,13 +188,13 @@ void
RamseyPolicyStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output);
symbol_list.writeOutput("var_list_", output);
output << "ramsey_policy(var_list_);\n";
}
EstimationStatement::EstimationStatement(const TmpSymbolTable &tmp_symbol_table_arg,
EstimationStatement::EstimationStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg) :
tmp_symbol_table(tmp_symbol_table_arg),
symbol_list(symbol_list_arg),
options_list(options_list_arg)
{
}
......@@ -214,13 +214,13 @@ void
EstimationStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output);
symbol_list.writeOutput("var_list_", output);
output << "dynare_estimation(var_list_);\n";
}
PriorAnalysisStatement::PriorAnalysisStatement(const TmpSymbolTable &tmp_symbol_table_arg,
PriorAnalysisStatement::PriorAnalysisStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg) :
tmp_symbol_table(tmp_symbol_table_arg),
symbol_list(symbol_list_arg),
options_list(options_list_arg)
{
}
......@@ -229,13 +229,13 @@ void
PriorAnalysisStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output);
symbol_list.writeOutput("var_list_", output);
output << "prior_analysis(var_list_);\n";
}
PosteriorAnalysisStatement::PosteriorAnalysisStatement(const TmpSymbolTable &tmp_symbol_table_arg,
PosteriorAnalysisStatement::PosteriorAnalysisStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg) :
tmp_symbol_table(tmp_symbol_table_arg),
symbol_list(symbol_list_arg),
options_list(options_list_arg)
{
}
......@@ -244,7 +244,7 @@ void
PosteriorAnalysisStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output);
symbol_list.writeOutput("var_list_", output);
output << "posterior_analysis(var_list_);\n";
}
......@@ -260,9 +260,9 @@ DynareSensitivityStatement::writeOutput(ostream &output, const string &basename)
output << "dynare_sensitivity(options_gsa);" << endl;
}
RplotStatement::RplotStatement(const TmpSymbolTable &tmp_symbol_table_arg,
RplotStatement::RplotStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg) :
tmp_symbol_table(tmp_symbol_table_arg),
symbol_list(symbol_list_arg),
options_list(options_list_arg)
{
}
......@@ -271,19 +271,19 @@ void
RplotStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output);
symbol_list.writeOutput("var_list_", output);
output << "rplot(var_list_);\n";
}
UnitRootVarsStatement::UnitRootVarsStatement(const TmpSymbolTable &tmp_symbol_table_arg) :
tmp_symbol_table(tmp_symbol_table_arg)
UnitRootVarsStatement::UnitRootVarsStatement(const SymbolList &symbol_list_arg) :
symbol_list(symbol_list_arg)
{
}
void
UnitRootVarsStatement::writeOutput(ostream &output, const string &basename) const
{
tmp_symbol_table.writeOutput("options_.unit_root_vars", output);
symbol_list.writeOutput("options_.unit_root_vars", output);
}
PeriodsStatement::PeriodsStatement(int periods_arg) : periods(periods_arg)
......@@ -334,15 +334,15 @@ DsampleStatement::writeOutput(ostream &output, const string &basename) const
output << "options_.dsample = [" << val1 << "; " << val2 << "];" << endl;
}
VarobsStatement::VarobsStatement(const TmpSymbolTable &tmp_symbol_table_arg) :
tmp_symbol_table(tmp_symbol_table_arg)
VarobsStatement::VarobsStatement(const SymbolList &symbol_list_arg) :
symbol_list(symbol_list_arg)
{
}
void
VarobsStatement::writeOutput(ostream &output, const string &basename) const
{
tmp_symbol_table.writeOutput("options_.varobs", output);
symbol_list.writeOutput("options_.varobs", output);
}
EstimatedParamsStatement::EstimatedParamsStatement(const vector<EstimationParams> &estim_params_list_arg,
......@@ -653,20 +653,20 @@ CalibStatement::writeOutput(ostream &output, const string &basename) const
output << "M_.Sigma_e=calib(calib_var_index,calib_targets,calib_weights," << covar << ",Sigma_e_);\n";
}
OsrParamsStatement::OsrParamsStatement(const TmpSymbolTable &tmp_symbol_table_arg) :
tmp_symbol_table(tmp_symbol_table_arg)
OsrParamsStatement::OsrParamsStatement(const SymbolList &symbol_list_arg) :
symbol_list(symbol_list_arg)
{
}
void
OsrParamsStatement::writeOutput(ostream &output, const string &basename) const
{
tmp_symbol_table.writeOutput("osr_params_", output);
symbol_list.writeOutput("osr_params_", output);
}
OsrStatement::OsrStatement(const TmpSymbolTable &tmp_symbol_table_arg,
OsrStatement::OsrStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg) :
tmp_symbol_table(tmp_symbol_table_arg),
symbol_list(symbol_list_arg),
options_list(options_list_arg)
{
}
......@@ -686,7 +686,7 @@ void
OsrStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output);
symbol_list.writeOutput("var_list_", output);
output << "osr(var_list_,osr_params_,obj_var_,optim_weights_);\n";
}
......@@ -733,9 +733,9 @@ OptimWeightsStatement::writeOutput(ostream &output, const string &basename) cons
}
}
DynaSaveStatement::DynaSaveStatement(const TmpSymbolTable &tmp_symbol_table_arg,
DynaSaveStatement::DynaSaveStatement(const SymbolList &symbol_list_arg,
const string &filename_arg, const string &ext_arg) :
tmp_symbol_table(tmp_symbol_table_arg),
symbol_list(symbol_list_arg),
filename(filename_arg),
ext(ext_arg)
{
......@@ -744,16 +744,16 @@ DynaSaveStatement::DynaSaveStatement(const TmpSymbolTable &tmp_symbol_table_arg,
void
DynaSaveStatement::writeOutput(ostream &output, const string &basename) const
{
tmp_symbol_table.writeOutput("var_list_", output);
symbol_list.writeOutput("var_list_", output);
output << "dynasave(" << filename;
if (ext.size() > 0)
output << "," << ext;
output << ",var_list_);\n";
}
DynaTypeStatement::DynaTypeStatement(const TmpSymbolTable &tmp_symbol_table_arg,
DynaTypeStatement::DynaTypeStatement(const SymbolList &symbol_list_arg,
const string &filename_arg, const string &ext_arg) :
tmp_symbol_table(tmp_symbol_table_arg),
symbol_list(symbol_list_arg),
filename(filename_arg),
ext(ext_arg)
{
......@@ -762,7 +762,7 @@ DynaTypeStatement::DynaTypeStatement(const TmpSymbolTable &tmp_symbol_table_arg,
void
DynaTypeStatement::writeOutput(ostream &output, const string &basename) const
{
tmp_symbol_table.writeOutput("var_list_", output);
symbol_list.writeOutput("var_list_", output);
output << "dynatype(" << filename;
if (ext.size() > 0)
output << "," << ext;
......
......@@ -665,17 +665,11 @@ stoch_simul_options : o_dr_algo
;
tmp_var_list : tmp_var_list NAME
{ driver.add_tmp_var($2); }
| tmp_var_list NAME EQUAL NAME
{ driver.add_tmp_var($2, $4); }
{ driver.add_in_symbol_list($2); }
| tmp_var_list COMMA NAME
{ driver.add_tmp_var($3); }
| tmp_var_list COMMA NAME EQUAL NAME
{ driver.add_tmp_var($3, $5); }
{ driver.add_in_symbol_list($3); }
| NAME
{ driver.add_tmp_var($1); }
| NAME EQUAL NAME
{ driver.add_tmp_var($1, $3); }
{ driver.add_in_symbol_list($1); }
;
signed_integer : PLUS INT_NUMBER
......@@ -1375,12 +1369,12 @@ o_gsa_threshold_redform : THRESHOLD_REDFORM EQUAL vec_int { driver.option_num("t
o_gsa_ksstat_redform : KSSTAT_REDFORM EQUAL number { driver.option_num("ksstat_redfrom", $3); };
o_gsa_alpha2_redform : ALPHA2_REDFORM EQUAL number { driver.option_num("alpha2_redform", $3); };
o_gsa_namendo : NAMENDO EQUAL '(' tmp_var_list ')' { driver.option_str_lst("namendo"); };
o_gsa_namlagendo : NAMLAGENDO EQUAL '(' tmp_var_list ')' { driver.option_str_lst("namlagendo"); };
o_gsa_namexo : NAMEXO EQUAL '(' tmp_var_list ')' { driver.option_str_lst("namexo"); };
o_gsa_namendo : NAMENDO EQUAL '(' tmp_var_list ')' { driver.option_symbol_list("namendo"); };
o_gsa_namlagendo : NAMLAGENDO EQUAL '(' tmp_var_list ')' { driver.option_symbol_list("namlagendo"); };
o_gsa_namexo : NAMEXO EQUAL '(' tmp_var_list ')' { driver.option_symbol_list("namexo"); };
o_gsa_rmse : RMSE EQUAL INT_NUMBER { driver.option_num("rmse", $3); };
o_gsa_lik_only : LIK_ONLY EQUAL INT_NUMBER { driver.option_num("lik_only", $3); };
o_gsa_var_rmse : VAR_RMSE EQUAL '(' tmp_var_list ')' { driver.option_str_lst("var_rmse"); };
o_gsa_var_rmse : VAR_RMSE EQUAL '(' tmp_var_list ')' { driver.option_symbol_list("var_rmse"); };
o_gsa_pfilt_rmse : PFILT_RMSE EQUAL number { driver.option_num("pfilt_rmse", $3); };
o_gsa_istart_rmse : ISTART_RMSE EQUAL INT_NUMBER { driver.option_num("istart_rmse", $3); };
o_gsa_alpha_rmse : ALPHA_RMSE EQUAL number { driver.option_num("alpha_rmse", $3); };
......
......@@ -23,7 +23,7 @@ COMMON_OBJ = \
Shocks.o \
SigmaeInitialization.o \
SymbolTable.o \
TmpSymbolTable.o \
SymbolList.o \
VariableTable.o \
ParsingDriver.o \
DataTree.o \
......
......@@ -65,7 +65,7 @@ ParsingDriver::parse(istream &in, bool debug)
{
mod_file = new ModFile();
tmp_symbol_table = new TmpSymbolTable(mod_file->symbol_table);
symbol_list.clear();
reset_data_tree();
......@@ -77,7 +77,6 @@ ParsingDriver::parse(istream &in, bool debug)
parser.parse();
delete lexer;
delete tmp_symbol_table;
return mod_file;
}
......@@ -655,19 +654,16 @@ ParsingDriver::option_str(const string &name_option, const string &opt)
}
void
ParsingDriver::option_str_lst(const string &name_option)
ParsingDriver::option_symbol_list(const string &name_option)
{
if (options_list.string_list_options.find(name_option)
!= options_list.string_list_options.end())
if (options_list.symbol_list_options.find(name_option)
!= options_list.symbol_list_options.end())
error("option " + name_option + " declared twice");
options_list.string_list_options[name_option] = new TmpSymbolTable::TmpSymbolTable(*tmp_symbol_table);
tmp_symbol_table->clear();
options_list.symbol_list_options[name_option] = symbol_list;
symbol_list.clear();
}
void
ParsingDriver::linear()
{
......@@ -675,34 +671,24 @@ ParsingDriver::linear()
}
void
ParsingDriver::add_tmp_var(string *tmp_var1, string *tmp_var2)
{
check_symbol_existence(*tmp_var1);
check_symbol_existence(*tmp_var2);
tmp_symbol_table->AddTempSymbol(*tmp_var1, *tmp_var2);
delete tmp_var1;
delete tmp_var2;
}
void
ParsingDriver::add_tmp_var(string *tmp_var)
ParsingDriver::add_in_symbol_list(string *tmp_var)
{
check_symbol_existence(*tmp_var);
tmp_symbol_table->AddTempSymbol(*tmp_var);
symbol_list.addSymbol(*tmp_var);
delete tmp_var;
}
void ParsingDriver::rplot()
{
mod_file->addStatement(new RplotStatement(*tmp_symbol_table, options_list));
mod_file->addStatement(new RplotStatement(symbol_list, options_list));
options_list.clear();
tmp_symbol_table->clear();
symbol_list.clear();
}
void ParsingDriver::stoch_simul()
{
mod_file->addStatement(new StochSimulStatement(*tmp_symbol_table, options_list));
tmp_symbol_table->clear();
mod_file->addStatement(new StochSimulStatement(symbol_list, options_list));
symbol_list.clear();
options_list.clear();
}
......@@ -776,31 +762,31 @@ ParsingDriver::estimated_params_bounds()
void
ParsingDriver::set_unit_root_vars()
{
mod_file->addStatement(new UnitRootVarsStatement(*tmp_symbol_table));
tmp_symbol_table->clear();
mod_file->addStatement(new UnitRootVarsStatement(symbol_list));
symbol_list.clear();
}
void
ParsingDriver::run_estimation()
{
mod_file->addStatement(new EstimationStatement(*tmp_symbol_table, options_list));
tmp_symbol_table->clear();
mod_file->addStatement(new EstimationStatement(symbol_list, options_list));
symbol_list.clear();
options_list.clear();
}
void
ParsingDriver::run_prior_analysis()
{
mod_file->addStatement(new PriorAnalysisStatement(*tmp_symbol_table, options_list));
tmp_symbol_table->clear();
mod_file->addStatement(new PriorAnalysisStatement(symbol_list, options_list));
symbol_list.clear();
options_list.clear();
}
void
ParsingDriver::run_posterior_analysis()
{
mod_file->addStatement(new PosteriorAnalysisStatement(*tmp_symbol_table, options_list));
tmp_symbol_table->clear();
mod_file->addStatement(new PosteriorAnalysisStatement(symbol_list, options_list));
symbol_list.clear();
options_list.clear();
}
......@@ -842,8 +828,8 @@ ParsingDriver::optim_options_num(string *name, string *value)
void
ParsingDriver::set_varobs()
{
mod_file->addStatement(new VarobsStatement(*tmp_symbol_table));
tmp_symbol_table->clear();
mod_file->addStatement(new VarobsStatement(symbol_list));
symbol_list.clear();
}
void
......@@ -908,15 +894,15 @@ ParsingDriver::optim_weights()
void
ParsingDriver::set_osr_params()
{
mod_file->addStatement(new OsrParamsStatement(*tmp_symbol_table));
tmp_symbol_table->clear();
mod_file->addStatement(new OsrParamsStatement(symbol_list));
symbol_list.clear();
}
void
ParsingDriver::run_osr()
{
mod_file->addStatement(new OsrStatement(*tmp_symbol_table, options_list));
tmp_symbol_table->clear();
mod_file->addStatement(new OsrStatement(symbol_list, options_list));
symbol_list.clear();
options_list.clear();
}
......@@ -1002,8 +988,8 @@ ParsingDriver::run_calib(int covar)
void
ParsingDriver::run_dynatype(string *filename, string *ext)
{
mod_file->addStatement(new DynaTypeStatement(*tmp_symbol_table, *filename, *ext));
tmp_symbol_table->clear();
mod_file->addStatement(new DynaTypeStatement(symbol_list, *filename, *ext));
symbol_list.clear();
delete filename;
delete ext;
}
......@@ -1011,8 +997,8 @@ ParsingDriver::run_dynatype(string *filename, string *ext)
void
ParsingDriver::run_dynasave(string *filename, string *ext)
{
mod_file->addStatement(new DynaSaveStatement(*tmp_symbol_table, *filename, *ext));
tmp_symbol_table->clear();
mod_file->addStatement(new DynaSaveStatement(symbol_list, *filename, *ext));
symbol_list.clear();
delete filename;
delete ext;
}
......@@ -1056,8 +1042,8 @@ ParsingDriver::end_planner_objective(NodeID expr)
void
ParsingDriver::ramsey_policy()
{
mod_file->addStatement(new RamseyPolicyStatement(*tmp_symbol_table, options_list));
tmp_symbol_table->clear();
mod_file->addStatement(new RamseyPolicyStatement(symbol_list, options_list));
symbol_list.clear();
options_list.clear();
}
......
......@@ -68,9 +68,9 @@ OptionsList::writeOutput(ostream &output) const
it != string_options.end(); it++)
output << "options_." << it->first << " = '" << it->second << "';" << endl;
for(string_list_options_type::const_iterator it = string_list_options.begin();
it != string_list_options.end(); it++)
it->second->writeOutput("options_."+it->first,output);
for(symbol_list_options_type::const_iterator it = symbol_list_options.begin();
it != symbol_list_options.end(); it++)
it->second.writeOutput("options_." + it->first, output);
}
void
......@@ -91,9 +91,9 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const
it != string_options.end(); it++)
output << option_group << "." << it->first << " = '" << it->second << "';" << endl;
for(string_list_options_type::const_iterator it = string_list_options.begin();
it != string_list_options.end(); it++)
it->second->writeOutput(option_group+"."+it->first,output);
for(symbol_list_options_type::const_iterator it = symbol_list_options.begin();
it != symbol_list_options.end(); it++)
it->second.writeOutput(option_group + "." + it->first, output);
}
void
......@@ -102,4 +102,5 @@ OptionsList::clear()
num_options.clear();
paired_num_options.clear();
string_options.clear();
symbol_list_options.clear();
}
......@@ -17,53 +17,29 @@
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/
using namespace std;
#include "SymbolTable.hh"
#include "TmpSymbolTable.hh"
#include "SymbolList.hh"
#include "Interface.hh"
TmpSymbolTable::TmpSymbolTable(const SymbolTable &symbol_table_arg) :
symbol_table(symbol_table_arg)
{
}
TmpSymbolTable::~TmpSymbolTable()
{
}
void
TmpSymbolTable::AddTempSymbol(const string &symbol)
{
// FIXME: add check to verify that symbol exists in symbol_table
// FIXME: add check to verify that symbol doesn't yet exist in the present table
tmpsymboltable.push_back(symbol);
}
void
TmpSymbolTable::AddTempSymbol(const string &symbol1, const string &symbol2)
SymbolList::addSymbol(const string &symbol)
{
// FIXME: add checks to verify that symbol1 and symbol2 exist in symbol_table
// FIXME: add check to verify that symbol1 doesn't yet exist in the present table
tmpsymboltable.push_back(symbol1);
nameTable.push_back(symbol2);
symbols.push_back(symbol);
}
void
TmpSymbolTable::writeOutput(const string &varname, ostream &output) const
SymbolList::writeOutput(const string &varname, ostream &output) const
{
output << varname << "=[];" << endl;
for (vector<string>::const_iterator it = tmpsymboltable.begin();
it != tmpsymboltable.end(); it++)
for (vector<string>::const_iterator it = symbols.begin();
it != symbols.end(); it++)
{
output << varname << " = ";
output << interfaces::strvcat(varname, "'" + *it + "'") << ";" << endl;
output << varname << " = "
<< interfaces::strvcat(varname, "'" + *it + "'") << ";" << endl;
}
}
void
TmpSymbolTable::clear()
SymbolList::clear()
{
tmpsymboltable.clear();
nameTable.clear();
symbols.clear();
}
......@@ -22,7 +22,7 @@
#include <ostream>
#include "TmpSymbolTable.hh"
#include "SymbolList.hh"
#include "SymbolTable.hh"
#include "Statement.hh"
#include "ModelTree.hh"
......@@ -79,10 +79,10 @@ public:
class StochSimulStatement : public Statement
{
private:
const TmpSymbolTable tmp_symbol_table;
const SymbolList symbol_list;
const OptionsList options_list;
public:
StochSimulStatement(const TmpSymbolTable &tmp_symbol_table_arg,
StochSimulStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg);
virtual void checkPass(ModFileStructure &mod_file_struct);
virtual void writeOutput(ostream &output, const string &basename) const;
......@@ -91,10 +91,10 @@ public:
class RamseyPolicyStatement : public Statement
{
private:
const TmpSymbolTable tmp_symbol_table;
const SymbolList symbol_list;
const OptionsList options_list;
public:
RamseyPolicyStatement(const TmpSymbolTable &tmp_symbol_table_arg,
RamseyPolicyStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg);
virtual void checkPass(ModFileStructure &mod_file_struct);
virtual void writeOutput(ostream &output, const string &basename) const;
......@@ -103,10 +103,10 @@ public:
class RplotStatement : public Statement
{
private:
const TmpSymbolTable tmp_symbol_table;
const SymbolList symbol_list;
const OptionsList options_list;
public:
RplotStatement(const TmpSymbolTable &tmp_symbol_table_arg,
RplotStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg);
virtual void writeOutput(ostream &output, const string &basename) const;
};
......@@ -114,9 +114,9 @@ public:
class UnitRootVarsStatement : public Statement
{
private:
const TmpSymbolTable tmp_symbol_table;
const SymbolList symbol_list;
public:
UnitRootVarsStatement(const TmpSymbolTable &tmp_symbol_table_arg);
UnitRootVarsStatement(const SymbolList &symbol_list_arg);
virtual void writeOutput(ostream &output, const string &basename) const;
};
......@@ -160,10 +160,10 @@ public:
class EstimationStatement : public Statement
{
private:
const TmpSymbolTable tmp_symbol_table;
const SymbolList symbol_list;
const OptionsList options_list;
public:
EstimationStatement(const TmpSymbolTable &tmp_symbol_table_arg,
EstimationStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg);
virtual void checkPass(ModFileStructure &mod_file_struct);