widl: Make the function return value a variable.

This commit is contained in:
Alexandre Julliard 2011-09-17 13:38:15 +02:00
parent 05ff9dfeb1
commit c31948a775
6 changed files with 51 additions and 50 deletions

View File

@ -74,9 +74,9 @@ static void write_function_stub( const type_t *iface, const var_t *func,
{
unsigned char explicit_fc, implicit_fc;
int has_full_pointer = is_full_pointer_function(func);
type_t *rettype = type_function_get_rettype(func->type);
var_t *retval = type_function_get_retval(func->type);
const var_t *handle_var = get_func_handle_var( iface, func, &explicit_fc, &implicit_fc );
int has_ret = !is_void(rettype);
int has_ret = !is_void(retval->type);
if (is_interpreted_func( iface, func ))
{
@ -97,9 +97,9 @@ static void write_function_stub( const type_t *iface, const var_t *func,
print_client("RPC_BINDING_HANDLE _Handle;\n");
}
if (has_ret && decl_indirect(rettype))
if (has_ret && decl_indirect(retval->type))
{
print_client("void *_p_%s;\n", "_RetVal" );
print_client("void *_p_%s;\n", retval->name);
}
indent--;
print_client( "};\n\n" );
@ -132,12 +132,12 @@ static void write_function_stub( const type_t *iface, const var_t *func,
indent++;
print_client( "struct __frame_%s%s __f, * const __frame = &__f;\n", prefix_client, get_name(func) );
/* declare return value '_RetVal' */
/* declare return value */
if (has_ret)
{
print_client("%s", "");
write_type_decl_left(client, rettype);
fprintf(client, " _RetVal;\n");
write_type_decl(client, retval->type, retval->name);
fprintf(client, ";\n");
}
print_client("RPC_MESSAGE _RpcMessage;\n");
@ -147,10 +147,9 @@ static void write_function_stub( const type_t *iface, const var_t *func,
if (explicit_fc == RPC_FC_BIND_GENERIC)
print_client("__frame->%s = %s;\n", handle_var->name, handle_var->name );
}
if (has_ret && decl_indirect(rettype))
if (has_ret && decl_indirect(retval->type))
{
print_client("__frame->_p_%s = &%s;\n",
"_RetVal", "_RetVal");
print_client("__frame->_p_%s = &%s;\n", retval->name, retval->name);
}
fprintf(client, "\n");
@ -258,10 +257,10 @@ static void write_function_stub( const type_t *iface, const var_t *func,
/* unmarshal return value */
if (has_ret)
{
if (decl_indirect(rettype))
print_client("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal");
else if (is_ptr(rettype) || is_array(rettype))
print_client("%s = 0;\n", "_RetVal");
if (decl_indirect(retval->type))
print_client("MIDL_memset(&%s, 0, sizeof(%s));\n", retval->name, retval->name);
else if (is_ptr(retval->type) || is_array(retval->type))
print_client("%s = 0;\n", retval->name);
write_remoting_arguments(client, indent, func, "", PASS_RETURN, PHASE_UNMARSHAL);
}
@ -280,7 +279,7 @@ static void write_function_stub( const type_t *iface, const var_t *func,
if (has_ret)
{
fprintf(client, "\n");
print_client("return _RetVal;\n");
print_client("return %s;\n", retval->name);
}
indent--;

View File

@ -1602,7 +1602,8 @@ static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, const decl
for (ft = v->type; is_ptr(ft); ft = type_pointer_get_ref(ft))
;
assert(type_get_type_detect_alias(ft) == TYPE_FUNCTION);
ft->details.function->rettype = return_type;
ft->details.function->retval = make_var(xstrdup("_RetVal"));
ft->details.function->retval->type = return_type;
/* move calling convention attribute, if present, from pointer nodes to
* function node */
for (t = v->type; is_ptr(t); t = type_pointer_get_ref(t))

View File

@ -193,8 +193,8 @@ 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)
{
type_t *rettype = type_function_get_rettype(func->type);
int has_ret = !is_void(rettype);
var_t *retval = type_function_get_retval(func->type);
int has_ret = !is_void(retval->type);
int has_full_pointer = is_full_pointer_function(func);
const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV);
const var_list_t *args = type_get_function_args(func->type);
@ -204,7 +204,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, type_function_get_rettype(func->type));
write_type_decl_left(proxy, retval->type);
print_proxy( " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(func));
write_args(proxy, args, iface->name, 1, TRUE);
print_proxy( ")\n");
@ -221,7 +221,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, rettype);
write_type_decl_left(proxy, retval->type);
print_proxy( " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(func));
write_args(proxy, args, iface->name, 1, TRUE);
print_proxy( ")\n");
@ -231,14 +231,13 @@ static void gen_proxy(type_t *iface, const var_t *func, int idx,
/* local variables */
if (has_ret) {
print_proxy( "%s", "" );
write_type_decl_left(proxy, rettype);
print_proxy( " _RetVal;\n");
write_type_decl(proxy, retval->type, retval->name);
fprintf( proxy, ";\n" );
}
print_proxy( "RPC_MESSAGE _RpcMessage;\n" );
if (has_ret) {
if (decl_indirect(rettype))
print_proxy("void *_p_%s = &%s;\n",
"_RetVal", "_RetVal");
if (decl_indirect(retval->type))
print_proxy("void *_p_%s = &%s;\n", retval->name, retval->name);
}
print_proxy( "\n");
@ -282,10 +281,10 @@ static void gen_proxy(type_t *iface, const var_t *func, int idx,
if (has_ret)
{
if (decl_indirect(rettype))
print_proxy("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal");
else if (is_ptr(rettype) || is_array(rettype))
print_proxy("%s = 0;\n", "_RetVal");
if (decl_indirect(retval->type))
print_proxy("MIDL_memset(&%s, 0, sizeof(%s));\n", retval->name, retval->name);
else if (is_ptr(retval->type) || is_array(retval->type))
print_proxy("%s = 0;\n", retval->name);
write_remoting_arguments(proxy, indent, func, "", PASS_RETURN, PHASE_UNMARSHAL);
}

View File

@ -899,10 +899,10 @@ static void write_var_init(FILE *file, int indent, const type_t *t, const char *
void write_parameters_init(FILE *file, int indent, const var_t *func, const char *local_var_prefix)
{
const var_t *var;
const var_t *var = type_function_get_retval(func->type);
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 (!is_void(var->type))
write_var_init(file, indent, var->type, var->name, local_var_prefix);
if (!type_get_function_args(func->type))
return;
@ -4473,12 +4473,8 @@ void write_remoting_arguments(FILE *file, int indent, const var_t *func, const c
if (pass == PASS_RETURN)
{
var_t var;
var = *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 );
write_remoting_arg( file, indent, func, local_var_prefix, pass, phase,
type_function_get_retval(func->type) );
}
else
{
@ -4535,14 +4531,14 @@ void declare_stub_args( FILE *file, int indent, const var_t *func )
{
int in_attr, out_attr;
int i = 0;
const var_t *var;
const var_t *var = type_function_get_retval(func->type);
/* declare return value '_RetVal' */
if (!is_void(type_function_get_rettype(func->type)))
/* declare return value */
if (!is_void(var->type))
{
print_file(file, indent, "%s", "");
write_type_decl_left(file, type_function_get_rettype(func->type));
fprintf(file, " _RetVal;\n");
write_type_decl(file, var->type, var->name);
fprintf(file, ";\n");
}
if (!type_get_function_args(func->type))
@ -4695,7 +4691,7 @@ void assign_stub_out_args( FILE *file, int indent, const var_t *func, const char
void write_func_param_struct( FILE *file, const type_t *iface, const type_t *func,
const char *var_decl, int add_retval )
{
type_t *rettype = type_function_get_rettype( func );
var_t *retval = type_function_get_retval( func );
const var_list_t *args = type_get_function_args( func );
const var_t *arg;
int needs_packing;
@ -4729,11 +4725,12 @@ void write_func_param_struct( FILE *file, const type_t *iface, const type_t *fun
else
fprintf( file, "%s DECLSPEC_ALIGN(%u);\n", arg->name, pointer_size );
}
if (add_retval && !is_void( rettype ))
if (add_retval && !is_void( retval->type ))
{
print_file(file, 2, "%s", "");
write_type_decl( file, rettype, "_RetVal" );
if (is_array( rettype ) || is_ptr( rettype ) || type_memsize( rettype ) == pointer_size)
write_type_decl( file, retval->type, retval->name );
if (is_array( retval->type ) || is_ptr( retval->type ) ||
type_memsize( retval->type ) == pointer_size)
fprintf( file, ";\n" );
else
fprintf( file, " DECLSPEC_ALIGN(%u);\n", pointer_size );

View File

@ -92,11 +92,16 @@ 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)
static inline var_t *type_function_get_retval(const type_t *type)
{
type = type_get_real_type(type);
assert(type_get_type(type) == TYPE_FUNCTION);
return type->details.function->rettype;
return type->details.function->retval;
}
static inline type_t *type_function_get_rettype(const type_t *type)
{
return type_function_get_retval(type)->type;
}
static inline var_list_t *type_enum_get_values(const type_t *type)

View File

@ -329,7 +329,7 @@ struct enumeration_details
struct func_details
{
var_list_t *args;
struct _type_t *rettype;
struct _var_t *retval;
int idx;
};