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/include/clang-c/Index.h b/include/clang-c/Index.h
index 0c67104..99c129b 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -416,17 +416,27 @@
 typedef void *CXDiagnostic;
 
 /**
- * \brief Callback function invoked for each diagnostic emitted during
- * translation.
- *
- * \param Diagnostic the diagnostic emitted during translation. This
- * diagnostic pointer is only valid during the execution of the
- * callback.
- *
- * \param ClientData the callback client data.
+ * \brief Determine the number of diagnostics produced for the given
+ * translation unit.
  */
-typedef void (*CXDiagnosticCallback)(CXDiagnostic Diagnostic,
-                                     CXClientData ClientData);
+CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
+
+/**
+ * \brief Retrieve a diagnostic associated with the given translation unit.
+ *
+ * \param Unit the translation unit to query.
+ * \param Index the zero-based diagnostic number to retrieve.
+ *
+ * \returns the requested diagnostic. This diagnostic must be freed
+ * via a call to \c clang_disposeDiagnostic().
+ */
+CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
+                                                unsigned Index);
+
+/**
+ * \brief Destroy a diagnostic.
+ */
+CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
 
 /**
  * \brief Determine the severity of the given diagnostic.
@@ -600,17 +610,13 @@
                                          int num_clang_command_line_args,
                                          const char **clang_command_line_args,
                                          unsigned num_unsaved_files,
-                                         struct CXUnsavedFile *unsaved_files,
-                                         CXDiagnosticCallback diag_callback,
-                                         CXClientData diag_client_data);
+                                         struct CXUnsavedFile *unsaved_files);
  
 /**
  * \brief Create a translation unit from an AST file (-emit-ast).
  */
 CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex, 
-                                             const char *ast_filename,
-                                             CXDiagnosticCallback diag_callback,
-                                             CXClientData diag_client_data);
+                                             const char *ast_filename);
 
 /**
  * \brief Destroy the specified CXTranslationUnit object.
@@ -1625,9 +1631,7 @@
                                           struct CXUnsavedFile *unsaved_files,
                                           const char *complete_filename,
                                           unsigned complete_line,
-                                          unsigned complete_column,
-                                          CXDiagnosticCallback diag_callback,
-                                          CXClientData diag_client_data);
+                                          unsigned complete_column);
 
 /**
  * \brief Free the given set of code-completion results.
@@ -1636,6 +1640,26 @@
 void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
 
 /**
+ * \brief Determine the number of diagnostics produced prior to the
+ * location where code completion was performed.
+ */
+CINDEX_LINKAGE 
+unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
+
+/**
+ * \brief Retrieve a diagnostic associated with the given code completion.
+ *
+ * \param Result the code completion results to query.
+ * \param Index the zero-based diagnostic number to retrieve.
+ *
+ * \returns the requested diagnostic. This diagnostic must be freed
+ * via a call to \c clang_disposeDiagnostic().
+ */
+CINDEX_LINKAGE 
+CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
+                                             unsigned Index);
+
+/**
  * @}
  */