|
22 | 22 | #include "clang/AST/StmtVisitor.h" |
23 | 23 | #include "clang/Basic/Diagnostic.h" |
24 | 24 | #include "clang/Basic/SourceLocation.h" |
| 25 | +#include "clang/Basic/Version.h" |
25 | 26 | #include "clang/Sema/Sema.h" |
26 | | - |
27 | | -#include <llvm/ADT/ArrayRef.h> |
28 | | -#include <llvm/ADT/SmallVector.h> |
| 27 | +#include "llvm/ADT/ArrayRef.h" |
| 28 | +#include "llvm/ADT/SmallVector.h" |
29 | 29 |
|
30 | 30 | #include <array> |
31 | 31 | #include <limits> |
@@ -90,7 +90,7 @@ namespace clad { |
90 | 90 |
|
91 | 91 | unsigned outputArrayCursor = 0; |
92 | 92 | unsigned numParams = 0; |
93 | | - clang::Expr* m_Pullback = nullptr; |
| 93 | + llvm::SmallVector<clang::Expr*, 1> m_Pullback; |
94 | 94 | const char* funcPostfix() const { |
95 | 95 | if (m_DiffReq.Mode == DiffMode::jacobian) |
96 | 96 | return "_jac"; |
@@ -386,6 +386,10 @@ namespace clad { |
386 | 386 | StmtDiff VisitForStmt(const clang::ForStmt* FS); |
387 | 387 | StmtDiff VisitIfStmt(const clang::IfStmt* If); |
388 | 388 | StmtDiff VisitImplicitCastExpr(const clang::ImplicitCastExpr* ICE); |
| 389 | + |
| 390 | +#if CLANG_VERSION_MAJOR > 16 |
| 391 | + StmtDiff VisitLambdaExpr(const clang::LambdaExpr* LE); |
| 392 | +#endif // CLANG_VERSION_MAJOR |
389 | 393 | StmtDiff |
390 | 394 | VisitCXXFunctionalCastExpr(const clang::CXXFunctionalCastExpr* FCE); |
391 | 395 | StmtDiff VisitCStyleCastExpr(const clang::CStyleCastExpr* CSCE); |
@@ -696,8 +700,21 @@ namespace clad { |
696 | 700 | ///\paramp[in] source An external RMV source |
697 | 701 | void AddExternalSource(ExternalRMVSource& source); |
698 | 702 |
|
| 703 | + clang::QualType GetLambdaDerivativeType(const clang::LambdaExpr* LE) { |
| 704 | + clang::FunctionDecl* FD = LE->getCallOperator(); |
| 705 | + llvm::SmallVector<const clang::ValueDecl*, 4> diffParams{}; |
| 706 | + for (const auto* param : FD->parameters()) |
| 707 | + diffParams.push_back(param); |
| 708 | + |
| 709 | + return utils::GetDerivativeType(m_Sema, FD, DiffMode::pullback, |
| 710 | + diffParams, |
| 711 | + /*forCustomDerv=*/false, |
| 712 | + /*shouldUseRestoreTracker=*/false); |
| 713 | + } |
| 714 | + clang::Expr* buildDerivedLambda(const clang::LambdaExpr* LE); |
699 | 715 | /// Builds and returns the sequence of derived function parameters. |
700 | | - void BuildParams(llvm::SmallVectorImpl<clang::ParmVarDecl*>& params); |
| 716 | + void BuildParams(llvm::SmallVectorImpl<clang::ParmVarDecl*>& params, |
| 717 | + const clang::LambdaExpr* LE = nullptr); |
701 | 718 |
|
702 | 719 | /// Stores data required for differentiating a switch statement. |
703 | 720 | struct SwitchStmtInfo { |
|
0 commit comments