History

fix for the array in struct initialization w/o '{', case 2 a test program:

struct { int a[2], b[2]; } cases[] = { { ((int)0), (((int)0)) }, ((int)0), (((int)0)) /* error: ',' expected (got ")") */ }; int main() { return 0; } This commit allow to skip ')' in the decl_initializer() and to see ','

seyko committed 11 years ago

Commit 8d4c8611 parent 238e7601 file · +16 −9Browse files

Unified · Split

tccgen.c+16−9
@@ -80,7 +80,7 @@ static int is_compatible_types(CType *type1, CType *type2); · 79 unmodified lines
8080 static int parse_btype(CType *type, AttributeDef *ad);
8181 static void type_decl(CType *type, AttributeDef *ad, int *v, int td);
8282 static void parse_expr_type(CType *type);
83−static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only);
83+static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only, int *par_count_p);
8484 static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr);
8585 static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, char *asm_label, int scope);
8686 static int decl0(int l, int is_for_loop_init);
@@ -5111,7 +5111,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 5024 unmodified lines
51115111 in arrays) */
51125112 static void decl_designator(CType *type, Section *sec, unsigned long c,
51135113 int *cur_index, Sym **cur_field,
5114− int size_only)
5114+ int size_only, int *par_count_p)
51155115 {
51165116 Sym *s, *f;
51175117 int notfirst, index, index_last, align, l, nb_elems, elem_size;
@@ -5203,7 +5203,7 @@ static void decl_designator(CType *type, Section *sec, unsigned long c, · 85 unmodified lines
52035203 c += f->c;
52045204 }
52055205 }
5206− decl_initializer(type, sec, c, 0, size_only);
5206+ decl_initializer(type, sec, c, 0, size_only, par_count_p);
52075207
52085208 /* XXX: make it more general */
52095209 if (!size_only && nb_elems > 1) {
@@ -5372,7 +5372,7 @@ static void init_putz(CType *t, Section *sec, unsigned long c, int size) · 162 unmodified lines
53725372 dimension implicit array init handling). 'size_only' is true if
53735373 size only evaluation is wanted (only for arrays). */
53745374 static void decl_initializer(CType *type, Section *sec, unsigned long c,
5375− int first, int size_only)
5375+ int first, int size_only, int *par_count_p)
53765376 {
53775377 int index, array_length, n, no_oblock, nb, parlevel, parlevel1, i;
53785378 int size1, align1, expr_type;
@@ -5468,7 +5468,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 89 unmodified lines
54685468 } else {
54695469 index = 0;
54705470 while (tok != '}') {
5471− decl_designator(type, sec, c, &index, NULL, size_only);
5471+ decl_designator(type, sec, c, &index, NULL, size_only, par_count_p);
54725472 if (n >= 0 && index >= n)
54735473 tcc_error("index too large");
54745474 /* must put zero in holes (note that doing it that way
@@ -5485,6 +5485,10 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 10 unmodified lines
54855485 same time) */
54865486 if (index >= n && no_oblock)
54875487 break;
5488+ if (*par_count_p != 0 && tok == ')') {
5489+ skip(')');
5490+ *par_count_p -= 1;
5491+ }
54885492 if (tok == '}')
54895493 break;
54905494 skip(',');
@@ -5541,7 +5545,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 50 unmodified lines
55415545 index = 0;
55425546 n = s->c;
55435547 while (tok != '}') {
5544− decl_designator(type, sec, c, NULL, &f, size_only);
5548+ decl_designator(type, sec, c, NULL, &f, size_only, &par_count);
55455549 index = f->c;
55465550 if (!size_only && array_length < index) {
55475551 init_putz(type, sec, c + array_length,
@@ -5607,8 +5611,9 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 59 unmodified lines
56075611 par_count--;
56085612 }
56095613 } else if (tok == '{') {
5614+ int par_count = 0;
56105615 next();
5611− decl_initializer(type, sec, c, first, size_only);
5616+ decl_initializer(type, sec, c, first, size_only, &par_count);
56125617 skip('}');
56135618 } else if (size_only) {
56145619 /* just skip expression */
@@ -5680,6 +5685,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 65 unmodified lines
56805685 initializers handling */
56815686 tok_str_new(&init_str);
56825687 if (size < 0 || (flexible_array && has_init)) {
5688+ int par_count = 0;
56835689 if (!has_init)
56845690 tcc_error("unknown type size");
56855691 /* get all init string */
@@ -5715,7 +5721,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 29 unmodified lines
57155721
57165722 macro_ptr = init_str.str;
57175723 next();
5718− decl_initializer(type, NULL, 0, 1, 1);
5724+ decl_initializer(type, NULL, 0, 1, 1, &par_count);
57195725 /* prepare second initializer parsing */
57205726 macro_ptr = init_str.str;
57215727 next();
@@ -5870,7 +5876,8 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 148 unmodified lines
58705876 #endif
58715877 }
58725878 if (has_init || (type->t & VT_VLA)) {
5873− decl_initializer(type, sec, addr, 1, 0);
5879+ int par_count = 0;
5880+ decl_initializer(type, sec, addr, 1, 0, &par_count);
58745881 /* restore parse state if needed */
58755882 if (init_str.str) {
58765883 tok_str_free(init_str.str);

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