type: Make an assert()ion independent of the last entry of an enum.
[cparser] / types.c
diff --git a/types.c b/types.c
index 8703386..3cd6332 100644 (file)
--- a/types.c
+++ b/types.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 "type_t.h"
 #include "types.h"
@@ -61,6 +46,10 @@ type_t *type_const_void_ptr_restrict;
 
 type_t *type_char_ptr_ptr;
 
+type_t *type_char16_t;
+type_t *type_char32_t;
+type_t *type_char16_t_const;
+type_t *type_char32_t_const;
 type_t *type_intmax_t;
 type_t *type_ptrdiff_t;
 type_t *type_size_t;
@@ -73,6 +62,10 @@ type_t *type_wint_t;
 type_t *type_int32_t;
 type_t *type_int64_t;
 
+type_t *type_char16_t_ptr;
+type_t *type_char32_t_ptr;
+type_t *type_char16_t_const_ptr;
+type_t *type_char32_t_const_ptr;
 type_t *type_intmax_t_ptr;
 type_t *type_ptrdiff_t_ptr;
 type_t *type_ssize_t_ptr;
@@ -82,16 +75,16 @@ type_t *type_const_wchar_t_ptr;
 type_t *type_valist;
 
 /* microsoft types */
-atomic_type_kind_t int8_type_kind            = ATOMIC_TYPE_INVALID;
-atomic_type_kind_t int16_type_kind           = ATOMIC_TYPE_INVALID;
-atomic_type_kind_t int32_type_kind           = ATOMIC_TYPE_INVALID;
-atomic_type_kind_t int64_type_kind           = ATOMIC_TYPE_INVALID;
-atomic_type_kind_t int128_type_kind          = ATOMIC_TYPE_INVALID;
-atomic_type_kind_t unsigned_int8_type_kind   = ATOMIC_TYPE_INVALID;
-atomic_type_kind_t unsigned_int16_type_kind  = ATOMIC_TYPE_INVALID;
-atomic_type_kind_t unsigned_int32_type_kind  = ATOMIC_TYPE_INVALID;
-atomic_type_kind_t unsigned_int64_type_kind  = ATOMIC_TYPE_INVALID;
-atomic_type_kind_t unsigned_int128_type_kind = ATOMIC_TYPE_INVALID;
+atomic_type_kind_t int8_type_kind;
+atomic_type_kind_t int16_type_kind;
+atomic_type_kind_t int32_type_kind;
+atomic_type_kind_t int64_type_kind;
+atomic_type_kind_t int128_type_kind;
+atomic_type_kind_t unsigned_int8_type_kind;
+atomic_type_kind_t unsigned_int16_type_kind;
+atomic_type_kind_t unsigned_int32_type_kind;
+atomic_type_kind_t unsigned_int64_type_kind;
+atomic_type_kind_t unsigned_int128_type_kind;
 
 type_t *type_int8;
 type_t *type_int16;
@@ -191,13 +184,23 @@ 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);
+
+       atomic_type_kind_t const u2 = find_unsigned_int_atomic_type_kind_for_size(2);
+       type_char16_t           = make_atomic_type(u2, TYPE_QUALIFIER_NONE);
+       type_char16_t_const     = make_atomic_type(u2, TYPE_QUALIFIER_CONST);
+       type_char16_t_ptr       = make_pointer_type(type_char16_t,       TYPE_QUALIFIER_NONE);
+       type_char16_t_const_ptr = make_pointer_type(type_char16_t_const, TYPE_QUALIFIER_NONE);
+
+       atomic_type_kind_t const u4 = find_unsigned_int_atomic_type_kind_for_size(4);
+       type_char32_t           = make_atomic_type(u4, TYPE_QUALIFIER_NONE);
+       type_char32_t_const     = make_atomic_type(u4, TYPE_QUALIFIER_CONST);
+       type_char32_t_ptr       = make_pointer_type(type_char32_t,       TYPE_QUALIFIER_NONE);
+       type_char32_t_const_ptr = make_pointer_type(type_char32_t_const, TYPE_QUALIFIER_NONE);
 }