From: Daniel Dunbar Date: Tue, 1 Dec 2009 02:03:10 +0000 (+0000) Subject: Add c-index-test -test-load-source, which loads the translation unit from a source... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ada487d498d82277bbc60312fc6f6479f0afda76;p=clang Add c-index-test -test-load-source, which loads the translation unit from a source file (and other command line arguments). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90187 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 289dee9629..3a16fcadbb 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -168,6 +168,38 @@ int perform_test_load_tu(const char *file, const char *filter) { return 0; } +int perform_test_load_source(int argc, const char **argv, const char *filter) { + CXIndex Idx; + CXTranslationUnit TU; + enum CXCursorKind K = CXCursor_NotImplemented; + enum CXCursorKind *ck = &K; + Idx = clang_createIndex(/* excludeDeclsFromPCH */ + !strcmp(filter, "local") ? 1 : 0, + /* displayDiagnostics */ 1); + + TU = clang_createTranslationUnitFromSourceFile(Idx, 0, argc, argv); + if (!TU) { + fprintf(stderr, "Unable to load translation unit!\n"); + return 1; + } + + /* Perform some simple filtering. */ + if (!strcmp(filter, "all") || !strcmp(filter, "local")) ck = NULL; + else if (!strcmp(filter, "category")) K = CXCursor_ObjCCategoryDecl; + else if (!strcmp(filter, "interface")) K = CXCursor_ObjCInterfaceDecl; + else if (!strcmp(filter, "protocol")) K = CXCursor_ObjCProtocolDecl; + else if (!strcmp(filter, "function")) K = CXCursor_FunctionDecl; + else if (!strcmp(filter, "typedef")) K = CXCursor_TypedefDecl; + else { + fprintf(stderr, "Unknown filter for -test-load-tu: %s\n", filter); + return 1; + } + + clang_loadTranslationUnit(TU, TranslationUnitVisitor, ck); + clang_disposeTranslationUnit(TU); + return 0; +} + /******************************************************************************/ /* Logic for testing clang_getCursor(). */ /******************************************************************************/ @@ -394,7 +426,8 @@ static void print_usage(void) { " c-index-test -test-file-scan " "[FileCheck prefix]\n" " c-index-test -test-load-tu \n\n" - " options for -test-load-tu:\n%s", + " c-index-test -test-load-source {}*\n\n" + " options for -test-load-tu and -test-load-source:\n%s", " all - load all symbols, including those from PCH\n" " local - load all symbols except those in PCH\n" " category - only load ObjC categories (non-PCH)\n" @@ -409,6 +442,8 @@ int main(int argc, const char **argv) { return perform_code_completion(argc, argv); if (argc == 4 && strcmp(argv[1], "-test-load-tu") == 0) return perform_test_load_tu(argv[2], argv[3]); + if (argc >= 4 && strcmp(argv[1], "-test-load-source") == 0) + return perform_test_load_source(argc - 3, argv + 3, argv[2]); if (argc >= 4 && strcmp(argv[1], "-test-file-scan") == 0) return perform_file_scan(argv[2], argv[3], argc >= 5 ? argv[4] : 0);