r206781 - Objective-C. Patch to allow use of dot syntax on class
Fariborz Jahanian
fjahanian at apple.com
Mon Apr 21 13:22:17 PDT 2014
Author: fjahanian
Date: Mon Apr 21 15:22:17 2014
New Revision: 206781
URL: http://llvm.org/viewvc/llvm-project?rev=206781&view=rev
Log:
Objective-C. Patch to allow use of dot syntax on class
objects to fund root class's instance methods.
// rdar://16650575
Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaPseudoObject.cpp
cfe/trunk/test/SemaObjC/class-property-access.m
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=206781&r1=206780&r2=206781&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Mon Apr 21 15:22:17 2014
@@ -1762,10 +1762,7 @@ ActOnClassPropertyRefExpr(IdentifierInfo
// If this reference is in an @implementation, check for 'private' methods.
if (!Getter)
- if (ObjCMethodDecl *CurMeth = getCurMethodDecl())
- if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface())
- if (ObjCImplementationDecl *ImpDecl = ClassDecl->getImplementation())
- Getter = ImpDecl->getClassMethod(Sel);
+ Getter = IFace->lookupPrivateClassMethod(Sel);
if (Getter) {
// FIXME: refactor/share with ActOnMemberReference().
@@ -1784,10 +1781,7 @@ ActOnClassPropertyRefExpr(IdentifierInfo
if (!Setter) {
// If this reference is in an @implementation, also check for 'private'
// methods.
- if (ObjCMethodDecl *CurMeth = getCurMethodDecl())
- if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface())
- if (ObjCImplementationDecl *ImpDecl = ClassDecl->getImplementation())
- Setter = ImpDecl->getClassMethod(SetterSel);
+ Setter = IFace->lookupPrivateClassMethod(SetterSel);
}
// Look through local category implementations associated with the class.
if (!Setter)
Modified: cfe/trunk/lib/Sema/SemaPseudoObject.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaPseudoObject.cpp?rev=206781&r1=206780&r2=206781&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaPseudoObject.cpp (original)
+++ cfe/trunk/lib/Sema/SemaPseudoObject.cpp Mon Apr 21 15:22:17 2014
@@ -681,7 +681,8 @@ ExprResult ObjCPropertyOpBuilder::buildG
// Build a message-send.
ExprResult msg;
- if (Getter->isInstanceMethod() || RefExpr->isObjectReceiver()) {
+ if ((Getter->isInstanceMethod() && !RefExpr->isClassReceiver()) ||
+ RefExpr->isObjectReceiver()) {
assert(InstanceReceiver || RefExpr->isSuperReceiver());
msg = S.BuildInstanceMessageImplicit(InstanceReceiver, receiverType,
GenericLoc, Getter->getSelector(),
@@ -750,7 +751,8 @@ ExprResult ObjCPropertyOpBuilder::buildS
// Build a message-send.
ExprResult msg;
- if (Setter->isInstanceMethod() || RefExpr->isObjectReceiver()) {
+ if ((Setter->isInstanceMethod() && !RefExpr->isClassReceiver()) ||
+ RefExpr->isObjectReceiver()) {
msg = S.BuildInstanceMessageImplicit(InstanceReceiver, receiverType,
GenericLoc, SetterSelector, Setter,
MultiExprArg(args, 1));
Modified: cfe/trunk/test/SemaObjC/class-property-access.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-property-access.m?rev=206781&r1=206780&r2=206781&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/class-property-access.m (original)
+++ cfe/trunk/test/SemaObjC/class-property-access.m Mon Apr 21 15:22:17 2014
@@ -11,3 +11,46 @@ int main ()
return Test.one.two;
}
+// rdar://16650575
+__attribute__((objc_root_class))
+ at interface RootClass {
+ Class isa;
+}
+
+ at property int property;
+-(int)method;
+- (void) setMethod : (int)arg;
++(int)classMethod;
+ at end
+
+ at interface Subclass : RootClass @end
+void Test1() {
+ // now okay
+ (void)RootClass.property;
+ (void)Subclass.property;
+ (void)RootClass.method;
+ (void)Subclass.method;
+
+ RootClass.property = 1;
+ Subclass.property = 2;
+ RootClass.method = 3;
+ Subclass.method = 4;
+
+ // okay
+ (void)RootClass.classMethod;
+ (void)Subclass.classMethod;
+
+ // also okay
+ [RootClass property];
+ [Subclass property];
+ [RootClass method];
+ [Subclass method];
+ [RootClass classMethod];
+ [Subclass classMethod];
+
+ // also okay
+ [RootClass setProperty : 1];
+ [Subclass setProperty : 2];
+ [RootClass setMethod : 3];
+ [Subclass setMethod : 4];
+}
More information about the cfe-commits
mailing list