diff options
| author | welinder@troll.com <welinder@troll.com> | 2004-09-08 11:52:38 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 21:03:11 -0700 |
| commit | ee1d2b7ef68ee42746174f0b7c51fda2473cc73d (patch) | |
| tree | fe4a4d493ce0e8318bacae66314ae1ff24fe7775 | |
| parent | 0467f900aa39c880c6f9755e7857c7d6aae0a61c (diff) | |
| download | sparse-dev-ee1d2b7ef68ee42746174f0b7c51fda2473cc73d.tar.gz | |
symbol.h, symbol.c:
Add s(char|short|int|long|longlong)_ctype.
show-parse.c:
Print "signed" as part of the type names when needed.
parse.c:
Add separate ctypes for signed char, short, int, long, and long long.
Make ctype_integer pick the explicitly signed type as needed.
| -rw-r--r-- | parse.c | 30 | ||||
| -rw-r--r-- | show-parse.c | 5 | ||||
| -rw-r--r-- | symbol.c | 67 | ||||
| -rw-r--r-- | symbol.h | 10 |
4 files changed, 67 insertions, 45 deletions
@@ -380,18 +380,19 @@ static struct token *attribute_specifier(struct token *token, struct ctype *ctyp } #define MOD_SPECIALBITS (MOD_STRUCTOF | MOD_UNIONOF | MOD_ENUMOF | MOD_ATTRIBUTE | MOD_TYPEOF) -#define MOD_SPECIFIER (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG | MOD_SIGNED | MOD_UNSIGNED) +#define MOD_SPECIFIER (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG | MOD_SIGNED | MOD_UNSIGNED | MOD_EXPLICITLY_SIGNED) struct symbol * ctype_integer(unsigned long spec) { - static struct symbol *const integer_ctypes[][2] = { - { &llong_ctype, &ullong_ctype }, - { &long_ctype, &ulong_ctype }, - { &short_ctype, &ushort_ctype }, - { &char_ctype, &uchar_ctype }, - { &int_ctype, &uint_ctype }, + static struct symbol *const integer_ctypes[][3] = { + { &llong_ctype, &sllong_ctype, &ullong_ctype }, + { &long_ctype, &slong_ctype, &ulong_ctype }, + { &short_ctype, &sshort_ctype, &ushort_ctype }, + { &char_ctype, &schar_ctype, &uchar_ctype }, + { &int_ctype, &sint_ctype, &uint_ctype }, }; - struct symbol *const (*ctype)[2]; + struct symbol *const (*ctype)[3]; + int sub; ctype = integer_ctypes; if (!(spec & MOD_LONGLONG)) { @@ -405,7 +406,14 @@ struct symbol * ctype_integer(unsigned long spec) } } } - return ctype[0][(spec & MOD_UNSIGNED) != 0]; + + sub = ((spec & MOD_UNSIGNED) + ? 2 + : ((spec & MOD_EXPLICITLY_SIGNED) + ? 1 + : 0)); + + return ctype[0][sub]; } struct symbol * ctype_fp(unsigned long spec) @@ -573,7 +581,7 @@ static struct token *declaration_specifiers(struct token *next, struct ctype *ct ctype->base_type = ctype_integer(ctype->modifiers); ctype->modifiers &= ~MOD_SPECIFIER; } else if (ctype->base_type == &fp_type) { - ctype->base_type = ctype_fp(ctype->modifiers & MOD_SPECIFIER); + ctype->base_type = ctype_fp(ctype->modifiers); ctype->modifiers &= ~MOD_SPECIFIER; } if (ctype->modifiers & MOD_BITWISE) { @@ -651,7 +659,7 @@ static struct token *direct_declarator(struct token *token, struct symbol **tree p = NULL; continue; } - + sym = indirect(token->pos, ctype, SYM_FN); token = parameter_type_list(next, sym); token = expect(token, ')', "in function declarator"); diff --git a/show-parse.c b/show-parse.c index b36edb48..1d423ad2 100644 --- a/show-parse.c +++ b/show-parse.c @@ -162,14 +162,19 @@ static void do_show_type(struct symbol *sym, struct type_name *name) char *name; } typenames[] = { { & char_ctype, "char" }, + { &schar_ctype, "signed char" }, { &uchar_ctype, "unsigned char" }, { & short_ctype, "short" }, + { &sshort_ctype, "signed short" }, { &ushort_ctype, "unsigned short" }, { & int_ctype, "int" }, + { &sint_ctype, "signed int" }, { &uint_ctype, "unsigned int" }, + { &slong_ctype, "signed long" }, { & long_ctype, "long" }, { &ulong_ctype, "unsigned long" }, { & llong_ctype, "long long" }, + { &sllong_ctype, "signed long long" }, { &ullong_ctype, "unsigned long long" }, { &void_ctype, "void" }, @@ -484,11 +484,11 @@ struct symbol int_type, * can map onto) */ struct symbol bool_ctype, void_ctype, type_ctype, - char_ctype, uchar_ctype, - short_ctype, ushort_ctype, - int_ctype, uint_ctype, - long_ctype, ulong_ctype, - llong_ctype, ullong_ctype, + char_ctype, schar_ctype, uchar_ctype, + short_ctype, sshort_ctype, ushort_ctype, + int_ctype, sint_ctype, uint_ctype, + long_ctype, slong_ctype, ulong_ctype, + llong_ctype, sllong_ctype, ullong_ctype, float_ctype, double_ctype, ldouble_ctype, string_ctype, ptr_ctype, lazy_ptr_ctype, incomplete_ctype, label_ctype; @@ -526,6 +526,8 @@ void init_symbols(void) } } +#define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED) +#define MOD_LL (MOD_LONG | MOD_LONGLONG) static const struct ctype_declare { struct symbol *ptr; enum type type; @@ -534,32 +536,39 @@ static const struct ctype_declare { int *maxalign; struct symbol *base_type; } ctype_declaration[] = { - { &bool_ctype, SYM_BASETYPE, 0, &bits_in_int, &max_int_alignment, &int_type }, - { &void_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL }, - { &type_ctype, SYM_BASETYPE, MOD_TYPE, NULL, NULL, NULL }, - { &incomplete_ctype,SYM_BASETYPE, 0, NULL, NULL, NULL }, - - { &char_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type }, - { &uchar_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type }, - { &short_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type }, - { &ushort_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type }, - { &int_ctype, SYM_BASETYPE, MOD_SIGNED, &bits_in_int, &max_int_alignment, &int_type }, - { &uint_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_int, &max_int_alignment, &int_type }, - { &long_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type }, - { &ulong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type }, - { &llong_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LONG | MOD_LONGLONG, &bits_in_longlong, &max_int_alignment, &int_type }, - { &ullong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LONG | MOD_LONGLONG, &bits_in_longlong, &max_int_alignment, &int_type }, - - { &float_ctype, SYM_BASETYPE, 0, &bits_in_float, &max_fp_alignment, &fp_type }, - { &double_ctype, SYM_BASETYPE, MOD_LONG, &bits_in_double, &max_fp_alignment, &fp_type }, - { &ldouble_ctype, SYM_BASETYPE, MOD_LONG | MOD_LONGLONG, &bits_in_longdouble, &max_fp_alignment, &fp_type }, - - { &string_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &char_ctype }, - { &ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype }, - { &label_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype }, - { &lazy_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype }, + { &bool_ctype, SYM_BASETYPE, 0, &bits_in_int, &max_int_alignment, &int_type }, + { &void_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL }, + { &type_ctype, SYM_BASETYPE, MOD_TYPE, NULL, NULL, NULL }, + { &incomplete_ctype,SYM_BASETYPE, 0, NULL, NULL, NULL }, + + { &char_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type }, + { &schar_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type }, + { &uchar_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type }, + { &short_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type }, + { &sshort_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type }, + { &ushort_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type }, + { &int_ctype, SYM_BASETYPE, MOD_SIGNED, &bits_in_int, &max_int_alignment, &int_type }, + { &sint_ctype, SYM_BASETYPE, MOD_ESIGNED, &bits_in_int, &max_int_alignment, &int_type }, + { &uint_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_int, &max_int_alignment, &int_type }, + { &long_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type }, + { &slong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type }, + { &ulong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type }, + { &llong_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type }, + { &sllong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type }, + { &ullong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type }, + + { &float_ctype, SYM_BASETYPE, 0, &bits_in_float, &max_fp_alignment, &fp_type }, + { &double_ctype, SYM_BASETYPE, MOD_LONG, &bits_in_double, &max_fp_alignment, &fp_type }, + { &ldouble_ctype, SYM_BASETYPE, MOD_LONG | MOD_LONGLONG, &bits_in_longdouble, &max_fp_alignment, &fp_type }, + + { &string_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &char_ctype }, + { &ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype }, + { &label_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype }, + { &lazy_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype }, { NULL, } }; +#undef MOD_LL +#undef MOD_ESIGNED void init_ctype(void) { @@ -164,11 +164,11 @@ extern struct symbol void_type, /* C types */ extern struct symbol bool_ctype, void_ctype, type_ctype, - char_ctype, uchar_ctype, - short_ctype, ushort_ctype, - int_ctype, uint_ctype, - long_ctype, ulong_ctype, - llong_ctype, ullong_ctype, + char_ctype, schar_ctype, uchar_ctype, + short_ctype, sshort_ctype, ushort_ctype, + int_ctype, sint_ctype, uint_ctype, + long_ctype, slong_ctype, ulong_ctype, + llong_ctype, sllong_ctype, ullong_ctype, float_ctype, double_ctype, ldouble_ctype, string_ctype, ptr_ctype, lazy_ptr_ctype, incomplete_ctype, label_ctype; |
