MLIR 22.0.0git
mlir::SourceMgrDiagnosticHandler Class Reference

This class is a utility diagnostic handler for use with llvm::SourceMgr. More...

#include "mlir/IR/Diagnostics.h"

Inheritance diagram for mlir::SourceMgrDiagnosticHandler:

Public Types

using ShouldShowLocFn = llvm::unique_function<bool(Location)>
 This type represents a functor used to filter out locations when printing a diagnostic.

Public Member Functions

 SourceMgrDiagnosticHandler (llvm::SourceMgr &mgr, MLIRContext *ctx, raw_ostream &os, ShouldShowLocFn &&shouldShowLocFn={})
 SourceMgrDiagnosticHandler (llvm::SourceMgr &mgr, MLIRContext *ctx, ShouldShowLocFn &&shouldShowLocFn={})
 ~SourceMgrDiagnosticHandler ()
void emitDiagnostic (Location loc, Twine message, DiagnosticSeverity kind, bool displaySourceLine=true)
 Emit the given diagnostic information with the held source manager.
void setCallStackLimit (unsigned limit)
 Set the maximum depth that a call stack will be printed. Defaults to 10.
Public Member Functions inherited from mlir::ScopedDiagnosticHandler
 ScopedDiagnosticHandler (MLIRContext *ctx)
template<typename FuncTy>
 ScopedDiagnosticHandler (MLIRContext *ctx, FuncTy &&handler)
 ~ScopedDiagnosticHandler ()

Protected Member Functions

void emitDiagnostic (Diagnostic &diag)
 Emit the given diagnostic with the held source manager.
const llvm::MemoryBuffer * getBufferForFile (StringRef filename)
 Get a memory buffer for the given file, or nullptr if no file is available.
Protected Member Functions inherited from mlir::ScopedDiagnosticHandler
template<typename FuncTy>
void setHandler (FuncTy &&handler)
 Set the handler to manage via RAII.

Protected Attributes

llvm::SourceMgr & mgr
 The source manager that we are wrapping.
raw_ostreamos
 The output stream to use when printing diagnostics.
ShouldShowLocFn shouldShowLocFn
 A functor used when determining if a location for a diagnostic should be shown.

Detailed Description

This class is a utility diagnostic handler for use with llvm::SourceMgr.

Definition at line 561 of file Diagnostics.h.

Member Typedef Documentation

◆ ShouldShowLocFn

This type represents a functor used to filter out locations when printing a diagnostic.

It should return true if the provided location is okay to display, false otherwise. If all locations in a diagnostic are filtered out, the first location is used as the sole location. When deciding whether or not to filter a location, this function should not recurse into any nested location. This recursion is handled automatically by the caller.

Definition at line 570 of file Diagnostics.h.

Constructor & Destructor Documentation

◆ SourceMgrDiagnosticHandler() [1/2]

SourceMgrDiagnosticHandler::SourceMgrDiagnosticHandler ( llvm::SourceMgr & mgr,
MLIRContext * ctx,
raw_ostream & os,
ShouldShowLocFn && shouldShowLocFn = {} )

◆ SourceMgrDiagnosticHandler() [2/2]

SourceMgrDiagnosticHandler::SourceMgrDiagnosticHandler ( llvm::SourceMgr & mgr,
MLIRContext * ctx,
ShouldShowLocFn && shouldShowLocFn = {} )

Definition at line 438 of file Diagnostics.cpp.

References mgr, shouldShowLocFn, and SourceMgrDiagnosticHandler().

◆ ~SourceMgrDiagnosticHandler()

SourceMgrDiagnosticHandler::~SourceMgrDiagnosticHandler ( )
default

References diag().

Member Function Documentation

◆ emitDiagnostic() [1/2]

void SourceMgrDiagnosticHandler::emitDiagnostic ( Diagnostic & diag)
protected

Emit the given diagnostic with the held source manager.

Definition at line 481 of file Diagnostics.cpp.

References diag(), emitDiagnostic(), getCallSiteLoc(), and mlir::Note.

◆ emitDiagnostic() [2/2]

void SourceMgrDiagnosticHandler::emitDiagnostic ( Location loc,
Twine message,
DiagnosticSeverity kind,
bool displaySourceLine = true )

Emit the given diagnostic information with the held source manager.

Definition at line 445 of file Diagnostics.cpp.

References diag(), mlir::LocationAttr::findInstanceOf(), getDiagKind(), mgr, and os.

Referenced by emitDiagnostic(), and SourceMgrDiagnosticHandler().

◆ getBufferForFile()

const llvm::MemoryBuffer * SourceMgrDiagnosticHandler::getBufferForFile ( StringRef filename)
protected

Get a memory buffer for the given file, or nullptr if no file is available.

Get a memory buffer for the given file, or nullptr if one is not found.

Definition at line 532 of file Diagnostics.cpp.

References mgr.

◆ setCallStackLimit()

void SourceMgrDiagnosticHandler::setCallStackLimit ( unsigned limit)

Set the maximum depth that a call stack will be printed. Defaults to 10.

Definition at line 526 of file Diagnostics.cpp.

Member Data Documentation

◆ mgr

llvm::SourceMgr& mlir::SourceMgrDiagnosticHandler::mgr
protected

◆ os

raw_ostream& mlir::SourceMgrDiagnosticHandler::os
protected

The output stream to use when printing diagnostics.

Definition at line 598 of file Diagnostics.h.

Referenced by emitDiagnostic(), SourceMgrDiagnosticHandler(), and mlir::SourceMgrDiagnosticVerifierHandler::verify().

◆ shouldShowLocFn

ShouldShowLocFn mlir::SourceMgrDiagnosticHandler::shouldShowLocFn
protected

A functor used when determining if a location for a diagnostic should be shown.

If null, all locations should be shown.

Definition at line 602 of file Diagnostics.h.

Referenced by SourceMgrDiagnosticHandler(), and SourceMgrDiagnosticHandler().


The documentation for this class was generated from the following files: