From 44ed0e76fe0c47af7defba68f6af8c4328c6f573 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Thu, 2 Nov 2023 21:26:23 +0200 Subject: [PATCH] Apply suggestions from clang-tidy and clang-format. --- include/clad/Differentiator/StmtClone.h | 6 +-- include/clad/Differentiator/VisitorBase.h | 2 +- lib/Differentiator/StmtClone.cpp | 50 ++++++++++++++++++----- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/include/clad/Differentiator/StmtClone.h b/include/clad/Differentiator/StmtClone.h index ee5d2e801..cf32b813f 100644 --- a/include/clad/Differentiator/StmtClone.h +++ b/include/clad/Differentiator/StmtClone.h @@ -50,10 +50,10 @@ namespace utils { /// Cloning types is necessary since VariableArrayType /// store a pointer to their size expression. - clang::QualType CloneType(const clang::QualType T); + clang::QualType CloneType(clang::QualType T); - // visitor part (not for public use) - // Stmt.def could be used if ABSTR_STMT is introduced + // visitor part (not for public use) + // Stmt.def could be used if ABSTR_STMT is introduced #define DECLARE_CLONE_FN(CLASS) clang::Stmt* Visit ## CLASS(clang::CLASS *Node); DECLARE_CLONE_FN(BinaryOperator) DECLARE_CLONE_FN(UnaryOperator) diff --git a/include/clad/Differentiator/VisitorBase.h b/include/clad/Differentiator/VisitorBase.h index 9036c2c96..08a6201f8 100644 --- a/include/clad/Differentiator/VisitorBase.h +++ b/include/clad/Differentiator/VisitorBase.h @@ -560,7 +560,7 @@ namespace clad { clang::Expr* Clone(const clang::Expr* E); /// Cloning types is necessary since VariableArrayType /// store a pointer to their size expression. - clang::QualType CloneType(const clang::QualType T); + clang::QualType CloneType(clang::QualType T); }; } // end namespace clad diff --git a/lib/Differentiator/StmtClone.cpp b/lib/Differentiator/StmtClone.cpp index 4dbbdd15d..ad7f9256d 100644 --- a/lib/Differentiator/StmtClone.cpp +++ b/lib/Differentiator/StmtClone.cpp @@ -62,7 +62,7 @@ Stmt* StmtClone::Visit ## CLASS(CLASS *Node) \ clad_compat::ExprSetDeps(result, Node); \ return result; \ } - +// NOLINTBEGIN(modernize-use-auto) DEFINE_CLONE_EXPR_CO11(BinaryOperator, (CLAD_COMPAT_CLANG11_Ctx_ExtraParams Clone(Node->getLHS()), Clone(Node->getRHS()), Node->getOpcode(), CloneType(Node->getType()), Node->getValueKind(), Node->getObjectKind(), Node->getOperatorLoc(), Node->getFPFeatures(CLAD_COMPAT_CLANG11_LangOptions_EtraParams))) DEFINE_CLONE_EXPR_CO11(UnaryOperator, (CLAD_COMPAT_CLANG11_Ctx_ExtraParams Clone(Node->getSubExpr()), Node->getOpcode(), CloneType(Node->getType()), Node->getValueKind(), Node->getObjectKind(), Node->getOperatorLoc() CLAD_COMPAT_CLANG7_UnaryOperator_ExtraParams CLAD_COMPAT_CLANG11_UnaryOperator_ExtraParams)) Stmt* StmtClone::VisitDeclRefExpr(DeclRefExpr *Node) { @@ -102,14 +102,42 @@ Stmt* StmtClone::VisitMemberExpr(MemberExpr* Node) { return result; } DEFINE_CLONE_EXPR(CompoundLiteralExpr, (Node->getLParenLoc(), Node->getTypeSourceInfo(), CloneType(Node->getType()), Node->getValueKind(), Clone(Node->getInitializer()), Node->isFileScope())) -DEFINE_CREATE_EXPR(ImplicitCastExpr, (Ctx, CloneType(Node->getType()), Node->getCastKind(), Clone(Node->getSubExpr()), 0, Node->getValueKind() /*EP*/CLAD_COMPAT_CLANG12_CastExpr_GetFPO(Node) )) -DEFINE_CREATE_EXPR(CStyleCastExpr, (Ctx, CloneType(Node->getType()), Node->getValueKind(), Node->getCastKind(), Clone(Node->getSubExpr()), 0 /*EP*/CLAD_COMPAT_CLANG12_CastExpr_GetFPO(Node), Node->getTypeInfoAsWritten(), Node->getLParenLoc(), Node->getRParenLoc())) -DEFINE_CREATE_EXPR(CXXStaticCastExpr, (Ctx, CloneType(Node->getType()), Node->getValueKind(), Node->getCastKind(), Clone(Node->getSubExpr()), 0, Node->getTypeInfoAsWritten() /*EP*/CLAD_COMPAT_CLANG12_CastExpr_GetFPO(Node), Node->getOperatorLoc(), Node->getRParenLoc(), Node->getAngleBrackets())) -DEFINE_CREATE_EXPR(CXXDynamicCastExpr, (Ctx, CloneType(Node->getType()), Node->getValueKind(), Node->getCastKind(), Clone(Node->getSubExpr()), 0, Node->getTypeInfoAsWritten(), Node->getOperatorLoc(), Node->getRParenLoc(), Node->getAngleBrackets())) -DEFINE_CREATE_EXPR(CXXReinterpretCastExpr, (Ctx, CloneType(Node->getType()), Node->getValueKind(), Node->getCastKind(), Clone(Node->getSubExpr()), 0, Node->getTypeInfoAsWritten(), Node->getOperatorLoc(), Node->getRParenLoc(), Node->getAngleBrackets())) +DEFINE_CREATE_EXPR( + ImplicitCastExpr, + (Ctx, CloneType(Node->getType()), Node->getCastKind(), + Clone(Node->getSubExpr()), nullptr, + Node->getValueKind() /*EP*/ CLAD_COMPAT_CLANG12_CastExpr_GetFPO(Node))) +DEFINE_CREATE_EXPR(CStyleCastExpr, + (Ctx, CloneType(Node->getType()), Node->getValueKind(), + Node->getCastKind(), Clone(Node->getSubExpr()), + nullptr /*EP*/ CLAD_COMPAT_CLANG12_CastExpr_GetFPO(Node), + Node->getTypeInfoAsWritten(), Node->getLParenLoc(), + Node->getRParenLoc())) +DEFINE_CREATE_EXPR( + CXXStaticCastExpr, + (Ctx, CloneType(Node->getType()), Node->getValueKind(), Node->getCastKind(), + Clone(Node->getSubExpr()), nullptr, + Node->getTypeInfoAsWritten() /*EP*/ CLAD_COMPAT_CLANG12_CastExpr_GetFPO( + Node), + Node->getOperatorLoc(), Node->getRParenLoc(), Node->getAngleBrackets())) +DEFINE_CREATE_EXPR(CXXDynamicCastExpr, + (Ctx, CloneType(Node->getType()), Node->getValueKind(), + Node->getCastKind(), Clone(Node->getSubExpr()), nullptr, + Node->getTypeInfoAsWritten(), Node->getOperatorLoc(), + Node->getRParenLoc(), Node->getAngleBrackets())) +DEFINE_CREATE_EXPR(CXXReinterpretCastExpr, + (Ctx, CloneType(Node->getType()), Node->getValueKind(), + Node->getCastKind(), Clone(Node->getSubExpr()), nullptr, + Node->getTypeInfoAsWritten(), Node->getOperatorLoc(), + Node->getRParenLoc(), Node->getAngleBrackets())) DEFINE_CREATE_EXPR(CXXConstCastExpr, (Ctx, CloneType(Node->getType()), Node->getValueKind(), Clone(Node->getSubExpr()), Node->getTypeInfoAsWritten(), Node->getOperatorLoc(), Node->getRParenLoc(), Node->getAngleBrackets())) DEFINE_CREATE_EXPR(CXXConstructExpr, (Ctx, CloneType(Node->getType()), Node->getLocation(), Node->getConstructor(), Node->isElidable(), clad_compat::makeArrayRef(Node->getArgs(), Node->getNumArgs()), Node->hadMultipleCandidates(), Node->isListInitialization(), Node->isStdInitListInitialization(), Node->requiresZeroInitialization(), Node->getConstructionKind(), Node->getParenOrBraceRange())) -DEFINE_CREATE_EXPR(CXXFunctionalCastExpr, (Ctx, CloneType(Node->getType()), Node->getValueKind(), Node->getTypeInfoAsWritten(), Node->getCastKind(), Clone(Node->getSubExpr()), 0 /*EP*/CLAD_COMPAT_CLANG12_CastExpr_GetFPO(Node), Node->getLParenLoc(), Node->getRParenLoc())) +DEFINE_CREATE_EXPR(CXXFunctionalCastExpr, + (Ctx, CloneType(Node->getType()), Node->getValueKind(), + Node->getTypeInfoAsWritten(), Node->getCastKind(), + Clone(Node->getSubExpr()), + nullptr /*EP*/ CLAD_COMPAT_CLANG12_CastExpr_GetFPO(Node), + Node->getLParenLoc(), Node->getRParenLoc())) DEFINE_CREATE_EXPR(ExprWithCleanups, (Ctx, Node->getSubExpr(), Node->cleanupsHaveSideEffects(), {})) // clang <= 7 do not have `ConstantExpr` node. @@ -140,8 +168,9 @@ DEFINE_CLONE_EXPR(SubstNonTypeTemplateParmExpr, (CloneType(Node->getType()), Nod DEFINE_CLONE_EXPR(SubstNonTypeTemplateParmExpr, (CloneType(Node->getType()), Node->getValueKind(), Node->getBeginLoc(), Node->getReplacement(), Node->getAssociatedDecl(), Node->getIndex(), Node->getPackIndex(), Node->isReferenceParameter())); #endif DEFINE_CREATE_EXPR(PseudoObjectExpr, (Ctx, Node->getSyntacticForm(), llvm::SmallVector(Node->semantics_begin(), Node->semantics_end()), Node->getResultExprIndex())) -//BlockExpr -//BlockDeclRefExpr +// NOLINTEND(modernize-use-auto) +// BlockExpr +// BlockDeclRefExpr Stmt* StmtClone::VisitStringLiteral(StringLiteral* Node) { llvm::SmallVector concatLocations(Node->tokloc_begin(), @@ -447,9 +476,8 @@ bool ReferencesUpdater::VisitStmt(clang::Stmt* S) { } void ReferencesUpdater::updateType(QualType QT) { - if (auto* varArrType = dyn_cast(QT)) { + if (const auto* varArrType = dyn_cast(QT)) TraverseStmt(varArrType->getSizeExpr()); - } } QualType StmtClone::CloneType(const clang::QualType T) {