aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/CFG.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-10-07 23:09:49 +0000
committerTed Kremenek <kremenek@apple.com>2008-10-07 23:09:49 +0000
commit8ffb159441e923322bef6b5dee1aaf24c738d75e (patch)
tree7de360cf9761bbfea545f1ea1f469dc0a9ae7942 /lib/AST/CFG.cpp
parent2c3352b5d1f5f4546af2f3051a304d84d57c697e (diff)
Migrate DeclStmt over to using a DeclGroup instead of a pointer to a ScopedDecl*.
This also removes the ugly hack needed in CFG.cpp for subclassing DeclStmt to create a DeclStmt with one Decl*. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57275 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/CFG.cpp')
-rw-r--r--lib/AST/CFG.cpp51
1 files changed, 17 insertions, 34 deletions
diff --git a/lib/AST/CFG.cpp b/lib/AST/CFG.cpp
index 2eea6492cd..2a79355a63 100644
--- a/lib/AST/CFG.cpp
+++ b/lib/AST/CFG.cpp
@@ -50,32 +50,6 @@ static SourceLocation GetEndLoc(ScopedDecl* D) {
return D->getLocation();
}
-class VISIBILITY_HIDDEN UnaryDeclStmt : public DeclStmt {
- Stmt* Ex;
-public:
- UnaryDeclStmt(ScopedDecl* D)
- : DeclStmt(D, D->getLocation(), GetEndLoc(D)), Ex(0) {
- if (VarDecl* VD = dyn_cast<VarDecl>(D))
- Ex = VD->getInit();
- }
-
- virtual ~UnaryDeclStmt() {}
- virtual void Destroy(ASTContext& Ctx) { assert(false && "Do not call"); }
-
- virtual child_iterator child_begin() {
- return Ex ? &Ex : 0;
- }
- virtual child_iterator child_end() {
- return Ex ? &Ex + 1 : 0;
- }
- virtual decl_iterator decl_begin() {
- return TheDecl;
- }
- virtual decl_iterator decl_end() {
- return TheDecl ? TheDecl->getNextDeclarator() : 0;
- }
-};
-
/// CFGBuilder - This class implements CFG construction from an AST.
/// The builder is stateful: an instance of the builder should be used to only
/// construct a single CFG.
@@ -395,16 +369,25 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* Terminator, bool AlwaysAddStmt = false) {
Buf.push_back(*DI);
for (BufTy::reverse_iterator I=Buf.rbegin(), E=Buf.rend(); I!=E; ++I) {
- // Get the alignment of UnaryDeclStmt, padding out to >=8 bytes.
- unsigned A = llvm::AlignOf<UnaryDeclStmt>::Alignment < 8
- ? 8 : llvm::AlignOf<UnaryDeclStmt>::Alignment;
+ // Get the alignment of the new DeclStmt, padding out to >=8 bytes.
+ unsigned A = llvm::AlignOf<DeclStmt>::Alignment < 8
+ ? 8 : llvm::AlignOf<DeclStmt>::Alignment;
+
+ // Allocate the DeclStmt using the BumpPtrAllocator. It will
+ // get automatically freed with the CFG. Note that even though
+ // we are using a DeclGroupOwningRef that wraps a singe Decl*,
+ // that Decl* will not get deallocated because the destroy method
+ // of DG is never called.
+ DeclGroupOwningRef DG(*I);
+ ScopedDecl* D = *I;
+ void* Mem = cfg->getAllocator().Allocate(sizeof(DeclStmt), A);
+
+ DeclStmt* DS = new (Mem) DeclStmt(DG, D->getLocation(),
+ GetEndLoc(D));
- // Allocate the UnaryDeclStmt using the BumpPtrAllocator. It will
- // get automatically freed with the CFG.
- void* Mem = cfg->getAllocator().Allocate(sizeof(UnaryDeclStmt), A);
// Append the fake DeclStmt to block.
- Block->appendStmt(new (Mem) UnaryDeclStmt(*I));
- B = WalkAST_VisitDeclSubExpr(*I);
+ Block->appendStmt(DS);
+ B = WalkAST_VisitDeclSubExpr(D);
}
return B;
}