clang API Documentation

TextDiagnosticPrinter.h
Go to the documentation of this file.
00001 //===--- TextDiagnosticPrinter.h - Text Diagnostic Client -------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This is a concrete diagnostic client, which prints the diagnostics to
00011 // standard error.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICPRINTER_H
00016 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICPRINTER_H
00017 
00018 #include "clang/Basic/Diagnostic.h"
00019 #include "clang/Basic/LLVM.h"
00020 #include "llvm/ADT/IntrusiveRefCntPtr.h"
00021 #include <memory>
00022 
00023 namespace clang {
00024 class DiagnosticOptions;
00025 class LangOptions;
00026 class TextDiagnostic;
00027 
00028 class TextDiagnosticPrinter : public DiagnosticConsumer {
00029   raw_ostream &OS;
00030   IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
00031 
00032   /// \brief Handle to the currently active text diagnostic emitter.
00033   std::unique_ptr<TextDiagnostic> TextDiag;
00034 
00035   /// A string to prefix to error messages.
00036   std::string Prefix;
00037 
00038   unsigned OwnsOutputStream : 1;
00039 
00040 public:
00041   TextDiagnosticPrinter(raw_ostream &os, DiagnosticOptions *diags,
00042                         bool OwnsOutputStream = false);
00043   virtual ~TextDiagnosticPrinter();
00044 
00045   /// setPrefix - Set the diagnostic printer prefix string, which will be
00046   /// printed at the start of any diagnostics. If empty, no prefix string is
00047   /// used.
00048   void setPrefix(std::string Value) { Prefix = Value; }
00049 
00050   void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override;
00051   void EndSourceFile() override;
00052   void HandleDiagnostic(DiagnosticsEngine::Level Level,
00053                         const Diagnostic &Info) override;
00054 };
00055 
00056 } // end namespace clang
00057 
00058 #endif