History

fixed structure init without {} - fixed function declaration parse

bellard committed 23 years ago

Commit 0841db01 parent ab9973c1 file · +17 −5Browse files

Unified · Split

tcc.c+17−5
@@ -5317,7 +5317,7 @@ void type_to_str(char *buf, int buf_size, · 5316 unmodified lines
53175317 else
53185318 tstr = "enum ";
53195319 pstrcat(buf, buf_size, tstr);
5320− v = type->ref->v;
5320+ v = type->ref->v & ~SYM_STRUCT;
53215321 if (v >= SYM_FIRST_ANOM)
53225322 pstrcat(buf, buf_size, "<anonymous>");
53235323 else
@@ -7428,9 +7428,17 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 2104 unmodified lines
74287428 /* patch type size if needed */
74297429 if (n < 0)
74307430 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 */
74327435 /* 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+ }
74347442 s = type->ref;
74357443 f = s->next;
74367444 array_length = 0;
@@ -7438,6 +7446,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 1 unmodified line
74387446 n = s->c;
74397447 while (tok != '}') {
74407448 decl_designator(type, sec, c, NULL, &f, size_only);
7449+ /* XXX: bitfields ? */
74417450 /* fill with zero between fields */
74427451 index = f->c;
74437452 if (!size_only && array_length < index) {
@@ -7447,6 +7456,8 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 3 unmodified lines
74477456 index = index + type_size(&f->type, &align1);
74487457 if (index > array_length)
74497458 array_length = index;
7459+ if (no_oblock && f->next == NULL)
7460+ break;
74507461 if (tok == '}')
74517462 break;
74527463 skip(',');
@@ -7457,7 +7468,8 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 4 unmodified lines
74577468 init_putz(type, sec, c + array_length,
74587469 n - array_length);
74597470 }
7460− skip('}');
7471+ if (!no_oblock)
7472+ skip('}');
74617473 } else if (tok == '{') {
74627474 next();
74637475 decl_initializer(type, sec, c, first, size_only);
@@ -7746,7 +7758,7 @@ static void func_decl_list(Sym *func_sym) · 282 unmodified lines
77467758 CType btype, type;
77477759
77487760 /* parse each declaration */
7749− while (tok != '{' && tok != ';' && tok != TOK_EOF) {
7761+ while (tok != '{' && tok != ';' && tok != ',' && tok != TOK_EOF) {
77507762 if (!parse_btype(&btype, &ad))
77517763 expect("declaration list");
77527764 if (((btype.t & VT_BTYPE) == VT_ENUM ||

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