Rebase against 4f1b297a14bbd304fb20da7c4b64266c14d110e5.

This commit is contained in:
Zebediah Figura
2021-02-05 18:01:09 -06:00
parent a2f82c5c85
commit 677b445b0d
24 changed files with 105 additions and 1969 deletions

View File

@@ -1,162 +0,0 @@
From 72fb994d9750998fde2d8ecbb9bd98983aeb66f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Bernon?= <rbernon@codeweavers.com>
Date: Thu, 4 Feb 2021 10:35:39 +0100
Subject: [PATCH] widl: Factor and cleanup interface type declaration and
definition.
---
tools/widl/parser.y | 34 ++++++++++------------------------
tools/widl/typetree.c | 19 ++++++++++++++++++-
tools/widl/typetree.h | 4 +++-
3 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index 1505e3e88a0..44716deb5b6 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -87,7 +87,6 @@ static void push_lookup_namespace(const char *name);
static void check_arg_attrs(const var_t *arg);
static void check_statements(const statement_list_t *stmts, int is_inside_library);
static void check_all_user_types(const statement_list_t *stmts);
-static attr_list_t *check_iface_attrs(const char *name, attr_list_t *attrs);
static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs);
static attr_list_t *check_typedef_attrs(attr_list_t *attrs);
static attr_list_t *check_enum_attrs(attr_list_t *attrs);
@@ -281,7 +280,6 @@ static typelib_t *current_typelib;
%type <expr> m_expr expr expr_const expr_int_const array m_bitfield
%type <expr_list> m_exprs /* exprs expr_list */ expr_list_int_const
%type <expr> contract_req
-%type <type> interfacehdr
%type <stgclass> storage_cls_spec
%type <type_qualifier> type_qualifier m_type_qual_list
%type <function_specifier> function_specifier
@@ -971,31 +969,20 @@ inherit: { $$ = NULL; }
| ':' qualified_type { $$ = $2; }
;
-interface: tINTERFACE aIDENTIFIER { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
- | tINTERFACE aKNOWNTYPE { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
+interface:
+ tINTERFACE aIDENTIFIER { $$ = type_interface_declare($2, current_namespace); }
+ | tINTERFACE aKNOWNTYPE { $$ = type_interface_declare($2, current_namespace); }
;
-interfacehdr: attributes interface { $$ = $2;
- check_def($2);
- $2->attrs = check_iface_attrs($2->name, $1);
- $2->defined = TRUE;
- }
- ;
-
-interfacedef: interfacehdr inherit
- '{' int_statements '}' semicolon_opt { $$ = $1;
- if($$ == $2)
- error_loc("Interface can't inherit from itself\n");
- type_interface_define($$, $2, $4);
+interfacedef: attributes interface inherit
+ '{' int_statements '}' semicolon_opt { $$ = type_interface_define($2, $1, $3, $5);
check_async_uuid($$);
}
/* MIDL is able to import the definition of a base class from inside the
* definition of a derived class, I'll try to support it with this rule */
- | interfacehdr ':' aIDENTIFIER
+ | attributes interface ':' aIDENTIFIER
'{' import int_statements '}'
- semicolon_opt { $$ = $1;
- type_interface_define($$, find_type_or_error($3), $6);
- }
+ semicolon_opt { $$ = type_interface_define($2, $1, find_type_or_error($4), $7); }
| dispinterfacedef semicolon_opt { $$ = $1; }
;
@@ -2340,7 +2327,7 @@ const char *get_attr_display_name(enum attr_type type)
return allowed_attr[type].display_name;
}
-static attr_list_t *check_iface_attrs(const char *name, attr_list_t *attrs)
+attr_list_t *check_interface_attrs(const char *name, attr_list_t *attrs)
{
const attr_t *attr;
if (!attrs) return attrs;
@@ -2978,8 +2965,7 @@ static void check_async_uuid(type_t *iface)
if (!inherit)
error_loc("async_uuid applied to an interface with incompatible parent\n");
- async_iface = get_type(TYPE_INTERFACE, strmake("Async%s", iface->name), iface->namespace, 0);
- async_iface->attrs = map_attrs(iface->attrs, async_iface_attrs);
+ async_iface = type_interface_declare(strmake("Async%s", iface->name), iface->namespace);
STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
{
@@ -3010,7 +2996,7 @@ static void check_async_uuid(type_t *iface)
stmts = append_statement(stmts, make_statement_declaration(finish_func));
}
- type_interface_define(async_iface, inherit, stmts);
+ type_interface_define(async_iface, map_attrs(iface->attrs, async_iface_attrs), inherit, stmts);
iface->details.iface->async_iface = async_iface->details.iface->async_iface = async_iface;
}
diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c
index 825348ddef4..84be75fa3b7 100644
--- a/tools/widl/typetree.c
+++ b/tools/widl/typetree.c
@@ -442,8 +442,24 @@ static unsigned int compute_method_indexes(type_t *iface)
return idx;
}
-void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts)
+type_t *type_interface_declare(char *name, struct namespace *namespace)
{
+ type_t *type = get_type(TYPE_INTERFACE, name, namespace, 0);
+ if (type_get_type_detect_alias(type) != TYPE_INTERFACE)
+ error_loc("interface %s previously not declared an interface at %s:%d\n",
+ type->name, type->loc_info.input_name, type->loc_info.line_number);
+ return type;
+}
+
+type_t *type_interface_define(type_t *iface, attr_list_t *attrs, type_t *inherit, statement_list_t *stmts)
+{
+ if (iface->defined)
+ error_loc("interface %s already defined at %s:%d\n",
+ iface->name, iface->loc_info.input_name, iface->loc_info.line_number);
+ if (iface == inherit)
+ error_loc("interface %s can't inherit from itself\n",
+ iface->name);
+ iface->attrs = check_interface_attrs(iface->name, attrs);
iface->details.iface = xmalloc(sizeof(*iface->details.iface));
iface->details.iface->disp_props = NULL;
iface->details.iface->disp_methods = NULL;
@@ -453,6 +469,7 @@ void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stm
iface->details.iface->async_iface = NULL;
iface->defined = TRUE;
compute_method_indexes(iface);
+ return iface;
}
void type_dispinterface_define(type_t *iface, var_list_t *props, var_list_t *methods)
diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h
index 8a8e1c529ac..7b67f3b996a 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_interface_attrs(const char *name, attr_list_t *attrs);
attr_list_t *check_runtimeclass_attrs(const char *name, attr_list_t *attrs);
type_t *type_new_function(var_list_t *args);
@@ -48,7 +49,8 @@ type_t *type_new_nonencapsulated_union(const char *name, int defined, var_list_t
type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases);
type_t *type_new_bitfield(type_t *field_type, const expr_t *bits);
type_t *type_runtimeclass_declare(char *name, struct namespace *namespace);
-void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts);
+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);
void type_module_define(type_t *module, statement_list_t *stmts);
--
2.20.1

