]> granicus.if.org Git - clang/commitdiff
Patch removes IVars list from ObjCInterfaceDecl and
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 19 Feb 2010 00:31:17 +0000 (00:31 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 19 Feb 2010 00:31:17 +0000 (00:31 +0000)
instead relies on their DeclContext for iteration, etc.

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

include/clang/AST/ASTContext.h
include/clang/AST/DeclObjC.h
lib/AST/ASTContext.cpp
lib/AST/RecordLayoutBuilder.cpp
lib/CodeGen/CGObjCMac.cpp
lib/Frontend/PCHReaderDecl.cpp
lib/Frontend/RewriteObjC.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclObjC.cpp
test/CodeGenObjC/stand-alone-implementation.m [new file with mode: 0644]

index 2ed9fd7080188adab318709b142ec4c360caff78..ec3fa2343e037074628d228ead6768313e657fa3 100644 (file)
@@ -882,9 +882,8 @@ public:
                         llvm::SmallVectorImpl<FieldDecl*> &Fields);
 
   void ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI,
-                               llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars,
-                               bool CollectSynthesized = true);
-  void CollectSynthesizedIvars(const ObjCInterfaceDecl *OI,
+                               llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
+  void CollectNonClassIvars(const ObjCInterfaceDecl *OI,
                                llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
   void CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
                                llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
index e562d352e070ee87dc7c0c591b8e3757d33e8a94..686c1eb2f8b0cd2947b76fbd2b92fbf370f8ba92 100644 (file)
@@ -494,11 +494,13 @@ public:
   }
   unsigned protocol_size() const { return ReferencedProtocols.size(); }
 
-  typedef ObjCList<ObjCIvarDecl>::iterator ivar_iterator;
-  ivar_iterator ivar_begin() const { return IVars.begin(); }
-  ivar_iterator ivar_end() const { return IVars.end(); }
-  unsigned ivar_size() const { return IVars.size(); }
-  bool ivar_empty() const { return IVars.empty(); }
+  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
+  ivar_iterator ivar_begin() const { return  ivar_iterator(decls_begin()); }
+  ivar_iterator ivar_end() const { return ivar_iterator(decls_end()); }
+  unsigned ivar_size() const {
+    return std::distance(ivar_begin(), ivar_end());
+  }
+  bool ivar_empty() const { return ivar_begin() == ivar_end(); }
 
   /// setProtocolList - Set the list of protocols that this interface
   /// implements.
@@ -514,10 +516,6 @@ public:
                                        const SourceLocation *Locs,
                                        ASTContext &C);
 
-  void setIVarList(ObjCIvarDecl * const *List, unsigned Num, ASTContext &C) {
-    IVars.set(List, Num, C);
-  }
-
   bool isForwardDecl() const { return ForwardDecl; }
   void setForwardDecl(bool val) { ForwardDecl = val; }
 
index c23babb9a4a534976a757367450dbc04278f98ba..74212fe785d8e9356cd5042ce540054d31ee6e96 100644 (file)
@@ -872,14 +872,13 @@ void ASTContext::CollectObjCIvars(const ObjCInterfaceDecl *OI,
 /// Collect all ivars, including those synthesized, in the current class.
 ///
 void ASTContext::ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI,
-                                 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars,
-                                 bool CollectSynthesized) {
+                                 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) {
   for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
          E = OI->ivar_end(); I != E; ++I) {
      Ivars.push_back(*I);
   }
-  if (CollectSynthesized)
-    CollectSynthesizedIvars(OI, Ivars);
+
+  CollectNonClassIvars(OI, Ivars);
 }
 
 void ASTContext::CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
@@ -895,10 +894,11 @@ void ASTContext::CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
     CollectProtocolSynthesizedIvars(*P, Ivars);
 }
 
-/// CollectSynthesizedIvars -
-/// This routine collect synthesized ivars for the designated class.
+/// CollectNonClassIvars -
+/// This routine collects all other ivars which are not declared in the class.
+/// This includes synthesized ivars and those in class's implementation.
 ///
