]> granicus.if.org Git - clang/commitdiff
switch the rest of the C decl classes to do their
authorChris Lattner <sabre@nondot.org>
Sun, 16 Mar 2008 00:16:02 +0000 (00:16 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 16 Mar 2008 00:16:02 +0000 (00:16 +0000)
allocation through ASTContext.

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

Driver/RewriteTest.cpp
clang.xcodeproj/project.pbxproj
include/clang/AST/Decl.h
lib/AST/ASTContext.cpp
lib/AST/Decl.cpp
lib/AST/DeclSerialization.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaDecl.cpp

index b4de21c707c80ec6e0535f820fd592909943bf96..8d19334eb80fef164c995b7fecc8ddd250f85a05 100644 (file)
@@ -1805,7 +1805,8 @@ QualType RewriteTest::getSuperStructType() {
     FieldDecl *FieldDecls[2];
   
     for (unsigned i = 0; i < 2; ++i)
-      FieldDecls[i] = new FieldDecl(SourceLocation(), 0, FieldTypes[i]);
+      FieldDecls[i] = FieldDecl::Create(*Context, SourceLocation(), 0, 
+                                        FieldTypes[i]);
   
     SuperStructDecl->defineBody(FieldDecls, 4);
   }
@@ -1831,7 +1832,8 @@ QualType RewriteTest::getConstantStringStructType() {
     FieldDecl *FieldDecls[2];
   
     for (unsigned i = 0; i < 4; ++i)
-      FieldDecls[i] = new FieldDecl(SourceLocation(), 0, FieldTypes[i]);
+      FieldDecls[i] = FieldDecl::Create(*Context, SourceLocation(), 0,
+                                        FieldTypes[i]);
   
     ConstantStringDecl->defineBody(FieldDecls, 4);
   }
index 63d76a716ab2af0da97ae13265dfc8ac35ee304e..872efe38550737bd39fdb4ef8cdd56e9a538a221 100644 (file)
@@ -62,6 +62,7 @@
                DE34621D0AFEB19B00DBC861 /* StmtPrinter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE34621C0AFEB19B00DBC861 /* StmtPrinter.cpp */; };
                DE3464220B03040900DBC861 /* Type.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE3464210B03040900DBC861 /* Type.h */; };
                DE38CD500D794D0100A273B6 /* CGObjCGNU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE38CD4F0D794D0100A273B6 /* CGObjCGNU.cpp */; };
+               DE38CF160D8C9DE000A273B6 /* DiagChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE38CF150D8C9DE000A273B6 /* DiagChecker.cpp */; };
                DE3985790CB8ADC800223765 /* ASTConsumers.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE3985780CB8ADC800223765 /* ASTConsumers.h */; };
                DE39857B0CB8ADCB00223765 /* ASTConsumers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE39857A0CB8ADCB00223765 /* ASTConsumers.cpp */; };
                DE3986F00CB8D4B300223765 /* IdentifierTable.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE3986EF0CB8D4B300223765 /* IdentifierTable.h */; };
                DEB0AEBB0C2087AB00718A22 /* TextDiagnostics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEB0AEBA0C2087AB00718A22 /* TextDiagnostics.cpp */; };
                DEC63B1A0C7B940200DBF169 /* CFG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEC63B190C7B940200DBF169 /* CFG.cpp */; };
                DEC63B1C0C7B940600DBF169 /* CFG.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEC63B1B0C7B940600DBF169 /* CFG.h */; };
