Commit a64ec3b1 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Reorganization of warnings

 - at the end of the computation, don't display all preprocessor warnings but
   only their number
 - also display if there has been a MATLAB/Octave warning (counting their
   number does not seem feasible). Closes #181
 - add new "nowarn" option to disable all warnings. Closes #301
parent cacb0470
......@@ -687,6 +687,9 @@ line numbering directives.
Instructs Dynare to no create a logfile of this run in
@file{@var{FILENAME}.log}. The default is to create the logfile.
@item nowarn
Suppresses all warnings.
@item warn_uninit
Display a warning for each variable or parameter which is not
initialized. @xref{Parameter initialization}, or
......
......@@ -10,7 +10,7 @@ function warning_config()
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2008-2012 Dynare Team
% Copyright (C) 2008-2013 Dynare Team
%
% This file is part of Dynare.
%
......@@ -55,3 +55,5 @@ else
% interface to set seed of random number generators
warning('off', 'MATLAB:RandStream:ActivatingLegacyGenerators');
end
lastwarn('') % Reset lastwarn, used to determine later if a warning has been emitted
/*
* Copyright (C) 2003-2012 Dynare Team
* Copyright (C) 2003-2013 Dynare Team
*
* This file is part of Dynare.
*
......@@ -34,7 +34,7 @@ using namespace std;
Splitting main() in two parts was necessary because ParsingDriver.h and MacroDriver.h can't be
included simultaneously (because of Bison limitations).
*/
void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool no_log, bool warn_uninit, bool console,
void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console,
bool parallel, const string &parallel_config_file, const string &cluster_name, bool parallel_slave_open_mode,
bool parallel_test
#if defined(_WIN32) || defined(__CYGWIN32__)
......@@ -72,6 +72,7 @@ main(int argc, char **argv)
bool only_macro = false;
bool no_line_macro = false;
bool no_log = false;
bool no_warn = false;
bool warn_uninit = false;
bool console = false;
#if defined(_WIN32) || defined(__CYGWIN32__)
......@@ -113,6 +114,8 @@ main(int argc, char **argv)
no_tmp_terms = true;
else if (!strcmp(argv[arg], "nolog"))
no_log = true;
else if (!strcmp(argv[arg], "nowarn"))
no_warn = true;
else if (!strcmp(argv[arg], "warn_uninit"))
warn_uninit = true;
else if (!strcmp(argv[arg], "console"))
......@@ -209,7 +212,7 @@ main(int argc, char **argv)
return EXIT_SUCCESS;
// Do the rest
main2(macro_output, basename, debug, clear_all, no_tmp_terms, no_log, warn_uninit, console,
main2(macro_output, basename, debug, clear_all, no_tmp_terms, no_log, no_warn, warn_uninit, console,
parallel, parallel_config_file, cluster_name, parallel_slave_open_mode, parallel_test
#if defined(_WIN32) || defined(__CYGWIN32__)
, cygwin, msvc
......
/*
* Copyright (C) 2008-2012 Dynare Team
* Copyright (C) 2008-2013 Dynare Team
*
* This file is part of Dynare.
*
......@@ -26,7 +26,7 @@ using namespace std;
#include "ConfigFile.hh"
void
main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool no_log, bool warn_uninit, bool console,
main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console,
bool parallel, const string &parallel_config_file, const string &cluster_name, bool parallel_slave_open_mode,
bool parallel_test
#if defined(_WIN32) || defined(__CYGWIN32__)
......@@ -34,7 +34,9 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tm
#endif
)
{
ParsingDriver p;
WarningConsolidation warnings(no_warn);
ParsingDriver p(warnings);
// Do parsing and construct internal representation of mod file
ModFile *mod_file = p.parse(in, debug);
......@@ -43,7 +45,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tm
// Run checking pass
mod_file->checkPass();
config_file.checkPass(mod_file->warnings);
config_file.checkPass(warnings);
// Perform transformations on the model (creation of auxiliary vars and equations)
mod_file->transformPass();
......@@ -56,7 +58,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tm
mod_file->computingPass(no_tmp_terms);
// Write outputs
mod_file->writeOutputFiles(basename, clear_all, no_log, console, config_file
mod_file->writeOutputFiles(basename, clear_all, no_log, no_warn, console, config_file
#if defined(_WIN32) || defined(__CYGWIN32__)
, cygwin, msvc
#endif
......
......@@ -30,14 +30,16 @@
#include "ConfigFile.hh"
#include "ComputingTasks.hh"
ModFile::ModFile() : expressions_tree(symbol_table, num_constants, external_functions_table),
dynamic_model(symbol_table, num_constants, external_functions_table),
trend_dynamic_model(symbol_table, num_constants, external_functions_table),
ramsey_FOC_equations_dynamic_model(symbol_table, num_constants, external_functions_table),
static_model(symbol_table, num_constants, external_functions_table),
steady_state_model(symbol_table, num_constants, external_functions_table, static_model),
linear(false), block(false), byte_code(false), use_dll(false), no_static(false),
nonstationary_variables(false), transform_logpow(false), ramsey_policy_orig_eqn_nbr(0)
ModFile::ModFile(WarningConsolidation &warnings_arg)
: expressions_tree(symbol_table, num_constants, external_functions_table),
dynamic_model(symbol_table, num_constants, external_functions_table),
trend_dynamic_model(symbol_table, num_constants, external_functions_table),
ramsey_FOC_equations_dynamic_model(symbol_table, num_constants, external_functions_table),
static_model(symbol_table, num_constants, external_functions_table),
steady_state_model(symbol_table, num_constants, external_functions_table, static_model),
linear(false), block(false), byte_code(false), use_dll(false), no_static(false),
nonstationary_variables(false), transform_logpow(false), ramsey_policy_orig_eqn_nbr(0),
warnings(warnings_arg)
{
}
......@@ -426,7 +428,7 @@ ModFile::computingPass(bool no_tmp_terms)
}
void
ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, bool console, const ConfigFile &config_file
ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, bool no_warn, bool console, const ConfigFile &config_file
#if defined(_WIN32) || defined(__CYGWIN32__)
, bool cygwin, bool msvc
#endif
......@@ -458,6 +460,9 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b
<< "% Warning : this file is generated automatically by Dynare" << endl
<< "% from model file (.mod)" << endl << endl;
if (no_warn)
mOutputFile << "warning off" << endl; // This will be executed *after* function warning_config()
if (clear_all)
{
mOutputFile << "clear all" << endl
......@@ -637,7 +642,14 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b
mOutputFile << endl << endl
<< "disp(['Total computing time : ' dynsec2hms(toc) ]);" << endl;
warnings.writeOutput(mOutputFile);
if (!no_warn)
{
mOutputFile << "disp('Note: " << warnings.countWarnings() << " warning(s) encountered in the preprocessor')" << endl
<< "if ~isempty(lastwarn)" << endl
<< " disp('Note: warning(s) encountered in MATLAB/Octave code')" << endl
<< "end" << endl;
}
if (!no_log)
mOutputFile << "diary off" << endl;
......
/*
* Copyright (C) 2006-2012 Dynare Team
* Copyright (C) 2006-2013 Dynare Team
*
* This file is part of Dynare.
*
......@@ -40,7 +40,7 @@ using namespace std;
class ModFile
{
public:
ModFile();
ModFile(WarningConsolidation &warnings_arg);
~ModFile();
//! Symbol table
SymbolTable symbol_table;
......@@ -88,13 +88,13 @@ 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;
//! Structure of the mod file
ModFileStructure mod_file_struct;
//! Warnings Encountered
WarningConsolidation &warnings;
public:
//! Add a statement
......@@ -120,7 +120,7 @@ public:
\param cygwin Should the MEX command of use_dll be adapted for Cygwin?
\param msvc Should the MEX command of use_dll be adapted for MSVC?
*/
void writeOutputFiles(const string &basename, bool clear_all, bool no_log, bool console, const ConfigFile &config_file
void writeOutputFiles(const string &basename, bool clear_all, bool no_log, bool no_warn, bool console, const ConfigFile &config_file
#if defined(_WIN32) || defined(__CYGWIN32__)
, bool cygwin, bool msvc
#endif
......
......@@ -82,7 +82,7 @@ ParsingDriver::reset_current_external_function_options()
ModFile *
ParsingDriver::parse(istream &in, bool debug)
{
mod_file = new ModFile();
mod_file = new ModFile(warnings);
symbol_list.clear();
......@@ -118,7 +118,7 @@ ParsingDriver::error(const string &m)
void
ParsingDriver::warning(const string &m)
{
mod_file->warnings << "WARNING: " << location << ": " << m << endl;
warnings << "WARNING: " << location << ": " << m << endl;
}
void
......@@ -1659,7 +1659,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->warnings));
mod_file->addStatement(new LoadParamsAndSteadyStateStatement(*filename, mod_file->symbol_table, warnings));
delete filename;
}
......
......@@ -205,7 +205,11 @@ private:
//! The mod file representation constructed by this ParsingDriver
ModFile *mod_file;
WarningConsolidation &warnings;
public:
ParsingDriver(WarningConsolidation &warnings_arg) : warnings(warnings_arg) { };
//! Starts parsing, and constructs the MOD file representation
/*! The returned pointer should be deleted after use */
ModFile *parse(istream &in, bool debug);
......
/*
* Copyright (C) 2012 Dynare Team
* Copyright (C) 2012-2013 Dynare Team
*
* This file is part of Dynare.
*
......@@ -25,6 +25,9 @@ using namespace std;
WarningConsolidation&
operator<< (WarningConsolidation& wcc, const string &warning)
{
if (wcc.no_warn)
return wcc;
cerr << warning;
wcc.addWarning(warning);
return wcc;
......@@ -33,6 +36,9 @@ operator<< (WarningConsolidation& wcc, const string &warning)
WarningConsolidation&
operator<< (WarningConsolidation& wcc, const Dynare::location& loc)
{
if (wcc.no_warn)
return wcc;
stringstream ostr;
Dynare::position last = loc.end - 1;
ostr << loc.begin;
......@@ -53,6 +59,9 @@ operator<< (WarningConsolidation& wcc, const Dynare::location& loc)
WarningConsolidation&
operator<< (WarningConsolidation& wcc, ostream& (*pf) (ostream&))
{
if (wcc.no_warn)
return wcc;
cerr << pf;
wcc.addWarning(pf);
return wcc;
......@@ -86,3 +95,16 @@ WarningConsolidation::writeOutput(ostream &output) const
}
}
}
int
WarningConsolidation::countWarnings() const
{
size_t p = 0;
int n = 0;
while ((p = warnings.str().find('\n', p)) != string::npos)
{
p++;
n++;
}
return n;
}
/*
* Copyright (C) 2012 Dynare Team
* Copyright (C) 2012-2013 Dynare Team
*
* This file is part of Dynare.
*
......@@ -31,9 +31,10 @@ class WarningConsolidation
{
private:
stringstream warnings;
bool no_warn;
public:
WarningConsolidation() { };
WarningConsolidation(bool no_warn_arg) : no_warn(no_warn_arg) { };
~WarningConsolidation() { };
//! Add A Warning to the StringStream
......@@ -41,11 +42,15 @@ public:
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(const string &w) { warnings << w; };
inline void addWarning(ostream& (*pf) (ostream&)) { warnings << pf; };
//! Write Warnings to m file
void writeOutput(ostream &output) const;
//! Count warnings
/*! This is done in a very lousy way, by counting newlines in the
stringstream... */
int countWarnings() const;
};
#endif
Supports Markdown
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