本文整理汇总了C++中PathDiagnostic类的典型用法代码示例。如果您正苦于以下问题:C++ PathDiagnostic类的具体用法?C++ PathDiagnostic怎么用?C++ PathDiagnostic使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PathDiagnostic类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PathDiagnostic
void PathDiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
const DiagnosticInfo &Info) {
// Create a PathDiagnostic with a single piece.
PathDiagnostic* D = new PathDiagnostic();
const char *LevelStr;
switch (DiagLevel) {
default:
case Diagnostic::Ignored: assert(0 && "Invalid diagnostic type");
case Diagnostic::Note: LevelStr = "note: "; break;
case Diagnostic::Warning: LevelStr = "warning: "; break;
case Diagnostic::Error: LevelStr = "error: "; break;
case Diagnostic::Fatal: LevelStr = "fatal error: "; break;
}
llvm::SmallString<100> StrC;
StrC += LevelStr;
Info.FormatDiagnostic(StrC);
PathDiagnosticPiece *P =
new PathDiagnosticEventPiece(Info.getLocation(), StrC.str());
for (unsigned i = 0, e = Info.getNumRanges(); i != e; ++i)
P->addRange(Info.getRange(i));
for (unsigned i = 0, e = Info.getNumCodeModificationHints(); i != e; ++i)
P->addCodeModificationHint(Info.getCodeModificationHint(i));
D->push_front(P);
HandlePathDiagnostic(D);
}
示例2: createResult
static json::Object createResult(const PathDiagnostic &Diag, json::Array &Files,
const StringMap<unsigned> &RuleMapping) {
const PathPieces &Path = Diag.path.flatten(false);
const SourceManager &SMgr = Path.front()->getLocation().getManager();
auto Iter = RuleMapping.find(Diag.getCheckName());
assert(Iter != RuleMapping.end() && "Rule ID is not in the array index map?");
return json::Object{
{"message", createMessage(Diag.getVerboseDescription())},
{"codeFlows", json::Array{createCodeFlow(Path, Files)}},
{"locations",
json::Array{createLocation(createPhysicalLocation(
Diag.getLocation().asRange(),
*Diag.getLocation().asLocation().getFileEntry(), SMgr, Files))}},
{"ruleIndex", Iter->getValue()},
{"ruleId", Diag.getCheckName()}};
}
示例3: createRule
static json::Object createRule(const PathDiagnostic &Diag) {
StringRef CheckName = Diag.getCheckName();
json::Object Ret{
{"fullDescription", createMessage(getRuleDescription(CheckName))},
{"name", createMessage(CheckName)},
{"id", CheckName}};
std::string RuleURI = getRuleHelpURIStr(CheckName);
if (!RuleURI.empty())
Ret["helpURI"] = RuleURI;
return Ret;
}
示例4: compare
static bool compare(const PathDiagnostic &X, const PathDiagnostic &Y) {
FullSourceLoc XL = X.getLocation().asLocation();
FullSourceLoc YL = Y.getLocation().asLocation();
if (XL != YL)
return XL.isBeforeInTranslationUnitThan(YL);
if (X.getBugType() != Y.getBugType())
return X.getBugType() < Y.getBugType();
if (X.getCategory() != Y.getCategory())
return X.getCategory() < Y.getCategory();
if (X.getVerboseDescription() != Y.getVerboseDescription())
return X.getVerboseDescription() < Y.getVerboseDescription();
if (X.getShortDescription() != Y.getShortDescription())
return X.getShortDescription() < Y.getShortDescription();
if (X.getDeclWithIssue() != Y.getDeclWithIssue()) {
const Decl *XD = X.getDeclWithIssue();
if (!XD)
return true;
const Decl *YD = Y.getDeclWithIssue();
if (!YD)
return false;
SourceLocation XDL = XD->getLocation();
SourceLocation YDL = YD->getLocation();
if (XDL != YDL) {
const SourceManager &SM = XL.getManager();
return SM.isBeforeInTranslationUnit(XDL, YDL);
}
}
PathDiagnostic::meta_iterator XI = X.meta_begin(), XE = X.meta_end();
PathDiagnostic::meta_iterator YI = Y.meta_begin(), YE = Y.meta_end();
if (XE - XI != YE - YI)
return (XE - XI) < (YE - YI);
for ( ; XI != XE ; ++XI, ++YI) {
if (*XI != *YI)
return (*XI) < (*YI);
}
llvm::Optional<bool> b = comparePath(X.path, Y.path);
assert(b.hasValue());
return b.getValue();
}
示例5: assert
void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
FilesMade *filesMade) {
// Create the HTML directory if it is missing.
if (!createdDir) {
createdDir = true;
std::string ErrorMsg;
Directory.createDirectoryOnDisk(true, &ErrorMsg);
bool IsDirectory;
if (llvm::sys::fs::is_directory(Directory.str(), IsDirectory) ||
!IsDirectory) {
llvm::errs() << "warning: could not create directory '"
<< Directory.str() << "'\n"
<< "reason: " << ErrorMsg << '\n';
noDir = true;
return;
}
}
if (noDir)
return;
// First flatten out the entire path to make it easier to use.
PathPieces path = D.path.flatten(/*ShouldFlattenMacros=*/false);
// The path as already been prechecked that all parts of the path are
// from the same file and that it is non-empty.
const SourceManager &SMgr = (*path.begin())->getLocation().getManager();
assert(!path.empty());
FileID FID =
(*path.begin())->getLocation().asLocation().getExpansionLoc().getFileID();
assert(!FID.isInvalid());
// Create a new rewriter to generate HTML.
Rewriter R(const_cast<SourceManager&>(SMgr), PP.getLangOpts());
// Process the path.
unsigned n = path.size();
unsigned max = n;
for (PathPieces::const_reverse_iterator I = path.rbegin(),
E = path.rend();
I != E; ++I, --n)
HandlePiece(R, FID, **I, n, max);
// Add line numbers, header, footer, etc.
// unsigned FID = R.getSourceMgr().getMainFileID();
html::EscapeText(R, FID);
html::AddLineNumbers(R, FID);
// If we have a preprocessor, relex the file and syntax highlight.
// We might not have a preprocessor if we come from a deserialized AST file,
// for example.
html::SyntaxHighlight(R, FID, PP);
html::HighlightMacros(R, FID, PP);
// Get the full directory name of the analyzed file.
const FileEntry* Entry = SMgr.getFileEntryForID(FID);
// This is a cludge; basically we want to append either the full
// working directory if we have no directory information. This is
// a work in progress.
std::string DirName = "";
if (llvm::sys::path::is_relative(Entry->getName())) {
llvm::sys::Path P = llvm::sys::Path::GetCurrentDirectory();
DirName = P.str() + "/";
}
// Add the name of the file as an <h1> tag.
{
std::string s;
llvm::raw_string_ostream os(s);
os << "<!-- REPORTHEADER -->\n"
<< "<h3>Bug Summary</h3>\n<table class=\"simpletable\">\n"
"<tr><td class=\"rowname\">File:</td><td>"
<< html::EscapeText(DirName)
<< html::EscapeText(Entry->getName())
<< "</td></tr>\n<tr><td class=\"rowname\">Location:</td><td>"
"<a href=\"#EndPath\">line "
<< (*path.rbegin())->getLocation().asLocation().getExpansionLineNumber()
<< ", column "
<< (*path.rbegin())->getLocation().asLocation().getExpansionColumnNumber()
<< "</a></td></tr>\n"
"<tr><td class=\"rowname\">Description:</td><td>"
<< D.getVerboseDescription() << "</td></tr>\n";
// Output any other meta data.
for (PathDiagnostic::meta_iterator I=D.meta_begin(), E=D.meta_end();
I!=E; ++I) {
//.........这里部分代码省略.........
示例6: assert
void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
FilesMade *filesMade) {
// Create the HTML directory if it is missing.
if (!createdDir) {
createdDir = true;
if (std::error_code ec = llvm::sys::fs::create_directories(Directory)) {
llvm::errs() << "warning: could not create directory '"
<< Directory << "': " << ec.message() << '\n';
noDir = true;
return;
}
}
if (noDir)
return;
// First flatten out the entire path to make it easier to use.
PathPieces path = D.path.flatten(/*ShouldFlattenMacros=*/false);
// The path as already been prechecked that all parts of the path are
// from the same file and that it is non-empty.
const SourceManager &SMgr = (*path.begin())->getLocation().getManager();
assert(!path.empty());
FileID FID =
(*path.begin())->getLocation().asLocation().getExpansionLoc().getFileID();
assert(!FID.isInvalid());
// Create a new rewriter to generate HTML.
Rewriter R(const_cast<SourceManager&>(SMgr), PP.getLangOpts());
// Get the function/method name
SmallString<128> declName("unknown");
int offsetDecl = 0;
if (const Decl *DeclWithIssue = D.getDeclWithIssue()) {
if (const NamedDecl *ND = dyn_cast<NamedDecl>(DeclWithIssue)) {
declName = ND->getDeclName().getAsString();
}
if (const Stmt *Body = DeclWithIssue->getBody()) {
// Retrieve the relative position of the declaration which will be used
// for the file name
FullSourceLoc L(
SMgr.getExpansionLoc((*path.rbegin())->getLocation().asLocation()),
SMgr);
FullSourceLoc FunL(SMgr.getExpansionLoc(Body->getLocStart()), SMgr);
offsetDecl = L.getExpansionLineNumber() - FunL.getExpansionLineNumber();
}
}
// Process the path.
unsigned n = path.size();
unsigned max = n;
for (PathPieces::const_reverse_iterator I = path.rbegin(),
E = path.rend();
I != E; ++I, --n)
HandlePiece(R, FID, **I, n, max);
// Add line numbers, header, footer, etc.
// unsigned FID = R.getSourceMgr().getMainFileID();
html::EscapeText(R, FID);
html::AddLineNumbers(R, FID);
// If we have a preprocessor, relex the file and syntax highlight.
// We might not have a preprocessor if we come from a deserialized AST file,
// for example.
html::SyntaxHighlight(R, FID, PP);
html::HighlightMacros(R, FID, PP);
// Get the full directory name of the analyzed file.
const FileEntry* Entry = SMgr.getFileEntryForID(FID);
// This is a cludge; basically we want to append either the full
// working directory if we have no directory information. This is
// a work in progress.
llvm::SmallString<0> DirName;
if (llvm::sys::path::is_relative(Entry->getName())) {
llvm::sys::fs::current_path(DirName);
DirName += '/';
}
int LineNumber = (*path.rbegin())->getLocation().asLocation().getExpansionLineNumber();
int ColumnNumber = (*path.rbegin())->getLocation().asLocation().getExpansionColumnNumber();
// Add the name of the file as an <h1> tag.
{
std::string s;
llvm::raw_string_ostream os(s);
os << "<!-- REPORTHEADER -->\n"
<< "<h3>Bug Summary</h3>\n<table class=\"simpletable\">\n"
//.........这里部分代码省略.........