diff options
author | Steve Naroff <snaroff@apple.com> | 2009-11-09 17:45:52 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2009-11-09 17:45:52 +0000 |
commit | ef0cef6cec8de5fc60e469a93436eed7212e0dc2 (patch) | |
tree | 09f4ed0fbd89774f185ec5c068cc4d34601737cd /tools/c-index-test/c-index-test.c | |
parent | 1c03ca30ae962199ef702324b48550f6af7fdc32 (diff) |
Introduce CXString type and associated functions clang_getCString() and clang_disposeString().
This abstraction will help us manage string memory for complex names that cross the C++/C boundary (e.g. ObjC methods, selectors). This patch also uses it in clang_getTranslationUnitSpelling (which I'm not sure is necessary). Will investigate later...since the extra malloc() can't hurt (for now).
Patch by John Thompson.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86562 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/c-index-test/c-index-test.c')
-rw-r--r-- | tools/c-index-test/c-index-test.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index fa6fc56fba..4649f5c133 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -28,8 +28,11 @@ static void PrintCursor(CXCursor Cursor) { printf("Invalid Cursor => %s\n", clang_getCursorKindSpelling(Cursor.kind)); else { CXDecl DeclReferenced; + CXString string; + string = clang_getCursorSpelling(Cursor); printf("%s=%s", clang_getCursorKindSpelling(Cursor.kind), - clang_getCursorSpelling(Cursor)); + clang_getCString(string)); + clang_disposeString(string); DeclReferenced = clang_getCursorDecl(Cursor); if (DeclReferenced) printf(":%d:%d", clang_getDeclLine(DeclReferenced), @@ -40,22 +43,29 @@ static void PrintCursor(CXCursor Cursor) { static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter) { if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) { + CXString string; printf("// CHECK: %s:%d:%d: ", basename(clang_getCursorSource(Cursor)), clang_getCursorLine(Cursor), clang_getCursorColumn(Cursor)); PrintCursor(Cursor); - printf(" [Context=%s]\n", clang_getDeclSpelling(Dcl)); + string = clang_getDeclSpelling(Dcl); + printf(" [Context=%s]\n", clang_getCString(string)); + clang_disposeString(string); } } static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor, CXClientData Filter) { if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) { + CXString string; printf("// CHECK: %s:%d:%d: ", basename(clang_getCursorSource(Cursor)), clang_getCursorLine(Cursor), clang_getCursorColumn(Cursor)); PrintCursor(Cursor); - printf(" [Context=%s]\n", basename(clang_getTranslationUnitSpelling(Unit))); + string = clang_getTranslationUnitSpelling(Unit); + printf(" [Context=%s]\n", + basename(clang_getCString(string))); + clang_disposeString(string); clang_loadDeclaration(Cursor.decl, DeclVisitor, 0); @@ -83,10 +93,13 @@ static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor, if (Ref.kind == CXCursor_NoDeclFound) { /* Nothing found here; that's fine. */ } else if (Ref.kind != CXCursor_FunctionDecl) { + CXString string; printf("// CHECK: %s:%d:%d: ", basename(clang_getCursorSource(Ref)), curLine, curColumn); PrintCursor(Ref); - printf(" [Context:%s]\n", clang_getDeclSpelling(Ref.decl)); + string = clang_getDeclSpelling(Ref.decl); + printf(" [Context:%s]\n", clang_getCString(string)); + clang_disposeString(string); } startBuf++; } |