本文整理汇总了C++中SourceLocation::printToString方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceLocation::printToString方法的具体用法?C++ SourceLocation::printToString怎么用?C++ SourceLocation::printToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceLocation
的用法示例。
在下文中一共展示了SourceLocation::printToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
virtual void run(const MatchFinder::MatchResult &Result){//freeVar
const DeclRefExpr* DRE = Result.Nodes.getNodeAs<DeclRefExpr>("freeVar");
#ifdef DEBUG
llvm::errs()<<"----DRE(freeVar) find----\n";
#endif
if(!DRE) return ;
const SourceManager *SM = Result.SourceManager;
const NamedDecl *ND = DRE->getFoundDecl();
checkPoint cp;
cp.name = rewrite.ConvertToString((Stmt*)DRE);
std::string str_decl = ND->getNameAsString();
cp.declName = str_decl;
SourceLocation declLocStart = ND->getLocStart();
std::string str_declLocStart = declLocStart.printToString(*SM);
loc_strToint(cp.declRow,cp.declCol,str_declLocStart.c_str());
SourceLocation locStart = DRE->getLocStart();
std::string str_locStart = locStart.printToString(*SM);
loc_strToint(cp.row,cp.col,str_locStart.c_str());
cpVecF.push_back(cp);
#ifdef DEBUG
llvm::errs()<<"----DRE(freeVar) end----\n";
#endif
}
示例2: run
virtual void run(const MatchFinder::MatchResult &Result) {
auto *d = Result.Nodes.getNodeAs<TypeLoc>("stuff");
SourceLocation locstart = d->getLocStart();
llvm::errs() << "*\n";
llvm::errs() << " start: " << locstart.printToString(*Result.SourceManager) << "\n";
SourceLocation locend = d->getLocEnd();
llvm::errs() << " end: " << locend.printToString(*Result.SourceManager) << "\n";
}
示例3: collectModuleHeaders
// Collect referenced headers from one module.
// Collects the headers referenced in the given module into
// HeaderFileNames.
bool ModularizeUtilities::collectModuleHeaders(const clang::Module &Mod) {
// Ignore explicit modules because they often have dependencies
// we can't know.
if (Mod.IsExplicit)
return true;
// Treat headers in umbrella directory as dependencies.
DependentsVector UmbrellaDependents;
// Recursively do submodules.
for (auto MI = Mod.submodule_begin(), MIEnd = Mod.submodule_end();
MI != MIEnd; ++MI)
collectModuleHeaders(**MI);
if (const FileEntry *UmbrellaHeader = Mod.getUmbrellaHeader().Entry) {
std::string HeaderPath = getCanonicalPath(UmbrellaHeader->getName());
// Collect umbrella header.
HeaderFileNames.push_back(HeaderPath);
// FUTURE: When needed, umbrella header header collection goes here.
}
else if (const DirectoryEntry *UmbrellaDir = Mod.getUmbrellaDir().Entry) {
// If there normal headers, assume these are umbrellas and skip collection.
if (Mod.Headers->size() == 0) {
// Collect headers in umbrella directory.
if (!collectUmbrellaHeaders(UmbrellaDir->getName(), UmbrellaDependents))
return false;
}
}
// We ignore HK_Private, HK_Textual, HK_PrivateTextual, and HK_Excluded,
// assuming they are marked as such either because of unsuitability for
// modules or because they are meant to be included by another header,
// and thus should be ignored by modularize.
int NormalHeaderCount = Mod.Headers[clang::Module::HK_Normal].size();
for (int Index = 0; Index < NormalHeaderCount; ++Index) {
DependentsVector NormalDependents;
// Collect normal header.
const clang::Module::Header &Header(
Mod.Headers[clang::Module::HK_Normal][Index]);
std::string HeaderPath = getCanonicalPath(Header.Entry->getName());
HeaderFileNames.push_back(HeaderPath);
}
int MissingCountThisModule = Mod.MissingHeaders.size();
for (int Index = 0; Index < MissingCountThisModule; ++Index) {
std::string MissingFile = Mod.MissingHeaders[Index].FileName;
SourceLocation Loc = Mod.MissingHeaders[Index].FileNameLoc;
errs() << Loc.printToString(*SourceMgr)
<< ": error : Header not found: " << MissingFile << "\n";
}
MissingHeaderCount += MissingCountThisModule;
return true;
}
示例4: recordCallLog
///record call-log pair
void FindPatternVisitor::recordCallLog(CallExpr *callExpr, CallExpr *logExpr){
if(!callExpr || !logExpr)
return;
if(callExpr == logExpr)
return;
if(!callExpr->getDirectCallee() || !logExpr->getDirectCallee())
return;
if(hasRecorded[logExpr] == 0)
hasRecorded[logExpr] = 1;
else
return;
SourceLocation callLocation = callExpr->getLocStart();
SourceLocation logLocation = logExpr->getLocStart();
if(callLocation.isValid() && logLocation.isValid()){
if(0){
llvm::outs()<<callExpr->getDirectCallee()->getQualifiedNameAsString()<<"@"<<callLocation.printToString(CI->getSourceManager());
llvm::outs()<<"#";
llvm::outs()<<logExpr->getDirectCallee()->getQualifiedNameAsString()<<"@"<<logLocation.printToString(CI->getSourceManager());
llvm::outs()<<"\n";
}
fputs(callExpr->getDirectCallee()->getQualifiedNameAsString().c_str(), out);
fputs("@", out);
string callloc = callLocation.printToString(CI->getSourceManager());
callloc = callloc.substr(0, callloc.find(" "));
fputs(callloc.c_str(), out);
fputs("#", out);
fputs(logExpr->getDirectCallee()->getQualifiedNameAsString().c_str(), out);
fputs("@", out);
string logloc = logLocation.printToString(CI->getSourceManager());
logloc = logloc.substr(0, logloc.find(" "));
fputs(logloc.c_str(), out);
fputs("\n", out);
totalPatternSnippet++;
}
}
示例5: FileName
string FileName(SourceLocation const& l, SourceManager const& sm) {
if(l.isValid()) {
return l.printToString(sm);
// if (l.isMacroID()){
// PresumedLoc pl = sm.getPresumedLoc(l);
// if (pl.isValid()){
// return string(pl.getFilename());
// }
// }
// return string(l.getFilename());
}
return string("UNKNOWN FILE");
}