From: Argyrios Kyrtzidis Date: Wed, 12 Oct 2011 07:07:40 +0000 (+0000) Subject: Introduce SourceManager::getFileLoc which returns a file location X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=796dbfb6c43336f58c026137c438e53eadc381f7;p=clang Introduce SourceManager::getFileLoc which returns a file location taking into account macro arguments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141771 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 12e7cdfc20..985ddd6412 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -828,6 +828,14 @@ public: return getExpansionLocSlowCase(Loc); } + /// \brief Given \arg Loc, if it is a macro location return the expansion + /// location or the spelling location, depending on if it comes from a + /// macro argument or not. + SourceLocation getFileLoc(SourceLocation Loc) const { + if (Loc.isFileID()) return Loc; + return getFileLocSlowCase(Loc); + } + /// getImmediateExpansionRange - Loc is required to be an expansion location. /// Return the start/end of the expansion information. std::pair @@ -1301,6 +1309,7 @@ private: SourceLocation getExpansionLocSlowCase(SourceLocation Loc) const; SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const; + SourceLocation getFileLocSlowCase(SourceLocation Loc) const; std::pair getDecomposedExpansionLocSlowCase(const SrcMgr::SLocEntry *E) const; diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index a540f3b945..364663ee32 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -815,6 +815,16 @@ SourceLocation SourceManager::getSpellingLocSlowCase(SourceLocation Loc) const { return Loc; } +SourceLocation SourceManager::getFileLocSlowCase(SourceLocation Loc) const { + do { + if (isMacroArgExpansion(Loc)) + Loc = getImmediateSpellingLoc(Loc); + else + Loc = getImmediateExpansionRange(Loc).first; + } while (!Loc.isFileID()); + return Loc; +} + std::pair SourceManager::getDecomposedExpansionLocSlowCase(