[cfe-commits] r116207 - in /cfe/trunk: include/clang-c/Index.h test/Index/remap-cursor-at.c test/Index/remap-load.c tools/c-index-test/c-index-test.c tools/libclang/CIndex.cpp tools/libclang/CIndexer.h tools/libclang/libclang.darwin.exports tools/libclang/libclang.exports

Douglas Gregor dgregor at apple.com
Mon Oct 11 09:52:23 PDT 2010


Author: dgregor
Date: Mon Oct 11 11:52:23 2010
New Revision: 116207

URL: http://llvm.org/viewvc/llvm-project?rev=116207&view=rev
Log:
Eliminate clang_setUseExternalASTGeneration() from libclang. Between
improvements to the compiler and the introduction of crash recovery,
it no longer makes sense to allow this mode. Moreover, this eliminates
one use of the "clang" executable from within libclang; we'd like them
all to go away.

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/test/Index/remap-cursor-at.c
    cfe/trunk/test/Index/remap-load.c
    cfe/trunk/tools/c-index-test/c-index-test.c
    cfe/trunk/tools/libclang/CIndex.cpp
    cfe/trunk/tools/libclang/CIndexer.h
    cfe/trunk/tools/libclang/libclang.darwin.exports
    cfe/trunk/tools/libclang/libclang.exports

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=116207&r1=116206&r2=116207&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Mon Oct 11 11:52:23 2010
@@ -202,18 +202,6 @@
 CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
 
 /**
- * \brief Request that AST's be generated externally for API calls which parse
- * source code on the fly, e.g. \see createTranslationUnitFromSourceFile.
- *
- * Note: This is for debugging purposes only, and may be removed at a later
- * date.
- *
- * \param index - The index to update.
- * \param value - The new flag value.
- */
-CINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index,
-                                                      int value);
-/**
  * \defgroup CINDEX_FILES File manipulation routines
  *
  * @{

Modified: cfe/trunk/test/Index/remap-cursor-at.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/remap-cursor-at.c?rev=116207&r1=116206&r2=116207&view=diff
==============================================================================
--- cfe/trunk/test/Index/remap-cursor-at.c (original)
+++ cfe/trunk/test/Index/remap-cursor-at.c Mon Oct 11 11:52:23 2010
@@ -1,5 +1,4 @@
 // RUN: c-index-test -cursor-at=%s:1:15 -cursor-at=%s:2:21 -remap-file="%s;%S/Inputs/remap-load-to.c" %s | FileCheck %s
-// RUN: env CINDEXTEST_USE_EXTERNAL_AST_GENERATION=1 c-index-test -cursor-at=%s:1:15 -cursor-at=%s:2:21 -remap-file="%s;%S/Inputs/remap-load-to.c" %s | FileCheck %s
 
 // CHECK: ParmDecl=parm1:1:13 (Definition)
 // CHECK: DeclRefExpr=parm2:1:26

Modified: cfe/trunk/test/Index/remap-load.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/remap-load.c?rev=116207&r1=116206&r2=116207&view=diff
==============================================================================
--- cfe/trunk/test/Index/remap-load.c (original)
+++ cfe/trunk/test/Index/remap-load.c Mon Oct 11 11:52:23 2010
@@ -1,6 +1,4 @@
 // RUN: c-index-test -test-load-source all -remap-file="%s;%S/Inputs/remap-load-to.c" %s | FileCheck -check-prefix=CHECK %s
-// RUN: env CINDEXTEST_USE_EXTERNAL_AST_GENERATION=1 c-index-test -test-load-source all -remap-file="%s;%S/Inputs/remap-load-to.c" %s | FileCheck -check-prefix=CHECK %s
-// XFAIL: win32
 
 // CHECK: remap-load.c:1:5: FunctionDecl=foo:1:5 (Definition) Extent=[1:5 - 3:2]
 // CHECK: remap-load.c:1:13: ParmDecl=parm1:1:13 (Definition) Extent=[1:9 - 1:18]

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=116207&r1=116206&r2=116207&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Mon Oct 11 11:52:23 2010
@@ -660,8 +660,6 @@
 int perform_test_load_source(int argc, const char **argv,
                              const char *filter, CXCursorVisitor Visitor,
                              PostVisitTU PV) {
-  const char *UseExternalASTs =
-    getenv("CINDEXTEST_USE_EXTERNAL_AST_GENERATION");
   CXIndex Idx;
   CXTranslationUnit TU;
   struct CXUnsavedFile *unsaved_files = 0;
@@ -673,9 +671,6 @@
                            !strcmp(filter, "local-display"))? 1 : 0,
                           /* displayDiagnosics=*/1);
 
