]> granicus.if.org Git - clang/commitdiff
start switching decls over to using an allocator controlled by ASTContext.
authorChris Lattner <sabre@nondot.org>
Sat, 15 Mar 2008 06:12:44 +0000 (06:12 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 15 Mar 2008 06:12:44 +0000 (06:12 +0000)
Right now only some ctors are switched over.  I need to switch them all
over so I can change the dtor over.

This lets us experiment with region allocation and other things in the
future.

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

AST/ASTContext.cpp
AST/Decl.cpp
Driver/RewriteTest.cpp
Sema/Sema.cpp
Sema/SemaDecl.cpp
include/clang/AST/ASTContext.h
include/clang/AST/Decl.h

index 3d312fa4a8081747c441ea58a6e6d62370bce73d..ad54010c50005693e4ccfdd830b65facee3cf54a 100644 (file)
@@ -1047,9 +1047,9 @@ QualType ASTContext::maxIntegerType(QualType lhs, QualType rhs) {
 // getCFConstantStringType - Return the type used for constant CFStrings. 
 QualType ASTContext::getCFConstantStringType() {
   if (!CFConstantStringTypeDecl) {
-    CFConstantStringTypeDecl = new RecordDecl(Decl::Struct, SourceLocation(), 
-                                              &Idents.get("NSConstantString"),
-                                              0);
+    CFConstantStringTypeDecl = 
+      RecordDecl::Create(Decl::Struct, SourceLocation(), 
+                         &Idents.get("NSConstantString"), 0, *this);
     QualType FieldTypes[4];
   
     // const int *isa;
index 32ca4198f56cbf476f8b09276dba94706d6018d6..aad8f212bfe704d220afe38f4ac350b83db28727 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "llvm/ADT/DenseMap.h"
@@ -200,6 +201,37 @@ void Decl::addDeclKind(Kind k) {
   }
 }
 
+//===----------------------------------------------------------------------===//
+// Decl Allocation/Deallocation Method Implementations
+//===----------------------------------------------------------------------===//
+
+EnumConstantDecl *EnumConstantDecl::Create(SourceLocation L, IdentifierInfo *Id,
+                                           QualType T, Expr *E, 
+                                           const llvm::APSInt &V, 
+                                           ScopedDecl *PrevDecl, ASTContext &C){
+  void *Mem = C.getAllocator().Allocate<EnumConstantDecl>();
+  return new (Mem) EnumConstantDecl(L, Id, T, E, V, PrevDecl);
+}
+
+TypedefDecl *TypedefDecl::Create(SourceLocation L, IdentifierInfo *Id,
+                                 QualType T, ScopedDecl *PD, ASTContext &C) {
+  void *Mem = C.getAllocator().Allocate<TypedefDecl>();
+  return new (Mem) TypedefDecl(L, Id, T, PD);
+}
+
+EnumDecl *EnumDecl::Create(SourceLocation L, IdentifierInfo *Id,
+                           ScopedDecl *PrevDecl, ASTContext &C) {
+  void *Mem = C.getAllocator().Allocate<EnumDecl>();
+  return new (Mem) EnumDecl(L, Id, PrevDecl);
+}
+
+RecordDecl *RecordDecl::Create(Kind DK, SourceLocation L, IdentifierInfo *Id, 
+                               ScopedDecl *PrevDecl, ASTContext &C) {
+  void *Mem = C.getAllocator().Allocate<RecordDecl>();
+  return new (Mem) RecordDecl(DK, L, Id, PrevDecl);
+}
+
+
 //===----------------------------------------------------------------------===//
 // Decl Implementation
 //===----------------------------------------------------------------------===//
@@ -292,7 +324,6 @@ FieldDecl* RecordDecl::getMember(IdentifierInfo *name) {
   return 0;
 }
 
-
 //===----------------------------------------------------------------------===//
 // Objective-C Decl Implementation
 //===----------------------------------------------------------------------===//
index e947f243f21495cfca140ccf6b4f41431f0817e5..652ce1c82c3256f6e733cdcd24f888cc8ba67b29 100644 (file)
@@ -796,7 +796,7 @@ Stmt *RewriteTest::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) {
         std::string RecName = clsDeclared->getIdentifier()->getName();
         RecName += "_IMPL";
         IdentifierInfo *II = &Context->Idents.get(RecName.c_str());
-        RecordDecl *RD = new RecordDecl(Decl::Struct, SourceLocation(), II, 0);
+        RecordDecl *RD = RecordDecl::Create(Decl::Struct, SourceLocation(), II, 0, *Context);
         assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl");
         QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
         CastExpr *castExpr = new CastExpr(castT, IV->getBase(), SourceLocation());
@@ -1622,8 +1622,9 @@ void RewriteTest::SynthMsgSendFunctionDecl() {
 void RewriteTest::SynthMsgSendSuperFunctionDecl() {
   IdentifierInfo *msgSendIdent = &Context->Idents.get("objc_msgSendSuper");
   llvm::SmallVector<QualType, 16> ArgTys;
-  RecordDecl *RD = new RecordDecl(Decl::Struct, SourceLocation(),
-                                  &Context->Idents.get("objc_super"), 0);
+  RecordDecl *RD = RecordDecl::Create(Decl::Struct, SourceLocation(),
+                                      &Context->Idents.get("objc_super"), 0,
+                                      *Context);
   QualType argT = Context->getPointerType(Context->getTagDeclType(RD));
   assert(!argT.isNull() && "Can't build 'struct objc_super *' type");
   ArgTys.push_back(argT);
@@ -1662,8 +1663,9 @@ void RewriteTest::SynthMsgSendSuperStretFunctionDecl() {
   IdentifierInfo *msgSendIdent = 
     &Context->Idents.get("objc_msgSendSuper_stret");
   llvm::SmallVector<QualType, 16> ArgTys;
-  RecordDecl *RD = new RecordDecl(Decl::Struct, SourceLocation(),
-                                  &Context->Idents.get("objc_super"), 0);
+  RecordDecl *RD = RecordDecl::Create(Decl::Struct, SourceLocation(),
+                                      &Context->Idents.get("objc_super"), 0,
+                                      *Context);
   QualType argT = Context->getPointerType(Context->getTagDeclType(RD));
   assert(!argT.isNull() && "Can't build 'struct objc_super *' type");
   ArgTys.push_back(argT);
@@ -1758,35 +1760,41 @@ Stmt *RewriteTest::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) {
 
 ObjCInterfaceDecl *RewriteTest::isSuperReceiver(Expr *recExpr) {
   // check if we are sending a message to 'super'
-  if (CurMethodDecl && CurMethodDecl->isInstance()) {
-    if (CastExpr *CE = dyn_cast<CastExpr>(recExpr)) {
-      if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr())) {
-        if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
-          if (!strcmp(PVD->getName(), "self")) {
-            // is this id<P1..> type?
-            if (CE->getType()->isObjCQualifiedIdType())
-              return 0;
-            if (const PointerType *PT = CE->getType()->getAsPointerType()) {
-              if (ObjCInterfaceType *IT = 
-                    dyn_cast<ObjCInterfaceType>(PT->getPointeeType())) {
-                if (IT->getDecl() == 
-                    CurMethodDecl->getClassInterface()->getSuperClass())
-                  return IT->getDecl();
-              }
-            }
-          }
-        }
-      }
-    }
-  }
-  return 0;
+  if (!CurMethodDecl || !CurMethodDecl->isInstance()) return 0;
+  
+  CastExpr *CE = dyn_cast<CastExpr>(recExpr);
+  if (!CE) return 0;
+  
+  DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr());
+  if (!DRE) return 0;
+  
+  ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl());
+  if (!PVD) return 0;
+  
+  if (strcmp(PVD->getName(), "self") != 0)
+    return 0;
+          
+  // is this id<P1..> type?
+  if (CE->getType()->isObjCQualifiedIdType())
+    return 0;
+  const PointerType *PT = CE->getType()->getAsPointerType();
+  if (!PT) return 0;
+  
+  ObjCInterfaceType *IT = dyn_cast<ObjCInterfaceType>(PT->getPointeeType());
+  if (!IT) return 0;
+  
+  if (IT->getDecl() != CurMethodDecl->getClassInterface()->getSuperClass())
+    return 0;
+              
+  return IT->getDecl();
 }
 
 // struct objc_super { struct objc_object *receiver; struct objc_class *super; };
 QualType RewriteTest::getSuperStructType() {
   if (!SuperStructDecl) {
-    SuperStructDecl = new RecordDecl(Decl::Struct, SourceLocation(), 
-                                     &Context->Idents.get("objc_super"), 0);
+    SuperStructDecl = RecordDecl::Create(Decl::Struct, SourceLocation(), 
+                                         &Context->Idents.get("objc_super"), 0,
+                                         *Context);
     QualType FieldTypes[2];
   
     // struct objc_object *receiver;
@@ -1806,8 +1814,9 @@ QualType RewriteTest::getSuperStructType() {
 
 QualType RewriteTest::getConstantStringStructType() {
   if (!ConstantStringDecl) {
-    ConstantStringDecl = new RecordDecl(Decl::Struct, SourceLocation(), 
-                                     &Context->Idents.get("__NSConstantStringImpl"), 0);
+    ConstantStringDecl = RecordDecl::Create(Decl::Struct, SourceLocation(), 
+                         &Context->Idents.get("__NSConstantStringImpl"), 0,
+                                            *Context);
     QualType FieldTypes[4];
   
     // struct objc_object *receiver;
index 5b7a3094d12d00a382f329781ce11fec2f4de0b0..d8549198beb53d764addc13be962cf255c9b1732 100644 (file)
@@ -59,15 +59,16 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
   TUScope->AddDecl(IDecl);
   
   // Synthesize "typedef struct objc_selector *SEL;"
-  RecordDecl *SelTag = new RecordDecl(Decl::Struct, SourceLocation(), 
-                                      &Context.Idents.get("objc_selector"), 0);
+  RecordDecl *SelTag = RecordDecl::Create(Decl::Struct, SourceLocation(), 
+                                          &Context.Idents.get("objc_selector"),
+                                          0, Context);
   SelTag->getIdentifier()->setFETokenInfo(SelTag);
   TUScope->AddDecl(SelTag);
   
   QualType SelT = Context.getPointerType(Context.getTagDeclType(SelTag));
-  TypedefDecl *SelTypedef = new TypedefDecl(SourceLocation(),
-                                            &Context.Idents.get("SEL"),
-                                            SelT, 0);
+  TypedefDecl *SelTypedef = TypedefDecl::Create(SourceLocation(),
+                                                &Context.Idents.get("SEL"),
+                                                SelT, 0, Context);
   SelTypedef->getIdentifier()->setFETokenInfo(SelTypedef);
   TUScope->AddDecl(SelTypedef);
   Context.setObjCSelType(SelTypedef);
@@ -96,12 +97,12 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer)
   // and make sure the decls get inserted into TUScope!
   if (PP.getLangOptions().ObjC1) {
     // Synthesize "typedef struct objc_class *Class;"
-    RecordDecl *ClassTag = new RecordDecl(Decl::Struct, SourceLocation(), 
-                                          &IT.get("objc_class"), 0);
+    RecordDecl *ClassTag = RecordDecl::Create(Decl::Struct, SourceLocation(), 
+                                              &IT.get("objc_class"), 0,Context);
     QualType ClassT = Context.getPointerType(Context.getTagDeclType(ClassTag));
-    TypedefDecl *ClassTypedef = new TypedefDecl(SourceLocation(),
-                                                &Context.Idents.get("Class"),
-                                                ClassT, 0);
+    TypedefDecl *ClassTypedef = 
+      TypedefDecl::Create(SourceLocation(), &Context.Idents.get("Class"),
+                          ClassT, 0, Context);
     Context.setObjCClassType(ClassTypedef);
     
     // Synthesize "@class Protocol;
@@ -110,15 +111,16 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer)
     Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl));
     
     // Synthesize "typedef struct objc_object { Class isa; } *id;"
-    RecordDecl *ObjectTag = new RecordDecl(Decl::Struct, SourceLocation(), 
-                                          &IT.get("objc_object"), 0);
+    RecordDecl *ObjectTag = 
+      RecordDecl::Create(Decl::Struct, SourceLocation(), &IT.get("objc_object"),
+                         0, Context);
     FieldDecl *IsaDecl = new FieldDecl(SourceLocation(), 0, 
                                        Context.getObjCClassType());
     ObjectTag->defineBody(&IsaDecl, 1);
     QualType ObjT = Context.getPointerType(Context.getTagDeclType(ObjectTag));
-    TypedefDecl *IdTypedef = new TypedefDecl(SourceLocation(),
-                                             &Context.Idents.get("id"),
-                                             ObjT, 0);
+    TypedefDecl *IdTypedef = TypedefDecl::Create(SourceLocation(),
+                                                 &Context.Idents.get("id"),
+                                                 ObjT, 0, Context);
     Context.setObjCIdType(IdTypedef);
   }
   TUScope = 0;
index 300a38259b6c2903f95038d16f4bc563163c3c09..90f9133d4b8272a53c15105a25df84fa8200c1be 100644 (file)
@@ -1175,8 +1175,9 @@ TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
   assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
   
   // Scope manipulation handled by caller.
-  TypedefDecl *NewTD = new TypedefDecl(D.getIdentifierLoc(), D.getIdentifier(), 
-                                       T, LastDeclarator);
+  TypedefDecl *NewTD = TypedefDecl::Create(D.getIdentifierLoc(), 
+                                           D.getIdentifier(), 
+                                           T, LastDeclarator, Context);
   if (D.getInvalidType())
     NewTD->setInvalidDecl();
   return NewTD;
@@ -1255,7 +1256,7 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK,
   case Decl::Enum:
     // FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
     // enum X { A, B, C } D;    D should chain to X.
-    New = new EnumDecl(Loc, Name, 0);
+    New = EnumDecl::Create(Loc, Name, 0, Context);
     // If this is an undefined enum, warn.
     if (TK != TK_Definition) Diag(Loc, diag::ext_forward_ref_enum);
     break;
@@ -1264,7 +1265,7 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK,
   case Decl::Class:
     // FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
     // struct X { int A; } D;    D should chain to X.
-    New = new RecordDecl(Kind, Loc, Name, 0);
+    New = RecordDecl::Create(Kind, Loc, Name, 0, Context);
     break;
   }    
   
@@ -1577,8 +1578,9 @@ Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl,
     }
   }
   
