本文整理汇总了C++中llvm::SMDiagnostic类的典型用法代码示例。如果您正苦于以下问题:C++ SMDiagnostic类的具体用法?C++ SMDiagnostic怎么用?C++ SMDiagnostic使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SMDiagnostic类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConvertBackendLocation
/// InlineAsmDiagHandler2 - This function is invoked when the backend hits an
/// error parsing inline asm. The SMDiagnostic indicates the error relative to
/// the temporary memory buffer that the inline asm parser has set up.
void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D,
SourceLocation LocCookie) {
// There are a couple of different kinds of errors we could get here. First,
// we re-format the SMDiagnostic in terms of a clang diagnostic.
// Strip "error: " off the start of the message string.
StringRef Message = D.getMessage();
if (Message.startswith("error: "))
Message = Message.substr(7);
// If the SMDiagnostic has an inline asm source location, translate it.
FullSourceLoc Loc;
if (D.getLoc() != SMLoc())
Loc = ConvertBackendLocation(D, Context->getSourceManager());
unsigned DiagID;
switch (D.getKind()) {
case llvm::SourceMgr::DK_Error:
DiagID = diag::err_fe_inline_asm;
break;
case llvm::SourceMgr::DK_Warning:
DiagID = diag::warn_fe_inline_asm;
break;
case llvm::SourceMgr::DK_Note:
DiagID = diag::note_fe_inline_asm;
break;
}
// If this problem has clang-level source location information, report the
// issue in the source with a note showing the instantiated
// code.
if (LocCookie.isValid()) {
Diags.Report(LocCookie, DiagID).AddString(Message);
if (D.getLoc().isValid()) {
DiagnosticBuilder B = Diags.Report(Loc, diag::note_fe_inline_asm_here);
// Convert the SMDiagnostic ranges into SourceRange and attach them
// to the diagnostic.
for (unsigned i = 0, e = D.getRanges().size(); i != e; ++i) {
std::pair<unsigned, unsigned> Range = D.getRanges()[i];
unsigned Column = D.getColumnNo();
B << SourceRange(Loc.getLocWithOffset(Range.first - Column),
Loc.getLocWithOffset(Range.second - Column));
}
}
return;
}
// Otherwise, report the backend issue as occurring in the generated .s file.
// If Loc is invalid, we still need to report the issue, it just gets no
// location info.
Diags.Report(Loc, DiagID).AddString(Message);
}
示例2: 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.
llvm::MemoryBuffer *CBuf =
llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
LBuf->getBufferIdentifier());
FileID FID = CSM.createFileIDForMemBuffer(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);
}
示例3: checkForFixIt
/// Return true if the given \p ExpectedFixIt is in the fix-its emitted by
/// diagnostic \p D.
static bool checkForFixIt(const ExpectedFixIt &Expected,
const llvm::SMDiagnostic &D,
StringRef buffer) {
for (auto &ActualFixIt : D.getFixIts()) {
if (ActualFixIt.getText() != Expected.Text)
continue;
llvm::SMRange Range = ActualFixIt.getRange();
if (getColumnNumber(buffer, Range.Start) != Expected.StartCol)
continue;
if (getColumnNumber(buffer, Range.End) != Expected.EndCol)
continue;
return true;
}
return false;
}
示例4: printToString
std::string printToString(const llvm::SMDiagnostic &diag) {
std::string errStr;
llvm::raw_string_ostream rsos(errStr);
diag.print(diag.getFilename().data(), rsos);
return rsos.str();
}
示例5: BitcodeInlineAsmDiagHandler
static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM,
void *Context,
unsigned LocCookie) {
SM.print(nullptr, llvm::errs());
}
示例6: 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();
}