From: Hans Leidekker hans@codeweavers.com
--- tools/widl/metadata.c | 281 +++++++++++++++++++++++------------------ tools/widl/widltypes.h | 22 +--- 2 files changed, 162 insertions(+), 141 deletions(-)
diff --git a/tools/widl/metadata.c b/tools/widl/metadata.c index de093022f66..15cd09bd494 100644 --- a/tools/widl/metadata.c +++ b/tools/widl/metadata.c @@ -1767,12 +1767,12 @@ static UINT make_deprecated_sig( UINT token, BYTE *buf ) return len; }
-static UINT make_contract_value( const type_t *type, BYTE *buf ) +static UINT make_contract_value( const attr_t *attr, BYTE *buf ) { - const expr_t *attr = get_attrp( type->attrs, ATTR_CONTRACT ); - const type_t *contract = attr->u.var->declspec.type; + const expr_t *expr = attr->u.pval; + const type_t *contract = expr->u.var->declspec.type; char *name = format_namespace( contract->namespace, "", ".", contract->name, NULL ); - UINT version = attr->ref->u.integer.value, len = strlen( name ); + UINT version = expr->ref->u.integer.value, len = strlen( name );
buf[0] = 1; buf[1] = 0; @@ -1788,12 +1788,12 @@ static UINT make_contract_value( const type_t *type, BYTE *buf ) return len; }
-static UINT make_version_value( const type_t *type, BYTE *buf ) +static UINT make_version_value( const attr_t *attr, BYTE *buf ) { - const version_t *version = get_attrp( type->attrs, ATTR_VERSION ); + const version_t *version; UINT value;
- if (version) value = (version->major << 16) | version->minor; + if (attr && (version = attr->u.pval)) value = (version->major << 16) | version->minor; else value = 1;
buf[0] = 1; @@ -1803,12 +1803,23 @@ static UINT make_version_value( const type_t *type, BYTE *buf ) return 8; }
-static void add_contract_attr_step1( type_t *type ) +static attr_t *get_attr( const attr_list_t *list, enum attr_type attr_type ) +{ + attr_t *attr; + if (list) LIST_FOR_EACH_ENTRY( attr, list, attr_t, entry ) + { + if (attr->type == attr_type ) return attr; + } + return NULL; +} + +static void add_contract_attr_step1( const type_t *type ) { UINT assemblyref, scope, typeref, typeref_type, class, sig_size; BYTE sig[32]; + attr_t *attr;
- if (!is_attr( type->attrs, ATTR_CONTRACT )) return; + if (!(attr = get_attr( type->attrs, ATTR_CONTRACT ))) return;
add_assemblyref_row( 0x200, 0, add_string("windowscontracts") ); assemblyref = add_assemblyref_row( 0x200, 0, add_string("Windows.Foundation") ); @@ -1821,72 +1832,77 @@ static void add_contract_attr_step1( type_t *type )
class = memberref_parent( TABLE_TYPEREF, typeref ); sig_size = make_member_sig( typedef_or_ref(TABLE_TYPEREF, typeref_type), sig ); - type->md.member[MD_ATTR_CONTRACT] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); }
-static void add_contract_attr_step2( type_t *type ) +static void add_contract_attr_step2( const type_t *type ) { UINT parent, attr_type, value_size; BYTE value[MAX_NAME + sizeof(UINT) + 5]; + const attr_t *attr;
- if (!is_attr( type->attrs, ATTR_CONTRACT )) return; + if (!(attr = get_attr( type->attrs, ATTR_CONTRACT ))) return;
parent = has_customattribute( TABLE_TYPEDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_CONTRACT] ); - value_size = make_contract_value( type, value ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); + value_size = make_contract_value( attr, value ); add_customattribute_row( parent, attr_type, add_blob(value, value_size) ); }
-static void add_version_attr_step1( type_t *type ) +static void add_version_attr_step1( const type_t *type ) { static const BYTE sig[] = { SIG_TYPE_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_U4 }; UINT assemblyref, scope, typeref, class; + attr_t *attr;
- if (!is_attr( type->attrs, ATTR_VERSION ) && is_attr( type->attrs, ATTR_CONTRACT )) return; + if (!(attr = get_attr( type->attrs, ATTR_VERSION )) && is_attr( type->attrs, ATTR_CONTRACT )) return;
assemblyref = add_assemblyref_row( 0x200, 0, add_string("Windows.Foundation") ); scope = resolution_scope( TABLE_ASSEMBLYREF, assemblyref );
typeref = add_typeref_row( scope, add_string("VersionAttribute"), add_string("Windows.Foundation.Metadata") ); class = memberref_parent( TABLE_TYPEREF, typeref ); - type->md.member[MD_ATTR_VERSION] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); }
-static void add_version_attr_step2( type_t *type ) +static void add_version_attr_step2( const type_t *type ) { UINT parent, attr_type, value_size; BYTE value[8]; + const attr_t *attr;
- if (!is_attr( type->attrs, ATTR_VERSION ) && is_attr( type->attrs, ATTR_CONTRACT )) return; + if (!(attr = get_attr( type->attrs, ATTR_VERSION )) && is_attr( type->attrs, ATTR_CONTRACT )) return;
parent = has_customattribute( TABLE_TYPEDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_VERSION] ); - value_size = make_version_value( type, value ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); + value_size = make_version_value( attr, value ); add_customattribute_row( parent, attr_type, add_blob(value, value_size) ); }
-static void add_flags_attr_step1( type_t *type ) +static void add_flags_attr_step1( const type_t *type ) { static const BYTE sig[] = { SIG_TYPE_HASTHIS, 0, ELEMENT_TYPE_VOID }; UINT scope, typeref, class; + attr_t *attr;
- if (!is_attr( type->attrs, ATTR_FLAGS )) return; + if (!(attr = get_attr( type->attrs, ATTR_FLAGS ))) return;
scope = resolution_scope( TABLE_ASSEMBLYREF, MSCORLIB_ROW ); typeref = add_typeref_row( scope, add_string("FlagsAttribute"), add_string("System") ); class = memberref_parent( TABLE_TYPEREF, typeref ); - type->md.member[MD_ATTR_FLAGS] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); }
-static void add_flags_attr_step2( type_t *type ) +static void add_flags_attr_step2( const type_t *type ) { static const BYTE value[] = { 0x01, 0x00, 0x00, 0x00 }; UINT parent, attr_type; + const attr_t *attr;
- if (!is_attr( type->attrs, ATTR_FLAGS )) return; + if (!(attr = get_attr( type->attrs, ATTR_FLAGS ))) return;
parent = has_customattribute( TABLE_TYPEDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_FLAGS] ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); add_customattribute_row( parent, attr_type, add_blob(value, sizeof(value)) ); }
@@ -1983,42 +1999,46 @@ static void add_struct_type_step2( type_t *type ) add_contract_attr_step2( type ); }
-static void add_uuid_attr_step1( type_t *type ) +static void add_uuid_attr_step1( const type_t *type ) { static const BYTE sig[] = { SIG_TYPE_HASTHIS, 11, ELEMENT_TYPE_VOID, ELEMENT_TYPE_U4, ELEMENT_TYPE_U2, ELEMENT_TYPE_U2, ELEMENT_TYPE_U1, ELEMENT_TYPE_U1, ELEMENT_TYPE_U1, ELEMENT_TYPE_U1, ELEMENT_TYPE_U1, ELEMENT_TYPE_U1, ELEMENT_TYPE_U1, ELEMENT_TYPE_U1 }; UINT assemblyref, scope, typeref, class; + attr_t *attr; + + if (!(attr = get_attr( type->attrs, ATTR_UUID ))) return;
assemblyref = add_assemblyref_row( 0x200, 0, add_string("Windows.Foundation") ); scope = resolution_scope( TABLE_ASSEMBLYREF, assemblyref ); typeref = add_typeref_row( scope, add_string("GuidAttribute"), add_string("Windows.Foundation.Metadata") );
class = memberref_parent( TABLE_TYPEREF, typeref ); - type->md.member[MD_ATTR_UUID] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); }
-static void add_uuid_attr_step2( type_t *type ) +static void add_uuid_attr_step2( const type_t *type ) { - static const BYTE default_uuid[] = - { 0xe7, 0x1f, 0xb5, 0x67, 0x6e, 0x38, 0x31, 0x5a, 0x8a, 0x1c, 0x89, 0x83, 0xc9, 0x49, 0x5c, 0x33 }; - const struct uuid *uuid = get_attrp( type->attrs, ATTR_UUID ); + const struct uuid *uuid; BYTE value[sizeof(*uuid) + 4] = { 0x01 }; UINT parent, attr_type; + const attr_t *attr; + + if (!(attr = get_attr( type->attrs, ATTR_UUID ))) return;
- if (uuid) memcpy( value + 2, uuid, sizeof(*uuid) ); - else memcpy( value + 2, default_uuid, sizeof(default_uuid) ); + uuid = attr->u.pval; + memcpy( value + 2, uuid, sizeof(*uuid) );
parent = has_customattribute( TABLE_TYPEDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_UUID] ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); add_customattribute_row( parent, attr_type, add_blob(value, sizeof(value)) ); }
-static UINT make_exclusiveto_value( const type_t *type, BYTE *buf ) +static UINT make_exclusiveto_value( const attr_t *attr, BYTE *buf ) { - const type_t *attr = get_attrp( type->attrs, ATTR_EXCLUSIVETO ); - char *name = format_namespace( attr->namespace, "", ".", attr->name, NULL ); + const type_t *type = attr->u.pval; + char *name = format_namespace( type->namespace, "", ".", type->name, NULL ); UINT len = strlen( name );
buf[0] = 1; @@ -2033,12 +2053,13 @@ static UINT make_exclusiveto_value( const type_t *type, BYTE *buf ) return len; }
-static void add_exclusiveto_attr_step1( type_t *type ) +static void add_exclusiveto_attr_step1( const type_t *type ) { UINT assemblyref, scope, typeref, typeref_type, class, sig_size; BYTE sig[32]; + attr_t *attr;
- if (!is_attr( type->attrs, ATTR_EXCLUSIVETO )) return; + if (!(attr = get_attr( type->attrs, ATTR_EXCLUSIVETO ))) return;
scope = resolution_scope( TABLE_ASSEMBLYREF, MSCORLIB_ROW ); typeref_type = add_typeref_row( scope, add_string("Type"), add_string("System") ); @@ -2049,30 +2070,31 @@ static void add_exclusiveto_attr_step1( type_t *type )
class = memberref_parent( TABLE_TYPEREF, typeref ); sig_size = make_member_sig2( ELEMENT_TYPE_CLASS, typedef_or_ref(TABLE_TYPEREF, typeref_type), sig ); - type->md.member[MD_ATTR_EXCLUSIVETO] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); }
-static void add_exclusiveto_attr_step2( type_t *type ) +static void add_exclusiveto_attr_step2( const type_t *type ) { UINT parent, attr_type, value_size; BYTE value[MAX_NAME + 5]; + const attr_t *attr;
- if (!is_attr( type->attrs, ATTR_EXCLUSIVETO )) return; + if (!(attr = get_attr( type->attrs, ATTR_EXCLUSIVETO ))) return;
parent = has_customattribute( TABLE_TYPEDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_EXCLUSIVETO] ); - value_size = make_exclusiveto_value( type, value ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); + value_size = make_exclusiveto_value( attr, value ); add_customattribute_row( parent, attr_type, add_blob(value, value_size) ); }
-static UINT make_overload_value( const var_t *method, BYTE *buf ) +static UINT make_overload_value( const char *name, BYTE *buf ) { - UINT len = strlen( method->name ); + UINT len = strlen( name );
buf[0] = 1; buf[1] = 0; buf[2] = len; - memcpy( buf + 3, method->name, len ); + memcpy( buf + 3, name, len ); len += 3; buf[len++] = 0; buf[len++] = 0; @@ -2084,16 +2106,16 @@ static void add_overload_attr_step1( const var_t *method ) { static const BYTE sig[] = { SIG_TYPE_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_STRING }; UINT assemblyref, scope, typeref, class; - type_t *type = method->declspec.type; + attr_t *attr;
- if (!is_attr( method->attrs, ATTR_OVERLOAD )) return; + if (!(attr = get_attr( method->attrs, ATTR_OVERLOAD ))) return;
assemblyref = add_assemblyref_row( 0x200, 0, add_string("Windows.Foundation") ); scope = resolution_scope( TABLE_ASSEMBLYREF, assemblyref ); typeref = add_typeref_row( scope, add_string("OverloadAttribute"), add_string("Windows.Foundation.Metadata") );
class = memberref_parent( TABLE_TYPEREF, typeref ); - type->md.member[MD_ATTR_OVERLOAD] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); }
static void add_overload_attr_step2( const var_t *method ) @@ -2101,12 +2123,13 @@ static void add_overload_attr_step2( const var_t *method ) const type_t *type = method->declspec.type; UINT parent, attr_type, value_size; BYTE value[MAX_NAME + 5]; + const attr_t *attr;
- if (!is_attr( method->attrs, ATTR_OVERLOAD )) return; + if (!(attr = get_attr( method->attrs, ATTR_OVERLOAD ))) return;
parent = has_customattribute( TABLE_METHODDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_OVERLOAD] ); - value_size = make_overload_value( method, value ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); + value_size = make_overload_value( method->name, value ); add_customattribute_row( parent, attr_type, add_blob(value, value_size) ); }
@@ -2114,16 +2137,16 @@ static void add_default_overload_attr_step1( const var_t *method ) { static const BYTE sig[] = { SIG_TYPE_HASTHIS, 0, ELEMENT_TYPE_VOID }; UINT assemblyref, scope, typeref, class; - type_t *type = method->declspec.type; + attr_t *attr;
- if (!is_attr( method->attrs, ATTR_DEFAULT_OVERLOAD ) || !is_attr( method->attrs, ATTR_OVERLOAD )) return; + if (!(attr = get_attr( method->attrs, ATTR_DEFAULT_OVERLOAD )) || !is_attr( method->attrs, ATTR_OVERLOAD )) return;
assemblyref = add_assemblyref_row( 0x200, 0, add_string("Windows.Foundation") ); scope = resolution_scope( TABLE_ASSEMBLYREF, assemblyref ); typeref = add_typeref_row( scope, add_string("DefaultOverloadAttribute"), add_string("Windows.Foundation.Metadata") );
class = memberref_parent( TABLE_TYPEREF, typeref ); - type->md.member[MD_ATTR_DEFAULT_OVERLOAD] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); }
static void add_default_overload_attr_step2( const var_t *method ) @@ -2131,21 +2154,22 @@ static void add_default_overload_attr_step2( const var_t *method ) static const BYTE value[] = { 0x01, 0x00, 0x00, 0x00 }; const type_t *type = method->declspec.type; UINT parent, attr_type; + const attr_t *attr;
- if (!is_attr( method->attrs, ATTR_DEFAULT_OVERLOAD ) || !is_attr( method->attrs, ATTR_OVERLOAD )) return; + if (!(attr = get_attr( method->attrs, ATTR_DEFAULT_OVERLOAD )) || !is_attr( method->attrs, ATTR_OVERLOAD )) return;
parent = has_customattribute( TABLE_METHODDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_DEFAULT_OVERLOAD] ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); add_customattribute_row( parent, attr_type, add_blob(value, sizeof(value)) ); }
-static UINT make_deprecated_value( const var_t *method, BYTE **ret_buf ) +static UINT make_deprecated_value( const attr_t *attr, BYTE **ret_buf ) { static const BYTE zero[] = { 0x00, 0x00, 0x00, 0x00 }, one[] = { 0x01, 0x00, 0x00, 0x00 }; - const expr_t *attr = get_attrp( method->attrs, ATTR_DEPRECATED ); - const type_t *type = attr->ext2->u.var->declspec.type; - const char *text = attr->ref->u.sval; - const char *kind = attr->u.ext->u.sval; + const expr_t *expr = attr->u.pval; + const type_t *type = expr->ext2->u.var->declspec.type; + const char *text = expr->ref->u.sval; + const char *kind = expr->u.ext->u.sval; BYTE encoded[4]; UINT len, len_text = strlen( text ), len_encoded = encode_int( len_text, encoded ); BYTE *buf = xmalloc( 2 + len_encoded + len_text + 6 + MAX_NAME + 5 ); @@ -2181,10 +2205,10 @@ static UINT make_deprecated_value( const var_t *method, BYTE **ret_buf ) static void add_deprecated_attr_step1( const var_t *method ) { UINT assemblyref, scope, typeref_type, typeref, class, sig_size; - type_t *type = method->declspec.type; BYTE sig[32]; + attr_t *attr;
- if (!is_attr( method->attrs, ATTR_DEPRECATED )) return; + if (!(attr = get_attr( method->attrs, ATTR_DEPRECATED ))) return;
assemblyref = add_assemblyref_row( 0x200, 0, add_string("Windows.Foundation") ); scope = resolution_scope( TABLE_ASSEMBLYREF, assemblyref ); @@ -2193,7 +2217,7 @@ static void add_deprecated_attr_step1( const var_t *method )
sig_size = make_deprecated_sig( typedef_or_ref(TABLE_TYPEREF, typeref_type), sig ); class = memberref_parent( TABLE_TYPEREF, typeref ); - type->md.member[MD_ATTR_DEPRECATED] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); }
static void add_deprecated_attr_step2( const var_t *method ) @@ -2201,12 +2225,13 @@ static void add_deprecated_attr_step2( const var_t *method ) const type_t *type = method->declspec.type; UINT parent, attr_type, value_size; BYTE *value; + const attr_t *attr;
- if (!is_attr( method->attrs, ATTR_DEPRECATED )) return; + if (!(attr = get_attr( method->attrs, ATTR_DEPRECATED ))) return;
parent = has_customattribute( TABLE_METHODDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_DEPRECATED] ); - value_size = make_deprecated_value( method, &value ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); + value_size = make_deprecated_value( attr, &value ); add_customattribute_row( parent, attr_type, add_blob(value, value_size) ); free( value ); } @@ -2593,9 +2618,9 @@ static void add_interface_type_step2( type_t *type ) add_exclusiveto_attr_step2( type ); }
-static UINT make_contractversion_value( const type_t *type, BYTE *buf ) +static UINT make_contractversion_value( const attr_t *attr, BYTE *buf ) { - UINT version = get_attrv( type->attrs, ATTR_CONTRACTVERSION ), len = 2 + sizeof(version); + UINT version = attr ? attr->u.ival : 0, len = 2 + sizeof(version);
buf[0] = 1; buf[1] = 0; @@ -2605,54 +2630,62 @@ static UINT make_contractversion_value( const type_t *type, BYTE *buf ) return len; }
-static void add_contractversion_attr_step1( type_t *type ) +static void add_contractversion_attr_step1( const type_t *type ) { static const BYTE sig[] = { SIG_TYPE_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_U4 }; UINT assemblyref, scope, typeref, class; + attr_t *attr;
- if (!is_attr( type->attrs, ATTR_CONTRACTVERSION )) return; + if (!(attr = get_attr( type->attrs, ATTR_CONTRACTVERSION ))) return;
assemblyref = add_assemblyref_row( 0x200, 0, add_string("Windows.Foundation") ); scope = resolution_scope( TABLE_ASSEMBLYREF, assemblyref ); typeref = add_typeref_row( scope, add_string("ContractVersionAttribute"), add_string("Windows.Foundation.Metadata") );
class = memberref_parent( TABLE_TYPEREF, typeref ); - type->md.member[MD_ATTR_CONTRACTVERSION] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); }
-static void add_contractversion_attr_step2( type_t *type ) +static void add_contractversion_attr_step2( const type_t *type ) { UINT parent, attr_type, value_size; BYTE value[8]; + const attr_t *attr;
- if (!is_attr( type->attrs, ATTR_CONTRACTVERSION )) return; + if (!(attr = get_attr( type->attrs, ATTR_CONTRACTVERSION ))) return;
parent = has_customattribute( TABLE_TYPEDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_CONTRACTVERSION] ); - value_size = make_contractversion_value( type, value ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); + value_size = make_contractversion_value( attr, value ); add_customattribute_row( parent, attr_type, add_blob(value, value_size) ); }
-static void add_apicontract_attr_step1( type_t *type ) +static void add_apicontract_attr_step1( const type_t *type ) { static const BYTE sig[] = { SIG_TYPE_HASTHIS, 0, ELEMENT_TYPE_VOID }; UINT assemblyref, scope, typeref, class; + attr_t *attr; + + if (!(attr = get_attr( type->attrs, ATTR_APICONTRACT ))) return;
assemblyref = add_assemblyref_row( 0x200, 0, add_string("Windows.Foundation") ); scope = resolution_scope( TABLE_ASSEMBLYREF, assemblyref ); typeref = add_typeref_row( scope, add_string("ApiContractAttribute"), add_string("Windows.Foundation.Metadata") );
class = memberref_parent( TABLE_TYPEREF, typeref ); - type->md.member[MD_ATTR_APICONTRACT] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sizeof(sig)) ); }
-static void add_apicontract_attr_step2( type_t *type ) +static void add_apicontract_attr_step2( const type_t *type ) { static const BYTE value[] = { 0x01, 0x00, 0x00, 0x00 }; UINT parent, attr_type; + const attr_t *attr; + + if (!(attr = get_attr( type->attrs, ATTR_APICONTRACT ))) return;
parent = has_customattribute( TABLE_TYPEDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_APICONTRACT] ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); add_customattribute_row( parent, attr_type, add_blob(value, sizeof(value)) ); }
@@ -2693,7 +2726,7 @@ static void add_runtimeclass_type_step1( type_t *type ) type->md.ref = add_typeref_row( resolution_scope(TABLE_MODULE, MODULE_ROW), name, namespace ); }
-static void add_default_attr( const type_t *type, UINT interfaceimpl_ref ) +static void add_default_attr( UINT interfaceimpl_ref ) { static const BYTE sig[] = { SIG_TYPE_HASTHIS, 0, ELEMENT_TYPE_VOID }; static const BYTE value[] = { 0x01, 0x00, 0x00, 0x00 }; @@ -2733,10 +2766,11 @@ static void add_method_contract_attrs( const type_t *class, const type_t *iface, { UINT parent, attr_type, value_size; BYTE value[MAX_NAME + sizeof(UINT) + 5]; + const attr_t *attr = get_attr( iface->attrs, ATTR_CONTRACT );
parent = has_customattribute( TABLE_METHODDEF, method->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, iface->md.member[MD_ATTR_CONTRACT] ); - value_size = make_contract_value( class, value ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); + value_size = make_contract_value( get_attr(class->attrs, ATTR_CONTRACT), value ); add_customattribute_row( parent, attr_type, add_blob(value, value_size) );
if (method->md.class_property) @@ -2781,12 +2815,13 @@ static UINT make_static_value( const expr_t *attr, BYTE *buf ) return len_iface + len_contract + 10; }
-static void add_static_attr_step1( type_t *type ) +static void add_static_attr_step1( const type_t *type ) { UINT assemblyref, scope, typeref, typeref_type, class, sig_size; BYTE sig[32]; + attr_t *attr;
- if (!is_attr( type->attrs, ATTR_STATIC )) return; + if (!(attr = get_attr( type->attrs, ATTR_STATIC ))) return;
assemblyref = add_assemblyref_row( 0x200, 0, add_string("Windows.Foundation") ); scope = resolution_scope( TABLE_ASSEMBLYREF, assemblyref ); @@ -2797,10 +2832,10 @@ static void add_static_attr_step1( type_t *type )
class = memberref_parent( TABLE_TYPEREF, typeref ); sig_size = make_member_sig3( typedef_or_ref(TABLE_TYPEREF, typeref_type), sig ); - type->md.member[MD_ATTR_STATIC] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); }
-static void add_static_attr_step2( type_t *type ) +static void add_static_attr_step2( const type_t *type ) { const attr_t *attr;
@@ -2812,7 +2847,7 @@ static void add_static_attr_step2( type_t *type ) if (attr->type != ATTR_STATIC) continue;
parent = has_customattribute( TABLE_TYPEDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_STATIC] ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); value_size = make_static_value( attr->u.pval, value ); add_customattribute_row( parent, attr_type, add_blob(value, value_size) ); } @@ -2870,7 +2905,7 @@ static UINT make_activatable_value( const expr_t *attr, BYTE *buf ) return len_iface + sizeof(version) + len_contract + len_extra; }
-static void add_activatable_attr_step1( type_t *type ) +static void add_activatable_attr_step1( const type_t *type ) { static const BYTE sig_default[] = { SIG_TYPE_HASTHIS, 2, ELEMENT_TYPE_VOID, ELEMENT_TYPE_U4, ELEMENT_TYPE_STRING }; attr_t *attr; @@ -2904,7 +2939,7 @@ static void add_activatable_attr_step1( type_t *type ) } }
-static void add_activatable_attr_step2( type_t *type ) +static void add_activatable_attr_step2( const type_t *type ) { const attr_t *attr;
@@ -2922,9 +2957,9 @@ static void add_activatable_attr_step2( type_t *type ) } }
-static UINT make_threading_value( const type_t *type, BYTE *buf ) +static UINT make_threading_value( const attr_t *attr, BYTE *buf ) { - UINT value, model = get_attrv( type->attrs, ATTR_THREADING ); + UINT value, model = attr->u.ival;
switch (model) { @@ -2949,12 +2984,13 @@ static UINT make_threading_value( const type_t *type, BYTE *buf ) return 8; }
-static void add_threading_attr_step1( type_t *type ) +static void add_threading_attr_step1( const type_t *type ) { UINT assemblyref, scope, typeref, typeref_attr, class, sig_size; BYTE sig[32]; + attr_t *attr;
- if (!is_attr( type->attrs, ATTR_THREADING )) return; + if (!(attr = get_attr( type->attrs, ATTR_THREADING ))) return;
assemblyref = add_assemblyref_row( 0x200, 0, add_string("Windows.Foundation") ); scope = resolution_scope( TABLE_ASSEMBLYREF, assemblyref ); @@ -2965,25 +3001,26 @@ static void add_threading_attr_step1( type_t *type )
class = memberref_parent( TABLE_TYPEREF, typeref_attr ); sig_size = make_member_sig2( ELEMENT_TYPE_VALUETYPE, typedef_or_ref(TABLE_TYPEREF, typeref), sig ); - type->md.member[MD_ATTR_THREADING] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); }
-static void add_threading_attr_step2( type_t *type ) +static void add_threading_attr_step2( const type_t *type ) { UINT parent, attr_type, value_size; BYTE value[8]; + const attr_t *attr;
- if (!is_attr( type->attrs, ATTR_THREADING )) return; + if (!(attr = get_attr( type->attrs, ATTR_THREADING ))) return;
parent = has_customattribute( TABLE_TYPEDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_THREADING] ); - value_size = make_threading_value( type, value ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); + value_size = make_threading_value( attr, value ); add_customattribute_row( parent, attr_type, add_blob(value, value_size) ); }
-static UINT make_marshalingbehavior_value( const type_t *type, BYTE *buf ) +static UINT make_marshalingbehavior_value( const attr_t *attr, BYTE *buf ) { - UINT marshaling = get_attrv( type->attrs, ATTR_MARSHALING_BEHAVIOR ); + UINT marshaling = attr->u.ival;
buf[0] = 1; buf[1] = 0; @@ -2992,12 +3029,13 @@ static UINT make_marshalingbehavior_value( const type_t *type, BYTE *buf ) return 8; }
-static void add_marshalingbehavior_attr_step1( type_t *type ) +static void add_marshalingbehavior_attr_step1( const type_t *type ) { UINT assemblyref, scope, typeref, typeref_attr, class, sig_size; BYTE sig[32]; + attr_t *attr;
- if (!is_attr( type->attrs, ATTR_MARSHALING_BEHAVIOR )) return; + if (!(attr = get_attr( type->attrs, ATTR_MARSHALING_BEHAVIOR ))) return;
assemblyref = add_assemblyref_row( 0x200, 0, add_string("Windows.Foundation") ); scope = resolution_scope( TABLE_ASSEMBLYREF, assemblyref ); @@ -3008,19 +3046,20 @@ static void add_marshalingbehavior_attr_step1( type_t *type )
class = memberref_parent( TABLE_TYPEREF, typeref_attr ); sig_size = make_member_sig2( ELEMENT_TYPE_VALUETYPE, typedef_or_ref(TABLE_TYPEREF, typeref), sig ); - type->md.member[MD_ATTR_MARSHALINGBEHAVIOR] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); + attr->md_member = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); }
-static void add_marshalingbehavior_attr_step2( type_t *type ) +static void add_marshalingbehavior_attr_step2( const type_t *type ) { UINT parent, attr_type, value_size; BYTE value[8]; + const attr_t *attr;
- if (!is_attr( type->attrs, ATTR_MARSHALING_BEHAVIOR )) return; + if (!(attr = get_attr( type->attrs, ATTR_MARSHALING_BEHAVIOR ))) return;
parent = has_customattribute( TABLE_TYPEDEF, type->md.def ); - attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_MARSHALINGBEHAVIOR] ); - value_size = make_marshalingbehavior_value( type, value ); + attr_type = customattribute_type( TABLE_MEMBERREF, attr->md_member ); + value_size = make_marshalingbehavior_value( attr, value ); add_customattribute_row( parent, attr_type, add_blob(value, value_size) ); }
@@ -3063,7 +3102,7 @@ static UINT make_composable_value( const expr_t *attr, BYTE *buf ) return len_iface + sizeof(access_type) + sizeof(contract_version) + len_contract + 6; }
-static void add_composable_attr_step1( type_t *type ) +static void add_composable_attr_step1( const type_t *type ) { attr_t *attr;
@@ -3088,7 +3127,7 @@ static void add_composable_attr_step1( type_t *type ) } }
-static void add_composable_attr_step2( type_t *type ) +static void add_composable_attr_step2( const type_t *type ) { const attr_t *attr;
@@ -3117,7 +3156,7 @@ static void add_member_interfaces( type_t *class ) UINT interfaceimpl_ref = add_interfaceimpl_row( class->md.def, interface ); const statement_t *stmt;
- if (is_attr( iface->attrs, ATTR_DEFAULT )) add_default_attr( class, interfaceimpl_ref ); + if (is_attr( iface->attrs, ATTR_DEFAULT )) add_default_attr( interfaceimpl_ref );
/* add properties in reverse order like midlrt */ STATEMENTS_FOR_EACH_FUNC_REV( stmt, type_iface_get_stmts(iface->type) ) @@ -3168,7 +3207,7 @@ static void add_static_interfaces( type_t *class ) static void add_activation_interfaces( const type_t *class ) { UINT flags = METHOD_ATTR_PUBLIC | METHOD_ATTR_HIDEBYSIG | METHOD_ATTR_SPECIALNAME | METHOD_ATTR_RTSPECIALNAME; - const attr_t *attr; + const attr_t *attr, *contract_attr = get_attr( class->attrs, ATTR_CONTRACT );
if (class->attrs) LIST_FOR_EACH_ENTRY_REV( attr, class->attrs, const attr_t, entry ) { @@ -3203,8 +3242,8 @@ static void add_activation_interfaces( const type_t *class ) methoddef = add_methoddef_row( METHOD_IMPL_RUNTIME, flags, add_string(".ctor"), add_blob(sig, sig_size), paramlist );
parent = has_customattribute( TABLE_METHODDEF, methoddef ); - attr_type = customattribute_type( TABLE_MEMBERREF, class->md.member[MD_ATTR_CONTRACT] ); - value_size = make_contract_value( class, value ); + attr_type = customattribute_type( TABLE_MEMBERREF, contract_attr->md_member ); + value_size = make_contract_value( contract_attr, value ); add_customattribute_row( parent, attr_type, add_blob(value, value_size) ); } } @@ -3212,7 +3251,7 @@ static void add_activation_interfaces( const type_t *class ) static void add_composition_interfaces( const type_t *class ) { UINT flags = METHOD_ATTR_FAMILY | METHOD_ATTR_HIDEBYSIG | METHOD_ATTR_SPECIALNAME | METHOD_ATTR_RTSPECIALNAME; - const attr_t *attr; + const attr_t *attr, *contract_attr = get_attr( class->attrs, ATTR_CONTRACT );
if (class->attrs) LIST_FOR_EACH_ENTRY_REV( attr, class->attrs, const attr_t, entry ) { @@ -3248,8 +3287,8 @@ static void add_composition_interfaces( const type_t *class ) methoddef = add_methoddef_row( METHOD_IMPL_RUNTIME, flags, add_string(".ctor"), add_blob(sig, sig_size), paramlist );
parent = has_customattribute( TABLE_METHODDEF, methoddef ); - attr_type = customattribute_type( TABLE_MEMBERREF, class->md.member[MD_ATTR_CONTRACT] ); - value_size = make_contract_value( class, value ); + attr_type = customattribute_type( TABLE_MEMBERREF, contract_attr->md_member ); + value_size = make_contract_value( contract_attr, value ); add_customattribute_row( parent, attr_type, add_blob(value, value_size) ); } } diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 36d7a179b06..558699bb2a6 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -345,10 +345,11 @@ struct _attr_t { unsigned int ival; void *pval; } u; + /* metadata */ + unsigned int md_member; /* parser-internal */ struct list entry; struct location where; - unsigned int md_member; };
struct integer @@ -500,30 +501,11 @@ enum type_type TYPE_DELEGATE, };
-enum -{ - MD_ATTR_CONTRACT, - MD_ATTR_FLAGS, - MD_ATTR_APICONTRACT, - MD_ATTR_CONTRACTVERSION, - MD_ATTR_VERSION, - MD_ATTR_UUID, - MD_ATTR_EXCLUSIVETO, - MD_ATTR_STATIC, - MD_ATTR_THREADING, - MD_ATTR_MARSHALINGBEHAVIOR, - MD_ATTR_OVERLOAD, - MD_ATTR_DEFAULT_OVERLOAD, - MD_ATTR_DEPRECATED, - MD_ATTR_MAX, -}; - struct metadata { unsigned int ref; unsigned int def; unsigned int extends; - unsigned int member[MD_ATTR_MAX]; /* get/put methods */ unsigned int class_property; unsigned int iface_property;