[cfe-commits] r101401 - /cfe/trunk/tools/CIndex/CIndexUSRs.cpp
Ted Kremenek
kremenek at apple.com
Thu Apr 15 14:04:25 PDT 2010
Author: kremenek
Date: Thu Apr 15 16:04:25 2010
New Revision: 101401
URL: http://llvm.org/viewvc/llvm-project?rev=101401&view=rev
Log:
Do not generate USRs for declarations with 'no linkage' except for enums, structs, typedefs.
Those still need work to disambiguate them across translation units.
Modified:
cfe/trunk/tools/CIndex/CIndexUSRs.cpp
Modified: cfe/trunk/tools/CIndex/CIndexUSRs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndexUSRs.cpp?rev=101401&r1=101400&r2=101401&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndexUSRs.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndexUSRs.cpp Thu Apr 15 16:04:25 2010
@@ -28,8 +28,10 @@
class USRGenerator : public DeclVisitor<USRGenerator> {
llvm::raw_ostream &Out;
bool IgnoreResults;
+ ASTUnit *AU;
public:
- USRGenerator(llvm::raw_ostream &out) : Out(out), IgnoreResults(false) {}
+ USRGenerator(ASTUnit *au, llvm::raw_ostream &out)
+ : Out(out), IgnoreResults(false), AU(au) {}
bool ignoreResults() const { return IgnoreResults; }
@@ -46,7 +48,6 @@
void VisitTagDecl(TagDecl *D);
void VisitTypedefDecl(TypedefDecl *D);
-
/// String generation methods used both by the visitation methods
/// and from other clients that want to directly generate USRs. These
/// methods do not construct complete USRs (which incorporate the parents
@@ -79,10 +80,10 @@
llvm::raw_svector_ostream Out;
USRGenerator UG;
public:
- StringUSRGenerator()
- : Out(StrBuf), UG(Out) {
+ StringUSRGenerator(const CXCursor *C = 0)
+ : Out(StrBuf), UG(C ? cxcursor::getCursorASTUnit(*C) : 0, Out) {
// Add the USR space prefix.
- Out << "c:";
+ Out << "c:";
}
llvm::StringRef str() {
@@ -269,7 +270,27 @@
if (!D)
return createCXString(NULL);
- StringUSRGenerator SUG;
+ // Check if the cursor has 'NoLinkage'.
+ if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D))
+ switch (ND->getLinkage()) {
+ case ExternalLinkage:
+ // Generate USRs for all entities with external linkage.
+ break;
+ case NoLinkage:
+ // We allow enums, typedefs, and structs that have no linkage to
+ // have USRs that are anchored to the file they were defined in
+ // (e.g., the header). This is a little gross, but in principal
+ // enums/anonymous structs/etc. defined in a common header file
+ // are referred to across multiple translation units.
+ if (isa<TagDecl>(ND))
+ break;
+ // Fall-through.
+ case InternalLinkage:
+ case UniqueExternalLinkage:
+ return createCXString("");
+ }
+
+ StringUSRGenerator SUG(&C);
SUG->Visit(D);
if (SUG->ignoreResults())
@@ -288,7 +309,7 @@
return getDeclCursorUSR(C);
if (K == CXCursor_MacroDefinition) {
- StringUSRGenerator SUG;
+ StringUSRGenerator SUG(&C);
SUG << "macro@"
<< cxcursor::getCursorMacroDefinition(C)->getName()->getNameStart();
return createCXString(SUG.str(), true);
More information about the cfe-commits
mailing list