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"
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2008-03-27 15:03:17 +01:00
|
|
|
typedef struct _user_type_t generic_handle_t;
|
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
static int indentation = 0;
|
2007-09-28 02:38:13 +02:00
|
|
|
user_type_list_t user_type_list = LIST_INIT(user_type_list);
|
|
|
|
static context_handle_list_t context_handle_list = LIST_INIT(context_handle_list);
|
2008-03-27 15:03:17 +01:00
|
|
|
static struct list generic_handle_list = LIST_INIT(generic_handle_list);
|
2002-07-16 05:20:45 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
type_t *type = var->type;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (is_attr(type->attrs, t))
|
|
|
|
return 1;
|
2009-01-06 00:33:43 +01:00
|
|
|
else if (type_is_alias(type))
|
2009-01-19 01:02:28 +01:00
|
|
|
type = type_alias_get_aliasee(type);
|
2007-05-10 05:50:49 +02:00
|
|
|
else if (is_ptr(type))
|
2009-01-06 00:34:58 +01:00
|
|
|
type = type_pointer_get_ref(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))
|
2009-01-19 01:02:28 +01:00
|
|
|
t = type_alias_get_aliasee(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
|
|
|
}
|
|
|
|
|
2007-01-22 14:20:36 +01:00
|
|
|
unsigned long 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
|
|
|
}
|
|
|
|
|
2007-05-10 05:50:49 +02:00
|
|
|
int is_void(const type_t *t)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
return type_get_type(t) == TYPE_VOID;
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
int is_conformant_array(const type_t *t)
|
2007-01-22 14:31:40 +01:00
|
|
|
{
|
2009-01-07 00:20:59 +01:00
|
|
|
return is_array(t) && type_array_has_conformance(t);
|
2007-02-06 15:59:24 +01:00
|
|
|
}
|
|
|
|
|
2006-08-04 02:48:45 +02:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2008-08-30 11:15:04 +02:00
|
|
|
const char *get_name(const var_t *v)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2008-08-30 11:15:04 +02:00
|
|
|
static char buffer[256];
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2008-08-30 11:15:04 +02:00
|
|
|
if (is_attr( v->attrs, ATTR_PROPGET ))
|
|
|
|
strcpy( buffer, "get_" );
|
|
|
|
else if (is_attr( v->attrs, ATTR_PROPPUT ))
|
|
|
|
strcpy( buffer, "put_" );
|
|
|
|
else if (is_attr( v->attrs, ATTR_PROPPUTREF ))
|
|
|
|
strcpy( buffer, "putref_" );
|
|
|
|
else
|
|
|
|
buffer[0] = 0;
|
|
|
|
strcat( buffer, v->name );
|
|
|
|
return buffer;
|
2007-04-26 03:17:31 +02:00
|
|
|
}
|
|
|
|
|
2002-11-12 03:12:35 +01:00
|
|
|
static void write_field(FILE *h, var_t *v)
|
|
|
|
{
|
|
|
|
if (!v) return;
|
|
|
|
if (v->type) {
|
2007-06-06 03:50:31 +02:00
|
|
|
indent(h, 0);
|
2009-02-10 12:32:36 +01:00
|
|
|
write_type_def_or_decl(h, v->type, TRUE, v->name);
|
2002-11-12 03:12:35 +01:00
|
|
|
fprintf(h, ";\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:26:12 +01:00
|
|
|
static void write_fields(FILE *h, var_list_t *fields)
|
2002-11-12 03:12:35 +01:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
var_t *v;
|
|
|
|
if (!fields) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, fields, var_t, entry ) write_field(h, v);
|
2002-11-12 03:12:35 +01:00
|
|
|
}
|
|
|
|
|
2007-01-22 14:26:12 +01:00
|
|
|
static void write_enums(FILE *h, var_list_t *enums)
|
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 )
|
|
|
|
{
|
2007-06-06 03:49:12 +02:00
|
|
|
if (v->name) {
|
2005-08-03 16:55:22 +02:00
|
|
|
indent(h, 0);
|
2008-08-30 11:15:04 +02:00
|
|
|
fprintf(h, "%s", 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");
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
2002-11-12 03:12:35 +01:00
|
|
|
fprintf(h, "\n");
|
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
|
|
|
}
|
|
|
|
|
2007-10-03 06:39:38 +02:00
|
|
|
void write_type_left(FILE *h, type_t *t, int declonly)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2007-10-03 06:40:13 +02:00
|
|
|
if (!h) return;
|
|
|
|
|
2008-04-29 21:39:53 +02:00
|
|
|
if (is_attr(t->attrs, ATTR_CONST) &&
|
2009-03-05 09:21:35 +01:00
|
|
|
(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
|
|
|
|
2009-01-06 00:33:43 +01:00
|
|
|
if (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:
|
2008-12-29 13:06:35 +01:00
|
|
|
if (!declonly && t->defined && !t->written) {
|
2002-11-12 03:12:35 +01:00
|
|
|
if (t->name) fprintf(h, "enum %s {\n", t->name);
|
|
|
|
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++;
|
2008-12-29 13:05:27 +01:00
|
|
|
write_enums(h, type_enum_get_values(t));
|
2005-08-03 16:55:22 +02:00
|
|
|
indent(h, -1);
|
2002-11-12 03:12:35 +01:00
|
|
|
fprintf(h, "}");
|
|
|
|
}
|
2007-10-03 06:40:13 +02:00
|
|
|
else fprintf(h, "enum %s", t->name ? t->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:
|
2008-12-29 13:06:35 +01:00
|
|
|
if (!declonly && t->defined && !t->written) {
|
2002-11-12 03:12:35 +01:00
|
|
|
if (t->name) fprintf(h, "struct %s {\n", t->name);
|
|
|
|
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)
|
2008-12-29 13:05:27 +01:00
|
|
|
write_fields(h, type_encapsulated_union_get_fields(t));
|
|
|
|
else
|
|
|
|
write_fields(h, type_struct_get_fields(t));
|
2005-08-03 16:55:22 +02:00
|
|
|
indent(h, -1);
|
2002-11-12 03:12:35 +01:00
|
|
|
fprintf(h, "}");
|
|
|
|
}
|
2007-10-03 06:40:13 +02:00
|
|
|
else fprintf(h, "struct %s", t->name ? t->name : "");
|
2002-11-12 03:12:35 +01:00
|
|
|
break;
|
2009-02-23 14:48:11 +01:00
|
|
|
case TYPE_UNION:
|
2008-12-29 13:06:35 +01:00
|
|
|
if (!declonly && t->defined && !t->written) {
|
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++;
|
2008-12-29 13:05:27 +01:00
|
|
|
write_fields(h, type_union_get_cases(t));
|
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:
|
2009-01-06 00:34:58 +01:00
|
|
|
write_type_left(h, type_pointer_get_ref(t), declonly);
|
|
|
|
fprintf(h, "%s*", needs_space_after(type_pointer_get_ref(t)) ? " " : "");
|
|
|
|
if (is_attr(t->attrs, ATTR_CONST)) fprintf(h, "const ");
|
2006-07-21 21:10:21 +02:00
|
|
|
break;
|
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
|
|
|
|
{
|
|
|
|
write_type_left(h, type_array_get_element(t), declonly);
|
2009-03-05 09:21:35 +01:00
|
|
|
if (type_array_is_decl_as_ptr(t))
|
|
|
|
fprintf(h, "%s*", needs_space_after(type_array_get_element(t)) ? " " : "");
|
2009-02-23 14:48:11 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TYPE_BASIC:
|
2009-03-12 23:04:35 +01:00
|
|
|
if (type_basic_get_type(t) != TYPE_BASIC_INT32 &&
|
|
|
|
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;
|
|
|
|
case TYPE_BASIC_INT64: fprintf(h, "__int64"); break;
|
|
|
|
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:
|
|
|
|
if (type_basic_get_sign(t) > 0)
|
|
|
|
fprintf(h, "ULONG");
|
|
|
|
else
|
|
|
|
fprintf(h, "LONG");
|
|
|
|
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:
|
2006-08-25 03:01:18 +02:00
|
|
|
fprintf(h, "%s", t->name);
|
2009-02-23 14:48:11 +01:00
|
|
|
break;
|
2009-03-05 09:21:51 +01:00
|
|
|
case TYPE_VOID:
|
|
|
|
fprintf(h, "void");
|
|
|
|
break;
|
2009-02-23 14:48:11 +01:00
|
|
|
case TYPE_ALIAS:
|
|
|
|
case TYPE_FUNCTION:
|
|
|
|
/* handled elsewhere */
|
|
|
|
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;
|
|
|
|
|
2009-03-05 09:21:35 +01:00
|
|
|
if (type_get_type(t) == TYPE_ARRAY && !type_array_is_decl_as_ptr(t)) {
|
2007-06-06 03:50:31 +02:00
|
|
|
if (is_conformant_array(t)) {
|
|
|
|
fprintf(h, "[%s]", is_field ? "1" : "");
|
2009-01-06 00:34:52 +01:00
|
|
|
t = type_array_get_element(t);
|
2007-06-06 03:50:31 +02:00
|
|
|
}
|
2009-03-05 09:21:35 +01:00
|
|
|
for ( ;
|
|
|
|
type_get_type(t) == TYPE_ARRAY && !type_array_is_decl_as_ptr(t);
|
|
|
|
t = type_array_get_element(t))
|
2009-02-06 14:30:38 +01:00
|
|
|
fprintf(h, "[%u]", type_array_get_dim(t));
|
2007-06-06 03:50:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:32:36 +01:00
|
|
|
static void write_type_v(FILE *h, type_t *t, int is_field, int declonly, const char *name)
|
2007-06-06 03:50:31 +02:00
|
|
|
{
|
2008-04-02 13:56:38 +02:00
|
|
|
type_t *pt;
|
|
|
|
int ptr_level = 0;
|
|
|
|
|
2007-10-03 06:40:13 +02:00
|
|
|
if (!h) return;
|
|
|
|
|
2009-01-06 00:34:58 +01:00
|
|
|
for (pt = t; is_ptr(pt); pt = type_pointer_get_ref(pt), ptr_level++)
|
2008-04-02 13:56:38 +02:00
|
|
|
;
|
|
|
|
|
2009-02-23 14:48:11 +01:00
|
|
|
if (type_get_type_detect_alias(pt) == TYPE_FUNCTION) {
|
2008-04-02 13:56:38 +02:00
|
|
|
int i;
|
|
|
|
const char *callconv = get_attrp(pt->attrs, ATTR_CALLCONV);
|
2008-04-02 13:56:13 +02:00
|
|
|
if (!callconv) callconv = "";
|
2008-04-29 21:40:30 +02:00
|
|
|
if (is_attr(pt->attrs, ATTR_INLINE)) fprintf(h, "inline ");
|
2009-01-06 00:35:24 +01:00
|
|
|
write_type_left(h, type_function_get_rettype(pt), declonly);
|
2008-04-02 13:56:38 +02:00
|
|
|
fputc(' ', h);
|
|
|
|
if (ptr_level) fputc('(', h);
|
|
|
|
fprintf(h, "%s ", callconv);
|
|
|
|
for (i = 0; i < ptr_level; i++)
|
|
|
|
fputc('*', h);
|
2008-04-02 13:56:13 +02:00
|
|
|
} else
|
|
|
|
write_type_left(h, t, declonly);
|
2009-02-10 12:32:36 +01:00
|
|
|
|
|
|
|
if (name) fprintf(h, "%s%s", needs_space_after(t) ? " " : "", name );
|
|
|
|
|
2009-02-23 14:48:11 +01:00
|
|
|
if (type_get_type_detect_alias(pt) == TYPE_FUNCTION) {
|
2008-04-02 13:56:38 +02:00
|
|
|
if (ptr_level) fputc(')', h);
|
|
|
|
fputc('(', h);
|
2008-12-29 13:05:27 +01:00
|
|
|
write_args(h, type_function_get_args(pt), NULL, 0, FALSE);
|
2008-04-02 13:56:38 +02:00
|
|
|
fputc(')', h);
|
2008-04-02 13:56:13 +02:00
|
|
|
} else
|
|
|
|
write_type_right(h, t, is_field);
|
2007-06-06 03:50:31 +02:00
|
|
|
}
|
|
|
|
|
2009-02-10 12:32:36 +01:00
|
|
|
void write_type_def_or_decl(FILE *f, type_t *t, int field, const char *name)
|
2007-10-03 06:39:38 +02:00
|
|
|
{
|
2009-02-10 12:32:36 +01:00
|
|
|
write_type_v(f, t, field, FALSE, name);
|
2007-10-03 06:39:38 +02:00
|
|
|
}
|
|
|
|
|
2009-02-10 12:32:36 +01:00
|
|
|
void write_type_decl(FILE *f, type_t *t, const char *name)
|
2007-10-03 06:39:38 +02:00
|
|
|
{
|
2009-02-10 12:32:36 +01:00
|
|
|
write_type_v(f, t, FALSE, TRUE, name);
|
2007-10-03 06:39:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void write_type_decl_left(FILE *f, type_t *t)
|
|
|
|
{
|
|
|
|
write_type_left(f, t, TRUE);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for types which require additional prototypes to be generated in the
|
|
|
|
* header */
|
|
|
|
void check_for_additional_prototype_types(const var_list_t *list)
|
2005-09-12 22:13:40 +02:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *v;
|
|
|
|
|
|
|
|
if (!list) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, list, const var_t, entry )
|
|
|
|
{
|
2009-01-06 00:34:58 +01:00
|
|
|
type_t *type = v->type;
|
|
|
|
if (!type) continue;
|
|
|
|
for (;;) {
|
2006-08-29 23:26:03 +02:00
|
|
|
const char *name = type->name;
|
2009-01-06 00:34:58 +01:00
|
|
|
if (type->user_types_registered) break;
|
2005-09-12 22:13:40 +02:00
|
|
|
type->user_types_registered = 1;
|
2007-09-28 02:38:13 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
/* don't carry on parsing fields within this type */
|
|
|
|
break;
|
|
|
|
}
|
2009-02-23 14:48:11 +01:00
|
|
|
if ((type_get_type(type) != TYPE_BASIC ||
|
2009-03-08 00:24:00 +01:00
|
|
|
type_basic_get_type(type) != TYPE_BASIC_HANDLE) &&
|
2009-02-23 14:48:11 +01:00
|
|
|
is_attr(type->attrs, ATTR_HANDLE)) {
|
2008-03-27 15:03:17 +01:00
|
|
|
if (!generic_handle_registered(name))
|
|
|
|
{
|
|
|
|
generic_handle_t *gh = xmalloc(sizeof(*gh));
|
|
|
|
gh->name = xstrdup(name);
|
|
|
|
list_add_tail(&generic_handle_list, &gh->entry);
|
|
|
|
}
|
|
|
|
/* don't carry on parsing fields within this type */
|
|
|
|
break;
|
|
|
|
}
|
2005-09-12 22:13:40 +02:00
|
|
|
if (is_attr(type->attrs, ATTR_WIREMARSHAL)) {
|
|
|
|
if (!user_type_registered(name))
|
|
|
|
{
|
2007-06-14 01:13:04 +02: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
|
|
|
}
|
|
|
|
/* don't carry on parsing fields within this type as we are already
|
|
|
|
* using a wire marshaled type */
|
|
|
|
break;
|
|
|
|
}
|
2008-12-29 13:05:35 +01:00
|
|
|
else if (type_is_complete(type))
|
2005-09-12 22:13:40 +02:00
|
|
|
{
|
2009-02-23 14:48:11 +01:00
|
|
|
var_list_t *vars;
|
|
|
|
switch (type_get_type_detect_alias(type))
|
|
|
|
{
|
|
|
|
case TYPE_ENUM:
|
2008-12-29 13:05:27 +01:00
|
|
|
vars = type_enum_get_values(type);
|
2009-02-23 14:48:11 +01:00
|
|
|
break;
|
|
|
|
case TYPE_STRUCT:
|
2008-12-29 13:05:27 +01:00
|
|
|
vars = type_struct_get_fields(type);
|
2009-02-23 14:48:11 +01:00
|
|
|
break;
|
|
|
|
case TYPE_UNION:
|
2008-12-29 13:05:27 +01:00
|
|
|
vars = type_union_get_cases(type);
|
2009-02-23 14:48:11 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
vars = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-29 13:05:27 +01:00
|
|
|
check_for_additional_prototype_types(vars);
|
2005-09-12 22:13:40 +02:00
|
|
|
}
|
2009-01-06 00:34:58 +01:00
|
|
|
|
|
|
|
if (type_is_alias(type))
|
2009-01-19 01:02:28 +01:00
|
|
|
type = type_alias_get_aliasee(type);
|
2009-01-06 00:34:58 +01:00
|
|
|
else if (is_ptr(type))
|
|
|
|
type = type_pointer_get_ref(type);
|
|
|
|
else if (is_array(type))
|
|
|
|
type = type_array_get_element(type);
|
|
|
|
else
|
|
|
|
break;
|
2005-09-12 22:13:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
static void write_typedef(FILE *header, type_t *type)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
|
|
|
fprintf(header, "typedef ");
|
2009-02-10 12:32:36 +01:00
|
|
|
write_type_def_or_decl(header, type_alias_get_aliasee(type), FALSE, type->name);
|
2007-06-06 03:50:31 +02:00
|
|
|
fprintf(header, ";\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)
|
|
|
|
{
|
|
|
|
const type_t *t;
|
|
|
|
/* 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 */
|
|
|
|
for (t = var->type; ; )
|
|
|
|
{
|
|
|
|
if (is_attr(t->attrs, ATTR_CONST))
|
|
|
|
return TRUE;
|
|
|
|
else if (is_ptr(t))
|
2009-01-06 00:34:58 +01:00
|
|
|
t = type_pointer_get_ref(t);
|
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
|
|
|
{
|
|
|
|
switch (v->stgclass)
|
|
|
|
{
|
|
|
|
case STG_NONE:
|
|
|
|
case STG_REGISTER: /* ignored */
|
|
|
|
break;
|
|
|
|
case STG_STATIC:
|
|
|
|
fprintf(header, "static ");
|
|
|
|
break;
|
|
|
|
case STG_EXTERN:
|
|
|
|
fprintf(header, "extern ");
|
|
|
|
break;
|
|
|
|
}
|
2009-02-10 12:32:36 +01:00
|
|
|
write_type_def_or_decl(header, v->type, FALSE, v->name);
|
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
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
const var_t* get_explicit_handle_var(const var_t *func)
|
2005-12-12 12:14:03 +01:00
|
|
|
{
|
2006-02-07 12:31:43 +01:00
|
|
|
const var_t* var;
|
2005-12-12 12:14:03 +01:00
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
if (!type_get_function_args(func->type))
|
2005-12-12 12:14:03 +01:00
|
|
|
return NULL;
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
|
2009-03-05 09:21:42 +01:00
|
|
|
{
|
|
|
|
const type_t *type = var->type;
|
2009-03-08 00:24:00 +01:00
|
|
|
if (type_get_type(type) == TYPE_BASIC && type_basic_get_type(type) == TYPE_BASIC_HANDLE)
|
2005-12-12 12:14:03 +01:00
|
|
|
return var;
|
2009-03-05 09:21:42 +01:00
|
|
|
}
|
2005-12-12 12:14:03 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-03-27 15:03:17 +01:00
|
|
|
const type_t* get_explicit_generic_handle_type(const var_t* var)
|
|
|
|
{
|
|
|
|
const type_t *t;
|
2009-03-05 09:21:42 +01:00
|
|
|
for (t = var->type;
|
|
|
|
is_ptr(t) || type_is_alias(t);
|
|
|
|
t = type_is_alias(t) ? type_alias_get_aliasee(t) : type_pointer_get_ref(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;
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
const var_t* get_explicit_generic_handle_var(const var_t *func)
|
2008-03-27 15:03:17 +01:00
|
|
|
{
|
|
|
|
const var_t* var;
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
if (!type_get_function_args(func->type))
|
2008-03-27 15:03:17 +01:00
|
|
|
return NULL;
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
|
2008-03-27 15:03:17 +01:00
|
|
|
if (get_explicit_generic_handle_type(var))
|
|
|
|
return var;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
const var_t* get_context_handle_var(const var_t *func)
|
2008-04-20 23:15:29 +02:00
|
|
|
{
|
|
|
|
const var_t* var;
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
if (!type_get_function_args(func->type))
|
2008-04-20 23:15:29 +02:00
|
|
|
return NULL;
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
|
2008-04-20 23:15:29 +02:00
|
|
|
if (is_attr(var->attrs, ATTR_IN) && is_context_handle(var->type))
|
|
|
|
return var;
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-01-06 00:35:24 +01:00
|
|
|
if (!is_void(type_function_get_rettype(func->type)))
|
2006-03-29 12:42:29 +02:00
|
|
|
return 1;
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
if (!type_get_function_args(func->type))
|
2006-03-29 12:42:29 +02:00
|
|
|
return 0;
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->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 **********/
|
|
|
|
|
2007-01-22 14:20:36 +01:00
|
|
|
int is_object(const attr_list_t *list)
|
2002-12-03 20:12:07 +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 == 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
|
|
|
}
|
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void write_method_macro(FILE *header, const type_t *iface, 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))
|
|
|
|
write_method_macro(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)
|
|
|
|
{
|
|
|
|
fprintf(header, "/*** %s methods ***/\n", iface->name);
|
|
|
|
first_iface = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
if (type_get_function_args(func->type))
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->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, ") ");
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(header, "(This)->lpVtbl->%s(This", get_name(func));
|
|
|
|
if (type_get_function_args(func->type))
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:26:12 +01:00
|
|
|
void write_args(FILE *h, const var_list_t *args, const char *name, int method, int do_indent)
|
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
|
|
|
}
|
2009-02-10 12:32:36 +01:00
|
|
|
write_type_decl(h, arg->type, arg->name);
|
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)) {
|
|
|
|
const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV);
|
2008-04-11 12:01:36 +02:00
|
|
|
if (!callconv) callconv = "";
|
2005-08-03 16:55:22 +02:00
|
|
|
indent(header, 0);
|
2002-12-15 04:01:20 +01:00
|
|
|
fprintf(header, "virtual ");
|
2009-01-06 00:35:24 +01:00
|
|
|
write_type_decl_left(header, type_function_get_rettype(func->type));
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(header, " %s %s(\n", callconv, get_name(func));
|
|
|
|
write_args(header, type_get_function_args(func->type), iface->name, 2, TRUE);
|
2002-12-15 04:01:20 +01:00
|
|
|
fprintf(header, ") = 0;\n");
|
|
|
|
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)) {
|
|
|
|
const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV);
|
2008-04-11 12:01:36 +02:00
|
|
|
if (!callconv) callconv = "";
|
2005-08-03 16:55:22 +02:00
|
|
|
indent(header, 0);
|
2009-01-06 00:35:24 +01:00
|
|
|
write_type_decl_left(header, type_function_get_rettype(func->type));
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(header, " (%s *%s)(\n", callconv, get_name(func));
|
|
|
|
write_args(header, type_get_function_args(func->type), name, 1, TRUE);
|
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
|
|
|
{
|
2008-05-01 13:35:31 +02:00
|
|
|
do_write_c_method_def(header, iface, iface->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
|
|
|
{
|
2009-01-06 00:35:06 +01:00
|
|
|
do_write_c_method_def(header, type_iface_get_inherit(iface), iface->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
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
if (!is_local(func->attrs)) {
|
|
|
|
const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV);
|
2008-04-11 12:01:36 +02:00
|
|
|
if (!callconv) callconv = "";
|
2002-07-16 05:20:45 +02:00
|
|
|
/* proxy prototype */
|
2009-01-06 00:35:24 +01:00
|
|
|
write_type_decl_left(header, type_function_get_rettype(func->type));
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(header, " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(func));
|
|
|
|
write_args(header, type_get_function_args(func->type), iface->name, 1, TRUE);
|
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-01-06 00:33:27 +01:00
|
|
|
if (!is_object(iface->attrs))
|
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))
|
2009-01-06 00:33:27 +01:00
|
|
|
if (!strcmp(stmt2->u.var->name, 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 */
|
2009-01-06 00:35:24 +01:00
|
|
|
write_type_decl_left(fp, type_function_get_rettype(m->type));
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(fp, " CALLBACK %s_%s_Proxy(\n", iface->name, get_name(m));
|
|
|
|
write_args(fp, type_get_function_args(m->type), iface->name, 1, TRUE);
|
2007-10-31 03:07:36 +01:00
|
|
|
fprintf(fp, ")");
|
|
|
|
if (body) {
|
2009-01-06 00:35:24 +01:00
|
|
|
type_t *rt = type_function_get_rettype(m->type);
|
2007-10-31 03:07:36 +01:00
|
|
|
fprintf(fp, "\n{\n");
|
|
|
|
fprintf(fp, " %s\n", comment);
|
|
|
|
if (rt->name && strcmp(rt->name, "HRESULT") == 0)
|
|
|
|
fprintf(fp, " return E_NOTIMPL;\n");
|
2009-02-23 14:48:11 +01:00
|
|
|
else if (type_get_type(rt) != 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 */
|
2009-01-06 00:35:24 +01:00
|
|
|
write_type_decl_left(fp, type_function_get_rettype(func->type));
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(fp, " __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(m));
|
|
|
|
write_args(fp, type_get_function_args(func->type), iface->name, 1, TRUE);
|
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);
|
|
|
|
else if (stmt->type == STMT_LIBRARY)
|
|
|
|
write_local_stubs_stmts(local_stubs, stmt->u.lib->stmts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2008-12-29 13:06:35 +01:00
|
|
|
const char *callconv = get_attrp(fun->type->attrs, ATTR_CALLCONV);
|
2007-04-26 03:17:31 +02:00
|
|
|
|
|
|
|
/* FIXME: do we need to handle call_as? */
|
2009-01-06 00:35:24 +01:00
|
|
|
write_type_decl_left(header, type_function_get_rettype(fun->type));
|
2007-04-26 03:17:31 +02:00
|
|
|
fprintf(header, " ");
|
2008-04-11 12:02:01 +02:00
|
|
|
if (callconv) fprintf(header, "%s ", callconv);
|
2008-12-29 13:06:35 +01:00
|
|
|
fprintf(header, "%s%s(\n", prefix, get_name(fun));
|
2009-01-06 00:33:27 +01:00
|
|
|
if (type_get_function_args(fun->type))
|
|
|
|
write_args(header, type_get_function_args(fun->type), iface->name, 0, TRUE);
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-12-29 13:06:35 +01:00
|
|
|
fprintf(header, "#ifndef __%s_FWD_DEFINED__\n", iface->name);
|
|
|
|
fprintf(header, "#define __%s_FWD_DEFINED__\n", iface->name);
|
|
|
|
fprintf(header, "typedef interface %s %s;\n", iface->name, iface->name);
|
|
|
|
fprintf(header, "#endif\n\n" );
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void write_iface_guid(FILE *header, const type_t *iface)
|
2004-10-11 21:54:37 +02:00
|
|
|
{
|
2006-02-07 12:31:17 +01:00
|
|
|
const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
|
2006-08-04 02:48:45 +02:00
|
|
|
write_guid(header, "IID", iface->name, uuid);
|
2004-10-11 21:54:37 +02:00
|
|
|
}
|
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void write_dispiface_guid(FILE *header, const type_t *iface)
|
2004-10-11 21:54:37 +02:00
|
|
|
{
|
2006-02-07 12:31:17 +01:00
|
|
|
const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
|
2006-08-04 02:48:45 +02:00
|
|
|
write_guid(header, "DIID", iface->name, uuid);
|
2004-10-11 21:54:37 +02:00
|
|
|
}
|
|
|
|
|
2008-05-01 13:35:31 +02:00
|
|
|
static void write_coclass_guid(FILE *header, const type_t *cocl)
|
2004-10-11 21:54:37 +02:00
|
|
|
{
|
2006-02-07 12:31:17 +01:00
|
|
|
const UUID *uuid = get_attrp(cocl->attrs, ATTR_UUID);
|
2006-08-04 02:48:45 +02:00
|
|
|
write_guid(header, "CLSID", cocl->name, uuid);
|
2004-10-11 21:54:37 +02:00
|
|
|
}
|
|
|
|
|
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);
|
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");
|
2008-05-01 13:35:31 +02:00
|
|
|
fprintf(header,"#ifndef __%s_%sINTERFACE_DEFINED__\n", iface->name, dispinterface ? "DISP" : "");
|
|
|
|
fprintf(header,"#define __%s_%sINTERFACE_DEFINED__\n\n", iface->name, dispinterface ? "DISP" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_com_interface_end(FILE *header, type_t *iface)
|
|
|
|
{
|
|
|
|
int dispinterface = is_attr(iface->attrs, ATTR_DISPINTERFACE);
|
|
|
|
if (dispinterface)
|
|
|
|
write_dispiface_guid(header, iface);
|
|
|
|
else
|
|
|
|
write_iface_guid(header, iface);
|
2003-04-10 02:19:24 +02:00
|
|
|
/* C++ interface */
|
|
|
|
fprintf(header, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
|
2009-01-06 00:35:06 +01:00
|
|
|
if (type_iface_get_inherit(iface))
|
2004-08-23 00:31:52 +02:00
|
|
|
{
|
2009-01-06 00:35:06 +01:00
|
|
|
fprintf(header, "interface %s : public %s\n", iface->name,
|
|
|
|
type_iface_get_inherit(iface)->name);
|
2008-05-01 13:35:31 +02:00
|
|
|
fprintf(header, "{\n");
|
2004-08-23 00:31:52 +02:00
|
|
|
}
|
2003-04-12 02:09:14 +02:00
|
|
|
else
|
|
|
|
{
|
2008-05-01 13:35:31 +02:00
|
|
|
fprintf(header, "interface %s\n", iface->name);
|
|
|
|
fprintf(header, "{\n");
|
|
|
|
fprintf(header, " BEGIN_INTERFACE\n");
|
|
|
|
fprintf(header, "\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 */
|
|
|
|
if (!dispinterface)
|
|
|
|
{
|
|
|
|
indentation++;
|
|
|
|
write_cpp_method_def(header, iface);
|
|
|
|
indentation--;
|
|
|
|
}
|
2009-01-06 00:35:06 +01:00
|
|
|
if (!type_iface_get_inherit(iface))
|
2008-05-01 13:35:31 +02:00
|
|
|
fprintf(header, " END_INTERFACE\n");
|
|
|
|
fprintf(header, "};\n");
|
2003-04-10 02:19:24 +02:00
|
|
|
fprintf(header, "#else\n");
|
|
|
|
/* C interface */
|
2005-12-02 13:29:52 +01:00
|
|
|
fprintf(header, "typedef struct %sVtbl {\n", iface->name);
|
2003-04-10 02:19:24 +02:00
|
|
|
indentation++;
|
2004-08-22 04:25:05 +02:00
|
|
|
fprintf(header, " BEGIN_INTERFACE\n");
|
2003-04-10 02:19:24 +02:00
|
|
|
fprintf(header, "\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);
|
2003-04-10 02:19:24 +02:00
|
|
|
indentation--;
|
2004-08-22 04:25:05 +02:00
|
|
|
fprintf(header, " END_INTERFACE\n");
|
2005-12-02 13:29:52 +01:00
|
|
|
fprintf(header, "} %sVtbl;\n", iface->name);
|
|
|
|
fprintf(header, "interface %s {\n", iface->name);
|
2006-09-29 12:45:18 +02:00
|
|
|
fprintf(header, " CONST_VTBL %sVtbl* lpVtbl;\n", iface->name);
|
2003-04-10 02:19:24 +02:00
|
|
|
fprintf(header, "};\n");
|
|
|
|
fprintf(header, "\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 */
|
2009-01-06 00:35:06 +01:00
|
|
|
write_method_macro(header, dispinterface ? type_iface_get_inherit(iface) : iface, iface->name);
|
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 */
|
|
|
|
if (!dispinterface)
|
|
|
|
{
|
|
|
|
write_method_proto(header, iface);
|
|
|
|
write_locals(header, iface, FALSE);
|
|
|
|
fprintf(header, "\n");
|
|
|
|
}
|
|
|
|
fprintf(header,"#endif /* __%s_%sINTERFACE_DEFINED__ */\n\n", iface->name, dispinterface ? "DISP" : "");
|
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);
|
2006-02-07 12:31:43 +01:00
|
|
|
const char *var = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
|
2006-03-31 13:45:29 +02:00
|
|
|
static int allocate_written = 0;
|
|
|
|
|
|
|
|
if (!allocate_written)
|
|
|
|
{
|
|
|
|
allocate_written = 1;
|
2009-01-30 14:46:17 +01:00
|
|
|
fprintf(header, "void * __RPC_USER MIDL_user_allocate(SIZE_T);\n");
|
2006-03-31 13:45:29 +02:00
|
|
|
fprintf(header, "void __RPC_USER MIDL_user_free(void *);\n\n");
|
|
|
|
}
|
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");
|
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);
|
2008-05-01 13:35:31 +02:00
|
|
|
if (var) fprintf(header, "extern handle_t %s;\n", var);
|
|
|
|
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
|
|
|
{
|
2008-05-01 13:35:31 +02:00
|
|
|
fprintf(header,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface->name);
|
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
|
|
|
{
|
|
|
|
fprintf(header, "/*****************************************************************************\n");
|
|
|
|
fprintf(header, " * %s coclass\n", cocl->name);
|
|
|
|
fprintf(header, " */\n\n");
|
2008-05-01 13:35:31 +02:00
|
|
|
write_coclass_guid(header, cocl);
|
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);
|
|
|
|
fprintf(header, "typedef struct %s %s;\n", cocl->name, cocl->name);
|
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
|
|
|
|
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:
|
|
|
|
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:
|
2009-02-23 14:48:05 +01:00
|
|
|
if (type_get_type(stmt->u.type) == TYPE_INTERFACE)
|
2008-12-29 13:06:35 +01:00
|
|
|
{
|
|
|
|
if (is_object(stmt->u.type->attrs) || is_attr(stmt->u.type->attrs, ATTR_DISPINTERFACE))
|
|
|
|
write_forward(header, stmt->u.type);
|
|
|
|
}
|
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);
|
|
|
|
break;
|
|
|
|
case STMT_TYPEREF:
|
|
|
|
case STMT_IMPORTLIB:
|
|
|
|
/* not included in header */
|
|
|
|
break;
|
|
|
|
case STMT_IMPORT:
|
|
|
|
case STMT_TYPEDEF:
|
|
|
|
case STMT_MODULE:
|
|
|
|
case STMT_CPPQUOTE:
|
|
|
|
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:
|
2009-02-23 14:48:05 +01:00
|
|
|
if (type_get_type(stmt->u.type) == TYPE_INTERFACE)
|
2008-12-29 13:06:35 +01:00
|
|
|
{
|
|
|
|
type_t *iface = stmt->u.type;
|
|
|
|
if (is_attr(stmt->u.type->attrs, ATTR_DISPINTERFACE) || is_object(stmt->u.type->attrs))
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
write_type_def_or_decl(header, stmt->u.type, FALSE, NULL);
|
|
|
|
fprintf(header, ";\n\n");
|
|
|
|
}
|
|
|
|
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:
|
|
|
|
/* not included in header */
|
|
|
|
break;
|
|
|
|
case STMT_IMPORT:
|
|
|
|
/* not processed here */
|
|
|
|
break;
|
|
|
|
case STMT_TYPEDEF:
|
|
|
|
{
|
|
|
|
const type_list_t *type_entry = stmt->u.type_list;
|
|
|
|
for (; type_entry; type_entry = type_entry->next)
|
|
|
|
write_typedef(header, type_entry->type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STMT_LIBRARY:
|
|
|
|
write_library(header, stmt->u.lib);
|
|
|
|
write_header_stmts(header, stmt->u.lib->stmts, NULL, FALSE);
|
|
|
|
break;
|
|
|
|
case STMT_CPPQUOTE:
|
|
|
|
fprintf(header, "%s\n", stmt->u.str);
|
|
|
|
break;
|
|
|
|
case STMT_DECLARATION:
|
2009-02-23 14:48:05 +01:00
|
|
|
if (iface && type_get_type(stmt->u.var->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);
|
|
|
|
fprintf(header, "#include <rpc.h>\n" );
|
|
|
|
fprintf(header, "#include <rpcndr.h>\n\n" );
|
|
|
|
|
|
|
|
fprintf(header, "#ifndef __WIDL_%s\n", header_token);
|
|
|
|
fprintf(header, "#define __WIDL_%s\n\n", header_token);
|
|
|
|
start_cplusplus_guard(header);
|
|
|
|
|
|
|
|
fprintf(header, "/* Headers for imported files */\n\n");
|
|
|
|
write_imports(header, stmts);
|
|
|
|
fprintf(header, "\n");
|
|
|
|
|
|
|
|
/* FIXME: should be before imported file includes */
|
|
|
|
fprintf(header, "/* Forward declarations */\n\n");
|
|
|
|
write_forward_decls(header, stmts);
|
|
|
|
fprintf(header, "\n");
|
|
|
|
|
|
|
|
write_header_stmts(header, stmts, NULL, FALSE);
|
|
|
|
|
|
|
|
fprintf(header, "/* Begin additional prototypes for all interfaces */\n");
|
|
|
|
fprintf(header, "\n");
|
|
|
|
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);
|
|
|
|
fprintf(header, "#endif /* __WIDL_%s */\n", header_token);
|
|
|
|
|
|
|
|
fclose(header);
|
|
|
|
}
|