2002-07-16 05:20:45 +02:00
|
|
|
/*
|
|
|
|
* IDL Compiler
|
|
|
|
*
|
|
|
|
* Copyright 2002 Ove Kaaven
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-07-16 05:20:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
#include <stdarg.h>
|
2002-07-16 05:20:45 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-17 20:28:43 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2002-07-16 05:20:45 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "header.h"
|
2008-04-22 12:36:38 +02:00
|
|
|
#include "expr.h"
|
2008-12-29 13:05:27 +01:00
|
|
|
#include "typetree.h"
|
2015-11-27 11:00:27 +01:00
|
|
|
#include "typelib.h"
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
static int indentation = 0;
|
2010-08-27 13:52:09 +02:00
|
|
|
static int is_object_interface = 0;
|
2007-09-28 02:38:13 +02:00
|
|
|
user_type_list_t user_type_list = LIST_INIT(user_type_list);
|
2011-06-13 20:31:42 +02:00
|
|
|
context_handle_list_t context_handle_list = LIST_INIT(context_handle_list);
|
2011-05-27 12:07:29 +02:00
|
|
|
generic_handle_list_t generic_handle_list = LIST_INIT(generic_handle_list);
|
2002-07-16 05:20:45 +02:00
|
|
|
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
static void write_type_v(FILE *f, const decl_spec_t *t, int is_field, int declonly, const char *name, enum name_type name_type);
|
2010-08-27 13:52:09 +02:00
|
|
|
|
2020-12-01 15:01:57 +01:00
|
|
|
static void write_apicontract_guard_start(FILE *header, const expr_t *expr);
|
|
|
|
static void write_apicontract_guard_end(FILE *header, const expr_t *expr);
|
|
|
|
|
2021-02-26 09:43:06 +01:00
|
|
|
static void write_widl_using_macros(FILE *header, type_t *iface);
|
|
|
|
|
2005-08-03 16:55:22 +02:00
|
|
|
static void indent(FILE *h, int delta)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
if (delta < 0) indentation += delta;
|
2005-08-03 16:55:22 +02:00
|
|
|
for (c=0; c<indentation; c++) fprintf(h, " ");
|
2002-07-16 05:20:45 +02:00
|
|
|
if (delta > 0) indentation += delta;
|
|
|
|
}
|
|
|
|
|
2015-07-31 13:37:57 +02:00
|
|
|
static void write_line(FILE *f, int delta, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
indent(f, delta);
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vfprintf(f, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
|
|
|
|
2007-05-10 05:50:49 +02:00
|
|
|
int is_ptrchain_attr(const var_t *var, enum attr_type t)
|
|
|
|
{
|
|
|
|
if (is_attr(var->attrs, t))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
{
|
2019-07-05 23:49:49 +02:00
|
|
|
type_t *type = var->declspec.type;
|
2007-05-10 05:50:49 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (is_attr(type->attrs, t))
|
|
|
|
return 1;
|
2009-01-06 00:33:43 +01:00
|
|
|
else if (type_is_alias(type))
|
2019-08-15 04:45:50 +02:00
|
|
|
type = type_alias_get_aliasee_type(type);
|
2007-05-10 05:50:49 +02:00
|
|
|
else if (is_ptr(type))
|
2019-07-05 23:51:32 +02:00
|
|
|
type = type_pointer_get_ref_type(type);
|
2007-05-10 05:50:49 +02:00
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-27 15:02:58 +01:00
|
|
|
int is_aliaschain_attr(const type_t *type, enum attr_type attr)
|
|
|
|
{
|
|
|
|
const type_t *t = type;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (is_attr(t->attrs, attr))
|
|
|
|
return 1;
|
2009-01-06 00:33:43 +01:00
|
|
|
else if (type_is_alias(t))
|
2019-08-15 04:45:50 +02:00
|
|
|
t = type_alias_get_aliasee_type(t);
|
2008-03-27 15:02:58 +01:00
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:20:36 +01:00
|
|
|
int is_attr(const attr_list_t *list, enum attr_type t)
|
2003-01-09 02:05:54 +01:00
|
|
|
{
|
2007-01-22 14:20:36 +01:00
|
|
|
const attr_t *attr;
|
|
|
|
if (list) LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
|
|
|
|
if (attr->type == t) return 1;
|
|
|
|
return 0;
|
2003-01-09 02:05:54 +01:00
|
|
|
}
|
|
|
|
|
2007-01-22 14:20:36 +01:00
|
|
|
void *get_attrp(const attr_list_t *list, enum attr_type t)
|
2003-01-09 02:05:54 +01:00
|
|
|
{
|
2007-01-22 14:20:36 +01:00
|
|
|
const attr_t *attr;
|
|
|
|
if (list) LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
|
|
|
|
if (attr->type == t) return attr->u.pval;
|
|
|
|
return NULL;
|
2003-01-09 02:05:54 +01:00
|
|
|
}
|
|
|
|
|
2010-03-26 11:42:28 +01:00
|
|
|
unsigned int get_attrv(const attr_list_t *list, enum attr_type t)
|
2003-01-09 02:05:54 +01:00
|
|
|
{
|
2007-01-22 14:20:36 +01:00
|
|
|
const attr_t *attr;
|
|
|
|
if (list) LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
|
|
|
|
if (attr->type == t) return attr->u.ival;
|
|
|
|
return 0;
|
2003-01-09 02:05:54 +01:00
|
|
|
}
|
|
|
|
|
2021-02-25 14:15:09 +01:00
|
|
|
static char *format_parameterized_type_args(const type_t *type, const char *prefix, const char *suffix)
|
|
|
|
{
|
|
|
|
typeref_list_t *params;
|
|
|
|
typeref_t *ref;
|
|
|
|
size_t len = 0, pos = 0;
|
|
|
|
char *buf = NULL;
|
|
|
|
|
|
|
|
params = type->details.parameterized.params;
|
|
|
|
if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
|
|
|
|
{
|
|
|
|
assert(ref->type->type_type != TYPE_POINTER);
|
|
|
|
pos += strappend(&buf, &len, pos, "%s%s%s", prefix, ref->type->name, suffix);
|
|
|
|
if (list_next(params, &ref->entry)) pos += strappend(&buf, &len, pos, ", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!buf) return xstrdup("");
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:15:02 +01:00
|
|
|
static void write_guid(FILE *f, const char *guid_prefix, const char *name, const UUID *uuid)
|
2005-03-05 11:49:22 +01:00
|
|
|
{
|
|
|
|
if (!uuid) return;
|
2006-10-15 12:27:34 +02:00
|
|
|
fprintf(f, "DEFINE_GUID(%s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
|
2005-03-05 11:49:22 +01:00
|
|
|
"0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
|
|
|
|
guid_prefix, 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]);
|
|
|
|
}
|
|
|
|
|
2015-07-31 13:38:32 +02:00
|
|
|
static void write_uuid_decl(FILE *f, type_t *type, const UUID *uuid)
|
2011-07-14 17:21:45 +02:00
|
|
|
{
|
|
|
|
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",
|
2021-02-19 12:04:00 +01:00
|
|
|
type->c_name, uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0], uuid->Data4[1],
|
2011-07-14 17:21:45 +02:00
|
|
|
uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5], uuid->Data4[6],
|
|
|
|
uuid->Data4[7]);
|
|
|
|
fprintf(f, "#endif\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *uuid_string(const UUID *uuid)
|
|
|
|
{
|
|
|
|
static char buf[37];
|
|
|
|
|
|
|
|
sprintf(buf, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
|
|
|
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]);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2015-07-31 13:37:57 +02:00
|
|
|
static void write_namespace_start(FILE *header, struct namespace *namespace)
|
|
|
|
{
|
2015-08-05 12:52:15 +02:00
|
|
|
if(is_global_namespace(namespace)) {
|
|
|
|
if(use_abi_namespace)
|
|
|
|
write_line(header, 1, "namespace ABI {");
|
2015-07-31 13:37:57 +02:00
|
|
|
return;
|
2015-08-05 12:52:15 +02:00
|
|
|
}
|
2015-07-31 13:37:57 +02:00
|
|
|
|
|
|
|
write_namespace_start(header, namespace->parent);
|
|
|
|
write_line(header, 1, "namespace %s {", namespace->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_namespace_end(FILE *header, struct namespace *namespace)
|
|
|
|
{
|
2015-08-05 12:52:15 +02:00
|
|
|
if(is_global_namespace(namespace)) {
|
|
|
|
if(use_abi_namespace)
|
2021-09-14 21:25:01 +02:00
|
|
|
write_line(header, -1, "}");
|
2015-07-31 13:37:57 +02:00
|
|
|
return;
|
2015-08-05 12:52:15 +02:00
|
|
|
}
|
2015-07-31 13:37:57 +02:00
|
|
|
|
2021-09-14 21:25:01 +02:00
|
|
|
write_line(header, -1, "}");
|
2015-07-31 13:37:57 +02:00
|
|
|
write_namespace_end(header, namespace->parent);
|
|
|
|
}
|
|
|
|
|
2008-08-30 11:15:04 +02:00
|
|
|
const char *get_name(const var_t *v)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2019-11-08 20:01:43 +01:00
|
|
|
static char *buffer;
|
|
|
|
free( buffer );
|
2021-01-29 09:50:06 +01:00
|
|
|
if (is_attr( v->attrs, ATTR_EVENTADD ))
|
|
|
|
return buffer = strmake( "add_%s", v->name );
|
|
|
|
if (is_attr( v->attrs, ATTR_EVENTREMOVE ))
|
|
|
|
return buffer = strmake( "remove_%s", v->name );
|
2008-08-30 11:15:04 +02:00
|
|
|
if (is_attr( v->attrs, ATTR_PROPGET ))
|
2019-11-08 20:01:43 +01:00
|
|
|
return buffer = strmake( "get_%s", v->name );
|
|
|
|
if (is_attr( v->attrs, ATTR_PROPPUT ))
|
|
|
|
return buffer = strmake( "put_%s", v->name );
|
|
|
|
if (is_attr( v->attrs, ATTR_PROPPUTREF ))
|
|
|
|
return buffer = strmake( "putref_%s", v->name );
|
|
|
|
buffer = NULL;
|
|
|
|
return v->name;
|
2007-04-26 03:17:31 +02:00
|
|
|
}
|
|
|
|
|
2020-11-04 19:49:29 +01:00
|
|
|
static void write_fields(FILE *h, var_list_t *fields, enum name_type name_type)
|
2002-11-12 03:12:35 +01:00
|
|
|
{
|
2012-05-12 16:13:57 +02:00
|
|
|
unsigned nameless_struct_cnt = 0, nameless_struct_i = 0, nameless_union_cnt = 0, nameless_union_i = 0;
|
|
|
|
const char *name;
|
|
|
|
char buf[32];
|
2007-01-22 14:26:12 +01:00
|
|
|
var_t *v;
|
2012-05-12 16:13:57 +02:00
|
|
|
|
2007-01-22 14:26:12 +01:00
|
|
|
if (!fields) return;
|
2012-05-12 16:13:57 +02:00
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( v, fields, var_t, entry ) {
|
2019-07-05 23:49:49 +02:00
|
|
|
if (!v || !v->declspec.type) continue;
|
2012-05-12 16:13:57 +02:00
|
|
|
|
2019-07-05 23:49:49 +02:00
|
|
|
switch(type_get_type_detect_alias(v->declspec.type)) {
|
2012-05-12 16:13:57 +02:00
|
|
|
case TYPE_STRUCT:
|
|
|
|
case TYPE_ENCAPSULATED_UNION:
|
|
|
|
nameless_struct_cnt++;
|
|
|
|
break;
|
|
|
|
case TYPE_UNION:
|
|
|
|
nameless_union_cnt++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( v, fields, var_t, entry ) {
|
2020-12-01 15:01:57 +01:00
|
|
|
expr_t *contract = get_attrp(v->attrs, ATTR_CONTRACT);
|
2019-07-05 23:49:49 +02:00
|
|
|
if (!v || !v->declspec.type) continue;
|
2020-12-01 15:01:57 +01:00
|
|
|
if (contract) write_apicontract_guard_start(h, contract);
|
2012-05-12 16:13:57 +02:00
|
|
|
|
|
|
|
indent(h, 0);
|
|
|
|
name = v->name;
|
|
|
|
|
2019-07-05 23:49:49 +02:00
|
|
|
switch(type_get_type_detect_alias(v->declspec.type)) {
|
2012-05-12 16:13:57 +02:00
|
|
|
case TYPE_STRUCT:
|
|
|
|
case TYPE_ENCAPSULATED_UNION:
|
|
|
|
if(!v->name) {
|
|
|
|
fprintf(h, "__C89_NAMELESS ");
|
|
|
|
if(nameless_struct_cnt == 1) {
|
|
|
|
name = "__C89_NAMELESSSTRUCTNAME";
|
|
|
|
}else if(nameless_struct_i < 5 /* # of supporting macros */) {
|
|
|
|
sprintf(buf, "__C89_NAMELESSSTRUCTNAME%d", ++nameless_struct_i);
|
|
|
|
name = buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TYPE_UNION:
|
|
|
|
if(!v->name) {
|
|
|
|
fprintf(h, "__C89_NAMELESS ");
|
|
|
|
if(nameless_union_cnt == 1) {
|
|
|
|
name = "__C89_NAMELESSUNIONNAME";
|
|
|
|
}else if(nameless_union_i < 8 /* # of supporting macros */ ) {
|
|
|
|
sprintf(buf, "__C89_NAMELESSUNIONNAME%d", ++nameless_union_i);
|
|
|
|
name = buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
2020-11-04 19:49:29 +01:00
|
|
|
write_type_v(h, &v->declspec, TRUE, v->declonly, name, name_type);
|
2012-05-12 16:13:57 +02:00
|
|
|
fprintf(h, ";\n");
|
2020-12-01 15:01:57 +01:00
|
|
|
if (contract) write_apicontract_guard_end(h, contract);
|
2012-05-12 16:13:57 +02:00
|
|
|
}
|
2002-11-12 03:12:35 +01:00
|
|
|
}
|
|
|
|
|
2015-08-07 15:41:55 +02:00
|
|
|
static void write_enums(FILE *h, var_list_t *enums, const char *enum_name)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
var_t *v;
|
|
|
|
if (!enums) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, enums, var_t, entry )
|
|
|
|
{
|
2020-12-01 15:01:57 +01:00
|
|
|
expr_t *contract = get_attrp(v->attrs, ATTR_CONTRACT);
|
|
|
|
if (contract) write_apicontract_guard_start(h, contract);
|
2007-06-06 03:49:12 +02:00
|
|
|
if (v->name) {
|
2005-08-03 16:55:22 +02:00
|
|
|
indent(h, 0);
|
2015-08-07 15:41:55 +02:00
|
|
|
if(!enum_name)
|
|
|
|
fprintf(h, "%s", get_name(v));
|
|
|
|
else
|
|
|
|
fprintf(h, "%s_%s", enum_name, get_name(v));
|
2002-11-30 02:49:46 +01:00
|
|
|
if (v->eval) {
|
|
|
|
fprintf(h, " = ");
|
2008-09-15 16:46:01 +02:00
|
|
|
write_expr(h, v->eval, 0, 1, NULL, NULL, "");
|
2002-11-30 02:49:46 +01:00
|
|
|
}
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
2007-01-22 14:26:12 +01:00
|
|
|
if (list_next( enums, &v->entry )) fprintf(h, ",\n");
|
2020-12-01 15:01:57 +01:00
|
|
|
else fprintf(h, "\n");
|
|
|
|
if (contract) write_apicontract_guard_end(h, contract);
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
int needs_space_after(type_t *t)
|
2006-08-29 23:28:05 +02:00
|
|
|
{
|
2009-01-06 00:33:43 +01:00
|
|
|
return (type_is_alias(t) ||
|
2009-03-05 09:22:19 +01:00
|
|
|
(!is_ptr(t) && (!is_array(t) || !type_array_is_decl_as_ptr(t) || t->name)));
|
2006-08-29 23:28:05 +02:00
|
|
|
}
|
|
|
|
|
2020-06-12 14:08:42 +02:00
|
|
|
static int decl_needs_parens(const type_t *t)
|
2019-08-18 03:07:05 +02:00
|
|
|
{
|
|
|
|
if (type_is_alias(t))
|
|
|
|
return FALSE;
|
|
|
|
if (is_array(t) && !type_array_is_decl_as_ptr(t))
|
|
|
|
return TRUE;
|
|
|
|
return is_func(t);
|
|
|
|
}
|
|
|
|
|
2018-10-05 23:57:51 +02:00
|
|
|
static void write_pointer_left(FILE *h, type_t *ref)
|
|
|
|
{
|
|
|
|
if (needs_space_after(ref))
|
|
|
|
fprintf(h, " ");
|
2019-08-18 03:07:05 +02:00
|
|
|
if (decl_needs_parens(ref))
|
2018-10-05 23:57:51 +02:00
|
|
|
fprintf(h, "(");
|
2019-08-18 03:07:05 +02:00
|
|
|
if (type_get_type_detect_alias(ref) == TYPE_FUNCTION)
|
|
|
|
{
|
|
|
|
const char *callconv = get_attrp(ref->attrs, ATTR_CALLCONV);
|
|
|
|
if (!callconv && is_object_interface) callconv = "STDMETHODCALLTYPE";
|
|
|
|
if (callconv) fprintf(h, "%s ", callconv);
|
|
|
|
}
|
2018-10-05 23:57:51 +02:00
|
|
|
fprintf(h, "*");
|
|
|
|
}
|
|
|
|
|
2019-08-18 03:07:05 +02:00
|
|
|
void write_type_left(FILE *h, const decl_spec_t *ds, enum name_type name_type, int declonly, int write_callconv)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2019-08-16 03:13:19 +02:00
|
|
|
type_t *t = ds->type;
|
2015-08-07 15:41:55 +02:00
|
|
|
const char *name;
|
2021-02-25 14:16:02 +01:00
|
|
|
char *args;
|
2015-08-07 15:41:55 +02:00
|
|
|
|
2007-10-03 06:40:13 +02:00
|
|
|
if (!h) return;
|
|
|
|
|
2015-08-07 15:41:55 +02:00
|
|
|
name = type_get_name(t, name_type);
|
|
|
|
|
2019-08-18 03:07:07 +02:00
|
|
|
if (ds->func_specifier & FUNCTION_SPECIFIER_INLINE)
|
|
|
|
fprintf(h, "inline ");
|
|
|
|
|
2019-08-18 03:07:06 +02:00
|
|
|
if ((ds->qualifier & TYPE_QUALIFIER_CONST) && (type_is_alias(t) || !is_ptr(t)))
|
2008-04-29 21:39:53 +02:00
|
|
|
fprintf(h, "const ");
|
2006-08-29 23:26:03 +02:00
|
|
|
|
2020-11-04 19:49:29 +01:00
|
|
|
if (!winrt_mode && type_is_alias(t)) fprintf(h, "%s", t->name);
|
2002-07-16 05:20:45 +02:00
|
|
|
else {
|
2009-02-23 14:48:11 +01:00
|
|
|
switch (type_get_type_detect_alias(t)) {
|
|
|
|
case TYPE_ENUM:
|
2019-08-20 04:17:36 +02:00
|
|
|
if (!declonly && !t->written) {
|
|
|
|
assert(t->defined);
|
2015-08-07 15:41:55 +02:00
|
|
|
if (name) fprintf(h, "enum %s {\n", name);
|
2002-11-12 03:12:35 +01:00
|
|
|
else fprintf(h, "enum {\n");
|
2002-11-30 02:49:46 +01:00
|
|
|
t->written = TRUE;
|
2002-11-12 03:12:35 +01:00
|
|
|
indentation++;
|
2015-08-07 15:41:55 +02:00
|
|
|
write_enums(h, type_enum_get_values(t), is_global_namespace(t->namespace) ? NULL : t->name);
|
2005-08-03 16:55:22 +02:00
|
|
|
indent(h, -1);
|
2002-11-12 03:12:35 +01:00
|
|
|
fprintf(h, "}");
|
|
|
|
}
|
2015-08-07 15:41:55 +02:00
|
|
|
else fprintf(h, "enum %s", name ? name : "");
|
2002-11-12 03:12:35 +01:00
|
|
|
break;
|
2009-02-23 14:48:11 +01:00
|
|
|
case TYPE_STRUCT:
|
|
|
|
case TYPE_ENCAPSULATED_UNION:
|
2019-08-20 04:17:36 +02:00
|
|
|
if (!declonly && !t->written) {
|
|
|
|
assert(t->defined);
|
2015-08-10 13:19:48 +02:00
|
|
|
if (name) fprintf(h, "struct %s {\n", name);
|
2002-11-12 03:12:35 +01:00
|
|
|
else fprintf(h, "struct {\n");
|
2002-11-30 02:49:46 +01:00
|
|
|
t->written = TRUE;
|
2002-11-12 03:12:35 +01:00
|
|
|
indentation++;
|
2009-02-23 14:48:11 +01:00
|
|
|
if (type_get_type(t) != TYPE_STRUCT)
|
2020-11-04 19:49:29 +01:00
|
|
|
write_fields(h, type_encapsulated_union_get_fields(t), name_type);
|
2008-12-29 13:05:27 +01:00
|
|
|
else
|
2020-11-04 19:49:29 +01:00
|
|
|
write_fields(h, type_struct_get_fields(t), name_type);
|
2005-08-03 16:55:22 +02:00
|
|
|
indent(h, -1);
|
2002-11-12 03:12:35 +01:00
|
|
|
fprintf(h, "}");
|
|
|
|
}
|
2015-08-10 13:19:48 +02:00
|
|
|
else fprintf(h, "struct %s", name ? name : "");
|
2002-11-12 03:12:35 +01:00
|
|
|
break;
|
2009-02-23 14:48:11 +01:00
|
|
|
case TYPE_UNION:
|
2019-08-20 04:17:36 +02:00
|
|
|
if (!declonly && !t->written) {
|
|
|
|
assert(t->defined);
|
2002-07-16 05:20:45 +02:00
|
|
|
if (t->name) fprintf(h, "union %s {\n", t->name);
|
|
|
|
else fprintf(h, "union {\n");
|
2002-11-30 02:49:46 +01:00
|
|
|
t->written = TRUE;
|
2002-07-16 05:20:45 +02:00
|
|
|
indentation++;
|
2020-11-04 19:49:29 +01:00
|
|
|
write_fields(h, type_union_get_cases(t), name_type);
|
2005-08-03 16:55:22 +02:00
|
|
|
indent(h, -1);
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(h, "}");
|
|
|
|
}
|
2007-10-03 06:40:13 +02:00
|
|
|
else fprintf(h, "union %s", t->name ? t->name : "");
|
2002-07-16 05:20:45 +02:00
|
|
|
break;
|
2009-02-23 14:48:11 +01:00
|
|
|
case TYPE_POINTER:
|
2018-10-05 23:57:51 +02:00
|
|
|
{
|
2019-08-18 03:07:05 +02:00
|
|
|
write_type_left(h, type_pointer_get_ref(t), name_type, declonly, FALSE);
|
2019-07-05 23:51:32 +02:00
|
|
|
write_pointer_left(h, type_pointer_get_ref_type(t));
|
2019-08-18 03:07:06 +02:00
|
|
|
if (ds->qualifier & TYPE_QUALIFIER_CONST) fprintf(h, "const ");
|
2006-07-21 21:10:21 +02:00
|
|
|
break;
|
2018-10-05 23:57:51 +02:00
|
|
|
}
|
2009-02-23 14:48:11 +01:00
|
|
|
case TYPE_ARRAY:
|
2009-03-05 09:21:35 +01:00
|
|
|
if (t->name && type_array_is_decl_as_ptr(t))
|
2009-02-23 14:48:11 +01:00
|
|
|
fprintf(h, "%s", t->name);
|
|
|
|
else
|
|
|
|
{
|
2019-08-18 03:07:05 +02:00
|
|
|
write_type_left(h, type_array_get_element(t), name_type, declonly, !type_array_is_decl_as_ptr(t));
|
2009-03-05 09:21:35 +01:00
|
|
|
if (type_array_is_decl_as_ptr(t))
|
2019-07-05 23:51:31 +02:00
|
|
|
write_pointer_left(h, type_array_get_element_type(t));
|
2009-02-23 14:48:11 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-08-18 03:07:05 +02:00
|
|
|
case TYPE_FUNCTION:
|
|
|
|
{
|
|
|
|
write_type_left(h, type_function_get_ret(t), name_type, declonly, TRUE);
|
|
|
|
|
|
|
|
/* A pointer to a function has to write the calling convention inside
|
|
|
|
* the parentheses. There's no way to handle that here, so we have to
|
|
|
|
* use an extra parameter to tell us whether to write the calling
|
|
|
|
* convention or not. */
|
|
|
|
if (write_callconv)
|
|
|
|
{
|
|
|
|
const char *callconv = get_attrp(t->attrs, ATTR_CALLCONV);
|
|
|
|
if (!callconv && is_object_interface) callconv = "STDMETHODCALLTYPE";
|
|
|
|
if (callconv) fprintf(h, " %s ", callconv);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-02-23 14:48:11 +01:00
|
|
|
case TYPE_BASIC:
|
2009-03-12 23:04:35 +01:00
|
|
|
if (type_basic_get_type(t) != TYPE_BASIC_INT32 &&
|
2009-11-21 14:24:02 +01:00
|
|
|
type_basic_get_type(t) != TYPE_BASIC_INT64 &&
|
2018-11-01 15:02:28 +01:00
|
|
|
type_basic_get_type(t) != TYPE_BASIC_LONG &&
|
2009-03-12 23:04:35 +01:00
|
|
|
type_basic_get_type(t) != TYPE_BASIC_HYPER)
|
2009-03-05 09:21:51 +01:00
|
|
|
{
|
|
|
|
if (type_basic_get_sign(t) < 0) fprintf(h, "signed ");
|
|
|
|
else if (type_basic_get_sign(t) > 0) fprintf(h, "unsigned ");
|
|
|
|
}
|
|
|
|
switch (type_basic_get_type(t))
|
|
|
|
{
|
|
|
|
case TYPE_BASIC_INT8: fprintf(h, "small"); break;
|
|
|
|
case TYPE_BASIC_INT16: fprintf(h, "short"); break;
|
|
|
|
case TYPE_BASIC_INT: fprintf(h, "int"); break;
|
2009-11-07 15:54:56 +01:00
|
|
|
case TYPE_BASIC_INT3264: fprintf(h, "__int3264"); break;
|
2009-03-05 09:21:51 +01:00
|
|
|
case TYPE_BASIC_BYTE: fprintf(h, "byte"); break;
|
|
|
|
case TYPE_BASIC_CHAR: fprintf(h, "char"); break;
|
|
|
|
case TYPE_BASIC_WCHAR: fprintf(h, "wchar_t"); break;
|
|
|
|
case TYPE_BASIC_FLOAT: fprintf(h, "float"); break;
|
|
|
|
case TYPE_BASIC_DOUBLE: fprintf(h, "double"); break;
|
|
|
|
case TYPE_BASIC_ERROR_STATUS_T: fprintf(h, "error_status_t"); break;
|
|
|
|
case TYPE_BASIC_HANDLE: fprintf(h, "handle_t"); break;
|
2009-03-12 23:04:35 +01:00
|
|
|
case TYPE_BASIC_INT32:
|
2018-11-01 15:02:28 +01:00
|
|
|
if (type_basic_get_sign(t) > 0)
|
|
|
|
fprintf(h, "UINT32");
|
|
|
|
else
|
|
|
|
fprintf(h, "INT32");
|
|
|
|
break;
|
|
|
|
case TYPE_BASIC_LONG:
|
2009-03-12 23:04:35 +01:00
|
|
|
if (type_basic_get_sign(t) > 0)
|
|
|
|
fprintf(h, "ULONG");
|
|
|
|
else
|
|
|
|
fprintf(h, "LONG");
|
|
|
|
break;
|
2009-11-21 14:24:02 +01:00
|
|
|
case TYPE_BASIC_INT64:
|
|
|
|
if (type_basic_get_sign(t) > 0)
|
|
|
|
fprintf(h, "UINT64");
|
|
|
|
else
|
|
|
|
fprintf(h, "INT64");
|
|
|
|
break;
|
2009-03-05 09:21:51 +01:00
|
|
|
case TYPE_BASIC_HYPER:
|
|
|
|
if (type_basic_get_sign(t) > 0)
|
|
|
|
fprintf(h, "MIDL_uhyper");
|
|
|
|
else
|
|
|
|
fprintf(h, "hyper");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2009-02-23 14:48:11 +01:00
|
|
|
case TYPE_INTERFACE:
|
|
|
|
case TYPE_MODULE:
|
|
|
|
case TYPE_COCLASS:
|
2021-02-19 12:03:58 +01:00
|
|
|
fprintf(h, "%s", type_get_qualified_name(t, name_type));
|
2009-02-23 14:48:11 +01:00
|
|
|
break;
|
2021-01-27 21:20:45 +01:00
|
|
|
case TYPE_RUNTIMECLASS:
|
2021-03-09 20:41:18 +01:00
|
|
|
fprintf(h, "%s", type_get_name(type_runtimeclass_get_default_iface(t, TRUE), name_type));
|
2021-01-27 21:20:45 +01:00
|
|
|
break;
|
2021-02-18 10:38:59 +01:00
|
|
|
case TYPE_DELEGATE:
|
2021-02-19 12:03:58 +01:00
|
|
|
fprintf(h, "%s", type_get_qualified_name(type_delegate_get_iface(t), name_type));
|
2021-02-18 10:38:59 +01:00
|
|
|
break;
|
2009-03-05 09:21:51 +01:00
|
|
|
case TYPE_VOID:
|
|
|
|
fprintf(h, "void");
|
|
|
|
break;
|
2009-11-07 15:55:09 +01:00
|
|
|
case TYPE_BITFIELD:
|
2019-08-16 03:13:19 +02:00
|
|
|
{
|
|
|
|
const decl_spec_t ds = {.type = type_bitfield_get_field(t)};
|
2019-08-18 03:07:05 +02:00
|
|
|
write_type_left(h, &ds, name_type, declonly, TRUE);
|
2009-11-07 15:55:09 +01:00
|
|
|
break;
|
2019-08-16 03:13:19 +02:00
|
|
|
}
|
2009-02-23 14:48:11 +01:00
|
|
|
case TYPE_ALIAS:
|
2020-11-04 19:49:29 +01:00
|
|
|
{
|
|
|
|
const decl_spec_t *ds = type_alias_get_aliasee(t);
|
|
|
|
int in_namespace = ds && ds->type && ds->type->namespace && !is_global_namespace(ds->type->namespace);
|
|
|
|
if (!in_namespace) fprintf(h, "%s", t->name);
|
|
|
|
else write_type_left(h, ds, name_type, declonly, write_callconv);
|
2009-02-23 14:48:11 +01:00
|
|
|
break;
|
2020-11-04 19:49:29 +01:00
|
|
|
}
|
2021-02-11 17:37:27 +01:00
|
|
|
case TYPE_PARAMETERIZED_TYPE:
|
2021-02-25 14:16:02 +01:00
|
|
|
{
|
|
|
|
type_t *iface = type_parameterized_type_get_real_type(t);
|
|
|
|
if (type_get_type(iface) == TYPE_DELEGATE) iface = type_delegate_get_iface(iface);
|
|
|
|
args = format_parameterized_type_args(t, "", "_logical");
|
|
|
|
fprintf(h, "%s<%s>", iface->name, args);
|
|
|
|
free(args);
|
|
|
|
break;
|
|
|
|
}
|
2021-02-11 17:37:27 +01:00
|
|
|
case TYPE_PARAMETER:
|
2021-02-25 14:16:02 +01:00
|
|
|
fprintf(h, "%s_abi", t->name);
|
|
|
|
break;
|
|
|
|
case TYPE_APICONTRACT:
|
2020-12-01 15:01:56 +01:00
|
|
|
/* shouldn't be here */
|
|
|
|
assert(0);
|
|
|
|
break;
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
void write_type_right(FILE *h, type_t *t, int is_field)
|
|
|
|
{
|
2007-10-03 06:40:13 +02:00
|
|
|
if (!h) return;
|
2018-10-05 23:57:51 +02:00
|
|
|
if (type_is_alias(t)) return;
|
2007-10-03 06:40:13 +02:00
|
|
|
|
2009-11-07 15:55:09 +01:00
|
|
|
switch (type_get_type(t))
|
|
|
|
{
|
|
|
|
case TYPE_ARRAY:
|
2018-10-05 23:57:51 +02:00
|
|
|
{
|
2019-07-05 23:51:31 +02:00
|
|
|
type_t *elem = type_array_get_element_type(t);
|
2018-10-05 23:57:51 +02:00
|
|
|
if (type_array_is_decl_as_ptr(t))
|
|
|
|
{
|
2019-08-18 03:07:05 +02:00
|
|
|
if (decl_needs_parens(elem))
|
2018-10-05 23:57:51 +02:00
|
|
|
fprintf(h, ")");
|
|
|
|
}
|
|
|
|
else
|
2009-11-07 15:55:09 +01:00
|
|
|
{
|
|
|
|
if (is_conformant_array(t))
|
|
|
|
fprintf(h, "[%s]", is_field ? "1" : "");
|
2018-10-05 23:57:51 +02:00
|
|
|
else
|
2009-11-07 15:55:09 +01:00
|
|
|
fprintf(h, "[%u]", type_array_get_dim(t));
|
2007-06-06 03:50:31 +02:00
|
|
|
}
|
2018-10-05 23:57:51 +02:00
|
|
|
write_type_right(h, elem, FALSE);
|
2009-11-07 15:55:09 +01:00
|
|
|
break;
|
2018-10-05 23:57:51 +02:00
|
|
|
}
|
2019-08-18 03:07:05 +02:00
|
|
|
case TYPE_FUNCTION:
|
|
|
|
{
|
|
|
|
const var_list_t *args = type_function_get_args(t);
|
|
|
|
fputc('(', h);
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
if (args) write_args(h, args, NULL, 0, FALSE, NAME_DEFAULT);
|
2019-08-18 03:07:05 +02:00
|
|
|
else
|
|
|
|
fprintf(h, "void");
|
|
|
|
fputc(')', h);
|
|
|
|
write_type_right(h, type_function_get_rettype(t), FALSE);
|
|
|
|
break;
|
|
|
|
}
|
2018-10-05 23:57:51 +02:00
|
|
|
case TYPE_POINTER:
|
|
|
|
{
|
2019-07-05 23:51:32 +02:00
|
|
|
type_t *ref = type_pointer_get_ref_type(t);
|
2019-08-18 03:07:05 +02:00
|
|
|
if (decl_needs_parens(ref))
|
2018-10-05 23:57:51 +02:00
|
|
|
fprintf(h, ")");
|
|
|
|
write_type_right(h, ref, FALSE);
|
|
|
|
break;
|
|
|
|
}
|
2009-11-07 15:55:09 +01:00
|
|
|
case TYPE_BITFIELD:
|
2010-03-26 11:42:28 +01:00
|
|
|
fprintf(h, " : %u", type_bitfield_get_bits(t)->cval);
|
2009-11-07 15:55:09 +01:00
|
|
|
break;
|
|
|
|
case TYPE_VOID:
|
|
|
|
case TYPE_BASIC:
|
|
|
|
case TYPE_ENUM:
|
|
|
|
case TYPE_STRUCT:
|
|
|
|
case TYPE_ENCAPSULATED_UNION:
|
|
|
|
case TYPE_UNION:
|
|
|
|
case TYPE_ALIAS:
|
|
|
|
case TYPE_MODULE:
|
|
|
|
case TYPE_COCLASS:
|
|
|
|
case TYPE_INTERFACE:
|
2021-01-27 21:20:45 +01:00
|
|
|
case TYPE_RUNTIMECLASS:
|
2021-02-18 10:38:59 +01:00
|
|
|
case TYPE_DELEGATE:
|
2021-02-11 17:37:27 +01:00
|
|
|
case TYPE_PARAMETERIZED_TYPE:
|
|
|
|
case TYPE_PARAMETER:
|
2021-02-25 14:16:02 +01:00
|
|
|
break;
|
|
|
|
case TYPE_APICONTRACT:
|
2020-12-01 15:01:56 +01:00
|
|
|
/* not supposed to be here */
|
|
|
|
assert(0);
|
|
|
|
break;
|
2007-06-06 03:50:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
static void write_type_v(FILE *h, const decl_spec_t *ds, int is_field, int declonly, const char *name, enum name_type name_type)
|
2007-06-06 03:50:31 +02:00
|
|
|
{
|
2019-08-18 03:07:05 +02:00
|
|
|
type_t *t = ds->type;
|
2008-04-02 13:56:38 +02:00
|
|
|
|
2019-08-18 03:07:05 +02:00
|
|
|
if (!h) return;
|
2009-11-07 15:55:13 +01:00
|
|
|
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
if (t) write_type_left(h, ds, name_type, declonly, TRUE);
|
2009-11-07 15:55:13 +01:00
|
|
|
|
2019-08-18 03:07:05 +02:00
|
|
|
if (name) fprintf(h, "%s%s", !t || needs_space_after(t) ? " " : "", name );
|
2009-11-07 15:55:13 +01:00
|
|
|
|
2019-08-18 03:07:05 +02:00
|
|
|
if (t)
|
|
|
|
write_type_right(h, t, is_field);
|
2007-06-06 03:50:31 +02:00
|
|
|
}
|
|
|
|
|
2019-08-20 04:17:36 +02:00
|
|
|
static void write_type_definition(FILE *f, type_t *t, int declonly)
|
2015-08-07 15:41:55 +02:00
|
|
|
{
|
|
|
|
int in_namespace = t->namespace && !is_global_namespace(t->namespace);
|
|
|
|
int save_written = t->written;
|
2019-08-16 03:13:19 +02:00
|
|
|
decl_spec_t ds = {.type = t};
|
2020-12-01 15:01:57 +01:00
|
|
|
expr_t *contract = get_attrp(t->attrs, ATTR_CONTRACT);
|
2015-08-07 15:41:55 +02:00
|
|
|
|
2020-12-01 15:01:57 +01:00
|
|
|
if (contract) write_apicontract_guard_start(f, contract);
|
2015-08-07 15:41:55 +02:00
|
|
|
if(in_namespace) {
|
|
|
|
fprintf(f, "#ifdef __cplusplus\n");
|
|
|
|
fprintf(f, "} /* extern \"C\" */\n");
|
|
|
|
write_namespace_start(f, t->namespace);
|
|
|
|
}
|
|
|
|
indent(f, 0);
|
2019-08-20 04:17:36 +02:00
|
|
|
write_type_left(f, &ds, NAME_DEFAULT, declonly, TRUE);
|
2015-08-07 15:41:55 +02:00
|
|
|
fprintf(f, ";\n");
|
|
|
|
if(in_namespace) {
|
|
|
|
t->written = save_written;
|
|
|
|
write_namespace_end(f, t->namespace);
|
|
|
|
fprintf(f, "extern \"C\" {\n");
|
|
|
|
fprintf(f, "#else\n");
|
2019-08-20 04:17:36 +02:00
|
|
|
write_type_left(f, &ds, NAME_C, declonly, TRUE);
|
2015-08-07 15:41:55 +02:00
|
|
|
fprintf(f, ";\n");
|
2021-02-26 09:43:06 +01:00
|
|
|
if (winrt_mode) write_widl_using_macros(f, t);
|
2015-08-07 15:41:55 +02:00
|
|
|
fprintf(f, "#endif\n\n");
|
|
|
|
}
|
2020-12-01 15:01:57 +01:00
|
|
|
if (contract) write_apicontract_guard_end(f, contract);
|
2015-08-07 15:41:55 +02:00
|
|
|
}
|
|
|
|
|
2019-08-16 03:13:18 +02:00
|
|
|
void write_type_decl(FILE *f, const decl_spec_t *t, const char *name)
|
2007-10-03 06:39:38 +02:00
|
|
|
{
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
write_type_v(f, t, FALSE, TRUE, name, NAME_DEFAULT);
|
2007-10-03 06:39:38 +02:00
|
|
|
}
|
|
|
|
|
2019-08-16 03:13:19 +02:00
|
|
|
void write_type_decl_left(FILE *f, const decl_spec_t *ds)
|
2007-10-03 06:39:38 +02:00
|
|
|
{
|
2019-08-18 03:07:05 +02:00
|
|
|
write_type_left(f, ds, NAME_DEFAULT, TRUE, TRUE);
|
2007-10-03 06:39:38 +02:00
|
|
|
}
|
|
|
|
|
2005-09-12 22:13:40 +02:00
|
|
|
static int user_type_registered(const char *name)
|
|
|
|
{
|
2007-06-14 01:13:04 +02:00
|
|
|
user_type_t *ut;
|
|
|
|
LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
|
2005-09-12 22:13:40 +02:00
|
|
|
if (!strcmp(name, ut->name))
|
2007-06-14 01:13:04 +02:00
|
|
|
return 1;
|
2005-09-12 22:13:40 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-28 02:38:13 +02:00
|
|
|
static int context_handle_registered(const char *name)
|
|
|
|
{
|
|
|
|
context_handle_t *ch;
|
|
|
|
LIST_FOR_EACH_ENTRY(ch, &context_handle_list, context_handle_t, entry)
|
|
|
|
if (!strcmp(name, ch->name))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-27 15:03:17 +01:00
|
|
|
static int generic_handle_registered(const char *name)
|
|
|
|
{
|
|
|
|
generic_handle_t *gh;
|
|
|
|
LIST_FOR_EACH_ENTRY(gh, &generic_handle_list, generic_handle_t, entry)
|
|
|
|
if (!strcmp(name, gh->name))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-01 20:21:37 +02:00
|
|
|
unsigned int get_context_handle_offset( const type_t *type )
|
|
|
|
{
|
|
|
|
context_handle_t *ch;
|
|
|
|
unsigned int index = 0;
|
|
|
|
|
|
|
|
while (!is_attr( type->attrs, ATTR_CONTEXTHANDLE ))
|
|
|
|
{
|
2019-08-15 04:45:50 +02:00
|
|
|
if (type_is_alias( type )) type = type_alias_get_aliasee_type( type );
|
2019-07-05 23:51:32 +02:00
|
|
|
else if (is_ptr( type )) type = type_pointer_get_ref_type( type );
|
2011-06-01 20:21:37 +02:00
|
|
|
else error( "internal error: %s is not a context handle\n", type->name );
|
|
|
|
}
|
|
|
|
LIST_FOR_EACH_ENTRY( ch, &context_handle_list, context_handle_t, entry )
|
|
|
|
{
|
|
|
|
if (!strcmp( type->name, ch->name )) return index;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
error( "internal error: %s is not registered as a context handle\n", type->name );
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2011-06-01 21:06:14 +02:00
|
|
|
unsigned int get_generic_handle_offset( const type_t *type )
|
|
|
|
{
|
|
|
|
generic_handle_t *gh;
|
|
|
|
unsigned int index = 0;
|
|
|
|
|
|
|
|
while (!is_attr( type->attrs, ATTR_HANDLE ))
|
|
|
|
{
|
2019-08-15 04:45:50 +02:00
|
|
|
if (type_is_alias( type )) type = type_alias_get_aliasee_type( type );
|
2019-07-05 23:51:32 +02:00
|
|
|
else if (is_ptr( type )) type = type_pointer_get_ref_type( type );
|
2011-06-01 21:06:14 +02:00
|
|
|
else error( "internal error: %s is not a generic handle\n", type->name );
|
|
|
|
}
|
|
|
|
LIST_FOR_EACH_ENTRY( gh, &generic_handle_list, generic_handle_t, entry )
|
|
|
|
{
|
|
|
|
if (!strcmp( type->name, gh->name )) return index;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
error( "internal error: %s is not registered as a generic handle\n", type->name );
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2008-03-27 15:03:17 +01:00
|
|
|
/* check for types which require additional prototypes to be generated in the
|
|
|
|
* header */
|
2019-01-29 15:46:30 +01:00
|
|
|
void check_for_additional_prototype_types(type_t *type)
|
|
|
|
{
|
|
|
|
if (!type) return;
|
|
|
|
for (;;) {
|
|
|
|
const char *name = type->name;
|
|
|
|
if (type->user_types_registered) break;
|
|
|
|
type->user_types_registered = 1;
|
|
|
|
if (is_attr(type->attrs, ATTR_CONTEXTHANDLE)) {
|
|
|
|
if (!context_handle_registered(name))
|
|
|
|
{
|
|
|
|
context_handle_t *ch = xmalloc(sizeof(*ch));
|
|
|
|
ch->name = xstrdup(name);
|
|
|
|
list_add_tail(&context_handle_list, &ch->entry);
|
2008-03-27 15:03:17 +01:00
|
|
|
}
|
2019-01-29 15:46:30 +01:00
|
|
|
/* don't carry on parsing fields within this type */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((type_get_type(type) != TYPE_BASIC ||
|
|
|
|
type_basic_get_type(type) != TYPE_BASIC_HANDLE) &&
|
|
|
|
is_attr(type->attrs, ATTR_HANDLE)) {
|
|
|
|
if (!generic_handle_registered(name))
|
|
|
|
{
|
|
|
|
generic_handle_t *gh = xmalloc(sizeof(*gh));
|
|
|
|
gh->name = xstrdup(name);
|
|
|
|
list_add_tail(&generic_handle_list, &gh->entry);
|
2005-09-12 22:13:40 +02:00
|
|
|
}
|
2019-01-29 15:46:30 +01:00
|
|
|
/* don't carry on parsing fields within this type */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (is_attr(type->attrs, ATTR_WIREMARSHAL)) {
|
|
|
|
if (!user_type_registered(name))
|
2005-09-12 22:13:40 +02:00
|
|
|
{
|
2019-01-29 15:46:30 +01:00
|
|
|
user_type_t *ut = xmalloc(sizeof *ut);
|
|
|
|
ut->name = xstrdup(name);
|
|
|
|
list_add_tail(&user_type_list, &ut->entry);
|
2005-09-12 22:13:40 +02:00
|
|
|
}
|
2019-01-29 15:46:30 +01:00
|
|
|
/* don't carry on parsing fields within this type as we are already
|
|
|
|
* using a wire marshaled type */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (type_is_complete(type))
|
|
|
|
{
|
|
|
|
var_list_t *vars;
|
|
|
|
const var_t *v;
|
|
|
|
switch (type_get_type_detect_alias(type))
|
|
|
|
{
|
|
|
|
case TYPE_ENUM:
|
|
|
|
vars = type_enum_get_values(type);
|
|
|
|
break;
|
|
|
|
case TYPE_STRUCT:
|
|
|
|
vars = type_struct_get_fields(type);
|
|
|
|
break;
|
|
|
|
case TYPE_UNION:
|
|
|
|
vars = type_union_get_cases(type);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
vars = NULL;
|
2009-01-06 00:34:58 +01:00
|
|
|
break;
|
2019-01-29 15:46:30 +01:00
|
|
|
}
|
|
|
|
if (vars) LIST_FOR_EACH_ENTRY( v, vars, const var_t, entry )
|
2019-07-05 23:49:49 +02:00
|
|
|
check_for_additional_prototype_types(v->declspec.type);
|
2005-09-12 22:13:40 +02:00
|
|
|
}
|
2019-01-29 15:46:30 +01:00
|
|
|
|
|
|
|
if (type_is_alias(type))
|
2019-08-15 04:45:50 +02:00
|
|
|
type = type_alias_get_aliasee_type(type);
|
2019-01-29 15:46:30 +01:00
|
|
|
else if (is_ptr(type))
|
2019-07-05 23:51:32 +02:00
|
|
|
type = type_pointer_get_ref_type(type);
|
2019-01-29 15:46:30 +01:00
|
|
|
else if (is_array(type))
|
2019-07-05 23:51:31 +02:00
|
|
|
type = type_array_get_element_type(type);
|
2019-01-29 15:46:30 +01:00
|
|
|
else
|
|
|
|
break;
|
2005-09-12 22:13:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-09 13:51:16 +01:00
|
|
|
static int write_serialize_function_decl(FILE *header, const type_t *type)
|
|
|
|
{
|
|
|
|
write_serialize_functions(header, type, NULL);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int serializable_exists(FILE *header, const type_t *type)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int for_each_serializable(const statement_list_t *stmts, FILE *header,
|
|
|
|
int (*proc)(FILE*, const type_t*))
|
|
|
|
{
|
|
|
|
statement_t *stmt, *iface_stmt;
|
|
|
|
statement_list_t *iface_stmts;
|
2021-02-17 19:33:33 +01:00
|
|
|
typeref_t *ref;
|
2018-11-09 13:51:16 +01:00
|
|
|
|
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, statement_t, entry )
|
|
|
|
{
|
|
|
|
if (stmt->type != STMT_TYPE || type_get_type(stmt->u.type) != TYPE_INTERFACE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
iface_stmts = type_iface_get_stmts(stmt->u.type);
|
|
|
|
if (iface_stmts) LIST_FOR_EACH_ENTRY( iface_stmt, iface_stmts, statement_t, entry )
|
|
|
|
{
|
|
|
|
if (iface_stmt->type != STMT_TYPEDEF) continue;
|
2021-02-17 19:33:33 +01:00
|
|
|
if (iface_stmt->u.type_list) LIST_FOR_EACH_ENTRY(ref, iface_stmt->u.type_list, typeref_t, entry)
|
2018-11-09 13:51:16 +01:00
|
|
|
{
|
2021-02-17 19:33:33 +01:00
|
|
|
if (!is_attr(ref->type->attrs, ATTR_ENCODE)
|
|
|
|
&& !is_attr(ref->type->attrs, ATTR_DECODE))
|
2018-11-09 13:51:16 +01:00
|
|
|
continue;
|
2021-02-17 19:33:33 +01:00
|
|
|
if (!proc(header, ref->type))
|
2018-11-09 13:51:16 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
static void write_user_types(FILE *header)
|
2005-09-12 22:13:40 +02:00
|
|
|
{
|
2007-06-14 01:13:04 +02:00
|
|
|
user_type_t *ut;
|
|
|
|
LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
|
2005-09-12 22:13:40 +02:00
|
|
|
{
|
|
|
|
const char *name = ut->name;
|
2006-11-08 23:43:28 +01:00
|
|
|
fprintf(header, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name, name);
|
2006-11-08 23:43:45 +01:00
|
|
|
fprintf(header, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name, name);
|
2006-11-08 23:44:00 +01:00
|
|
|
fprintf(header, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name, name);
|
2006-11-08 23:44:10 +01:00
|
|
|
fprintf(header, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name, name);
|
2005-09-12 22:13:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
static void write_context_handle_rundowns(FILE *header)
|
2007-09-28 02:38:13 +02:00
|
|
|
{
|
|
|
|
context_handle_t *ch;
|
|
|
|
LIST_FOR_EACH_ENTRY(ch, &context_handle_list, context_handle_t, entry)
|
|
|
|
{
|
|
|
|
const char *name = ch->name;
|
|
|
|
fprintf(header, "void __RPC_USER %s_rundown(%s);\n", name, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
static void write_generic_handle_routines(FILE *header)
|
2008-03-27 15:03:17 +01:00
|
|
|
{
|
|
|
|
generic_handle_t *gh;
|
|
|
|
LIST_FOR_EACH_ENTRY(gh, &generic_handle_list, generic_handle_t, entry)
|
|
|
|
{
|
|
|
|
const char *name = gh->name;
|
|
|
|
fprintf(header, "handle_t __RPC_USER %s_bind(%s);\n", name, name);
|
|
|
|
fprintf(header, "void __RPC_USER %s_unbind(%s, handle_t);\n", name, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-20 04:17:36 +02:00
|
|
|
static void write_typedef(FILE *header, type_t *type, int declonly)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2021-03-23 18:20:47 +01:00
|
|
|
type_t *t = type_alias_get_aliasee_type(type);
|
|
|
|
if (winrt_mode && t->namespace && !is_global_namespace(t->namespace))
|
|
|
|
{
|
|
|
|
fprintf(header, "#ifdef __cplusplus\n");
|
|
|
|
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);
|
|
|
|
fprintf(header, ";\n");
|
|
|
|
if (winrt_mode && t->namespace && !is_global_namespace(t->namespace))
|
|
|
|
{
|
|
|
|
write_namespace_end(header, t->namespace);
|
|
|
|
fprintf(header, "#else /* __cplusplus */\n");
|
|
|
|
fprintf(header, "typedef ");
|
|
|
|
write_type_v(header, type_alias_get_aliasee(type), FALSE, declonly, type->c_name, NAME_C);
|
|
|
|
fprintf(header, ";\n");
|
|
|
|
fprintf(header, "#endif /* __cplusplus */\n\n");
|
|
|
|
}
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
2008-04-30 16:23:23 +02:00
|
|
|
int is_const_decl(const var_t *var)
|
|
|
|
{
|
2019-08-18 03:07:06 +02:00
|
|
|
const decl_spec_t *t;
|
2008-04-30 16:23:23 +02:00
|
|
|
/* strangely, MIDL accepts a const attribute on any pointer in the
|
|
|
|
* declaration to mean that data isn't being instantiated. this appears
|
|
|
|
* to be a bug, but there is no benefit to being incompatible with MIDL,
|
|
|
|
* so we'll do the same thing */
|
2019-08-18 03:07:06 +02:00
|
|
|
for (t = &var->declspec; ; )
|
2008-04-30 16:23:23 +02:00
|
|
|
{
|
2019-08-18 03:07:06 +02:00
|
|
|
if (t->qualifier & TYPE_QUALIFIER_CONST)
|
2008-04-30 16:23:23 +02:00
|
|
|
return TRUE;
|
2019-08-18 03:07:06 +02:00
|
|
|
else if (is_ptr(t->type))
|
|
|
|
t = type_pointer_get_ref(t->type);
|
2008-04-30 16:23:23 +02:00
|
|
|
else break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2002-11-30 02:49:46 +01:00
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
static void write_declaration(FILE *header, const var_t *v)
|
2002-11-30 02:49:46 +01:00
|
|
|
{
|
2008-04-30 16:23:23 +02:00
|
|
|
if (is_const_decl(v) && v->eval)
|
|
|
|
{
|
|
|
|
fprintf(header, "#define %s (", v->name);
|
2008-09-15 16:46:01 +02:00
|
|
|
write_expr(header, v->eval, 0, 1, NULL, NULL, "");
|
2008-04-30 16:23:23 +02:00
|
|
|
fprintf(header, ")\n\n");
|
|
|
|
}
|
2008-12-29 13:06:35 +01:00
|
|
|
else
|
2008-04-30 16:23:23 +02:00
|
|
|
{
|
2019-07-05 23:49:49 +02:00
|
|
|
switch (v->declspec.stgclass)
|
2008-04-30 16:23:23 +02:00
|
|
|
{
|
|
|
|
case STG_NONE:
|
|
|
|
case STG_REGISTER: /* ignored */
|
|
|
|
break;
|
|
|
|
case STG_STATIC:
|
|
|
|
fprintf(header, "static ");
|
|
|
|
break;
|
|
|
|
case STG_EXTERN:
|
|
|
|
fprintf(header, "extern ");
|
|
|
|
break;
|
|
|
|
}
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
write_type_v(header, &v->declspec, FALSE, v->declonly, v->name, NAME_DEFAULT);
|
2008-04-30 16:23:23 +02:00
|
|
|
fprintf(header, ";\n\n");
|
|
|
|
}
|
2002-11-30 02:49:46 +01:00
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
static void write_library(FILE *header, const typelib_t *typelib)
|
2007-01-22 14:20:36 +01:00
|
|
|
{
|
2008-04-24 20:06:28 +02:00
|
|
|
const UUID *uuid = get_attrp(typelib->attrs, ATTR_UUID);
|
2005-03-05 11:49:22 +01:00
|
|
|
fprintf(header, "\n");
|
2008-04-24 20:06:28 +02:00
|
|
|
write_guid(header, "LIBID", typelib->name, uuid);
|
2005-03-05 11:49:22 +01:00
|
|
|
fprintf(header, "\n");
|
|
|
|
}
|
|
|
|
|
2005-12-12 12:14:03 +01:00
|
|
|
|
2008-03-27 15:03:17 +01:00
|
|
|
const type_t* get_explicit_generic_handle_type(const var_t* var)
|
|
|
|
{
|
|
|
|
const type_t *t;
|
2019-07-05 23:49:49 +02:00
|
|
|
for (t = var->declspec.type;
|
2009-03-05 09:21:42 +01:00
|
|
|
is_ptr(t) || type_is_alias(t);
|
2019-08-15 04:45:50 +02:00
|
|
|
t = type_is_alias(t) ? type_alias_get_aliasee_type(t) : type_pointer_get_ref_type(t))
|
2009-03-08 00:24:00 +01:00
|
|
|
if ((type_get_type_detect_alias(t) != TYPE_BASIC || type_basic_get_type(t) != TYPE_BASIC_HANDLE) &&
|
2009-03-05 09:21:42 +01:00
|
|
|
is_attr(t->attrs, ATTR_HANDLE))
|
2008-03-27 15:03:17 +01:00
|
|
|
return t;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-31 13:30:04 +02:00
|
|
|
const var_t *get_func_handle_var( const type_t *iface, const var_t *func,
|
|
|
|
unsigned char *explicit_fc, unsigned char *implicit_fc )
|
2008-03-27 15:03:17 +01:00
|
|
|
{
|
2011-05-31 13:30:04 +02:00
|
|
|
const var_t *var;
|
2019-08-14 04:08:03 +02:00
|
|
|
const var_list_t *args = type_function_get_args( func->declspec.type );
|
2008-03-27 15:03:17 +01:00
|
|
|
|
2011-05-31 13:30:04 +02:00
|
|
|
*explicit_fc = *implicit_fc = 0;
|
|
|
|
if (args) LIST_FOR_EACH_ENTRY( var, args, const var_t, entry )
|
|
|
|
{
|
|
|
|
if (!is_attr( var->attrs, ATTR_IN ) && is_attr( var->attrs, ATTR_OUT )) continue;
|
2019-07-05 23:49:49 +02:00
|
|
|
if (type_get_type( var->declspec.type ) == TYPE_BASIC && type_basic_get_type( var->declspec.type ) == TYPE_BASIC_HANDLE)
|
2011-05-31 13:30:04 +02:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
*explicit_fc = FC_BIND_PRIMITIVE;
|
2008-03-27 15:03:17 +01:00
|
|
|
return var;
|
2011-05-31 13:30:04 +02:00
|
|
|
}
|
|
|
|
if (get_explicit_generic_handle_type( var ))
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
*explicit_fc = FC_BIND_GENERIC;
|
2008-04-20 23:15:29 +02:00
|
|
|
return var;
|
2011-05-31 13:30:04 +02:00
|
|
|
}
|
2019-07-05 23:49:49 +02:00
|
|
|
if (is_context_handle( var->declspec.type ))
|
2011-05-31 13:30:04 +02:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
*explicit_fc = FC_BIND_CONTEXT;
|
2011-05-31 13:30:04 +02:00
|
|
|
return var;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((var = get_attrp( iface->attrs, ATTR_IMPLICIT_HANDLE )))
|
|
|
|
{
|
2019-07-05 23:49:49 +02:00
|
|
|
if (type_get_type( var->declspec.type ) == TYPE_BASIC &&
|
|
|
|
type_basic_get_type( var->declspec.type ) == TYPE_BASIC_HANDLE)
|
2018-06-13 04:19:11 +02:00
|
|
|
*implicit_fc = FC_BIND_PRIMITIVE;
|
2011-05-31 13:30:04 +02:00
|
|
|
else
|
2018-06-13 04:19:11 +02:00
|
|
|
*implicit_fc = FC_BIND_GENERIC;
|
2011-05-31 13:30:04 +02:00
|
|
|
return var;
|
|
|
|
}
|
2008-04-20 23:15:29 +02:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
*implicit_fc = FC_AUTO_HANDLE;
|
2008-04-20 23:15:29 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
int has_out_arg_or_return(const var_t *func)
|
2006-03-29 12:42:29 +02:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *var;
|
2006-03-29 12:42:29 +02:00
|
|
|
|
2019-07-05 23:49:49 +02:00
|
|
|
if (!is_void(type_function_get_rettype(func->declspec.type)))
|
2006-03-29 12:42:29 +02:00
|
|
|
return 1;
|
|
|
|
|
2019-08-14 04:08:03 +02:00
|
|
|
if (!type_function_get_args(func->declspec.type))
|
2006-03-29 12:42:29 +02:00
|
|
|
return 0;
|
|
|
|
|
2019-08-14 04:08:03 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( var, type_function_get_args(func->declspec.type), const var_t, entry )
|
2006-03-29 12:42:29 +02:00
|
|
|
if (is_attr(var->attrs, ATTR_OUT))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-12-12 12:14:03 +01:00
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
/********** INTERFACES **********/
|
|
|
|
|
2009-11-25 10:53:49 +01:00
|
|
|
int is_object(const type_t *iface)
|
2002-12-03 20:12:07 +01:00
|
|
|
{
|
2007-01-22 14:20:36 +01:00
|
|
|
const attr_t *attr;
|
2021-02-18 10:38:59 +01:00
|
|
|
if (type_is_defined(iface) && (type_get_type(iface) == TYPE_DELEGATE || type_iface_get_inherit(iface)))
|
2009-11-25 10:53:49 +01:00
|
|
|
return 1;
|
|
|
|
if (iface->attrs) LIST_FOR_EACH_ENTRY( attr, iface->attrs, const attr_t, entry )
|
2007-01-22 14:20:36 +01:00
|
|
|
if (attr->type == ATTR_OBJECT || attr->type == ATTR_ODL) return 1;
|
|
|
|
return 0;
|
2002-12-03 20:12:07 +01:00
|
|
|
}
|
|
|
|
|
2007-01-22 14:20:36 +01:00
|
|
|
int is_local(const attr_list_t *a)
|
2002-12-03 20:12:07 +01:00
|
|
|
{
|
|
|
|
return is_attr(a, ATTR_LOCAL);
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:20:36 +01:00
|
|
|
const var_t *is_callas(const attr_list_t *a)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2002-12-03 20:12:07 +01:00
|
|
|
return get_attrp(a, ATTR_CALLAS);
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
2012-07-27 17:18:04 +02:00
|
|
|
static int is_inherited_method(const type_t *iface, const var_t *func)
|
|
|
|
{
|
|
|
|
while ((iface = type_iface_get_inherit(iface)))
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(iface))
|
|
|
|
{
|
|
|
|
const var_t *funccmp = stmt->u.var;
|
|
|
|
|
|
|
|
if (!is_callas(func->attrs))
|
|
|
|
{
|
|
|
|
char inherit_name[256];
|
|
|
|
/* compare full name including property prefix */
|
|
|
|
strcpy(inherit_name, get_name(funccmp));
|
|
|
|
if (!strcmp(inherit_name, get_name(func))) return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-13 12:23:22 +02:00
|
|
|
static int is_override_method(const type_t *iface, const type_t *child, const var_t *func)
|
|
|
|
{
|
|
|
|
if (iface == child)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(child))
|
|
|
|
{
|
|
|
|
const var_t *funccmp = stmt->u.var;
|
|
|
|
|
|
|
|
if (!is_callas(func->attrs))
|
|
|
|
{
|
|
|
|
char inherit_name[256];
|
|
|
|
/* compare full name including property prefix */
|
|
|
|
strcpy(inherit_name, get_name(funccmp));
|
|
|
|
if (!strcmp(inherit_name, get_name(func))) return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ((child = type_iface_get_inherit(child)) && child != iface);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-05 17:33:03 +02:00
|
|
|
static int is_aggregate_return(const var_t *func)
|
|
|
|
{
|
2019-07-05 23:49:49 +02:00
|
|
|
enum type_type type = type_get_type(type_function_get_rettype(func->declspec.type));
|
2014-09-05 17:33:03 +02:00
|
|
|
return type == TYPE_STRUCT || type == TYPE_UNION ||
|
2021-01-27 21:20:45 +01:00
|
|
|
type == TYPE_COCLASS || type == TYPE_INTERFACE ||
|
|
|
|
type == TYPE_RUNTIMECLASS;
|
2014-09-05 17:33:03 +02:00
|
|
|
}
|
|
|
|
|
2014-10-13 12:23:22 +02:00
|
|
|
static char *get_vtbl_entry_name(const type_t *iface, const var_t *func)
|
|
|
|
{
|
|
|
|
static char buff[255];
|
|
|
|
if (is_inherited_method(iface, func))
|
|
|
|
sprintf(buff, "%s_%s", iface->name, get_name(func));
|
|
|
|
else
|
|
|
|
sprintf(buff, "%s", get_name(func));
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_method_macro(FILE *header, const type_t *iface, const type_t *child, const char *name)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
const statement_t *stmt;
|
|
|
|
int first_iface = 1;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2009-01-06 00:35:06 +01:00
|
|
|
if (type_iface_get_inherit(iface))
|
2014-10-13 12:23:22 +02:00
|
|
|
write_method_macro(header, type_iface_get_inherit(iface), child, name);
|
2003-07-22 05:18:46 +02:00
|
|
|
|
2009-01-06 00:35:13 +01:00
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(iface))
|
2007-01-22 14:23:08 +01:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
|
|
|
|
if (first_iface)
|
|
|
|
{
|
|
|
|
fprintf(header, "/*** %s methods ***/\n", iface->name);
|
|
|
|
first_iface = 0;
|
|
|
|
}
|
|
|
|
|
2014-10-13 12:23:22 +02:00
|
|
|
if (is_override_method(iface, child, func))
|
|
|
|
continue;
|
|
|
|
|
2017-11-14 03:29:38 +01:00
|
|
|
if (!is_callas(func->attrs)) {
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *arg;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(header, "#define %s_%s(This", name, get_name(func));
|
2019-08-14 04:08:03 +02:00
|
|
|
if (type_function_get_args(func->declspec.type))
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, type_function_get_args(func->declspec.type), const var_t, entry )
|
2008-01-18 12:03:22 +01:00
|
|
|
fprintf(header, ",%s", arg->name);
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(header, ") ");
|
|
|
|
|
2017-11-14 03:29:38 +01:00
|
|
|
if (is_aggregate_return(func))
|
|
|
|
{
|
|
|
|
fprintf(header, "%s_%s_define_WIDL_C_INLINE_WRAPPERS_for_aggregate_return_support\n", name, get_name(func));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-10-13 12:23:22 +02:00
|
|
|
fprintf(header, "(This)->lpVtbl->%s(This", get_vtbl_entry_name(iface, func));
|
2019-08-14 04:08:03 +02:00
|
|
|
if (type_function_get_args(func->declspec.type))
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, type_function_get_args(func->declspec.type), const var_t, entry )
|
2008-01-18 12:03:22 +01:00
|
|
|
fprintf(header, ",%s", arg->name);
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(header, ")\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
void write_args(FILE *h, const var_list_t *args, const char *name, int method, int do_indent, enum name_type name_type)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *arg;
|
2002-12-03 20:12:07 +01:00
|
|
|
int count = 0;
|
2007-01-22 14:26:12 +01:00
|
|
|
|
2003-09-03 22:16:24 +02:00
|
|
|
if (do_indent)
|
|
|
|
{
|
2005-08-03 16:55:22 +02:00
|
|
|
indentation++;
|
|
|
|
indent(h, 0);
|
2003-09-03 22:16:24 +02:00
|
|
|
}
|
2002-12-15 04:01:20 +01:00
|
|
|
if (method == 1) {
|
|
|
|
fprintf(h, "%s* This", name);
|
2002-12-03 20:12:07 +01:00
|
|
|
count++;
|
|
|
|
}
|
2007-01-22 14:26:12 +01:00
|
|
|
if (args) LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry ) {
|
2002-12-15 04:01:20 +01:00
|
|
|
if (count) {
|
2003-09-03 22:16:24 +02:00
|
|
|
if (do_indent)
|
|
|
|
{
|
|
|
|
fprintf(h, ",\n");
|
2005-08-03 16:55:22 +02:00
|
|
|
indent(h, 0);
|
2003-09-03 22:16:24 +02:00
|
|
|
}
|
|
|
|
else fprintf(h, ",");
|
2002-12-15 04:01:20 +01:00
|
|
|
}
|
2019-08-20 04:17:36 +02:00
|
|
|
/* In theory we should be writing the definition using write_type_v(..., arg->declonly),
|
|
|
|
* but that causes redefinition in e.g. proxy files. In fact MIDL disallows
|
|
|
|
* defining UDTs inside of an argument list. */
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
write_type_v(h, &arg->declspec, FALSE, TRUE, arg->name, name_type);
|
2012-07-26 13:20:50 +02:00
|
|
|
if (method == 2) {
|
|
|
|
const expr_t *expr = get_attrp(arg->attrs, ATTR_DEFAULTVALUE);
|
|
|
|
if (expr) {
|
2015-07-26 18:07:37 +02:00
|
|
|
const var_t *tail_arg;
|
|
|
|
|
|
|
|
/* Output default value only if all following arguments also have default value. */
|
|
|
|
LIST_FOR_EACH_ENTRY_REV( tail_arg, args, const var_t, entry ) {
|
|
|
|
if(tail_arg == arg) {
|
2015-11-27 11:00:27 +01:00
|
|
|
expr_t bstr;
|
|
|
|
|
|
|
|
/* Fixup the expression type for a BSTR like midl does. */
|
2019-07-05 23:49:49 +02:00
|
|
|
if (get_type_vt(arg->declspec.type) == VT_BSTR && expr->type == EXPR_STRLIT)
|
2015-11-27 11:00:27 +01:00
|
|
|
{
|
|
|
|
bstr = *expr;
|
|
|
|
bstr.type = EXPR_WSTRLIT;
|
|
|
|
expr = &bstr;
|
|
|
|
}
|
|
|
|
|
2015-07-26 18:07:37 +02:00
|
|
|
fprintf(h, " = ");
|
|
|
|
write_expr( h, expr, 0, 1, NULL, NULL, "" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!get_attrp(tail_arg->attrs, ATTR_DEFAULTVALUE))
|
|
|
|
break;
|
|
|
|
}
|
2012-07-26 13:20:50 +02:00
|
|
|
}
|
|
|
|
}
|
2002-12-03 20:12:07 +01:00
|
|
|
count++;
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
2005-08-03 16:55:22 +02:00
|
|
|
if (do_indent) indentation--;
|
2002-12-15 04:01:20 +01:00
|
|
|
}
|
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void write_cpp_method_def(FILE *header, const type_t *iface)
|
2002-12-15 04:01:20 +01:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
const statement_t *stmt;
|
2003-07-22 05:18:46 +02:00
|
|
|
|
2009-01-06 00:35:13 +01:00
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(iface))
|
2007-01-22 14:23:08 +01:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
if (!is_callas(func->attrs)) {
|
2019-08-16 03:13:19 +02:00
|
|
|
const decl_spec_t *ret = type_function_get_ret(func->declspec.type);
|
2019-07-05 23:49:49 +02:00
|
|
|
const char *callconv = get_attrp(func->declspec.type->attrs, ATTR_CALLCONV);
|
2019-08-14 04:08:03 +02:00
|
|
|
const var_list_t *args = type_function_get_args(func->declspec.type);
|
2017-07-21 13:03:41 +02:00
|
|
|
const var_t *arg;
|
|
|
|
|
2010-08-27 13:52:09 +02:00
|
|
|
if (!callconv) callconv = "STDMETHODCALLTYPE";
|
2017-07-21 13:03:41 +02:00
|
|
|
|
|
|
|
if (is_aggregate_return(func)) {
|
|
|
|
fprintf(header, "#ifdef WIDL_EXPLICIT_AGGREGATE_RETURNS\n");
|
|
|
|
|
|
|
|
indent(header, 0);
|
|
|
|
fprintf(header, "virtual ");
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(header, ret);
|
2017-07-21 13:03:41 +02:00
|
|
|
fprintf(header, "* %s %s(\n", callconv, get_name(func));
|
|
|
|
++indentation;
|
|
|
|
indent(header, 0);
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(header, ret);
|
2017-07-21 13:03:41 +02:00
|
|
|
fprintf(header, " *__ret");
|
|
|
|
--indentation;
|
|
|
|
if (args) {
|
|
|
|
fprintf(header, ",\n");
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
write_args(header, args, iface->name, 2, TRUE, NAME_DEFAULT);
|
2017-07-21 13:03:41 +02:00
|
|
|
}
|
|
|
|
fprintf(header, ") = 0;\n");
|
|
|
|
|
|
|
|
indent(header, 0);
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(header, ret);
|
2017-07-21 13:03:41 +02:00
|
|
|
fprintf(header, " %s %s(\n", callconv, get_name(func));
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
write_args(header, args, iface->name, 2, TRUE, NAME_DEFAULT);
|
2017-07-21 13:03:41 +02:00
|
|
|
fprintf(header, ")\n");
|
|
|
|
indent(header, 0);
|
|
|
|
fprintf(header, "{\n");
|
|
|
|
++indentation;
|
|
|
|
indent(header, 0);
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(header, ret);
|
2017-07-21 13:03:41 +02:00
|
|
|
fprintf(header, " __ret;\n");
|
|
|
|
indent(header, 0);
|
|
|
|
fprintf(header, "return *%s(&__ret", get_name(func));
|
|
|
|
if (args)
|
|
|
|
LIST_FOR_EACH_ENTRY(arg, args, const var_t, entry)
|
|
|
|
fprintf(header, ", %s", arg->name);
|
|
|
|
fprintf(header, ");\n");
|
|
|
|
--indentation;
|
|
|
|
indent(header, 0);
|
|
|
|
fprintf(header, "}\n");
|
|
|
|
|
|
|
|
fprintf(header, "#else\n");
|
|
|
|
}
|
|
|
|
|
2005-08-03 16:55:22 +02:00
|
|
|
indent(header, 0);
|
2002-12-15 04:01:20 +01:00
|
|
|
fprintf(header, "virtual ");
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(header, ret);
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(header, " %s %s(\n", callconv, get_name(func));
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
write_args(header, args, iface->name, 2, TRUE, NAME_DEFAULT);
|
2002-12-15 04:01:20 +01:00
|
|
|
fprintf(header, ") = 0;\n");
|
2017-07-21 13:03:41 +02:00
|
|
|
|
|
|
|
if (is_aggregate_return(func))
|
|
|
|
fprintf(header, "#endif\n");
|
2002-12-15 04:01:20 +01:00
|
|
|
fprintf(header, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 12:23:22 +02:00
|
|
|
static void write_inline_wrappers(FILE *header, const type_t *iface, const type_t *child, const char *name)
|
2012-07-26 11:35:43 +02:00
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
int first_iface = 1;
|
|
|
|
|
|
|
|
if (type_iface_get_inherit(iface))
|
2014-10-13 12:23:22 +02:00
|
|
|
write_inline_wrappers(header, type_iface_get_inherit(iface), child, name);
|
2012-07-26 11:35:43 +02:00
|
|
|
|
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(iface))
|
|
|
|
{
|
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
|
|
|
|
if (first_iface)
|
|
|
|
{
|
|
|
|
fprintf(header, "/*** %s methods ***/\n", iface->name);
|
|
|
|
first_iface = 0;
|
|
|
|
}
|
|
|
|
|
2014-10-13 12:23:22 +02:00
|
|
|
if (is_override_method(iface, child, func))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!is_callas(func->attrs)) {
|
2012-07-26 11:35:43 +02:00
|
|
|
const var_t *arg;
|
|
|
|
|
|
|
|
fprintf(header, "static FORCEINLINE ");
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(header, type_function_get_ret(func->declspec.type));
|
2012-07-26 11:35:43 +02:00
|
|
|
fprintf(header, " %s_%s(", name, get_name(func));
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
write_args(header, type_function_get_args(func->declspec.type), name, 1, FALSE, NAME_C);
|
2012-07-26 11:35:43 +02:00
|
|
|
fprintf(header, ") {\n");
|
2014-09-05 17:33:03 +02:00
|
|
|
++indentation;
|
|
|
|
if (!is_aggregate_return(func)) {
|
|
|
|
indent(header, 0);
|
|
|
|
fprintf(header, "%sThis->lpVtbl->%s(This",
|
2019-07-05 23:49:49 +02:00
|
|
|
is_void(type_function_get_rettype(func->declspec.type)) ? "" : "return ",
|
2014-10-13 12:23:22 +02:00
|
|
|
get_vtbl_entry_name(iface, func));
|
2014-09-05 17:33:03 +02:00
|
|
|
} else {
|
|
|
|
indent(header, 0);
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(header, type_function_get_ret(func->declspec.type));
|
2014-09-05 17:33:03 +02:00
|
|
|
fprintf(header, " __ret;\n");
|
|
|
|
indent(header, 0);
|
2014-10-13 12:23:22 +02:00
|
|
|
fprintf(header, "return *This->lpVtbl->%s(This,&__ret", get_vtbl_entry_name(iface, func));
|
2014-09-05 17:33:03 +02:00
|
|
|
}
|
2019-08-14 04:08:03 +02:00
|
|
|
if (type_function_get_args(func->declspec.type))
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, type_function_get_args(func->declspec.type), const var_t, entry )
|
2012-07-26 11:35:43 +02:00
|
|
|
fprintf(header, ",%s", arg->name);
|
|
|
|
fprintf(header, ");\n");
|
2014-09-05 17:33:03 +02:00
|
|
|
--indentation;
|
2012-07-26 11:35:43 +02:00
|
|
|
fprintf(header, "}\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void do_write_c_method_def(FILE *header, const type_t *iface, const char *name)
|
2002-12-15 04:01:20 +01:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
const statement_t *stmt;
|
|
|
|
int first_iface = 1;
|
2002-12-15 04:01:20 +01:00
|
|
|
|
2009-01-06 00:35:06 +01:00
|
|
|
if (type_iface_get_inherit(iface))
|
|
|
|
do_write_c_method_def(header, type_iface_get_inherit(iface), name);
|
2003-07-22 05:18:46 +02:00
|
|
|
|
2009-01-06 00:35:13 +01:00
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(iface))
|
2007-01-22 14:23:08 +01:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
if (first_iface) {
|
|
|
|
indent(header, 0);
|
|
|
|
fprintf(header, "/*** %s methods ***/\n", iface->name);
|
|
|
|
first_iface = 0;
|
|
|
|
}
|
|
|
|
if (!is_callas(func->attrs)) {
|
2019-07-05 23:49:49 +02:00
|
|
|
const char *callconv = get_attrp(func->declspec.type->attrs, ATTR_CALLCONV);
|
2010-08-27 13:52:09 +02:00
|
|
|
if (!callconv) callconv = "STDMETHODCALLTYPE";
|
2005-08-03 16:55:22 +02:00
|
|
|
indent(header, 0);
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(header, type_function_get_ret(func->declspec.type));
|
2014-09-05 17:33:03 +02:00
|
|
|
if (is_aggregate_return(func))
|
|
|
|
fprintf(header, " *");
|
2012-07-27 17:18:04 +02:00
|
|
|
if (is_inherited_method(iface, func))
|
|
|
|
fprintf(header, " (%s *%s_%s)(\n", callconv, iface->name, func->name);
|
|
|
|
else
|
|
|
|
fprintf(header, " (%s *%s)(\n", callconv, get_name(func));
|
2014-09-05 17:33:03 +02:00
|
|
|
++indentation;
|
|
|
|
indent(header, 0);
|
|
|
|
fprintf(header, "%s *This", name);
|
|
|
|
if (is_aggregate_return(func)) {
|
|
|
|
fprintf(header, ",\n");
|
|
|
|
indent(header, 0);
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(header, type_function_get_ret(func->declspec.type));
|
2014-09-05 17:33:03 +02:00
|
|
|
fprintf(header, " *__ret");
|
|
|
|
}
|
|
|
|
--indentation;
|
2019-08-14 04:08:03 +02:00
|
|
|
if (type_function_get_args(func->declspec.type)) {
|
2014-09-05 17:33:03 +02:00
|
|
|
fprintf(header, ",\n");
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
write_args(header, type_function_get_args(func->declspec.type), name, 0, TRUE, NAME_C);
|
2014-09-05 17:33:03 +02:00
|
|
|
}
|
2002-12-15 04:01:20 +01:00
|
|
|
fprintf(header, ");\n");
|
|
|
|
fprintf(header, "\n");
|
|
|
|
}
|
|
|
|
}
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void write_c_method_def(FILE *header, const type_t *iface)
|
2003-01-09 02:05:54 +01:00
|
|
|
{
|
2015-07-31 13:38:18 +02:00
|
|
|
do_write_c_method_def(header, iface, iface->c_name);
|
2003-01-09 02:05:54 +01:00
|
|
|
}
|
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void write_c_disp_method_def(FILE *header, const type_t *iface)
|
2004-10-11 21:54:37 +02:00
|
|
|
{
|
2015-07-31 13:38:18 +02:00
|
|
|
do_write_c_method_def(header, type_iface_get_inherit(iface), iface->c_name);
|
2004-10-11 21:54:37 +02:00
|
|
|
}
|
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void write_method_proto(FILE *header, const type_t *iface)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
const statement_t *stmt;
|
2003-07-22 05:18:46 +02:00
|
|
|
|
2009-01-06 00:35:13 +01:00
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(iface))
|
2007-01-22 14:23:08 +01:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
const var_t *func = stmt->u.var;
|
2007-01-22 14:26:12 +01:00
|
|
|
|
2017-07-11 04:30:15 +02:00
|
|
|
if (is_callas(func->attrs)) {
|
2019-07-05 23:49:49 +02:00
|
|
|
const char *callconv = get_attrp(func->declspec.type->attrs, ATTR_CALLCONV);
|
2010-08-27 13:52:09 +02:00
|
|
|
if (!callconv) callconv = "STDMETHODCALLTYPE";
|
2002-07-16 05:20:45 +02:00
|
|
|
/* proxy prototype */
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(header, type_function_get_ret(func->declspec.type));
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(header, " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(func));
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
write_args(header, type_function_get_args(func->declspec.type), iface->name, 1, TRUE, NAME_DEFAULT);
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(header, ");\n");
|
|
|
|
/* stub prototype */
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(header, "void __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(func));
|
2005-12-02 13:32:09 +01:00
|
|
|
fprintf(header, " IRpcStubBuffer* This,\n");
|
|
|
|
fprintf(header, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(header, " PRPC_MESSAGE pRpcMessage,\n");
|
|
|
|
fprintf(header, " DWORD* pdwStubPhase);\n");
|
|
|
|
}
|
2007-10-31 03:07:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:24 +01:00
|
|
|
static void write_locals(FILE *fp, const type_t *iface, int body)
|
2007-10-31 03:07:36 +01:00
|
|
|
{
|
|
|
|
static const char comment[]
|
|
|
|
= "/* WIDL-generated stub. You must provide an implementation for this. */";
|
2009-01-06 00:33:27 +01:00
|
|
|
const statement_t *stmt;
|
2007-10-31 03:07:36 +01:00
|
|
|
|
2009-11-25 10:53:49 +01:00
|
|
|
if (!is_object(iface))
|
2007-10-31 03:07:36 +01:00
|
|
|
return;
|
|
|
|
|
2009-01-06 00:35:13 +01:00
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(iface)) {
|
2009-01-06 00:33:27 +01:00
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
const var_t *cas = is_callas(func->attrs);
|
2007-10-31 03:07:36 +01:00
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
if (cas) {
|
2009-01-06 00:33:27 +01:00
|
|
|
const statement_t *stmt2 = NULL;
|
2009-01-06 00:35:13 +01:00
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt2, type_iface_get_stmts(iface))
|
2018-11-02 16:53:08 +01:00
|
|
|
if (!strcmp(get_name(stmt2->u.var), cas->name))
|
2007-10-31 03:07:36 +01:00
|
|
|
break;
|
2009-01-06 00:35:13 +01:00
|
|
|
if (&stmt2->entry != type_iface_get_stmts(iface)) {
|
2009-01-06 00:33:27 +01:00
|
|
|
const var_t *m = stmt2->u.var;
|
2002-07-16 05:20:45 +02:00
|
|
|
/* proxy prototype - use local prototype */
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(fp, type_function_get_ret(m->declspec.type));
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(fp, " CALLBACK %s_%s_Proxy(\n", iface->name, get_name(m));
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
write_args(fp, type_function_get_args(m->declspec.type), iface->name, 1, TRUE, NAME_DEFAULT);
|
2007-10-31 03:07:36 +01:00
|
|
|
fprintf(fp, ")");
|
|
|
|
if (body) {
|
2019-08-16 03:13:18 +02:00
|
|
|
const decl_spec_t *rt = type_function_get_ret(m->declspec.type);
|
2007-10-31 03:07:36 +01:00
|
|
|
fprintf(fp, "\n{\n");
|
|
|
|
fprintf(fp, " %s\n", comment);
|
2019-08-16 03:13:18 +02:00
|
|
|
if (rt->type->name && strcmp(rt->type->name, "HRESULT") == 0)
|
2007-10-31 03:07:36 +01:00
|
|
|
fprintf(fp, " return E_NOTIMPL;\n");
|
2019-08-16 03:13:18 +02:00
|
|
|
else if (type_get_type(rt->type) != TYPE_VOID) {
|
2007-10-31 03:07:36 +01:00
|
|
|
fprintf(fp, " ");
|
|
|
|
write_type_decl(fp, rt, "rv");
|
|
|
|
fprintf(fp, ";\n");
|
|
|
|
fprintf(fp, " memset(&rv, 0, sizeof rv);\n");
|
|
|
|
fprintf(fp, " return rv;\n");
|
|
|
|
}
|
|
|
|
fprintf(fp, "}\n\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fprintf(fp, ";\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
/* stub prototype - use remotable prototype */
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(fp, type_function_get_ret(func->declspec.type));
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(fp, " __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(m));
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
write_args(fp, type_function_get_args(func->declspec.type), iface->name, 1, TRUE, NAME_DEFAULT);
|
2007-10-31 03:07:36 +01:00
|
|
|
fprintf(fp, ")");
|
|
|
|
if (body)
|
|
|
|
/* Remotable methods must all return HRESULTs. */
|
|
|
|
fprintf(fp, "\n{\n %s\n return E_NOTIMPL;\n}\n\n", comment);
|
|
|
|
else
|
|
|
|
fprintf(fp, ";\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
2007-10-31 03:07:36 +01:00
|
|
|
else
|
2009-01-06 00:33:27 +01:00
|
|
|
error_loc("invalid call_as attribute (%s -> %s)\n", func->name, cas->name);
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:24 +01:00
|
|
|
static void write_local_stubs_stmts(FILE *local_stubs, const statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
|
|
|
|
{
|
2009-02-23 14:48:05 +01:00
|
|
|
if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE)
|
2008-12-29 13:06:24 +01:00
|
|
|
write_locals(local_stubs, stmt->u.type, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_local_stubs(const statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
FILE *local_stubs;
|
|
|
|
|
|
|
|
if (!local_stubs_name) return;
|
|
|
|
|
|
|
|
local_stubs = fopen(local_stubs_name, "w");
|
|
|
|
if (!local_stubs) {
|
|
|
|
error("Could not open %s for output\n", local_stubs_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf(local_stubs, "/* call_as/local stubs for %s */\n\n", input_name);
|
|
|
|
fprintf(local_stubs, "#include <objbase.h>\n");
|
|
|
|
fprintf(local_stubs, "#include \"%s\"\n\n", header_name);
|
|
|
|
|
|
|
|
write_local_stubs_stmts(local_stubs, stmts);
|
|
|
|
|
|
|
|
fclose(local_stubs);
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
static void write_function_proto(FILE *header, const type_t *iface, const var_t *fun, const char *prefix)
|
2007-04-26 03:17:31 +02:00
|
|
|
{
|
2019-07-05 23:49:49 +02:00
|
|
|
const char *callconv = get_attrp(fun->declspec.type->attrs, ATTR_CALLCONV);
|
2007-04-26 03:17:31 +02:00
|
|
|
|
2011-06-10 13:40:05 +02:00
|
|
|
if (!callconv) callconv = "__cdecl";
|
2007-04-26 03:17:31 +02:00
|
|
|
/* FIXME: do we need to handle call_as? */
|
2019-08-16 03:13:19 +02:00
|
|
|
write_type_decl_left(header, type_function_get_ret(fun->declspec.type));
|
2011-06-10 13:40:05 +02:00
|
|
|
fprintf(header, " %s ", callconv);
|
2008-12-29 13:06:35 +01:00
|
|
|
fprintf(header, "%s%s(\n", prefix, get_name(fun));
|
2019-08-14 04:08:03 +02:00
|
|
|
if (type_function_get_args(fun->declspec.type))
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
write_args(header, type_function_get_args(fun->declspec.type), iface->name, 0, TRUE, NAME_DEFAULT);
|
2007-04-26 03:17:31 +02:00
|
|
|
else
|
|
|
|
fprintf(header, " void");
|
2008-04-02 13:56:27 +02:00
|
|
|
fprintf(header, ");\n\n");
|
2007-04-26 03:17:31 +02:00
|
|
|
}
|
|
|
|
|
2021-02-25 14:15:09 +01:00
|
|
|
static void write_parameterized_type_forward(FILE *header, type_t *type)
|
|
|
|
{
|
|
|
|
type_t *iface = type->details.parameterized.type;
|
|
|
|
char *args;
|
|
|
|
|
|
|
|
if (type_get_type(iface) == TYPE_DELEGATE) iface = type_delegate_get_iface(iface);
|
|
|
|
|
|
|
|
fprintf(header, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
|
|
|
|
write_namespace_start(header, type->namespace);
|
|
|
|
|
|
|
|
args = format_parameterized_type_args(type, "class ", "");
|
|
|
|
write_line(header, 0, "template <%s>", args);
|
|
|
|
write_line(header, 0, "struct %s_impl;\n", iface->name);
|
|
|
|
|
|
|
|
write_line(header, 0, "template <%s>", args);
|
|
|
|
free(args);
|
|
|
|
args = format_parameterized_type_args(type, "", "");
|
|
|
|
write_line(header, 0, "struct %s : %s_impl<%s> {};", iface->name, iface->name, args);
|
|
|
|
free(args);
|
|
|
|
|
|
|
|
write_namespace_end(header, type->namespace);
|
|
|
|
fprintf(header, "#endif\n\n" );
|
|
|
|
}
|
|
|
|
|
2021-02-25 14:16:02 +01:00
|
|
|
static void write_parameterized_implementation(FILE *header, type_t *type, int declonly)
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
2021-02-27 15:25:24 +01:00
|
|
|
typeref_list_t *params = type->details.parameterized.params;
|
2021-02-25 14:16:02 +01:00
|
|
|
typeref_t *ref;
|
|
|
|
type_t *iface = type->details.parameterized.type, *base;
|
|
|
|
char *args = NULL;
|
|
|
|
|
|
|
|
fprintf(header, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
|
|
|
|
write_line(header, 0, "} /* extern \"C\" */");
|
|
|
|
write_namespace_start(header, type->namespace);
|
|
|
|
|
|
|
|
if (type_get_type(iface) == TYPE_DELEGATE) iface = type_delegate_get_iface(iface);
|
|
|
|
base = type_iface_get_inherit(iface);
|
|
|
|
|
|
|
|
args = format_parameterized_type_args(type, "class ", "");
|
|
|
|
write_line(header, 0, "template <%s>", args);
|
|
|
|
free(args);
|
|
|
|
write_line(header, 0, "struct %s_impl%s", iface->name, base ? strmake(" : %s", base->name) : "");
|
|
|
|
write_line(header, 0, "{");
|
|
|
|
|
|
|
|
write_line(header, 1, "private:");
|
|
|
|
if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
|
|
|
|
{
|
|
|
|
write_line(header, 0, "typedef typename Windows::Foundation::Internal::GetAbiType<%s>::type %s_abi;", ref->type->name, ref->type->name);
|
|
|
|
write_line(header, 0, "typedef typename Windows::Foundation::Internal::GetLogicalType<%s>::type %s_logical;", ref->type->name, ref->type->name);
|
|
|
|
}
|
|
|
|
indentation -= 1;
|
|
|
|
|
|
|
|
write_line(header, 1, "public:");
|
|
|
|
if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
|
|
|
|
write_line(header, 0, "typedef %s %s_complex;", ref->type->name, ref->type->name);
|
|
|
|
|
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(iface))
|
|
|
|
{
|
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
if (is_callas(func->attrs)) continue;
|
|
|
|
indent(header, 1);
|
|
|
|
fprintf(header, "virtual ");
|
|
|
|
write_type_decl_left(header, &func->declspec);
|
|
|
|
fprintf(header, "%s(", get_name(func));
|
|
|
|
write_args(header, type_function_get_args(func->declspec.type), NULL, 0, 0, NAME_DEFAULT);
|
|
|
|
fprintf(header, ") = 0;\n");
|
|
|
|
indentation -= 1;
|
|
|
|
}
|
|
|
|
write_line(header, -1, "};");
|
|
|
|
|
|
|
|
write_namespace_end(header, type->namespace);
|
|
|
|
write_line(header, 0, "extern \"C\" {");
|
|
|
|
write_line(header, 0, "#endif\n");
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
static void write_forward(FILE *header, type_t *iface)
|
2002-12-03 20:12:07 +01:00
|
|
|
{
|
2015-07-31 13:37:50 +02:00
|
|
|
fprintf(header, "#ifndef __%s_FWD_DEFINED__\n", iface->c_name);
|
|
|
|
fprintf(header, "#define __%s_FWD_DEFINED__\n", iface->c_name);
|
2015-07-31 13:37:57 +02:00
|
|
|
fprintf(header, "typedef interface %s %s;\n", iface->c_name, iface->c_name);
|
|
|
|
fprintf(header, "#ifdef __cplusplus\n");
|
2021-02-19 12:03:59 +01:00
|
|
|
if (iface->namespace && !is_global_namespace(iface->namespace))
|
|
|
|
fprintf(header, "#define %s %s\n", iface->c_name, iface->qualified_name);
|
2021-02-25 14:16:10 +01:00
|
|
|
if (!iface->impl_name)
|
|
|
|
{
|
|
|
|
write_namespace_start(header, iface->namespace);
|
|
|
|
write_line(header, 0, "interface %s;", iface->name);
|
|
|
|
write_namespace_end(header, iface->namespace);
|
|
|
|
}
|
2015-07-31 13:37:57 +02:00
|
|
|
fprintf(header, "#endif /* __cplusplus */\n");
|
2008-12-29 13:06:35 +01:00
|
|
|
fprintf(header, "#endif\n\n" );
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
2020-12-01 15:01:56 +01:00
|
|
|
static char *format_apicontract_macro(const type_t *type)
|
|
|
|
{
|
|
|
|
char *name = format_namespace(type->namespace, "", "_", type->name, NULL);
|
|
|
|
int i;
|
|
|
|
for (i = strlen(name); i > 0; --i) name[i - 1] = toupper(name[i - 1]);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2020-12-01 15:01:57 +01:00
|
|
|
static void write_apicontract_guard_start(FILE *header, const expr_t *expr)
|
|
|
|
{
|
|
|
|
const type_t *type;
|
|
|
|
char *name;
|
|
|
|
int ver;
|
|
|
|
if (!winrt_mode) return;
|
|
|
|
type = expr->u.tref.type;
|
|
|
|
ver = expr->ref->u.lval;
|
|
|
|
name = format_apicontract_macro(type);
|
|
|
|
fprintf(header, "#if %s_VERSION >= %#x\n", name, ver);
|
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_apicontract_guard_end(FILE *header, const expr_t *expr)
|
|
|
|
{
|
|
|
|
const type_t *type;
|
|
|
|
char *name;
|
|
|
|
int ver;
|
|
|
|
if (!winrt_mode) return;
|
|
|
|
type = expr->u.tref.type;
|
|
|
|
ver = expr->ref->u.lval;
|
|
|
|
name = format_apicontract_macro(type);
|
|
|
|
fprintf(header, "#endif /* %s_VERSION >= %#x */\n", name, ver);
|
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void write_com_interface_start(FILE *header, const type_t *iface)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2008-05-01 13:35:31 +02:00
|
|
|
int dispinterface = is_attr(iface->attrs, ATTR_DISPINTERFACE);
|
2020-12-01 15:01:57 +01:00
|
|
|
expr_t *contract = get_attrp(iface->attrs, ATTR_CONTRACT);
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(header, "/*****************************************************************************\n");
|
2008-05-01 13:35:31 +02:00
|
|
|
fprintf(header, " * %s %sinterface\n", iface->name, dispinterface ? "disp" : "");
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(header, " */\n");
|
2020-12-01 15:01:57 +01:00
|
|
|
if (contract) write_apicontract_guard_start(header, contract);
|
2015-07-31 13:38:18 +02:00
|
|
|
fprintf(header,"#ifndef __%s_%sINTERFACE_DEFINED__\n", iface->c_name, dispinterface ? "DISP" : "");
|
|
|
|
fprintf(header,"#define __%s_%sINTERFACE_DEFINED__\n\n", iface->c_name, dispinterface ? "DISP" : "");
|
2008-05-01 13:35:31 +02:00
|
|
|
}
|
|
|
|
|
2021-02-26 09:43:06 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void write_com_interface_end(FILE *header, type_t *iface)
|
|
|
|
{
|
|
|
|
int dispinterface = is_attr(iface->attrs, ATTR_DISPINTERFACE);
|
2011-07-14 17:21:45 +02:00
|
|
|
const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
|
2020-12-01 15:01:57 +01:00
|
|
|
expr_t *contract = get_attrp(iface->attrs, ATTR_CONTRACT);
|
2014-10-13 12:23:22 +02:00
|
|
|
type_t *type;
|
2011-07-14 17:21:45 +02:00
|
|
|
|
|
|
|
if (uuid)
|
2015-07-31 13:38:18 +02:00
|
|
|
write_guid(header, dispinterface ? "DIID" : "IID", iface->c_name, uuid);
|
2011-07-14 17:21:45 +02:00
|
|
|
|
2003-04-10 02:19:24 +02:00
|
|
|
/* C++ interface */
|
|
|
|
fprintf(header, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
|
2015-07-31 13:38:06 +02:00
|
|
|
if (!is_global_namespace(iface->namespace)) {
|
|
|
|
write_line(header, 0, "} /* extern \"C\" */");
|
|
|
|
write_namespace_start(header, iface->namespace);
|
|
|
|
}
|
|
|
|
if (uuid) {
|
2021-02-17 19:33:35 +01:00
|
|
|
if (strchr(iface->name, '<')) write_line(header, 0, "template<>");
|
2015-07-31 13:38:06 +02:00
|
|
|
write_line(header, 0, "MIDL_INTERFACE(\"%s\")", uuid_string(uuid));
|
|
|
|
indent(header, 0);
|
|
|
|
}else {
|
|
|
|
indent(header, 0);
|
2021-02-17 19:33:35 +01:00
|
|
|
if (strchr(iface->name, '<')) fprintf(header, "template<> struct ");
|
|
|
|
else fprintf(header, "interface ");
|
2015-07-31 13:38:06 +02:00
|
|
|
}
|
2021-02-25 14:16:10 +01:00
|
|
|
if (iface->impl_name)
|
|
|
|
{
|
|
|
|
fprintf(header, "%s : %s\n", iface->name, iface->impl_name);
|
|
|
|
write_line(header, 1, "{");
|
|
|
|
}
|
|
|
|
else if (type_iface_get_inherit(iface))
|
2004-08-23 00:31:52 +02:00
|
|
|
{
|
2011-07-14 17:21:45 +02:00
|
|
|
fprintf(header, "%s : public %s\n", iface->name,
|
2009-01-06 00:35:06 +01:00
|
|
|
type_iface_get_inherit(iface)->name);
|
2015-07-31 13:38:06 +02:00
|
|
|
write_line(header, 1, "{");
|
2004-08-23 00:31:52 +02:00
|
|
|
}
|
2003-04-12 02:09:14 +02:00
|
|
|
else
|
|
|
|
{
|
2011-07-14 17:21:45 +02:00
|
|
|
fprintf(header, "%s\n", iface->name);
|
2015-07-31 13:38:06 +02:00
|
|
|
write_line(header, 1, "{\n");
|
|
|
|
write_line(header, 0, "BEGIN_INTERFACE\n");
|
2003-04-12 02:09:14 +02:00
|
|
|
}
|
2008-05-01 13:35:31 +02:00
|
|
|
/* dispinterfaces don't have real functions, so don't write C++ functions for
|
|
|
|
* them */
|
2021-02-25 14:16:10 +01:00
|
|
|
if (!dispinterface && !iface->impl_name)
|
2008-05-01 13:35:31 +02:00
|
|
|
write_cpp_method_def(header, iface);
|
2021-02-25 14:16:10 +01:00
|
|
|
if (!type_iface_get_inherit(iface) && !iface->impl_name)
|
2015-07-31 13:38:06 +02:00
|
|
|
write_line(header, 0, "END_INTERFACE\n");
|
|
|
|
write_line(header, -1, "};");
|
|
|
|
if (!is_global_namespace(iface->namespace)) {
|
|
|
|
write_namespace_end(header, iface->namespace);
|
|
|
|
write_line(header, 0, "extern \"C\" {");
|
|
|
|
}
|
2011-07-14 17:21:45 +02:00
|
|
|
if (uuid)
|
2015-07-31 13:38:32 +02:00
|
|
|
write_uuid_decl(header, iface, uuid);
|
2003-04-10 02:19:24 +02:00
|
|
|
fprintf(header, "#else\n");
|
|
|
|
/* C interface */
|
2015-07-31 13:38:18 +02:00
|
|
|
write_line(header, 1, "typedef struct %sVtbl {", iface->c_name);
|
|
|
|
write_line(header, 0, "BEGIN_INTERFACE\n");
|
2008-05-01 13:35:31 +02:00
|
|
|
if (dispinterface)
|
|
|
|
write_c_disp_method_def(header, iface);
|
|
|
|
else
|
|
|
|
write_c_method_def(header, iface);
|
2015-07-31 13:38:18 +02:00
|
|
|
write_line(header, 0, "END_INTERFACE");
|
|
|
|
write_line(header, -1, "} %sVtbl;\n", iface->c_name);
|
|
|
|
fprintf(header, "interface %s {\n", iface->c_name);
|
|
|
|
fprintf(header, " CONST_VTBL %sVtbl* lpVtbl;\n", iface->c_name);
|
|
|
|
fprintf(header, "};\n\n");
|
2004-08-11 21:43:45 +02:00
|
|
|
fprintf(header, "#ifdef COBJMACROS\n");
|
2008-05-01 13:35:31 +02:00
|
|
|
/* dispinterfaces don't have real functions, so don't write macros for them,
|
|
|
|
* only for the interface this interface inherits from, i.e. IDispatch */
|
2012-07-26 11:35:43 +02:00
|
|
|
fprintf(header, "#ifndef WIDL_C_INLINE_WRAPPERS\n");
|
2014-10-13 12:23:22 +02:00
|
|
|
type = dispinterface ? type_iface_get_inherit(iface) : iface;
|
2015-07-31 13:38:18 +02:00
|
|
|
write_method_macro(header, type, type, iface->c_name);
|
2012-07-26 11:35:43 +02:00
|
|
|
fprintf(header, "#else\n");
|
2015-07-31 13:38:18 +02:00
|
|
|
write_inline_wrappers(header, type, type, iface->c_name);
|
2012-07-26 11:35:43 +02:00
|
|
|
fprintf(header, "#endif\n");
|
2021-02-26 09:43:06 +01:00
|
|
|
if (winrt_mode) write_widl_using_macros(header, iface);
|
2004-08-11 21:43:45 +02:00
|
|
|
fprintf(header, "#endif\n");
|
2003-04-10 02:19:24 +02:00
|
|
|
fprintf(header, "\n");
|
|
|
|
fprintf(header, "#endif\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(header, "\n");
|
2008-05-01 13:35:31 +02:00
|
|
|
/* dispinterfaces don't have real functions, so don't write prototypes for
|
|
|
|
* them */
|
2015-07-31 13:38:18 +02:00
|
|
|
if (!dispinterface && !winrt_mode)
|
2008-05-01 13:35:31 +02:00
|
|
|
{
|
|
|
|
write_method_proto(header, iface);
|
|
|
|
write_locals(header, iface, FALSE);
|
|
|
|
fprintf(header, "\n");
|
|
|
|
}
|
2020-12-01 15:01:57 +01:00
|
|
|
fprintf(header, "#endif /* __%s_%sINTERFACE_DEFINED__ */\n", iface->c_name, dispinterface ? "DISP" : "");
|
|
|
|
if (contract) write_apicontract_guard_end(header, contract);
|
|
|
|
fprintf(header, "\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
2002-12-03 20:12:07 +01:00
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void write_rpc_interface_start(FILE *header, const type_t *iface)
|
2002-12-03 20:12:07 +01:00
|
|
|
{
|
2007-12-12 15:49:34 +01:00
|
|
|
unsigned int ver = get_attrv(iface->attrs, ATTR_VERSION);
|
2011-05-31 13:01:32 +02:00
|
|
|
const var_t *var = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
|
2020-12-01 15:01:57 +01:00
|
|
|
expr_t *contract = get_attrp(iface->attrs, ATTR_CONTRACT);
|
2002-12-03 20:12:07 +01:00
|
|
|
|
|
|
|
fprintf(header, "/*****************************************************************************\n");
|
2007-12-12 15:49:34 +01:00
|
|
|
fprintf(header, " * %s interface (v%d.%d)\n", iface->name, MAJORVERSION(ver), MINORVERSION(ver));
|
2002-12-03 20:12:07 +01:00
|
|
|
fprintf(header, " */\n");
|
2020-12-01 15:01:57 +01:00
|
|
|
if (contract) write_apicontract_guard_start(header, contract);
|
2006-03-31 13:44:53 +02:00
|
|
|
fprintf(header,"#ifndef __%s_INTERFACE_DEFINED__\n", iface->name);
|
|
|
|
fprintf(header,"#define __%s_INTERFACE_DEFINED__\n\n", iface->name);
|
2011-05-31 13:01:32 +02:00
|
|
|
if (var)
|
|
|
|
{
|
|
|
|
fprintf(header, "extern ");
|
2019-08-16 03:13:18 +02:00
|
|
|
write_type_decl( header, &var->declspec, var->name );
|
2011-05-31 13:01:32 +02:00
|
|
|
fprintf(header, ";\n");
|
|
|
|
}
|
2008-05-01 13:35:31 +02:00
|
|
|
if (old_names)
|
2006-03-31 13:50:34 +02:00
|
|
|
{
|
2008-05-01 13:35:31 +02:00
|
|
|
fprintf(header, "extern RPC_IF_HANDLE %s%s_ClientIfHandle;\n", prefix_client, iface->name);
|
|
|
|
fprintf(header, "extern RPC_IF_HANDLE %s%s_ServerIfHandle;\n", prefix_server, iface->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(header, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n",
|
|
|
|
prefix_client, iface->name, MAJORVERSION(ver), MINORVERSION(ver));
|
|
|
|
fprintf(header, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n",
|
|
|
|
prefix_server, iface->name, MAJORVERSION(ver), MINORVERSION(ver));
|
2006-03-31 13:50:34 +02:00
|
|
|
}
|
2002-12-03 20:12:07 +01:00
|
|
|
}
|
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void write_rpc_interface_end(FILE *header, const type_t *iface)
|
2002-12-03 20:12:07 +01:00
|
|
|
{
|
2020-12-01 15:01:57 +01:00
|
|
|
expr_t *contract = get_attrp(iface->attrs, ATTR_CONTRACT);
|
|
|
|
fprintf(header, "\n#endif /* __%s_INTERFACE_DEFINED__ */\n", iface->name);
|
|
|
|
if (contract) write_apicontract_guard_end(header, contract);
|
|
|
|
fprintf(header, "\n");
|
2002-12-03 20:12:07 +01:00
|
|
|
}
|
2004-10-11 21:54:37 +02:00
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
static void write_coclass(FILE *header, type_t *cocl)
|
2004-10-11 21:54:37 +02:00
|
|
|
{
|
2011-07-14 17:21:45 +02:00
|
|
|
const UUID *uuid = get_attrp(cocl->attrs, ATTR_UUID);
|
|
|
|
|
2004-10-11 21:54:37 +02:00
|
|
|
fprintf(header, "/*****************************************************************************\n");
|
|
|
|
fprintf(header, " * %s coclass\n", cocl->name);
|
|
|
|
fprintf(header, " */\n\n");
|
2011-07-14 17:21:45 +02:00
|
|
|
if (uuid)
|
|
|
|
write_guid(header, "CLSID", cocl->name, uuid);
|
2011-07-06 14:08:16 +02:00
|
|
|
fprintf(header, "\n#ifdef __cplusplus\n");
|
2011-07-14 17:21:45 +02:00
|
|
|
if (uuid)
|
|
|
|
{
|
|
|
|
fprintf(header, "class DECLSPEC_UUID(\"%s\") %s;\n", uuid_string(uuid), cocl->name);
|
2015-07-31 13:38:32 +02:00
|
|
|
write_uuid_decl(header, cocl, uuid);
|
2011-07-14 17:21:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(header, "class %s;\n", cocl->name);
|
|
|
|
}
|
2011-07-06 14:08:16 +02:00
|
|
|
fprintf(header, "#endif\n");
|
2004-10-11 21:54:37 +02:00
|
|
|
fprintf(header, "\n");
|
|
|
|
}
|
2006-06-06 21:05:39 +02:00
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
static void write_coclass_forward(FILE *header, type_t *cocl)
|
2006-06-06 21:05:39 +02:00
|
|
|
{
|
|
|
|
fprintf(header, "#ifndef __%s_FWD_DEFINED__\n", cocl->name);
|
|
|
|
fprintf(header, "#define __%s_FWD_DEFINED__\n", cocl->name);
|
2012-10-14 18:35:14 +02:00
|
|
|
fprintf(header, "#ifdef __cplusplus\n");
|
|
|
|
fprintf(header, "typedef class %s %s;\n", cocl->name, cocl->name);
|
|
|
|
fprintf(header, "#else\n");
|
2006-06-06 21:05:39 +02:00
|
|
|
fprintf(header, "typedef struct %s %s;\n", cocl->name, cocl->name);
|
2012-10-14 18:35:14 +02:00
|
|
|
fprintf(header, "#endif /* defined __cplusplus */\n");
|
2006-07-14 03:10:12 +02:00
|
|
|
fprintf(header, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl->name );
|
2006-06-06 21:05:39 +02:00
|
|
|
}
|
2008-04-25 11:59:40 +02:00
|
|
|
|
2020-12-01 15:01:56 +01:00
|
|
|
static void write_apicontract(FILE *header, type_t *apicontract)
|
|
|
|
{
|
|
|
|
char *name = format_apicontract_macro(apicontract);
|
|
|
|
fprintf(header, "#if !defined(%s_VERSION)\n", name);
|
|
|
|
fprintf(header, "#define %s_VERSION %#x\n", name, get_attrv(apicontract->attrs, ATTR_CONTRACTVERSION));
|
|
|
|
fprintf(header, "#endif // defined(%s_VERSION)\n\n", name);
|
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
|
2021-01-27 21:20:45 +01:00
|
|
|
static void write_runtimeclass(FILE *header, type_t *runtimeclass)
|
|
|
|
{
|
|
|
|
expr_t *contract = get_attrp(runtimeclass->attrs, ATTR_CONTRACT);
|
|
|
|
char *name, *c_name;
|
2021-02-02 09:22:33 +01:00
|
|
|
size_t i, len;
|
2021-01-27 21:20:45 +01:00
|
|
|
name = format_namespace(runtimeclass->namespace, "", ".", runtimeclass->name, NULL);
|
|
|
|
c_name = format_namespace(runtimeclass->namespace, "", "_", runtimeclass->name, NULL);
|
|
|
|
fprintf(header, "/*\n");
|
|
|
|
fprintf(header, " * Class %s\n", name);
|
|
|
|
fprintf(header, " */\n");
|
|
|
|
if (contract) write_apicontract_guard_start(header, contract);
|
|
|
|
fprintf(header, "#ifndef RUNTIMECLASS_%s_DEFINED\n", c_name);
|
|
|
|
fprintf(header, "#define RUNTIMECLASS_%s_DEFINED\n", c_name);
|
2021-02-26 15:36:42 +01:00
|
|
|
fprintf(header, "#if !defined(_MSC_VER) && !defined(__MINGW32__)\n");
|
|
|
|
fprintf(header, "static const WCHAR RuntimeClass_%s[] = {", c_name);
|
|
|
|
for (i = 0, len = strlen(name); i < len; ++i) fprintf(header, "'%c',", name[i]);
|
|
|
|
fprintf(header, "0};\n");
|
|
|
|
fprintf(header, "#elif defined(__GNUC__) && !defined(__cplusplus)\n");
|
2021-02-02 09:22:33 +01:00
|
|
|
/* FIXME: MIDL generates extern const here but GCC warns if extern is initialized */
|
|
|
|
fprintf(header, "const DECLSPEC_SELECTANY WCHAR RuntimeClass_%s[] = L\"%s\";\n", c_name, name);
|
|
|
|
fprintf(header, "#else\n");
|
2021-02-26 15:36:42 +01:00
|
|
|
fprintf(header, "extern const DECLSPEC_SELECTANY WCHAR RuntimeClass_%s[] = {", c_name);
|
2021-02-02 09:22:33 +01:00
|
|
|
for (i = 0, len = strlen(name); i < len; ++i) fprintf(header, "'%c',", name[i]);
|
|
|
|
fprintf(header, "0};\n");
|
|
|
|
fprintf(header, "#endif\n");
|
2021-01-27 21:20:45 +01:00
|
|
|
fprintf(header, "#endif /* RUNTIMECLASS_%s_DEFINED */\n", c_name);
|
|
|
|
free(c_name);
|
|
|
|
free(name);
|
|
|
|
if (contract) write_apicontract_guard_end(header, contract);
|
|
|
|
fprintf(header, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_runtimeclass_forward(FILE *header, type_t *runtimeclass)
|
|
|
|
{
|
|
|
|
fprintf(header, "#ifndef __%s_FWD_DEFINED__\n", runtimeclass->c_name);
|
|
|
|
fprintf(header, "#define __%s_FWD_DEFINED__\n", runtimeclass->c_name);
|
|
|
|
fprintf(header, "#ifdef __cplusplus\n");
|
|
|
|
write_namespace_start(header, runtimeclass->namespace);
|
|
|
|
write_line(header, 0, "class %s;", runtimeclass->name);
|
|
|
|
write_namespace_end(header, runtimeclass->namespace);
|
|
|
|
fprintf(header, "#else\n");
|
|
|
|
fprintf(header, "typedef struct %s %s;\n", runtimeclass->c_name, runtimeclass->c_name);
|
|
|
|
fprintf(header, "#endif /* defined __cplusplus */\n");
|
|
|
|
fprintf(header, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", runtimeclass->c_name);
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
static void write_import(FILE *header, const char *fname)
|
2008-04-25 11:59:40 +02:00
|
|
|
{
|
|
|
|
char *hname, *p;
|
|
|
|
|
|
|
|
hname = dup_basename(fname, ".idl");
|
|
|
|
p = hname + strlen(hname) - 2;
|
|
|
|
if (p <= hname || strcmp( p, ".h" )) strcat(hname, ".h");
|
|
|
|
|
|
|
|
fprintf(header, "#include <%s>\n", hname);
|
|
|
|
free(hname);
|
|
|
|
}
|
2008-12-29 13:06:35 +01:00
|
|
|
|
|
|
|
static void write_imports(FILE *header, const statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
|
|
|
|
{
|
|
|
|
switch (stmt->type)
|
|
|
|
{
|
|
|
|
case STMT_TYPE:
|
2009-02-23 14:48:05 +01:00
|
|
|
if (type_get_type(stmt->u.type) == TYPE_INTERFACE)
|
2009-01-06 00:35:13 +01:00
|
|
|
write_imports(header, type_iface_get_stmts(stmt->u.type));
|
2008-12-29 13:06:35 +01:00
|
|
|
break;
|
|
|
|
case STMT_TYPEREF:
|
|
|
|
case STMT_IMPORTLIB:
|
|
|
|
/* not included in header */
|
|
|
|
break;
|
|
|
|
case STMT_IMPORT:
|
|
|
|
write_import(header, stmt->u.str);
|
|
|
|
break;
|
|
|
|
case STMT_TYPEDEF:
|
|
|
|
case STMT_MODULE:
|
|
|
|
case STMT_CPPQUOTE:
|
2013-11-04 14:13:06 +01:00
|
|
|
case STMT_PRAGMA:
|
2008-12-29 13:06:35 +01:00
|
|
|
case STMT_DECLARATION:
|
|
|
|
/* not processed here */
|
|
|
|
break;
|
|
|
|
case STMT_LIBRARY:
|
|
|
|
write_imports(header, stmt->u.lib->stmts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_forward_decls(FILE *header, const statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
|
|
|
|
{
|
|
|
|
switch (stmt->type)
|
|
|
|
{
|
|
|
|
case STMT_TYPE:
|
2021-02-18 10:38:59 +01:00
|
|
|
if (type_get_type(stmt->u.type) == TYPE_INTERFACE || type_get_type(stmt->u.type) == TYPE_DELEGATE)
|
2008-12-29 13:06:35 +01:00
|
|
|
{
|
2018-11-07 16:14:06 +01:00
|
|
|
type_t *iface = stmt->u.type;
|
2021-02-18 10:38:59 +01:00
|
|
|
if (type_get_type(iface) == TYPE_DELEGATE) iface = type_delegate_get_iface(iface);
|
2018-11-07 16:14:06 +01:00
|
|
|
if (is_object(iface) || is_attr(iface->attrs, ATTR_DISPINTERFACE))
|
|
|
|
{
|
|
|
|
write_forward(header, iface);
|
2019-08-15 04:45:46 +02:00
|
|
|
if (type_iface_get_async_iface(iface))
|
|
|
|
write_forward(header, type_iface_get_async_iface(iface));
|
2018-11-07 16:14:06 +01:00
|
|
|
}
|
2008-12-29 13:06:35 +01:00
|
|
|
}
|
2009-02-23 14:48:05 +01:00
|
|
|
else if (type_get_type(stmt->u.type) == TYPE_COCLASS)
|
2008-12-29 13:06:35 +01:00
|
|
|
write_coclass_forward(header, stmt->u.type);
|
2021-01-27 21:20:45 +01:00
|
|
|
else if (type_get_type(stmt->u.type) == TYPE_RUNTIMECLASS)
|
|
|
|
write_runtimeclass_forward(header, stmt->u.type);
|
2021-02-25 14:15:09 +01:00
|
|
|
else if (type_get_type(stmt->u.type) == TYPE_PARAMETERIZED_TYPE)
|
|
|
|
write_parameterized_type_forward(header, stmt->u.type);
|
2008-12-29 13:06:35 +01:00
|
|
|
break;
|
|
|
|
case STMT_TYPEREF:
|
|
|
|
case STMT_IMPORTLIB:
|
|
|
|
/* not included in header */
|
|
|
|
break;
|
|
|
|
case STMT_IMPORT:
|
|
|
|
case STMT_TYPEDEF:
|
|
|
|
case STMT_MODULE:
|
|
|
|
case STMT_CPPQUOTE:
|
2013-11-04 14:13:06 +01:00
|
|
|
case STMT_PRAGMA:
|
2008-12-29 13:06:35 +01:00
|
|
|
case STMT_DECLARATION:
|
|
|
|
/* not processed here */
|
|
|
|
break;
|
|
|
|
case STMT_LIBRARY:
|
|
|
|
write_forward_decls(header, stmt->u.lib->stmts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_header_stmts(FILE *header, const statement_list_t *stmts, const type_t *iface, int ignore_funcs)
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
|
|
|
|
{
|
|
|
|
switch (stmt->type)
|
|
|
|
{
|
|
|
|
case STMT_TYPE:
|
2021-02-18 10:38:59 +01:00
|
|
|
if (type_get_type(stmt->u.type) == TYPE_INTERFACE || type_get_type(stmt->u.type) == TYPE_DELEGATE)
|
2008-12-29 13:06:35 +01:00
|
|
|
{
|
2021-02-18 10:38:59 +01:00
|
|
|
type_t *iface = stmt->u.type, *async_iface;
|
|
|
|
if (type_get_type(stmt->u.type) == TYPE_DELEGATE) iface = type_delegate_get_iface(iface);
|
|
|
|
async_iface = type_iface_get_async_iface(iface);
|
2010-08-27 13:52:09 +02:00
|
|
|
if (is_object(iface)) is_object_interface++;
|
2009-11-25 10:53:49 +01:00
|
|
|
if (is_attr(stmt->u.type->attrs, ATTR_DISPINTERFACE) || is_object(stmt->u.type))
|
2008-12-29 13:06:35 +01:00
|
|
|
{
|
|
|
|
write_com_interface_start(header, iface);
|
2009-01-06 00:35:13 +01:00
|
|
|
write_header_stmts(header, type_iface_get_stmts(iface), stmt->u.type, TRUE);
|
2008-12-29 13:06:35 +01:00
|
|
|
write_com_interface_end(header, iface);
|
2018-11-07 16:14:06 +01:00
|
|
|
if (async_iface)
|
|
|
|
{
|
|
|
|
write_com_interface_start(header, async_iface);
|
|
|
|
write_com_interface_end(header, async_iface);
|
|
|
|
}
|
2008-12-29 13:06:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
write_rpc_interface_start(header, iface);
|
2009-01-06 00:35:13 +01:00
|
|
|
write_header_stmts(header, type_iface_get_stmts(iface), iface, FALSE);
|
2008-12-29 13:06:35 +01:00
|
|
|
write_rpc_interface_end(header, iface);
|
|
|
|
}
|
2011-07-06 16:00:31 +02:00
|
|
|
if (is_object(iface)) is_object_interface--;
|
2008-12-29 13:06:35 +01:00
|
|
|
}
|
2009-02-23 14:48:05 +01:00
|
|
|
else if (type_get_type(stmt->u.type) == TYPE_COCLASS)
|
2008-12-29 13:06:35 +01:00
|
|
|
write_coclass(header, stmt->u.type);
|
2020-12-01 15:01:56 +01:00
|
|
|
else if (type_get_type(stmt->u.type) == TYPE_APICONTRACT)
|
|
|
|
write_apicontract(header, stmt->u.type);
|
2021-01-27 21:20:45 +01:00
|
|
|
else if (type_get_type(stmt->u.type) == TYPE_RUNTIMECLASS)
|
|
|
|
write_runtimeclass(header, stmt->u.type);
|
2021-02-11 17:37:27 +01:00
|
|
|
else if (type_get_type(stmt->u.type) != TYPE_PARAMETERIZED_TYPE)
|
2019-08-20 04:17:36 +02:00
|
|
|
write_type_definition(header, stmt->u.type, stmt->declonly);
|
2021-02-25 14:16:02 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
is_object_interface++;
|
|
|
|
write_parameterized_implementation(header, stmt->u.type, stmt->declonly);
|
|
|
|
is_object_interface--;
|
|
|
|
}
|
2008-12-29 13:06:35 +01:00
|
|
|
break;
|
|
|
|
case STMT_TYPEREF:
|
|
|
|
/* FIXME: shouldn't write out forward declarations for undefined
|
|
|
|
* interfaces but a number of our IDL files depend on this */
|
2009-02-23 14:48:05 +01:00
|
|
|
if (type_get_type(stmt->u.type) == TYPE_INTERFACE && !stmt->u.type->written)
|
2008-12-29 13:06:35 +01:00
|
|
|
write_forward(header, stmt->u.type);
|
|
|
|
break;
|
|
|
|
case STMT_IMPORTLIB:
|
|
|
|
case STMT_MODULE:
|
2013-11-04 14:13:06 +01:00
|
|
|
case STMT_PRAGMA:
|
2008-12-29 13:06:35 +01:00
|
|
|
/* not included in header */
|
|
|
|
break;
|
|
|
|
case STMT_IMPORT:
|
|
|
|
/* not processed here */
|
|
|
|
break;
|
|
|
|
case STMT_TYPEDEF:
|
|
|
|
{
|
2021-02-17 19:33:33 +01:00
|
|
|
typeref_t *ref;
|
|
|
|
if (stmt->u.type_list) LIST_FOR_EACH_ENTRY(ref, stmt->u.type_list, typeref_t, entry)
|
|
|
|
write_typedef(header, ref->type, stmt->declonly);
|
2008-12-29 13:06:35 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STMT_LIBRARY:
|
2020-09-14 14:51:06 +02:00
|
|
|
fprintf(header, "#ifndef __%s_LIBRARY_DEFINED__\n", stmt->u.lib->name);
|
|
|
|
fprintf(header, "#define __%s_LIBRARY_DEFINED__\n", stmt->u.lib->name);
|
2008-12-29 13:06:35 +01:00
|
|
|
write_library(header, stmt->u.lib);
|
|
|
|
write_header_stmts(header, stmt->u.lib->stmts, NULL, FALSE);
|
2020-09-14 14:51:06 +02:00
|
|
|
fprintf(header, "#endif /* __%s_LIBRARY_DEFINED__ */\n", stmt->u.lib->name);
|
2008-12-29 13:06:35 +01:00
|
|
|
break;
|
|
|
|
case STMT_CPPQUOTE:
|
|
|
|
fprintf(header, "%s\n", stmt->u.str);
|
|
|
|
break;
|
|
|
|
case STMT_DECLARATION:
|
2019-07-05 23:49:49 +02:00
|
|
|
if (iface && type_get_type(stmt->u.var->declspec.type) == TYPE_FUNCTION)
|
2008-12-29 13:06:35 +01:00
|
|
|
{
|
|
|
|
if (!ignore_funcs)
|
|
|
|
{
|
|
|
|
int prefixes_differ = strcmp(prefix_client, prefix_server);
|
|
|
|
|
|
|
|
if (prefixes_differ)
|
|
|
|
{
|
|
|
|
fprintf(header, "/* client prototype */\n");
|
|
|
|
write_function_proto(header, iface, stmt->u.var, prefix_client);
|
|
|
|
fprintf(header, "/* server prototype */\n");
|
|
|
|
}
|
|
|
|
write_function_proto(header, iface, stmt->u.var, prefix_server);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
write_declaration(header, stmt->u.var);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_header(const statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
FILE *header;
|
|
|
|
|
|
|
|
if (!do_header) return;
|
|
|
|
|
|
|
|
if(!(header = fopen(header_name, "w"))) {
|
|
|
|
error("Could not open %s for output\n", header_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf(header, "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n\n", PACKAGE_VERSION, input_name);
|
2011-09-22 15:01:50 +02:00
|
|
|
|
2018-11-19 15:07:02 +01:00
|
|
|
fprintf(header, "#ifdef _WIN32\n");
|
2011-09-22 15:01:50 +02:00
|
|
|
fprintf(header, "#ifndef __REQUIRED_RPCNDR_H_VERSION__\n");
|
|
|
|
fprintf(header, "#define __REQUIRED_RPCNDR_H_VERSION__ 475\n");
|
2018-11-19 15:07:02 +01:00
|
|
|
fprintf(header, "#endif\n");
|
2008-12-29 13:06:35 +01:00
|
|
|
fprintf(header, "#include <rpc.h>\n" );
|
2018-11-09 13:51:16 +01:00
|
|
|
fprintf(header, "#include <rpcndr.h>\n" );
|
|
|
|
if (!for_each_serializable(stmts, NULL, serializable_exists))
|
|
|
|
fprintf(header, "#include <midles.h>\n" );
|
2018-11-19 15:07:02 +01:00
|
|
|
fprintf(header, "#endif\n\n");
|
2008-12-29 13:06:35 +01:00
|
|
|
|
2012-01-20 15:59:02 +01:00
|
|
|
fprintf(header, "#ifndef COM_NO_WINDOWS_H\n");
|
2011-06-24 19:34:54 +02:00
|
|
|
fprintf(header, "#include <windows.h>\n");
|
|
|
|
fprintf(header, "#include <ole2.h>\n");
|
|
|
|
fprintf(header, "#endif\n\n");
|
|
|
|
|
2012-03-08 14:52:21 +01:00
|
|
|
fprintf(header, "#ifndef __%s__\n", header_token);
|
|
|
|
fprintf(header, "#define __%s__\n\n", header_token);
|
2008-12-29 13:06:35 +01:00
|
|
|
|
|
|
|
fprintf(header, "/* Forward declarations */\n\n");
|
|
|
|
write_forward_decls(header, stmts);
|
2010-09-06 17:06:59 +02:00
|
|
|
|
|
|
|
fprintf(header, "/* Headers for imported files */\n\n");
|
|
|
|
write_imports(header, stmts);
|
2008-12-29 13:06:35 +01:00
|
|
|
fprintf(header, "\n");
|
2010-09-06 17:06:59 +02:00
|
|
|
start_cplusplus_guard(header);
|
2008-12-29 13:06:35 +01:00
|
|
|
|
|
|
|
write_header_stmts(header, stmts, NULL, FALSE);
|
|
|
|
|
|
|
|
fprintf(header, "/* Begin additional prototypes for all interfaces */\n");
|
|
|
|
fprintf(header, "\n");
|
2018-11-09 13:51:16 +01:00
|
|
|
for_each_serializable(stmts, header, write_serialize_function_decl);
|
2008-12-29 13:06:35 +01:00
|
|
|
write_user_types(header);
|
|
|
|
write_generic_handle_routines(header);
|
|
|
|
write_context_handle_rundowns(header);
|
|
|
|
fprintf(header, "\n");
|
|
|
|
fprintf(header, "/* End additional prototypes */\n");
|
|
|
|
fprintf(header, "\n");
|
|
|
|
|
|
|
|
end_cplusplus_guard(header);
|
2012-03-08 14:52:21 +01:00
|
|
|
fprintf(header, "#endif /* __%s__ */\n", header_token);
|
2008-12-29 13:06:35 +01:00
|
|
|
|
|
|
|
fclose(header);
|
|
|
|
}
|