aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-07-07 21:54:45 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-07-07 21:54:45 +0000
commit7a759606d93975866051f67104ae58446e55f404 (patch)
tree7cea5f3d5011bf43b5ba37f3163aa33b3e48ccb1 /lib
parent14ef3191a75b8bcdab391e6ffa6367b731c2ce67 (diff)
Move SourceManager::isAt[Start/End]OfMacroInstantiation functions to the Lexer, since they depend on it now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134644 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/ARCMigrate/TransformActions.cpp4
-rw-r--r--lib/ARCMigrate/Transforms.cpp2
-rw-r--r--lib/Basic/SourceManager.cpp55
-rw-r--r--lib/Lex/Lexer.cpp53
-rw-r--r--lib/Parse/ParseExpr.cpp3
5 files changed, 56 insertions, 61 deletions
diff --git a/lib/ARCMigrate/TransformActions.cpp b/lib/ARCMigrate/TransformActions.cpp
index 2ae979896a..3e49942788 100644
--- a/lib/ARCMigrate/TransformActions.cpp
+++ b/lib/ARCMigrate/TransformActions.cpp
@@ -388,7 +388,7 @@ bool TransformActionsImpl::canInsert(SourceLocation loc) {
if (loc.isFileID())
return true;
- return SM.isAtStartOfMacroInstantiation(loc, Ctx.getLangOptions());
+ return PP.isAtStartOfMacroInstantiation(loc);
}
bool TransformActionsImpl::canInsertAfterToken(SourceLocation loc) {
@@ -401,7 +401,7 @@ bool TransformActionsImpl::canInsertAfterToken(SourceLocation loc) {
if (loc.isFileID())
return true;
- return SM.isAtEndOfMacroInstantiation(loc, Ctx.getLangOptions());
+ return PP.isAtEndOfMacroInstantiation(loc);
}
bool TransformActionsImpl::canRemoveRange(SourceRange range) {
diff --git a/lib/ARCMigrate/Transforms.cpp b/lib/ARCMigrate/Transforms.cpp
index 80c52d7940..546829120c 100644
--- a/lib/ARCMigrate/Transforms.cpp
+++ b/lib/ARCMigrate/Transforms.cpp
@@ -37,7 +37,7 @@ SourceLocation trans::findLocationAfterSemi(SourceLocation loc,
ASTContext &Ctx) {
SourceManager &SM = Ctx.getSourceManager();
if (loc.isMacroID()) {
- if (!SM.isAtEndOfMacroInstantiation(loc, Ctx.getLangOptions()))
+ if (!Lexer::isAtEndOfMacroInstantiation(loc, SM, Ctx.getLangOptions()))
return SourceLocation();
loc = SM.getInstantiationRange(loc).second;
}
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp
index 137da0d87a..cd098b23aa 100644
--- a/lib/Basic/SourceManager.cpp
+++ b/lib/Basic/SourceManager.cpp
@@ -11,7 +11,6 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/Lex/Lexer.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/SourceManagerInternals.h"
#include "clang/Basic/Diagnostic.h"
@@ -1215,60 +1214,6 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc) const {
return PresumedLoc(Filename, LineNo, ColNo, IncludeLoc);
}
-/// \brief Returns true if the given MacroID location points at the first
-/// token of the macro instantiation.
-bool SourceManager::isAtStartOfMacroInstantiation(SourceLocation loc,
- const LangOptions &LangOpts) const {
- assert(loc.isValid() && loc.isMacroID() && "Expected a valid macro loc");
-
- std::pair<FileID, unsigned> infoLoc = getDecomposedLoc(loc);
- // FIXME: If the token comes from the macro token paste operator ('##')
- // this function will always return false;
- if (infoLoc.second > 0)
- return false; // Does not point at the start of token.
-
- SourceLocation instLoc =
- getSLocEntry(infoLoc.first).getInstantiation().getInstantiationLocStart();
- if (instLoc.isFileID())
- return true; // No other macro instantiations, this is the first.
-
- return isAtStartOfMacroInstantiation(instLoc, LangOpts);
-}
-
-/// \brief Returns true if the given MacroID location points at the last
-/// token of the macro instantiation.
-bool SourceManager::isAtEndOfMacroInstantiation(SourceLocation loc,
- const LangOptions &LangOpts) const {
- assert(loc.isValid() && loc.isMacroID() && "Expected a valid macro loc");
-
- SourceLocation spellLoc = getSpellingLoc(loc);
- unsigned tokLen = Lexer::MeasureTokenLength(spellLoc, *this, LangOpts);
- if (tokLen == 0)
- return false;
-
- std::pair<FileID, unsigned> infoLoc = getDecomposedLoc(loc);
- unsigned FID = infoLoc.first.ID;
-
- unsigned NextOffset;
- if (FID+1 == sloc_entry_size())
- NextOffset = getNextOffset();
- else
- NextOffset = getSLocEntry(FID+1).getOffset();
-
- // FIXME: If the token comes from the macro token paste operator ('##')
- // or the stringify operator ('#') this function will always return false;
- assert(loc.getOffset() + tokLen < NextOffset);
- if (loc.getOffset() + tokLen < NextOffset-1)
- return false; // Does not point to the last token.
-
- SourceLocation instLoc =
- getSLocEntry(infoLoc.first).getInstantiation().getInstantiationLocEnd();
- if (instLoc.isFileID())
- return true; // No other macro instantiations.
-
- return isAtEndOfMacroInstantiation(instLoc, LangOpts);
-}
-
//===----------------------------------------------------------------------===//
// Other miscellaneous methods.
//===----------------------------------------------------------------------===//
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index 6d25d2b2cf..aabba0aa56 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -683,7 +683,7 @@ SourceLocation Lexer::getLocForEndOfToken(SourceLocation Loc, unsigned Offset,
return SourceLocation();
if (Loc.isMacroID()) {
- if (Offset > 0 || !SM.isAtEndOfMacroInstantiation(Loc, Features))
+ if (Offset > 0 || !isAtEndOfMacroInstantiation(Loc, SM, Features))
return SourceLocation(); // Points inside the macro instantiation.
// Continue and find the location just after the macro instantiation.
@@ -699,6 +699,57 @@ SourceLocation Lexer::getLocForEndOfToken(SourceLocation Loc, unsigned Offset,
return Loc.getFileLocWithOffset(Len);
}
+/// \brief Returns true if the given MacroID location points at the first
+/// token of the macro instantiation.
+bool Lexer::isAtStartOfMacroInstantiation(SourceLocation loc,
+ const SourceManager &SM,
+ const LangOptions &LangOpts) {
+ assert(loc.isValid() && loc.isMacroID() && "Expected a valid macro loc");
+
+ std::pair<FileID, unsigned> infoLoc = SM.getDecomposedLoc(loc);
+ // FIXME: If the token comes from the macro token paste operator ('##')
+ // this function will always return false;
+ if (infoLoc.second > 0)
+ return false; // Does not point at the start of token.
+
+ SourceLocation instLoc =
+ SM.getSLocEntry(infoLoc.first).getInstantiation().getInstantiationLocStart();
+ if (instLoc.isFileID())
+ return true; // No other macro instantiations, this is the first.
+
+ return isAtStartOfMacroInstantiation(instLoc, SM, LangOpts);
+}
+
+/// \brief Returns true if the given MacroID location points at the last
+/// token of the macro instantiation.
+bool Lexer::isAtEndOfMacroInstantiation(SourceLocation loc,
+ const SourceManager &SM,
+ const LangOptions &LangOpts) {
+ assert(loc.isValid() && loc.isMacroID() && "Expected a valid macro loc");
+
+ SourceLocation spellLoc = SM.getSpellingLoc(loc);
+ unsigned tokLen = MeasureTokenLength(spellLoc, SM, LangOpts);
+ if (tokLen == 0)
+ return false;
+
+ FileID FID = SM.getFileID(loc);
+ SourceLocation afterLoc = loc.getFileLocWithOffset(tokLen+1);
+ if (!SM.isBeforeInSourceLocationOffset(afterLoc, SM.getNextOffset()))
+ return true; // We got past the last FileID, this points to the last token.
+
+ // FIXME: If the token comes from the macro token paste operator ('##')
+ // or the stringify operator ('#') this function will always return false;
+ if (FID == SM.getFileID(afterLoc))
+ return false; // Still in the same FileID, does not point to the last token.
+
+ SourceLocation instLoc =
+ SM.getSLocEntry(FID).getInstantiation().getInstantiationLocEnd();
+ if (instLoc.isFileID())
+ return true; // No other macro instantiations.
+
+ return isAtEndOfMacroInstantiation(instLoc, SM, LangOpts);
+}
+
//===----------------------------------------------------------------------===//
// Character information.
//===----------------------------------------------------------------------===//
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index f8652e0074..7df43d7874 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -310,8 +310,7 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
SourceLocation FILoc = Tok.getLocation();
const char *FIText = ": ";
const SourceManager &SM = PP.getSourceManager();
- if (FILoc.isFileID() ||
- SM.isAtStartOfMacroInstantiation(FILoc, getLang())) {
+ if (FILoc.isFileID() || PP.isAtStartOfMacroInstantiation(FILoc)) {
FILoc = SM.getInstantiationLoc(FILoc);
bool IsInvalid = false;
const char *SourcePtr =