Commit e4916a1d authored by Houtan Bastani's avatar Houtan Bastani

preprocessor: display a summary of preprocessor warnings at the end of a Dynare run

parent c60de03e
This diff is collapsed.
This diff is collapsed.
......@@ -371,7 +371,7 @@ ConfigFile::addConfFileElement(bool inNode, bool inCluster, member_nodes_t membe
}
void
ConfigFile::checkPass() const
ConfigFile::checkPass(WarningConsolidation &warnings) const
{
if (!parallel && !parallel_test)
return;
......@@ -389,9 +389,9 @@ ConfigFile::checkPass() const
#if !defined(_WIN32) && !defined(__CYGWIN32__)
//For Linux/Mac, check that cpuNbr starts at 0
if (it->second->minCpuNbr != 0)
cerr << "WARNING: On Unix-based operating systems, you cannot specify the CPU that is used" << endl
<< " in parallel processing. This will be adjusted for you such that the same" << endl
<< " number of CPUs are used." << endl;
warnings << "WARNING: On Unix-based operating systems, you cannot specify the CPU that is "
<< "used in parallel processing. This will be adjusted for you such that the "
<< "same number of CPUs are used." << endl;
#endif
if (!it->second->computerName.compare("localhost")) // We are working locally
{
......
/*
* Copyright (C) 2010 Dynare Team
* Copyright (C) 2010-2012 Dynare Team
*
* This file is part of Dynare.
*
......@@ -23,6 +23,8 @@
#include <map>
#include <vector>
#include "WarningConsolidation.hh"
using namespace std;
typedef map<string, double> member_nodes_t;
......@@ -90,7 +92,7 @@ public:
//! Parse config file
void getConfigFileInfo(const string &parallel_config_file);
//! Check Pass
void checkPass() const;
void checkPass(WarningConsolidation &warnings) const;
//! Check Pass
void transformPass();
//! Create options_.parallel structure, write options
......
/*
* Copyright (C) 2008-2011 Dynare Team
* Copyright (C) 2008-2012 Dynare Team
*
* This file is part of Dynare.
*
......@@ -43,7 +43,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tm
// Run checking pass
mod_file->checkPass();
config_file.checkPass();
config_file.checkPass(mod_file->warnings);
// Perform transformations on the model (creation of auxiliary vars and equations)
mod_file->transformPass();
......
......@@ -51,7 +51,9 @@ dynare_m_SOURCES = \
ExternalFunctionsTable.cc \
ExternalFunctionsTable.hh \
SteadyStateModel.hh \
SteadyStateModel.cc
SteadyStateModel.cc \
WarningConsolidation.hh \
WarningConsolidation.cc
# The -I. is for <FlexLexer.h>
dynare_m_CPPFLAGS = $(BOOST_CPPFLAGS) -I.
......
......@@ -80,7 +80,8 @@ ModFile::evalAllExpressions(bool warn_uninit)
&& global_eval_context.find(id) == global_eval_context.end())
{
if (warn_uninit)
cerr << "WARNING: can't find a numeric initial value for " << symbol_table.getName(id) << ", using zero" << endl;
warnings << "WARNING: Can't find a numeric initial value for "
<< symbol_table.getName(id) << ", using zero" << endl;
global_eval_context[id] = 0;
}
}
......@@ -103,7 +104,7 @@ ModFile::checkPass()
{
for (vector<Statement *>::iterator it = statements.begin();
it != statements.end(); it++)
(*it)->checkPass(mod_file_struct);
(*it)->checkPass(mod_file_struct, warnings);
// Check the steady state block
steady_state_model.checkPass(mod_file_struct.ramsey_policy_present);
......@@ -192,8 +193,9 @@ ModFile::checkPass()
exit(EXIT_FAILURE);
}
else
cerr << "WARNING: When estimating a DSGE-Var, declaring dsge_prior_weight as a parameter is deprecated. "
<< "The preferred method is to do this via the dsge_var option in the estimation statement." << endl;
warnings << "WARNING: When estimating a DSGE-Var, declaring dsge_prior_weight as a "
<< "parameter is deprecated. The preferred method is to do this via "
<< "the dsge_var option in the estimation statement." << endl;
if (mod_file_struct.dsge_var_estimated || !mod_file_struct.dsge_var_calibrated.empty())
{
......@@ -617,9 +619,12 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool console,
config_file.writeEndParallel(mOutputFile);
mOutputFile << endl << endl
<< "disp(['Total computing time : ' dynsec2hms(toc) ]);" << endl
<< "diary off" << endl;
mOutputFile << endl << endl
<< "disp(['Total computing time : ' dynsec2hms(toc) ]);" << endl;
warnings.writeOutput(mOutputFile);
mOutputFile << "diary off" << endl;
mOutputFile.close();
......
/*
* Copyright (C) 2006-2010 Dynare Team
* Copyright (C) 2006-2012 Dynare Team
*
* This file is part of Dynare.
*
......@@ -34,6 +34,7 @@ using namespace std;
#include "Statement.hh"
#include "ExternalFunctionsTable.hh"
#include "ConfigFile.hh"
#include "WarningConsolidation.hh"
//! The abstract representation of a "mod" file
class ModFile
......@@ -84,6 +85,8 @@ public:
//! Stores the original number of equations in the model_block
int ramsey_policy_orig_eqn_nbr;
//! Warnings Encountered
WarningConsolidation warnings;
private:
//! List of statements
vector<Statement *> statements;
......
......@@ -19,6 +19,7 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include "NumericalInitialization.hh"
......@@ -33,7 +34,7 @@ InitParamStatement::InitParamStatement(int symb_id_arg,
}
void
InitParamStatement::checkPass(ModFileStructure &mod_file_struct)
InitParamStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{
if (symbol_table.getName(symb_id) == "dsge_prior_weight")
mod_file_struct.dsge_prior_weight_initialized = true;
......@@ -147,7 +148,7 @@ EndValStatement::EndValStatement(const init_values_t &init_values_arg,
}
void
EndValStatement::checkPass(ModFileStructure &mod_file_struct)
EndValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{
if (mod_file_struct.shocks_present)
{
......@@ -177,7 +178,7 @@ HistValStatement::HistValStatement(const hist_values_t &hist_values_arg,
}
void
HistValStatement::checkPass(ModFileStructure &mod_file_struct)
HistValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{
mod_file_struct.histval_present = true;
}
......@@ -298,7 +299,8 @@ SaveParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &ba
}
LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const string &filename,
const SymbolTable &symbol_table_arg) :
const SymbolTable &symbol_table_arg,
WarningConsolidation &warnings) :
symbol_table(symbol_table_arg)
{
cout << "Reading " << filename << "." << endl;
......@@ -325,7 +327,7 @@ LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const strin
}
catch (SymbolTable::UnknownSymbolNameException &e)
{
cerr << "WARNING: Unknown symbol " << symb_name << " in " << filename << endl;
warnings << "WARNING: Unknown symbol " << symb_name << " in " << filename << endl;
}
}
f.close();
......
/*
* Copyright (C) 2003-2011 Dynare Team
* Copyright (C) 2003-2012 Dynare Team
*
* This file is part of Dynare.
*
......@@ -39,7 +39,7 @@ private:
public:
InitParamStatement(int symb_id_arg, const expr_t param_value_arg,
const SymbolTable &symbol_table_arg);
virtual void checkPass(ModFileStructure &mod_file_struct);
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
virtual void writeOutput(ostream &output, const string &basename) const;
//! Fill eval context with parameter value
void fillEvalContext(eval_context_t &eval_context) const;
......@@ -81,7 +81,7 @@ public:
EndValStatement(const init_values_t &init_values_arg,
const SymbolTable &symbol_table_arg);
//! Workaround for trac ticket #35
virtual void checkPass(ModFileStructure &mod_file_struct);
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
virtual void writeOutput(ostream &output, const string &basename) const;
};
......@@ -101,7 +101,7 @@ public:
HistValStatement(const hist_values_t &hist_values_arg,
const SymbolTable &symbol_table_arg);
//! Workaround for trac ticket #157
virtual void checkPass(ModFileStructure &mod_file_struct);
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
virtual void writeOutput(ostream &output, const string &basename) const;
};
......@@ -147,7 +147,8 @@ private:
map<int, string> content;
public:
LoadParamsAndSteadyStateStatement(const string &filename,
const SymbolTable &symbol_table_arg);
const SymbolTable &symbol_table_arg,
WarningConsolidation &warnings);
virtual void writeOutput(ostream &output, const string &basename) const;
//! Fill eval context with parameters/variables values
void fillEvalContext(eval_context_t &eval_context) const;
......
/*
* Copyright (C) 2003-2011 Dynare Team
* Copyright (C) 2003-2012 Dynare Team
*
* This file is part of Dynare.
*
......@@ -27,6 +27,7 @@
#include "ParsingDriver.hh"
#include "Statement.hh"
#include "ExprNode.hh"
#include "WarningConsolidation.hh"
bool
ParsingDriver::symbol_exists_and_is_not_modfile_local_or_external_function(const char *s)
......@@ -117,7 +118,7 @@ ParsingDriver::error(const string &m)
void
ParsingDriver::warning(const string &m)
{
cerr << "WARNING: " << location << ": " << m << endl;
mod_file->warnings << "WARNING: " << location << ": " << m << endl;
}
void
......@@ -1541,7 +1542,7 @@ ParsingDriver::run_dynasave(string *filename)
void
ParsingDriver::run_load_params_and_steady_state(string *filename)
{
mod_file->addStatement(new LoadParamsAndSteadyStateStatement(*filename, mod_file->symbol_table));
mod_file->addStatement(new LoadParamsAndSteadyStateStatement(*filename, mod_file->symbol_table, mod_file->warnings));
delete filename;
}
......
......@@ -60,7 +60,7 @@ Statement::~Statement()
}
void
Statement::checkPass(ModFileStructure &mod_file_struct)
Statement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{
}
......
......@@ -27,6 +27,7 @@ using namespace std;
#include <map>
#include "SymbolList.hh"
#include "WarningConsolidation.hh"
class ModFileStructure
{
......@@ -109,7 +110,7 @@ class Statement
public:
virtual ~Statement();
//! Do some internal check, and fill the ModFileStructure class
virtual void checkPass(ModFileStructure &mod_file_struct);
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
virtual void computingPass();
//! Write Matlab output code
/*!
......
/*
* Copyright (C) 2012 Dynare Team
*
* This file is part of Dynare.
*
* Dynare is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dynare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/
using namespace std;
#include "WarningConsolidation.hh"
#include <ostream>
WarningConsolidation&
operator<< (WarningConsolidation& wcc, const string &warning)
{
cerr << warning;
wcc.addWarning(warning);
return wcc;
};
WarningConsolidation&
operator<< (WarningConsolidation& wcc, const Dynare::location& loc)
{
stringstream ostr;
Dynare::position last = loc.end - 1;
ostr << loc.begin;
if (last.filename
&& (!loc.begin.filename
|| *loc.begin.filename != *last.filename))
ostr << '-' << last;
else if (loc.begin.line != last.line)
ostr << '-' << last.line << '.' << last.column;
else if (loc.begin.column != last.column)
ostr << '-' << last.column;
cerr << ostr.str();
wcc.addWarning(ostr.str());
return wcc;
};
WarningConsolidation&
operator<< (WarningConsolidation& wcc, ostream& (*pf) (ostream&))
{
cerr << pf;
wcc.addWarning(pf);
return wcc;
}
void
WarningConsolidation::writeOutput(ostream &output) const
{
if (warnings.str().empty())
return;
output << "disp([char(10) 'Dynare Preprocessor Warning(s) Encountered:']);" << endl;
bool writedisp = true;
string warningsstr = warnings.str();
for (size_t i = 0; i < warningsstr.length(); i++)
{
if (writedisp)
{
output << "disp(' ";
writedisp = false;
}
if (warningsstr[i] != '\n')
output << warningsstr[i];
else
{
output << "');" << endl;
if (i+1 < warningsstr.length())
writedisp = true;
}
}
}
/*
* Copyright (C) 2012 Dynare Team
*
* This file is part of Dynare.
*
* Dynare is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dynare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _WARNINGCONSOLIDATION_HH
#define _WARNINGCONSOLIDATION_HH
using namespace std;
#include <sstream>
#include <string>
#include "location.hh"
//! Stores Warnings issued by the Preprocessor
class WarningConsolidation
{
private:
stringstream warnings;
public:
WarningConsolidation() { };
~WarningConsolidation() { };
//! Add A Warning to the StringStream
friend WarningConsolidation& operator<< (WarningConsolidation& wcc, const string &warning);
friend WarningConsolidation& operator<< (WarningConsolidation& wcc, const Dynare::location &loc);
friend WarningConsolidation& operator<< (WarningConsolidation& wcc, ostream& (*pf) (ostream&));
inline void addWarning(const string w) { warnings << w; };
inline void addWarning(ostream& (*pf) (ostream&)) { warnings << pf; };
//! Write Warnings to m file
void writeOutput(ostream &output) const;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment