diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-01-18 20:23:29 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-01-18 20:23:29 +0000 |
commit | cf84aa46def41cccf4dd4c51cd0543b70c11e4eb (patch) | |
tree | 97cf0e8db09f9114f5dee32b9425ea953d7f6690 /tools | |
parent | 42f56b50062cd3b3c6b23fdb9053578ae9145664 (diff) |
Replace clang_getDeclUSR() with clang_getCursorUSR(). Also remove printing 'contexts' from c-index-test output; it wasn't helpful and was extremely brittle.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93760 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CIndex/CIndex.exports | 4 | ||||
-rw-r--r-- | tools/CIndex/CIndexUSRs.cpp | 41 | ||||
-rw-r--r-- | tools/c-index-test/c-index-test.c | 22 |
3 files changed, 31 insertions, 36 deletions
diff --git a/tools/CIndex/CIndex.exports b/tools/CIndex/CIndex.exports index a695ba2b08..d5f8298997 100644 --- a/tools/CIndex/CIndex.exports +++ b/tools/CIndex/CIndex.exports @@ -21,14 +21,14 @@ _clang_getCursorLine _clang_getCursorSource _clang_getCursorSourceFile _clang_getCursorSpelling +_clang_getCursorUSR _clang_getDeclColumn _clang_getDeclExtent -_clang_getDeclLine _clang_getDeclExtent +_clang_getDeclLine _clang_getDeclSource _clang_getDeclSourceFile _clang_getDeclSpelling -_clang_getDeclUSR _clang_getDeclaration _clang_getDefinitionSpellingAndExtent _clang_getEntityFromDecl diff --git a/tools/CIndex/CIndexUSRs.cpp b/tools/CIndex/CIndexUSRs.cpp index b52b9da921..c8933fa000 100644 --- a/tools/CIndex/CIndexUSRs.cpp +++ b/tools/CIndex/CIndexUSRs.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "CIndexer.h" +#include "CXCursor.h" #include "clang/AST/DeclVisitor.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/raw_ostream.h" @@ -184,6 +185,23 @@ void USRGenerator::VisitTypedefDecl(TypedefDecl *D) { Out << "typedef@" << D->getName(); } +// FIXME: This is a skeleton implementation. It will be overhauled. +static CXString ConstructUSR(Decl *D) { + llvm::SmallString<1024> StrBuf; + { + llvm::raw_svector_ostream Out(StrBuf); + USRGenerator UG(Out); + UG.Visit(static_cast<Decl*>(D)); + } + + if (StrBuf.empty()) + return CIndexer::createCXString(NULL); + + // Return a copy of the string that must be disposed by the caller. + return CIndexer::createCXString(StrBuf.c_str(), true); +} + + extern "C" { /// clang_getDeclaration() maps from a CXEntity to the matching CXDecl (if any) @@ -198,22 +216,13 @@ CXEntity clang_getEntityFromDecl(CXIndex CIdx, CXDecl CE) { return MakeEntity(CIdx, Entity::get(D, GetProgram(CIdx))); return NullCXEntity(); } - -// FIXME: This is a skeleton implementation. It will be overhauled. -CXString clang_getDeclUSR(CXDecl D) { - assert(D && "Null CXDecl passed to clang_getDeclUSR()"); - llvm::SmallString<1024> StrBuf; - { - llvm::raw_svector_ostream Out(StrBuf); - USRGenerator UG(Out); - UG.Visit(static_cast<Decl*>(D)); - } - - if (StrBuf.empty()) - return CIndexer::createCXString(NULL); - // Return a copy of the string that must be disposed by the caller. - return CIndexer::createCXString(StrBuf.c_str(), true); -} +CXString clang_getCursorUSR(CXCursor C) { + if (Decl *D = cxcursor::getCursorDecl(C)) + return ConstructUSR(D); + + + return CIndexer::createCXString(NULL); +} } // end extern "C" diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index afceafab20..db95644c4c 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -84,17 +84,11 @@ static void PrintDeclExtent(CXDecl Dcl) { static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter) { if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) { - CXString string; printf("// %s: %s:%d:%d: ", FileCheckPrefix, GetCursorSource(Cursor), clang_getCursorLine(Cursor), clang_getCursorColumn(Cursor)); - PrintCursor(Cursor); - - string = clang_getDeclSpelling(Dcl); - printf(" [Context=%s]", clang_getCString(string)); - clang_disposeString(string); - + PrintCursor(Cursor); PrintDeclExtent(clang_getCursorDecl(Cursor)); printf("\n"); @@ -105,15 +99,10 @@ static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor, CXClientData Filter) { if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) { CXDecl D; - CXString string; printf("// %s: %s:%d:%d: ", FileCheckPrefix, GetCursorSource(Cursor), clang_getCursorLine(Cursor), clang_getCursorColumn(Cursor)); PrintCursor(Cursor); - string = clang_getTranslationUnitSpelling(Unit); - printf(" [Context=%s]", - basename(clang_getCString(string))); - clang_disposeString(string); D = clang_getCursorDecl(Cursor); if (!D) { @@ -156,13 +145,10 @@ static void FunctionScanVisitor(CXTranslationUnit Unit, CXCursor Cursor, if (Ref.kind == CXCursor_NoDeclFound) { /* Nothing found here; that's fine. */ } else if (Ref.kind != CXCursor_FunctionDecl) { - CXString string; printf("// %s: %s:%d:%d: ", FileCheckPrefix, GetCursorSource(Ref), curLine, curColumn); PrintCursor(Ref); - string = clang_getDeclSpelling(Ref.data[0]); - printf(" [Context:%s]\n", clang_getCString(string)); - clang_disposeString(string); + printf("\n"); } startBuf++; } @@ -174,13 +160,13 @@ static void FunctionScanVisitor(CXTranslationUnit Unit, CXCursor Cursor, static void USRDeclVisitor(CXDecl D, CXCursor C, CXClientData Filter) { if (!Filter || (C.kind == *(enum CXCursorKind *)Filter)) { - CXString USR = clang_getDeclUSR(C.data[0]); + CXString USR = clang_getCursorUSR(C); if (!USR.Spelling) { clang_disposeString(USR); return; } printf("// %s: %s %s", FileCheckPrefix, GetCursorSource(C), USR.Spelling); - PrintDeclExtent(C.data[0]); + PrintDeclExtent(clang_getCursorDecl(C)); printf("\n"); clang_disposeString(USR); } |