diff options
Diffstat (limited to 'include/clang/Lex/Token.h')
| -rw-r--r-- | include/clang/Lex/Token.h | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/include/clang/Lex/Token.h b/include/clang/Lex/Token.h index 4f6391d6502d5..c8b77d11747ea 100644 --- a/include/clang/Lex/Token.h +++ b/include/clang/Lex/Token.h @@ -18,6 +18,7 @@ #include "clang/Basic/SourceLocation.h" #include "clang/Basic/TemplateKinds.h" #include "clang/Basic/TokenKinds.h" +#include "llvm/ADT/StringRef.h" #include <cstdlib> namespace clang { @@ -62,8 +63,7 @@ class Token { void *PtrData; /// Kind - The actual flavor of token this is. - /// - unsigned short Kind; + tok::TokenKind Kind; /// Flags - Bits we track about this token, members of the TokenFlags enum. unsigned char Flags; @@ -83,13 +83,13 @@ public: IgnoredComma = 0x80 // This comma is not a macro argument separator (MS). }; - tok::TokenKind getKind() const { return (tok::TokenKind)Kind; } + tok::TokenKind getKind() const { return Kind; } void setKind(tok::TokenKind K) { Kind = K; } /// is/isNot - Predicates to check if this token is a specific kind, as in /// "if (Tok.is(tok::l_brace)) {...}". - bool is(tok::TokenKind K) const { return Kind == (unsigned) K; } - bool isNot(tok::TokenKind K) const { return Kind != (unsigned) K; } + bool is(tok::TokenKind K) const { return Kind == K; } + bool isNot(tok::TokenKind K) const { return Kind != K; } /// \brief Return true if this is a raw identifier (when lexing /// in raw mode) or a non-keyword identifier (when lexing in non-raw mode). @@ -145,15 +145,13 @@ public: setAnnotationEndLoc(R.getEnd()); } - const char *getName() const { - return tok::getTokenName( (tok::TokenKind) Kind); - } + const char *getName() const { return tok::getTokenName(Kind); } /// \brief Reset all flags to cleared. void startToken() { Kind = tok::unknown; Flags = 0; - PtrData = 0; + PtrData = nullptr; UintData = 0; Loc = SourceLocation(); } @@ -163,19 +161,19 @@ public: "getIdentifierInfo() on a tok::raw_identifier token!"); assert(!isAnnotation() && "getIdentifierInfo() on an annotation token!"); - if (isLiteral()) return 0; + if (isLiteral()) return nullptr; return (IdentifierInfo*) PtrData; } void setIdentifierInfo(IdentifierInfo *II) { PtrData = (void*) II; } - /// getRawIdentifierData - For a raw identifier token (i.e., an identifier - /// lexed in raw mode), returns a pointer to the start of it in the text - /// buffer if known, null otherwise. - const char *getRawIdentifierData() const { + /// getRawIdentifier - For a raw identifier token (i.e., an identifier + /// lexed in raw mode), returns a reference to the text substring in the + /// buffer if known. + StringRef getRawIdentifier() const { assert(is(tok::raw_identifier)); - return reinterpret_cast<const char*>(PtrData); + return StringRef(reinterpret_cast<const char *>(PtrData), getLength()); } void setRawIdentifierData(const char *Ptr) { assert(is(tok::raw_identifier)); |
