widl: Add a more generic way of determining the type of handle for a function.

This commit is contained in:
Alexandre Julliard 2011-05-31 13:30:04 +02:00
parent 21cbdaa1eb
commit 0f8b64a57b
5 changed files with 82 additions and 111 deletions

View File

@ -83,33 +83,22 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) ) STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
{ {
unsigned char explicit_fc, implicit_fc;
const var_t *func = stmt->u.var; const var_t *func = stmt->u.var;
const var_t* explicit_handle_var;
const var_t* explicit_generic_handle_var = NULL;
const var_t* context_handle_var = NULL;
int has_full_pointer = is_full_pointer_function(func); int has_full_pointer = is_full_pointer_function(func);
const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV); const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV);
const var_list_t *args = type_get_function_args(func->type); const var_list_t *args = type_get_function_args(func->type);
const var_t *handle_var = get_func_handle_var( iface, func, &explicit_fc, &implicit_fc );
/* check for a defined binding handle */
explicit_handle_var = get_explicit_handle_var(func);
if (!explicit_handle_var)
{
explicit_generic_handle_var = get_explicit_generic_handle_var(func);
if (!explicit_generic_handle_var)
context_handle_var = get_context_handle_var(func);
}
print_client( "struct __frame_%s%s\n{\n", prefix_client, get_name(func) ); print_client( "struct __frame_%s%s\n{\n", prefix_client, get_name(func) );
indent++; indent++;
print_client( "__DECL_EXCEPTION_FRAME\n" ); print_client( "__DECL_EXCEPTION_FRAME\n" );
print_client("MIDL_STUB_MESSAGE _StubMsg;\n"); print_client("MIDL_STUB_MESSAGE _StubMsg;\n");
if (implicit_handle || explicit_handle_var || explicit_generic_handle_var || context_handle_var) if (handle_var)
{ {
if (!implicit_handle && explicit_generic_handle_var) if (explicit_fc == RPC_FC_BIND_GENERIC)
print_client("%s %s;\n", print_client("%s %s;\n",
get_explicit_generic_handle_type(explicit_generic_handle_var)->name, get_explicit_generic_handle_type(handle_var)->name, handle_var->name );
explicit_generic_handle_var->name );
print_client("RPC_BINDING_HANDLE _Handle;\n"); print_client("RPC_BINDING_HANDLE _Handle;\n");
} }
@ -130,14 +119,13 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
print_client("NdrFreeBuffer(&__frame->_StubMsg);\n"); print_client("NdrFreeBuffer(&__frame->_StubMsg);\n");
if (!implicit_handle && explicit_generic_handle_var) if (explicit_fc == RPC_FC_BIND_GENERIC)
{ {
fprintf(client, "\n"); fprintf(client, "\n");
print_client("if (__frame->_Handle)\n"); print_client("if (__frame->_Handle)\n");
indent++; indent++;
print_client("%s_unbind(__frame->%s, __frame->_Handle);\n", print_client("%s_unbind(__frame->%s, __frame->_Handle);\n",
get_explicit_generic_handle_type(explicit_generic_handle_var)->name, get_explicit_generic_handle_type(handle_var)->name, handle_var->name);
explicit_generic_handle_var->name);
indent--; indent--;
} }
indent--; indent--;
@ -170,12 +158,11 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
} }
print_client("RPC_MESSAGE _RpcMessage;\n"); print_client("RPC_MESSAGE _RpcMessage;\n");
if (implicit_handle || explicit_handle_var || explicit_generic_handle_var || context_handle_var) if (handle_var)
{ {
print_client( "__frame->_Handle = 0;\n" ); print_client( "__frame->_Handle = 0;\n" );
if (!implicit_handle && explicit_generic_handle_var) if (explicit_fc == RPC_FC_BIND_GENERIC)
print_client("__frame->%s = %s;\n", print_client("__frame->%s = %s;\n", handle_var->name, handle_var->name );
explicit_generic_handle_var->name, explicit_generic_handle_var->name );
} }
if (!is_void(type_function_get_rettype(func->type)) && if (!is_void(type_function_get_rettype(func->type)) &&
decl_indirect(type_function_get_rettype(func->type))) decl_indirect(type_function_get_rettype(func->type)))
@ -210,31 +197,29 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
fprintf(client, ");\n\n"); fprintf(client, ");\n\n");
} }
if (explicit_handle_var) switch (explicit_fc)
{ {
print_client("__frame->_Handle = %s;\n", explicit_handle_var->name); case RPC_FC_BIND_PRIMITIVE:
print_client("__frame->_Handle = %s;\n", handle_var->name);
fprintf(client, "\n"); fprintf(client, "\n");
} break;
else if (explicit_generic_handle_var) case RPC_FC_BIND_GENERIC:
{
print_client("__frame->_Handle = %s_bind(%s);\n", print_client("__frame->_Handle = %s_bind(%s);\n",
get_explicit_generic_handle_type(explicit_generic_handle_var)->name, get_explicit_generic_handle_type(handle_var)->name, handle_var->name);
explicit_generic_handle_var->name);
fprintf(client, "\n"); fprintf(client, "\n");
} break;
else if (context_handle_var) case RPC_FC_BIND_CONTEXT:
{ {
/* if the context_handle attribute appears in the chain of types /* if the context_handle attribute appears in the chain of types
* without pointers being followed, then the context handle must * without pointers being followed, then the context handle must
* be direct, otherwise it is a pointer */ * be direct, otherwise it is a pointer */
int is_ch_ptr = is_aliaschain_attr(context_handle_var->type, ATTR_CONTEXTHANDLE) ? FALSE : TRUE; int is_ch_ptr = !is_aliaschain_attr(handle_var->type, ATTR_CONTEXTHANDLE);
print_client("if (%s%s != 0)\n", is_ch_ptr ? "*" : "", context_handle_var->name); print_client("if (%s%s != 0)\n", is_ch_ptr ? "*" : "", handle_var->name);
indent++; indent++;
print_client("__frame->_Handle = NDRCContextBinding(%s%s);\n", print_client("__frame->_Handle = NDRCContextBinding(%s%s);\n",
is_ch_ptr ? "*" : "", context_handle_var->name); is_ch_ptr ? "*" : "", handle_var->name);
indent--; indent--;
if (is_attr(context_handle_var->attrs, ATTR_IN) && if (is_attr(handle_var->attrs, ATTR_IN) && !is_attr(handle_var->attrs, ATTR_OUT))
!is_attr(context_handle_var->attrs, ATTR_OUT))
{ {
print_client("else\n"); print_client("else\n");
indent++; indent++;
@ -242,17 +227,21 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
indent--; indent--;
} }
fprintf(client, "\n"); fprintf(client, "\n");
break;
} }
else if (implicit_handle) case 0: /* implicit handle */
if (handle_var)
{ {
print_client("__frame->_Handle = %s;\n", implicit_handle->name); print_client("__frame->_Handle = %s;\n", handle_var->name);
fprintf(client, "\n"); fprintf(client, "\n");
} }
break;
}
write_remoting_arguments(client, indent, func, "", PASS_IN, PHASE_BUFFERSIZE); write_remoting_arguments(client, indent, func, "", PASS_IN, PHASE_BUFFERSIZE);
print_client("NdrGetBuffer(&__frame->_StubMsg, __frame->_StubMsg.BufferLength, "); print_client("NdrGetBuffer(&__frame->_StubMsg, __frame->_StubMsg.BufferLength, ");
if (implicit_handle || explicit_handle_var || explicit_generic_handle_var || context_handle_var) if (handle_var)
fprintf(client, "__frame->_Handle);\n\n"); fprintf(client, "__frame->_Handle);\n\n");
else else
fprintf(client,"%s__MIDL_AutoBindHandle);\n\n", iface->name); fprintf(client,"%s__MIDL_AutoBindHandle);\n\n", iface->name);

