From 8c7662d454ff1bf59f50c27a21ccdea688ff2881 Mon Sep 17 00:00:00 2001 From: MichelJuillard <michel.juillard@mjui.fr> Date: Thu, 14 Dec 2023 17:35:22 +0100 Subject: [PATCH] integrate master changes --- src/ModelTree.cc | 1 - src/Statement.cc | 166 +++++++++++++++++++++++---------------------- src/SymbolTable.cc | 56 ++++++--------- src/meson.build | 5 +- 4 files changed, 110 insertions(+), 118 deletions(-) diff --git a/src/ModelTree.cc b/src/ModelTree.cc index 9c06c78f..a3e1a7df 100644 --- a/src/ModelTree.cc +++ b/src/ModelTree.cc @@ -1943,7 +1943,6 @@ ModelTree::initializeMEXCompilationWorkers(int numworkers, const filesystem::pat /* Look for an object to compile, whose prerequisites are already compiled. If found, remove it from the queue, save the output path and the compilation command, and return true. Must be run under the lock. */ - auto pick_job = [&cmd, &output] { /* auto pick_job = [&cmd, &output] { for (auto it {mex_compilation_queue.begin()}; it != mex_compilation_queue.end(); ++it) diff --git a/src/Statement.cc b/src/Statement.cc index 481681d6..51391852 100644 --- a/src/Statement.cc +++ b/src/Statement.cc @@ -188,89 +188,93 @@ OptionsList::writeOutputCommon(ostream& output, const string& option_group) cons for (const auto &[name, val] : options) { auto name1 = name; - if constexpr(is_same_v<T, SymbolListVal>) - v.writeOutput(option_group + "." + name1, output); - else - { - output << option_group << "." << name1 << " = "; - if constexpr(is_same_v<T, NumVal> || is_same_v<T, DateVal>) - output << v; - else if constexpr(is_same_v<T, pair<string, string>>) - output << '[' << v.first << "; " << v.second << ']'; - else if constexpr(is_same_v<T, StringVal>) - output << "'" << v << "'"; - else if constexpr(is_same_v<T, vector<int>>) - { - output << option_group << "." << name << " = "; - if constexpr (is_same_v<T, NumVal> || is_same_v<T, DateVal>) - output << v; - else if constexpr (is_same_v<T, pair<string, string>>) - output << '[' << v.first << "; " << v.second << ']'; - else if constexpr (is_same_v<T, StringVal>) - output << "'" << v << "'"; - else if constexpr (is_same_v<T, vector<int>>) - { - if (v.size() > 1) - { - output << '['; - for (int it : v) - output << it << ";"; - output << ']'; - } - else - output << v.front(); - } - else if constexpr (is_same_v<T, VecStrVal>) - { - if (v.size() > 1) - { - output << '{'; - for (const auto& it : v) + std::visit( + [&]<class T>(const T& v) { + if constexpr(is_same_v<T, SymbolListVal>) + v.writeOutput(option_group + "." + name1, output); + else + { + output << option_group << "." << name1 << " = "; + if constexpr(is_same_v<T, NumVal> || is_same_v<T, DateVal>) + output << v; + else if constexpr(is_same_v<T, pair<string, string>>) + output << '[' << v.first << "; " << v.second << ']'; + else if constexpr(is_same_v<T, StringVal>) + output << "'" << v << "'"; + else if constexpr(is_same_v<T, vector<int>>) + { + output << option_group << "." << name << " = "; + if constexpr (is_same_v<T, NumVal> || is_same_v<T, DateVal>) + output << v; + else if constexpr (is_same_v<T, pair<string, string>>) + output << '[' << v.first << "; " << v.second << ']'; + else if constexpr (is_same_v<T, StringVal>) + output << "'" << v << "'"; + else if constexpr (is_same_v<T, vector<int>>) + { + if (v.size() > 1) + { + output << '['; + for (int it : v) + output << it << ";"; + output << ']'; + } + else + output << v.front(); + } + else if constexpr (is_same_v<T, VecStrVal>) + { + if (v.size() > 1) + { + output << '{'; + for (const auto& it : v) output << "'" << it << "';"; - output << '}'; + output << '}'; } - else - output << v.front(); - } - else if constexpr (is_same_v<T, VecCellStrVal>) - { - /* VecCellStrVal should ideally be merged into VecStrVal. - only difference is treatment of v.size==1, where VecStrVal - does not add quotes and curly brackets, i.e. allows for type conversion of - '2' into the number 2 */ - output << '{'; - for (const auto& it : v) - output << "'" << it << "';"; - output << '}'; - } - else if constexpr (is_same_v<T, VecValueVal>) - { - /* For historical reason, those vectors are output as row vectors (contrary - to vectors of integers which are output as column vectors) */ - output << '['; - for (const auto& it : v) - output << it << ','; - output << ']'; - } - else if constexpr (is_same_v<T, vector<vector<string>>>) - { - // Same remark as for VecValueVal - output << '{'; - for (const auto& v2 : v) - { - output << '['; - for (const auto& it : v2) - output << it << ','; - output << "], "; - } - output << '}'; - } - else - static_assert(always_false_v<T>, "Non-exhaustive visitor!"); - output << ";" << endl; - } - }, - val); + else + output << v.front(); + } + else if constexpr (is_same_v<T, VecCellStrVal>) + { + /* VecCellStrVal should ideally be merged into VecStrVal. + only difference is treatment of v.size==1, where VecStrVal + does not add quotes and curly brackets, i.e. allows for type conversion of + '2' into the number 2 */ + output << '{'; + for (const auto& it : v) + output << "'" << it << "';"; + output << '}'; + } + else if constexpr (is_same_v<T, VecValueVal>) + { + /* For historical reason, those vectors are output as row vectors (contrary + to vectors of integers which are output as column vectors) */ + output << '['; + for (const auto& it : v) + output << it << ','; + output << ']'; + } + else if constexpr (is_same_v<T, vector<vector<string>>>) + { + // Same remark as for VecValueVal + output << '{'; + for (const auto& v2 : v) + { + output << '['; + for (const auto& it : v2) + output << it << ','; + output << "], "; + } + output << '}'; + } + else + static_assert(always_false_v<T>, "Non-exhaustive visitor!"); + output << ";" << endl; + } + } + }, + val); + } // NOLINTEND(clang-analyzer-core.CallAndMessage) } diff --git a/src/SymbolTable.cc b/src/SymbolTable.cc index ec0f3c70..f02c81ec 100644 --- a/src/SymbolTable.cc +++ b/src/SymbolTable.cc @@ -436,9 +436,8 @@ SymbolTable::addLeadAuxiliaryVarInternal(bool endo, int index, expr_t expr_arg) << ", this name is internally used by Dynare" << endl; exit(EXIT_FAILURE); } - AuxVarInfo aux_var_info = {symb_id, (endo ? AuxVarType::endoLead : AuxVarType::exoLead), 0, 0, 0, 0, - expr_arg, ""}; - aux_vars.emplace_back(aux_var_info); + aux_vars.emplace_back(symb_id, (endo ? AuxVarType::endoLead : AuxVarType::exoLead), 0, 0, 0, 0, + expr_arg, ""); return symb_id; } @@ -461,9 +460,8 @@ SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_le exit(EXIT_FAILURE); } - AuxVarInfo::aux_var_info = {symb_id, (endo ? AuxVarType::endoLag : AuxVarType::exoLag), orig_symb_id, - orig_lead_lag, 0, 0, expr_arg, ""}; - aux_vars.emplace_back(aux_var_info); + aux_vars.emplace_back(symb_id, (endo ? AuxVarType::endoLag : AuxVarType::exoLag), orig_symb_id, + orig_lead_lag, 0, 0, expr_arg, ""); return symb_id; } @@ -512,9 +510,8 @@ SymbolTable::addExpectationAuxiliaryVar(int information_set, int index, exit(EXIT_FAILURE); } - AuxVarInfo aux_var_info = {symb_id, AuxVarType::expectation, 0, 0, 0, information_set, - expr_arg, ""}; - aux_vars.emplace_back(aux_var_info); + aux_vars.emplace_back(symb_id, AuxVarType::expectation, 0, 0, 0, information_set, + expr_arg, ""); return symb_id; } @@ -537,9 +534,8 @@ SymbolTable::addLogTransformAuxiliaryVar(int orig_symb_id, int orig_lead_lag, exit(EXIT_FAILURE); } - AuxVarInfo aux_var_info = {symb_id, AuxVarType::logTransform, orig_symb_id, orig_lead_lag, 0, 0, - expr_arg, ""}; - aux_vars.emplace_back(aux_var_info); + aux_vars.emplace_back(symb_id, AuxVarType::logTransform, orig_symb_id, orig_lead_lag, 0, 0, + expr_arg, ""); return symb_id; } @@ -561,9 +557,8 @@ SymbolTable::addDiffLagAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id exit(EXIT_FAILURE); } - AuxVarInfo aux_var_info = {symb_id, AuxVarType::diffLag, orig_symb_id, orig_lag, 0, 0, - expr_arg, ""}; - aux_vars.emplace_back(aux_var_info); + aux_vars.emplace_back(symb_id, AuxVarType::diffLag, orig_symb_id, orig_lag, 0, 0, + expr_arg, ""); return symb_id; } @@ -585,9 +580,8 @@ SymbolTable::addDiffLeadAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_i exit(EXIT_FAILURE); } - AuxVarInfo aux_var_info = {symb_id, AuxVarType::diffLead, orig_symb_id, orig_lead, 0, 0, - expr_arg, ""}; - aux_vars.emplace_back(aux_var_info); + aux_vars.emplace_back(symb_id, AuxVarType::diffLead, orig_symb_id, orig_lead, 0, 0, + expr_arg, ""); return symb_id; } @@ -609,9 +603,8 @@ SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg, const optional<int> exit(EXIT_FAILURE); } - AuxVarInfo aux_var_info = {symb_id, AuxVarType::diff, move(orig_symb_id), move(orig_lag), 0, 0, - expr_arg, ""}; - aux_vars.emplace_back(aux_var_info); + aux_vars.emplace_back(symb_id, AuxVarType::diff, move(orig_symb_id), move(orig_lag), 0, 0, + expr_arg, ""); return symb_id; } @@ -634,9 +627,8 @@ SymbolTable::addUnaryOpAuxiliaryVar(int index, expr_t expr_arg, string unary_op, exit(EXIT_FAILURE); } - AuxVarInfo::aux_var_info = {symb_id, AuxVarType::unaryOp, move(orig_symb_id), move(orig_lag), 0, 0, - expr_arg, unary_op}; - aux_vars.push_back(aux_var_info); + aux_vars.emplace_back(symb_id, AuxVarType::unaryOp, move(orig_symb_id), move(orig_lag), 0, 0, + expr_arg, unary_op); return symb_id; } @@ -657,8 +649,7 @@ SymbolTable::addMultiplierAuxiliaryVar(int index) noexcept(false) exit(EXIT_FAILURE); } - AuxVarInfo aux_var_info = {symb_id, AuxVarType::multiplier, 0, 0, index, 0, nullptr, ""}; - aux_vars.emplace_back(aux_var_info); + aux_vars.emplace_back(symb_id, AuxVarType::multiplier, 0, 0, index, 0, nullptr, ""); return symb_id; } @@ -679,9 +670,8 @@ SymbolTable::addDiffForwardAuxiliaryVar(int orig_symb_id, int orig_lead_lag, exit(EXIT_FAILURE); } - AuxVarInfo aux_var_info = {symb_id, AuxVarType::diffForward, orig_symb_id, orig_lead_lag, 0, 0, - expr_arg, ""}; - aux_vars.emplace_back(aux_var_info); + aux_vars.emplace_back(symb_id, AuxVarType::diffForward, orig_symb_id, orig_lead_lag, 0, 0, + expr_arg, ""); return symb_id; } @@ -702,8 +692,7 @@ SymbolTable::addPacExpectationAuxiliaryVar(const string& name, expr_t expr_arg) exit(EXIT_FAILURE); } - AuxVarInfo aux_var_info = {symb_id, AuxVarType::pacExpectation, 0, 0, 0, 0, expr_arg, ""}; - aux_vars.emplace_back(aux_var_info); + aux_vars.emplace_back(symb_id, AuxVarType::pacExpectation, 0, 0, 0, 0, expr_arg, ""); return symb_id; } @@ -724,9 +713,8 @@ SymbolTable::addPacTargetNonstationaryAuxiliaryVar(const string& name, expr_t ex exit(EXIT_FAILURE); } - AuxVarInfo aux_var_info = {symb_id, AuxVarType::pacTargetNonstationary, 0, 0, 0, 0, - expr_arg, ""}; - aux_vars.emplace_back(aux_var_info); + aux_vars.emplace_back(symb_id, AuxVarType::pacTargetNonstationary, 0, 0, 0, 0, + expr_arg, ""); return symb_id; } diff --git a/src/meson.build b/src/meson.build index 14eb2e36..63c10ba8 100644 --- a/src/meson.build +++ b/src/meson.build @@ -20,7 +20,8 @@ if not cpp_compiler.has_header('FlexLexer.h') fs.parent(fs.parent(flex_exe.full_path())) / 'include' / 'FlexLexer.h', 'FlexLexer.h' ) - flexlexer_h = '../../src/FlexLexer.h' +# flexlexer_h = '../../src/FlexLexer.h' + flexlexer_h = 'FlexLexer.h' else flexlexer_h = [] endif @@ -63,7 +64,7 @@ preprocessor_src = [ 'ComputingTasks.cc', 'macro/Environment.cc', 'macro/Expressions.cc', 'macro/Directives.cc' ] - + executable('dynare-preprocessor', preprocessor_src, flex_src, flexlexer_h, bison_src, include_directories : preprocessor_incdir, dependencies : boost_dep, link_args : [], -- GitLab