]> granicus.if.org Git - clang/blobdiff - include/clang/Frontend/TextDiagnosticPrinter.h
Header guard canonicalization, clang part.
[clang] / include / clang / Frontend / TextDiagnosticPrinter.h
index 9341b89f56ab9d164974926979a777cfca780f36..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;
+class TextDiagnosticPrinter : public DiagnosticConsumer {
+  raw_ostream &OS;
+  IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
 
-  bool ShowColumn;
-  bool CaretDiagnostics;
-  bool ShowLocation;
-  bool PrintRangeInfo;
-  bool PrintDiagnosticOption;
-public:
-  TextDiagnosticPrinter(llvm::raw_ostream &os,
-                        bool showColumn = true,
-                        bool caretDiagnistics = true, bool showLocation = true,
-                        bool printRangeInfo = true,
-                        bool printDiagnosticOption = true)
-    : OS(os), LangOpts(0),
-      LastCaretDiagnosticWasNote(false), ShowColumn(showColumn), 
-      CaretDiagnostics(caretDiagnistics), ShowLocation(showLocation),
-      PrintRangeInfo(printRangeInfo),
-      PrintDiagnosticOption(printDiagnosticOption) {}
+  /// \brief Handle to the currently active text diagnostic emitter.
+  std::unique_ptr<TextDiagnostic> TextDiag;
 
-  void SetLangOpts(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 = 0,
-                           unsigned NumHints = 0);
-  
-  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