]> granicus.if.org Git - clang/commitdiff
Allow BumpVectorContext to conditionally own the underlying BumpPtrAllocator.
authorTed Kremenek <kremenek@apple.com>
Mon, 12 Oct 2009 19:54:17 +0000 (19:54 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 12 Oct 2009 19:54:17 +0000 (19:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83884 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/Support/BumpVector.h

index 243332fec0d5c8a53c9ac3344b63ec92757b16bc..a5e11a100665cb824507c172edaa28551fe10b6c 100644 (file)
 
 #include "llvm/Support/type_traits.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/ADT/PointerIntPair.h"
 #include <algorithm>
 
 namespace clang {
   
 class BumpVectorContext {
-  llvm::BumpPtrAllocator Alloc;
+  llvm::PointerIntPair<llvm::BumpPtrAllocator*, 1, bool> Alloc;
 public:
-  llvm::BumpPtrAllocator &getAllocator() { return Alloc; }
+  /// Construct a new BumpVectorContext that creates a new BumpPtrAllocator
+  /// and destroys it when the BumpVectorContext object is destroyed.
+  BumpVectorContext() : Alloc(new llvm::BumpPtrAllocator(), true) {}
+  
+  /// Construct a new BumpVectorContext that reuses an existing
+  /// BumpPtrAllocator.  This BumpPtrAllocator is not destroyed when the
+  /// BumpVectorContext object is destroyed.
+  BumpVectorContext(llvm::BumpPtrAllocator &A) : Alloc(&A, false) {}
+  
+  ~BumpVectorContext() {
+    if (Alloc.getInt())
+      delete Alloc.getPointer();
+  }
+  
+  llvm::BumpPtrAllocator &getAllocator() { return *Alloc.getPointer(); }
 };
   
 template<typename T>