]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/TextDiagnosticPrinter.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / tools / 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/SourceLocation.h"
20
21 namespace clang {
22 class DiagnosticOptions;
23 class LangOptions;
24
25 class TextDiagnosticPrinter : public DiagnosticConsumer {
26   raw_ostream &OS;
27   const LangOptions *LangOpts;
28   const DiagnosticOptions *DiagOpts;
29
30   SourceLocation LastWarningLoc;
31   FullSourceLoc LastLoc;
32   unsigned LastCaretDiagnosticWasNote : 1;
33   unsigned OwnsOutputStream : 1;
34
35   /// A string to prefix to error messages.
36   std::string Prefix;
37
38 public:
39   TextDiagnosticPrinter(raw_ostream &os, const DiagnosticOptions &diags,
40                         bool OwnsOutputStream = false);
41   virtual ~TextDiagnosticPrinter();
42
43   /// setPrefix - Set the diagnostic printer prefix string, which will be
44   /// printed at the start of any diagnostics. If empty, no prefix string is
45   /// used.
46   void setPrefix(std::string Value) { Prefix = Value; }
47
48   void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) {
49     LangOpts = &LO;
50   }
51
52   void EndSourceFile() {
53     LangOpts = 0;
54   }
55
56   void PrintIncludeStack(DiagnosticsEngine::Level Level, SourceLocation Loc,
57                          const SourceManager &SM);
58
59   virtual void HandleDiagnostic(DiagnosticsEngine::Level Level,
60                                 const Diagnostic &Info);
61
62   DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const;
63
64 private:
65   void EmitDiagnosticLoc(DiagnosticsEngine::Level Level,
66                          const Diagnostic &Info,
67                          const SourceManager &SM,
68                          PresumedLoc PLoc);
69 };
70
71 } // end namespace clang
72
73 #endif