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
80static int parse_btype(CType *type, AttributeDef *ad);80static int parse_btype(CType *type, AttributeDef *ad);
81static void type_decl(CType *type, AttributeDef *ad, int *v, int td);81static void type_decl(CType *type, AttributeDef *ad, int *v, int td);
82static void parse_expr_type(CType *type);82static void parse_expr_type(CType *type);
83static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only);83static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only, int *par_count_p);
84static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr);84static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr);
85static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, char *asm_label, int scope);85static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, char *asm_label, int scope);
86static int decl0(int l, int is_for_loop_init);86static 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
5111 in arrays) */5111 in arrays) */
5112static void decl_designator(CType *type, Section *sec, unsigned long c, 5112static void decl_designator(CType *type, Section *sec, unsigned long c,
5113 int *cur_index, Sym **cur_field, 5113 int *cur_index, Sym **cur_field,
5114 int size_only)5114 int size_only, int *par_count_p)
5115{5115{
5116 Sym *s, *f;5116 Sym *s, *f;
5117 int notfirst, index, index_last, align, l, nb_elems, elem_size;5117 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
5203 c += f->c;5203 c += f->c;
5204 }5204 }
5205 }5205 }
5206 decl_initializer(type, sec, c, 0, size_only);5206 decl_initializer(type, sec, c, 0, size_only, par_count_p);
5207 5207
5208 /* XXX: make it more general */5208 /* XXX: make it more general */
5209 if (!size_only && nb_elems > 1) {5209 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
5372 dimension implicit array init handling). 'size_only' is true if5372 dimension implicit array init handling). 'size_only' is true if
5373 size only evaluation is wanted (only for arrays). */5373 size only evaluation is wanted (only for arrays). */
5374static void decl_initializer(CType *type, Section *sec, unsigned long c, 5374static 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)
5376{5376{
5377 int index, array_length, n, no_oblock, nb, parlevel, parlevel1, i;5377 int index, array_length, n, no_oblock, nb, parlevel, parlevel1, i;
5378 int size1, align1, expr_type;5378 int size1, align1, expr_type;
@@ -5468,7 +5468,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 89 unmodified lines
5468 } else {5468 } else {
5469 index = 0;5469 index = 0;
5470 while (tok != '}') {5470 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);
5472 if (n >= 0 && index >= n)5472 if (n >= 0 && index >= n)
5473 tcc_error("index too large");5473 tcc_error("index too large");
5474 /* must put zero in holes (note that doing it that way5474 /* 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
5485 same time) */5485 same time) */
5486 if (index >= n && no_oblock)5486 if (index >= n && no_oblock)
5487 break;5487 break;
5488 if (*par_count_p != 0 && tok == ')') {
5489 skip(')');
5490 *par_count_p -= 1;
5491 }
5488 if (tok == '}')5492 if (tok == '}')
5489 break;5493 break;
5490 skip(',');5494 skip(',');
@@ -5541,7 +5545,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 50 unmodified lines
5541 index = 0;5545 index = 0;
5542 n = s->c;5546 n = s->c;
5543 while (tok != '}') {5547 while (tok != '}') {
5544 decl_designator(type, sec, c, NULL, &f, size_only);5548 decl_designator(type, sec, c, NULL, &f, size_only, &par_count);
5545 index = f->c;5549 index = f->c;
5546 if (!size_only && array_length < index) {5550 if (!size_only && array_length < index) {
5547 init_putz(type, sec, c + array_length, 5551 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
5607 par_count--;5611 par_count--;
5608 }5612 }
5609 } else if (tok == '{') {5613 } else if (tok == '{') {
5614 int par_count = 0;
5610 next();5615 next();
5611 decl_initializer(type, sec, c, first, size_only);5616 decl_initializer(type, sec, c, first, size_only, &par_count);
5612 skip('}');5617 skip('}');
5613 } else if (size_only) {5618 } else if (size_only) {
5614 /* just skip expression */5619 /* just skip expression */
@@ -5680,6 +5685,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 65 unmodified lines
5680 initializers handling */5685 initializers handling */
5681 tok_str_new(&init_str);5686 tok_str_new(&init_str);
5682 if (size < 0 || (flexible_array && has_init)) {5687 if (size < 0 || (flexible_array && has_init)) {
5688 int par_count = 0;
5683 if (!has_init) 5689 if (!has_init)
5684 tcc_error("unknown type size");5690 tcc_error("unknown type size");
5685 /* get all init string */5691 /* get all init string */
@@ -5715,7 +5721,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 29 unmodified lines
5715 5721
5716 macro_ptr = init_str.str;5722 macro_ptr = init_str.str;
5717 next();5723 next();
5718 decl_initializer(type, NULL, 0, 1, 1);5724 decl_initializer(type, NULL, 0, 1, 1, &par_count);
5719 /* prepare second initializer parsing */5725 /* prepare second initializer parsing */
5720 macro_ptr = init_str.str;5726 macro_ptr = init_str.str;
5721 next();5727 next();
@@ -5870,7 +5876,8 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 148 unmodified lines
5870#endif5876#endif
5871 }5877 }
5872 if (has_init || (type->t & VT_VLA)) {5878 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);
5874 /* restore parse state if needed */5881 /* restore parse state if needed */
5875 if (init_str.str) {5882 if (init_str.str) {
5876 tok_str_free(init_str.str);5883 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