[cfe-commits] r89115 - in /cfe/trunk: test/Index/c-index-api-test.m test/Index/c-index-pch.c tools/c-index-test/c-index-test.c
Ted Kremenek
kremenek at apple.com
Tue Nov 17 10:09:14 PST 2009
Author: kremenek
Date: Tue Nov 17 12:09:14 2009
New Revision: 89115
URL: http://llvm.org/viewvc/llvm-project?rev=89115&view=rev
Log:
Clean up c-index-test command line usage a bit by requiring a "-test-load-tu" option when testing clang_loadTranslationUnit(). Running c-index-test without the correct arguments now also prints a useful summary of its correct usage.
Modified:
cfe/trunk/test/Index/c-index-api-test.m
cfe/trunk/test/Index/c-index-pch.c
cfe/trunk/tools/c-index-test/c-index-test.c
Modified: cfe/trunk/test/Index/c-index-api-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/c-index-api-test.m?rev=89115&r1=89114&r2=89115&view=diff
==============================================================================
--- cfe/trunk/test/Index/c-index-api-test.m (original)
+++ cfe/trunk/test/Index/c-index-api-test.m Tue Nov 17 12:09:14 2009
@@ -1,5 +1,5 @@
// RUN: clang-cc -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fblocks -emit-pch -x objective-c %s -o %t.ast
-// RUN: c-index-test %t.ast all | FileCheck %s
+// RUN: c-index-test -test-load-tu %t.ast all | FileCheck %s
// CHECK: <invalid loc>:0:0: TypedefDecl=__int128_t:0:0 [Context=c-index-api-test.m]
// CHECK: <invalid loc>:0:0: TypedefDecl=__uint128_t:0:0 [Context=c-index-api-test.m]
Modified: cfe/trunk/test/Index/c-index-pch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/c-index-pch.c?rev=89115&r1=89114&r2=89115&view=diff
==============================================================================
--- cfe/trunk/test/Index/c-index-pch.c (original)
+++ cfe/trunk/test/Index/c-index-pch.c Tue Nov 17 12:09:14 2009
@@ -1,7 +1,7 @@
// RUN: clang-cc -emit-pch -x c -o %t.pch %S/Inputs/c-index-pch.h
// RUN: clang-cc -include-pch %t.pch -x c -emit-pch -o %t.ast %s
-// RUN: c-index-test %t.ast all | FileCheck -check-prefix=ALL %s
-// RUN: c-index-test %t.ast local | FileCheck -check-prefix=LOCAL %s
+// RUN: c-index-test -test-load-tu %t.ast all | FileCheck -check-prefix=ALL %s
+// RUN: c-index-test -test-load-tu %t.ast local | FileCheck -check-prefix=LOCAL %s
// ALL: FunctionDecl=foo
// ALL: VarDecl=bar
// ALL: FunctionDecl=wibble
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=89115&r1=89114&r2=89115&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Tue Nov 17 12:09:14 2009
@@ -215,67 +215,80 @@
fprintf(file, "\n");
}
-void perform_code_completion(int argc, const char **argv) {
+int perform_code_completion(int argc, const char **argv) {
const char *input = argv[1];
char *filename = 0;
unsigned line;
unsigned column;
CXIndex CIdx;
+ int errorCode;
input += strlen("-code-completion-at=");
- if (parse_file_line_column(input, &filename, &line, &column))
- return;
+ if ((errorCode = parse_file_line_column(input, &filename, &line, &column)))
+ return errorCode;
CIdx = clang_createIndex(0, 0);
clang_codeComplete(CIdx, argv[argc - 1], argc - 3, argv + 2,
filename, line, column, &print_completion_result, stdout);
clang_disposeIndex(CIdx);
free(filename);
+
+ return 0;
}
-/*
- * First sign of life:-)
- */
-int main(int argc, char **argv) {
- if (argc > 2 && strstr(argv[1], "-code-completion-at=") == argv[1]) {
- perform_code_completion(argc, (const char **)argv);
- return 0;
- }
-
-
- if (argc != 3) {
- printf("Incorrect usage of c-index-test (requires 3 arguments)\n");
- return 0;
- }
- {
+int perform_test_load_tu(const char *file, const char *filter) {
CXIndex Idx;
CXTranslationUnit TU;
enum CXCursorKind K = CXCursor_NotImplemented;
-
- Idx = clang_createIndex(/* excludeDeclsFromPCH */ !strcmp(argv[2], "local") ? 1 : 0,
+ enum CXCursorKind *ck = &K;
+ Idx = clang_createIndex(/* excludeDeclsFromPCH */
+ !strcmp(filter, "local") ? 1 : 0,
/* displayDiagnostics */ 1);
- TU = clang_createTranslationUnit(Idx, argv[1]);
-
+ TU = clang_createTranslationUnit(Idx, file);
+
if (!TU) {
- fprintf(stderr, "Unable to load translation unit!\n");
+ fprintf(stderr, "Unable to load translation unit from '%s'!\n", file);
return 1;
}
-
- if (!strcmp(argv[2], "all") || !strcmp(argv[2], "local")) {
- clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
- clang_disposeTranslationUnit(TU);
+
+ /* 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;
}
- /* Perform some simple filtering. */
- if (!strcmp(argv[2], "category")) K = CXCursor_ObjCCategoryDecl;
- else if (!strcmp(argv[2], "interface")) K = CXCursor_ObjCInterfaceDecl;
- else if (!strcmp(argv[2], "protocol")) K = CXCursor_ObjCProtocolDecl;
- else if (!strcmp(argv[2], "function")) K = CXCursor_FunctionDecl;
- else if (!strcmp(argv[2], "typedef")) K = CXCursor_TypedefDecl;
-
- clang_loadTranslationUnit(TU, TranslationUnitVisitor, &K);
+
+ clang_loadTranslationUnit(TU, TranslationUnitVisitor, ck);
clang_disposeTranslationUnit(TU);
+ return 0;
+}
+
+static void print_usage(void) {
+ fprintf(stderr,
+ "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
+ " c-index-test -test-load-tu <AST file> <symbol filter>\n\n"
+ " <symbol filter> options for -test-load-tu:\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"
+ " interface - only load ObjC interfaces (non-PCH)\n"
+ " protocol - only load ObjC protocols (non-PCH)\n"
+ " function - only load functions (non-PCH)\n"
+ " typedef - only load typdefs (non-PCH)\n\n");
+}
+
+int main(int argc, const char **argv) {
+ if (argc > 2 && strstr(argv[1], "-code-completion-at=") == argv[1])
+ 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]);
+
+ print_usage();
return 1;
- }
}
More information about the cfe-commits
mailing list