Unified · Split
| @@ -5317,7 +5317,7 @@ void type_to_str(char *buf, int buf_size, · 5316 unmodified lines | ||
| 5317 | 5317 | else |
| 5318 | 5318 | tstr = "enum "; |
| 5319 | 5319 | pstrcat(buf, buf_size, tstr); |
| 5320 | − v = type->ref->v; | |
| 5320 | + v = type->ref->v & ~SYM_STRUCT; | |
| 5321 | 5321 | if (v >= SYM_FIRST_ANOM) |
| 5322 | 5322 | pstrcat(buf, buf_size, "<anonymous>"); |
| 5323 | 5323 | else |
| @@ -7428,9 +7428,17 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 2104 unmodified lines | ||
| 7428 | 7428 | /* patch type size if needed */ |
| 7429 | 7429 | if (n < 0) |
| 7430 | 7430 | s->c = array_length; |
| 7431 | − } else if ((type->t & VT_BTYPE) == VT_STRUCT && tok == '{') { | |
| 7431 | + } else if ((type->t & VT_BTYPE) == VT_STRUCT && | |
| 7432 | + (sec || !first || tok == '{')) { | |
| 7433 | + /* NOTE: the previous test is a specific case for automatic | |
| 7434 | + struct/union init */ | |
| 7432 | 7435 | /* XXX: union needs only one init */ |
| 7433 | − next(); | |
| 7436 | + /* XXX: handle bit fields */ | |
| 7437 | + no_oblock = 1; | |
| 7438 | + if (first || tok == '{') { | |
| 7439 | + skip('{'); | |
| 7440 | + no_oblock = 0; | |
| 7441 | + } | |
| 7434 | 7442 | s = type->ref; |
| 7435 | 7443 | f = s->next; |
| 7436 | 7444 | array_length = 0; |
| @@ -7438,6 +7446,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 1 unmodified line | ||
| 7438 | 7446 | n = s->c; |
| 7439 | 7447 | while (tok != '}') { |
| 7440 | 7448 | decl_designator(type, sec, c, NULL, &f, size_only); |
| 7449 | + /* XXX: bitfields ? */ | |
| 7441 | 7450 | /* fill with zero between fields */ |
| 7442 | 7451 | index = f->c; |
| 7443 | 7452 | if (!size_only && array_length < index) { |
| @@ -7447,6 +7456,8 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 3 unmodified lines | ||
| 7447 | 7456 | index = index + type_size(&f->type, &align1); |
| 7448 | 7457 | if (index > array_length) |
| 7449 | 7458 | array_length = index; |
| 7459 | + if (no_oblock && f->next == NULL) | |
| 7460 | + break; | |
| 7450 | 7461 | if (tok == '}') |
| 7451 | 7462 | break; |
| 7452 | 7463 | skip(','); |
| @@ -7457,7 +7468,8 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 4 unmodified lines | ||
| 7457 | 7468 | init_putz(type, sec, c + array_length, |
| 7458 | 7469 | n - array_length); |
| 7459 | 7470 | } |
| 7460 | − skip('}'); | |
| 7471 | + if (!no_oblock) | |
| 7472 | + skip('}'); | |
| 7461 | 7473 | } else if (tok == '{') { |
| 7462 | 7474 | next(); |
| 7463 | 7475 | decl_initializer(type, sec, c, first, size_only); |
| @@ -7746,7 +7758,7 @@ static void func_decl_list(Sym *func_sym) · 282 unmodified lines | ||
| 7746 | 7758 | CType btype, type; |
| 7747 | 7759 | |
| 7748 | 7760 | /* parse each declaration */ |
| 7749 | − while (tok != '{' && tok != ';' && tok != TOK_EOF) { | |
| 7761 | + while (tok != '{' && tok != ';' && tok != ',' && tok != TOK_EOF) { | |
| 7750 | 7762 | if (!parse_btype(&btype, &ad)) |
| 7751 | 7763 | expect("declaration list"); |
| 7752 | 7764 | if (((btype.t & VT_BTYPE) == VT_ENUM || |