本文整理汇总了C++中clang::SourceManager::getFileID方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceManager::getFileID方法的具体用法?C++ SourceManager::getFileID怎么用?C++ SourceManager::getFileID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clang::SourceManager
的用法示例。
在下文中一共展示了SourceManager::getFileID方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetTokenBefore
clang::Token GetTokenBefore(const clang::SourceManager &sources,
clang::SourceLocation loc) {
clang::Token token;
token.setKind(clang::tok::unknown);
clang::LangOptions lang_options;
loc = loc.getLocWithOffset(-1);
while (loc != sources.getLocForStartOfFile(sources.getFileID(loc))) {
loc = clang::Lexer::GetBeginningOfToken(loc, sources, lang_options);
if (!clang::Lexer::getRawToken(loc, token, sources, lang_options)) {
if (!token.is(clang::tok::comment)) {
break;
}
}
loc = loc.getLocWithOffset(-1);
}
return token;
}
示例2: GetTag
std::string MocNg::GetTag(clang::SourceLocation DeclLoc, const clang::SourceManager &SM)
{
clang::SourceLocation FileLoc = SM.getFileLoc(DeclLoc);
clang::FileID FID = SM.getFileID(FileLoc);
const llvm::MemoryBuffer *Buffer = SM.getBuffer(FID);
const char *B = Buffer->getBufferStart();
int Off = SM.getFileOffset(FileLoc);
int Orig = Off;
while (Off > 0 && B[Off] != ';' && B[Off]!=',' && B[Off] != '}' && B[Off] != ':' /*&& B[Off] != '\n'*/ ) {
Off--;
}
auto it_before = Tags.lower_bound(FileLoc.getLocWithOffset(Off - Orig));
auto it_after = Tags.upper_bound(FileLoc);
if (it_before != Tags.end() && it_after != Tags.begin() && it_before == (--it_after)) {
return it_before->second;
}
return {};
}
示例3: GetTokenAfterLocation
clang::Token GetTokenAfterLocation(clang::SourceLocation loc,
const clang::SourceManager &source_manager) {
clang::Token token;
token.setKind(clang::tok::unknown);
clang::LangOptions lang_options;
loc = loc.getLocWithOffset(1);
while (loc !=
source_manager.getLocForEndOfFile(source_manager.getFileID(loc))) {
if (!clang::Lexer::getRawToken(loc, token, source_manager, lang_options)) {
if (!token.is(clang::tok::comment)) {
break;
}
loc = clang::Lexer::getLocForEndOfToken(token.getLocation(), /*Offset=*/0,
source_manager, lang_options);
} else {
loc = loc.getLocWithOffset(1);
}
}
return token;
}
示例4: collect
RangeSet collect(clang::ASTContext &astContext, oclint::RuleBase *rule)
{
_rule = rule;
_sourceManager = &astContext.getSourceManager();
_range.clear();
clang::DeclContext *decl = astContext.getTranslationUnitDecl();
for (clang::DeclContext::decl_iterator declIt = decl->decls_begin(),
declEnd = decl->decls_end(); declIt != declEnd; ++declIt)
{
clang::SourceLocation startLocation = (*declIt)->getLocStart();
if (startLocation.isValid() &&
_sourceManager->getMainFileID() == _sourceManager->getFileID(startLocation))
{
(void) /* explicitly ignore the return of this function */
clang::RecursiveASTVisitor<DeclAnnotationRangeCollector>::TraverseDecl(*declIt);
}
}
return _range;
}
示例5: builder
core::annotations::Location convertClangSrcLoc(core::NodeManager& man, const clang::SourceManager& sm, clang::SourceLocation start,
clang::SourceLocation end) {
// check file validity
FileID&& fileId = sm.getFileID(start);
if(fileId.isInvalid()) return core::annotations::Location::getShared();
const clang::FileEntry* fileEntry = sm.getFileEntryForID(fileId);
// if we cannot get the file entry, lets try to get the source filename directly
std::string filename;
if(!fileEntry) {
StringRef s = sm.getFilename(start);
filename = s.str();
} else {
assert_true(fileEntry);
filename = fileEntry->getName();
}
// update macro locations, if required
start = getExpansionLoc(sm, start);
end = getExpansionLoc(sm, end);
// generate location object
core::IRBuilder builder(man);
return core::annotations::Location(builder.stringValue(filename.c_str()),
core::annotations::TextPosition(sm.getSpellingLineNumber(start), sm.getSpellingColumnNumber(start)),
core::annotations::TextPosition(sm.getSpellingLineNumber(end), sm.getSpellingColumnNumber(end)));
}