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;
41 static void indent(FILE *h
, int delta
)
44 if (delta
< 0) indentation
+= delta
;
45 for (c
=0; c
<indentation
; c
++) fprintf(h
, " ");
46 if (delta
> 0) indentation
+= delta
;
49 int is_attr(const attr_list_t
*list
, enum attr_type t
)
52 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
53 if (attr
->type
== t
) return 1;
57 void *get_attrp(const attr_list_t
*list
, enum attr_type t
)
60 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
61 if (attr
->type
== t
) return attr
->u
.pval
;
65 unsigned long get_attrv(const attr_list_t
*list
, enum attr_type t
)
68 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
69 if (attr
->type
== t
) return attr
->u
.ival
;
73 int is_void(const type_t
*t
, const var_t
*v
)
75 if (v
&& v
->ptr_level
) return 0;
76 if (!t
->type
&& !t
->ref
) return 1;
80 int is_conformant_array( const array_dims_t
*array
)
84 dim
= LIST_ENTRY( list_head( array
), expr_t
, entry
);
85 return !dim
->is_const
;
88 int is_non_void(const expr_list_t
*list
)
93 LIST_FOR_EACH_ENTRY( expr
, list
, const expr_t
, entry
)
94 if (expr
->type
!= EXPR_VOID
) return 1;
98 void write_guid(FILE *f
, const char *guid_prefix
, const char *name
, const UUID
*uuid
)
101 fprintf(f
, "DEFINE_GUID(%s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
102 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
103 guid_prefix
, name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0],
104 uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5],
105 uuid
->Data4
[6], uuid
->Data4
[7]);
108 static void write_pident(FILE *h
, const var_t
*v
)
111 for (c
=0; c
<v
->ptr_level
; c
++) {
114 if (v
->name
) fprintf(h
, "%s", v
->name
);
117 void write_name(FILE *h
, const var_t
*v
)
119 if (is_attr( v
->attrs
, ATTR_PROPGET
))
121 else if (is_attr( v
->attrs
, ATTR_PROPPUT
))
123 else if (is_attr( v
->attrs
, ATTR_PROPPUTREF
))
124 fprintf(h
, "putref_" );
125 fprintf(h
, "%s", v
->name
);
128 void write_prefix_name(FILE *h
, const char *prefix
, const var_t
*v
)
130 fprintf(h
, "%s", prefix
);
134 const char* get_name(const var_t
*v
)
139 void write_array(FILE *h
, array_dims_t
*dims
, int field
)
145 LIST_FOR_EACH_ENTRY( v
, dims
, expr_t
, entry
)
148 fprintf(h
, "%ld", v
->cval
); /* statically sized array */
150 if (field
) fprintf(h
, "1"); /* dynamically sized array */
151 if (list_next( dims
, &v
->entry
))
157 static void write_field(FILE *h
, var_t
*v
)
162 write_type(h
, v
->type
, NULL
);
168 /* not all C/C++ compilers support anonymous structs and unions */
169 switch (v
->type
->type
) {
171 case RPC_FC_CVSTRUCT
:
172 case RPC_FC_CPSTRUCT
:
175 case RPC_FC_BOGUS_STRUCT
:
176 case RPC_FC_ENCAPSULATED_UNION
:
177 fprintf(h
, " DUMMYSTRUCTNAME");
179 case RPC_FC_NON_ENCAPSULATED_UNION
:
180 fprintf(h
, " DUMMYUNIONNAME");
187 write_array(h
, v
->array
, 1);
192 static void write_fields(FILE *h
, var_list_t
*fields
)
196 LIST_FOR_EACH_ENTRY( v
, fields
, var_t
, entry
) write_field(h
, v
);
199 static void write_enums(FILE *h
, var_list_t
*enums
)
203 LIST_FOR_EACH_ENTRY( v
, enums
, var_t
, entry
)
210 write_expr(h
, v
->eval
, 0);
213 if (list_next( enums
, &v
->entry
)) fprintf(h
, ",\n");
218 static int needs_space_after(type_t
*t
)
220 return t
->kind
== TKIND_ALIAS
|| ! is_ptr(t
);
223 void write_type(FILE *h
, type_t
*t
, const var_t
*v
)
227 if (t
->is_const
) fprintf(h
, "const ");
229 if (t
->kind
== TKIND_ALIAS
) fprintf(h
, "%s", t
->name
);
231 if (t
->sign
> 0) fprintf(h
, "signed ");
232 else if (t
->sign
< 0) fprintf(h
, "unsigned ");
236 if (t
->defined
&& !t
->written
&& !t
->ignore
) {
237 if (t
->name
) fprintf(h
, "enum %s {\n", t
->name
);
238 else fprintf(h
, "enum {\n");
241 write_enums(h
, t
->fields
);
245 else fprintf(h
, "enum %s", t
->name
);
248 case RPC_FC_CVSTRUCT
:
249 case RPC_FC_CPSTRUCT
:
252 case RPC_FC_BOGUS_STRUCT
:
253 case RPC_FC_ENCAPSULATED_UNION
:
254 if (t
->defined
&& !t
->written
&& !t
->ignore
) {
255 if (t
->name
) fprintf(h
, "struct %s {\n", t
->name
);
256 else fprintf(h
, "struct {\n");
259 write_fields(h
, t
->fields
);
263 else fprintf(h
, "struct %s", t
->name
);
265 case RPC_FC_NON_ENCAPSULATED_UNION
:
266 if (t
->defined
&& !t
->written
&& !t
->ignore
) {
267 if (t
->name
) fprintf(h
, "union %s {\n", t
->name
);
268 else fprintf(h
, "union {\n");
271 write_fields(h
, t
->fields
);
275 else fprintf(h
, "union %s", t
->name
);
281 if (t
->ref
) write_type(h
, t
->ref
, NULL
);
282 fprintf(h
, "%s*", needs_space_after(t
->ref
) ? " " : "");
285 fprintf(h
, "%s", t
->name
);
289 for (c
=0; c
<v
->ptr_level
; c
++) {
298 struct user_type
*next
;
302 static struct user_type
*user_type_list
;
304 static int user_type_registered(const char *name
)
306 struct user_type
*ut
;
307 for (ut
= user_type_list
; ut
; ut
= ut
->next
)
308 if (!strcmp(name
, ut
->name
))
313 static void check_for_user_types(const var_list_t
*list
)
318 LIST_FOR_EACH_ENTRY( v
, list
, const var_t
, entry
)
321 for (type
= v
->type
; type
; type
= type
->kind
== TKIND_ALIAS
? type
->orig
: type
->ref
) {
322 const char *name
= type
->name
;
323 if (type
->user_types_registered
) continue;
324 type
->user_types_registered
= 1;
325 if (is_attr(type
->attrs
, ATTR_WIREMARSHAL
)) {
326 if (!user_type_registered(name
))
328 struct user_type
*ut
= xmalloc(sizeof(struct user_type
) + strlen(name
));
329 strcpy(ut
->name
, name
);
330 ut
->next
= user_type_list
;
333 /* don't carry on parsing fields within this type as we are already
334 * using a wire marshaled type */
339 check_for_user_types(type
->fields
);
345 void write_user_types(void)
347 struct user_type
*ut
;
348 for (ut
= user_type_list
; ut
; ut
= ut
->next
)
350 const char *name
= ut
->name
;
351 fprintf(header
, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name
, name
);
352 fprintf(header
, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name
, name
);
353 fprintf(header
, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name
, name
);
354 fprintf(header
, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name
, name
);
358 void write_typedef(type_t
*type
)
360 fprintf(header
, "typedef ");
361 write_type(header
, type
->orig
, NULL
);
362 fprintf(header
, "%s%s;\n", needs_space_after(type
->orig
) ? " " : "", type
->name
);
365 void write_expr(FILE *h
, const expr_t
*e
, int brackets
)
371 fprintf(h
, "%lu", e
->u
.lval
);
374 fprintf(h
, "0x%lx", e
->u
.lval
);
382 case EXPR_IDENTIFIER
:
383 fprintf(h
, "%s", e
->u
.sval
);
387 write_expr(h
, e
->ref
, 1);
391 write_expr(h
, e
->ref
, 1);
395 write_expr(h
, e
->ref
, 1);
399 write_type(h
, e
->u
.tref
, NULL
);
401 write_expr(h
, e
->ref
, 1);
404 fprintf(h
, "sizeof(");
405 write_type(h
, e
->u
.tref
, NULL
);
416 if (brackets
) fprintf(h
, "(");
417 write_expr(h
, e
->ref
, 1);
419 case EXPR_SHL
: fprintf(h
, " << "); break;
420 case EXPR_SHR
: fprintf(h
, " >> "); break;
421 case EXPR_MUL
: fprintf(h
, " * "); break;
422 case EXPR_DIV
: fprintf(h
, " / "); break;
423 case EXPR_ADD
: fprintf(h
, " + "); break;
424 case EXPR_SUB
: fprintf(h
, " - "); break;
425 case EXPR_AND
: fprintf(h
, " & "); break;
426 case EXPR_OR
: fprintf(h
, " | "); break;
429 write_expr(h
, e
->u
.ext
, 1);
430 if (brackets
) fprintf(h
, ")");
433 if (brackets
) fprintf(h
, "(");
434 write_expr(h
, e
->ref
, 1);
436 write_expr(h
, e
->u
.ext
, 1);
438 write_expr(h
, e
->ext2
, 1);
439 if (brackets
) fprintf(h
, ")");
444 void write_constdef(const var_t
*v
)
446 fprintf(header
, "#define %s (", get_name(v
));
447 write_expr(header
, v
->eval
, 0);
448 fprintf(header
, ")\n\n");
451 void write_externdef(const var_t
*v
)
453 fprintf(header
, "extern const ");
454 write_type(header
, v
->type
, NULL
);
456 fprintf(header
, " ");
457 write_pident(header
, v
);
459 fprintf(header
, ";\n\n");
462 void write_library(const char *name
, const attr_list_t
*attr
)
464 const UUID
*uuid
= get_attrp(attr
, ATTR_UUID
);
465 fprintf(header
, "\n");
466 write_guid(header
, "LIBID", name
, uuid
);
467 fprintf(header
, "\n");
471 const var_t
* get_explicit_handle_var(const func_t
* func
)
478 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
479 if (var
->type
->type
== RPC_FC_BIND_PRIMITIVE
)
485 int has_out_arg_or_return(const func_t
*func
)
489 if (!is_void(func
->def
->type
, NULL
))
495 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
496 if (is_attr(var
->attrs
, ATTR_OUT
))
503 /********** INTERFACES **********/
505 int is_object(const attr_list_t
*list
)
508 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
509 if (attr
->type
== ATTR_OBJECT
|| attr
->type
== ATTR_ODL
) return 1;
513 int is_local(const attr_list_t
*a
)
515 return is_attr(a
, ATTR_LOCAL
);
518 const var_t
*is_callas(const attr_list_t
*a
)
520 return get_attrp(a
, ATTR_CALLAS
);
523 static void write_method_macro(const type_t
*iface
, const char *name
)
527 if (iface
->ref
) write_method_macro(iface
->ref
, name
);
529 if (!iface
->funcs
) return;
531 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
532 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
534 var_t
*def
= cur
->def
;
535 if (!is_callas(def
->attrs
)) {
540 if (cur
->args
) LIST_FOR_EACH_ENTRY( arg
, cur
->args
, const var_t
, entry
) argc
++;
542 fprintf(header
, "#define %s_", name
);
543 write_name(header
,def
);
544 fprintf(header
, "(p");
545 for (c
=0; c
<argc
; c
++)
546 fprintf(header
, ",%c", c
+'a');
547 fprintf(header
, ") ");
549 fprintf(header
, "(p)->lpVtbl->");
550 write_name(header
, def
);
551 fprintf(header
, "(p");
552 for (c
=0; c
<argc
; c
++)
553 fprintf(header
, ",%c", c
+'a');
554 fprintf(header
, ")\n");
559 void write_args(FILE *h
, const var_list_t
*args
, const char *name
, int method
, int do_indent
)
570 fprintf(h
, "%s* This", name
);
573 if (args
) LIST_FOR_EACH_ENTRY( arg
, args
, const var_t
, entry
) {
580 else fprintf(h
, ",");
582 write_type(h
, arg
->type
, arg
);
585 fprintf(h
, " (STDMETHODCALLTYPE *");
588 write_args(h
, arg
->args
, NULL
, 0, FALSE
);
593 if (needs_space_after(arg
->type
))
597 write_array(h
, arg
->array
, 0);
600 if (do_indent
) indentation
--;
603 static void write_cpp_method_def(const type_t
*iface
)
607 if (!iface
->funcs
) return;
609 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
611 var_t
*def
= cur
->def
;
612 if (!is_callas(def
->attrs
)) {
614 fprintf(header
, "virtual ");
615 write_type(header
, def
->type
, def
);
616 fprintf(header
, " STDMETHODCALLTYPE ");
617 write_name(header
, def
);
618 fprintf(header
, "(\n");
619 write_args(header
, cur
->args
, iface
->name
, 2, TRUE
);
620 fprintf(header
, ") = 0;\n");
621 fprintf(header
, "\n");
626 static void do_write_c_method_def(const type_t
*iface
, const char *name
)
630 if (iface
->ref
) do_write_c_method_def(iface
->ref
, name
);
632 if (!iface
->funcs
) return;
634 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
635 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
637 const var_t
*def
= cur
->def
;
638 if (!is_callas(def
->attrs
)) {
640 write_type(header
, def
->type
, def
);
641 fprintf(header
, " (STDMETHODCALLTYPE *");
642 write_name(header
, def
);
643 fprintf(header
, ")(\n");
644 write_args(header
, cur
->args
, name
, 1, TRUE
);
645 fprintf(header
, ");\n");
646 fprintf(header
, "\n");
651 static void write_c_method_def(const type_t
*iface
)
653 do_write_c_method_def(iface
, iface
->name
);
656 static void write_c_disp_method_def(const type_t
*iface
)
658 do_write_c_method_def(iface
->ref
, iface
->name
);
661 static void write_method_proto(const type_t
*iface
)
665 if (!iface
->funcs
) return;
666 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
668 const var_t
*def
= cur
->def
;
669 const var_t
*cas
= is_callas(def
->attrs
);
671 if (!is_local(def
->attrs
)) {
672 /* proxy prototype */
673 write_type(header
, def
->type
, def
);
674 fprintf(header
, " CALLBACK %s_", iface
->name
);
675 write_name(header
, def
);
676 fprintf(header
, "_Proxy(\n");
677 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
678 fprintf(header
, ");\n");
680 fprintf(header
, "void __RPC_STUB %s_", iface
->name
);
681 write_name(header
,def
);
682 fprintf(header
, "_Stub(\n");
683 fprintf(header
, " IRpcStubBuffer* This,\n");
684 fprintf(header
, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
685 fprintf(header
, " PRPC_MESSAGE pRpcMessage,\n");
686 fprintf(header
, " DWORD* pdwStubPhase);\n");
687 check_for_user_types(cur
->args
);
691 LIST_FOR_EACH_ENTRY( m
, iface
->funcs
, const func_t
, entry
)
692 if (!strcmp(get_name(m
->def
), cas
->name
)) break;
693 if (&m
->entry
!= iface
->funcs
) {
694 const var_t
*mdef
= m
->def
;
695 /* proxy prototype - use local prototype */
696 write_type(header
, mdef
->type
, mdef
);
697 fprintf(header
, " CALLBACK %s_", iface
->name
);
698 write_name(header
, mdef
);
699 fprintf(header
, "_Proxy(\n");
700 write_args(header
, m
->args
, iface
->name
, 1, TRUE
);
701 fprintf(header
, ");\n");
702 /* stub prototype - use remotable prototype */
703 write_type(header
, def
->type
, def
);
704 fprintf(header
, " __RPC_STUB %s_", iface
->name
);
705 write_name(header
, mdef
);
706 fprintf(header
, "_Stub(\n");
707 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
708 fprintf(header
, ");\n");
711 parser_warning("invalid call_as attribute (%s -> %s)\n", get_name(def
), cas
->name
);
717 static void write_function_proto(const type_t
*iface
, const func_t
*fun
, const char *prefix
)
719 var_t
*def
= fun
->def
;
721 /* FIXME: do we need to handle call_as? */
722 write_type(header
, def
->type
, def
);
723 fprintf(header
, " ");
724 write_prefix_name(header
, prefix
, def
);
725 fprintf(header
, "(\n");
727 write_args(header
, fun
->args
, iface
->name
, 0, TRUE
);
729 fprintf(header
, " void");
730 fprintf(header
, ");\n");
733 static void write_function_protos(const type_t
*iface
)
735 const char *implicit_handle
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
736 int explicit_handle
= is_attr(iface
->attrs
, ATTR_EXPLICIT_HANDLE
);
737 const var_t
* explicit_handle_var
;
739 int prefixes_differ
= strcmp(prefix_client
, prefix_server
);
741 if (!iface
->funcs
) return;
742 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
744 var_t
*def
= cur
->def
;
746 /* check for a defined binding handle */
747 explicit_handle_var
= get_explicit_handle_var(cur
);
748 if (explicit_handle
) {
749 if (!explicit_handle_var
) {
750 error("%s() does not define an explicit binding handle!\n", def
->name
);
753 } else if (implicit_handle
) {
754 if (explicit_handle_var
) {
755 error("%s() must not define a binding handle!\n", def
->name
);
760 if (prefixes_differ
) {
761 fprintf(header
, "/* client prototype */\n");
762 write_function_proto(iface
, cur
, prefix_client
);
763 fprintf(header
, "/* server prototype */\n");
765 write_function_proto(iface
, cur
, prefix_server
);
769 void write_forward(type_t
*iface
)
771 /* C/C++ forwards should only be written for object interfaces, so if we
772 * have a full definition we only write one if we find [object] among the
773 * attributes - however, if we don't have a full definition at this point
774 * (i.e. this is an IDL forward), then we also assume that it is an object
775 * interface, since non-object interfaces shouldn't need forwards */
776 if ((!iface
->defined
|| is_object(iface
->attrs
) || is_attr(iface
->attrs
, ATTR_DISPINTERFACE
))
777 && !iface
->written
) {
778 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", iface
->name
);
779 fprintf(header
, "#define __%s_FWD_DEFINED__\n", iface
->name
);
780 fprintf(header
, "typedef interface %s %s;\n", iface
->name
, iface
->name
);
781 fprintf(header
, "#endif\n\n" );
782 iface
->written
= TRUE
;
786 static void write_iface_guid(const type_t
*iface
)
788 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
789 write_guid(header
, "IID", iface
->name
, uuid
);
792 static void write_dispiface_guid(const type_t
*iface
)
794 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
795 write_guid(header
, "DIID", iface
->name
, uuid
);
798 static void write_coclass_guid(type_t
*cocl
)
800 const UUID
*uuid
= get_attrp(cocl
->attrs
, ATTR_UUID
);
801 write_guid(header
, "CLSID", cocl
->name
, uuid
);
804 static void write_com_interface(type_t
*iface
)
806 if (!iface
->funcs
&& !iface
->ref
) {
807 parser_warning("%s has no methods", iface
->name
);
811 fprintf(header
, "/*****************************************************************************\n");
812 fprintf(header
, " * %s interface\n", iface
->name
);
813 fprintf(header
, " */\n");
814 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
815 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
816 write_iface_guid(iface
);
817 write_forward(iface
);
819 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
822 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
823 fprintf(header
, "{\n");
825 write_cpp_method_def(iface
);
827 fprintf(header
, "};\n");
831 fprintf(header
, "interface %s\n", iface
->name
);
832 fprintf(header
, "{\n");
833 fprintf(header
, " BEGIN_INTERFACE\n");
834 fprintf(header
, "\n");
836 write_cpp_method_def(iface
);
838 fprintf(header
, " END_INTERFACE\n");
839 fprintf(header
, "};\n");
841 fprintf(header
, "#else\n");
843 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
845 fprintf(header
, " BEGIN_INTERFACE\n");
846 fprintf(header
, "\n");
847 write_c_method_def(iface
);
849 fprintf(header
, " END_INTERFACE\n");
850 fprintf(header
, "} %sVtbl;\n", iface
->name
);
851 fprintf(header
, "interface %s {\n", iface
->name
);
852 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
853 fprintf(header
, "};\n");
854 fprintf(header
, "\n");
855 fprintf(header
, "#ifdef COBJMACROS\n");
856 write_method_macro(iface
, iface
->name
);
857 fprintf(header
, "#endif\n");
858 fprintf(header
, "\n");
859 fprintf(header
, "#endif\n");
860 fprintf(header
, "\n");
861 write_method_proto(iface
);
862 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
865 static void write_rpc_interface(const type_t
*iface
)
867 unsigned long ver
= get_attrv(iface
->attrs
, ATTR_VERSION
);
868 const char *var
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
869 static int allocate_written
= 0;
871 if (!allocate_written
)
873 allocate_written
= 1;
874 fprintf(header
, "void * __RPC_USER MIDL_user_allocate(size_t);\n");
875 fprintf(header
, "void __RPC_USER MIDL_user_free(void *);\n\n");
878 fprintf(header
, "/*****************************************************************************\n");
879 fprintf(header
, " * %s interface (v%d.%d)\n", iface
->name
, LOWORD(ver
), HIWORD(ver
));
880 fprintf(header
, " */\n");
881 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
882 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
885 write_iface_guid(iface
);
886 if (var
) fprintf(header
, "extern handle_t %s;\n", var
);
889 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ClientIfHandle;\n", prefix_client
, iface
->name
);
890 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ServerIfHandle;\n", prefix_server
, iface
->name
);
894 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n",
895 prefix_client
, iface
->name
, LOWORD(ver
), HIWORD(ver
));
896 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n",
897 prefix_server
, iface
->name
, LOWORD(ver
), HIWORD(ver
));
899 write_function_protos(iface
);
901 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
903 /* FIXME: server/client code */
906 void write_interface(type_t
*iface
)
908 if (is_object(iface
->attrs
))
909 write_com_interface(iface
);
911 write_rpc_interface(iface
);
914 void write_dispinterface(type_t
*iface
)
916 fprintf(header
, "/*****************************************************************************\n");
917 fprintf(header
, " * %s dispinterface\n", iface
->name
);
918 fprintf(header
, " */\n");
919 fprintf(header
,"#ifndef __%s_DISPINTERFACE_DEFINED__\n", iface
->name
);
920 fprintf(header
,"#define __%s_DISPINTERFACE_DEFINED__\n\n", iface
->name
);
921 write_dispiface_guid(iface
);
922 write_forward(iface
);
924 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
925 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
926 fprintf(header
, "{\n");
927 fprintf(header
, "};\n");
928 fprintf(header
, "#else\n");
930 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
932 fprintf(header
, " BEGIN_INTERFACE\n");
933 fprintf(header
, "\n");
934 write_c_disp_method_def(iface
);
936 fprintf(header
, " END_INTERFACE\n");
937 fprintf(header
, "} %sVtbl;\n", iface
->name
);
938 fprintf(header
, "interface %s {\n", iface
->name
);
939 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
940 fprintf(header
, "};\n");
941 fprintf(header
, "\n");
942 fprintf(header
, "#ifdef COBJMACROS\n");
943 write_method_macro(iface
->ref
, iface
->name
);
944 fprintf(header
, "#endif\n");
945 fprintf(header
, "\n");
946 fprintf(header
, "#endif\n");
947 fprintf(header
, "\n");
948 fprintf(header
,"#endif /* __%s_DISPINTERFACE_DEFINED__ */\n\n", iface
->name
);
951 void write_coclass(type_t
*cocl
)
953 fprintf(header
, "/*****************************************************************************\n");
954 fprintf(header
, " * %s coclass\n", cocl
->name
);
955 fprintf(header
, " */\n\n");
956 write_coclass_guid(cocl
);
957 fprintf(header
, "\n");
960 void write_coclass_forward(type_t
*cocl
)
962 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", cocl
->name
);
963 fprintf(header
, "#define __%s_FWD_DEFINED__\n", cocl
->name
);
964 fprintf(header
, "typedef struct %s %s;\n", cocl
->name
, cocl
->name
);
965 fprintf(header
, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl
->name
);