aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-11-26 23:59:17 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-11-26 23:59:17 +0100
commit467d8d026c8b0a7eee93f31559cccf9157588d12 (patch)
treef9ab06f7c789acf519d8843121e881d36eb7ff85
parentd06e1d291f581d14bfc78bc0c4b58c0b6e876c92 (diff)
parent10b89d60b671642031675e839556aa63d76b634c (diff)
downloadsparse-467d8d026c8b0a7eee93f31559cccf9157588d12.tar.gz
Merge branch 'parse-spec' into master
-rw-r--r--evaluate.c19
-rw-r--r--expand.c11
-rw-r--r--gdbhelpers15
-rw-r--r--parse.c45
-rw-r--r--show-parse.c5
-rw-r--r--symbol.c135
-rw-r--r--symbol.h20
7 files changed, 124 insertions, 126 deletions
diff --git a/evaluate.c b/evaluate.c
index 863750fa..19bdab92 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -150,7 +150,7 @@ static inline struct symbol *integer_promotion(struct symbol *type)
return &int_ctype;
/* If char/short has as many bits as int, it still gets "promoted" */
- if (mod & (MOD_CHAR | MOD_SHORT)) {
+ if (type->rank < 0) {
if (mod & MOD_UNSIGNED)
return &uint_ctype;
return &int_ctype;
@@ -196,7 +196,7 @@ static struct symbol *bigger_int_type(struct symbol *left, struct symbol *right)
if ((lmod ^ rmod) & MOD_UNSIGNED) {
if (lmod & MOD_UNSIGNED)
goto left;
- } else if ((lmod & ~rmod) & (MOD_LONG_ALL))
+ } else if (left->rank > right->rank)
goto left;
right:
left = right;
@@ -557,9 +557,7 @@ Normal:
else
return rtype;
} else if (rclass & TYPE_FLOAT) {
- unsigned long lmod = ltype->ctype.modifiers;
- unsigned long rmod = rtype->ctype.modifiers;
- if (rmod & ~lmod & (MOD_LONG_ALL))
+ if (rtype->rank > ltype->rank)
return rtype;
else
return ltype;
@@ -798,11 +796,11 @@ const char *type_difference(struct ctype *c1, struct ctype *c2,
return "different address spaces";
if (base1 != base2)
return "different base types";
+ if (t1->rank != t2->rank)
+ return "different type sizes";
diff = (mod1 ^ mod2) & ~MOD_IGNORE;
if (!diff)
return NULL;
- if (diff & MOD_SIZE)
- return "different type sizes";
else if (diff & ~MOD_SIGNEDNESS)
return "different modifiers";
else
@@ -1391,9 +1389,9 @@ static int whitelist_pointers(struct symbol *t1, struct symbol *t2)
return 0;
if (t1 == t2)
return 1;
- if (t1->ctype.modifiers & t2->ctype.modifiers & MOD_CHAR)
+ if (t1->rank == -2 && t2->rank == -2)
return 1;
- if ((t1->ctype.modifiers ^ t2->ctype.modifiers) & MOD_SIZE)
+ if (t1->rank != t2->rank)
return 0;
return !Wtypesign;
}
@@ -2348,8 +2346,7 @@ static int evaluate_arguments(struct symbol *fn, struct expression_list *head)
if (is_int(class)) {
*p = cast_to(expr, integer_promotion(type));
} else if (class & TYPE_FLOAT) {
- unsigned long mod = type->ctype.modifiers;
- if (!(mod & (MOD_LONG_ALL)))
+ if (type->rank < 0)
*p = cast_to(expr, &double_ctype);
} else if (class & TYPE_PTR) {
if (expr->ctype == &null_ctype)
diff --git a/expand.c b/expand.c
index d66375f4..ae764153 100644
--- a/expand.c
+++ b/expand.c
@@ -161,9 +161,8 @@ Float:
else
expr->fvalue = old->fvalue;
- if (!(newtype->ctype.modifiers & MOD_LONGLONG) && \
- !(newtype->ctype.modifiers & MOD_LONGLONGLONG)) {
- if ((newtype->ctype.modifiers & MOD_LONG))
+ if (newtype->rank <= 0) {
+ if (newtype->rank == 0)
expr->fvalue = (double)expr->fvalue;
else
expr->fvalue = (float)expr->fvalue;
@@ -358,7 +357,7 @@ static int simplify_cmp_binop(struct expression *expr, struct symbol *ctype)
static int simplify_float_binop(struct expression *expr)
{
struct expression *left = expr->left, *right = expr->right;
- unsigned long mod = expr->ctype->ctype.modifiers;
+ int rank = expr->ctype->rank;
long double l, r, res;
if (left->type != EXPR_FVALUE || right->type != EXPR_FVALUE)
@@ -367,7 +366,7 @@ static int simplify_float_binop(struct expression *expr)
l = left->fvalue;
r = right->fvalue;
- if (mod & MOD_LONGLONG) {
+ if (rank > 0) {
switch (expr->op) {
case '+': res = l + r; break;
case '-': res = l - r; break;
@@ -376,7 +375,7 @@ static int simplify_float_binop(struct expression *expr)
res = l / r; break;
default: return 0;
}
- } else if (mod & MOD_LONG) {
+ } else if (rank == 0) {
switch (expr->op) {
case '+': res = (double) l + (double) r; break;
case '-': res = (double) l - (double) r; break;
diff --git a/gdbhelpers b/gdbhelpers
index 8d186cee..9488a607 100644
--- a/gdbhelpers
+++ b/gdbhelpers
@@ -119,21 +119,6 @@ define gdb_show_ctype
if ($arg0->modifiers & MOD_UNSIGNED)
printf "MOD_UNSIGNED "
end
- if ($arg0->modifiers & MOD_CHAR)
- printf "MOD_CHAR "
- end
- if ($arg0->modifiers & MOD_SHORT)
- printf "MOD_SHORT "
- end
- if ($arg0->modifiers & MOD_LONG)
- printf "MOD_LONG "
- end
- if ($arg0->modifiers & MOD_LONGLONG)
- printf "MOD_LONGLONG "
- end
- if ($arg0->modifiers & MOD_LONGLONGLONG)
- printf "MOD_LONGLONGLONG "
- end
if ($arg0->modifiers & MOD_INLINE)
printf "MOD_INLINE "
end
diff --git a/parse.c b/parse.c
index acae63af..4f7ba0c9 100644
--- a/parse.c
+++ b/parse.c
@@ -113,7 +113,7 @@ enum {
};
enum {
- CInt = 0, CSInt, CUInt, CReal, CChar, CSChar, CUChar,
+ CInt = 0, CSInt, CUInt, CReal,
};
enum {
@@ -249,7 +249,7 @@ static struct symbol_op char_op = {
.type = KW_SPECIFIER,
.test = Set_T|Set_Long|Set_Short,
.set = Set_T|Set_Char,
- .class = CChar,
+ .class = CInt,
};
static struct symbol_op int_op = {
@@ -266,14 +266,14 @@ static struct symbol_op double_op = {
};
static struct symbol_op float_op = {
- .type = KW_SPECIFIER | KW_SHORT,
+ .type = KW_SPECIFIER,
.test = Set_T|Set_Signed|Set_Unsigned|Set_Short|Set_Long,
.set = Set_T|Set_Float,
.class = CReal,
};
static struct symbol_op short_op = {
- .type = KW_SPECIFIER | KW_SHORT,
+ .type = KW_SPECIFIER,
.test = Set_S|Set_Char|Set_Float|Set_Double|Set_Long|Set_Short,
.set = Set_Short,
};
@@ -293,15 +293,16 @@ static struct symbol_op unsigned_op = {
};
static struct symbol_op long_op = {
- .type = KW_SPECIFIER | KW_LONG,
+ .type = KW_SPECIFIER,
.test = Set_S|Set_Char|Set_Float|Set_Short|Set_Vlong,
.set = Set_Long,
};
static struct symbol_op int128_op = {
- .type = KW_SPECIFIER | KW_LONG,
+ .type = KW_SPECIFIER,
.test = Set_S|Set_T|Set_Char|Set_Short|Set_Int|Set_Float|Set_Double|Set_Long|Set_Vlong|Set_Int128,
- .set = Set_T|Set_Int128,
+ .set = Set_T|Set_Int128|Set_Vlong,
+ .class = CInt,
};
static struct symbol_op if_op = {
@@ -1568,20 +1569,20 @@ Catch_all:
}
static struct symbol * const int_types[] =
- {&short_ctype, &int_ctype, &long_ctype, &llong_ctype, &lllong_ctype};
+ {&char_ctype, &short_ctype, &int_ctype, &long_ctype, &llong_ctype, &lllong_ctype};
static struct symbol * const signed_types[] =
- {&sshort_ctype, &sint_ctype, &slong_ctype, &sllong_ctype,
+ {&schar_ctype, &sshort_ctype, &sint_ctype, &slong_ctype, &sllong_ctype,
&slllong_ctype};
static struct symbol * const unsigned_types[] =
- {&ushort_ctype, &uint_ctype, &ulong_ctype, &ullong_ctype,
+ {&uchar_ctype, &ushort_ctype, &uint_ctype, &ulong_ctype, &ullong_ctype,
&ulllong_ctype};
static struct symbol * const real_types[] =
{&float_ctype, &double_ctype, &ldouble_ctype};
-static struct symbol * const char_types[] =
- {&char_ctype, &schar_ctype, &uchar_ctype};
static struct symbol * const * const types[] = {
- int_types + 1, signed_types + 1, unsigned_types + 1,
- real_types + 1, char_types, char_types + 1, char_types + 2
+ [CInt] = int_types + 2,
+ [CSInt] = signed_types + 2,
+ [CUInt] = unsigned_types + 2,
+ [CReal] = real_types + 1,
};
struct symbol *ctype_integer(int size, int want_unsigned)
@@ -1610,7 +1611,7 @@ static struct token *declaration_specifiers(struct token *token, struct decl_sta
{
int seen = 0;
int class = CInt;
- int size = 0;
+ int rank = 0;
while (token_type(token) == TOKEN_IDENT) {
struct symbol *s = lookup_symbol(token->ident,
@@ -1636,10 +1637,12 @@ static struct token *declaration_specifiers(struct token *token, struct decl_sta
seen |= s->op->set;
class += s->op->class;
if (s->op->set & Set_Int128)
- size = 2;
- if (s->op->type & KW_SHORT) {
- size = -1;
- } else if (s->op->type & KW_LONG && size++) {
+ rank = 3;
+ else if (s->op->set & Set_Char)
+ rank = -2;
+ if (s->op->set & (Set_Short|Set_Float)) {
+ rank = -1;
+ } else if (s->op->set & Set_Long && rank++) {
if (class == CReal) {
specifier_conflict(token->pos,
Set_Vlong,
@@ -1661,7 +1664,7 @@ static struct token *declaration_specifiers(struct token *token, struct decl_sta
if (!(seen & Set_S)) { /* not set explicitly? */
struct symbol *base = &incomplete_ctype;
if (seen & Set_Any)
- base = types[class][size];
+ base = types[class][rank];
ctx->ctype.base_type = base;
}
@@ -2833,7 +2836,7 @@ static struct token *parse_function_body(struct token *token, struct symbol *dec
static void promote_k_r_types(struct symbol *arg)
{
struct symbol *base = arg->ctype.base_type;
- if (base && base->ctype.base_type == &int_type && (base->ctype.modifiers & (MOD_CHAR | MOD_SHORT))) {
+ if (base && base->ctype.base_type == &int_type && base->rank < 0) {
arg->ctype.base_type = &int_ctype;
}
}
diff --git a/show-parse.c b/show-parse.c
index 1c0ecf7e..a0436cbe 100644
--- a/show-parse.c
+++ b/show-parse.c
@@ -128,11 +128,6 @@ const char *modifier_string(unsigned long mod)
{MOD_ATOMIC, "[atomic]"},
{MOD_SIGNED, "[signed]"},
{MOD_UNSIGNED, "[unsigned]"},
- {MOD_CHAR, "[char]"},
- {MOD_SHORT, "[short]"},
- {MOD_LONG, "[long]"},
- {MOD_LONGLONG, "[long long]"},
- {MOD_LONGLONGLONG, "[long long long]"},
{MOD_TLS, "[tls]"},
{MOD_INLINE, "inline"},
{MOD_ADDRESSABLE, "[addressable]"},
diff --git a/symbol.c b/symbol.c
index fb86c642..6fa5c2ff 100644
--- a/symbol.c
+++ b/symbol.c
@@ -221,6 +221,7 @@ static struct symbol *examine_base_type(struct symbol *sym)
if (base_type->type == SYM_NODE) {
base_type = base_type->ctype.base_type;
sym->ctype.base_type = base_type;
+ sym->rank = base_type->rank;
}
return base_type;
}
@@ -299,7 +300,7 @@ static int count_array_initializer(struct symbol *t, struct expression *expr)
* on T - if it's a character type, we get the length of string literal
* (including NUL), otherwise we have one element here.
*/
- if (t->ctype.base_type == &int_type && t->ctype.modifiers & MOD_CHAR)
+ if (t->ctype.base_type == &int_type && t->rank == -2)
is_char = 1;
switch (expr->type) {
@@ -416,6 +417,7 @@ static struct symbol * examine_node_type(struct symbol *sym)
}
sym->bit_size = bit_size;
+ sym->rank = base_type->rank;
return sym;
}
@@ -561,6 +563,7 @@ void create_fouled(struct symbol *type)
struct symbol *new = alloc_symbol(type->pos, type->type);
*new = *type;
new->bit_size = bits_in_int;
+ new->rank = 0;
new->type = SYM_FOULED;
new->ctype.base_type = type;
add_symbol(&restr, type);
@@ -762,73 +765,79 @@ static int bits_in_type32 = 32;
static int bits_in_type64 = 64;
static int bits_in_type128 = 128;
-#define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
-#define MOD_LL (MOD_LONG | MOD_LONGLONG)
-#define MOD_LLL MOD_LONGLONGLONG
+#define T_BASETYPE SYM_BASETYPE, 0, 0, NULL, NULL, NULL
+#define T_INT(R, S, M) SYM_BASETYPE, M, R, &bits_in_##S, &max_int_alignment, &int_type
+#define T__INT(R, S) T_INT(R, S, MOD_SIGNED)
+#define T_SINT(R, S) T_INT(R, S, MOD_ESIGNED)
+#define T_UINT(R,S) T_INT(R, S, MOD_UNSIGNED)
+#define T_FLOAT_(R,S,A) SYM_BASETYPE, 0, R, &bits_in_##S, A, &fp_type
+#define T_FLOAT(R, S) T_FLOAT_(R, S, &max_fp_alignment)
+#define T_PTR(B) SYM_PTR, 0, 0, &bits_in_pointer, &pointer_alignment, B
+#define T_NODE(M,B,S,A) SYM_NODE, M, 0, S, A, B
+#define T_CONST(B,S,A) T_NODE(MOD_CONST, B, S, A)
+
static const struct ctype_declare {
struct symbol *ptr;
enum type type;
unsigned long modifiers;
+ int rank;
int *bit_size;
int *maxalign;
struct symbol *base_type;
} ctype_declaration[] = {
- { &bool_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_bool, &max_int_alignment, &int_type },
- { &void_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL },
- { &type_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL },
- { &incomplete_ctype,SYM_BASETYPE, 0, NULL, NULL, NULL },
- { &bad_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 },
- { &lllong_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LLL, &bits_in_longlonglong, &max_int_alignment, &int_type },
- { &slllong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LLL, &bits_in_longlonglong, &max_int_alignment, &int_type },
- { &ulllong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LLL, &bits_in_longlonglong, &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 },
-
- { &float32_ctype, SYM_BASETYPE, 0, &bits_in_type32, &max_fp_alignment, &fp_type },
- { &float32x_ctype, SYM_BASETYPE, MOD_LONG, &bits_in_double, &max_fp_alignment, &fp_type },
- { &float64_ctype, SYM_BASETYPE, 0, &bits_in_type64, &max_fp_alignment, &fp_type },
- { &float64x_ctype, SYM_BASETYPE, MOD_LONG | MOD_LONGLONG, &bits_in_longdouble, &max_fp_alignment, &fp_type },
- { &float128_ctype, SYM_BASETYPE, 0, &bits_in_type128, &max_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 },
- { &null_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 },
- { &int_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &int_ctype },
- { &uint_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &uint_ctype },
- { &long_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &long_ctype },
- { &ulong_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &ulong_ctype },
- { &llong_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &llong_ctype },
- { &ullong_ptr_ctype,SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &ullong_ctype },
-
- { &const_void_ctype, SYM_NODE, MOD_CONST, NULL, NULL, &void_ctype },
- { &const_char_ctype, SYM_NODE, MOD_CONST, &bits_in_char, &max_int_alignment, &char_ctype },
- { &const_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &const_void_ctype },
- { &const_string_ctype,SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &const_char_ctype },
+ { &bool_ctype, T_INT(-3, bool, MOD_UNSIGNED) },
+ { &void_ctype, T_BASETYPE },
+ { &type_ctype, T_BASETYPE },
+ { &incomplete_ctype, T_BASETYPE },
+ { &bad_ctype, T_BASETYPE },
+
+ { &char_ctype, T__INT(-2, char) },
+ { &schar_ctype, T_SINT(-2, char) },
+ { &uchar_ctype, T_UINT(-2, char) },
+ { &short_ctype, T__INT(-1, short) },
+ { &sshort_ctype, T_SINT(-1, short) },
+ { &ushort_ctype, T_UINT(-1, short) },
+ { &int_ctype, T__INT( 0, int) },
+ { &sint_ctype, T_SINT( 0, int) },
+ { &uint_ctype, T_UINT( 0, int) },
+ { &long_ctype, T__INT( 1, long) },
+ { &slong_ctype, T_SINT( 1, long) },
+ { &ulong_ctype, T_UINT( 1, long) },
+ { &llong_ctype, T__INT( 2, longlong) },
+ { &sllong_ctype, T_SINT( 2, longlong) },
+ { &ullong_ctype, T_UINT( 2, longlong) },
+ { &lllong_ctype, T__INT( 3, longlonglong) },
+ { &slllong_ctype, T_SINT( 3, longlonglong) },
+ { &ulllong_ctype, T_UINT( 3, longlonglong) },
+
+ { &float_ctype, T_FLOAT(-1, float) },
+ { &double_ctype, T_FLOAT( 0, double) },
+ { &ldouble_ctype, T_FLOAT( 1, longdouble) },
+
+ { &float32_ctype, T_FLOAT(-1, type32) },
+ { &float32x_ctype, T_FLOAT(-1, double) },
+ { &float64_ctype, T_FLOAT( 0, type64) },
+ { &float64x_ctype, T_FLOAT( 1, longdouble) },
+ { &float128_ctype, T_FLOAT_(2, type128, &max_alignment) },
+
+ { &string_ctype, T_PTR(&char_ctype) },
+ { &ptr_ctype, T_PTR(&void_ctype) },
+ { &null_ctype, T_PTR(&void_ctype) },
+ { &label_ctype, T_PTR(&void_ctype) },
+ { &lazy_ptr_ctype, T_PTR(&void_ctype) },
+ { &int_ptr_ctype, T_PTR(&int_ctype) },
+ { &uint_ptr_ctype, T_PTR(&uint_ctype) },
+ { &long_ptr_ctype, T_PTR(&long_ctype) },
+ { &ulong_ptr_ctype, T_PTR(&ulong_ctype) },
+ { &llong_ptr_ctype, T_PTR(&llong_ctype) },
+ { &ullong_ptr_ctype, T_PTR(&ullong_ctype) },
+ { &const_ptr_ctype, T_PTR(&const_void_ctype) },
+ { &const_string_ctype, T_PTR(&const_char_ctype) },
+
+ { &const_void_ctype, T_CONST(&void_ctype, NULL, NULL) },
+ { &const_char_ctype, T_CONST(&char_ctype, &bits_in_char, &max_int_alignment)},
{ NULL, }
};
-#undef MOD_LLL
-#undef MOD_LL
-#undef MOD_ESIGNED
void init_ctype(void)
{
@@ -843,10 +852,20 @@ void init_ctype(void)
if (alignment > maxalign)
alignment = maxalign;
sym->type = ctype->type;
+ sym->rank = ctype->rank;
sym->bit_size = bit_size;
sym->ctype.alignment = alignment;
sym->ctype.base_type = ctype->base_type;
sym->ctype.modifiers = ctype->modifiers;
+
+ if (sym->type == SYM_NODE) {
+ struct symbol *base = sym->ctype.base_type;
+ sym->rank = base->rank;
+ if (!ctype->bit_size)
+ sym->bit_size = base->bit_size;
+ if (!ctype->maxalign)
+ sym->ctype.alignment = base->ctype.alignment;
+ }
}
// and now some adjustments
diff --git a/symbol.h b/symbol.h
index d8a4f3b6..ad65a904 100644
--- a/symbol.h
+++ b/symbol.h
@@ -81,8 +81,8 @@ enum keyword {
// KW UNUSED = 1 << 4,
KW_ASM = 1 << 5,
KW_MODE = 1 << 6,
- KW_SHORT = 1 << 7,
- KW_LONG = 1 << 8,
+ // KW UNUSED = 1 << 7,
+ // KW UNUSED = 1 << 8,
KW_EXACT = 1 << 9,
};
@@ -178,6 +178,7 @@ struct symbol {
builtin:1,
torename:1,
transparent_union:1;
+ int rank:3; // arithmetic's rank
struct expression *array_size;
struct ctype ctype;
struct symbol_list *arguments;
@@ -225,11 +226,11 @@ struct symbol {
// MOD UNUSED 0x00010000
#define MOD_USERTYPE 0x00020000
-#define MOD_CHAR 0x00040000
-#define MOD_SHORT 0x00080000
-#define MOD_LONG 0x00100000
-#define MOD_LONGLONG 0x00200000
-#define MOD_LONGLONGLONG 0x00400000
+ // MOD UNUSED 0x00040000
+ // MOD UNUSED 0x00080000
+ // MOD UNUSED 0x00100000
+ // MOD UNUSED 0x00200000
+ // MOD UNUSED 0x00400000
#define MOD_SAFE 0x00800000 // non-null/non-trapping pointer
#define MOD_PURE 0x01000000
@@ -243,10 +244,9 @@ struct symbol {
#define MOD_ACCESS (MOD_ASSIGNED | MOD_ADDRESSABLE)
#define MOD_NONLOCAL (MOD_EXTERN | MOD_TOPLEVEL)
#define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
+#define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
#define MOD_SIGNEDNESS (MOD_SIGNED | MOD_UNSIGNED | MOD_EXPLICITLY_SIGNED)
-#define MOD_LONG_ALL (MOD_LONG | MOD_LONGLONG | MOD_LONGLONGLONG)
-#define MOD_SPECIFIER (MOD_CHAR | MOD_SHORT | MOD_LONG_ALL | MOD_SIGNEDNESS)
-#define MOD_SIZE (MOD_CHAR | MOD_SHORT | MOD_LONG_ALL)
+#define MOD_SPECIFIER MOD_SIGNEDNESS
#define MOD_IGNORE (MOD_STORAGE | MOD_ACCESS | MOD_USERTYPE | MOD_EXPLICITLY_SIGNED | MOD_EXT_VISIBLE)
#define MOD_QUALIFIER (MOD_CONST | MOD_VOLATILE | MOD_RESTRICT | MOD_ATOMIC)
#define MOD_PTRINHERIT (MOD_QUALIFIER | MOD_NODEREF | MOD_NORETURN | MOD_NOCAST)