[cfe-commits] r93778 - /cfe/trunk/tools/CIndex/CIndexUSRs.cpp

Ted Kremenek kremenek at apple.com
Mon Jan 18 14:02:49 PST 2010


Author: kremenek
Date: Mon Jan 18 16:02:49 2010
New Revision: 93778

URL: http://llvm.org/viewvc/llvm-project?rev=93778&view=rev
Log:
Tweak USR generation to handle anonymous bitfields.

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=93778&r1=93777&r2=93778&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CIndexUSRs.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndexUSRs.cpp Mon Jan 18 16:02:49 2010
@@ -70,12 +70,16 @@
 namespace {
 class USRGenerator : public DeclVisitor<USRGenerator> {
   llvm::raw_ostream &Out;
+  bool IgnoreResults;
 public:
-  USRGenerator(llvm::raw_ostream &out) : Out(out) {}
+  USRGenerator(llvm::raw_ostream &out) : Out(out), IgnoreResults(false) {}
+  
+  bool ignoreResults() const { return IgnoreResults; }
   
   void VisitBlockDecl(BlockDecl *D);
   void VisitDeclContext(DeclContext *D);
   void VisitEnumDecl(EnumDecl *D);
+  void VisitFieldDecl(FieldDecl *D);
   void VisitFunctionDecl(FunctionDecl *D);
   void VisitNamedDecl(NamedDecl *D);
   void VisitNamespaceDecl(NamespaceDecl *D);
@@ -105,6 +109,17 @@
   VisitTagDeclCommon(D);
 }
 
+void USRGenerator::VisitFieldDecl(FieldDecl *D) {
+  const std::string &s = D->getNameAsString();
+  if (s.empty()) {
+    // Bit fields can be anonymous.
+    IgnoreResults = true;
+    return;
+  }
+  VisitDeclContext(D->getDeclContext());
+  Out << "@^FI^" << s;
+}
+
 void USRGenerator::VisitFunctionDecl(FunctionDecl *D) {
   VisitDeclContext(D->getDeclContext());
   Out << "@F^" << D->getNameAsString();
@@ -192,6 +207,8 @@
     llvm::raw_svector_ostream Out(StrBuf);
     USRGenerator UG(Out);
     UG.Visit(static_cast<Decl*>(D));
+    if (UG.ignoreResults())
+      return CIndexer::createCXString(NULL);
   }
   
   if (StrBuf.empty())





More information about the cfe-commits mailing list