-               DEC82DC40C32D50A00BAC245 /* DiagChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEC82DC30C32D50A00BAC245 /* DiagChecker.cpp */; };
                DEC8D9910A9433CD00353FCA /* Decl.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEC8D9900A9433CD00353FCA /* Decl.h */; };
                DEC8D9A40A94346E00353FCA /* AST.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEC8D9A30A94346E00353FCA /* AST.h */; };
                DED626C90AE0C065001E80A4 /* TargetInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DED626C80AE0C065001E80A4 /* TargetInfo.cpp */; };
                DE3464210B03040900DBC861 /* Type.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Type.h; path = clang/AST/Type.h; sourceTree = "<group>"; };
                DE38CD4E0D794CF900A273B6 /* CGObjCRuntime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CGObjCRuntime.h; path = lib/CodeGen/CGObjCRuntime.h; sourceTree = "<group>"; };
                DE38CD4F0D794D0100A273B6 /* CGObjCGNU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CGObjCGNU.cpp; path = lib/CodeGen/CGObjCGNU.cpp; sourceTree = "<group>"; };
+               DE38CF150D8C9DE000A273B6 /* DiagChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DiagChecker.cpp; path = Driver/DiagChecker.cpp; sourceTree = "<group>"; };
                DE3985780CB8ADC800223765 /* ASTConsumers.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ASTConsumers.h; path = Driver/ASTConsumers.h; sourceTree = "<group>"; };
                DE39857A0CB8ADCB00223765 /* ASTConsumers.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ASTConsumers.cpp; path = Driver/ASTConsumers.cpp; sourceTree = "<group>"; };
                DE3986EF0CB8D4B300223765 /* IdentifierTable.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = IdentifierTable.h; sourceTree = "<group>"; };
                DEB0AEBA0C2087AB00718A22 /* TextDiagnostics.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = TextDiagnostics.cpp; path = Driver/TextDiagnostics.cpp; sourceTree = "<group>"; };
                DEC63B190C7B940200DBF169 /* CFG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = CFG.cpp; path = lib/AST/CFG.cpp; sourceTree = "<group>"; };
                DEC63B1B0C7B940600DBF169 /* CFG.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = CFG.h; path = clang/AST/CFG.h; sourceTree = "<group>"; };
-               DEC82DC30C32D50A00BAC245 /* DiagChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = DiagChecker.cpp; path = lib/Driver/DiagChecker.cpp; sourceTree = "<group>"; };
                DEC8D9900A9433CD00353FCA /* Decl.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Decl.h; path = clang/AST/Decl.h; sourceTree = "<group>"; };
                DEC8D9A30A94346E00353FCA /* AST.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AST.h; path = clang/AST/AST.h; sourceTree = "<group>"; };
                DED626C80AE0C065001E80A4 /* TargetInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = TargetInfo.cpp; sourceTree = "<group>"; };
                                DE5932CE0AD60FF400BC794C /* clang.h */,
                                DE3985780CB8ADC800223765 /* ASTConsumers.h */,
                                DE39857A0CB8ADCB00223765 /* ASTConsumers.cpp */,
-                               DEC82DC30C32D50A00BAC245 /* DiagChecker.cpp */,
+                               DE38CF150D8C9DE000A273B6 /* DiagChecker.cpp */,
                                DE5932CF0AD60FF400BC794C /* PrintParserCallbacks.cpp */,
                                DE5932D00AD60FF400BC794C /* PrintPreprocessedOutput.cpp */,
                                DEA977890CBE87EB00F872F9 /* RewriteTest.cpp */,
                                84D9A8880C1A57E100AC7ABC /* AttributeList.cpp in Sources */,
                                DEB0AEBB0C2087AB00718A22 /* TextDiagnostics.cpp in Sources */,
                                DEEBC3BC0C2363BC00A9FE82 /* CodeGenTypes.cpp in Sources */,
-                               DEC82DC40C32D50A00BAC245 /* DiagChecker.cpp in Sources */,
                                DEEBCBE50C33703100A9FE82 /* TextDiagnosticBuffer.cpp in Sources */,
                                DEF2EDA70C6A4252000C4259 /* StmtDumper.cpp in Sources */,
                                DEF2EFF30C6CDD74000C4259 /* CGExprAgg.cpp in Sources */,
                                DE85CDAC0D838C120070E26E /* PPMacroExpansion.cpp in Sources */,
                                DE85CDB00D838C390070E26E /* PPDirectives.cpp in Sources */,
                                DE85CDB60D839BAE0070E26E /* PPLexerChange.cpp in Sources */,
