diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 707c0df20170a786f8b4ab3005b50860eafbe950..1dc4c05c0258e36910e7468ab2600d2e300f7df1 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -201,18 +201,6 @@ CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH, */ 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 * diff --git a/test/Index/remap-cursor-at.c b/test/Index/remap-cursor-at.c index fb97d5d62bc721f636f298c07000b46f84c7ff8e..c2bed0e69cacfc2d280acb06e5d519ed3b5189a2 100644 --- a/test/Index/remap-cursor-at.c +++ b/test/Index/remap-cursor-at.c @@ -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 diff --git a/test/Index/remap-load.c b/test/Index/remap-load.c index 2e57fe4cd94d0cdb3d8226e304ce551cf288e4c0..d54c3a107682e14f8d4a9766b8c08277d30129ba 100644 --- a/test/Index/remap-load.c +++ b/test/Index/remap-load.c @@ -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] diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index ca4b1e3169cd81c36b4a98ac5afabb2c709cae05..4b9ab500dc56d7497dc9a005829189b992aa1eae 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -660,8 +660,6 @@ int perform_test_load_tu(const char *file, const char *filter, 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 @@ int perform_test_load_source(int argc, const char **argv, !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_load_source(int argc, const char **argv, 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 @@ int perform_test_reparse_source(int argc, const char **argv, int trials, !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; diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 1dfabcac65732619a767ecffb5c23a6f4f8757d2..a5b342dbe75f4e80c43badf84998dbbf5045e2c7 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1950,13 +1950,6 @@ void clang_disposeIndex(CXIndex CIdx) { 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 @@ static void clang_parseTranslationUnit_Impl(void *UserData) { 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); - - // 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; - } + unsigned NumErrors = Diags->getNumErrors(); - Diags->Report(diag::err_fe_invoking) << AllArgs << ErrMsg; - } +#ifdef USE_CRASHTRACER + ArgsCrashTracerInfo ACTI(Args); +#endif - 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); - } - + 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, diff --git a/tools/libclang/CIndexer.h b/tools/libclang/CIndexer.h index 31bf779ea4a569b9f7377ebbe1318733958e038a..6ef8b40e039910ce68720281f2609d0fc2a4b824 100644 --- a/tools/libclang/CIndexer.h +++ b/tools/libclang/CIndexer.h @@ -28,16 +28,13 @@ namespace cxstring { } 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 @@ public: 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(); diff --git a/tools/libclang/libclang.darwin.exports b/tools/libclang/libclang.darwin.exports index 0682a58e6b97b4c32b83b8e1cbac9bf798b10a2b..6f3cfffc74c2e1801063dfb2edbce4a0a3362933 100644 --- a/tools/libclang/libclang.darwin.exports +++ b/tools/libclang/libclang.darwin.exports @@ -109,7 +109,6 @@ _clang_isVirtualBase _clang_parseTranslationUnit _clang_reparseTranslationUnit _clang_saveTranslationUnit -_clang_setUseExternalASTGeneration _clang_sortCodeCompletionResults _clang_tokenize _clang_visitChildren diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index e7e4f8be14dcbc1aa746a429cb93e81de193a06e..b41fbcafcfe708286c4de6252842982c8beabd23 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -109,7 +109,6 @@ clang_isVirtualBase clang_parseTranslationUnit clang_reparseTranslationUnit clang_saveTranslationUnit -clang_setUseExternalASTGeneration clang_sortCodeCompletionResults clang_tokenize clang_visitChildren