From e6e7055c0b8c27c4584bf1afb6a952ef37d718b8 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Thu, 15 Oct 2015 20:46:28 +0800 Subject: [PATCH] widl: Add support for unions to the typelib generator. Signed-off-by: Dmitry Timoshkov Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- tools/widl/write_msft.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tools/widl/write_msft.c b/tools/widl/write_msft.c index a39e986ea88..fc0eae781f4 100644 --- a/tools/widl/write_msft.c +++ b/tools/widl/write_msft.c @@ -745,6 +745,7 @@ static importinfo_t *find_importinfo(msft_typelib_t *typelib, const char *name) 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_union_typeinfo(msft_typelib_t *typelib, type_t *tunion); static void add_coclass_typeinfo(msft_typelib_t *typelib, type_t *cls); static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinterface); @@ -993,6 +994,9 @@ static int encode_type( case TYPE_ENUM: add_enum_typeinfo(typelib, type); break; + case TYPE_UNION: + add_union_typeinfo(typelib, type); + break; case TYPE_COCLASS: add_coclass_typeinfo(typelib, type); break; @@ -1752,6 +1756,10 @@ static HRESULT add_var_desc(msft_typeinfo_t *typeinfo, UINT index, var_t* var) typedata[4] = typeinfo->datawidth; typeinfo->datawidth += var_datawidth; break; + case TKIND_UNION: + typedata[4] = typeinfo->datawidth; + typeinfo->datawidth = max(typeinfo->datawidth, var_datawidth); + break; case TKIND_DISPATCH: var_kind = 3; /* VAR_DISPATCH */ typeinfo->datawidth = pointer_size; @@ -2141,6 +2149,24 @@ static void add_enum_typeinfo(msft_typelib_t *typelib, type_t *enumeration) add_var_desc(msft_typeinfo, idx++, cur); } +static void add_union_typeinfo(msft_typelib_t *typelib, type_t *tunion) +{ + int idx = 0; + var_t *cur; + msft_typeinfo_t *msft_typeinfo; + + if (-1 < tunion->typelib_idx) + return; + + tunion->typelib_idx = typelib->typelib_header.nrtypeinfos; + msft_typeinfo = create_msft_typeinfo(typelib, TKIND_UNION, tunion->name, tunion->attrs); + msft_typeinfo->typeinfo->size = 0; + + if (type_union_get_cases(tunion)) + LIST_FOR_EACH_ENTRY(cur, type_union_get_cases(tunion), var_t, entry) + add_var_desc(msft_typeinfo, idx++, cur); +} + static void add_typedef_typeinfo(msft_typelib_t *typelib, type_t *tdef) { msft_typeinfo_t *msft_typeinfo = NULL; @@ -2288,6 +2314,9 @@ static void add_type_typeinfo(msft_typelib_t *typelib, type_t *type) case TYPE_ENUM: add_enum_typeinfo(typelib, type); break; + case TYPE_UNION: + add_union_typeinfo(typelib, type); + break; case TYPE_COCLASS: add_coclass_typeinfo(typelib, type); break;