View File

@ -615,23 +615,6 @@ static void write_library(FILE *header, const typelib_t *typelib)
} }
const var_t* get_explicit_handle_var(const var_t *func)
{
const var_t* var;
if (!type_get_function_args(func->type))
return NULL;
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
{
const type_t *type = var->type;
if (type_get_type(type) == TYPE_BASIC && type_basic_get_type(type) == TYPE_BASIC_HANDLE)
return var;
}
return NULL;
}
const type_t* get_explicit_generic_handle_type(const var_t* var) const type_t* get_explicit_generic_handle_type(const var_t* var)
{ {
const type_t *t; const type_t *t;
@ -644,31 +627,44 @@ const type_t* get_explicit_generic_handle_type(const var_t* var)
return NULL; return NULL;
} }
const var_t* get_explicit_generic_handle_var(const var_t *func) const var_t *get_func_handle_var( const type_t *iface, const var_t *func,
unsigned char *explicit_fc, unsigned char *implicit_fc )
{ {
const var_t *var; const var_t *var;
const var_list_t *args = type_get_function_args( func->type );
if (!type_get_function_args(func->type)) *explicit_fc = *implicit_fc = 0;
return NULL; if (args) LIST_FOR_EACH_ENTRY( var, args, const var_t, entry )
{
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) if (!is_attr( var->attrs, ATTR_IN ) && is_attr( var->attrs, ATTR_OUT )) continue;
if (get_explicit_generic_handle_type(var)) if (type_get_type( var->type ) == TYPE_BASIC && type_basic_get_type( var->type ) == TYPE_BASIC_HANDLE)
{
*explicit_fc = RPC_FC_BIND_PRIMITIVE;
return var; return var;
}
return NULL; if (get_explicit_generic_handle_type( var ))
{
*explicit_fc = RPC_FC_BIND_GENERIC;
return var;
}
if (is_context_handle( var->type ))
{
*explicit_fc = RPC_FC_BIND_CONTEXT;
return var;
}
} }
const var_t* get_context_handle_var(const var_t *func) if ((var = get_attrp( iface->attrs, ATTR_IMPLICIT_HANDLE )))
{ {
const var_t* var; if (type_get_type( var->type ) == TYPE_BASIC &&
type_basic_get_type( var->type ) == TYPE_BASIC_HANDLE)
if (!type_get_function_args(func->type)) *implicit_fc = RPC_FC_BIND_PRIMITIVE;
return NULL; else
*implicit_fc = RPC_FC_BIND_GENERIC;
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
if (is_attr(var->attrs, ATTR_IN) && is_context_handle(var->type))
return var; return var;
}
*implicit_fc = RPC_FC_AUTO_HANDLE;
return NULL; return NULL;
} }

