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 int is_void(const type_t
*t
)
114 return type_get_type(t
) == TYPE_VOID
;
117 int is_conformant_array(const type_t
*t
)
119 return is_array(t
) && type_array_has_conformance(t
);
122 void write_guid(FILE *f
, const char *guid_prefix
, const char *name
, const UUID
*uuid
)
125 fprintf(f
, "DEFINE_GUID(%s_%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 guid_prefix
, name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0],
128 uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5],
129 uuid
->Data4
[6], uuid
->Data4
[7]);
132 static void write_uuid_decl(FILE *f
, const char *name
, const UUID
*uuid
)
134 fprintf(f
, "#ifdef __CRT_UUID_DECL\n");
135 fprintf(f
, "__CRT_UUID_DECL(%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
136 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x)\n",
137 name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0], uuid
->Data4
[1],
138 uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5], uuid
->Data4
[6],
140 fprintf(f
, "#endif\n");
143 static const char *uuid_string(const UUID
*uuid
)
147 sprintf(buf
, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
148 uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0], uuid
->Data4
[1], uuid
->Data4
[2],
149 uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5], uuid
->Data4
[6], uuid
->Data4
[7]);
154 const char *get_name(const var_t
*v
)
156 static char buffer
[256];
158 if (is_attr( v
->attrs
, ATTR_PROPGET
))
159 strcpy( buffer
, "get_" );
160 else if (is_attr( v
->attrs
, ATTR_PROPPUT
))
161 strcpy( buffer
, "put_" );
162 else if (is_attr( v
->attrs
, ATTR_PROPPUTREF
))
163 strcpy( buffer
, "putref_" );
166 strcat( buffer
, v
->name
);
170 static void write_fields(FILE *h
, var_list_t
*fields
)
172 unsigned nameless_struct_cnt
= 0, nameless_struct_i
= 0, nameless_union_cnt
= 0, nameless_union_i
= 0;
179 LIST_FOR_EACH_ENTRY( v
, fields
, var_t
, entry
) {
180 if (!v
|| !v
->type
) continue;
182 switch(type_get_type_detect_alias(v
->type
)) {
184 case TYPE_ENCAPSULATED_UNION
:
185 nameless_struct_cnt
++;
188 nameless_union_cnt
++;
195 LIST_FOR_EACH_ENTRY( v
, fields
, var_t
, entry
) {
196 if (!v
|| !v
->type
) continue;
201 switch(type_get_type_detect_alias(v
->type
)) {
203 case TYPE_ENCAPSULATED_UNION
:
205 fprintf(h
, "__C89_NAMELESS ");
206 if(nameless_struct_cnt
== 1) {
207 name
= "__C89_NAMELESSSTRUCTNAME";
208 }else if(nameless_struct_i
< 5 /* # of supporting macros */) {
209 sprintf(buf
, "__C89_NAMELESSSTRUCTNAME%d", ++nameless_struct_i
);
216 fprintf(h
, "__C89_NAMELESS ");
217 if(nameless_union_cnt
== 1) {
218 name
= "__C89_NAMELESSUNIONNAME";
219 }else if(nameless_union_i
< 8 /* # of supporting macros */ ) {
220 sprintf(buf
, "__C89_NAMELESSUNIONNAME%d", ++nameless_union_i
);
228 write_type_def_or_decl(h
, v
->type
, TRUE
, name
);
233 static void write_enums(FILE *h
, var_list_t
*enums
)
237 LIST_FOR_EACH_ENTRY( v
, enums
, var_t
, entry
)
241 fprintf(h
, "%s", get_name(v
));
244 write_expr(h
, v
->eval
, 0, 1, NULL
, NULL
, "");
247 if (list_next( enums
, &v
->entry
)) fprintf(h
, ",\n");
252 int needs_space_after(type_t
*t
)
254 return (type_is_alias(t
) ||
255 (!is_ptr(t
) && (!is_array(t
) || !type_array_is_decl_as_ptr(t
) || t
->name
)));
258 void write_type_left(FILE *h
, type_t
*t
, int declonly
)
262 if (is_attr(t
->attrs
, ATTR_CONST
) &&
263 (type_is_alias(t
) || !is_ptr(t
)))
264 fprintf(h
, "const ");
266 if (type_is_alias(t
)) fprintf(h
, "%s", t
->name
);
268 switch (type_get_type_detect_alias(t
)) {
270 if (!declonly
&& t
->defined
&& !t
->written
) {
271 if (t
->name
) fprintf(h
, "enum %s {\n", t
->name
);
272 else fprintf(h
, "enum {\n");
275 write_enums(h
, type_enum_get_values(t
));
279 else fprintf(h
, "enum %s", t
->name
? t
->name
: "");
282 case TYPE_ENCAPSULATED_UNION
:
283 if (!declonly
&& t
->defined
&& !t
->written
) {
284 if (t
->name
) fprintf(h
, "struct %s {\n", t
->name
);
285 else fprintf(h
, "struct {\n");
288 if (type_get_type(t
) != TYPE_STRUCT
)
289 write_fields(h
, type_encapsulated_union_get_fields(t
));
291 write_fields(h
, type_struct_get_fields(t
));
295 else fprintf(h
, "struct %s", t
->name
? t
->name
: "");
298 if (!declonly
&& t
->defined
&& !t
->written
) {
299 if (t
->name
) fprintf(h
, "union %s {\n", t
->name
);
300 else fprintf(h
, "union {\n");
303 write_fields(h
, type_union_get_cases(t
));
307 else fprintf(h
, "union %s", t
->name
? t
->name
: "");
310 write_type_left(h
, type_pointer_get_ref(t
), declonly
);
311 fprintf(h
, "%s*", needs_space_after(type_pointer_get_ref(t
)) ? " " : "");
312 if (is_attr(t
->attrs
, ATTR_CONST
)) fprintf(h
, "const ");
315 if (t
->name
&& type_array_is_decl_as_ptr(t
))
316 fprintf(h
, "%s", t
->name
);
319 write_type_left(h
, type_array_get_element(t
), declonly
);
320 if (type_array_is_decl_as_ptr(t
))
321 fprintf(h
, "%s*", needs_space_after(type_array_get_element(t
)) ? " " : "");
325 if (type_basic_get_type(t
) != TYPE_BASIC_INT32
&&
326 type_basic_get_type(t
) != TYPE_BASIC_INT64
&&
327 type_basic_get_type(t
) != TYPE_BASIC_HYPER
)
329 if (type_basic_get_sign(t
) < 0) fprintf(h
, "signed ");
330 else if (type_basic_get_sign(t
) > 0) fprintf(h
, "unsigned ");
332 switch (type_basic_get_type(t
))
334 case TYPE_BASIC_INT8
: fprintf(h
, "small"); break;
335 case TYPE_BASIC_INT16
: fprintf(h
, "short"); break;
336 case TYPE_BASIC_INT
: fprintf(h
, "int"); break;
337 case TYPE_BASIC_INT3264
: fprintf(h
, "__int3264"); break;
338 case TYPE_BASIC_BYTE
: fprintf(h
, "byte"); break;
339 case TYPE_BASIC_CHAR
: fprintf(h
, "char"); break;
340 case TYPE_BASIC_WCHAR
: fprintf(h
, "wchar_t"); break;
341 case TYPE_BASIC_FLOAT
: fprintf(h
, "float"); break;
342 case TYPE_BASIC_DOUBLE
: fprintf(h
, "double"); break;
343 case TYPE_BASIC_ERROR_STATUS_T
: fprintf(h
, "error_status_t"); break;
344 case TYPE_BASIC_HANDLE
: fprintf(h
, "handle_t"); break;
345 case TYPE_BASIC_INT32
:
346 if (type_basic_get_sign(t
) > 0)
351 case TYPE_BASIC_INT64
:
352 if (type_basic_get_sign(t
) > 0)
353 fprintf(h
, "UINT64");
357 case TYPE_BASIC_HYPER
:
358 if (type_basic_get_sign(t
) > 0)
359 fprintf(h
, "MIDL_uhyper");
368 fprintf(h
, "%s", t
->name
);
374 write_type_left(h
, type_bitfield_get_field(t
), declonly
);
378 /* handled elsewhere */
385 void write_type_right(FILE *h
, type_t
*t
, int is_field
)
389 switch (type_get_type(t
))
392 if (!type_array_is_decl_as_ptr(t
))
394 if (is_conformant_array(t
))
396 fprintf(h
, "[%s]", is_field
? "1" : "");
397 t
= type_array_get_element(t
);
400 type_get_type(t
) == TYPE_ARRAY
&& !type_array_is_decl_as_ptr(t
);
401 t
= type_array_get_element(t
))
402 fprintf(h
, "[%u]", type_array_get_dim(t
));
406 fprintf(h
, " : %u", type_bitfield_get_bits(t
)->cval
);
412 case TYPE_ENCAPSULATED_UNION
:
424 static void write_type_v(FILE *h
, type_t
*t
, int is_field
, int declonly
, const char *name
)
432 for (pt
= t
; is_ptr(pt
); pt
= type_pointer_get_ref(pt
), ptr_level
++)
435 if (type_get_type_detect_alias(pt
) == TYPE_FUNCTION
) {
437 const char *callconv
= get_attrp(pt
->attrs
, ATTR_CALLCONV
);
438 if (!callconv
&& is_object_interface
) callconv
= "STDMETHODCALLTYPE";
439 if (is_attr(pt
->attrs
, ATTR_INLINE
)) fprintf(h
, "inline ");
440 write_type_left(h
, type_function_get_rettype(pt
), declonly
);
442 if (ptr_level
) fputc('(', h
);
443 if (callconv
) fprintf(h
, "%s ", callconv
);
444 for (i
= 0; i
< ptr_level
; i
++)
447 write_type_left(h
, t
, declonly
);
450 if (name
) fprintf(h
, "%s%s", !t
|| needs_space_after(t
) ? " " : "", name
);
453 if (type_get_type_detect_alias(pt
) == TYPE_FUNCTION
) {
454 const var_list_t
*args
= type_function_get_args(pt
);
456 if (ptr_level
) fputc(')', h
);
459 write_args(h
, args
, NULL
, 0, FALSE
);
464 write_type_right(h
, t
, is_field
);
468 static void write_type_def_or_decl(FILE *f
, type_t
*t
, int field
, const char *name
)
470 write_type_v(f
, t
, field
, FALSE
, name
);
473 void write_type_decl(FILE *f
, type_t
*t
, const char *name
)
475 write_type_v(f
, t
, FALSE
, TRUE
, name
);
478 void write_type_decl_left(FILE *f
, type_t
*t
)
480 write_type_left(f
, t
, TRUE
);
483 static int user_type_registered(const char *name
)
486 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
487 if (!strcmp(name
, ut
->name
))
492 static int context_handle_registered(const char *name
)
494 context_handle_t
*ch
;
495 LIST_FOR_EACH_ENTRY(ch
, &context_handle_list
, context_handle_t
, entry
)
496 if (!strcmp(name
, ch
->name
))
501 static int generic_handle_registered(const char *name
)
503 generic_handle_t
*gh
;
504 LIST_FOR_EACH_ENTRY(gh
, &generic_handle_list
, generic_handle_t
, entry
)
505 if (!strcmp(name
, gh
->name
))
510 unsigned int get_context_handle_offset( const type_t
*type
)
512 context_handle_t
*ch
;
513 unsigned int index
= 0;
515 while (!is_attr( type
->attrs
, ATTR_CONTEXTHANDLE
))
517 if (type_is_alias( type
)) type
= type_alias_get_aliasee( type
);
518 else if (is_ptr( type
)) type
= type_pointer_get_ref( type
);
519 else error( "internal error: %s is not a context handle\n", type
->name
);
521 LIST_FOR_EACH_ENTRY( ch
, &context_handle_list
, context_handle_t
, entry
)
523 if (!strcmp( type
->name
, ch
->name
)) return index
;
526 error( "internal error: %s is not registered as a context handle\n", type
->name
);
530 unsigned int get_generic_handle_offset( const type_t
*type
)
532 generic_handle_t
*gh
;
533 unsigned int index
= 0;
535 while (!is_attr( type
->attrs
, ATTR_HANDLE
))
537 if (type_is_alias( type
)) type
= type_alias_get_aliasee( type
);
538 else if (is_ptr( type
)) type
= type_pointer_get_ref( type
);
539 else error( "internal error: %s is not a generic handle\n", type
->name
);
541 LIST_FOR_EACH_ENTRY( gh
, &generic_handle_list
, generic_handle_t
, entry
)
543 if (!strcmp( type
->name
, gh
->name
)) return index
;
546 error( "internal error: %s is not registered as a generic handle\n", type
->name
);
550 /* check for types which require additional prototypes to be generated in the
552 void check_for_additional_prototype_types(const var_list_t
*list
)
557 LIST_FOR_EACH_ENTRY( v
, list
, const var_t
, entry
)
559 type_t
*type
= v
->type
;
562 const char *name
= type
->name
;
563 if (type
->user_types_registered
) break;
564 type
->user_types_registered
= 1;
565 if (is_attr(type
->attrs
, ATTR_CONTEXTHANDLE
)) {
566 if (!context_handle_registered(name
))
568 context_handle_t
*ch
= xmalloc(sizeof(*ch
));
569 ch
->name
= xstrdup(name
);
570 list_add_tail(&context_handle_list
, &ch
->entry
);
572 /* don't carry on parsing fields within this type */
575 if ((type_get_type(type
) != TYPE_BASIC
||
576 type_basic_get_type(type
) != TYPE_BASIC_HANDLE
) &&
577 is_attr(type
->attrs
, ATTR_HANDLE
)) {
578 if (!generic_handle_registered(name
))
580 generic_handle_t
*gh
= xmalloc(sizeof(*gh
));
581 gh
->name
= xstrdup(name
);
582 list_add_tail(&generic_handle_list
, &gh
->entry
);
584 /* don't carry on parsing fields within this type */
587 if (is_attr(type
->attrs
, ATTR_WIREMARSHAL
)) {
588 if (!user_type_registered(name
))
590 user_type_t
*ut
= xmalloc(sizeof *ut
);
591 ut
->name
= xstrdup(name
);
592 list_add_tail(&user_type_list
, &ut
->entry
);
594 /* don't carry on parsing fields within this type as we are already
595 * using a wire marshaled type */
598 else if (type_is_complete(type
))
601 switch (type_get_type_detect_alias(type
))
604 vars
= type_enum_get_values(type
);
607 vars
= type_struct_get_fields(type
);
610 vars
= type_union_get_cases(type
);
616 check_for_additional_prototype_types(vars
);
619 if (type_is_alias(type
))
620 type
= type_alias_get_aliasee(type
);
621 else if (is_ptr(type
))
622 type
= type_pointer_get_ref(type
);
623 else if (is_array(type
))
624 type
= type_array_get_element(type
);
631 static void write_user_types(FILE *header
)
634 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
636 const char *name
= ut
->name
;
637 fprintf(header
, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name
, name
);
638 fprintf(header
, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name
, name
);
639 fprintf(header
, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name
, name
);
640 fprintf(header
, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name
, name
);
644 static void write_context_handle_rundowns(FILE *header
)
646 context_handle_t
*ch
;
647 LIST_FOR_EACH_ENTRY(ch
, &context_handle_list
, context_handle_t
, entry
)
649 const char *name
= ch
->name
;
650 fprintf(header
, "void __RPC_USER %s_rundown(%s);\n", name
, name
);
654 static void write_generic_handle_routines(FILE *header
)
656 generic_handle_t
*gh
;
657 LIST_FOR_EACH_ENTRY(gh
, &generic_handle_list
, generic_handle_t
, entry
)
659 const char *name
= gh
->name
;
660 fprintf(header
, "handle_t __RPC_USER %s_bind(%s);\n", name
, name
);
661 fprintf(header
, "void __RPC_USER %s_unbind(%s, handle_t);\n", name
, name
);
665 static void write_typedef(FILE *header
, type_t
*type
)
667 fprintf(header
, "typedef ");
668 write_type_def_or_decl(header
, type_alias_get_aliasee(type
), FALSE
, type
->name
);
669 fprintf(header
, ";\n");
672 int is_const_decl(const var_t
*var
)
675 /* strangely, MIDL accepts a const attribute on any pointer in the
676 * declaration to mean that data isn't being instantiated. this appears
677 * to be a bug, but there is no benefit to being incompatible with MIDL,
678 * so we'll do the same thing */
679 for (t
= var
->type
; ; )
681 if (is_attr(t
->attrs
, ATTR_CONST
))
684 t
= type_pointer_get_ref(t
);
690 static void write_declaration(FILE *header
, const var_t
*v
)
692 if (is_const_decl(v
) && v
->eval
)
694 fprintf(header
, "#define %s (", v
->name
);
695 write_expr(header
, v
->eval
, 0, 1, NULL
, NULL
, "");
696 fprintf(header
, ")\n\n");
703 case STG_REGISTER
: /* ignored */
706 fprintf(header
, "static ");
709 fprintf(header
, "extern ");
712 write_type_def_or_decl(header
, v
->type
, FALSE
, v
->name
);
713 fprintf(header
, ";\n\n");
717 static void write_library(FILE *header
, const typelib_t
*typelib
)
719 const UUID
*uuid
= get_attrp(typelib
->attrs
, ATTR_UUID
);
720 fprintf(header
, "\n");
721 write_guid(header
, "LIBID", typelib
->name
, uuid
);
722 fprintf(header
, "\n");
726 const type_t
* get_explicit_generic_handle_type(const var_t
* var
)
730 is_ptr(t
) || type_is_alias(t
);
731 t
= type_is_alias(t
) ? type_alias_get_aliasee(t
) : type_pointer_get_ref(t
))
732 if ((type_get_type_detect_alias(t
) != TYPE_BASIC
|| type_basic_get_type(t
) != TYPE_BASIC_HANDLE
) &&
733 is_attr(t
->attrs
, ATTR_HANDLE
))
738 const var_t
*get_func_handle_var( const type_t
*iface
, const var_t
*func
,
739 unsigned char *explicit_fc
, unsigned char *implicit_fc
)
742 const var_list_t
*args
= type_get_function_args( func
->type
);
744 *explicit_fc
= *implicit_fc
= 0;
745 if (args
) LIST_FOR_EACH_ENTRY( var
, args
, const var_t
, entry
)
747 if (!is_attr( var
->attrs
, ATTR_IN
) && is_attr( var
->attrs
, ATTR_OUT
)) continue;
748 if (type_get_type( var
->type
) == TYPE_BASIC
&& type_basic_get_type( var
->type
) == TYPE_BASIC_HANDLE
)
750 *explicit_fc
= RPC_FC_BIND_PRIMITIVE
;
753 if (get_explicit_generic_handle_type( var
))
755 *explicit_fc
= RPC_FC_BIND_GENERIC
;
758 if (is_context_handle( var
->type
))
760 *explicit_fc
= RPC_FC_BIND_CONTEXT
;
765 if ((var
= get_attrp( iface
->attrs
, ATTR_IMPLICIT_HANDLE
)))
767 if (type_get_type( var
->type
) == TYPE_BASIC
&&
768 type_basic_get_type( var
->type
) == TYPE_BASIC_HANDLE
)
769 *implicit_fc
= RPC_FC_BIND_PRIMITIVE
;
771 *implicit_fc
= RPC_FC_BIND_GENERIC
;
775 *implicit_fc
= RPC_FC_AUTO_HANDLE
;
779 int has_out_arg_or_return(const var_t
*func
)
783 if (!is_void(type_function_get_rettype(func
->type
)))
786 if (!type_get_function_args(func
->type
))
789 LIST_FOR_EACH_ENTRY( var
, type_get_function_args(func
->type
), const var_t
, entry
)
790 if (is_attr(var
->attrs
, ATTR_OUT
))
797 /********** INTERFACES **********/
799 int is_object(const type_t
*iface
)
802 if (type_is_defined(iface
) && type_iface_get_inherit(iface
))
804 if (iface
->attrs
) LIST_FOR_EACH_ENTRY( attr
, iface
->attrs
, const attr_t
, entry
)
805 if (attr
->type
== ATTR_OBJECT
|| attr
->type
== ATTR_ODL
) return 1;
809 int is_local(const attr_list_t
*a
)
811 return is_attr(a
, ATTR_LOCAL
);
814 const var_t
*is_callas(const attr_list_t
*a
)
816 return get_attrp(a
, ATTR_CALLAS
);
819 static int is_inherited_method(const type_t
*iface
, const var_t
*func
)
821 while ((iface
= type_iface_get_inherit(iface
)))
823 const statement_t
*stmt
;
824 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
))
826 const var_t
*funccmp
= stmt
->u
.var
;
828 if (!is_callas(func
->attrs
))
830 char inherit_name
[256];
831 /* compare full name including property prefix */
832 strcpy(inherit_name
, get_name(funccmp
));
833 if (!strcmp(inherit_name
, get_name(func
))) return 1;
841 static void write_method_macro(FILE *header
, const type_t
*iface
, const char *name
)
843 const statement_t
*stmt
;
846 if (type_iface_get_inherit(iface
))
847 write_method_macro(header
, type_iface_get_inherit(iface
), name
);
849 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
))
851 const var_t
*func
= stmt
->u
.var
;
855 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
859 if (!is_callas(func
->attrs
) && !is_inherited_method(iface
, func
)) {
862 fprintf(header
, "#define %s_%s(This", name
, get_name(func
));
863 if (type_get_function_args(func
->type
))
864 LIST_FOR_EACH_ENTRY( arg
, type_get_function_args(func
->type
), const var_t
, entry
)
865 fprintf(header
, ",%s", arg
->name
);
866 fprintf(header
, ") ");
868 fprintf(header
, "(This)->lpVtbl->%s(This", get_name(func
));
869 if (type_get_function_args(func
->type
))
870 LIST_FOR_EACH_ENTRY( arg
, type_get_function_args(func
->type
), const var_t
, entry
)
871 fprintf(header
, ",%s", arg
->name
);
872 fprintf(header
, ")\n");
877 void write_args(FILE *h
, const var_list_t
*args
, const char *name
, int method
, int do_indent
)
888 fprintf(h
, "%s* This", name
);
891 if (args
) LIST_FOR_EACH_ENTRY( arg
, args
, const var_t
, entry
) {
898 else fprintf(h
, ",");
900 write_type_decl(h
, arg
->type
, arg
->name
);
902 const expr_t
*expr
= get_attrp(arg
->attrs
, ATTR_DEFAULTVALUE
);
905 write_expr( h
, expr
, 0, 1, NULL
, NULL
, "" );
910 if (do_indent
) indentation
--;
913 static void write_cpp_method_def(FILE *header
, const type_t
*iface
)
915 const statement_t
*stmt
;
917 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
))
919 const var_t
*func
= stmt
->u
.var
;
920 if (!is_callas(func
->attrs
)) {
921 const char *callconv
= get_attrp(func
->type
->attrs
, ATTR_CALLCONV
);
922 if (!callconv
) callconv
= "STDMETHODCALLTYPE";
924 fprintf(header
, "virtual ");
925 write_type_decl_left(header
, type_function_get_rettype(func
->type
));
926 fprintf(header
, " %s %s(\n", callconv
, get_name(func
));
927 write_args(header
, type_get_function_args(func
->type
), iface
->name
, 2, TRUE
);
928 fprintf(header
, ") = 0;\n");
929 fprintf(header
, "\n");
934 static void write_inline_wrappers(FILE *header
, const type_t
*iface
, const char *name
)
936 const statement_t
*stmt
;
939 if (type_iface_get_inherit(iface
))
940 write_inline_wrappers(header
, type_iface_get_inherit(iface
), name
);
942 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
))
944 const var_t
*func
= stmt
->u
.var
;
948 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
952 if (!is_callas(func
->attrs
) && !is_inherited_method(iface
, func
)) {
955 fprintf(header
, "static FORCEINLINE ");
956 write_type_decl_left(header
, type_function_get_rettype(func
->type
));
957 fprintf(header
, " %s_%s(", name
, get_name(func
));
958 write_args(header
, type_get_function_args(func
->type
), name
, 1, FALSE
);
959 fprintf(header
, ") {\n");
960 fprintf(header
, " %s", is_void(type_function_get_rettype(func
->type
)) ? "" : "return ");
961 fprintf(header
, "This->lpVtbl->%s(This", get_name(func
));
962 if (type_get_function_args(func
->type
))
963 LIST_FOR_EACH_ENTRY( arg
, type_get_function_args(func
->type
), const var_t
, entry
)
964 fprintf(header
, ",%s", arg
->name
);
965 fprintf(header
, ");\n");
966 fprintf(header
, "}\n");
971 static void do_write_c_method_def(FILE *header
, const type_t
*iface
, const char *name
)
973 const statement_t
*stmt
;
976 if (type_iface_get_inherit(iface
))
977 do_write_c_method_def(header
, type_iface_get_inherit(iface
), name
);
979 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
))
981 const var_t
*func
= stmt
->u
.var
;
984 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
987 if (!is_callas(func
->attrs
)) {
988 const char *callconv
= get_attrp(func
->type
->attrs
, ATTR_CALLCONV
);
989 if (!callconv
) callconv
= "STDMETHODCALLTYPE";
991 write_type_decl_left(header
, type_function_get_rettype(func
->type
));
992 if (is_inherited_method(iface
, func
))
993 fprintf(header
, " (%s *%s_%s)(\n", callconv
, iface
->name
, func
->name
);
995 fprintf(header
, " (%s *%s)(\n", callconv
, get_name(func
));
996 write_args(header
, type_get_function_args(func
->type
), name
, 1, TRUE
);
997 fprintf(header
, ");\n");
998 fprintf(header
, "\n");
1003 static void write_c_method_def(FILE *header
, const type_t
*iface
)
1005 do_write_c_method_def(header
, iface
, iface
->name
);
1008 static void write_c_disp_method_def(FILE *header
, const type_t
*iface
)
1010 do_write_c_method_def(header
, type_iface_get_inherit(iface
), iface
->name
);
1013 static void write_method_proto(FILE *header
, const type_t
*iface
)
1015 const statement_t
*stmt
;
1017 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
))
1019 const var_t
*func
= stmt
->u
.var
;
1021 if (!is_local(func
->attrs
)) {
1022 const char *callconv
= get_attrp(func
->type
->attrs
, ATTR_CALLCONV
);
1023 if (!callconv
) callconv
= "STDMETHODCALLTYPE";
1024 /* proxy prototype */
1025 write_type_decl_left(header
, type_function_get_rettype(func
->type
));
1026 fprintf(header
, " %s %s_%s_Proxy(\n", callconv
, iface
->name
, get_name(func
));
1027 write_args(header
, type_get_function_args(func
->type
), iface
->name
, 1, TRUE
);
1028 fprintf(header
, ");\n");
1029 /* stub prototype */
1030 fprintf(header
, "void __RPC_STUB %s_%s_Stub(\n", iface
->name
, get_name(func
));
1031 fprintf(header
, " IRpcStubBuffer* This,\n");
1032 fprintf(header
, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
1033 fprintf(header
, " PRPC_MESSAGE pRpcMessage,\n");
1034 fprintf(header
, " DWORD* pdwStubPhase);\n");
1039 static void write_locals(FILE *fp
, const type_t
*iface
, int body
)
1041 static const char comment
[]
1042 = "/* WIDL-generated stub. You must provide an implementation for this. */";
1043 const statement_t
*stmt
;
1045 if (!is_object(iface
))
1048 STATEMENTS_FOR_EACH_FUNC(stmt
, type_iface_get_stmts(iface
)) {
1049 const var_t
*func
= stmt
->u
.var
;
1050 const var_t
*cas
= is_callas(func
->attrs
);
1053 const statement_t
*stmt2
= NULL
;
1054 STATEMENTS_FOR_EACH_FUNC(stmt2
, type_iface_get_stmts(iface
))
1055 if (!strcmp(stmt2
->u
.var
->name
, cas
->name
))
1057 if (&stmt2
->entry
!= type_iface_get_stmts(iface
)) {
1058 const var_t
*m
= stmt2
->u
.var
;
1059 /* proxy prototype - use local prototype */
1060 write_type_decl_left(fp
, type_function_get_rettype(m
->type
));
1061 fprintf(fp
, " CALLBACK %s_%s_Proxy(\n", iface
->name
, get_name(m
));
1062 write_args(fp
, type_get_function_args(m
->type
), iface
->name
, 1, TRUE
);
1065 type_t
*rt
= type_function_get_rettype(m
->type
);
1066 fprintf(fp
, "\n{\n");
1067 fprintf(fp
, " %s\n", comment
);
1068 if (rt
->name
&& strcmp(rt
->name
, "HRESULT") == 0)
1069 fprintf(fp
, " return E_NOTIMPL;\n");
1070 else if (type_get_type(rt
) != TYPE_VOID
) {
1072 write_type_decl(fp
, rt
, "rv");
1074 fprintf(fp
, " memset(&rv, 0, sizeof rv);\n");
1075 fprintf(fp
, " return rv;\n");
1077 fprintf(fp
, "}\n\n");
1081 /* stub prototype - use remotable prototype */
1082 write_type_decl_left(fp
, type_function_get_rettype(func
->type
));
1083 fprintf(fp
, " __RPC_STUB %s_%s_Stub(\n", iface
->name
, get_name(m
));
1084 write_args(fp
, type_get_function_args(func
->type
), iface
->name
, 1, TRUE
);
1087 /* Remotable methods must all return HRESULTs. */
1088 fprintf(fp
, "\n{\n %s\n return E_NOTIMPL;\n}\n\n", comment
);
1093 error_loc("invalid call_as attribute (%s -> %s)\n", func
->name
, cas
->name
);
1098 static void write_local_stubs_stmts(FILE *local_stubs
, const statement_list_t
*stmts
)
1100 const statement_t
*stmt
;
1101 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
1103 if (stmt
->type
== STMT_TYPE
&& type_get_type(stmt
->u
.type
) == TYPE_INTERFACE
)
1104 write_locals(local_stubs
, stmt
->u
.type
, TRUE
);
1108 void write_local_stubs(const statement_list_t
*stmts
)
1112 if (!local_stubs_name
) return;
1114 local_stubs
= fopen(local_stubs_name
, "w");
1116 error("Could not open %s for output\n", local_stubs_name
);
1119 fprintf(local_stubs
, "/* call_as/local stubs for %s */\n\n", input_name
);
1120 fprintf(local_stubs
, "#include <objbase.h>\n");
1121 fprintf(local_stubs
, "#include \"%s\"\n\n", header_name
);
1123 write_local_stubs_stmts(local_stubs
, stmts
);
1125 fclose(local_stubs
);
1128 static void write_function_proto(FILE *header
, const type_t
*iface
, const var_t
*fun
, const char *prefix
)
1130 const char *callconv
= get_attrp(fun
->type
->attrs
, ATTR_CALLCONV
);
1132 if (!callconv
) callconv
= "__cdecl";
1133 /* FIXME: do we need to handle call_as? */
1134 write_type_decl_left(header
, type_function_get_rettype(fun
->type
));
1135 fprintf(header
, " %s ", callconv
);
1136 fprintf(header
, "%s%s(\n", prefix
, get_name(fun
));
1137 if (type_get_function_args(fun
->type
))
1138 write_args(header
, type_get_function_args(fun
->type
), iface
->name
, 0, TRUE
);
1140 fprintf(header
, " void");
1141 fprintf(header
, ");\n\n");
1144 static void write_forward(FILE *header
, type_t
*iface
)
1146 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", iface
->name
);
1147 fprintf(header
, "#define __%s_FWD_DEFINED__\n", iface
->name
);
1148 fprintf(header
, "typedef interface %s %s;\n", iface
->name
, iface
->name
);
1149 fprintf(header
, "#endif\n\n" );
1152 static void write_com_interface_start(FILE *header
, const type_t
*iface
)
1154 int dispinterface
= is_attr(iface
->attrs
, ATTR_DISPINTERFACE
);
1155 fprintf(header
, "/*****************************************************************************\n");
1156 fprintf(header
, " * %s %sinterface\n", iface
->name
, dispinterface
? "disp" : "");
1157 fprintf(header
, " */\n");
1158 fprintf(header
,"#ifndef __%s_%sINTERFACE_DEFINED__\n", iface
->name
, dispinterface
? "DISP" : "");
1159 fprintf(header
,"#define __%s_%sINTERFACE_DEFINED__\n\n", iface
->name
, dispinterface
? "DISP" : "");
1162 static void write_com_interface_end(FILE *header
, type_t
*iface
)
1164 int dispinterface
= is_attr(iface
->attrs
, ATTR_DISPINTERFACE
);
1165 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
1168 write_guid(header
, dispinterface
? "DIID" : "IID", iface
->name
, uuid
);
1171 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
1173 fprintf(header
, "MIDL_INTERFACE(\"%s\")\n", uuid_string(uuid
));
1175 fprintf(header
, "interface ");
1176 if (type_iface_get_inherit(iface
))
1178 fprintf(header
, "%s : public %s\n", iface
->name
,
1179 type_iface_get_inherit(iface
)->name
);
1180 fprintf(header
, "{\n");
1184 fprintf(header
, "%s\n", iface
->name
);
1185 fprintf(header
, "{\n");
1186 fprintf(header
, " BEGIN_INTERFACE\n");
1187 fprintf(header
, "\n");
1189 /* dispinterfaces don't have real functions, so don't write C++ functions for
1194 write_cpp_method_def(header
, iface
);
1197 if (!type_iface_get_inherit(iface
))
1198 fprintf(header
, " END_INTERFACE\n");
1199 fprintf(header
, "};\n");
1201 write_uuid_decl(header
, iface
->name
, uuid
);
1202 fprintf(header
, "#else\n");
1204 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
1206 fprintf(header
, " BEGIN_INTERFACE\n");
1207 fprintf(header
, "\n");
1209 write_c_disp_method_def(header
, iface
);
1211 write_c_method_def(header
, iface
);
1213 fprintf(header
, " END_INTERFACE\n");
1214 fprintf(header
, "} %sVtbl;\n", iface
->name
);
1215 fprintf(header
, "interface %s {\n", iface
->name
);
1216 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
1217 fprintf(header
, "};\n");
1218 fprintf(header
, "\n");
1219 fprintf(header
, "#ifdef COBJMACROS\n");
1220 /* dispinterfaces don't have real functions, so don't write macros for them,
1221 * only for the interface this interface inherits from, i.e. IDispatch */
1222 fprintf(header
, "#ifndef WIDL_C_INLINE_WRAPPERS\n");
1223 write_method_macro(header
, dispinterface
? type_iface_get_inherit(iface
) : iface
, iface
->name
);
1224 fprintf(header
, "#else\n");
1225 write_inline_wrappers(header
, dispinterface
? type_iface_get_inherit(iface
) : iface
, iface
->name
);
1226 fprintf(header
, "#endif\n");
1227 fprintf(header
, "#endif\n");
1228 fprintf(header
, "\n");
1229 fprintf(header
, "#endif\n");
1230 fprintf(header
, "\n");
1231 /* dispinterfaces don't have real functions, so don't write prototypes for
1235 write_method_proto(header
, iface
);
1236 write_locals(header
, iface
, FALSE
);
1237 fprintf(header
, "\n");
1239 fprintf(header
,"#endif /* __%s_%sINTERFACE_DEFINED__ */\n\n", iface
->name
, dispinterface
? "DISP" : "");
1242 static void write_rpc_interface_start(FILE *header
, const type_t
*iface
)
1244 unsigned int ver
= get_attrv(iface
->attrs
, ATTR_VERSION
);
1245 const var_t
*var
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
1247 fprintf(header
, "/*****************************************************************************\n");
1248 fprintf(header
, " * %s interface (v%d.%d)\n", iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
1249 fprintf(header
, " */\n");
1250 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
1251 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
1254 fprintf(header
, "extern ");
1255 write_type_decl( header
, var
->type
, var
->name
);
1256 fprintf(header
, ";\n");
1260 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ClientIfHandle;\n", prefix_client
, iface
->name
);
1261 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ServerIfHandle;\n", prefix_server
, iface
->name
);
1265 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n",
1266 prefix_client
, iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
1267 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n",
1268 prefix_server
, iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
1272 static void write_rpc_interface_end(FILE *header
, const type_t
*iface
)
1274 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
1277 static void write_coclass(FILE *header
, type_t
*cocl
)
1279 const UUID
*uuid
= get_attrp(cocl
->attrs
, ATTR_UUID
);
1281 fprintf(header
, "/*****************************************************************************\n");
1282 fprintf(header
, " * %s coclass\n", cocl
->name
);
1283 fprintf(header
, " */\n\n");
1285 write_guid(header
, "CLSID", cocl
->name
, uuid
);
1286 fprintf(header
, "\n#ifdef __cplusplus\n");
1289 fprintf(header
, "class DECLSPEC_UUID(\"%s\") %s;\n", uuid_string(uuid
), cocl
->name
);
1290 write_uuid_decl(header
, cocl
->name
, uuid
);
1294 fprintf(header
, "class %s;\n", cocl
->name
);
1296 fprintf(header
, "#endif\n");
1297 fprintf(header
, "\n");
1300 static void write_coclass_forward(FILE *header
, type_t
*cocl
)
1302 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", cocl
->name
);
1303 fprintf(header
, "#define __%s_FWD_DEFINED__\n", cocl
->name
);
1304 fprintf(header
, "#ifdef __cplusplus\n");
1305 fprintf(header
, "typedef class %s %s;\n", cocl
->name
, cocl
->name
);
1306 fprintf(header
, "#else\n");
1307 fprintf(header
, "typedef struct %s %s;\n", cocl
->name
, cocl
->name
);
1308 fprintf(header
, "#endif /* defined __cplusplus */\n");
1309 fprintf(header
, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl
->name
);
1312 static void write_import(FILE *header
, const char *fname
)
1316 hname
= dup_basename(fname
, ".idl");
1317 p
= hname
+ strlen(hname
) - 2;
1318 if (p
<= hname
|| strcmp( p
, ".h" )) strcat(hname
, ".h");
1320 fprintf(header
, "#include <%s>\n", hname
);
1324 static void write_imports(FILE *header
, const statement_list_t
*stmts
)
1326 const statement_t
*stmt
;
1327 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
1332 if (type_get_type(stmt
->u
.type
) == TYPE_INTERFACE
)
1333 write_imports(header
, type_iface_get_stmts(stmt
->u
.type
));
1336 case STMT_IMPORTLIB
:
1337 /* not included in header */
1340 write_import(header
, stmt
->u
.str
);
1345 case STMT_DECLARATION
:
1346 /* not processed here */
1349 write_imports(header
, stmt
->u
.lib
->stmts
);
1355 static void write_forward_decls(FILE *header
, const statement_list_t
*stmts
)
1357 const statement_t
*stmt
;
1358 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
1363 if (type_get_type(stmt
->u
.type
) == TYPE_INTERFACE
)
1365 if (is_object(stmt
->u
.type
) || is_attr(stmt
->u
.type
->attrs
, ATTR_DISPINTERFACE
))
1366 write_forward(header
, stmt
->u
.type
);
1368 else if (type_get_type(stmt
->u
.type
) == TYPE_COCLASS
)
1369 write_coclass_forward(header
, stmt
->u
.type
);
1372 case STMT_IMPORTLIB
:
1373 /* not included in header */
1379 case STMT_DECLARATION
:
1380 /* not processed here */
1383 write_forward_decls(header
, stmt
->u
.lib
->stmts
);
1389 static void write_header_stmts(FILE *header
, const statement_list_t
*stmts
, const type_t
*iface
, int ignore_funcs
)
1391 const statement_t
*stmt
;
1392 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
1397 if (type_get_type(stmt
->u
.type
) == TYPE_INTERFACE
)
1399 type_t
*iface
= stmt
->u
.type
;
1400 if (is_object(iface
)) is_object_interface
++;
1401 if (is_attr(stmt
->u
.type
->attrs
, ATTR_DISPINTERFACE
) || is_object(stmt
->u
.type
))
1403 write_com_interface_start(header
, iface
);
1404 write_header_stmts(header
, type_iface_get_stmts(iface
), stmt
->u
.type
, TRUE
);
1405 write_com_interface_end(header
, iface
);
1409 write_rpc_interface_start(header
, iface
);
1410 write_header_stmts(header
, type_iface_get_stmts(iface
), iface
, FALSE
);
1411 write_rpc_interface_end(header
, iface
);
1413 if (is_object(iface
)) is_object_interface
--;
1415 else if (type_get_type(stmt
->u
.type
) == TYPE_COCLASS
)
1416 write_coclass(header
, stmt
->u
.type
);
1419 write_type_def_or_decl(header
, stmt
->u
.type
, FALSE
, NULL
);
1420 fprintf(header
, ";\n\n");
1424 /* FIXME: shouldn't write out forward declarations for undefined
1425 * interfaces but a number of our IDL files depend on this */
1426 if (type_get_type(stmt
->u
.type
) == TYPE_INTERFACE
&& !stmt
->u
.type
->written
)
1427 write_forward(header
, stmt
->u
.type
);
1429 case STMT_IMPORTLIB
:
1431 /* not included in header */
1434 /* not processed here */
1438 const type_list_t
*type_entry
= stmt
->u
.type_list
;
1439 for (; type_entry
; type_entry
= type_entry
->next
)
1440 write_typedef(header
, type_entry
->type
);
1444 write_library(header
, stmt
->u
.lib
);
1445 write_header_stmts(header
, stmt
->u
.lib
->stmts
, NULL
, FALSE
);
1448 fprintf(header
, "%s\n", stmt
->u
.str
);
1450 case STMT_DECLARATION
:
1451 if (iface
&& type_get_type(stmt
->u
.var
->type
) == TYPE_FUNCTION
)
1455 int prefixes_differ
= strcmp(prefix_client
, prefix_server
);
1457 if (prefixes_differ
)
1459 fprintf(header
, "/* client prototype */\n");
1460 write_function_proto(header
, iface
, stmt
->u
.var
, prefix_client
);
1461 fprintf(header
, "/* server prototype */\n");
1463 write_function_proto(header
, iface
, stmt
->u
.var
, prefix_server
);
1467 write_declaration(header
, stmt
->u
.var
);
1473 void write_header(const statement_list_t
*stmts
)
1477 if (!do_header
) return;
1479 if(!(header
= fopen(header_name
, "w"))) {
1480 error("Could not open %s for output\n", header_name
);
1483 fprintf(header
, "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n\n", PACKAGE_VERSION
, input_name
);
1485 fprintf(header
, "#ifndef __REQUIRED_RPCNDR_H_VERSION__\n");
1486 fprintf(header
, "#define __REQUIRED_RPCNDR_H_VERSION__ 475\n");
1487 fprintf(header
, "#endif\n\n");
1489 fprintf(header
, "#include <rpc.h>\n" );
1490 fprintf(header
, "#include <rpcndr.h>\n\n" );
1492 fprintf(header
, "#ifndef COM_NO_WINDOWS_H\n");
1493 fprintf(header
, "#include <windows.h>\n");
1494 fprintf(header
, "#include <ole2.h>\n");
1495 fprintf(header
, "#endif\n\n");
1497 fprintf(header
, "#ifndef __%s__\n", header_token
);
1498 fprintf(header
, "#define __%s__\n\n", header_token
);
1500 fprintf(header
, "/* Forward declarations */\n\n");
1501 write_forward_decls(header
, stmts
);
1503 fprintf(header
, "/* Headers for imported files */\n\n");
1504 write_imports(header
, stmts
);
1505 fprintf(header
, "\n");
1506 start_cplusplus_guard(header
);
1508 write_header_stmts(header
, stmts
, NULL
, FALSE
);
1510 fprintf(header
, "/* Begin additional prototypes for all interfaces */\n");
1511 fprintf(header
, "\n");
1512 write_user_types(header
);
1513 write_generic_handle_routines(header
);
1514 write_context_handle_rundowns(header
);
1515 fprintf(header
, "\n");
1516 fprintf(header
, "/* End additional prototypes */\n");
1517 fprintf(header
, "\n");
1519 end_cplusplus_guard(header
);
1520 fprintf(header
, "#endif /* __%s__ */\n", header_token
);