[cfe-commits] r96606 - in /cfe/trunk: include/clang-c/Index.h test/Index/cindex-on-invalid.m tools/CIndex/CIndex.cpp tools/CIndex/CIndexer.h tools/c-index-test/c-index-test.c
Douglas Gregor
dgregor at apple.com
Thu Feb 18 12:11:31 PST 2010
Author: dgregor
Date: Thu Feb 18 14:11:31 2010
New Revision: 96606
URL: http://llvm.org/viewvc/llvm-project?rev=96606&view=rev
Log:
Resurrect the displayDiagnostics parameter to clang_createIndex(), and
display captured diagnostics when we can't return an invalid
CXTranslationUnit.
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/test/Index/cindex-on-invalid.m
cfe/trunk/tools/CIndex/CIndex.cpp
cfe/trunk/tools/CIndex/CIndexer.h
cfe/trunk/tools/c-index-test/c-index-test.c
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=96606&r1=96605&r2=96606&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Feb 18 14:11:31 2010
@@ -146,8 +146,8 @@
*
* Here is an example:
*
- * // excludeDeclsFromPCH = 1
- * Idx = clang_createIndex(1);
+ * // excludeDeclsFromPCH = 1, displayDiagnostics=1
+ * Idx = clang_createIndex(1, 1);
*
* // IndexTest.pch was produced with the following command:
* // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
@@ -171,7 +171,8 @@
* -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
* (which gives the indexer the same performance benefit as the compiler).
*/
-CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH);
+CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
+ int displayDiagnostics);
/**
* \brief Destroy the given index.
Modified: cfe/trunk/test/Index/cindex-on-invalid.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/cindex-on-invalid.m?rev=96606&r1=96605&r2=96606&view=diff
==============================================================================
--- cfe/trunk/test/Index/cindex-on-invalid.m (original)
+++ cfe/trunk/test/Index/cindex-on-invalid.m Thu Feb 18 14:11:31 2010
@@ -1,6 +1,5 @@
// RUN: not c-index-test -test-load-source local %s > %t 2> %t.err
// RUN: FileCheck %s < %t.err
-// XFAIL: *
// CHECK: error: expected identifier or '('
// CHECK: Unable to load translation unit!
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=96606&r1=96605&r2=96606&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Thu Feb 18 14:11:31 2010
@@ -903,10 +903,13 @@
}
extern "C" {
-CXIndex clang_createIndex(int excludeDeclarationsFromPCH) {
+CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
+ int displayDiagnostics) {
CIndexer *CIdxr = new CIndexer();
if (excludeDeclarationsFromPCH)
CIdxr->setOnlyLocalDecls();
+ if (displayDiagnostics)
+ CIdxr->setDisplayDiagnostics();
return CIdxr;
}
@@ -993,8 +996,18 @@
// FIXME: Until we have broader testing, just drop the entire AST if we
// encountered an error.
- if (NumErrors != Diags->getNumErrors())
+ if (NumErrors != Diags->getNumErrors()) {
+ if (CXXIdx->getDisplayDiagnostics()) {
+ for (ASTUnit::diag_iterator D = Unit->diag_begin(),
+ DEnd = Unit->diag_end();
+ D != DEnd; ++D) {
+ CXStoredDiagnostic Diag(*D, Unit->getASTContext().getLangOptions());
+ clang_displayDiagnostic(&Diag, stderr,
+ clang_defaultDiagnosticDisplayOptions());
+ }
+ }
return 0;
+ }
return Unit.take();
}
@@ -1085,18 +1098,35 @@
RemappedFiles.data(),
RemappedFiles.size(),
/*CaptureDiagnostics=*/true);
- if (ATU)
- ATU->unlinkTemporaryFile();
-
- // FIXME: Currently we don't report diagnostics on invalid ASTs.
if (ATU) {
LoadSerializedDiagnostics(DiagnosticsFile,
num_unsaved_files, unsaved_files,
ATU->getFileManager(),
ATU->getSourceManager(),
ATU->getDiagnostics());
+ } else if (CXXIdx->getDisplayDiagnostics()) {
+ // We failed to load the ASTUnit, but we can still deserialize the
+ // diagnostics and emit them.
+ FileManager FileMgr;
+ SourceManager SourceMgr;
+ // 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);
+ clang_displayDiagnostic(&Diag, stderr,
+ clang_defaultDiagnosticDisplayOptions());
+ }
}
+ if (ATU)
+ ATU->unlinkTemporaryFile();
+
for (unsigned i = 0, e = TemporaryFiles.size(); i != e; ++i)
TemporaryFiles[i].eraseFromDisk();
Modified: cfe/trunk/tools/CIndex/CIndexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndexer.h?rev=96606&r1=96605&r2=96606&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndexer.h (original)
+++ cfe/trunk/tools/CIndex/CIndexer.h Thu Feb 18 14:11:31 2010
@@ -34,11 +34,14 @@
class CIndexer {
bool UseExternalASTGeneration;
bool OnlyLocalDecls;
-
+ bool DisplayDiagnostics;
+
llvm::sys::Path ClangPath;
public:
- CIndexer() : UseExternalASTGeneration(false), OnlyLocalDecls(false) { }
+ CIndexer()
+ : UseExternalASTGeneration(false), 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
@@ -46,6 +49,11 @@
bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
+ bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
+ void setDisplayDiagnostics(bool Display = true) {
+ DisplayDiagnostics = Display;
+ }
+
bool getUseExternalASTGeneration() const { return UseExternalASTGeneration; }
void setUseExternalASTGeneration(bool Value) {
UseExternalASTGeneration = Value;
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=96606&r1=96605&r2=96606&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Feb 18 14:11:31 2010
@@ -487,7 +487,8 @@
CXTranslationUnit TU;
int result;
Idx = clang_createIndex(/* excludeDeclsFromPCH */
- !strcmp(filter, "local") ? 1 : 0);
+ !strcmp(filter, "local") ? 1 : 0,
+ /* displayDiagnosics=*/1);
if (!CreateTranslationUnit(Idx, file, &TU)) {
clang_disposeIndex(Idx);
@@ -511,7 +512,8 @@
int result;
Idx = clang_createIndex(/* excludeDeclsFromPCH */
- !strcmp(filter, "local") ? 1 : 0);
+ !strcmp(filter, "local") ? 1 : 0,
+ /* displayDiagnosics=*/1);
if (UseExternalASTs && strlen(UseExternalASTs))
clang_setUseExternalASTGeneration(Idx, 1);
@@ -565,7 +567,8 @@
unsigned line = 1, col = 1;
unsigned start_line = 1, start_col = 1;
- if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1))) {
+ if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
+ /* displayDiagnosics=*/1))) {
fprintf(stderr, "Could not create Index\n");
return 1;
}
@@ -766,7 +769,7 @@
if (parse_remapped_files(argc, argv, 2, &unsaved_files, &num_unsaved_files))
return -1;
- CIdx = clang_createIndex(0);
+ CIdx = clang_createIndex(0, 1);
results = clang_codeComplete(CIdx,
argv[argc - 1], argc - num_unsaved_files - 3,
argv + num_unsaved_files + 2,
@@ -830,7 +833,7 @@
&num_unsaved_files))
return -1;
- CIdx = clang_createIndex(0);
+ CIdx = clang_createIndex(0, 1);
TU = clang_createTranslationUnitFromSourceFile(CIdx, argv[argc - 1],
argc - num_unsaved_files - 2 - NumLocations,
argv + num_unsaved_files + 1 + NumLocations,
@@ -888,7 +891,7 @@
if (parse_remapped_files(argc, argv, 2, &unsaved_files, &num_unsaved_files))
return -1;
- CIdx = clang_createIndex(0);
+ CIdx = clang_createIndex(0, 1);
TU = clang_createTranslationUnitFromSourceFile(CIdx, argv[argc - 1],
argc - num_unsaved_files - 3,
argv + num_unsaved_files + 2,
More information about the cfe-commits
mailing list