C++17 modernization: convert the remaining enums to enum classes

issue#70
Sébastien Villemot 2021-02-01 11:10:59 +01:00
parent ce09f6620a
commit 89e2daf7c7
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
4 changed files with 221 additions and 217 deletions

File diff suppressed because it is too large Load Diff

View File

@ -927,7 +927,7 @@ DynamicModel::writeDynamicBytecode(const string &basename) const
int symb = getSymbIDByDerivID(deriv_id); int symb = getSymbIDByDerivID(deriv_id);
int var = symbol_table.getTypeSpecificID(symb); int var = symbol_table.getTypeSpecificID(symb);
int lag = getLagByDerivID(deriv_id); int lag = getLagByDerivID(deriv_id);
FNUMEXPR_ fnumexpr(FirstEndoDerivative, eq, var, lag); FNUMEXPR_ fnumexpr(ExpressionType::FirstEndoDerivative, eq, var, lag);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
if (!my_derivatives[eq].size()) if (!my_derivatives[eq].size())
my_derivatives[eq].clear(); my_derivatives[eq].clear();
@ -986,7 +986,7 @@ DynamicModel::writeDynamicBytecode(const string &basename) const
{ {
auto [lag, var, eq] = it.first; auto [lag, var, eq] = it.first;
expr_t d1 = it.second; expr_t d1 = it.second;
FNUMEXPR_ fnumexpr(FirstEndoDerivative, eq, var, lag); FNUMEXPR_ fnumexpr(ExpressionType::FirstEndoDerivative, eq, var, lag);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
if (prev_var != var || prev_lag != lag) if (prev_var != var || prev_lag != lag)
{ {
@ -1005,7 +1005,7 @@ DynamicModel::writeDynamicBytecode(const string &basename) const
{ {
auto [lag, ignore, var, eq] = it.first; auto [lag, ignore, var, eq] = it.first;
expr_t d1 = it.second; expr_t d1 = it.second;
FNUMEXPR_ fnumexpr(FirstExoDerivative, eq, var, lag); FNUMEXPR_ fnumexpr(ExpressionType::FirstExoDerivative, eq, var, lag);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
if (prev_var != var || prev_lag != lag) if (prev_var != var || prev_lag != lag)
{ {
@ -1130,7 +1130,7 @@ DynamicModel::writeDynamicBlockBytecode(const string &basename) const
if (dynamic_cast<AbstractExternalFunctionNode *>(it)) if (dynamic_cast<AbstractExternalFunctionNode *>(it))
it->compileExternalFunctionOutput(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, true, false, tef_terms); it->compileExternalFunctionOutput(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, true, false, tef_terms);
FNUMEXPR_ fnumexpr(TemporaryTerm, static_cast<int>(blocks_temporary_terms_idxs.at(it))); FNUMEXPR_ fnumexpr(ExpressionType::TemporaryTerm, static_cast<int>(blocks_temporary_terms_idxs.at(it)));
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
it->compile(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, true, false, tef_terms); it->compile(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, true, false, tef_terms);
FSTPT_ fstpt(static_cast<int>(blocks_temporary_terms_idxs.at(it))); FSTPT_ fstpt(static_cast<int>(blocks_temporary_terms_idxs.at(it)));
@ -1161,7 +1161,7 @@ DynamicModel::writeDynamicBlockBytecode(const string &basename) const
case BlockSimulationType::evaluateForward: case BlockSimulationType::evaluateForward:
equ_type = getBlockEquationType(block, i); equ_type = getBlockEquationType(block, i);
{ {
FNUMEXPR_ fnumexpr(ModelEquation, getBlockEquationID(block, i)); FNUMEXPR_ fnumexpr(ExpressionType::ModelEquation, getBlockEquationID(block, i));
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
} }
if (equ_type == EquationType::evaluate) if (equ_type == EquationType::evaluate)
@ -1194,7 +1194,7 @@ DynamicModel::writeDynamicBlockBytecode(const string &basename) const
goto end; goto end;
default: default:
end: end:
FNUMEXPR_ fnumexpr(ModelEquation, getBlockEquationID(block, i)); FNUMEXPR_ fnumexpr(ExpressionType::ModelEquation, getBlockEquationID(block, i));
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
eq_node = getBlockEquationExpr(block, i); eq_node = getBlockEquationExpr(block, i);
lhs = eq_node->arg1; lhs = eq_node->arg1;
@ -1228,7 +1228,7 @@ DynamicModel::writeDynamicBlockBytecode(const string &basename) const
case BlockSimulationType::solveBackwardSimple: case BlockSimulationType::solveBackwardSimple:
case BlockSimulationType::solveForwardSimple: case BlockSimulationType::solveForwardSimple:
{ {
FNUMEXPR_ fnumexpr(FirstEndoDerivative, getBlockEquationID(block, 0), getBlockVariableID(block, 0), 0); FNUMEXPR_ fnumexpr(ExpressionType::FirstEndoDerivative, getBlockEquationID(block, 0), getBlockVariableID(block, 0), 0);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
} }
compileDerivative(code_file, instruction_number, getBlockEquationID(block, 0), getBlockVariableID(block, 0), 0, temporary_terms_union, blocks_temporary_terms_idxs); compileDerivative(code_file, instruction_number, getBlockEquationID(block, 0), getBlockVariableID(block, 0), 0, temporary_terms_union, blocks_temporary_terms_idxs);
@ -1268,7 +1268,7 @@ DynamicModel::writeDynamicBlockBytecode(const string &basename) const
Uf[eqr].Ufl->u = count_u; Uf[eqr].Ufl->u = count_u;
Uf[eqr].Ufl->var = varr; Uf[eqr].Ufl->var = varr;
Uf[eqr].Ufl->lag = lag; Uf[eqr].Ufl->lag = lag;
FNUMEXPR_ fnumexpr(FirstEndoDerivative, eqr, varr, lag); FNUMEXPR_ fnumexpr(ExpressionType::FirstEndoDerivative, eqr, varr, lag);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
compileChainRuleDerivative(code_file, instruction_number, block, eq, var, lag, temporary_terms_union, blocks_temporary_terms_idxs); compileChainRuleDerivative(code_file, instruction_number, block, eq, var, lag, temporary_terms_union, blocks_temporary_terms_idxs);
FSTPU_ fstpu(count_u); FSTPU_ fstpu(count_u);
@ -1337,7 +1337,7 @@ DynamicModel::writeDynamicBlockBytecode(const string &basename) const
auto [eq, var, lag] = indices; auto [eq, var, lag] = indices;
int eqr = getBlockEquationID(block, eq); int eqr = getBlockEquationID(block, eq);
int varr = getBlockVariableID(block, var); int varr = getBlockVariableID(block, var);
FNUMEXPR_ fnumexpr(FirstEndoDerivative, eqr, varr, lag); FNUMEXPR_ fnumexpr(ExpressionType::FirstEndoDerivative, eqr, varr, lag);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
compileDerivative(code_file, instruction_number, eqr, varr, lag, temporary_terms_union, blocks_temporary_terms_idxs); compileDerivative(code_file, instruction_number, eqr, varr, lag, temporary_terms_union, blocks_temporary_terms_idxs);
FSTPG3_ fstpg3(eq, var, lag, blocks_jacob_cols_endo[block].at({ var, lag })); FSTPG3_ fstpg3(eq, var, lag, blocks_jacob_cols_endo[block].at({ var, lag }));
@ -1348,7 +1348,7 @@ DynamicModel::writeDynamicBlockBytecode(const string &basename) const
auto [eqr, var, lag] = indices; auto [eqr, var, lag] = indices;
int eq = getBlockEquationID(block, eqr); int eq = getBlockEquationID(block, eqr);
int varr = 0; // Dummy value, actually unused by the bytecode MEX int varr = 0; // Dummy value, actually unused by the bytecode MEX
FNUMEXPR_ fnumexpr(FirstExoDerivative, eqr, varr, lag); FNUMEXPR_ fnumexpr(ExpressionType::FirstExoDerivative, eqr, varr, lag);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
d->compile(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, true, false); d->compile(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, true, false);
FSTPG3_ fstpg3(eq, var, lag, blocks_jacob_cols_exo[block].at({ var, lag })); FSTPG3_ fstpg3(eq, var, lag, blocks_jacob_cols_exo[block].at({ var, lag }));
@ -1359,7 +1359,7 @@ DynamicModel::writeDynamicBlockBytecode(const string &basename) const
auto [eqr, var, lag] = indices; auto [eqr, var, lag] = indices;
int eq = getBlockEquationID(block, eqr); int eq = getBlockEquationID(block, eqr);
int varr = 0; // Dummy value, actually unused by the bytecode MEX int varr = 0; // Dummy value, actually unused by the bytecode MEX
FNUMEXPR_ fnumexpr(FirstExodetDerivative, eqr, varr, lag); FNUMEXPR_ fnumexpr(ExpressionType::FirstExodetDerivative, eqr, varr, lag);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
d->compile(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, true, false); d->compile(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, true, false);
FSTPG3_ fstpg3(eq, var, lag, blocks_jacob_cols_exo_det[block].at({ var, lag })); FSTPG3_ fstpg3(eq, var, lag, blocks_jacob_cols_exo_det[block].at({ var, lag }));
@ -1370,7 +1370,7 @@ DynamicModel::writeDynamicBlockBytecode(const string &basename) const
auto [eqr, var, lag] = indices; auto [eqr, var, lag] = indices;
int eq = getBlockEquationID(block, eqr); int eq = getBlockEquationID(block, eqr);
int varr = 0; // Dummy value, actually unused by the bytecode MEX int varr = 0; // Dummy value, actually unused by the bytecode MEX
FNUMEXPR_ fnumexpr(FirstOtherEndoDerivative, eqr, varr, lag); FNUMEXPR_ fnumexpr(ExpressionType::FirstOtherEndoDerivative, eqr, varr, lag);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
d->compile(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, true, false); d->compile(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, true, false);
FSTPG3_ fstpg3(eq, var, lag, blocks_jacob_cols_other_endo[block].at({ var, lag })); FSTPG3_ fstpg3(eq, var, lag, blocks_jacob_cols_other_endo[block].at({ var, lag }));

View File

@ -1263,7 +1263,7 @@ ModelTree::compileTemporaryTerms(ostream &code_file, unsigned int &instruction_n
if (dynamic_cast<AbstractExternalFunctionNode *>(tt)) if (dynamic_cast<AbstractExternalFunctionNode *>(tt))
tt->compileExternalFunctionOutput(code_file, instruction_number, false, temporary_terms_union, temporary_terms_idxs, dynamic, steady_dynamic, tef_terms); tt->compileExternalFunctionOutput(code_file, instruction_number, false, temporary_terms_union, temporary_terms_idxs, dynamic, steady_dynamic, tef_terms);
FNUMEXPR_ fnumexpr(TemporaryTerm, idx); FNUMEXPR_ fnumexpr(ExpressionType::TemporaryTerm, idx);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
tt->compile(code_file, instruction_number, false, temporary_terms_union, temporary_terms_idxs, dynamic, steady_dynamic, tef_terms); tt->compile(code_file, instruction_number, false, temporary_terms_union, temporary_terms_idxs, dynamic, steady_dynamic, tef_terms);
if (dynamic) if (dynamic)
@ -1399,7 +1399,7 @@ ModelTree::compileModelEquations(ostream &code_file, unsigned int &instruction_n
BinaryOpNode *eq_node = equations[eq]; BinaryOpNode *eq_node = equations[eq];
expr_t lhs = eq_node->arg1; expr_t lhs = eq_node->arg1;
expr_t rhs = eq_node->arg2; expr_t rhs = eq_node->arg2;
FNUMEXPR_ fnumexpr(ModelEquation, eq); FNUMEXPR_ fnumexpr(ExpressionType::ModelEquation, eq);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
// Test if the right hand side of the equation is empty. // Test if the right hand side of the equation is empty.
double vrhs = 1.0; double vrhs = 1.0;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2003-2020 Dynare Team * Copyright © 2003-2021 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -442,7 +442,7 @@ StaticModel::writeStaticBytecode(const string &basename) const
int eq = indices[0]; int eq = indices[0];
int symb = getSymbIDByDerivID(deriv_id); int symb = getSymbIDByDerivID(deriv_id);
int var = symbol_table.getTypeSpecificID(symb); int var = symbol_table.getTypeSpecificID(symb);
FNUMEXPR_ fnumexpr(FirstEndoDerivative, eq, var); FNUMEXPR_ fnumexpr(ExpressionType::FirstEndoDerivative, eq, var);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
if (!my_derivatives[eq].size()) if (!my_derivatives[eq].size())
my_derivatives[eq].clear(); my_derivatives[eq].clear();
@ -504,7 +504,7 @@ StaticModel::writeStaticBytecode(const string &basename) const
int eq = indices[0]; int eq = indices[0];
int symb = getSymbIDByDerivID(deriv_id); int symb = getSymbIDByDerivID(deriv_id);
int var = symbol_table.getTypeSpecificID(symb); int var = symbol_table.getTypeSpecificID(symb);
FNUMEXPR_ fnumexpr(FirstEndoDerivative, eq, var); FNUMEXPR_ fnumexpr(ExpressionType::FirstEndoDerivative, eq, var);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
if (!my_derivatives[eq].size()) if (!my_derivatives[eq].size())
my_derivatives[eq].clear(); my_derivatives[eq].clear();
@ -628,7 +628,7 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
if (dynamic_cast<AbstractExternalFunctionNode *>(it)) if (dynamic_cast<AbstractExternalFunctionNode *>(it))
it->compileExternalFunctionOutput(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, false, false, tef_terms); it->compileExternalFunctionOutput(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, false, false, tef_terms);
FNUMEXPR_ fnumexpr(TemporaryTerm, static_cast<int>(blocks_temporary_terms_idxs.at(it))); FNUMEXPR_ fnumexpr(ExpressionType::TemporaryTerm, static_cast<int>(blocks_temporary_terms_idxs.at(it)));
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
it->compile(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, false, false, tef_terms); it->compile(code_file, instruction_number, false, temporary_terms_union, blocks_temporary_terms_idxs, false, false, tef_terms);
FSTPST_ fstpst(static_cast<int>(blocks_temporary_terms_idxs.at(it))); FSTPST_ fstpst(static_cast<int>(blocks_temporary_terms_idxs.at(it)));
@ -651,7 +651,7 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
case BlockSimulationType::evaluateForward: case BlockSimulationType::evaluateForward:
equ_type = getBlockEquationType(block, i); equ_type = getBlockEquationType(block, i);
{ {
FNUMEXPR_ fnumexpr(ModelEquation, getBlockEquationID(block, i)); FNUMEXPR_ fnumexpr(ExpressionType::ModelEquation, getBlockEquationID(block, i));
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
} }
if (equ_type == EquationType::evaluate) if (equ_type == EquationType::evaluate)
@ -682,7 +682,7 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
goto end; goto end;
default: default:
end: end:
FNUMEXPR_ fnumexpr(ModelEquation, getBlockEquationID(block, i)); FNUMEXPR_ fnumexpr(ExpressionType::ModelEquation, getBlockEquationID(block, i));
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
eq_node = getBlockEquationExpr(block, i); eq_node = getBlockEquationExpr(block, i);
lhs = eq_node->arg1; lhs = eq_node->arg1;
@ -712,7 +712,7 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
case BlockSimulationType::solveBackwardSimple: case BlockSimulationType::solveBackwardSimple:
case BlockSimulationType::solveForwardSimple: case BlockSimulationType::solveForwardSimple:
{ {
FNUMEXPR_ fnumexpr(FirstEndoDerivative, 0, 0); FNUMEXPR_ fnumexpr(ExpressionType::FirstEndoDerivative, 0, 0);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
} }
compileDerivative(code_file, instruction_number, getBlockEquationID(block, 0), getBlockVariableID(block, 0), temporary_terms_union, blocks_temporary_terms_idxs); compileDerivative(code_file, instruction_number, getBlockEquationID(block, 0), getBlockVariableID(block, 0), temporary_terms_union, blocks_temporary_terms_idxs);
@ -745,7 +745,7 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
Uf[eqr].Ufl->pNext = nullptr; Uf[eqr].Ufl->pNext = nullptr;
Uf[eqr].Ufl->u = count_u; Uf[eqr].Ufl->u = count_u;
Uf[eqr].Ufl->var = varr; Uf[eqr].Ufl->var = varr;
FNUMEXPR_ fnumexpr(FirstEndoDerivative, eqr, varr); FNUMEXPR_ fnumexpr(ExpressionType::FirstEndoDerivative, eqr, varr);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
compileChainRuleDerivative(code_file, instruction_number, block, eq, var, 0, temporary_terms_union, blocks_temporary_terms_idxs); compileChainRuleDerivative(code_file, instruction_number, block, eq, var, 0, temporary_terms_union, blocks_temporary_terms_idxs);
FSTPSU_ fstpsu(count_u); FSTPSU_ fstpsu(count_u);
@ -827,7 +827,7 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
case BlockSimulationType::evaluateForward: case BlockSimulationType::evaluateForward:
equ_type = getBlockEquationType(block, i); equ_type = getBlockEquationType(block, i);
{ {
FNUMEXPR_ fnumexpr(ModelEquation, getBlockEquationID(block, i)); FNUMEXPR_ fnumexpr(ExpressionType::ModelEquation, getBlockEquationID(block, i));
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
} }
if (equ_type == EquationType::evaluate) if (equ_type == EquationType::evaluate)
@ -858,7 +858,7 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
goto end_l; goto end_l;
default: default:
end_l: end_l:
FNUMEXPR_ fnumexpr(ModelEquation, getBlockEquationID(block, i)); FNUMEXPR_ fnumexpr(ExpressionType::ModelEquation, getBlockEquationID(block, i));
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
eq_node = getBlockEquationExpr(block, i); eq_node = getBlockEquationExpr(block, i);
lhs = eq_node->arg1; lhs = eq_node->arg1;
@ -886,7 +886,7 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
case BlockSimulationType::solveBackwardSimple: case BlockSimulationType::solveBackwardSimple:
case BlockSimulationType::solveForwardSimple: case BlockSimulationType::solveForwardSimple:
{ {
FNUMEXPR_ fnumexpr(FirstEndoDerivative, 0, 0); FNUMEXPR_ fnumexpr(ExpressionType::FirstEndoDerivative, 0, 0);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
} }
compileDerivative(code_file, instruction_number, getBlockEquationID(block, 0), getBlockVariableID(block, 0), temporary_terms_union, blocks_temporary_terms_idxs); compileDerivative(code_file, instruction_number, getBlockEquationID(block, 0), getBlockVariableID(block, 0), temporary_terms_union, blocks_temporary_terms_idxs);
@ -905,7 +905,7 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
auto &[eq, var, ignore] = indices; auto &[eq, var, ignore] = indices;
int eqr = getBlockEquationID(block, eq); int eqr = getBlockEquationID(block, eq);
int varr = getBlockVariableID(block, var); int varr = getBlockVariableID(block, var);
FNUMEXPR_ fnumexpr(FirstEndoDerivative, eqr, varr, 0); FNUMEXPR_ fnumexpr(ExpressionType::FirstEndoDerivative, eqr, varr, 0);
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
compileChainRuleDerivative(code_file, instruction_number, block, eq, var, 0, temporary_terms_union, blocks_temporary_terms_idxs); compileChainRuleDerivative(code_file, instruction_number, block, eq, var, 0, temporary_terms_union, blocks_temporary_terms_idxs);