本文整理汇总了C++中llvm::SMDiagnostic::getSourceMgr方法的典型用法代码示例。如果您正苦于以下问题:C++ SMDiagnostic::getSourceMgr方法的具体用法?C++ SMDiagnostic::getSourceMgr怎么用?C++ SMDiagnostic::getSourceMgr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm::SMDiagnostic
的用法示例。
在下文中一共展示了SMDiagnostic::getSourceMgr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConvertBackendLocation
/// ConvertBackendLocation - Convert a location in a temporary llvm::SourceMgr
/// buffer to be a valid FullSourceLoc.
static FullSourceLoc ConvertBackendLocation(const llvm::SMDiagnostic &D,
SourceManager &CSM) {
// Get both the clang and llvm source managers. The location is relative to
// a memory buffer that the LLVM Source Manager is handling, we need to add
// a copy to the Clang source manager.
const llvm::SourceMgr &LSM = *D.getSourceMgr();
// We need to copy the underlying LLVM memory buffer because llvm::SourceMgr
// already owns its one and clang::SourceManager wants to own its one.
const MemoryBuffer *LBuf =
LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc()));
// Create the copy and transfer ownership to clang::SourceManager.
// TODO: Avoid copying files into memory.
std::unique_ptr<llvm::MemoryBuffer> CBuf =
llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
LBuf->getBufferIdentifier());
// FIXME: Keep a file ID map instead of creating new IDs for each location.
FileID FID = CSM.createFileID(std::move(CBuf));
// Translate the offset into the file.
unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart();
SourceLocation NewLoc =
CSM.getLocForStartOfFile(FID).getLocWithOffset(Offset);
return FullSourceLoc(NewLoc, CSM);
}
示例2: handleDiagnostic
void ClangAsmParserCallback::handleDiagnostic(const llvm::SMDiagnostic &D) {
const llvm::SourceMgr &LSM = *D.getSourceMgr();
SourceLocation Loc = translateLocation(LSM, D.getLoc());
TheParser.Diag(Loc, diag::err_inline_ms_asm_parsing) << D.getMessage();
}