summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-15 21:26:50 +0000
committerChris Lattner <sabre@nondot.org>2009-02-15 21:26:50 +0000
commitf52c0b261cb09bda8d39821f264578b7c5f181bf (patch)
treeebdd0c240f4eb116611c8457ab57adc020af255f
parent641f1eab779ee5b52bc9be19652a8e1d65508b3d (diff)
downloadbcm5719-llvm-f52c0b261cb09bda8d39821f264578b7c5f181bf.tar.gz
bcm5719-llvm-f52c0b261cb09bda8d39821f264578b7c5f181bf.zip
add a new SourceManager::getInstantiationRange helper method.
llvm-svn: 64606
-rw-r--r--clang/include/clang/Basic/SourceManager.h10
-rw-r--r--clang/lib/Basic/SourceManager.cpp18
-rw-r--r--clang/lib/Lex/PPMacroExpansion.cpp4
3 files changed, 27 insertions, 5 deletions
diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index d5845baa31a..b29a1acd4a5 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -425,8 +425,8 @@ public:
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 @@ public:
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.
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 71bda5b255f..88980efcdaa 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -606,6 +606,24 @@ SourceManager::getImmediateInstantiationRange(SourceLocation Loc) const {
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;
+}
+
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index 33b5ef86568..a8b09e5edee 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -471,9 +471,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
// 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
OpenPOWER on IntegriCloud