1//===--- TextDiagnosticPrinter.h - Text Diagnostic Client -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This is a concrete diagnostic client, which prints the diagnostics to
10// standard error.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICPRINTER_H
15#define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICPRINTER_H
16
17#include "clang/Basic/Diagnostic.h"
18#include "clang/Basic/LLVM.h"
19#include "llvm/ADT/IntrusiveRefCntPtr.h"
20#include <memory>
21
22namespace clang {
23class DiagnosticOptions;
24class LangOptions;
25class TextDiagnostic;
26
27class TextDiagnosticPrinter : public DiagnosticConsumer {
28 raw_ostream &OS;
29 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
30
31 /// Handle to the currently active text diagnostic emitter.
32 std::unique_ptr<TextDiagnostic> TextDiag;
33
34 /// A string to prefix to error messages.
35 std::string Prefix;
36
37 LLVM_PREFERRED_TYPE(bool)
38 unsigned OwnsOutputStream : 1;
39
40public:
41 TextDiagnosticPrinter(raw_ostream &os, DiagnosticOptions *diags,
42 bool OwnsOutputStream = false);
43 ~TextDiagnosticPrinter() override;
44
45 /// 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 = std::move(Value); }
49
50 void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override;
51 void EndSourceFile() override;
52 void HandleDiagnostic(DiagnosticsEngine::Level Level,
53 const Diagnostic &Info) override;
54};
55
56} // end namespace clang
57
58#endif
59

source code of clang/include/clang/Frontend/TextDiagnosticPrinter.h