From: R��mi Bernon rbernon@codeweavers.com
--- tools/widl/client.c | 29 ++++++++++++----------------- tools/widl/header.c | 42 +++++++++++++++++------------------------- tools/widl/parser.h | 8 +++++++- tools/widl/parser.y | 12 +++--------- tools/widl/proxy.c | 39 +++++++++++++++++++-------------------- tools/widl/register.c | 18 +++++++++--------- tools/widl/server.c | 38 ++++++++++++++++---------------------- tools/widl/utils.c | 2 +- tools/widl/utils.h | 2 +- tools/widl/widl.c | 41 ++++++++++++++++++++++++++--------------- tools/widl/widl.h | 18 +++++++++--------- 11 files changed, 120 insertions(+), 129 deletions(-)
diff --git a/tools/widl/client.c b/tools/widl/client.c index 704be91cb78..d15fe8cd535 100644 --- a/tools/widl/client.c +++ b/tools/widl/client.c @@ -488,17 +488,15 @@ static void write_implicithandledecl(type_t *iface) } }
- -static void init_client(void) +static void init_client( const struct idl_ctx *ctx ) { if (client) return; - if (!(client = fopen(client_name, "w"))) - error("Could not open %s for output\n", client_name); + if (!(client = fopen( client_name, "w" ))) error( "Could not open %s for output\n", client_name );
- print_client("/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name); - print_client("#include <string.h>\n"); + print_client( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, ctx->input ); + print_client( "#include <string.h>\n" ); print_client( "\n"); - print_client("#include "%s"\n", header_name); + print_client( "#include "%s"\n", header_name ); print_client( "\n"); print_client( "#ifndef DECLSPEC_HIDDEN\n"); print_client( "#define DECLSPEC_HIDDEN\n"); @@ -611,17 +609,14 @@ static void write_client_routines(const statement_list_t *stmts) write_typeformatstring(client, stmts, need_stub); }
-void write_client(const statement_list_t *stmts) +void write_client( const struct idl_ctx *ctx ) { - if (!do_client) - return; - if (do_everything && !need_stub_files(stmts)) - return; + if (!do_client) return; + if (do_everything && !need_stub_files( ctx->statements )) return;
- init_client(); - if (!client) - return; + init_client( ctx ); + if (!client) return;
- write_client_routines( stmts ); - fclose(client); + write_client_routines( ctx->statements ); + fclose( client ); } diff --git a/tools/widl/header.c b/tools/widl/header.c index 8b9c64e1e38..5ba1f57a8c7 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -1495,24 +1495,20 @@ static void write_local_stubs_stmts(FILE *local_stubs, const statement_list_t *s } }
-void write_local_stubs(const statement_list_t *stmts) +void write_local_stubs( const struct idl_ctx *ctx ) { - FILE *local_stubs; + FILE *local_stubs;
- if (!local_stubs_name) return; + if (!local_stubs_name) return; + if (!(local_stubs = fopen( local_stubs_name, "w" ))) error( "Could not open %s for output\n", local_stubs_name );
- 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 <objbase.h>\n"); - fprintf(local_stubs, "#include "%s"\n\n", header_name); + fprintf( local_stubs, "/* call_as/local stubs for %s */\n\n", ctx->input ); + fprintf( local_stubs, "#include <objbase.h>\n" ); + fprintf( local_stubs, "#include "%s"\n\n", header_name );
- write_local_stubs_stmts(local_stubs, stmts); + write_local_stubs_stmts( local_stubs, ctx->statements );
- fclose(local_stubs); + fclose(local_stubs); }
static void write_function_proto(FILE *header, const type_t *iface, const var_t *fun, const char *prefix) @@ -2125,17 +2121,13 @@ static void write_header_stmts(FILE *header, const statement_list_t *stmts, cons } }
-void write_header(const statement_list_t *stmts) +void write_header( const struct idl_ctx *ctx ) { FILE *header;
if (!do_header) return; - - if(!(header = fopen(header_name, "w"))) { - error("Could not open %s for output\n", header_name); - return; - } - fprintf(header, "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n\n", PACKAGE_VERSION, input_name); + if (!(header = fopen( header_name, "w" ))) error( "Could not open %s for output\n", header_name ); + fprintf( header, "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n\n", PACKAGE_VERSION, ctx->input );
fprintf(header, "#ifdef _WIN32\n"); fprintf(header, "#ifndef __REQUIRED_RPCNDR_H_VERSION__\n"); @@ -2143,7 +2135,7 @@ void write_header(const statement_list_t *stmts) fprintf(header, "#endif\n"); fprintf(header, "#include <rpc.h>\n" ); fprintf(header, "#include <rpcndr.h>\n" ); - if (!for_each_serializable(stmts, NULL, serializable_exists)) + if (!for_each_serializable(ctx->statements, NULL, serializable_exists)) fprintf(header, "#include <midles.h>\n" ); fprintf(header, "#endif\n\n");
@@ -2156,18 +2148,18 @@ void write_header(const statement_list_t *stmts) fprintf(header, "#define __%s__\n\n", header_token);
fprintf(header, "/* Forward declarations */\n\n"); - write_forward_decls(header, stmts); + write_forward_decls(header, ctx->statements);
fprintf(header, "/* Headers for imported files */\n\n"); - write_imports(header, stmts); + write_imports(header, ctx->statements); fprintf(header, "\n"); start_cplusplus_guard(header);
- write_header_stmts(header, stmts, NULL, FALSE); + write_header_stmts(header, ctx->statements, NULL, FALSE);
fprintf(header, "/* Begin additional prototypes for all interfaces */\n"); fprintf(header, "\n"); - for_each_serializable(stmts, header, write_serialize_function_decl); + for_each_serializable(ctx->statements, header, write_serialize_function_decl); write_user_types(header); write_generic_handle_routines(header); write_context_handle_rundowns(header); diff --git a/tools/widl/parser.h b/tools/widl/parser.h index 47bcf4bc5db..5f6b8c091e8 100644 --- a/tools/widl/parser.h +++ b/tools/widl/parser.h @@ -21,7 +21,13 @@ #ifndef __WIDL_PARSER_H #define __WIDL_PARSER_H
-int parser_parse(void); +struct idl_ctx +{ + const char *input; + statement_list_t *statements; +}; + +int parser_parse( struct idl_ctx *ctx );
extern FILE *parser_in; extern char *parser_text; diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 6d8332a2423..044279f9906 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -124,6 +124,7 @@ static typelib_t *current_typelib; %code provides {
+void parser_error( struct idl_ctx *ctx, const char *message ) __attribute__((noreturn)); int parser_lex( PARSER_STYPE *yylval );
} @@ -131,6 +132,7 @@ int parser_lex( PARSER_STYPE *yylval ); %define api.prefix {parser_} %define api.pure full %define parse.error verbose +%parse-param {struct idl_ctx *ctx}
%union { attr_t *attr; @@ -361,15 +363,7 @@ int parser_lex( PARSER_STYPE *yylval ); input: gbl_statements m_acf { $1 = append_parameterized_type_stmts($1); check_statements($1, FALSE); check_all_user_types($1); - write_header($1); - write_id_data($1); - write_proxies($1); - write_client($1); - write_server($1); - write_regscript($1); - write_typelib_regscript($1); - write_dlldata($1); - write_local_stubs($1); + ctx->statements = $1; } ;
diff --git a/tools/widl/proxy.c b/tools/widl/proxy.c index a80aa5d77fe..d878c2152ec 100644 --- a/tools/widl/proxy.c +++ b/tools/widl/proxy.c @@ -76,20 +76,19 @@ static void write_stubdesc(int expr_eval_routines) print_proxy( "\n"); }
-static void init_proxy(const statement_list_t *stmts) +static void init_proxy( const struct idl_ctx *ctx ) { - if (proxy) return; - if(!(proxy = fopen(proxy_name, "w"))) - error("Could not open %s for output\n", proxy_name); - print_proxy( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name); - print_proxy( "\n"); - print_proxy( "#define __midl_proxy\n"); - print_proxy( "#include "objbase.h"\n"); - print_proxy( "\n"); - print_proxy( "#ifndef DECLSPEC_HIDDEN\n"); - print_proxy( "#define DECLSPEC_HIDDEN\n"); - print_proxy( "#endif\n"); - print_proxy( "\n"); + if (proxy) return; + if (!(proxy = fopen( proxy_name, "w" ))) error( "Could not open %s for output\n", proxy_name ); + print_proxy( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, ctx->input ); + print_proxy( "\n"); + print_proxy( "#define __midl_proxy\n"); + print_proxy( "#include "objbase.h"\n"); + print_proxy( "\n"); + print_proxy( "#ifndef DECLSPEC_HIDDEN\n"); + print_proxy( "#define DECLSPEC_HIDDEN\n"); + print_proxy( "#endif\n"); + print_proxy( "\n"); }
static void clear_output_vars( const var_list_t *args ) @@ -1042,14 +1041,14 @@ static void write_proxy_routines(const statement_list_t *stmts) fprintf(proxy, "};\n"); }
-void write_proxies(const statement_list_t *stmts) +void write_proxies( const struct idl_ctx *ctx ) { - if (!do_proxies) return; - if (do_everything && !need_proxy_file(stmts)) return; + if (!do_proxies) return; + if (do_everything && !need_proxy_file( ctx->statements )) return;
- init_proxy(stmts); - if(!proxy) return; + init_proxy( ctx ); + if (!proxy) return;
- write_proxy_routines( stmts ); - fclose(proxy); + write_proxy_routines( ctx->statements ); + fclose( proxy ); } diff --git a/tools/widl/register.c b/tools/widl/register.c index 6c00dfaf5a2..39239cef556 100644 --- a/tools/widl/register.c +++ b/tools/widl/register.c @@ -240,12 +240,12 @@ static void write_progids( const statement_list_t *stmts ) } }
-void write_regscript( const statement_list_t *stmts ) +void write_regscript( const struct idl_ctx *ctx ) { const type_t *ps_factory;
if (!do_regscript) return; - if (do_everything && !need_proxy_file( stmts )) return; + if (do_everything && !need_proxy_file( ctx->statements )) return;
init_output_buffer();
@@ -261,7 +261,7 @@ void write_regscript( const statement_list_t *stmts ) put_str( indent++, "{\n" ); put_str( indent, "NoRemove ActivatableClassId\n" ); put_str( indent++, "{\n" ); - write_runtimeclasses_registry( stmts ); + write_runtimeclasses_registry( ctx->statements ); put_str( --indent, "}\n" ); put_str( --indent, "}\n" ); put_str( --indent, "}\n" ); @@ -275,16 +275,16 @@ void write_regscript( const statement_list_t *stmts )
put_str( indent, "NoRemove Interface\n" ); put_str( indent++, "{\n" ); - ps_factory = find_ps_factory( stmts ); - if (ps_factory) write_interfaces( stmts, ps_factory ); + ps_factory = find_ps_factory( ctx->statements ); + if (ps_factory) write_interfaces( ctx->statements, ps_factory ); put_str( --indent, "}\n" );
put_str( indent, "NoRemove CLSID\n" ); put_str( indent++, "{\n" ); - write_coclasses( stmts, NULL ); + write_coclasses( ctx->statements, NULL ); put_str( --indent, "}\n" );
- write_progids( stmts ); + write_progids( ctx->statements ); put_str( --indent, "}\n" ); }
@@ -304,13 +304,13 @@ void write_regscript( const statement_list_t *stmts ) } }
-void write_typelib_regscript( const statement_list_t *stmts ) +void write_typelib_regscript( const struct idl_ctx *ctx ) { const statement_t *stmt; unsigned int count = 0;
if (!do_typelib) return; - if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry ) + if (ctx->statements) LIST_FOR_EACH_ENTRY( stmt, ctx->statements, const statement_t, entry ) { if (stmt->type != STMT_LIBRARY) continue; if (count && !strendswith( typelib_name, ".res" )) diff --git a/tools/widl/server.c b/tools/widl/server.c index 1d8ab41185d..0c2c573d6a2 100644 --- a/tools/widl/server.c +++ b/tools/widl/server.c @@ -441,19 +441,16 @@ static void write_serverinterfacedecl(type_t *iface) fprintf(server, "\n"); }
- -static void init_server(void) +static void init_server( const struct idl_ctx *ctx ) { - if (server) - return; - if (!(server = fopen(server_name, "w"))) - error("Could not open %s for output\n", server_name); - - print_server("/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name); - print_server("#include <string.h>\n"); - fprintf(server, "\n"); - print_server("#include "%s"\n", header_name); - print_server("\n"); + if (server) return; + if (!(server = fopen( server_name, "w" ))) error( "Could not open %s for output\n", server_name ); + + print_server( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, ctx->input ); + print_server( "#include <string.h>\n" ); + fprintf( server, "\n" ); + print_server( "#include "%s"\n", header_name ); + print_server( "\n" ); print_server( "#ifndef DECLSPEC_HIDDEN\n"); print_server( "#define DECLSPEC_HIDDEN\n"); print_server( "#endif\n"); @@ -537,17 +534,14 @@ static void write_server_routines(const statement_list_t *stmts) write_typeformatstring(server, stmts, need_stub); }
-void write_server(const statement_list_t *stmts) +void write_server( const struct idl_ctx *ctx ) { - if (!do_server) - return; - if (do_everything && !need_stub_files(stmts)) - return; + if (!do_server) return; + if (do_everything && !need_stub_files( ctx->statements )) return;
- init_server(); - if (!server) - return; + init_server( ctx ); + if (!server) return;
- write_server_routines( stmts ); - fclose(server); + write_server_routines( ctx->statements ); + fclose( server ); } diff --git a/tools/widl/utils.c b/tools/widl/utils.c index aad40f6b087..93ff5f35e8a 100644 --- a/tools/widl/utils.c +++ b/tools/widl/utils.c @@ -76,7 +76,7 @@ void error_loc(const char *s, ...) }
/* yyerror: yacc assumes this is not newline terminated. */ -void parser_error(const char *s) +void parser_error( struct idl_ctx *ctx, const char *s ) { error_loc("%s\n", s); } diff --git a/tools/widl/utils.h b/tools/widl/utils.h index f042f0e064c..0d7fe306fe5 100644 --- a/tools/widl/utils.h +++ b/tools/widl/utils.h @@ -22,8 +22,8 @@ #define __WIDL_UTILS_H
#include "widltypes.h" +#include "parser.h"
-void parser_error(const char *s) __attribute__((noreturn)); int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2))); void error_loc(const char *s, ...) __attribute__((format (printf, 1, 2))) __attribute__((noreturn)); void error(const char *s, ...) __attribute__((format (printf, 1, 2))) __attribute__((noreturn)); diff --git a/tools/widl/widl.c b/tools/widl/widl.c index 7b2276b0a41..84cb30ac7a4 100644 --- a/tools/widl/widl.c +++ b/tools/widl/widl.c @@ -38,6 +38,7 @@ #include "widl.h" #include "utils.h" #include "parser.h" +#include "parser.tab.h" #include "wpp_private.h" #include "header.h"
@@ -327,16 +328,15 @@ static char *eat_space(char *s) return s; }
-void write_dlldata(const statement_list_t *stmts) +void write_dlldata( const struct idl_ctx *ctx ) { struct strarray filenames = empty_strarray; int define_proxy_delegation = 0; FILE *dlldata;
- if (!do_dlldata || !need_proxy_file(stmts)) - return; + if (!do_dlldata || !need_proxy_file( ctx->statements )) return;
- define_proxy_delegation = need_proxy_delegation(stmts); + define_proxy_delegation = need_proxy_delegation( ctx->statements );
dlldata = fopen(dlldata_name, "r"); if (dlldata) { @@ -429,7 +429,7 @@ static void write_id_data_stmts(const statement_list_t *stmts) } }
-void write_id_data(const statement_list_t *stmts) +static void write_id_data( const struct idl_ctx *ctx ) { if (!do_idfile) return;
@@ -470,7 +470,7 @@ void write_id_data(const statement_list_t *stmts) fprintf(idfile, "#endif\n\n"); start_cplusplus_guard(idfile);
- write_id_data_stmts(stmts); + write_id_data_stmts( ctx->statements );
fprintf(idfile, "\n"); end_cplusplus_guard(idfile); @@ -715,6 +715,7 @@ int open_typelib( const char *name )
int main(int argc,char *argv[]) { + struct idl_ctx ctx = {0}; int i; int ret = 0; struct strarray files; @@ -805,7 +806,7 @@ int main(int argc,char *argv[]) return 1; } else - input_idl_name = input_name = xstrdup(files.str[0]); + ctx.input = input_idl_name = input_name = xstrdup(files.str[0]); } else { fprintf(stderr, "%s", usage); @@ -826,25 +827,25 @@ int main(int argc,char *argv[]) (debuglevel & DEBUGLEVEL_PPMSG) != 0 );
if (!header_name) - header_name = replace_extension( get_basename(input_name), ".idl", ".h" ); + header_name = replace_extension( get_basename( ctx.input ), ".idl", ".h" );
if (!typelib_name && do_typelib) - typelib_name = replace_extension( get_basename(input_name), ".idl", ".tlb" ); + typelib_name = replace_extension( get_basename( ctx.input ), ".idl", ".tlb" );
if (!proxy_name && do_proxies) - proxy_name = replace_extension( get_basename(input_name), ".idl", "_p.c" ); + proxy_name = replace_extension( get_basename( ctx.input ), ".idl", "_p.c" );
if (!client_name && do_client) - client_name = replace_extension( get_basename(input_name), ".idl", "_c.c" ); + client_name = replace_extension( get_basename( ctx.input ), ".idl", "_c.c" );
if (!server_name && do_server) - server_name = replace_extension( get_basename(input_name), ".idl", "_s.c" ); + server_name = replace_extension( get_basename( ctx.input ), ".idl", "_s.c" );
if (!regscript_name && do_regscript) - regscript_name = replace_extension( get_basename(input_name), ".idl", "_r.rgs" ); + regscript_name = replace_extension( get_basename( ctx.input ), ".idl", "_r.rgs" );
if (!idfile_name && do_idfile) - idfile_name = replace_extension( get_basename(input_name), ".idl", "_i.c" ); + idfile_name = replace_extension( get_basename( ctx.input ), ".idl", "_i.c" );
if (do_proxies) proxy_token = dup_basename_token(proxy_name,"_p.c"); if (do_client) client_token = dup_basename_token(client_name,"_c.c"); @@ -895,7 +896,7 @@ int main(int argc,char *argv[]) header_token = make_token(header_name);
init_types(); - ret = parser_parse(); + ret = parser_parse( &ctx );
fclose(parser_in);
@@ -903,6 +904,16 @@ int main(int argc,char *argv[]) exit(1); }
+ write_header( &ctx ); + write_id_data( &ctx ); + write_proxies( &ctx ); + write_client( &ctx ); + write_server( &ctx ); + write_regscript( &ctx ); + write_typelib_regscript( &ctx ); + write_dlldata( &ctx ); + write_local_stubs( &ctx ); + /* Everything has been done successfully, don't delete any files. */ set_everything(FALSE); local_stubs_name = NULL; diff --git a/tools/widl/widl.h b/tools/widl/widl.h index c63882108a8..3576f028d19 100644 --- a/tools/widl/widl.h +++ b/tools/widl/widl.h @@ -84,16 +84,16 @@ enum stub_mode extern enum stub_mode get_stub_mode(void); extern int open_typelib( const char *name );
-extern void write_header(const statement_list_t *stmts); -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_regscript(const statement_list_t *stmts); -extern void write_typelib_regscript(const statement_list_t *stmts); +struct idl_ctx; +extern void write_header( const struct idl_ctx *ctx ); +extern void write_proxies( const struct idl_ctx *ctx ); +extern void write_client( const struct idl_ctx *ctx ); +extern void write_server( const struct idl_ctx *ctx ); +extern void write_regscript( const struct idl_ctx *ctx ); +extern void write_typelib_regscript( const struct idl_ctx *ctx ); extern void output_typelib_regscript( const typelib_t *typelib ); -extern void write_local_stubs(const statement_list_t *stmts); -extern void write_dlldata(const statement_list_t *stmts); +extern void write_local_stubs( const struct idl_ctx *ctx ); +extern void write_dlldata( const struct idl_ctx *ctx );
extern void start_cplusplus_guard(FILE *fp); extern void end_cplusplus_guard(FILE *fp);