+                               DE38CF160D8C9DE000A273B6 /* DiagChecker.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 7c3560c503588bbc49b8ef9de60f179fe5142267..357ded624c23b366ed6723231653e06eaa3a00bf 100644 (file)
@@ -434,6 +434,22 @@ public:
     None, Extern, Static, PrivateExtern
   };
 private:
+  /// ParamInfo - new[]'d array of pointers to VarDecls for the formal
+  /// parameters of this function.  This is null if a prototype or if there are
+  /// no formals.  TODO: we could allocate this space immediately after the
+  /// FunctionDecl object to save an allocation like FunctionType does.
+  ParmVarDecl **ParamInfo;
+  
+  Stmt *Body;  // Null if a prototype.
+  
+  /// DeclChain - Linked list of declarations that are defined inside this
+  /// function.
+  ScopedDecl *DeclChain;
+  
+  // NOTE: VC++ treats enums as signed, avoid using the StorageClass enum
+  unsigned SClass : 2;
+  bool IsInline : 1;
+  
   FunctionDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
                StorageClass S, bool isInline, ScopedDecl *PrevDecl)
     : ValueDecl(Function, L, Id, T, PrevDecl), 
@@ -480,23 +496,6 @@ public:
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return D->getKind() == Function; }
   static bool classof(const FunctionDecl *D) { return true; }
-  
-private:
-  /// ParamInfo - new[]'d array of pointers to VarDecls for the formal
-  /// parameters of this function.  This is null if a prototype or if there are
-  /// no formals.  TODO: we could allocate this space immediately after the
-  /// FunctionDecl object to save an allocation like FunctionType does.
-  ParmVarDecl **ParamInfo;
-  
-  Stmt *Body;  // Null if a prototype.
-  
-  /// DeclChain - Linked list of declarations that are defined inside this
-  /// function.
-  ScopedDecl *DeclChain;
-
-  // NOTE: VC++ treats enums as signed, avoid using the StorageClass enum
-  unsigned SClass : 2;
-  bool IsInline : 1;
 
 protected:
   /// EmitImpl - Serialize this FunctionDecl.  Called by Decl::Emit.
@@ -518,10 +517,11 @@ protected:
   FieldDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
             Expr *BW = NULL)
     : NamedDecl(DK, L, Id), DeclType(T), BitWidth(BW) {}
-public:
-  FieldDecl(SourceLocation L, IdentifierInfo *Id, QualType T, 
-            Expr *BW = NULL)
+  FieldDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Expr *BW)
     : NamedDecl(Field, L, Id), DeclType(T), BitWidth(BW) {}
+public:
+  static FieldDecl *Create(ASTContext &C, SourceLocation L, IdentifierInfo *Id,
+                           QualType T, Expr *BW = NULL);
 
   QualType getType() const { return DeclType; }
   QualType getCanonicalType() const { return DeclType.getCanonicalType(); }
@@ -688,7 +688,6 @@ class EnumDecl : public TagDecl {
       ElementList = 0;
       IntegerType = QualType();
     }
-  ~EnumDecl() {}
 public:
   static EnumDecl *Create(ASTContext &C, SourceLocation L, IdentifierInfo *Id,
                           ScopedDecl *PrevDecl);
@@ -749,8 +748,6 @@ class RecordDecl : public TagDecl {
     Members = 0;
     NumMembers = -1;
   }
-  
-  ~RecordDecl() {}
 public:
   
   static RecordDecl *Create(ASTContext &C, Kind DK, SourceLocation L,
@@ -791,9 +788,11 @@ protected:
 
 class FileScopeAsmDecl : public Decl {
   StringLiteral *AsmString;
-public:
   FileScopeAsmDecl(SourceLocation L, StringLiteral *asmstring)
     : Decl(FileScopeAsm, L), AsmString(asmstring) {}
+public:
+  static FileScopeAsmDecl *Create(ASTContext &C, SourceLocation L,
+                                  StringLiteral *Str);
 
   const StringLiteral *getAsmString() const { return AsmString; }
   StringLiteral *getAsmString() { return AsmString; }
@@ -828,10 +827,13 @@ private:
   LanguageIDs Language;
   /// D - This is the Decl of the linkage specification.
   Decl *D;
-public:
+  
   LinkageSpecDecl(SourceLocation L, LanguageIDs lang, Decl *d)
    : Decl(LinkageSpec, L), Language(lang), D(d) {}
-  
+public:
+  static LinkageSpecDecl *Create(ASTContext &C, SourceLocation L,
+                                 LanguageIDs Lang, Decl *D);
+
   LanguageIDs getLanguage() const { return Language; }
   const Decl *getDecl() const { return D; }
   Decl *getDecl() { return D; }
index db4d53aa481ec6783fe6865eb169c5fa628c5dbd..902f422dacb1f922db609ff3fe051849b7f18ea9 100644 (file)
@@ -1064,7 +1064,8 @@ QualType ASTContext::getCFConstantStringType() {
     FieldDecl *FieldDecls[4];
   
     for (unsigned i = 0; i < 4; ++i)
-      FieldDecls[i] = new FieldDecl(SourceLocation(), 0, FieldTypes[i]);
+      FieldDecls[i] = FieldDecl::Create(*this, SourceLocation(), 0,
+                                        FieldTypes[i]);
   
     CFConstantStringTypeDecl->defineBody(FieldDecls, 4);
   }
index 7fa679cbc08302a8450a7f88a45649e9ccfdb25a..4ce6fa8f3c4f03429b5f3b330a6c78b4a2427979 100644 (file)
@@ -235,6 +235,12 @@ FunctionDecl *FunctionDecl::Create(ASTContext &C, SourceLocation L,
   return new (Mem) FunctionDecl(L, Id, T, S, isInline, PrevDecl);
 }
 
+FieldDecl *FieldDecl::Create(ASTContext &C, SourceLocation L,
+                             IdentifierInfo *Id, QualType T, Expr *BW) {
+  void *Mem = C.getAllocator().Allocate<FieldDecl>();
+  return new (Mem) FieldDecl(L, Id, T, BW);
+}
+
 
 EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, SourceLocation L,
                                            IdentifierInfo *Id, QualType T,
@@ -263,6 +269,17 @@ RecordDecl *RecordDecl::Create(ASTContext &C, Kind DK, SourceLocation L,
   return new (Mem) RecordDecl(DK, L, Id, PrevDecl);
 }
 
+FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, SourceLocation L,
+                                           StringLiteral *Str) {
+  void *Mem = C.getAllocator().Allocate<FileScopeAsmDecl>();
+  return new (Mem) FileScopeAsmDecl(L, Str);
+}
+
+LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, SourceLocation L,
+                                         LanguageIDs Lang, Decl *D) {
+  void *Mem = C.getAllocator().Allocate<LinkageSpecDecl>();
+  return new (Mem) LinkageSpecDecl(L, Lang, D);
+}
 
 //===----------------------------------------------------------------------===//
 // Decl Implementation
index a7eaed5b2efefc4fcf46c15758e72679714ef9d9..fe2ccefdce2afacf25d9f9abf45bf2f8cfb2764e 100644 (file)
@@ -302,7 +302,7 @@ void FieldDecl::EmitImpl(Serializer& S) const {
 }
 
 FieldDecl* FieldDecl::CreateImpl(Deserializer& D) {
-  FieldDecl* decl = new FieldDecl(SourceLocation(),NULL,QualType());
+  FieldDecl* decl = new FieldDecl(SourceLocation(), NULL, QualType(), 0);
   decl->DeclType.ReadBackpatch(D);  
   decl->ReadInRec(D);
   decl->BitWidth = D.ReadOwnedPtr<Expr>();
index 4bd04e3a1a535723abbaee7e30f40f3b5722e8d7..f4c271cdcb13bbddfecd191142861c18de62e832 100644 (file)
@@ -116,8 +116,8 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer)
     RecordDecl *ObjectTag = 
       RecordDecl::Create(Context, Decl::Struct, SourceLocation(),
                          &IT.get("objc_object"), 0);
-    FieldDecl *IsaDecl = new FieldDecl(SourceLocation(), 0, 
-                                       Context.getObjCClassType());
+    FieldDecl *IsaDecl = FieldDecl::Create(Context, SourceLocation(), 0, 
+                                           Context.getObjCClassType());
     ObjectTag->defineBody(&IsaDecl, 1);
     QualType ObjT = Context.getPointerType(Context.getTagDeclType(ObjectTag));
     TypedefDecl *IdTypedef = TypedefDecl::Create(Context, SourceLocation(),
index 7914e865741b4cd920024745517d83bd948c53cb..28b396a8f0d51d4a4f12008e42eb08426911a967 100644 (file)
@@ -1332,7 +1332,7 @@ Sema::DeclTy *Sema::ActOnField(Scope *S, DeclTy *TagDecl,
   FieldDecl *NewFD;
   
   if (isa<RecordDecl>(static_cast<Decl *>(TagDecl)))
-    NewFD = new FieldDecl(Loc, II, T, BitWidth);
+    NewFD = FieldDecl::Create(Context, Loc, II, T, BitWidth);
   else if (isa<ObjCInterfaceDecl>(static_cast<Decl *>(TagDecl)) ||
            isa<ObjCImplementationDecl>(static_cast<Decl *>(TagDecl)) ||
            isa<ObjCCategoryDecl>(static_cast<Decl *>(TagDecl)) ||
@@ -1750,7 +1750,7 @@ Sema::DeclTy *Sema::ActOnFileScopeAsmDecl(SourceLocation Loc,
                                           ExprTy *expr) {
   StringLiteral *AsmString = cast<StringLiteral>((Expr*)expr);
   
-  return new FileScopeAsmDecl(Loc, AsmString);
+  return FileScopeAsmDecl::Create(Context, Loc, AsmString);
 }
 
 Sema::DeclTy* Sema::ActOnLinkageSpec(SourceLocation Loc,
@@ -1771,7 +1771,7 @@ Sema::DeclTy* Sema::ActOnLinkageSpec(SourceLocation Loc,
   }
 
   // FIXME: Add all the various semantics of linkage specifications
-  return new LinkageSpecDecl(Loc, Language, dcl);
+  return LinkageSpecDecl::Create(Context, Loc, Language, dcl);
 }
 
 void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) {