From ce148774363988b08f9648eacec941ec6c47e91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Fri, 5 Feb 2021 10:11:01 +0100 Subject: [PATCH] widl: Factor and cleanup dispinterface type declaration and definition. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RĂ©mi Bernon Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- tools/widl/parser.y | 36 +++++++++++++----------------------- tools/widl/typetree.c | 23 +++++++++++++++++++++-- tools/widl/typetree.h | 6 ++++-- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 44716deb5b6..349e4730d96 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -95,7 +95,6 @@ static attr_list_t *check_struct_attrs(attr_list_t *attrs); static attr_list_t *check_union_attrs(attr_list_t *attrs); static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs); static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs); -static attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs); static attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs); static attr_list_t *check_apicontract_attrs(const char *name, attr_list_t *attrs); const char *get_attr_display_name(enum attr_type type); @@ -276,6 +275,7 @@ static typelib_t *current_typelib; %type attribute acf_attribute %type m_attributes attributes attrib_list %type acf_attributes acf_attribute_list +%type dispattributes %type str_list %type m_expr expr expr_const expr_int_const array m_bitfield %type m_exprs /* exprs expr_list */ expr_list_int_const @@ -286,7 +286,7 @@ static typelib_t *current_typelib; %type decl_spec decl_spec_no_type m_decl_spec_no_type %type inherit interface interfacedef %type interfaceref -%type dispinterface dispinterfacehdr dispinterfacedef +%type dispinterface dispinterfacedef %type module modulehdr moduledef %type namespacedef %type base_type int_std @@ -932,17 +932,12 @@ class_interface: m_attributes interfaceref ';' { $$ = make_ifref($2); $$->attrs = $1; } ; -dispinterface: tDISPINTERFACE aIDENTIFIER { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); } - | tDISPINTERFACE aKNOWNTYPE { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); } +dispinterface: + tDISPINTERFACE aIDENTIFIER { $$ = type_dispinterface_declare($2); } + | tDISPINTERFACE aKNOWNTYPE { $$ = type_dispinterface_declare($2); } ; -dispinterfacehdr: attributes dispinterface { attr_t *attrs; - $$ = $2; - check_def($$); - attrs = make_attr(ATTR_DISPINTERFACE); - $$->attrs = append_attr( check_dispiface_attrs($2->name, $1), attrs ); - $$->defined = TRUE; - } +dispattributes: attributes { $$ = append_attr($1, make_attr(ATTR_DISPINTERFACE)); } ; dispint_props: tPROPERTIES ':' { $$ = NULL; } @@ -953,16 +948,11 @@ dispint_meths: tMETHODS ':' { $$ = NULL; } | dispint_meths funcdef ';' { $$ = append_var( $1, $2 ); } ; -dispinterfacedef: dispinterfacehdr '{' - dispint_props - dispint_meths - '}' { $$ = $1; - type_dispinterface_define($$, $3, $4); - } - | dispinterfacehdr - '{' interface ';' '}' { $$ = $1; - type_dispinterface_define_from_iface($$, $3); - } +dispinterfacedef: + dispattributes dispinterface '{' dispint_props dispint_meths '}' + { $$ = type_dispinterface_define($2, $1, $4, $5); } + | dispattributes dispinterface '{' interface ';' '}' + { $$ = type_dispinterface_define_from_iface($2, $1, $4); } ; inherit: { $$ = NULL; } @@ -2214,7 +2204,7 @@ struct allowed_attr allowed_attr[] = /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" }, /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "defaultvtable" }, /* ATTR_DISABLECONSISTENCYCHECK */{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "disable_consistency_check" }, - /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL }, + /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, NULL }, /* ATTR_DISPLAYBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" }, /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "dllname" }, /* ATTR_DUAL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" }, @@ -2471,7 +2461,7 @@ static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs) return attrs; } -static attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs) +attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs) { const attr_t *attr; if (!attrs) return attrs; diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c index 84be75fa3b7..81eaba5556b 100644 --- a/tools/widl/typetree.c +++ b/tools/widl/typetree.c @@ -472,8 +472,21 @@ type_t *type_interface_define(type_t *iface, attr_list_t *attrs, type_t *inherit return iface; } -void type_dispinterface_define(type_t *iface, var_list_t *props, var_list_t *methods) +type_t *type_dispinterface_declare(char *name) { + type_t *type = get_type(TYPE_INTERFACE, name, NULL, 0); + if (type_get_type_detect_alias(type) != TYPE_INTERFACE) + error_loc("dispinterface %s previously not declared a dispinterface at %s:%d\n", + type->name, type->loc_info.input_name, type->loc_info.line_number); + return type; +} + +type_t *type_dispinterface_define(type_t *iface, attr_list_t *attrs, var_list_t *props, var_list_t *methods) +{ + if (iface->defined) + error_loc("dispinterface %s already defined at %s:%d\n", + iface->name, iface->loc_info.input_name, iface->loc_info.line_number); + iface->attrs = check_dispiface_attrs(iface->name, attrs); iface->details.iface = xmalloc(sizeof(*iface->details.iface)); iface->details.iface->disp_props = props; iface->details.iface->disp_methods = methods; @@ -484,10 +497,15 @@ void type_dispinterface_define(type_t *iface, var_list_t *props, var_list_t *met iface->details.iface->async_iface = NULL; iface->defined = TRUE; compute_method_indexes(iface); + return iface; } -void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface) +type_t *type_dispinterface_define_from_iface(type_t *dispiface, attr_list_t *attrs, type_t *iface) { + if (dispiface->defined) + error_loc("dispinterface %s already defined at %s:%d\n", + dispiface->name, dispiface->loc_info.input_name, dispiface->loc_info.line_number); + dispiface->attrs = check_dispiface_attrs(dispiface->name, attrs); dispiface->details.iface = xmalloc(sizeof(*dispiface->details.iface)); dispiface->details.iface->disp_props = NULL; dispiface->details.iface->disp_methods = NULL; @@ -498,6 +516,7 @@ void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface) dispiface->details.iface->async_iface = NULL; dispiface->defined = TRUE; compute_method_indexes(dispiface); + return dispiface; } void type_module_define(type_t *module, statement_list_t *stmts) diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h index 7b67f3b996a..280d2e722cf 100644 --- a/tools/widl/typetree.h +++ b/tools/widl/typetree.h @@ -30,6 +30,7 @@ enum name_type { }; attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs); +attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs); attr_list_t *check_interface_attrs(const char *name, attr_list_t *attrs); attr_list_t *check_runtimeclass_attrs(const char *name, attr_list_t *attrs); @@ -51,8 +52,9 @@ type_t *type_new_bitfield(type_t *field_type, const expr_t *bits); type_t *type_runtimeclass_declare(char *name, struct namespace *namespace); type_t *type_interface_declare(char *name, struct namespace *namespace); type_t *type_interface_define(type_t *iface, attr_list_t *attrs, type_t *inherit, statement_list_t *stmts); -void type_dispinterface_define(type_t *iface, var_list_t *props, var_list_t *methods); -void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface); +type_t *type_dispinterface_declare(char *name); +type_t *type_dispinterface_define(type_t *iface, attr_list_t *attrs, var_list_t *props, var_list_t *methods); +type_t *type_dispinterface_define_from_iface(type_t *dispiface, attr_list_t *attrs, type_t *iface); void type_module_define(type_t *module, statement_list_t *stmts); type_t *type_coclass_define(type_t *coclass, attr_list_t *attrs, ifref_list_t *ifaces); type_t *type_runtimeclass_define(type_t *runtimeclass, attr_list_t *attrs, ifref_list_t *ifaces);