diff --git a/configure.ac b/configure.ac index 3a10af2f..ff0acfd0 100644 --- a/configure.ac +++ b/configure.ac @@ -44,7 +44,7 @@ esac # Use C++ for testing headers AC_LANG([C++]) -AM_CXXFLAGS="-Wall -Wno-parentheses" +AM_CXXFLAGS="-Wall -Wno-parentheses -Wold-style-cast" AC_SUBST([AM_CXXFLAGS]) # If default 'ar' is not available, try to find one with a host prefix (see ticket #145) diff --git a/src/CodeInterpreter.hh b/src/CodeInterpreter.hh index 5892214f..ab0bd4c4 100644 --- a/src/CodeInterpreter.hh +++ b/src/CodeInterpreter.hh @@ -1266,13 +1266,13 @@ public: memcpy(&function_type, code, sizeof(function_type)); code += sizeof(function_type); int size; memcpy(&size, code, sizeof(size)); code += sizeof(size); - char *name = (char *) mxMalloc((size+1)*sizeof(char)); + char *name = static_cast(mxMalloc((size+1)*sizeof(char))); memcpy(name, code, size); code += size; name[size] = 0; func_name = name; mxFree(name); memcpy(&size, code, sizeof(size)); code += sizeof(size); - name = (char *) mxMalloc((size+1)*sizeof(char)); + name = static_cast(mxMalloc((size+1)*sizeof(char))); memcpy(name, code, size); code += size; name[size] = 0; arg_func_name = name; @@ -1699,7 +1699,7 @@ public: } Code_Size = CompiledCode.tellg(); CompiledCode.seekg(std::ios::beg); - code = (uint8_t *) mxMalloc(Code_Size); + code = static_cast(mxMalloc(Code_Size)); CompiledCode.seekg(0); CompiledCode.read(reinterpret_cast(code), Code_Size); CompiledCode.close(); diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 9fef7ade..f9c4665d 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -297,7 +297,7 @@ DynamicModel::computeTemporaryTermsOrdered() getBlockEquationRenormalizedExpr(block, i)->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, block, v_temporary_terms, i); else { - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); eq_node->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, block, v_temporary_terms, i); } } @@ -328,7 +328,7 @@ DynamicModel::computeTemporaryTermsOrdered() getBlockEquationRenormalizedExpr(block, i)->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, block, v_temporary_terms, i); else { - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); eq_node->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, block, v_temporary_terms, i); } } @@ -355,7 +355,7 @@ DynamicModel::computeTemporaryTermsOrdered() getBlockEquationRenormalizedExpr(block, i)->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); else { - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); eq_node->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); } } @@ -579,7 +579,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &basename) const if (simulation_type == SOLVE_TWO_BOUNDARIES_COMPLETE || simulation_type == SOLVE_TWO_BOUNDARIES_SIMPLE) { temporary_terms_t tt2; - for (int i = 0; i < (int) block_size; i++) + for (int i = 0; i < static_cast(block_size); i++) { if (v_temporary_terms[block][i].size() && global_temporary_terms) { @@ -645,7 +645,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &basename) const int equation_ID = getBlockEquationID(block, i); EquationType equ_type = getBlockEquationType(block, i); string sModel = symbol_table.getName(symbol_table.getID(SymbolType::endogenous, variable_ID)); - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; tmp_output.str(""); @@ -673,7 +673,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &basename) const rhs->writeOutput(output, local_output_type, local_temporary_terms, {}); output << endl << " "; tmp_output.str(""); - eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i); + eq_node = static_cast(getBlockEquationRenormalizedExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; lhs->writeOutput(output, local_output_type, local_temporary_terms, {}); @@ -1360,7 +1360,7 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id compileTemporaryTerms(code_file, instruction_number, temporary_terms, map_idx, true, false); // The equations - for (i = 0; i < (int) block_size; i++) + for (i = 0; i < static_cast(block_size); i++) { //The Temporary terms temporary_terms_t tt2; @@ -1371,10 +1371,10 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id if (dynamic_cast(it) != nullptr) it->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, true, false, tef_terms); - FNUMEXPR_ fnumexpr(TemporaryTerm, (int)(map_idx.find(it->idx)->second)); + FNUMEXPR_ fnumexpr(TemporaryTerm, static_cast(map_idx.find(it->idx)->second)); fnumexpr.write(code_file, instruction_number); it->compile(code_file, instruction_number, false, tt2, map_idx, true, false, tef_terms); - FSTPT_ fstpt((int)(map_idx.find(it->idx)->second)); + FSTPT_ fstpt(static_cast(map_idx.find(it->idx)->second)); fstpt.write(code_file, instruction_number); // Insert current node into tt2 tt2.insert(it); @@ -1411,7 +1411,7 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id } if (equ_type == E_EVALUATE) { - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; rhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, true, false); @@ -1419,7 +1419,7 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id } else if (equ_type == E_EVALUATE_S) { - eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i); + eq_node = static_cast(getBlockEquationRenormalizedExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; rhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, true, false); @@ -1430,7 +1430,7 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id case SOLVE_FORWARD_COMPLETE: case SOLVE_TWO_BOUNDARIES_COMPLETE: case SOLVE_TWO_BOUNDARIES_SIMPLE: - if (i < (int) block_recursive) + if (i < static_cast(block_recursive)) goto evaluation; variable_ID = getBlockVariableID(block, i); equation_ID = getBlockEquationID(block, i); @@ -1441,7 +1441,7 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id end: FNUMEXPR_ fnumexpr(ModelEquation, getBlockEquationID(block, i)); fnumexpr.write(code_file, instruction_number); - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; lhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, true, false); @@ -1498,12 +1498,12 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id continue; if (!Uf[eqr].Ufl) { - Uf[eqr].Ufl = (Uff_l *) malloc(sizeof(Uff_l)); + Uf[eqr].Ufl = static_cast(malloc(sizeof(Uff_l))); Uf[eqr].Ufl_First = Uf[eqr].Ufl; } else { - Uf[eqr].Ufl->pNext = (Uff_l *) malloc(sizeof(Uff_l)); + Uf[eqr].Ufl->pNext = static_cast(malloc(sizeof(Uff_l))); Uf[eqr].Ufl = Uf[eqr].Ufl->pNext; } Uf[eqr].Ufl->pNext = nullptr; @@ -1518,9 +1518,9 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id count_u++; } } - for (i = 0; i < (int) block_size; i++) + for (i = 0; i < static_cast(block_size); i++) { - if (i >= (int) block_recursive) + if (i >= static_cast(block_recursive)) { FLDR_ fldr(i-block_recursive); fldr.write(code_file, instruction_number); @@ -1938,12 +1938,12 @@ DynamicModel::Write_Inf_To_Bin_File_Block(const string &basename, const int &num if (is_two_boundaries) u_count_int += block_mfs; - for (j = block_recursive; j < (int) block_size; j++) + for (j = block_recursive; j < static_cast(block_size); j++) { unsigned int varr = getBlockVariableID(num, j); SaveCode.write(reinterpret_cast(&varr), sizeof(varr)); } - for (j = block_recursive; j < (int) block_size; j++) + for (j = block_recursive; j < static_cast(block_size); j++) { unsigned int eqr = getBlockEquationID(num, j); SaveCode.write(reinterpret_cast(&eqr), sizeof(eqr)); @@ -4624,7 +4624,7 @@ DynamicModel::addPacModelConsistentExpectationEquation(const string & name, int { int symb_id = symbol_table.addDiffAuxiliaryVar(diff_node_to_search->idx, diff_node_to_search); target_base_diff_node = AddVariable(symb_id); - addEquation(dynamic_cast(AddEqual((expr_t) target_base_diff_node, + addEquation(dynamic_cast(AddEqual(const_cast(target_base_diff_node), AddMinus(AddVariable(pac_target_symb_id), AddVariable(pac_target_symb_id, -1)))), -1); neqs++; @@ -4666,7 +4666,7 @@ DynamicModel::addPacModelConsistentExpectationEquation(const string & name, int fs = AddPlus(fs, AddTimes(ssum, target_aux_var_to_add[k])); } addEquation(AddEqual(AddVariable(mce_z1_symb_id), - AddMinus(AddTimes(A, AddMinus((expr_t) target_base_diff_node, fs)), fp)), -1); + AddMinus(AddTimes(A, AddMinus(const_cast(target_base_diff_node), fs)), fp)), -1); neqs++; pac_expectation_substitution[{name, eqtag}] = AddVariable(mce_z1_symb_id); } @@ -5383,7 +5383,7 @@ DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model) // Add aux LM to constraints in equations // equation[i]->lhs = rhs becomes equation[i]->MULT_(i+1)*(lhs-rhs) = 0 int i; - for (i = 0; i < (int) equations.size(); i++) + for (i = 0; i < static_cast(equations.size()); i++) { auto *substeq = dynamic_cast(equations[i]->addMultipliersToConstraints(i)); assert(substeq != nullptr); @@ -5419,7 +5419,7 @@ DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model) // Create (modified) Lagrangian (so that we can take the derivative once at time t) expr_t lagrangian = Zero; - for (i = 0; i < (int) equations.size(); i++) + for (i = 0; i < static_cast(equations.size()); i++) for (int lag = -max_eq_lag; lag <= max_eq_lead; lag++) { expr_t dfpower = nullptr; @@ -5611,7 +5611,7 @@ DynamicModel::getTypeByDerivID(int deriv_id) const noexcept(false) int DynamicModel::getLagByDerivID(int deriv_id) const noexcept(false) { - if (deriv_id < 0 || deriv_id >= (int) inv_deriv_id_table.size()) + if (deriv_id < 0 || deriv_id >= static_cast(inv_deriv_id_table.size())) throw UnknownDerivIDException(); return inv_deriv_id_table[deriv_id].second; @@ -5620,7 +5620,7 @@ DynamicModel::getLagByDerivID(int deriv_id) const noexcept(false) int DynamicModel::getSymbIDByDerivID(int deriv_id) const noexcept(false) { - if (deriv_id < 0 || deriv_id >= (int) inv_deriv_id_table.size()) + if (deriv_id < 0 || deriv_id >= static_cast(inv_deriv_id_table.size())) throw UnknownDerivIDException(); return inv_deriv_id_table[deriv_id].first; @@ -5715,7 +5715,7 @@ DynamicModel::testTrendDerivativesEqualToZero(const eval_context_t &eval_context it != deriv_id_table.end(); it++) if (symbol_table.getType(it->first.first) == SymbolType::trend || symbol_table.getType(it->first.first) == SymbolType::logTrend) - for (int eq = 0; eq < (int) equations.size(); eq++) + for (int eq = 0; eq < static_cast(equations.size()); eq++) { expr_t homogeneq = AddMinus(equations[eq]->arg1, equations[eq]->arg2); @@ -6525,7 +6525,7 @@ DynamicModel::isChecksumMatching(const string &basename, bool block) const ExprNodeOutputType buffer_type = block ? ExprNodeOutputType::matlabDynamicModelSparse : ExprNodeOutputType::CDynamicModel; - for (int eq = 0; eq < (int) equations.size(); eq++) + for (int eq = 0; eq < static_cast(equations.size()); eq++) { BinaryOpNode *eq_node = equations[eq]; expr_t lhs = eq_node->arg1; @@ -6624,7 +6624,7 @@ DynamicModel::writeJsonAST(ostream &output) const { vector> eqtags; output << R"("abstract_syntax_tree":[)" << endl; - for (int eq = 0; eq < (int) equations.size(); eq++) + for (int eq = 0; eq < static_cast(equations.size()); eq++) { if (eq != 0) output << ", "; diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh index e00bd354..fb68206c 100644 --- a/src/DynamicModel.hh +++ b/src/DynamicModel.hh @@ -607,13 +607,13 @@ public: int getBlockInitialEquationID(int block_number, int equation_number) const override { - return ((int) inv_equation_reordered[equation_number] - (int) get<1>(block_type_firstequation_size_mfs[block_number])); + return (static_cast(inv_equation_reordered[equation_number]) - static_cast(get<1>(block_type_firstequation_size_mfs[block_number]))); }; //! Return the position of variable_number in the block number belonging to the block block_number int getBlockInitialVariableID(int block_number, int variable_number) const override { - return ((int) inv_variable_reordered[variable_number] - (int) get<1>(block_type_firstequation_size_mfs[block_number])); + return (static_cast(inv_variable_reordered[variable_number]) - static_cast(get<1>(block_type_firstequation_size_mfs[block_number]))); }; //! Return the block number containing the endogenous variable variable_number int diff --git a/src/ExprNode.cc b/src/ExprNode.cc index fde0cceb..08f39601 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -4899,18 +4899,18 @@ BinaryOpNode::normalizeEquation(int var_endo, vector> { if (op_code == BinaryOpcode::equal) /* The end of the normalization process : All the operations needed to normalize the equation are applied. */ - for (int i = 0; i < (int) List_of_Op_RHS1.size(); i++) + for (int i = 0; i < static_cast(List_of_Op_RHS1.size()); i++) { tuple it = List_of_Op_RHS1.back(); List_of_Op_RHS1.pop_back(); if (get<1>(it) && !get<2>(it)) /*Binary operator*/ - expr_t_2 = Compute_RHS(expr_t_2, (BinaryOpNode *) get<1>(it), get<0>(it), 1); + expr_t_2 = Compute_RHS(expr_t_2, static_cast(get<1>(it)), get<0>(it), 1); else if (get<2>(it) && !get<1>(it)) /*Binary operator*/ expr_t_2 = Compute_RHS(get<2>(it), expr_t_2, get<0>(it), 1); else if (get<2>(it) && get<1>(it)) /*Binary operator*/ expr_t_2 = Compute_RHS(get<1>(it), get<2>(it), get<0>(it), 1); else /*Unary operator*/ - expr_t_2 = Compute_RHS((UnaryOpNode *) expr_t_2, (UnaryOpNode *) get<1>(it), get<0>(it), 0); + expr_t_2 = Compute_RHS(static_cast(expr_t_2), static_cast(get<1>(it)), get<0>(it), 0); } else List_of_Op_RHS = List_of_Op_RHS1; @@ -4918,18 +4918,18 @@ BinaryOpNode::normalizeEquation(int var_endo, vector> else if (is_endogenous_present_2) { if (op_code == BinaryOpcode::equal) - for (int i = 0; i < (int) List_of_Op_RHS2.size(); i++) + for (int i = 0; i < static_cast(List_of_Op_RHS2.size()); i++) { tuple it = List_of_Op_RHS2.back(); List_of_Op_RHS2.pop_back(); if (get<1>(it) && !get<2>(it)) /*Binary operator*/ - expr_t_1 = Compute_RHS((BinaryOpNode *) expr_t_1, (BinaryOpNode *) get<1>(it), get<0>(it), 1); + expr_t_1 = Compute_RHS(static_cast(expr_t_1), static_cast(get<1>(it)), get<0>(it), 1); else if (get<2>(it) && !get<1>(it)) /*Binary operator*/ - expr_t_1 = Compute_RHS((BinaryOpNode *) get<2>(it), (BinaryOpNode *) expr_t_1, get<0>(it), 1); + expr_t_1 = Compute_RHS(static_cast(get<2>(it)), static_cast(expr_t_1), get<0>(it), 1); else if (get<2>(it) && get<1>(it)) /*Binary operator*/ expr_t_1 = Compute_RHS(get<1>(it), get<2>(it), get<0>(it), 1); else - expr_t_1 = Compute_RHS((UnaryOpNode *) expr_t_1, (UnaryOpNode *) get<1>(it), get<0>(it), 0); + expr_t_1 = Compute_RHS(static_cast(expr_t_1), static_cast(get<1>(it)), get<0>(it), 0); } else List_of_Op_RHS = List_of_Op_RHS2; @@ -6910,7 +6910,7 @@ AbstractExternalFunctionNode::prepareForDerivation() argument->prepareForDerivation(); non_null_derivatives = arguments.at(0)->non_null_derivatives; - for (int i = 1; i < (int) arguments.size(); i++) + for (int i = 1; i < static_cast(arguments.size()); i++) set_union(non_null_derivatives.begin(), non_null_derivatives.end(), arguments.at(i)->non_null_derivatives.begin(), @@ -7521,7 +7521,7 @@ expr_t ExternalFunctionNode::composeDerivatives(const vector &dargs) { vector dNodes; - for (int i = 0; i < (int) dargs.size(); i++) + for (int i = 0; i < static_cast(dargs.size()); i++) dNodes.push_back(datatree.AddTimes(dargs.at(i), datatree.AddFirstDerivExternalFunction(symb_id, arguments, i+1))); @@ -7596,7 +7596,7 @@ ExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCode, unsign if (!alreadyWrittenAsTefTerm(symb_id, tef_terms)) { - tef_terms[{ symb_id, arguments }] = (int) tef_terms.size(); + tef_terms[{ symb_id, arguments }] = static_cast(tef_terms.size()); int indx = getIndxInTefTerms(symb_id, tef_terms); int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id); assert(second_deriv_symb_id != ExternalFunctionsTable::IDSetButNoNameProvided); @@ -7698,7 +7698,7 @@ ExternalFunctionNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutpu if (!alreadyWrittenAsTefTerm(symb_id, tef_terms)) { - tef_terms[{ symb_id, arguments }] = (int) tef_terms.size(); + tef_terms[{ symb_id, arguments }] = static_cast(tef_terms.size()); int indx = getIndxInTefTerms(symb_id, tef_terms); int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id); assert(second_deriv_symb_id != ExternalFunctionsTable::IDSetButNoNameProvided); @@ -7775,7 +7775,7 @@ ExternalFunctionNode::writeJsonExternalFunctionOutput(vector &efout, if (!alreadyWrittenAsTefTerm(symb_id, tef_terms)) { - tef_terms[{ symb_id, arguments }] = (int) tef_terms.size(); + tef_terms[{ symb_id, arguments }] = static_cast(tef_terms.size()); int indx = getIndxInTefTerms(symb_id, tef_terms); int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id); assert(second_deriv_symb_id != ExternalFunctionsTable::IDSetButNoNameProvided); @@ -7866,7 +7866,7 @@ expr_t FirstDerivExternalFunctionNode::composeDerivatives(const vector &dargs) { vector dNodes; - for (int i = 0; i < (int) dargs.size(); i++) + for (int i = 0; i < static_cast(dargs.size()); i++) dNodes.push_back(datatree.AddTimes(dargs.at(i), datatree.AddSecondDerivExternalFunction(symb_id, arguments, inputIndex, i+1))); expr_t theDeriv = datatree.Zero; @@ -8054,7 +8054,7 @@ FirstDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Exp } else { - tef_terms[{ first_deriv_symb_id, arguments }] = (int) tef_terms.size(); + tef_terms[{ first_deriv_symb_id, arguments }] = static_cast(tef_terms.size()); int indx = getIndxInTefTerms(first_deriv_symb_id, tef_terms); stringstream ending; ending << "_tefd_def_" << indx; @@ -8080,7 +8080,7 @@ FirstDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Exp << datatree.symbol_table.getName(symb_id) << "'," << inputIndex << ",{"; else { - tef_terms[{ first_deriv_symb_id, arguments }] = (int) tef_terms.size(); + tef_terms[{ first_deriv_symb_id, arguments }] = static_cast(tef_terms.size()); output << "TEFD_def_" << getIndxInTefTerms(first_deriv_symb_id, tef_terms) << " = " << datatree.symbol_table.getName(first_deriv_symb_id) << "("; } @@ -8123,7 +8123,7 @@ FirstDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector & << R"(, "value": ")" << datatree.symbol_table.getName(symb_id) << "("; else { - tef_terms[{ first_deriv_symb_id, arguments }] = (int) tef_terms.size(); + tef_terms[{ first_deriv_symb_id, arguments }] = static_cast(tef_terms.size()); ef << R"({"first_deriv_external_function": {)" << R"("external_function_term": "TEFD_def_)" << getIndxInTefTerms(first_deriv_symb_id, tef_terms) << R"(")" << R"(, "analytic_derivative": true)" @@ -8165,7 +8165,7 @@ FirstDerivExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCo } else { - tef_terms[{ first_deriv_symb_id, arguments }] = (int) tef_terms.size(); + tef_terms[{ first_deriv_symb_id, arguments }] = static_cast(tef_terms.size()); int indx = getIndxInTefTerms(symb_id, tef_terms); int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id); assert(second_deriv_symb_id != ExternalFunctionsTable::IDSetButNoNameProvided); @@ -8419,7 +8419,7 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex } else { - tef_terms[{ second_deriv_symb_id, arguments }] = (int) tef_terms.size(); + tef_terms[{ second_deriv_symb_id, arguments }] = static_cast(tef_terms.size()); int indx = getIndxInTefTerms(second_deriv_symb_id, tef_terms); stringstream ending; ending << "_tefdd_def_" << indx; @@ -8447,7 +8447,7 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex << inputIndex1 << "," << inputIndex2 << ",{"; else { - tef_terms[{ second_deriv_symb_id, arguments }] = (int) tef_terms.size(); + tef_terms[{ second_deriv_symb_id, arguments }] = static_cast(tef_terms.size()); output << "TEFDD_def_" << getIndxInTefTerms(second_deriv_symb_id, tef_terms) << " = " << datatree.symbol_table.getName(second_deriv_symb_id) << "("; } @@ -8491,7 +8491,7 @@ SecondDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector << R"(, "value": ")" << datatree.symbol_table.getName(symb_id) << "("; else { - tef_terms[{ second_deriv_symb_id, arguments }] = (int) tef_terms.size(); + tef_terms[{ second_deriv_symb_id, arguments }] = static_cast(tef_terms.size()); ef << R"({"second_deriv_external_function": {)" << R"("external_function_term": "TEFDD_def_)" << getIndxInTefTerms(second_deriv_symb_id, tef_terms) << R"(")" << R"(, "analytic_derivative": true)" diff --git a/src/ExprNode.hh b/src/ExprNode.hh index c5c948e3..c2d04f5f 100644 --- a/src/ExprNode.hh +++ b/src/ExprNode.hh @@ -134,7 +134,7 @@ isLatexOutput(ExprNodeOutputType output_type) /* Equal to 1 for Matlab langage or Julia, or to 0 for C language. Not defined for LaTeX. In Matlab and Julia, array indexes begin at 1, while they begin at 0 in C */ -#define ARRAY_SUBSCRIPT_OFFSET(output_type) ((int) (isMatlabOutput(output_type) || isJuliaOutput(output_type))) +#define ARRAY_SUBSCRIPT_OFFSET(output_type) (static_cast(isMatlabOutput(output_type) || isJuliaOutput(output_type))) // Left and right array subscript delimiters: '(' and ')' for Matlab, '[' and ']' for C #define LEFT_ARRAY_SUBSCRIPT(output_type) (isMatlabOutput(output_type) ? '(' : '[') diff --git a/src/Makefile.am b/src/Makefile.am index 71099dcb..aced0535 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -72,6 +72,8 @@ DynareFlex.cc FlexLexer.h: DynareFlex.ll $(LEX) -o DynareFlex.cc DynareFlex.ll cp $(LEXINC)/FlexLexer.h . || test -f ./FlexLexer.h +dynare_m-DynareFlex.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast + DynareBison.cc DynareBison.hh location.hh stack.hh position.hh: DynareBison.yy $(YACC) -W -o DynareBison.cc DynareBison.yy diff --git a/src/ModelTree.cc b/src/ModelTree.cc index d236bfd4..46031571 100644 --- a/src/ModelTree.cc +++ b/src/ModelTree.cc @@ -371,7 +371,7 @@ ModelTree::computeNormalizedEquations(multimap &endo2eqs) const if (endo.find({ symbol_table.getTypeSpecificID(symb_id), 0 }) != endo.end()) continue; - endo2eqs.emplace(symbol_table.getTypeSpecificID(symb_id), (int) i); + endo2eqs.emplace(symbol_table.getTypeSpecificID(symb_id), static_cast(i)); cout << "Endogenous " << symbol_table.getName(symb_id) << " normalized in equation " << (i+1) << endl; } } @@ -517,7 +517,7 @@ ModelTree::computeNaturalNormalization() bool bool_result = true; set > result; endo2eq.resize(equations.size()); - for (int eq = 0; eq < (int) equations.size(); eq++) + for (int eq = 0; eq < static_cast(equations.size()); eq++) if (!is_equation_linear[eq]) { BinaryOpNode *eq_node = equations[eq]; @@ -621,7 +621,7 @@ ModelTree::computePrologueAndEpilogue(const jacob_map_t &static_jacobian_arg, ve { int tmp_epilogue = epilogue; something_has_been_done = false; - for (int i = prologue; i < n - (int) epilogue; i++) + for (int i = prologue; i < n - static_cast(epilogue); i++) { int nze = 0; for (int j = prologue; j < n - tmp_epilogue; j++) @@ -712,12 +712,12 @@ ModelTree::getVariableLeadLagByBlock(const dynamic_jacob_map_t &dynamic_jacobian vector variable_blck(nb_endo), equation_blck(nb_endo); for (int i = 0; i < nb_endo; i++) { - if (i < (int) prologue) + if (i < static_cast(prologue)) { variable_blck[variable_reordered[i]] = i; equation_blck[equation_reordered[i]] = i; } - else if (i < (int) (components_set.size() + prologue)) + else if (i < static_cast(components_set.size() + prologue)) { variable_blck[variable_reordered[i]] = components_set[i-prologue] + prologue; equation_blck[equation_reordered[i]] = components_set[i-prologue] + prologue; @@ -782,8 +782,8 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob else tmp_normalized_contemporaneous_jacobian = static_jacobian; for (const auto &it : tmp_normalized_contemporaneous_jacobian) - if (reverse_equation_reordered[it.first.first] >= (int) prologue && reverse_equation_reordered[it.first.first] < (int) (nb_var - epilogue) - && reverse_variable_reordered[it.first.second] >= (int) prologue && reverse_variable_reordered[it.first.second] < (int) (nb_var - epilogue) + if (reverse_equation_reordered[it.first.first] >= static_cast(prologue) && reverse_equation_reordered[it.first.first] < static_cast(nb_var - epilogue) + && reverse_variable_reordered[it.first.second] >= static_cast(prologue) && reverse_variable_reordered[it.first.second] < static_cast(nb_var - epilogue) && it.first.first != endo2eq[it.first.second]) add_edge(vertex(reverse_equation_reordered[endo2eq[it.first.second]]-prologue, G2), vertex(reverse_equation_reordered[it.first.first]-prologue, G2), @@ -863,7 +863,7 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob n_backward = vector(prologue+num+epilogue, 0); n_mixed = vector(prologue+num+epilogue, 0); - for (int i = 0; i < (int) prologue; i++) + for (int i = 0; i < static_cast(prologue); i++) { if (variable_lag_lead[tmp_variable_reordered[i]].first != 0 && variable_lag_lead[tmp_variable_reordered[i]].second != 0) n_mixed[i]++; @@ -961,7 +961,7 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob } } - for (int i = 0; i < (int) epilogue; i++) + for (int i = 0; i < static_cast(epilogue); i++) { if (variable_lag_lead[tmp_variable_reordered[prologue+n+i]].first != 0 && variable_lag_lead[tmp_variable_reordered[prologue+n+i]].second != 0) n_mixed[prologue+num+i]++; @@ -1025,21 +1025,21 @@ ModelTree::reduceBlocksAndTypeDetermination(const dynamic_jacob_map_t &dynamic_j unsigned int l_n_forward = 0; unsigned int l_n_backward = 0; unsigned int l_n_mixed = 0; - for (i = 0; i < (int) (prologue+blocks.size()+epilogue); i++) + for (i = 0; i < static_cast(prologue+blocks.size()+epilogue); i++) { int first_count_equ = count_equ; - if (i < (int) prologue) + if (i < static_cast(prologue)) { Blck_Size = 1; MFS_Size = 1; } - else if (i < (int) (prologue+blocks.size())) + else if (i < static_cast(prologue+blocks.size())) { Blck_Size = blocks[blck_count_simult].first; MFS_Size = blocks[blck_count_simult].second; blck_count_simult++; } - else if (i < (int) (prologue+blocks.size()+epilogue)) + else if (i < static_cast(prologue+blocks.size()+epilogue)) { Blck_Size = 1; MFS_Size = 1; @@ -1348,7 +1348,7 @@ ModelTree::computeTemporaryTerms(bool is_matlab, bool no_tmp_terms) reference_count, is_matlab); - for (int order = 1; order < (int) derivatives.size(); order++) + for (int order = 1; order < static_cast(derivatives.size()); order++) for (const auto &it : derivatives[order]) it.second->computeTemporaryTerms({ 0, order }, temp_terms_map, @@ -1364,14 +1364,14 @@ ModelTree::computeTemporaryTerms(bool is_matlab, bool no_tmp_terms) // Fill the new structure temporary_terms_derivatives.clear(); temporary_terms_derivatives.resize(derivatives.size()); - for (int order = 0; order < (int) derivatives.size(); order++) + for (int order = 0; order < static_cast(derivatives.size()); order++) temporary_terms_derivatives[order] = move(temp_terms_map[{ 0, order }]); // Compute indices in MATLAB/Julia vector int idx = 0; for (auto &it : temporary_terms_mlv) temporary_terms_idxs[it.first] = idx++; - for (int order = 0; order < (int) derivatives.size(); order++) + for (int order = 0; order < static_cast(derivatives.size()); order++) for (const auto &it : temporary_terms_derivatives[order]) temporary_terms_idxs[it] = idx++; } @@ -1618,17 +1618,17 @@ ModelTree::compileTemporaryTerms(ostream &code_file, unsigned int &instruction_n it->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, dynamic, steady_dynamic, tef_terms); } - FNUMEXPR_ fnumexpr(TemporaryTerm, (int)(map_idx.find(it->idx)->second)); + FNUMEXPR_ fnumexpr(TemporaryTerm, static_cast(map_idx.find(it->idx)->second)); fnumexpr.write(code_file, instruction_number); it->compile(code_file, instruction_number, false, tt2, map_idx, dynamic, steady_dynamic, tef_terms); if (dynamic) { - FSTPT_ fstpt((int)(map_idx.find(it->idx)->second)); + FSTPT_ fstpt(static_cast(map_idx.find(it->idx)->second)); fstpt.write(code_file, instruction_number); } else { - FSTPST_ fstpst((int)(map_idx.find(it->idx)->second)); + FSTPST_ fstpst(static_cast(map_idx.find(it->idx)->second)); fstpst.write(code_file, instruction_number); } // Insert current node into tt2 @@ -1696,7 +1696,7 @@ void ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const { - for (int eq = 0; eq < (int) equations.size(); eq++) + for (int eq = 0; eq < static_cast(equations.size()); eq++) { BinaryOpNode *eq_node = equations[eq]; expr_t lhs = eq_node->arg1; @@ -1754,7 +1754,7 @@ ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type, void ModelTree::compileModelEquations(ostream &code_file, unsigned int &instruction_number, const temporary_terms_t &tt, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic) const { - for (int eq = 0; eq < (int) equations.size(); eq++) + for (int eq = 0; eq < static_cast(equations.size()); eq++) { BinaryOpNode *eq_node = equations[eq]; expr_t lhs = eq_node->arg1; @@ -1827,9 +1827,9 @@ ModelTree::Write_Inf_To_Bin_File(const string &filename, } if (is_two_boundaries) u_count_int += symbol_table.endo_nbr(); - for (j = 0; j < (int) symbol_table.endo_nbr(); j++) + for (j = 0; j < static_cast(symbol_table.endo_nbr()); j++) SaveCode.write(reinterpret_cast(&j), sizeof(j)); - for (j = 0; j < (int) symbol_table.endo_nbr(); j++) + for (j = 0; j < static_cast(symbol_table.endo_nbr()); j++) SaveCode.write(reinterpret_cast(&j), sizeof(j)); SaveCode.close(); } @@ -1875,7 +1875,7 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output content_output << endl << R"(\end{dmath*})" << endl; } - for (int eq = 0; eq < (int) equations.size(); eq++) + for (int eq = 0; eq < static_cast(equations.size()); eq++) { content_output << "% Equation " << eq + 1 << endl; if (write_equation_tags) @@ -2042,7 +2042,7 @@ ModelTree::computeParamsDerivatives(int paramsDerivsOrder) // First-order derivatives w.r.t. params for (int param : deriv_id_set) { - for (int eq = 0; eq < (int) equations.size(); eq++) + for (int eq = 0; eq < static_cast(equations.size()); eq++) { expr_t d = equations[eq]->getDerivative(param); if (d == Zero) @@ -2050,7 +2050,7 @@ ModelTree::computeParamsDerivatives(int paramsDerivsOrder) params_derivatives[{ 0, 1 }][{ eq, param }] = d; } - for (int endoOrd = 1; endoOrd < (int) derivatives.size(); endoOrd++) + for (int endoOrd = 1; endoOrd < static_cast(derivatives.size()); endoOrd++) for (const auto &it : derivatives[endoOrd]) { expr_t d = it.second->getDerivative(param); @@ -2063,7 +2063,7 @@ ModelTree::computeParamsDerivatives(int paramsDerivsOrder) } // Higher-order derivatives w.r.t. parameters - for (int endoOrd = 0; endoOrd < (int) derivatives.size(); endoOrd++) + for (int endoOrd = 0; endoOrd < static_cast(derivatives.size()); endoOrd++) for (int paramOrd = 2; paramOrd <= paramsDerivsOrder; paramOrd++) for (const auto &it : params_derivatives[{ endoOrd, paramOrd-1 }]) for (int param : deriv_id_set) @@ -2120,7 +2120,7 @@ ModelTree::writeJsonModelEquations(ostream &output, bool residuals) const output << endl << R"("residuals":[)" << endl; else output << endl << R"("model":[)" << endl; - for (int eq = 0; eq < (int) equations.size(); eq++) + for (int eq = 0; eq < static_cast(equations.size()); eq++) { if (eq > 0) output << ", "; diff --git a/src/NumericalConstants.cc b/src/NumericalConstants.cc index 8aba3c1e..2117d03a 100644 --- a/src/NumericalConstants.cc +++ b/src/NumericalConstants.cc @@ -33,7 +33,7 @@ NumericalConstants::AddNonNegativeConstant(const string &iConst) if (iter != numConstantsIndex.end()) return iter->second; - auto id = (int) mNumericalConstants.size(); + auto id = static_cast(mNumericalConstants.size()); mNumericalConstants.push_back(iConst); numConstantsIndex[iConst] = id; @@ -52,13 +52,13 @@ NumericalConstants::AddNonNegativeConstant(const string &iConst) string NumericalConstants::get(int ID) const { - assert(ID >= 0 && ID < (int) mNumericalConstants.size()); + assert(ID >= 0 && ID < static_cast(mNumericalConstants.size())); return mNumericalConstants[ID]; } double NumericalConstants::getDouble(int ID) const { - assert(ID >= 0 && ID < (int) double_vals.size()); + assert(ID >= 0 && ID < static_cast(double_vals.size())); return (double_vals[ID]); } diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index c46f94b2..dab1623c 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -3022,7 +3022,7 @@ ParsingDriver::add_model_var_or_external_function(const string &function_name, b model_error("Symbol " + function_name + " is being treated as if it were a function (i.e., takes an argument that is not an integer).", ""); - nid = add_model_variable(mod_file->symbol_table.getID(function_name), (int) rv.second); + nid = add_model_variable(mod_file->symbol_table.getID(function_name), static_cast(rv.second)); stack_external_function_args.pop(); return nid; } @@ -3037,7 +3037,7 @@ ParsingDriver::add_model_var_or_external_function(const string &function_name, b if (mod_file->external_functions_table.getNargs(symb_id) == ExternalFunctionsTable::IDNotSet) error("Before using " + function_name +"() in the model block, you must first declare it via the external_function() statement"); - else if ((int) (stack_external_function_args.top().size()) != mod_file->external_functions_table.getNargs(symb_id)) + else if (static_cast(stack_external_function_args.top().size()) != mod_file->external_functions_table.getNargs(symb_id)) error("The number of arguments passed to " + function_name +"() does not match those of a previous call or declaration of this function."); } @@ -3058,7 +3058,7 @@ ParsingDriver::add_model_var_or_external_function(const string &function_name, b { // assume it's a lead/lagged variable declare_exogenous(function_name); - return add_model_variable(mod_file->symbol_table.getID(function_name), (int) rv.second); + return add_model_variable(mod_file->symbol_table.getID(function_name), static_cast(rv.second)); } else error("To use an external function (" + function_name + @@ -3301,7 +3301,7 @@ ParsingDriver::smm_estimation() void ParsingDriver::prior_posterior_function(bool prior_func) { - mod_file->addStatement(make_unique((bool) prior_func, options_list)); + mod_file->addStatement(make_unique(static_cast(prior_func), options_list)); options_list.clear(); } diff --git a/src/Shocks.cc b/src/Shocks.cc index c55ab572..bf0f8684 100644 --- a/src/Shocks.cc +++ b/src/Shocks.cc @@ -52,9 +52,9 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const const expr_t value = it.value; output << "M_.det_shocks = [ M_.det_shocks;" << endl - << "struct('exo_det'," << (int) exo_det + << "struct('exo_det'," << static_cast(exo_det) << ",'exo_id'," << id - << ",'multiplicative'," << (int) mshocks + << ",'multiplicative'," << static_cast(mshocks) << ",'periods'," << period1 << ":" << period2 << ",'value',"; value->writeOutput(output); diff --git a/src/StaticModel.cc b/src/StaticModel.cc index 9d41d45f..99949fd2 100644 --- a/src/StaticModel.cc +++ b/src/StaticModel.cc @@ -269,7 +269,7 @@ StaticModel::computeTemporaryTermsOrdered() getBlockEquationRenormalizedExpr(block, i)->computeTemporaryTerms(reference_count_local, temporary_terms_l, first_occurence_local, block, v_temporary_terms_local, i); else { - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); eq_node->computeTemporaryTerms(reference_count_local, temporary_terms_l, first_occurence_local, block, v_temporary_terms_local, i); } } @@ -296,7 +296,7 @@ StaticModel::computeTemporaryTermsOrdered() getBlockEquationRenormalizedExpr(block, i)->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, block, v_temporary_terms, i); else { - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); eq_node->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, block, v_temporary_terms, i); } } @@ -320,7 +320,7 @@ StaticModel::computeTemporaryTermsOrdered() getBlockEquationRenormalizedExpr(block, i)->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); else { - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); eq_node->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); } } @@ -329,7 +329,7 @@ StaticModel::computeTemporaryTermsOrdered() expr_t id = get<3>(it); id->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); } - for (int i = 0; i < (int) getBlockSize(block); i++) + for (int i = 0; i < static_cast(getBlockSize(block)); i++) for (const auto &it : v_temporary_terms[block][i]) it->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); v_temporary_terms_inuse[block] = temporary_terms_in_use; @@ -454,7 +454,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &basename) const int equation_ID = getBlockEquationID(block, i); EquationType equ_type = getBlockEquationType(block, i); string sModel = symbol_table.getName(symbol_table.getID(SymbolType::endogenous, variable_ID)); - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; tmp_output.str(""); @@ -482,7 +482,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &basename) const rhs->writeOutput(output, local_output_type, local_temporary_terms, {}); output << endl << " "; tmp_output.str(""); - eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i); + eq_node = static_cast(getBlockEquationRenormalizedExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; lhs->writeOutput(output, local_output_type, local_temporary_terms, {}); @@ -793,7 +793,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map fjmp_if_eval.write(code_file, instruction_number); int prev_instruction_number = instruction_number; - for (i = 0; i < (int) block_size; i++) + for (i = 0; i < static_cast(block_size); i++) { //The Temporary terms temporary_terms_t tt2; @@ -804,10 +804,10 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map if (dynamic_cast(it) != nullptr) it->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, false, false, tef_terms); - FNUMEXPR_ fnumexpr(TemporaryTerm, (int)(map_idx.find(it->idx)->second)); + FNUMEXPR_ fnumexpr(TemporaryTerm, static_cast(map_idx.find(it->idx)->second)); fnumexpr.write(code_file, instruction_number); it->compile(code_file, instruction_number, false, tt2, map_idx, false, false, tef_terms); - FSTPST_ fstpst((int)(map_idx.find(it->idx)->second)); + FSTPST_ fstpst(static_cast(map_idx.find(it->idx)->second)); fstpst.write(code_file, instruction_number); // Insert current node into tt2 tt2.insert(it); @@ -829,7 +829,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map } if (equ_type == E_EVALUATE) { - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; rhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, false, false); @@ -837,7 +837,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map } else if (equ_type == E_EVALUATE_S) { - eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i); + eq_node = static_cast(getBlockEquationRenormalizedExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; rhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, false, false); @@ -846,7 +846,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map break; case SOLVE_BACKWARD_COMPLETE: case SOLVE_FORWARD_COMPLETE: - if (i < (int) block_recursive) + if (i < static_cast(block_recursive)) goto evaluation; variable_ID = getBlockVariableID(block, i); equation_ID = getBlockEquationID(block, i); @@ -857,7 +857,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map end: FNUMEXPR_ fnumexpr(ModelEquation, getBlockEquationID(block, i)); fnumexpr.write(code_file, instruction_number); - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; lhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, false, false); @@ -905,12 +905,12 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map { if (!Uf[eqr].Ufl) { - Uf[eqr].Ufl = (Uff_l *) malloc(sizeof(Uff_l)); + Uf[eqr].Ufl = static_cast(malloc(sizeof(Uff_l))); Uf[eqr].Ufl_First = Uf[eqr].Ufl; } else { - Uf[eqr].Ufl->pNext = (Uff_l *) malloc(sizeof(Uff_l)); + Uf[eqr].Ufl->pNext = static_cast(malloc(sizeof(Uff_l))); Uf[eqr].Ufl = Uf[eqr].Ufl->pNext; } Uf[eqr].Ufl->pNext = nullptr; @@ -924,9 +924,9 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map count_u++; } } - for (i = 0; i < (int) block_size; i++) + for (i = 0; i < static_cast(block_size); i++) { - if (i >= (int) block_recursive) + if (i >= static_cast(block_recursive)) { FLDR_ fldr(i-block_recursive); fldr.write(code_file, instruction_number); @@ -984,7 +984,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map temporary_terms_t tt2, tt3; deriv_node_temp_terms_t tef_terms2; - for (i = 0; i < (int) block_size; i++) + for (i = 0; i < static_cast(block_size); i++) { if (v_temporary_terms_local[block].size()) { @@ -993,12 +993,12 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map if (dynamic_cast(it) != nullptr) it->compileExternalFunctionOutput(code_file, instruction_number, false, tt3, map_idx2[block], false, false, tef_terms2); - FNUMEXPR_ fnumexpr(TemporaryTerm, (int)(map_idx2[block].find(it->idx)->second)); + FNUMEXPR_ fnumexpr(TemporaryTerm, static_cast(map_idx2[block].find(it->idx)->second)); fnumexpr.write(code_file, instruction_number); it->compile(code_file, instruction_number, false, tt3, map_idx2[block], false, false, tef_terms); - FSTPST_ fstpst((int)(map_idx2[block].find(it->idx)->second)); + FSTPST_ fstpst(static_cast(map_idx2[block].find(it->idx)->second)); fstpst.write(code_file, instruction_number); // Insert current node into tt2 tt3.insert(it); @@ -1021,7 +1021,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map } if (equ_type == E_EVALUATE) { - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; rhs->compile(code_file, instruction_number, false, tt2, map_idx2[block], false, false); @@ -1029,7 +1029,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map } else if (equ_type == E_EVALUATE_S) { - eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i); + eq_node = static_cast(getBlockEquationRenormalizedExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; rhs->compile(code_file, instruction_number, false, tt2, map_idx2[block], false, false); @@ -1038,7 +1038,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map break; case SOLVE_BACKWARD_COMPLETE: case SOLVE_FORWARD_COMPLETE: - if (i < (int) block_recursive) + if (i < static_cast(block_recursive)) goto evaluation_l; variable_ID = getBlockVariableID(block, i); equation_ID = getBlockEquationID(block, i); @@ -1049,7 +1049,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map end_l: FNUMEXPR_ fnumexpr(ModelEquation, getBlockEquationID(block, i)); fnumexpr.write(code_file, instruction_number); - eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i); + eq_node = static_cast(getBlockEquationExpr(block, i)); lhs = eq_node->arg1; rhs = eq_node->arg2; lhs->compile(code_file, instruction_number, false, tt2, map_idx2[block], false, false); @@ -1155,12 +1155,12 @@ StaticModel::Write_Inf_To_Bin_File_Block(const string &basename, const int &num, } } - for (j = block_recursive; j < (int) block_size; j++) + for (j = block_recursive; j < static_cast(block_size); j++) { unsigned int varr = getBlockVariableID(num, j); SaveCode.write(reinterpret_cast(&varr), sizeof(varr)); } - for (j = block_recursive; j < (int) block_size; j++) + for (j = block_recursive; j < static_cast(block_size); j++) { unsigned int eqr = getBlockEquationID(num, j); SaveCode.write(reinterpret_cast(&eqr), sizeof(eqr)); @@ -2106,7 +2106,7 @@ StaticModel::writeStaticBlockMFSFile(const string &basename) const unsigned int nb_blocks = getNbBlocks(); - for (int b = 0; b < (int) nb_blocks; b++) + for (int b = 0; b < static_cast(nb_blocks); b++) { set local_var; @@ -2119,7 +2119,7 @@ StaticModel::writeStaticBlockMFSFile(const string &basename) const { output << " y_tmp = " << basename << ".block.static_" << b+1 << "(y, x, params);" << endl; ostringstream tmp; - for (int i = 0; i < (int) getBlockSize(b); i++) + for (int i = 0; i < static_cast(getBlockSize(b)); i++) tmp << " " << getBlockVariableID(b, i)+1; output << " var_index = [" << tmp.str() << "];" << endl << " residual = y(var_index) - y_tmp(var_index);" << endl @@ -2146,7 +2146,7 @@ StaticModel::writeOutput(ostream &output, bool block) const return; unsigned int nb_blocks = getNbBlocks(); - for (int b = 0; b < (int) nb_blocks; b++) + for (int b = 0; b < static_cast(nb_blocks); b++) { BlockSimulationType simulation_type = getBlockSimulationType(b); unsigned int block_size = getBlockSize(b); diff --git a/src/StaticModel.hh b/src/StaticModel.hh index 236a989b..ed7b9256 100644 --- a/src/StaticModel.hh +++ b/src/StaticModel.hh @@ -330,13 +330,13 @@ public: int getBlockInitialEquationID(int block_number, int equation_number) const override { - return ((int) inv_equation_reordered[equation_number] - (int) get<1>(block_type_firstequation_size_mfs[block_number])); + return (static_cast(inv_equation_reordered[equation_number]) - static_cast(get<1>(block_type_firstequation_size_mfs[block_number]))); }; //! Return the position of variable_number in the block number belonging to the block block_number int getBlockInitialVariableID(int block_number, int variable_number) const override { - return ((int) inv_variable_reordered[variable_number] - (int) get<1>(block_type_firstequation_size_mfs[block_number])); + return (static_cast(inv_variable_reordered[variable_number]) - static_cast(get<1>(block_type_firstequation_size_mfs[block_number]))); }; //! Return the position of variable_number in the block number belonging to the block block_number int diff --git a/src/SubModel.cc b/src/SubModel.cc index d9deb01d..a8e64d1b 100644 --- a/src/SubModel.cc +++ b/src/SubModel.cc @@ -354,7 +354,7 @@ TrendComponentModelTable::writeOutput(const string &basename, ostream &output) c { int eqn, lag, lhs_symb_id; tie (eqn, lag, lhs_symb_id) = it.first; - int colidx = (int) distance(nontarget_lhs_vec.begin(), find(nontarget_lhs_vec.begin(), nontarget_lhs_vec.end(), lhs_symb_id)); + int colidx = static_cast(distance(nontarget_lhs_vec.begin(), find(nontarget_lhs_vec.begin(), nontarget_lhs_vec.end(), lhs_symb_id))); ar_ec_output << " AR(" << eqn + 1 << ", " << colidx + 1 << ", " << lag << ") = "; it.second->writeOutput(ar_ec_output, ExprNodeOutputType::matlabDynamicModel); ar_ec_output << ";" << endl; @@ -527,7 +527,7 @@ VarModelTable::writeOutput(const string &basename, ostream &output) const { int eqn, lag, lhs_symb_id; tie (eqn, lag, lhs_symb_id) = it.first; - int colidx = (int) distance(lhs.begin(), find(lhs.begin(), lhs.end(), lhs_symb_id)); + int colidx = static_cast(distance(lhs.begin(), find(lhs.begin(), lhs.end(), lhs_symb_id))); ar_output << " ar(" << eqn + 1 << ", " << colidx + 1 << ", " << lag << ") = "; it.second->writeOutput(ar_output, ExprNodeOutputType::matlabDynamicModel); ar_output << ";" << endl; diff --git a/src/SymbolTable.cc b/src/SymbolTable.cc index f2cb2ad2..f7c94502 100644 --- a/src/SymbolTable.cc +++ b/src/SymbolTable.cc @@ -108,7 +108,7 @@ SymbolTable::freeze() noexcept(false) frozen = true; - for (int i = 0; i < (int) symbol_table.size(); i++) + for (int i = 0; i < static_cast(symbol_table.size()); i++) { int tsi; switch (getType(i)) @@ -168,22 +168,22 @@ SymbolTable::getID(SymbolType type, int tsid) const noexcept(false) switch (type) { case SymbolType::endogenous: - if (tsid < 0 || tsid >= (int) endo_ids.size()) + if (tsid < 0 || tsid >= static_cast(endo_ids.size())) throw UnknownTypeSpecificIDException(tsid, type); else return endo_ids[tsid]; case SymbolType::exogenous: - if (tsid < 0 || tsid >= (int) exo_ids.size()) + if (tsid < 0 || tsid >= static_cast(exo_ids.size())) throw UnknownTypeSpecificIDException(tsid, type); else return exo_ids[tsid]; case SymbolType::exogenousDet: - if (tsid < 0 || tsid >= (int) exo_det_ids.size()) + if (tsid < 0 || tsid >= static_cast(exo_det_ids.size())) throw UnknownTypeSpecificIDException(tsid, type); else return exo_det_ids[tsid]; case SymbolType::parameter: - if (tsid < 0 || tsid >= (int) param_ids.size()) + if (tsid < 0 || tsid >= static_cast(param_ids.size())) throw UnknownTypeSpecificIDException(tsid, type); else return param_ids[tsid]; @@ -347,7 +347,7 @@ SymbolTable::writeOutput(ostream &output) const noexcept(false) if (aux_vars.size() == 0) output << "M_.aux_vars = [];" << endl; else - for (int i = 0; i < (int) aux_vars.size(); i++) + for (int i = 0; i < static_cast(aux_vars.size()); i++) { output << "M_.aux_vars(" << i+1 << ").endo_index = " << getTypeSpecificID(aux_vars[i].get_symb_id())+1 << ";" << endl << "M_.aux_vars(" << i+1 << ").type = " << aux_vars[i].get_type_id() << ";" << endl; @@ -475,7 +475,7 @@ SymbolTable::writeCOutput(ostream &output) const noexcept(false) if (aux_vars.size() > 0) { output << "struct aux_vars_t *av[" << aux_vars.size() << "];" << endl; - for (int i = 0; i < (int) aux_vars.size(); i++) + for (int i = 0; i < static_cast(aux_vars.size()); i++) { output << "av[" << i << "].endo_index = " << getTypeSpecificID(aux_vars[i].get_symb_id()) << ";" << endl << "av[" << i << "].type = " << aux_vars[i].get_type_id() << ";" << endl; @@ -580,7 +580,7 @@ SymbolTable::writeCCOutput(ostream &output) const noexcept(false) output << R"(param_names[")" << getName(param_ids[id]) << R"("] = )" << id << ";" << endl; // Write the auxiliary variable table - for (int i = 0; i < (int) aux_vars.size(); i++) + for (int i = 0; i < static_cast(aux_vars.size()); i++) { output << "aux_vars_t av" << i << ";" << endl; output << "av" << i << ".endo_index = " << getTypeSpecificID(aux_vars[i].get_symb_id()) << ";" << endl @@ -987,7 +987,7 @@ SymbolTable::addObservedVariable(int symb_id) noexcept(false) int SymbolTable::observedVariablesNbr() const { - return (int) varobs.size(); + return static_cast(varobs.size()); } bool @@ -1001,7 +1001,7 @@ SymbolTable::getObservedVariableIndex(int symb_id) const { auto it = find(varobs.begin(), varobs.end(), symb_id); assert(it != varobs.end()); - return (int) (it - varobs.begin()); + return static_cast(it - varobs.begin()); } void @@ -1015,7 +1015,7 @@ SymbolTable::addObservedExogenousVariable(int symb_id) noexcept(false) int SymbolTable::observedExogenousVariablesNbr() const { - return (int) varexobs.size(); + return static_cast(varexobs.size()); } bool @@ -1029,7 +1029,7 @@ SymbolTable::getObservedExogenousVariableIndex(int symb_id) const { auto it = find(varexobs.begin(), varexobs.end(), symb_id); assert(it != varexobs.end()); - return (int) (it - varexobs.begin()); + return static_cast(it - varexobs.begin()); } vector diff --git a/src/SymbolTable.hh b/src/SymbolTable.hh index 06dc7214..64bd7b37 100644 --- a/src/SymbolTable.hh +++ b/src/SymbolTable.hh @@ -422,7 +422,7 @@ public: inline void SymbolTable::validateSymbID(int symb_id) const noexcept(false) { - if (symb_id < 0 || symb_id > (int) symbol_table.size()) + if (symb_id < 0 || symb_id > static_cast(symbol_table.size())) throw UnknownSymbolIDException(symb_id); } diff --git a/src/macro/MacroDriver.cc b/src/macro/MacroDriver.cc index 6004f7fc..5214f028 100644 --- a/src/macro/MacroDriver.cc +++ b/src/macro/MacroDriver.cc @@ -356,7 +356,7 @@ MacroDriver::begin_if(const MacroValuePtr &value) noexcept(false) auto ival = dynamic_pointer_cast(value); if (!ival) throw MacroValue::TypeError("Argument of @#if must be an integer"); - last_if = (bool) ival->value; + last_if = static_cast(ival->value); } void diff --git a/src/macro/Makefile.am b/src/macro/Makefile.am index ad1b0685..5317e313 100644 --- a/src/macro/Makefile.am +++ b/src/macro/Makefile.am @@ -19,5 +19,7 @@ libmacro_a_CPPFLAGS = $(BOOST_CPPFLAGS) -I.. MacroFlex.cc: MacroFlex.ll $(LEX) -o MacroFlex.cc MacroFlex.ll +libmacro_a-MacroFlex.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast + MacroBison.cc MacroBison.hh location.hh stack.hh position.hh: MacroBison.yy $(YACC) -W -o MacroBison.cc MacroBison.yy