Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions include/clad/Differentiator/StmtClone.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,11 @@ namespace clang {
namespace clad {
namespace utils {

struct StmtCloneMapping;

class StmtClone : public clang::StmtVisitor<StmtClone, clang::Stmt*> {
public:
// first: original stmt, second: appropriate cloned stmt
typedef llvm::DenseMap<const clang::Stmt*, clang::Stmt*> StmtMapping;
typedef llvm::DenseMap<clang::ValueDecl*, clang::ValueDecl*> DeclMapping;
typedef StmtCloneMapping Mapping;

private:
clang::Sema& m_Sema;
clang::ASTContext& Ctx;
Mapping* m_OriginalToClonedStmts;
// While cloning a PseudoObjectExpr, maps each original OpaqueValueExpr to
// its clone so the syntactic form and the semantic expressions reference
// the same fresh OVE (null outside such a clone). See
Expand All @@ -52,8 +44,8 @@ namespace utils {
clang::VarDecl* CloneDeclOrNull(clang::VarDecl* Node);

public:
StmtClone(clang::Sema& sema, clang::ASTContext& ctx, Mapping* originalToClonedStmts = 0)
: m_Sema(sema), Ctx(ctx), m_OriginalToClonedStmts(originalToClonedStmts) {}
StmtClone(clang::Sema& sema, clang::ASTContext& ctx)
: m_Sema(sema), Ctx(ctx) {}

template<class StmtTy>
StmtTy* Clone(const StmtTy* S);
Expand Down Expand Up @@ -141,22 +133,12 @@ namespace utils {
clang::Stmt* VisitStmt(clang::Stmt*);
};

// Not a StmtClone member class to make it forwardable:
struct StmtCloneMapping {
StmtClone::StmtMapping m_StmtMapping;
StmtClone::DeclMapping m_DeclMapping;
};

template<class StmtTy>
StmtTy* StmtClone::Clone(const StmtTy* S) {
if (!S)
return 0;

clang::Stmt* clonedStmt = Visit(const_cast<StmtTy*>(S));

if (m_OriginalToClonedStmts)
m_OriginalToClonedStmts->m_StmtMapping[S] = clonedStmt;

return static_cast<StmtTy*>(clonedStmt);
}

Expand Down
5 changes: 1 addition & 4 deletions lib/Differentiator/StmtClone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,7 @@ Decl* StmtClone::CloneDecl(Decl* Node) {
if (VD->getInit())
m_Sema.AddInitializerToDecl(cloned_Decl, Clone(VD->getInit()), VD->isDirectInit());
cloned_Decl->setTSCSpec(VD->getTSCSpec());
//cloned_Decl->setDeclaredInCondition(VD->isDeclaredInCondition());
if (m_OriginalToClonedStmts != 0)
m_OriginalToClonedStmts->m_DeclMapping[VD] = cloned_Decl;

// cloned_Decl->setDeclaredInCondition(VD->isDeclaredInCondition());
return cloned_Decl;
}
assert(0 && "other decl clones aren't supported");
Expand Down
Loading