diff --git a/tools/widl/client.c b/tools/widl/client.c index 8b3b1399e57..b05c3c9f42f 100644 --- a/tools/widl/client.c +++ b/tools/widl/client.c @@ -287,6 +287,29 @@ static void write_function_stub( const type_t *iface, const var_t *func, fprintf(client, "\n"); } +static void write_serialize_function(FILE *file, const type_t *type, const type_t *iface, + const char *func_name, const char *ret_type) +{ + /* FIXME: Assuming explicit handle */ + + fprintf(file, "%s __cdecl %s_%s(handle_t IDL_handle, %s *IDL_type)%s\n", + ret_type ? ret_type : "void", type->name, func_name, type->name, iface ? "" : ";"); +} + +void write_serialize_functions(FILE *file, const type_t *type, const type_t *iface) +{ + if (is_attr(type->attrs, ATTR_ENCODE)) + { + write_serialize_function(file, type, iface, "AlignSize", "SIZE_T"); + write_serialize_function(file, type, iface, "Encode", NULL); + } + if (is_attr(type->attrs, ATTR_DECODE)) + { + write_serialize_function(file, type, iface, "Decode", NULL); + write_serialize_function(file, type, iface, "Free", NULL); + } +} + static void write_function_stubs(type_t *iface, unsigned int *proc_offset) { const statement_t *stmt; diff --git a/tools/widl/header.c b/tools/widl/header.c index c4b26d3286c..defc7f85037 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -716,6 +716,47 @@ void check_for_additional_prototype_types(const var_list_t *list) } } +static int write_serialize_function_decl(FILE *header, const type_t *type) +{ + write_serialize_functions(header, type, NULL); + return 1; +} + +static int serializable_exists(FILE *header, const type_t *type) +{ + return 0; +} + +static int for_each_serializable(const statement_list_t *stmts, FILE *header, + int (*proc)(FILE*, const type_t*)) +{ + statement_t *stmt, *iface_stmt; + statement_list_t *iface_stmts; + const type_list_t *type_entry; + + if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, statement_t, entry ) + { + if (stmt->type != STMT_TYPE || type_get_type(stmt->u.type) != TYPE_INTERFACE) + continue; + + iface_stmts = type_iface_get_stmts(stmt->u.type); + if (iface_stmts) LIST_FOR_EACH_ENTRY( iface_stmt, iface_stmts, statement_t, entry ) + { + if (iface_stmt->type != STMT_TYPEDEF) continue; + for (type_entry = iface_stmt->u.type_list; type_entry; type_entry = type_entry->next) + { + if (!is_attr(type_entry->type->attrs, ATTR_ENCODE) + && !is_attr(type_entry->type->attrs, ATTR_DECODE)) + continue; + if (!proc(header, type_entry->type)) + return 0; + } + } + } + + return 1; +} + static void write_user_types(FILE *header) { user_type_t *ut; @@ -1748,7 +1789,10 @@ void write_header(const statement_list_t *stmts) fprintf(header, "#endif\n\n"); fprintf(header, "#include \n" ); - fprintf(header, "#include \n\n" ); + fprintf(header, "#include \n" ); + if (!for_each_serializable(stmts, NULL, serializable_exists)) + fprintf(header, "#include \n" ); + fprintf(header, "\n" ); fprintf(header, "#ifndef COM_NO_WINDOWS_H\n"); fprintf(header, "#include \n"); @@ -1770,6 +1814,7 @@ void write_header(const statement_list_t *stmts) fprintf(header, "/* Begin additional prototypes for all interfaces */\n"); fprintf(header, "\n"); + for_each_serializable(stmts, header, write_serialize_function_decl); write_user_types(header); write_generic_handle_routines(header); write_context_handle_rundowns(header); diff --git a/tools/widl/header.h b/tools/widl/header.h index 6222a480785..0d44b4039fe 100644 --- a/tools/widl/header.h +++ b/tools/widl/header.h @@ -54,6 +54,8 @@ extern const var_t *get_func_handle_var( const type_t *iface, const var_t *func, extern int has_out_arg_or_return(const var_t *func); extern int is_const_decl(const var_t *var); +extern void write_serialize_functions(FILE *file, const type_t *type, const type_t *iface); + static inline int is_ptr(const type_t *t) { return type_get_type(t) == TYPE_POINTER;