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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102641 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndexUSRs.cpp b/tools/CIndex/CIndexUSRs.cpp
index 0f70a0a..f3c74e8 100644
--- a/tools/CIndex/CIndexUSRs.cpp
+++ b/tools/CIndex/CIndexUSRs.cpp
@@ -131,7 +131,14 @@
}
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 @@
// 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;
+ }
- const std::string &s = D->getNameAsString();
+ // Variables always have simple names.
+ llvm::StringRef s = D->getName();
+
// 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 @@
// 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("");
}