Commit 9c4d01f3 authored by Alexandre Julliard's avatar Alexandre Julliard

widl: Add support for generating old-style interpreted stubs for clients.

parent 33ba9731
...@@ -72,23 +72,58 @@ static void check_pointers(const var_t *func) ...@@ -72,23 +72,58 @@ static void check_pointers(const var_t *func)
} }
} }
static void write_function_stubs(type_t *iface, unsigned int *proc_offset) static void write_client_func_decl( const type_t *iface, const var_t *func )
{ {
const statement_t *stmt; const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV);
const var_t *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE); const var_list_t *args = type_get_function_args(func->type);
int method_count = 0; type_t *rettype = type_function_get_rettype(func->type);
if (!implicit_handle) write_type_decl_left(client, rettype);
print_client("static RPC_BINDING_HANDLE %s__MIDL_AutoBindHandle;\n\n", iface->name); if (needs_space_after(rettype)) fprintf(client, " ");
if (callconv) 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);
else
print_client("void");
fprintf(client, ")\n");
indent--;
}
STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) ) static void write_function_stub( const type_t *iface, const var_t *func,
{ int method_count, unsigned int proc_offset )
{
unsigned char explicit_fc, implicit_fc; unsigned char explicit_fc, implicit_fc;
const 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 char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV); type_t *rettype = type_function_get_rettype(func->type);
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 ); const var_t *handle_var = get_func_handle_var( iface, func, &explicit_fc, &implicit_fc );
int has_ret = !is_void(rettype);
if (is_interpreted_func( iface, func ))
{
write_client_func_decl( iface, func );
fprintf(client, "{\n");
indent++;
if (has_ret) print_client( "%s", "CLIENT_CALL_RETURN _RetVal;\n\n" );
print_client( "%sNdrClientCall( &%s_StubDesc, &__MIDL_ProcFormatString.Format[%u], ",
has_ret ? "_RetVal = " : "", iface->name, proc_offset );
if (args)
fprintf( client, "(unsigned char *)&%s );\n",
LIST_ENTRY( list_head(args), const var_t, entry )->name );
else
fprintf( client, "(unsigned char *)0 );\n" );
if (has_ret)
{
print_client( "return (" );
write_type_decl_left(client, rettype);
fprintf( client, ")*(LONG_PTR *)&_RetVal;\n" );
}
indent--;
print_client( "}\n\n");
return;
}
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++;
...@@ -102,8 +137,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) ...@@ -102,8 +137,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
print_client("RPC_BINDING_HANDLE _Handle;\n"); print_client("RPC_BINDING_HANDLE _Handle;\n");
} }
if (!is_void(type_function_get_rettype(func->type)) && if (has_ret && decl_indirect(rettype))
decl_indirect(type_function_get_rettype(func->type)))
{ {
print_client("void *_p_%s;\n", "_RetVal" ); print_client("void *_p_%s;\n", "_RetVal" );
} }
...@@ -131,18 +165,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) ...@@ -131,18 +165,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
indent--; indent--;
print_client( "}\n\n" ); print_client( "}\n\n" );
write_type_decl_left(client, type_function_get_rettype(func->type)); write_client_func_decl( iface, func );
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));
indent++;
if (args)
write_args(client, args, iface->name, 0, TRUE);
else
print_client("void");
fprintf(client, ")\n");
indent--;
/* write the functions body */ /* write the functions body */
fprintf(client, "{\n"); fprintf(client, "{\n");
...@@ -150,10 +173,10 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) ...@@ -150,10 +173,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) ); print_client( "struct __frame_%s%s __f, * const __frame = &__f;\n", prefix_client, get_name(func) );
/* declare return value '_RetVal' */ /* declare return value '_RetVal' */
if (!is_void(type_function_get_rettype(func->type))) if (has_ret)
{ {
print_client("%s", ""); print_client("%s", "");
write_type_decl_left(client, type_function_get_rettype(func->type)); write_type_decl_left(client, rettype);
fprintf(client, " _RetVal;\n"); fprintf(client, " _RetVal;\n");
} }
print_client("RPC_MESSAGE _RpcMessage;\n"); print_client("RPC_MESSAGE _RpcMessage;\n");
...@@ -164,8 +187,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) ...@@ -164,8 +187,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
if (explicit_fc == RPC_FC_BIND_GENERIC) if (explicit_fc == RPC_FC_BIND_GENERIC)
print_client("__frame->%s = %s;\n", handle_var->name, handle_var->name ); print_client("__frame->%s = %s;\n", handle_var->name, handle_var->name );
} }
if (!is_void(type_function_get_rettype(func->type)) && if (has_ret && decl_indirect(rettype))
decl_indirect(type_function_get_rettype(func->type)))
{ {
print_client("__frame->_p_%s = &%s;\n", print_client("__frame->_p_%s = &%s;\n",
"_RetVal", "_RetVal"); "_RetVal", "_RetVal");
...@@ -265,7 +287,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) ...@@ -265,7 +287,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
print_client("if ((_RpcMessage.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)\n"); print_client("if ((_RpcMessage.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)\n");
indent++; indent++;
print_client("NdrConvert(&__frame->_StubMsg, (PFORMAT_STRING)&__MIDL_ProcFormatString.Format[%u]);\n", print_client("NdrConvert(&__frame->_StubMsg, (PFORMAT_STRING)&__MIDL_ProcFormatString.Format[%u]);\n",
*proc_offset); proc_offset);
indent--; indent--;
} }
...@@ -274,19 +296,15 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) ...@@ -274,19 +296,15 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
write_remoting_arguments(client, indent, func, "", PASS_OUT, PHASE_UNMARSHAL); write_remoting_arguments(client, indent, func, "", PASS_OUT, PHASE_UNMARSHAL);
/* unmarshal return value */ /* unmarshal return value */
if (!is_void(type_function_get_rettype(func->type))) if (has_ret)
{ {
if (decl_indirect(type_function_get_rettype(func->type))) if (decl_indirect(rettype))
print_client("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal"); print_client("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal");
else if (is_ptr(type_function_get_rettype(func->type)) || else if (is_ptr(rettype) || is_array(rettype))
is_array(type_function_get_rettype(func->type)))
print_client("%s = 0;\n", "_RetVal"); print_client("%s = 0;\n", "_RetVal");
write_remoting_arguments(client, indent, func, "", PASS_RETURN, PHASE_UNMARSHAL); write_remoting_arguments(client, indent, func, "", PASS_RETURN, PHASE_UNMARSHAL);
} }
/* update proc_offset */
*proc_offset += get_size_procformatstring_func( iface, func );
indent--; indent--;
print_client("}\n"); print_client("}\n");
print_client("RpcFinally\n"); print_client("RpcFinally\n");
...@@ -299,7 +317,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) ...@@ -299,7 +317,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
/* emit return code */ /* emit return code */
if (!is_void(type_function_get_rettype(func->type))) if (has_ret)
{ {
fprintf(client, "\n"); fprintf(client, "\n");
print_client("return _RetVal;\n"); print_client("return _RetVal;\n");
...@@ -308,8 +326,22 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) ...@@ -308,8 +326,22 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
indent--; indent--;
fprintf(client, "}\n"); fprintf(client, "}\n");
fprintf(client, "\n"); fprintf(client, "\n");
}
method_count++; static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
{
const statement_t *stmt;
const var_t *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
int method_count = 0;
if (!implicit_handle)
print_client("static RPC_BINDING_HANDLE %s__MIDL_AutoBindHandle;\n\n", iface->name);
STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
{
const var_t *func = stmt->u.var;
write_function_stub( iface, func, method_count++, *proc_offset );
*proc_offset += get_size_procformatstring_func( iface, func );
} }
} }
...@@ -510,8 +542,11 @@ static void write_client_routines(const statement_list_t *stmts) ...@@ -510,8 +542,11 @@ static void write_client_routines(const statement_list_t *stmts)
unsigned int proc_offset = 0; unsigned int proc_offset = 0;
int expr_eval_routines; int expr_eval_routines;
if (need_inline_stubs_file( stmts ))
{
write_exceptions( client ); write_exceptions( client );
print_client( "\n"); print_client( "\n");
}
write_formatstringsdecl(client, indent, stmts, need_stub); write_formatstringsdecl(client, indent, stmts, need_stub);
expr_eval_routines = write_expr_eval_routines(client, client_token); expr_eval_routines = write_expr_eval_routines(client, client_token);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment