本文整理汇总了C++中clang::SourceManager::getFilename方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceManager::getFilename方法的具体用法?C++ SourceManager::getFilename怎么用?C++ SourceManager::getFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clang::SourceManager
的用法示例。
在下文中一共展示了SourceManager::getFilename方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: filenameForLoc
string Utils::filenameForLoc(SourceLocation loc, const clang::SourceManager &sm)
{
string filename = sm.getFilename(loc);
auto splitted = clazy_std::splitString(filename, '/');
if (splitted.empty())
return {};
return splitted[splitted.size() - 1];
}
示例2: Add
void EditTracker::Add(const clang::SourceManager& source_manager,
clang::SourceLocation location,
llvm::StringRef original_text,
llvm::StringRef new_text) {
llvm::StringRef filename;
for (int i = 0; i < 10; i++) {
filename = source_manager.getFilename(location);
if (!filename.empty() || !location.isMacroID())
break;
// Otherwise, no filename and the SourceLocation is a macro ID. Look one
// level up the stack...
location = source_manager.getImmediateMacroCallerLoc(location);
}
assert(!filename.empty() && "Can't track edit with no filename!");
auto result = tracked_edits_.try_emplace(original_text);
if (result.second) {
result.first->getValue().new_text = new_text;
}
result.first->getValue().filenames.try_emplace(filename);
}
示例3: 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)));
}