History

Tidy decl_designator

Removing the need for the notfirst local variable, and tidy loop structure and error messaging a bit.

Michael Matz committed 9 years ago

Commit 149678e1 parent 9839b601 file · +15 −26Browse files

Unified · Split

tccgen.c+15−26
@@ -5923,69 +5923,58 @@ static void decl_designator(CType *type, Section *sec, unsigned long c, · 5922 unmodified lines
59235923 Sym **cur_field, int size_only)
59245924 {
59255925 Sym *s, *f;
5926− int notfirst, index, index_last, align, l, nb_elems, elem_size;
5926+ int index, index_last, align, l, nb_elems, elem_size;
59275927
5928− notfirst = 0;
59295928 elem_size = 0;
59305929 nb_elems = 1;
59315930 if (gnu_ext && (l = is_label()) != 0)
59325931 goto struct_field;
5933− while (tok == '[' || tok == '.') {
5932+ /* NOTE: we only support ranges for last designator */
5933+ while (nb_elems == 1 && (tok == '[' || tok == '.')) {
59345934 if (tok == '[') {
59355935 if (!(type->t & VT_ARRAY))
59365936 expect("array type");
5937− s = type->ref;
59385937 next();
5939− index = expr_const();
5940− if (index < 0 || (s->c >= 0 && index >= s->c))
5941− tcc_error("invalid index");
5938+ index = index_last = expr_const();
59425939 if (tok == TOK_DOTS && gnu_ext) {
59435940 next();
59445941 index_last = expr_const();
5945− if (index_last < 0 ||
5946− (s->c >= 0 && index_last >= s->c) ||
5947− index_last < index)
5948− tcc_error("invalid index");
5949− } else {
5950− index_last = index;
59515942 }
59525943 skip(']');
5953− if (!notfirst) {
5944+ s = type->ref;
5945+ if (index < 0 || (s->c >= 0 && index_last >= s->c) ||
5946+ index_last < index)
5947+ tcc_error("invalid index");
5948+ if (cur_field) {
59545949 (*cur_field)->c = index;
59555950 (*cur_field)->r = index_last;
59565951 }
59575952 type = pointed_type(type);
59585953 elem_size = type_size(type, &align);
59595954 c += index * elem_size;
5960− /* NOTE: we only support ranges for last designator */
59615955 nb_elems = index_last - index + 1;
5962− if (nb_elems != 1) {
5963− notfirst = 1;
5964− break;
5965− }
59665956 } else {
59675957 next();
59685958 l = tok;
5969− next();
59705959 struct_field:
5960+ next();
59715961 if ((type->t & VT_BTYPE) != VT_STRUCT)
59725962 expect("struct/union type");
59735963 f = find_field(type, l);
59745964 if (!f)
59755965 expect("field");
5976− if (!notfirst)
5966+ if (cur_field)
59775967 *cur_field = f;
59785968 type = &f->type;
59795969 c += f->c;
59805970 }
5981− notfirst = 1;
5971+ cur_field = NULL;
59825972 }
5983− if (notfirst) {
5973+ if (!cur_field) {
59845974 if (tok == '=') {
59855975 next();
5986− } else {
5987− if (!gnu_ext)
5988− expect("=");
5976+ } else if (!gnu_ext) {
5977+ expect("=");
59895978 }
59905979 } else {
59915980 if (type->t & VT_ARRAY) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t