diff options
| author | Michael Matz <matz@suse.de> | 2017-07-03 18:13:15 +0200 |
|---|---|---|
| committer | Michael Matz <matz@suse.de> | 2017-07-03 18:13:15 +0200 |
| commit | 27ca3038748d9bff81ae72cd19dadb4467e5d1de (patch) | |
| tree | 73e683742e0fa442832dea0e6e44eb7a07792e24 | |
| parent | d4fe9aba3fc6f4b9cc97b100e86ffe7af5c29619 (diff) | |
| download | tinycc-27ca3038748d9bff81ae72cd19dadb4467e5d1de.tar.gz tinycc-27ca3038748d9bff81ae72cd19dadb4467e5d1de.tar.bz2 | |
Improve skip_or_save_block
Stop at level 0 only for matching outer '}' (which is added).
Otherwise stop only at stop tokens (which aren't added).
| -rw-r--r-- | tccgen.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -5867,11 +5867,13 @@ static void block(int *bsym, int *csym, int is_expr) } /* This skips over a stream of tokens containing balanced {} and () - pairs, stopping at outer ',' ';' and '}'. If STR then allocates - and stores the skipped tokens in *STR. This doesn't check if - () and {} are nested correctly, i.e. "({)}" is accepted. */ + pairs, stopping at outer ',' ';' and '}' (or matching '}' if we started + with a '{'). If STR then allocates and stores the skipped tokens + in *STR. This doesn't check if () and {} are nested correctly, + i.e. "({)}" is accepted. */ static void skip_or_save_block(TokenString **str) { + int braces = tok == '{'; int level = 0; if (str) *str = tok_str_alloc(); @@ -5892,7 +5894,7 @@ static void skip_or_save_block(TokenString **str) level++; } else if (t == '}' || t == ')') { level--; - if (level == 0) + if (level == 0 && braces && t == '}') break; } } @@ -6413,9 +6415,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, But GNU C supports it, so we need to recurse even into subfields of structs and arrays when size_only is set. */ /* just skip expression */ - do { - skip_or_save_block(NULL); - } while (tok != '}' && tok != ',' && tok != -1); + skip_or_save_block(NULL); } else { if (!have_elem) { /* This should happen only when we haven't parsed |
