blob: 754ebf323d4cb9cd5d80764b9f2da872ef3e3b7d [file] [log] [blame]
//===--- TextDiagnosticPrinter.h - Text Diagnostic Client -------*- C++ -*-===//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// This is a concrete diagnostic client. In terminals that support it, the
// diagnostics are pretty-printed (colors + bold). The printing/flushing
// happens in HandleDiagnostics (usually called at the point when the
// diagnostic is generated).
#include "clang/Basic/Diagnostic.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/Support/raw_ostream.h"
namespace clang {
class DiagnosticOptions;
class DiagnosticsEngine;
} // namespace clang
using llvm::IntrusiveRefCntPtr;
using llvm::raw_ostream;
namespace Fortran::frontend {
class TextDiagnostic;
class TextDiagnosticPrinter : public clang::DiagnosticConsumer {
raw_ostream &os_;
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagOpts_;
/// A string to prefix to error messages.
std::string prefix_;
TextDiagnosticPrinter(raw_ostream &os, clang::DiagnosticOptions *diags);
~TextDiagnosticPrinter() override;
/// Set the diagnostic printer prefix string, which will be printed at the
/// start of any diagnostics. If empty, no prefix string is used.
void set_prefix(std::string value) { prefix_ = std::move(value); }
void HandleDiagnostic(clang::DiagnosticsEngine::Level level,
const clang::Diagnostic &info) override;
} // namespace Fortran::frontend