From b8951e782399c301c6cedff8c8d7a3aecf968368 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Mon, 6 Jan 2014 12:54:51 +0000 Subject: [PATCH] Correct underlying integer type of enum TokenKind This matches up the underlying type against the actual storage type 'unsigned short' and lets us get rid of some casts while we're at it. Effort is made to keep this building in pre-C++11 but as with other features Token will be less efficiently packed in in legacy configurations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198607 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Diagnostic.h | 2 +- include/clang/Basic/TokenKinds.h | 2 +- include/clang/Lex/Token.h | 13 +++++-------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 97f2e80244..c04d2fd9b7 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -40,7 +40,7 @@ namespace clang { class StoredDiagnostic; #if LLVM_HAS_STRONG_ENUMS namespace tok { - enum TokenKind : unsigned; + enum TokenKind : unsigned short; } #endif diff --git a/include/clang/Basic/TokenKinds.h b/include/clang/Basic/TokenKinds.h index f7a5f9eef9..5ba168e215 100644 --- a/include/clang/Basic/TokenKinds.h +++ b/include/clang/Basic/TokenKinds.h @@ -22,7 +22,7 @@ namespace clang { namespace tok { /// \brief Provides a simple uniform namespace for tokens from all C languages. -enum TokenKind LLVM_ENUM_INT_TYPE(unsigned) { +enum TokenKind LLVM_ENUM_INT_TYPE(unsigned short) { #define TOK(X) X, #include "clang/Basic/TokenKinds.def" NUM_TOKENS diff --git a/include/clang/Lex/Token.h b/include/clang/Lex/Token.h index 4f6391d650..580bb128c5 100644 --- a/include/clang/Lex/Token.h +++ b/include/clang/Lex/Token.h @@ -62,8 +62,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 +82,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,9 +144,7 @@ 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() { -- 2.40.0