MLIR  16.0.0git
Classes | Functions
MLIRServer.cpp File Reference
#include "MLIRServer.h"
#include "../lsp-server-support/Logging.h"
#include "../lsp-server-support/Protocol.h"
#include "../lsp-server-support/SourceMgrUtils.h"
#include "mlir/AsmParser/AsmParser.h"
#include "mlir/AsmParser/AsmParserState.h"
#include "mlir/AsmParser/CodeComplete.h"
#include "mlir/IR/FunctionInterfaces.h"
#include "mlir/IR/Operation.h"
#include "llvm/Support/SourceMgr.h"
+ Include dependency graph for MLIRServer.cpp:

Go to the source code of this file.

Classes

struct  mlir::lsp::MLIRServer::Impl
 

Functions

static Optional< lsp::LocationgetLocationFromLoc (FileLineColLoc loc)
 Returns a language server location from the given MLIR file location. More...
 
static Optional< lsp::LocationgetLocationFromLoc (llvm::SourceMgr &sourceMgr, Location loc, const lsp::URIForFile *uri=nullptr)
 Returns a language server location from the given MLIR location, or None if one couldn't be created. More...
 
static void collectLocationsFromLoc (Location loc, std::vector< lsp::Location > &locations, const lsp::URIForFile &uri)
 Collect all of the locations from the given MLIR location that are not contained within the given URI. More...
 
static bool contains (SMRange range, SMLoc loc)
 Returns true if the given range contains the given source location. More...
 
static bool isDefOrUse (const AsmParserState::SMDefinition &def, SMLoc loc, SMRange *overlappedRange=nullptr)
 Returns true if the given location is contained by the definition or one of the uses of the given SMDefinition. More...
 
static Optional< unsignedgetResultNumberFromLoc (SMLoc loc)
 Given a location pointing to a result, return the result number it refers to or None if it refers to all of the results. More...
 
static Optional< StringRef > getTextFromRange (SMRange range)
 Given a source location range, return the text covered by the given range. More...
 
static unsigned getBlockNumber (Block *block)
 Given a block, return its position in its parent region. More...
 
static void printDefBlockName (raw_ostream &os, Block *block, SMRange loc={})
 Given a block and source location, print the source name of the block to the given output stream. More...
 
static void printDefBlockName (raw_ostream &os, const AsmParserState::BlockDefinition &def)
 
static lsp::Diagnostic getLspDiagnoticFromDiag (llvm::SourceMgr &sourceMgr, Diagnostic &diag, const lsp::URIForFile &uri)
 Convert the given MLIR diagnostic to the LSP form. More...
 

Function Documentation

◆ collectLocationsFromLoc()

static void collectLocationsFromLoc ( Location  loc,
std::vector< lsp::Location > &  locations,
const lsp::URIForFile uri 
)
static

Collect all of the locations from the given MLIR location that are not contained within the given URI.

Definition at line 74 of file MLIRServer.cpp.

References mlir::WalkResult::advance(), mlir::Location::dyn_cast(), getLocationFromLoc(), and mlir::LocationAttr::walk().

Referenced by getLspDiagnoticFromDiag().

◆ contains()

static bool contains ( SMRange  range,
SMLoc  loc 
)
static

Returns true if the given range contains the given source location.

Note that this has slightly different behavior than SMRange because it is inclusive of the end location.

Definition at line 93 of file MLIRServer.cpp.

Referenced by mlir::tblgen::SymbolInfoMap::end(), findDuplicateElement(), getLspDiagnoticFromDiag(), isDefOrUse(), and lexLocStringTok().

◆ getBlockNumber()

static unsigned getBlockNumber ( Block block)
static

Given a block, return its position in its parent region.

Definition at line 158 of file MLIRServer.cpp.

References mlir::Region::begin(), and mlir::Block::getParent().

Referenced by getLspDiagnoticFromDiag(), and printDefBlockName().

◆ getLocationFromLoc() [1/2]

static Optional<lsp::Location> getLocationFromLoc ( FileLineColLoc  loc)
static

Returns a language server location from the given MLIR file location.

Definition at line 23 of file MLIRServer.cpp.

References mlir::lsp::Position::character, mlir::lsp::Logger::error(), mlir::lsp::URIForFile::fromFile(), mlir::lsp::Position::line, and mlir::toString().

Referenced by collectLocationsFromLoc(), getLocationFromLoc(), and getLspDiagnoticFromDiag().

◆ getLocationFromLoc() [2/2]

static Optional<lsp::Location> getLocationFromLoc ( llvm::SourceMgr &  sourceMgr,
Location  loc,
const lsp::URIForFile uri = nullptr 
)
static

Returns a language server location from the given MLIR location, or None if one couldn't be created.

uri is an optional additional filter that, when present, is used to filter sub locations that do not share the same uri.

