r182895 - [libclang] When indexing a @synthesize, don't consider that it defines a getter/setter if one is already defined by the user.

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed May 29 16:58:31 PDT 2013


Author: akirtzidis
Date: Wed May 29 18:58:31 2013
New Revision: 182895

URL: http://llvm.org/viewvc/llvm-project?rev=182895&view=rev
Log:
[libclang] When indexing a @synthesize, don't consider that it defines a getter/setter if one is already defined by the user.

Fixes rdar://13925258

Modified:
    cfe/trunk/test/Index/index-decls.m
    cfe/trunk/tools/libclang/IndexDecl.cpp

Modified: cfe/trunk/test/Index/index-decls.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-decls.m?rev=182895&r1=182894&r2=182895&view=diff
==============================================================================
--- cfe/trunk/test/Index/index-decls.m (original)
+++ cfe/trunk/test/Index/index-decls.m Wed May 29 18:58:31 2013
@@ -33,6 +33,21 @@ int test1() {
   return extfn();
 }
 
+ at interface I4
+ at property (assign, nonatomic) id prop;
+-(id)prop;
+-(void)setProp:(id)p;
+ at end
+
+ at implementation I4
+ at synthesize prop = _prop;
+-(id)prop {
+  return 0;
+}
+-(void)setProp:(id)p {
+}
+ at end
+
 // RUN: c-index-test -index-file %s -target x86_64-apple-macosx10.7 > %t
 // RUN: FileCheck %s -input-file=%t
 // CHECK: [indexDeclaration]: kind: objc-class | name: I | {{.*}} | loc: 1:12
@@ -54,3 +69,7 @@ int test1() {
 // CHECK: [indexEntityReference]: kind: variable | name: extvar | {{.*}} | loc: 31:3
 // CHECK: [indexDeclaration]: kind: function | name: extfn | {{.*}} | loc: 32:14
 // CHECK: [indexEntityReference]: kind: function | name: extfn | {{.*}} | loc: 33:10
+
+// CHECK: [indexDeclaration]: kind: objc-class | name: I4 | {{.*}} | loc: 36:12
+// CHECK-NOT: [indexDeclaration]: kind: objc-instance-method {{.*}} loc: 37:
+// CHECK-NOT: [indexDeclaration]: kind: objc-instance-method {{.*}} loc: 43:

Modified: cfe/trunk/tools/libclang/IndexDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexDecl.cpp?rev=182895&r1=182894&r2=182895&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexDecl.cpp (original)
+++ cfe/trunk/tools/libclang/IndexDecl.cpp Wed May 29 18:58:31 2013
@@ -22,6 +22,15 @@ public:
   explicit IndexingDeclVisitor(IndexingContext &indexCtx)
     : IndexCtx(indexCtx) { }
 
+  /// \brief Returns true if the given method has been defined explicitly by the
+  /// user.
+  static bool hasUserDefined(const ObjCMethodDecl *D,
+                             const ObjCImplDecl *Container) {
+    const ObjCMethodDecl *MD = Container->getMethod(D->getSelector(),
+                                                    D->isInstanceMethod());
+    return MD && !MD->isImplicit() && MD->isThisDeclarationADefinition();
+  }
+
   void handleDeclarator(const DeclaratorDecl *D, const NamedDecl *Parent = 0) {
     if (!Parent) Parent = D;
 
@@ -234,12 +243,14 @@ public:
     }
 
     if (ObjCMethodDecl *MD = PD->getGetterMethodDecl()) {
-      if (MD->isPropertyAccessor())
+      if (MD->isPropertyAccessor() &&
+          !hasUserDefined(MD, cast<ObjCImplDecl>(D->getDeclContext())))
         IndexCtx.handleSynthesizedObjCMethod(MD, D->getLocation(),
                                              D->getLexicalDeclContext());
     }
     if (ObjCMethodDecl *MD = PD->getSetterMethodDecl()) {
-      if (MD->isPropertyAccessor())
+      if (MD->isPropertyAccessor() &&
+          !hasUserDefined(MD, cast<ObjCImplDecl>(D->getDeclContext())))
         IndexCtx.handleSynthesizedObjCMethod(MD, D->getLocation(),
                                              D->getLexicalDeclContext());
     }





More information about the cfe-commits mailing list