From 4a04a383744a7769f7f20838168eeb808553655c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 18 Jul 2018 17:28:05 +0200 Subject: [PATCH] C++11: convert ExtendedPreprocessorTypes to class enums --- src/ComputingTasks.cc | 2 +- src/DynareMain.cc | 32 ++++++++++++------------ src/DynareMain2.cc | 12 ++++----- src/ExtendedPreprocessorTypes.hh | 8 +++--- src/ModFile.cc | 42 ++++++++++++++++---------------- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index 63ad33e1..c13a5056 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -2265,7 +2265,7 @@ PlannerObjectiveStatement::getPlannerObjective() const void PlannerObjectiveStatement::computingPass() { - model_tree->computingPass(eval_context_t(), false, true, true, none, false, false, false); + model_tree->computingPass({}, false, true, true, 0, false, false, false); computing_pass_called = true; } diff --git a/src/DynareMain.cc b/src/DynareMain.cc index 974b331a..57178276 100644 --- a/src/DynareMain.cc +++ b/src/DynareMain.cc @@ -117,12 +117,12 @@ main(int argc, char **argv) bool transform_unary_ops = false; map defines; vector path; - FileOutputType output_mode = none; - JsonOutputPointType json = nojson; - JsonFileOutputType json_output_mode = file; + FileOutputType output_mode{FileOutputType::none}; + JsonOutputPointType json{JsonOutputPointType::nojson}; + JsonFileOutputType json_output_mode{JsonFileOutputType::file}; bool onlyjson = false; bool jsonderivsimple = false; - LanguageOutputType language = matlab; + LanguageOutputType language{LanguageOutputType::matlab}; bool nopreprocessoroutput = false; // Parse options @@ -265,13 +265,13 @@ main(int argc, char **argv) usage(); } if (strlen(argv[arg]) == 14 && !strncmp(argv[arg] + 7, "dynamic", 7)) - output_mode = dynamic; + output_mode = FileOutputType::dynamic; else if (strlen(argv[arg]) == 12 && !strncmp(argv[arg] + 7, "first", 5)) - output_mode = first; + output_mode = FileOutputType::first; else if (strlen(argv[arg]) == 13 && !strncmp(argv[arg] + 7, "second", 6)) - output_mode = second; + output_mode = FileOutputType::second; else if (strlen(argv[arg]) == 12 && !strncmp(argv[arg] + 7, "third", 5)) - output_mode = third; + output_mode = FileOutputType::third; else { cerr << "Incorrect syntax for output option" << endl; @@ -287,15 +287,15 @@ main(int argc, char **argv) } if (strlen(argv[arg]) == 14 && !strncmp(argv[arg] + 9, "julia", 5)) - language = julia; + language = LanguageOutputType::julia; else { // we don't want temp terms in external functions (except Julia) no_tmp_terms = true; if (strlen(argv[arg]) == 13 && !strncmp(argv[arg] + 9, "cuda", 4)) - language = cuda; + language = LanguageOutputType::cuda; else if (strlen(argv[arg]) == 15 && !strncmp(argv[arg] + 9, "python", 6)) - language = python; + language = LanguageOutputType::python; else { cerr << "Incorrect syntax for language option" << endl; @@ -304,7 +304,7 @@ main(int argc, char **argv) } } else if (!strcmp(argv[arg], "jsonstdout")) - json_output_mode = standardout; + json_output_mode = JsonFileOutputType::standardout; else if (!strcmp(argv[arg], "onlyjson")) onlyjson = true; else if (!strcmp(argv[arg], "nopreprocessoroutput")) @@ -319,13 +319,13 @@ main(int argc, char **argv) usage(); } if (strlen(argv[arg]) == 10 && !strncmp(argv[arg] + 5, "parse", 5)) - json = parsing; + json = JsonOutputPointType::parsing; else if (strlen(argv[arg]) == 10 && !strncmp(argv[arg] + 5, "check", 5)) - json = checkpass; + json = JsonOutputPointType::checkpass; else if (strlen(argv[arg]) == 14 && !strncmp(argv[arg] + 5, "transform", 9)) - json = transformpass; + json = JsonOutputPointType::transformpass; else if (strlen(argv[arg]) == 12 && !strncmp(argv[arg] + 5, "compute", 7)) - json = computingpass; + json = JsonOutputPointType::computingpass; else { cerr << "Incorrect syntax for json option" << endl; diff --git a/src/DynareMain2.cc b/src/DynareMain2.cc index 819a90e3..f12e6324 100644 --- a/src/DynareMain2.cc +++ b/src/DynareMain2.cc @@ -46,17 +46,17 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear // Do parsing and construct internal representation of mod file ModFile *mod_file = p.parse(in, debug); - if (json == parsing) + if (json == JsonOutputPointType::parsing) mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, nopreprocessoroutput); // Run checking pass mod_file->checkPass(nostrict, stochastic); - if (json == checkpass) + if (json == JsonOutputPointType::checkpass) mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, nopreprocessoroutput); // Perform transformations on the model (creation of auxiliary vars and equations) - mod_file->transformPass(nostrict, stochastic, compute_xrefs || json == transformpass, nopreprocessoroutput, transform_unary_ops); - if (json == transformpass) + mod_file->transformPass(nostrict, stochastic, compute_xrefs || json == JsonOutputPointType::transformpass, nopreprocessoroutput, transform_unary_ops); + if (json == JsonOutputPointType::transformpass) mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, nopreprocessoroutput); // Evaluate parameters initialization, initval, endval and pounds @@ -64,11 +64,11 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear // Do computations mod_file->computingPass(no_tmp_terms, output_mode, params_derivs_order, nopreprocessoroutput); - if (json == computingpass) + if (json == JsonOutputPointType::computingpass) mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, nopreprocessoroutput, jsonderivsimple); // Write outputs - if (output_mode != none) + if (output_mode != FileOutputType::none) mod_file->writeExternalFiles(basename, output_mode, language, nopreprocessoroutput); else mod_file->writeOutputFiles(basename, clear_all, clear_global, no_log, no_warn, console, nograph, diff --git a/src/ExtendedPreprocessorTypes.hh b/src/ExtendedPreprocessorTypes.hh index 87fea10c..e65ed3e6 100644 --- a/src/ExtendedPreprocessorTypes.hh +++ b/src/ExtendedPreprocessorTypes.hh @@ -20,7 +20,7 @@ #ifndef _EXTENDED_PREPROCESSOR_TYPES_HH #define _EXTENDED_PREPROCESSOR_TYPES_HH -enum FileOutputType +enum class FileOutputType { none, // outputs files for Matlab/Octave processing dynamic, // outputs _dynamic.* and related files @@ -29,7 +29,7 @@ enum FileOutputType third, // outputs _first_derivatives.*, _second_derivatives.*, _third_derivatives.* and related files }; -enum LanguageOutputType +enum class LanguageOutputType { matlab, // outputs files for Matlab/Octave processing cuda, // outputs files for CUDA (not yet implemented) @@ -37,13 +37,13 @@ enum LanguageOutputType python, // outputs files for Python (not yet implemented) (not yet implemented) }; -enum JsonFileOutputType +enum class JsonFileOutputType { file, // output JSON files to file standardout, // output JSON files to stdout }; -enum JsonOutputPointType +enum class JsonOutputPointType { nojson, // don't output JSON parsing, // output JSON after the parsing step diff --git a/src/ModFile.cc b/src/ModFile.cc index 92c89bf9..f7fcbe84 100644 --- a/src/ModFile.cc +++ b/src/ModFile.cc @@ -677,7 +677,7 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output, int params_deri || mod_file_struct.calib_smoother_present) { if (mod_file_struct.perfect_foresight_solver_present) - dynamic_model.computingPass(true, false, false, none, global_eval_context, no_tmp_terms, block, use_dll, byte_code, nopreprocessoroutput); + dynamic_model.computingPass(true, false, false, 0, global_eval_context, no_tmp_terms, block, use_dll, byte_code, nopreprocessoroutput); else { if (mod_file_struct.stoch_simul_present @@ -694,11 +694,11 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output, int params_deri || mod_file_struct.identification_present || mod_file_struct.estimation_analytic_derivation || linear - || output == second - || output == third; + || output == FileOutputType::second + || output == FileOutputType::third; bool thirdDerivatives = mod_file_struct.order_option == 3 || mod_file_struct.estimation_analytic_derivation - || output == third; + || output == FileOutputType::third; int paramsDerivsOrder = 0; if (mod_file_struct.identification_present || mod_file_struct.estimation_analytic_derivation) paramsDerivsOrder = params_derivs_order; @@ -708,7 +708,7 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output, int params_deri } } else // No computing task requested, compute derivatives up to 2nd order by default - dynamic_model.computingPass(true, true, false, none, global_eval_context, no_tmp_terms, block, use_dll, byte_code, nopreprocessoroutput); + dynamic_model.computingPass(true, true, false, 0, global_eval_context, no_tmp_terms, block, use_dll, byte_code, nopreprocessoroutput); map eqs; if (mod_file_struct.ramsey_model_present) @@ -1061,7 +1061,7 @@ ModFile::writeExternalFiles(const string &basename, FileOutputType output, Langu { switch (language) { - case julia: + case LanguageOutputType::julia: writeExternalFilesJulia(basename, output, nopreprocessoroutput); break; default: @@ -1201,44 +1201,44 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output, void ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, const bool nopreprocessoroutput, bool jsonderivsimple) { - if (json == nojson) + if (json == JsonOutputPointType::nojson) return; - if (json == parsing || json == checkpass) + if (json == JsonOutputPointType::parsing || json == JsonOutputPointType::checkpass) symbol_table.freeze(); - if (json_output_mode == standardout) + if (json_output_mode == JsonFileOutputType::standardout) cout << "//-- BEGIN JSON --// " << endl << "{" << endl; - writeJsonOutputParsingCheck(basename, json_output_mode, json == transformpass, json == computingpass); + writeJsonOutputParsingCheck(basename, json_output_mode, json == JsonOutputPointType::transformpass, json == JsonOutputPointType::computingpass); - if (json == parsing || json == checkpass) + if (json == JsonOutputPointType::parsing || json == JsonOutputPointType::checkpass) symbol_table.unfreeze(); - if (json == computingpass) + if (json == JsonOutputPointType::computingpass) writeJsonComputingPassOutput(basename, json_output_mode, jsonderivsimple); - if (json_output_mode == standardout) + if (json_output_mode == JsonFileOutputType::standardout) cout << "}" << endl << "//-- END JSON --// " << endl; if (!nopreprocessoroutput) switch (json) { - case parsing: + case JsonOutputPointType::parsing: cout << "JSON written after Parsing step." << endl; break; - case checkpass: + case JsonOutputPointType::checkpass: cout << "JSON written after Check step." << endl; break; - case transformpass: + case JsonOutputPointType::transformpass: cout << "JSON written after Transform step." << endl; break; - case computingpass: + case JsonOutputPointType::computingpass: cout << "JSON written after Computing step." << endl; break; - case nojson: + case JsonOutputPointType::nojson: cerr << "ModFile::writeJsonOutput: should not arrive here." << endl; exit(EXIT_FAILURE); } @@ -1292,7 +1292,7 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType steady_state_model.writeJsonSteadyStateFile(steady_state_model_output, transformpass || computingpass); - if (json_output_mode == standardout) + if (json_output_mode == JsonFileOutputType::standardout) { if (transformpass || computingpass) cout << "\"transformed_modfile\": "; @@ -1376,7 +1376,7 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType void ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonderivsimple) const { - if (basename.empty() && json_output_mode != standardout) + if (basename.empty() && json_output_mode != JsonFileOutputType::standardout) { cerr << "ERROR: Missing file name" << endl; exit(EXIT_FAILURE); @@ -1404,7 +1404,7 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType if (!tmp_out.str().empty()) dynamic_paramsd_output << "{" << tmp_out.str() << "}" << endl; - if (json_output_mode == standardout) + if (json_output_mode == JsonFileOutputType::standardout) { cout << ", \"static_model\": " << static_output.str() << endl << ", \"dynamic_model\": " << dynamic_output.str() << endl;