From 760e3c2551cda8001203912ddfbfeff8fbe0f53c Mon Sep 17 00:00:00 2001 From: "petro.zarytskyi" Date: Wed, 6 Mar 2024 18:51:40 +0200 Subject: [PATCH] Apply clang-format --- include/clad/Differentiator/ErrorEstimator.h | 6 +-- .../clad/Differentiator/ExternalRMVSource.h | 3 +- include/clad/Differentiator/VisitorBase.h | 4 +- lib/Differentiator/ErrorEstimator.cpp | 42 +++++++++---------- lib/Differentiator/ReverseModeVisitor.cpp | 3 +- 5 files changed, 28 insertions(+), 30 deletions(-) diff --git a/include/clad/Differentiator/ErrorEstimator.h b/include/clad/Differentiator/ErrorEstimator.h index e7d5548a6..9dc2a5320 100644 --- a/include/clad/Differentiator/ErrorEstimator.h +++ b/include/clad/Differentiator/ErrorEstimator.h @@ -52,8 +52,8 @@ class ErrorEstimationHandler : public ExternalRMVSource { public: using direction = rmv::direction; ErrorEstimationHandler() - : m_FinalError(nullptr), m_RetErrorExpr(nullptr), - m_EstModel(nullptr), m_IdxExpr(nullptr) {} + : m_FinalError(nullptr), m_RetErrorExpr(nullptr), m_EstModel(nullptr), + m_IdxExpr(nullptr) {} ~ErrorEstimationHandler() override = default; /// Function to set the error estimation model currently in use. @@ -74,7 +74,7 @@ class ErrorEstimationHandler : public ExternalRMVSource { /// \param[in] errorExpr The error expression (LHS) of the variable. /// \param[in] addToTheFront A flag to decide whether the error stmts /// should be added to the beginning of the block or the current position. - void AddErrorStmtToBlock(clang::Expr* errorExpr, bool addToTheFront=true); + void AddErrorStmtToBlock(clang::Expr* errorExpr, bool addToTheFront = true); /// Emit the error estimation related statements that were saved to be /// emitted at later points into specific blocks. diff --git a/include/clad/Differentiator/ExternalRMVSource.h b/include/clad/Differentiator/ExternalRMVSource.h index 71bafa45a..4879cc18a 100644 --- a/include/clad/Differentiator/ExternalRMVSource.h +++ b/include/clad/Differentiator/ExternalRMVSource.h @@ -139,7 +139,8 @@ class ExternalRMVSource { } /// This is called just after finalising processing of assignment operator. - virtual void ActBeforeFinalizingAssignOp(clang::Expr*&, clang::Expr*&, clang::Expr*&, + virtual void ActBeforeFinalizingAssignOp(clang::Expr*&, clang::Expr*&, + clang::Expr*&, clang::BinaryOperator::Opcode&){}; /// This is called at that beginning of diff --git a/include/clad/Differentiator/VisitorBase.h b/include/clad/Differentiator/VisitorBase.h index 40d785aae..eabcac02f 100644 --- a/include/clad/Differentiator/VisitorBase.h +++ b/include/clad/Differentiator/VisitorBase.h @@ -427,9 +427,7 @@ namespace clad { /// Build an array subscript expression with a given base expression and /// one index. - clang::Expr* - BuildArraySubscript(clang::Expr* Base, - clang::Expr*& Idx) { + clang::Expr* BuildArraySubscript(clang::Expr* Base, clang::Expr*& Idx) { llvm::SmallVector IS = {Idx}; return BuildArraySubscript(Base, IS); } diff --git a/lib/Differentiator/ErrorEstimator.cpp b/lib/Differentiator/ErrorEstimator.cpp index cca832c16..358e36cfb 100644 --- a/lib/Differentiator/ErrorEstimator.cpp +++ b/lib/Differentiator/ErrorEstimator.cpp @@ -48,15 +48,16 @@ void ErrorEstimationHandler::BuildReturnErrorStmt() { Expr* finExpr = m_EstModel->AssignError(StmtDiff(m_RetErrorExpr, flitr), "return_expr"); m_RMV->addToCurrentBlock( - m_RMV->BuildOp(BO_AddAssign, m_FinalError, finExpr), - direction::forward); + m_RMV->BuildOp(BO_AddAssign, m_FinalError, finExpr), + direction::forward); } } -void ErrorEstimationHandler::AddErrorStmtToBlock(Expr* errorExpr, bool addToTheFront) { +void ErrorEstimationHandler::AddErrorStmtToBlock(Expr* errorExpr, + bool addToTheFront) { Stmt* errorStmt = m_RMV->BuildOp(BO_AddAssign, m_FinalError, errorExpr); - if (addToTheFront) { - auto &block = m_RMV->getCurrentBlock(direction::reverse); + if (addToTheFront) { + auto& block = m_RMV->getCurrentBlock(direction::reverse); block.insert(block.begin(), errorStmt); } else { m_RMV->addToCurrentBlock(errorStmt, direction::reverse); @@ -119,8 +120,7 @@ bool ErrorEstimationHandler::ShouldEstimateErrorFor(VarDecl* VD) { // Get the types on the declartion and initalization expression. QualType varDeclBase = VD->getType(); - QualType varDeclType = - getUnderlyingArrayType(varDeclBase, m_RMV->m_Context); + QualType varDeclType = getUnderlyingArrayType(varDeclBase, m_RMV->m_Context); const Expr* init = VD->getInit(); // If declarationg type in not floating point type, we want to do two // things. @@ -176,7 +176,7 @@ void ErrorEstimationHandler::EmitFinalErrorStmts( auto* paramClone = m_RMV->BuildDeclRef(decl); // Finally emit the error. auto* errorExpr = GetError(paramClone, m_RMV->m_Variables[decl], - params[i]->getNameAsString()); + params[i]->getNameAsString()); m_RMV->addToCurrentBlock( m_RMV->BuildOp(BO_AddAssign, m_FinalError, errorExpr)); } else { @@ -190,8 +190,7 @@ void ErrorEstimationHandler::EmitFinalErrorStmts( m_IdxExpr = m_RMV->BuildDeclRef(idxExprDecl); } Expr* Ldiff = nullptr; - Ldiff = m_RMV->BuildArraySubscript( - LdiffExpr, m_IdxExpr); + Ldiff = m_RMV->BuildArraySubscript(LdiffExpr, m_IdxExpr); auto* paramClone = m_RMV->BuildDeclRef(decl); auto* LRepl = m_RMV->BuildArraySubscript(paramClone, m_IdxExpr); // Build the loop to put in reverse mode. @@ -228,22 +227,22 @@ void ErrorEstimationHandler::EmitUnaryOpErrorStmts(StmtDiff var, // First check if it was registered. // If not, we don't care about it. if (ShouldEstimateErrorFor(cast(DRE->getDecl()))) { - Expr* erroExpr = GetError(DRE, var.getExpr_dx(), - DRE->getDecl()->getNameAsString()); + Expr* erroExpr = + GetError(DRE, var.getExpr_dx(), DRE->getDecl()->getNameAsString()); AddErrorStmtToBlock(erroExpr); } } } -void ErrorEstimationHandler::EmitBinaryOpErrorStmts(Expr* LExpr, Expr* oldValue) { +void ErrorEstimationHandler::EmitBinaryOpErrorStmts(Expr* LExpr, + Expr* oldValue) { // Assign the error. auto decl = GetUnderlyingDeclRefOrNull(LExpr)->getDecl(); if (!ShouldEstimateErrorFor(cast(decl))) - return; + return; bool errorFromFunctionCall = (bool)m_NestedFuncError; - Expr* errorExpr = - UpdateErrorForFuncCallAssigns(this, LExpr, oldValue, - m_NestedFuncError, decl->getNameAsString()); + Expr* errorExpr = UpdateErrorForFuncCallAssigns( + this, LExpr, oldValue, m_NestedFuncError, decl->getNameAsString()); AddErrorStmtToBlock(errorExpr, /*addToTheFront=*/!errorFromFunctionCall); // If there are assign statements to emit in reverse, do that. EmitErrorEstimationStmts(direction::reverse); @@ -262,9 +261,8 @@ void ErrorEstimationHandler::EmitDeclErrorStmts(VarDeclDiff VDDiff, if (VD->getInit() && !GetUnderlyingDeclRefOrNull(VD->getInit())) { bool errorFromFunctionCall = (bool)m_NestedFuncError; Expr* errorExpr = UpdateErrorForFuncCallAssigns( - this, VDRef, - m_RMV->BuildDeclRef(VDDiff.getDecl_dx()), m_NestedFuncError, - VD->getNameAsString()); + this, VDRef, m_RMV->BuildDeclRef(VDDiff.getDecl_dx()), + m_NestedFuncError, VD->getNameAsString()); AddErrorStmtToBlock(errorExpr, /*addToTheFront=*/!errorFromFunctionCall); } } @@ -390,8 +388,8 @@ void ErrorEstimationHandler::ActBeforeFinalizingVisitCallExpr( } void ErrorEstimationHandler::ActBeforeFinalizingAssignOp( - clang::Expr*& LCloned, clang::Expr*& oldValue, - clang::Expr*& R, clang::BinaryOperator::Opcode& opCode) { + clang::Expr*& LCloned, clang::Expr*& oldValue, clang::Expr*& R, + clang::BinaryOperator::Opcode& opCode) { DeclRefExpr* RRef = GetUnderlyingDeclRefOrNull(R); // In the case that an RHS expression is a declReference, we do not emit // any error because the assignment operation entials zero error. diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index fa28c1259..2bcd1a7f7 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -2572,7 +2572,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } else llvm_unreachable("unknown assignment opCode"); if (m_ExternalSource) - m_ExternalSource->ActBeforeFinalizingAssignOp(LCloned, ResultRef, R, opCode); + m_ExternalSource->ActBeforeFinalizingAssignOp(LCloned, ResultRef, R, + opCode); // Output statements from Visit(L). for (auto it = Lblock_begin; it != Lblock_end; ++it)