diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-15 06:20:16 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-15 06:20:16 +0000 |
commit | 21ee5707e6e59d982d2f2ae28e079c7ff46dc519 (patch) | |
tree | 24099e80ee098567726affd8c2a19c73c20d9f61 /tools/c-index-test/c-index-test.c | |
parent | ca3d3fcabaa0d7255e9a778ef468daa6e052b211 (diff) |
[libclang] Introduce a new function to apply the indexing callbacks on an existing
CXTranslationUnit, mainly to be used for indexing a PCH.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144623 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 | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 177ffa5a88..ed58fd28fb 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -1765,6 +1765,10 @@ static void index_indexDeclaration(CXClientData client_data, if ((CatInfo = clang_index_getObjCCategoryDeclInfo(info))) { printEntityInfo(" <ObjCCategoryInfo>: class", client_data, CatInfo->objcClass); + printf(" | cursor: "); + PrintCursor(CatInfo->classCursor); + printf(" | loc: "); + printCXIndexLoc(CatInfo->classLoc); printf("\n"); } @@ -1842,9 +1846,51 @@ static int index_file(int argc, const char **argv) { index_data.first_check_printed = 0; index_data.fail_for_error = 0; - result = clang_indexTranslationUnit(CIdx, &index_data, - &IndexCB,sizeof(IndexCB), - 0, 0, argv, argc, 0, 0, 0, 0); + result = clang_indexSourceFile(CIdx, &index_data, + &IndexCB,sizeof(IndexCB), + 0, 0, argv, argc, 0, 0, 0, 0); + if (index_data.fail_for_error) + return -1; + + return result; +} + +static int index_tu(int argc, const char **argv) { + CXIndex Idx; + CXTranslationUnit TU; + const char *check_prefix; + IndexData index_data; + int result; + + check_prefix = 0; + if (argc > 0) { + if (strstr(argv[0], "-check-prefix=") == argv[0]) { + check_prefix = argv[0] + strlen("-check-prefix="); + ++argv; + --argc; + } + } + + if (argc == 0) { + fprintf(stderr, "no ast file\n"); + return -1; + } + + if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1, + /* displayDiagnosics=*/1))) { + fprintf(stderr, "Could not create Index\n"); + return 1; + } + + if (!CreateTranslationUnit(Idx, argv[0], &TU)) + return 1; + + index_data.check_prefix = check_prefix; + index_data.first_check_printed = 0; + index_data.fail_for_error = 0; + + result = clang_indexTranslationUnit(TU, &index_data, + &IndexCB,sizeof(IndexCB), 0); if (index_data.fail_for_error) return -1; @@ -2394,6 +2440,7 @@ static void print_usage(void) { " c-index-test -cursor-at=<site> <compiler arguments>\n" " c-index-test -file-refs-at=<site> <compiler arguments>\n" " c-index-test -index-file [-check-prefix=<FileCheck prefix>] <compiler arguments>\n" + " c-index-test -index-tu [-check-prefix=<FileCheck prefix>] <AST file>\n" " c-index-test -test-file-scan <AST file> <source file> " "[FileCheck prefix]\n"); fprintf(stderr, @@ -2449,6 +2496,8 @@ int cindextest_main(int argc, const char **argv) { return find_file_refs_at(argc, argv); if (argc > 2 && strcmp(argv[1], "-index-file") == 0) return index_file(argc - 2, argv + 2); + if (argc > 2 && strcmp(argv[1], "-index-tu") == 0) + return index_tu(argc - 2, argv + 2); else if (argc >= 4 && strncmp(argv[1], "-test-load-tu", 13) == 0) { CXCursorVisitor I = GetVisitor(argv[1] + 13); if (I) |