forked from OSchip/llvm-project
Add USR support for 'static inline' functions (which can be declared in header files).
Add USR support for 'static' functions and local variables, which can be handy for resolving named variables within a translation unit. llvm-svn: 102641
This commit is contained in:
parent
9825536eea
commit
3b9ad93a35
|
@ -1,5 +1,7 @@
|
|||
// RUN: c-index-test -test-load-source-usrs all %s | FileCheck %s
|
||||
|
||||
static inline int my_helper(int x, int y) { return x + y; }
|
||||
|
||||
enum {
|
||||
ABA,
|
||||
CADABA
|
||||
|
@ -36,6 +38,7 @@ enum Pizza {
|
|||
return 0;
|
||||
}
|
||||
+ (id) kingkong {
|
||||
int local_var;
|
||||
return 0;
|
||||
}
|
||||
@synthesize d1;
|
||||
|
@ -43,32 +46,42 @@ enum Pizza {
|
|||
|
||||
int z;
|
||||
|
||||
// CHECK: usrs.m c:@Ea@usrs.m@3:1 Extent=[3:1 - 6:2]
|
||||
// CHECK: usrs.m c:@Ea@usrs.m@3:1@ABA Extent=[4:3 - 4:6]
|
||||
// CHECK: usrs.m c:@Ea@usrs.m@3:1@CADABA Extent=[5:3 - 5:9]
|
||||
// CHECK: usrs.m c:@Ea@usrs.m@8:1 Extent=[8:1 - 11:2]
|
||||
// CHECK: usrs.m c:@Ea@usrs.m@8:1@FOO Extent=[9:3 - 9:6]
|
||||
// CHECK: usrs.m c:@Ea@usrs.m@8:1@BAR Extent=[10:3 - 10:6]
|
||||
// CHECK: usrs.m c:@SA@MyStruct Extent=[13:9 - 16:2]
|
||||
// CHECK: usrs.m c:@SA@MyStruct@FI@wa Extent=[14:7 - 14:9]
|
||||
// CHECK: usrs.m c:@SA@MyStruct@FI@moo Extent=[15:7 - 15:10]
|
||||
// CHECK: usrs.m c:@T@usrs.m@16:3@MyStruct Extent=[16:3 - 16:11]
|
||||
// CHECK: usrs.m c:@E@Pizza Extent=[18:1 - 21:2]
|
||||
// CHECK: usrs.m c:@E@Pizza@CHEESE Extent=[19:3 - 19:9]
|
||||
// CHECK: usrs.m c:@E@Pizza@MUSHROOMS Extent=[20:3 - 20:12]
|
||||
// CHECK: usrs.m c:objc(cs)Foo Extent=[23:1 - 30:5]
|
||||
// CHECK: usrs.m c:objc(cs)Foo@x Extent=[24:6 - 24:7]
|
||||
// CHECK: usrs.m c:objc(cs)Foo@y Extent=[25:6 - 25:7]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(py)d1 Extent=[29:15 - 29:17]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(im)godzilla Extent=[27:1 - 27:17]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(cm)kingkong Extent=[28:1 - 28:17]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(im)d1 Extent=[29:15 - 29:17]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(im)setD1: Extent=[29:15 - 29:17]
|
||||
// CHECK: usrs.m c:objc(cs)Foo Extent=[32:1 - 42:2]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(im)godzilla Extent=[33:1 - 37:2]
|
||||
// CHECK: usrs.m c:@z Extent=[35:10 - 35:15]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(cm)kingkong Extent=[38:1 - 40:2]
|
||||
// CHECK: usrs.m c:objc(cs)Foo@d1 Extent=[41:13 - 41:15]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(py)d1 Extent=[41:1 - 41:15]
|
||||
// CHECK: usrs.m c:@z Extent=[44:1 - 44:6]
|
||||
static int local_func(int x) { return x; }
|
||||
|
||||
// CHECK: usrs.m c:usrs.m@3:19@F@my_helper Extent=[3:19 - 3:60]
|
||||
// CHECK: usrs.m c:usrs.m@3:29@x Extent=[3:29 - 3:34]
|
||||
// CHECK: usrs.m c:usrs.m@3:36@y Extent=[3:36 - 3:41]
|
||||
// CHECK: usrs.m c:@Ea@usrs.m@5:1 Extent=[5:1 - 8:2]
|
||||
// CHECK: usrs.m c:@Ea@usrs.m@5:1@ABA Extent=[6:3 - 6:6]
|
||||
// CHECK: usrs.m c:@Ea@usrs.m@5:1@CADABA Extent=[7:3 - 7:9]
|
||||
// CHECK: usrs.m c:@Ea@usrs.m@10:1 Extent=[10:1 - 13:2]
|
||||
// CHECK: usrs.m c:@Ea@usrs.m@10:1@FOO Extent=[11:3 - 11:6]
|
||||
// CHECK: usrs.m c:@Ea@usrs.m@10:1@BAR Extent=[12:3 - 12:6]
|
||||
// CHECK: usrs.m c:@SA@MyStruct Extent=[15:9 - 18:2]
|
||||
// CHECK: usrs.m c:@SA@MyStruct@FI@wa Extent=[16:7 - 16:9]
|
||||
// CHECK: usrs.m c:@SA@MyStruct@FI@moo Extent=[17:7 - 17:10]
|
||||
// CHECK: usrs.m c:@T@usrs.m@18:3@MyStruct Extent=[18:3 - 18:11]
|
||||
// CHECK: usrs.m c:@E@Pizza Extent=[20:1 - 23:2]
|
||||
// CHECK: usrs.m c:@E@Pizza@CHEESE Extent=[21:3 - 21:9]
|
||||
// CHECK: usrs.m c:@E@Pizza@MUSHROOMS Extent=[22:3 - 22:12]
|
||||
// CHECK: usrs.m c:objc(cs)Foo Extent=[25:1 - 32:5]
|
||||
// CHECK: usrs.m c:objc(cs)Foo@x Extent=[26:6 - 26:7]
|
||||
// CHECK: usrs.m c:objc(cs)Foo@y Extent=[27:6 - 27:7]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(py)d1 Extent=[31:15 - 31:17]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(im)godzilla Extent=[29:1 - 29:17]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(cm)kingkong Extent=[30:1 - 30:17]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(im)d1 Extent=[31:15 - 31:17]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(im)setD1: Extent=[31:15 - 31:17]
|
||||
// CHECK: usrs.m c:usrs.m@31:15@d1 Extent=[31:15 - 31:17]
|
||||
// CHECK: usrs.m c:objc(cs)Foo Extent=[34:1 - 45:2]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(im)godzilla Extent=[35:1 - 39:2]
|
||||
// CHECK: usrs.m c:usrs.m@36:10@a Extent=[36:10 - 36:19]
|
||||
// CHECK: usrs.m c:@z Extent=[37:10 - 37:15]
|
||||
// CHECK: usrs.m c:objc(cs)Foo(cm)kingkong Extent=[40:1 - 43:2]
|
||||
// CHECK: usrs.m c:usrs.m@41:3@local_var Extent=[41:3 - 41:16]
|
||||
// CHECK: usrs.m c:objc(cs)Foo@d1 Extent=[44:13 - 44:15]
|
||||
// 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@49:12@F@local_func Extent=[49:12 - 49:43]
|
||||
// CHECK: usrs.m c:usrs.m@49:23@x Extent=[49:23 - 49:28]
|
||||
|
||||
|
|
|
@ -131,7 +131,14 @@ void USRGenerator::VisitFieldDecl(FieldDecl *D) {
|
|||
}
|
||||
|
||||
void USRGenerator::VisitFunctionDecl(FunctionDecl *D) {
|
||||
VisitDeclContext(D->getDeclContext());
|
||||
if (D->getLinkage() != ExternalLinkage) {
|
||||
GenLoc(D);
|
||||
if (IgnoreResults)
|
||||
return;
|
||||
}
|
||||
else
|
||||
VisitDeclContext(D->getDeclContext());
|
||||
|
||||
Out << "@F@" << D;
|
||||
}
|
||||
|
||||
|
@ -152,10 +159,15 @@ void USRGenerator::VisitVarDecl(VarDecl *D) {
|
|||
// 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 (!D->hasExternalStorage())
|
||||
VisitDeclContext(D->getDeclContext());
|
||||
if (D->getLinkage() != ExternalLinkage) {
|
||||
GenLoc(D);
|
||||
if (IgnoreResults)
|
||||
return;
|
||||
}
|
||||
|
||||
// Variables always have simple names.
|
||||
llvm::StringRef s = D->getName();
|
||||
|
||||
const std::string &s = D->getNameAsString();
|
||||
// The string can be empty if the declaration has no name; e.g., it is
|
||||
// the ParmDecl with no name for declaration of a function pointer type, e.g.:
|
||||
// void (*f)(void *);
|
||||
|
@ -377,10 +389,13 @@ static CXString getDeclCursorUSR(const CXCursor &C) {
|
|||
// enums/anonymous structs/etc. defined in a common header file
|
||||
// are referred to across multiple translation units.
|
||||
if (isa<TagDecl>(ND) || isa<TypedefDecl>(ND) ||
|
||||
isa<EnumConstantDecl>(ND) || isa<FieldDecl>(ND))
|
||||
isa<EnumConstantDecl>(ND) || isa<FieldDecl>(ND) ||
|
||||
isa<VarDecl>(ND))
|
||||
break;
|
||||
// Fall-through.
|
||||
case InternalLinkage:
|
||||
if (isa<FunctionDecl>(ND))
|
||||
break;
|
||||
case UniqueExternalLinkage:
|
||||
return createCXString("");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue