From c5b48b3319be4d7a421871e32fb016cff93172e6 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 15 Jan 2010 23:34:31 +0000 Subject: [PATCH] Refactor USR logic for EnumDecls and RecordDecls so that both handle 'anonymous' declarations in the same way. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93585 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/CIndex/CIndexUSRs.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tools/CIndex/CIndexUSRs.cpp b/tools/CIndex/CIndexUSRs.cpp index 12157f4b1d..b52b9da921 100644 --- a/tools/CIndex/CIndexUSRs.cpp +++ b/tools/CIndex/CIndexUSRs.cpp @@ -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(DC)) -- 2.40.0