本文整理汇总了C++中clang::SourceLocation::isFileID方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceLocation::isFileID方法的具体用法?C++ SourceLocation::isFileID怎么用?C++ SourceLocation::isFileID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clang::SourceLocation
的用法示例。
在下文中一共展示了SourceLocation::isFileID方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: location
std::string location(clang::SourceLocation const& l, clang::SourceManager const& sm) {
if(l.isValid()) {
if(l.isFileID()) {
// if (sm.isLoadedFileID (sm.getFileID(l))) return "PRELOADED MODULE";
if(sm.isLoadedSourceLocation(l)) { return "PRELOADED MODULE"; }
return l.printToString(sm);
}
if(l.isMacroID()) {
// FIXME: what do we do here? somehow clang fails
/*
std::cout << "SLoc isMacroID\n";
auto sl = sm.getSpellingLoc(l);
if (sm.isLoadedSourceLocation(sl) ) { return "PRELOADED MODULE"; }
if(sl.isValid()) {
return sl.printToString(sm);
}
PresumedLoc pl = sm.getPresumedLoc(l);
if (pl.isValid()){
return string(pl.getFilename());
}
*/
}
return string("UNKNOWN FILE");
}
return string("INVALID LOC");
}
示例2: string
// Get a "file:line:column" source location string.
static std::string getSourceLocationString(clang::Preprocessor &PP,
clang::SourceLocation Loc) {
if (Loc.isInvalid())
return std::string("(none)");
if (Loc.isFileID()) {
clang::PresumedLoc PLoc = PP.getSourceManager().getPresumedLoc(Loc);
if (PLoc.isInvalid()) {
return std::string("(invalid)");
}
std::string Str;
llvm::raw_string_ostream SS(Str);
// The macro expansion and spelling pos is identical for file locs.
SS << "\"" << PLoc.getFilename() << ':' << PLoc.getLine() << ':'
<< PLoc.getColumn() << "\"";
std::string Result = SS.str();
// YAML treats backslash as escape, so use forward slashes.
std::replace(Result.begin(), Result.end(), '\\', '/');
return Result;
}
return std::string("(nonfile)");
}
示例3: HandlePPCond
void PreprocessorCallback::HandlePPCond(clang::SourceLocation Loc, clang::SourceLocation IfLoc)
{
if (!Loc.isValid() || !Loc.isFileID())
return;
clang::SourceManager &SM = annotator.getSourceMgr();
clang::FileID FID = SM.getFileID(Loc);
if (!annotator.shouldProcess(FID))
return;
while(ElifMapping.count(IfLoc)) {
IfLoc = Loc;
}
if (SM.getFileID(IfLoc) != FID) {
return;
}
annotator.generator(FID).addTag("span", ("data-ppcond=\"" + clang::Twine(SM.getExpansionLineNumber(IfLoc)) + "\"").str(),
SM.getFileOffset(Loc), clang::Lexer::MeasureTokenLength(Loc, SM, PP.getLangOpts()));
}
示例4: InclusionDirective
void PreprocessorCallback::InclusionDirective(clang::SourceLocation HashLoc, const clang::Token& IncludeTok,
llvm::StringRef FileName, bool IsAngled,
clang::CharSourceRange FilenameRange, const clang::FileEntry* File,
llvm::StringRef SearchPath, llvm::StringRef RelativePath,
const clang::Module* Imported)
{
if (!HashLoc.isValid() || !HashLoc.isFileID() || !File)
return;
clang::SourceManager &sm = annotator.getSourceMgr();
clang::FileID FID = sm.getFileID(HashLoc);
if (!annotator.shouldProcess(FID))
return;
std::string link = annotator.pathTo(FID, File);
if (link.empty())
return;
auto B = sm.getFileOffset(FilenameRange.getBegin());
auto E = sm.getFileOffset(FilenameRange.getEnd());
annotator.generator(FID).addTag("a", "href=\"" % link % "\"", B, E-B);
}
示例5: addFileLocation
void RefFinder::addFileLocation(clang::SourceLocation loc) {
if (!loc.isFileID()) return; // skip macro expansions etc
locs.push_back(loc);
}