From e1b552551089a63ca5f1eb18679ceaefbb61eab2 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 14 Jan 2010 01:50:21 +0000 Subject: [PATCH] Further tweak USR generation by shorting names and distinguish between namespaces and functions. llvm-svn: 93404 --- clang/tools/CIndex/CIndexUSRs.cpp | 63 ++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/clang/tools/CIndex/CIndexUSRs.cpp b/clang/tools/CIndex/CIndexUSRs.cpp index b1170eb96200..549c65058d86 100644 --- a/clang/tools/CIndex/CIndexUSRs.cpp +++ b/clang/tools/CIndex/CIndexUSRs.cpp @@ -67,37 +67,56 @@ static inline Program &GetProgram(CXIndex CIdx) { //===----------------------------------------------------------------------===// namespace { - class USRGenerator : public DeclVisitor { - llvm::raw_ostream &Out; - public: - USRGenerator(llvm::raw_ostream &out) : Out(out) {} - - void VisitNamedDecl(NamedDecl *D); - void VisitObjCContainerDecl(ObjCContainerDecl *CD); - void VisitObjCMethodDecl(ObjCMethodDecl *MD); - void VisitObjCPropertyDecl(ObjCPropertyDecl *D); - void VisitRecordDecl(RecordDecl *D); - void VisitTypedefDecl(TypedefDecl *D); - }; +class USRGenerator : public DeclVisitor { + llvm::raw_ostream &Out; +public: + USRGenerator(llvm::raw_ostream &out) : Out(out) {} + + void VisitBlockDecl(BlockDecl *D); + void VisitDeclContext(DeclContext *D); + void VisitFunctionDecl(FunctionDecl *D); + void VisitNamedDecl(NamedDecl *D); + void VisitNamespaceDecl(NamespaceDecl *D); + void VisitObjCContainerDecl(ObjCContainerDecl *CD); + void VisitObjCMethodDecl(ObjCMethodDecl *MD); + void VisitObjCPropertyDecl(ObjCPropertyDecl *D); + void VisitRecordDecl(RecordDecl *D); + void VisitTypedefDecl(TypedefDecl *D); +}; } // end anonymous namespace +void USRGenerator::VisitBlockDecl(BlockDecl *D) { + VisitDeclContext(D->getDeclContext()); + // FIXME: Better support for anonymous blocks. + Out << "@B^anon"; +} + +void USRGenerator::VisitDeclContext(DeclContext *DC) { + if (NamedDecl *D = dyn_cast(DC)) + Visit(D); +} + +void USRGenerator::VisitFunctionDecl(FunctionDecl *D) { + VisitDeclContext(D->getDeclContext()); + Out << "@F^" << D->getNameAsString(); +} void USRGenerator::VisitNamedDecl(NamedDecl *D) { - DeclContext *DC = D->getDeclContext(); - if (NamedDecl *DCN = dyn_cast(DC)) - Visit(DCN); - + VisitDeclContext(D->getDeclContext()); const std::string &s = D->getNameAsString(); assert(!s.empty()); - Out << '@' << s; + Out << "@^" << s; +} + +void USRGenerator::VisitNamespaceDecl(NamespaceDecl *D) { + VisitDeclContext(D->getDeclContext()); + Out << "@N^" << D->getNameAsString(); } void USRGenerator::VisitRecordDecl(RecordDecl *D) { - DeclContext *DC = D->getDeclContext(); - if (NamedDecl *DCN = dyn_cast(DC)) - Visit(DCN); - - Out << "@struct^"; + VisitDeclContext(D->getDeclContext()); + Out << "@S^"; + // FIXME: Better support for anonymous structures. const std::string &s = D->getNameAsString(); if (s.empty()) Out << "^anon";