diff --git a/DynareMain.cc b/DynareMain.cc index a43f078de1f9f7111e88be02808aeb40363672ca..23f75e07ad5809eaf62325428805d4e9bb794c3c 100644 --- a/DynareMain.cc +++ b/DynareMain.cc @@ -1,5 +1,5 @@ /* - * 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 ¶llel_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 diff --git a/DynareMain2.cc b/DynareMain2.cc index 8eba44e3a1dcdea9f38fc25096c440ac81f5bfa1..f50436f5cb288814659184a492a6663b2216c1cb 100644 --- a/DynareMain2.cc +++ b/DynareMain2.cc @@ -1,5 +1,5 @@ /* - * 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 ¶llel_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 diff --git a/ModFile.cc b/ModFile.cc index 7aa034d7a57bac3fc80ed39eb5697541bec06c0b..830b446e892e296819e6a4f49786930db42f7383 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -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; diff --git a/ModFile.hh b/ModFile.hh index 1f515f05dbe823ae38bac80384d2228a9fbe76e5..55d46fe8a2cc61e90431cbcb55de2ad18b93395d 100644 --- a/ModFile.hh +++ b/ModFile.hh @@ -1,5 +1,5 @@ /* - * 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 diff --git a/ParsingDriver.cc b/ParsingDriver.cc index d4520975fbd1c650d733eaa8403d506f4ba13803..9e08e9a93d8a1709bbfcd931158a23bc6af48887 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -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; } diff --git a/ParsingDriver.hh b/ParsingDriver.hh index 7c637ddc1cb1f1e2a5c8c6ad0fc126bcdc56174a..34304ee5a57535af0e688075a80e28a068128aa9 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -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); diff --git a/WarningConsolidation.cc b/WarningConsolidation.cc index 7b9be9174a037984a0bd3271b4bbab80ed9e9b85..beaf061dee40ed51b0f147fa7de8fe251fbba2db 100644 --- a/WarningConsolidation.cc +++ b/WarningConsolidation.cc @@ -1,5 +1,5 @@ /* - * 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; +} diff --git a/WarningConsolidation.hh b/WarningConsolidation.hh index 8efbbc2e651a7775d9f32490503d9be53eaa6d19..ba63301429f4f657447308aa56b2a9248590bb4e 100644 --- a/WarningConsolidation.hh +++ b/WarningConsolidation.hh @@ -1,5 +1,5 @@ /* - * 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