From 8a976a7d785d256eb93b81f3e05bb66234b3d4a4 Mon Sep 17 00:00:00 2001 From: Rob Shearman Date: Mon, 5 Jan 2009 23:35:24 +0000 Subject: [PATCH] widl: Replace uses of get_func_return_type with type_function_get_rettype. Also replace direct accesses into the type structure to get the return type of a function with the same function. --- tools/widl/client.c | 27 +++++++++++++++------------ tools/widl/header.c | 18 +++++++++--------- tools/widl/proxy.c | 19 ++++++++++--------- tools/widl/server.c | 6 +++--- tools/widl/typegen.c | 33 +++++++++++++++++---------------- tools/widl/typetree.h | 6 ++++++ tools/widl/widltypes.h | 5 ----- tools/widl/write_msft.c | 2 +- 8 files changed, 61 insertions(+), 55 deletions(-) diff --git a/tools/widl/client.c b/tools/widl/client.c index 7559786291..a23e298491 100644 --- a/tools/widl/client.c +++ b/tools/widl/client.c @@ -113,7 +113,8 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) print_client("RPC_BINDING_HANDLE _Handle;\n"); } - if (!is_void(get_func_return_type(func)) && decl_indirect(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type)) && + decl_indirect(type_function_get_rettype(func->type))) { print_client("void *_p_%s;\n", "_RetVal" ); } @@ -144,8 +145,8 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) indent--; print_client( "}\n\n" ); - write_type_decl_left(client, get_func_return_type(func)); - if (needs_space_after(get_func_return_type(func))) + write_type_decl_left(client, type_function_get_rettype(func->type)); + if (needs_space_after(type_function_get_rettype(func->type))) fprintf(client, " "); if (callconv) fprintf(client, "%s ", callconv); fprintf(client, "%s%s(\n", prefix_client, get_name(func)); @@ -163,10 +164,10 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) print_client( "struct __frame_%s%s __f, * const __frame = &__f;\n", prefix_client, get_name(func) ); /* declare return value '_RetVal' */ - if (!is_void(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type))) { print_client(""); - write_type_decl_left(client, get_func_return_type(func)); + write_type_decl_left(client, type_function_get_rettype(func->type)); fprintf(client, " _RetVal;\n"); } print_client("RPC_MESSAGE _RpcMessage;\n"); @@ -178,7 +179,8 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) print_client("__frame->%s = %s;\n", explicit_generic_handle_var->name, explicit_generic_handle_var->name ); } - if (!is_void(get_func_return_type(func)) && decl_indirect(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type)) && + decl_indirect(type_function_get_rettype(func->type))) { print_client("__frame->_p_%s = &%s;\n", "_RetVal", "_RetVal"); @@ -285,11 +287,12 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) write_remoting_arguments(client, indent, func, "", PASS_OUT, PHASE_UNMARSHAL); /* unmarshal return value */ - if (!is_void(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type))) { - if (decl_indirect(get_func_return_type(func))) + if (decl_indirect(type_function_get_rettype(func->type))) print_client("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal"); - else if (is_ptr(get_func_return_type(func)) || is_array(get_func_return_type(func))) + else if (is_ptr(type_function_get_rettype(func->type)) || + is_array(type_function_get_rettype(func->type))) print_client("%s = 0;\n", "_RetVal"); write_remoting_arguments(client, indent, func, "", PASS_RETURN, PHASE_UNMARSHAL); } @@ -300,8 +303,8 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) LIST_FOR_EACH_ENTRY( var, args, const var_t, entry ) *proc_offset += get_size_procformatstring_type(var->name, var->type, var->attrs); } - if (!is_void(get_func_return_type(func))) - *proc_offset += get_size_procformatstring_type("return value", get_func_return_type(func), NULL); + if (!is_void(type_function_get_rettype(func->type))) + *proc_offset += get_size_procformatstring_type("return value", type_function_get_rettype(func->type), NULL); else *proc_offset += 2; /* FC_END and FC_PAD */ @@ -317,7 +320,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) /* emit return code */ - if (!is_void(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type))) { fprintf(client, "\n"); print_client("return _RetVal;\n"); diff --git a/tools/widl/header.c b/tools/widl/header.c index e8c53db855..fc09e63feb 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -299,7 +299,7 @@ void write_type_v(FILE *h, type_t *t, int is_field, int declonly, const char *callconv = get_attrp(pt->attrs, ATTR_CALLCONV); if (!callconv) callconv = ""; if (is_attr(pt->attrs, ATTR_INLINE)) fprintf(h, "inline "); - write_type_left(h, pt->ref, declonly); + write_type_left(h, type_function_get_rettype(pt), declonly); fputc(' ', h); if (ptr_level) fputc('(', h); fprintf(h, "%s ", callconv); @@ -589,7 +589,7 @@ int has_out_arg_or_return(const var_t *func) { const var_t *var; - if (!is_void(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type))) return 1; if (!type_get_function_args(func->type)) @@ -700,7 +700,7 @@ static void write_cpp_method_def(FILE *header, const type_t *iface) if (!callconv) callconv = ""; indent(header, 0); fprintf(header, "virtual "); - write_type_decl_left(header, get_func_return_type(func)); + write_type_decl_left(header, type_function_get_rettype(func->type)); fprintf(header, " %s %s(\n", callconv, get_name(func)); write_args(header, type_get_function_args(func->type), iface->name, 2, TRUE); fprintf(header, ") = 0;\n"); @@ -729,7 +729,7 @@ static void do_write_c_method_def(FILE *header, const type_t *iface, const char const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV); if (!callconv) callconv = ""; indent(header, 0); - write_type_decl_left(header, get_func_return_type(func)); + write_type_decl_left(header, type_function_get_rettype(func->type)); fprintf(header, " (%s *%s)(\n", callconv, get_name(func)); write_args(header, type_get_function_args(func->type), name, 1, TRUE); fprintf(header, ");\n"); @@ -760,7 +760,7 @@ static void write_method_proto(FILE *header, const type_t *iface) const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV); if (!callconv) callconv = ""; /* proxy prototype */ - write_type_decl_left(header, get_func_return_type(func)); + write_type_decl_left(header, type_function_get_rettype(func->type)); fprintf(header, " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(func)); write_args(header, type_get_function_args(func->type), iface->name, 1, TRUE); fprintf(header, ");\n"); @@ -795,12 +795,12 @@ 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, get_func_return_type(m)); + write_type_decl_left(fp, type_function_get_rettype(m->type)); fprintf(fp, " CALLBACK %s_%s_Proxy(\n", iface->name, get_name(m)); write_args(fp, type_get_function_args(m->type), iface->name, 1, TRUE); fprintf(fp, ")"); if (body) { - type_t *rt = get_func_return_type(m); + type_t *rt = type_function_get_rettype(m->type); fprintf(fp, "\n{\n"); fprintf(fp, " %s\n", comment); if (rt->name && strcmp(rt->name, "HRESULT") == 0) @@ -817,7 +817,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, get_func_return_type(func)); + write_type_decl_left(fp, type_function_get_rettype(func->type)); fprintf(fp, " __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(m)); write_args(fp, type_get_function_args(func->type), iface->name, 1, TRUE); fprintf(fp, ")"); @@ -870,7 +870,7 @@ static void write_function_proto(FILE *header, const type_t *iface, const var_t const char *callconv = get_attrp(fun->type->attrs, ATTR_CALLCONV); /* FIXME: do we need to handle call_as? */ - write_type_decl_left(header, fun->type->ref); + write_type_decl_left(header, type_function_get_rettype(fun->type)); fprintf(header, " "); if (callconv) fprintf(header, "%s ", callconv); fprintf(header, "%s%s(\n", prefix, get_name(fun)); diff --git a/tools/widl/proxy.c b/tools/widl/proxy.c index e8dc418c7a..878e820ce6 100644 --- a/tools/widl/proxy.c +++ b/tools/widl/proxy.c @@ -300,7 +300,7 @@ static void proxy_free_variables( var_list_t *args, const char *local_var_prefix static void gen_proxy(type_t *iface, const var_t *func, int idx, unsigned int proc_offset) { - int has_ret = !is_void(get_func_return_type(func)); + int has_ret = !is_void(type_function_get_rettype(func->type)); int has_full_pointer = is_full_pointer_function(func); const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV); if (!callconv) callconv = ""; @@ -316,7 +316,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, get_func_return_type(func)); + write_type_decl_left(proxy, type_function_get_rettype(func->type)); print_proxy( " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(func)); write_args(proxy, type_get_function_args(func->type), iface->name, 1, TRUE); print_proxy( ")\n"); @@ -326,12 +326,12 @@ static void gen_proxy(type_t *iface, const var_t *func, int idx, /* local variables */ if (has_ret) { print_proxy( "" ); - write_type_decl_left(proxy, get_func_return_type(func)); + write_type_decl_left(proxy, type_function_get_rettype(func->type)); print_proxy( " _RetVal;\n"); } print_proxy( "RPC_MESSAGE _RpcMessage;\n" ); if (has_ret) { - if (decl_indirect(get_func_return_type(func))) + if (decl_indirect(type_function_get_rettype(func->type))) print_proxy("void *_p_%s = &%s;\n", "_RetVal", "_RetVal"); } @@ -377,9 +377,10 @@ static void gen_proxy(type_t *iface, const var_t *func, int idx, if (has_ret) { - if (decl_indirect(get_func_return_type(func))) + if (decl_indirect(type_function_get_rettype(func->type))) print_proxy("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal"); - else if (is_ptr(get_func_return_type(func)) || is_array(get_func_return_type(func))) + else if (is_ptr(type_function_get_rettype(func->type)) || + is_array(type_function_get_rettype(func->type))) print_proxy("%s = 0;\n", "_RetVal"); write_remoting_arguments(proxy, indent, func, "", PASS_RETURN, PHASE_UNMARSHAL); } @@ -418,7 +419,7 @@ static void gen_stub(type_t *iface, const var_t *func, const char *cas, unsigned int proc_offset) { const var_t *arg; - int has_ret = !is_void(get_func_return_type(func)); + int has_ret = !is_void(type_function_get_rettype(func->type)); int has_full_pointer = is_full_pointer_function(func); indent = 0; @@ -498,7 +499,7 @@ static void gen_stub(type_t *iface, const var_t *func, const char *cas, write_remoting_arguments(proxy, indent, func, "__frame->", PASS_OUT, PHASE_BUFFERSIZE); - if (!is_void(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type))) write_remoting_arguments(proxy, indent, func, "__frame->", PASS_RETURN, PHASE_BUFFERSIZE); print_proxy("NdrStubGetBuffer(This, _pRpcChannelBuffer, &__frame->_StubMsg);\n"); @@ -507,7 +508,7 @@ static void gen_stub(type_t *iface, const var_t *func, const char *cas, fprintf(proxy, "\n"); /* marshall the return value */ - if (!is_void(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type))) write_remoting_arguments(proxy, indent, func, "__frame->", PASS_RETURN, PHASE_MARSHAL); indent--; diff --git a/tools/widl/server.c b/tools/widl/server.c index d0b950e070..3b0e2f40f9 100644 --- a/tools/widl/server.c +++ b/tools/widl/server.c @@ -155,7 +155,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) assign_stub_out_args(server, indent, func, "__frame->"); /* Call the real server function */ - if (!is_void(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type))) print_server("__frame->_RetVal = "); else print_server(""); @@ -201,7 +201,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) { write_remoting_arguments(server, indent, func, "__frame->", PASS_OUT, PHASE_BUFFERSIZE); - if (!is_void(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type))) write_remoting_arguments(server, indent, func, "__frame->", PASS_RETURN, PHASE_BUFFERSIZE); print_server("_pRpcMessage->BufferLength = __frame->_StubMsg.BufferLength;\n"); @@ -220,7 +220,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) write_remoting_arguments(server, indent, func, "__frame->", PASS_OUT, PHASE_MARSHAL); /* marshall the return value */ - if (!is_void(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type))) write_remoting_arguments(server, indent, func, "__frame->", PASS_RETURN, PHASE_MARSHAL); indent--; diff --git a/tools/widl/typegen.c b/tools/widl/typegen.c index 9df00a4896..2436f40b8c 100644 --- a/tools/widl/typegen.c +++ b/tools/widl/typegen.c @@ -541,8 +541,8 @@ void write_parameters_init(FILE *file, int indent, const var_t *func, const char { const var_t *var; - if (!is_void(get_func_return_type(func))) - write_var_init(file, indent, get_func_return_type(func), "_RetVal", local_var_prefix); + if (!is_void(type_function_get_rettype(func->type))) + write_var_init(file, indent, type_function_get_rettype(func->type), "_RetVal", local_var_prefix); if (!type_get_function_args(func->type)) return; @@ -695,13 +695,13 @@ static void write_procformatstring_stmts(FILE *file, int indent, const statement } /* emit return value data */ - if (is_void(get_func_return_type(func))) + if (is_void(type_function_get_rettype(func->type))) { print_file(file, indent, "0x5b, /* FC_END */\n"); print_file(file, indent, "0x5c, /* FC_PAD */\n"); } else - write_procformatstring_type(file, indent, "return value", get_func_return_type(func), NULL, TRUE); + write_procformatstring_type(file, indent, "return value", type_function_get_rettype(func->type), NULL, TRUE); } } else if (stmt->type == STMT_LIBRARY) @@ -1080,7 +1080,7 @@ size_t type_memsize(const type_t *t, unsigned int *align) int is_full_pointer_function(const var_t *func) { const var_t *var; - if (type_has_full_pointer(get_func_return_type(func))) + if (type_has_full_pointer(type_function_get_rettype(func->type))) return TRUE; if (!type_get_function_args(func->type)) return FALSE; @@ -2604,13 +2604,14 @@ static size_t process_tfs_stmts(FILE *file, const statement_list_t *stmts, const var_t *func = stmt_func->u.var; if (is_local(func->attrs)) continue; - if (!is_void(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type))) { var_t v = *func; - v.type = get_func_return_type(func); - update_tfsoff(get_func_return_type(func), + v.type = type_function_get_rettype(func->type); + update_tfsoff(type_function_get_rettype(func->type), write_typeformatstring_var( - file, 2, NULL, get_func_return_type(func), + file, 2, NULL, + type_function_get_rettype(func->type), &v, typeformat_offset), file); } @@ -2768,10 +2769,10 @@ static unsigned int get_function_buffer_size( const var_t *func, enum pass pass } } - if (pass == PASS_OUT && !is_void(get_func_return_type(func))) + if (pass == PASS_OUT && !is_void(type_function_get_rettype(func->type))) { var_t v = *func; - v.type = get_func_return_type(func); + v.type = type_function_get_rettype(func->type); total_size += get_required_buffer_size(&v, &alignment, PASS_RETURN); total_size += alignment; } @@ -3208,7 +3209,7 @@ void write_remoting_arguments(FILE *file, int indent, const var_t *func, const c { var_t var; var = *func; - var.type = get_func_return_type(func); + var.type = type_function_get_rettype(func->type); var.name = xstrdup( "_RetVal" ); write_remoting_arg( file, indent, func, local_var_prefix, pass, phase, &var ); free( var.name ); @@ -3241,10 +3242,10 @@ size_t get_size_procformatstring_func(const var_t *func) size += get_size_procformatstring_type(var->name, var->type, var->attrs); /* return value size */ - if (is_void(get_func_return_type(func))) + if (is_void(type_function_get_rettype(func->type))) size += 2; /* FC_END and FC_PAD */ else - size += get_size_procformatstring_type("return value", get_func_return_type(func), NULL); + size += get_size_procformatstring_type("return value", type_function_get_rettype(func->type), NULL); return size; } @@ -3294,10 +3295,10 @@ void declare_stub_args( FILE *file, int indent, const var_t *func ) const var_t *var; /* declare return value '_RetVal' */ - if (!is_void(get_func_return_type(func))) + if (!is_void(type_function_get_rettype(func->type))) { print_file(file, indent, ""); - write_type_decl_left(file, get_func_return_type(func)); + write_type_decl_left(file, type_function_get_rettype(func->type)); fprintf(file, " _RetVal;\n"); } diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h index 69751254e0..1538541197 100644 --- a/tools/widl/typetree.h +++ b/tools/widl/typetree.h @@ -49,6 +49,12 @@ static inline var_list_t *type_function_get_args(const type_t *type) return type->details.function->args; } +static inline type_t *type_function_get_rettype(const type_t *type) +{ + assert(type->type == RPC_FC_FUNCTION); + return type->ref; +} + static inline var_list_t *type_enum_get_values(const type_t *type) { assert(type->type == RPC_FC_ENUM16 || type->type == RPC_FC_ENUM32); diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 9dd23bf18a..fe8c25045b 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -455,11 +455,6 @@ type_t *make_type(unsigned char type, type_t *ref); void init_loc_info(loc_info_t *); -static inline type_t *get_func_return_type(const var_t *func) -{ - return func->type->ref; -} - static inline var_list_t *type_get_function_args(const type_t *func_type) { return func_type->details.function->args; diff --git a/tools/widl/write_msft.c b/tools/widl/write_msft.c index 5e28432797..04195ff4a0 100644 --- a/tools/widl/write_msft.c +++ b/tools/widl/write_msft.c @@ -1438,7 +1438,7 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, var_t *func, int index) /* fill out the basic type information */ typedata[0] = typedata_size | (index << 16); - encode_var(typeinfo->typelib, get_func_return_type(func), func, &typedata[1], NULL, NULL, &decoded_size); + encode_var(typeinfo->typelib, type_function_get_rettype(func->type), func, &typedata[1], NULL, NULL, &decoded_size); typedata[2] = funcflags; typedata[3] = ((52 /*sizeof(FUNCDESC)*/ + decoded_size) << 16) | typeinfo->typeinfo->cbSizeVft; typedata[4] = (next_idx << 16) | (callconv << 8) | (invokekind << 3) | funckind;