summaryrefslogtreecommitdiffstats
path: root/clang/tools/CIndex/CIndexDiagnostic.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/tools/CIndex/CIndexDiagnostic.cpp')
-rw-r--r--clang/tools/CIndex/CIndexDiagnostic.cpp85
1 files changed, 82 insertions, 3 deletions
diff --git a/clang/tools/CIndex/CIndexDiagnostic.cpp b/clang/tools/CIndex/CIndexDiagnostic.cpp
index 70676f0e141..07c1983672d 100644
--- a/clang/tools/CIndex/CIndexDiagnostic.cpp
+++ b/clang/tools/CIndex/CIndexDiagnostic.cpp
@@ -47,6 +47,81 @@ void clang_disposeDiagnostic(CXDiagnostic Diagnostic) {
delete Stored;
}
+void clang_displayDiagnostic(CXDiagnostic Diagnostic, FILE *Out,
+ unsigned Options) {
+ if (!Diagnostic || !Out)
+ return;
+
+ CXDiagnosticSeverity Severity = clang_getDiagnosticSeverity(Diagnostic);
+
+ // Ignore diagnostics that should be ignored.
+ if (Severity == CXDiagnostic_Ignored)
+ return;
+
+ if (Options & CXDiagnostic_DisplaySourceLocation) {
+ // Print source location (file:line), along with optional column
+ // and source ranges.
+ CXFile File;
+ unsigned Line, Column;
+ clang_getInstantiationLocation(clang_getDiagnosticLocation(Diagnostic),
+ &File, &Line, &Column, 0);
+ if (File) {
+ CXString FName = clang_getFileName(File);
+ fprintf(Out, "%s:%d:", clang_getCString(FName), Line);
+ clang_disposeString(FName);
+ if (Options & CXDiagnostic_DisplayColumn)
+ fprintf(Out, "%d:", Column);
+
+ if (Options & CXDiagnostic_DisplaySourceRanges) {
+ unsigned N = clang_getDiagnosticNumRanges(Diagnostic);
+ bool PrintedRange = false;
+ for (unsigned I = 0; I != N; ++I) {
+ CXFile StartFile, EndFile;
+ CXSourceRange Range = clang_getDiagnosticRange(Diagnostic, I);
+
+ unsigned StartLine, StartColumn, EndLine, EndColumn;
+ clang_getInstantiationLocation(clang_getRangeStart(Range),
+ &StartFile, &StartLine, &StartColumn,
+ 0);
+ clang_getInstantiationLocation(clang_getRangeEnd(Range),
+ &EndFile, &EndLine, &EndColumn, 0);
+
+ if (StartFile != EndFile || StartFile != File)
+ continue;
+
+ fprintf(Out, "{%d:%d-%d:%d}", StartLine, StartColumn,
+ EndLine, EndColumn);
+ PrintedRange = true;
+ }
+ if (PrintedRange)
+ fprintf(Out, ":");
+ }
+ }
+
+ fprintf(Out, " ");
+ }
+
+ /* Print warning/error/etc. */
+ switch (Severity) {
+ case CXDiagnostic_Ignored: assert(0 && "impossible"); break;
+ case CXDiagnostic_Note: fprintf(Out, "note: "); break;
+ case CXDiagnostic_Warning: fprintf(Out, "warning: "); break;
+ case CXDiagnostic_Error: fprintf(Out, "error: "); break;
+ case CXDiagnostic_Fatal: fprintf(Out, "fatal error: "); break;
+ }
+
+ CXString Text = clang_getDiagnosticSpelling(Diagnostic);
+ if (clang_getCString(Text))
+ fprintf(Out, "%s\n", clang_getCString(Text));
+ else
+ fprintf(Out, "<no diagnostic text>\n");
+ clang_disposeString(Text);
+}
+
+unsigned clang_defaultDiagnosticDisplayOptions() {
+ return CXDiagnostic_DisplaySourceLocation | CXDiagnostic_DisplayColumn;
+}
+
enum CXDiagnosticSeverity clang_getDiagnosticSeverity(CXDiagnostic Diag) {
CXStoredDiagnostic *StoredDiag = static_cast<CXStoredDiagnostic *>(Diag);
if (!StoredDiag)
@@ -204,15 +279,18 @@ void clang::LoadSerializedDiagnostics(const llvm::sys::Path &DiagnosticsPath,
Diags.push_back(StoredDiagnostic(Diagnostic::Fatal,
(Twine("could not remap from missing file ") +
unsaved_files[I].Filename).str()));
+ delete F;
return;
}
MemoryBuffer *Buffer
= MemoryBuffer::getMemBuffer(unsaved_files[I].Contents,
unsaved_files[I].Contents + unsaved_files[I].Length);
- if (!Buffer)
+ if (!Buffer) {
+ delete F;
return;
-
+ }
+
SourceMgr.overrideFileContents(File, Buffer);
}
@@ -224,8 +302,9 @@ void clang::LoadSerializedDiagnostics(const llvm::sys::Path &DiagnosticsPath,
StoredDiagnostic Stored = StoredDiagnostic::Deserialize(FileMgr, SourceMgr,
Memory, MemoryEnd);
if (!Stored)
- return;
+ break;
Diags.push_back(Stored);
}
+ delete F;
}
OpenPOWER on IntegriCloud