Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- tools/widl/header.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
diff --git a/tools/widl/header.c b/tools/widl/header.c index fcc73169d00..6b86f0a95fe 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -1460,12 +1460,65 @@ static void write_com_interface_start(FILE *header, const type_t *iface) fprintf(header,"#define __%s_%sINTERFACE_DEFINED__\n\n", iface->c_name, dispinterface ? "DISP" : ""); }
+static char *get_winrt_guard_macro(type_t *iface) +{ + const char *tmp = (char *)iface->c_name; + char *macro; + int i; + + if (!strncmp(tmp, "__x", 3)) tmp += 3; + if (!strncmp(tmp, "_ABI_", 5)) tmp += 5; + macro = xstrdup(tmp); + for (i = strlen(macro); i > 0; --i) macro[i - 1] = toupper(macro[i - 1]); + + return macro; +} + +static void write_widl_using_method_macros(FILE *header, const type_t *iface, const type_t *child) +{ + const statement_t *stmt; + + if (type_iface_get_inherit(iface)) write_widl_using_method_macros(header, type_iface_get_inherit(iface), child); + + STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(iface)) + { + const var_t *func = stmt->u.var; + + if (is_override_method(iface, child, func)) continue; + + if (!is_callas(func->attrs)) + fprintf(header, "#define %s_%s %s_%s\n", child->name, get_name(func), child->c_name, get_name(func)); + } +} + +static void write_widl_using_macros(FILE *header, type_t *iface) +{ + const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID); + char *macro; + + if (!strcmp(iface->name, iface->c_name)) return; + + macro = get_winrt_guard_macro(iface); + fprintf(header, "#ifdef WIDL_USING_%s\n", macro); + + if (uuid) fprintf(header, "#define IID_%s IID_%s\n", iface->name, iface->c_name); + fprintf(header, "#define %sVtbl %sVtbl\n", iface->name, iface->c_name); + fprintf(header, "#define %s %s\n", iface->name, iface->c_name); + + write_widl_using_method_macros(header, iface, iface); + + fprintf(header, "#endif /* WIDL_USING_%s */\n\n", macro); + free(macro); +} + static void write_com_interface_end(FILE *header, type_t *iface) { int dispinterface = is_attr(iface->attrs, ATTR_DISPINTERFACE); const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID); type_t *type;
+ if (winrt_mode) write_widl_using_macros(header, iface); + if (uuid) write_guid(header, dispinterface ? "DIID" : "IID", iface->c_name, uuid);