blob: 04a570559fe06a0670ef8a7e6e94c40aa37e55a9 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- TextDiagnosticPrinter.h - Text Diagnostic Client -------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This is a concrete diagnostic client, which prints the diagnostics to
11// standard error.
12//
13//===----------------------------------------------------------------------===//
14
Stephen Hines176edba2014-12-01 14:53:08 -080015#ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICPRINTER_H
16#define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICPRINTER_H
Reid Spencer5f016e22007-07-11 17:01:13 +000017
Nico Weber7bfaaae2008-08-10 19:59:06 +000018#include "clang/Basic/Diagnostic.h"
Chandler Carruth21a869a2011-10-16 02:57:39 +000019#include "clang/Basic/LLVM.h"
Douglas Gregor02c23eb2012-10-23 22:26:28 +000020#include "llvm/ADT/IntrusiveRefCntPtr.h"
Stephen Hines651f13c2014-04-23 16:59:28 -070021#include <memory>
Chris Lattnera03a5b52008-11-19 06:56:25 +000022
Reid Spencer5f016e22007-07-11 17:01:13 +000023namespace clang {
Daniel Dunbareace8742009-11-04 06:24:30 +000024class DiagnosticOptions;
Chris Lattner2c78b872009-04-14 23:22:57 +000025class LangOptions;
Chandler Carruth21a869a2011-10-16 02:57:39 +000026class TextDiagnostic;
Reid Spencer5f016e22007-07-11 17:01:13 +000027
David Blaikie78ad0b92011-09-25 23:39:51 +000028class TextDiagnosticPrinter : public DiagnosticConsumer {
Chris Lattner8cc488f2011-07-20 07:06:53 +000029 raw_ostream &OS;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +000030 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
Daniel Dunbareace8742009-11-04 06:24:30 +000031
Chandler Carruth21a869a2011-10-16 02:57:39 +000032 /// \brief Handle to the currently active text diagnostic emitter.
Stephen Hines651f13c2014-04-23 16:59:28 -070033 std::unique_ptr<TextDiagnostic> TextDiag;
Chris Lattner2c78b872009-04-14 23:22:57 +000034
Daniel Dunbarb96b6702010-02-25 03:23:40 +000035 /// A string to prefix to error messages.
36 std::string Prefix;
37
Chandler Carruth21a869a2011-10-16 02:57:39 +000038 unsigned OwnsOutputStream : 1;
39
Reid Spencer5f016e22007-07-11 17:01:13 +000040public:
Douglas Gregor02c23eb2012-10-23 22:26:28 +000041 TextDiagnosticPrinter(raw_ostream &os, DiagnosticOptions *diags,
Daniel Dunbaraea36412009-11-11 09:38:24 +000042 bool OwnsOutputStream = false);
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -070043 ~TextDiagnosticPrinter() override;
Reid Spencer5f016e22007-07-11 17:01:13 +000044
Daniel Dunbarb96b6702010-02-25 03:23:40 +000045 /// setPrefix - Set the diagnostic printer prefix string, which will be
46 /// printed at the start of any diagnostics. If empty, no prefix string is
47 /// used.
48 void setPrefix(std::string Value) { Prefix = Value; }
49
Stephen Hines651f13c2014-04-23 16:59:28 -070050 void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override;
51 void EndSourceFile() override;
52 void HandleDiagnostic(DiagnosticsEngine::Level Level,
53 const Diagnostic &Info) override;
Reid Spencer5f016e22007-07-11 17:01:13 +000054};
55
Douglas Gregor6c1cb992010-05-04 17:13:42 +000056} // end namespace clang
Reid Spencer5f016e22007-07-11 17:01:13 +000057
58#endif