diff options
| author | Michael Matz <matz@suse.de> | 2017-04-15 20:07:26 +0200 |
|---|---|---|
| committer | Michael Matz <matz@suse.de> | 2017-05-02 03:14:05 +0200 |
| commit | 149678e88836fa3e0c9640e2b56204205fe3eeb3 (patch) | |
| tree | 4bc8aded6c8937aea2792d223e2ab0fdc3cb4a8d | |
| parent | 9839b601773fecd1145b817f61980978c4af35e8 (diff) | |
| download | tinycc-149678e88836fa3e0c9640e2b56204205fe3eeb3.tar.gz tinycc-149678e88836fa3e0c9640e2b56204205fe3eeb3.tar.bz2 | |
Tidy decl_designator
Removing the need for the notfirst local variable, and tidy loop structure
and error messaging a bit.
| -rw-r--r-- | tccgen.c | 41 |
1 files changed, 15 insertions, 26 deletions
@@ -5923,69 +5923,58 @@ static void decl_designator(CType *type, Section *sec, unsigned long c, Sym **cur_field, int size_only) { Sym *s, *f; - int notfirst, index, index_last, align, l, nb_elems, elem_size; + int index, index_last, align, l, nb_elems, elem_size; - notfirst = 0; elem_size = 0; nb_elems = 1; if (gnu_ext && (l = is_label()) != 0) goto struct_field; - while (tok == '[' || tok == '.') { + /* NOTE: we only support ranges for last designator */ + while (nb_elems == 1 && (tok == '[' || tok == '.')) { if (tok == '[') { if (!(type->t & VT_ARRAY)) expect("array type"); - s = type->ref; next(); - index = expr_const(); - if (index < 0 || (s->c >= 0 && index >= s->c)) - tcc_error("invalid index"); + index = index_last = expr_const(); if (tok == TOK_DOTS && gnu_ext) { next(); index_last = expr_const(); - if (index_last < 0 || - (s->c >= 0 && index_last >= s->c) || - index_last < index) - tcc_error("invalid index"); - } else { - index_last = index; } skip(']'); - if (!notfirst) { + s = type->ref; + if (index < 0 || (s->c >= 0 && index_last >= s->c) || + index_last < index) + tcc_error("invalid index"); + if (cur_field) { (*cur_field)->c = index; (*cur_field)->r = index_last; } type = pointed_type(type); elem_size = type_size(type, &align); c += index * elem_size; - /* NOTE: we only support ranges for last designator */ nb_elems = index_last - index + 1; - if (nb_elems != 1) { - notfirst = 1; - break; - } } else { next(); l = tok; - next(); struct_field: + next(); if ((type->t & VT_BTYPE) != VT_STRUCT) expect("struct/union type"); f = find_field(type, l); if (!f) expect("field"); - if (!notfirst) + if (cur_field) *cur_field = f; type = &f->type; c += f->c; } - notfirst = 1; + cur_field = NULL; } - if (notfirst) { + if (!cur_field) { if (tok == '=') { next(); - } else { - if (!gnu_ext) - expect("="); + } else if (!gnu_ext) { + expect("="); } } else { if (type->t & VT_ARRAY) { |
