diff --git a/mex/sources/bytecode/ErrorHandling.hh b/mex/sources/bytecode/ErrorHandling.hh index 32ccc6987c5527e219721d4d9925adb9860bf658..59deb438b008a1dea7da5a3633ec65a5c0a930f9 100644 --- a/mex/sources/bytecode/ErrorHandling.hh +++ b/mex/sources/bytecode/ErrorHandling.hh @@ -419,7 +419,10 @@ public: inline string print_expression(it_code_type it_code, bool evaluate, int size, int block_num, bool steady_state, int Per_u_, int it_, it_code_type &it_code_ret, bool compute) const { - int var, lag = 0, op, eq; + int var, lag{0}, eq; + UnaryOpcode op1; + BinaryOpcode op2; + TrinaryOpcode op3; stack<string> Stack; stack<double> Stackf; ostringstream tmp_out, tmp_out2; @@ -480,7 +483,7 @@ public: break; case Tags::FLDV: //load a variable in the processor - switch (static_cast<SymbolType>(static_cast<FLDV_ *>(it_code->second)->get_type())) + switch (static_cast<FLDV_ *>(it_code->second)->get_type()) { case SymbolType::parameter: var = static_cast<FLDV_ *>(it_code->second)->get_pos(); @@ -540,7 +543,7 @@ public: case Tags::FLDSV: case Tags::FLDVS: //load a variable in the processor - switch (static_cast<SymbolType>(static_cast<FLDSV_ *>(it_code->second)->get_type())) + switch (static_cast<FLDSV_ *>(it_code->second)->get_type()) { case SymbolType::parameter: var = static_cast<FLDSV_ *>(it_code->second)->get_pos(); @@ -647,7 +650,7 @@ public: case Tags::FSTPV: //load a variable in the processor go_on = false; - switch (static_cast<SymbolType>(static_cast<FSTPV_ *>(it_code->second)->get_type())) + switch (static_cast<FSTPV_ *>(it_code->second)->get_type()) { case SymbolType::parameter: var = static_cast<FSTPV_ *>(it_code->second)->get_pos(); @@ -722,7 +725,7 @@ public: case Tags::FSTPSV: go_on = false; //load a variable in the processor - switch (static_cast<SymbolType>(static_cast<FSTPSV_ *>(it_code->second)->get_type())) + switch (static_cast<FSTPSV_ *>(it_code->second)->get_type()) { case SymbolType::parameter: var = static_cast<FSTPSV_ *>(it_code->second)->get_pos(); @@ -916,7 +919,7 @@ public: } break; case Tags::FBINARY: - op = static_cast<FBINARY_ *>(it_code->second)->get_op_type(); + op2 = static_cast<FBINARY_ *>(it_code->second)->get_op_type(); v2 = Stack.top(); Stack.pop(); v1 = Stack.top(); @@ -928,7 +931,7 @@ public: v1f = Stackf.top(); Stackf.pop(); } - switch (static_cast<BinaryOpcode>(op)) + switch (op2) { case BinaryOpcode::plus: if (compute) @@ -1188,12 +1191,12 @@ public: break; case BinaryOpcode::equal: default: - mexPrintf("Error unknown Unary operator=%d\n", op); mexEvalString("drawnow;"); + mexPrintf("Error unknown binary operator=%d\n", static_cast<int>(op2)); mexEvalString("drawnow;"); ; } break; case Tags::FUNARY: - op = static_cast<FUNARY_ *>(it_code->second)->get_op_type(); + op1 = static_cast<FUNARY_ *>(it_code->second)->get_op_type(); v1 = Stack.top(); Stack.pop(); if (compute) @@ -1201,7 +1204,7 @@ public: v1f = Stackf.top(); Stackf.pop(); } - switch (static_cast<UnaryOpcode>(op)) + switch (op1) { case UnaryOpcode::uminus: if (compute) @@ -1351,12 +1354,12 @@ public: Stack.push(tmp_out.str()); break; default: - mexPrintf("Error unknown Binary operator=%d\n", op); mexEvalString("drawnow;"); + mexPrintf("Error unknown unary operator=%d\n", static_cast<int>(op1)); mexEvalString("drawnow;"); ; } break; case Tags::FTRINARY: - op = static_cast<FTRINARY_ *>(it_code->second)->get_op_type(); + op3 = static_cast<FTRINARY_ *>(it_code->second)->get_op_type(); v3 = Stack.top(); Stack.pop(); v2 = Stack.top(); @@ -1372,7 +1375,7 @@ public: v1f = Stackf.top(); Stackf.pop(); } - switch (static_cast<TrinaryOpcode>(op)) + switch (op3) { case TrinaryOpcode::normcdf: if (compute) @@ -1389,7 +1392,7 @@ public: Stack.push(tmp_out.str()); break; default: - mexPrintf("Error unknown Trinary operator=%d\n", op); mexEvalString("drawnow;"); + mexPrintf("Error unknown trinary operator=%d\n", static_cast<int>(op3)); mexEvalString("drawnow;"); } break; case Tags::FCALL: diff --git a/mex/sources/bytecode/Evaluate.cc b/mex/sources/bytecode/Evaluate.cc index 55a2b2ecbd412540d2716e589ecdede746857e57..983f5892abf1b83ff3868d5afc934be6b935a3be 100644 --- a/mex/sources/bytecode/Evaluate.cc +++ b/mex/sources/bytecode/Evaluate.cc @@ -102,7 +102,10 @@ Evaluate::log10_1(double a) void Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) { - int var = 0, lag = 0, op; + int var{0}, lag{0}; + UnaryOpcode op1; + BinaryOpcode op2; + TrinaryOpcode op3; unsigned int eq, pos_col; ostringstream tmp_out; double v1, v2, v3; @@ -200,7 +203,7 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) break; case Tags::FLDV: //load a variable in the processor - switch (static_cast<SymbolType>(static_cast<FLDV_ *>(it_code->second)->get_type())) + switch (static_cast<FLDV_ *>(it_code->second)->get_type()) { case SymbolType::parameter: var = static_cast<FLDV_ *>(it_code->second)->get_pos(); @@ -253,7 +256,7 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) break; case Tags::FLDSV: //load a variable in the processor - switch (static_cast<SymbolType>(static_cast<FLDSV_ *>(it_code->second)->get_type())) + switch (static_cast<FLDSV_ *>(it_code->second)->get_type()) { case SymbolType::parameter: var = static_cast<FLDSV_ *>(it_code->second)->get_pos(); @@ -301,7 +304,7 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) break; case Tags::FLDVS: //load a variable in the processor - switch (static_cast<SymbolType>(static_cast<FLDVS_ *>(it_code->second)->get_type())) + switch (static_cast<FLDVS_ *>(it_code->second)->get_type()) { case SymbolType::parameter: var = static_cast<FLDVS_ *>(it_code->second)->get_pos(); @@ -411,7 +414,7 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) break; case Tags::FSTPV: //load a variable in the processor - switch (static_cast<SymbolType>(static_cast<FSTPV_ *>(it_code->second)->get_type())) + switch (static_cast<FSTPV_ *>(it_code->second)->get_type()) { case SymbolType::parameter: var = static_cast<FSTPV_ *>(it_code->second)->get_pos(); @@ -461,7 +464,7 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) break; case Tags::FSTPSV: //load a variable in the processor - switch (static_cast<SymbolType>(static_cast<FSTPSV_ *>(it_code->second)->get_type())) + switch (static_cast<FSTPSV_ *>(it_code->second)->get_type()) { case SymbolType::parameter: var = static_cast<FSTPSV_ *>(it_code->second)->get_pos(); @@ -676,15 +679,15 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) break; case Tags::FBINARY: - op = static_cast<FBINARY_ *>(it_code->second)->get_op_type(); + op2 = static_cast<FBINARY_ *>(it_code->second)->get_op_type(); #ifdef DEBUG - mexPrintf("FBINARY, op=%d\n", op); + mexPrintf("FBINARY, op=%d\n", static_cast<int>(op2)); #endif v2 = Stack.top(); Stack.pop(); v1 = Stack.top(); Stack.pop(); - switch (static_cast<BinaryOpcode>(op)) + switch (op2) { case BinaryOpcode::plus: Stack.push(v1 + v2); @@ -826,18 +829,18 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) { mexPrintf("Error\n"); throw FatalExceptionHandling(" in compute_block_time, unknown binary operator " - + to_string(op) + "\n"); + + to_string(static_cast<int>(op2)) + "\n"); } } break; case Tags::FUNARY: - op = static_cast<FUNARY_ *>(it_code->second)->get_op_type(); + op1 = static_cast<FUNARY_ *>(it_code->second)->get_op_type(); v1 = Stack.top(); Stack.pop(); #ifdef DEBUG - mexPrintf("FUNARY, op=%d\n", op); + mexPrintf("FUNARY, op=%d\n", static_cast<int>(op1)); #endif - switch (static_cast<UnaryOpcode>(op)) + switch (op1) { case UnaryOpcode::uminus: Stack.push(-v1); @@ -979,19 +982,19 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) default: { mexPrintf("Error\n"); - throw FatalExceptionHandling(" in compute_block_time, unknown unary operator " + to_string(op) + "\n"); + throw FatalExceptionHandling(" in compute_block_time, unknown unary operator " + to_string(static_cast<int>(op1)) + "\n"); } } break; case Tags::FTRINARY: - op = static_cast<FTRINARY_ *>(it_code->second)->get_op_type(); + op3 = static_cast<FTRINARY_ *>(it_code->second)->get_op_type(); v3 = Stack.top(); Stack.pop(); v2 = Stack.top(); Stack.pop(); v1 = Stack.top(); Stack.pop(); - switch (static_cast<TrinaryOpcode>(op)) + switch (op3) { case TrinaryOpcode::normcdf: Stack.push(0.5*(1+erf((v1-v2)/v3/M_SQRT2))); @@ -1008,7 +1011,7 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) default: { mexPrintf("Error\n"); - throw FatalExceptionHandling(" in compute_block_time, unknown trinary operator " + to_string(op) + "\n"); + throw FatalExceptionHandling(" in compute_block_time, unknown trinary operator " + to_string(static_cast<int>(op3)) + "\n"); } } break; @@ -1457,7 +1460,7 @@ Evaluate::solve_simple_over_periods(bool forward) } void -Evaluate::set_block(int size_arg, int type_arg, string file_name_arg, string bin_base_name_arg, int block_num_arg, +Evaluate::set_block(int size_arg, BlockSimulationType type_arg, string file_name_arg, string bin_base_name_arg, int block_num_arg, bool is_linear_arg, int symbol_table_endo_nbr_arg, int Block_List_Max_Lag_arg, int Block_List_Max_Lead_arg, int u_count_int_arg, int block_arg) { size = size_arg; diff --git a/mex/sources/bytecode/Evaluate.hh b/mex/sources/bytecode/Evaluate.hh index 9feace69da4959c2a1954e0080f8244ada86e75b..9c4ad93b93c5055f7c98582a0fb50852f3354120 100644 --- a/mex/sources/bytecode/Evaluate.hh +++ b/mex/sources/bytecode/Evaluate.hh @@ -67,13 +67,14 @@ protected: bool print_it, forward; int minimal_solving_periods; - int type, block_num, symbol_table_endo_nbr, Block_List_Max_Lag, Block_List_Max_Lead, u_count_int, block; + BlockSimulationType type; + int block_num, symbol_table_endo_nbr, Block_List_Max_Lag, Block_List_Max_Lead, u_count_int, block; string file_name, bin_base_name; bool Gaussian_Elimination, is_linear; public: bool steady_state; Evaluate(int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool print_it_arg, bool steady_state_arg, int periods_arg, int minimal_solving_periods_arg); - void set_block(int size_arg, int type_arg, string file_name_arg, string bin_base_name_arg, int block_num_arg, + void set_block(int size_arg, BlockSimulationType type_arg, string file_name_arg, string bin_base_name_arg, int block_num_arg, bool is_linear_arg, int symbol_table_endo_nbr_arg, int Block_List_Max_Lag_arg, int Block_List_Max_Lead_arg, int u_count_int_arg, int block_arg); void evaluate_complete(bool no_derivatives); bool compute_complete(bool no_derivatives, double &res1, double &res2, double &max_res, int &max_res_idx); diff --git a/mex/sources/bytecode/Interpreter.cc b/mex/sources/bytecode/Interpreter.cc index a3b3d3a9a1b3d2fb7d81dcf3df67ea6f22de04c7..7690be1d58aaba5c00553c4a8c45fea19e291f79 100644 --- a/mex/sources/bytecode/Interpreter.cc +++ b/mex/sources/bytecode/Interpreter.cc @@ -70,7 +70,7 @@ Interpreter::evaluate_a_block(bool initialization) { it_code_type begining; - switch (static_cast<BlockSimulationType>(type)) + switch (type) { case BlockSimulationType::evaluateForward: if (steady_state) @@ -314,7 +314,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_ mexPrintf("simulate_a_block type = %d, periods=%d, y_kmin=%d, y_kmax=%d\n", type, periods, y_kmin, y_kmax); mexEvalString("drawnow;"); #endif - switch (static_cast<BlockSimulationType>(type)) + switch (type) { case BlockSimulationType::evaluateForward: #ifdef DEBUG @@ -503,7 +503,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_ End_Solver(); break; default: - throw FatalExceptionHandling(" in simulate_a_block, Unknown type = " + to_string(type) + "\n"); + throw FatalExceptionHandling(" in simulate_a_block, Unknown type = " + to_string(static_cast<int>(type)) + "\n"); return ERROR_ON_EXIT; } return NO_ERROR_ON_EXIT; @@ -585,8 +585,8 @@ Interpreter::check_for_controlled_exo_validity(FBEGINBLOCK_ *fb, const vector<s_ + ")\n You should not use block in model options\n"); else if (find(endogenous.begin(), endogenous.end(), it.exo_num) != endogenous.end() && find(exogenous.begin(), exogenous.end(), it.var_num) != exogenous.end() - && (fb->get_type() == static_cast<uint8_t>(BlockSimulationType::evaluateForward) - || fb->get_type() == static_cast<uint8_t>(BlockSimulationType::evaluateBackward))) + && (fb->get_type() == BlockSimulationType::evaluateForward + || fb->get_type() == BlockSimulationType::evaluateBackward)) throw FatalExceptionHandling("\n the conditional forecast cannot be implemented for the block=" + to_string(Block_Count+1) + ") that has to be evaluated instead to be solved\n You should not use block in model options\n"); else if (find(previous_block_exogenous.begin(), previous_block_exogenous.end(), it.var_num) diff --git a/preprocessor b/preprocessor index 2ea6a5244e38b6babbd56a5e9773e5434dd246cb..5cd5676c8e937d0cb603feaf1d9f780122c13fd8 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit 2ea6a5244e38b6babbd56a5e9773e5434dd246cb +Subproject commit 5cd5676c8e937d0cb603feaf1d9f780122c13fd8