widl: Generate helper macros for WinRT implementation.
This generates additional macros to help keeping implementation simple, guarded with WIDL_using ifdefs, like this: #ifdef WIDL_using_Windows_Foo #define IFooVtbl __x_ABI_CWindows_CFoo_CIFooVtbl #define IFoo __x_ABI_CWindows_CFoo_CIFoo #define IFoo_DoFoo __x_ABI_CWindows_CFoo_CIFoo_DoFoo #endif /* WIDL_using_Windows_Foo */ Implementation files can define the desired WIDL_using preprocessor macros before including the header, and then implement or use the interface methods with the simple non-prefixed names instead. Signed-off-by: Rémi Bernon <rbernon@codeweavers.com> Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
5f6fdb1838
commit
dc65f88654
|
@ -48,6 +48,8 @@ static void write_type_v(FILE *f, const decl_spec_t *t, int is_field, int declon
|
||||||
static void write_apicontract_guard_start(FILE *header, const expr_t *expr);
|
static void write_apicontract_guard_start(FILE *header, const expr_t *expr);
|
||||||
static void write_apicontract_guard_end(FILE *header, const expr_t *expr);
|
static void write_apicontract_guard_end(FILE *header, const expr_t *expr);
|
||||||
|
|
||||||
|
static void write_widl_using_macros(FILE *header, type_t *iface);
|
||||||
|
|
||||||
static void indent(FILE *h, int delta)
|
static void indent(FILE *h, int delta)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
@ -634,6 +636,7 @@ static void write_type_definition(FILE *f, type_t *t, int declonly)
|
||||||
fprintf(f, "#else\n");
|
fprintf(f, "#else\n");
|
||||||
write_type_left(f, &ds, NAME_C, declonly, TRUE);
|
write_type_left(f, &ds, NAME_C, declonly, TRUE);
|
||||||
fprintf(f, ";\n");
|
fprintf(f, ";\n");
|
||||||
|
if (winrt_mode) write_widl_using_macros(f, t);
|
||||||
fprintf(f, "#endif\n\n");
|
fprintf(f, "#endif\n\n");
|
||||||
}
|
}
|
||||||
if (contract) write_apicontract_guard_end(f, contract);
|
if (contract) write_apicontract_guard_end(f, contract);
|
||||||
|
@ -1644,6 +1647,47 @@ 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" : "");
|
fprintf(header,"#define __%s_%sINTERFACE_DEFINED__\n\n", iface->c_name, dispinterface ? "DISP" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void write_widl_using_method_macros(FILE *header, const type_t *iface, const type_t *top_iface)
|
||||||
|
{
|
||||||
|
const statement_t *stmt;
|
||||||
|
const char *name = top_iface->short_name ? top_iface->short_name : top_iface->name;
|
||||||
|
|
||||||
|
if (type_iface_get_inherit(iface)) write_widl_using_method_macros(header, type_iface_get_inherit(iface), top_iface);
|
||||||
|
|
||||||
|
STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(iface))
|
||||||
|
{
|
||||||
|
const var_t *func = stmt->u.var;
|
||||||
|
const char *func_name;
|
||||||
|
|
||||||
|
if (is_override_method(iface, top_iface, func)) continue;
|
||||||
|
if (is_callas(func->attrs)) continue;
|
||||||
|
|
||||||
|
func_name = get_name(func);
|
||||||
|
fprintf(header, "#define %s_%s %s_%s\n", name, func_name, top_iface->c_name, func_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void write_widl_using_macros(FILE *header, type_t *iface)
|
||||||
|
{
|
||||||
|
const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
|
||||||
|
const char *name = iface->short_name ? iface->short_name : iface->name;
|
||||||
|
char *macro;
|
||||||
|
|
||||||
|
if (!strcmp(iface->name, iface->c_name)) return;
|
||||||
|
|
||||||
|
macro = format_namespace(iface->namespace, "WIDL_using_", "_", NULL, NULL);
|
||||||
|
fprintf(header, "#ifdef %s\n", macro);
|
||||||
|
|
||||||
|
if (uuid) fprintf(header, "#define IID_%s IID_%s\n", name, iface->c_name);
|
||||||
|
if (iface->type_type == TYPE_INTERFACE) fprintf(header, "#define %sVtbl %sVtbl\n", name, iface->c_name);
|
||||||
|
fprintf(header, "#define %s %s\n", name, iface->c_name);
|
||||||
|
|
||||||
|
if (iface->type_type == TYPE_INTERFACE) write_widl_using_method_macros(header, iface, iface);
|
||||||
|
|
||||||
|
fprintf(header, "#endif /* %s */\n", macro);
|
||||||
|
free(macro);
|
||||||
|
}
|
||||||
|
|
||||||
static void write_com_interface_end(FILE *header, type_t *iface)
|
static void write_com_interface_end(FILE *header, type_t *iface)
|
||||||
{
|
{
|
||||||
int dispinterface = is_attr(iface->attrs, ATTR_DISPINTERFACE);
|
int dispinterface = is_attr(iface->attrs, ATTR_DISPINTERFACE);
|
||||||
|
@ -1721,6 +1765,7 @@ static void write_com_interface_end(FILE *header, type_t *iface)
|
||||||
fprintf(header, "#else\n");
|
fprintf(header, "#else\n");
|
||||||
write_inline_wrappers(header, type, type, iface->c_name);
|
write_inline_wrappers(header, type, type, iface->c_name);
|
||||||
fprintf(header, "#endif\n");
|
fprintf(header, "#endif\n");
|
||||||
|
if (winrt_mode) write_widl_using_macros(header, iface);
|
||||||
fprintf(header, "#endif\n");
|
fprintf(header, "#endif\n");
|
||||||
fprintf(header, "\n");
|
fprintf(header, "\n");
|
||||||
fprintf(header, "#endif\n");
|
fprintf(header, "#endif\n");
|
||||||
|
|
|
@ -53,6 +53,7 @@ type_t *make_type(enum type_type type)
|
||||||
t->signature = NULL;
|
t->signature = NULL;
|
||||||
t->qualified_name = NULL;
|
t->qualified_name = NULL;
|
||||||
t->impl_name = NULL;
|
t->impl_name = NULL;
|
||||||
|
t->short_name = NULL;
|
||||||
memset(&t->details, 0, sizeof(t->details));
|
memset(&t->details, 0, sizeof(t->details));
|
||||||
t->typestring_offset = 0;
|
t->typestring_offset = 0;
|
||||||
t->ptrdesc = 0;
|
t->ptrdesc = 0;
|
||||||
|
@ -347,6 +348,22 @@ static char *format_parameterized_type_signature(type_t *type, typeref_list_t *p
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *format_parameterized_type_short_name(type_t *type, typeref_list_t *params, const char *prefix)
|
||||||
|
{
|
||||||
|
size_t len = 0, pos = 0;
|
||||||
|
char *buf = NULL;
|
||||||
|
typeref_t *ref;
|
||||||
|
|
||||||
|
pos += strappend(&buf, &len, pos, "%s%s", prefix, type->name);
|
||||||
|
if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
|
||||||
|
{
|
||||||
|
type = type_pointer_get_root_type(ref->type);
|
||||||
|
pos += strappend(&buf, &len, pos, "_%s", type->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
static char *format_parameterized_type_impl_name(type_t *type, typeref_list_t *params, const char *prefix)
|
static char *format_parameterized_type_impl_name(type_t *type, typeref_list_t *params, const char *prefix)
|
||||||
{
|
{
|
||||||
size_t len = 0, pos = 0;
|
size_t len = 0, pos = 0;
|
||||||
|
@ -1201,11 +1218,13 @@ type_t *type_parameterized_type_specialize_declare(type_t *type, typeref_list_t
|
||||||
new_type->name = format_parameterized_type_name(type, params);
|
new_type->name = format_parameterized_type_name(type, params);
|
||||||
reg_type(new_type, new_type->name, new_type->namespace, 0);
|
reg_type(new_type, new_type->name, new_type->namespace, 0);
|
||||||
new_type->c_name = format_parameterized_type_c_name(type, params, "");
|
new_type->c_name = format_parameterized_type_c_name(type, params, "");
|
||||||
|
new_type->short_name = format_parameterized_type_short_name(type, params, "");
|
||||||
|
|
||||||
if (new_type->type_type == TYPE_DELEGATE)
|
if (new_type->type_type == TYPE_DELEGATE)
|
||||||
{
|
{
|
||||||
new_type->details.delegate.iface = duptype(tmpl->details.delegate.iface, 0);
|
new_type->details.delegate.iface = duptype(tmpl->details.delegate.iface, 0);
|
||||||
compute_delegate_iface_names(new_type, type, params);
|
compute_delegate_iface_names(new_type, type, params);
|
||||||
|
new_type->details.delegate.iface->short_name = format_parameterized_type_short_name(type, params, "I");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new_type;
|
return new_type;
|
||||||
|
|
|
@ -505,6 +505,7 @@ struct _type_t {
|
||||||
const char *signature;
|
const char *signature;
|
||||||
const char *qualified_name;
|
const char *qualified_name;
|
||||||
const char *impl_name;
|
const char *impl_name;
|
||||||
|
const char *short_name;
|
||||||
unsigned int typestring_offset;
|
unsigned int typestring_offset;
|
||||||
unsigned int ptrdesc; /* used for complex structs */
|
unsigned int ptrdesc; /* used for complex structs */
|
||||||
int typelib_idx;
|
int typelib_idx;
|
||||||
|
|
Loading…
Reference in New Issue