The constructor for ASTUnit now takes a DiagnosticClient*, allowing uses of ASTUnit to specify
alternate DiagnosticClients. To match this API, ASTUnit::LoadFromPCHFile() now takes a corresponding
DiagnosticClient* argument as well. The DiagnosticClient object is destroyed when the ASTUnit object
is destroyed.

The CIndex library now uses this API to create a 'IgnoreDiagnosticsClient' that simply silences
diagnostics when using the clang_createTranslationUnitFromSourceFile() function. This fixes
<rdar://problem/7312058>. This API can change in the future as we add more flexibility for clients.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84539 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index 9bc3c70..3f3fc8c 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -23,9 +23,11 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "llvm/Config/config.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/System/Path.h"
 #include "llvm/System/Program.h"
+
 #include <cstdio>
 #include <vector>
 
@@ -40,7 +42,6 @@
 using namespace idx;
 
 namespace {
-
 static enum CXCursorKind TranslateDeclRefExpr(DeclRefExpr *DRE) 
 {
   NamedDecl *D = DRE->getDecl();
@@ -89,6 +90,14 @@
   }
 };
 #endif
+  
+/// IgnoreDiagnosticsClient - A DiagnosticsClient that just ignores emitted
+/// warnings and errors.
+class VISIBILITY_HIDDEN IgnoreDiagnosticsClient : public DiagnosticClient {
+public:
+  virtual ~IgnoreDiagnosticsClient() {}
+  virtual void HandleDiagnostic(Diagnostic::Level, const DiagnosticInfo &) {}  
+};
 
 // Translation Unit Visitor.
 class TUVisitor : public DeclVisitor<TUVisitor> {
@@ -349,6 +358,7 @@
   std::string ErrMsg;
   
   return ASTUnit::LoadFromPCHFile(astName, &ErrMsg,
+                                  new IgnoreDiagnosticsClient(),
                                   CXXIdx->getOnlyLocalDecls(),
                                   /* UseBumpAllocator = */ true);
 }