aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang-c/Index.h12
-rw-r--r--test/Index/remap-cursor-at.c1
-rw-r--r--test/Index/remap-load.c2
-rw-r--r--tools/c-index-test/c-index-test.c10
-rw-r--r--tools/libclang/CIndex.cpp265
-rw-r--r--tools/libclang/CIndexer.h10
-rw-r--r--tools/libclang/libclang.darwin.exports1
-rw-r--r--tools/libclang/libclang.exports1
8 files changed, 53 insertions, 249 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 707c0df201..1dc4c05c02 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -202,18 +202,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 fb97d5d62b..c2bed0e69c 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 2e57fe4cd9..d54c3a1076 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 ca4b1e3169..4b9ab500dc 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 1dfabcac65..a5b342dbe7 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 31bf779ea4..6ef8b40e03 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 0682a58e6b..6f3cfffc74 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 e7e4f8be14..b41fbcafcf 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