Files
swift-mirror/include/swift/Frontend/PrintingDiagnosticConsumer.h
Doug Gregor 7d569b989d [Diagnostics] Remove rendering of educational notes to the terminal
We're moving over to a model where we provide direct links to educational notes /
diagnostic group notes whenever relevant. Rendering the Markdown from these
files to the terminal is less relevant with this approach, so remove it from the
compiler.
2025-03-28 14:12:27 -07:00

92 lines
2.6 KiB
C++

//===--- PrintingDiagnosticConsumer.h - Print Text Diagnostics --*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 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/AST/DiagnosticBridge.h"
#include "swift/AST/DiagnosticConsumer.h"
#include "swift/Basic/DiagnosticOptions.h"
#include "swift/Basic/LLVM.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/raw_ostream.h"
namespace swift {
/// Diagnostic consumer that displays diagnostics to standard error.
class PrintingDiagnosticConsumer : public DiagnosticConsumer {
llvm::raw_ostream &Stream;
bool ForceColors = false;
bool EmitMacroExpansionFiles = false;
bool DidErrorOccur = false;
DiagnosticOptions::FormattingStyle FormattingStyle =
DiagnosticOptions::FormattingStyle::LLVM;
bool SuppressOutput = false;
#if SWIFT_BUILD_SWIFT_SYNTAX
/// swift-syntax rendering
DiagnosticBridge DiagBridge;
#endif
public:
PrintingDiagnosticConsumer(llvm::raw_ostream &stream = llvm::errs());
~PrintingDiagnosticConsumer();
virtual void handleDiagnostic(SourceManager &SM,
const DiagnosticInfo &Info) override;
virtual bool finishProcessing() override;
void flush(bool includeTrailingBreak);
virtual void flush() override { flush(false); }
void forceColors() {
ForceColors = true;
llvm::sys::Process::UseANSIEscapeCodes(true);
}
void setFormattingStyle(DiagnosticOptions::FormattingStyle style) {
FormattingStyle = style;
}
void setEmitMacroExpansionFiles(bool ShouldEmit) {
EmitMacroExpansionFiles = ShouldEmit;
}
bool didErrorOccur() {
return DidErrorOccur;
}
void setSuppressOutput(bool suppressOutput) {
SuppressOutput = suppressOutput;
}
private:
/// Retrieve the SourceFileSyntax for the given buffer.
void *getSourceFileSyntax(SourceManager &SM, unsigned bufferID,
StringRef displayName);
void queueBuffer(SourceManager &sourceMgr, unsigned bufferID);
void printDiagnostic(SourceManager &SM, const DiagnosticInfo &Info);
};
}
#endif