History

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).

Michael Matz committed 9 years ago

Commit 27ca3031 parent d4fe9ab1 file · +7 −7Browse files

Unified · Split

tccgen.c+7−7
@@ -5867,11 +5867,13 @@ static void block(int *bsym, int *csym, int is_expr) · 5866 unmodified lines
58675867 }
58685868
58695869 /* This skips over a stream of tokens containing balanced {} and ()
5870− pairs, stopping at outer ',' ';' and '}'. If STR then allocates
5871− and stores the skipped tokens in *STR. This doesn't check if
5872− () and {} are nested correctly, i.e. "({)}" is accepted. */
5870+ pairs, stopping at outer ',' ';' and '}' (or matching '}' if we started
5871+ with a '{'). If STR then allocates and stores the skipped tokens
5872+ in *STR. This doesn't check if () and {} are nested correctly,
5873+ i.e. "({)}" is accepted. */
58735874 static void skip_or_save_block(TokenString **str)
58745875 {
5876+ int braces = tok == '{';
58755877 int level = 0;
58765878 if (str)
58775879 *str = tok_str_alloc();
@@ -5892,7 +5894,7 @@ static void skip_or_save_block(TokenString **str) · 14 unmodified lines
58925894 level++;
58935895 } else if (t == '}' || t == ')') {
58945896 level--;
5895− if (level == 0)
5897+ if (level == 0 && braces && t == '}')
58965898 break;
58975899 }
58985900 }
@@ -6413,9 +6415,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 514 unmodified lines
64136415 But GNU C supports it, so we need to recurse even into
64146416 subfields of structs and arrays when size_only is set. */
64156417 /* just skip expression */
6416− do {
6417− skip_or_save_block(NULL);
6418− } while (tok != '}' && tok != ',' && tok != -1);
6418+ skip_or_save_block(NULL);
64196419 } else {
64206420 if (!have_elem) {
64216421 /* This should happen only when we haven't parsed

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