aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Basic/SourceManager.h
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 /include/clang/Basic/SourceManager.h
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 'include/clang/Basic/SourceManager.h')
-rw-r--r--include/clang/Basic/SourceManager.h44
1 files changed, 35 insertions, 9 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h
index 77ad2b2086..d5845baa31 100644
--- a/include/clang/Basic/SourceManager.h
+++ b/include/clang/Basic/SourceManager.h
@@ -177,23 +177,43 @@ namespace SrcMgr {
/// location - where the token was ultimately instantiated, and the
/// SpellingLoc - where the actual character data for the token came from.
class InstantiationInfo {
- unsigned InstantiationLoc, SpellingLoc; // Really these are SourceLocations.
+ // Really these are all SourceLocations.
+
+ /// SpellingLoc - Where the spelling for the token can be found.
+ unsigned SpellingLoc;
+
+ /// InstantiationLocStart/InstantiationLocEnd - In a macro expansion, these
+ /// indicate the start and end of the instantiation. In object-line macros,
+ /// these will be the same. In a function-like macro instantiation, the
+ /// start will be the identifier and the end will be the ')'.
+ unsigned InstantiationLocStart, InstantiationLocEnd;
public:
- SourceLocation getInstantiationLoc() const {
- return SourceLocation::getFromRawEncoding(InstantiationLoc);
- }
SourceLocation getSpellingLoc() const {
return SourceLocation::getFromRawEncoding(SpellingLoc);
}
+ SourceLocation getInstantiationLocStart() const {
+ return SourceLocation::getFromRawEncoding(InstantiationLocStart);
+ }
+ SourceLocation getInstantiationLocEnd() const {
+ return SourceLocation::getFromRawEncoding(InstantiationLocEnd);
+ }
+
+ std::pair<SourceLocation,SourceLocation> getInstantiationLocRange() const {
+ return std::make_pair(getInstantiationLocStart(),
+ getInstantiationLocEnd());
+ }
- /// get - Return a InstantiationInfo for an expansion. VL specifies
+ /// get - Return a InstantiationInfo for an expansion. IL specifies
/// the instantiation location (where the macro is expanded), and SL
/// specifies the spelling location (where the characters from the token
- /// come from). Both VL and PL refer to normal File SLocs.
- static InstantiationInfo get(SourceLocation IL, SourceLocation SL) {
+ /// come from). IL and PL can both refer to normal File SLocs or
+ /// instantiation locations.
+ static InstantiationInfo get(SourceLocation ILStart, SourceLocation ILEnd,
+ SourceLocation SL) {
InstantiationInfo X;
- X.InstantiationLoc = IL.getRawEncoding();
X.SpellingLoc = SL.getRawEncoding();
+ X.InstantiationLocStart = ILStart.getRawEncoding();
+ X.InstantiationLocEnd = ILEnd.getRawEncoding();
return X;
}
};
@@ -354,7 +374,8 @@ public:
/// that a token at Loc should actually be referenced from InstantiationLoc.
/// TokLength is the length of the token being instantiated.
SourceLocation createInstantiationLoc(SourceLocation Loc,
- SourceLocation InstantiationLoc,
+ SourceLocation InstantiationLocStart,
+ SourceLocation InstantiationLocEnd,
unsigned TokLength);
//===--------------------------------------------------------------------===//
@@ -413,6 +434,11 @@ public:
return getInstantiationLocSlowCase(Loc);
}
+ /// getImmediateInstantiationRange - Loc is required to be an instantiation
+ /// location. Return the start/end of the instantiation information.
+ std::pair<SourceLocation,SourceLocation>
+ getImmediateInstantiationRange(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.