]> granicus.if.org Git - clang/blobdiff - include/clang/Frontend/TextDiagnosticPrinter.h
Header guard canonicalization, clang part.
[clang] / include / clang / Frontend / TextDiagnosticPrinter.h
index f8408bdbd742ea580e4cc32c158aab29de50add7..f8a71fe5e0f630defa254309b8add3446588ccfd 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_CLANG_FRONTEND_TEXT_DIAGNOSTIC_PRINTER_H_
-#define LLVM_CLANG_FRONTEND_TEXT_DIAGNOSTIC_PRINTER_H_
+#ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICPRINTER_H
+#define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICPRINTER_H
 
 #include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/SourceLocation.h"
-
-namespace llvm {
-  class raw_ostream;
-}
+#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include <memory>
 
 namespace clang {
-class SourceManager;
+class DiagnosticOptions;
 class LangOptions;
+class TextDiagnostic;
 
-class TextDiagnosticPrinter : public DiagnosticClient {
-  llvm::raw_ostream &OS;
-  const LangOptions *LangOpts;
-  SourceLocation LastWarningLoc;
-  FullSourceLoc LastLoc;
-  bool LastCaretDiagnosticWasNote;
-
-  bool ShowColumn;
-  bool CaretDiagnostics;
-  bool ShowLocation;
-  bool PrintRangeInfo;
-  bool PrintDiagnosticOption;
-  bool PrintFixItInfo;
-  unsigned MessageLength;
-  bool UseColors;
+class TextDiagnosticPrinter : public DiagnosticConsumer {
+  raw_ostream &OS;
+  IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
 
-public:
-  TextDiagnosticPrinter(llvm::raw_ostream &os,
-                        bool showColumn = true,
-                        bool caretDiagnistics = true, bool showLocation = true,
-                        bool printRangeInfo = true,
-                        bool printDiagnosticOption = true,
-                        bool printFixItInfo = true,
-                        unsigned messageLength = 0,
-                        bool useColors = false)
-    : OS(os), LangOpts(0),
-      LastCaretDiagnosticWasNote(false), ShowColumn(showColumn), 
-      CaretDiagnostics(caretDiagnistics), ShowLocation(showLocation),
-      PrintRangeInfo(printRangeInfo),
-      PrintDiagnosticOption(printDiagnosticOption),
-      PrintFixItInfo(printFixItInfo),
-      MessageLength(messageLength),
-      UseColors(useColors) {}
+  /// \brief Handle to the currently active text diagnostic emitter.
+  std::unique_ptr<TextDiagnostic> TextDiag;
 
-  void setLangOptions(const LangOptions *LO) {
-    LangOpts = LO;
-  }
-  
-  void PrintIncludeStack(SourceLocation Loc, const SourceManager &SM);
+  /// A string to prefix to error messages.
+  std::string Prefix;
 
-  void HighlightRange(const SourceRange &R,
-                      const SourceManager &SrcMgr,
-                      unsigned LineNo, FileID FID,
-                      std::string &CaretLine,
-                      const std::string &SourceLine);
+  unsigned OwnsOutputStream : 1;
 
-  void EmitCaretDiagnostic(SourceLocation Loc, 
-                           SourceRange *Ranges, unsigned NumRanges,
-                           SourceManager &SM,
-                           const CodeModificationHint *Hints,
-                           unsigned NumHints,
-                           unsigned Columns);
-  
-  virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
-                                const DiagnosticInfo &Info);
+public:
+  TextDiagnosticPrinter(raw_ostream &os, DiagnosticOptions *diags,
+                        bool OwnsOutputStream = false);
+  virtual ~TextDiagnosticPrinter();
+
+  /// setPrefix - Set the diagnostic printer prefix string, which will be
+  /// printed at the start of any diagnostics. If empty, no prefix string is
+  /// used.
+  void setPrefix(std::string Value) { Prefix = Value; }
+
+  void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override;
+  void EndSourceFile() override;
+  void HandleDiagnostic(DiagnosticsEngine::Level Level,
+                        const Diagnostic &Info) override;
 };
 
-} // end namspace clang
+} // end namespace clang
 
 #endif