From: Richard Pospesel richard@torproject.org
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- This supersedes https://source.winehq.org/patches/data/167612.
tools/widl/client.c | 2 +- tools/widl/header.c | 52 ++++++++++++++++++++++++-------------------- tools/widl/header.h | 4 ++-- tools/widl/proxy.c | 4 ++-- tools/widl/server.c | 2 +- tools/widl/typegen.c | 13 ++++++----- 6 files changed, 42 insertions(+), 35 deletions(-)
diff --git a/tools/widl/client.c b/tools/widl/client.c index 6b1da134ec..6ef1cee2f7 100644 --- a/tools/widl/client.c +++ b/tools/widl/client.c @@ -54,7 +54,7 @@ static void write_client_func_decl( const type_t *iface, const var_t *func ) { const char *callconv = get_attrp(func->declspec.type->attrs, ATTR_CALLCONV); const var_list_t *args = type_function_get_args(func->declspec.type); - type_t *rettype = type_function_get_rettype(func->declspec.type); + const decl_spec_t *rettype = type_function_get_ret(func->declspec.type);
if (!callconv) callconv = "__cdecl"; write_type_decl_left(client, rettype); diff --git a/tools/widl/header.c b/tools/widl/header.c index b5a88bc107..5bf5d09ef1 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -294,8 +294,9 @@ static void write_pointer_left(FILE *h, type_t *ref) fprintf(h, "*"); }
-void write_type_left(FILE *h, type_t *t, enum name_type name_type, int declonly) +void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, int declonly) { + type_t *t = ds->type; const char *name;
if (!h) return; @@ -351,7 +352,7 @@ void write_type_left(FILE *h, type_t *t, enum name_type name_type, int declonly) break; case TYPE_POINTER: { - write_type_left(h, type_pointer_get_ref_type(t), name_type, declonly); + write_type_left(h, type_pointer_get_ref(t), name_type, declonly); write_pointer_left(h, type_pointer_get_ref_type(t)); if (is_attr(t->attrs, ATTR_CONST)) fprintf(h, "const "); break; @@ -361,7 +362,7 @@ void write_type_left(FILE *h, type_t *t, enum name_type name_type, int declonly) fprintf(h, "%s", t->name); else { - write_type_left(h, type_array_get_element_type(t), name_type, declonly); + write_type_left(h, type_array_get_element(t), name_type, declonly); if (type_array_is_decl_as_ptr(t)) write_pointer_left(h, type_array_get_element_type(t)); } @@ -423,8 +424,11 @@ void write_type_left(FILE *h, type_t *t, enum name_type name_type, int declonly) fprintf(h, "void"); break; case TYPE_BITFIELD: - write_type_left(h, type_bitfield_get_field(t), name_type, declonly); + { + const decl_spec_t ds = {.type = type_bitfield_get_field(t)}; + write_type_left(h, &ds, name_type, declonly); break; + } case TYPE_ALIAS: case TYPE_FUNCTION: /* handled elsewhere */ @@ -501,14 +505,14 @@ static void write_type_v(FILE *h, const decl_spec_t *ds, int is_field, int declo const char *callconv = get_attrp(pt->attrs, ATTR_CALLCONV); if (!callconv && is_object_interface) callconv = "STDMETHODCALLTYPE"; if (is_attr(pt->attrs, ATTR_INLINE)) fprintf(h, "inline "); - write_type_left(h, type_function_get_rettype(pt), NAME_DEFAULT, declonly); + write_type_left(h, type_function_get_ret(pt), NAME_DEFAULT, declonly); fputc(' ', h); if (ptr_level) fputc('(', h); if (callconv) fprintf(h, "%s ", callconv); for (i = 0; i < ptr_level; i++) fputc('*', h); } else - write_type_left(h, t, NAME_DEFAULT, declonly); + write_type_left(h, ds, NAME_DEFAULT, declonly); }
if (name) fprintf(h, "%s%s", !t || needs_space_after(t) ? " " : "", name ); @@ -538,6 +542,7 @@ static void write_type_definition(FILE *f, type_t *t) { int in_namespace = t->namespace && !is_global_namespace(t->namespace); int save_written = t->written; + decl_spec_t ds = {.type = t};
if(in_namespace) { fprintf(f, "#ifdef __cplusplus\n"); @@ -545,14 +550,14 @@ static void write_type_definition(FILE *f, type_t *t) write_namespace_start(f, t->namespace); } indent(f, 0); - write_type_left(f, t, NAME_DEFAULT, FALSE); + write_type_left(f, &ds, NAME_DEFAULT, FALSE); fprintf(f, ";\n"); if(in_namespace) { t->written = save_written; write_namespace_end(f, t->namespace); fprintf(f, "extern "C" {\n"); fprintf(f, "#else\n"); - write_type_left(f, t, NAME_C, FALSE); + write_type_left(f, &ds, NAME_C, FALSE); fprintf(f, ";\n"); fprintf(f, "#endif\n\n"); } @@ -563,9 +568,9 @@ void write_type_decl(FILE *f, const decl_spec_t *t, const char *name) write_type_v(f, t, FALSE, TRUE, name); }
-void write_type_decl_left(FILE *f, type_t *t) +void write_type_decl_left(FILE *f, const decl_spec_t *ds) { - write_type_left(f, t, NAME_DEFAULT, TRUE); + write_type_left(f, ds, NAME_DEFAULT, TRUE); }
static int user_type_registered(const char *name) @@ -1114,6 +1119,7 @@ static void write_cpp_method_def(FILE *header, const type_t *iface) { const var_t *func = stmt->u.var; if (!is_callas(func->attrs)) { + const decl_spec_t *ret = type_function_get_ret(func->declspec.type); const char *callconv = get_attrp(func->declspec.type->attrs, ATTR_CALLCONV); const var_list_t *args = type_function_get_args(func->declspec.type); const var_t *arg; @@ -1125,11 +1131,11 @@ static void write_cpp_method_def(FILE *header, const type_t *iface)
indent(header, 0); fprintf(header, "virtual "); - write_type_decl_left(header, type_function_get_rettype(func->declspec.type)); + write_type_decl_left(header, ret); fprintf(header, "* %s %s(\n", callconv, get_name(func)); ++indentation; indent(header, 0); - write_type_decl_left(header, type_function_get_rettype(func->declspec.type)); + write_type_decl_left(header, ret); fprintf(header, " *__ret"); --indentation; if (args) { @@ -1139,7 +1145,7 @@ static void write_cpp_method_def(FILE *header, const type_t *iface) fprintf(header, ") = 0;\n");
indent(header, 0); - write_type_decl_left(header, type_function_get_rettype(func->declspec.type)); + write_type_decl_left(header, ret); fprintf(header, " %s %s(\n", callconv, get_name(func)); write_args(header, args, iface->name, 2, TRUE); fprintf(header, ")\n"); @@ -1147,7 +1153,7 @@ static void write_cpp_method_def(FILE *header, const type_t *iface) fprintf(header, "{\n"); ++indentation; indent(header, 0); - write_type_decl_left(header, type_function_get_rettype(func->declspec.type)); + write_type_decl_left(header, ret); fprintf(header, " __ret;\n"); indent(header, 0); fprintf(header, "return *%s(&__ret", get_name(func)); @@ -1164,7 +1170,7 @@ static void write_cpp_method_def(FILE *header, const type_t *iface)
indent(header, 0); fprintf(header, "virtual "); - write_type_decl_left(header, type_function_get_rettype(func->declspec.type)); + write_type_decl_left(header, ret); fprintf(header, " %s %s(\n", callconv, get_name(func)); write_args(header, args, iface->name, 2, TRUE); fprintf(header, ") = 0;\n"); @@ -1201,7 +1207,7 @@ static void write_inline_wrappers(FILE *header, const type_t *iface, const type_ const var_t *arg;
fprintf(header, "static FORCEINLINE "); - write_type_decl_left(header, type_function_get_rettype(func->declspec.type)); + 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); fprintf(header, ") {\n"); @@ -1213,7 +1219,7 @@ static void write_inline_wrappers(FILE *header, const type_t *iface, const type_ get_vtbl_entry_name(iface, func)); } else { indent(header, 0); - write_type_decl_left(header, type_function_get_rettype(func->declspec.type)); + write_type_decl_left(header, type_function_get_ret(func->declspec.type)); fprintf(header, " __ret;\n"); indent(header, 0); fprintf(header, "return *This->lpVtbl->%s(This,&__ret", get_vtbl_entry_name(iface, func)); @@ -1248,7 +1254,7 @@ static void do_write_c_method_def(FILE *header, const type_t *iface, const char const char *callconv = get_attrp(func->declspec.type->attrs, ATTR_CALLCONV); if (!callconv) callconv = "STDMETHODCALLTYPE"; indent(header, 0); - write_type_decl_left(header, type_function_get_rettype(func->declspec.type)); + write_type_decl_left(header, type_function_get_ret(func->declspec.type)); if (is_aggregate_return(func)) fprintf(header, " *"); if (is_inherited_method(iface, func)) @@ -1261,7 +1267,7 @@ static void do_write_c_method_def(FILE *header, const type_t *iface, const char if (is_aggregate_return(func)) { fprintf(header, ",\n"); indent(header, 0); - write_type_decl_left(header, type_function_get_rettype(func->declspec.type)); + write_type_decl_left(header, type_function_get_ret(func->declspec.type)); fprintf(header, " *__ret"); } --indentation; @@ -1297,7 +1303,7 @@ static void write_method_proto(FILE *header, const type_t *iface) const char *callconv = get_attrp(func->declspec.type->attrs, ATTR_CALLCONV); if (!callconv) callconv = "STDMETHODCALLTYPE"; /* proxy prototype */ - write_type_decl_left(header, type_function_get_rettype(func->declspec.type)); + 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); fprintf(header, ");\n"); @@ -1332,7 +1338,7 @@ static void write_locals(FILE *fp, const type_t *iface, int body) if (&stmt2->entry != type_iface_get_stmts(iface)) { const var_t *m = stmt2->u.var; /* proxy prototype - use local prototype */ - write_type_decl_left(fp, type_function_get_rettype(m->declspec.type)); + 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); fprintf(fp, ")"); @@ -1354,7 +1360,7 @@ static void write_locals(FILE *fp, const type_t *iface, int body) else fprintf(fp, ";\n"); /* stub prototype - use remotable prototype */ - write_type_decl_left(fp, type_function_get_rettype(func->declspec.type)); + 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); fprintf(fp, ")"); @@ -1406,7 +1412,7 @@ static void write_function_proto(FILE *header, const type_t *iface, const var_t
if (!callconv) callconv = "__cdecl"; /* FIXME: do we need to handle call_as? */ - write_type_decl_left(header, type_function_get_rettype(fun->declspec.type)); + write_type_decl_left(header, type_function_get_ret(fun->declspec.type)); fprintf(header, " %s ", callconv); fprintf(header, "%s%s(\n", prefix, get_name(fun)); if (type_function_get_args(fun->declspec.type)) diff --git a/tools/widl/header.h b/tools/widl/header.h index 8d728c5df5..e047e4e2e4 100644 --- a/tools/widl/header.h +++ b/tools/widl/header.h @@ -29,10 +29,10 @@ extern int is_attr(const attr_list_t *list, enum attr_type t); extern void *get_attrp(const attr_list_t *list, enum attr_type t); extern unsigned int get_attrv(const attr_list_t *list, enum attr_type t); extern const char* get_name(const var_t *v); -extern void write_type_left(FILE *h, type_t *t, enum name_type name_type, int declonly); +extern void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, int declonly); extern void write_type_right(FILE *h, type_t *t, int is_field); extern void write_type_decl(FILE *f, const decl_spec_t *t, const char *name); -extern void write_type_decl_left(FILE *f, type_t *t); +extern void write_type_decl_left(FILE *f, const decl_spec_t *ds); extern unsigned int get_context_handle_offset( const type_t *type ); extern unsigned int get_generic_handle_offset( const type_t *type ); extern int needs_space_after(type_t *t); diff --git a/tools/widl/proxy.c b/tools/widl/proxy.c index 1633e6c9b2..d7788e1d57 100644 --- a/tools/widl/proxy.c +++ b/tools/widl/proxy.c @@ -202,7 +202,7 @@ static void gen_proxy(type_t *iface, const var_t *func, int idx, if (is_interpreted_func( iface, func )) { if (get_stub_mode() == MODE_Oif && !is_callas( func->attrs )) return; - write_type_decl_left(proxy, retval->declspec.type); + 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); print_proxy( ")\n"); @@ -219,7 +219,7 @@ static void gen_proxy(type_t *iface, const var_t *func, int idx, print_proxy( "}\n"); print_proxy( "\n");
- write_type_decl_left(proxy, retval->declspec.type); + 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); print_proxy( ")\n"); diff --git a/tools/widl/server.c b/tools/widl/server.c index 3004efc8d2..79dc079fd2 100644 --- a/tools/widl/server.c +++ b/tools/widl/server.c @@ -185,7 +185,7 @@ static void write_function_stub(const type_t *iface, const var_t *func, unsigned * be direct, otherwise it is a pointer */ const char *ch_ptr = is_aliaschain_attr(var->declspec.type, ATTR_CONTEXTHANDLE) ? "*" : ""; print_server("("); - write_type_decl_left(server, var->declspec.type); + write_type_decl_left(server, &var->declspec); fprintf(server, ")%sNDRSContextValue(__frame->%s)", ch_ptr, var->name); } else diff --git a/tools/widl/typegen.c b/tools/widl/typegen.c index 5d47a72112..55abd0a40c 100644 --- a/tools/widl/typegen.c +++ b/tools/widl/typegen.c @@ -4652,7 +4652,7 @@ void declare_stub_args( FILE *file, int indent, const var_t *func ) }
print_file(file, indent, "%s", ""); - write_type_decl_left(file, var->declspec.type); + write_type_decl_left(file, &var->declspec); fprintf(file, " "); if (type_get_type(var->declspec.type) == TYPE_ARRAY && !type_array_is_decl_as_ptr(var->declspec.type)) { @@ -4805,7 +4805,7 @@ void write_func_param_struct( FILE *file, const type_t *iface, const type_t *fun if (args) LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry ) { print_file(file, 2, "%s", ""); - write_type_left( file, (type_t *)arg->declspec.type, NAME_DEFAULT, TRUE ); + write_type_left( file, &arg->declspec, NAME_DEFAULT, TRUE ); if (needs_space_after( arg->declspec.type )) fputc( ' ', file ); if (is_array( arg->declspec.type ) && !type_array_is_decl_as_ptr( arg->declspec.type )) fputc( '*', file );
@@ -4869,10 +4869,11 @@ int write_expr_eval_routines(FILE *file, const char *iface) } else { + decl_spec_t ds = {.type = (type_t *)eval->cont_type}; print_file(file, 1, "%s", ""); - write_type_left(file, (type_t *)eval->cont_type, NAME_DEFAULT, TRUE); + write_type_left(file, &ds, NAME_DEFAULT, TRUE); fprintf(file, " *%s = (", var_name); - write_type_left(file, (type_t *)eval->cont_type, NAME_DEFAULT, TRUE); + write_type_left(file, &ds, NAME_DEFAULT, TRUE); fprintf(file, " *)(pStubMsg->StackTop - %u);\n", eval->baseoff); } print_file(file, 1, "pStubMsg->Offset = 0;\n"); /* FIXME */ @@ -4966,8 +4967,8 @@ error: void write_client_call_routine( FILE *file, const type_t *iface, const var_t *func, const char *prefix, unsigned int proc_offset ) { - type_t *rettype = type_function_get_rettype( func->declspec.type ); - int has_ret = !is_void( rettype ); + const decl_spec_t *rettype = type_function_get_ret( func->declspec.type ); + int has_ret = !is_void( rettype->type ); const var_list_t *args = type_function_get_args( func->declspec.type ); const var_t *arg; int len, needs_params = 0;