[cfe-commits] r61966 - in /cfe/trunk: Driver/RewriteObjC.cpp include/clang/AST/Decl.h include/clang/AST/DeclBase.h include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Sema/Sema.cpp lib/Sema/SemaDeclObjC.cpp

Douglas Gregor dgregor at apple.com
Thu Jan 8 16:49:46 PST 2009


Author: dgregor
Date: Thu Jan  8 18:49:46 2009
New Revision: 61966

URL: http://llvm.org/viewvc/llvm-project?rev=61966&view=rev
Log:
Addressed the issue in <rdar://problem/6479085>, where we failed to
rewrite @class declarations that showed up within linkage
specifications because those @class declarations never made it any
place where the rewriter could find them.

Moved all of the ObjC*Decl nodes over to ScopedDecls, so that they can
live in the appropriate top-level or transparent DeclContext near the
top level, e.g., TranslationUnitDecl or LinkageSpecDecl. Objective-C
declarations now show up in a traversal of the declarations in a
DeclContext (they didn't before!). This way, the rewriter finds all
Objective-C declarations within linkage specifications.

Modified:
    cfe/trunk/Driver/RewriteObjC.cpp
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=61966&r1=61965&r2=61966&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Thu Jan  8 18:49:46 2009
@@ -580,6 +580,12 @@
   } else if (ObjCForwardProtocolDecl *FP = 
              dyn_cast<ObjCForwardProtocolDecl>(D)){
     RewriteForwardProtocolDecl(FP);
+  } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) {
+    // Recurse into linkage specifications
+    for (DeclContext::decl_iterator DI = LSD->decls_begin(),
+                                 DIEnd = LSD->decls_end();
+         DI != DIEnd; ++DI)
+      HandleTopLevelDecl(*DI);
   }
   // If we have a decl in the main file, see if we should rewrite it.
   if (SM->isFromMainFile(Loc))
@@ -4367,14 +4373,6 @@
 /// HandleDeclInMainFile - This is called for each top-level decl defined in the
 /// main file of the input.
 void RewriteObjC::HandleDeclInMainFile(Decl *D) {
-  // Required when rewriting in objective-c++ mode...
-  if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) {
-    for (LinkageSpecDecl::decl_iterator i = LSD->decls_begin(), 
-                                        e = LSD->decls_end(); i != e; ++i) {
-      HandleDeclInMainFile(*i);
-    }
-    return;
-  }
   if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
     if (FD->isOverloadedOperator())
       return;

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Jan  8 18:49:46 2009
@@ -143,7 +143,7 @@
 
 protected:
   ScopedDecl(Kind DK, DeclContext *DC, SourceLocation L,
-             DeclarationName N, ScopedDecl *PrevDecl)
+             DeclarationName N, ScopedDecl *PrevDecl = 0)
     : NamedDecl(DK, L, N), NextDeclarator(PrevDecl),
       DeclCtx(reinterpret_cast<uintptr_t>(DC)) {}
 

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Jan  8 18:49:46 2009
@@ -53,14 +53,7 @@
     // Decl
          TranslationUnit,  // [DeclContext]
     //   NamedDecl
-    //     ObjCContainerDecl // [DeclContext]
-             ObjCCategory,
-             ObjCProtocol,
-             ObjCInterface,
            OverloadedFunction,
-           ObjCCategoryImpl,  // [DeclContext]
-           ObjCImplementation, // [DeclContext]
-           ObjCProperty,
     //     ScopedDecl
              Field,
                ObjCIvar,
@@ -88,18 +81,25 @@
   	         NonTypeTemplateParm,
              LinkageSpec, // [DeclContext]
              ObjCMethod,  // [DeclContext]
