From f52c0b261cb09bda8d39821f264578b7c5f181bf Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 15 Feb 2009 21:26:50 +0000 Subject: add a new SourceManager::getInstantiationRange helper method. llvm-svn: 64606 --- clang/lib/Basic/SourceManager.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'clang/lib/Basic/SourceManager.cpp') 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 +SourceManager::getInstantiationRange(SourceLocation Loc) const { + if (Loc.isFileID()) return std::make_pair(Loc, Loc); + + std::pair 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; +} + //===----------------------------------------------------------------------===// -- cgit v1.2.3