Rebase against 4de079bb7247c8b849558c0f27a280a9546c5570.

This commit is contained in:
Zebediah Figura
2021-02-19 19:32:08 -06:00
parent aa8a3d90cb
commit 9aeea5d12e
9 changed files with 59 additions and 254 deletions

View File

@@ -1,29 +0,0 @@
From f3fb964cf3cf78efb9242cc0ca281c2a16bec089 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 7 Jan 2021 13:07:33 +0100
Subject: [PATCH] widl: Never use the namespace ABI prefix for global types.
Otherwise we end up with types like ABI::IInspectable.
---
tools/widl/typetree.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c
index 65bc24edb0f..bd7ae2e4463 100644
--- a/tools/widl/typetree.c
+++ b/tools/widl/typetree.c
@@ -106,9 +106,10 @@ static size_t append_namespace(char **buf, size_t *len, size_t pos, struct names
static size_t append_namespaces(char **buf, size_t *len, size_t pos, struct namespace *namespace, const char *prefix,
const char *separator, const char *suffix, const char *abi_prefix)
{
+ int nested = namespace && !is_global_namespace(namespace);
size_t n = 0;
n += strappend(buf, len, pos + n, "%s", prefix);
- n += append_namespace(buf, len, pos + n, namespace, separator, abi_prefix);
+ if (nested) n += append_namespace(buf, len, pos + n, namespace, separator, abi_prefix);
n += strappend(buf, len, pos + n, "%s", suffix);
return n;
}
--
2.20.1

View File

@@ -1,140 +0,0 @@
From 6253706be0eef579fd9f68530ce646575e42a2e3 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 7 Jan 2021 14:28:21 +0100
Subject: [PATCH] widl: Precompute qualified type names, and use them for C++
interfaces.
This is what MIDL does and avoid mismatching and even fixes some compiling issues.
---
tools/widl/header.c | 8 +++-----
tools/widl/parser.y | 6 ++++++
tools/widl/typetree.c | 16 ++++++++++++++++
tools/widl/typetree.h | 1 +
tools/widl/widltypes.h | 1 +
5 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/tools/widl/header.c b/tools/widl/header.c
index a8141d5f61d..d327c621ad8 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -137,15 +137,13 @@ static void write_guid(FILE *f, const char *guid_prefix, const char *name, const
static void write_uuid_decl(FILE *f, type_t *type, const UUID *uuid)
{
- char *name = format_namespace(type->namespace, "", "::", type->name, use_abi_namespace ? "ABI" : NULL);
fprintf(f, "#ifdef __CRT_UUID_DECL\n");
fprintf(f, "__CRT_UUID_DECL(%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
"0x%02x,0x%02x,0x%02x,0x%02x,0x%02x)\n",
- name, uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0], uuid->Data4[1],
+ type->qualified_name, 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]);
fprintf(f, "#endif\n");
- free(name);
}
static const char *uuid_string(const UUID *uuid)
@@ -467,13 +465,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", name);
+ fprintf(h, "%s", type_get_qualified_name(t, name_type));
break;
case TYPE_RUNTIMECLASS:
fprintf(h, "%s", type_get_name(type_runtimeclass_get_default_iface(t), name_type));
break;
case TYPE_DELEGATE:
- fprintf(h, "%s", type_get_name(type_delegate_get_iface(t), name_type));
+ fprintf(h, "%s", type_get_qualified_name(type_delegate_get_iface(t), name_type));
break;
case TYPE_VOID:
fprintf(h, "void");
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index d8ab4a24ced..bd6f5c7e37f 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -2089,9 +2089,15 @@ type_t *reg_type(type_t *type, const char *name, struct namespace *namespace, in
nt = xmalloc(sizeof(struct rtype));
nt->name = name;
if (is_global_namespace(namespace))
+ {
type->c_name = name;
+ type->qualified_name = name;
+ }
else
+ {
type->c_name = format_namespace(namespace, "__x_", "_C", name, use_abi_namespace ? "ABI" : NULL);
+ type->qualified_name = format_namespace(namespace, "", "::", name, use_abi_namespace ? "ABI" : NULL);
+ }
nt->type = type;
nt->t = t;
nt->next = namespace->type_hash[hash];
diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c
index bd7ae2e4463..fc8da22c730 100644
--- a/tools/widl/typetree.c
+++ b/tools/widl/typetree.c
@@ -52,6 +52,7 @@ type_t *make_type(enum type_type type)
t->c_name = NULL;
t->signature = NULL;
t->short_name = NULL;
+ t->qualified_name = NULL;
memset(&t->details, 0, sizeof(t->details));
t->typestring_offset = 0;
t->ptrdesc = 0;
@@ -92,6 +93,20 @@ 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)
+{
+ assert(!!type->c_name == !!type->qualified_name);
+ switch(name_type) {
+ case NAME_DEFAULT:
+ return type->qualified_name;
+ case NAME_C:
+ return type->c_name;
+ }
+
+ assert(0);
+ return NULL;
+}
+
static size_t append_namespace(char **buf, size_t *len, size_t pos, struct namespace *namespace, const char *separator, const char *abi_prefix)
{
int nested = namespace && !is_global_namespace(namespace);
@@ -815,6 +830,7 @@ static void compute_delegate_iface_names(type_t *delegate, type_t *type, type_li
iface->name = strmake("I%s", delegate->name);
if (type) iface->c_name = format_parameterized_type_c_name(type, params, "I");
else iface->c_name = format_namespace(delegate->namespace, "__x_", "_C", iface->name, use_abi_namespace ? "ABI" : NULL);
+ iface->qualified_name = format_namespace(delegate->namespace, "", "::", iface->name, use_abi_namespace ? "ABI" : NULL);
}
type_t *type_delegate_declare(char *name, struct namespace *namespace)
diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h
index db43a9aa456..b72147af5c7 100644
--- a/tools/widl/typetree.h
+++ b/tools/widl/typetree.h
@@ -75,6 +75,7 @@ type_t *type_parameterized_type_specialize_declare(type_t *type, type_list_t *pa
type_t *type_parameterized_type_specialize_define(type_t *type, type_list_t *params);
int type_is_equal(const type_t *type1, const type_t *type2);
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);
diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h
index 21598a9213d..6aeeac228b6 100644
--- a/tools/widl/widltypes.h
+++ b/tools/widl/widltypes.h
@@ -505,6 +505,7 @@ struct _type_t {
const char *c_name;
const char *signature;
const char *short_name;
+ const char *qualified_name;
unsigned int typestring_offset;
unsigned int ptrdesc; /* used for complex structs */
int typelib_idx;
--
2.20.1

View File

@@ -1,26 +0,0 @@
From 248bbf6533e66975d4971a5cc72ae9e8d2091210 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 7 Jan 2021 14:14:22 +0100
Subject: [PATCH] widl: Define the C type name as an alias for the C++
qualified name.
---
tools/widl/header.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/widl/header.c b/tools/widl/header.c
index d327c621ad8..1bf527c642d 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -1483,6 +1483,8 @@ static void write_forward(FILE *header, type_t *iface)
fprintf(header, "#define __%s_FWD_DEFINED__\n", iface->c_name);
fprintf(header, "typedef interface %s %s;\n", iface->c_name, iface->c_name);
fprintf(header, "#ifdef __cplusplus\n");
+ if (iface->namespace && !is_global_namespace(iface->namespace))
+ fprintf(header, "#define %s %s\n", iface->c_name, iface->qualified_name);
write_namespace_start(header, iface->namespace);
if (strchr(iface->name, '<')) write_line(header, 0, "template<> struct %s;", iface->name);
else write_line(header, 0, "interface %s;", iface->name);
--
2.20.1