diff mbox series

[06/11] give a type to wchar

Message ID 20181209234320.65274-7-luc.vanoostenryck@gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series predefined macros for intmax_t/intptr_t/... | expand

Commit Message

Luc Van Oostenryck Dec. 9, 2018, 11:43 p.m. UTC
This allows to use predefined_ctype() on wchar_t.

Note: currently __WCHAR_TYPE__ is defined to 'int'
      but thsi is incorrect on: i386, m68k, ppc32, ...
---
 char.c   | 4 ++--
 lib.c    | 4 +---
 target.c | 3 +--
 target.h | 3 +--
 4 files changed, 5 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/char.c b/char.c
index c52521bc8..f26b2a806 100644
--- a/char.c
+++ b/char.c
@@ -84,7 +84,7 @@  void get_char_constant(struct token *token, unsigned long long *val)
 		end = p + type - TOKEN_WIDE_CHAR;
 	}
 	p = parse_escape(p, &v, end,
-			type < TOKEN_WIDE_CHAR ? bits_in_char : bits_in_wchar, token->pos);
+			type < TOKEN_WIDE_CHAR ? bits_in_char : wchar_ctype->bit_size, token->pos);
 	if (p != end)
 		warning(token->pos,
 			"multi-character character constant");
@@ -113,7 +113,7 @@  struct token *get_string_constant(struct token *token, struct expression *expr)
 			done = next;
 		}
 	}
-	bits = is_wide ? bits_in_wchar : bits_in_char;
+	bits = is_wide ? wchar_ctype->bit_size: bits_in_char;
 	while (token != done) {
 		unsigned v;
 		const char *p = token->string->data;
diff --git a/lib.c b/lib.c
index 1156f6f6c..6523cf419 100644
--- a/lib.c
+++ b/lib.c
@@ -1246,9 +1246,7 @@  static void predefined_macros(void)
 	predefined_ctype("SHORT", &short_ctype, PTYPE_SIZEOF);
 	predefined_ctype("SHRT",  &short_ctype, PTYPE_MAX|PTYPE_WIDTH);
 	predefined_ctype("SCHAR",  &char_ctype, PTYPE_MAX|PTYPE_WIDTH);
-	predefined_sizeof("WCHAR", "_T", bits_in_wchar);
-	predefined_max("WCHAR", "", bits_in_wchar);
-	predefined_width("WCHAR",   bits_in_wchar);
+	predefined_ctype("WCHAR",  wchar_ctype, PTYPE_ALL|PTYPE_T);
 
 	predefine("__CHAR_BIT__", 1, "%d", bits_in_char);
 
diff --git a/target.c b/target.c
index 86a9e2e63..e09eff865 100644
--- a/target.c
+++ b/target.c
@@ -5,6 +5,7 @@ 
 
 struct symbol *size_t_ctype = &uint_ctype;
 struct symbol *ssize_t_ctype = &int_ctype;
+struct symbol *wchar_ctype = &int_ctype;
 
 /*
  * For "__attribute__((aligned))"
@@ -22,8 +23,6 @@  int bits_in_long = 32;
 int bits_in_longlong = 64;
 int bits_in_longlonglong = 128;
 
-int bits_in_wchar = 32;
-
 int max_int_alignment = 4;
 
 /*
diff --git a/target.h b/target.h
index 8326fa21a..74f51ffeb 100644
--- a/target.h
+++ b/target.h
@@ -3,6 +3,7 @@ 
 
 extern struct symbol *size_t_ctype;
 extern struct symbol *ssize_t_ctype;
+extern struct symbol *wchar_ctype;
 
 /*
  * For "__attribute__((aligned))"
@@ -20,8 +21,6 @@  extern int bits_in_long;
 extern int bits_in_longlong;
 extern int bits_in_longlonglong;
 
-extern int bits_in_wchar;
-
 extern int max_int_alignment;
 
 /*