aboutsummaryrefslogtreecommitdiff
path: root/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-15 20:52:18 +0000
committerChris Lattner <sabre@nondot.org>2009-02-15 20:52:18 +0000
commite7fb48466afcbf2c4ccdfa658824282fdc3c512c (patch)
tree4c2ea5e76f59eb02d41ce34a981cf1c19227ec87 /lib/Basic/SourceManager.cpp
parent3ada6ffd92e02b02f1cdb3c2044aab24dbe0b755 (diff)
track "just a little more" location information for macro instantiations.
Now instead of just tracking the expansion history, also track the full range of the macro that got replaced. For object-like macros, this doesn't change anything. For _Pragma and function-like macros, this means we track the locations of the ')'. This is required for PR3579 because apparently GCC uses the line of the ')' of a function-like macro as the location to expand __LINE__ to. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64601 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/SourceManager.cpp')
-rw-r--r--lib/Basic/SourceManager.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp
index e023a91f2f..71bda5b255 100644
--- a/lib/Basic/SourceManager.cpp
+++ b/lib/Basic/SourceManager.cpp
@@ -352,7 +352,7 @@ void SourceManager::clearIDTables() {
// Use up FileID #0 as an invalid instantiation.
NextOffset = 0;
- createInstantiationLoc(SourceLocation(), SourceLocation(), 1);
+ createInstantiationLoc(SourceLocation(),SourceLocation(),SourceLocation(), 1);
}
/// getOrCreateContentCache - Create or return a cached ContentCache for the
@@ -418,11 +418,11 @@ FileID SourceManager::createFileID(const ContentCache *File,
/// that a token from SpellingLoc should actually be referenced from
/// InstantiationLoc.
SourceLocation SourceManager::createInstantiationLoc(SourceLocation SpellingLoc,
- SourceLocation InstantLoc,
+ SourceLocation ILocStart,
+ SourceLocation ILocEnd,
unsigned TokLength) {
- SLocEntryTable.push_back(SLocEntry::get(NextOffset,
- InstantiationInfo::get(InstantLoc,
- SpellingLoc)));
+ InstantiationInfo II = InstantiationInfo::get(ILocStart,ILocEnd, SpellingLoc);
+ SLocEntryTable.push_back(SLocEntry::get(NextOffset, II));
assert(NextOffset+TokLength+1 > NextOffset && "Ran out of source locations!");
NextOffset += TokLength+1;
return SourceLocation::getMacroLoc(NextOffset-(TokLength+1));
@@ -543,7 +543,8 @@ SourceLocation SourceManager::
getInstantiationLocSlowCase(SourceLocation Loc) const {
do {
std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc);
- Loc =getSLocEntry(LocInfo.first).getInstantiation().getInstantiationLoc();
+ Loc = getSLocEntry(LocInfo.first).getInstantiation()
+ .getInstantiationLocStart();
Loc = Loc.getFileLocWithOffset(LocInfo.second);
} while (!Loc.isFileID());
@@ -568,7 +569,7 @@ SourceManager::getDecomposedInstantiationLocSlowCase(const SrcMgr::SLocEntry *E,
FileID FID;
SourceLocation Loc;
do {
- Loc = E->getInstantiation().getInstantiationLoc();
+ Loc = E->getInstantiation().getInstantiationLocStart();
FID = getFileID(Loc);
E = &getSLocEntry(FID);
@@ -596,6 +597,16 @@ SourceManager::getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
return std::make_pair(FID, Offset);
}
+/// getImmediateInstantiationRange - Loc is required to be an instantiation
+/// location. Return the start/end of the instantiation information.
+std::pair<SourceLocation,SourceLocation>
+SourceManager::getImmediateInstantiationRange(SourceLocation Loc) const {
+ assert(Loc.isMacroID() && "Not an instantiation loc!");
+ const InstantiationInfo &II = getSLocEntry(getFileID(Loc)).getInstantiation();
+ return II.getInstantiationLocRange();
+}
+
+
//===----------------------------------------------------------------------===//
// Queries about the code at a SourceLocation.