-  EnumConstantDecl *New = new EnumConstantDecl(IdLoc, Id, EltTy, Val, EnumVal,
-                                               LastEnumConst);
+  EnumConstantDecl *New = 
+    EnumConstantDecl::Create(IdLoc, Id, EltTy, Val, EnumVal, LastEnumConst,
+                             Context);
   
   // Register this decl in the current scope stack.
   New->setNext(Id->getFETokenInfo<ScopedDecl>());
index 66ac9fd08aebb08215f2cd47daab7312aac6c7cd..c6f40b7a526bc14b2317d0bd064dc130543ab37a 100644 (file)
@@ -22,6 +22,7 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/Bitcode/SerializationFwd.h"
+#include "llvm/Support/Allocator.h"
 #include <vector>
 
 namespace clang {
@@ -75,13 +76,15 @@ class ASTContext {
   RecordDecl *CFConstantStringTypeDecl;
 
   SourceManager &SourceMgr;
+  llvm::MallocAllocator Allocator;
 public:
   TargetInfo &Target;
   IdentifierTable &Idents;
   SelectorTable &Selectors;
   
   SourceManager& getSourceManager() { return SourceMgr; }
-
+  llvm::MallocAllocator &getAllocator() { return Allocator; }
+  
   FullSourceLoc getFullLoc(SourceLocation Loc) const { 
     return FullSourceLoc(Loc,SourceMgr);
   }
index 06c0d73d0899272236c2eacba36ca46dcdb47c33..9e8f065ae69685461f9365b9e8d91d7d59497792 100644 (file)
@@ -171,8 +171,8 @@ public:
     }
   }
   // global temp stats (until we have a per-module visitor)
