ast2firm: Implement casting from complex to real types.
[cparser] / token.c
diff --git a/token.c b/token.c
index 9db11b1..f278a6f 100644 (file)
--- a/token.c
+++ b/token.c
@@ -1,21 +1,6 @@
 /*
  * This file is part of cparser.
- * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
  */
 #include <config.h>
 
@@ -24,6 +9,7 @@
 
 #include <assert.h>
 #include <stdio.h>
+#include <stdbool.h>
 
 #include "symbol.h"
 #include "lang_features.h"
@@ -31,9 +17,9 @@
 #include "adt/error.h"
 #include "adt/util.h"
 
-static symbol_t *token_symbols[T_LAST_TOKEN];
+symbol_t *token_symbols[T_LAST_TOKEN];
 
-const source_position_t builtin_source_position = { "<built-in>", 0, 0, true };
+const position_t builtin_position = { "<built-in>", 0, 0, true };
 
 static token_kind_t last_id;
 
@@ -67,12 +53,15 @@ static void register_pp_token(pp_token_kind_t const id, char const *const string
 
 void init_tokens(void)
 {
+       static bool tokens_initialized = false;
+       if (tokens_initialized)
+               return;
+       tokens_initialized = true;
+
        memset(token_symbols, 0, T_LAST_TOKEN * sizeof(token_symbols[0]));
 
-#define T(mode,x,str,val)  register_token(mode, T_##x, str);
-#define TS(x,str,val)      intern_register_token(T_##x, str);
+#define T(mode,x,str,val)  register_token(mode, x, str);
 #include "tokens.inc"
-#undef TS
 #undef T
 
 #define T(token) register_pp_token(TP_##token, #token);
@@ -97,8 +86,11 @@ void print_token_kind(FILE *f, token_kind_t token_kind)
 char const *get_string_encoding_prefix(string_encoding_t const enc)
 {
        switch (enc) {
-       case STRING_ENCODING_CHAR: return "";
-       case STRING_ENCODING_WIDE: return "L";
+       case STRING_ENCODING_CHAR:   return "";
+       case STRING_ENCODING_CHAR16: return "u";
+       case STRING_ENCODING_CHAR32: return "U";
+       case STRING_ENCODING_UTF8:   return "u8";
+       case STRING_ENCODING_WIDE:   return "L";
        }
        panic("invalid string encoding");
 }
@@ -110,11 +102,11 @@ void print_token(FILE *f, const token_t *token)
        char const *val;
        switch (token->kind) {
        case T_IDENTIFIER:
+       case T_MACRO_PARAMETER:
        case T_UNKNOWN_CHAR:
                val = token->base.symbol->string;
                break;
 
-       case T_HEADERNAME:
        case T_STRING_LITERAL:
                delim = '"';
                /* FALLTHROUGH */