From e7c9c26d2d6f8c46390d2dc7c61dd738f4bdd992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Tue, 15 Jan 2019 11:08:47 +0100 Subject: [PATCH] More modernizations with clang-tidy --- src/ComputingTasks.cc | 6 +++--- src/ComputingTasks.hh | 2 +- src/DynamicModel.cc | 4 ++-- src/DynareMain.cc | 2 +- src/ExprNode.cc | 2 +- src/Shocks.cc | 8 ++++---- src/Statement.cc | 24 ++++++++---------------- src/Statement.hh | 2 +- src/SymbolTable.cc | 3 ++- 9 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index ec587a82..1b19d922 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -683,11 +683,11 @@ ForecastStatement::writeJsonOutput(ostream &output) const output << "}"; } -DetCondForecast::DetCondForecast(const SymbolList &symbol_list_arg, +DetCondForecast::DetCondForecast(SymbolList symbol_list_arg, OptionsList options_list_arg, const bool linear_decomposition_arg) : options_list{move(options_list_arg)}, - symbol_list{symbol_list_arg}, + symbol_list{move(symbol_list_arg)}, linear_decomposition{linear_decomposition_arg} { @@ -3427,7 +3427,7 @@ SubsamplesStatement::SubsamplesStatement(string name1_arg, const SymbolTable &symbol_table_arg) : name1{move(name1_arg)}, name2{move(name2_arg)}, - subsample_declaration_map{subsample_declaration_map_arg}, + subsample_declaration_map{move(subsample_declaration_map_arg)}, symbol_table{symbol_table_arg} { } diff --git a/src/ComputingTasks.hh b/src/ComputingTasks.hh index e999bd0d..f28d47d2 100644 --- a/src/ComputingTasks.hh +++ b/src/ComputingTasks.hh @@ -103,7 +103,7 @@ private: const SymbolList symbol_list; const bool linear_decomposition; public: - DetCondForecast(const SymbolList &symbol_list_arg, + DetCondForecast(SymbolList symbol_list_arg, OptionsList options_list_arg, const bool linear_decompositiontion_arg); //virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index d762ffb7..fbd878af 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -3333,9 +3333,9 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de tmp_s.str(""); } vector<int> inter_state_var; - for (auto it_l = local_state_var.begin(); it_l != local_state_var.end(); ++it_l) + for (int & it_l : local_state_var) for (auto it = state_var.begin(); it != state_var.end(); ++it) - if (*it == *it_l) + if (*it == it_l) inter_state_var.push_back(it - state_var.begin()+1); output << "block_structure.block(" << block+1 << ").sorted_col_dr_ghx = ["; for (int it : inter_state_var) diff --git a/src/DynareMain.cc b/src/DynareMain.cc index 9a87e537..599dbf86 100644 --- a/src/DynareMain.cc +++ b/src/DynareMain.cc @@ -121,7 +121,7 @@ main(int argc, char **argv) // Create options list, using first line of mod-file and command line vector<string> options = parse_options_line(modfile); for (int arg = 2; arg < argc; arg++) - options.push_back(argv[arg]); + options.emplace_back(argv[arg]); // Parse options bool clear_all = true; diff --git a/src/ExprNode.cc b/src/ExprNode.cc index 04fa9de6..d6ac99cb 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -5729,7 +5729,7 @@ BinaryOpNode::fillErrorCorrectionRowHelper(expr_t arg1, expr_t arg2, if (tmp.size() != 0) return; - BinaryOpNode *multiplicandr = dynamic_cast<BinaryOpNode *>(arg2); + auto *multiplicandr = dynamic_cast<BinaryOpNode *>(arg2); if (multiplicandr == nullptr || multiplicandr->op_code != BinaryOpcode::minus) return; diff --git a/src/Shocks.cc b/src/Shocks.cc index a1f618f2..0af4541b 100644 --- a/src/Shocks.cc +++ b/src/Shocks.cc @@ -45,11 +45,11 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const int id = symbol_table.getTypeSpecificID(det_shock.first) + 1; bool exo_det = (symbol_table.getType(det_shock.first) == SymbolType::exogenousDet); - for (size_t i = 0; i < det_shock.second.size(); i++) + for (const auto &it : det_shock.second) { - const int &period1 = det_shock.second[i].period1; - const int &period2 = det_shock.second[i].period2; - const expr_t value = det_shock.second[i].value; + const int &period1 = it.period1; + const int &period2 = it.period2; + const expr_t value = it.value; output << "M_.det_shocks = [ M_.det_shocks;" << endl << "struct('exo_det'," << (int) exo_det diff --git a/src/Statement.cc b/src/Statement.cc index ee699124..80d3548d 100644 --- a/src/Statement.cc +++ b/src/Statement.cc @@ -21,10 +21,6 @@ #include <boost/xpressive/xpressive.hpp> #include <utility> -ModFileStructure::ModFileStructure() -{ -} - void Statement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) { @@ -120,9 +116,8 @@ OptionsList::writeOutput(ostream &output) const if (vector_int_option.second.size() > 1) { output << "["; - for (auto viit = vector_int_option.second.begin(); - viit != vector_int_option.second.end(); viit++) - output << *viit << ";"; + for (int viit : vector_int_option.second) + output << viit << ";"; output << "];" << endl; } else @@ -135,9 +130,8 @@ OptionsList::writeOutput(ostream &output) const if (vector_str_option.second.size() > 1) { output << "{"; - for (auto viit = vector_str_option.second.begin(); - viit != vector_str_option.second.end(); viit++) - output << "'" << *viit << "';"; + for (const auto & viit : vector_str_option.second) + output << "'" << viit << "';"; output << "};" << endl; } else @@ -181,9 +175,8 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const if (vector_int_option.second.size() > 1) { output << "["; - for (auto viit = vector_int_option.second.begin(); - viit != vector_int_option.second.end(); viit++) - output << *viit << ";"; + for (int viit : vector_int_option.second) + output << viit << ";"; output << "];" << endl; } else @@ -196,9 +189,8 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const if (vector_str_option.second.size() > 1) { output << "{"; - for (auto viit = vector_str_option.second.begin(); - viit != vector_str_option.second.end(); viit++) - output << "'" << *viit << "';"; + for (const auto & viit : vector_str_option.second) + output << "'" << viit << "';"; output << "};" << endl; } else diff --git a/src/Statement.hh b/src/Statement.hh index d5c30c21..240e89fd 100644 --- a/src/Statement.hh +++ b/src/Statement.hh @@ -31,7 +31,7 @@ class ModFileStructure { public: - ModFileStructure(); + ModFileStructure() = default; //! Whether check is present bool check_present{false}; //! Whether steady is present diff --git a/src/SymbolTable.cc b/src/SymbolTable.cc index a21b2b22..e0338ba8 100644 --- a/src/SymbolTable.cc +++ b/src/SymbolTable.cc @@ -22,6 +22,7 @@ #include <iostream> #include <cassert> #include <boost/algorithm/string/replace.hpp> +#include <utility> #include "SymbolTable.hh" @@ -35,7 +36,7 @@ AuxVarInfo::AuxVarInfo(int symb_id_arg, AuxVarType type_arg, int orig_symb_id_ar equation_number_for_multiplier{equation_number_for_multiplier_arg}, information_set{information_set_arg}, expr_node{expr_node_arg}, - unary_op{unary_op_arg} + unary_op{move(unary_op_arg)} { } -- GitLab