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

Ted Kremenek kremenek at apple.com
Fri Jan 15 15:34:32 PST 2010


Author: kremenek
Date: Fri Jan 15 17:34:31 2010
New Revision: 93585

URL: http://llvm.org/viewvc/llvm-project?rev=93585&view=rev
Log:
Refactor USR logic for EnumDecls and RecordDecls so that both handle 'anonymous' declarations in the same way.

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=93585&r1=93584&r2=93585&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CIndexUSRs.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndexUSRs.cpp Fri Jan 15 17:34:31 2010
@@ -82,6 +82,7 @@
   void VisitObjCMethodDecl(ObjCMethodDecl *MD);
   void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
   void VisitRecordDecl(RecordDecl *D);
+  void VisitTagDeclCommon(TagDecl *D);
   void VisitTypedefDecl(TypedefDecl *D);
 };
 } // end anonymous namespace
@@ -100,11 +101,7 @@
 void USRGenerator::VisitEnumDecl(EnumDecl *D) {
   VisitDeclContext(D->getDeclContext());
   Out << "@E^";
-  const std::string &s = D->getNameAsString();
-  if (s.empty())
-    Out << "anon";
-  else
-    Out << s;
+  VisitTagDeclCommon(D);
 }
 
 void USRGenerator::VisitFunctionDecl(FunctionDecl *D) {
@@ -127,16 +124,7 @@
 void USRGenerator::VisitRecordDecl(RecordDecl *D) {
   VisitDeclContext(D->getDeclContext());
   Out << "@S^";
-  // FIXME: Better support for anonymous structures. 
-  const std::string &s = D->getNameAsString();
-  if (s.empty()) {
-    if (TypedefDecl *TD = D->getTypedefForAnonDecl())
-      Out << "^anontd^" << TD->getNameAsString();    
-    else
-      Out << "^anon";
-  }
-  else
-    Out << s;
+  VisitTagDeclCommon(D);
 }
 
 void USRGenerator::VisitObjCMethodDecl(ObjCMethodDecl *D) {
@@ -176,6 +164,19 @@
   Out << "(py)" << D->getName();
 }
 
+void USRGenerator::VisitTagDeclCommon(TagDecl *D) {
+  // FIXME: Better support for anonymous structures and enums.
+  const std::string &s = D->getNameAsString();
+  if (s.empty()) {
+    if (TypedefDecl *TD = D->getTypedefForAnonDecl())
+      Out << "^anontd^" << TD->getNameAsString();    
+    else
+      Out << "^anon";
+  }
+  else
+    Out << s;
+}
+
 void USRGenerator::VisitTypedefDecl(TypedefDecl *D) {
   DeclContext *DC = D->getDeclContext();
   if (NamedDecl *DCN = dyn_cast<NamedDecl>(DC))





More information about the cfe-commits mailing list