Commit b2a1e381 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

widl: Clarify declaration type names vs (reference) type names.

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: 's avatarRémi Bernon <rbernon@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 86c565cf
...@@ -339,11 +339,12 @@ static void write_pointer_left(FILE *h, type_t *ref) ...@@ -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) 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; type_t *t = ds->type;
const char *name; const char *decl_name, *name;
char *args; char *args;
if (!h) return; if (!h) return;
decl_name = type_get_decl_name(t, name_type);
name = type_get_name(t, name_type); name = type_get_name(t, name_type);
if (ds->func_specifier & FUNCTION_SPECIFIER_INLINE) 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 ...@@ -356,9 +357,10 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i
else { else {
switch (type_get_type_detect_alias(t)) { switch (type_get_type_detect_alias(t)) {
case TYPE_ENUM: case TYPE_ENUM:
if (!declonly && !t->written) { if (declonly) fprintf(h, "enum %s", decl_name ? decl_name : "");
else if (!t->written) {
assert(t->defined); 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"); else fprintf(h, "enum {\n");
t->written = TRUE; t->written = TRUE;
indentation++; indentation++;
...@@ -366,13 +368,15 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i ...@@ -366,13 +368,15 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i
indent(h, -1); indent(h, -1);
fprintf(h, "}"); fprintf(h, "}");
} }
else if (winrt_mode && name_type == NAME_DEFAULT && name) fprintf(h, "%s", name);
else fprintf(h, "enum %s", name ? name : ""); else fprintf(h, "enum %s", name ? name : "");
break; break;
case TYPE_STRUCT: case TYPE_STRUCT:
case TYPE_ENCAPSULATED_UNION: 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); 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"); else fprintf(h, "struct {\n");
t->written = TRUE; t->written = TRUE;
indentation++; indentation++;
...@@ -383,12 +387,14 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i ...@@ -383,12 +387,14 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i
indent(h, -1); indent(h, -1);
fprintf(h, "}"); fprintf(h, "}");
} }
else if (winrt_mode && name_type == NAME_DEFAULT && name) fprintf(h, "%s", name);
else fprintf(h, "struct %s", name ? name : ""); else fprintf(h, "struct %s", name ? name : "");
break; break;
case TYPE_UNION: case TYPE_UNION:
if (!declonly && !t->written) { if (declonly) fprintf(h, "union %s", decl_name ? decl_name : "");
else if (!t->written) {
assert(t->defined); 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"); else fprintf(h, "union {\n");
t->written = TRUE; t->written = TRUE;
indentation++; indentation++;
...@@ -396,7 +402,8 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i ...@@ -396,7 +402,8 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i
indent(h, -1); indent(h, -1);
fprintf(h, "}"); 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; break;
case TYPE_POINTER: case TYPE_POINTER:
{ {
...@@ -482,13 +489,13 @@ void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, i ...@@ -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_INTERFACE:
case TYPE_MODULE: case TYPE_MODULE:
case TYPE_COCLASS: case TYPE_COCLASS:
fprintf(h, "%s", type_get_qualified_name(t, name_type)); fprintf(h, "%s", type_get_name(t, name_type));
break; break;
case TYPE_RUNTIMECLASS: case TYPE_RUNTIMECLASS:
fprintf(h, "%s", type_get_name(type_runtimeclass_get_default_iface(t, TRUE), name_type)); fprintf(h, "%s", type_get_name(type_runtimeclass_get_default_iface(t, TRUE), name_type));
break; break;
case TYPE_DELEGATE: 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; break;
case TYPE_VOID: case TYPE_VOID:
fprintf(h, "void"); fprintf(h, "void");
...@@ -882,7 +889,7 @@ static void write_typedef(FILE *header, type_t *type, int declonly) ...@@ -882,7 +889,7 @@ static void write_typedef(FILE *header, type_t *type, int declonly)
write_namespace_start(header, t->namespace); write_namespace_start(header, t->namespace);
indent(header, 0); indent(header, 0);
fprintf(header, "typedef "); 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"); fprintf(header, ";\n");
write_namespace_end(header, t->namespace); write_namespace_end(header, t->namespace);
} }
......
...@@ -81,7 +81,7 @@ static const var_t *find_arg(const var_list_t *args, const char *name) ...@@ -81,7 +81,7 @@ static const var_t *find_arg(const var_list_t *args, const char *name)
return NULL; 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) { switch(name_type) {
case NAME_DEFAULT: case NAME_DEFAULT:
...@@ -94,13 +94,13 @@ const char *type_get_name(const type_t *type, enum name_type name_type) ...@@ -94,13 +94,13 @@ const char *type_get_name(const type_t *type, enum name_type name_type)
return NULL; 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) { switch(name_type) {
case NAME_DEFAULT: case NAME_DEFAULT:
return type->qualified_name; return type->qualified_name ? type->qualified_name : type->name;
case NAME_C: case NAME_C:
return type->c_name; return type->c_name ? type->c_name : type->name;
} }
assert(0); assert(0);
......
...@@ -77,8 +77,8 @@ type_t *type_parameterized_type_specialize_partial(type_t *type, typeref_list_t ...@@ -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_declare(type_t *type, typeref_list_t *params);
type_t *type_parameterized_type_specialize_define(type_t *type); type_t *type_parameterized_type_specialize_define(type_t *type);
int type_is_equal(const type_t *type1, const type_t *type2); 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_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); char *gen_name(void);
extern int is_attr(const attr_list_t *list, enum attr_type t); extern int is_attr(const attr_list_t *list, enum attr_type t);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment