]> granicus.if.org Git - clang/blob - include/clang/Frontend/TextDiagnosticPrinter.h
Fix an assertion hit when the serialized diagnostics writer receive a diagnostic
[clang] / include / clang / Frontend / TextDiagnosticPrinter.h
1 //===--- TextDiagnosticPrinter.h - Text Diagnostic Client -------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This is a concrete diagnostic client, which prints the diagnostics to
11 // standard error.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_FRONTEND_TEXT_DIAGNOSTIC_PRINTER_H_
16 #define LLVM_CLANG_FRONTEND_TEXT_DIAGNOSTIC_PRINTER_H_
17
18 #include "clang/Basic/Diagnostic.h"
19 #include "clang/Basic/LLVM.h"
20 #include "llvm/ADT/OwningPtr.h"
21
22 namespace clang {
23 class DiagnosticOptions;
24 class LangOptions;
25 class TextDiagnostic;
26
27 class TextDiagnosticPrinter : public DiagnosticConsumer {
28   raw_ostream &OS;
29   const DiagnosticOptions *DiagOpts;
30
31   /// \brief Handle to the currently active text diagnostic emitter.
32   OwningPtr<TextDiagnostic> TextDiag;
33
34   /// A string to prefix to error messages.
35   std::string Prefix;
36
37   unsigned OwnsOutputStream : 1;
38
39 public:
40   TextDiagnosticPrinter(raw_ostream &os, const DiagnosticOptions &diags,
41                         bool OwnsOutputStream = false);
42   virtual ~TextDiagnosticPrinter();
43
44   /// setPrefix - Set the diagnostic printer prefix string, which will be
45   /// printed at the start of any diagnostics. If empty, no prefix string is
46   /// used.
47   void setPrefix(std::string Value) { Prefix = Value; }
48
49   void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP);
50   void EndSourceFile();
51   void HandleDiagnostic(DiagnosticsEngine::Level Level, const Diagnostic &Info);
52   DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const;
53 };
54
55 } // end namespace clang
56
57 #endif