diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-11-17 05:31:58 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-11-17 05:31:58 +0000 |
commit | 9298cfc7475c48fa42b168c37f628663d65ddde7 (patch) | |
tree | f95e7377e4e888e5d86d30f7949560655cdbbfb4 /tools/c-index-test/c-index-test.c | |
parent | b91c7f67e85309fbd4cd5007c873e1d27b86e8bb (diff) |
Have clang_getCursorSource() return NULL when the source location is invalid or refers to a built-in buffer. Implements <rdar://problem/7296243>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89044 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 | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 36deb2e6d9..3b0e4c8e9c 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -40,11 +40,18 @@ static void PrintCursor(CXCursor Cursor) { } } +static const char* GetCursorSource(CXCursor Cursor) { + const char *source = clang_getCursorSource(Cursor); + if (!source) + return "<invalid loc>"; + return basename(source); +} + 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)), + printf("// CHECK: %s:%d:%d: ", GetCursorSource(Cursor), clang_getCursorLine(Cursor), clang_getCursorColumn(Cursor)); PrintCursor(Cursor); @@ -58,7 +65,7 @@ static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor, { if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) { CXString string; - printf("// CHECK: %s:%d:%d: ", basename(clang_getCursorSource(Cursor)), + printf("// CHECK: %s:%d:%d: ", GetCursorSource(Cursor), clang_getCursorLine(Cursor), clang_getCursorColumn(Cursor)); PrintCursor(Cursor); @@ -94,8 +101,8 @@ static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor, /* 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); + printf("// CHECK: %s:%d:%d: ", GetCursorSource(Ref), + curLine, curColumn); PrintCursor(Ref); string = clang_getDeclSpelling(Ref.decl); printf(" [Context:%s]\n", clang_getCString(string)); |