Definition at line 43 of file MLIRServer.cpp.

References mlir::WalkResult::advance(), mlir::lsp::convertTokenLocToRange(), mlir::Location::dyn_cast(), getLocationFromLoc(), mlir::WalkResult::interrupt(), max(), and mlir::LocationAttr::walk().

◆ getLspDiagnoticFromDiag()

static lsp::Diagnostic getLspDiagnoticFromDiag ( llvm::SourceMgr &  sourceMgr,
Diagnostic diag,
const lsp::URIForFile uri 
)
static

Convert the given MLIR diagnostic to the LSP form.

Definition at line 181 of file MLIRServer.cpp.

References mlir::AsmParserState::BlockDefinition::block, mlir::lsp::Diagnostic::category, mlir::lsp::Class, collectLocationsFromLoc(), mlir::AsmParserCodeCompleteContext::completeDialectName(), contains(), mlir::lsp::Hover::contents, mlir::lsp::CompletionItem::detail, diag(), mlir::detail::enumerate(), mlir::lsp::Logger::error(), mlir::Error, mlir::lsp::Error, mlir::failed(), mlir::lsp::Field, mlir::lsp::URIForFile::file(), mlir::lsp::Function, mlir::BlockArgument::getArgNumber(), mlir::Block::getArgument(), mlir::lsp::Position::getAsSMLoc(), mlir::MLIRContext::getAvailableDialects(), getBlockNumber(), mlir::Operation::getDialect(), mlir::Diagnostic::getLocation(), getLocationFromLoc(), mlir::Operation::getName(), mlir::Diagnostic::getNotes(), mlir::Operation::getNumRegions(), mlir::MLIRContext::getOrLoadDialect(), mlir::Block::getParentOp(), mlir::Block::getPredecessors(), mlir::Operation::getRegions(), mlir::MLIRContext::getRegisteredOperations(), mlir::Operation::getResult(), getResultNumberFromLoc(), mlir::Operation::getResults(), mlir::Diagnostic::getSeverity(), mlir::OperationName::getStringRef(), mlir::Block::getSuccessors(), mlir::Value::getType(), mlir::ResultRange::getType(), mlir::Block::hasNoPredecessors(), mlir::Block::hasNoSuccessors(), mlir::Operation::hasTrait(), mlir::lsp::Information, mlir::lsp::CompletionItem::insertText, isDefOrUse(), mlir::lsp::CompletionList::items, mlir::lsp::Keyword, mlir::lsp::Diagnostic::message, mlir::lsp::Module, mlir::lsp::Namespace, mlir::Note, mlir::AsmParserState::OperationDefinition::op, mlir::parseAsmSourceFile(), mlir::Operation::print(), printDefBlockName(), mlir::lsp::Diagnostic::range, mlir::lsp::Diagnostic::relatedInformation, mlir::Remark, mlir::lsp::Diagnostic::severity, mlir::lsp::Diagnostic::source, mlir::Diagnostic::str(), mlir::lsp::Location::uri, mlir::lsp::MarkupContent::value, mlir::lsp::Variable, mlir::Warning, and mlir::lsp::Warning.

◆ getResultNumberFromLoc()

static Optional<unsigned> getResultNumberFromLoc ( SMLoc  loc)
static

Given a location pointing to a result, return the result number it refers to or None if it refers to all of the results.

Definition at line 123 of file MLIRServer.cpp.

Referenced by getLspDiagnoticFromDiag().

◆ getTextFromRange()

static Optional<StringRef> getTextFromRange ( SMRange  range)
static

Given a source location range, return the text covered by the given range.

If the range is invalid, returns None.

Definition at line 150 of file MLIRServer.cpp.

References None.

Referenced by printDefBlockName().

◆ isDefOrUse()

static bool isDefOrUse ( const AsmParserState::SMDefinition def,
SMLoc  loc,
SMRange *  overlappedRange = nullptr 
)
static

Returns true if the given location is contained by the definition or one of the uses of the given SMDefinition.

If provided, overlappedRange is set to the range within def that the provided loc overlapped with.

Definition at line 101 of file MLIRServer.cpp.

References contains(), mlir::AsmParserState::SMDefinition::loc, and mlir::AsmParserState::SMDefinition::uses.

Referenced by getLspDiagnoticFromDiag().

◆ printDefBlockName() [1/2]

static void printDefBlockName ( raw_ostream &  os,
Block block,
SMRange  loc = {} 
)
static

Given a block and source location, print the source name of the block to the given output stream.

Definition at line 164 of file MLIRServer.cpp.

References getBlockNumber(), and getTextFromRange().

Referenced by getLspDiagnoticFromDiag(), and printDefBlockName().

◆ printDefBlockName() [2/2]

static void printDefBlockName ( raw_ostream &  os,
const AsmParserState::BlockDefinition def 
)
static