slightly simplify wchar_t handling
authorMatthias Braun <matthias.braun@kit.edu>
Tue, 3 Jul 2012 10:38:21 +0000 (12:38 +0200)
committerMatthias Braun <matthias.braun@kit.edu>
Tue, 3 Jul 2012 18:02:55 +0000 (20:02 +0200)
main.c
type.h
types.c
types.h

diff --git a/main.c b/main.c
index bcfd70d..7269c88 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1671,12 +1671,11 @@ int main(int argc, char **argv)
        init_types_and_adjust();
        init_typehash();
        init_basic_types();
-       if (wchar_atomic_kind == ATOMIC_TYPE_INT)
-               init_wchar_types(type_int);
-       else if (wchar_atomic_kind == ATOMIC_TYPE_USHORT)
-               init_wchar_types(type_short);
-       else
-               panic("unexpected wchar type");
+       if (c_mode & _CXX) {
+               init_wchar_types(ATOMIC_TYPE_WCHAR_T);
+       } else {
+               init_wchar_types(wchar_atomic_kind);
+       }
        init_preprocessor();
        init_ast();
        init_parser();
diff --git a/type.h b/type.h
index 502096d..95edbc1 100644 (file)
--- a/type.h
+++ b/type.h
@@ -35,7 +35,7 @@ typedef enum atomic_type_kind_t {
        ATOMIC_TYPE_INVALID = 0,
        ATOMIC_TYPE_VOID,
        ATOMIC_TYPE_BOOL,
-       ATOMIC_TYPE_WCHAR_T,
+       ATOMIC_TYPE_WCHAR_T, /* only used in C++, in C code wchar_t is a pp-macro */
        ATOMIC_TYPE_CHAR,
        ATOMIC_TYPE_SCHAR,
        ATOMIC_TYPE_UCHAR,
diff --git a/types.c b/types.c
index 8703386..f1afc0a 100644 (file)
--- a/types.c
+++ b/types.c
@@ -191,13 +191,11 @@ void init_basic_types(void)
        type_ssize_t_ptr   = make_pointer_type(type_ssize_t,   TYPE_QUALIFIER_NONE);
 }
 
-void init_wchar_types(type_t *base)
+void init_wchar_types(atomic_type_kind_t akind)
 {
-       assert(base->kind == TYPE_ATOMIC);
-       type_wchar_t = base;
-       type_const_wchar_t
-               = make_atomic_type(base->atomic.akind, TYPE_QUALIFIER_CONST);
-       type_wchar_t_ptr   = make_pointer_type(type_wchar_t,   TYPE_QUALIFIER_NONE);
+       type_wchar_t       = make_atomic_type(akind, TYPE_QUALIFIER_NONE);
+       type_const_wchar_t = make_atomic_type(akind, TYPE_QUALIFIER_CONST);
+       type_wchar_t_ptr   = make_pointer_type(type_wchar_t, TYPE_QUALIFIER_NONE);
        type_const_wchar_t_ptr
                = make_pointer_type(type_const_wchar_t, TYPE_QUALIFIER_NONE);
 }
diff --git a/types.h b/types.h
index 285974e..b173a00 100644 (file)
--- a/types.h
+++ b/types.h
@@ -106,6 +106,6 @@ extern type_t *type_unsigned_int64;
 extern type_t *type_unsigned_int128;
 
 void init_basic_types(void);
-void init_wchar_types(type_t *base);
+void init_wchar_types(atomic_type_kind_t wchar_akind);
 
 #endif