-  if (UseExternalASTs && strlen(UseExternalASTs))
-    clang_setUseExternalASTGeneration(Idx, 1);
-
   if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) {
     clang_disposeIndex(Idx);
     return -1;
@@ -702,8 +697,6 @@
 int perform_test_reparse_source(int argc, const char **argv, int trials,
                                 const char *filter, CXCursorVisitor Visitor,
                                 PostVisitTU PV) {
-  const char *UseExternalASTs =
-  getenv("CINDEXTEST_USE_EXTERNAL_AST_GENERATION");
   CXIndex Idx;
   CXTranslationUnit TU;
   struct CXUnsavedFile *unsaved_files = 0;
@@ -715,9 +708,6 @@
                           !strcmp(filter, "local") ? 1 : 0,
                           /* displayDiagnosics=*/1);
   
-  if (UseExternalASTs && strlen(UseExternalASTs))
-    clang_setUseExternalASTGeneration(Idx, 1);
-  
   if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) {
     clang_disposeIndex(Idx);
     return -1;

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=116207&r1=116206&r2=116207&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Mon Oct 11 11:52:23 2010
@@ -1950,13 +1950,6 @@
     delete static_cast<CIndexer *>(CIdx);
 }
 
-void clang_setUseExternalASTGeneration(CXIndex CIdx, int value) {
-  if (CIdx) {
-    CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
-    CXXIdx->setUseExternalASTGeneration(value);
-  }
-}
-
 CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx,
                                               const char *ast_filename) {
   if (!CIdx)
@@ -2035,233 +2028,79 @@
                                            Buffer));
   }
 
-  if (!CXXIdx->getUseExternalASTGeneration()) {
-    llvm::SmallVector<const char *, 16> Args;
-
-    // The 'source_filename' argument is optional.  If the caller does not
-    // specify it then it is assumed that the source file is specified
-    // in the actual argument list.
-    if (source_filename)
-      Args.push_back(source_filename);
-    
-    // Since the Clang C library is primarily used by batch tools dealing with
-    // (often very broken) source code, where spell-checking can have a
-    // significant negative impact on performance (particularly when 
-    // precompiled headers are involved), we disable it by default.
-    // Only do this if we haven't found a spell-checking-related argument.
-    bool FoundSpellCheckingArgument = false;
-    for (int I = 0; I != num_command_line_args; ++I) {
-      if (strcmp(command_line_args[I], "-fno-spell-checking") == 0 ||
-          strcmp(command_line_args[I], "-fspell-checking") == 0) {
-        FoundSpellCheckingArgument = true;
-        break;
-      }
-    }
-    if (!FoundSpellCheckingArgument)
-      Args.push_back("-fno-spell-checking");
-    
-    Args.insert(Args.end(), command_line_args,
-                command_line_args + num_command_line_args);
-
-    // Do we need the detailed preprocessing record?
-    if (options & CXTranslationUnit_DetailedPreprocessingRecord) {
-      Args.push_back("-Xclang");
-      Args.push_back("-detailed-preprocessing-record");
-    }
-    
-    unsigned NumErrors = Diags->getNumErrors();
-
-#ifdef USE_CRASHTRACER
-    ArgsCrashTracerInfo ACTI(Args);
-#endif
-
-    llvm::OwningPtr<ASTUnit> Unit(
-      ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(),
-                                   Diags,
-                                   CXXIdx->getClangResourcesPath(),
-                                   CXXIdx->getOnlyLocalDecls(),
-                                   RemappedFiles.data(),
-                                   RemappedFiles.size(),
-                                   /*CaptureDiagnostics=*/true,
-                                   PrecompilePreamble,
-                                   CompleteTranslationUnit,
-                                   CacheCodeCompetionResults));
-
-    if (NumErrors != Diags->getNumErrors()) {
-      // Make sure to check that 'Unit' is non-NULL.
-      if (CXXIdx->getDisplayDiagnostics() && Unit.get()) {
-        for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(), 
-                                        DEnd = Unit->stored_diag_end();
-             D != DEnd; ++D) {
-          CXStoredDiagnostic Diag(*D, Unit->getASTContext().getLangOptions());
-          CXString Msg = clang_formatDiagnostic(&Diag,
-                                      clang_defaultDiagnosticDisplayOptions());
-          fprintf(stderr, "%s\n", clang_getCString(Msg));
-          clang_disposeString(Msg);
-        }
-#ifdef LLVM_ON_WIN32
-        // On Windows, force a flush, since there may be multiple copies of
-        // stderr and stdout in the file system, all with different buffers
-        // but writing to the same device.
-        fflush(stderr);
-#endif
-      }
-    }
-
-    PTUI->result = Unit.take();
-    return;
-  }
-
-  // Build up the arguments for invoking 'clang'.
-  std::vector<const char *> argv;
-
-  // First add the complete path to the 'clang' executable.
-  llvm::sys::Path ClangPath = static_cast<CIndexer *>(CIdx)->getClangPath();
-  argv.push_back(ClangPath.c_str());
-
-  // Add the '-emit-ast' option as our execution mode for 'clang'.
-  argv.push_back("-emit-ast");
+  llvm::SmallVector<const char *, 16> Args;
 
   // The 'source_filename' argument is optional.  If the caller does not
   // specify it then it is assumed that the source file is specified
   // in the actual argument list.
   if (source_filename)
