widl [5/5]: Encode coclass types in typelibs

Dan Hipschman dsh at linux.ucla.edu
Fri Jul 28 15:45:33 CDT 2006


This gives WIDL the ability to encode coclasses as types in the typelib.
It also adds a bit of type checking to the parser.  With this patch, WIDL
can finally generate a typelib for the file found at
<http://www.winehq.org/pipermail/wine-devel/2006-June/048307.html>, given
that you tweak two things in the file: 1) change "help_string" to "helpstring",
and 2) remove the propget attribute from the Value function.  The first is
not a WIDL bug (MIDL won't take it either), and the second is easy enough to
work around for now (if it should indeed be allowed by WIDL, it's easy enough
to add that in another patch).

ChangeLog:
* Support encoding of coclasses as types in typelibs
---
 tools/widl/parser.y     |    3 +++
 tools/widl/widltypes.h  |    4 +++-
 tools/widl/write_msft.c |    7 ++++++-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index a4efb66..b8e1c39 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -638,6 +638,7 @@ int_std:  tINT					{ $$ = make_type(RPC_
 coclass:  tCOCLASS aIDENTIFIER			{ $$ = make_class($2); }
 	| tCOCLASS aKNOWNTYPE			{ $$ = find_type($2, 0);
 						  if ($$->defined) yyerror("multiple definition error");
+						  if ($$->kind != TKIND_COCLASS) yyerror("%s was not declared a coclass", $2);
 						}
 	;
 
@@ -1060,6 +1061,7 @@ static type_t *make_type(unsigned char t
 {
   type_t *t = xmalloc(sizeof(type_t));
   t->name = NULL;
+  t->kind = TKIND_PRIMITIVE;
   t->type = type;
   t->ref = ref;
   t->attrs = NULL;
@@ -1153,6 +1155,7 @@ static type_t *make_class(char *name)
 {
   type_t *c = make_type(0, NULL);
   c->name = name;
+  c->kind = TKIND_COCLASS;
   INIT_LINK(c);
   return c;
 }
diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h
index 84a2fc2..7bf2229 100644
--- a/tools/widl/widltypes.h
+++ b/tools/widl/widltypes.h
@@ -160,7 +160,8 @@ enum expr_type
 
 enum type_kind
 {
-    TKIND_ENUM = 0,
+    TKIND_PRIMITIVE = -1,
+    TKIND_ENUM,
     TKIND_RECORD,
     TKIND_MODULE,
     TKIND_INTERFACE,
@@ -199,6 +200,7 @@ struct _expr_t {
 
 struct _type_t {
   const char *name;
+  enum type_kind kind;
   unsigned char type;
   struct _type_t *ref;
   const attr_t *attrs;
diff --git a/tools/widl/write_msft.c b/tools/widl/write_msft.c
index aae864a..7554654 100644
--- a/tools/widl/write_msft.c
+++ b/tools/widl/write_msft.c
@@ -738,6 +738,7 @@ static importinfo_t *find_importinfo(msf
 static void add_structure_typeinfo(msft_typelib_t *typelib, type_t *structure);
 static void add_interface_typeinfo(msft_typelib_t *typelib, type_t *interface);
 static void add_enum_typeinfo(msft_typelib_t *typelib, type_t *enumeration);
+static void add_coclass_typeinfo(msft_typelib_t *typelib, type_t *cls);
 
 
 /****************************************************************************
@@ -971,7 +972,11 @@ #endif
                 add_enum_typeinfo(typelib, type);
                 break;
             case 0:
-                error("encode_type: VT_USERDEFINED - can't yet add typedef's on the fly\n");
+                if (type->kind == TKIND_COCLASS)
+                    add_coclass_typeinfo(typelib, type);
+                else
+                    error("encode_type: VT_USERDEFINED - can't yet add typedef's on the fly\n");
+                break;
             default:
                 error("encode_type: VT_USERDEFINED - unhandled type %d\n", type->type);
             }



More information about the wine-patches mailing list