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.
llvm-svn: 89115
This commit is contained in:
parent
2650723d81
commit
ef3339b7d4
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -215,67 +215,80 @@ void print_completion_result(CXCompletionResult *completion_result,
|
|||
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");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[2], "all") || !strcmp(argv[2], "local")) {
|
||||
clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
|
||||
clang_disposeTranslationUnit(TU);
|
||||
fprintf(stderr, "Unable to load translation unit from '%s'!\n", file);
|
||||
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_disposeTranslationUnit(TU);
|
||||
return 1;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue