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.

llvm-svn: 198607

clang/include/clang/Basic/Diagnostic.h
clang/include/clang/Basic/TokenKinds.h
clang/include/clang/Lex/Token.h

index 97f2e80..c04d2fd 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 f7a5f9e..5ba168e 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 4f6391d..580bb12 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() {