Files
swift-mirror/include/swift/Frontend/PrintingDiagnosticConsumer.h
Owen Voorhees 8a6711769e [Diagnostics] Refactor DiagnosticConsumer interface
DiagnosticInfo now holds all the information needed to consume
a diagnostic, so remove unneeded parameters from handleDiagnostic.
2019-10-29 13:52:12 -07:00

57 lines
1.6 KiB
C++

//===--- PrintingDiagnosticConsumer.h - Print Text Diagnostics --*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines the PrintingDiagnosticConsumer class, which displays
// diagnostics as text to a terminal.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_PRINTINGDIAGNOSTICCONSUMER_H
#define SWIFT_PRINTINGDIAGNOSTICCONSUMER_H
#include "swift/Basic/LLVM.h"
#include "swift/AST/DiagnosticConsumer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Process.h"
namespace swift {
/// Diagnostic consumer that displays diagnostics to standard error.
class PrintingDiagnosticConsumer : public DiagnosticConsumer {
llvm::raw_ostream &Stream;
bool ForceColors = false;
bool DidErrorOccur = false;
public:
PrintingDiagnosticConsumer(llvm::raw_ostream &stream = llvm::errs()) :
Stream(stream) { }
virtual void handleDiagnostic(SourceManager &SM,
const DiagnosticInfo &Info) override;
void forceColors() {
ForceColors = true;
llvm::sys::Process::UseANSIEscapeCodes(true);
}
bool didErrorOccur() {
return DidErrorOccur;
}
private:
void printDiagnostic(SourceManager &SM, const DiagnosticInfo &Info);
};
}
#endif