View File

@@ -1,182 +0,0 @@
From ae71cd3e9512f1b96ef79eb76507046128e94f6e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Bernon?= <rbernon@codeweavers.com>
Date: Thu, 4 Feb 2021 10:34:24 +0100
Subject: [PATCH] widl: Factor and cleanup dispinterface type declaration and
definition.
---
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 <attr> attribute acf_attribute
%type <attr_list> m_attributes attributes attrib_list
%type <attr_list> acf_attributes acf_attribute_list
+%type <attr_list> dispattributes
%type <str_list> str_list
%type <expr> m_expr expr expr_const expr_int_const array m_bitfield
%type <expr_list> m_exprs /* exprs expr_list */ expr_list_int_const
@@ -286,7 +286,7 @@ static typelib_t *current_typelib;
%type <declspec> decl_spec decl_spec_no_type m_decl_spec_no_type
%type <type> inherit interface interfacedef
%type <type> interfaceref
-%type <type> dispinterface dispinterfacehdr dispinterfacedef
+%type <type> dispinterface dispinterfacedef
%type <type> module modulehdr moduledef
%type <str> namespacedef
%type <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);
--
2.20.1

View File

@@ -1,154 +0,0 @@
From 623643c78b618ae83aaebaaf16988d8765bf5eff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Bernon?= <rbernon@codeweavers.com>
Date: Thu, 4 Feb 2021 10:56:18 +0100
Subject: [PATCH] widl: Factor and cleanup apicontract type declaration and
definition.
And remove unused check_def helper.
---
tools/widl/parser.y | 35 +++++++++++++++--------------------
tools/widl/typetree.c | 19 +++++++++++++++++++
tools/widl/typetree.h | 3 +++
3 files changed, 37 insertions(+), 20 deletions(-)
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index 349e4730d96..8c805e481f8 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -96,10 +96,8 @@ 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_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);
static void add_explicit_handle_if_necessary(const type_t *iface, var_t *func);
-static void check_def(const type_t *t);
static void check_async_uuid(type_t *iface);
@@ -305,7 +303,7 @@ static typelib_t *current_typelib;
%type <declarator_list> declarator_list struct_declarator_list
%type <type> coclass coclassdef
%type <type> runtimeclass runtimeclass_def
-%type <type> apicontract
+%type <type> apicontract apicontract_def
%type <num> contract_ver
%type <num> pointer_type threading_type marshaling_behavior version
%type <str> libraryhdr callconv cppquote importlib import t_ident
@@ -364,8 +362,9 @@ gbl_statements: { $$ = NULL; }
| gbl_statements coclassdef { $$ = append_statement($1, make_statement_type_decl($2));
reg_type($2, $2->name, current_namespace, 0);
}
- | gbl_statements apicontract ';' { $$ = append_statement($1, make_statement_type_decl($2));
- reg_type($2, $2->name, current_namespace, 0); }
+ | gbl_statements apicontract ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
+ | gbl_statements apicontract_def { $$ = append_statement($1, make_statement_type_decl($2));
+ reg_type($2, $2->name, current_namespace, 0); }
| gbl_statements runtimeclass ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
| gbl_statements runtimeclass_def { $$ = append_statement($1, make_statement_type_decl($2));
reg_type($2, $2->name, current_namespace, 0); }
@@ -384,8 +383,9 @@ imp_statements: { $$ = NULL; }
| imp_statements coclassdef { $$ = append_statement($1, make_statement_type_decl($2));
reg_type($2, $2->name, current_namespace, 0);
}
- | imp_statements apicontract ';' { $$ = append_statement($1, make_statement_type_decl($2));
- reg_type($2, $2->name, current_namespace, 0); }
+ | imp_statements apicontract ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
+ | imp_statements apicontract_def { $$ = append_statement($1, make_statement_type_decl($2));
+ reg_type($2, $2->name, current_namespace, 0); }
| imp_statements runtimeclass ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
| imp_statements runtimeclass_def { $$ = append_statement($1, make_statement_type_decl($2));
reg_type($2, $2->name, current_namespace, 0); }
@@ -913,11 +913,13 @@ runtimeclass_def: attributes runtimeclass '{' class_interfaces '}' semicolon_opt
{ $$ = type_runtimeclass_define($2, $1, $4); }
;
-apicontract: attributes tAPICONTRACT aIDENTIFIER '{' '}'
- { $$ = get_type(TYPE_APICONTRACT, $3, current_namespace, 0);
- check_def($$);
- $$->attrs = check_apicontract_attrs($$->name, $1);
- }
+apicontract:
+ tAPICONTRACT aIDENTIFIER { $$ = type_apicontract_declare($2, current_namespace); }
+ | tAPICONTRACT aKNOWNTYPE { $$ = type_apicontract_declare($2, current_namespace); }
+ ;
+
+apicontract_def: attributes apicontract '{' '}' semicolon_opt
+ { $$ = type_apicontract_define($2, $1); }
;
namespacedef: tNAMESPACE aIDENTIFIER { $$ = $2; }
@@ -2511,7 +2513,7 @@ attr_list_t *check_runtimeclass_attrs(const char *name, attr_list_t *attrs)
return attrs;
}
-static attr_list_t *check_apicontract_attrs(const char *name, attr_list_t *attrs)
+attr_list_t *check_apicontract_attrs(const char *name, attr_list_t *attrs)
{
const attr_t *attr;
if (!attrs) return attrs;
@@ -3205,10 +3207,3 @@ void init_loc_info(loc_info_t *i)
i->line_number = line_number;
i->near_text = parser_text;
}
-
-static void check_def(const type_t *t)
-{
- if (t->defined)
- error_loc("%s: redefinition error; original definition was at %s:%d\n",
- t->name, t->loc_info.input_name, t->loc_info.line_number);
-}
diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c
index 81eaba5556b..004f7fc7b0d 100644
--- a/tools/widl/typetree.c
+++ b/tools/widl/typetree.c
@@ -569,6 +569,25 @@ type_t *type_runtimeclass_define(type_t *runtimeclass, attr_list_t *attrs, ifref
return runtimeclass;
}
+type_t *type_apicontract_declare(char *name, struct namespace *namespace)
+{
+ type_t *type = get_type(TYPE_APICONTRACT, name, namespace, 0);
+ if (type_get_type_detect_alias(type) != TYPE_APICONTRACT)
+ error_loc("apicontract %s previously not declared a apicontract at %s:%d\n",
+ type->name, type->loc_info.input_name, type->loc_info.line_number);
+ return type;
+}
+
+type_t *type_apicontract_define(type_t *apicontract, attr_list_t *attrs)
+{
+ if (apicontract->defined)
+ error_loc("apicontract %s already defined at %s:%d\n",
+ apicontract->name, apicontract->loc_info.input_name, apicontract->loc_info.line_number);
+ apicontract->attrs = check_apicontract_attrs(apicontract->name, attrs);
+ apicontract->defined = TRUE;
+ return apicontract;
+}
+
int type_is_equal(const type_t *type1, const type_t *type2)
{
if (type_get_type_detect_alias(type1) != type_get_type_detect_alias(type2))
diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h
index 280d2e722cf..7c19da8e045 100644
--- a/tools/widl/typetree.h
+++ b/tools/widl/typetree.h
@@ -29,6 +29,7 @@ enum name_type {
NAME_C
};
+attr_list_t *check_apicontract_attrs(const char *name, attr_list_t *attrs);
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);
@@ -58,6 +59,8 @@ type_t *type_dispinterface_define_from_iface(type_t *dispiface, attr_list_t *att
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);
+type_t *type_apicontract_declare(char *name, struct namespace *namespace);
+type_t *type_apicontract_define(type_t *apicontract, attr_list_t *attrs);
int type_is_equal(const type_t *type1, const type_t *type2);
const char *type_get_name(const type_t *type, enum name_type name_type);
char *gen_name(void);
--
2.20.1

