[cfe-commits] r66689 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/newproperty-class-method-1.m
Steve Naroff
snaroff at apple.com
Wed Mar 11 13:12:19 PDT 2009
Author: snaroff
Date: Wed Mar 11 15:12:18 2009
New Revision: 66689
URL: http://llvm.org/viewvc/llvm-project?rev=66689&view=rev
Log:
Implement FIXME related to <rdar://problem/6496506> Implement class setter/getter for properties.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/newproperty-class-method-1.m
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=66689&r1=66688&r2=66689&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Mar 11 15:12:18 2009
@@ -1957,16 +1957,54 @@
// Also must look for a getter name which uses property syntax.
Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
if (ObjCMethodDecl *MD = getCurMethodDecl()) {
- ObjCMethodDecl *OMD;
+ ObjCInterfaceDecl *IFace = MD->getClassInterface();
+ ObjCMethodDecl *Getter;
// FIXME: need to also look locally in the implementation.
- if ((OMD = MD->getClassInterface()->lookupClassMethod(Sel))) {
+ if ((Getter = IFace->lookupClassMethod(Sel))) {
// Check the use of this method.
- if (DiagnoseUseOfDecl(OMD, MemberLoc))
+ if (DiagnoseUseOfDecl(Getter, MemberLoc))
return ExprError();
+ }
+ // If we found a getter then this may be a valid dot-reference, we
+ // will look for the matching setter, in case it is needed.
+ Selector SetterSel =
+ SelectorTable::constructSetterName(PP.getIdentifierTable(),
+ PP.getSelectorTable(), &Member);
+ ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel);
+ if (!Setter) {
+ // If this reference is in an @implementation, also check for 'private'
+ // methods.
+ if (ObjCImplementationDecl *ImpDecl =
+ ObjCImplementations[IFace->getIdentifier()])
+ Setter = ImpDecl->getInstanceMethod(SetterSel);
+ }
+ // Look through local category implementations associated with the class.
+ if (!Setter) {
+ for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Setter; i++) {
+ if (ObjCCategoryImpls[i]->getClassInterface() == IFace)
+ Setter = ObjCCategoryImpls[i]->getClassMethod(SetterSel);
+ }
+ }
- return Owned(new (Context) ObjCMessageExpr(BaseExpr, Sel,
- OMD->getResultType(), OMD, OpLoc, MemberLoc, NULL, 0));
+ if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
+ return ExprError();
+
+ if (Getter || Setter) {
+ QualType PType;
+
+ if (Getter)
+ PType = Getter->getResultType();
+ else {
+ for (ObjCMethodDecl::param_iterator PI = Setter->param_begin(),
+ E = Setter->param_end(); PI != E; ++PI)
+ PType = (*PI)->getType();
+ }
+ // FIXME: we must check that the setter has property type.
+ return Owned(new (Context) ObjCKVCRefExpr(Getter, PType,
+ Setter, MemberLoc, BaseExpr));
}
+ return ExprError(Diag(MemberLoc, diag::err_property_not_found)
+ << &Member << BaseType);
}
}
Modified: cfe/trunk/test/SemaObjC/newproperty-class-method-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/newproperty-class-method-1.m?rev=66689&r1=66688&r2=66689&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/newproperty-class-method-1.m (original)
+++ cfe/trunk/test/SemaObjC/newproperty-class-method-1.m Wed Mar 11 15:12:18 2009
@@ -22,12 +22,9 @@
+ (void) classMeth
{
-#if 0
-// FIXME: implement.
self.magicNumber = 10;
if (self.magicNumber != 10)
abort ();
-#endif
}
@end
More information about the cfe-commits
mailing list