]> granicus.if.org Git - clang/commitdiff
Refactor USR logic for EnumDecls and RecordDecls so that both handle 'anonymous'...
authorTed Kremenek <kremenek@apple.com>
Fri, 15 Jan 2010 23:34:31 +0000 (23:34 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 15 Jan 2010 23:34:31 +0000 (23:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93585 91177308-0d34-0410-b5e6-96231b3b80d8

tools/CIndex/CIndexUSRs.cpp

index 12157f4b1d204dbb913bce8d92ac1494964e684a..b52b9da92124d341fbdb861d8da266e33ddd5d07 100644 (file)
@@ -82,6 +82,7 @@ public:
   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::VisitDeclContext(DeclContext *DC) {
 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::VisitNamespaceDecl(NamespaceDecl *D) {
 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 @@ void USRGenerator::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
   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))