[cfe-commits] r48390 - in /cfe/trunk: 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

Chris Lattner sabre at nondot.org
Fri Mar 14 23:12:44 PDT 2008


Author: lattner
Date: Sat Mar 15 01:12:44 2008
New Revision: 48390

URL: http://llvm.org/viewvc/llvm-project?rev=48390&view=rev
Log:
start switching decls over to using an allocator controlled by ASTContext.  
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.

Modified:
    cfe/trunk/AST/ASTContext.cpp
    cfe/trunk/AST/Decl.cpp
    cfe/trunk/Driver/RewriteTest.cpp
    cfe/trunk/Sema/Sema.cpp
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/include/clang/AST/Decl.h

Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=48390&r1=48389&r2=48390&view=diff

==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Sat Mar 15 01:12:44 2008
@@ -1047,9 +1047,9 @@
 // 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;

Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=48390&r1=48389&r2=48390&view=diff

==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Sat Mar 15 01:12:44 2008
@@ -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"
@@ -201,6 +202,37 @@
 }
 
 //===----------------------------------------------------------------------===//
+// 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 @@
   return 0;
 }
 
-
 //===----------------------------------------------------------------------===//
 // Objective-C Decl Implementation
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=48390&r1=48389&r2=48390&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Sat Mar 15 01:12:44 2008
@@ -796,7 +796,7 @@
         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::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 @@
   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 @@
 
 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::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;

Modified: cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.cpp?rev=48390&r1=48389&r2=48390&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/trunk/Sema/Sema.cpp Sat Mar 15 01:12:44 2008
@@ -59,15 +59,16 @@
   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 @@
   // 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 @@
     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;

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=48390&r1=48389&r2=48390&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Sat Mar 15 01:12:44 2008
@@ -1175,8 +1175,9 @@
   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 @@
   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 @@
   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 @@
     }
   }
   
-  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>());

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=48390&r1=48389&r2=48390&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sat Mar 15 01:12:44 2008
@@ -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 @@
   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);
   }

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=48390&r1=48389&r2=48390&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sat Mar 15 01:12:44 2008
@@ -171,8 +171,8 @@
     }
   }
   // 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 @@
 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 @@
 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 @@
   /// 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 @@
   /// 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; }
   





More information about the cfe-commits mailing list