]> granicus.if.org Git - clang/commitdiff
[ASTContext] Add a templated convenience wrapper for Allocate.
authorBenjamin Kramer <benny.kra@googlemail.com>
Tue, 4 Aug 2015 12:34:23 +0000 (12:34 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Tue, 4 Aug 2015 12:34:23 +0000 (12:34 +0000)
This brings ASTContext closer to LLVM's Allocator concept. Ideally we
would just derive ASTContext from llvm::AllocatorBase, but that does
not work because ASTContext's allocator is mutable and we allocate using
const ASTContext& everywhere.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243972 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
lib/AST/Stmt.cpp

index c67fa67ab6b95738cd4bc24e24ab67fdce7be7cf..dc9bc29d8da9ad731222c6573d27b66051b12608 100644 (file)
@@ -501,6 +501,9 @@ public:
   void *Allocate(size_t Size, unsigned Align = 8) const {
     return BumpAlloc.Allocate(Size, Align);
   }
+  template <typename T> T *Allocate(size_t Num = 1) const {
+    return static_cast<T *>(Allocate(Num * sizeof(T), llvm::alignOf<T>()));
+  }
   void Deallocate(void *Ptr) const { }
   
   /// Return the total amount of physical memory allocated for representing
index 771aeefda74df6b6ac7564c3862e26f7b0bb5466..46dce32287588359eaa963f18087b39bbc1dca3d 100644 (file)
@@ -724,7 +724,7 @@ MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
 }
 
 static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
-  return str.copy(C.getAllocator());
+  return str.copy(C);
 }
 
 void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr,