]> granicus.if.org Git - clang/blob - include/clang/Frontend/TextDiagnosticPrinter.h
Eliminate extra vertical space in Clang diagnostics
[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 llvm {
22   class raw_ostream;
23 }
24
25 namespace clang {
26 class SourceManager;
27 class LangOptions;
28
29 class TextDiagnosticPrinter : public DiagnosticClient {
30   llvm::raw_ostream &OS;
31   const LangOptions *LangOpts;
32   SourceLocation LastWarningLoc;
33   FullSourceLoc LastLoc;
34   bool LastCaretDiagnosticWasNote;
35
36   bool ShowColumn;
37   bool CaretDiagnostics;
38   bool ShowLocation;
39   bool PrintRangeInfo;
40   bool PrintDiagnosticOption;
41   bool PrintFixItInfo;
42   unsigned MessageLength;
43
44 public:
45   TextDiagnosticPrinter(llvm::raw_ostream &os,
46                         bool showColumn = true,
47                         bool caretDiagnistics = true, bool showLocation = true,
48                         bool printRangeInfo = true,
49                         bool printDiagnosticOption = true,
50                         bool printFixItInfo = true,
51                         unsigned messageLength = 0)
52     : OS(os), LangOpts(0),
53       LastCaretDiagnosticWasNote(false), ShowColumn(showColumn), 
54       CaretDiagnostics(caretDiagnistics), ShowLocation(showLocation),
55       PrintRangeInfo(printRangeInfo),
56       PrintDiagnosticOption(printDiagnosticOption),
57       PrintFixItInfo(printFixItInfo),
58       MessageLength(messageLength) {}
59
60   void setLangOptions(const LangOptions *LO) {
61     LangOpts = LO;
62   }
63   
64   void PrintIncludeStack(SourceLocation Loc, const SourceManager &SM);
65
66   void HighlightRange(const SourceRange &R,
67                       const SourceManager &SrcMgr,
68                       unsigned LineNo, FileID FID,
69                       std::string &CaretLine,
70                       const std::string &SourceLine);
71
72   void EmitCaretDiagnostic(SourceLocation Loc, 
73                            SourceRange *Ranges, unsigned NumRanges,
74                            SourceManager &SM,
75                            const CodeModificationHint *Hints,
76                            unsigned NumHints,
77                            unsigned Columns);
78   
79   virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
80                                 const DiagnosticInfo &Info);
81 };
82
83 } // end namspace clang
84
85 #endif