[cfe-commits] r86817 - in /cfe/trunk: include/clang/Frontend/ChainedDiagnosticClient.h tools/clang-cc/clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Wed Nov 11 00:13:24 PST 2009


Author: ddunbar
Date: Wed Nov 11 02:13:24 2009
New Revision: 86817

URL: http://llvm.org/viewvc/llvm-project?rev=86817&view=rev
Log:
Turn LoggingDiagnosticClient into a more general ChainedDiagnosticClient and
move to libFrontend.

Added:
    cfe/trunk/include/clang/Frontend/ChainedDiagnosticClient.h
Modified:
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Added: cfe/trunk/include/clang/Frontend/ChainedDiagnosticClient.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ChainedDiagnosticClient.h?rev=86817&view=auto

==============================================================================
--- cfe/trunk/include/clang/Frontend/ChainedDiagnosticClient.h (added)
+++ cfe/trunk/include/clang/Frontend/ChainedDiagnosticClient.h Wed Nov 11 02:13:24 2009
@@ -0,0 +1,56 @@
+//===--- ChainedDiagnosticClient.h - Chain Diagnostic Clients ---*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCLIENT_H
+#define LLVM_CLANG_FRONTEND_CHAINEDDIAGNOSTICCLIENT_H
+
+#include "clang/Basic/Diagnostic.h"
+
+namespace clang {
+class LangOptions;
+
+/// ChainedDiagnosticClient - Chain two diagnostic clients so that diagnostics
+/// go to the first client and then the second. The first diagnostic client
+/// should be the "primary" client, and will be used for computing whether the
+/// diagnostics should be included in counts.
+class ChainedDiagnosticClient : public DiagnosticClient {
+  llvm::OwningPtr<DiagnosticClient> Primary;
+  llvm::OwningPtr<DiagnosticClient> Secondary;
+
+public:
+  ChainedDiagnosticClient(DiagnosticClient *_Primary,
+                          DiagnosticClient *_Secondary) {
+    Primary.reset(_Primary);
+    Secondary.reset(_Secondary);
+  }
+
+  virtual void BeginSourceFile(const LangOptions &LO) {
+    Primary->BeginSourceFile(LO);
+    Secondary->BeginSourceFile(LO);
+  }
+
+  virtual void EndSourceFile() {
+    Secondary->EndSourceFile();
+    Primary->EndSourceFile();
+  }
+
+  virtual bool IncludeInDiagnosticCounts() const {
+    return Primary->IncludeInDiagnosticCounts();
+  }
+
+  virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
+                                const DiagnosticInfo &Info) {
+    Primary->HandleDiagnostic(DiagLevel, Info);
+    Secondary->HandleDiagnostic(DiagLevel, Info);
+  }
+};
+
+} // end namspace clang
+
+#endif

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=86817&r1=86816&r2=86817&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Nov 11 02:13:24 2009
@@ -19,6 +19,7 @@
 #include "clang/Frontend/AnalysisConsumer.h"
 #include "clang/Frontend/ASTConsumers.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/ChainedDiagnosticClient.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/DiagnosticOptions.h"
 #include "clang/Frontend/FixItRewriter.h"
@@ -811,48 +812,9 @@
 
 static llvm::raw_ostream *BuildLogFile = 0;
 
-/// LoggingDiagnosticClient - This is a simple diagnostic client that forwards
-/// all diagnostics to both BuildLogFile and a chained DiagnosticClient.
-namespace {
-class LoggingDiagnosticClient : public DiagnosticClient {
-  llvm::OwningPtr<DiagnosticClient> Chain1;
-  llvm::OwningPtr<DiagnosticClient> Chain2;
-public:
-
-  LoggingDiagnosticClient(const DiagnosticOptions &DiagOpts,
-                          DiagnosticClient *Normal) {
-    // Output diags both where requested...
-    Chain1.reset(Normal);
-    // .. and to our log file.
-    Chain2.reset(new TextDiagnosticPrinter(*BuildLogFile, DiagOpts));
-  }
-
-  virtual void BeginSourceFile(const LangOptions &LO) {
-    Chain1->BeginSourceFile(LO);
-    Chain2->BeginSourceFile(LO);
-  }
-
-  virtual void EndSourceFile() {
-    Chain1->EndSourceFile();
-    Chain2->EndSourceFile();
-  }
-
-  virtual bool IncludeInDiagnosticCounts() const {
-    return Chain1->IncludeInDiagnosticCounts();
-  }
-
-  virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
-                                const DiagnosticInfo &Info) {
-    Chain1->HandleDiagnostic(DiagLevel, Info);
-    Chain2->HandleDiagnostic(DiagLevel, Info);
-  }
-};
-} // end anonymous namespace.
-
 static void SetUpBuildDumpLog(const DiagnosticOptions &DiagOpts,
                               unsigned argc, char **argv,
                               llvm::OwningPtr<DiagnosticClient> &DiagClient) {
-
   std::string ErrorInfo;
   BuildLogFile = new llvm::raw_fd_ostream(DumpBuildInformation.c_str(),
                                           ErrorInfo);
@@ -871,9 +833,9 @@
     (*BuildLogFile) << argv[i] << ' ';
   (*BuildLogFile) << '\n';
 
-  // LoggingDiagnosticClient - Insert a new logging diagnostic client in between
-  // the diagnostic producers and the normal receiver.
-  DiagClient.reset(new LoggingDiagnosticClient(DiagOpts, DiagClient.take()));
+  // Chain in a diagnostic client which will log the diagnostics.
+  DiagnosticClient *Logger = new TextDiagnosticPrinter(*BuildLogFile, DiagOpts);
+  DiagClient.reset(new ChainedDiagnosticClient(DiagClient.take(), Logger));
 }
 
 





More information about the cfe-commits mailing list