From 6698a2ef7f1b481fb3e9562c4915fefb39635a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Thu, 3 Sep 2020 14:52:07 +0200 Subject: [PATCH] widl: Output interface C names in method argument list. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes WinRT interface generation where only simple names were used instead of the C interface names. With the previous sample idl: #ifdef __WIDL__ #pragma winrt ns_prefix #endif import "wtypes.idl"; namespace Windows { [object] interface IFoo {} [object] interface IBar { HRESULT DoBar([in] IFoo *foo); } } $ widl -o windows.foo.h windows.foo.idl Generated file diff before/after: diff --git a/windows.foo.h b/windows.foo.h index 3790dc7..65151cb 100644 --- a/windows.foo.h +++ b/windows.foo.h @@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl { /*** IBar methods ***/ HRESULT (STDMETHODCALLTYPE *DoBar)( __x_ABI_CWindows_CIBar *This, - IFoo *foo); + __x_ABI_CWindows_CIFoo *foo); END_INTERFACE } __x_ABI_CWindows_CIBarVtbl; @@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar { #define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo) #else /*** IBar methods ***/ -static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) { +static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) { return This->lpVtbl->DoBar(This,foo); } #endif Signed-off-by: RĂ©mi Bernon Signed-off-by: Alexandre Julliard --- tools/widl/client.c | 3 +-- tools/widl/header.c | 42 ++++++++++++++++++++---------------------- tools/widl/header.h | 2 +- tools/widl/proxy.c | 4 ++-- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/tools/widl/client.c b/tools/widl/client.c index 6ef1cee2f73..185ab8dffc2 100644 --- a/tools/widl/client.c +++ b/tools/widl/client.c @@ -61,8 +61,7 @@ static void write_client_func_decl( const type_t *iface, const var_t *func ) fprintf(client, " %s ", callconv); fprintf(client, "%s%s(\n", prefix_client, get_name(func)); indent++; - if (args) - write_args(client, args, iface->name, 0, TRUE); + if (args) write_args(client, args, iface->name, 0, TRUE, NAME_DEFAULT); else print_client("void"); fprintf(client, ")\n"); diff --git a/tools/widl/header.c b/tools/widl/header.c index a319f2425e3..c8a12556cc9 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -43,7 +43,7 @@ user_type_list_t user_type_list = LIST_INIT(user_type_list); context_handle_list_t context_handle_list = LIST_INIT(context_handle_list); generic_handle_list_t generic_handle_list = LIST_INIT(generic_handle_list); -static void write_type_v(FILE *f, const decl_spec_t *t, int is_field, int declonly, const char *name); +static void write_type_v(FILE *f, const decl_spec_t *t, int is_field, int declonly, const char *name, enum name_type name_type); static void indent(FILE *h, int delta) { @@ -250,7 +250,7 @@ static void write_fields(FILE *h, var_list_t *fields) default: ; } - write_type_v(h, &v->declspec, TRUE, v->declonly, name); + write_type_v(h, &v->declspec, TRUE, v->declonly, name, NAME_DEFAULT); fprintf(h, ";\n"); } } @@ -452,7 +452,7 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i case TYPE_INTERFACE: case TYPE_MODULE: case TYPE_COCLASS: - fprintf(h, "%s", t->name); + fprintf(h, "%s", name); break; case TYPE_VOID: fprintf(h, "void"); @@ -500,8 +500,7 @@ void write_type_right(FILE *h, type_t *t, int is_field) { const var_list_t *args = type_function_get_args(t); fputc('(', h); - if (args) - write_args(h, args, NULL, 0, FALSE); + if (args) write_args(h, args, NULL, 0, FALSE, NAME_DEFAULT); else fprintf(h, "void"); fputc(')', h); @@ -533,14 +532,13 @@ void write_type_right(FILE *h, type_t *t, int is_field) } } -static void write_type_v(FILE *h, const decl_spec_t *ds, int is_field, int declonly, const char *name) +static void write_type_v(FILE *h, const decl_spec_t *ds, int is_field, int declonly, const char *name, enum name_type name_type) { type_t *t = ds->type; if (!h) return; - if (t) - write_type_left(h, ds, NAME_DEFAULT, declonly, TRUE); + if (t) write_type_left(h, ds, name_type, declonly, TRUE); if (name) fprintf(h, "%s%s", !t || needs_space_after(t) ? " " : "", name ); @@ -575,7 +573,7 @@ static void write_type_definition(FILE *f, type_t *t, int declonly) void write_type_decl(FILE *f, const decl_spec_t *t, const char *name) { - write_type_v(f, t, FALSE, TRUE, name); + write_type_v(f, t, FALSE, TRUE, name, NAME_DEFAULT); } void write_type_decl_left(FILE *f, const decl_spec_t *ds) @@ -804,7 +802,7 @@ static void write_generic_handle_routines(FILE *header) static void write_typedef(FILE *header, type_t *type, int declonly) { fprintf(header, "typedef "); - write_type_v(header, type_alias_get_aliasee(type), FALSE, declonly, type->name); + write_type_v(header, type_alias_get_aliasee(type), FALSE, declonly, type->name, NAME_DEFAULT); fprintf(header, ";\n"); } @@ -848,7 +846,7 @@ static void write_declaration(FILE *header, const var_t *v) fprintf(header, "extern "); break; } - write_type_v(header, &v->declspec, FALSE, v->declonly, v->name); + write_type_v(header, &v->declspec, FALSE, v->declonly, v->name, NAME_DEFAULT); fprintf(header, ";\n\n"); } } @@ -1065,7 +1063,7 @@ static void write_method_macro(FILE *header, const type_t *iface, const type_t * } } -void write_args(FILE *h, const var_list_t *args, const char *name, int method, int do_indent) +void write_args(FILE *h, const var_list_t *args, const char *name, int method, int do_indent, enum name_type name_type) { const var_t *arg; int count = 0; @@ -1091,7 +1089,7 @@ void write_args(FILE *h, const var_list_t *args, const char *name, int method, i /* In theory we should be writing the definition using write_type_v(..., arg->declonly), * but that causes redefinition in e.g. proxy files. In fact MIDL disallows * defining UDTs inside of an argument list. */ - write_type_decl(h, &arg->declspec, arg->name); + write_type_v(h, &arg->declspec, FALSE, TRUE, arg->name, name_type); if (method == 2) { const expr_t *expr = get_attrp(arg->attrs, ATTR_DEFAULTVALUE); if (expr) { @@ -1153,14 +1151,14 @@ static void write_cpp_method_def(FILE *header, const type_t *iface) --indentation; if (args) { fprintf(header, ",\n"); - write_args(header, args, iface->name, 2, TRUE); + write_args(header, args, iface->name, 2, TRUE, NAME_DEFAULT); } fprintf(header, ") = 0;\n"); indent(header, 0); write_type_decl_left(header, ret); fprintf(header, " %s %s(\n", callconv, get_name(func)); - write_args(header, args, iface->name, 2, TRUE); + write_args(header, args, iface->name, 2, TRUE, NAME_DEFAULT); fprintf(header, ")\n"); indent(header, 0); fprintf(header, "{\n"); @@ -1185,7 +1183,7 @@ static void write_cpp_method_def(FILE *header, const type_t *iface) fprintf(header, "virtual "); write_type_decl_left(header, ret); fprintf(header, " %s %s(\n", callconv, get_name(func)); - write_args(header, args, iface->name, 2, TRUE); + write_args(header, args, iface->name, 2, TRUE, NAME_DEFAULT); fprintf(header, ") = 0;\n"); if (is_aggregate_return(func)) @@ -1222,7 +1220,7 @@ static void write_inline_wrappers(FILE *header, const type_t *iface, const type_ fprintf(header, "static FORCEINLINE "); write_type_decl_left(header, type_function_get_ret(func->declspec.type)); fprintf(header, " %s_%s(", name, get_name(func)); - write_args(header, type_function_get_args(func->declspec.type), name, 1, FALSE); + write_args(header, type_function_get_args(func->declspec.type), name, 1, FALSE, NAME_C); fprintf(header, ") {\n"); ++indentation; if (!is_aggregate_return(func)) { @@ -1286,7 +1284,7 @@ static void do_write_c_method_def(FILE *header, const type_t *iface, const char --indentation; if (type_function_get_args(func->declspec.type)) { fprintf(header, ",\n"); - write_args(header, type_function_get_args(func->declspec.type), name, 0, TRUE); + write_args(header, type_function_get_args(func->declspec.type), name, 0, TRUE, NAME_C); } fprintf(header, ");\n"); fprintf(header, "\n"); @@ -1318,7 +1316,7 @@ static void write_method_proto(FILE *header, const type_t *iface) /* proxy prototype */ write_type_decl_left(header, type_function_get_ret(func->declspec.type)); fprintf(header, " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(func)); - write_args(header, type_function_get_args(func->declspec.type), iface->name, 1, TRUE); + write_args(header, type_function_get_args(func->declspec.type), iface->name, 1, TRUE, NAME_DEFAULT); fprintf(header, ");\n"); /* stub prototype */ fprintf(header, "void __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(func)); @@ -1353,7 +1351,7 @@ static void write_locals(FILE *fp, const type_t *iface, int body) /* proxy prototype - use local prototype */ write_type_decl_left(fp, type_function_get_ret(m->declspec.type)); fprintf(fp, " CALLBACK %s_%s_Proxy(\n", iface->name, get_name(m)); - write_args(fp, type_function_get_args(m->declspec.type), iface->name, 1, TRUE); + write_args(fp, type_function_get_args(m->declspec.type), iface->name, 1, TRUE, NAME_DEFAULT); fprintf(fp, ")"); if (body) { const decl_spec_t *rt = type_function_get_ret(m->declspec.type); @@ -1375,7 +1373,7 @@ static void write_locals(FILE *fp, const type_t *iface, int body) /* stub prototype - use remotable prototype */ write_type_decl_left(fp, type_function_get_ret(func->declspec.type)); fprintf(fp, " __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(m)); - write_args(fp, type_function_get_args(func->declspec.type), iface->name, 1, TRUE); + write_args(fp, type_function_get_args(func->declspec.type), iface->name, 1, TRUE, NAME_DEFAULT); fprintf(fp, ")"); if (body) /* Remotable methods must all return HRESULTs. */ @@ -1429,7 +1427,7 @@ static void write_function_proto(FILE *header, const type_t *iface, const var_t fprintf(header, " %s ", callconv); fprintf(header, "%s%s(\n", prefix, get_name(fun)); if (type_function_get_args(fun->declspec.type)) - write_args(header, type_function_get_args(fun->declspec.type), iface->name, 0, TRUE); + write_args(header, type_function_get_args(fun->declspec.type), iface->name, 0, TRUE, NAME_DEFAULT); else fprintf(header, " void"); fprintf(header, ");\n\n"); diff --git a/tools/widl/header.h b/tools/widl/header.h index cebfd83fe4c..d14e310addf 100644 --- a/tools/widl/header.h +++ b/tools/widl/header.h @@ -47,7 +47,7 @@ extern int need_proxy_file(const statement_list_t *stmts); extern int need_proxy_delegation(const statement_list_t *stmts); extern int need_inline_stubs_file(const statement_list_t *stmts); extern const var_t *is_callas(const attr_list_t *list); -extern void write_args(FILE *h, const var_list_t *arg, const char *name, int obj, int do_indent); +extern void write_args(FILE *h, const var_list_t *arg, const char *name, int obj, int do_indent, enum name_type name_type); extern const type_t* get_explicit_generic_handle_type(const var_t* var); extern const var_t *get_func_handle_var( const type_t *iface, const var_t *func, unsigned char *explicit_fc, unsigned char *implicit_fc ); diff --git a/tools/widl/proxy.c b/tools/widl/proxy.c index d7788e1d57e..457f29a2650 100644 --- a/tools/widl/proxy.c +++ b/tools/widl/proxy.c @@ -204,7 +204,7 @@ static void gen_proxy(type_t *iface, const var_t *func, int idx, if (get_stub_mode() == MODE_Oif && !is_callas( func->attrs )) return; write_type_decl_left(proxy, &retval->declspec); print_proxy( " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(func)); - write_args(proxy, args, iface->name, 1, TRUE); + write_args(proxy, args, iface->name, 1, TRUE, NAME_DEFAULT); print_proxy( ")\n"); write_client_call_routine( proxy, iface, func, "Object", proc_offset ); return; @@ -221,7 +221,7 @@ static void gen_proxy(type_t *iface, const var_t *func, int idx, write_type_decl_left(proxy, &retval->declspec); print_proxy( " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(func)); - write_args(proxy, args, iface->name, 1, TRUE); + write_args(proxy, args, iface->name, 1, TRUE, NAME_DEFAULT); print_proxy( ")\n"); print_proxy( "{\n"); indent ++;