Dan Hipschman : widl: Generate names for tagless structs, unions and enums.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Sep 7 03:45:44 CDT 2006


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

Author: Dan Hipschman <dsh at linux.ucla.edu>
Date:   Tue Aug 29 14:25:19 2006 -0700

widl: Generate names for tagless structs, unions and enums.

---

 tools/widl/parser.y |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index ead02cb..d70cc04 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -104,6 +104,7 @@ static void write_diid(type_t *iface);
 static void write_iid(type_t *iface);
 
 static int compute_method_indexes(type_t *iface);
+static char *gen_name(void);
 
 #define tsENUM   1
 #define tsSTRUCT 2
@@ -824,9 +825,19 @@ type:	  tVOID					{ $$ = make_tref(NULL,
 	;
 
 typedef: tTYPEDEF m_attributes type pident_list	{ typeref_t *tref = uniq_tref($3);
+						  type_t *t;
 						  $4->tname = tref->name;
 						  tref->name = NULL;
 						  $$ = type_ref(tref);
+						  t = $$->ref;
+						  if ((t->kind == TKIND_ENUM || t->kind == TKIND_RECORD
+						       || t->kind == TKIND_UNION) && ! t->name && ! parse_only)
+						  {
+						    attr_t *a = make_attr(ATTR_PUBLIC);
+						    LINK(a, $2);
+						    $2 = a;
+						    t->name = gen_name();
+						  }
 						  $$->attrs = $2;
 						  if (!parse_only && do_header)
 						    write_typedef($$, $4);
@@ -1614,3 +1625,28 @@ static int compute_method_indexes(type_t
 
   return idx;
 }
+
+static char *gen_name(void)
+{
+  static const char format[] = "__WIDL_%s_generated_name_%08lX";
+  static unsigned long n = 0;
+  static const char *file_id;
+  static size_t size;
+  char *name;
+
+  if (! file_id)
+  {
+    char *dst = dup_basename(input_name, ".idl");
+    file_id = dst;
+
+    for (; *dst; ++dst)
+      if (! isalnum((unsigned char) *dst))
+        *dst = '_';
+
+    size = sizeof format - 7 + strlen(file_id) + 8;
+  }
+
+  name = xmalloc(size);
+  sprintf(name, format, file_id, n++);
+  return name;
+}




More information about the wine-cvs mailing list