typedef token_kind_t as int
authorMatthias Braun <matthias.braun@kit.edu>
Fri, 25 May 2012 15:51:08 +0000 (17:51 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Sun, 17 Jun 2012 15:00:37 +0000 (17:00 +0200)
The enum was renamed to token_kind_tag_t, because extensions like the
ast-grep branch can register additional tokens. This also avoids
warnings, because we have a clearly defined type for the enum now.

diagnostic.c
parser.c
preprocessor.c
token.c
token_t.h

index 9ac7ecb..c603f46 100644 (file)
@@ -169,7 +169,7 @@ done_flags:;
                                va_list*          toks      = va_arg(ap, va_list*);
                                const char* const delimiter = va_arg(ap, const char*);
                                for (;;) {
-                                       const token_kind_t tok = va_arg(*toks, token_kind_t);
+                                       const token_kind_t tok = (token_kind_t)va_arg(*toks, int);
                                        if (tok == 0)
                                                break;
                                        if (first) {
@@ -180,7 +180,7 @@ done_flags:;
                                        print_token_kind(stderr, tok);
                                }
                        } else {
-                               const token_kind_t token = va_arg(ap, token_kind_t);
+                               const token_kind_t token = (token_kind_t)va_arg(ap, int);
                                print_token_kind(stderr, token);
                        }
                        break;
index 578087e..986b831 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -481,12 +481,17 @@ static inline void next_token(void)
 #endif
 }
 
-#define eat(token_kind) (assert(token.kind == (token_kind)), next_token())
+static inline void eat(token_kind_t const kind)
+{
+       assert(token.kind == kind);
+       (void)kind;
+       next_token();
+}
 
-static inline bool next_if(token_kind_t const type)
+static inline bool next_if(token_kind_t const kind)
 {
-       if (token.kind == type) {
-               eat(type);
+       if (token.kind == kind) {
+               eat(kind);
                return true;
        } else {
                return false;
index 92d4f37..af95d90 100644 (file)
@@ -99,7 +99,7 @@ static const char       *printed_input_name = NULL;
 static source_position_t expansion_pos;
 static pp_definition_t  *current_expansion  = NULL;
 static strset_t          stringset;
-static preprocessor_token_kind_t last_token;
+static token_kind_t      last_token;
 
 static searchpath_entry_t *searchpath;
 
@@ -460,7 +460,9 @@ static string_t sym_make_string(string_encoding_t const enc)
        return (string_t){ result, len, enc };
 }
 
-static void parse_string(utf32 const delimiter, preprocessor_token_kind_t const kind, string_encoding_t const enc, char const *const context)
+static void parse_string(utf32 const delimiter, token_kind_t const kind,
+                         string_encoding_t const enc,
+                         char const *const context)
 {
        const unsigned start_linenr = input.position.lineno;
 
@@ -738,10 +740,10 @@ static void skip_whitespace(void)
        }
 }
 
-static void eat_pp(preprocessor_token_kind_t const type)
+static inline void eat_pp(token_kind_t const kind)
 {
-       (void) type;
-       assert(pp_token.kind == type);
+       assert(pp_token.kind == kind);
+       (void) kind;
        next_preprocessing_token();
 }
 
diff --git a/token.c b/token.c
index 933c3a3..db5c3aa 100644 (file)
--- a/token.c
+++ b/token.c
@@ -47,7 +47,7 @@ static symbol_t *intern_register_token(token_kind_t id, const char *string)
        return symbol;
 }
 
-static symbol_t *intern_register_pp_token(preprocessor_token_kind_t id, const char *string)
+static symbol_t *intern_register_pp_token(token_kind_t id, const char *string)
 {
        assert(id < TP_LAST_TOKEN);
        symbol_t *symbol = symbol_table_insert(string);
@@ -68,7 +68,7 @@ static void register_token(unsigned mode, token_kind_t id, const char *string)
        }
 }
 
-static void register_pp_token(unsigned mode, preprocessor_token_kind_t id,
+static void register_pp_token(unsigned mode, token_kind_t id,
                               const char *string)
 {
        if (! (c_mode & mode))
@@ -200,7 +200,7 @@ void print_pp_token_kind(FILE *f, int token_kind)
 
 void print_pp_token(FILE *f, const token_t *token)
 {
-       switch((preprocessor_token_kind_t) token->kind) {
+       switch ((token_kind_t)token->kind) {
        case TP_IDENTIFIER:
                fprintf(f, "identifier '%s'", token->base.symbol->string);
                break;
@@ -211,13 +211,12 @@ void print_pp_token(FILE *f, const token_t *token)
                fprintf(f, "string \"%s\"", token->literal.string.begin);
                break;
        default:
-               print_pp_token_kind(f, (preprocessor_token_kind_t) token->kind);
+               print_pp_token_kind(f, (token_kind_t) token->kind);
                break;
        }
 }
 
-bool tokens_would_paste(preprocessor_token_kind_t token1,
-                        preprocessor_token_kind_t token2)
+bool tokens_would_paste(token_kind_t token1, token_kind_t token2)
 {
        char c = token2 < 256 ? (char) token2 : pp_token_symbols[token2]->string[0];
 
index 741845d..ab49825 100644 (file)
--- a/token_t.h
+++ b/token_t.h
@@ -26,7 +26,7 @@
 #include "symbol_table.h"
 #include "type.h"
 
-typedef enum token_kind_t {
+typedef enum token_kind_tag_t {
        T_NULL  =  0,
        T_EOF   = '\x04', // EOT
 #define T(mode,x,str,val) T_##x val,
@@ -35,9 +35,9 @@ typedef enum token_kind_t {
 #undef TS
 #undef T
        T_LAST_TOKEN
-} token_kind_t;
+} token_kind_tag_t;
 
-typedef enum preprocessor_token_kind_t {
+typedef enum preprocessor_token_kind_tag_t {
        TP_NULL  = T_NULL,
        TP_EOF   = T_EOF,
 #define T(mode,x,str,val) TP_##x val,
@@ -46,7 +46,8 @@ typedef enum preprocessor_token_kind_t {
 #undef TS
 #undef T
        TP_LAST_TOKEN
-} preprocessor_token_kind_t;
+} preprocessor_token_kind_tag_t;
+typedef unsigned short token_kind_t;
 
 typedef struct source_position_t source_position_t;
 struct source_position_t {
@@ -64,7 +65,7 @@ typedef struct literal_t    literal_t;
 typedef union  token_t      token_t;
 
 struct token_base_t {
-       unsigned          kind;
+       token_kind_t      kind;
        source_position_t source_position;
        symbol_t         *symbol;
 };
@@ -94,7 +95,6 @@ void print_pp_token(FILE *out, const token_t *token);
  * returns true if pasting 2 preprocessing tokens next to each other
  * without a space in between would generate (an)other preprocessing token(s)
  */
-bool tokens_would_paste(preprocessor_token_kind_t token1,
-                        preprocessor_token_kind_t token2);
+bool tokens_would_paste(token_kind_t token1, token_kind_t token2);
 
 #endif