Made all LLDB-generated ASTContexts have valid
DiagnosticClients, and removed code that was patching
over the original problem.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@121601 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Symbol/ClangASTContext.cpp b/source/Symbol/ClangASTContext.cpp
index c4cd159..9f73faf 100644
--- a/source/Symbol/ClangASTContext.cpp
+++ b/source/Symbol/ClangASTContext.cpp
@@ -312,6 +312,8 @@
                 *getSelectorTable(),
                 *getBuiltinContext(),
                 0));
+        
+        m_ast_context_ap->getDiagnostics().setClient(getDiagnosticClient(), false);
     }
     return m_ast_context_ap.get();
 }
@@ -382,6 +384,37 @@
     return m_diagnostic_ap.get();
 }
 
+class NullDiagnosticClient : public DiagnosticClient
+{
+public:
+    NullDiagnosticClient ()
+    {
+        m_log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
+    }
+    
+    void HandleDiagnostic (Diagnostic::Level DiagLevel, const DiagnosticInfo &info)
+    {
+        if (m_log)
+        {
+            llvm::SmallVectorImpl<char> diag_str(10);
+            info.FormatDiagnostic(diag_str);
+            diag_str.push_back('\0');
+            m_log->Printf("Compiler diagnostic: %s\n", diag_str.data());
+        }
+    }
+private:
+    LogSP m_log;
+};
+
+DiagnosticClient *
+ClangASTContext::getDiagnosticClient()
+{
+    if (m_diagnostic_client_ap.get() == NULL)
+        m_diagnostic_client_ap.reset(new NullDiagnosticClient);
+    
+    return m_diagnostic_client_ap.get();
+}
+
 TargetOptions *
 ClangASTContext::getTargetOptions()
 {
@@ -720,52 +753,11 @@
     return void_ptr_type.getAsOpaquePtr();
 }
 
-class NullDiagnosticClient : public DiagnosticClient
-{
-public:
-    NullDiagnosticClient ()
-    {
-        m_log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
-    }
-    
-    void HandleDiagnostic (Diagnostic::Level DiagLevel, const DiagnosticInfo &info)
-    {
-        if (m_log)
-        {
-            llvm::SmallVectorImpl<char> diag_str(10);
-            info.FormatDiagnostic(diag_str);
-            diag_str.push_back('\0');
-            m_log->Printf("Compiler diagnostic: %s\n", diag_str.data());
-        }
-    }
-private:
-    LogSP m_log;
-};
-
 clang_type_t
 ClangASTContext::CopyType (ASTContext *dst_ast, 
                            ASTContext *src_ast,
                            clang_type_t clang_type)
 {
-    // we temporarily install diagnostic clients as needed to ensure that
-    // errors are properly handled
-    
-    std::auto_ptr<NullDiagnosticClient> diag_client;
-    
-    bool dst_needs_diag = !dst_ast->getDiagnostics().getClient();
-    bool src_needs_diag = !src_ast->getDiagnostics().getClient();
-    
-    if (dst_needs_diag || src_needs_diag)
-    {
-        diag_client.reset(new NullDiagnosticClient);
-    
-        if (dst_needs_diag)
-            dst_ast->getDiagnostics().setClient(diag_client.get(), false);
-        
-        if (src_needs_diag)
-            src_ast->getDiagnostics().setClient(diag_client.get(), false);
-    }
-        
     FileSystemOptions file_system_options;
     FileManager file_manager (file_system_options);
     ASTImporter importer(*dst_ast, file_manager,
@@ -774,12 +766,6 @@
     QualType src (QualType::getFromOpaquePtr(clang_type));
     QualType dst (importer.Import(src));
     
-    if (dst_needs_diag)
-        dst_ast->getDiagnostics().setClient(NULL, false);
-    
-    if (src_needs_diag)
-        src_ast->getDiagnostics().setClient(NULL, false);
-    
     return dst.getAsOpaquePtr();
 }
 
@@ -788,37 +774,12 @@
 ClangASTContext::CopyDecl (ASTContext *dst_ast, 
                            ASTContext *src_ast,
                            clang::Decl *source_decl)
-{
-    // we temporarily install diagnostic clients as needed to ensure that
-    // errors are properly handled
-    
-    std::auto_ptr<NullDiagnosticClient> diag_client;
-    
-    bool dst_needs_diag = !dst_ast->getDiagnostics().getClient();
-    bool src_needs_diag = !src_ast->getDiagnostics().getClient();
-    
-    if (dst_needs_diag || src_needs_diag)
-    {
-        diag_client.reset(new NullDiagnosticClient);
-        
-        if (dst_needs_diag)
-            dst_ast->getDiagnostics().setClient(diag_client.get(), false);
-        
-        if (src_needs_diag)
-            src_ast->getDiagnostics().setClient(diag_client.get(), false);
-    }
-    
+{    
     FileSystemOptions file_system_options;
     FileManager file_manager (file_system_options);
     ASTImporter importer(*dst_ast, file_manager,
                          *src_ast, file_manager);
     
-    if (dst_needs_diag)
-        dst_ast->getDiagnostics().setClient(NULL, false);
-    
-    if (src_needs_diag)
-        src_ast->getDiagnostics().setClient(NULL, false);
-    
     return importer.Import(source_decl);
 }