本文整理汇总了C++中PathDiagnosticPiece::getRanges方法的典型用法代码示例。如果您正苦于以下问题:C++ PathDiagnosticPiece::getRanges方法的具体用法?C++ PathDiagnosticPiece::getRanges怎么用?C++ PathDiagnosticPiece::getRanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathDiagnosticPiece
的用法示例。
在下文中一共展示了PathDiagnosticPiece::getRanges方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReportEvent
static void ReportEvent(raw_ostream &o, const PathDiagnosticPiece& P,
const FIDMap& FM,
const SourceManager &SM,
const LangOptions &LangOpts,
unsigned indent,
unsigned depth,
bool isKeyEvent = false) {
Indent(o, indent) << "<dict>\n";
++indent;
Indent(o, indent) << "<key>kind</key><string>event</string>\n";
if (isKeyEvent) {
Indent(o, indent) << "<key>key_event</key><true/>\n";
}
// Output the location.
FullSourceLoc L = P.getLocation().asLocation();
Indent(o, indent) << "<key>location</key>\n";
EmitLocation(o, SM, LangOpts, L, FM, indent);
// Output the ranges (if any).
ArrayRef<SourceRange> Ranges = P.getRanges();
if (!Ranges.empty()) {
Indent(o, indent) << "<key>ranges</key>\n";
Indent(o, indent) << "<array>\n";
++indent;
for (ArrayRef<SourceRange>::iterator I = Ranges.begin(), E = Ranges.end();
I != E; ++I) {
EmitRange(o, SM, LangOpts, CharSourceRange::getTokenRange(*I), FM,
indent + 1);
}
--indent;
Indent(o, indent) << "</array>\n";
}
// Output the call depth.
Indent(o, indent) << "<key>depth</key>"
<< "<integer>" << depth << "</integer>\n";
// Output the text.
assert(!P.getString().empty());
Indent(o, indent) << "<key>extended_message</key>\n";
Indent(o, indent);
EmitString(o, P.getString()) << '\n';
// Output the short text.
// FIXME: Really use a short string.
Indent(o, indent) << "<key>message</key>\n";
Indent(o, indent);
EmitString(o, P.getString()) << '\n';
// Finish up.
--indent;
Indent(o, indent); o << "</dict>\n";
}
示例2: ReportEvent
static void ReportEvent(raw_ostream &o, const PathDiagnosticPiece& P,
const FIDMap& FM,
const SourceManager &SM,
const LangOptions &LangOpts,
unsigned indent,
unsigned depth,
bool isKeyEvent = false) {
Indent(o, indent) << "<dict>\n";
++indent;
Indent(o, indent) << "<key>kind</key><string>event</string>\n";
if (isKeyEvent) {
Indent(o, indent) << "<key>key_event</key><true/>\n";
}
// Output the location.
FullSourceLoc L = P.getLocation().asLocation();
Indent(o, indent) << "<key>location</key>\n";
EmitLocation(o, SM, L, FM, indent);
// Output the ranges (if any).
ArrayRef<SourceRange> Ranges = P.getRanges();
if (!Ranges.empty()) {
Indent(o, indent) << "<key>ranges</key>\n";
Indent(o, indent) << "<array>\n";
++indent;
for (auto &R : Ranges)
EmitRange(o, SM,
Lexer::getAsCharRange(SM.getExpansionRange(R), SM, LangOpts),
FM, indent + 1);
--indent;
Indent(o, indent) << "</array>\n";
}
// Output the call depth.
Indent(o, indent) << "<key>depth</key>";
EmitInteger(o, depth) << '\n';
// Output the text.
assert(!P.getString().empty());
Indent(o, indent) << "<key>extended_message</key>\n";
Indent(o, indent);
EmitString(o, P.getString()) << '\n';
// Output the short text.
// FIXME: Really use a short string.
Indent(o, indent) << "<key>message</key>\n";
Indent(o, indent);
EmitString(o, P.getString()) << '\n';
// Finish up.
--indent;
Indent(o, indent); o << "</dict>\n";
}
示例3: compareControlFlow
static Optional<bool> comparePiece(const PathDiagnosticPiece &X,
const PathDiagnosticPiece &Y) {
if (X.getKind() != Y.getKind())
return X.getKind() < Y.getKind();
FullSourceLoc XL = X.getLocation().asLocation();
FullSourceLoc YL = Y.getLocation().asLocation();
if (XL != YL)
return XL.isBeforeInTranslationUnitThan(YL);
if (X.getString() != Y.getString())
return X.getString() < Y.getString();
if (X.getRanges().size() != Y.getRanges().size())
return X.getRanges().size() < Y.getRanges().size();
const SourceManager &SM = XL.getManager();
for (unsigned i = 0, n = X.getRanges().size(); i < n; ++i) {
SourceRange XR = X.getRanges()[i];
SourceRange YR = Y.getRanges()[i];
if (XR != YR) {
if (XR.getBegin() != YR.getBegin())
return SM.isBeforeInTranslationUnit(XR.getBegin(), YR.getBegin());
return SM.isBeforeInTranslationUnit(XR.getEnd(), YR.getEnd());
}
}
switch (X.getKind()) {
case PathDiagnosticPiece::ControlFlow:
return compareControlFlow(cast<PathDiagnosticControlFlowPiece>(X),
cast<PathDiagnosticControlFlowPiece>(Y));
case PathDiagnosticPiece::Event:
case PathDiagnosticPiece::Note:
return None;
case PathDiagnosticPiece::Macro:
return compareMacro(cast<PathDiagnosticMacroPiece>(X),
cast<PathDiagnosticMacroPiece>(Y));
case PathDiagnosticPiece::Call:
return compareCall(cast<PathDiagnosticCallPiece>(X),
cast<PathDiagnosticCallPiece>(Y));
}
llvm_unreachable("all cases handled");
}
示例4: HandlePiece
//.........这里部分代码省略.........
else
os << "; max-width:100em";
os << "\">";
if (max > 1) {
os << "<table class=\"msgT\"><tr><td valign=\"top\">";
os << "<div class=\"PathIndex";
if (Kind) os << " PathIndex" << Kind;
os << "\">" << num << "</div>";
if (num > 1) {
os << "</td><td><div class=\"PathNav\"><a href=\"#Path"
<< (num - 1)
<< "\" title=\"Previous event ("
<< (num - 1)
<< ")\">←</a></div></td>";
}
os << "</td><td>";
}
if (const PathDiagnosticMacroPiece *MP =
dyn_cast<PathDiagnosticMacroPiece>(&P)) {
os << "Within the expansion of the macro '";
// Get the name of the macro by relexing it.
{
FullSourceLoc L = MP->getLocation().asLocation().getExpansionLoc();
assert(L.isFileID());
StringRef BufferInfo = L.getBufferData();
std::pair<FileID, unsigned> LocInfo = L.getDecomposedLoc();
const char* MacroName = LocInfo.second + BufferInfo.data();
Lexer rawLexer(SM.getLocForStartOfFile(LocInfo.first), PP.getLangOpts(),
BufferInfo.begin(), MacroName, BufferInfo.end());
Token TheTok;
rawLexer.LexFromRawLexer(TheTok);
for (unsigned i = 0, n = TheTok.getLength(); i < n; ++i)
os << MacroName[i];
}
os << "':\n";
if (max > 1) {
os << "</td>";
if (num < max) {
os << "<td><div class=\"PathNav\"><a href=\"#";
if (num == max - 1)
os << "EndPath";
else
os << "Path" << (num + 1);
os << "\" title=\"Next event ("
<< (num + 1)
<< ")\">→</a></div></td>";
}
os << "</tr></table>";
}
// Within a macro piece. Write out each event.
ProcessMacroPiece(os, *MP, 0);
}
else {
os << html::EscapeText(P.getString());
if (max > 1) {
os << "</td>";
if (num < max) {
os << "<td><div class=\"PathNav\"><a href=\"#";
if (num == max - 1)
os << "EndPath";
else
os << "Path" << (num + 1);
os << "\" title=\"Next event ("
<< (num + 1)
<< ")\">→</a></div></td>";
}
os << "</tr></table>";
}
}
os << "</div></td></tr>";
// Insert the new html.
unsigned DisplayPos = LineEnd - FileStart;
SourceLocation Loc =
SM.getLocForStartOfFile(LPosInfo.first).getLocWithOffset(DisplayPos);
R.InsertTextBefore(Loc, os.str());
// Now highlight the ranges.
ArrayRef<SourceRange> Ranges = P.getRanges();
for (ArrayRef<SourceRange>::iterator I = Ranges.begin(),
E = Ranges.end(); I != E; ++I) {
HighlightRange(R, LPosInfo.first, *I);
}
}