From: Hans Leidekker hans@codeweavers.com
--- tools/widl/attribute.c | 11 +++++++++++ tools/widl/client.c | 8 +++++--- tools/widl/header.c | 10 ++++++---- tools/widl/parser.y | 30 ++++++++++++++++++++---------- tools/widl/register.c | 24 +++++++++++++++--------- tools/widl/server.c | 18 +++++++++++------- tools/widl/utils.h | 7 ------- tools/widl/widl.h | 1 + tools/widl/widltypes.h | 6 ++++++ tools/widl/write_msft.c | 13 ++++++++++--- tools/widl/write_sltg.c | 13 +++++++++++-- 11 files changed, 96 insertions(+), 45 deletions(-)
diff --git a/tools/widl/attribute.c b/tools/widl/attribute.c index 2546e88b30a..feb4c2b5db4 100644 --- a/tools/widl/attribute.c +++ b/tools/widl/attribute.c @@ -103,6 +103,17 @@ void *get_aliaschain_attrp( const type_t *type, enum attr_type attr_type ) } }
+void get_version( const attr_list_t *list, unsigned short *major, unsigned short *minor ) +{ + version_t *version = get_attrp( list, ATTR_VERSION ); + if (version) + { + *major = version->major; + *minor = version->minor; + } + else *major = *minor = 0; +} + struct allowed_attr { unsigned int dce_compatible : 1; diff --git a/tools/widl/client.c b/tools/widl/client.c index 795e3ba2104..e5d93cdc1c3 100644 --- a/tools/widl/client.c +++ b/tools/widl/client.c @@ -439,9 +439,11 @@ static void write_stubdescriptor(type_t *iface, int expr_eval_routines)
static void write_clientinterfacedecl(type_t *iface) { - unsigned int ver = get_attrv(iface->attrs, ATTR_VERSION); const struct uuid *uuid = get_attrp(iface->attrs, ATTR_UUID); const str_list_t *endpoints = get_attrp(iface->attrs, ATTR_ENDPOINT); + unsigned short major, minor; + + get_version( iface->attrs, &major, &minor );
if (endpoints) write_endpoints( client, iface->name, endpoints );
@@ -452,7 +454,7 @@ static void write_clientinterfacedecl(type_t *iface) print_client("{{0x%08x,0x%04x,0x%04x,{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x}},{%d,%d}},\n", uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0], uuid->Data4[1], uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5], uuid->Data4[6], - uuid->Data4[7], MAJORVERSION(ver), MINORVERSION(ver)); + uuid->Data4[7], major, minor); print_client("{{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},\n"); /* FIXME */ print_client("0,\n"); if (endpoints) @@ -475,7 +477,7 @@ static void write_clientinterfacedecl(type_t *iface) iface->name, iface->name); else print_client("RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec = (RPC_IF_HANDLE)& %s___RpcClientInterface;\n", - prefix_client, iface->name, MAJORVERSION(ver), MINORVERSION(ver), iface->name); + prefix_client, iface->name, major, minor, iface->name); fprintf(client, "\n"); }
diff --git a/tools/widl/header.c b/tools/widl/header.c index 81a789a74df..b993286a85c 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -1760,12 +1760,14 @@ static void write_com_interface_end(FILE *header, type_t *iface)
static void write_rpc_interface_start(FILE *header, const type_t *iface) { - unsigned int ver = get_attrv(iface->attrs, ATTR_VERSION); const var_t *var = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE); expr_t *contract = get_attrp(iface->attrs, ATTR_CONTRACT); + unsigned short major, minor; + + get_version( iface->attrs, &major, &minor );
fprintf(header, "/*****************************************************************************\n"); - fprintf(header, " * %s interface (v%d.%d)\n", iface->name, MAJORVERSION(ver), MINORVERSION(ver)); + fprintf(header, " * %s interface (v%d.%d)\n", iface->name, major, minor); fprintf(header, " */\n"); if (contract) write_apicontract_guard_start(header, contract); fprintf(header,"#ifndef __%s_INTERFACE_DEFINED__\n", iface->name); @@ -1784,9 +1786,9 @@ static void write_rpc_interface_start(FILE *header, const type_t *iface) else { fprintf(header, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n", - prefix_client, iface->name, MAJORVERSION(ver), MINORVERSION(ver)); + prefix_client, iface->name, major, minor); fprintf(header, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n", - prefix_server, iface->name, MAJORVERSION(ver), MINORVERSION(ver)); + prefix_server, iface->name, major, minor); } }
diff --git a/tools/widl/parser.y b/tools/widl/parser.y index fb21a2417f1..c2f5000ab1b 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -59,6 +59,7 @@ static void append_array(declarator_t *decl, expr_t *expr); static void append_chain_type(declarator_t *decl, type_t *type, enum type_qualifier qual); static void append_chain_callconv( struct location where, type_t *chain, char *callconv ); static warning_list_t *append_warning(warning_list_t *, int); +static version_t *make_version( unsigned short major, unsigned short minor );
static type_t *reg_typedefs( struct location where, decl_spec_t *decl_spec, var_list_t *names, attr_list_t *attrs ); static type_t *find_type_or_error(struct namespace *parent, const char *name); @@ -148,6 +149,7 @@ PARSER_LTYPE pop_import(void); warning_list_t *warning_list; typeref_t *typeref; typeref_list_t *typeref_list; + version_t *version; char *str; struct uuid *uuid; unsigned int num; @@ -336,8 +338,7 @@ PARSER_LTYPE pop_import(void); %type <type> coclass coclassdef %type <type> runtimeclass runtimeclass_def %type <type> apicontract apicontract_def -%type <num> contract_ver -%type <num> pointer_type threading_type marshaling_behavior version +%type <num> pointer_type threading_type marshaling_behavior %type <str> libraryhdr callconv cppquote importlib import %type <str> typename m_typename %type <str> import_start @@ -349,6 +350,7 @@ PARSER_LTYPE pop_import(void); %type <warning_list> warnings %type <num> allocate_option_list allocate_option %type <namespace> namespace_pfx +%type <version> version contract_ver
%left ',' %right '?' ':' @@ -594,13 +596,13 @@ marshaling_behavior: ;
contract_ver: - aNUM { $$ = MAKEVERSION(0, $1.value); } - | aNUM '.' aNUM { $$ = MAKEVERSION($3.value, $1.value); } + aNUM { $$ = make_version( 0, $1.value ); } + | aNUM '.' aNUM { $$ = make_version( $3.value, $1.value ); } ;
contract_req : decl_spec ',' contract_ver { - struct integer integer = {.value = $3}; + struct integer integer = {.value = ($3->major << 16) | $3->minor }; if ($1->type->type_type != TYPE_APICONTRACT) error_loc("type %s is not an apicontract\n", $1->type->name); $$ = make_exprl(EXPR_NUM, &integer); @@ -660,7 +662,7 @@ attribute | tCONTEXTHANDLENOSERIALIZE { $$ = attr_int( @$, ATTR_CONTEXTHANDLE, 0 ); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ } | tCONTEXTHANDLESERIALIZE { $$ = attr_int( @$, ATTR_CONTEXTHANDLE, 0 ); /* RPC_CONTEXT_HANDLE_SERIALIZE */ } | tCONTRACT '(' contract_req ')' { $$ = attr_ptr( @$, ATTR_CONTRACT, $3 ); } - | tCONTRACTVERSION '(' contract_ver ')' { $$ = attr_int( @$, ATTR_CONTRACTVERSION, $3 ); } + | tCONTRACTVERSION '(' contract_ver ')' { $$ = attr_ptr( @$, ATTR_CONTRACTVERSION, $3 ); } | tCONTROL { $$ = attr_int( @$, ATTR_CONTROL, 0 ); } | tCUSTOM '(' aUUID ',' expr_const ')' { attr_custdata_t *data = xmalloc( sizeof(*data) ); data->id = *$3; data->pval = $5; @@ -765,7 +767,7 @@ attribute | tASYNCUUID '(' aUUID ')' { $$ = attr_ptr( @$, ATTR_ASYNCUUID, $3 ); } | tV1ENUM { $$ = attr_int( @$, ATTR_V1ENUM, 0 ); } | tVARARG { $$ = attr_int( @$, ATTR_VARARG, 0 ); } - | tVERSION '(' version ')' { $$ = attr_int( @$, ATTR_VERSION, $3 ); } + | tVERSION '(' version ')' { $$ = attr_ptr( @$, ATTR_VERSION, $3 ); } | tVIPROGID '(' aSTRING ')' { $$ = attr_ptr( @$, ATTR_VIPROGID, $3 ); } | tWIREMARSHAL '(' type ')' { $$ = attr_ptr( @$, ATTR_WIREMARSHAL, $3 ); } | pointer_type { $$ = attr_int( @$, ATTR_POINTERTYPE, $1 ); } @@ -1386,9 +1388,9 @@ uniondef: tUNION m_typename '{' ne_union_fields '}' ;
version: - aNUM { $$ = MAKEVERSION($1.value, 0); } - | aNUM '.' aNUM { $$ = MAKEVERSION($1.value, $3.value); } - | aHEXNUM { $$ = $1.value; } + aNUM { $$ = make_version( $1.value, 0 ); } + | aNUM '.' aNUM { $$ = make_version( $1.value, $3.value ); } + | aHEXNUM { $$ = make_version( $1.value >> 16, $1.value & 0xffff ); } ;
acf_statements @@ -1990,6 +1992,14 @@ static typelib_t *make_library(const char *name, const attr_list_t *attrs) return typelib; }
+static version_t *make_version( unsigned short major, unsigned short minor ) +{ + version_t *version = xmalloc( sizeof(*version) ); + version->major = major; + version->minor = minor; + return version; +} + static int hash_ident(const char *name) { const char *p = name; diff --git a/tools/widl/register.c b/tools/widl/register.c index c5600c9e7ea..be3743c9d10 100644 --- a/tools/widl/register.c +++ b/tools/widl/register.c @@ -112,7 +112,9 @@ static void write_typelib_interface( const type_t *iface, const typelib_t *typel { const struct uuid *typelib_uuid = get_attrp( typelib->attrs, ATTR_UUID ); const struct uuid *uuid = get_attrp( iface->attrs, ATTR_UUID ); - unsigned int version = get_attrv( typelib->attrs, ATTR_VERSION ); + unsigned short major, minor; + + get_version( iface->attrs, &major, &minor );
if (!uuid) return; if (!is_object( iface )) return; @@ -121,9 +123,9 @@ static void write_typelib_interface( const type_t *iface, const typelib_t *typel indent++; put_str( indent, "ProxyStubClsid = s '{00020424-0000-0000-C000-000000000046}'\n" ); put_str( indent, "ProxyStubClsid32 = s '{00020424-0000-0000-C000-000000000046}'\n" ); - if (version) + if (major || minor) put_str( indent, "TypeLib = s '%s' { val Version = s '%u.%u' }\n", - format_uuid( typelib_uuid ), MAJORVERSION(version), MINORVERSION(version) ); + format_uuid( typelib_uuid ), major, minor ); else put_str( indent, "TypeLib = s '%s'", format_uuid( typelib_uuid )); indent--; @@ -145,7 +147,9 @@ static int write_coclass( const type_t *class, const typelib_t *typelib ) const char *progid = get_attrp( class->attrs, ATTR_PROGID ); const char *vi_progid = get_attrp( class->attrs, ATTR_VIPROGID ); const char *threading = get_coclass_threading( class ); - unsigned int version = get_attrv( class->attrs, ATTR_VERSION ); + unsigned short major, minor; + + get_version( class->attrs, &major, &minor );
if (!uuid) return 0; if (typelib && !threading && !progid) return 0; @@ -160,9 +164,10 @@ static int write_coclass( const type_t *class, const typelib_t *typelib ) { const struct uuid *typelib_uuid = get_attrp( typelib->attrs, ATTR_UUID ); put_str( indent, "TypeLib = s '%s'\n", format_uuid( typelib_uuid )); - if (!version) version = get_attrv( typelib->attrs, ATTR_VERSION ); + if (!(major && minor)) + get_version( typelib->attrs, &major, &minor ); } - if (version) put_str( indent, "Version = s '%u.%u'\n", MAJORVERSION(version), MINORVERSION(version) ); + if (major || minor) put_str( indent, "Version = s '%u.%u'\n", major, minor ); if (vi_progid) put_str( indent, "VersionIndependentProgId = s '%s'\n", vi_progid ); put_str( --indent, "}\n" ); return 1; @@ -336,12 +341,14 @@ void output_typelib_regscript( const typelib_t *typelib ) const struct uuid *typelib_uuid = get_attrp( typelib->attrs, ATTR_UUID ); const char *descr = get_attrp( typelib->attrs, ATTR_HELPSTRING ); const expr_t *lcid_expr = get_attrp( typelib->attrs, ATTR_LIBLCID ); - unsigned int version = get_attrv( typelib->attrs, ATTR_VERSION ); + unsigned short major, minor; unsigned int flags = 0; char id_part[12] = ""; char *resname = typelib_name; expr_t *expr;
+ get_version( typelib->attrs, &major, &minor ); + if (is_attr( typelib->attrs, ATTR_RESTRICTED )) flags |= 1; /* LIBFLAG_FRESTRICTED */ if (is_attr( typelib->attrs, ATTR_CONTROL )) flags |= 2; /* LIBFLAG_FCONTROL */ if (is_attr( typelib->attrs, ATTR_HIDDEN )) flags |= 4; /* LIBFLAG_FHIDDEN */ @@ -353,8 +360,7 @@ void output_typelib_regscript( const typelib_t *typelib ) put_str( indent++, "{\n" ); put_str( indent, "NoRemove '%s'\n", format_uuid( typelib_uuid )); put_str( indent++, "{\n" ); - put_str( indent, "'%u.%u' = s '%s'\n", - MAJORVERSION(version), MINORVERSION(version), descr ? descr : typelib->name ); + put_str( indent, "'%u.%u' = s '%s'\n", major, minor, descr ? descr : typelib->name ); put_str( indent++, "{\n" ); expr = get_attrp( typelib->attrs, ATTR_ID ); if (expr) diff --git a/tools/widl/server.c b/tools/widl/server.c index 8bc179f1438..4c72b106069 100644 --- a/tools/widl/server.c +++ b/tools/widl/server.c @@ -266,9 +266,11 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
static void write_dispatchtable(type_t *iface) { - unsigned int ver = get_attrv(iface->attrs, ATTR_VERSION); unsigned int method_count = 0; const statement_t *stmt; + unsigned short major, minor; + + get_version( iface->attrs, &major, &minor );
print_server("static RPC_DISPATCH_FUNCTION %s_table[] =\n", iface->name); print_server("{\n"); @@ -286,7 +288,7 @@ static void write_dispatchtable(type_t *iface) print_server("0\n"); indent--; print_server("};\n"); - print_server("static RPC_DISPATCH_TABLE %s_v%d_%d_DispatchTable =\n", iface->name, MAJORVERSION(ver), MINORVERSION(ver)); + print_server("static RPC_DISPATCH_TABLE %s_v%d_%d_DispatchTable =\n", iface->name, major, minor); print_server("{\n"); indent++; print_server("%u,\n", method_count); @@ -403,13 +405,15 @@ static void write_stubdescriptor(type_t *iface, int expr_eval_routines)
static void write_serverinterfacedecl(type_t *iface) { - unsigned int ver = get_attrv(iface->attrs, ATTR_VERSION); struct uuid *uuid = get_attrp(iface->attrs, ATTR_UUID); const str_list_t *endpoints = get_attrp(iface->attrs, ATTR_ENDPOINT); + unsigned short major, minor; + + get_version( iface->attrs, &major, &minor );
if (endpoints) write_endpoints( server, iface->name, endpoints );
- print_server("static RPC_DISPATCH_TABLE %s_v%d_%d_DispatchTable;\n", iface->name, MAJORVERSION(ver), MINORVERSION(ver)); + print_server("static RPC_DISPATCH_TABLE %s_v%d_%d_DispatchTable;\n", iface->name, major, minor); print_server( "static const MIDL_SERVER_INFO %s_ServerInfo;\n", iface->name ); fprintf(server, "\n"); print_server("static const RPC_SERVER_INTERFACE %s___RpcServerInterface =\n", iface->name ); @@ -419,9 +423,9 @@ static void write_serverinterfacedecl(type_t *iface) print_server("{{0x%08x,0x%04x,0x%04x,{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x}},{%d,%d}},\n", uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0], uuid->Data4[1], uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5], uuid->Data4[6], - uuid->Data4[7], MAJORVERSION(ver), MINORVERSION(ver)); + uuid->Data4[7], major, minor); print_server("{{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},\n"); /* FIXME */ - print_server("&%s_v%d_%d_DispatchTable,\n", iface->name, MAJORVERSION(ver), MINORVERSION(ver)); + print_server("&%s_v%d_%d_DispatchTable,\n", iface->name, major, minor); if (endpoints) { print_server("%u,\n", list_count(endpoints)); @@ -442,7 +446,7 @@ static void write_serverinterfacedecl(type_t *iface) iface->name, iface->name); else print_server("RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec = (RPC_IF_HANDLE)& %s___RpcServerInterface;\n", - prefix_server, iface->name, MAJORVERSION(ver), MINORVERSION(ver), iface->name); + prefix_server, iface->name, major, minor, iface->name); fprintf(server, "\n"); }
diff --git a/tools/widl/utils.h b/tools/widl/utils.h index 2a6bc7d7930..ac469fe1fca 100644 --- a/tools/widl/utils.h +++ b/tools/widl/utils.h @@ -41,11 +41,4 @@ extern void add_output_to_resources( const char *type, const char *name ); extern void flush_output_resources( const char *name ); extern void put_pword( unsigned int val ); extern void put_str( int indent, const char *format, ... ) __attribute__((format (printf, 2, 3))); - -/* typelibs expect the minor version to be stored in the higher bits and - * major to be stored in the lower bits */ -#define MAKEVERSION(major, minor) ((((minor) & 0xffff) << 16) | ((major) & 0xffff)) -#define MAJORVERSION(version) ((version) & 0xffff) -#define MINORVERSION(version) (((version) >> 16) & 0xffff) - #endif diff --git a/tools/widl/widl.h b/tools/widl/widl.h index 08071e8fdf8..a6d3bc6bf33 100644 --- a/tools/widl/widl.h +++ b/tools/widl/widl.h @@ -105,6 +105,7 @@ extern int is_aliaschain_attr( const type_t *type, enum attr_type attr_type ); extern unsigned int get_attrv( const attr_list_t *list, enum attr_type attr_type ); extern void *get_attrp( const attr_list_t *list, enum attr_type attr_type ); extern void *get_aliaschain_attrp( const type_t *type, enum attr_type attr_type ); +extern void get_version( const attr_list_t *list, unsigned short *major, unsigned short *minor );
typedef int (*map_attrs_filter_t)( attr_list_t *, const attr_t * ); extern attr_list_t *append_attr( attr_list_t *list, attr_t *attr ); diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 1706f392670..6063aa7ef5e 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -55,6 +55,7 @@ typedef struct _user_type_t context_handle_t; typedef struct _user_type_t generic_handle_t; typedef struct _statement_t statement_t; typedef struct _warning_t warning_t; +typedef struct _version_t version_t;
typedef struct list attr_list_t; typedef struct list str_list_t; @@ -674,6 +675,11 @@ struct _statement_t { unsigned int is_defined : 1; };
+struct _version_t { + unsigned short major; + unsigned short minor; +}; + struct _warning_t { int num; struct list entry; diff --git a/tools/widl/write_msft.c b/tools/widl/write_msft.c index b0401d81238..6c63e2716b7 100644 --- a/tools/widl/write_msft.c +++ b/tools/widl/write_msft.c @@ -2006,9 +2006,13 @@ static msft_typeinfo_t *create_msft_typeinfo(msft_typelib_t *typelib, enum type_ break;
case ATTR_VERSION: - typeinfo->version = attr->u.ival; - break; + { + const version_t *version = attr->u.pval; + unsigned short major = version ? version->major : 0, minor = version ? version->minor : 0;
+ typeinfo->version = (minor << 16) | major; + break; + } default: break; } @@ -2507,7 +2511,10 @@ static void set_name(msft_typelib_t *typelib)
static void set_version(msft_typelib_t *typelib) { - typelib->typelib_header.version = get_attrv( typelib->typelib->attrs, ATTR_VERSION ); + unsigned short major, minor; + + get_version( typelib->typelib->attrs, &major, &minor ); + typelib->typelib_header.version = (minor << 16) | major; }
static void set_guid(msft_typelib_t *typelib) diff --git a/tools/widl/write_sltg.c b/tools/widl/write_sltg.c index b4ec340b11a..3c80e21d86b 100644 --- a/tools/widl/write_sltg.c +++ b/tools/widl/write_sltg.c @@ -320,8 +320,13 @@ static void init_library(struct sltg_typelib *sltg) switch (attr->type) { case ATTR_VERSION: - sltg->library.version = attr->u.ival; + { + const version_t *version = attr->u.pval; + unsigned short major = version ? version->major : 0, minor = version ? version->minor : 0; + + sltg->library.version = (minor << 16) | major; break; + } case ATTR_HELPSTRING: sltg->library.helpstring = attr->u.pval; break; @@ -522,12 +527,16 @@ static const char *add_typeinfo_block(struct sltg_typelib *typelib, const type_t static void init_typeinfo(struct sltg_typeinfo_header *ti, const type_t *type, short kind, const struct sltg_hrefmap *hrefmap) { + unsigned short major, minor; + + get_version( type->attrs, &major, &minor ); + ti->magic = 0x0501; ti->href_offset = -1; ti->res06 = -1; ti->member_offset = sizeof(*ti); ti->res0e = -1; - ti->version = get_attrv(type->attrs, ATTR_VERSION); + ti->version = minor << 16 | major; ti->res16 = 0xfffe0000; ti->misc.unknown1 = 0x02; ti->misc.flags = 0; /* FIXME */