Teach c-index-test to reparse the source file a few times when testing
clang_getCursor() via -cursor-at=??? and CINDEXTEST_EDITING is set in the environment. This mirrors how we test code completion and source-loading in the presence of this environment variable. llvm-svn: 120392
This commit is contained in:
parent
3590ef817c
commit
2f6358b100
|
@ -1100,7 +1100,8 @@ int inspect_cursor_at(int argc, const char **argv) {
|
||||||
CXCursor Cursor;
|
CXCursor Cursor;
|
||||||
CursorSourceLocation *Locations = 0;
|
CursorSourceLocation *Locations = 0;
|
||||||
unsigned NumLocations = 0, Loc;
|
unsigned NumLocations = 0, Loc;
|
||||||
|
unsigned Repeats = 1;
|
||||||
|
|
||||||
/* Count the number of locations. */
|
/* Count the number of locations. */
|
||||||
while (strstr(argv[NumLocations+1], "-cursor-at=") == argv[NumLocations+1])
|
while (strstr(argv[NumLocations+1], "-cursor-at=") == argv[NumLocations+1])
|
||||||
++NumLocations;
|
++NumLocations;
|
||||||
|
@ -1121,30 +1122,48 @@ int inspect_cursor_at(int argc, const char **argv) {
|
||||||
&num_unsaved_files))
|
&num_unsaved_files))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
CIdx = clang_createIndex(0, 1);
|
if (getenv("CINDEXTEST_EDITING"))
|
||||||
TU = clang_createTranslationUnitFromSourceFile(CIdx, argv[argc - 1],
|
Repeats = 5;
|
||||||
|
|
||||||
|
/* Parse the translation unit. When we're testing clang_getCursor() after
|
||||||
|
reparsing, don't remap unsaved files until the second parse. */
|
||||||
|
CIdx = clang_createIndex(1, 1);
|
||||||
|
TU = clang_parseTranslationUnit(CIdx, argv[argc - 1],
|
||||||
|
argv + num_unsaved_files + 1 + NumLocations,
|
||||||
argc - num_unsaved_files - 2 - NumLocations,
|
argc - num_unsaved_files - 2 - NumLocations,
|
||||||
argv + num_unsaved_files + 1 + NumLocations,
|
unsaved_files,
|
||||||
num_unsaved_files,
|
Repeats > 1? 0 : num_unsaved_files,
|
||||||
unsaved_files);
|
getDefaultParsingOptions());
|
||||||
|
|
||||||
if (!TU) {
|
if (!TU) {
|
||||||
fprintf(stderr, "unable to parse input\n");
|
fprintf(stderr, "unable to parse input\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Loc = 0; Loc < NumLocations; ++Loc) {
|
for (unsigned I = 0; I != Repeats; ++I) {
|
||||||
CXFile file = clang_getFile(TU, Locations[Loc].filename);
|
if (Repeats > 1 &&
|
||||||
if (!file)
|
clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
|
||||||
continue;
|
clang_defaultReparseOptions(TU))) {
|
||||||
|
clang_disposeTranslationUnit(TU);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Loc = 0; Loc < NumLocations; ++Loc) {
|
||||||
|
CXFile file = clang_getFile(TU, Locations[Loc].filename);
|
||||||
|
if (!file)
|
||||||
|
continue;
|
||||||
|
|
||||||
Cursor = clang_getCursor(TU,
|
Cursor = clang_getCursor(TU,
|
||||||
clang_getLocation(TU, file, Locations[Loc].line,
|
clang_getLocation(TU, file, Locations[Loc].line,
|
||||||
Locations[Loc].column));
|
Locations[Loc].column));
|
||||||
PrintCursor(Cursor);
|
if (I + 1 == Repeats) {
|
||||||
printf("\n");
|
PrintCursor(Cursor);
|
||||||
free(Locations[Loc].filename);
|
printf("\n");
|
||||||
|
free(Locations[Loc].filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintDiagnostics(TU);
|
PrintDiagnostics(TU);
|
||||||
clang_disposeTranslationUnit(TU);
|
clang_disposeTranslationUnit(TU);
|
||||||
clang_disposeIndex(CIdx);
|
clang_disposeIndex(CIdx);
|
||||||
|
|
Loading…
Reference in New Issue