diff options
Diffstat (limited to 'include/clang/Lex/Token.h')
-rw-r--r-- | include/clang/Lex/Token.h | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/include/clang/Lex/Token.h b/include/clang/Lex/Token.h index 4a53c9c..e087809 100644 --- a/include/clang/Lex/Token.h +++ b/include/clang/Lex/Token.h @@ -35,8 +35,8 @@ class IdentifierInfo; /// can be represented by a single typename annotation token that carries /// information about the SourceRange of the tokens and the type object. class Token { - /// The location of the token. - SourceLocation Loc; + /// The location of the token. This is actually a SourceLocation. + unsigned Loc; // Conceptually these next two fields could be in a union. However, this // causes gcc 4.2 to pessimize LexTokenInternal, a very performance critical @@ -114,13 +114,15 @@ public: /// \brief Return a source location identifier for the specified /// offset in the current file. - SourceLocation getLocation() const { return Loc; } + SourceLocation getLocation() const { + return SourceLocation::getFromRawEncoding(Loc); + } unsigned getLength() const { assert(!isAnnotation() && "Annotation tokens have no length field"); return UintData; } - void setLocation(SourceLocation L) { Loc = L; } + void setLocation(SourceLocation L) { Loc = L.getRawEncoding(); } void setLength(unsigned Len) { assert(!isAnnotation() && "Annotation tokens have no length field"); UintData = Len; @@ -128,7 +130,7 @@ public: SourceLocation getAnnotationEndLoc() const { assert(isAnnotation() && "Used AnnotEndLocID on non-annotation token"); - return SourceLocation::getFromRawEncoding(UintData); + return SourceLocation::getFromRawEncoding(UintData ? UintData : Loc); } void setAnnotationEndLoc(SourceLocation L) { assert(isAnnotation() && "Used AnnotEndLocID on non-annotation token"); @@ -139,6 +141,11 @@ public: return isAnnotation() ? getAnnotationEndLoc() : getLocation(); } + SourceLocation getEndLoc() const { + return isAnnotation() ? getAnnotationEndLoc() + : getLocation().getLocWithOffset(getLength()); + } + /// \brief SourceRange of the group of tokens that this annotation token /// represents. SourceRange getAnnotationRange() const { @@ -157,7 +164,7 @@ public: Flags = 0; PtrData = nullptr; UintData = 0; - Loc = SourceLocation(); + Loc = SourceLocation().getRawEncoding(); } IdentifierInfo *getIdentifierInfo() const { |