From 901a42b7f90a8b7f9859dba0b55e58cd4c38a6e0 Mon Sep 17 00:00:00 2001 From: Rob Shearman Date: Mon, 5 Jan 2009 23:33:27 +0000 Subject: [PATCH] widl: Move funcs and stmts fields from type_t structure to module_details and function_details. --- tools/widl/client.c | 53 ++++++++------ tools/widl/header.c | 160 +++++++++++++++++++++--------------------- tools/widl/header.h | 8 +-- tools/widl/parser.h | 2 - tools/widl/parser.y | 74 +++++++------------- tools/widl/proxy.c | 182 ++++++++++++++++++++++++++---------------------- tools/widl/server.c | 39 +++++------ tools/widl/typegen.c | 99 +++++++++++++------------- tools/widl/typegen.h | 16 ++--- tools/widl/typetree.c | 32 ++++++--- tools/widl/typetree.h | 1 + tools/widl/widltypes.h | 39 +++++++++-- tools/widl/write_msft.c | 60 ++++++++-------- 13 files changed, 408 insertions(+), 357 deletions(-) diff --git a/tools/widl/client.c b/tools/widl/client.c index 673b9188357..a4497c261cb 100644 --- a/tools/widl/client.c +++ b/tools/widl/client.c @@ -50,14 +50,14 @@ static void print_client( const char *format, ... ) } -static void check_pointers(const func_t *func) +static void check_pointers(const var_t *func) { const var_t *var; - if (!func->args) + if (!type_get_function_args(func->type)) return; - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) { if (is_var_ptr(var) && cant_be_null(var)) { @@ -73,7 +73,7 @@ static void check_pointers(const func_t *func) static void write_function_stubs(type_t *iface, unsigned int *proc_offset) { - const func_t *func; + const statement_t *stmt; const char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE); const var_t *var; int method_count = 0; @@ -81,14 +81,15 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) if (!implicit_handle) print_client("static RPC_BINDING_HANDLE %s__MIDL_AutoBindHandle;\n\n", iface->name); - if (iface->funcs) LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry ) + STATEMENTS_FOR_EACH_FUNC( stmt, iface->details.iface->stmts ) { - const var_t *def = func->def; + 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); - const char *callconv = get_attrp(def->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); /* check for a defined binding handle */ explicit_handle_var = get_explicit_handle_var(func); @@ -99,7 +100,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) context_handle_var = get_context_handle_var(func); } - print_client( "struct __frame_%s%s\n{\n", prefix_client, get_name(def) ); + print_client( "struct __frame_%s%s\n{\n", prefix_client, get_name(func) ); indent++; print_client( "__DECL_EXCEPTION_FRAME\n" ); print_client("MIDL_STUB_MESSAGE _StubMsg;\n"); @@ -119,8 +120,8 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) indent--; print_client( "};\n\n" ); - print_client( "static void __finally_%s%s(", prefix_client, get_name(def) ); - print_client( " struct __frame_%s%s *__frame )\n{\n", prefix_client, get_name(def) ); + print_client( "static void __finally_%s%s(", prefix_client, get_name(func) ); + print_client( " struct __frame_%s%s *__frame )\n{\n", prefix_client, get_name(func) ); indent++; /* FIXME: emit client finally code */ @@ -147,10 +148,10 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) if (needs_space_after(get_func_return_type(func))) fprintf(client, " "); if (callconv) fprintf(client, "%s ", callconv); - fprintf(client, "%s%s(\n", prefix_client, get_name(def)); + fprintf(client, "%s%s(\n", prefix_client, get_name(func)); indent++; - if (func->args) - write_args(client, func->args, iface->name, 0, TRUE); + if (args) + write_args(client, args, iface->name, 0, TRUE); else print_client("void"); fprintf(client, ")\n"); @@ -159,7 +160,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) /* write the functions body */ fprintf(client, "{\n"); indent++; - print_client( "struct __frame_%s%s __f, * const __frame = &__f;\n", prefix_client, get_name(def) ); + 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))) @@ -184,7 +185,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) } fprintf(client, "\n"); - print_client( "RpcExceptionInit( 0, __finally_%s%s );\n", prefix_client, get_name(def) ); + print_client( "RpcExceptionInit( 0, __finally_%s%s );\n", prefix_client, get_name(func) ); if (has_full_pointer) write_full_pointer_init(client, indent, func, FALSE); @@ -199,12 +200,12 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) print_client("NdrClientInitializeNew(&_RpcMessage, &__frame->_StubMsg, &%s_StubDesc, %d);\n", iface->name, method_count); - if (is_attr(def->attrs, ATTR_IDEMPOTENT) || is_attr(def->attrs, ATTR_BROADCAST)) + if (is_attr(func->attrs, ATTR_IDEMPOTENT) || is_attr(func->attrs, ATTR_BROADCAST)) { print_client("_RpcMessage.RpcFlags = ( RPC_NCA_FLAGS_DEFAULT "); - if (is_attr(def->attrs, ATTR_IDEMPOTENT)) + if (is_attr(func->attrs, ATTR_IDEMPOTENT)) fprintf(client, "| RPC_NCA_FLAGS_IDEMPOTENT "); - if (is_attr(def->attrs, ATTR_BROADCAST)) + if (is_attr(func->attrs, ATTR_BROADCAST)) fprintf(client, "| RPC_NCA_FLAGS_BROADCAST "); fprintf(client, ");\n\n"); } @@ -294,9 +295,9 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) } /* update proc_offset */ - if (func->args) + if (args) { - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + 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))) @@ -309,7 +310,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) print_client("RpcFinally\n"); print_client("{\n"); indent++; - print_client( "__finally_%s%s( __frame );\n", prefix_client, get_name(def) ); + print_client( "__finally_%s%s( __frame );\n", prefix_client, get_name(func) ); indent--; print_client("}\n"); print_client("RpcEndFinally\n"); @@ -466,6 +467,8 @@ static void write_client_ifaces(const statement_list_t *stmts, int expr_eval_rou { if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP) { + int has_func = 0; + const statement_t *stmt2; type_t *iface = stmt->u.type; if (!need_stub(iface)) return; @@ -475,7 +478,13 @@ static void write_client_ifaces(const statement_list_t *stmts, int expr_eval_rou fprintf(client, " */\n"); fprintf(client, "\n"); - if (iface->funcs) + STATEMENTS_FOR_EACH_FUNC(stmt2, iface->details.iface->stmts) + { + has_func = 1; + break; + } + + if (has_func) { write_implicithandledecl(iface); diff --git a/tools/widl/header.c b/tools/widl/header.c index b7df77bb171..8ea0dec1436 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -521,14 +521,14 @@ static void write_library(FILE *header, const typelib_t *typelib) } -const var_t* get_explicit_handle_var(const func_t* func) +const var_t* get_explicit_handle_var(const var_t *func) { const var_t* var; - if (!func->args) + if (!type_get_function_args(func->type)) return NULL; - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) if (var->type->type == RPC_FC_BIND_PRIMITIVE) return var; @@ -544,45 +544,45 @@ const type_t* get_explicit_generic_handle_type(const var_t* var) return NULL; } -const var_t* get_explicit_generic_handle_var(const func_t* func) +const var_t* get_explicit_generic_handle_var(const var_t *func) { const var_t* var; - if (!func->args) + if (!type_get_function_args(func->type)) return NULL; - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) if (get_explicit_generic_handle_type(var)) return var; return NULL; } -const var_t* get_context_handle_var(const func_t* func) +const var_t* get_context_handle_var(const var_t *func) { const var_t* var; - if (!func->args) + if (!type_get_function_args(func->type)) return NULL; - LIST_FOR_EACH_ENTRY( var, func->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_context_handle(var->type)) return var; return NULL; } -int has_out_arg_or_return(const func_t *func) +int has_out_arg_or_return(const var_t *func) { const var_t *var; if (!is_void(get_func_return_type(func))) return 1; - if (!func->args) + if (!type_get_function_args(func->type)) return 0; - LIST_FOR_EACH_ENTRY( var, func->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_OUT)) return 1; @@ -612,28 +612,33 @@ const var_t *is_callas(const attr_list_t *a) static void write_method_macro(FILE *header, const type_t *iface, const char *name) { - const func_t *cur; + const statement_t *stmt; + int first_iface = 1; if (iface->ref) write_method_macro(header, iface->ref, name); - if (!iface->funcs) return; - - fprintf(header, "/*** %s methods ***/\n", iface->name); - LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) + STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) { - var_t *def = cur->def; - if (!is_callas(def->attrs)) { + const var_t *func = stmt->u.var; + + if (first_iface) + { + fprintf(header, "/*** %s methods ***/\n", iface->name); + first_iface = 0; + } + + if (!is_callas(func->attrs)) { const var_t *arg; - fprintf(header, "#define %s_%s(This", name, get_name(def)); - if (cur->args) - LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry ) + fprintf(header, "#define %s_%s(This", name, get_name(func)); + if (type_get_function_args(func->type)) + LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->type), const var_t, entry ) fprintf(header, ",%s", arg->name); fprintf(header, ") "); - fprintf(header, "(This)->lpVtbl->%s(This", get_name(def)); - if (cur->args) - LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry ) + fprintf(header, "(This)->lpVtbl->%s(This", get_name(func)); + if (type_get_function_args(func->type)) + LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->type), const var_t, entry ) fprintf(header, ",%s", arg->name); fprintf(header, ")\n"); } @@ -671,21 +676,19 @@ void write_args(FILE *h, const var_list_t *args, const char *name, int method, i static void write_cpp_method_def(FILE *header, const type_t *iface) { - const func_t *cur; - - if (!iface->funcs) return; + const statement_t *stmt; - LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) + STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) { - var_t *def = cur->def; - if (!is_callas(def->attrs)) { - const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV); + const var_t *func = stmt->u.var; + if (!is_callas(func->attrs)) { + const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV); if (!callconv) callconv = ""; indent(header, 0); fprintf(header, "virtual "); - write_type_decl_left(header, get_func_return_type(cur)); - fprintf(header, " %s %s(\n", callconv, get_name(def)); - write_args(header, cur->args, iface->name, 2, TRUE); + write_type_decl_left(header, get_func_return_type(func)); + 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"); fprintf(header, "\n"); } @@ -694,23 +697,26 @@ static void write_cpp_method_def(FILE *header, const type_t *iface) static void do_write_c_method_def(FILE *header, const type_t *iface, const char *name) { - const func_t *cur; + const statement_t *stmt; + int first_iface = 1; if (iface->ref) do_write_c_method_def(header, iface->ref, name); - if (!iface->funcs) return; - indent(header, 0); - fprintf(header, "/*** %s methods ***/\n", iface->name); - LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) + STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) { - const var_t *def = cur->def; - if (!is_callas(def->attrs)) { - const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV); + const var_t *func = stmt->u.var; + if (first_iface) { + indent(header, 0); + fprintf(header, "/*** %s methods ***/\n", iface->name); + first_iface = 0; + } + if (!is_callas(func->attrs)) { + 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(cur)); - fprintf(header, " (%s *%s)(\n", callconv, get_name(def)); - write_args(header, cur->args, name, 1, TRUE); + write_type_decl_left(header, get_func_return_type(func)); + fprintf(header, " (%s *%s)(\n", callconv, get_name(func)); + write_args(header, type_get_function_args(func->type), name, 1, TRUE); fprintf(header, ");\n"); fprintf(header, "\n"); } @@ -729,23 +735,22 @@ static void write_c_disp_method_def(FILE *header, const type_t *iface) static void write_method_proto(FILE *header, const type_t *iface) { - const func_t *cur; + const statement_t *stmt; - if (!iface->funcs) return; - LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) + STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) { - const var_t *def = cur->def; + const var_t *func = stmt->u.var; - if (!is_local(def->attrs)) { - const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV); + if (!is_local(func->attrs)) { + const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV); if (!callconv) callconv = ""; /* proxy prototype */ - write_type_decl_left(header, get_func_return_type(cur)); - fprintf(header, " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(def)); - write_args(header, cur->args, iface->name, 1, TRUE); + write_type_decl_left(header, get_func_return_type(func)); + 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"); /* stub prototype */ - fprintf(header, "void __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(def)); + fprintf(header, "void __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(func)); fprintf(header, " IRpcStubBuffer* This,\n"); fprintf(header, " IRpcChannelBuffer* pRpcChannelBuffer,\n"); fprintf(header, " PRPC_MESSAGE pRpcMessage,\n"); @@ -758,27 +763,26 @@ static void write_locals(FILE *fp, const type_t *iface, int body) { static const char comment[] = "/* WIDL-generated stub. You must provide an implementation for this. */"; - const func_list_t *funcs = iface->funcs; - const func_t *cur; + const statement_t *stmt; - if (!is_object(iface->attrs) || !funcs) + if (!is_object(iface->attrs)) return; - LIST_FOR_EACH_ENTRY(cur, funcs, const func_t, entry) { - const var_t *def = cur->def; - const var_t *cas = is_callas(def->attrs); + STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) { + const var_t *func = stmt->u.var; + const var_t *cas = is_callas(func->attrs); if (cas) { - const func_t *m; - LIST_FOR_EACH_ENTRY(m, iface->funcs, const func_t, entry) - if (!strcmp(m->def->name, cas->name)) + const statement_t *stmt2 = NULL; + STATEMENTS_FOR_EACH_FUNC(stmt2, iface->details.iface->stmts) + if (!strcmp(stmt2->u.var->name, cas->name)) break; - if (&m->entry != iface->funcs) { - const var_t *mdef = m->def; + if (&stmt2->entry != iface->details.iface->stmts) { + const var_t *m = stmt2->u.var; /* proxy prototype - use local prototype */ write_type_decl_left(fp, get_func_return_type(m)); - fprintf(fp, " CALLBACK %s_%s_Proxy(\n", iface->name, get_name(mdef)); - write_args(fp, m->args, iface->name, 1, TRUE); + 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); @@ -798,9 +802,9 @@ 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(cur)); - fprintf(fp, " __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(mdef)); - write_args(fp, cur->args, iface->name, 1, TRUE); + write_type_decl_left(fp, get_func_return_type(func)); + 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, ")"); if (body) /* Remotable methods must all return HRESULTs. */ @@ -809,7 +813,7 @@ static void write_locals(FILE *fp, const type_t *iface, int body) fprintf(fp, ";\n"); } else - error_loc("invalid call_as attribute (%s -> %s)\n", def->name, cas->name); + error_loc("invalid call_as attribute (%s -> %s)\n", func->name, cas->name); } } } @@ -855,8 +859,8 @@ static void write_function_proto(FILE *header, const type_t *iface, const var_t fprintf(header, " "); if (callconv) fprintf(header, "%s ", callconv); fprintf(header, "%s%s(\n", prefix, get_name(fun)); - if (fun->type->details.function->args) - write_args(header, fun->type->details.function->args, iface->name, 0, TRUE); + if (type_get_function_args(fun->type)) + write_args(header, type_get_function_args(fun->type), iface->name, 0, TRUE); else fprintf(header, " void"); fprintf(header, ");\n\n"); @@ -1042,7 +1046,7 @@ static void write_imports(FILE *header, const statement_list_t *stmts) { case STMT_TYPE: if (stmt->u.type->type == RPC_FC_IP) - write_imports(header, stmt->u.type->stmts); + write_imports(header, stmt->u.type->details.iface->stmts); break; case STMT_TYPEREF: case STMT_IMPORTLIB: @@ -1112,13 +1116,13 @@ static void write_header_stmts(FILE *header, const statement_list_t *stmts, cons if (is_attr(stmt->u.type->attrs, ATTR_DISPINTERFACE) || is_object(stmt->u.type->attrs)) { write_com_interface_start(header, iface); - write_header_stmts(header, iface->stmts, stmt->u.type, TRUE); + write_header_stmts(header, iface->details.iface->stmts, stmt->u.type, TRUE); write_com_interface_end(header, iface); } else { write_rpc_interface_start(header, iface); - write_header_stmts(header, iface->stmts, iface, FALSE); + write_header_stmts(header, iface->details.iface->stmts, iface, FALSE); write_rpc_interface_end(header, iface); } } diff --git a/tools/widl/header.h b/tools/widl/header.h index 23561ce37e6..25344c7b677 100644 --- a/tools/widl/header.h +++ b/tools/widl/header.h @@ -47,11 +47,11 @@ extern int need_proxy_file(const statement_list_t *stmts); 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_array(FILE *h, array_dims_t *v, int field); -extern const var_t* get_explicit_handle_var(const func_t* func); +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 var_t* get_explicit_generic_handle_var(const func_t* func); -extern const var_t* get_context_handle_var(const func_t* func); -extern int has_out_arg_or_return(const func_t *func); +extern const var_t* get_explicit_generic_handle_var(const var_t *func); +extern const var_t* get_context_handle_var(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, const UUID *uuid); extern int is_const_decl(const var_t *var); diff --git a/tools/widl/parser.h b/tools/widl/parser.h index 5822984f8e9..71f08dc994a 100644 --- a/tools/widl/parser.h +++ b/tools/widl/parser.h @@ -45,6 +45,4 @@ void pop_import(void); int is_type(const char *name); -func_list_t *gen_function_list(const statement_list_t *stmts); - #endif diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 0f15f85c282..7905b21c381 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -152,7 +152,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_coclass_attrs(const char *name, attr_list_t *attrs); const char *get_attr_display_name(enum attr_type type); -static void add_explicit_handle_if_necessary(func_t *func); +static void add_explicit_handle_if_necessary(var_t *func); static void check_def(const type_t *t); static statement_t *make_statement(enum statement_type type); @@ -929,8 +929,7 @@ modulehdr: attributes module { $$ = $2; moduledef: modulehdr '{' int_statements '}' semicolon_opt { $$ = $1; - $$->stmts = $3; - $$->funcs = gen_function_list($3); + type_module_define($$, $3); } ; @@ -1299,7 +1298,6 @@ type_t *make_type(unsigned char type, type_t *ref) t->ref = ref; t->attrs = NULL; t->orig = NULL; - t->funcs = NULL; memset(&t->details, 0, sizeof(t->details)); t->ifaces = NULL; t->dim = 0; @@ -1392,15 +1390,14 @@ static type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_ return t; } -static void function_add_head_arg(func_t *func, var_t *arg) +static void type_function_add_head_arg(type_t *type, var_t *arg) { - if (!func->def->type->details.function->args) + if (!type->details.function->args) { - func->def->type->details.function->args = xmalloc( sizeof(*func->def->type->details.function->args) ); - list_init( func->def->type->details.function->args ); + type->details.function->args = xmalloc( sizeof(*type->details.function->args) ); + list_init( type->details.function->args ); } - list_add_head( func->def->type->details.function->args, &arg->entry ); - func->args = func->def->type->details.function->args; + list_add_head( type->details.function->args, &arg->entry ); } static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type) @@ -1705,8 +1702,6 @@ static func_t *make_func(var_t *def) { func_t *f = xmalloc(sizeof(func_t)); f->def = def; - f->args = def->type->details.function->args; - f->idx = -1; return f; } @@ -1980,25 +1975,6 @@ var_t *find_const(const char *name, int f) return cur->var; } -func_list_t *gen_function_list(const statement_list_t *stmts) -{ - func_list_t *func_list = NULL; - const statement_t *stmt; - if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry ) - { - if (stmt->type == STMT_DECLARATION) - { - var_t *var = stmt->u.var; - if (var->stgclass == STG_NONE && var->type->type == RPC_FC_FUNCTION) - { - check_function_attrs(var->name, var->type->attrs); - func_list = append_func(func_list, make_func(var)); - } - } - } - return func_list; -} - static char *gen_name(void) { static const char format[] = "__WIDL_%s_generated_name_%08lX"; @@ -2466,12 +2442,12 @@ static void check_remoting_fields(const var_t *var, type_t *type) } /* checks that arguments for a function make sense for marshalling and unmarshalling */ -static void check_remoting_args(const func_t *func) +static void check_remoting_args(const var_t *func) { - const char *funcname = func->def->name; + const char *funcname = func->name; const var_t *arg; - if (func->args) LIST_FOR_EACH_ENTRY( arg, func->args, const var_t, entry ) + if (func->type->details.function->args) LIST_FOR_EACH_ENTRY( arg, func->type->details.function->args, const var_t, entry ) { int ptr_level = 0; const type_t *type = arg->type; @@ -2506,11 +2482,11 @@ static void check_remoting_args(const func_t *func) } } - check_field_common(func->def->type, funcname, arg); + check_field_common(func->type, funcname, arg); } } -static void add_explicit_handle_if_necessary(func_t *func) +static void add_explicit_handle_if_necessary(var_t *func) { const var_t* explicit_handle_var; const var_t* explicit_generic_handle_var = NULL; @@ -2532,7 +2508,7 @@ static void add_explicit_handle_if_necessary(func_t *func) var_t *idl_handle = make_var(xstrdup("IDL_handle")); idl_handle->attrs = append_attr(NULL, make_attr(ATTR_IN)); idl_handle->type = find_type_or_error("handle_t", 0); - function_add_head_arg(func, idl_handle); + type_function_add_head_arg(func->type, idl_handle); } } } @@ -2540,18 +2516,21 @@ static void add_explicit_handle_if_necessary(func_t *func) static void check_functions(const type_t *iface, int is_inside_library) { - if (is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE) && iface->funcs) + const statement_t *stmt; + if (is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE)) { - func_t *func; - LIST_FOR_EACH_ENTRY( func, iface->funcs, func_t, entry ) + STATEMENTS_FOR_EACH_FUNC( stmt, iface->details.iface->stmts ) + { + var_t *func = stmt->u.var; add_explicit_handle_if_necessary(func); + } } if (!is_inside_library && !is_attr(iface->attrs, ATTR_LOCAL)) { - const func_t *func; - if (iface->funcs) LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry ) + STATEMENTS_FOR_EACH_FUNC( stmt, iface->details.iface->stmts ) { - if (!is_attr(func->def->attrs, ATTR_LOCAL)) + const var_t *func = stmt->u.var; + if (!is_attr(func->attrs, ATTR_LOCAL)) check_remoting_args(func); } } @@ -2581,10 +2560,11 @@ static void check_all_user_types(const statement_list_t *stmts) else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP && !is_local(stmt->u.type->attrs)) { - const func_t *f; - const func_list_t *fs = stmt->u.type->funcs; - if (fs) LIST_FOR_EACH_ENTRY(f, fs, const func_t, entry) - check_for_additional_prototype_types(f->args); + const statement_t *stmt_func; + STATEMENTS_FOR_EACH_FUNC(stmt_func, stmt->u.type->details.iface->stmts) { + const var_t *func = stmt_func->u.var; + check_for_additional_prototype_types(func->type->details.function->args); + } } } } diff --git a/tools/widl/proxy.c b/tools/widl/proxy.c index 9585d2c6130..387b4afc181 100644 --- a/tools/widl/proxy.c +++ b/tools/widl/proxy.c @@ -295,29 +295,28 @@ static void proxy_free_variables( var_list_t *args, const char *local_var_prefix } } -static void gen_proxy(type_t *iface, const func_t *cur, int idx, +static void gen_proxy(type_t *iface, const var_t *func, int idx, unsigned int proc_offset) { - var_t *def = cur->def; - int has_ret = !is_void(get_func_return_type(cur)); - int has_full_pointer = is_full_pointer_function(cur); - const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV); + int has_ret = !is_void(get_func_return_type(func)); + int has_full_pointer = is_full_pointer_function(func); + const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV); if (!callconv) callconv = ""; indent = 0; print_proxy( "static void __finally_%s_%s_Proxy( struct __proxy_frame *__frame )\n", - iface->name, get_name(def) ); + iface->name, get_name(func) ); print_proxy( "{\n"); indent++; - if (has_full_pointer) write_full_pointer_free(proxy, indent, cur); + if (has_full_pointer) write_full_pointer_free(proxy, indent, func); print_proxy( "NdrProxyFreeBuffer( __frame->This, &__frame->_StubMsg );\n" ); indent--; print_proxy( "}\n"); print_proxy( "\n"); - write_type_decl_left(proxy, get_func_return_type(cur)); - print_proxy( " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(def)); - write_args(proxy, cur->args, iface->name, 1, TRUE); + write_type_decl_left(proxy, get_func_return_type(func)); + 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"); print_proxy( "{\n"); indent ++; @@ -325,41 +324,41 @@ static void gen_proxy(type_t *iface, const func_t *cur, int idx, /* local variables */ if (has_ret) { print_proxy( "" ); - write_type_decl_left(proxy, get_func_return_type(cur)); + write_type_decl_left(proxy, get_func_return_type(func)); print_proxy( " _RetVal;\n"); } print_proxy( "RPC_MESSAGE _RpcMessage;\n" ); if (has_ret) { - if (decl_indirect(get_func_return_type(cur))) + if (decl_indirect(get_func_return_type(func))) print_proxy("void *_p_%s = &%s;\n", "_RetVal", "_RetVal"); } print_proxy( "\n"); - print_proxy( "RpcExceptionInit( __proxy_filter, __finally_%s_%s_Proxy );\n", iface->name, get_name(def) ); + print_proxy( "RpcExceptionInit( __proxy_filter, __finally_%s_%s_Proxy );\n", iface->name, get_name(func) ); print_proxy( "__frame->This = This;\n" ); if (has_full_pointer) - write_full_pointer_init(proxy, indent, cur, FALSE); + write_full_pointer_init(proxy, indent, func, FALSE); /* FIXME: trace */ - clear_output_vars( cur->args ); + clear_output_vars( type_get_function_args(func->type) ); print_proxy( "RpcTryExcept\n" ); print_proxy( "{\n" ); indent++; print_proxy( "NdrProxyInitialize(This, &_RpcMessage, &__frame->_StubMsg, &Object_StubDesc, %d);\n", idx); - proxy_check_pointers( cur->args ); + proxy_check_pointers( type_get_function_args(func->type) ); print_proxy( "RpcTryFinally\n" ); print_proxy( "{\n" ); indent++; - write_remoting_arguments(proxy, indent, cur, "", PASS_IN, PHASE_BUFFERSIZE); + write_remoting_arguments(proxy, indent, func, "", PASS_IN, PHASE_BUFFERSIZE); print_proxy( "NdrProxyGetBuffer(This, &__frame->_StubMsg);\n" ); - write_remoting_arguments(proxy, indent, cur, "", PASS_IN, PHASE_MARSHAL); + write_remoting_arguments(proxy, indent, func, "", PASS_IN, PHASE_MARSHAL); print_proxy( "NdrProxySendReceive(This, &__frame->_StubMsg);\n" ); fprintf(proxy, "\n"); @@ -372,15 +371,15 @@ static void gen_proxy(type_t *iface, const func_t *cur, int idx, indent--; fprintf(proxy, "\n"); - write_remoting_arguments(proxy, indent, cur, "", PASS_OUT, PHASE_UNMARSHAL); + write_remoting_arguments(proxy, indent, func, "", PASS_OUT, PHASE_UNMARSHAL); if (has_ret) { - if (decl_indirect(get_func_return_type(cur))) + if (decl_indirect(get_func_return_type(func))) print_proxy("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal"); - else if (is_ptr(get_func_return_type(cur)) || is_array(get_func_return_type(cur))) + else if (is_ptr(get_func_return_type(func)) || is_array(get_func_return_type(func))) print_proxy("%s = 0;\n", "_RetVal"); - write_remoting_arguments(proxy, indent, cur, "", PASS_RETURN, PHASE_UNMARSHAL); + write_remoting_arguments(proxy, indent, func, "", PASS_RETURN, PHASE_UNMARSHAL); } indent--; @@ -388,7 +387,7 @@ static void gen_proxy(type_t *iface, const func_t *cur, int idx, print_proxy( "RpcFinally\n" ); print_proxy( "{\n" ); indent++; - print_proxy( "__finally_%s_%s_Proxy( __frame );\n", iface->name, get_name(def) ); + print_proxy( "__finally_%s_%s_Proxy( __frame );\n", iface->name, get_name(func) ); indent--; print_proxy( "}\n"); print_proxy( "RpcEndFinally\n" ); @@ -398,7 +397,7 @@ static void gen_proxy(type_t *iface, const func_t *cur, int idx, print_proxy( "{\n" ); if (has_ret) { indent++; - proxy_free_variables( cur->args, "" ); + proxy_free_variables( type_get_function_args(func->type), "" ); print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" ); indent--; } @@ -413,34 +412,33 @@ static void gen_proxy(type_t *iface, const func_t *cur, int idx, print_proxy( "\n"); } -static void gen_stub(type_t *iface, const func_t *cur, const char *cas, +static void gen_stub(type_t *iface, const var_t *func, const char *cas, unsigned int proc_offset) { - var_t *def = cur->def; const var_t *arg; - int has_ret = !is_void(get_func_return_type(cur)); - int has_full_pointer = is_full_pointer_function(cur); + int has_ret = !is_void(get_func_return_type(func)); + int has_full_pointer = is_full_pointer_function(func); indent = 0; - print_proxy( "struct __frame_%s_%s_Stub\n{\n", iface->name, get_name(def)); + print_proxy( "struct __frame_%s_%s_Stub\n{\n", iface->name, get_name(func)); indent++; print_proxy( "__DECL_EXCEPTION_FRAME\n" ); print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n"); print_proxy( "%s * _This;\n", iface->name ); - declare_stub_args( proxy, indent, cur ); + declare_stub_args( proxy, indent, func ); indent--; print_proxy( "};\n\n" ); - print_proxy( "static void __finally_%s_%s_Stub(", iface->name, get_name(def) ); - print_proxy( " struct __frame_%s_%s_Stub *__frame )\n{\n", iface->name, get_name(def) ); + print_proxy( "static void __finally_%s_%s_Stub(", iface->name, get_name(func) ); + print_proxy( " struct __frame_%s_%s_Stub *__frame )\n{\n", iface->name, get_name(func) ); indent++; - write_remoting_arguments(proxy, indent, cur, "__frame->", PASS_OUT, PHASE_FREE); + write_remoting_arguments(proxy, indent, func, "__frame->", PASS_OUT, PHASE_FREE); if (has_full_pointer) - write_full_pointer_free(proxy, indent, cur); + write_full_pointer_free(proxy, indent, func); indent--; print_proxy( "}\n\n" ); - print_proxy( "void __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(def)); + print_proxy( "void __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(func)); indent++; print_proxy( "IRpcStubBuffer* This,\n"); print_proxy( "IRpcChannelBuffer *_pRpcChannelBuffer,\n"); @@ -450,7 +448,7 @@ static void gen_stub(type_t *iface, const func_t *cur, const char *cas, print_proxy( "{\n"); indent++; print_proxy( "struct __frame_%s_%s_Stub __f, * const __frame = &__f;\n\n", - iface->name, get_name(def) ); + iface->name, get_name(func) ); print_proxy("__frame->_This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n\n", iface->name); @@ -458,37 +456,37 @@ static void gen_stub(type_t *iface, const func_t *cur, const char *cas, print_proxy("NdrStubInitialize(_pRpcMessage, &__frame->_StubMsg, &Object_StubDesc, _pRpcChannelBuffer);\n"); fprintf(proxy, "\n"); - print_proxy( "RpcExceptionInit( 0, __finally_%s_%s_Stub );\n", iface->name, get_name(def) ); + print_proxy( "RpcExceptionInit( 0, __finally_%s_%s_Stub );\n", iface->name, get_name(func) ); - write_parameters_init(proxy, indent, cur, "__frame->"); + write_parameters_init(proxy, indent, func, "__frame->"); print_proxy("RpcTryFinally\n"); print_proxy("{\n"); indent++; if (has_full_pointer) - write_full_pointer_init(proxy, indent, cur, TRUE); + write_full_pointer_init(proxy, indent, func, TRUE); print_proxy("if ((_pRpcMessage->DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n"); indent++; print_proxy("NdrConvert( &__frame->_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset ); indent--; fprintf(proxy, "\n"); - write_remoting_arguments(proxy, indent, cur, "__frame->", PASS_IN, PHASE_UNMARSHAL); + write_remoting_arguments(proxy, indent, func, "__frame->", PASS_IN, PHASE_UNMARSHAL); fprintf(proxy, "\n"); - assign_stub_out_args( proxy, indent, cur, "__frame->" ); + assign_stub_out_args( proxy, indent, func, "__frame->" ); print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n"); fprintf(proxy, "\n"); print_proxy(""); if (has_ret) fprintf(proxy, "__frame->_RetVal = "); if (cas) fprintf(proxy, "%s_%s_Stub", iface->name, cas); - else fprintf(proxy, "__frame->_This->lpVtbl->%s", get_name(def)); + else fprintf(proxy, "__frame->_This->lpVtbl->%s", get_name(func)); fprintf(proxy, "(__frame->_This"); - if (cur->args) + if (type_get_function_args(func->type)) { - LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry ) + LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->type), const var_t, entry ) fprintf(proxy, ", %s__frame->%s", arg->type->declarray ? "*" : "", arg->name); } fprintf(proxy, ");\n"); @@ -496,26 +494,26 @@ static void gen_stub(type_t *iface, const func_t *cur, const char *cas, print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n"); fprintf(proxy, "\n"); - write_remoting_arguments(proxy, indent, cur, "__frame->", PASS_OUT, PHASE_BUFFERSIZE); + write_remoting_arguments(proxy, indent, func, "__frame->", PASS_OUT, PHASE_BUFFERSIZE); - if (!is_void(get_func_return_type(cur))) - write_remoting_arguments(proxy, indent, cur, "__frame->", PASS_RETURN, PHASE_BUFFERSIZE); + if (!is_void(get_func_return_type(func))) + write_remoting_arguments(proxy, indent, func, "__frame->", PASS_RETURN, PHASE_BUFFERSIZE); print_proxy("NdrStubGetBuffer(This, _pRpcChannelBuffer, &__frame->_StubMsg);\n"); - write_remoting_arguments(proxy, indent, cur, "__frame->", PASS_OUT, PHASE_MARSHAL); + write_remoting_arguments(proxy, indent, func, "__frame->", PASS_OUT, PHASE_MARSHAL); fprintf(proxy, "\n"); /* marshall the return value */ - if (!is_void(get_func_return_type(cur))) - write_remoting_arguments(proxy, indent, cur, "__frame->", PASS_RETURN, PHASE_MARSHAL); + if (!is_void(get_func_return_type(func))) + write_remoting_arguments(proxy, indent, func, "__frame->", PASS_RETURN, PHASE_MARSHAL); indent--; print_proxy("}\n"); print_proxy("RpcFinally\n"); print_proxy("{\n"); indent++; - print_proxy( "__finally_%s_%s_Stub( __frame );\n", iface->name, get_name(def) ); + print_proxy( "__finally_%s_%s_Stub( __frame );\n", iface->name, get_name(func) ); indent--; print_proxy("}\n"); print_proxy("RpcEndFinally\n"); @@ -529,28 +527,29 @@ static void gen_stub(type_t *iface, const func_t *cur, const char *cas, static int count_methods(type_t *iface) { - const func_t *cur; + const statement_t *stmt; int count = 0; if (iface->ref) count = count_methods(iface->ref); - if (iface->funcs) - LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) - if (!is_callas(cur->def->attrs)) count++; + STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) { + const var_t *func = stmt->u.var; + if (!is_callas(func->attrs)) count++; + } return count; } static int write_proxy_methods(type_t *iface, int skip) { - const func_t *cur; + const statement_t *stmt; int i = 0; if (iface->ref) i = write_proxy_methods(iface->ref, need_delegation(iface)); - if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) { - var_t *def = cur->def; - if (!is_callas(def->attrs)) { + STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) { + const var_t *func = stmt->u.var; + if (!is_callas(func->attrs)) { if (i) fprintf(proxy, ",\n"); - if (skip) print_proxy( "0 /* %s_%s_Proxy */", iface->name, get_name(def)); - else print_proxy( "%s_%s_Proxy", iface->name, get_name(def)); + if (skip) print_proxy( "0 /* %s_%s_Proxy */", iface->name, get_name(func)); + else print_proxy( "%s_%s_Proxy", iface->name, get_name(func)); i++; } } @@ -559,18 +558,18 @@ static int write_proxy_methods(type_t *iface, int skip) static int write_stub_methods(type_t *iface, int skip) { - const func_t *cur; + const statement_t *stmt; int i = 0; if (iface->ref) i = write_stub_methods(iface->ref, need_delegation(iface)); else return i; /* skip IUnknown */ - if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) { - var_t *def = cur->def; - if (!is_local(def->attrs)) { + STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) { + const var_t *func = stmt->u.var; + if (!is_local(func->attrs)) { if (i) fprintf(proxy,",\n"); if (skip) print_proxy("STUB_FORWARDING_FUNCTION"); - else print_proxy( "%s_%s_Stub", iface->name, get_name(def)); + else print_proxy( "%s_%s_Stub", iface->name, get_name(func)); i++; } } @@ -580,38 +579,55 @@ static int write_stub_methods(type_t *iface, int skip) static void write_proxy(type_t *iface, unsigned int *proc_offset) { int midx = -1, count; - const func_t *cur; + const statement_t *stmt; + int first_func = 1; /* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */ - fprintf(proxy, "/*****************************************************************************\n"); - fprintf(proxy, " * %s interface\n", iface->name); - fprintf(proxy, " */\n"); - if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) - { - const var_t *def = cur->def; - if (!is_local(def->attrs)) { - const var_t *cas = is_callas(def->attrs); + STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) { + const var_t *func = stmt->u.var; + if (first_func) { + fprintf(proxy, "/*****************************************************************************\n"); + fprintf(proxy, " * %s interface\n", iface->name); + fprintf(proxy, " */\n"); + first_func = 0; + } + if (!is_local(func->attrs)) { + const var_t *cas = is_callas(func->attrs); const char *cname = cas ? cas->name : NULL; - int idx = cur->idx; + int idx = func->type->details.function->idx; if (cname) { - const func_t *m; - LIST_FOR_EACH_ENTRY( m, iface->funcs, const func_t, entry ) - if (!strcmp(m->def->name, cname)) + const statement_t *stmt2; + STATEMENTS_FOR_EACH_FUNC(stmt2, iface->details.iface->stmts) { + const var_t *m = stmt2->u.var; + if (!strcmp(m->name, cname)) { - idx = m->idx; + idx = m->type->details.function->idx; break; } + } } - gen_proxy(iface, cur, idx, *proc_offset); - gen_stub(iface, cur, cname, *proc_offset); - *proc_offset += get_size_procformatstring_func( cur ); + gen_proxy(iface, func, idx, *proc_offset); + gen_stub(iface, func, cname, *proc_offset); + *proc_offset += get_size_procformatstring_func( func ); if (midx == -1) midx = idx; else if (midx != idx) error("method index mismatch in write_proxy\n"); midx++; } } + /* interface didn't have any methods - search in inherited interfaces */ + if (midx == -1) { + const type_t *inherit_iface; + for (inherit_iface = iface->ref; inherit_iface; inherit_iface = inherit_iface->ref) { + STATEMENTS_FOR_EACH_FUNC(stmt, inherit_iface->details.iface->stmts) { + const var_t *func = stmt->u.var; + int idx = func->type->details.function->idx; + if (idx + 1 > midx) midx = idx + 1; + } + } + } + count = count_methods(iface); if (midx != -1 && midx != count) error("invalid count %u/%u\n", count, midx); diff --git a/tools/widl/server.c b/tools/widl/server.c index 20d0e7e43c7..e5d4d99ca80 100644 --- a/tools/widl/server.c +++ b/tools/widl/server.c @@ -50,20 +50,19 @@ static void print_server(const char *format, ...) static void write_function_stubs(type_t *iface, unsigned int *proc_offset) { - const func_t *func; + const statement_t *stmt; const var_t *var; const var_t* explicit_handle_var; - if (!iface->funcs) return; - LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry ) + STATEMENTS_FOR_EACH_FUNC( stmt, iface->details.iface->stmts ) { - const var_t *def = func->def; + const var_t *func = stmt->u.var; int has_full_pointer = is_full_pointer_function(func); /* 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(def)); + print_server("struct __frame_%s_%s\n{\n", iface->name, get_name(func)); indent++; print_server("__DECL_EXCEPTION_FRAME\n"); print_server("MIDL_STUB_MESSAGE _StubMsg;\n"); @@ -74,8 +73,8 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) indent--; print_server("};\n\n"); - print_server("static void __finally_%s_%s(", iface->name, get_name(def)); - fprintf(server," struct __frame_%s_%s *__frame )\n{\n", iface->name, get_name(def)); + print_server("static void __finally_%s_%s(", iface->name, get_name(func)); + fprintf(server," struct __frame_%s_%s *__frame )\n{\n", iface->name, get_name(func)); indent++; write_remoting_arguments(server, indent, func, "__frame->", PASS_OUT, PHASE_FREE); @@ -86,12 +85,12 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) indent--; print_server("}\n\n"); - print_server("void __RPC_STUB %s_%s( PRPC_MESSAGE _pRpcMessage )\n", iface->name, get_name(def)); + print_server("void __RPC_STUB %s_%s( PRPC_MESSAGE _pRpcMessage )\n", iface->name, get_name(func)); /* write the functions body */ fprintf(server, "{\n"); indent++; - print_server("struct __frame_%s_%s __f, * const __frame = &__f;\n", iface->name, get_name(def)); + print_server("struct __frame_%s_%s __f, * const __frame = &__f;\n", iface->name, get_name(func)); if (has_out_arg_or_return(func)) print_server("RPC_STATUS _Status;\n"); fprintf(server, "\n"); @@ -102,7 +101,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) print_server("&%s_StubDesc);\n", iface->name); indent--; fprintf(server, "\n"); - print_server( "RpcExceptionInit( __server_filter, __finally_%s_%s );\n", iface->name, get_name(def)); + print_server( "RpcExceptionInit( __server_filter, __finally_%s_%s );\n", iface->name, get_name(func)); write_parameters_init(server, indent, func, "__frame->"); @@ -122,7 +121,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) if (has_full_pointer) write_full_pointer_init(server, indent, func, TRUE); - if (func->args) + if (type_get_function_args(func->type)) { print_server("if ((_pRpcMessage->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)\n"); indent++; @@ -160,15 +159,15 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) print_server("__frame->_RetVal = "); else print_server(""); - fprintf(server, "%s%s", prefix_server, get_name(def)); + fprintf(server, "%s%s", prefix_server, get_name(func)); - if (func->args) + if (type_get_function_args(func->type)) { int first_arg = 1; fprintf(server, "(\n"); indent++; - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) { if (first_arg) first_arg = 0; @@ -229,7 +228,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) print_server("RpcFinally\n"); print_server("{\n"); indent++; - print_server("__finally_%s_%s( __frame );\n", iface->name, get_name(def)); + print_server("__finally_%s_%s( __frame );\n", iface->name, get_name(func)); indent--; print_server("}\n"); print_server("RpcEndFinally\n"); @@ -251,16 +250,16 @@ static void write_dispatchtable(type_t *iface) { unsigned long ver = get_attrv(iface->attrs, ATTR_VERSION); unsigned long method_count = 0; - const func_t *func; + const statement_t *stmt; print_server("static RPC_DISPATCH_FUNCTION %s_table[] =\n", iface->name); print_server("{\n"); indent++; - if (iface->funcs) LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry ) + STATEMENTS_FOR_EACH_FUNC( stmt, iface->details.iface->stmts ) { - var_t *def = func->def; - print_server("%s_%s,\n", iface->name, get_name(def)); + var_t *func = stmt->u.var; + print_server("%s_%s,\n", iface->name, get_name(func)); method_count++; } print_server("0\n"); @@ -417,7 +416,7 @@ static void write_server_stmts(const statement_list_t *stmts, int expr_eval_rout fprintf(server, " */\n"); fprintf(server, "\n"); - if (iface->funcs) + if (statements_has_func(iface->details.iface->stmts)) { write_serverinterfacedecl(iface); write_stubdescdecl(iface); diff --git a/tools/widl/typegen.c b/tools/widl/typegen.c index 7810f80d507..0afa3dc9e7d 100644 --- a/tools/widl/typegen.c +++ b/tools/widl/typegen.c @@ -46,7 +46,7 @@ /* value to add on to round size up to a multiple of alignment */ #define ROUNDING(size, alignment) (((alignment) - 1) - (((size) + ((alignment) - 1)) & ((alignment) - 1))) -static const func_t *current_func; +static const var_t *current_func; static const type_t *current_structure; static const type_t *current_iface; @@ -536,17 +536,17 @@ static void write_var_init(FILE *file, int indent, const type_t *t, const char * print_file(file, indent, "%s%s = 0;\n", local_var_prefix, n); } -void write_parameters_init(FILE *file, int indent, const func_t *func, const char *local_var_prefix) +void write_parameters_init(FILE *file, int indent, const var_t *func, const char *local_var_prefix) { 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 (!func->args) + if (!type_get_function_args(func->type)) return; - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) write_var_init(file, indent, var->type, var->name, local_var_prefix); fprintf(file, "\n"); @@ -678,17 +678,18 @@ static void write_procformatstring_stmts(FILE *file, int indent, const statement { if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP) { - const func_t *func; + const statement_t *stmt_func; if (!pred(stmt->u.type)) continue; - if (stmt->u.type->funcs) LIST_FOR_EACH_ENTRY( func, stmt->u.type->funcs, const func_t, entry ) + STATEMENTS_FOR_EACH_FUNC(stmt_func, stmt->u.type->details.iface->stmts) { - if (is_local(func->def->attrs)) continue; + const var_t *func = stmt_func->u.var; + if (is_local(func->attrs)) continue; /* emit argument data */ - if (func->args) + if (type_get_function_args(func->type)) { const var_t *var; - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) write_procformatstring_type(file, indent, var->name, var->type, var->attrs, FALSE); } @@ -1075,27 +1076,27 @@ size_t type_memsize(const type_t *t, unsigned int *align) return size; } -int is_full_pointer_function(const func_t *func) +int is_full_pointer_function(const var_t *func) { const var_t *var; if (type_has_full_pointer(get_func_return_type(func))) return TRUE; - if (!func->args) + if (!type_get_function_args(func->type)) return FALSE; - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) if (type_has_full_pointer( var->type )) return TRUE; return FALSE; } -void write_full_pointer_init(FILE *file, int indent, const func_t *func, int is_server) +void write_full_pointer_init(FILE *file, int indent, const var_t *func, int is_server) { print_file(file, indent, "__frame->_StubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,%s);\n", is_server ? "XLAT_SERVER" : "XLAT_CLIENT"); fprintf(file, "\n"); } -void write_full_pointer_free(FILE *file, int indent, const func_t *func) +void write_full_pointer_free(FILE *file, int indent, const var_t *func) { print_file(file, indent, "NdrFullPointerXlatFree(__frame->_StubMsg.FullPtrXlatTables);\n"); fprintf(file, "\n"); @@ -2391,7 +2392,7 @@ static size_t write_contexthandle_tfs(FILE *file, const type_t *type, return start_offset; } -static size_t write_typeformatstring_var(FILE *file, int indent, const func_t *func, +static size_t write_typeformatstring_var(FILE *file, int indent, const var_t *func, type_t *type, const var_t *var, unsigned int *typeformat_offset) { @@ -2572,6 +2573,8 @@ static size_t process_tfs_stmts(FILE *file, const statement_list_t *stmts, if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry ) { const type_t *iface; + const statement_t *stmt_func; + if (stmt->type == STMT_LIBRARY) { process_tfs_stmts(file, stmt->u.lib->stmts, pred, typeformat_offset); @@ -2584,17 +2587,15 @@ static size_t process_tfs_stmts(FILE *file, const statement_list_t *stmts, if (!pred(iface)) continue; - if (iface->funcs) + current_iface = iface; + STATEMENTS_FOR_EACH_FUNC( stmt_func, iface->details.iface->stmts ) { - const func_t *func; - current_iface = iface; - LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry ) - { - if (is_local(func->def->attrs)) continue; + const var_t *func = stmt_func->u.var; + if (is_local(func->attrs)) continue; if (!is_void(get_func_return_type(func))) { - var_t v = *func->def; + var_t v = *func; v.type = get_func_return_type(func); update_tfsoff(get_func_return_type(func), write_typeformatstring_var( @@ -2604,15 +2605,14 @@ static size_t process_tfs_stmts(FILE *file, const statement_list_t *stmts, } current_func = func; - if (func->args) - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + if (type_get_function_args(func->type)) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) update_tfsoff( var->type, write_typeformatstring_var( file, 2, func, var->type, var, typeformat_offset), file); - } } } @@ -2742,14 +2742,14 @@ static unsigned int get_required_buffer_size(const var_t *var, unsigned int *ali return 0; } -static unsigned int get_function_buffer_size( const func_t *func, enum pass pass ) +static unsigned int get_function_buffer_size( const var_t *func, enum pass pass ) { const var_t *var; unsigned int total_size = 0, alignment; - if (func->args) + if (type_get_function_args(func->type)) { - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) { total_size += get_required_buffer_size(var, &alignment, pass); total_size += alignment; @@ -2758,7 +2758,7 @@ static unsigned int get_function_buffer_size( const func_t *func, enum pass pass if (pass == PASS_OUT && !is_void(get_func_return_type(func))) { - var_t v = *func->def; + var_t v = *func; v.type = get_func_return_type(func); total_size += get_required_buffer_size(&v, &alignment, PASS_RETURN); total_size += alignment; @@ -2991,7 +2991,7 @@ static void write_parameter_conf_or_var_exprs(FILE *file, int indent, const char } } -static void write_remoting_arg(FILE *file, int indent, const func_t *func, const char *local_var_prefix, +static void write_remoting_arg(FILE *file, int indent, const var_t *func, const char *local_var_prefix, enum pass pass, enum remoting_phase phase, const var_t *var) { int in_attr, out_attr, pointer_type; @@ -3183,7 +3183,7 @@ static void write_remoting_arg(FILE *file, int indent, const func_t *func, const fprintf(file, "\n"); } -void write_remoting_arguments(FILE *file, int indent, const func_t *func, const char *local_var_prefix, +void write_remoting_arguments(FILE *file, int indent, const var_t *func, const char *local_var_prefix, enum pass pass, enum remoting_phase phase) { if (phase == PHASE_BUFFERSIZE && pass != PASS_RETURN) @@ -3195,7 +3195,7 @@ void write_remoting_arguments(FILE *file, int indent, const func_t *func, const if (pass == PASS_RETURN) { var_t var; - var = *func->def; + var = *func; var.type = get_func_return_type(func); var.name = xstrdup( "_RetVal" ); write_remoting_arg( file, indent, func, local_var_prefix, pass, phase, &var ); @@ -3204,9 +3204,9 @@ void write_remoting_arguments(FILE *file, int indent, const func_t *func, const else { const var_t *var; - if (!func->args) + if (!type_get_function_args(func->type)) return; - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) write_remoting_arg( file, indent, func, local_var_prefix, pass, phase, var ); } } @@ -3218,14 +3218,14 @@ size_t get_size_procformatstring_type(const char *name, const type_t *type, cons } -size_t get_size_procformatstring_func(const func_t *func) +size_t get_size_procformatstring_func(const var_t *func) { const var_t *var; size_t size = 0; /* argument list size */ - if (func->args) - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + if (type_get_function_args(func->type)) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) size += get_size_procformatstring_type(var->name, var->type, var->attrs); /* return value size */ @@ -3241,11 +3241,12 @@ size_t get_size_procformatstring(const statement_list_t *stmts, type_pred_t pred { const statement_t *stmt; size_t size = 1; - const func_t *func; if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry ) { const type_t *iface; + const statement_t *stmt_func; + if (stmt->type == STMT_LIBRARY) { size += get_size_procformatstring(stmt->u.lib->stmts, pred) - 1; @@ -3258,10 +3259,12 @@ size_t get_size_procformatstring(const statement_list_t *stmts, type_pred_t pred if (!pred(iface)) continue; - if (iface->funcs) - LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry ) - if (!is_local(func->def->attrs)) - size += get_size_procformatstring_func( func ); + STATEMENTS_FOR_EACH_FUNC( stmt_func, iface->details.iface->stmts ) + { + const var_t *func = stmt_func->u.var; + if (!is_local(func->attrs)) + size += get_size_procformatstring_func( func ); + } } return size; } @@ -3272,7 +3275,7 @@ size_t get_size_typeformatstring(const statement_list_t *stmts, type_pred_t pred return process_tfs(NULL, stmts, pred); } -void declare_stub_args( FILE *file, int indent, const func_t *func ) +void declare_stub_args( FILE *file, int indent, const var_t *func ) { int in_attr, out_attr; int i = 0; @@ -3286,10 +3289,10 @@ void declare_stub_args( FILE *file, int indent, const func_t *func ) fprintf(file, " _RetVal;\n"); } - if (!func->args) + if (!type_get_function_args(func->type)) return; - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) { int is_string = is_string_type(var->attrs, var->type); @@ -3327,16 +3330,16 @@ void declare_stub_args( FILE *file, int indent, const func_t *func ) } -void assign_stub_out_args( FILE *file, int indent, const func_t *func, const char *local_var_prefix ) +void assign_stub_out_args( FILE *file, int indent, const var_t *func, const char *local_var_prefix ) { int in_attr, out_attr; int i = 0, sep = 0; const var_t *var; - if (!func->args) + if (!type_get_function_args(func->type)) return; - LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry ) + LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry ) { int is_string = is_string_type(var->attrs, var->type); in_attr = is_attr(var->attrs, ATTR_IN); diff --git a/tools/widl/typegen.h b/tools/widl/typegen.h index 0276b7fa433..b2c48df1993 100644 --- a/tools/widl/typegen.h +++ b/tools/widl/typegen.h @@ -43,14 +43,14 @@ void write_procformatstring(FILE *file, const statement_list_t *stmts, type_pred void write_typeformatstring(FILE *file, const statement_list_t *stmts, type_pred_t pred); void print_phase_basetype(FILE *file, int indent, const char *local_var_prefix, enum remoting_phase phase, enum pass pass, const var_t *var, const char *varname); -void write_remoting_arguments(FILE *file, int indent, const func_t *func, const char *local_var_prefix, +void write_remoting_arguments(FILE *file, int indent, const var_t *func, const char *local_var_prefix, enum pass pass, enum remoting_phase phase); size_t get_size_procformatstring_type(const char *name, const type_t *type, const attr_list_t *attrs); -size_t get_size_procformatstring_func(const func_t *func); +size_t get_size_procformatstring_func(const var_t *func); size_t get_size_procformatstring(const statement_list_t *stmts, type_pred_t pred); size_t get_size_typeformatstring(const statement_list_t *stmts, type_pred_t pred); -void assign_stub_out_args( FILE *file, int indent, const func_t *func, const char *local_var_prefix ); -void declare_stub_args( FILE *file, int indent, const func_t *func ); +void assign_stub_out_args( FILE *file, int indent, const var_t *func, const char *local_var_prefix ); +void declare_stub_args( FILE *file, int indent, const var_t *func ); int write_expr_eval_routines(FILE *file, const char *iface); void write_expr_eval_routine_list(FILE *file, const char *iface); void write_user_quad_list(FILE *file); @@ -58,11 +58,11 @@ void write_endpoints( FILE *f, const char *prefix, const str_list_t *list ); void write_exceptions( FILE *file ); size_t type_memsize(const type_t *t, unsigned int *align); int decl_indirect(const type_t *t); -void write_parameters_init(FILE *file, int indent, const func_t *func, const char *local_var_prefix); +void write_parameters_init(FILE *file, int indent, const var_t *func, const char *local_var_prefix); void print(FILE *file, int indent, const char *format, va_list ap); int get_padding(const var_list_t *fields); int is_user_type(const type_t *t); expr_t *get_size_is_expr(const type_t *t, const char *name); -int is_full_pointer_function(const func_t *func); -void write_full_pointer_init(FILE *file, int indent, const func_t *func, int is_server); -void write_full_pointer_free(FILE *file, int indent, const func_t *func); +int is_full_pointer_function(const var_t *func); +void write_full_pointer_init(FILE *file, int indent, const var_t *func, int is_server); +void write_full_pointer_free(FILE *file, int indent, const var_t *func); diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c index f13ec5354d3..c6def4b0891 100644 --- a/tools/widl/typetree.c +++ b/tools/widl/typetree.c @@ -34,6 +34,7 @@ type_t *type_new_function(var_list_t *args) type_t *t = make_type(RPC_FC_FUNCTION, NULL); t->details.function = xmalloc(sizeof(*t->details.function)); t->details.function->args = args; + t->details.function->idx = -1; return t; } @@ -47,19 +48,22 @@ type_t *type_new_pointer(type_t *ref, attr_list_t *attrs) static int compute_method_indexes(type_t *iface) { int idx; - func_t *f; + statement_t *stmt; + + if (!iface->details.iface) + return 0; if (iface->ref) idx = compute_method_indexes(iface->ref); else idx = 0; - if (!iface->funcs) - return idx; - - LIST_FOR_EACH_ENTRY( f, iface->funcs, func_t, entry ) - if (! is_callas(f->def->attrs)) - f->idx = idx++; + STATEMENTS_FOR_EACH_FUNC( stmt, iface->details.iface->stmts ) + { + var_t *func = stmt->u.var; + if (!is_callas(func->attrs)) + func->type->details.function->idx = idx++; + } return idx; } @@ -68,10 +72,9 @@ void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stm { iface->ref = inherit; iface->details.iface = xmalloc(sizeof(*iface->details.iface)); - iface->funcs = gen_function_list(stmts); iface->details.iface->disp_props = NULL; iface->details.iface->disp_methods = NULL; - iface->stmts = stmts; + iface->details.iface->stmts = stmts; iface->defined = TRUE; compute_method_indexes(iface); } @@ -81,10 +84,9 @@ void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *me iface->ref = find_type("IDispatch", 0); if (!iface->ref) error_loc("IDispatch is undefined\n"); iface->details.iface = xmalloc(sizeof(*iface->details.iface)); - iface->funcs = NULL; iface->details.iface->disp_props = props; iface->details.iface->disp_methods = methods; - iface->stmts = NULL; + iface->details.iface->stmts = NULL; iface->defined = TRUE; compute_method_indexes(iface); } @@ -94,3 +96,11 @@ void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface) type_dispinterface_define(dispiface, iface->details.iface->disp_props, iface->details.iface->disp_methods); } + +void type_module_define(type_t *module, statement_list_t *stmts) +{ + if (module->details.module) error_loc("multiple definition error\n"); + module->details.module = xmalloc(sizeof(*module->details.module)); + module->details.module->stmts = stmts; + module->defined = TRUE; +} diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h index 99c0d2f911d..ebd543ac691 100644 --- a/tools/widl/typetree.h +++ b/tools/widl/typetree.h @@ -29,6 +29,7 @@ type_t *type_new_pointer(type_t *ref, attr_list_t *attrs); void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts); void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods); void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface); +void type_module_define(type_t *module, statement_list_t *stmts); static inline var_list_t *type_struct_get_fields(const type_t *type) { diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 2ae856c827e..245f7f1080f 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -273,14 +273,22 @@ struct enumeration_details struct func_details { var_list_t *args; + int idx; }; struct iface_details { + statement_list_t *stmts; func_list_t *disp_methods; var_list_t *disp_props; }; +struct module_details +{ + statement_list_t *stmts; + func_list_t *funcs; +}; + struct _type_t { const char *name; enum type_kind kind; @@ -293,9 +301,8 @@ struct _type_t { struct enumeration_details *enumeration; struct func_details *function; struct iface_details *iface; + struct module_details *module; } details; - func_list_t *funcs; /* interfaces and modules */ - statement_list_t *stmts; /* interfaces and modules */ ifref_list_t *ifaces; /* coclasses */ unsigned long dim; /* array dimension */ expr_t *size_is, *length_is; @@ -339,8 +346,6 @@ struct _declarator_t { struct _func_t { var_t *def; - var_list_t *args; - int idx; /* parser-internal */ struct list entry; @@ -442,9 +447,31 @@ 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 func_t *func) +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->def->type->ref; + return func_type->details.function->args; +} + +#define STATEMENTS_FOR_EACH_FUNC(stmt, stmts) \ + if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, statement_t, entry ) \ + if (stmt->type == STMT_DECLARATION && stmt->u.var->stgclass == STG_NONE && \ + stmt->u.var->type->type == RPC_FC_FUNCTION) + +static inline int statements_has_func(const statement_list_t *stmts) +{ + const statement_t *stmt; + int has_func = 0; + STATEMENTS_FOR_EACH_FUNC(stmt, stmts) + { + has_func = 1; + break; + } + return has_func; } #endif diff --git a/tools/widl/write_msft.c b/tools/widl/write_msft.c index fd237dcfc17..c41ed6b4466 100644 --- a/tools/widl/write_msft.c +++ b/tools/widl/write_msft.c @@ -1261,7 +1261,7 @@ static HRESULT set_custdata(msft_typelib_t *typelib, REFGUID guid, return S_OK; } -static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int index) +static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, var_t *func, int index) { int offset, name_offset; int *typedata, typedata_size; @@ -1292,13 +1292,13 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int break; } - if (is_local( func->def->attrs )) { + if (is_local( func->attrs )) { chat("add_func_desc: skipping local function\n"); return S_FALSE; } - if (func->args) - LIST_FOR_EACH_ENTRY( arg, func->args, var_t, entry ) + if (type_get_function_args(func->type)) + LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->type), var_t, entry ) { num_params++; if (arg->attrs) LIST_FOR_EACH_ENTRY( attr, arg->attrs, const attr_t, entry ) { @@ -1311,9 +1311,9 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int chat("add_func_desc: num of params %d\n", num_params); - name_offset = ctl2_alloc_name(typeinfo->typelib, func->def->name); + name_offset = ctl2_alloc_name(typeinfo->typelib, func->name); - if (func->def->attrs) LIST_FOR_EACH_ENTRY( attr, func->def->attrs, const attr_t, entry ) { + if (func->attrs) LIST_FOR_EACH_ENTRY( attr, func->attrs, const attr_t, entry ) { expr_t *expr = attr->u.pval; switch(attr->type) { case ATTR_BINDABLE: @@ -1434,7 +1434,7 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int /* fill out the basic type information */ typedata[0] = typedata_size | (index << 16); - encode_var(typeinfo->typelib, get_func_return_type(func), func->def, &typedata[1], NULL, NULL, &decoded_size); + encode_var(typeinfo->typelib, get_func_return_type(func), 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; @@ -1460,10 +1460,10 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int warning("unknown number of optional attrs\n"); } - if (func->args) + if (type_get_function_args(func->type)) { i = 0; - LIST_FOR_EACH_ENTRY( arg, func->args, var_t, entry ) + LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->type), var_t, entry ) { int paramflags = 0; int *paramdata = typedata + 6 + extra_attr + (num_defaults ? num_params : 0) + i * 3; @@ -1567,10 +1567,10 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int if(typeinfo->typekind == TKIND_MODULE) namedata[9] |= 0x20; - if (func->args) + if (type_get_function_args(func->type)) { i = 0; - LIST_FOR_EACH_ENTRY( arg, func->args, var_t, entry ) + LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->type), var_t, entry ) { /* don't give the last arg of a [propput*] func a name */ if(i != num_params - 1 || (invokekind != 0x4 /* INVOKE_PROPERTYPUT */ && invokekind != 0x8 /* INVOKE_PROPERTYPUTREF */)) @@ -1965,9 +1965,10 @@ static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinte add_dispatch(typelib); msft_typeinfo->typeinfo->cImplTypes = 1; - /* count the no of funcs, as the variable indices come after the funcs */ - if (dispinterface->funcs) - LIST_FOR_EACH_ENTRY( func, dispinterface->funcs, const func_t, entry ) idx++; + /* count the no of methods, as the variable indices come after the funcs */ + if (dispinterface->details.iface->disp_methods) + LIST_FOR_EACH_ENTRY( func, dispinterface->details.iface->disp_methods, const func_t, entry ) + idx++; if (type_dispiface_get_props(dispinterface)) LIST_FOR_EACH_ENTRY( var, type_dispiface_get_props(dispinterface), var_t, entry ) @@ -1977,7 +1978,7 @@ static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinte { idx = 0; LIST_FOR_EACH_ENTRY( func, type_dispiface_get_methods(dispinterface), const func_t, entry ) - if(add_func_desc(msft_typeinfo, func, idx) == S_OK) + if(add_func_desc(msft_typeinfo, func->def, idx) == S_OK) idx++; } } @@ -1985,7 +1986,7 @@ static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinte static void add_interface_typeinfo(msft_typelib_t *typelib, type_t *interface) { int idx = 0; - const func_t *func; + const statement_t *stmt_func; type_t *ref; msft_typeinfo_t *msft_typeinfo; importinfo_t *ref_importinfo = NULL; @@ -2027,17 +2028,19 @@ static void add_interface_typeinfo(msft_typelib_t *typelib, type_t *interface) /* count the number of inherited interfaces and non-local functions */ for(ref = interface->ref; ref; ref = ref->ref) { num_parents++; - if (ref->funcs) - LIST_FOR_EACH_ENTRY( func, ref->funcs, const func_t, entry ) - if (!is_local(func->def->attrs)) num_funcs++; + STATEMENTS_FOR_EACH_FUNC( stmt_func, ref->details.iface->stmts ) { + var_t *func = stmt_func->u.var; + if (!is_local(func->attrs)) num_funcs++; + } } msft_typeinfo->typeinfo->datatype2 = num_funcs << 16 | num_parents; msft_typeinfo->typeinfo->cbSizeVft = num_funcs * 4; - if (interface->funcs) - LIST_FOR_EACH_ENTRY( func, interface->funcs, const func_t, entry ) - if(add_func_desc(msft_typeinfo, func, idx) == S_OK) - idx++; + STATEMENTS_FOR_EACH_FUNC( stmt_func, interface->details.iface->stmts ) { + var_t *func = stmt_func->u.var; + if(add_func_desc(msft_typeinfo, func, idx) == S_OK) + idx++; + } } static void add_structure_typeinfo(msft_typelib_t *typelib, type_t *structure) @@ -2173,7 +2176,7 @@ static void add_coclass_typeinfo(msft_typelib_t *typelib, type_t *cls) static void add_module_typeinfo(msft_typelib_t *typelib, type_t *module) { int idx = 0; - const func_t *func; + const statement_t *stmt; msft_typeinfo_t *msft_typeinfo; if (-1 < module->typelib_idx) @@ -2183,10 +2186,11 @@ static void add_module_typeinfo(msft_typelib_t *typelib, type_t *module) msft_typeinfo = create_msft_typeinfo(typelib, TKIND_MODULE, module->name, module->attrs); msft_typeinfo->typeinfo->typekind |= 0x0a00; - if (module->funcs) - LIST_FOR_EACH_ENTRY( func, module->funcs, const func_t, entry ) - if(add_func_desc(msft_typeinfo, func, idx) == S_OK) - idx++; + STATEMENTS_FOR_EACH_FUNC( stmt, module->details.module->stmts ) { + var_t *func = stmt->u.var; + if(add_func_desc(msft_typeinfo, func, idx) == S_OK) + idx++; + } msft_typeinfo->typeinfo->size = idx; } -- 2.11.4.GIT