本文整理汇总了C++中clang::SourceLocation类的典型用法代码示例。如果您正苦于以下问题:C++ SourceLocation类的具体用法?C++ SourceLocation怎么用?C++ SourceLocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SourceLocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSourceLocationString
// 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)");
}
示例2: FSL
void
NamedDeclMatcher::renameLocation(clang::SourceLocation L, std::string& N)
{
if (L.isValid()) {
if (L.isMacroID()) {
// TODO: emit error using diagnostics
clang::SourceManager &SM = ci->getSourceManager();
if (SM.isMacroArgExpansion(L) || SM.isInSystemMacro(L)) {
// see if it's the macro expansion we can handle
// e.g.
// #define call(x) x
// call(y()); // if we want to rename y()
L = SM.getSpellingLoc(L);
// this falls through to the rename routine below
}
else {
// if the spelling location is from an actual file that we can
// touch, then do the replacement, but show a warning
clang::SourceManager &SM = ci->getSourceManager();
auto SL = SM.getSpellingLoc(L);
clang::FullSourceLoc FSL(SL, SM);
const clang::FileEntry *FE = SM.getFileEntryForID(FSL.getFileID());
if (FE) {
llvm::errs() << "Warning: Rename attempted as a result of macro "
<< "expansion may break things, at: " << loc(L) << "\n";
L = SL;
// this falls through to the rename routine below
}
else {
// cannot handle this case
llvm::errs() << "Error: Token is resulted from macro expansion"
" and is therefore not renamed, at: " << loc(L) << "\n";
return;
}
}
}
if (!canChangeLocation(L)) {
return;
}
clang::Preprocessor &P = ci->getPreprocessor();
auto LE = P.getLocForEndOfToken(L);
if (LE.isValid()) {
// getLocWithOffset returns the location *past* the token, hence -1
auto E = LE.getLocWithOffset(-1);
// TODO: Determine if it's a writable file
// TODO: Determine if the location has already been touched or
// needs skipping (such as in refactoring API user's code, then
// the API headers need no changing since later the new API will be
// in place)
Replacer::instance().replace(clang::SourceRange(L, E), N, ci->getSourceManager());
}
}
}
示例3: 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");
}
示例4: expansionLoc
ReportStream Reporter::report(const clang::SourceRange &range)
{
// Track this report
mTotalReports++;
// Print the expansion location
const clang::SourceLocation expansionLoc(mSourceManager.getExpansionLoc(range.getBegin()));
std::cerr << boldCode() << expansionLoc.printToString(mSourceManager) << ": ";
// Print the "connect" in a different color than warnings or errors
std::cerr << connectColorCode() << "connect:" << defaultColorCode();
return ReportStream();
}
示例5: FSL
bool
NamedDeclMatcher::shouldIgnore(clang::SourceLocation L)
{
if (!L.isValid()) {
return true;
}
clang::SourceManager &SM = ci->getSourceManager();
clang::FullSourceLoc FSL(L, SM);
const clang::FileEntry *FE = SM.getFileEntryForID(FSL.getFileID());
if (!FE) {
// attempt to get the spelling location
auto SL = SM.getSpellingLoc(L);
if (!SL.isValid()) {
return true;
}
clang::FullSourceLoc FSL2(SL, SM);
FE = SM.getFileEntryForID(FSL2.getFileID());
if (!FE) {
return true;
}
}
auto FN = FE->getName();
for (auto I = ignoreList.begin(), E = ignoreList.end(); I != E; ++I) {
if (I->FullMatch(FN)) {
return true;
}
}
return false;
}
示例6: appendArgument
// Append a SourceLocation argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
clang::SourceLocation Value) {
if (Value.isInvalid()) {
appendArgument(Name, "(invalid)");
return;
}
appendArgument(Name, getSourceLocationString(PP, Value).c_str());
}
示例7: 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;
}
示例8: isInterceptedLibHeader
bool HeaderTagger::isInterceptedLibHeader(const clang::SourceLocation& loc) const {
if(!loc.isValid()) { return false; }
auto fit = isInterceptedCache.find(sm.getFileID(loc));
if(fit != isInterceptedCache.end()) { return !fit->second.second; }
std::string filename = sm.getPresumedLoc(loc).getFilename();
bool isIntercepted = isInterceptedLibHeader(filename);
isInterceptedCache[sm.getFileID(loc)] = {filename, !isIntercepted};
return isIntercepted;
}
示例9: GetTokenBeforeLocation
clang::Token GetTokenBeforeLocation(clang::SourceLocation loc,
const clang::ASTContext& ast_context) {
clang::Token token;
token.setKind(clang::tok::unknown);
clang::LangOptions lang_options = ast_context.getLangOpts();
const clang::SourceManager& source_manager = ast_context.getSourceManager();
clang::SourceLocation file_start_loc =
source_manager.getLocForStartOfFile(source_manager.getFileID(loc));
loc = loc.getLocWithOffset(-1);
while (loc != file_start_loc) {
loc = clang::Lexer::GetBeginningOfToken(loc, source_manager, lang_options);
if (!clang::Lexer::getRawToken(loc, token, source_manager, lang_options)) {
if (!token.is(clang::tok::comment)) {
break;
}
}
loc = loc.getLocWithOffset(-1);
}
return token;
}
示例10: 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;
}
示例11: isIgnored
bool ClangTidyMisraCheck::isIgnored(clang::SourceLocation loc) {
if (loc.isInvalid()) {
return IgnoreInvalidLocations;
}
if (isBuiltIn(loc)) {
return IgnoreBuiltInLocations;
}
if (isCommandLine(loc)) {
return IgnoreCommandLineLocations;
}
return false;
}
示例12: 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()));
}
示例13: 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);
}
示例14: if
void c2ffi::process_macros(clang::CompilerInstance &ci, std::ostream &os) {
using namespace c2ffi;
clang::SourceManager &sm = ci.getSourceManager();
clang::Preprocessor &pp = ci.getPreprocessor();
for(clang::Preprocessor::macro_iterator i = pp.macro_begin();
i != pp.macro_end(); i++) {
const clang::MacroInfo *mi = (*i).second->getMacroInfo();
const clang::SourceLocation sl = mi->getDefinitionLoc();
std::string loc = sl.printToString(sm);
const char *name = (*i).first->getNameStart();
if(mi->isBuiltinMacro() || loc.substr(0,10) == "<built-in>") {
} else if(mi->isFunctionLike()) {
} else if(best_guess type = macro_type(pp, name, mi)) {
os << "/* " << loc << " */" << std::endl;
os << "#define " << name << " "
<< macro_to_string(pp, mi)
<< std::endl << std::endl;
}
}
for(clang::Preprocessor::macro_iterator i = pp.macro_begin();
i != pp.macro_end(); i++) {
clang::MacroInfo *mi = (*i).second->getMacroInfo();
clang::SourceLocation sl = mi->getDefinitionLoc();
std::string loc = sl.printToString(sm);
const char *name = (*i).first->getNameStart();
if(mi->isBuiltinMacro() || loc.substr(0,10) == "<built-in>") {
} else if(mi->isFunctionLike()) {
} else if(best_guess type = macro_type(pp, name, mi)) {
output_redef(pp, name, mi, type, os);
}
}
}
示例15: updateLastEntityLine
void ClangCommentPrinter::updateLastEntityLine(clang::SourceLocation Loc) {
if (Loc.isInvalid())
return;
const auto &Ctx = ClangLoader.getClangASTContext();
const auto &SM = Ctx.getSourceManager();
unsigned LineNo = SM.getSpellingLineNumber(Loc);
clang::FileID FID = SM.getFileID(Loc);
if (FID.isInvalid())
return;
updateLastEntityLine(FID, LineNo);
}