From 15eeaca3215e1b3005c722fc8770fa5f06f5ba16 Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Tue, 27 May 2008 21:50:18 +0100 Subject: [PATCH] widl: Move funcs and stmts fields from type_t structure to module_details and function_details. --- tools/widl/client.c | 41 +++++++----- tools/widl/header.c | 162 +++++++++++++++++++++++++----------------------- tools/widl/header.h | 8 +-- tools/widl/parser.y | 104 ++++++++++++++----------------- tools/widl/proxy.c | 149 ++++++++++++++++++++++---------------------- tools/widl/server.c | 27 ++++---- tools/widl/typegen.c | 99 +++++++++++++++-------------- tools/widl/typegen.h | 16 ++--- tools/widl/widltypes.h | 39 ++++++++++-- tools/widl/write_msft.c | 60 +++++++++--------- 10 files changed, 372 insertions(+), 333 deletions(-) diff --git a/tools/widl/client.c b/tools/widl/client.c index 779492e9171..91267c7b527 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); @@ -103,11 +104,11 @@ 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); - write_prefix_name(client, prefix_client, def); + write_prefix_name(client, prefix_client, func); fprintf(client, "(\n"); 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"); @@ -156,12 +157,12 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) indent--; fprintf(client, "\n"); - 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"); } @@ -253,9 +254,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))) @@ -438,6 +439,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; @@ -447,7 +450,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 f0a78efb421..50aff05140f 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -329,7 +329,7 @@ void write_type_v(FILE *h, type_t *t, int is_field, int declonly, if (pt->type == RPC_FC_FUNCTION) { if (ptr_level) fputc(')', h); fputc('(', h); - write_args(h, pt->details.function->args, NULL, 0, FALSE); + write_args(h, type_get_function_args(pt), NULL, 0, FALSE); fputc(')', h); } else write_type_right(h, t, is_field); @@ -538,14 +538,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; @@ -561,45 +561,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; @@ -629,32 +629,37 @@ 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_", name); - write_name(header,def); + write_name(header, func); fprintf(header, "(This"); - if (cur->args) - LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry ) + 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->"); - write_name(header, def); + write_name(header, func); fprintf(header, "(This"); - if (cur->args) - LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry ) + 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"); } @@ -692,23 +697,21 @@ 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)); + write_type_decl_left(header, get_func_return_type(func)); fprintf(header, " %s ", callconv); - write_name(header, def); + write_name(header, func); fprintf(header, "(\n"); - write_args(header, cur->args, iface->name, 2, TRUE); + write_args(header, type_get_function_args(func->type), iface->name, 2, TRUE); fprintf(header, ") = 0;\n"); fprintf(header, "\n"); } @@ -717,25 +720,28 @@ 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)); + write_type_decl_left(header, get_func_return_type(func)); fprintf(header, " (%s *", callconv); - write_name(header, def); + write_name(header, func); fprintf(header, ")(\n"); - write_args(header, cur->args, name, 1, TRUE); + write_args(header, type_get_function_args(func->type), name, 1, TRUE); fprintf(header, ");\n"); fprintf(header, "\n"); } @@ -754,26 +760,25 @@ 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)); + write_type_decl_left(header, get_func_return_type(func)); fprintf(header, " %s %s_", callconv, iface->name); - write_name(header, def); + write_name(header, func); fprintf(header, "_Proxy(\n"); - write_args(header, cur->args, iface->name, 1, TRUE); + write_args(header, type_get_function_args(func->type), iface->name, 1, TRUE); fprintf(header, ");\n"); /* stub prototype */ fprintf(header, "void __RPC_STUB %s_", iface->name); - write_name(header,def); + write_name(header, func); fprintf(header, "_Stub(\n"); fprintf(header, " IRpcStubBuffer* This,\n"); fprintf(header, " IRpcChannelBuffer* pRpcChannelBuffer,\n"); @@ -787,29 +792,28 @@ 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_", iface->name); - write_name(fp, mdef); + write_name(fp, m); fprintf(fp, "_Proxy(\n"); - write_args(fp, m->args, iface->name, 1, TRUE); + 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); @@ -829,11 +833,11 @@ 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)); + write_type_decl_left(fp, get_func_return_type(func)); fprintf(fp, " __RPC_STUB %s_", iface->name); - write_name(fp, mdef); + write_name(fp, m); fprintf(fp, "_Stub(\n"); - write_args(fp, cur->args, iface->name, 1, TRUE); + write_args(fp, type_get_function_args(func->type), iface->name, 1, TRUE); fprintf(fp, ")"); if (body) /* Remotable methods must all return HRESULTs. */ @@ -842,7 +846,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); } } } @@ -889,8 +893,8 @@ static void write_function_proto(FILE *header, const type_t *iface, const var_t if (callconv) fprintf(header, "%s ", callconv); write_prefix_name(header, prefix, fun); fprintf(header, "(\n"); - 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"); @@ -1076,7 +1080,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: @@ -1146,13 +1150,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 781f0f7b7e3..afc56d9e3c9 100644 --- a/tools/widl/header.h +++ b/tools/widl/header.h @@ -49,11 +49,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.y b/tools/widl/parser.y index 8ecde729e89..a7be88ac6b9 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -128,6 +128,7 @@ static type_t *make_e_union_type(char *name, var_t *switch_field, var_t *union_f static type_t *make_pointer_type(type_t *ref, attr_list_t *attrs); static void define_interface_type(type_t *iface, type_t *inherit, statement_list_t *stmts); static void define_dispinterface_type(type_t *iface, var_list_t *props, func_list_t *methods); +static void define_module_type(type_t *module, statement_list_t *stmts); static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type); static type_t *reg_type(type_t *type, const char *name, int t); @@ -153,8 +154,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 func_list_t *gen_function_list(const statement_list_t *stmts); +static void add_explicit_handle_if_necessary(var_t *func); static statement_t *make_statement(enum statement_type type); static statement_t *make_statement_type_decl(type_t *type); @@ -925,8 +925,7 @@ modulehdr: attributes module { $$ = $2; moduledef: modulehdr '{' int_statements '}' semicolon_opt { $$ = $1; - $$->stmts = $3; - $$->funcs = gen_function_list($3); + define_module_type($$, $3); } ; @@ -1288,7 +1287,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; @@ -1313,6 +1311,7 @@ static type_t *make_func_type(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; } @@ -1400,10 +1399,9 @@ static void define_interface_type(type_t *iface, type_t *inherit, statement_list if (iface->details.iface) error_loc("multiple definition error\n"); iface->ref = inherit; iface->details.iface = xmalloc(sizeof(*iface->details.iface)); - iface->funcs = gen_function_list(stmts); + iface->details.iface->stmts = stmts; iface->details.iface->disp_props = NULL; iface->details.iface->disp_methods = NULL; - iface->stmts = stmts; iface->defined = TRUE; compute_method_indexes(iface); } @@ -1414,14 +1412,21 @@ static void define_dispinterface_type(type_t *iface, var_list_t *props, func_li 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->stmts = NULL; iface->details.iface->disp_props = props; iface->details.iface->disp_methods = methods; - iface->stmts = NULL; iface->defined = TRUE; compute_method_indexes(iface); } +static void define_module_type(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; +} + static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type) { type_t *ptrchain_type; @@ -1759,8 +1764,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; } @@ -2185,41 +2188,25 @@ var_t *find_const(const char *name, int f) return cur->var; } -static 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 int compute_method_indexes(type_t *iface) { int idx; - func_t *f; + const 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; } @@ -2662,12 +2649,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; @@ -2702,11 +2689,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; @@ -2728,13 +2715,12 @@ 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); - if (!func->def->type->details.function->args) + if (!func->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 ); + func->type->details.function->args = xmalloc( sizeof(*func->type->details.function->args) ); + list_init( func->type->details.function->args ); } - list_add_head( func->def->type->details.function->args, &idl_handle->entry ); - func->args = func->def->type->details.function->args; + list_add_head( func->type->details.function->args, &idl_handle->entry ); } } } @@ -2742,18 +2728,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); } } @@ -2783,10 +2772,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 ee8db3939c1..129f85f908e 100644 --- a/tools/widl/proxy.c +++ b/tools/widl/proxy.c @@ -248,60 +248,59 @@ static void proxy_free_variables( var_list_t *args ) } } -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; - write_type_decl_left(proxy, get_func_return_type(cur)); + write_type_decl_left(proxy, get_func_return_type(func)); print_proxy( " %s %s_", callconv, iface->name); - write_name(proxy, def); + write_name(proxy, func); print_proxy( "_Proxy(\n"); - write_args(proxy, cur->args, iface->name, 1, TRUE); + write_args(proxy, type_get_function_args(func->type), iface->name, 1, TRUE); print_proxy( ")\n"); print_proxy( "{\n"); indent ++; /* 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" ); print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\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"); 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, &_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, &_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, &_StubMsg);\n" ); fprintf(proxy, "\n"); @@ -314,15 +313,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--; @@ -331,7 +330,7 @@ static void gen_proxy(type_t *iface, const func_t *cur, int idx, print_proxy( "{\n" ); indent++; if (has_full_pointer) - write_full_pointer_free(proxy, indent, cur); + write_full_pointer_free(proxy, indent, func); print_proxy( "NdrProxyFreeBuffer(This, &_StubMsg);\n" ); indent--; print_proxy( "}\n"); @@ -342,7 +341,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--; } @@ -357,17 +356,16 @@ 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( "void __RPC_STUB %s_", iface->name); - write_name(proxy, def); + write_name(proxy, func); print_proxy( "_Stub(\n"); indent++; print_proxy( "IRpcStubBuffer* This,\n"); @@ -379,7 +377,7 @@ static void gen_stub(type_t *iface, const func_t *cur, const char *cas, indent++; print_proxy("%s * _This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n", iface->name, iface->name); print_proxy("MIDL_STUB_MESSAGE _StubMsg;\n"); - declare_stub_args( proxy, indent, cur ); + declare_stub_args( proxy, indent, func ); fprintf(proxy, "\n"); /* FIXME: trace */ @@ -387,23 +385,23 @@ static void gen_stub(type_t *iface, const func_t *cur, const char *cas, print_proxy("NdrStubInitialize(_pRpcMessage, &_StubMsg, &Object_StubDesc, _pRpcChannelBuffer);\n"); fprintf(proxy, "\n"); - write_parameters_init(proxy, indent, cur); + write_parameters_init(proxy, indent, func); 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( &_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset ); indent--; fprintf(proxy, "\n"); - write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_UNMARSHAL); + write_remoting_arguments(proxy, indent, func, PASS_IN, PHASE_UNMARSHAL); fprintf(proxy, "\n"); - assign_stub_out_args( proxy, indent, cur ); + assign_stub_out_args( proxy, indent, func ); print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n"); fprintf(proxy, "\n"); @@ -413,13 +411,13 @@ static void gen_stub(type_t *iface, const func_t *cur, const char *cas, else { fprintf(proxy, "_This->lpVtbl->"); - write_name(proxy, def); + write_name(proxy, func); } fprintf(proxy, "(_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, ", "); if (arg->type->declarray) @@ -432,29 +430,29 @@ 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, PASS_OUT, PHASE_BUFFERSIZE); + write_remoting_arguments(proxy, indent, func, PASS_OUT, PHASE_BUFFERSIZE); - if (!is_void(get_func_return_type(cur))) - write_remoting_arguments(proxy, indent, cur, PASS_RETURN, PHASE_BUFFERSIZE); + if (!is_void(get_func_return_type(func))) + write_remoting_arguments(proxy, indent, func, PASS_RETURN, PHASE_BUFFERSIZE); print_proxy("NdrStubGetBuffer(This, _pRpcChannelBuffer, &_StubMsg);\n"); - write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_MARSHAL); + write_remoting_arguments(proxy, indent, func, 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, PASS_RETURN, PHASE_MARSHAL); + if (!is_void(get_func_return_type(func))) + write_remoting_arguments(proxy, indent, func, PASS_RETURN, PHASE_MARSHAL); indent--; print_proxy("}\n"); print_proxy("RpcFinally\n"); print_proxy("{\n"); - write_remoting_arguments(proxy, indent+1, cur, PASS_OUT, PHASE_FREE); + write_remoting_arguments(proxy, indent+1, func, PASS_OUT, PHASE_FREE); if (has_full_pointer) - write_full_pointer_free(proxy, indent, cur); + write_full_pointer_free(proxy, indent, func); print_proxy("}\n"); print_proxy("RpcEndFinally\n"); @@ -468,16 +466,16 @@ static void gen_stub(type_t *iface, const func_t *cur, const char *cas, static int write_proxy_methods(type_t *iface) { - const func_t *cur; + const statement_t *stmt; int i = 0; if (iface->ref) i = write_proxy_methods(iface->ref); - 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"); print_proxy( "%s_", iface->name); - write_name(proxy, def); + write_name(proxy, func); fprintf(proxy, "_Proxy"); i++; } @@ -487,18 +485,18 @@ static int write_proxy_methods(type_t *iface) static int write_stub_methods(type_t *iface) { - const func_t *cur; + const statement_t *stmt; int i = 0; if (iface->ref) i = write_stub_methods(iface->ref); 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"); print_proxy( "%s_", iface->name); - write_name(proxy, def); + write_name(proxy, func); fprintf(proxy, "_Stub"); i++; } @@ -509,34 +507,37 @@ static int write_stub_methods(type_t *iface) static void write_proxy(type_t *iface, unsigned int *proc_offset) { int midx = -1, stubs; - const func_t *cur; - - if (!iface->funcs) return; + 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"); - 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++; @@ -659,7 +660,8 @@ static void write_proxy_iface_name_format(const statement_list_t *stmts, const c else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP) { type_t *iface = stmt->u.type; - if (iface->ref && iface->funcs && need_proxy(iface)) + if (iface->ref && statements_has_func(iface->details.iface->stmts) && + need_proxy(iface)) fprintf(proxy, format, iface->name); } } @@ -675,7 +677,8 @@ static void write_iid_lookup(const statement_list_t *stmts, const char *file_id, else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP) { type_t *iface = stmt->u.type; - if(iface->ref && iface->funcs && need_proxy(iface)) + if(iface->ref && statements_has_func(iface->details.iface->stmts) && + need_proxy(iface)) { fprintf(proxy, " if (!_%s_CHECK_IID(%d))\n", file_id, *c); fprintf(proxy, " {\n"); diff --git a/tools/widl/server.c b/tools/widl/server.c index 3581fdc88b4..6d4364f6a8e 100644 --- a/tools/widl/server.c +++ b/tools/widl/server.c @@ -50,14 +50,13 @@ 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 */ @@ -65,7 +64,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) fprintf(server, "void __RPC_STUB\n"); fprintf(server, "%s_", iface->name); - write_name(server, def); + write_name(server, func); fprintf(server, "(\n"); indent++; print_server("PRPC_MESSAGE _pRpcMessage)\n"); @@ -110,7 +109,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++; @@ -150,15 +149,15 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset) print_server("_RetVal = "); else print_server(""); - write_prefix_name(server, prefix_server, def); + write_prefix_name(server, prefix_server, 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; @@ -251,18 +250,18 @@ 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; + var_t *func = stmt->u.var; print_server("%s_", iface->name); - write_name(server, def); + write_name(server, func); fprintf(server, ",\n"); method_count++; @@ -404,7 +403,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 c08ad0c0a53..cced32b932d 100644 --- a/tools/widl/typegen.c +++ b/tools/widl/typegen.c @@ -41,7 +41,7 @@ #include "typegen.h" #include "expr.h" -static const func_t *current_func; +static const var_t *current_func; static const type_t *current_structure; static const type_t *current_iface; @@ -346,17 +346,17 @@ static void write_var_init(FILE *file, int indent, const type_t *t, const char * print_file(file, indent, "%s = 0;\n", n); } -void write_parameters_init(FILE *file, int indent, const func_t *func) +void write_parameters_init(FILE *file, int indent, const var_t *func) { const var_t *var; if (!is_void(get_func_return_type(func))) write_var_init(file, indent, get_func_return_type(func), "_RetVal"); - 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); fprintf(file, "\n"); @@ -486,17 +486,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); } @@ -880,27 +881,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, "_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(_StubMsg.FullPtrXlatTables);\n"); fprintf(file, "\n"); @@ -2110,7 +2111,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) { @@ -2289,6 +2290,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); @@ -2301,17 +2304,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( @@ -2321,15 +2322,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); - } } } @@ -2518,14 +2518,14 @@ static unsigned int get_required_buffer_size(const var_t *var, unsigned int *ali } } -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; @@ -2534,7 +2534,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; @@ -2706,7 +2706,7 @@ expr_t *get_size_is_expr(const type_t *t, const char *name) return x; } -static void write_remoting_arg(FILE *file, int indent, const func_t *func, +static void write_remoting_arg(FILE *file, int indent, const var_t *func, enum pass pass, enum remoting_phase phase, const var_t *var) { @@ -2966,7 +2966,7 @@ static void write_remoting_arg(FILE *file, int indent, const func_t *func, fprintf(file, "\n"); } -void write_remoting_arguments(FILE *file, int indent, const func_t *func, +void write_remoting_arguments(FILE *file, int indent, const var_t *func, enum pass pass, enum remoting_phase phase) { if (phase == PHASE_BUFFERSIZE && pass != PASS_RETURN) @@ -2978,7 +2978,7 @@ void write_remoting_arguments(FILE *file, int indent, const func_t *func, 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, pass, phase, &var ); @@ -2987,9 +2987,9 @@ void write_remoting_arguments(FILE *file, int indent, const func_t *func, 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, pass, phase, var ); } } @@ -3001,14 +3001,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 */ @@ -3024,11 +3024,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; @@ -3041,10 +3042,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; } @@ -3055,7 +3058,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; @@ -3069,10 +3072,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_attr(var->attrs, ATTR_STRING); @@ -3113,16 +3116,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 ) +void assign_stub_out_args( FILE *file, int indent, const var_t *func ) { 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_attr(var->attrs, ATTR_STRING); in_attr = is_attr(var->attrs, ATTR_IN); diff --git a/tools/widl/typegen.h b/tools/widl/typegen.h index a1013cb37f8..aa1d89ba9aa 100644 --- a/tools/widl/typegen.h +++ b/tools/widl/typegen.h @@ -42,24 +42,24 @@ void write_formatstringsdecl(FILE *f, int indent, const statement_list_t *stmts, void write_procformatstring(FILE *file, const statement_list_t *stmts, type_pred_t pred); void write_typeformatstring(FILE *file, const statement_list_t *stmts, type_pred_t pred); void print_phase_basetype(FILE *file, int indent, 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, enum pass pass, enum remoting_phase phase); +void write_remoting_arguments(FILE *file, int indent, const var_t *func, 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 ); -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 ); +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); void write_endpoints( FILE *f, const char *prefix, const str_list_t *list ); 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); +void write_parameters_init(FILE *file, int indent, const var_t *func); 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/widltypes.h b/tools/widl/widltypes.h index 182dcddecef..20a9d7180e6 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -272,14 +272,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; @@ -292,9 +300,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; @@ -337,8 +344,6 @@ struct _declarator_t { struct _func_t { var_t *def; - var_list_t *args; - int idx; /* parser-internal */ struct list entry; @@ -437,9 +442,31 @@ var_t *find_const(const char *name, int f); type_t *find_type(const char *name, int t); type_t *make_type(unsigned char type, type_t *ref); -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 b1daf31bddf..3297b9e8457 100644 --- a/tools/widl/write_msft.c +++ b/tools/widl/write_msft.c @@ -1264,7 +1264,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; @@ -1295,13 +1295,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 ) { @@ -1314,9 +1314,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: @@ -1437,7 +1437,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; @@ -1463,10 +1463,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; @@ -1570,10 +1570,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 */)) @@ -1969,9 +1969,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 (dispinterface->details.iface->disp_props) LIST_FOR_EACH_ENTRY( var, dispinterface->details.iface->disp_props, var_t, entry ) @@ -1981,7 +1982,7 @@ static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinte { idx = 0; LIST_FOR_EACH_ENTRY( func, dispinterface->details.iface->disp_methods, 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++; } } @@ -1989,7 +1990,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; @@ -2031,17 +2032,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) @@ -2177,7 +2180,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) @@ -2187,10 +2190,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