Make types globally visible, add more type(def)s.
authorChristoph Mallon <christoph.mallon@gmx.de>
Wed, 5 Dec 2007 20:23:35 +0000 (20:23 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Wed, 5 Dec 2007 20:23:35 +0000 (20:23 +0000)
[r18617]

Makefile
lexer.c
main.c
parser.c

index 2e85c3b..45920e3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -32,6 +32,7 @@ SOURCES := \
        symbol_table.c \
        token.c \
        type.c \
+       types.c \
        type_hash.c \
        write_fluffy.c \
        driver/firm_cmdline.c \
diff --git a/lexer.c b/lexer.c
index 525bb85..66401d5 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -6,6 +6,7 @@
 #include "adt/error.h"
 #include "adt/strset.h"
 #include "adt/util.h"
+#include "types.h"
 #include "type_t.h"
 #include "target_architecture.h"
 #include "parser.h"
@@ -41,16 +42,6 @@ static const char *bufend;
 static const char *bufpos;
 static strset_t    stringset;
 
-static type_t     *type_int        = NULL;
-static type_t     *type_uint       = NULL;
-static type_t     *type_long       = NULL;
-static type_t     *type_ulong      = NULL;
-static type_t     *type_longlong   = NULL;
-static type_t     *type_ulonglong  = NULL;
-static type_t     *type_float      = NULL;
-static type_t     *type_double     = NULL;
-static type_t     *type_longdouble = NULL;
-
 static void error_prefix_at(const char *input_name, unsigned linenr)
 {
        fprintf(stderr, "%s:%u: Error: ", input_name, linenr);
@@ -309,7 +300,7 @@ static void parse_integer_suffix(bool is_oct_hex)
                } else if(c == 'u' || c == 'U') {
                        is_unsigned = true;
                        next_char();
-                       lexer_token.datatype = type_ulong;
+                       lexer_token.datatype = type_unsigned_long;
                }
        }
 
@@ -320,7 +311,7 @@ static void parse_integer_suffix(bool is_oct_hex)
                                lexer_token.datatype = type_int;
                                return;
                        } else if(is_oct_hex && v >= 0 && v <= TARGET_UINT_MAX) {
-                               lexer_token.datatype = type_uint;
+                               lexer_token.datatype = type_unsigned_int;
                                return;
                        }
                }
@@ -329,28 +320,28 @@ static void parse_integer_suffix(bool is_oct_hex)
                                lexer_token.datatype = type_long;
                                return;
                        } else if(is_oct_hex && v >= 0 && v <= TARGET_ULONG_MAX) {
-                               lexer_token.datatype = type_ulong;
+                               lexer_token.datatype = type_unsigned_long;
                                return;
                        }
                }
                unsigned long long uv = (unsigned long long) v;
                if(is_oct_hex && uv > (unsigned long long) TARGET_LONGLONG_MAX) {
-                       lexer_token.datatype = type_ulonglong;
+                       lexer_token.datatype = type_unsigned_long_long;
                        return;
                }
 
-               lexer_token.datatype = type_longlong;
+               lexer_token.datatype = type_long_long;
        } else {
                unsigned long long v = (unsigned long long) lexer_token.v.intvalue;
                if(!min_long && v <= TARGET_UINT_MAX) {
-                       lexer_token.datatype = type_uint;
+                       lexer_token.datatype = type_unsigned_int;
                        return;
                }
                if(!min_longlong && v <= TARGET_ULONG_MAX) {
-                       lexer_token.datatype = type_ulong;
+                       lexer_token.datatype = type_unsigned_long;
                        return;
                }
-               lexer_token.datatype = type_ulonglong;
+               lexer_token.datatype = type_unsigned_long_long;
        }
 }
 
@@ -366,7 +357,7 @@ static void parse_floating_suffix(void)
        case 'l':
        case 'L':
                next_char();
-               lexer_token.datatype = type_longdouble;
+               lexer_token.datatype = type_long_double;
                break;
        default:
                lexer_token.datatype = type_double;
@@ -1285,21 +1276,6 @@ newline_found:
 void init_lexer(void)
 {
        strset_init(&stringset);
-
-       type_int       = make_atomic_type(ATOMIC_TYPE_INT, TYPE_QUALIFIER_NONE);
-       type_uint      = make_atomic_type(ATOMIC_TYPE_UINT, TYPE_QUALIFIER_NONE);
-       type_long      = make_atomic_type(ATOMIC_TYPE_LONG, TYPE_QUALIFIER_NONE);
-       type_ulong     = make_atomic_type(ATOMIC_TYPE_ULONG, TYPE_QUALIFIER_NONE);
-       type_longlong  = make_atomic_type(ATOMIC_TYPE_LONGLONG,
-                                         TYPE_QUALIFIER_NONE);
-       type_ulonglong = make_atomic_type(ATOMIC_TYPE_ULONGLONG,
-                                         TYPE_QUALIFIER_NONE);
-
-       type_float      = make_atomic_type(ATOMIC_TYPE_FLOAT, TYPE_QUALIFIER_CONST);
-       type_double     = make_atomic_type(ATOMIC_TYPE_DOUBLE,
-                                          TYPE_QUALIFIER_CONST);
-       type_longdouble = make_atomic_type(ATOMIC_TYPE_LONG_DOUBLE,
-                                          TYPE_QUALIFIER_CONST);
 }
 
 void lexer_open_stream(FILE *stream, const char *input_name)
