9 #ifndef MLIR_TOOLS_PDLL_AST_DIAGNOSTIC_H
10 #define MLIR_TOOLS_PDLL_AST_DIAGNOSTIC_H
16 #include "llvm/ADT/FunctionExtras.h"
17 #include "llvm/Support/SourceMgr.h"
22 class DiagnosticEngine;
43 auto getNotes()
const {
return llvm::make_pointee_range(notes); }
47 std::optional<SMRange> noteLoc = std::nullopt) {
49 "cannot attach a Note to a Note");
51 new Diagnostic(Severity::DK_Note, noteLoc.value_or(location), msg));
57 operator LogicalResult()
const {
return failure(); }
61 : severity(severity), message(msg.str()), location(loc) {}
73 std::vector<std::unique_ptr<Diagnostic>> notes;
87 : owner(rhs.owner),
impl(std::move(rhs.
impl)) {
109 operator LogicalResult()
const {
return failure(isActive()); }
115 : owner(owner),
impl(std::move(rhs)) {}
119 bool isActive()
const {
return impl.has_value(); }
122 bool isInFlight()
const {
return owner; }
125 friend DiagnosticEngine;
128 DiagnosticEngine *owner =
nullptr;
131 std::optional<Diagnostic>
impl;
147 this,
Diagnostic(Diagnostic::Severity::DK_Error, loc, msg));
151 this,
Diagnostic(Diagnostic::Severity::DK_Warning, loc, msg));
165 HandlerFn oldHandler = std::move(handler);
This class is the main interface for diagnostics.
This class manages the construction and emission of PDLL diagnostics.
InFlightDiagnostic emitWarning(SMRange loc, const Twine &msg)
void setHandlerFn(HandlerFn &&newHandler)
Set the handler function for this diagnostic engine.
InFlightDiagnostic emitError(SMRange loc, const Twine &msg)
Emit an error to the diagnostic engine.
llvm::unique_function< void(Diagnostic &)> HandlerFn
A function used to handle diagnostics emitted by the engine.
void report(Diagnostic &&diagnostic)
Report the given diagnostic.
HandlerFn takeHandlerFn()
Take the current handler function, resetting the current handler to null.
const HandlerFn & getHandlerFn() const
Get the current handler function of this diagnostic engine.
This class provides a simple implementation of a PDLL diagnostic.
llvm::SourceMgr::DiagKind Severity
StringRef getMessage() const
Return the message of this diagnostic.
SMRange getLocation() const
Return the location of this diagnostic.
Severity getSeverity() const
Return the severity of this diagnostic.
Diagnostic & attachNote(const Twine &msg, std::optional< SMRange > noteLoc=std::nullopt)
Attach a note to this diagnostic.
auto getNotes() const
Return the notes of this diagnostic.
This class represents a diagnostic that is inflight and set to be reported.
InFlightDiagnostic(InFlightDiagnostic &&rhs)
void report()
Reports the diagnostic to the engine.
InFlightDiagnostic()=default
Diagnostic & operator*()
Access the internal diagnostic.
void abandon()
Abandons this diagnostic so that it will no longer be reported.
Diagnostic * operator->()
Include the generated interface declarations.