]> granicus.if.org Git - clang/commitdiff
Add create methods for ObjCIvarDecl and ObjCInterfaceDecl
authorChris Lattner <sabre@nondot.org>
Sun, 16 Mar 2008 01:15:50 +0000 (01:15 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 16 Mar 2008 01:15:50 +0000 (01:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48408 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclObjC.cpp

index 290d99efaceeef912d17f76e84d893d4a4facead..74f0a25c316d351790b2ff39b79079268ab2022b 100644 (file)
@@ -224,7 +224,7 @@ class ObjCInterfaceDecl : public TypeDecl {
   
   SourceLocation EndLoc; // marks the '>', '}', or identifier.
   SourceLocation AtEndLoc; // marks the end of the entire interface.
-public:
+
   ObjCInterfaceDecl(SourceLocation atLoc, unsigned numRefProtos,
                     IdentifierInfo *Id, bool FD = false, 
                     bool isInternal = false)
@@ -237,6 +237,12 @@ public:
       ForwardDecl(FD), InternalInterface(isInternal) {
         AllocIntfRefProtocols(numRefProtos);
       }
+public:
+
+  static ObjCInterfaceDecl *Create(ASTContext &C, SourceLocation atLoc,
+                                   unsigned numRefProtos, IdentifierInfo *Id,
+                                   bool ForwardDecl = false,
+                                   bool isInternal = false);
   
   // This is necessary when converting a forward declaration to a definition.
   void AllocIntfRefProtocols(unsigned numRefProtos) {
@@ -303,20 +309,20 @@ public:
   // Get the local instance method declared in this interface.
   ObjCMethodDecl *getInstanceMethod(Selector &Sel) {
     for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); 
-             I != E; ++I) {
+         I != E; ++I) {
       if ((*I)->getSelector() == Sel)
         return *I;
     }
-        return 0;
+    return 0;
   }
   // Get the local class method declared in this interface.
   ObjCMethodDecl *getClassMethod(Selector &Sel) {
     for (classmeth_iterator I = classmeth_begin(), E = classmeth_end(); 
-             I != E; ++I) {
+         I != E; ++I) {
       if ((*I)->getSelector() == Sel)
         return *I;
     }
-        return 0;
+    return 0;
   }
   // Lookup a method. First, we search locally. If a method isn't
   // found, we search referenced protocols and class categories.
@@ -365,9 +371,11 @@ public:
 ///   }
 ///
 class ObjCIvarDecl : public FieldDecl {
-public:
   ObjCIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T) 
     : FieldDecl(ObjCIvar, L, Id, T) {}
+public:
+  static ObjCIvarDecl *Create(ASTContext &C, SourceLocation L,
+                              IdentifierInfo *Id, QualType T);
     
   enum AccessControl {
     None, Private, Protected, Public, Package
index 9580e0cbf8571de5fd20c2074e9bfabd8da86e3b..53ba8c121948218b34f7d5bab99529e40588c64d 100644 (file)
@@ -30,7 +30,21 @@ ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, SourceLocation beginLoc,
   return new (Mem) ObjCMethodDecl(beginLoc, endLoc, SelInfo, T, contextDecl,
                                   M, isInstance, 
                                   isVariadic, impControl);
+}
+
+ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,SourceLocation atLoc,
+                                             unsigned numRefProtos,
+                                             IdentifierInfo *Id,
+                                             bool ForwardDecl, bool isInternal){
+  void *Mem = C.getAllocator().Allocate<ObjCInterfaceDecl>();
+  return new (Mem) ObjCInterfaceDecl(atLoc, numRefProtos, Id, ForwardDecl,
+                                     isInternal);
+}
 
+ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L,
+                                   IdentifierInfo *Id, QualType T) {
+  void *Mem = C.getAllocator().Allocate<ObjCIvarDecl>();
+  return new (Mem) ObjCIvarDecl(L, Id, T);
 }
 
 
index f4c271cdcb13bbddfecd191142861c18de62e832..da78ec0678788e86b2d6cb289896d9e2641b365e 100644 (file)
@@ -108,8 +108,9 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer)
     Context.setObjCClassType(ClassTypedef);
     
     // Synthesize "@class Protocol;
-    ObjCInterfaceDecl *ProtocolDecl = new ObjCInterfaceDecl(SourceLocation(), 0, 
-                                        &Context.Idents.get("Protocol"), true);
+    ObjCInterfaceDecl *ProtocolDecl =
+      ObjCInterfaceDecl::Create(Context, SourceLocation(), 0, 
+                                &Context.Idents.get("Protocol"), true);
     Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl));
     
     // Synthesize "typedef struct objc_object { Class isa; } *id;"
index 28b396a8f0d51d4a4f12008e42eb08426911a967..5ac51b29bfca7bdaf40ef27724b681083e5e96d6 100644 (file)
@@ -1340,7 +1340,7 @@ Sema::DeclTy *Sema::ActOnField(Scope *S, DeclTy *TagDecl,
            // properties can appear within a protocol.
            // See corresponding FIXME in DeclObjC.h:ObjCPropertyDecl.
            isa<ObjCProtocolDecl>(static_cast<Decl *>(TagDecl)))
-    NewFD = new ObjCIvarDecl(Loc, II, T);
+    NewFD = ObjCIvarDecl::Create(Context, Loc, II, T);
   else
     assert(0 && "Sema::ActOnField(): Unknown TagDecl");
     
index 4dd84d8555e4056cf9ab95731b290208a552af9e..d5d658d4ff1c3d97e77fdbae0ec63fbedd06f4c1 100644 (file)
@@ -98,7 +98,8 @@ Sema::DeclTy *Sema::ActOnStartClassInterface(
     }
   }
   else {
-    IDecl = new ObjCInterfaceDecl(AtInterfaceLoc, NumProtocols, ClassName);
+    IDecl = ObjCInterfaceDecl::Create(Context, AtInterfaceLoc, NumProtocols,
+                                      ClassName);
   
     // Chain & install the interface decl into the identifier.
     IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
@@ -382,8 +383,8 @@ Sema::DeclTy *Sema::ActOnStartClassImplementation(
   if (!IDecl) {
     // Legacy case of @implementation with no corresponding @interface.
     // Build, chain & install the interface decl into the identifier.
-    IDecl = new ObjCInterfaceDecl(AtClassImplLoc, 0, ClassName, 
-                                  false, true);
+    IDecl = ObjCInterfaceDecl::Create(Context, AtClassImplLoc, 0, ClassName, 
+                                      false, true);
     IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
     ClassName->setFETokenInfo(IDecl);
     IDecl->setSuperClass(SDecl);
@@ -589,7 +590,8 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
     }
     ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); 
     if (!IDecl) {  // Not already seen?  Make a forward decl.
-      IDecl = new ObjCInterfaceDecl(AtClassLoc, 0, IdentList[i], true);
+      IDecl = ObjCInterfaceDecl::Create(Context, AtClassLoc, 0, IdentList[i],
+                                        true);
       // Chain & install the interface decl into the identifier.
       IDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
       IdentList[i]->setFETokenInfo(IDecl);