]> granicus.if.org Git - clang/commitdiff
Partial fix <rdar://problem/6301205> [irgen] dot-syntax on super isn't supported.
authorSteve Naroff <snaroff@apple.com>
Thu, 5 Mar 2009 20:12:00 +0000 (20:12 +0000)
committerSteve Naroff <snaroff@apple.com>
Thu, 5 Mar 2009 20:12:00 +0000 (20:12 +0000)
Tweak Sema::ActOnMemberReferenceExpr() and Sema::ActOnDeclarationNameExpr() to handle "super." notation for Class methods.

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

lib/Sema/SemaExpr.cpp
test/SemaObjC/super-property-notation.m [new file with mode: 0644]

index f71f82daa902547984ea3c5f0aee11a588936dd0..8630da3c3f1739bd75a604bf755d22537aab7ec5 100644 (file)
@@ -673,8 +673,13 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
     }
     // Needed to implement property "super.method" notation.
     if (D == 0 && II->isStr("super")) {
-      QualType T = Context.getPointerType(Context.getObjCInterfaceType(
-                     getCurMethodDecl()->getClassInterface()));
+      QualType T;
+      
+      if (getCurMethodDecl()->isInstanceMethod())
+        T = Context.getPointerType(Context.getObjCInterfaceType(
+                                   getCurMethodDecl()->getClassInterface()));
+      else
+        T = Context.getObjCClassType();
       return Owned(new (Context) ObjCSuperExpr(Loc, T));
     }
   }
@@ -1956,6 +1961,24 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
     return ExprError(Diag(MemberLoc, diag::err_property_not_found)
                        << &Member << BaseType);
   }
+  // Handle properties on ObjC 'Class' types.
+  if (OpKind == tok::period && (BaseType == Context.getObjCClassType())) {
+    // Also must look for a getter name which uses property syntax.
+    Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
+    if (ObjCMethodDecl *MD = getCurMethodDecl()) {
+      ObjCMethodDecl *OMD;
+      // FIXME: need to also look locally in the implementation.
+      if ((OMD = MD->getClassInterface()->lookupClassMethod(Sel))) {
+        // Check the use of this method.
+        if (DiagnoseUseOfDecl(OMD, MemberLoc))
+          return ExprError();
+
+        return Owned(new (Context) ObjCMessageExpr(BaseExpr, Sel,
+                        OMD->getResultType(), OMD, OpLoc, MemberLoc, NULL, 0));
+      }
+    }
+  }
+  
   // Handle 'field access' to vectors, such as 'V.xx'.
   if (BaseType->isExtVectorType()) {
     QualType ret = CheckExtVectorComponent(BaseType, OpLoc, Member, MemberLoc);
diff --git a/test/SemaObjC/super-property-notation.m b/test/SemaObjC/super-property-notation.m
new file mode 100644 (file)
index 0000000..4c96362
--- /dev/null
@@ -0,0 +1,30 @@
+// RUN: clang -fsyntax-only -verify %s
+
+@interface B
++(int) classGetter;
+-(int) getter;
+@end
+
+@interface A : B
+@end
+
+@implementation A
++(int) classGetter {
+  return 0;
+}
+
++(int) classGetter2 {
+  return super.classGetter;
+}
+
+-(void) method {
+  int x = super.getter;
+}
+@end
+
+void f0() {
+  // FIXME: not implemented yet.
+  //int l1 = A.classGetter;
+  int l2 = [A classGetter2];
+}
+