-    argv.push_back(source_filename);
-
-  // Generate a temporary name for the AST file.
-  argv.push_back("-o");
-  char astTmpFile[L_tmpnam];
-  argv.push_back(tmpnam(astTmpFile));
+    Args.push_back(source_filename);
   
   // Since the Clang C library is primarily used by batch tools dealing with
   // (often very broken) source code, where spell-checking can have a
   // significant negative impact on performance (particularly when 
   // precompiled headers are involved), we disable it by default.
-  // Note that we place this argument early in the list, so that it can be
-  // overridden by the caller with "-fspell-checking".
-  argv.push_back("-fno-spell-checking");
-
-  // Remap any unsaved files to temporary files.
-  std::vector<llvm::sys::Path> TemporaryFiles;
-  std::vector<std::string> RemapArgs;
-  if (RemapFiles(num_unsaved_files, unsaved_files, RemapArgs, TemporaryFiles))
-    return;
-
-  // The pointers into the elements of RemapArgs are stable because we
-  // won't be adding anything to RemapArgs after this point.
-  for (unsigned i = 0, e = RemapArgs.size(); i != e; ++i)
-    argv.push_back(RemapArgs[i].c_str());
-
-  // Process the compiler options, stripping off '-o', '-c', '-fsyntax-only'.
-  for (int i = 0; i < num_command_line_args; ++i)
-    if (const char *arg = command_line_args[i]) {
-      if (strcmp(arg, "-o") == 0) {
-        ++i; // Also skip the matching argument.
-        continue;
-      }
-      if (strcmp(arg, "-emit-ast") == 0 ||
-          strcmp(arg, "-c") == 0 ||
-          strcmp(arg, "-fsyntax-only") == 0) {
-        continue;
-      }
-
-      // Keep the argument.
-      argv.push_back(arg);
+  // Only do this if we haven't found a spell-checking-related argument.
+  bool FoundSpellCheckingArgument = false;
+  for (int I = 0; I != num_command_line_args; ++I) {
+    if (strcmp(command_line_args[I], "-fno-spell-checking") == 0 ||
+        strcmp(command_line_args[I], "-fspell-checking") == 0) {
+      FoundSpellCheckingArgument = true;
+      break;
     }
-
-  // Generate a temporary name for the diagnostics file.
-  char tmpFileResults[L_tmpnam];
-  char *tmpResultsFileName = tmpnam(tmpFileResults);
-  llvm::sys::Path DiagnosticsFile(tmpResultsFileName);
-  TemporaryFiles.push_back(DiagnosticsFile);
-  argv.push_back("-fdiagnostics-binary");
+  }
+  if (!FoundSpellCheckingArgument)
+    Args.push_back("-fno-spell-checking");
+  
+  Args.insert(Args.end(), command_line_args,
+              command_line_args + num_command_line_args);
 
   // Do we need the detailed preprocessing record?
   if (options & CXTranslationUnit_DetailedPreprocessingRecord) {
-    argv.push_back("-Xclang");
-    argv.push_back("-detailed-preprocessing-record");
+    Args.push_back("-Xclang");
+    Args.push_back("-detailed-preprocessing-record");
   }
   
-  // Add the null terminator.
-  argv.push_back(NULL);
+  unsigned NumErrors = Diags->getNumErrors();
 
-  // Invoke 'clang'.
-  llvm::sys::Path DevNull; // leave empty, causes redirection to /dev/null
-                           // on Unix or NUL (Windows).
-  std::string ErrMsg;
-  const llvm::sys::Path *Redirects[] = { &DevNull, &DevNull, &DiagnosticsFile,
-                                         NULL };
-  llvm::sys::Program::ExecuteAndWait(ClangPath, &argv[0], /* env */ NULL,
-      /* redirects */ &Redirects[0],
-      /* secondsToWait */ 0, /* memoryLimits */ 0, &ErrMsg);
-
-  if (!ErrMsg.empty()) {
-    std::string AllArgs;
-    for (std::vector<const char*>::iterator I = argv.begin(), E = argv.end();
-         I != E; ++I) {
-      AllArgs += ' ';
-      if (*I)
-        AllArgs += *I;
-    }
-
-    Diags->Report(diag::err_fe_invoking) << AllArgs << ErrMsg;
-  }
-
-  ASTUnit *ATU = ASTUnit::LoadFromASTFile(astTmpFile, Diags,
-                                          CXXIdx->getOnlyLocalDecls(),
-                                          RemappedFiles.data(),
-                                          RemappedFiles.size(),
-                                          /*CaptureDiagnostics=*/true);
-  if (ATU) {
-    LoadSerializedDiagnostics(DiagnosticsFile, 
-                              num_unsaved_files, unsaved_files,
-                              ATU->getFileManager(),
-                              ATU->getSourceManager(),
-                              ATU->getStoredDiagnostics());
-  } else if (CXXIdx->getDisplayDiagnostics()) {
-    // We failed to load the ASTUnit, but we can still deserialize the
-    // diagnostics and emit them.
-    FileManager FileMgr;
-    Diagnostic Diag;
-    SourceManager SourceMgr(Diag);
-    // FIXME: Faked LangOpts!
-    LangOptions LangOpts;
-    llvm::SmallVector<StoredDiagnostic, 4> Diags;
-    LoadSerializedDiagnostics(DiagnosticsFile, 
-                              num_unsaved_files, unsaved_files,
-                              FileMgr, SourceMgr, Diags);
-    for (llvm::SmallVector<StoredDiagnostic, 4>::iterator D = Diags.begin(), 
-                                                       DEnd = Diags.end();
-         D != DEnd; ++D) {
-      CXStoredDiagnostic Diag(*D, LangOpts);
-      CXString Msg = clang_formatDiagnostic(&Diag,
-                                      clang_defaultDiagnosticDisplayOptions());
-      fprintf(stderr, "%s\n", clang_getCString(Msg));
-      clang_disposeString(Msg);
-    }
-    
+#ifdef USE_CRASHTRACER
+  ArgsCrashTracerInfo ACTI(Args);
+#endif
+
+  llvm::OwningPtr<ASTUnit> Unit(
+    ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(),
+                                 Diags,
+                                 CXXIdx->getClangResourcesPath(),
+                                 CXXIdx->getOnlyLocalDecls(),
+                                 RemappedFiles.data(),
+                                 RemappedFiles.size(),
+                                 /*CaptureDiagnostics=*/true,
+                                 PrecompilePreamble,
+                                 CompleteTranslationUnit,
+                                 CacheCodeCompetionResults));
+
+  if (NumErrors != Diags->getNumErrors()) {
+    // Make sure to check that 'Unit' is non-NULL.
+    if (CXXIdx->getDisplayDiagnostics() && Unit.get()) {
+      for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(), 
+                                      DEnd = Unit->stored_diag_end();
+           D != DEnd; ++D) {
+        CXStoredDiagnostic Diag(*D, Unit->getASTContext().getLangOptions());
+        CXString Msg = clang_formatDiagnostic(&Diag,
+                                    clang_defaultDiagnosticDisplayOptions());
+        fprintf(stderr, "%s\n", clang_getCString(Msg));
+        clang_disposeString(Msg);
+      }
 #ifdef LLVM_ON_WIN32
-    // On Windows, force a flush, since there may be multiple copies of
-    // stderr and stdout in the file system, all with different buffers
-    // but writing to the same device.
-    fflush(stderr);
-#endif    
+      // On Windows, force a flush, since there may be multiple copies of
+      // stderr and stdout in the file system, all with different buffers
+      // but writing to the same device.
+      fflush(stderr);
+#endif
+    }
   }
 