-           ObjCCompatibleAlias,
-           ObjCClass,
-           ObjCForwardProtocol,
-           ObjCPropertyImpl,
+    //       ObjCContainerDecl // [DeclContext]
+               ObjCCategory,
+               ObjCProtocol,
+               ObjCInterface,
+             ObjCCategoryImpl,  // [DeclContext]
+             ObjCImplementation, // [DeclContext]
+             ObjCProperty,
+             ObjCCompatibleAlias,
+             ObjCClass,
+             ObjCForwardProtocol,
+             ObjCPropertyImpl,
          FileScopeAsm,
 	     Block, // [DeclContext]
   
     // For each non-leaf class, we now define a mapping to the first/last member
     // of the class, to allow efficient classof.
-    NamedFirst     = OverloadedFunction , NamedLast     = NonTypeTemplateParm,
+    NamedFirst     = OverloadedFunction , NamedLast     = ObjCPropertyImpl,
     FieldFirst     = Field        , FieldLast     = ObjCAtDefsField,
-    ScopedFirst    = Field        , ScopedLast    = ObjCMethod,
+    ScopedFirst    = Field        , ScopedLast    = ObjCPropertyImpl,
     TypeFirst      = Typedef      , TypeLast      = TemplateTypeParm,
     TagFirst       = Enum         , TagLast       = CXXRecord,
     RecordFirst    = Record       , RecordLast    = CXXRecord,

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Jan  8 18:49:46 2009
@@ -254,12 +254,13 @@
 /// If DeclContext ends up providing some support for creating more strongly 
 /// typed iterators, the code below should be reduced considerably.
 ///
-class ObjCContainerDecl : public NamedDecl, public DeclContext {
+class ObjCContainerDecl : public ScopedDecl, public DeclContext {
   SourceLocation AtEndLoc; // marks the end of the method container.
 public:
 
-  ObjCContainerDecl(Kind DK, SourceLocation L, IdentifierInfo *Id)
-    : NamedDecl(DK, L, Id), DeclContext(DK) {}
+  ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L, 
+                    IdentifierInfo *Id)
+    : ScopedDecl(DK, DC, L, Id), DeclContext(DK) {}
 
   virtual ~ObjCContainerDecl();
     
@@ -479,9 +480,9 @@
   SourceLocation SuperClassLoc; // location of the super class identifier.
   SourceLocation EndLoc; // marks the '>', '}', or identifier.
 
-  ObjCInterfaceDecl(SourceLocation atLoc, IdentifierInfo *Id,
+  ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
                     SourceLocation CLoc, bool FD, bool isInternal)
-    : ObjCContainerDecl(ObjCInterface, atLoc, Id),
+    : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id),
       TypeForDecl(0), SuperClass(0),
       Ivars(0), NumIvars(0),
       CategoryList(0), PropertyDecl(0), NumPropertyDecl(0),
@@ -496,7 +497,7 @@
   /// Destroy - Call destructors and release memory.
   virtual void Destroy(ASTContext& C);
 
