Message ID | 20201226175129.9621-11-luc.vanoostenryck@gmail.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | support __packed struct | expand |
On 26/12/2020 17:51, Luc Van Oostenryck wrote: > Type attributes for struct can be placed either just after the > keyword 'struct' or after the '}' ending its definition but this > later case is currently ignored. > > Prepare the handling of this by factoring the code common to both > cases in a single place. > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> > --- > parse.c | 11 +++++------ > validation/parsing/enum-attr.c | 4 ++-- > 2 files changed, 7 insertions(+), 8 deletions(-) > > diff --git a/parse.c b/parse.c > index d6343f0e48bf..99d810910dab 100644 > --- a/parse.c > +++ b/parse.c > @@ -745,12 +745,7 @@ static struct token *struct_union_enum_specifier(enum type type, > if (sym->symbol_list) > error_die(token->pos, "redefinition of %s", show_typename (sym)); > sym->pos = *repos; > - token = parse(token->next, sym); > - token = expect(token, '}', "at end of struct-union-enum-specifier"); > - > - // Mark the structure as needing re-examination > - sym->examined = 0; > - sym->endpos = token->pos; > + goto end; > } > return token; > } > @@ -763,10 +758,14 @@ static struct token *struct_union_enum_specifier(enum type type, > } > > sym = alloc_symbol(token->pos, type); > +end: > set_current_scope(sym); // used by dissect > token = parse(token->next, sym); > ctx->ctype.base_type = sym; > token = expect(token, '}', "at end of specifier"); > + > + // Mark the structure as needing re-examination > + sym->examined = 0; > sym->endpos = token->pos; Hmm, this is not a simple 1:1 code movement. Is the 'set_current_scope(sym);' or 'ctx->ctype.base_type = sym;' relevant to this change? It is not mentioned in the commit message (and I can't tell just looking at the patch text). ATB, Ramsay Jones > > return token; > diff --git a/validation/parsing/enum-attr.c b/validation/parsing/enum-attr.c > index a962d8b417af..8d851a162135 100644 > --- a/validation/parsing/enum-attr.c > +++ b/validation/parsing/enum-attr.c > @@ -21,9 +21,9 @@ enum bad { > parsing/enum-attr.c:10:15: error: typename in expression > parsing/enum-attr.c:10:15: error: undefined identifier '__attribute__' > parsing/enum-attr.c:10:15: error: bad constant expression type > -parsing/enum-attr.c:10:22: error: Expected } at end of struct-union-enum-specifier > +parsing/enum-attr.c:10:22: error: Expected } at end of specifier > parsing/enum-attr.c:10:22: error: got 33 > -parsing/enum-attr.c:14:18: error: Expected } at end of struct-union-enum-specifier > +parsing/enum-attr.c:14:18: error: Expected } at end of specifier > parsing/enum-attr.c:14:18: error: got __attribute__ > * check-error-end > */ >
On Mon, Dec 28, 2020 at 04:54:30PM +0000, Ramsay Jones wrote: > On 26/12/2020 17:51, Luc Van Oostenryck wrote: > > Type attributes for struct can be placed either just after the > > keyword 'struct' or after the '}' ending its definition but this > > later case is currently ignored. > > > > Prepare the handling of this by factoring the code common to both > > cases in a single place. > > > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> > > --- > > parse.c | 11 +++++------ > > validation/parsing/enum-attr.c | 4 ++-- > > 2 files changed, 7 insertions(+), 8 deletions(-) > > > > diff --git a/parse.c b/parse.c > > index d6343f0e48bf..99d810910dab 100644 > > --- a/parse.c > > +++ b/parse.c > > @@ -745,12 +745,7 @@ static struct token *struct_union_enum_specifier(enum type type, > > if (sym->symbol_list) > > error_die(token->pos, "redefinition of %s", show_typename (sym)); > > sym->pos = *repos; > > - token = parse(token->next, sym); > > - token = expect(token, '}', "at end of struct-union-enum-specifier"); > > - > > - // Mark the structure as needing re-examination > > - sym->examined = 0; > > - sym->endpos = token->pos; > > + goto end; > > } > > return token; > > } > > @@ -763,10 +758,14 @@ static struct token *struct_union_enum_specifier(enum type type, > > } > > > > sym = alloc_symbol(token->pos, type); > > +end: > > set_current_scope(sym); // used by dissect > > token = parse(token->next, sym); > > ctx->ctype.base_type = sym; > > token = expect(token, '}', "at end of specifier"); > > + > > + // Mark the structure as needing re-examination > > + sym->examined = 0; > > sym->endpos = token->pos; > > Hmm, this is not a simple 1:1 code movement. > Is the 'set_current_scope(sym);' or 'ctx->ctype.base_type = sym;' > relevant to this change? It is not mentioned in the commit > message (and I can't tell just looking at the patch text). Good points, thanks. For the 'set_current_scope(sym);', I'm not 100% sure it's OK and it's to me to reason about it because it's done only for dissect. Thinking a bit more about it, it should be moved just above the 'end:'. Thanks, -- Luc
diff --git a/parse.c b/parse.c index d6343f0e48bf..99d810910dab 100644 --- a/parse.c +++ b/parse.c @@ -745,12 +745,7 @@ static struct token *struct_union_enum_specifier(enum type type, if (sym->symbol_list) error_die(token->pos, "redefinition of %s", show_typename (sym)); sym->pos = *repos; - token = parse(token->next, sym); - token = expect(token, '}', "at end of struct-union-enum-specifier"); - - // Mark the structure as needing re-examination - sym->examined = 0; - sym->endpos = token->pos; + goto end; } return token; } @@ -763,10 +758,14 @@ static struct token *struct_union_enum_specifier(enum type type, } sym = alloc_symbol(token->pos, type); +end: set_current_scope(sym); // used by dissect token = parse(token->next, sym); ctx->ctype.base_type = sym; token = expect(token, '}', "at end of specifier"); + + // Mark the structure as needing re-examination + sym->examined = 0; sym->endpos = token->pos; return token; diff --git a/validation/parsing/enum-attr.c b/validation/parsing/enum-attr.c index a962d8b417af..8d851a162135 100644 --- a/validation/parsing/enum-attr.c +++ b/validation/parsing/enum-attr.c @@ -21,9 +21,9 @@ enum bad { parsing/enum-attr.c:10:15: error: typename in expression parsing/enum-attr.c:10:15: error: undefined identifier '__attribute__' parsing/enum-attr.c:10:15: error: bad constant expression type -parsing/enum-attr.c:10:22: error: Expected } at end of struct-union-enum-specifier +parsing/enum-attr.c:10:22: error: Expected } at end of specifier parsing/enum-attr.c:10:22: error: got 33 -parsing/enum-attr.c:14:18: error: Expected } at end of struct-union-enum-specifier +parsing/enum-attr.c:14:18: error: Expected } at end of specifier parsing/enum-attr.c:14:18: error: got __attribute__ * check-error-end */
Type attributes for struct can be placed either just after the keyword 'struct' or after the '}' ending its definition but this later case is currently ignored. Prepare the handling of this by factoring the code common to both cases in a single place. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- parse.c | 11 +++++------ validation/parsing/enum-attr.c | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-)