From 05edf944c0f3c057247c50bd1e57ff8613ab0a3a Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 4 Feb 2011 07:13:40 +0000 Subject: [PATCH] USRs for Objective-C methods use the USR of the @interface as their base, not the USR of the class category or extension. llvm-svn: 124859 --- clang/test/Index/usrs.m | 4 ++-- clang/tools/libclang/CIndexUSRs.cpp | 24 ++++++------------------ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/clang/test/Index/usrs.m b/clang/test/Index/usrs.m index f34cc1e87bf3..d5da2dcf5ea7 100644 --- a/clang/test/Index/usrs.m +++ b/clang/test/Index/usrs.m @@ -119,13 +119,13 @@ int test_multi_declaration(void) { // CHECK: usrs.m c:objc(ext)CWithExt@usrs.m@654 Extent=[57:1 - 59:5] // CHECK: usrs.m c:objc(cs)CWithExt(im)meth3 Extent=[58:1 - 58:14] // CHECK: usrs.m c:objc(cy)CWithExt@Bar Extent=[60:1 - 62:5] -// CHECK: usrs.m c:objc(cy)CWithExt@Bar(im)meth4 Extent=[61:1 - 61:14] +// CHECK: usrs.m c:objc(cs)CWithExt(im)meth4 Extent=[61:1 - 61:14] // CHECK: usrs.m c:objc(cs)CWithExt Extent=[63:1 - 67:2] // CHECK: usrs.m c:objc(cs)CWithExt(im)meth1 Extent=[64:1 - 64:27] // CHECK: usrs.m c:objc(cs)CWithExt(im)meth2 Extent=[65:1 - 65:27] // CHECK: usrs.m c:objc(cs)CWithExt(im)meth3 Extent=[66:1 - 66:27] // CHECK: usrs.m c:objc(cy)CWithExt@Bar Extent=[68:1 - 70:2] -// CHECK: usrs.m c:objc(cy)CWithExt@Bar(im)meth4 Extent=[69:1 - 69:27] +// CHECK: usrs.m c:objc(cs)CWithExt(im)meth4 Extent=[69:1 - 69:27] // CHECK: usrs.m c:@F@aux_1 Extent=[72:6 - 72:26] // CHECK: usrs.m c:@F@test_multi_declaration Extent=[73:5 - 77:2] // CHECK: usrs.m c:usrs.m@980@F@test_multi_declaration@foo Extent=[74:3 - 74:14] diff --git a/clang/tools/libclang/CIndexUSRs.cpp b/clang/tools/libclang/CIndexUSRs.cpp index 5e632b9e96e6..36b91cf97862 100644 --- a/clang/tools/libclang/CIndexUSRs.cpp +++ b/clang/tools/libclang/CIndexUSRs.cpp @@ -283,26 +283,14 @@ void USRGenerator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { } void USRGenerator::VisitObjCMethodDecl(ObjCMethodDecl *D) { - Decl *container = cast(D->getDeclContext()); - - // The USR for a method declared in a class extension is based on + // The USR for a method declared in a class extension or category is based on // the ObjCInterfaceDecl, not the ObjCCategoryDecl. - do { - if (ObjCCategoryDecl *CD = dyn_cast(container)) - if (CD->IsClassExtension()) { - // ID can be null with invalid code. - if (ObjCInterfaceDecl *ID = CD->getClassInterface()) { - Visit(ID); - break; - } - // Invalid code. Can't generate USR. - IgnoreResults = true; - return; - } - - Visit(container); + ObjCInterfaceDecl *ID = D->getClassInterface(); + if (!ID) { + IgnoreResults = true; + return; } - while (false); + Visit(ID); // Ideally we would use 'GenObjCMethod', but this is such a hot path // for Objective-C code that we don't want to use