[cfe-commits] r64606 - in /cfe/trunk: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Lex/PPMacroExpansion.cpp
Chris Lattner
sabre at nondot.org
Sun Feb 15 13:26:50 PST 2009
Author: lattner
Date: Sun Feb 15 15:26:50 2009
New Revision: 64606
URL: http://llvm.org/viewvc/llvm-project?rev=64606&view=rev
Log:
add a new SourceManager::getInstantiationRange helper method.
Modified:
cfe/trunk/include/clang/Basic/SourceManager.h
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=64606&r1=64605&r2=64606&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Sun Feb 15 15:26:50 2009
@@ -425,8 +425,8 @@
return SourceLocation::getFileLoc(FileOffset);
}
- /// Given a SourceLocation object, return the instantiation location
- /// referenced by the ID.
+ /// getInstantiationLoc - Given a SourceLocation object, return the
+ /// instantiation location referenced by the ID.
SourceLocation getInstantiationLoc(SourceLocation Loc) const {
// Handle the non-mapped case inline, defer to out of line code to handle
// instantiations.
@@ -439,6 +439,12 @@
std::pair<SourceLocation,SourceLocation>
getImmediateInstantiationRange(SourceLocation Loc) const;
+ /// getInstantiationRange - Given a SourceLocation object, return the
+ /// range of tokens covered by the instantiation in the ultimate file.
+ std::pair<SourceLocation,SourceLocation>
+ getInstantiationRange(SourceLocation Loc) const;
+
+
/// getSpellingLoc - Given a SourceLocation object, return the spelling
/// location referenced by the ID. This is the place where the characters
/// that make up the lexed token can be found.
Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=64606&r1=64605&r2=64606&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Sun Feb 15 15:26:50 2009
@@ -606,6 +606,24 @@
return II.getInstantiationLocRange();
}
+/// getInstantiationRange - Given a SourceLocation object, return the
+/// range of tokens covered by the instantiation in the ultimate file.
+std::pair<SourceLocation,SourceLocation>
+SourceManager::getInstantiationRange(SourceLocation Loc) const {
+ if (Loc.isFileID()) return std::make_pair(Loc, Loc);
+
+ std::pair<SourceLocation,SourceLocation> Res =
+ getImmediateInstantiationRange(Loc);
+
+ // Fully resolve the start and end locations to their ultimate instantiation
+ // points.
+ while (!Res.first.isFileID())
+ Res.first = getImmediateInstantiationRange(Res.first).first;
+ while (!Res.second.isFileID())
+ Res.second = getImmediateInstantiationRange(Res.second).second;
+ return Res;
+}
+
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=64606&r1=64605&r2=64606&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sun Feb 15 15:26:50 2009
@@ -471,9 +471,7 @@
// can matter for a function-like macro that expands to contain __LINE__.
// Skip down through instantiation points until we find a file loc for the
// end of the instantiation history.
- while (!Loc.isFileID())
- Loc = SourceMgr.getImmediateInstantiationRange(Loc).second;
-
+ Loc = SourceMgr.getInstantiationRange(Loc).second;
PresumedLoc PLoc = SourceMgr.getPresumedLoc(Loc);
// __LINE__ expands to a simple numeric value. Add a space after it so that
More information about the cfe-commits
mailing list