-  static ObjCInterfaceDecl *Create(ASTContext &C,
+  static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC,
                                    SourceLocation atLoc,
                                    IdentifierInfo *Id, 
                                    SourceLocation ClassLoc = SourceLocation(),
@@ -713,8 +714,8 @@
   SourceLocation EndLoc; // marks the '>' or identifier.
   SourceLocation AtEndLoc; // marks the end of the entire interface.
   
-  ObjCProtocolDecl(SourceLocation L, IdentifierInfo *Id)
-    : ObjCContainerDecl(ObjCProtocol, L, Id), 
+  ObjCProtocolDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
+    : ObjCContainerDecl(ObjCProtocol, DC, L, Id), 
       PropertyDecl(0), NumPropertyDecl(0),
       isForwardProtoDecl(true) {
   }
@@ -726,8 +727,8 @@
   /// Destroy - Call destructors and release memory.
   virtual void Destroy(ASTContext& C);
   
-  static ObjCProtocolDecl *Create(ASTContext &C, SourceLocation L,
-                                  IdentifierInfo *Id);
+  static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC, 
+                                  SourceLocation L, IdentifierInfo *Id);
 
   const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const { 
     return ReferencedProtocols;
@@ -784,12 +785,14 @@
 ///
 /// @class NSCursor, NSImage, NSPasteboard, NSWindow;
 ///
-class ObjCClassDecl : public Decl {
+/// FIXME: This could be a transparent DeclContext (!)
+class ObjCClassDecl : public ScopedDecl {
   ObjCInterfaceDecl **ForwardDecls;
   unsigned NumForwardDecls;
   
-  ObjCClassDecl(SourceLocation L, ObjCInterfaceDecl **Elts, unsigned nElts)
-    : Decl(ObjCClass, L) { 
+  ObjCClassDecl(DeclContext *DC, SourceLocation L, 
+                ObjCInterfaceDecl **Elts, unsigned nElts)
+    : ScopedDecl(ObjCClass, DC, L, DeclarationName()) { 
     if (nElts) {
       ForwardDecls = new ObjCInterfaceDecl*[nElts];
       memcpy(ForwardDecls, Elts, nElts*sizeof(ObjCInterfaceDecl*));
@@ -806,7 +809,7 @@
   /// Destroy - Call destructors and release memory.
   virtual void Destroy(ASTContext& C);
   
-  static ObjCClassDecl *Create(ASTContext &C, SourceLocation L,
+  static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
                                ObjCInterfaceDecl **Elts, unsigned nElts);
   
   void setInterfaceDecl(unsigned idx, ObjCInterfaceDecl *OID) {
@@ -829,13 +832,14 @@
 /// 
 /// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo;
 /// 
-class ObjCForwardProtocolDecl : public Decl {
+/// FIXME: Should this be a transparent DeclContext?
+class ObjCForwardProtocolDecl : public ScopedDecl {
   ObjCProtocolDecl **ReferencedProtocols;
   unsigned NumReferencedProtocols;
   
-  ObjCForwardProtocolDecl(SourceLocation L,
+  ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
                           ObjCProtocolDecl **Elts, unsigned nElts)
-  : Decl(ObjCForwardProtocol, L) { 
+    : ScopedDecl(ObjCForwardProtocol, DC, L, DeclarationName()) { 
     NumReferencedProtocols = nElts;
     if (nElts) {
       ReferencedProtocols = new ObjCProtocolDecl*[nElts];
@@ -848,7 +852,8 @@
   virtual ~ObjCForwardProtocolDecl();
   
 public:
-  static ObjCForwardProtocolDecl *Create(ASTContext &C, SourceLocation L, 
+  static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
+                                         SourceLocation L, 
                                          ObjCProtocolDecl **Elts, unsigned Num);
 
   
@@ -911,14 +916,14 @@
   
   SourceLocation EndLoc; // marks the '>' or identifier.
   
-  ObjCCategoryDecl(SourceLocation L, IdentifierInfo *Id)
-    : ObjCContainerDecl(ObjCCategory, L, Id),
+  ObjCCategoryDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
+    : ObjCContainerDecl(ObjCCategory, DC, L, Id),
       ClassInterface(0),
       NextClassCategory(0), PropertyDecl(0),  NumPropertyDecl(0) {
   }
 public:
   
-  static ObjCCategoryDecl *Create(ASTContext &C,
+  static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
                                   SourceLocation L, IdentifierInfo *Id);
   
   ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
@@ -987,7 +992,7 @@
 ///  @dynamic p1,d1;
 /// @end
 ///
-class ObjCCategoryImplDecl : public NamedDecl, public DeclContext {
+class ObjCCategoryImplDecl : public ScopedDecl, public DeclContext {
   /// Class interface for this category implementation
   ObjCInterfaceDecl *ClassInterface;
 
@@ -1002,12 +1007,12 @@
 
   SourceLocation EndLoc;  
 
-  ObjCCategoryImplDecl(SourceLocation L, IdentifierInfo *Id,
+  ObjCCategoryImplDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
                        ObjCInterfaceDecl *classInterface)
-    : NamedDecl(ObjCCategoryImpl, L, Id), DeclContext(ObjCCategoryImpl),
+    : ScopedDecl(ObjCCategoryImpl, DC, L, Id), DeclContext(ObjCCategoryImpl),
       ClassInterface(classInterface) {}
 public:
-  static ObjCCategoryImplDecl *Create(ASTContext &C,
+  static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
                                       SourceLocation L, IdentifierInfo *Id,
                                       ObjCInterfaceDecl *classInterface);
         
@@ -1090,7 +1095,7 @@
 /// the legacy semantics and allow developers to move private ivar declarations
 /// from the class interface to the class implementation (but I digress:-)
 ///
-class ObjCImplementationDecl : public NamedDecl, public DeclContext {
+class ObjCImplementationDecl : public ScopedDecl, public DeclContext {
   /// Class interface for this implementation
   ObjCInterfaceDecl *ClassInterface;
   
@@ -1112,14 +1117,14 @@
   
   SourceLocation EndLoc;
 
-  ObjCImplementationDecl(SourceLocation L, IdentifierInfo *Id,
+  ObjCImplementationDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
                          ObjCInterfaceDecl *classInterface,
                          ObjCInterfaceDecl *superDecl)
-    : NamedDecl(ObjCImplementation, L, Id), DeclContext(ObjCImplementation),
+    : ScopedDecl(ObjCImplementation, DC, L, Id), DeclContext(ObjCImplementation),
       ClassInterface(classInterface), SuperClass(superDecl),
       Ivars(0), NumIvars(0) {}
 public:  
-  static ObjCImplementationDecl *Create(ASTContext &C,
+  static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC, 
                                         SourceLocation L, IdentifierInfo *Id,
                                         ObjCInterfaceDecl *classInterface,
                                         ObjCInterfaceDecl *superDecl);
@@ -1205,15 +1210,15 @@
 
 /// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is 
 /// declared as @compatibility_alias alias class.
-class ObjCCompatibleAliasDecl : public NamedDecl {
+class ObjCCompatibleAliasDecl : public ScopedDecl {
   /// Class that this is an alias of.
   ObjCInterfaceDecl *AliasedClass;
   
-  ObjCCompatibleAliasDecl(SourceLocation L, IdentifierInfo *Id,
+  ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
                           ObjCInterfaceDecl* aliasedClass)
-    : NamedDecl(ObjCCompatibleAlias, L, Id), AliasedClass(aliasedClass) {}
+    : ScopedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
 public:
-  static ObjCCompatibleAliasDecl *Create(ASTContext &C,
+  static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
                                          SourceLocation L, IdentifierInfo *Id,
                                          ObjCInterfaceDecl* aliasedClass);
 
@@ -1231,7 +1236,7 @@
 /// For example:
 /// @property (assign, readwrite) int MyProperty;
 ///
-class ObjCPropertyDecl : public NamedDecl {
+class ObjCPropertyDecl : public ScopedDecl {
 public:
   enum PropertyAttributeKind {
     OBJC_PR_noattr    = 0x00, 
@@ -1260,14 +1265,16 @@
   ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
   ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
 
-  ObjCPropertyDecl(SourceLocation L, IdentifierInfo *Id, QualType T)
-    : NamedDecl(ObjCProperty, L, Id), DeclType(T),
+  ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 
+                   QualType T)
+    : ScopedDecl(ObjCProperty, DC, L, Id), DeclType(T),
       PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None),
       GetterName(Selector()), 
       SetterName(Selector()),
       GetterMethodDecl(0), SetterMethodDecl(0) {}
 public:
-  static ObjCPropertyDecl *Create(ASTContext &C, SourceLocation L, 
+  static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC, 
+                                  SourceLocation L, 
                                   IdentifierInfo *Id, QualType T,
                                   PropertyControl propControl = None);
   QualType getType() const { return DeclType; }
@@ -1332,7 +1339,7 @@
 /// in a class or category implementation block. For example:
 /// @synthesize prop1 = ivar1;
 ///
-class ObjCPropertyImplDecl : public Decl {
+class ObjCPropertyImplDecl : public ScopedDecl {
 public:
   enum Kind {
     Synthesize,
@@ -1346,18 +1353,18 @@
   /// Null for @dynamic. Required for @synthesize.
   ObjCIvarDecl *PropertyIvarDecl;
 
-  ObjCPropertyImplDecl(SourceLocation atLoc, SourceLocation L,
+  ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
                        ObjCPropertyDecl *property, 
                        Kind PK, 
                        ObjCIvarDecl *ivarDecl)
-    : Decl(ObjCPropertyImpl, L), AtLoc(atLoc), PropertyDecl(property), 
-      PropertyIvarDecl(ivarDecl) {
+    : ScopedDecl(ObjCPropertyImpl, DC, L, DeclarationName()), AtLoc(atLoc), 
+      PropertyDecl(property), PropertyIvarDecl(ivarDecl) {
     assert (PK == Dynamic || PropertyIvarDecl);
   }
   
 public:
-  static ObjCPropertyImplDecl *Create(ASTContext &C, SourceLocation atLoc, 
-                                      SourceLocation L, 
+  static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
+                                      SourceLocation atLoc, SourceLocation L, 
                                       ObjCPropertyDecl *property, 
                                       Kind PK, 
                                       ObjCIvarDecl *ivarDecl);

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=61966&r1=61965&r2=61966&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Thu Jan  8 18:49:46 2009
@@ -51,12 +51,13 @@
 }
 
 ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
+                                             DeclContext *DC,
                                              SourceLocation atLoc,
                                              IdentifierInfo *Id, 
                                              SourceLocation ClassLoc,
                                              bool ForwardDecl, bool isInternal){
   void *Mem = C.getAllocator().Allocate<ObjCInterfaceDecl>();
-  return new (Mem) ObjCInterfaceDecl(atLoc, Id, ClassLoc, ForwardDecl,
+  return new (Mem) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl,
                                      isInternal);
 }
 
@@ -104,11 +105,11 @@
   C.getAllocator().Deallocate((void *)this); 
 }
 
-ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C,
+ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
                                            SourceLocation L, 
                                            IdentifierInfo *Id) {
   void *Mem = C.getAllocator().Allocate<ObjCProtocolDecl>();
-  return new (Mem) ObjCProtocolDecl(L, Id);
+  return new (Mem) ObjCProtocolDecl(DC, L, Id);
 }
 
 ObjCProtocolDecl::~ObjCProtocolDecl() {
@@ -130,11 +131,11 @@
 }
 
 
-ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C,
+ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC,
                                      SourceLocation L,
                                      ObjCInterfaceDecl **Elts, unsigned nElts) {
   void *Mem = C.getAllocator().Allocate<ObjCClassDecl>();
-  return new (Mem) ObjCClassDecl(L, Elts, nElts);
+  return new (Mem) ObjCClassDecl(DC, L, Elts, nElts);
 }
 
 ObjCClassDecl::~ObjCClassDecl() {
@@ -155,58 +156,58 @@
 }
 
 ObjCForwardProtocolDecl *
-ObjCForwardProtocolDecl::Create(ASTContext &C,
+ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC,
                                 SourceLocation L, 
                                 ObjCProtocolDecl **Elts, unsigned NumElts) {
   void *Mem = C.getAllocator().Allocate<ObjCForwardProtocolDecl>();
-  return new (Mem) ObjCForwardProtocolDecl(L, Elts, NumElts);
+  return new (Mem) ObjCForwardProtocolDecl(DC, L, Elts, NumElts);
 }
 
 ObjCForwardProtocolDecl::~ObjCForwardProtocolDecl() {
   delete [] ReferencedProtocols;
 }
 
-ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C,
+ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
                                            SourceLocation L,
                                            IdentifierInfo *Id) {
   void *Mem = C.getAllocator().Allocate<ObjCCategoryDecl>();
-  return new (Mem) ObjCCategoryDecl(L, Id);
+  return new (Mem) ObjCCategoryDecl(DC, L, Id);
 }
 
 ObjCCategoryImplDecl *
-ObjCCategoryImplDecl::Create(ASTContext &C,
+ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
                              SourceLocation L,IdentifierInfo *Id,
                              ObjCInterfaceDecl *ClassInterface) {
   void *Mem = C.getAllocator().Allocate<ObjCCategoryImplDecl>();
-  return new (Mem) ObjCCategoryImplDecl(L, Id, ClassInterface);
+  return new (Mem) ObjCCategoryImplDecl(DC, L, Id, ClassInterface);
 }
 
 ObjCImplementationDecl *
-ObjCImplementationDecl::Create(ASTContext &C,
+ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, 
                                SourceLocation L,
                                IdentifierInfo *Id,
                                ObjCInterfaceDecl *ClassInterface,
                                ObjCInterfaceDecl *SuperDecl) {
   void *Mem = C.getAllocator().Allocate<ObjCImplementationDecl>();
-  return new (Mem) ObjCImplementationDecl(L, Id, ClassInterface, SuperDecl);
+  return new (Mem) ObjCImplementationDecl(DC, L, Id, ClassInterface, SuperDecl);
 }
 
 ObjCCompatibleAliasDecl *
-ObjCCompatibleAliasDecl::Create(ASTContext &C,
+ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
                                 SourceLocation L,
                                 IdentifierInfo *Id, 
                                 ObjCInterfaceDecl* AliasedClass) {
   void *Mem = C.getAllocator().Allocate<ObjCCompatibleAliasDecl>();
-  return new (Mem) ObjCCompatibleAliasDecl(L, Id, AliasedClass);
+  return new (Mem) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
 }
 
-ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C,
+ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
                                            SourceLocation L,
                                            IdentifierInfo *Id,
                                            QualType T,
                                            PropertyControl propControl) {
   void *Mem = C.getAllocator().Allocate<ObjCPropertyDecl>();
-  return new (Mem) ObjCPropertyDecl(L, Id, T);
+  return new (Mem) ObjCPropertyDecl(DC, L, Id, T);
 }
 
 //===----------------------------------------------------------------------===//
@@ -757,13 +758,14 @@
 }
 
 ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
+                                                   DeclContext *DC,
                                                    SourceLocation atLoc,
                                                    SourceLocation L,
                                                    ObjCPropertyDecl *property,
                                                    Kind PK,
                                                    ObjCIvarDecl *ivar) {
   void *Mem = C.getAllocator().Allocate<ObjCPropertyImplDecl>();
-  return new (Mem) ObjCPropertyImplDecl(atLoc, L, property, PK, ivar);
+  return new (Mem) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar);
 }
 
 

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Thu Jan  8 18:49:46 2009
@@ -94,7 +94,7 @@
   Context.setObjCClassType(ClassTypedef);
   // Synthesize "@class Protocol;
   ObjCInterfaceDecl *ProtocolDecl =
-    ObjCInterfaceDecl::Create(Context, SourceLocation(),
+    ObjCInterfaceDecl::Create(Context, CurContext, SourceLocation(),
                               &Context.Idents.get("Protocol"), 
                               SourceLocation(), true);
   Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl));

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=61966&r1=61965&r2=61966&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Jan  8 18:49:46 2009
@@ -93,12 +93,14 @@
       IDecl->setForwardDecl(false);
     }
   } else {
-    IDecl = ObjCInterfaceDecl::Create(Context, AtInterfaceLoc, 
+    IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtInterfaceLoc, 
                                       ClassName, ClassLoc);
     if (AttrList)
       ProcessDeclAttributeList(IDecl, AttrList);
   
     ObjCInterfaceDecls[ClassName] = IDecl;
+    // FIXME: PushOnScopeChains
+    CurContext->addDecl(Context, IDecl);
     // Remember that this needs to be removed when the scope is popped.
     TUScope->AddDecl(IDecl);
   }
@@ -178,13 +180,15 @@
   
   // Everything checked out, instantiate a new alias declaration AST.
   ObjCCompatibleAliasDecl *AliasDecl = 
-    ObjCCompatibleAliasDecl::Create(Context, AtLoc, AliasName, CDecl);
+    ObjCCompatibleAliasDecl::Create(Context, CurContext, AtLoc, AliasName, CDecl);
   
   ObjCAliasDecls[AliasName] = AliasDecl;
-  
+
+  // FIXME: PushOnScopeChains?
+  CurContext->addDecl(Context, AliasDecl);
   if (!CheckObjCDeclScope(AliasDecl))
     TUScope->AddDecl(AliasDecl);
-  
+
   return AliasDecl;
 }
 
@@ -212,7 +216,10 @@
     PDecl->setLocation(AtProtoInterfaceLoc);
     PDecl->setForwardDecl(false);
   } else {
-    PDecl = ObjCProtocolDecl::Create(Context, AtProtoInterfaceLoc,ProtocolName);
+    PDecl = ObjCProtocolDecl::Create(Context, CurContext, 
+                                     AtProtoInterfaceLoc,ProtocolName);
+    // FIXME: PushOnScopeChains?
+    CurContext->addDecl(Context, PDecl);
     PDecl->setForwardDecl(false);
     ObjCProtocols[ProtocolName] = PDecl;
   }
@@ -442,17 +449,21 @@
   for (unsigned i = 0; i != NumElts; ++i) {
     IdentifierInfo *Ident = IdentList[i].first;
     ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident];
-    if (PDecl == 0) // Not already seen?
-      PDecl = ObjCProtocolDecl::Create(Context, IdentList[i].second, Ident);
+    if (PDecl == 0) { // Not already seen?
+      PDecl = ObjCProtocolDecl::Create(Context, CurContext, 
+                                       IdentList[i].second, Ident);
+      // FIXME: PushOnScopeChains?
+      CurContext->addDecl(Context, PDecl);
+    }
     if (attrList)
       ProcessDeclAttributeList(PDecl, attrList);
     Protocols.push_back(PDecl);
   }
   
   ObjCForwardProtocolDecl *PDecl = 
-    ObjCForwardProtocolDecl::Create(Context, AtProtocolLoc,
+    ObjCForwardProtocolDecl::Create(Context, CurContext, AtProtocolLoc,
                                     &Protocols[0], Protocols.size());
-  
+  CurContext->addDecl(Context, PDecl);
   CheckObjCDeclScope(PDecl);
   return PDecl;
 }
@@ -468,7 +479,9 @@
   ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName);
   
   ObjCCategoryDecl *CDecl = 
-    ObjCCategoryDecl::Create(Context, AtInterfaceLoc, CategoryName);
+    ObjCCategoryDecl::Create(Context, CurContext, AtInterfaceLoc, CategoryName);
+  // FIXME: PushOnScopeChains?
+  CurContext->addDecl(Context, CDecl);
   CDecl->setClassInterface(IDecl);
   
   /// Check that class of this category is already completely declared.
@@ -508,11 +521,15 @@
                       IdentifierInfo *CatName, SourceLocation CatLoc) {
   ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName);
   ObjCCategoryImplDecl *CDecl = 
-    ObjCCategoryImplDecl::Create(Context, AtCatImplLoc, CatName, IDecl);
+    ObjCCategoryImplDecl::Create(Context, CurContext, AtCatImplLoc, CatName,
+                                 IDecl);
   /// Check that class of this category is already completely declared.
   if (!IDecl || IDecl->isForwardDecl())
     Diag(ClassLoc, diag::err_undef_interface) << ClassName;
 
+  // FIXME: PushOnScopeChains?
+  CurContext->addDecl(Context, CDecl);
+
   /// TODO: Check that CatName, category name, is not used in another
   // implementation.
   ObjCCategoryImpls.push_back(CDecl);
@@ -570,20 +587,25 @@
 
     // FIXME: Do we support attributes on the @implementation? If so
     // we should copy them over.
-    IDecl = ObjCInterfaceDecl::Create(Context, AtClassImplLoc, ClassName, 
-                                      ClassLoc, false, true);
+    IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassImplLoc, 
+                                      ClassName, ClassLoc, false, true);
     ObjCInterfaceDecls[ClassName] = IDecl;
     IDecl->setSuperClass(SDecl);
     IDecl->setLocEnd(ClassLoc);
     
+    // FIXME: PushOnScopeChains?
+    CurContext->addDecl(Context, IDecl);
     // Remember that this needs to be removed when the scope is popped.
     TUScope->AddDecl(IDecl);
   }
   
   ObjCImplementationDecl* IMPDecl = 
-    ObjCImplementationDecl::Create(Context, AtClassImplLoc, ClassName, 
-                                   IDecl, SDecl);
+    ObjCImplementationDecl::Create(Context, CurContext, AtClassImplLoc, 
+                                   ClassName, IDecl, SDecl);
   
+  // FIXME: PushOnScopeChains?
+  CurContext->addDecl(Context, IMPDecl);
+
   if (CheckObjCDeclScope(IMPDecl))
     return IMPDecl;
   
@@ -875,10 +897,12 @@
     }
     ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); 
     if (!IDecl) {  // Not already seen?  Make a forward decl.
-      IDecl = ObjCInterfaceDecl::Create(Context, AtClassLoc, IdentList[i],
-                                        SourceLocation(), true);
+      IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassLoc, 
+                                        IdentList[i], SourceLocation(), true);
       ObjCInterfaceDecls[IdentList[i]] = IDecl;
 
+      // FIXME: PushOnScopeChains?
+      CurContext->addDecl(Context, IDecl);
       // Remember that this needs to be removed when the scope is popped.
       TUScope->AddDecl(IDecl);
     }
