2002-07-16 03:20:45 +00: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 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-07-16 03:20:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2007-06-06 01:50:31 +00:00
|
|
|
#include <stdarg.h>
|
2002-07-16 03:20:45 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-17 18:28:43 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2002-07-16 03:20:45 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "header.h"
|
2008-04-22 10:36:38 +00:00
|
|
|
#include "expr.h"
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2008-03-27 14:03:17 +00:00
|
|
|
typedef struct _user_type_t generic_handle_t;
|
|
|
|
|
2002-07-16 03:20:45 +00:00
|
|
|
static int indentation = 0;
|
2007-09-28 00:38:13 +00: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 14:03:17 +00:00
|
|
|
static struct list generic_handle_list = LIST_INIT(generic_handle_list);
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2005-08-03 14:55:22 +00:00
|
|
|
static void indent(FILE *h, int delta)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
if (delta < 0) indentation += delta;
|
2005-08-03 14:55:22 +00:00
|
|
|
for (c=0; c<indentation; c++) fprintf(h, " ");
|
2002-07-16 03:20:45 +00:00
|
|
|
if (delta > 0) indentation += delta;
|
|
|
|
}
|
|
|
|
|
2007-05-10 03:50:49 +00: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;
|
|
|
|
else if (type->kind == TKIND_ALIAS)
|
|
|
|
type = type->orig;
|
|
|
|
else if (is_ptr(type))
|
|
|
|
type = type->ref;
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-27 14:02:58 +00: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;
|
|
|
|
else if (t->kind == TKIND_ALIAS)
|
|
|
|
t = t->orig;
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-22 13:20:36 +00:00
|
|
|
int is_attr(const attr_list_t *list, enum attr_type t)
|
2003-01-09 01:05:54 +00:00
|
|
|
{
|
2007-01-22 13:20:36 +00: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 01:05:54 +00:00
|
|
|
}
|
|
|
|
|
2007-01-22 13:20:36 +00:00
|
|
|
void *get_attrp(const attr_list_t *list, enum attr_type t)
|
2003-01-09 01:05:54 +00:00
|
|
|
{
|
2007-01-22 13:20:36 +00: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 01:05:54 +00:00
|
|
|
}
|
|
|
|
|
2007-01-22 13:20:36 +00:00
|
|
|
unsigned long get_attrv(const attr_list_t *list, enum attr_type t)
|
2003-01-09 01:05:54 +00:00
|
|
|
{
|
2007-01-22 13:20:36 +00: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 01:05:54 +00:00
|
|
|
}
|
|
|
|
|
2007-05-10 03:50:49 +00:00
|
|
|
int is_void(const type_t *t)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
|
|
|
if (!t->type && !t->ref) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-06 01:50:31 +00:00
|
|
|
int is_conformant_array(const type_t *t)
|
2007-01-22 13:31:40 +00:00
|
|
|
{
|
2007-10-18 01:06:26 +00:00
|
|
|
return t->type == RPC_FC_CARRAY
|
|
|
|
|| t->type == RPC_FC_CVARRAY
|
|
|
|
|| (t->type == RPC_FC_BOGUS_ARRAY && t->size_is);
|
2007-02-06 14:59:24 +00:00
|
|
|
}
|
|
|
|
|
2006-08-04 00:48:45 +00:00
|
|
|
void write_guid(FILE *f, const char *guid_prefix, const char *name, const UUID *uuid)
|
2005-03-05 10:49:22 +00:00
|
|
|
{
|
|
|
|
if (!uuid) return;
|
2006-10-15 10:27:34 +00:00
|
|
|
fprintf(f, "DEFINE_GUID(%s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
|
2005-03-05 10:49:22 +00: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]);
|
|
|
|
}
|
|
|
|
|
2005-12-26 12:11:33 +00:00
|
|
|
void write_name(FILE *h, const var_t *v)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2004-10-05 02:14:54 +00:00
|
|
|
if (is_attr( v->attrs, ATTR_PROPGET ))
|
|
|
|
fprintf(h, "get_" );
|
|
|
|
else if (is_attr( v->attrs, ATTR_PROPPUT ))
|
|
|
|
fprintf(h, "put_" );
|
2005-11-14 15:12:24 +00:00
|
|
|
else if (is_attr( v->attrs, ATTR_PROPPUTREF ))
|
|
|
|
fprintf(h, "putref_" );
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(h, "%s", v->name);
|
|
|
|
}
|
|
|
|
|
2007-04-26 01:17:31 +00:00
|
|
|
void write_prefix_name(FILE *h, const char *prefix, const var_t *v)
|
|
|
|
{
|
|
|
|
fprintf(h, "%s", prefix);
|
|
|
|
write_name(h, v);
|
|
|
|
}
|
|
|
|
|
2002-11-12 02:12:35 +00:00
|
|
|
static void write_field(FILE *h, var_t *v)
|
|
|
|
{
|
|
|
|
if (!v) return;
|
|
|
|
if (v->type) {
|
2007-06-06 01:50:31 +00:00
|
|
|
const char *name = v->name;
|
|
|
|
if (name == NULL) {
|
2002-11-30 01:49:46 +00:00
|
|
|
switch (v->type->type) {
|
|
|
|
case RPC_FC_STRUCT:
|
2004-09-14 19:28:12 +00:00
|
|
|
case RPC_FC_CVSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_PSTRUCT:
|
|
|
|
case RPC_FC_BOGUS_STRUCT:
|
2002-11-30 01:49:46 +00:00
|
|
|
case RPC_FC_ENCAPSULATED_UNION:
|
2007-06-06 01:50:31 +00:00
|
|
|
name = "DUMMYSTRUCTNAME";
|
2002-11-30 01:49:46 +00:00
|
|
|
break;
|
|
|
|
case RPC_FC_NON_ENCAPSULATED_UNION:
|
2007-06-06 01:50:31 +00:00
|
|
|
name = "DUMMYUNIONNAME";
|
2002-11-30 01:49:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* ? */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-06-06 01:50:31 +00:00
|
|
|
indent(h, 0);
|
2007-10-03 04:39:38 +00:00
|
|
|
write_type_def_or_decl(h, v->type, TRUE, "%s", name);
|
2002-11-12 02:12:35 +00:00
|
|
|
fprintf(h, ";\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-22 13:26:12 +00:00
|
|
|
static void write_fields(FILE *h, var_list_t *fields)
|
2002-11-12 02:12:35 +00:00
|
|
|
{
|
2007-01-22 13:26:12 +00:00
|
|
|
var_t *v;
|
|
|
|
if (!fields) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, fields, var_t, entry ) write_field(h, v);
|
2002-11-12 02:12:35 +00:00
|
|
|
}
|
|
|
|
|
2007-01-22 13:26:12 +00:00
|
|
|
static void write_enums(FILE *h, var_list_t *enums)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2007-01-22 13:26:12 +00:00
|
|
|
var_t *v;
|
|
|
|
if (!enums) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, enums, var_t, entry )
|
|
|
|
{
|
2007-06-06 01:49:12 +00:00
|
|
|
if (v->name) {
|
2005-08-03 14:55:22 +00:00
|
|
|
indent(h, 0);
|
2002-11-12 02:12:35 +00:00
|
|
|
write_name(h, v);
|
2002-11-30 01:49:46 +00:00
|
|
|
if (v->eval) {
|
|
|
|
fprintf(h, " = ");
|
2008-04-22 10:37:07 +00:00
|
|
|
write_expr(h, v->eval, 0, 1, NULL, NULL);
|
2002-11-30 01:49:46 +00:00
|
|
|
}
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
2007-01-22 13:26:12 +00:00
|
|
|
if (list_next( enums, &v->entry )) fprintf(h, ",\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
2002-11-12 02:12:35 +00:00
|
|
|
fprintf(h, "\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-06 01:50:31 +00:00
|
|
|
int needs_space_after(type_t *t)
|
2006-08-29 21:28:05 +00:00
|
|
|
{
|
2007-06-06 01:50:31 +00:00
|
|
|
return (t->kind == TKIND_ALIAS
|
|
|
|
|| (!is_ptr(t) && (!is_conformant_array(t) || t->declarray)));
|
2006-08-29 21:28:05 +00:00
|
|
|
}
|
|
|
|
|
2007-10-03 04:39:38 +00:00
|
|
|
void write_type_left(FILE *h, type_t *t, int declonly)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2007-10-03 04:40:13 +00:00
|
|
|
if (!h) return;
|
|
|
|
|
2008-04-29 19:39:53 +00:00
|
|
|
if (is_attr(t->attrs, ATTR_CONST) &&
|
|
|
|
(t->kind == TKIND_ALIAS || t->declarray || !is_ptr(t)))
|
|
|
|
fprintf(h, "const ");
|
2006-08-29 21:26:03 +00:00
|
|
|
|
2007-05-01 01:32:33 +00:00
|
|
|
if (t->kind == TKIND_ALIAS) fprintf(h, "%s", t->name);
|
2007-10-03 04:39:38 +00:00
|
|
|
else if (t->declarray) write_type_left(h, t->ref, declonly);
|
2002-07-16 03:20:45 +00:00
|
|
|
else {
|
2006-08-29 21:26:03 +00:00
|
|
|
if (t->sign > 0) fprintf(h, "signed ");
|
|
|
|
else if (t->sign < 0) fprintf(h, "unsigned ");
|
|
|
|
switch (t->type) {
|
2002-11-12 02:12:35 +00:00
|
|
|
case RPC_FC_ENUM16:
|
|
|
|
case RPC_FC_ENUM32:
|
2007-10-03 04:39:38 +00:00
|
|
|
if (!declonly && t->defined && !t->written && !t->ignore) {
|
2002-11-12 02:12:35 +00:00
|
|
|
if (t->name) fprintf(h, "enum %s {\n", t->name);
|
|
|
|
else fprintf(h, "enum {\n");
|
2002-11-30 01:49:46 +00:00
|
|
|
t->written = TRUE;
|
2002-11-12 02:12:35 +00:00
|
|
|
indentation++;
|
2008-04-02 11:55:53 +00:00
|
|
|
write_enums(h, t->fields_or_args);
|
2005-08-03 14:55:22 +00:00
|
|
|
indent(h, -1);
|
2002-11-12 02:12:35 +00:00
|
|
|
fprintf(h, "}");
|
|
|
|
}
|
2007-10-03 04:40:13 +00:00
|
|
|
else fprintf(h, "enum %s", t->name ? t->name : "");
|
2002-11-12 02:12:35 +00:00
|
|
|
break;
|
2002-07-16 03:20:45 +00:00
|
|
|
case RPC_FC_STRUCT:
|
2004-09-14 19:28:12 +00:00
|
|
|
case RPC_FC_CVSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_PSTRUCT:
|
|
|
|
case RPC_FC_BOGUS_STRUCT:
|
2002-11-12 02:12:35 +00:00
|
|
|
case RPC_FC_ENCAPSULATED_UNION:
|
2007-10-03 04:39:38 +00:00
|
|
|
if (!declonly && t->defined && !t->written && !t->ignore) {
|
2002-11-12 02:12:35 +00:00
|
|
|
if (t->name) fprintf(h, "struct %s {\n", t->name);
|
|
|
|
else fprintf(h, "struct {\n");
|
2002-11-30 01:49:46 +00:00
|
|
|
t->written = TRUE;
|
2002-11-12 02:12:35 +00:00
|
|
|
indentation++;
|
2008-04-02 11:55:53 +00:00
|
|
|
write_fields(h, t->fields_or_args);
|
2005-08-03 14:55:22 +00:00
|
|
|
indent(h, -1);
|
2002-11-12 02:12:35 +00:00
|
|
|
fprintf(h, "}");
|
|
|
|
}
|
2007-10-03 04:40:13 +00:00
|
|
|
else fprintf(h, "struct %s", t->name ? t->name : "");
|
2002-11-12 02:12:35 +00:00
|
|
|
break;
|
2002-07-16 03:20:45 +00:00
|
|
|
case RPC_FC_NON_ENCAPSULATED_UNION:
|
2007-10-03 04:39:38 +00:00
|
|
|
if (!declonly && t->defined && !t->written && !t->ignore) {
|
2002-07-16 03:20:45 +00:00
|
|
|
if (t->name) fprintf(h, "union %s {\n", t->name);
|
|
|
|
else fprintf(h, "union {\n");
|
2002-11-30 01:49:46 +00:00
|
|
|
t->written = TRUE;
|
2002-07-16 03:20:45 +00:00
|
|
|
indentation++;
|
2008-04-02 11:55:53 +00:00
|
|
|
write_fields(h, t->fields_or_args);
|
2005-08-03 14:55:22 +00:00
|
|
|
indent(h, -1);
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(h, "}");
|
|
|
|
}
|
2007-10-03 04:40:13 +00:00
|
|
|
else fprintf(h, "union %s", t->name ? t->name : "");
|
2002-07-16 03:20:45 +00:00
|
|
|
break;
|
2006-08-29 01:30:16 +00:00
|
|
|
case RPC_FC_RP:
|
|
|
|
case RPC_FC_UP:
|
2006-07-21 19:10:21 +00:00
|
|
|
case RPC_FC_FP:
|
2006-08-29 01:30:16 +00:00
|
|
|
case RPC_FC_OP:
|
2007-06-06 01:50:31 +00:00
|
|
|
case RPC_FC_CARRAY:
|
|
|
|
case RPC_FC_CVARRAY:
|
2007-09-16 21:28:30 +00:00
|
|
|
case RPC_FC_BOGUS_ARRAY:
|
2007-10-03 04:39:38 +00:00
|
|
|
write_type_left(h, t->ref, declonly);
|
2006-08-29 21:28:05 +00:00
|
|
|
fprintf(h, "%s*", needs_space_after(t->ref) ? " " : "");
|
2008-04-29 19:39:53 +00:00
|
|
|
if (is_ptr(t) && is_attr(t->attrs, ATTR_CONST)) fprintf(h, "const ");
|
2006-07-21 19:10:21 +00:00
|
|
|
break;
|
2002-07-16 03:20:45 +00:00
|
|
|
default:
|
2006-08-25 01:01:18 +00:00
|
|
|
fprintf(h, "%s", t->name);
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-06 01:50:31 +00:00
|
|
|
void write_type_right(FILE *h, type_t *t, int is_field)
|
|
|
|
{
|
2007-10-03 04:40:13 +00:00
|
|
|
if (!h) return;
|
|
|
|
|
2007-06-06 01:50:31 +00:00
|
|
|
if (t->declarray) {
|
|
|
|
if (is_conformant_array(t)) {
|
|
|
|
fprintf(h, "[%s]", is_field ? "1" : "");
|
|
|
|
t = t->ref;
|
|
|
|
}
|
|
|
|
for ( ; t->declarray; t = t->ref)
|
|
|
|
fprintf(h, "[%lu]", t->dim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-03 04:39:38 +00:00
|
|
|
void write_type_v(FILE *h, type_t *t, int is_field, int declonly,
|
|
|
|
const char *fmt, va_list args)
|
2007-06-06 01:50:31 +00:00
|
|
|
{
|
2008-04-02 11:56:38 +00:00
|
|
|
type_t *pt;
|
|
|
|
int ptr_level = 0;
|
|
|
|
|
2007-10-03 04:40:13 +00:00
|
|
|
if (!h) return;
|
|
|
|
|
2008-04-02 11:56:38 +00:00
|
|
|
for (pt = t; is_ptr(pt); pt = pt->ref, ptr_level++)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (pt->type == RPC_FC_FUNCTION) {
|
|
|
|
int i;
|
|
|
|
const char *callconv = get_attrp(pt->attrs, ATTR_CALLCONV);
|
2008-04-02 11:56:13 +00:00
|
|
|
if (!callconv) callconv = "";
|
2008-04-29 19:40:30 +00:00
|
|
|
if (is_attr(pt->attrs, ATTR_INLINE)) fprintf(h, "inline ");
|
2008-04-02 11:56:38 +00:00
|
|
|
write_type_left(h, pt->ref, declonly);
|
|
|
|
fputc(' ', h);
|
|
|
|
if (ptr_level) fputc('(', h);
|
|
|
|
fprintf(h, "%s ", callconv);
|
|
|
|
for (i = 0; i < ptr_level; i++)
|
|
|
|
fputc('*', h);
|
2008-04-02 11:56:13 +00:00
|
|
|
} else
|
|
|
|
write_type_left(h, t, declonly);
|
2007-06-06 01:50:31 +00:00
|
|
|
if (fmt) {
|
|
|
|
if (needs_space_after(t))
|
2008-04-02 11:56:38 +00:00
|
|
|
fputc(' ', h);
|
2007-06-06 01:50:31 +00:00
|
|
|
vfprintf(h, fmt, args);
|
|
|
|
}
|
2008-04-02 11:56:38 +00:00
|
|
|
if (pt->type == RPC_FC_FUNCTION) {
|
|
|
|
if (ptr_level) fputc(')', h);
|
|
|
|
fputc('(', h);
|
|
|
|
write_args(h, pt->fields_or_args, NULL, 0, FALSE);
|
|
|
|
fputc(')', h);
|
2008-04-02 11:56:13 +00:00
|
|
|
} else
|
|
|
|
write_type_right(h, t, is_field);
|
2007-06-06 01:50:31 +00:00
|
|
|
}
|
|
|
|
|
2007-10-03 04:39:38 +00:00
|
|
|
void write_type_def_or_decl(FILE *f, type_t *t, int field, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
write_type_v(f, t, field, FALSE, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_type_decl(FILE *f, type_t *t, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
write_type_v(f, t, FALSE, TRUE, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_type_decl_left(FILE *f, type_t *t)
|
|
|
|
{
|
|
|
|
write_type_left(f, t, TRUE);
|
|
|
|
}
|
|
|
|
|
2005-09-12 20:13:40 +00:00
|
|
|
static int user_type_registered(const char *name)
|
|
|
|
{
|
2007-06-13 23:13:04 +00:00
|
|
|
user_type_t *ut;
|
|
|
|
LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
|
2005-09-12 20:13:40 +00:00
|
|
|
if (!strcmp(name, ut->name))
|
2007-06-13 23:13:04 +00:00
|
|
|
return 1;
|
2005-09-12 20:13:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-28 00:38:13 +00: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 14:03:17 +00: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 20:13:40 +00:00
|
|
|
{
|
2007-01-22 13:26:12 +00:00
|
|
|
const var_t *v;
|
|
|
|
|
|
|
|
if (!list) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, list, const var_t, entry )
|
|
|
|
{
|
2006-08-29 21:26:03 +00:00
|
|
|
type_t *type;
|
|
|
|
for (type = v->type; type; type = type->kind == TKIND_ALIAS ? type->orig : type->ref) {
|
|
|
|
const char *name = type->name;
|
2005-09-12 20:13:40 +00:00
|
|
|
if (type->user_types_registered) continue;
|
|
|
|
type->user_types_registered = 1;
|
2007-09-28 00:38:13 +00: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;
|
|
|
|
}
|
2008-03-27 14:03:17 +00:00
|
|
|
if (type->type != RPC_FC_BIND_PRIMITIVE && 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);
|
|
|
|
}
|
|
|
|
/* don't carry on parsing fields within this type */
|
|
|
|
break;
|
|
|
|
}
|
2005-09-12 20:13:40 +00:00
|
|
|
if (is_attr(type->attrs, ATTR_WIREMARSHAL)) {
|
|
|
|
if (!user_type_registered(name))
|
|
|
|
{
|
2007-06-13 23:13:04 +00:00
|
|
|
user_type_t *ut = xmalloc(sizeof *ut);
|
|
|
|
ut->name = xstrdup(name);
|
|
|
|
list_add_tail(&user_type_list, &ut->entry);
|
2005-09-12 20:13:40 +00:00
|
|
|
}
|
|
|
|
/* don't carry on parsing fields within this type as we are already
|
|
|
|
* using a wire marshaled type */
|
|
|
|
break;
|
|
|
|
}
|
2007-01-22 13:26:12 +00:00
|
|
|
else
|
2005-09-12 20:13:40 +00:00
|
|
|
{
|
2008-04-02 11:55:53 +00:00
|
|
|
check_for_additional_prototype_types(type->fields_or_args);
|
2005-09-12 20:13:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_user_types(void)
|
|
|
|
{
|
2007-06-13 23:13:04 +00:00
|
|
|
user_type_t *ut;
|
|
|
|
LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
|
2005-09-12 20:13:40 +00:00
|
|
|
{
|
|
|
|
const char *name = ut->name;
|
2006-11-08 22:43:28 +00:00
|
|
|
fprintf(header, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name, name);
|
2006-11-08 22:43:45 +00:00
|
|
|
fprintf(header, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name, name);
|
2006-11-08 22:44:00 +00:00
|
|
|
fprintf(header, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name, name);
|
2006-11-08 22:44:10 +00:00
|
|
|
fprintf(header, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name, name);
|
2005-09-12 20:13:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-28 00:38:13 +00:00
|
|
|
void write_context_handle_rundowns(void)
|
|
|
|
{
|
|
|
|
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-03-27 14:03:17 +00:00
|
|
|
void write_generic_handle_routines(void)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-29 21:26:03 +00:00
|
|
|
void write_typedef(type_t *type)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
|
|
|
fprintf(header, "typedef ");
|
2007-10-03 04:39:38 +00:00
|
|
|
write_type_def_or_decl(header, type->orig, FALSE, "%s", type->name);
|
2007-06-06 01:50:31 +00:00
|
|
|
fprintf(header, ";\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
|
|
|
|
2008-04-30 14:23:23 +00: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))
|
|
|
|
t = t->ref;
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2002-11-30 01:49:46 +00:00
|
|
|
}
|
|
|
|
|
2008-04-30 14:23:23 +00:00
|
|
|
void write_declaration(const var_t *v, int is_in_interface)
|
2002-11-30 01:49:46 +00:00
|
|
|
{
|
2008-04-30 14:23:23 +00:00
|
|
|
if (is_const_decl(v) && v->eval)
|
|
|
|
{
|
|
|
|
fprintf(header, "#define %s (", v->name);
|
|
|
|
write_expr(header, v->eval, 0, 1, NULL, NULL);
|
|
|
|
fprintf(header, ")\n\n");
|
|
|
|
}
|
|
|
|
else if (v->type->type != RPC_FC_FUNCTION || !is_in_interface)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
write_type_def_or_decl(header, v->type, FALSE, "%s", v->name);
|
|
|
|
fprintf(header, ";\n\n");
|
|
|
|
}
|
2002-11-30 01:49:46 +00:00
|
|
|
}
|
|
|
|
|
2008-04-24 18:06:28 +00:00
|
|
|
void write_library(const typelib_t *typelib)
|
2007-01-22 13:20:36 +00:00
|
|
|
{
|
2008-04-24 18:06:28 +00:00
|
|
|
const UUID *uuid = get_attrp(typelib->attrs, ATTR_UUID);
|
2005-03-05 10:49:22 +00:00
|
|
|
fprintf(header, "\n");
|
2008-04-24 18:06:28 +00:00
|
|
|
write_guid(header, "LIBID", typelib->name, uuid);
|
2005-03-05 10:49:22 +00:00
|
|
|
fprintf(header, "\n");
|
|
|
|
}
|
|
|
|
|
2005-12-12 11:14:03 +00:00
|
|
|
|
2006-02-07 11:31:43 +00:00
|
|
|
const var_t* get_explicit_handle_var(const func_t* func)
|
2005-12-12 11:14:03 +00:00
|
|
|
{
|
2006-02-07 11:31:43 +00:00
|
|
|
const var_t* var;
|
2005-12-12 11:14:03 +00:00
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return NULL;
|
|
|
|
|
2007-01-22 13:26:12 +00:00
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
2006-01-31 17:06:17 +00:00
|
|
|
if (var->type->type == RPC_FC_BIND_PRIMITIVE)
|
2005-12-12 11:14:03 +00:00
|
|
|
return var;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-03-27 14:03:17 +00:00
|
|
|
const type_t* get_explicit_generic_handle_type(const var_t* var)
|
|
|
|
{
|
|
|
|
const type_t *t;
|
|
|
|
for (t = var->type; is_ptr(t); t = t->ref)
|
|
|
|
if (t->type != RPC_FC_BIND_PRIMITIVE && is_attr(t->attrs, ATTR_HANDLE))
|
|
|
|
return t;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const var_t* get_explicit_generic_handle_var(const func_t* func)
|
|
|
|
{
|
|
|
|
const var_t* var;
|
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
|
|
|
if (get_explicit_generic_handle_type(var))
|
|
|
|
return var;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-04-20 21:15:29 +00:00
|
|
|
const var_t* get_context_handle_var(const func_t* func)
|
|
|
|
{
|
|
|
|
const var_t* var;
|
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
|
|
|
if (is_attr(var->attrs, ATTR_IN) && is_context_handle(var->type))
|
|
|
|
return var;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-03-29 10:42:29 +00:00
|
|
|
int has_out_arg_or_return(const func_t *func)
|
|
|
|
{
|
2007-01-22 13:26:12 +00:00
|
|
|
const var_t *var;
|
2006-03-29 10:42:29 +00:00
|
|
|
|
2008-04-02 11:55:34 +00:00
|
|
|
if (!is_void(get_func_return_type(func)))
|
2006-03-29 10:42:29 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return 0;
|
|
|
|
|
2007-01-22 13:26:12 +00:00
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
2006-03-29 10:42:29 +00:00
|
|
|
if (is_attr(var->attrs, ATTR_OUT))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-12-12 11:14:03 +00:00
|
|
|
|
2002-07-16 03:20:45 +00:00
|
|
|
/********** INTERFACES **********/
|
|
|
|
|
2007-01-22 13:20:36 +00:00
|
|
|
int is_object(const attr_list_t *list)
|
2002-12-03 19:12:07 +00:00
|
|
|
{
|
2007-01-22 13:20:36 +00: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 19:12:07 +00:00
|
|
|
}
|
|
|
|
|
2007-01-22 13:20:36 +00:00
|
|
|
int is_local(const attr_list_t *a)
|
2002-12-03 19:12:07 +00:00
|
|
|
{
|
|
|
|
return is_attr(a, ATTR_LOCAL);
|
|
|
|
}
|
|
|
|
|
2007-01-22 13:20:36 +00:00
|
|
|
const var_t *is_callas(const attr_list_t *a)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2002-12-03 19:12:07 +00:00
|
|
|
return get_attrp(a, ATTR_CALLAS);
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_method_macro(FILE *header, const type_t *iface, const char *name)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2007-01-22 13:23:08 +00:00
|
|
|
const func_t *cur;
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
if (iface->ref) write_method_macro(header, iface->ref, name);
|
2003-07-22 03:18:46 +00:00
|
|
|
|
2007-01-22 13:23:08 +00:00
|
|
|
if (!iface->funcs) return;
|
2003-07-22 03:18:46 +00:00
|
|
|
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(header, "/*** %s methods ***/\n", iface->name);
|
2007-01-22 13:23:08 +00:00
|
|
|
LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
|
|
|
|
{
|
2002-07-16 03:20:45 +00:00
|
|
|
var_t *def = cur->def;
|
|
|
|
if (!is_callas(def->attrs)) {
|
2007-01-22 13:26:12 +00:00
|
|
|
const var_t *arg;
|
2002-07-16 03:20:45 +00:00
|
|
|
|
|
|
|
fprintf(header, "#define %s_", name);
|
|
|
|
write_name(header,def);
|
2008-01-18 11:03:22 +00:00
|
|
|
fprintf(header, "(This");
|
|
|
|
if (cur->args)
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
|
|
|
|
fprintf(header, ",%s", arg->name);
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(header, ") ");
|
|
|
|
|
2008-01-18 11:03:22 +00:00
|
|
|
fprintf(header, "(This)->lpVtbl->");
|
2003-04-10 21:13:58 +00:00
|
|
|
write_name(header, def);
|
2008-01-18 11:03:22 +00:00
|
|
|
fprintf(header, "(This");
|
|
|
|
if (cur->args)
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
|
|
|
|
fprintf(header, ",%s", arg->name);
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(header, ")\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-22 13:26:12 +00:00
|
|
|
void write_args(FILE *h, const var_list_t *args, const char *name, int method, int do_indent)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2007-01-22 13:26:12 +00:00
|
|
|
const var_t *arg;
|
2002-12-03 19:12:07 +00:00
|
|
|
int count = 0;
|
2007-01-22 13:26:12 +00:00
|
|
|
|
2003-09-03 20:16:24 +00:00
|
|
|
if (do_indent)
|
|
|
|
{
|
2005-08-03 14:55:22 +00:00
|
|
|
indentation++;
|
|
|
|
indent(h, 0);
|
2003-09-03 20:16:24 +00:00
|
|
|
}
|
2002-12-15 03:01:20 +00:00
|
|
|
if (method == 1) {
|
|
|
|
fprintf(h, "%s* This", name);
|
2002-12-03 19:12:07 +00:00
|
|
|
count++;
|
|
|
|
}
|
2007-01-22 13:26:12 +00:00
|
|
|
if (args) LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry ) {
|
2002-12-15 03:01:20 +00:00
|
|
|
if (count) {
|
2003-09-03 20:16:24 +00:00
|
|
|
if (do_indent)
|
|
|
|
{
|
|
|
|
fprintf(h, ",\n");
|
2005-08-03 14:55:22 +00:00
|
|
|
indent(h, 0);
|
2003-09-03 20:16:24 +00:00
|
|
|
}
|
|
|
|
else fprintf(h, ",");
|
2002-12-15 03:01:20 +00:00
|
|
|
}
|
2008-04-02 11:56:13 +00:00
|
|
|
write_type_decl(h, arg->type, "%s", arg->name);
|
2002-12-03 19:12:07 +00:00
|
|
|
count++;
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
2005-08-03 14:55:22 +00:00
|
|
|
if (do_indent) indentation--;
|
2002-12-15 03:01:20 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_cpp_method_def(FILE *header, const type_t *iface)
|
2002-12-15 03:01:20 +00:00
|
|
|
{
|
2007-01-22 13:23:08 +00:00
|
|
|
const func_t *cur;
|
|
|
|
|
|
|
|
if (!iface->funcs) return;
|
2003-07-22 03:18:46 +00:00
|
|
|
|
2007-01-22 13:23:08 +00:00
|
|
|
LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
|
|
|
|
{
|
2002-12-15 03:01:20 +00:00
|
|
|
var_t *def = cur->def;
|
|
|
|
if (!is_callas(def->attrs)) {
|
2008-04-11 10:01:36 +00:00
|
|
|
const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV);
|
|
|
|
if (!callconv) callconv = "";
|
2005-08-03 14:55:22 +00:00
|
|
|
indent(header, 0);
|
2002-12-15 03:01:20 +00:00
|
|
|
fprintf(header, "virtual ");
|
2008-04-02 11:55:34 +00:00
|
|
|
write_type_decl_left(header, get_func_return_type(cur));
|
2008-04-11 10:01:36 +00:00
|
|
|
fprintf(header, " %s ", callconv);
|
2002-12-15 03:01:20 +00:00
|
|
|
write_name(header, def);
|
|
|
|
fprintf(header, "(\n");
|
2003-09-03 20:16:24 +00:00
|
|
|
write_args(header, cur->args, iface->name, 2, TRUE);
|
2002-12-15 03:01:20 +00:00
|
|
|
fprintf(header, ") = 0;\n");
|
|
|
|
fprintf(header, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void do_write_c_method_def(FILE *header, const type_t *iface, const char *name)
|
2002-12-15 03:01:20 +00:00
|
|
|
{
|
2007-01-22 13:23:08 +00:00
|
|
|
const func_t *cur;
|
2002-12-15 03:01:20 +00:00
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
if (iface->ref) do_write_c_method_def(header, iface->ref, name);
|
2003-07-22 03:18:46 +00:00
|
|
|
|
2007-01-22 13:23:08 +00:00
|
|
|
if (!iface->funcs) return;
|
2005-08-03 14:55:22 +00:00
|
|
|
indent(header, 0);
|
2002-12-15 03:01:20 +00:00
|
|
|
fprintf(header, "/*** %s methods ***/\n", iface->name);
|
2007-01-22 13:23:08 +00:00
|
|
|
LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
|
|
|
|
{
|
2006-02-07 11:31:17 +00:00
|
|
|
const var_t *def = cur->def;
|
2002-12-15 03:01:20 +00:00
|
|
|
if (!is_callas(def->attrs)) {
|
2008-04-11 10:01:36 +00:00
|
|
|
const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV);
|
|
|
|
if (!callconv) callconv = "";
|
2005-08-03 14:55:22 +00:00
|
|
|
indent(header, 0);
|
2008-04-02 11:55:34 +00:00
|
|
|
write_type_decl_left(header, get_func_return_type(cur));
|
2008-04-11 10:01:36 +00:00
|
|
|
fprintf(header, " (%s *", callconv);
|
2002-12-15 03:01:20 +00:00
|
|
|
write_name(header, def);
|
|
|
|
fprintf(header, ")(\n");
|
2003-09-03 20:16:24 +00:00
|
|
|
write_args(header, cur->args, name, 1, TRUE);
|
2002-12-15 03:01:20 +00:00
|
|
|
fprintf(header, ");\n");
|
|
|
|
fprintf(header, "\n");
|
|
|
|
}
|
|
|
|
}
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_c_method_def(FILE *header, const type_t *iface)
|
2003-01-09 01:05:54 +00:00
|
|
|
{
|
2008-05-01 11:35:31 +00:00
|
|
|
do_write_c_method_def(header, iface, iface->name);
|
2003-01-09 01:05:54 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_c_disp_method_def(FILE *header, const type_t *iface)
|
2004-10-11 19:54:37 +00:00
|
|
|
{
|
2008-05-01 11:35:31 +00:00
|
|
|
do_write_c_method_def(header, iface->ref, iface->name);
|
2004-10-11 19:54:37 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_method_proto(FILE *header, const type_t *iface)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2007-01-22 13:23:08 +00:00
|
|
|
const func_t *cur;
|
2003-07-22 03:18:46 +00:00
|
|
|
|
2007-01-22 13:23:08 +00:00
|
|
|
if (!iface->funcs) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
|
|
|
|
{
|
2006-02-07 11:31:17 +00:00
|
|
|
const var_t *def = cur->def;
|
2007-01-22 13:26:12 +00:00
|
|
|
|
2002-07-16 03:20:45 +00:00
|
|
|
if (!is_local(def->attrs)) {
|
2008-04-11 10:01:36 +00:00
|
|
|
const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV);
|
|
|
|
if (!callconv) callconv = "";
|
2002-07-16 03:20:45 +00:00
|
|
|
/* proxy prototype */
|
2008-04-02 11:55:34 +00:00
|
|
|
write_type_decl_left(header, get_func_return_type(cur));
|
2008-04-11 10:01:36 +00:00
|
|
|
fprintf(header, " %s %s_", callconv, iface->name);
|
2002-12-03 19:12:07 +00:00
|
|
|
write_name(header, def);
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(header, "_Proxy(\n");
|
2003-09-03 20:16:24 +00:00
|
|
|
write_args(header, cur->args, iface->name, 1, TRUE);
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(header, ");\n");
|
|
|
|
/* stub prototype */
|
|
|
|
fprintf(header, "void __RPC_STUB %s_", iface->name);
|
|
|
|
write_name(header,def);
|
|
|
|
fprintf(header, "_Stub(\n");
|
2005-12-02 12:32:09 +00:00
|
|
|
fprintf(header, " IRpcStubBuffer* This,\n");
|
|
|
|
fprintf(header, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(header, " PRPC_MESSAGE pRpcMessage,\n");
|
|
|
|
fprintf(header, " DWORD* pdwStubPhase);\n");
|
|
|
|
}
|
2007-10-31 02:07:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_locals(FILE *fp, const type_t *iface, int body)
|
|
|
|
{
|
|
|
|
static const char comment[]
|
|
|
|
= "/* WIDL-generated stub. You must provide an implementation for this. */";
|
|
|
|
const func_list_t *funcs = iface->funcs;
|
|
|
|
const func_t *cur;
|
|
|
|
|
|
|
|
if (!is_object(iface->attrs) || !funcs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(cur, funcs, const func_t, entry) {
|
|
|
|
const var_t *def = cur->def;
|
|
|
|
const var_t *cas = is_callas(def->attrs);
|
|
|
|
|
2002-07-16 03:20:45 +00:00
|
|
|
if (cas) {
|
2007-01-22 13:23:08 +00:00
|
|
|
const func_t *m;
|
2007-10-31 02:07:36 +00:00
|
|
|
LIST_FOR_EACH_ENTRY(m, iface->funcs, const func_t, entry)
|
|
|
|
if (!strcmp(m->def->name, cas->name))
|
|
|
|
break;
|
2007-01-22 13:23:08 +00:00
|
|
|
if (&m->entry != iface->funcs) {
|
2006-02-07 11:31:17 +00:00
|
|
|
const var_t *mdef = m->def;
|
2002-07-16 03:20:45 +00:00
|
|
|
/* proxy prototype - use local prototype */
|
2008-04-02 11:55:34 +00:00
|
|
|
write_type_decl_left(fp, get_func_return_type(m));
|
2007-10-31 02:07:36 +00:00
|
|
|
fprintf(fp, " CALLBACK %s_", iface->name);
|
|
|
|
write_name(fp, mdef);
|
|
|
|
fprintf(fp, "_Proxy(\n");
|
|
|
|
write_args(fp, m->args, iface->name, 1, TRUE);
|
|
|
|
fprintf(fp, ")");
|
|
|
|
if (body) {
|
2008-04-02 11:55:34 +00:00
|
|
|
type_t *rt = get_func_return_type(m);
|
2007-10-31 02:07:36 +00:00
|
|
|
fprintf(fp, "\n{\n");
|
|
|
|
fprintf(fp, " %s\n", comment);
|
|
|
|
if (rt->name && strcmp(rt->name, "HRESULT") == 0)
|
|
|
|
fprintf(fp, " return E_NOTIMPL;\n");
|
|
|
|
else if (rt->type) {
|
|
|
|
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 03:20:45 +00:00
|
|
|
/* stub prototype - use remotable prototype */
|
2008-04-02 11:55:34 +00:00
|
|
|
write_type_decl_left(fp, get_func_return_type(cur));
|
2007-10-31 02:07:36 +00:00
|
|
|
fprintf(fp, " __RPC_STUB %s_", iface->name);
|
|
|
|
write_name(fp, mdef);
|
|
|
|
fprintf(fp, "_Stub(\n");
|
|
|
|
write_args(fp, cur->args, iface->name, 1, TRUE);
|
|
|
|
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 03:20:45 +00:00
|
|
|
}
|
2007-10-31 02:07:36 +00:00
|
|
|
else
|
|
|
|
error_loc("invalid call_as attribute (%s -> %s)\n", def->name, cas->name);
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_function_proto(FILE *header, const type_t *iface, const func_t *fun, const char *prefix)
|
2007-04-26 01:17:31 +00:00
|
|
|
{
|
|
|
|
var_t *def = fun->def;
|
2008-04-11 10:02:01 +00:00
|
|
|
const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV);
|
2007-04-26 01:17:31 +00:00
|
|
|
|
|
|
|
/* FIXME: do we need to handle call_as? */
|
2008-04-02 11:55:34 +00:00
|
|
|
write_type_decl_left(header, get_func_return_type(fun));
|
2007-04-26 01:17:31 +00:00
|
|
|
fprintf(header, " ");
|
2008-04-11 10:02:01 +00:00
|
|
|
if (callconv) fprintf(header, "%s ", callconv);
|
2007-04-26 01:17:31 +00:00
|
|
|
write_prefix_name(header, prefix, def);
|
|
|
|
fprintf(header, "(\n");
|
|
|
|
if (fun->args)
|
|
|
|
write_args(header, fun->args, iface->name, 0, TRUE);
|
|
|
|
else
|
|
|
|
fprintf(header, " void");
|
2008-04-02 11:56:27 +00:00
|
|
|
fprintf(header, ");\n\n");
|
2007-04-26 01:17:31 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_function_protos(FILE *header, const type_t *iface)
|
2002-12-03 19:12:07 +00:00
|
|
|
{
|
2007-01-22 13:23:08 +00:00
|
|
|
const func_t *cur;
|
2007-04-26 01:17:31 +00:00
|
|
|
int prefixes_differ = strcmp(prefix_client, prefix_server);
|
2005-12-12 11:14:03 +00:00
|
|
|
|
2007-01-22 13:23:08 +00:00
|
|
|
if (!iface->funcs) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
|
|
|
|
{
|
2007-04-26 01:17:31 +00:00
|
|
|
if (prefixes_differ) {
|
|
|
|
fprintf(header, "/* client prototype */\n");
|
2008-05-01 11:35:31 +00:00
|
|
|
write_function_proto(header, iface, cur, prefix_client);
|
2007-04-26 01:17:31 +00:00
|
|
|
fprintf(header, "/* server prototype */\n");
|
|
|
|
}
|
2008-05-01 11:35:31 +00:00
|
|
|
write_function_proto(header, iface, cur, prefix_server);
|
2002-12-03 19:12:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-16 03:20:45 +00:00
|
|
|
void write_forward(type_t *iface)
|
|
|
|
{
|
2002-11-21 00:02:38 +00:00
|
|
|
/* C/C++ forwards should only be written for object interfaces, so if we
|
|
|
|
* have a full definition we only write one if we find [object] among the
|
|
|
|
* attributes - however, if we don't have a full definition at this point
|
|
|
|
* (i.e. this is an IDL forward), then we also assume that it is an object
|
|
|
|
* interface, since non-object interfaces shouldn't need forwards */
|
2004-10-18 19:35:08 +00:00
|
|
|
if ((!iface->defined || is_object(iface->attrs) || is_attr(iface->attrs, ATTR_DISPINTERFACE))
|
|
|
|
&& !iface->written) {
|
2005-12-02 12:28:05 +00: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);
|
2003-07-01 03:43:09 +00:00
|
|
|
fprintf(header, "#endif\n\n" );
|
2002-07-16 03:20:45 +00:00
|
|
|
iface->written = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_iface_guid(FILE *header, const type_t *iface)
|
2004-10-11 19:54:37 +00:00
|
|
|
{
|
2006-02-07 11:31:17 +00:00
|
|
|
const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
|
2006-08-04 00:48:45 +00:00
|
|
|
write_guid(header, "IID", iface->name, uuid);
|
2004-10-11 19:54:37 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_dispiface_guid(FILE *header, const type_t *iface)
|
2004-10-11 19:54:37 +00:00
|
|
|
{
|
2006-02-07 11:31:17 +00:00
|
|
|
const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
|
2006-08-04 00:48:45 +00:00
|
|
|
write_guid(header, "DIID", iface->name, uuid);
|
2004-10-11 19:54:37 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_coclass_guid(FILE *header, const type_t *cocl)
|
2004-10-11 19:54:37 +00:00
|
|
|
{
|
2006-02-07 11:31:17 +00:00
|
|
|
const UUID *uuid = get_attrp(cocl->attrs, ATTR_UUID);
|
2006-08-04 00:48:45 +00:00
|
|
|
write_guid(header, "CLSID", cocl->name, uuid);
|
2004-10-11 19:54:37 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_com_interface_start(FILE *header, const type_t *iface)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2008-05-01 11:35:31 +00:00
|
|
|
int dispinterface = is_attr(iface->attrs, ATTR_DISPINTERFACE);
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(header, "/*****************************************************************************\n");
|
2008-05-01 11:35:31 +00:00
|
|
|
fprintf(header, " * %s %sinterface\n", iface->name, dispinterface ? "disp" : "");
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(header, " */\n");
|
2008-05-01 11:35:31 +00: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 00:19:24 +00:00
|
|
|
/* C++ interface */
|
|
|
|
fprintf(header, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
|
|
|
|
if (iface->ref)
|
2004-08-22 22:31:52 +00:00
|
|
|
{
|
2008-05-01 11:35:31 +00:00
|
|
|
fprintf(header, "interface %s : public %s\n", iface->name, iface->ref->name);
|
|
|
|
fprintf(header, "{\n");
|
2004-08-22 22:31:52 +00:00
|
|
|
}
|
2003-04-12 00:09:14 +00:00
|
|
|
else
|
|
|
|
{
|
2008-05-01 11:35:31 +00:00
|
|
|
fprintf(header, "interface %s\n", iface->name);
|
|
|
|
fprintf(header, "{\n");
|
|
|
|
fprintf(header, " BEGIN_INTERFACE\n");
|
|
|
|
fprintf(header, "\n");
|
2003-04-12 00:09:14 +00:00
|
|
|
}
|
2008-05-01 11:35:31 +00: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--;
|
|
|
|
}
|
|
|
|
if (!iface->ref)
|
|
|
|
fprintf(header, " END_INTERFACE\n");
|
|
|
|
fprintf(header, "};\n");
|
2003-04-10 00:19:24 +00:00
|
|
|
fprintf(header, "#else\n");
|
|
|
|
/* C interface */
|
2005-12-02 12:29:52 +00:00
|
|
|
fprintf(header, "typedef struct %sVtbl {\n", iface->name);
|
2003-04-10 00:19:24 +00:00
|
|
|
indentation++;
|
2004-08-22 02:25:05 +00:00
|
|
|
fprintf(header, " BEGIN_INTERFACE\n");
|
2003-04-10 00:19:24 +00:00
|
|
|
fprintf(header, "\n");
|
2008-05-01 11:35:31 +00:00
|
|
|
if (dispinterface)
|
|
|
|
write_c_disp_method_def(header, iface);
|
|
|
|
else
|
|
|
|
write_c_method_def(header, iface);
|
2003-04-10 00:19:24 +00:00
|
|
|
indentation--;
|
2004-08-22 02:25:05 +00:00
|
|
|
fprintf(header, " END_INTERFACE\n");
|
2005-12-02 12:29:52 +00:00
|
|
|
fprintf(header, "} %sVtbl;\n", iface->name);
|
|
|
|
fprintf(header, "interface %s {\n", iface->name);
|
2006-09-29 10:45:18 +00:00
|
|
|
fprintf(header, " CONST_VTBL %sVtbl* lpVtbl;\n", iface->name);
|
2003-04-10 00:19:24 +00:00
|
|
|
fprintf(header, "};\n");
|
|
|
|
fprintf(header, "\n");
|
2004-08-11 19:43:45 +00:00
|
|
|
fprintf(header, "#ifdef COBJMACROS\n");
|
2008-05-01 11:35:31 +00: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 */
|
|
|
|
write_method_macro(header, dispinterface ? iface->ref : iface, iface->name);
|
2004-08-11 19:43:45 +00:00
|
|
|
fprintf(header, "#endif\n");
|
2003-04-10 00:19:24 +00:00
|
|
|
fprintf(header, "\n");
|
|
|
|
fprintf(header, "#endif\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(header, "\n");
|
2008-05-01 11:35:31 +00: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 03:20:45 +00:00
|
|
|
}
|
2002-12-03 19:12:07 +00:00
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_rpc_interface_start(FILE *header, const type_t *iface)
|
2002-12-03 19:12:07 +00:00
|
|
|
{
|
2007-12-12 14:49:34 +00:00
|
|
|
unsigned int ver = get_attrv(iface->attrs, ATTR_VERSION);
|
2006-02-07 11:31:43 +00:00
|
|
|
const char *var = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
|
2006-03-31 11:45:29 +00:00
|
|
|
static int allocate_written = 0;
|
|
|
|
|
|
|
|
if (!allocate_written)
|
|
|
|
{
|
|
|
|
allocate_written = 1;
|
|
|
|
fprintf(header, "void * __RPC_USER MIDL_user_allocate(size_t);\n");
|
|
|
|
fprintf(header, "void __RPC_USER MIDL_user_free(void *);\n\n");
|
|
|
|
}
|
2002-12-03 19:12:07 +00:00
|
|
|
|
|
|
|
fprintf(header, "/*****************************************************************************\n");
|
2007-12-12 14:49:34 +00:00
|
|
|
fprintf(header, " * %s interface (v%d.%d)\n", iface->name, MAJORVERSION(ver), MINORVERSION(ver));
|
2002-12-03 19:12:07 +00:00
|
|
|
fprintf(header, " */\n");
|
2006-03-31 11:44:53 +00:00
|
|
|
fprintf(header,"#ifndef __%s_INTERFACE_DEFINED__\n", iface->name);
|
|
|
|
fprintf(header,"#define __%s_INTERFACE_DEFINED__\n\n", iface->name);
|
2008-05-01 11:35:31 +00:00
|
|
|
if (var) fprintf(header, "extern handle_t %s;\n", var);
|
|
|
|
if (old_names)
|
2006-03-31 11:50:34 +00:00
|
|
|
{
|
2008-05-01 11:35:31 +00: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 11:50:34 +00:00
|
|
|
}
|
2002-12-03 19:12:07 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
static void write_rpc_interface_end(FILE *header, const type_t *iface)
|
2002-12-03 19:12:07 +00:00
|
|
|
{
|
2008-05-01 11:35:31 +00:00
|
|
|
fprintf(header,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface->name);
|
2002-12-03 19:12:07 +00:00
|
|
|
}
|
2004-10-11 19:54:37 +00:00
|
|
|
|
2008-05-01 11:35:31 +00:00
|
|
|
void write_interface(type_t *iface)
|
2004-10-11 19:54:37 +00:00
|
|
|
{
|
2008-05-01 11:35:31 +00:00
|
|
|
if (is_attr(iface->attrs, ATTR_DISPINTERFACE) || is_object(iface->attrs))
|
|
|
|
{
|
|
|
|
write_com_interface_start(header, iface);
|
|
|
|
write_com_interface_end(header, iface);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
write_rpc_interface_start(header, iface);
|
|
|
|
write_function_protos(header, iface);
|
|
|
|
write_rpc_interface_end(header, iface);
|
|
|
|
}
|
2004-10-11 19:54:37 +00:00
|
|
|
}
|
|
|
|
|
2006-07-28 20:43:00 +00:00
|
|
|
void write_coclass(type_t *cocl)
|
2004-10-11 19:54:37 +00:00
|
|
|
{
|
|
|
|
fprintf(header, "/*****************************************************************************\n");
|
|
|
|
fprintf(header, " * %s coclass\n", cocl->name);
|
|
|
|
fprintf(header, " */\n\n");
|
2008-05-01 11:35:31 +00:00
|
|
|
write_coclass_guid(header, cocl);
|
2004-10-11 19:54:37 +00:00
|
|
|
fprintf(header, "\n");
|
|
|
|
}
|
2006-06-06 19:05:39 +00:00
|
|
|
|
2006-07-28 20:43:00 +00:00
|
|
|
void write_coclass_forward(type_t *cocl)
|
2006-06-06 19:05:39 +00: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 01:10:12 +00:00
|
|
|
fprintf(header, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl->name );
|
2006-06-06 19:05:39 +00:00
|
|
|
}
|
2008-04-25 09:59:40 +00:00
|
|
|
|
|
|
|
void write_import(const char *fname)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|