View File

@@ -1,146 +0,0 @@
From fd50398643cafcfa3868a9e47429db7136a16ef5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Bernon?= <rbernon@codeweavers.com>
Date: Thu, 4 Feb 2021 11:02:09 +0100
Subject: [PATCH] widl: Factor and cleanup module type declaration and
definition.
---
tools/widl/parser.y | 20 ++++++--------------
tools/widl/typetree.c | 27 +++++++++++++++------------
tools/widl/typetree.h | 5 +++--
3 files changed, 24 insertions(+), 28 deletions(-)
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index 8c805e481f8..782ed39643c 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_module_attrs(const char *name, attr_list_t *attrs);
const char *get_attr_display_name(enum attr_type type);
static void add_explicit_handle_if_necessary(const type_t *iface, var_t *func);
@@ -285,7 +284,7 @@ static typelib_t *current_typelib;
%type <type> inherit interface interfacedef
%type <type> interfaceref
%type <type> dispinterface dispinterfacedef
-%type <type> module modulehdr moduledef
+%type <type> module moduledef
%type <str> namespacedef
%type <type> base_type int_std
%type <type> enumdef structdef uniondef typedecl
@@ -985,19 +984,12 @@ interfaceref:
| tDISPINTERFACE aKNOWNTYPE { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
;
-module: tMODULE aIDENTIFIER { $$ = type_new_module($2); }
- | tMODULE aKNOWNTYPE { $$ = type_new_module($2); }
+module: tMODULE aIDENTIFIER { $$ = type_module_declare($2); }
+ | tMODULE aKNOWNTYPE { $$ = type_module_declare($2); }
;
-modulehdr: attributes module { $$ = $2;
- $$->attrs = check_module_attrs($2->name, $1);
- }
- ;
-
-moduledef: modulehdr '{' int_statements '}'
- semicolon_opt { $$ = $1;
- type_module_define($$, $3);
- }
+moduledef: attributes module '{' int_statements '}' semicolon_opt
+ { $$ = type_module_define($2, $1, $4); }
;
storage_cls_spec:
@@ -2476,7 +2468,7 @@ attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs)
return attrs;
}
-static attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs)
+attr_list_t *check_module_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 004f7fc7b0d..b3f0725f00e 100644
--- a/tools/widl/typetree.c
+++ b/tools/widl/typetree.c
@@ -195,16 +195,6 @@ type_t *type_new_alias(const decl_spec_t *t, const char *name)
return a;
}
-type_t *type_new_module(char *name)
-{
- type_t *type = get_type(TYPE_MODULE, name, NULL, 0);
- if (type->type_type != TYPE_MODULE || type->defined)
- error_loc("%s: redefinition error; original definition was at %s:%d\n",
- type->name, type->loc_info.input_name, type->loc_info.line_number);
- type->name = name;
- return type;
-}
-
type_t *type_new_array(const char *name, const decl_spec_t *element, int declptr,
unsigned int dim, expr_t *size_is, expr_t *length_is)
{
@@ -519,12 +509,25 @@ type_t *type_dispinterface_define_from_iface(type_t *dispiface, attr_list_t *att
return dispiface;
}
-void type_module_define(type_t *module, statement_list_t *stmts)
+type_t *type_module_declare(char *name)
+{
+ type_t *type = get_type(TYPE_MODULE, name, NULL, 0);
+ if (type_get_type_detect_alias(type) != TYPE_MODULE)
+ error_loc("module %s previously not declared a module at %s:%d\n",
+ type->name, type->loc_info.input_name, type->loc_info.line_number);
+ return type;
+}
+
+type_t *type_module_define(type_t* module, attr_list_t *attrs, statement_list_t *stmts)
{
- if (module->details.module) error_loc("multiple definition error\n");
+ if (module->defined)
+ error_loc("module %s already defined at %s:%d\n",
+ module->name, module->loc_info.input_name, module->loc_info.line_number);
+ module->attrs = check_module_attrs(module->name, attrs);
module->details.module = xmalloc(sizeof(*module->details.module));
module->details.module->stmts = stmts;
module->defined = TRUE;
+ return module;
}
type_t *type_coclass_declare(char *name)
diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h
index 7c19da8e045..8e04537ab4d 100644
--- a/tools/widl/typetree.h
+++ b/tools/widl/typetree.h
@@ -33,12 +33,13 @@ attr_list_t *check_apicontract_attrs(const char *name, attr_list_t *attrs);
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_module_attrs(const char *name, attr_list_t *attrs);
attr_list_t *check_runtimeclass_attrs(const char *name, attr_list_t *attrs);
type_t *type_new_function(var_list_t *args);
type_t *type_new_pointer(type_t *ref);
type_t *type_new_alias(const decl_spec_t *t, const char *name);
-type_t *type_new_module(char *name);
+type_t *type_module_declare(char *name);
type_t *type_new_array(const char *name, const decl_spec_t *element, int declptr,
unsigned int dim, expr_t *size_is, expr_t *length_is);
type_t *type_new_basic(enum type_basic_type basic_type);
@@ -56,7 +57,7 @@ type_t *type_interface_define(type_t *iface, attr_list_t *attrs, type_t *inherit
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_module_define(type_t* module, attr_list_t *attrs, 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);
type_t *type_apicontract_declare(char *name, struct namespace *namespace);
--
2.20.1

View File

@@ -1,159 +0,0 @@
From bc7044d3cd826d7b3e01566514f9515c3fd7bc5c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Bernon?= <rbernon@codeweavers.com>
Date: Thu, 4 Feb 2021 16:46:40 +0100
Subject: [PATCH] widl: Fold aIDENTIFIER / aKNOWNTYPE rules together.
Splitting t_ident rule as typename / m_typename rules.
---
tools/widl/parser.y | 55 ++++++++++++++++++---------------------------
1 file changed, 22 insertions(+), 33 deletions(-)
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index 782ed39643c..2d527805c14 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -305,7 +305,8 @@ static typelib_t *current_typelib;
%type <type> apicontract apicontract_def
%type <num> contract_ver
%type <num> pointer_type threading_type marshaling_behavior version
-%type <str> libraryhdr callconv cppquote importlib import t_ident
+%type <str> libraryhdr callconv cppquote importlib import
+%type <str> typename m_typename
%type <uuid> uuid_string
%type <import> import_start
%type <typelib> library_start librarydef
@@ -459,8 +460,7 @@ importlib: tIMPORTLIB '(' aSTRING ')'
semicolon_opt { $$ = $3; if(!parse_only) add_importlib($3, current_typelib); }
;
-libraryhdr: tLIBRARY aIDENTIFIER { $$ = $2; }
- | tLIBRARY aKNOWNTYPE { $$ = $2; }
+libraryhdr: tLIBRARY typename { $$ = $2; }
;
library_start: attributes libraryhdr '{' { $$ = make_library($2, check_library_attrs($2, $1));
if (!parse_only && do_typelib) current_typelib = $$;
@@ -715,7 +715,7 @@ enum: enum_member '=' expr_int_const { $$ = reg_const($1);
}
;
-enumdef: tENUM t_ident '{' enums '}' { $$ = type_new_enum($2, current_namespace, TRUE, $4); }
+enumdef: tENUM m_typename '{' enums '}' { $$ = type_new_enum($2, current_namespace, TRUE, $4); }
;
m_exprs: m_expr { $$ = append_expr( NULL, $1 ); }
@@ -847,14 +847,15 @@ m_ident: { $$ = NULL; }
| ident
;
-t_ident: { $$ = NULL; }
- | aIDENTIFIER { $$ = $1; }
- | aKNOWNTYPE { $$ = $1; }
+m_typename: { $$ = NULL; }
+ | typename
;
-ident: aIDENTIFIER { $$ = make_var($1); }
-/* some "reserved words" used in attributes are also used as field names in some MS IDL files */
- | aKNOWNTYPE { $$ = make_var($<str>1); }
+typename: aIDENTIFIER
+ | aKNOWNTYPE
+ ;
+
+ident: typename { $$ = make_var($1); }
;
base_type: tBYTE { $$ = find_type_or_error($<str>1); }
@@ -895,26 +896,21 @@ qualified_type:
| aNAMESPACE '.' { init_lookup_namespace($1); } qualified_seq { $$ = $4; }
;
-coclass: tCOCLASS aIDENTIFIER { $$ = type_coclass_declare($2); }
- | tCOCLASS aKNOWNTYPE { $$ = type_coclass_declare($2); }
+coclass: tCOCLASS typename { $$ = type_coclass_declare($2); }
;
coclassdef: attributes coclass '{' class_interfaces '}' semicolon_opt
{ $$ = type_coclass_define($2, $1, $4); }
;
-runtimeclass:
- tRUNTIMECLASS aIDENTIFIER { $$ = type_runtimeclass_declare($2, current_namespace); }
- | tRUNTIMECLASS aKNOWNTYPE { $$ = type_runtimeclass_declare($2, current_namespace); }
+runtimeclass: tRUNTIMECLASS typename { $$ = type_runtimeclass_declare($2, current_namespace); }
;
runtimeclass_def: attributes runtimeclass '{' class_interfaces '}' semicolon_opt
{ $$ = type_runtimeclass_define($2, $1, $4); }
;
-apicontract:
- tAPICONTRACT aIDENTIFIER { $$ = type_apicontract_declare($2, current_namespace); }
- | tAPICONTRACT aKNOWNTYPE { $$ = type_apicontract_declare($2, current_namespace); }
+apicontract: tAPICONTRACT typename { $$ = type_apicontract_declare($2, current_namespace); }
;
apicontract_def: attributes apicontract '{' '}' semicolon_opt
@@ -933,9 +929,7 @@ class_interface:
m_attributes interfaceref ';' { $$ = make_ifref($2); $$->attrs = $1; }
;
-dispinterface:
- tDISPINTERFACE aIDENTIFIER { $$ = type_dispinterface_declare($2); }
- | tDISPINTERFACE aKNOWNTYPE { $$ = type_dispinterface_declare($2); }
+dispinterface: tDISPINTERFACE typename { $$ = type_dispinterface_declare($2); }
;
dispattributes: attributes { $$ = append_attr($1, make_attr(ATTR_DISPINTERFACE)); }
@@ -960,9 +954,7 @@ inherit: { $$ = NULL; }
| ':' qualified_type { $$ = $2; }
;
-interface:
- tINTERFACE aIDENTIFIER { $$ = type_interface_declare($2, current_namespace); }
- | tINTERFACE aKNOWNTYPE { $$ = type_interface_declare($2, current_namespace); }
+interface: tINTERFACE typename { $$ = type_interface_declare($2, current_namespace); }
;
interfacedef: attributes interface inherit
@@ -978,14 +970,11 @@ interfacedef: attributes interface inherit
;
interfaceref:
- tINTERFACE aIDENTIFIER { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
- | tINTERFACE aKNOWNTYPE { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
- | tDISPINTERFACE aIDENTIFIER { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
- | tDISPINTERFACE aKNOWNTYPE { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
+ tINTERFACE typename { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
+ | tDISPINTERFACE typename { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
;
-module: tMODULE aIDENTIFIER { $$ = type_module_declare($2); }
- | tMODULE aKNOWNTYPE { $$ = type_module_declare($2); }
+module: tMODULE typename { $$ = type_module_declare($2); }
;
moduledef: attributes module '{' int_statements '}' semicolon_opt
@@ -1153,7 +1142,7 @@ pointer_type:
| tPTR { $$ = FC_FP; }
;
-structdef: tSTRUCT t_ident '{' fields '}' { $$ = type_new_struct($2, current_namespace, TRUE, $4); }
+structdef: tSTRUCT m_typename '{' fields '}' { $$ = type_new_struct($2, current_namespace, TRUE, $4); }
;
type: tVOID { $$ = type_new_void(); }
@@ -1175,9 +1164,9 @@ typedef: m_attributes tTYPEDEF m_attributes decl_spec declarator_list
}
;
-uniondef: tUNION t_ident '{' ne_union_fields '}'
+uniondef: tUNION m_typename '{' ne_union_fields '}'
{ $$ = type_new_nonencapsulated_union($2, TRUE, $4); }
- | tUNION t_ident
+ | tUNION m_typename
tSWITCH '(' s_field ')'
m_ident '{' cases '}' { $$ = type_new_encapsulated_union($2, $5, $7, $9); }
;
--
2.20.1