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).
master
Michael Matz 2017-07-03 18:13:15 +02:00
parent d4fe9aba3f
commit 27ca303874
1 changed files with 7 additions and 7 deletions

View File

@ -5867,11 +5867,13 @@ static void block(int *bsym, int *csym, int is_expr)
} }
/* This skips over a stream of tokens containing balanced {} and () /* This skips over a stream of tokens containing balanced {} and ()
pairs, stopping at outer ',' ';' and '}'. If STR then allocates pairs, stopping at outer ',' ';' and '}' (or matching '}' if we started
and stores the skipped tokens in *STR. This doesn't check if with a '{'). If STR then allocates and stores the skipped tokens
() and {} are nested correctly, i.e. "({)}" is accepted. */ in *STR. This doesn't check if () and {} are nested correctly,
i.e. "({)}" is accepted. */
static void skip_or_save_block(TokenString **str) static void skip_or_save_block(TokenString **str)
{ {
int braces = tok == '{';
int level = 0; int level = 0;
if (str) if (str)
*str = tok_str_alloc(); *str = tok_str_alloc();
@ -5892,7 +5894,7 @@ static void skip_or_save_block(TokenString **str)
level++; level++;
} else if (t == '}' || t == ')') { } else if (t == '}' || t == ')') {
level--; level--;
if (level == 0) if (level == 0 && braces && t == '}')
break; 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 But GNU C supports it, so we need to recurse even into
subfields of structs and arrays when size_only is set. */ subfields of structs and arrays when size_only is set. */
/* just skip expression */ /* just skip expression */
do { skip_or_save_block(NULL);
skip_or_save_block(NULL);
} while (tok != '}' && tok != ',' && tok != -1);
} else { } else {
if (!have_elem) { if (!have_elem) {
/* This should happen only when we haven't parsed /* This should happen only when we haven't parsed