@@ -886,10 +910,10 @@
     Interfaces.push_back(IDecl);
   }
   
-  ObjCClassDecl *CDecl = ObjCClassDecl::Create(Context, AtClassLoc,
+  ObjCClassDecl *CDecl = ObjCClassDecl::Create(Context, CurContext, AtClassLoc,
                                                &Interfaces[0],
                                                Interfaces.size());
-  
+  CurContext->addDecl(Context, CDecl);
   CheckObjCDeclScope(CDecl);
   return CDecl;  
 }
@@ -1527,8 +1551,11 @@
   if (t->isArrayType() || t->isFunctionType())
     Diag(AtLoc, diag::err_property_type) << T;
   
-  ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, AtLoc, 
+  ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, CurContext, AtLoc, 
                                                      FD.D.getIdentifier(), T);
+  // FIXME: PushOnScopeChains?
+  CurContext->addDecl(Context, PDecl);
+
   // Regardless of setter/getter attribute, we save the default getter/setter
   // selector names in anticipation of declaration of setter/getter methods.
   PDecl->setGetterName(GetterSel);
@@ -1661,11 +1688,13 @@
   }
   assert (property && "ActOnPropertyImplDecl - property declaration missing");
   ObjCPropertyImplDecl *PIDecl = 
-    ObjCPropertyImplDecl::Create(Context, AtLoc, PropertyLoc, property, 
+    ObjCPropertyImplDecl::Create(Context, CurContext, AtLoc, PropertyLoc, 
+                                 property, 
                                  (Synthesize ? 
                                   ObjCPropertyImplDecl::Synthesize 
                                   : ObjCPropertyImplDecl::Dynamic),
                                  Ivar);
+  CurContext->addDecl(Context, PIDecl);
   if (IC) {
     if (Synthesize)
       if (ObjCPropertyImplDecl *PPIDecl = 





More information about the cfe-commits mailing list