r201990 - [Index] Make the USRs more stable.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Sun Feb 23 10:23:29 PST 2014
Author: akirtzidis
Date: Sun Feb 23 12:23:29 2014
New Revision: 201990
URL: http://llvm.org/viewvc/llvm-project?rev=201990&view=rev
Log:
[Index] Make the USRs more stable.
- Only include offsets with local (in function scope) symbols, where we don't encode scoping
- Only include the filename with non-system symbols. Presumably the system headers will not provide conflicting definitions.
rdar://15976823
Modified:
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/test/Index/annotate-comments-typedef.m
cfe/trunk/test/Index/cxx11-lambdas.cpp
cfe/trunk/test/Index/index-refs.cpp
cfe/trunk/test/Index/usrs.cpp
cfe/trunk/test/Index/usrs.m
Modified: cfe/trunk/lib/Index/USRGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/USRGeneration.cpp?rev=201990&r1=201989&r2=201990&view=diff
==============================================================================
--- cfe/trunk/lib/Index/USRGeneration.cpp (original)
+++ cfe/trunk/lib/Index/USRGeneration.cpp Sun Feb 23 12:23:29 2014
@@ -80,10 +80,16 @@ public:
void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D) {
IgnoreResults = true;
}
-
+
+ bool ShouldGenerateLocation(const NamedDecl *D);
+
+ bool isLocal(const NamedDecl *D) {
+ return D->getParentFunctionOrMethod() != 0;
+ }
+
/// Generate the string component containing the location of the
/// declaration.
- bool GenLoc(const Decl *D);
+ bool GenLoc(const Decl *D, bool IncludeOffset);
/// String generation methods used both by the visitation methods
/// and from other clients that want to directly generate USRs. These
@@ -143,8 +149,13 @@ bool USRGenerator::EmitDeclName(const Na
return startSize == endSize;
}
-static inline bool ShouldGenerateLocation(const NamedDecl *D) {
- return !D->isExternallyVisible();
+bool USRGenerator::ShouldGenerateLocation(const NamedDecl *D) {
+ if (D->isExternallyVisible())
+ return false;
+ if (D->getParentFunctionOrMethod())
+ return true;
+ const SourceManager &SM = Context->getSourceManager();
+ return !SM.isInSystemHeader(D->getLocation());
}
void USRGenerator::VisitDeclContext(const DeclContext *DC) {
@@ -168,7 +179,7 @@ void USRGenerator::VisitFieldDecl(const
}
void USRGenerator::VisitFunctionDecl(const FunctionDecl *D) {
- if (ShouldGenerateLocation(D) && GenLoc(D))
+ if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
return;
VisitDeclContext(D->getDeclContext());
@@ -229,7 +240,7 @@ void USRGenerator::VisitVarDecl(const Va
// VarDecls can be declared 'extern' within a function or method body,
// but their enclosing DeclContext is the function, not the TU. We need
// to check the storage class to correctly generate the USR.
- if (ShouldGenerateLocation(D) && GenLoc(D))
+ if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
return;
VisitDeclContext(D->getDeclContext());
@@ -249,13 +260,13 @@ void USRGenerator::VisitVarDecl(const Va
void USRGenerator::VisitNonTypeTemplateParmDecl(
const NonTypeTemplateParmDecl *D) {
- GenLoc(D);
+ GenLoc(D, /*IncludeOffset=*/true);
return;
}
void USRGenerator::VisitTemplateTemplateParmDecl(
const TemplateTemplateParmDecl *D) {
- GenLoc(D);
+ GenLoc(D, /*IncludeOffset=*/true);
return;
}
@@ -329,7 +340,7 @@ void USRGenerator::VisitObjCContainerDec
// We want to mangle in the location to uniquely distinguish them.
if (CD->IsClassExtension()) {
Out << "objc(ext)" << ID->getName() << '@';
- GenLoc(CD);
+ GenLoc(CD, /*IncludeOffset=*/true);
}
else
GenObjCCategory(ID->getName(), CD->getName());
@@ -378,7 +389,7 @@ void USRGenerator::VisitObjCPropertyImpl
void USRGenerator::VisitTagDecl(const TagDecl *D) {
// Add the location of the tag decl to handle resolution across
// translation units.
- if (ShouldGenerateLocation(D) && GenLoc(D))
+ if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
return;
D = D->getCanonicalDecl();
@@ -449,7 +460,7 @@ void USRGenerator::VisitTagDecl(const Ta
}
void USRGenerator::VisitTypedefDecl(const TypedefDecl *D) {
- if (ShouldGenerateLocation(D) && GenLoc(D))
+ if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
return;
const DeclContext *DC = D->getDeclContext();
if (const NamedDecl *DCN = dyn_cast<NamedDecl>(DC))
@@ -459,11 +470,11 @@ void USRGenerator::VisitTypedefDecl(cons
}
void USRGenerator::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
- GenLoc(D);
+ GenLoc(D, /*IncludeOffset=*/true);
return;
}
-bool USRGenerator::GenLoc(const Decl *D) {
+bool USRGenerator::GenLoc(const Decl *D, bool IncludeOffset) {
if (generatedLoc)
return IgnoreResults;
generatedLoc = true;
@@ -494,10 +505,12 @@ bool USRGenerator::GenLoc(const Decl *D)
IgnoreResults = true;
return true;
}
- // Use the offest into the FileID to represent the location. Using
- // a line/column can cause us to look back at the original source file,
- // which is expensive.
- Out << '@' << Decomposed.second;
+ if (IncludeOffset) {
+ // Use the offest into the FileID to represent the location. Using
+ // a line/column can cause us to look back at the original source file,
+ // which is expensive.
+ Out << '@' << Decomposed.second;
+ }
return IgnoreResults;
}
Modified: cfe/trunk/test/Index/annotate-comments-typedef.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-comments-typedef.m?rev=201990&r1=201989&r2=201990&view=diff
==============================================================================
--- cfe/trunk/test/Index/annotate-comments-typedef.m (original)
+++ cfe/trunk/test/Index/annotate-comments-typedef.m Sun Feb 23 12:23:29 2014
@@ -45,5 +45,5 @@ struct Foo1 {
/** About Foo1T */
typedef struct Foo1 Foo1T;
// FIXME: we don't attach this comment to 'struct Foo1'
-// CHECK: TypedefDecl=Foo1T:[[@LINE-2]]:21 (Definition) {{.*}} FullCommentAsHTML=[<p class="para-brief"> About Foo1T </p>] FullCommentAsXML=[<Typedef file="{{[^"]+}}annotate-comments-typedef.m" line="[[@LINE-2]]" column="21"><Name>Foo1T</Name><USR>c:annotate-comments-typedef.m@{{[0-9]+}}@T at Foo1T</USR><Declaration>typedef struct Foo1 Foo1T</Declaration><Abstract><Para> About Foo1T </Para></Abstract></Typedef>]
+// CHECK: TypedefDecl=Foo1T:[[@LINE-2]]:21 (Definition) {{.*}} FullCommentAsHTML=[<p class="para-brief"> About Foo1T </p>] FullCommentAsXML=[<Typedef file="{{[^"]+}}annotate-comments-typedef.m" line="[[@LINE-2]]" column="21"><Name>Foo1T</Name><USR>c:annotate-comments-typedef.m at T@Foo1T</USR><Declaration>typedef struct Foo1 Foo1T</Declaration><Abstract><Para> About Foo1T </Para></Abstract></Typedef>]
Modified: cfe/trunk/test/Index/cxx11-lambdas.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/cxx11-lambdas.cpp?rev=201990&r1=201989&r2=201990&view=diff
==============================================================================
--- cfe/trunk/test/Index/cxx11-lambdas.cpp (original)
+++ cfe/trunk/test/Index/cxx11-lambdas.cpp Sun Feb 23 12:23:29 2014
@@ -26,8 +26,8 @@ struct X {
// RUN: env CINDEXTEST_INDEXLOCALSYMBOLS=1 c-index-test -index-file -std=c++11 %s | FileCheck -check-prefix=CHECK-INDEX %s
// CHECK-INDEX: [indexEntityReference]: kind: variable | name: localA | USR: c:cxx11-lambdas.cpp at 100@S at X@F at f#@localA | lang: C | cursor: VariableRef=localA:6:9 | loc: 7:21
// CHECK-INDEX: [indexEntityReference]: kind: variable | name: localB | USR: c:cxx11-lambdas.cpp at 100@S at X@F at f#@localB | lang: C | cursor: VariableRef=localB:6:17 | loc: 7:29
-// CHECK-INDEX: [indexEntityReference]: kind: typedef | name: Integer | USR: c:cxx11-lambdas.cpp at 51@T at Integer | lang: C | cursor: TypeRef=Integer:3:13 | loc: 7:52
-// CHECK-INDEX: [indexEntityReference]: kind: typedef | name: Integer | USR: c:cxx11-lambdas.cpp at 51@T at Integer | lang: C | cursor: TypeRef=Integer:3:13 | loc: 7:38
+// CHECK-INDEX: [indexEntityReference]: kind: typedef | name: Integer | USR: c:cxx11-lambdas.cpp at T@Integer | lang: C | cursor: TypeRef=Integer:3:13 | loc: 7:52
+// CHECK-INDEX: [indexEntityReference]: kind: typedef | name: Integer | USR: c:cxx11-lambdas.cpp at T@Integer | lang: C | cursor: TypeRef=Integer:3:13 | loc: 7:38
// CHECK-INDEX: [indexEntityReference]: kind: variable | name: localA | USR: c:cxx11-lambdas.cpp at 100@S at X@F at f#@localA | lang: C | cursor: DeclRefExpr=localA:6:9 | loc: 8:14
// CHECK-INDEX: [indexEntityReference]: kind: variable | name: localB | USR: c:cxx11-lambdas.cpp at 100@S at X@F at f#@localB | lang: C | cursor: DeclRefExpr=localB:6:17 | loc: 8:23
// CHECK-INDEX: [indexEntityReference]: kind: variable | name: x | USR: c:cxx11-lambdas.cpp at 157@S at X@F at f#@Ca at F@operator()#I#1 at x | lang: C | cursor: DeclRefExpr=x:7:46 | loc: 8:32
Modified: cfe/trunk/test/Index/index-refs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-refs.cpp?rev=201990&r1=201989&r2=201990&view=diff
==============================================================================
--- cfe/trunk/test/Index/index-refs.cpp (original)
+++ cfe/trunk/test/Index/index-refs.cpp Sun Feb 23 12:23:29 2014
@@ -102,7 +102,7 @@ void foo5() {
// CHECK: [indexDeclaration]: kind: c++-class-template | name: TS | {{.*}} | loc: 47:8
// CHECK-NEXT: [indexDeclaration]: kind: struct-template-partial-spec | name: TS | USR: c:@SP>1#T at TS>#t0.0#I | {{.*}} | loc: 50:8
-// CHECK-NEXT: [indexDeclaration]: kind: typedef | name: MyInt | USR: c:index-refs.cpp at 593@SP>1#T at TS>#t0.0#I at T@MyInt | {{.*}} | loc: 51:15 | semantic-container: [TS:50:8] | lexical-container: [TS:50:8]
+// CHECK-NEXT: [indexDeclaration]: kind: typedef | name: MyInt | USR: c:index-refs.cpp at SP>1#T at TS>#t0.0#I at T@MyInt | {{.*}} | loc: 51:15 | semantic-container: [TS:50:8] | lexical-container: [TS:50:8]
/* when indexing implicit instantiations
[indexDeclaration]: kind: struct-template-spec | name: TS | USR: c:@S at TS>#I | {{.*}} | loc: 50:8
[indexDeclaration]: kind: typedef | name: MyInt | USR: c:index-refs.cpp at 593@S at TS>#I at T@MyInt | {{.*}} | loc: 51:15 | semantic-container: [TS:50:8] | lexical-container: [TS:50:8]
Modified: cfe/trunk/test/Index/usrs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/usrs.cpp?rev=201990&r1=201989&r2=201990&view=diff
==============================================================================
--- cfe/trunk/test/Index/usrs.cpp (original)
+++ cfe/trunk/test/Index/usrs.cpp Sun Feb 23 12:23:29 2014
@@ -85,7 +85,7 @@ void rdar9371763() {
// CHECK: usrs.cpp c:@N at foo@F at bar#I# Extent=[3:3 - 3:18]
// CHECK: usrs.cpp c:usrs.cpp at 36@N at foo@F at bar#I#@z Extent=[3:12 - 3:17]
// CHECK: usrs.cpp c:@N at bar Extent=[5:1 - 8:2]
-// CHECK: usrs.cpp c:usrs.cpp at 64@N at bar@T at QType Extent=[6:3 - 6:20]
+// CHECK: usrs.cpp c:usrs.cpp at N@bar at T@QType Extent=[6:3 - 6:20]
// CHECK: usrs.cpp c:@N at bar@F at bar#I# Extent=[7:3 - 7:20]
// CHECK: usrs.cpp c:usrs.cpp at 94@N at bar@F at bar#I#@z Extent=[7:12 - 7:19]
// CHECK: usrs.cpp c:@C at ClsA Extent=[10:1 - 14:2]
@@ -101,13 +101,13 @@ void rdar9371763() {
// CHECK: usrs.cpp c:@N at foo@C at ClsB@F at ClsB# Extent=[19:5 - 19:27]
// CHECK: usrs.cpp c:@N at foo@C at ClsB@F at result#1 Extent=[20:5 - 20:23]
// CHECK: usrs.cpp c:@N at foo@C at ClsB@F at result#1 Extent=[24:1 - 26:2]
-// CHECK: usrs.cpp c:usrs.cpp at 360@aN at C@ClsC Extent=[29:3 - 29:35]
-// CHECK: usrs.cpp c:usrs.cpp at 396@aN at w Extent=[30:3 - 30:8]
+// CHECK: usrs.cpp c:usrs.cpp at aN@C at ClsC Extent=[29:3 - 29:35]
+// CHECK: usrs.cpp c:usrs.cpp at aN@w Extent=[30:3 - 30:8]
// CHECK: usrs.cpp c:@z Extent=[33:1 - 33:6]
// CHECK: usrs.cpp c:@N at foo Extent=[35:1 - 40:2]
// CHECK: usrs.cpp c:@N at foo@N at taz Extent=[35:17 - 39:2]
// CHECK: usrs.cpp c:@N at foo@N at taz@x Extent=[36:3 - 36:8]
-// CHECK: usrs.cpp c:usrs.cpp at 457@N at foo@N at taz@F at add#I#I# Extent=[37:3 - 37:56]
+// CHECK: usrs.cpp c:usrs.cpp at N@foo at N@taz at F@add#I#I# Extent=[37:3 - 37:56]
// CHECK: usrs.cpp c:usrs.cpp at 479@N at foo@N at taz@F at add#I#I#@a Extent=[37:25 - 37:30]
// CHECK: usrs.cpp c:usrs.cpp at 486@N at foo@N at taz@F at add#I#I#@b Extent=[37:32 - 37:37]
// CHECK: usrs.cpp c:@N at foo@N at taz@F at sub#I#I# Extent=[38:3 - 38:25]
@@ -137,10 +137,10 @@ void rdar9371763() {
// CHECK-NOT: ClsB
// CHECK: usrs.cpp c:@NA at foo_alias3
// CHECK: usrs.cpp c:@aN Extent=[68:1 - 73:2]
-// CHECK: usrs.cpp c:usrs.cpp at 1097@aN at C@RDar9371763_Foo Extent=[69:1 - 72:2]
+// CHECK: usrs.cpp c:usrs.cpp at aN@C at RDar9371763_Foo Extent=[69:1 - 72:2]
// CHECK: usrs.cpp c: Extent=[70:1 - 70:8]
-// CHECK: usrs.cpp c:usrs.cpp at 1131@aN at C@RDar9371763_Foo at F@bar# Extent=[71:3 - 71:13]
-// CHECK: usrs.cpp c:usrs.cpp at 1131@aN at C@RDar9371763_Foo at F@bar# Extent=[75:1 - 75:31]
+// CHECK: usrs.cpp c:usrs.cpp at aN@C at RDar9371763_Foo@F at bar# Extent=[71:3 - 71:13]
+// CHECK: usrs.cpp c:usrs.cpp at aN@C at RDar9371763_Foo@F at bar# Extent=[75:1 - 75:31]
// CHECK: usrs.cpp c:@F at rdar9371763# Extent=[77:1 - 80:2]
// CHECK: usrs.cpp c:usrs.cpp at 1204@F at rdar9371763#@foo Extent=[78:3 - 78:22]
Modified: cfe/trunk/test/Index/usrs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/usrs.m?rev=201990&r1=201989&r2=201990&view=diff
==============================================================================
--- cfe/trunk/test/Index/usrs.m (original)
+++ cfe/trunk/test/Index/usrs.m Sun Feb 23 12:23:29 2014
@@ -90,19 +90,19 @@ int test_multi_declaration(void) {
@end
// RUN: c-index-test -test-load-source-usrs all -target x86_64-apple-macosx10.7 %s | FileCheck %s
-// CHECK: usrs.m c:usrs.m at 67@F at my_helper Extent=[3:1 - 3:60]
+// CHECK: usrs.m c:usrs.m at F@my_helper Extent=[3:1 - 3:60]
// CHECK: usrs.m c:usrs.m at 95@F at my_helper@x Extent=[3:29 - 3:34]
// CHECK: usrs.m c:usrs.m at 102@F at my_helper@y Extent=[3:36 - 3:41]
-// CHECK: usrs.m c:usrs.m at 128@Ea Extent=[5:1 - 8:2]
-// CHECK: usrs.m c:usrs.m at 128@Ea at ABA Extent=[6:3 - 6:6]
-// CHECK: usrs.m c:usrs.m at 128@Ea at CADABA Extent=[7:3 - 7:9]
-// CHECK: usrs.m c:usrs.m at 155@Ea Extent=[10:1 - 13:2]
-// CHECK: usrs.m c:usrs.m at 155@Ea at FOO Extent=[11:3 - 11:6]
-// CHECK: usrs.m c:usrs.m at 155@Ea at BAR Extent=[12:3 - 12:6]
+// CHECK: usrs.m c:usrs.m at Ea Extent=[5:1 - 8:2]
+// CHECK: usrs.m c:usrs.m at Ea@ABA Extent=[6:3 - 6:6]
+// CHECK: usrs.m c:usrs.m at Ea@CADABA Extent=[7:3 - 7:9]
+// CHECK: usrs.m c:usrs.m at Ea Extent=[10:1 - 13:2]
+// CHECK: usrs.m c:usrs.m at Ea@FOO Extent=[11:3 - 11:6]
+// CHECK: usrs.m c:usrs.m at Ea@BAR Extent=[12:3 - 12:6]
// CHECK: usrs.m c:@SA at MyStruct Extent=[15:9 - 18:2]
// CHECK: usrs.m c:@SA at MyStruct@FI at wa Extent=[16:3 - 16:9]
// CHECK: usrs.m c:@SA at MyStruct@FI at moo Extent=[17:3 - 17:10]
-// CHECK: usrs.m c:usrs.m at 179@T at MyStruct Extent=[15:1 - 18:11]
+// CHECK: usrs.m c:usrs.m at T@MyStruct Extent=[15:1 - 18:11]
// CHECK: usrs.m c:@E at Pizza Extent=[20:1 - 23:2]
// CHECK: usrs.m c:@E at Pizza@CHEESE Extent=[21:3 - 21:9]
// CHECK: usrs.m c:@E at Pizza@MUSHROOMS Extent=[22:3 - 22:12]
@@ -123,7 +123,7 @@ int test_multi_declaration(void) {
// CHECK: usrs.m c:usrs.m at 470objc(cs)Foo(cm)kingkong at local_var Extent=[41:3 - 41:16]
// CHECK: usrs.m c:objc(cs)Foo(py)d1 Extent=[44:1 - 44:15]
// CHECK: usrs.m c:@z Extent=[47:1 - 47:6]
-// CHECK: usrs.m c:usrs.m at 529@F at local_func Extent=[49:1 - 49:43]
+// CHECK: usrs.m c:usrs.m at F@local_func Extent=[49:1 - 49:43]
// CHECK: usrs.m c:usrs.m at 551@F at local_func@x Extent=[49:23 - 49:28]
// CHECK: usrs.m c:objc(cs)CWithExt Extent=[51:1 - 53:5]
// CHECK: usrs.m c:objc(cs)CWithExt(im)meth1 Extent=[52:1 - 52:14]
More information about the cfe-commits
mailing list