From 8e08dec6374473b11c019035aef130e0bb0551f9 Mon Sep 17 00:00:00 2001 From: Douglas Gregor <dgregor@apple.com> Date: Tue, 30 Nov 2010 05:52:55 +0000 Subject: [PATCH] =?UTF-8?q?Teach=20c-index-test=20to=20reparse=20the=20sou?= =?UTF-8?q?rce=20file=20a=20few=20times=20when=20testing=20clang=5FgetCurs?= =?UTF-8?q?or()=20via=20-cursor-at=3D=3F=3F=3F=20and=20CINDEXTEST=5FEDITIN?= =?UTF-8?q?G=20is=20set=20in=20the=20environment.=20This=20mirrors=20how?= =?UTF-8?q?=20we=20test=20code=20completion=20and=20source-loading=20in=20?= =?UTF-8?q?the=20presence=20of=20this=20environment=20variable.?= git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120392 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/c-index-test/c-index-test.c | 53 +++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 8e76dc0b8b1..72afe577ed4 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -1100,7 +1100,8 @@ int inspect_cursor_at(int argc, const char **argv) { CXCursor Cursor; CursorSourceLocation *Locations = 0; unsigned NumLocations = 0, Loc; - + unsigned Repeats = 1; + /* Count the number of locations. */ while (strstr(argv[NumLocations+1], "-cursor-at=") == argv[NumLocations+1]) ++NumLocations; @@ -1121,30 +1122,48 @@ int inspect_cursor_at(int argc, const char **argv) { &num_unsaved_files)) return -1; - CIdx = clang_createIndex(0, 1); - TU = clang_createTranslationUnitFromSourceFile(CIdx, argv[argc - 1], + if (getenv("CINDEXTEST_EDITING")) + 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, - argv + num_unsaved_files + 1 + NumLocations, - num_unsaved_files, - unsaved_files); + unsaved_files, + Repeats > 1? 0 : num_unsaved_files, + getDefaultParsingOptions()); + if (!TU) { fprintf(stderr, "unable to parse input\n"); return -1; } - for (Loc = 0; Loc < NumLocations; ++Loc) { - CXFile file = clang_getFile(TU, Locations[Loc].filename); - if (!file) - continue; + for (unsigned I = 0; I != Repeats; ++I) { + if (Repeats > 1 && + clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files, + 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, - clang_getLocation(TU, file, Locations[Loc].line, - Locations[Loc].column)); - PrintCursor(Cursor); - printf("\n"); - free(Locations[Loc].filename); + Cursor = clang_getCursor(TU, + clang_getLocation(TU, file, Locations[Loc].line, + Locations[Loc].column)); + if (I + 1 == Repeats) { + PrintCursor(Cursor); + printf("\n"); + free(Locations[Loc].filename); + } + } } - + PrintDiagnostics(TU); clang_disposeTranslationUnit(TU); clang_disposeIndex(CIdx); -- GitLab