-void ASTContext::CollectSynthesizedIvars(const ObjCInterfaceDecl *OI,
+void ASTContext::CollectNonClassIvars(const ObjCInterfaceDecl *OI,
                                 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) {
   for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(),
        E = OI->prop_end(); I != E; ++I) {
@@ -912,6 +912,13 @@ void ASTContext::CollectSynthesizedIvars(const ObjCInterfaceDecl *OI,
     ObjCProtocolDecl *PD = (*P);
     CollectProtocolSynthesizedIvars(PD, Ivars);
   }
+
+  // Also add any ivar defined in this class's implementation
+  if (ObjCImplementationDecl *ImplDecl = OI->getImplementation()) {
+    for (ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(),
+         E = ImplDecl->ivar_end(); I != E; ++I)
+      Ivars.push_back(*I);
+  }
 }
 
 /// CollectInheritedProtocols - Collect all protocols in current class and
index 50acd15fde05c6c63eaa5ec3fc6d0b1e4c4f4423..10c5089f2253f6a49c479af3035bca0fc1d9d23d 100644 (file)
@@ -487,6 +487,7 @@ void ASTRecordLayoutBuilder::Layout(const RecordDecl *D) {
   FinishLayout();
 }
 
+// FIXME. Impl is no longer needed.
 void ASTRecordLayoutBuilder::Layout(const ObjCInterfaceDecl *D,
                                     const ObjCImplementationDecl *Impl) {
   if (ObjCInterfaceDecl *SD = D->getSuperClass()) {
@@ -508,10 +509,9 @@ void ASTRecordLayoutBuilder::Layout(const ObjCInterfaceDecl *D,
 
   if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
     UpdateAlignment(AA->getMaxAlignment());
-
   // Layout each ivar sequentially.
   llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
-  Ctx.ShallowCollectObjCIvars(D, Ivars, Impl);
+  Ctx.ShallowCollectObjCIvars(D, Ivars);
   for (unsigned i = 0, e = Ivars.size(); i != e; ++i)
     LayoutField(Ivars[i]);
 
index b16a510f98f6b2ed9f4758c685402f6e162643a5..5f9c51813ad654eac8252aae7b477d97ca271e15 100644 (file)
@@ -3293,7 +3293,7 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayout(
 
   // Add this implementations synthesized ivars.
   llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
-  CGM.getContext().CollectSynthesizedIvars(OI, Ivars);
+  CGM.getContext().CollectNonClassIvars(OI, Ivars);
   for (unsigned k = 0, e = Ivars.size(); k != e; ++k)
     RecFields.push_back(cast<FieldDecl>(Ivars[k]));
 
index cadc5427658abc8252787a17658f70fb4d3da1f5..af69664fe1f05409897dfc0ad0a2d2b0442b6588 100644 (file)
@@ -235,7 +235,6 @@ void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
   IVars.reserve(NumIvars);
   for (unsigned I = 0; I != NumIvars; ++I)
     IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
-  ID->setIVarList(IVars.data(), NumIvars, *Reader.getContext());
   ID->setCategoryList(
                cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
   ID->setForwardDecl(Record[Idx++]);
index 5d99491cd6a1962a85cf178945bd6efe156862ae..fff8b54ba6cb4d0269b926d07ca42a32311ea8ec 100644 (file)
@@ -3534,12 +3534,12 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
     ObjCInterfaceDecl::ivar_iterator IVI, IVE;
     llvm::SmallVector<ObjCIvarDecl *, 8> IVars;
     if (!IDecl->ivar_empty()) {
-      for (ObjCImplementationDecl::ivar_iterator
+      for (ObjCInterfaceDecl::ivar_iterator
              IV = IDecl->ivar_begin(), IVEnd = IDecl->ivar_end();
            IV != IVEnd; ++IV)
         IVars.push_back(*IV);
-      IVI = IVars.begin();
-      IVE = IVars.end();
+      IVI = IDecl->ivar_begin();
+      IVE = IDecl->ivar_end();
     } else {
       IVI = CDecl->ivar_begin();
       IVE = CDecl->ivar_end();
index 949669aa5722817ed2ddbc00ebdc55b70b5a6076..847602d8027cbb5e07dee736ccd7107117f62014 100644 (file)
@@ -5641,7 +5641,6 @@ void Sema::ActOnFields(Scope* S,
     ObjCIvarDecl **ClsFields =
       reinterpret_cast<ObjCIvarDecl**>(RecFields.data());
     if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(EnclosingDecl)) {
-      ID->setIVarList(ClsFields, RecFields.size(), Context);
       ID->setLocEnd(RBrac);
       // Add ivar's to class's DeclContext.
       for (unsigned i = 0, e = RecFields.size(); i != e; ++i) {
index a7e0145a521495eaef681c63e4d4262ed348360c..cd64e664816bd2ea18bf8962d157a8fff488c1c3 100644 (file)
@@ -821,12 +821,12 @@ void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
   /// (legacy objective-c @implementation decl without an @interface decl).
   /// Add implementations's ivar to the synthesize class's ivar list.
   if (IDecl->isImplicitInterfaceDecl()) {
-    IDecl->setIVarList(ivars, numIvars, Context);
     IDecl->setLocEnd(RBrace);
     // Add ivar's to class's DeclContext.
     for (unsigned i = 0, e = numIvars; i != e; ++i) {
       ivars[i]->setLexicalDeclContext(ImpDecl);
       IDecl->makeDeclVisibleInContext(ivars[i], false);
+      ImpDecl->addDecl(ivars[i]);
     }
     
     return;
@@ -2446,8 +2446,7 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
                                   PropertyIvar, PropType, /*Dinfo=*/0,
                                   ObjCIvarDecl::Public,
                                   (Expr *)0);
-      Ivar->setLexicalDeclContext(IDecl);
-      IDecl->addDecl(Ivar);
+      IDecl->makeDeclVisibleInContext(Ivar, false);
       property->setPropertyIvarDecl(Ivar);
       if (!getLangOptions().ObjCNonFragileABI)
         Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId;
diff --git a/test/CodeGenObjC/stand-alone-implementation.m b/test/CodeGenObjC/stand-alone-implementation.m
new file mode 100644 (file)
index 0000000..a519495
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-X86-64 %s
+
+// radar 7547942
+// Allow injection of ivars into implementation's implicit class.
+
+@implementation INTFSTANDALONE // expected-warning {{cannot find interface declaration for 'INTFSTANDALONE'}}
+{
+  id IVAR1;
+  id IVAR2;
+}
+- (id) Meth { return IVAR1; }
+@end
+
+// CHECK-X86-64: @"OBJC_IVAR_$_INTFSTANDALONE.IVAR1"
+// CHECK-X86-64: @"OBJC_IVAR_$_INTFSTANDALONE.IVAR2"
+