View File

@ -47,10 +47,9 @@ extern int need_proxy_file(const statement_list_t *stmts);
extern const var_t *is_callas(const attr_list_t *list); 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);
extern void write_array(FILE *h, array_dims_t *v, int field); extern void write_array(FILE *h, array_dims_t *v, int field);
extern const var_t* get_explicit_handle_var(const var_t *func);
extern const type_t* get_explicit_generic_handle_type(const var_t* var); extern const type_t* get_explicit_generic_handle_type(const var_t* var);
extern const var_t* get_explicit_generic_handle_var(const var_t *func); extern const var_t *get_func_handle_var( const type_t *iface, const var_t *func,
extern const var_t* get_context_handle_var(const var_t *func); unsigned char *explicit_fc, unsigned char *implicit_fc );
extern int has_out_arg_or_return(const var_t *func); extern int has_out_arg_or_return(const var_t *func);
extern void write_guid(FILE *f, const char *guid_prefix, const char *name, extern void write_guid(FILE *f, const char *guid_prefix, const char *name,
const UUID *uuid); const UUID *uuid);

View File

@ -133,7 +133,7 @@ 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_module_attrs(const char *name, attr_list_t *attrs);
static attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs); static attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs);
const char *get_attr_display_name(enum attr_type type); const char *get_attr_display_name(enum attr_type type);
static void add_explicit_handle_if_necessary(var_t *func); 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_def(const type_t *t);
static statement_t *make_statement(enum statement_type type); static statement_t *make_statement(enum statement_type type);
@ -2598,21 +2598,12 @@ static void check_remoting_args(const var_t *func)
} }
} }
static void add_explicit_handle_if_necessary(var_t *func) static void add_explicit_handle_if_necessary(const type_t *iface, var_t *func)
{ {
const var_t* explicit_handle_var; unsigned char explicit_fc, implicit_fc;
const var_t* explicit_generic_handle_var = NULL;
const var_t* context_handle_var = NULL;
/* check for a defined binding handle */ /* check for a defined binding handle */
explicit_handle_var = get_explicit_handle_var(func); if (!get_func_handle_var( iface, func, &explicit_fc, &implicit_fc ) || !explicit_fc)
if (!explicit_handle_var)
{
explicit_generic_handle_var = get_explicit_generic_handle_var(func);
if (!explicit_generic_handle_var)
{
context_handle_var = get_context_handle_var(func);
if (!context_handle_var)
{ {
/* no explicit handle specified so add /* no explicit handle specified so add
* "[in] handle_t IDL_handle" as the first parameter to the * "[in] handle_t IDL_handle" as the first parameter to the
@ -2623,8 +2614,6 @@ static void add_explicit_handle_if_necessary(var_t *func)
type_function_add_head_arg(func->type, idl_handle); type_function_add_head_arg(func->type, idl_handle);
} }
} }
}
}
static void check_functions(const type_t *iface, int is_inside_library) static void check_functions(const type_t *iface, int is_inside_library)
{ {
@ -2634,7 +2623,7 @@ static void check_functions(const type_t *iface, int is_inside_library)
STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) ) STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
{ {
var_t *func = stmt->u.var; var_t *func = stmt->u.var;
add_explicit_handle_if_necessary(func); add_explicit_handle_if_necessary(iface, func);
} }
} }
if (!is_inside_library && !is_attr(iface->attrs, ATTR_LOCAL)) if (!is_inside_library && !is_attr(iface->attrs, ATTR_LOCAL))

View File

@ -53,15 +53,13 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
{ {
const statement_t *stmt; const statement_t *stmt;
const var_t *var; const var_t *var;
const var_t* explicit_handle_var;
STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) ) STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
{ {
unsigned char explicit_fc, implicit_fc;
var_t *func = stmt->u.var; var_t *func = stmt->u.var;
int has_full_pointer = is_full_pointer_function(func); int has_full_pointer = is_full_pointer_function(func);
const var_t *handle_var = get_func_handle_var( iface, func, &explicit_fc, &implicit_fc );
/* check for a defined binding handle */
explicit_handle_var = get_explicit_handle_var(func);
print_server("struct __frame_%s_%s\n{\n", iface->name, get_name(func)); print_server("struct __frame_%s_%s\n{\n", iface->name, get_name(func));
indent++; indent++;
@ -109,9 +107,9 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
write_parameters_init(server, indent, func, "__frame->"); write_parameters_init(server, indent, func, "__frame->");
if (explicit_handle_var) if (explicit_fc == RPC_FC_BIND_PRIMITIVE)
{ {
print_server("__frame->%s = _pRpcMessage->Handle;\n", explicit_handle_var->name); print_server("__frame->%s = _pRpcMessage->Handle;\n", handle_var->name);
fprintf(server, "\n"); fprintf(server, "\n");
} }