diff --git a/main.c b/main.c
index ce8c6ff..60f3336 100644 (file)
--- a/main.c
+++ b/main.c
@@ -46,6 +46,7 @@
 
 #include "lexer.h"
 #include "token_t.h"
+#include "types.h"
 #include "type_hash.h"
 #include "parser.h"
 #include "ast2firm.h"
@@ -497,6 +498,7 @@ int main(int argc, char **argv)
        init_tokens();
        init_types();
        init_typehash();
+       init_basic_types();
        init_lexer();
        init_ast();
        init_parser();
index 18e4285..b451a95 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -7,6 +7,7 @@
 #include "parser.h"
 #include "lexer.h"
 #include "token_t.h"
+#include "types.h"
 #include "type_t.h"
 #include "type_hash.h"
 #include "ast_t.h"
@@ -48,20 +49,7 @@ static declaration_t  *current_function  = NULL;
 static struct obstack  temp_obst;
 static bool            found_error;
 
-static type_t         *type_int         = NULL;
-static type_t         *type_long_double = NULL;
-static type_t         *type_double      = NULL;
-static type_t         *type_float       = NULL;
-static type_t         *type_char        = NULL;
-static type_t         *type_string      = NULL;
-static type_t         *type_void        = NULL;
-static type_t         *type_void_ptr    = NULL;
-static type_t         *type_valist      = NULL;
-
-type_t *type_size_t      = NULL;
-type_t *type_ptrdiff_t   = NULL;
-type_t *type_wchar_t     = NULL;
-type_t *type_wchar_t_ptr = NULL;
+static type_t *type_valist;
 
 static statement_t *parse_compound_statement(void);
 static statement_t *parse_statement(void);
@@ -5175,12 +5163,19 @@ static statement_t *parse_compound_statement(void)
 
 static void initialize_builtins(void)
 {
-       type_wchar_t     = make_global_typedef("__WCHAR_TYPE__", type_int);
-       type_wchar_t_ptr = make_pointer_type(type_wchar_t, TYPE_QUALIFIER_NONE);
-       type_size_t      = make_global_typedef("__SIZE_TYPE__",
-                       make_atomic_type(ATOMIC_TYPE_ULONG, TYPE_QUALIFIER_NONE));
-       type_ptrdiff_t   = make_global_typedef("__PTRDIFF_TYPE__",
-                       make_atomic_type(ATOMIC_TYPE_LONG, TYPE_QUALIFIER_NONE));
+       type_intmax_t    = make_global_typedef("__intmax_t__",      type_long_long);
+       type_size_t      = make_global_typedef("__SIZE_TYPE__",     type_unsigned_long);
+       type_ssize_t     = make_global_typedef("__SSIZE_TYPE__",    type_long);
+       type_ptrdiff_t   = make_global_typedef("__PTRDIFF_TYPE__",  type_long);
+       type_uintmax_t   = make_global_typedef("__uintmax_t__",     type_unsigned_long_long);
+       type_uptrdiff_t  = make_global_typedef("__UPTRDIFF_TYPE__", type_unsigned_long);
+       type_wchar_t     = make_global_typedef("__WCHAR_TYPE__",    type_int);
+       type_wint_t      = make_global_typedef("__WINT_TYPE__",     type_int);
+
+       type_intmax_t_ptr  = make_pointer_type(type_intmax_t,  TYPE_QUALIFIER_NONE);
+       type_ptrdiff_t_ptr = make_pointer_type(type_ptrdiff_t, TYPE_QUALIFIER_NONE);
+       type_ssize_t_ptr   = make_pointer_type(type_ssize_t,   TYPE_QUALIFIER_NONE);
+       type_wchar_t_ptr   = make_pointer_type(type_wchar_t,   TYPE_QUALIFIER_NONE);
 }
 
 static translation_unit_t *parse_translation_unit(void)
@@ -5238,17 +5233,6 @@ void init_parser(void)
        init_expression_parsers();
        obstack_init(&temp_obst);
 
-       type_int         = make_atomic_type(ATOMIC_TYPE_INT, TYPE_QUALIFIER_NONE);
-       type_long_double = make_atomic_type(ATOMIC_TYPE_LONG_DOUBLE,
-                                           TYPE_QUALIFIER_NONE);
-       type_double      = make_atomic_type(ATOMIC_TYPE_DOUBLE,
-                                           TYPE_QUALIFIER_NONE);
-       type_float       = make_atomic_type(ATOMIC_TYPE_FLOAT, TYPE_QUALIFIER_NONE);
-       type_char        = make_atomic_type(ATOMIC_TYPE_CHAR, TYPE_QUALIFIER_NONE);
-       type_void        = make_atomic_type(ATOMIC_TYPE_VOID, TYPE_QUALIFIER_NONE);
-       type_void_ptr    = make_pointer_type(type_void, TYPE_QUALIFIER_NONE);
-       type_string      = make_pointer_type(type_char, TYPE_QUALIFIER_NONE);
-
        symbol_t *const va_list_sym = symbol_table_insert("__builtin_va_list");
        type_valist = create_builtin_type(va_list_sym, type_void_ptr);
 }