C++11: convert ExtendedPreprocessorTypes to class enums
parent
97868cbd2a
commit
4a04a38374
|
@ -2265,7 +2265,7 @@ PlannerObjectiveStatement::getPlannerObjective() const
|
||||||
void
|
void
|
||||||
PlannerObjectiveStatement::computingPass()
|
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;
|
computing_pass_called = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,12 +117,12 @@ main(int argc, char **argv)
|
||||||
bool transform_unary_ops = false;
|
bool transform_unary_ops = false;
|
||||||
map<string, string> defines;
|
map<string, string> defines;
|
||||||
vector<string> path;
|
vector<string> path;
|
||||||
FileOutputType output_mode = none;
|
FileOutputType output_mode{FileOutputType::none};
|
||||||
JsonOutputPointType json = nojson;
|
JsonOutputPointType json{JsonOutputPointType::nojson};
|
||||||
JsonFileOutputType json_output_mode = file;
|
JsonFileOutputType json_output_mode{JsonFileOutputType::file};
|
||||||
bool onlyjson = false;
|
bool onlyjson = false;
|
||||||
bool jsonderivsimple = false;
|
bool jsonderivsimple = false;
|
||||||
LanguageOutputType language = matlab;
|
LanguageOutputType language{LanguageOutputType::matlab};
|
||||||
bool nopreprocessoroutput = false;
|
bool nopreprocessoroutput = false;
|
||||||
|
|
||||||
// Parse options
|
// Parse options
|
||||||
|
@ -265,13 +265,13 @@ main(int argc, char **argv)
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
if (strlen(argv[arg]) == 14 && !strncmp(argv[arg] + 7, "dynamic", 7))
|
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))
|
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))
|
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))
|
else if (strlen(argv[arg]) == 12 && !strncmp(argv[arg] + 7, "third", 5))
|
||||||
output_mode = third;
|
output_mode = FileOutputType::third;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cerr << "Incorrect syntax for output option" << endl;
|
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))
|
if (strlen(argv[arg]) == 14 && !strncmp(argv[arg] + 9, "julia", 5))
|
||||||
language = julia;
|
language = LanguageOutputType::julia;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// we don't want temp terms in external functions (except Julia)
|
// we don't want temp terms in external functions (except Julia)
|
||||||
no_tmp_terms = true;
|
no_tmp_terms = true;
|
||||||
if (strlen(argv[arg]) == 13 && !strncmp(argv[arg] + 9, "cuda", 4))
|
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))
|
else if (strlen(argv[arg]) == 15 && !strncmp(argv[arg] + 9, "python", 6))
|
||||||
language = python;
|
language = LanguageOutputType::python;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cerr << "Incorrect syntax for language option" << endl;
|
cerr << "Incorrect syntax for language option" << endl;
|
||||||
|
@ -304,7 +304,7 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!strcmp(argv[arg], "jsonstdout"))
|
else if (!strcmp(argv[arg], "jsonstdout"))
|
||||||
json_output_mode = standardout;
|
json_output_mode = JsonFileOutputType::standardout;
|
||||||
else if (!strcmp(argv[arg], "onlyjson"))
|
else if (!strcmp(argv[arg], "onlyjson"))
|
||||||
onlyjson = true;
|
onlyjson = true;
|
||||||
else if (!strcmp(argv[arg], "nopreprocessoroutput"))
|
else if (!strcmp(argv[arg], "nopreprocessoroutput"))
|
||||||
|
@ -319,13 +319,13 @@ main(int argc, char **argv)
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
if (strlen(argv[arg]) == 10 && !strncmp(argv[arg] + 5, "parse", 5))
|
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))
|
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))
|
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))
|
else if (strlen(argv[arg]) == 12 && !strncmp(argv[arg] + 5, "compute", 7))
|
||||||
json = computingpass;
|
json = JsonOutputPointType::computingpass;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cerr << "Incorrect syntax for json option" << endl;
|
cerr << "Incorrect syntax for json option" << endl;
|
||||||
|
|
|
@ -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
|
// Do parsing and construct internal representation of mod file
|
||||||
ModFile *mod_file = p.parse(in, debug);
|
ModFile *mod_file = p.parse(in, debug);
|
||||||
if (json == parsing)
|
if (json == JsonOutputPointType::parsing)
|
||||||
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, nopreprocessoroutput);
|
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, nopreprocessoroutput);
|
||||||
|
|
||||||
// Run checking pass
|
// Run checking pass
|
||||||
mod_file->checkPass(nostrict, stochastic);
|
mod_file->checkPass(nostrict, stochastic);
|
||||||
if (json == checkpass)
|
if (json == JsonOutputPointType::checkpass)
|
||||||
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, nopreprocessoroutput);
|
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, nopreprocessoroutput);
|
||||||
|
|
||||||
// Perform transformations on the model (creation of auxiliary vars and equations)
|
// Perform transformations on the model (creation of auxiliary vars and equations)
|
||||||
mod_file->transformPass(nostrict, stochastic, compute_xrefs || json == transformpass, nopreprocessoroutput, transform_unary_ops);
|
mod_file->transformPass(nostrict, stochastic, compute_xrefs || json == JsonOutputPointType::transformpass, nopreprocessoroutput, transform_unary_ops);
|
||||||
if (json == transformpass)
|
if (json == JsonOutputPointType::transformpass)
|
||||||
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, nopreprocessoroutput);
|
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, nopreprocessoroutput);
|
||||||
|
|
||||||
// Evaluate parameters initialization, initval, endval and pounds
|
// 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
|
// Do computations
|
||||||
mod_file->computingPass(no_tmp_terms, output_mode, params_derivs_order, nopreprocessoroutput);
|
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);
|
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, nopreprocessoroutput, jsonderivsimple);
|
||||||
|
|
||||||
// Write outputs
|
// Write outputs
|
||||||
if (output_mode != none)
|
if (output_mode != FileOutputType::none)
|
||||||
mod_file->writeExternalFiles(basename, output_mode, language, nopreprocessoroutput);
|
mod_file->writeExternalFiles(basename, output_mode, language, nopreprocessoroutput);
|
||||||
else
|
else
|
||||||
mod_file->writeOutputFiles(basename, clear_all, clear_global, no_log, no_warn, console, nograph,
|
mod_file->writeOutputFiles(basename, clear_all, clear_global, no_log, no_warn, console, nograph,
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#ifndef _EXTENDED_PREPROCESSOR_TYPES_HH
|
#ifndef _EXTENDED_PREPROCESSOR_TYPES_HH
|
||||||
#define _EXTENDED_PREPROCESSOR_TYPES_HH
|
#define _EXTENDED_PREPROCESSOR_TYPES_HH
|
||||||
|
|
||||||
enum FileOutputType
|
enum class FileOutputType
|
||||||
{
|
{
|
||||||
none, // outputs files for Matlab/Octave processing
|
none, // outputs files for Matlab/Octave processing
|
||||||
dynamic, // outputs <fname>_dynamic.* and related files
|
dynamic, // outputs <fname>_dynamic.* and related files
|
||||||
|
@ -29,7 +29,7 @@ enum FileOutputType
|
||||||
third, // outputs <fname>_first_derivatives.*, <fname>_second_derivatives.*, <fname>_third_derivatives.* and related files
|
third, // outputs <fname>_first_derivatives.*, <fname>_second_derivatives.*, <fname>_third_derivatives.* and related files
|
||||||
};
|
};
|
||||||
|
|
||||||
enum LanguageOutputType
|
enum class LanguageOutputType
|
||||||
{
|
{
|
||||||
matlab, // outputs files for Matlab/Octave processing
|
matlab, // outputs files for Matlab/Octave processing
|
||||||
cuda, // outputs files for CUDA (not yet implemented)
|
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)
|
python, // outputs files for Python (not yet implemented) (not yet implemented)
|
||||||
};
|
};
|
||||||
|
|
||||||
enum JsonFileOutputType
|
enum class JsonFileOutputType
|
||||||
{
|
{
|
||||||
file, // output JSON files to file
|
file, // output JSON files to file
|
||||||
standardout, // output JSON files to stdout
|
standardout, // output JSON files to stdout
|
||||||
};
|
};
|
||||||
|
|
||||||
enum JsonOutputPointType
|
enum class JsonOutputPointType
|
||||||
{
|
{
|
||||||
nojson, // don't output JSON
|
nojson, // don't output JSON
|
||||||
parsing, // output JSON after the parsing step
|
parsing, // output JSON after the parsing step
|
||||||
|
|
|
@ -677,7 +677,7 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output, int params_deri
|
||||||
|| mod_file_struct.calib_smoother_present)
|
|| mod_file_struct.calib_smoother_present)
|
||||||
{
|
{
|
||||||
if (mod_file_struct.perfect_foresight_solver_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
|
else
|
||||||
{
|
{
|
||||||
if (mod_file_struct.stoch_simul_present
|
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.identification_present
|
||||||
|| mod_file_struct.estimation_analytic_derivation
|
|| mod_file_struct.estimation_analytic_derivation
|
||||||
|| linear
|
|| linear
|
||||||
|| output == second
|
|| output == FileOutputType::second
|
||||||
|| output == third;
|
|| output == FileOutputType::third;
|
||||||
bool thirdDerivatives = mod_file_struct.order_option == 3
|
bool thirdDerivatives = mod_file_struct.order_option == 3
|
||||||
|| mod_file_struct.estimation_analytic_derivation
|
|| mod_file_struct.estimation_analytic_derivation
|
||||||
|| output == third;
|
|| output == FileOutputType::third;
|
||||||
int paramsDerivsOrder = 0;
|
int paramsDerivsOrder = 0;
|
||||||
if (mod_file_struct.identification_present || mod_file_struct.estimation_analytic_derivation)
|
if (mod_file_struct.identification_present || mod_file_struct.estimation_analytic_derivation)
|
||||||
paramsDerivsOrder = params_derivs_order;
|
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
|
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<int, string> eqs;
|
map<int, string> eqs;
|
||||||
if (mod_file_struct.ramsey_model_present)
|
if (mod_file_struct.ramsey_model_present)
|
||||||
|
@ -1061,7 +1061,7 @@ ModFile::writeExternalFiles(const string &basename, FileOutputType output, Langu
|
||||||
{
|
{
|
||||||
switch (language)
|
switch (language)
|
||||||
{
|
{
|
||||||
case julia:
|
case LanguageOutputType::julia:
|
||||||
writeExternalFilesJulia(basename, output, nopreprocessoroutput);
|
writeExternalFilesJulia(basename, output, nopreprocessoroutput);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1201,44 +1201,44 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output,
|
||||||
void
|
void
|
||||||
ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, const bool nopreprocessoroutput, bool jsonderivsimple)
|
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;
|
return;
|
||||||
|
|
||||||
if (json == parsing || json == checkpass)
|
if (json == JsonOutputPointType::parsing || json == JsonOutputPointType::checkpass)
|
||||||
symbol_table.freeze();
|
symbol_table.freeze();
|
||||||
|
|
||||||
if (json_output_mode == standardout)
|
if (json_output_mode == JsonFileOutputType::standardout)
|
||||||
cout << "//-- BEGIN JSON --// " << endl
|
cout << "//-- BEGIN JSON --// " << endl
|
||||||
<< "{" << 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();
|
symbol_table.unfreeze();
|
||||||
|
|
||||||
if (json == computingpass)
|
if (json == JsonOutputPointType::computingpass)
|
||||||
writeJsonComputingPassOutput(basename, json_output_mode, jsonderivsimple);
|
writeJsonComputingPassOutput(basename, json_output_mode, jsonderivsimple);
|
||||||
|
|
||||||
if (json_output_mode == standardout)
|
if (json_output_mode == JsonFileOutputType::standardout)
|
||||||
cout << "}" << endl
|
cout << "}" << endl
|
||||||
<< "//-- END JSON --// " << endl;
|
<< "//-- END JSON --// " << endl;
|
||||||
|
|
||||||
if (!nopreprocessoroutput)
|
if (!nopreprocessoroutput)
|
||||||
switch (json)
|
switch (json)
|
||||||
{
|
{
|
||||||
case parsing:
|
case JsonOutputPointType::parsing:
|
||||||
cout << "JSON written after Parsing step." << endl;
|
cout << "JSON written after Parsing step." << endl;
|
||||||
break;
|
break;
|
||||||
case checkpass:
|
case JsonOutputPointType::checkpass:
|
||||||
cout << "JSON written after Check step." << endl;
|
cout << "JSON written after Check step." << endl;
|
||||||
break;
|
break;
|
||||||
case transformpass:
|
case JsonOutputPointType::transformpass:
|
||||||
cout << "JSON written after Transform step." << endl;
|
cout << "JSON written after Transform step." << endl;
|
||||||
break;
|
break;
|
||||||
case computingpass:
|
case JsonOutputPointType::computingpass:
|
||||||
cout << "JSON written after Computing step." << endl;
|
cout << "JSON written after Computing step." << endl;
|
||||||
break;
|
break;
|
||||||
case nojson:
|
case JsonOutputPointType::nojson:
|
||||||
cerr << "ModFile::writeJsonOutput: should not arrive here." << endl;
|
cerr << "ModFile::writeJsonOutput: should not arrive here." << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -1292,7 +1292,7 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
|
||||||
steady_state_model.writeJsonSteadyStateFile(steady_state_model_output,
|
steady_state_model.writeJsonSteadyStateFile(steady_state_model_output,
|
||||||
transformpass || computingpass);
|
transformpass || computingpass);
|
||||||
|
|
||||||
if (json_output_mode == standardout)
|
if (json_output_mode == JsonFileOutputType::standardout)
|
||||||
{
|
{
|
||||||
if (transformpass || computingpass)
|
if (transformpass || computingpass)
|
||||||
cout << "\"transformed_modfile\": ";
|
cout << "\"transformed_modfile\": ";
|
||||||
|
@ -1376,7 +1376,7 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
|
||||||
void
|
void
|
||||||
ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonderivsimple) const
|
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;
|
cerr << "ERROR: Missing file name" << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -1404,7 +1404,7 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType
|
||||||
if (!tmp_out.str().empty())
|
if (!tmp_out.str().empty())
|
||||||
dynamic_paramsd_output << "{" << tmp_out.str() << "}" << endl;
|
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
|
cout << ", \"static_model\": " << static_output.str() << endl
|
||||||
<< ", \"dynamic_model\": " << dynamic_output.str() << endl;
|
<< ", \"dynamic_model\": " << dynamic_output.str() << endl;
|
||||||
|
|
Loading…
Reference in New Issue