-  static void addDeclKind(const Kind k);
-  static bool CollectingStats(bool enable=false);
+  static void addDeclKind(Kind k);
+  static bool CollectingStats(bool Enable = false);
   static void PrintStats();
     
   // Implement isa/cast/dyncast/etc.
@@ -539,11 +539,17 @@ protected:
 class EnumConstantDecl : public ValueDecl {
   Expr *Init; // an integer constant expression
   llvm::APSInt Val; // The value.
-public:
+protected:
   EnumConstantDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E,
                    const llvm::APSInt &V, ScopedDecl *PrevDecl)
     : ValueDecl(EnumConstant, L, Id, T, PrevDecl), Init(E), Val(V) {}
+  ~EnumConstantDecl() {}
+public:
 
+  static EnumConstantDecl *Create(SourceLocation L, IdentifierInfo *Id,
+                                  QualType T, Expr *E, const llvm::APSInt &V, 
+                                  ScopedDecl *PrevDecl, ASTContext &C);
+  
   const Expr *getInitExpr() const { return Init; }
   Expr *getInitExpr() { return Init; }
   const llvm::APSInt &getInitVal() const { return Val; }
@@ -591,9 +597,13 @@ public:
 class TypedefDecl : public TypeDecl {
   /// UnderlyingType - This is the type the typedef is set to.
   QualType UnderlyingType;
-public:
   TypedefDecl(SourceLocation L, IdentifierInfo *Id, QualType T, ScopedDecl *PD) 
     : TypeDecl(Typedef, L, Id, PD), UnderlyingType(T) {}
+  ~TypedefDecl() {}
+public:
+  
+  static TypedefDecl *Create(SourceLocation L, IdentifierInfo *Id, QualType T,
+                             ScopedDecl *PD, ASTContext &C);
   
   QualType getUnderlyingType() const { return UnderlyingType; }
   void setUnderlyingType(QualType newType) { UnderlyingType = newType; }
@@ -660,12 +670,16 @@ class EnumDecl : public TagDecl {
   /// to for code generation purposes.  Note that the enumerator constants may
   /// have a different type than this does.
   QualType IntegerType;
-public:
+  
   EnumDecl(SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
     : TagDecl(Enum, L, Id, PrevDecl) {
-    ElementList = 0;
-        IntegerType = QualType();
-  }
+      ElementList = 0;
+      IntegerType = QualType();
+    }
+  ~EnumDecl() {}
+public:
+  static EnumDecl *Create(SourceLocation L, IdentifierInfo *Id,
+                          ScopedDecl *PrevDecl, ASTContext &C);
   
   /// defineElements - When created, EnumDecl correspond to a forward declared
   /// enum.  This method is used to mark the decl as being defined, with the
@@ -715,15 +729,21 @@ class RecordDecl : public TagDecl {
   /// Members/NumMembers - This is a new[]'d array of pointers to Decls.
   FieldDecl **Members;   // Null if not defined.
   int NumMembers;   // -1 if not defined.
-public:
-  RecordDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl*PrevDecl)
-    : TagDecl(DK, L, Id, PrevDecl) {
+  
+  RecordDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, 
+             ScopedDecl *PrevDecl) : TagDecl(DK, L, Id, PrevDecl) {
     HasFlexibleArrayMember = false;
     assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
     Members = 0;
     NumMembers = -1;
   }
   
+  ~RecordDecl() {}
+public:
+  
+  static RecordDecl *Create(Kind DK, SourceLocation L, IdentifierInfo *Id, 
+                            ScopedDecl *PrevDecl, ASTContext &C);
+  
   bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
   void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; }