From 7e6474a32a11978b041b529edd1227782530cc00 Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Mon, 21 Apr 2008 17:35:26 +0100 Subject: [PATCH] widl: Write the local stubs file based on the parsed list of statements, rather than using hooks in the parser code. --- tools/widl/header.c | 34 +++++++++++++++++++++++++++++++++- tools/widl/header.h | 1 - tools/widl/parser.y | 3 +-- tools/widl/widl.c | 17 ----------------- tools/widl/widl.h | 2 +- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/tools/widl/header.c b/tools/widl/header.c index 152dae5cdb6..abdc2edbef7 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -783,7 +783,7 @@ static void write_method_proto(FILE *header, const type_t *iface) } } -void write_locals(FILE *fp, const type_t *iface, int body) +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. */"; @@ -847,6 +847,38 @@ void write_locals(FILE *fp, const type_t *iface, int body) } } +static void write_local_stubs_stmts(FILE *local_stubs, const statement_list_t *stmts) +{ + const statement_t *stmt; + if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry ) + { + if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP) + write_locals(local_stubs, stmt->u.type, TRUE); + else if (stmt->type == STMT_LIBRARY) + write_local_stubs_stmts(local_stubs, stmt->u.lib->stmts); + } +} + +void write_local_stubs(const statement_list_t *stmts) +{ + FILE *local_stubs; + + if (!local_stubs_name) return; + + local_stubs = fopen(local_stubs_name, "w"); + if (!local_stubs) { + error("Could not open %s for output\n", local_stubs_name); + return; + } + fprintf(local_stubs, "/* call_as/local stubs for %s */\n\n", input_name); + fprintf(local_stubs, "#include \n"); + fprintf(local_stubs, "#include \"%s\"\n\n", header_name); + + write_local_stubs_stmts(local_stubs, stmts); + + fclose(local_stubs); +} + static void write_function_proto(FILE *header, const type_t *iface, const func_t *fun, const char *prefix) { var_t *def = fun->def; diff --git a/tools/widl/header.h b/tools/widl/header.h index 3fd3b43e3a5..72413bbd7f3 100644 --- a/tools/widl/header.h +++ b/tools/widl/header.h @@ -52,7 +52,6 @@ extern void write_array(FILE *h, array_dims_t *v, int field); extern void write_import(const char *fname); extern void write_forward(type_t *iface); extern void write_interface(type_t *iface); -extern void write_locals(FILE *fp, const type_t *iface, int body); extern void write_coclass(type_t *cocl); extern void write_coclass_forward(type_t *cocl); extern void write_typedef(type_t *type); diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 056006a07eb..3d148dfcfa0 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -355,6 +355,7 @@ input: gbl_statements { fix_incomplete(); write_client($1); write_server($1); write_dlldata($1); + write_local_stubs($1); } ; @@ -927,7 +928,6 @@ interfacedef: interfacehdr inherit '{' int_statements '}' semicolon_opt { $$ = $1.interface; define_interface_type($$, $2, $4); if (!parse_only && do_header) write_interface($$); - if (!parse_only && local_stubs) write_locals(local_stubs, $$, TRUE); pointer_default = $1.old_pointer_default; is_in_interface = FALSE; } @@ -941,7 +941,6 @@ interfacedef: interfacehdr inherit if (!inherit) error_loc("base class '%s' not found in import\n", $3); define_interface_type($$, inherit, $6); if (!parse_only && do_header) write_interface($$); - if (!parse_only && local_stubs) write_locals(local_stubs, $$, TRUE); pointer_default = $1.old_pointer_default; is_in_interface = FALSE; } diff --git a/tools/widl/widl.c b/tools/widl/widl.c index e93d684aeee..71fa1a09baa 100644 --- a/tools/widl/widl.c +++ b/tools/widl/widl.c @@ -128,8 +128,6 @@ const char *prefix_server = ""; int line_number = 1; FILE *header; -FILE *local_stubs; -FILE *proxy; FILE *idfile; time_t now; @@ -625,17 +623,6 @@ int main(int argc,char *argv[]) start_cplusplus_guard(header); } - if (local_stubs_name) { - local_stubs = fopen(local_stubs_name, "w"); - if (!local_stubs) { - fprintf(stderr, "Could not open %s for output\n", local_stubs_name); - return 1; - } - fprintf(local_stubs, "/* call_as/local stubs for %s */\n\n", input_name); - fprintf(local_stubs, "#include \n"); - fprintf(local_stubs, "#include \"%s\"\n\n", header_name); - } - init_types(); ret = parser_parse(); @@ -653,10 +640,6 @@ int main(int argc,char *argv[]) fclose(header); } - if (local_stubs) { - fclose(local_stubs); - } - fclose(parser_in); if(ret) { diff --git a/tools/widl/widl.h b/tools/widl/widl.h index 39a1b812a4e..76a373594b7 100644 --- a/tools/widl/widl.h +++ b/tools/widl/widl.h @@ -65,13 +65,13 @@ extern int line_number; extern int char_number; extern FILE* header; -extern FILE* local_stubs; extern FILE* idfile; extern void write_id_data(const statement_list_t *stmts); extern void write_proxies(const statement_list_t *stmts); extern void write_client(const statement_list_t *stmts); extern void write_server(const statement_list_t *stmts); +extern void write_local_stubs(const statement_list_t *stmts); extern void write_dlldata(const statement_list_t *stmts); #endif -- 2.11.4.GIT