зеркало из https://github.com/microsoft/clang-1.git
Add -cursor-at=file:line:column command line option to c-index-test,
to directly check the results of clang_getCursor(). Also, start migrating some index-test tests over to c-index test [*] and some grep-using tests over to FileCheck. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93537 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
c89724cc6d
Коммит
f2c87bd036
|
@ -264,7 +264,7 @@ ASTLocation DeclLocResolver::VisitFunctionDecl(FunctionDecl *D) {
|
||||||
return ASTLocation(D);
|
return ASTLocation(D);
|
||||||
|
|
||||||
// Second, search through the declarations that are part of the function.
|
// Second, search through the declarations that are part of the function.
|
||||||
// If we find he location there, we won't have to search through its body.
|
// If we find the location there, we won't have to search through its body.
|
||||||
|
|
||||||
for (DeclContext::decl_iterator
|
for (DeclContext::decl_iterator
|
||||||
I = D->decls_begin(), E = D->decls_end(); I != E; ++I) {
|
I = D->decls_begin(), E = D->decls_end(); I != E; ++I) {
|
||||||
|
|
|
@ -15,23 +15,25 @@ struct S {
|
||||||
int field_var;
|
int field_var;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// RUN: %clang_cc1 -emit-pch %s -o %t.ast
|
// RUN: %clang_cc1 -emit-pch %s -o %t.ast
|
||||||
// RUN: index-test %t.ast -point-at %s:3:8 | grep top_var
|
// RUN: c-index-test \
|
||||||
// RUN: index-test %t.ast -point-at %s:5:15 | grep top_func_decl
|
// RUN: -cursor-at=%s:3:8 -cursor-at=%s:5:15 -cursor-at=%s:5:25 \
|
||||||
// RUN: index-test %t.ast -point-at %s:5:25 | grep param1
|
// RUN: -cursor-at=%s:7:17 -cursor-at=%s:7:23 -cursor-at=%s:8:10 \
|
||||||
// RUN: index-test %t.ast -point-at %s:7:17 | grep top_func_def
|
// RUN: -cursor-at=%s:9:15 -cursor-at=%s:10:9 -cursor-at=%s:15:10 \
|
||||||
// RUN: index-test %t.ast -point-at %s:7:23 | grep param2
|
// RUN: %s | FileCheck %s
|
||||||
// RUN: index-test %t.ast -point-at %s:8:10 | grep local_var1
|
// CHECK: VarDecl=top_var
|
||||||
// RUN: index-test %t.ast -point-at %s:9:15 | grep for_var
|
// CHECK: FunctionDecl=top_func_decl
|
||||||
|
// CHECK: ParmDecl=param1
|
||||||
|
// CHECK: FunctionDecl=top_func_def
|
||||||
|
// CHECK: ParmDecl=param2
|
||||||
|
// CHECK: VarDecl=local_var1
|
||||||
|
// CHECK: VarDecl=for_var
|
||||||
|
// CHECK: VarDecl=local_var2
|
||||||
|
// CHECK: FieldDecl=field_var
|
||||||
|
|
||||||
|
// FIXME: Eliminate these once clang_getCursor supports them.
|
||||||
// RUN: index-test %t.ast -point-at %s:9:43 > %t
|
// RUN: index-test %t.ast -point-at %s:9:43 > %t
|
||||||
// RUN: grep '++for_var' %t
|
// RUN: grep '++for_var' %t
|
||||||
|
|
||||||
// RUN: index-test %t.ast -point-at %s:10:9 | grep local_var2
|
|
||||||
|
|
||||||
// RUN: index-test %t.ast -point-at %s:10:30 > %t
|
// RUN: index-test %t.ast -point-at %s:10:30 > %t
|
||||||
// RUN: grep 'for_var + 1' %t
|
// RUN: grep 'for_var + 1' %t
|
||||||
|
|
||||||
// fields test.
|
|
||||||
// RUN: index-test %t.ast -point-at %s:15:10 | grep field_var
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* Utility functions. */
|
/* Utility functions. */
|
||||||
|
@ -586,6 +587,71 @@ int perform_code_completion(int argc, const char **argv) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *filename;
|
||||||
|
unsigned line;
|
||||||
|
unsigned column;
|
||||||
|
} CursorSourceLocation;
|
||||||
|
|
||||||
|
int inspect_cursor_at(int argc, const char **argv) {
|
||||||
|
CXIndex CIdx;
|
||||||
|
int errorCode;
|
||||||
|
struct CXUnsavedFile *unsaved_files = 0;
|
||||||
|
int num_unsaved_files = 0;
|
||||||
|
CXTranslationUnit TU;
|
||||||
|
CXCursor Cursor;
|
||||||
|
CursorSourceLocation *Locations = 0;
|
||||||
|
unsigned NumLocations = 0, Loc;
|
||||||
|
|
||||||
|
/* Count the number of locations. */
|
||||||
|
while (strstr(argv[NumLocations+1], "-cursor-at=") == argv[NumLocations+1])
|
||||||
|
++NumLocations;
|
||||||
|
|
||||||
|
/* Parse the locations. */
|
||||||
|
assert(NumLocations > 0 && "Unable to count locations?");
|
||||||
|
Locations = (CursorSourceLocation *)malloc(
|
||||||
|
NumLocations * sizeof(CursorSourceLocation));
|
||||||
|
for (Loc = 0; Loc < NumLocations; ++Loc) {
|
||||||
|
const char *input = argv[Loc + 1] + strlen("-cursor-at=");
|
||||||
|
if ((errorCode = parse_file_line_column(input, &Locations[Loc].filename,
|
||||||
|
&Locations[Loc].line,
|
||||||
|
&Locations[Loc].column)))
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parse_remapped_files(argc, argv, NumLocations + 1, &unsaved_files,
|
||||||
|
&num_unsaved_files))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (num_unsaved_files > 0) {
|
||||||
|
fprintf(stderr, "cannot remap files when looking for a cursor\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CIdx = clang_createIndex(0, 1);
|
||||||
|
TU = clang_createTranslationUnitFromSourceFile(CIdx, argv[argc - 1],
|
||||||
|
argc - num_unsaved_files - 2 - NumLocations,
|
||||||
|
argv + num_unsaved_files + 1 + NumLocations);
|
||||||
|
if (!TU) {
|
||||||
|
fprintf(stderr, "unable to parse input\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Loc = 0; Loc < NumLocations; ++Loc) {
|
||||||
|
Cursor = clang_getCursor(TU, Locations[Loc].filename,
|
||||||
|
Locations[Loc].line, Locations[Loc].column);
|
||||||
|
PrintCursor(Cursor);
|
||||||
|
printf("\n");
|
||||||
|
free(Locations[Loc].filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
clang_disposeTranslationUnit(TU);
|
||||||
|
clang_disposeIndex(CIdx);
|
||||||
|
free(Locations);
|
||||||
|
free_remapped_files(unsaved_files, num_unsaved_files);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* Command line processing. */
|
/* Command line processing. */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -601,6 +667,7 @@ static CXTranslationUnitIterator GetVisitor(const char *s) {
|
||||||
static void print_usage(void) {
|
static void print_usage(void) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
|
"usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
|
||||||
|
" c-index-test -cursor-at=<site> <compiler arguments>\n"
|
||||||
" c-index-test -test-file-scan <AST file> <source file> "
|
" c-index-test -test-file-scan <AST file> <source file> "
|
||||||
"[FileCheck prefix]\n"
|
"[FileCheck prefix]\n"
|
||||||
" c-index-test -test-load-tu <AST file> <symbol filter> "
|
" c-index-test -test-load-tu <AST file> <symbol filter> "
|
||||||
|
@ -608,7 +675,8 @@ static void print_usage(void) {
|
||||||
" c-index-test -test-load-tu-usrs <AST file> <symbol filter> "
|
" c-index-test -test-load-tu-usrs <AST file> <symbol filter> "
|
||||||
"[FileCheck prefix]\n"
|
"[FileCheck prefix]\n"
|
||||||
" c-index-test -test-load-source <symbol filter> {<args>}*\n"
|
" c-index-test -test-load-source <symbol filter> {<args>}*\n"
|
||||||
" c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n\n"
|
" c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n\n");
|
||||||
|
fprintf(stderr,
|
||||||
" <symbol filter> values:\n%s",
|
" <symbol filter> values:\n%s",
|
||||||
" all - load all symbols, including those from PCH\n"
|
" all - load all symbols, including those from PCH\n"
|
||||||
" local - load all symbols except those in PCH\n"
|
" local - load all symbols except those in PCH\n"
|
||||||
|
@ -623,6 +691,8 @@ static void print_usage(void) {
|
||||||
int main(int argc, const char **argv) {
|
int main(int argc, const char **argv) {
|
||||||
if (argc > 2 && strstr(argv[1], "-code-completion-at=") == argv[1])
|
if (argc > 2 && strstr(argv[1], "-code-completion-at=") == argv[1])
|
||||||
return perform_code_completion(argc, argv);
|
return perform_code_completion(argc, argv);
|
||||||
|
if (argc > 2 && strstr(argv[1], "-cursor-at=") == argv[1])
|
||||||
|
return inspect_cursor_at(argc, argv);
|
||||||
else if (argc >= 4 && strncmp(argv[1], "-test-load-tu", 13) == 0) {
|
else if (argc >= 4 && strncmp(argv[1], "-test-load-tu", 13) == 0) {
|
||||||
CXTranslationUnitIterator I = GetVisitor(argv[1] + 13);
|
CXTranslationUnitIterator I = GetVisitor(argv[1] + 13);
|
||||||
if (I)
|
if (I)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче