本文整理汇总了C++中SourceManager::getDisplayNameForLoc方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceManager::getDisplayNameForLoc方法的具体用法?C++ SourceManager::getDisplayNameForLoc怎么用?C++ SourceManager::getDisplayNameForLoc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceManager
的用法示例。
在下文中一共展示了SourceManager::getDisplayNameForLoc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addLocToRecord
void SerializedDiagnosticConsumer::
emitDiagnosticMessage(SourceManager &SM,
SourceLoc Loc,
DiagnosticKind Kind,
StringRef Text,
const DiagnosticInfo &Info) {
// Emit the diagnostic to bitcode.
llvm::BitstreamWriter &Stream = State->Stream;
RecordData &Record = State->Record;
AbbreviationMap &Abbrevs = State->Abbrevs;
StringRef filename = "";
if (Loc.isValid())
filename = SM.getDisplayNameForLoc(Loc);
// Emit the RECORD_DIAG record.
Record.clear();
Record.push_back(RECORD_DIAG);
Record.push_back(getDiagnosticLevel(Kind));
addLocToRecord(Loc, SM, filename, Record);
// FIXME: Swift diagnostics currently have no category.
Record.push_back(0);
// FIXME: Swift diagnostics currently have no flags.
Record.push_back(0);
// Emit the message.
Record.push_back(Text.size());
Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_DIAG), Record, Text);
// If the location is invalid, do not emit source ranges or fixits.
if (Loc.isInvalid())
return;
// Emit source ranges.
auto RangeAbbrev = State->Abbrevs.get(RECORD_SOURCE_RANGE);
for (const auto &R : Info.Ranges) {
if (R.isInvalid())
continue;
State->Record.clear();
State->Record.push_back(RECORD_SOURCE_RANGE);
addRangeToRecord(R, SM, filename, State->Record);
State->Stream.EmitRecordWithAbbrev(RangeAbbrev, State->Record);
}
// Emit FixIts.
auto FixItAbbrev = State->Abbrevs.get(RECORD_FIXIT);
for (const auto &F : Info.FixIts) {
if (F.getRange().isValid()) {
State->Record.clear();
State->Record.push_back(RECORD_FIXIT);
addRangeToRecord(F.getRange(), SM, filename, State->Record);
State->Record.push_back(F.getText().size());
Stream.EmitRecordWithBlob(FixItAbbrev, Record, F.getText());
}
}
}
示例2: mapping
static void mapping(IO &io, SourceLoc &Loc) {
assert(io.outputting() && "input not yet implemented");
SourceManager *SM = static_cast<SourceManager *>(io.getContext());
StringRef File = SM->getDisplayNameForLoc(Loc);
unsigned Line, Col;
std::tie(Line, Col) = SM->getLineAndColumn(Loc);
io.mapRequired("File", File);
io.mapRequired("Line", Line);
io.mapRequired("Column", Col);
}