]> granicus.if.org Git - clang/commitdiff
Correct underlying integer type of enum TokenKind
authorAlp Toker <alp@nuanti.com>
Mon, 6 Jan 2014 12:54:51 +0000 (12:54 +0000)
committerAlp Toker <alp@nuanti.com>
Mon, 6 Jan 2014 12:54:51 +0000 (12:54 +0000)
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
include/clang/Basic/TokenKinds.h
include/clang/Lex/Token.h

index 97f2e80244c4601352b6cdbd6129424c345e5286..c04d2fd9b7b176a0507622e3eaa445da5008e6d7 100644 (file)
@@ -40,7 +40,7 @@ namespace clang {
   class StoredDiagnostic;
 #if LLVM_HAS_STRONG_ENUMS
   namespace tok {
-  enum TokenKind : unsigned;
+  enum TokenKind : unsigned short;
   }
 #endif
 
index f7a5f9eef92875d5bc49fcabd12ef3c275f89ea1..5ba168e21551f8486246e03bf0db250450e708e2 100644 (file)
@@ -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
index 4f6391d6502d5a4f2877ccb29245c22feb92ae4f..580bb128c5ec4b315fc6eb4a316e458f6e93ed4b 100644 (file)
@@ -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() {