From 957dd4b160d5943a0a9f096b841d6a4aa5ba0684 Mon Sep 17 00:00:00 2001 From: Rob Shearman Date: Fri, 25 Apr 2008 10:59:00 +0100 Subject: [PATCH] widl: Add support for declaring multiple fields of a structure in one statement. --- tools/widl/parser.y | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 1732eaec018..36f57898eb7 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -91,9 +91,11 @@ static attr_t *make_attrp(enum attr_type type, void *val); static expr_list_t *append_expr(expr_list_t *list, expr_t *expr); static array_dims_t *append_array(array_dims_t *list, expr_t *expr); static void set_type(var_t *v, type_t *type, const declarator_t *decl, int top); +static var_list_t *set_var_types(attr_list_t *attrs, type_t *type, declarator_list_t *decls); static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface); static ifref_t *make_ifref(type_t *iface); static var_list_t *append_var(var_list_t *list, var_t *var); +static var_list_t *append_var_list(var_list_t *list, var_list_t *vars); static var_t *make_var(char *name); static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *p); static declarator_t *make_declarator(var_t *var); @@ -287,8 +289,8 @@ static statement_list_t *append_statement(statement_list_t *list, statement_t *s %type type %type coclass_int %type coclass_ints -%type arg field ne_union_field union_field s_field case enum constdef externdef -%type m_args no_args args fields ne_union_fields cases enums enum_list dispint_props +%type arg ne_union_field union_field s_field case enum constdef externdef +%type m_args no_args args fields ne_union_fields cases enums enum_list dispint_props field %type m_ident t_ident ident %type declarator func_declarator direct_declarator %type declarator_list @@ -702,11 +704,16 @@ externdef: tEXTERN tCONST type ident { $$ = $4; ; fields: { $$ = NULL; } - | fields field { $$ = append_var( $1, $2 ); } + | fields field { $$ = append_var_list($1, $2); } ; -field: s_field ';' { $$ = $1; } - | m_attributes uniondef ';' { $$ = make_var(NULL); $$->type = $2; $$->attrs = $1; } +field: m_attributes type declarator_list ';' { const char *first = LIST_ENTRY(list_head($3), declarator_t, entry)->var->name; + check_field_attrs(first, $1); + $$ = set_var_types($1, $2, $3); } + | m_attributes uniondef ';' { var_t *v = make_var(NULL); + v->type = $2; v->attrs = $1; + $$ = append_var(NULL, v); + } ; ne_union_field: @@ -1413,6 +1420,23 @@ static void set_type(var_t *v, type_t *type, const declarator_t *decl, } } +static var_list_t *set_var_types(attr_list_t *attrs, type_t *type, declarator_list_t *decls) +{ + declarator_t *decl, *next; + var_list_t *var_list = NULL; + + LIST_FOR_EACH_ENTRY_SAFE( decl, next, decls, declarator_t, entry ) + { + var_t *var = decl->var; + + var->attrs = attrs; + set_type(var, type, decl, 0); + var_list = append_var(var_list, var); + free(decl); + } + return var_list; +} + static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface) { if (!iface) return list; @@ -1445,6 +1469,18 @@ static var_list_t *append_var(var_list_t *list, var_t *var) return list; } +static var_list_t *append_var_list(var_list_t *list, var_list_t *vars) +{ + if (!vars) return list; + if (!list) + { + list = xmalloc( sizeof(*list) ); + list_init( list ); + } + list_move_tail( list, vars ); + return list; +} + static var_t *make_var(char *name) { var_t *v = xmalloc(sizeof(var_t)); -- 2.11.4.GIT