[cfe-commits] r67314 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/access-property-getter.m

Fariborz Jahanian fjahanian at apple.com
Thu Mar 19 11:15:34 PDT 2009


Author: fjahanian
Date: Thu Mar 19 13:15:34 2009
New Revision: 67314

URL: http://llvm.org/viewvc/llvm-project?rev=67314&view=rev
Log:
When looking for property name (or getter method) in a
dot-syntax expression after earching the list of protocols
in the qualified-id, must keep searching the protocol list
of each of the protocols in the list.

Added:
    cfe/trunk/test/SemaObjC/access-property-getter.m
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=67314&r1=67313&r2=67314&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Mar 19 13:15:34 2009
@@ -1697,6 +1697,51 @@
   return VT; // should never get here (a typedef type should always be found).
 }
 
+static Decl *FindGetterNameDeclFromProtocolList(const ObjCProtocolDecl*PDecl,
+                                                IdentifierInfo &Member,
+                                                const Selector &Sel) {
+  
+  if (ObjCPropertyDecl *PD = PDecl->FindPropertyDeclaration(&Member))
+    return PD;
+  if (ObjCMethodDecl *OMD = PDecl->getInstanceMethod(Sel))
+    return OMD;
+  
+  for (ObjCProtocolDecl::protocol_iterator I = PDecl->protocol_begin(),
+       E = PDecl->protocol_end(); I != E; ++I) {
+    if (Decl *D = FindGetterNameDeclFromProtocolList(*I, Member, Sel))
+      return D;
+  }
+  return 0;
+}
+
+static Decl *FindGetterNameDecl(const ObjCQualifiedIdType *QIdTy,
+                                IdentifierInfo &Member,
+                                const Selector &Sel) {
+  // Check protocols on qualified interfaces.
+  Decl *GDecl = 0;
+  for (ObjCQualifiedIdType::qual_iterator I = QIdTy->qual_begin(),
+       E = QIdTy->qual_end(); I != E; ++I) {
+    if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(&Member)) {
+      GDecl = PD;
+      break;
+    }
+    // Also must look for a getter name which uses property syntax.
+    if (ObjCMethodDecl *OMD = (*I)->getInstanceMethod(Sel)) {
+      GDecl = OMD;
+      break;
+    }
+  }
+  if (!GDecl) {
+    for (ObjCQualifiedIdType::qual_iterator I = QIdTy->qual_begin(),
+         E = QIdTy->qual_end(); I != E; ++I) {
+      // Search in the protocol-qualifier list of current protocol.
+      GDecl = FindGetterNameDeclFromProtocolList(*I, Member, Sel);
+      if (GDecl)
+        return GDecl;
+    }
+  }
+  return GDecl;
+}
 
 Action::OwningExprResult
 Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
@@ -1968,25 +2013,25 @@
   const ObjCQualifiedIdType *QIdTy;
   if (OpKind == tok::period && (QIdTy = BaseType->getAsObjCQualifiedIdType())) {
     // Check protocols on qualified interfaces.
-    for (ObjCQualifiedIdType::qual_iterator I = QIdTy->qual_begin(),
-         E = QIdTy->qual_end(); I != E; ++I) {
-      if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(&Member)) {
+    Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
+    if (Decl *PMDecl = FindGetterNameDecl(QIdTy, Member, Sel)) {
+      if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(PMDecl)) {
         // Check the use of this declaration
         if (DiagnoseUseOfDecl(PD, MemberLoc))
           return ExprError();
-
+        
         return Owned(new (Context) ObjCPropertyRefExpr(PD, PD->getType(),
                                                        MemberLoc, BaseExpr));
       }
-      // Also must look for a getter name which uses property syntax.
-      Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
-      if (ObjCMethodDecl *OMD = (*I)->getInstanceMethod(Sel)) {
+      if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(PMDecl)) {
         // 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));
+                                                   OMD->getResultType(), 
+                                                   OMD, OpLoc, MemberLoc, 
+                                                   NULL, 0));
       }
     }
 

Added: cfe/trunk/test/SemaObjC/access-property-getter.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/access-property-getter.m?rev=67314&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/access-property-getter.m (added)
+++ cfe/trunk/test/SemaObjC/access-property-getter.m Thu Mar 19 13:15:34 2009
@@ -0,0 +1,35 @@
+// RUN: clang -verify %s
+
+ at protocol NSObject
+- (oneway void)release;
+ at end
+
+ at protocol XCOutputStreams <NSObject>
+ at end
+
+
+ at interface XCWorkQueueCommandInvocation 
+{
+    id <XCOutputStreams> _outputStream;
+}
+ at end
+
+ at interface XCWorkQueueCommandSubprocessInvocation : XCWorkQueueCommandInvocation
+ at end
+
+ at interface XCWorkQueueCommandLocalSubprocessInvocation : XCWorkQueueCommandSubprocessInvocation
+ at end
+
+ at interface XCWorkQueueCommandDistributedSubprocessInvocation : XCWorkQueueCommandSubprocessInvocation
+ at end
+
+ at interface XCWorkQueueCommandCacheFetchInvocation : XCWorkQueueCommandSubprocessInvocation
+
+ at end
+
+ at implementation XCWorkQueueCommandCacheFetchInvocation
+- (id)harvestPredictivelyProcessedOutputFiles
+{
+     _outputStream.release;
+}
+ at end





More information about the cfe-commits mailing list