-  if (ATU) {
-    // Make the translation unit responsible for destroying all temporary files.
-    for (unsigned i = 0, e = TemporaryFiles.size(); i != e; ++i)
-      ATU->addTemporaryFile(TemporaryFiles[i]);
-    ATU->addTemporaryFile(llvm::sys::Path(ATU->getASTFileName()));
-  } else {
-    // Destroy all of the temporary files now; they can't be referenced any
-    // longer.
-    llvm::sys::Path(astTmpFile).eraseFromDisk();
-    for (unsigned i = 0, e = TemporaryFiles.size(); i != e; ++i)
-      TemporaryFiles[i].eraseFromDisk();
-  }
-  
-  PTUI->result = ATU;
+  PTUI->result = Unit.take();
 }
 CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
                                              const char *source_filename,

Modified: cfe/trunk/tools/libclang/CIndexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexer.h?rev=116207&r1=116206&r2=116207&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexer.h (original)
+++ cfe/trunk/tools/libclang/CIndexer.h Mon Oct 11 11:52:23 2010
@@ -28,16 +28,13 @@
 }
 
 class CIndexer {
-  bool UseExternalASTGeneration;
   bool OnlyLocalDecls;
   bool DisplayDiagnostics;
 
   llvm::sys::Path ClangPath;
   
 public:
- CIndexer() 
-   : UseExternalASTGeneration(false), OnlyLocalDecls(false),
-     DisplayDiagnostics(false) { }
+ CIndexer() : OnlyLocalDecls(false), DisplayDiagnostics(false) { }
   
   /// \brief Whether we only want to see "local" declarations (that did not
   /// come from a previous precompiled header). If false, we want to see all
@@ -50,11 +47,6 @@
     DisplayDiagnostics = Display;
   }
 
-  bool getUseExternalASTGeneration() const { return UseExternalASTGeneration; }
-  void setUseExternalASTGeneration(bool Value) {
-    UseExternalASTGeneration = Value;
-  }
-  
   /// \brief Get the path of the clang binary.
   const llvm::sys::Path& getClangPath();
   

Modified: cfe/trunk/tools/libclang/libclang.darwin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.darwin.exports?rev=116207&r1=116206&r2=116207&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.darwin.exports (original)
+++ cfe/trunk/tools/libclang/libclang.darwin.exports Mon Oct 11 11:52:23 2010
@@ -109,7 +109,6 @@
 _clang_parseTranslationUnit
 _clang_reparseTranslationUnit
 _clang_saveTranslationUnit
-_clang_setUseExternalASTGeneration
 _clang_sortCodeCompletionResults
 _clang_tokenize
 _clang_visitChildren

Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=116207&r1=116206&r2=116207&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Mon Oct 11 11:52:23 2010
@@ -109,7 +109,6 @@
 clang_parseTranslationUnit
 clang_reparseTranslationUnit
 clang_saveTranslationUnit
-clang_setUseExternalASTGeneration
 clang_sortCodeCompletionResults
 clang_tokenize
 clang_visitChildren





More information about the cfe-commits mailing list