9 #ifndef MLIR_TOOLS_PDLL_AST_DIAGNOSTIC_H
10 #define MLIR_TOOLS_PDLL_AST_DIAGNOSTIC_H
17 #include "llvm/ADT/FunctionExtras.h"
18 #include "llvm/Support/SourceMgr.h"
23 class DiagnosticEngine;
44 auto getNotes()
const {
return llvm::make_pointee_range(notes); }
48 std::optional<SMRange> noteLoc = std::nullopt) {
50 "cannot attach a Note to a Note");
52 new Diagnostic(Severity::DK_Note, noteLoc.value_or(location), msg));
62 : severity(severity), message(msg.str()), location(loc) {}
74 std::vector<std::unique_ptr<Diagnostic>> notes;
88 : owner(rhs.owner),
impl(std::move(rhs.
impl)) {
116 : owner(owner),
impl(std::move(rhs)) {}
120 bool isActive()
const {
return impl.has_value(); }
123 bool isInFlight()
const {
return owner; }
126 friend DiagnosticEngine;
129 DiagnosticEngine *owner =
nullptr;
132 std::optional<Diagnostic>
impl;
148 this,
Diagnostic(Diagnostic::Severity::DK_Error, loc, msg));
152 this,
Diagnostic(Diagnostic::Severity::DK_Warning, loc, msg));
166 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->()
This header declares functions that assist transformations in the MemRef dialect.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
This class represents an efficient way to signal success or failure.