From 1864d5d2ef3148fae9cad55bef373a8c0074acaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Fri, 27 Dec 2024 15:24:47 +0100 Subject: [PATCH] clang-format: reindent using the RemoveParentheses option However do not set that option permanently (and also disable RemoveSemicolon by default), since the clang-format manual states that these options can lead to incorrect formatting and thus their result should be carefully reviewed. --- .clang-format | 3 ++- src/DataTree.hh | 2 +- src/ExprNode.cc | 26 +++++++++++++------------- src/ModelTree.cc | 2 +- src/macro/Expressions.cc | 10 +++++----- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/.clang-format b/.clang-format index 21875122..585a91f5 100644 --- a/.clang-format +++ b/.clang-format @@ -15,7 +15,8 @@ InsertNewlineAtEOF: true PackConstructorInitializers: NextLine PPIndentWidth: 1 PointerAlignment: Left -RemoveSemicolon: true +# RemoveParentheses: ReturnStatement +# RemoveSemicolon: true SpaceAfterTemplateKeyword: false SpaceBeforeParens: ControlStatements SpaceBeforeCpp11BracedList: true diff --git a/src/DataTree.hh b/src/DataTree.hh index 38ff89ac..98b2206a 100644 --- a/src/DataTree.hh +++ b/src/DataTree.hh @@ -402,7 +402,7 @@ DataTree::AddPossiblyNegativeConstant(double v) if (isnan(v)) return NaN; if (isinf(v)) - return (v < 0 ? MinusInfinity : Infinity); + return v < 0 ? MinusInfinity : Infinity; bool neg = false; if (v < 0) diff --git a/src/ExprNode.cc b/src/ExprNode.cc index 30eae4f1..ec54ec3d 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -6458,9 +6458,9 @@ TrinaryOpNode::eval_opcode(double v1, TrinaryOpcode op_code, double v2, double v switch (op_code) { case TrinaryOpcode::normcdf: - return (0.5 * (1 + erf((v1 - v2) / v3 / numbers::sqrt2))); + return 0.5 * (1 + erf((v1 - v2) / v3 / numbers::sqrt2)); case TrinaryOpcode::normpdf: - return (1 / (v3 * sqrt(2 * numbers::pi) * exp(pow((v1 - v2) / v3, 2) / 2))); + return 1 / (v3 * sqrt(2 * numbers::pi) * exp(pow((v1 - v2) / v3, 2) / 2)); } __builtin_unreachable(); // Silence GCC warning } @@ -6989,9 +6989,9 @@ TrinaryOpNode::isVariableNodeEqualTo([[maybe_unused]] SymbolType type_arg, bool TrinaryOpNode::containsPacExpectation(const string& pac_model_name) const { - return (arg1->containsPacExpectation(pac_model_name) - || arg2->containsPacExpectation(pac_model_name) - || arg3->containsPacExpectation(pac_model_name)); + return arg1->containsPacExpectation(pac_model_name) + || arg2->containsPacExpectation(pac_model_name) + || arg3->containsPacExpectation(pac_model_name); } bool @@ -7907,7 +7907,7 @@ ExternalFunctionNode::sameTefTermPredicate() const { return [this](expr_t e) { auto e2 = dynamic_cast<ExternalFunctionNode*>(e); - return (e2 != nullptr && e2->symb_id == symb_id && e2->arguments == arguments); + return e2 != nullptr && e2->symb_id == symb_id && e2->arguments == arguments; }; } @@ -8245,12 +8245,12 @@ FirstDerivExternalFunctionNode::sameTefTermPredicate() const if (first_deriv_symb_id == symb_id) return [this](expr_t e) { auto e2 = dynamic_cast<ExternalFunctionNode*>(e); - return (e2 && e2->symb_id == symb_id && e2->arguments == arguments); + return e2 && e2->symb_id == symb_id && e2->arguments == arguments; }; else return [this](expr_t e) { auto e2 = dynamic_cast<FirstDerivExternalFunctionNode*>(e); - return (e2 && e2->symb_id == symb_id && e2->arguments == arguments); + return e2 && e2->symb_id == symb_id && e2->arguments == arguments; }; } @@ -8600,12 +8600,12 @@ SecondDerivExternalFunctionNode::sameTefTermPredicate() const if (second_deriv_symb_id == symb_id) return [this](expr_t e) { auto e2 = dynamic_cast<ExternalFunctionNode*>(e); - return (e2 && e2->symb_id == symb_id && e2->arguments == arguments); + return e2 && e2->symb_id == symb_id && e2->arguments == arguments; }; else return [this](expr_t e) { auto e2 = dynamic_cast<SecondDerivExternalFunctionNode*>(e); - return (e2 && e2->symb_id == symb_id && e2->arguments == arguments); + return e2 && e2->symb_id == symb_id && e2->arguments == arguments; }; } @@ -9491,9 +9491,9 @@ ExprNode::matchParamTimesTargetMinusVariable(int symb_id) const auto& avi = datatree.symbol_table.getAuxVarInfo(target->symb_id); if (avi.type == AuxVarType::pacTargetNonstationary && target->lag == -1) return true; - return (avi.type == AuxVarType::unaryOp && avi.unary_op == "log" && avi.orig_symb_id - && !datatree.symbol_table.isAuxiliaryVariable(*avi.orig_symb_id) - && target->lag + avi.orig_lead_lag.value() == -1); + return avi.type == AuxVarType::unaryOp && avi.unary_op == "log" && avi.orig_symb_id + && !datatree.symbol_table.isAuxiliaryVariable(*avi.orig_symb_id) + && target->lag + avi.orig_lead_lag.value() == -1; } else return target->lag == -1; diff --git a/src/ModelTree.cc b/src/ModelTree.cc index 70a4cd03..2e49f9ec 100644 --- a/src/ModelTree.cc +++ b/src/ModelTree.cc @@ -895,7 +895,7 @@ ModelTree::determineLinearBlocks() int ModelTree::equation_number() const { - return (equations.size()); + return equations.size(); } void diff --git a/src/macro/Expressions.cc b/src/macro/Expressions.cc index 04a33a8b..2fbfe9dd 100644 --- a/src/macro/Expressions.cc +++ b/src/macro/Expressions.cc @@ -241,9 +241,9 @@ Real::normpdf(const BaseTypePtr& btp1, const BaseTypePtr& btp2) const auto btp22 = dynamic_pointer_cast<Real>(btp2); if (!btp12 || !btp22) throw StackTrace("Type mismatch for operands of `normpdf` operator"); - return make_shared<Real>((1 - / (btp22->value * std::sqrt(2 * numbers::pi) - * std::exp(pow((value - btp12->value) / btp22->value, 2) / 2)))); + return make_shared<Real>(1 + / (btp22->value * std::sqrt(2 * numbers::pi) + * std::exp(pow((value - btp12->value) / btp22->value, 2) / 2))); } RealPtr @@ -254,7 +254,7 @@ Real::normcdf(const BaseTypePtr& btp1, const BaseTypePtr& btp2) const if (!btp12 || !btp22) throw StackTrace("Type mismatch for operands of `normpdf` operator"); return make_shared<Real>( - (0.5 * (1 + std::erf((value - btp12->value) / btp22->value / numbers::sqrt2)))); + 0.5 * (1 + std::erf((value - btp12->value) / btp22->value / numbers::sqrt2))); } BaseTypePtr @@ -314,7 +314,7 @@ String::is_equal(const BaseTypePtr& btp) const BoolPtr String::cast_bool([[maybe_unused]] Environment& env) const { - auto f = [](const char& a, const char& b) { return (tolower(a) == tolower(b)); }; + auto f = [](const char& a, const char& b) { return tolower(a) == tolower(b); }; if (ranges::equal(value, "true"s, f)) return make_shared<Bool>(true); -- GitLab