Rework how CIndex handles diagnostics. Rather than using a callback,
we attach diagnostics to translation units and code-completion
results, so they can be queried at any time.
To facilitate this, the new StoredDiagnostic class stores a diagnostic
in a serializable/deserializable form, and ASTUnit knows how to
capture diagnostics in this stored form. CIndex's CXDiagnostic is a
thin wrapper around StoredDiagnostic, providing a C interface to
stored or de-serialized diagnostics.
I've XFAIL'd one test case temporarily, because currently we end up
storing diagnostics in an ASTUnit that's never returned to the user
(because it contains errors). I'll introduce a temporary fix for this
soon; the real fix will be to allow us to return and query invalid ASTs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96592 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndexDiagnostic.h b/tools/CIndex/CIndexDiagnostic.h
index 9f7ae51..79a5df0 100644
--- a/tools/CIndex/CIndexDiagnostic.h
+++ b/tools/CIndex/CIndexDiagnostic.h
@@ -16,6 +16,7 @@
#include "clang-c/Index.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallVector.h"
namespace llvm { namespace sys {
class Path;
@@ -26,40 +27,25 @@
class Diagnostic;
class LangOptions;
class Preprocessor;
-
-/**
- * \brief Diagnostic client that translates Clang diagnostics into diagnostics
- * for the C interface to Clang.
- */
-class CIndexDiagnosticClient : public DiagnosticClient {
- CXDiagnosticCallback Callback;
- CXClientData ClientData;
- const LangOptions *LangOptsPtr;
-
-public:
- CIndexDiagnosticClient(CXDiagnosticCallback Callback,
- CXClientData ClientData)
- : Callback(Callback), ClientData(ClientData), LangOptsPtr(0) { }
-
- virtual ~CIndexDiagnosticClient();
-
- virtual void BeginSourceFile(const LangOptions &LangOpts,
- const Preprocessor *PP);
-
- virtual void EndSourceFile();
- virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
- const DiagnosticInfo &Info);
+/// \brief The storage behind a CXDiagnostic
+struct CXStoredDiagnostic {
+ const StoredDiagnostic &Diag;
+ const LangOptions &LangOpts;
+
+ CXStoredDiagnostic(const StoredDiagnostic &Diag,
+ const LangOptions &LangOpts)
+ : Diag(Diag), LangOpts(LangOpts) { }
};
-
+
/// \brief Given the path to a file that contains binary, serialized
-/// diagnostics produced by Clang, emit those diagnostics via the
-/// given diagnostic engine.
-void ReportSerializedDiagnostics(const llvm::sys::Path &DiagnosticsPath,
- Diagnostic &Diags,
- unsigned num_unsaved_files,
- struct CXUnsavedFile *unsaved_files,
- const LangOptions &LangOpts);
+/// diagnostics produced by Clang, load those diagnostics.
+void LoadSerializedDiagnostics(const llvm::sys::Path &DiagnosticsPath,
+ unsigned num_unsaved_files,
+ struct CXUnsavedFile *unsaved_files,
+ FileManager &FileMgr,
+ SourceManager &SourceMgr,
+ llvm::SmallVectorImpl<StoredDiagnostic> &Diags);
} // end namespace clang