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