4 * Copyright 2002 Ove Kaaven
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
39 static int indentation
= 0;
40 static int is_object_interface
= 0;
41 user_type_list_t user_type_list
= LIST_INIT(user_type_list
);
42 context_handle_list_t context_handle_list
= LIST_INIT(context_handle_list
);
43 generic_handle_list_t generic_handle_list
= LIST_INIT(generic_handle_list
);
45 static void write_type_def_or_decl(FILE *f
, type_t
*t
, int field
, const char *name
);
47 static void indent(FILE *h
, int delta
)
50 if (delta
< 0) indentation
+= delta
;
51 for (c
=0; c
<indentation
; c
++) fprintf(h
, " ");
52 if (delta
> 0) indentation
+= delta
;
55 int is_ptrchain_attr(const var_t
*var
, enum attr_type t
)
57 if (is_attr(var
->attrs
, t
))
61 type_t
*type
= var
->type
;
64 if (is_attr(type
->attrs
, t
))
66 else if (type_is_alias(type
))
67 type
= type_alias_get_aliasee(type
);
68 else if (is_ptr(type
))
69 type
= type_pointer_get_ref(type
);
75 int is_aliaschain_attr(const type_t
*type
, enum attr_type attr
)
77 const type_t
*t
= type
;
80 if (is_attr(t
->attrs
, attr
))
82 else if (type_is_alias(t
))
83 t
= type_alias_get_aliasee(t
);
88 int is_attr(const attr_list_t
*list
, enum attr_type t
)
91 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
92 if (attr
->type
== t
) return 1;
96 void *get_attrp(const attr_list_t
*list
, enum attr_type t
)
99 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
100 if (attr
->type
== t
) return attr
->u
.pval
;
104 unsigned int get_attrv(const attr_list_t
*list
, enum attr_type t
)
107 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
108 if (attr
->type
== t
) return attr
->u
.ival
;
112 static void write_guid(FILE *f
, const char *guid_prefix
, const char *name
, const UUID
*uuid
)
115 fprintf(f
, "DEFINE_GUID(%s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
116 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
117 guid_prefix
, name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0],
118 uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5],
119 uuid
->Data4
[6], uuid
->Data4
[7]);
122 static void write_uuid_decl(FILE *f
, const char *name
, const UUID
*uuid
)
124 fprintf(f
, "#ifdef __CRT_UUID_DECL\n");
125 fprintf(f
, "__CRT_UUID_DECL(%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
126 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x)\n",
127 name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0], uuid
->Data4
[1],
128 uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5], uuid
->Data4
[6],
130 fprintf(f
, "#endif\n");
133 static const char *uuid_string(const UUID
*uuid
)
137 sprintf(buf
, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
138 uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0], uuid
->Data4
[1], uuid
->Data4
[2],
139 uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5], uuid
->Data4
[6], uuid
->Data4
[7]);
144 const char *get_name(const var_t
*v
)
146 static char buffer
[256];
148 if (is_attr( v
->attrs
, ATTR_PROPGET
))
149 strcpy( buffer
, "get_" );
150 else if (is_attr( v
->attrs
, ATTR_PROPPUT
))
151 strcpy( buffer
, "put_" );
152 else if (is_attr( v
->attrs
, ATTR_PROPPUTREF
))
153 strcpy( buffer
, "putref_" );
156 strcat( buffer
, v
->name
);
160 static void write_fields(FILE *h
, var_list_t
*fields
)
162 unsigned nameless_struct_cnt
= 0, nameless_struct_i
= 0, nameless_union_cnt
= 0, nameless_union_i
= 0;
169 LIST_FOR_EACH_ENTRY( v
, fields
, var_t
, entry
) {
170 if (!v
|| !v
->type
) continue;
172 switch(type_get_type_detect_alias(v
->type
)) {
174 case TYPE_ENCAPSULATED_UNION
:
175 nameless_struct_cnt
++;
178 nameless_union_cnt
++;
185 LIST_FOR_EACH_ENTRY( v
, fields
, var_t
, entry
) {
186 if (!v
|| !v
->type
) continue;
191 switch(type_get_type_detect_alias(v
->type
)) {
193 case TYPE_ENCAPSULATED_UNION
:
195 fprintf(h
, "__C89_NAMELESS ");
196 if(nameless_struct_cnt
== 1) {
197 name
= "__C89_NAMELESSSTRUCTNAME";
198 }else if(nameless_struct_i
< 5 /* # of supporting macros */) {
199 sprintf(buf
, "__C89_NAMELESSSTRUCTNAME%d", ++nameless_struct_i
);
206 fprintf(h
, "__C89_NAMELESS ");
207 if(nameless_union_cnt
== 1) {
208 name
= "__C89_NAMELESSUNIONNAME";
209 }else if(nameless_union_i
< 8 /* # of supporting macros */ ) {
210 sprintf(buf
, "__C89_NAMELESSUNIONNAME%d", ++nameless_union_i
);
218 write_type_def_or_decl(h
, v
->type
, TRUE
, name
);
223 static void write_enums(FILE *h
, var_list_t
*enums
)
227 LIST_FOR_EACH_ENTRY( v
, enums
, var_t
, entry
)
231 fprintf(h
, "%s", get_name(v
));
234 write_expr(h
, v
->eval
, 0, 1, NULL
, NULL
, "");
237 if (list_next( enums
, &v
->entry
)) fprintf(h
, ",\n");
242 int needs_space_after(type_t
*t
)
244 return (type_is_alias(t
) ||
245 (!is_ptr(t
) && (!is_array(t
) || !type_array_is_decl_as_ptr(t
) || t
->name
)));
248 void write_type_left(FILE *h
, type_t
*t
, int declonly
)
252 if (is_attr(t
->attrs
, ATTR_CONST
) &&
253 (type_is_alias(t
) || !is_ptr(t
)))
254 fprintf(h
, "const ");
256 if (type_is_alias(t
)) fprintf(h
, "%s", t
->name
);
258 switch (type_get_type_detect_alias(t
)) {
260 if (!declonly
&& t
->defined
&& !t
->written
) {
261 if (t
->name
) fprintf(h
, "enum %s {\n", t
->name
);
262 else fprintf(h
, "enum {\n");
265 write_enums(h
, type_enum_get_values(t
));
269 else fprintf(h
, "enum %s", t
->name
? t
->name
: "");
272 case TYPE_ENCAPSULATED_UNION
:
273 if (!declonly
&& t
->defined
&& !t
->written
) {
274 if (t
->name
) fprintf(h
, "struct %s {\n", t
->name
);
275 else fprintf(h
, "struct {\n");
278 if (type_get_type(t
) != TYPE_STRUCT
)
279 write_fields(h
, type_encapsulated_union_get_fields(t
));
281 write_fields(h
, type_struct_get_fields(t
));
285 else fprintf(h
, "struct %s", t
->name
? t
->name
: "");
288 if (!declonly
&& t
->defined
&& !t
->written
) {
289 if (t
->name
) fprintf(h
, "union %s {\n", t
->name
);
290 else fprintf(h
, "union {\n");
293 write_fields(h
, type_union_get_cases(t
));
297 else fprintf(h
, "union %s", t
->name
? t
->name
: "");
300 write_type_left(h
, type_pointer_get_ref(t
), declonly
);
301 fprintf(h
, "%s*", needs_space_after(type_pointer_get_ref(t
)) ? " " : "");
302 if (is_attr(t
->attrs
, ATTR_CONST
)) fprintf(h
, "const ");
305 if (t
->name
&& type_array_is_decl_as_ptr(t
))
306 fprintf(h
, "%s", t
->name
);
309 write_type_left(h
, type_array_get_element(t
), declonly
);
310 if (type_array_is_decl_as_ptr(t
))
311 fprintf(h
, "%s*", needs_space_after(type_array_get_element(t
)) ? " " : "");
315 if (type_basic_get_type(t
) != TYPE_BASIC_INT32
&&
316 type_basic_get_type(t
) != TYPE_BASIC_INT64
&&
317 type_basic_get_type(t
) != TYPE_BASIC_HYPER
)
319 if (type_basic_get_sign(t
) < 0) fprintf(h
, "signed ");
320 else if (type_basic_get_sign(t
) > 0) fprintf(h
, "unsigned ");
322 switch (type_basic_get_type(t
))
324 case TYPE_BASIC_INT8
: fprintf(h
, "small"); break;
325 case TYPE_BASIC_INT16
: fprintf(h
, "short"); break;
326 case TYPE_BASIC_INT
: fprintf(h
, "int"); break;
327 case TYPE_BASIC_INT3264
: fprintf(h
, "__int3264"); break;
328 case TYPE_BASIC_BYTE
: fprintf(h
, "byte"); break;
329 case TYPE_BASIC_CHAR
: fprintf(h
, "char"); break;
330 case TYPE_BASIC_WCHAR
: fprintf(h
, "wchar_t"); break;
331 case TYPE_BASIC_FLOAT
: fprintf(h
, "float"); break;
332 case TYPE_BASIC_DOUBLE
: fprintf(h
, "double"); break;
333 case TYPE_BASIC_ERROR_STATUS_T
: fprintf(h
, "error_status_t"); break;
334 case TYPE_BASIC_HANDLE
: fprintf(h
, "handle_t"); break;
335 case TYPE_BASIC_INT32
:
336 if (type_basic_get_sign(t
) > 0)
341 case TYPE_BASIC_INT64
:
342 if (type_basic_get_sign(t
) > 0)
343 fprintf(h
, "UINT64");
347 case TYPE_BASIC_HYPER
:
348 if (type_basic_get_sign(t
) > 0)
349 fprintf(h
, "MIDL_uhyper");
358 fprintf(h
, "%s", t
->name
);
364 write_type_left(h
, type_bitfield_get_field(t
), declonly
);
368 /* handled elsewhere */
375 void write_type_right(FILE *h
, type_t
*t
, int is_field
)
379 switch (type_get_type(t
))
382 if (!type_array_is_decl_as_ptr(t
))
384 if (is_conformant_array(t
))
386 fprintf(h
, "[%s]", is_field
? "1" : "");
387 t
= type_array_get_element(t
);
390 type_get_type(t
) == TYPE_ARRAY
&& !type_array_is_decl_as_ptr(t
);
391 t
= type_array_get_element(t
))
392 fprintf(h
, "[%u]", type_array_get_dim(t
));
396 fprintf(h
, " : %u", type_bitfield_get_bits(t
)->cval
);
402 case TYPE_ENCAPSULATED_UNION
:
414 static void write_type_v(FILE *h
, type_t
*t
, int is_field
, int declonly
, const char *name
)
422 for (pt
= t
; is_ptr(pt
); pt
= type_pointer_get_ref(pt
), ptr_level
++)
425 if (type_get_type_detect_alias(pt
) == TYPE_FUNCTION
) {
427 const char *callconv
= get_attrp(pt
->attrs
, ATTR_CALLCONV
);
428 if (!callconv
&& is_object_interface
) callconv
= "STDMETHODCALLTYPE";
429 if (is_attr(pt
->attrs
, ATTR_INLINE
)) fprintf(h
, "inline ");
430 write_type_left(h
, type_function_get_rettype(pt
), declonly
);
432 if (ptr_level
) fputc('(', h
);
433 if (callconv
) fprintf(h
, "%s ", callconv
);
434 for (i
= 0; i
< ptr_level
; i
++)
437 write_type_left(h
, t
, declonly
);
440 if (name
) fprintf(h
, "%s%s", !t
|| needs_space_after(t
) ? " " : "", name
);
443 if (type_get_type_detect_alias(pt
) == TYPE_FUNCTION
) {
444 const var_list_t
*args
= type_function_get_args(pt
);
446 if (ptr_level
) fputc(')', h
);
449 write_args(h
, args
, NULL
, 0, FALSE
);
454 write_type_right(h
, t
, is_field
);
458 static void write_type_def_or_decl(FILE *f
, type_t
*t
, int field
, const char *name
)
460 write_type_v(f
, t
, field
, FALSE
, name
);
463 void write_type_decl(FILE *f
, type_t
*t
, const char *name
)
465 write_type_v(f
, t
, FALSE
, TRUE
, name
);
468 void write_type_decl_left(FILE *f
, type_t
*t
)
470 write_type_left(f
, t
, TRUE
);
473 static int user_type_registered(const char *name
)
476 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
477 if (!strcmp(name
, ut
->name
))
482 static int context_handle_registered(const char *name
)
484 context_handle_t
*ch
;
485 LIST_FOR_EACH_ENTRY(ch
, &context_handle_list
, context_handle_t
, entry
)
486 if (!strcmp(name
, ch
->name
))
491 static int generic_handle_registered(const char *name
)
493 generic_handle_t
*gh
;
494 LIST_FOR_EACH_ENTRY(gh
, &generic_handle_list
, generic_handle_t
, entry
)
495 if (!strcmp(name
, gh
->name
))
500 unsigned int get_context_handle_offset( const type_t
*type
)
502 context_handle_t
*ch
;
503 unsigned int index
= 0;
505 while (!is_attr( type
->attrs
, ATTR_CONTEXTHANDLE
))
507 if (type_is_alias( type
)) type
= type_alias_get_aliasee( type
);
508 else if (is_ptr( type
)) type
= type_pointer_get_ref( type
);
509 else error( "internal error: %s is not a context handle\n", type
->name
);
511 LIST_FOR_EACH_ENTRY( ch
, &context_handle_list
, context_handle_t
, entry
)
513 if (!strcmp( type
->name
, ch
->name
)) return index
;
516 error( "internal error: %s is not registered as a context handle\n", type
->name
);
520 unsigned int get_generic_handle_offset( const type_t
*type
)
522 generic_handle_t
*gh
;
523 unsigned int index
= 0;
525 while (!is_attr( type
->attrs
, ATTR_HANDLE
))
527 if (type_is_alias( type
)) type
= type_alias_get_aliasee( type
);
528 else if (is_ptr( type
)) type
= type_pointer_get_ref( type
);
529 else error( "internal error: %s is not a generic handle\n", type
->name
);
531 LIST_FOR_EACH_ENTRY( gh
, &generic_handle_list
, generic_handle_t
, entry
)
533 if (!strcmp( type
->name
, gh
->name
)) return index
;
536 error( "internal error: %s is not registered as a generic handle\n", type
->name
);
540 /* check for types which require additional prototypes to be generated in the
542 void check_for_additional_prototype_types(const var_list_t
*list
)
547 LIST_FOR_EACH_ENTRY( v
, list
, const var_t
, entry
)
549 type_t
*type
= v
->type
;
552 const char *name
= type
->name
;
553 if (type
->user_types_registered
) break;
554 type
->user_types_registered
= 1;
555 if (is_attr(type
->attrs
, ATTR_CONTEXTHANDLE
)) {
556 if (!context_handle_registered(name
))
558 context_handle_t
*ch
= xmalloc(sizeof(*ch
));
559 ch
->name
= xstrdup(name
);
560 list_add_tail(&context_handle_list
, &ch
->entry
);
562 /* don't carry on parsing fields within this type */
565 if ((type_get_type(type
) != TYPE_BASIC
||
566 type_basic_get_type(type
) != TYPE_BASIC_HANDLE
) &&
567 is_attr(type
->attrs
, ATTR_HANDLE
)) {
568 if (!generic_handle_registered(name
))
570 generic_handle_t
*gh
= xmalloc(sizeof(*gh
));
571 gh
->name
= xstrdup(name
);
572 list_add_tail(&generic_handle_list
, &gh
->entry
);
574 /* don't carry on parsing fields within this type */
577 if (is_attr(type
->attrs
, ATTR_WIREMARSHAL
)) {
578 if (!user_type_registered(name
))
580 user_type_t
*ut
= xmalloc(sizeof *ut
);
581 ut
->name
= xstrdup(name
);
582 list_add_tail(&user_type_list
, &ut
->entry
);
584 /* don't carry on parsing fields within this type as we are already
585 * using a wire marshaled type */
588 else if (type_is_complete(type
))
591 switch (type_get_type_detect_alias(type
))
594 vars
= type_enum_get_values(type
);
597 vars
= type_struct_get_fields(type
);
600 vars
= type_union_get_cases(type
);
606 check_for_additional_prototype_types(vars
);
609 if (type_is_alias(type
))
610 type
= type_alias_get_aliasee(type
);
611 else if (is_ptr(type
))
612 type
= type_pointer_get_ref(type
);
613 else if (is_array(type
))
614 type
= type_array_get_element(type
);
621 static void write_user_types(FILE *header
)
624 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
626 const char *name
= ut
->name
;
627 fprintf(header
, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name
, name
);
628 fprintf(header
, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name
, name
);
629 fprintf(header
, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name
, name
);
630 fprintf(header
, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name
, name
);
634 static void write_context_handle_rundowns(FILE *header
)
636 context_handle_t
*ch
;
637 LIST_FOR_EACH_ENTRY(ch
, &context_handle_list
, context_handle_t
, entry
)
639 const char *name
= ch
->name
;
640 fprintf(header
, "void __RPC_USER %s_rundown(%s);\n", name
, name
);
644 static void write_generic_handle_routines(FILE *header
)
646 generic_handle_t
*gh
;
647 LIST_FOR_EACH_ENTRY(gh
, &generic_handle_list
, generic_handle_t
, entry
)
649 const char *name
= gh
->name
;
650 fprintf(header
, "handle_t __RPC_USER %s_bind(%s);\n", name
, name
);
651 fprintf(header
, "void __RPC_USER %s_unbind(%s, handle_t);\n", name
, name
);
655 static void write_typedef(FILE *header
, type_t
*type
)
657 fprintf(header
, "typedef ");
658 write_type_def_or_decl(header
, type_alias_get_aliasee(type
), FALSE
, type
->name
);
659 fprintf(header
, ";\n");
662 int is_const_decl(const var_t
*var
)
665 /* strangely, MIDL accepts a const attribute on any pointer in the
666 * declaration to mean that data isn't being instantiated. this appears
667 * to be a bug, but there is no benefit to being incompatible with MIDL,
668 * so we'll do the same thing */
669 for (t
= var
->type
; ; )
671 if (is_attr(t
->attrs
, ATTR_CONST
))
674 t
= type_pointer_get_ref(t
);
680 static void write_declaration(FILE *header
, const var_t
*v
)
682 if (is_const_decl(v
) && v
->eval
)
684 fprintf(header
, "#define %s (", v
->name
);
685 write_expr(header
, v
->eval
, 0, 1, NULL
, NULL
, "");
686 fprintf(header
, ")\n\n");
693 case STG_REGISTER
: /* ignored */
696 fprintf(header
, "static ");
699 fprintf(header
, "extern ");
702 write_type_def_or_decl(header
, v
->type
, FALSE
, v
->name
);
703 fprintf(header
, ";\n\n");
707 static void write_library(FILE *header
, const typelib_t
*typelib
)
709 const UUID
*uuid
= get_attrp(typelib
->attrs
, ATTR_UUID
);
710 fprintf(header
, "\n");
711 write_guid(header
, "LIBID", typelib
->name
, uuid
);
712 fprintf(header
, "\n");
716 const type_t
* get_explicit_generic_handle_type(const var_t
* var
)
720 is_ptr(t
) || type_is_alias(t
);
721 t
= type_is_alias(t
) ? type_alias_get_aliasee(t
) : type_pointer_get_ref(t
))
722 if ((type_get_type_detect_alias(t
) != TYPE_BASIC
|| type_basic_get_type(t
) != TYPE_BASIC_HANDLE
) &&
723 is_attr(t
->attrs
, ATTR_HANDLE
))
728 const var_t
*get_func_handle_var( const type_t
*iface
, const var_t
*func
,
729 unsigned char *explicit_fc
, unsigned char *implicit_fc
)
732 const var_list_t
*args
= type_get_function_args( func
->type
);
734 *explicit_fc
= *implicit_fc
= 0;
735 if (args
) LIST_FOR_EACH_ENTRY( var
, args
, const var_t
, entry
)
737 if (!is_attr( var
->attrs
, ATTR_IN
) && is_attr( var
->attrs
, ATTR_OUT
)) continue;
738 if (type_get_type( var
->type
) == TYPE_BASIC
&& type_basic_get_type( var
->type
) == TYPE_BASIC_HANDLE
)
740 *explicit_fc
= RPC_FC_BIND_PRIMITIVE
;
743 if (get_explicit_generic_handle_type( var
))
745 *explicit_fc
= RPC_FC_BIND_GENERIC
;
748 if (is_context_handle( var
->type
))
750 *explicit_fc
= RPC_FC_BIND_CONTEXT
;
755 if ((var
= get_attrp( iface
->attrs
, ATTR_IMPLICIT_HANDLE
)))
757 if (type_get_type( var
->type
) == TYPE_BASIC
&&
758 type_basic_get_type( var
->type
) == TYPE_BASIC_HANDLE
)
759 *implicit_fc
= RPC_FC_BIND_PRIMITIVE
;
761 *implicit_fc
= RPC_FC_BIND_GENERIC
;
765 *implicit_fc
= RPC_FC_AUTO_HANDLE
;
769 int has_out_arg_or_return(const var_t
*func
)
773 if (!is_void(type_function_get_rettype(func
->type
)))
776 if (!type_get_function_args(func
->type
))
779 LIST_FOR_EACH_ENTRY( var
, type_get_function_args(func
->type
), const var_t
, entry
)
780 if (is_attr(var
->attrs
, ATTR_OUT
))
787 /********** INTERFACES **********/
789 int is_object(const type_t
*iface
)
792 if (type_is_defined(iface
) && type_iface_get_inherit(iface
))
794 if (iface
->attrs
) LIST_FOR_EACH_ENTRY( attr
, iface
->attrs
, const attr_t
, entry
)
795 if (attr
->type
== ATTR_OBJECT
|| attr
->type
== ATTR_ODL
) return 1;
799 int is_local(const attr_list_t
*a
)
801 return is_attr(a
, ATTR_LOCAL
);
804 const var_t
*is_callas(const attr_list_t
*a
)
806 return get_attrp(a
, ATTR_CALLAS
);
809 static int is_inherited_method(const type_t
*iface
, const var_t
*func
)
811 while ((iface
= type_iface_get_inherit(iface
)))
813 const statement_t
*stmt
;
814 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
))
816 const var_t
*funccmp
= stmt
->u
.var
;
818 if (!is_callas(func
->attrs
))
820 char inherit_name
[256];
821 /* compare full name including property prefix */
822 strcpy(inherit_name
, get_name(funccmp
));
823 if (!strcmp(inherit_name
, get_name(func
))) return 1;
831 static void write_method_macro(FILE *header
, const type_t
*iface
, const char *name
)
833 const statement_t
*stmt
;
836 if (type_iface_get_inherit(iface
))
837 write_method_macro(header
, type_iface_get_inherit(iface
), name
);
839 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
))
841 const var_t
*func
= stmt
->u
.var
;
845 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
849 if (!is_callas(func
->attrs
) && !is_inherited_method(iface
, func
)) {
852 fprintf(header
, "#define %s_%s(This", name
, get_name(func
));
853 if (type_get_function_args(func
->type
))
854 LIST_FOR_EACH_ENTRY( arg
, type_get_function_args(func
->type
), const var_t
, entry
)
855 fprintf(header
, ",%s", arg
->name
);
856 fprintf(header
, ") ");
858 fprintf(header
, "(This)->lpVtbl->%s(This", get_name(func
));
859 if (type_get_function_args(func
->type
))
860 LIST_FOR_EACH_ENTRY( arg
, type_get_function_args(func
->type
), const var_t
, entry
)
861 fprintf(header
, ",%s", arg
->name
);
862 fprintf(header
, ")\n");
867 void write_args(FILE *h
, const var_list_t
*args
, const char *name
, int method
, int do_indent
)
878 fprintf(h
, "%s* This", name
);
881 if (args
) LIST_FOR_EACH_ENTRY( arg
, args
, const var_t
, entry
) {
888 else fprintf(h
, ",");
890 write_type_decl(h
, arg
->type
, arg
->name
);
892 const expr_t
*expr
= get_attrp(arg
->attrs
, ATTR_DEFAULTVALUE
);
895 write_expr( h
, expr
, 0, 1, NULL
, NULL
, "" );
900 if (do_indent
) indentation
--;
903 static void write_cpp_method_def(FILE *header
, const type_t
*iface
)
905 const statement_t
*stmt
;
907 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
))
909 const var_t
*func
= stmt
->u
.var
;
910 if (!is_callas(func
->attrs
)) {
911 const char *callconv
= get_attrp(func
->type
->attrs
, ATTR_CALLCONV
);
912 if (!callconv
) callconv
= "STDMETHODCALLTYPE";
914 fprintf(header
, "virtual ");
915 write_type_decl_left(header
, type_function_get_rettype(func
->type
));
916 fprintf(header
, " %s %s(\n", callconv
, get_name(func
));
917 write_args(header
, type_get_function_args(func
->type
), iface
->name
, 2, TRUE
);
918 fprintf(header
, ") = 0;\n");
919 fprintf(header
, "\n");
924 static void write_inline_wrappers(FILE *header
, const type_t
*iface
, const char *name
)
926 const statement_t
*stmt
;
929 if (type_iface_get_inherit(iface
))
930 write_inline_wrappers(header
, type_iface_get_inherit(iface
), name
);
932 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
))
934 const var_t
*func
= stmt
->u
.var
;
938 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
942 if (!is_callas(func
->attrs
) && !is_inherited_method(iface
, func
)) {
945 fprintf(header
, "static FORCEINLINE ");
946 write_type_decl_left(header
, type_function_get_rettype(func
->type
));
947 fprintf(header
, " %s_%s(", name
, get_name(func
));
948 write_args(header
, type_get_function_args(func
->type
), name
, 1, FALSE
);
949 fprintf(header
, ") {\n");
950 fprintf(header
, " %s", is_void(type_function_get_rettype(func
->type
)) ? "" : "return ");
951 fprintf(header
, "This->lpVtbl->%s(This", get_name(func
));
952 if (type_get_function_args(func
->type
))
953 LIST_FOR_EACH_ENTRY( arg
, type_get_function_args(func
->type
), const var_t
, entry
)
954 fprintf(header
, ",%s", arg
->name
);
955 fprintf(header
, ");\n");
956 fprintf(header
, "}\n");
961 static void do_write_c_method_def(FILE *header
, const type_t
*iface
, const char *name
)
963 const statement_t
*stmt
;
966 if (type_iface_get_inherit(iface
))
967 do_write_c_method_def(header
, type_iface_get_inherit(iface
), name
);
969 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
))
971 const var_t
*func
= stmt
->u
.var
;
974 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
977 if (!is_callas(func
->attrs
)) {
978 const char *callconv
= get_attrp(func
->type
->attrs
, ATTR_CALLCONV
);
979 if (!callconv
) callconv
= "STDMETHODCALLTYPE";
981 write_type_decl_left(header
, type_function_get_rettype(func
->type
));
982 if (is_inherited_method(iface
, func
))
983 fprintf(header
, " (%s *%s_%s)(\n", callconv
, iface
->name
, func
->name
);
985 fprintf(header
, " (%s *%s)(\n", callconv
, get_name(func
));
986 write_args(header
, type_get_function_args(func
->type
), name
, 1, TRUE
);
987 fprintf(header
, ");\n");
988 fprintf(header
, "\n");
993 static void write_c_method_def(FILE *header
, const type_t
*iface
)
995 do_write_c_method_def(header
, iface
, iface
->name
);
998 static void write_c_disp_method_def(FILE *header
, const type_t
*iface
)
1000 do_write_c_method_def(header
, type_iface_get_inherit(iface
), iface
->name
);
1003 static void write_method_proto(FILE *header
, const type_t
*iface
)
1005 const statement_t
*stmt
;
1007 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
))
1009 const var_t
*func
= stmt
->u
.var
;
1011 if (!is_local(func
->attrs
)) {
1012 const char *callconv
= get_attrp(func
->type
->attrs
, ATTR_CALLCONV
);
1013 if (!callconv
) callconv
= "STDMETHODCALLTYPE";
1014 /* proxy prototype */
1015 write_type_decl_left(header
, type_function_get_rettype(func
->type
));
1016 fprintf(header
, " %s %s_%s_Proxy(\n", callconv
, iface
->name
, get_name(func
));
1017 write_args(header
, type_get_function_args(func
->type
), iface
->name
, 1, TRUE
);
1018 fprintf(header
, ");\n");
1019 /* stub prototype */
1020 fprintf(header
, "void __RPC_STUB %s_%s_Stub(\n", iface
->name
, get_name(func
));
1021 fprintf(header
, " IRpcStubBuffer* This,\n");
1022 fprintf(header
, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
1023 fprintf(header
, " PRPC_MESSAGE pRpcMessage,\n");
1024 fprintf(header
, " DWORD* pdwStubPhase);\n");
1029 static void write_locals(FILE *fp
, const type_t
*iface
, int body
)
1031 static const char comment
[]
1032 = "/* WIDL-generated stub. You must provide an implementation for this. */";
1033 const statement_t
*stmt
;
1035 if (!is_object(iface
))
1038 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
)) {
1039 const var_t
*func
= stmt
->u
.var
;
1040 const var_t
*cas
= is_callas(func
->attrs
);
1043 const statement_t
*stmt2
= NULL
;
1044 STATEMENTS_FOR_EACH_FUNC(stmt2
, type_iface_get_stmts(iface
))
1045 if (!strcmp(stmt2
->u
.var
->name
, cas
->name
))
1047 if (&stmt2
->entry
!= type_iface_get_stmts(iface
)) {
1048 const var_t
*m
= stmt2
->u
.var
;
1049 /* proxy prototype - use local prototype */
1050 write_type_decl_left(fp
, type_function_get_rettype(m
->type
));
1051 fprintf(fp
, " CALLBACK %s_%s_Proxy(\n", iface
->name
, get_name(m
));
1052 write_args(fp
, type_get_function_args(m
->type
), iface
->name
, 1, TRUE
);
1055 type_t
*rt
= type_function_get_rettype(m
->type
);
1056 fprintf(fp
, "\n{\n");
1057 fprintf(fp
, " %s\n", comment
);
1058 if (rt
->name
&& strcmp(rt
->name
, "HRESULT") == 0)
1059 fprintf(fp
, " return E_NOTIMPL;\n");
1060 else if (type_get_type(rt
) != TYPE_VOID
) {
1062 write_type_decl(fp
, rt
, "rv");
1064 fprintf(fp
, " memset(&rv, 0, sizeof rv);\n");
1065 fprintf(fp
, " return rv;\n");
1067 fprintf(fp
, "}\n\n");
1071 /* stub prototype - use remotable prototype */
1072 write_type_decl_left(fp
, type_function_get_rettype(func
->type
));
1073 fprintf(fp
, " __RPC_STUB %s_%s_Stub(\n", iface
->name
, get_name(m
));
1074 write_args(fp
, type_get_function_args(func
->type
), iface
->name
, 1, TRUE
);
1077 /* Remotable methods must all return HRESULTs. */
1078 fprintf(fp
, "\n{\n %s\n return E_NOTIMPL;\n}\n\n", comment
);
1083 error_loc("invalid call_as attribute (%s -> %s)\n", func
->name
, cas
->name
);
1088 static void write_local_stubs_stmts(FILE *local_stubs
, const statement_list_t
*stmts
)
1090 const statement_t
*stmt
;
1091 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
1093 if (stmt
->type
== STMT_TYPE
&& type_get_type(stmt
->u
.type
) == TYPE_INTERFACE
)
1094 write_locals(local_stubs
, stmt
->u
.type
, TRUE
);
1098 void write_local_stubs(const statement_list_t
*stmts
)
1102 if (!local_stubs_name
) return;
1104 local_stubs
= fopen(local_stubs_name
, "w");
1106 error("Could not open %s for output\n", local_stubs_name
);
1109 fprintf(local_stubs
, "/* call_as/local stubs for %s */\n\n", input_name
);
1110 fprintf(local_stubs
, "#include <objbase.h>\n");
1111 fprintf(local_stubs
, "#include \"%s\"\n\n", header_name
);
1113 write_local_stubs_stmts(local_stubs
, stmts
);
1115 fclose(local_stubs
);
1118 static void write_function_proto(FILE *header
, const type_t
*iface
, const var_t
*fun
, const char *prefix
)
1120 const char *callconv
= get_attrp(fun
->type
->attrs
, ATTR_CALLCONV
);
1122 if (!callconv
) callconv
= "__cdecl";
1123 /* FIXME: do we need to handle call_as? */
1124 write_type_decl_left(header
, type_function_get_rettype(fun
->type
));
1125 fprintf(header
, " %s ", callconv
);
1126 fprintf(header
, "%s%s(\n", prefix
, get_name(fun
));
1127 if (type_get_function_args(fun
->type
))
1128 write_args(header
, type_get_function_args(fun
->type
), iface
->name
, 0, TRUE
);
1130 fprintf(header
, " void");
1131 fprintf(header
, ");\n\n");
1134 static void write_forward(FILE *header
, type_t
*iface
)
1136 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", iface
->name
);
1137 fprintf(header
, "#define __%s_FWD_DEFINED__\n", iface
->name
);
1138 fprintf(header
, "typedef interface %s %s;\n", iface
->name
, iface
->name
);
1139 fprintf(header
, "#endif\n\n" );
1142 static void write_com_interface_start(FILE *header
, const type_t
*iface
)
1144 int dispinterface
= is_attr(iface
->attrs
, ATTR_DISPINTERFACE
);
1145 fprintf(header
, "/*****************************************************************************\n");
1146 fprintf(header
, " * %s %sinterface\n", iface
->name
, dispinterface
? "disp" : "");
1147 fprintf(header
, " */\n");
1148 fprintf(header
,"#ifndef __%s_%sINTERFACE_DEFINED__\n", iface
->name
, dispinterface
? "DISP" : "");
1149 fprintf(header
,"#define __%s_%sINTERFACE_DEFINED__\n\n", iface
->name
, dispinterface
? "DISP" : "");
1152 static void write_com_interface_end(FILE *header
, type_t
*iface
)
1154 int dispinterface
= is_attr(iface
->attrs
, ATTR_DISPINTERFACE
);
1155 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
1158 write_guid(header
, dispinterface
? "DIID" : "IID", iface
->name
, uuid
);
1161 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
1163 fprintf(header
, "MIDL_INTERFACE(\"%s\")\n", uuid_string(uuid
));
1165 fprintf(header
, "interface ");
1166 if (type_iface_get_inherit(iface
))
1168 fprintf(header
, "%s : public %s\n", iface
->name
,
1169 type_iface_get_inherit(iface
)->name
);
1170 fprintf(header
, "{\n");
1174 fprintf(header
, "%s\n", iface
->name
);
1175 fprintf(header
, "{\n");
1176 fprintf(header
, " BEGIN_INTERFACE\n");
1177 fprintf(header
, "\n");
1179 /* dispinterfaces don't have real functions, so don't write C++ functions for
1184 write_cpp_method_def(header
, iface
);
1187 if (!type_iface_get_inherit(iface
))
1188 fprintf(header
, " END_INTERFACE\n");
1189 fprintf(header
, "};\n");
1191 write_uuid_decl(header
, iface
->name
, uuid
);
1192 fprintf(header
, "#else\n");
1194 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
1196 fprintf(header
, " BEGIN_INTERFACE\n");
1197 fprintf(header
, "\n");
1199 write_c_disp_method_def(header
, iface
);
1201 write_c_method_def(header
, iface
);
1203 fprintf(header
, " END_INTERFACE\n");
1204 fprintf(header
, "} %sVtbl;\n", iface
->name
);
1205 fprintf(header
, "interface %s {\n", iface
->name
);
1206 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
1207 fprintf(header
, "};\n");
1208 fprintf(header
, "\n");
1209 fprintf(header
, "#ifdef COBJMACROS\n");
1210 /* dispinterfaces don't have real functions, so don't write macros for them,
1211 * only for the interface this interface inherits from, i.e. IDispatch */
1212 fprintf(header
, "#ifndef WIDL_C_INLINE_WRAPPERS\n");
1213 write_method_macro(header
, dispinterface
? type_iface_get_inherit(iface
) : iface
, iface
->name
);
1214 fprintf(header
, "#else\n");
1215 write_inline_wrappers(header
, dispinterface
? type_iface_get_inherit(iface
) : iface
, iface
->name
);
1216 fprintf(header
, "#endif\n");
1217 fprintf(header
, "#endif\n");
1218 fprintf(header
, "\n");
1219 fprintf(header
, "#endif\n");
1220 fprintf(header
, "\n");
1221 /* dispinterfaces don't have real functions, so don't write prototypes for
1225 write_method_proto(header
, iface
);
1226 write_locals(header
, iface
, FALSE
);
1227 fprintf(header
, "\n");
1229 fprintf(header
,"#endif /* __%s_%sINTERFACE_DEFINED__ */\n\n", iface
->name
, dispinterface
? "DISP" : "");
1232 static void write_rpc_interface_start(FILE *header
, const type_t
*iface
)
1234 unsigned int ver
= get_attrv(iface
->attrs
, ATTR_VERSION
);
1235 const var_t
*var
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
1237 fprintf(header
, "/*****************************************************************************\n");
1238 fprintf(header
, " * %s interface (v%d.%d)\n", iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
1239 fprintf(header
, " */\n");
1240 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
1241 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
1244 fprintf(header
, "extern ");
1245 write_type_decl( header
, var
->type
, var
->name
);
1246 fprintf(header
, ";\n");
1250 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ClientIfHandle;\n", prefix_client
, iface
->name
);
1251 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ServerIfHandle;\n", prefix_server
, iface
->name
);
1255 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n",
1256 prefix_client
, iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
1257 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n",
1258 prefix_server
, iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
1262 static void write_rpc_interface_end(FILE *header
, const type_t
*iface
)
1264 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
1267 static void write_coclass(FILE *header
, type_t
*cocl
)
1269 const UUID
*uuid
= get_attrp(cocl
->attrs
, ATTR_UUID
);
1271 fprintf(header
, "/*****************************************************************************\n");
1272 fprintf(header
, " * %s coclass\n", cocl
->name
);
1273 fprintf(header
, " */\n\n");
1275 write_guid(header
, "CLSID", cocl
->name
, uuid
);
1276 fprintf(header
, "\n#ifdef __cplusplus\n");
1279 fprintf(header
, "class DECLSPEC_UUID(\"%s\") %s;\n", uuid_string(uuid
), cocl
->name
);
1280 write_uuid_decl(header
, cocl
->name
, uuid
);
1284 fprintf(header
, "class %s;\n", cocl
->name
);
1286 fprintf(header
, "#endif\n");
1287 fprintf(header
, "\n");
1290 static void write_coclass_forward(FILE *header
, type_t
*cocl
)
1292 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", cocl
->name
);
1293 fprintf(header
, "#define __%s_FWD_DEFINED__\n", cocl
->name
);
1294 fprintf(header
, "#ifdef __cplusplus\n");
1295 fprintf(header
, "typedef class %s %s;\n", cocl
->name
, cocl
->name
);
1296 fprintf(header
, "#else\n");
1297 fprintf(header
, "typedef struct %s %s;\n", cocl
->name
, cocl
->name
);
1298 fprintf(header
, "#endif /* defined __cplusplus */\n");
1299 fprintf(header
, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl
->name
);
1302 static void write_import(FILE *header
, const char *fname
)
1306 hname
= dup_basename(fname
, ".idl");
1307 p
= hname
+ strlen(hname
) - 2;
1308 if (p
<= hname
|| strcmp( p
, ".h" )) strcat(hname
, ".h");
1310 fprintf(header
, "#include <%s>\n", hname
);
1314 static void write_imports(FILE *header
, const statement_list_t
*stmts
)
1316 const statement_t
*stmt
;
1317 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
1322 if (type_get_type(stmt
->u
.type
) == TYPE_INTERFACE
)
1323 write_imports(header
, type_iface_get_stmts(stmt
->u
.type
));
1326 case STMT_IMPORTLIB
:
1327 /* not included in header */
1330 write_import(header
, stmt
->u
.str
);
1336 case STMT_DECLARATION
:
1337 /* not processed here */
1340 write_imports(header
, stmt
->u
.lib
->stmts
);
1346 static void write_forward_decls(FILE *header
, const statement_list_t
*stmts
)
1348 const statement_t
*stmt
;
1349 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
1354 if (type_get_type(stmt
->u
.type
) == TYPE_INTERFACE
)
1356 if (is_object(stmt
->u
.type
) || is_attr(stmt
->u
.type
->attrs
, ATTR_DISPINTERFACE
))
1357 write_forward(header
, stmt
->u
.type
);
1359 else if (type_get_type(stmt
->u
.type
) == TYPE_COCLASS
)
1360 write_coclass_forward(header
, stmt
->u
.type
);
1363 case STMT_IMPORTLIB
:
1364 /* not included in header */
1371 case STMT_DECLARATION
:
1372 /* not processed here */
1375 write_forward_decls(header
, stmt
->u
.lib
->stmts
);
1381 static void write_header_stmts(FILE *header
, const statement_list_t
*stmts
, const type_t
*iface
, int ignore_funcs
)
1383 const statement_t
*stmt
;
1384 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
1389 if (type_get_type(stmt
->u
.type
) == TYPE_INTERFACE
)
1391 type_t
*iface
= stmt
->u
.type
;
1392 if (is_object(iface
)) is_object_interface
++;
1393 if (is_attr(stmt
->u
.type
->attrs
, ATTR_DISPINTERFACE
) || is_object(stmt
->u
.type
))
1395 write_com_interface_start(header
, iface
);
1396 write_header_stmts(header
, type_iface_get_stmts(iface
), stmt
->u
.type
, TRUE
);
1397 write_com_interface_end(header
, iface
);
1401 write_rpc_interface_start(header
, iface
);
1402 write_header_stmts(header
, type_iface_get_stmts(iface
), iface
, FALSE
);
1403 write_rpc_interface_end(header
, iface
);
1405 if (is_object(iface
)) is_object_interface
--;
1407 else if (type_get_type(stmt
->u
.type
) == TYPE_COCLASS
)
1408 write_coclass(header
, stmt
->u
.type
);
1411 write_type_def_or_decl(header
, stmt
->u
.type
, FALSE
, NULL
);
1412 fprintf(header
, ";\n\n");
1416 /* FIXME: shouldn't write out forward declarations for undefined
1417 * interfaces but a number of our IDL files depend on this */
1418 if (type_get_type(stmt
->u
.type
) == TYPE_INTERFACE
&& !stmt
->u
.type
->written
)
1419 write_forward(header
, stmt
->u
.type
);
1421 case STMT_IMPORTLIB
:
1424 /* not included in header */
1427 /* not processed here */
1431 const type_list_t
*type_entry
= stmt
->u
.type_list
;
1432 for (; type_entry
; type_entry
= type_entry
->next
)
1433 write_typedef(header
, type_entry
->type
);
1437 write_library(header
, stmt
->u
.lib
);
1438 write_header_stmts(header
, stmt
->u
.lib
->stmts
, NULL
, FALSE
);
1441 fprintf(header
, "%s\n", stmt
->u
.str
);
1443 case STMT_DECLARATION
:
1444 if (iface
&& type_get_type(stmt
->u
.var
->type
) == TYPE_FUNCTION
)
1448 int prefixes_differ
= strcmp(prefix_client
, prefix_server
);
1450 if (prefixes_differ
)
1452 fprintf(header
, "/* client prototype */\n");
1453 write_function_proto(header
, iface
, stmt
->u
.var
, prefix_client
);
1454 fprintf(header
, "/* server prototype */\n");
1456 write_function_proto(header
, iface
, stmt
->u
.var
, prefix_server
);
1460 write_declaration(header
, stmt
->u
.var
);
1466 void write_header(const statement_list_t
*stmts
)
1470 if (!do_header
) return;
1472 if(!(header
= fopen(header_name
, "w"))) {
1473 error("Could not open %s for output\n", header_name
);
1476 fprintf(header
, "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n\n", PACKAGE_VERSION
, input_name
);
1478 fprintf(header
, "#ifndef __REQUIRED_RPCNDR_H_VERSION__\n");
1479 fprintf(header
, "#define __REQUIRED_RPCNDR_H_VERSION__ 475\n");
1480 fprintf(header
, "#endif\n\n");
1482 fprintf(header
, "#include <rpc.h>\n" );
1483 fprintf(header
, "#include <rpcndr.h>\n\n" );
1485 fprintf(header
, "#ifndef COM_NO_WINDOWS_H\n");
1486 fprintf(header
, "#include <windows.h>\n");
1487 fprintf(header
, "#include <ole2.h>\n");
1488 fprintf(header
, "#endif\n\n");
1490 fprintf(header
, "#ifndef __%s__\n", header_token
);
1491 fprintf(header
, "#define __%s__\n\n", header_token
);
1493 fprintf(header
, "/* Forward declarations */\n\n");
1494 write_forward_decls(header
, stmts
);
1496 fprintf(header
, "/* Headers for imported files */\n\n");
1497 write_imports(header
, stmts
);
1498 fprintf(header
, "\n");
1499 start_cplusplus_guard(header
);
1501 write_header_stmts(header
, stmts
, NULL
, FALSE
);
1503 fprintf(header
, "/* Begin additional prototypes for all interfaces */\n");
1504 fprintf(header
, "\n");
1505 write_user_types(header
);
1506 write_generic_handle_routines(header
);
1507 write_context_handle_rundowns(header
);
1508 fprintf(header
, "\n");
1509 fprintf(header
, "/* End additional prototypes */\n");
1510 fprintf(header
, "\n");
1512 end_cplusplus_guard(header
);
1513 fprintf(header
, "#endif /* __%s__ */\n", header_token
);