Declaration type names prefer unqualified names whereas reference type names prefer fully qualified names.
This makes C++ code use fully qualified names when referencing a type, fixing cases where types from other namespaces are used. It also allows to skip the enum / struct / union type prefix in WinRT C++ code.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com ---
This does the following kind of changes to the headers:
diff --git a/windows.gaming.input.h b/windows.gaming.input.h index fee55a0..ed51840 100644 --- a/windows.gaming.input.h +++ b/windows.gaming.input.h @@ -846,13 +846,13 @@ namespace ABI { EventRegistrationToken token) = 0;
virtual HRESULT STDMETHODCALLTYPE get_Headset(
IHeadset **value) = 0;
ABI::Windows::Gaming::Input::IHeadset **value) = 0; virtual HRESULT STDMETHODCALLTYPE get_IsWireless( boolean *value) = 0; virtual HRESULT STDMETHODCALLTYPE get_User(
IUser **value) = 0;
ABI::Windows::System::IUser **value) = 0; }; }
tools/widl/header.c | 29 ++++++++++++++++++----------- tools/widl/typetree.c | 8 ++++---- tools/widl/typetree.h | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/tools/widl/header.c b/tools/widl/header.c index 4a59cb9162a..637d39953f0 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -339,11 +339,12 @@ static void write_pointer_left(FILE *h, type_t *ref) void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, int declonly, int write_callconv) { type_t *t = ds->type; - const char *name; + const char *decl_name, *name; char *args;
if (!h) return;
+ decl_name = type_get_decl_name(t, name_type); name = type_get_name(t, name_type);
if (ds->func_specifier & FUNCTION_SPECIFIER_INLINE) @@ -356,9 +357,10 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i else { switch (type_get_type_detect_alias(t)) { case TYPE_ENUM: - if (!declonly && !t->written) { + if (declonly) fprintf(h, "enum %s", decl_name ? decl_name : ""); + else if (!t->written) { assert(t->defined); - if (name) fprintf(h, "enum %s {\n", name); + if (decl_name) fprintf(h, "enum %s {\n", decl_name); else fprintf(h, "enum {\n"); t->written = TRUE; indentation++; @@ -366,13 +368,15 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i indent(h, -1); fprintf(h, "}"); } + else if (winrt_mode && name_type == NAME_DEFAULT && name) fprintf(h, "%s", name); else fprintf(h, "enum %s", name ? name : ""); break; case TYPE_STRUCT: case TYPE_ENCAPSULATED_UNION: - if (!declonly && !t->written) { + if (declonly) fprintf(h, "struct %s", decl_name ? decl_name : ""); + else if (!t->written) { assert(t->defined); - if (name) fprintf(h, "struct %s {\n", name); + if (decl_name) fprintf(h, "struct %s {\n", decl_name); else fprintf(h, "struct {\n"); t->written = TRUE; indentation++; @@ -383,12 +387,14 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i indent(h, -1); fprintf(h, "}"); } + else if (winrt_mode && name_type == NAME_DEFAULT && name) fprintf(h, "%s", name); else fprintf(h, "struct %s", name ? name : ""); break; case TYPE_UNION: - if (!declonly && !t->written) { + if (declonly) fprintf(h, "union %s", decl_name ? decl_name : ""); + else if (!t->written) { assert(t->defined); - if (t->name) fprintf(h, "union %s {\n", t->name); + if (decl_name) fprintf(h, "union %s {\n", decl_name); else fprintf(h, "union {\n"); t->written = TRUE; indentation++; @@ -396,7 +402,8 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i indent(h, -1); fprintf(h, "}"); } - else fprintf(h, "union %s", t->name ? t->name : ""); + else if (winrt_mode && name_type == NAME_DEFAULT && name) fprintf(h, "%s", name); + else fprintf(h, "union %s", name ? name : ""); break; case TYPE_POINTER: { @@ -482,13 +489,13 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i case TYPE_INTERFACE: case TYPE_MODULE: case TYPE_COCLASS: - fprintf(h, "%s", type_get_qualified_name(t, name_type)); + fprintf(h, "%s", type_get_name(t, name_type)); break; case TYPE_RUNTIMECLASS: fprintf(h, "%s", type_get_name(type_runtimeclass_get_default_iface(t, TRUE), name_type)); break; case TYPE_DELEGATE: - fprintf(h, "%s", type_get_qualified_name(type_delegate_get_iface(t), name_type)); + fprintf(h, "%s", type_get_name(type_delegate_get_iface(t), name_type)); break; case TYPE_VOID: fprintf(h, "void"); @@ -882,7 +889,7 @@ static void write_typedef(FILE *header, type_t *type, int declonly) write_namespace_start(header, t->namespace); indent(header, 0); fprintf(header, "typedef "); - write_type_v(header, type_alias_get_aliasee(type), FALSE, declonly, type->name, NAME_DEFAULT); + write_type_v(header, type_alias_get_aliasee(type), FALSE, TRUE, type->name, NAME_DEFAULT); fprintf(header, ";\n"); write_namespace_end(header, t->namespace); } diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c index 33735d26f58..765ed483d47 100644 --- a/tools/widl/typetree.c +++ b/tools/widl/typetree.c @@ -81,7 +81,7 @@ static const var_t *find_arg(const var_list_t *args, const char *name) return NULL; }
-const char *type_get_name(const type_t *type, enum name_type name_type) +const char *type_get_decl_name(const type_t *type, enum name_type name_type) { switch(name_type) { case NAME_DEFAULT: @@ -94,13 +94,13 @@ const char *type_get_name(const type_t *type, enum name_type name_type) return NULL; }
-const char *type_get_qualified_name(const type_t *type, enum name_type name_type) +const char *type_get_name(const type_t *type, enum name_type name_type) { switch(name_type) { case NAME_DEFAULT: - return type->qualified_name; + return type->qualified_name ? type->qualified_name : type->name; case NAME_C: - return type->c_name; + return type->c_name ? type->c_name : type->name; }
assert(0); diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h index db723817266..8f5e1ebdac5 100644 --- a/tools/widl/typetree.h +++ b/tools/widl/typetree.h @@ -77,8 +77,8 @@ type_t *type_parameterized_type_specialize_partial(type_t *type, typeref_list_t type_t *type_parameterized_type_specialize_declare(type_t *type, typeref_list_t *params); type_t *type_parameterized_type_specialize_define(type_t *type); int type_is_equal(const type_t *type1, const type_t *type2); +const char *type_get_decl_name(const type_t *type, enum name_type name_type); const char *type_get_name(const type_t *type, enum name_type name_type); -const char *type_get_qualified_name(const type_t *type, enum name_type name_type); char *gen_name(void); extern int is_attr(const attr_list_t *list, enum attr_type t);