Rob Shearman : widl: Write the local stubs file based on the parsed list of statements, rather than using hooks in the parser code.

Alexandre Julliard julliard at winehq.org
Mon Dec 29 08:48:02 CST 2008


Module: wine
Branch: master
Commit: bf5a9cb61ed888da25cb7b65a05266f1e18dabbb
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=bf5a9cb61ed888da25cb7b65a05266f1e18dabbb

Author: Rob Shearman <robertshearman at gmail.com>
Date:   Mon Dec 29 12:06:24 2008 +0000

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 68bf1ec..d06ef4d 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -754,7 +754,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.  */";
@@ -814,6 +814,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 <objbase.h>\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 d87ae16..84b652d 100644
--- a/tools/widl/header.h
+++ b/tools/widl/header.h
@@ -50,7 +50,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 42479dc..1bcfd33 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -354,6 +354,7 @@ input:   gbl_statements				{ fix_incomplete();
 						  write_client($1);
 						  write_server($1);
 						  write_dlldata($1);
+						  write_local_stubs($1);
 						}
 	;
 
@@ -925,7 +926,6 @@ interfacedef: interfacehdr inherit
 	  '{' int_statements '}' semicolon_opt	{ $$ = $1.interface;
 						  type_interface_define($$, $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;
 						}
@@ -936,7 +936,6 @@ interfacedef: interfacehdr inherit
 	   semicolon_opt			{ $$ = $1.interface;
 						  type_interface_define($$, find_type_or_error2($3, 0), $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 cc3b40e..4f076c3 100644
--- a/tools/widl/widl.c
+++ b/tools/widl/widl.c
@@ -132,8 +132,6 @@ const char *prefix_server = "";
 int line_number = 1;
 
 FILE *header;
-FILE *local_stubs;
-FILE *proxy;
 FILE *idfile;
 
 size_t pointer_size = 0;
@@ -643,17 +641,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 <objbase.h>\n");
-    fprintf(local_stubs, "#include \"%s\"\n\n", header_name);
-  }
-
   init_types();
   ret = parser_parse();
 
@@ -671,10 +658,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 d45c157..c368317 100644
--- a/tools/widl/widl.h
+++ b/tools/widl/widl.h
@@ -68,13 +68,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




More information about the wine-cvs mailing list