[cfe-commits] r71571 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/protocol-property-synth.m
Fariborz Jahanian
fjahanian at apple.com
Tue May 12 11:14:29 PDT 2009
Author: fjahanian
Date: Tue May 12 13:14:29 2009
New Revision: 71571
URL: http://llvm.org/viewvc/llvm-project?rev=71571&view=rev
Log:
Patch to implement ivar synthesis of properties declared in protocols
only and used in class imllementations (objc2 Nonfragile ABI specific).
Added:
cfe/trunk/test/CodeGenObjC/protocol-property-synth.m
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=71571&r1=71570&r2=71571&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue May 12 13:14:29 2009
@@ -535,6 +535,11 @@
void CollectObjCIvars(const ObjCInterfaceDecl *OI,
llvm::SmallVectorImpl<FieldDecl*> &Fields);
+
+ void CollectSynthesizedIvars(const ObjCInterfaceDecl *OI,
+ llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
+ void CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
+ llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
//===--------------------------------------------------------------------===//
// Type Operators
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=71571&r1=71570&r2=71571&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue May 12 13:14:29 2009
@@ -685,6 +685,38 @@
CollectLocalObjCIvars(this, OI, Fields);
}
+void ASTContext::CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
+ llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) {
+ for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(*this),
+ E = PD->prop_end(*this); I != E; ++I)
+ if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl())
+ Ivars.push_back(Ivar);
+
+ // Also look into nested protocols.
+ for (ObjCProtocolDecl::protocol_iterator P = PD->protocol_begin(),
+ E = PD->protocol_end(); P != E; ++P)
+ CollectProtocolSynthesizedIvars(*P, Ivars);
+}
+
+/// CollectSynthesizedIvars -
+/// This routine collect synthesized ivars for the designated class.
+///
+void ASTContext::CollectSynthesizedIvars(const ObjCInterfaceDecl *OI,
+ llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) {
+ for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(*this),
+ E = OI->prop_end(*this); I != E; ++I) {
+ if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl())
+ Ivars.push_back(Ivar);
+ }
+ // Also look into interface's protocol list for properties declared
+ // in the protocol and whose ivars are synthesized.
+ for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(),
+ PE = OI->protocol_end(); P != PE; ++P) {
+ ObjCProtocolDecl *PD = (*P);
+ CollectProtocolSynthesizedIvars(PD, Ivars);
+ }
+}
+
/// getInterfaceLayoutImpl - Get or compute information about the
/// layout of the given interface.
///
@@ -704,11 +736,9 @@
unsigned FieldCount = D->ivar_size();
// Add in synthesized ivar count if laying out an implementation.
if (Impl) {
- for (ObjCInterfaceDecl::prop_iterator I = D->prop_begin(*this),
- E = D->prop_end(*this); I != E; ++I)
- if ((*I)->getPropertyIvarDecl())
- ++FieldCount;
-
+ llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
+ CollectSynthesizedIvars(D, Ivars);
+ FieldCount += Ivars.size();
// If there aren't any sythesized ivars then reuse the interface
// entry. Note we can't cache this because we simply free all
// entries later; however we shouldn't look up implementations
@@ -750,11 +780,11 @@
}
// And synthesized ivars, if this is an implementation.
if (Impl) {
- for (ObjCInterfaceDecl::prop_iterator I = D->prop_begin(*this),
- E = D->prop_end(*this); I != E; ++I) {
- if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl())
- NewEntry->LayoutField(Ivar, i++, false, StructPacking, *this);
- }
+ // FIXME. Do we need to colltect twice?
+ llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
+ CollectSynthesizedIvars(D, Ivars);
+ for (unsigned k = 0, e = Ivars.size(); k != e; ++k)
+ NewEntry->LayoutField(Ivars[k], i++, false, StructPacking, *this);
}
// Finally, round the size of the total struct up to the alignment of the
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=71571&r1=71570&r2=71571&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue May 12 13:14:29 2009
@@ -53,15 +53,14 @@
return OID;
// Also look in synthesized ivars.
- for (ObjCInterfaceDecl::prop_iterator I = OID->prop_begin(Context),
- E = OID->prop_end(Context); I != E; ++I) {
- if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl()) {
- if (OIVD == Ivar)
- return OID;
- ++Index;
- }
+ llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
+ Context.CollectSynthesizedIvars(OID, Ivars);
+ for (unsigned k = 0, e = Ivars.size(); k != e; ++k) {
+ if (OIVD == Ivars[k])
+ return OID;
+ ++Index;
}
-
+
// Otherwise check in the super class.
if (const ObjCInterfaceDecl *Super = OID->getSuperClass())
return FindIvarInterface(Context, Super, OIVD, Index);
@@ -3153,14 +3152,13 @@
llvm::SmallVector<FieldDecl*, 32> RecFields;
const ObjCInterfaceDecl *OI = OMD->getClassInterface();
CGM.getContext().CollectObjCIvars(OI, RecFields);
-
+
// Add this implementations synthesized ivars.
- for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(CGM.getContext()),
- E = OI->prop_end(CGM.getContext()); I != E; ++I) {
- if (ObjCIvarDecl *IV = (*I)->getPropertyIvarDecl())
- RecFields.push_back(cast<FieldDecl>(IV));
- }
-
+ llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
+ CGM.getContext().CollectSynthesizedIvars(OI, Ivars);
+ for (unsigned k = 0, e = Ivars.size(); k != e; ++k)
+ RecFields.push_back(cast<FieldDecl>(Ivars[k]));
+
if (RecFields.empty())
return llvm::Constant::getNullValue(PtrTy);
@@ -4677,10 +4675,12 @@
Res.push_back(*I);
}
- for (ObjCInterfaceDecl::prop_iterator I = OID->prop_begin(CGM.getContext()),
- E = OID->prop_end(CGM.getContext()); I != E; ++I)
- if (ObjCIvarDecl *IV = (*I)->getPropertyIvarDecl())
- Res.push_back(IV);
+ // Also save synthesize ivars.
+ // FIXME. Why can't we just use passed in Res small vector?
+ llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
+ CGM.getContext().CollectSynthesizedIvars(OID, Ivars);
+ for (unsigned k = 0, e = Ivars.size(); k != e; ++k)
+ Res.push_back(Ivars[k]);
}
llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList(
Added: cfe/trunk/test/CodeGenObjC/protocol-property-synth.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/protocol-property-synth.m?rev=71571&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/protocol-property-synth.m (added)
+++ cfe/trunk/test/CodeGenObjC/protocol-property-synth.m Tue May 12 13:14:29 2009
@@ -0,0 +1,33 @@
+// RUN: clang-cc -triple x86_64-apple-darwin10 -emit-llvm -o %t %s
+
+ at interface BaseClass {
+ id _delegate;
+}
+ at end
+
+ at protocol MyProtocol
+ at optional
+ at property(assign) id delegate;
+ at end
+
+ at protocol AnotherProtocol
+ at optional
+ at property(assign) id myanother;
+ at end
+
+ at protocol SubProtocol <MyProtocol>
+ at property(assign) id another;
+ at end
+
+ at interface SubClass : BaseClass <SubProtocol, AnotherProtocol> {
+}
+
+ at end
+
+ at implementation BaseClass @end
+
+ at implementation SubClass
+ at synthesize delegate = _Subdelegate;
+ at synthesize another;
+ at synthesize myanother;
+ at end
More information about the cfe-commits
mailing list