Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 4.6
  • 5.x
  • 6.x
  • aux_vars_fix
  • julia
  • llvm-15
  • master
  • python-codegen
  • rework_pac
  • uop
  • julia-6.2.0
  • julia-6.3.0
  • julia-6.4.0
  • julia-7.0.0
14 results

Target

Select target project
  • normann/preprocessor
  • Dynare/preprocessor
  • FerhatMihoubi/preprocessor
  • MichelJuillard/preprocessor
  • sebastien/preprocessor
  • lnsongxf/preprocessor
  • albop/preprocessor
  • DoraK/preprocessor
  • amg/preprocessor
  • wmutschl/preprocessor
  • JohannesPfeifer/preprocessor
11 results
Select Git revision
  • 4.6
  • 5.x
  • aux_vars_fix
  • dynare_lite
  • julia
  • master
  • pylib
  • rework_pac
  • uop
  • wasm
  • created_preprocessor_repo
  • julia-6.2.0
12 results
Show changes
Showing
with 6915 additions and 4665 deletions
This diff is collapsed.
...@@ -17,24 +17,24 @@ ...@@ -17,24 +17,24 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iostream> #include <iostream>
#include <regex>
#include <sstream> #include <sstream>
#include <fstream>
#include <vector>
#include <string> #include <string>
#include <regex>
#include <thread> #include <thread>
#include <algorithm> #include <vector>
#include <filesystem>
#include <cstdlib> #include <cstdlib>
#include <unistd.h> #include <unistd.h>
#include "ParsingDriver.hh" #include "Configuration.hh"
#include "ExtendedPreprocessorTypes.hh" #include "ExtendedPreprocessorTypes.hh"
#include "ConfigFile.hh"
#include "ModFile.hh" #include "ModFile.hh"
#include "ParsingDriver.hh"
/* Prototype for the function that handles the macro-expansion of the .mod file /* Prototype for the function that handles the macro-expansion of the .mod file
Splitting this out was necessary because ParsingDriver.hh and macro/Driver.hh can't be Splitting this out was necessary because ParsingDriver.hh and macro/Driver.hh can't be
...@@ -42,21 +42,27 @@ ...@@ -42,21 +42,27 @@
Function can be found in: MacroExpandModFile.cc Function can be found in: MacroExpandModFile.cc
*/ */
stringstream stringstream macroExpandModFile(const filesystem::path& filename, const istream& modfile,
macroExpandModFile(const filesystem::path &filename, const istream &modfile, bool debug, bool save_macro, filesystem::path save_macro_file,
bool debug, bool save_macro, filesystem::path save_macro_file, bool line_macro, bool line_macro, const vector<pair<string, string>>& defines,
const vector<pair<string, string>> &defines,
vector<filesystem::path> paths); vector<filesystem::path> paths);
void void
usage() usage()
{ {
cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [linemacro] [notmpterms] [nolog] [warn_uninit]" cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] "
<< " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_follower_open_mode] [parallel_test] [parallel_use_psexec=true|false]" "[savemacro[=macro_file]] [onlymacro] [linemacro] [notmpterms] [nolog] [warn_uninit]"
<< " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] [compute_xrefs] [output=second|third] [language=matlab|julia]" << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] "
<< " [params_derivs_order=0|1|2] [transform_unary_ops] [exclude_eqs=<equation_tag_list_or_file>] [include_eqs=<equation_tag_list_or_file>]" "[conffile=path_to_config_file] [parallel_follower_open_mode] "
<< " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple] [nopathchange] [nopreprocessoroutput]" "[parallel_test] [parallel_use_psexec=true|false]"
<< " [mexext=<extension>] [matlabroot=<path>] [onlymodel] [notime] [use_dll] [nocommutativity]" << " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] "
"[compute_xrefs] [output=first|second|third] [language=matlab|julia]"
<< " [params_derivs_order=0|1|2] [transform_unary_ops] "
"[exclude_eqs=<equation_tag_list_or_file>] [include_eqs=<equation_tag_list_or_file>]"
<< " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple] "
"[nopathchange] [nopreprocessoroutput]"
<< " [mexext=<extension>] [matlabroot=<path>] [onlymodel] [notime] [use_dll] "
"[nocommutativity]"
<< endl; << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -75,13 +81,12 @@ parse_options_line(istream &modfile) ...@@ -75,13 +81,12 @@ parse_options_line(istream &modfile)
while (getline(modfile, first_nonempty_line)) while (getline(modfile, first_nonempty_line))
if (!first_nonempty_line.empty()) if (!first_nonempty_line.empty())
{ {
if (regex_search(first_nonempty_line, matches, pat) if (regex_search(first_nonempty_line, matches, pat) && matches.size() > 1
&& matches.size() > 1 && matches[1].matched) && matches[1].matched)
{ {
regex pat2 {R"([^,\s]+)"}; regex pat2 {R"([^,\s]+)"};
string s {matches[1]}; string s {matches[1]};
for (sregex_iterator p(s.begin(), s.end(), pat2); for (sregex_iterator p(s.begin(), s.end(), pat2); p != sregex_iterator {}; ++p)
p != sregex_iterator{}; ++p)
options.push_back(p->str()); options.push_back(p->str());
} }
break; break;
...@@ -137,10 +142,11 @@ main(int argc, char **argv) ...@@ -137,10 +142,11 @@ main(int argc, char **argv)
bool console = false; bool console = false;
bool nograph = false; bool nograph = false;
bool nointeractive = false; bool nointeractive = false;
filesystem::path parallel_config_file; filesystem::path conffile;
bool parallel = false; bool parallel = false;
string cluster_name; string cluster_name;
bool parallel_follower_open_mode = false; // Must be the same default as in matlab/default_option_values.m bool parallel_follower_open_mode
= false; // Must be the same default as in matlab/default_option_values.m
bool parallel_test = false; bool parallel_test = false;
bool parallel_use_psexec = true; // Must be the same default as in matlab/default_option_values.m bool parallel_use_psexec = true; // Must be the same default as in matlab/default_option_values.m
bool nostrict = false; bool nostrict = false;
...@@ -228,7 +234,7 @@ main(int argc, char **argv) ...@@ -228,7 +234,7 @@ main(int argc, char **argv)
cerr << "Incorrect syntax for conffile option" << endl; cerr << "Incorrect syntax for conffile option" << endl;
usage(); usage();
} }
parallel_config_file = s.substr(9); conffile = s.substr(9);
} }
else if (s == "parallel_follower_open_mode" else if (s == "parallel_follower_open_mode"
|| s == "parallel_slave_open_mode") // Kept for backward compatibility, see #86 || s == "parallel_slave_open_mode") // Kept for backward compatibility, see #86
...@@ -289,8 +295,7 @@ main(int argc, char **argv) ...@@ -289,8 +295,7 @@ main(int argc, char **argv)
usage(); usage();
} }
if (auto equal_index = s.find('='); if (auto equal_index = s.find('='); equal_index != string::npos)
equal_index != string::npos)
defines.emplace_back(s.substr(2, equal_index - 2), s.substr(equal_index + 1)); defines.emplace_back(s.substr(2, equal_index - 2), s.substr(equal_index + 1));
else else
defines.emplace_back(s.substr(2), "true"); defines.emplace_back(s.substr(2), "true");
...@@ -315,7 +320,9 @@ main(int argc, char **argv) ...@@ -315,7 +320,9 @@ main(int argc, char **argv)
s.erase(0, 7); s.erase(0, 7);
if (s == "second") if (s == "first")
output_mode = OutputType::first;
else if (s == "second")
output_mode = OutputType::second; output_mode = OutputType::second;
else if (s == "third") else if (s == "third")
output_mode = OutputType::third; output_mode = OutputType::third;
...@@ -439,9 +446,9 @@ main(int argc, char **argv) ...@@ -439,9 +446,9 @@ main(int argc, char **argv)
dynareroot = dynareroot.parent_path(); dynareroot = dynareroot.parent_path();
// Construct basename (i.e. remove file extension if there is one) // Construct basename (i.e. remove file extension if there is one)
/* Calling `string()` method on filename because of bug in GCC/MinGW 10.2 /* Calling string() method on filename.stem(): not necessary on GNU/Linux and macOS because there
(shipped in Debian “Bullseye” 11), that fails to accept implicit is an implicit conversion from filesystem:path to string (i.e. basic_string<char>), but needed
conversion to string from filename::path. */ on Windows because the implicit conversion is only to wstring (i.e. basic_string<wchar_t>). */
const string basename {filename.stem().string()}; const string basename {filename.stem().string()};
// Forbid some basenames, since they will cause trouble (see preprocessor#62) // Forbid some basenames, since they will cause trouble (see preprocessor#62)
...@@ -456,21 +463,22 @@ main(int argc, char **argv) ...@@ -456,21 +463,22 @@ main(int argc, char **argv)
WarningConsolidation warnings(no_warn); WarningConsolidation warnings(no_warn);
// Process config file // Process config file
ConfigFile config_file(parallel, parallel_test, parallel_follower_open_mode, parallel_use_psexec, cluster_name); Configuration config {parallel, parallel_test, parallel_follower_open_mode, parallel_use_psexec,
config_file.getConfigFileInfo(parallel_config_file); cluster_name};
config_file.checkPass(warnings); config.getConfigFileInfo(conffile, warnings);
config_file.transformPass(); config.checkPass(warnings);
config.transformPass();
// If Include option was passed to the [paths] block of the config file, add // If Include option was passed to the [paths] block of the config file, add
// it to paths before macroprocessing // it to paths before macroprocessing
for (const auto &it : config_file.getIncludePaths()) for (const auto& it : config.getIncludePaths())
paths.emplace_back(it); paths.emplace_back(it);
/* /*
* Macro-expand MOD file * Macro-expand MOD file
*/ */
stringstream macro_output = stringstream macro_output
macroExpandModFile(filename, modfile, debug, save_macro, move(save_macro_file), line_macro, = macroExpandModFile(filename, modfile, debug, save_macro, move(save_macro_file), line_macro,
defines, move(paths)); defines, move(paths));
if (only_macro) if (only_macro)
...@@ -503,8 +511,8 @@ main(int argc, char **argv) ...@@ -503,8 +511,8 @@ main(int argc, char **argv)
} }
if (mod_file->use_dll) if (mod_file->use_dll)
ModelTree::initializeMEXCompilationWorkers(max(jthread::hardware_concurrency(), 1U), ModelTree::initializeMEXCompilationWorkers(max(jthread::hardware_concurrency(), 1U), dynareroot,
dynareroot, mexext); mexext);
if (json == JsonOutputPointType::parsing) if (json == JsonOutputPointType::parsing)
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson); mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
...@@ -515,7 +523,8 @@ main(int argc, char **argv) ...@@ -515,7 +523,8 @@ main(int argc, char **argv)
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson); mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
// 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 == JsonOutputPointType::transformpass, mod_file->transformPass(nostrict, stochastic,
compute_xrefs || json == JsonOutputPointType::transformpass,
transform_unary_ops, exclude_eqs, include_eqs); transform_unary_ops, exclude_eqs, include_eqs);
if (json == JsonOutputPointType::transformpass) if (json == JsonOutputPointType::transformpass)
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson); mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
...@@ -533,8 +542,8 @@ main(int argc, char **argv) ...@@ -533,8 +542,8 @@ main(int argc, char **argv)
mod_file->writeJuliaOutput(basename); mod_file->writeJuliaOutput(basename);
else else
mod_file->writeMOutput(basename, clear_all, clear_global, no_warn, console, nograph, mod_file->writeMOutput(basename, clear_all, clear_global, no_warn, console, nograph,
nointeractive, config_file, check_model_changes, minimal_workspace, compute_xrefs, nointeractive, config, check_model_changes, minimal_workspace,
mexext, matlabroot, onlymodel, gui, notime); compute_xrefs, mexext, matlabroot, onlymodel, gui, notime);
/* Ensures that workers are not destroyed before they finish compiling. /* Ensures that workers are not destroyed before they finish compiling.
Also ensures that the preprocessor final message is printed after the end of Also ensures that the preprocessor final message is printed after the end of
......
/* /*
* Copyright © 2020-2023 Dynare Team * Copyright © 2020-2025 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
#include "EquationTags.hh" #include "EquationTags.hh"
#include <regex>
#include <ostream> #include <ostream>
#include <regex>
#include <utility> #include <utility>
set<int> set<int>
...@@ -62,8 +62,7 @@ EquationTags::getEqnsByTags(const map<string, string> &tags_selected) const ...@@ -62,8 +62,7 @@ EquationTags::getEqnsByTags(const map<string, string> &tags_selected) const
if (auto tmp = tags.find(key); tmp == tags.end() || tmp->second != value) if (auto tmp = tags.find(key); tmp == tags.end() || tmp->second != value)
goto next_eq; goto next_eq;
retval.insert(eqn); retval.insert(eqn);
next_eq: next_eq:;
;
} }
return retval; return retval;
} }
...@@ -75,10 +74,9 @@ EquationTags::erase(const set<int> &eqns, const map<int, int> &old_eqn_num_2_new ...@@ -75,10 +74,9 @@ EquationTags::erase(const set<int> &eqns, const map<int, int> &old_eqn_num_2_new
eqn_tags.erase(eqn); eqn_tags.erase(eqn);
for (const auto& [oldeqn, neweqn] : old_eqn_num_2_new) for (const auto& [oldeqn, neweqn] : old_eqn_num_2_new)
for (auto & [eqn, tags] : eqn_tags) if (eqn_tags.contains(oldeqn))
if (eqn == oldeqn)
{ {
auto tmp = eqn_tags.extract(eqn); auto tmp = eqn_tags.extract(oldeqn);
tmp.key() = neweqn; tmp.key() = neweqn;
eqn_tags.insert(move(tmp)); eqn_tags.insert(move(tmp));
} }
...@@ -89,8 +87,7 @@ EquationTags::writeCheckSumInfo(ostream &output) const ...@@ -89,8 +87,7 @@ EquationTags::writeCheckSumInfo(ostream &output) const
{ {
for (const auto& [eqn, tags] : eqn_tags) for (const auto& [eqn, tags] : eqn_tags)
for (const auto& [key, value] : tags) for (const auto& [key, value] : tags)
output << " " << eqn + 1 output << " " << eqn + 1 << key << " " << value << endl;
<< key << " " << value << endl;
} }
void void
...@@ -99,8 +96,7 @@ EquationTags::writeOutput(ostream &output) const ...@@ -99,8 +96,7 @@ EquationTags::writeOutput(ostream &output) const
output << "M_.equations_tags = {" << endl; output << "M_.equations_tags = {" << endl;
for (const auto& [eqn, tags] : eqn_tags) for (const auto& [eqn, tags] : eqn_tags)
for (const auto& [key, value] : tags) for (const auto& [key, value] : tags)
output << " " << eqn + 1 << " , '" output << " " << eqn + 1 << " , '" << key << "' , '" << value << "' ;" << endl;
<< key << "' , '" << value << "' ;" << endl;
output << "};" << endl; output << "};" << endl;
} }
...@@ -110,8 +106,7 @@ EquationTags::writeLatexOutput(ostream &output, int eqn) const ...@@ -110,8 +106,7 @@ EquationTags::writeLatexOutput(ostream &output, int eqn) const
if (!eqn_tags.contains(eqn)) if (!eqn_tags.contains(eqn))
return; return;
auto escape_special_latex_symbols = [](string str) auto escape_special_latex_symbols = [](string str) {
{
const regex special_latex_chars(R"([&%$#_{}])"); const regex special_latex_chars(R"([&%$#_{}])");
const regex backslash(R"(\\)"); const regex backslash(R"(\\)");
const regex tilde(R"(~)"); const regex tilde(R"(~)");
...@@ -125,8 +120,7 @@ EquationTags::writeLatexOutput(ostream &output, int eqn) const ...@@ -125,8 +120,7 @@ EquationTags::writeLatexOutput(ostream &output, int eqn) const
}; };
output << R"(\noindent[)"; output << R"(\noindent[)";
for (bool wrote_eq_tag {false}; for (bool wrote_eq_tag {false}; const auto& [key, value] : eqn_tags.at(eqn))
const auto & [key, value] : eqn_tags.at(eqn))
{ {
if (exchange(wrote_eq_tag, true)) if (exchange(wrote_eq_tag, true))
output << ", "; output << ", ";
...@@ -145,8 +139,7 @@ EquationTags::writeJsonAST(ostream &output, int eqn) const ...@@ -145,8 +139,7 @@ EquationTags::writeJsonAST(ostream &output, int eqn) const
return; return;
output << R"(, "tags": {)"; output << R"(, "tags": {)";
for (bool wroteFirst {false}; for (bool wroteFirst {false}; const auto& [key, value] : eqn_tags.at(eqn))
const auto &[key, value] : eqn_tags.at(eqn))
{ {
if (exchange(wroteFirst, true)) if (exchange(wroteFirst, true))
output << ", "; output << ", ";
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.