[llvm-branch-commits] [cfe-branch] r120669 - /cfe/branches/Apple/whitney/tools/c-index-test/c-index-test.c

Daniel Dunbar daniel at zuster.org
Wed Dec 1 18:52:26 PST 2010


Author: ddunbar
Date: Wed Dec  1 20:52:26 2010
New Revision: 120669

URL: http://llvm.org/viewvc/llvm-project?rev=120669&view=rev
Log:
Merge r120392:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Tue Nov 30 05:52:55 2010 +0000

    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.

Modified:
    cfe/branches/Apple/whitney/tools/c-index-test/c-index-test.c

Modified: cfe/branches/Apple/whitney/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/c-index-test/c-index-test.c?rev=120669&r1=120668&r2=120669&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/c-index-test/c-index-test.c (original)
+++ cfe/branches/Apple/whitney/tools/c-index-test/c-index-test.c Wed Dec  1 20:52:26 2010
@@ -1100,7 +1100,8 @@
   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 @@
                            &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;
-
-    Cursor = clang_getCursor(TU,
-                             clang_getLocation(TU, file, Locations[Loc].line,
-                                               Locations[Loc].column));
-    PrintCursor(Cursor);
-    printf("\n");
-    free(Locations[Loc].filename);
-  }
+  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));
+      if (I + 1 == Repeats) {
+        PrintCursor(Cursor);
+        printf("\n");
+        free(Locations[Loc].filename);
+      }
+    }
+  }
+  
   PrintDiagnostics(TU);
   clang_disposeTranslationUnit(TU);
   clang_disposeIndex(CIdx);





More information about the llvm-branch-commits mailing list