[PATCH] D42458: [NFC] Extract method to SourceManager for traversing the macro "stack"
George Karpenkov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 9 15:33:50 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324780: [NFC] Extract method to SourceManager for traversing the macro "stack" (authored by george.karpenkov, committed by ).
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D42458?vs=131187&id=133704#toc
Repository:
rL LLVM
https://reviews.llvm.org/D42458
Files:
cfe/trunk/include/clang/Basic/SourceManager.h
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/Edit/Commit.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
Index: cfe/trunk/include/clang/Basic/SourceManager.h
===================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h
+++ cfe/trunk/include/clang/Basic/SourceManager.h
@@ -1646,6 +1646,9 @@
return getImmediateExpansionRange(Loc).first;
}
+ /// \return Location of the top-level macro caller.
+ SourceLocation getTopMacroCallerLoc(SourceLocation Loc) const;
+
private:
friend class ASTReader;
friend class ASTWriter;
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -9357,11 +9357,8 @@
// Venture through the macro stacks to get to the source of macro arguments.
// The new location is a better location than the complete location that was
// passed in.
- while (S.SourceMgr.isMacroArgExpansion(Loc))
- Loc = S.SourceMgr.getImmediateMacroCallerLoc(Loc);
-
- while (S.SourceMgr.isMacroArgExpansion(CC))
- CC = S.SourceMgr.getImmediateMacroCallerLoc(CC);
+ Loc = S.SourceMgr.getTopMacroCallerLoc(Loc);
+ CC = S.SourceMgr.getTopMacroCallerLoc(CC);
// __null is usually wrapped in a macro. Go up a macro if that is the case.
if (NullKind == Expr::NPCK_GNUNull && Loc.isMacroID()) {
Index: cfe/trunk/lib/Edit/Commit.cpp
===================================================================
--- cfe/trunk/lib/Edit/Commit.cpp
+++ cfe/trunk/lib/Edit/Commit.cpp
@@ -225,8 +225,7 @@
isAtStartOfMacroExpansion(loc, &loc);
const SourceManager &SM = SourceMgr;
- while (SM.isMacroArgExpansion(loc))
- loc = SM.getImmediateSpellingLoc(loc);
+ loc = SM.getTopMacroCallerLoc(loc);
if (loc.isMacroID())
if (!isAtStartOfMacroExpansion(loc, &loc))
@@ -256,8 +255,7 @@
isAtEndOfMacroExpansion(loc, &loc);
const SourceManager &SM = SourceMgr;
- while (SM.isMacroArgExpansion(loc))
- loc = SM.getImmediateSpellingLoc(loc);
+ loc = SM.getTopMacroCallerLoc(loc);
if (loc.isMacroID())
if (!isAtEndOfMacroExpansion(loc, &loc))
Index: cfe/trunk/lib/Basic/SourceManager.cpp
===================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp
+++ cfe/trunk/lib/Basic/SourceManager.cpp
@@ -955,6 +955,12 @@
return Expansion.getExpansionLocRange();
}
+SourceLocation SourceManager::getTopMacroCallerLoc(SourceLocation Loc) const {
+ while (isMacroArgExpansion(Loc))
+ Loc = getImmediateSpellingLoc(Loc);
+ return Loc;
+}
+
/// getExpansionRange - Given a SourceLocation object, return the range of
/// tokens covered by the expansion in the ultimate file.
std::pair<SourceLocation,SourceLocation>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42458.133704.patch
Type: text/x-patch
Size: 2714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180209/93592334/attachment.bin>
More information about the llvm-commits
mailing list