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
40 static int indentation
= 0;
41 user_type_list_t user_type_list
= LIST_INIT(user_type_list
);
42 static context_handle_list_t context_handle_list
= LIST_INIT(context_handle_list
);
44 static void indent(FILE *h
, int delta
)
47 if (delta
< 0) indentation
+= delta
;
48 for (c
=0; c
<indentation
; c
++) fprintf(h
, " ");
49 if (delta
> 0) indentation
+= delta
;
52 int is_ptrchain_attr(const var_t
*var
, enum attr_type t
)
54 if (is_attr(var
->attrs
, t
))
58 type_t
*type
= var
->type
;
61 if (is_attr(type
->attrs
, t
))
63 else if (type
->kind
== TKIND_ALIAS
)
65 else if (is_ptr(type
))
72 int is_attr(const attr_list_t
*list
, enum attr_type t
)
75 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
76 if (attr
->type
== t
) return 1;
80 void *get_attrp(const attr_list_t
*list
, enum attr_type t
)
83 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
84 if (attr
->type
== t
) return attr
->u
.pval
;
88 unsigned long get_attrv(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 attr
->u
.ival
;
96 int is_void(const type_t
*t
)
98 if (!t
->type
&& !t
->ref
) return 1;
102 int is_conformant_array(const type_t
*t
)
104 return t
->type
== RPC_FC_CARRAY
|| t
->type
== RPC_FC_CVARRAY
;
107 void write_guid(FILE *f
, const char *guid_prefix
, const char *name
, const UUID
*uuid
)
110 fprintf(f
, "DEFINE_GUID(%s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
111 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
112 guid_prefix
, name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0],
113 uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5],
114 uuid
->Data4
[6], uuid
->Data4
[7]);
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 static void write_field(FILE *h
, var_t
*v
)
138 const char *name
= v
->name
;
140 switch (v
->type
->type
) {
142 case RPC_FC_CVSTRUCT
:
143 case RPC_FC_CPSTRUCT
:
146 case RPC_FC_BOGUS_STRUCT
:
147 case RPC_FC_ENCAPSULATED_UNION
:
148 name
= "DUMMYSTRUCTNAME";
150 case RPC_FC_NON_ENCAPSULATED_UNION
:
151 name
= "DUMMYUNIONNAME";
159 write_type(h
, v
->type
, TRUE
, "%s", name
);
164 static void write_fields(FILE *h
, var_list_t
*fields
)
168 LIST_FOR_EACH_ENTRY( v
, fields
, var_t
, entry
) write_field(h
, v
);
171 static void write_enums(FILE *h
, var_list_t
*enums
)
175 LIST_FOR_EACH_ENTRY( v
, enums
, var_t
, entry
)
182 write_expr(h
, v
->eval
, 0);
185 if (list_next( enums
, &v
->entry
)) fprintf(h
, ",\n");
190 int needs_space_after(type_t
*t
)
192 return (t
->kind
== TKIND_ALIAS
193 || (!is_ptr(t
) && (!is_conformant_array(t
) || t
->declarray
)));
196 void write_type_left(FILE *h
, type_t
*t
)
198 if (t
->is_const
) fprintf(h
, "const ");
200 if (t
->kind
== TKIND_ALIAS
) fprintf(h
, "%s", t
->name
);
201 else if (t
->declarray
) write_type_left(h
, t
->ref
);
203 if (t
->sign
> 0) fprintf(h
, "signed ");
204 else if (t
->sign
< 0) fprintf(h
, "unsigned ");
208 if (t
->defined
&& !t
->written
&& !t
->ignore
) {
209 if (t
->name
) fprintf(h
, "enum %s {\n", t
->name
);
210 else fprintf(h
, "enum {\n");
213 write_enums(h
, t
->fields
);
217 else fprintf(h
, "enum %s", t
->name
);
220 case RPC_FC_CVSTRUCT
:
221 case RPC_FC_CPSTRUCT
:
224 case RPC_FC_BOGUS_STRUCT
:
225 case RPC_FC_ENCAPSULATED_UNION
:
226 if (t
->defined
&& !t
->written
&& !t
->ignore
) {
227 if (t
->name
) fprintf(h
, "struct %s {\n", t
->name
);
228 else fprintf(h
, "struct {\n");
231 write_fields(h
, t
->fields
);
235 else fprintf(h
, "struct %s", t
->name
);
237 case RPC_FC_NON_ENCAPSULATED_UNION
:
238 if (t
->defined
&& !t
->written
&& !t
->ignore
) {
239 if (t
->name
) fprintf(h
, "union %s {\n", t
->name
);
240 else fprintf(h
, "union {\n");
243 write_fields(h
, t
->fields
);
247 else fprintf(h
, "union %s", t
->name
);
255 case RPC_FC_BOGUS_ARRAY
:
256 write_type_left(h
, t
->ref
);
257 fprintf(h
, "%s*", needs_space_after(t
->ref
) ? " " : "");
260 fprintf(h
, "%s", t
->name
);
265 void write_type_right(FILE *h
, type_t
*t
, int is_field
)
268 if (is_conformant_array(t
)) {
269 fprintf(h
, "[%s]", is_field
? "1" : "");
272 for ( ; t
->declarray
; t
= t
->ref
)
273 fprintf(h
, "[%lu]", t
->dim
);
277 void write_type(FILE *h
, type_t
*t
, int is_field
, const char *fmt
, ...)
279 write_type_left(h
, t
);
283 if (needs_space_after(t
))
285 vfprintf(h
, fmt
, args
);
288 write_type_right(h
, t
, is_field
);
291 static int user_type_registered(const char *name
)
294 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
295 if (!strcmp(name
, ut
->name
))
300 static int context_handle_registered(const char *name
)
302 context_handle_t
*ch
;
303 LIST_FOR_EACH_ENTRY(ch
, &context_handle_list
, context_handle_t
, entry
)
304 if (!strcmp(name
, ch
->name
))
309 void check_for_user_types_and_context_handles(const var_list_t
*list
)
314 LIST_FOR_EACH_ENTRY( v
, list
, const var_t
, entry
)
317 for (type
= v
->type
; type
; type
= type
->kind
== TKIND_ALIAS
? type
->orig
: type
->ref
) {
318 const char *name
= type
->name
;
319 if (type
->user_types_registered
) continue;
320 type
->user_types_registered
= 1;
321 if (is_attr(type
->attrs
, ATTR_CONTEXTHANDLE
)) {
322 if (!context_handle_registered(name
))
324 context_handle_t
*ch
= xmalloc(sizeof(*ch
));
325 ch
->name
= xstrdup(name
);
326 list_add_tail(&context_handle_list
, &ch
->entry
);
328 /* don't carry on parsing fields within this type */
331 if (is_attr(type
->attrs
, ATTR_WIREMARSHAL
)) {
332 if (!user_type_registered(name
))
334 user_type_t
*ut
= xmalloc(sizeof *ut
);
335 ut
->name
= xstrdup(name
);
336 list_add_tail(&user_type_list
, &ut
->entry
);
338 /* don't carry on parsing fields within this type as we are already
339 * using a wire marshaled type */
344 check_for_user_types_and_context_handles(type
->fields
);
350 void write_user_types(void)
353 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
355 const char *name
= ut
->name
;
356 fprintf(header
, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name
, name
);
357 fprintf(header
, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name
, name
);
358 fprintf(header
, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name
, name
);
359 fprintf(header
, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name
, name
);
363 void write_context_handle_rundowns(void)
365 context_handle_t
*ch
;
366 LIST_FOR_EACH_ENTRY(ch
, &context_handle_list
, context_handle_t
, entry
)
368 const char *name
= ch
->name
;
369 fprintf(header
, "void __RPC_USER %s_rundown(%s);\n", name
, name
);
373 void write_typedef(type_t
*type
)
375 fprintf(header
, "typedef ");
376 write_type(header
, type
->orig
, FALSE
, "%s", type
->name
);
377 fprintf(header
, ";\n");
380 void write_expr(FILE *h
, const expr_t
*e
, int brackets
)
386 fprintf(h
, "%lu", e
->u
.lval
);
389 fprintf(h
, "0x%lx", e
->u
.lval
);
392 fprintf(h
, "%#.15g", e
->u
.dval
);
400 case EXPR_IDENTIFIER
:
401 fprintf(h
, "%s", e
->u
.sval
);
405 write_expr(h
, e
->ref
, 1);
409 write_expr(h
, e
->ref
, 1);
413 write_expr(h
, e
->ref
, 1);
417 write_type(h
, e
->u
.tref
, FALSE
, NULL
);
419 write_expr(h
, e
->ref
, 1);
422 fprintf(h
, "sizeof(");
423 write_type(h
, e
->u
.tref
, FALSE
, NULL
);
434 if (brackets
) fprintf(h
, "(");
435 write_expr(h
, e
->ref
, 1);
437 case EXPR_SHL
: fprintf(h
, " << "); break;
438 case EXPR_SHR
: fprintf(h
, " >> "); break;
439 case EXPR_MUL
: fprintf(h
, " * "); break;
440 case EXPR_DIV
: fprintf(h
, " / "); break;
441 case EXPR_ADD
: fprintf(h
, " + "); break;
442 case EXPR_SUB
: fprintf(h
, " - "); break;
443 case EXPR_AND
: fprintf(h
, " & "); break;
444 case EXPR_OR
: fprintf(h
, " | "); break;
447 write_expr(h
, e
->u
.ext
, 1);
448 if (brackets
) fprintf(h
, ")");
451 if (brackets
) fprintf(h
, "(");
452 write_expr(h
, e
->ref
, 1);
454 write_expr(h
, e
->u
.ext
, 1);
456 write_expr(h
, e
->ext2
, 1);
457 if (brackets
) fprintf(h
, ")");
462 void write_constdef(const var_t
*v
)
464 fprintf(header
, "#define %s (", v
->name
);
465 write_expr(header
, v
->eval
, 0);
466 fprintf(header
, ")\n\n");
469 void write_externdef(const var_t
*v
)
471 fprintf(header
, "extern const ");
472 write_type(header
, v
->type
, FALSE
, "%s", v
->name
);
473 fprintf(header
, ";\n\n");
476 void write_library(const char *name
, const attr_list_t
*attr
)
478 const UUID
*uuid
= get_attrp(attr
, ATTR_UUID
);
479 fprintf(header
, "\n");
480 write_guid(header
, "LIBID", name
, uuid
);
481 fprintf(header
, "\n");
485 const var_t
* get_explicit_handle_var(const func_t
* func
)
492 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
493 if (var
->type
->type
== RPC_FC_BIND_PRIMITIVE
)
499 int has_out_arg_or_return(const func_t
*func
)
503 if (!is_void(func
->def
->type
))
509 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
510 if (is_attr(var
->attrs
, ATTR_OUT
))
517 /********** INTERFACES **********/
519 int is_object(const attr_list_t
*list
)
522 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
523 if (attr
->type
== ATTR_OBJECT
|| attr
->type
== ATTR_ODL
) return 1;
527 int is_local(const attr_list_t
*a
)
529 return is_attr(a
, ATTR_LOCAL
);
532 const var_t
*is_callas(const attr_list_t
*a
)
534 return get_attrp(a
, ATTR_CALLAS
);
537 static void write_method_macro(const type_t
*iface
, const char *name
)
541 if (iface
->ref
) write_method_macro(iface
->ref
, name
);
543 if (!iface
->funcs
) return;
545 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
546 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
548 var_t
*def
= cur
->def
;
549 if (!is_callas(def
->attrs
)) {
554 if (cur
->args
) LIST_FOR_EACH_ENTRY( arg
, cur
->args
, const var_t
, entry
) argc
++;
556 fprintf(header
, "#define %s_", name
);
557 write_name(header
,def
);
558 fprintf(header
, "(p");
559 for (c
=0; c
<argc
; c
++)
560 fprintf(header
, ",%c", c
+'a');
561 fprintf(header
, ") ");
563 fprintf(header
, "(p)->lpVtbl->");
564 write_name(header
, def
);
565 fprintf(header
, "(p");
566 for (c
=0; c
<argc
; c
++)
567 fprintf(header
, ",%c", c
+'a');
568 fprintf(header
, ")\n");
573 void write_args(FILE *h
, const var_list_t
*args
, const char *name
, int method
, int do_indent
)
584 fprintf(h
, "%s* This", name
);
587 if (args
) LIST_FOR_EACH_ENTRY( arg
, args
, const var_t
, entry
) {
594 else fprintf(h
, ",");
598 write_type_left(h
, arg
->type
);
599 fprintf(h
, " (STDMETHODCALLTYPE *");
602 write_args(h
, arg
->args
, NULL
, 0, FALSE
);
606 write_type(h
, arg
->type
, FALSE
, "%s", arg
->name
);
609 if (do_indent
) indentation
--;
612 static void write_cpp_method_def(const type_t
*iface
)
616 if (!iface
->funcs
) return;
618 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
620 var_t
*def
= cur
->def
;
621 if (!is_callas(def
->attrs
)) {
623 fprintf(header
, "virtual ");
624 write_type_left(header
, def
->type
);
625 fprintf(header
, " STDMETHODCALLTYPE ");
626 write_name(header
, def
);
627 fprintf(header
, "(\n");
628 write_args(header
, cur
->args
, iface
->name
, 2, TRUE
);
629 fprintf(header
, ") = 0;\n");
630 fprintf(header
, "\n");
635 static void do_write_c_method_def(const type_t
*iface
, const char *name
)
639 if (iface
->ref
) do_write_c_method_def(iface
->ref
, name
);
641 if (!iface
->funcs
) return;
643 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
644 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
646 const var_t
*def
= cur
->def
;
647 if (!is_callas(def
->attrs
)) {
649 write_type_left(header
, def
->type
);
650 fprintf(header
, " (STDMETHODCALLTYPE *");
651 write_name(header
, def
);
652 fprintf(header
, ")(\n");
653 write_args(header
, cur
->args
, name
, 1, TRUE
);
654 fprintf(header
, ");\n");
655 fprintf(header
, "\n");
660 static void write_c_method_def(const type_t
*iface
)
662 do_write_c_method_def(iface
, iface
->name
);
665 static void write_c_disp_method_def(const type_t
*iface
)
667 do_write_c_method_def(iface
->ref
, iface
->name
);
670 static void write_method_proto(const type_t
*iface
)
674 if (!iface
->funcs
) return;
675 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
677 const var_t
*def
= cur
->def
;
678 const var_t
*cas
= is_callas(def
->attrs
);
680 if (!is_local(def
->attrs
)) {
681 /* proxy prototype */
682 write_type_left(header
, def
->type
);
683 fprintf(header
, " CALLBACK %s_", iface
->name
);
684 write_name(header
, def
);
685 fprintf(header
, "_Proxy(\n");
686 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
687 fprintf(header
, ");\n");
689 fprintf(header
, "void __RPC_STUB %s_", iface
->name
);
690 write_name(header
,def
);
691 fprintf(header
, "_Stub(\n");
692 fprintf(header
, " IRpcStubBuffer* This,\n");
693 fprintf(header
, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
694 fprintf(header
, " PRPC_MESSAGE pRpcMessage,\n");
695 fprintf(header
, " DWORD* pdwStubPhase);\n");
699 LIST_FOR_EACH_ENTRY( m
, iface
->funcs
, const func_t
, entry
)
700 if (!strcmp(m
->def
->name
, cas
->name
)) break;
701 if (&m
->entry
!= iface
->funcs
) {
702 const var_t
*mdef
= m
->def
;
703 /* proxy prototype - use local prototype */
704 write_type_left(header
, mdef
->type
);
705 fprintf(header
, " CALLBACK %s_", iface
->name
);
706 write_name(header
, mdef
);
707 fprintf(header
, "_Proxy(\n");
708 write_args(header
, m
->args
, iface
->name
, 1, TRUE
);
709 fprintf(header
, ");\n");
710 /* stub prototype - use remotable prototype */
711 write_type_left(header
, def
->type
);
712 fprintf(header
, " __RPC_STUB %s_", iface
->name
);
713 write_name(header
, mdef
);
714 fprintf(header
, "_Stub(\n");
715 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
716 fprintf(header
, ");\n");
719 parser_warning("invalid call_as attribute (%s -> %s)\n", def
->name
, cas
->name
);
725 static void write_function_proto(const type_t
*iface
, const func_t
*fun
, const char *prefix
)
727 var_t
*def
= fun
->def
;
729 /* FIXME: do we need to handle call_as? */
730 write_type_left(header
, def
->type
);
731 fprintf(header
, " ");
732 write_prefix_name(header
, prefix
, def
);
733 fprintf(header
, "(\n");
735 write_args(header
, fun
->args
, iface
->name
, 0, TRUE
);
737 fprintf(header
, " void");
738 fprintf(header
, ");\n");
741 static void write_function_protos(const type_t
*iface
)
743 const char *implicit_handle
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
744 int explicit_handle
= is_attr(iface
->attrs
, ATTR_EXPLICIT_HANDLE
);
745 const var_t
* explicit_handle_var
;
747 int prefixes_differ
= strcmp(prefix_client
, prefix_server
);
749 if (!iface
->funcs
) return;
750 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
752 var_t
*def
= cur
->def
;
754 /* check for a defined binding handle */
755 explicit_handle_var
= get_explicit_handle_var(cur
);
756 if (explicit_handle
) {
757 if (!explicit_handle_var
) {
758 error("%s() does not define an explicit binding handle!\n", def
->name
);
761 } else if (implicit_handle
) {
762 if (explicit_handle_var
) {
763 error("%s() must not define a binding handle!\n", def
->name
);
768 if (prefixes_differ
) {
769 fprintf(header
, "/* client prototype */\n");
770 write_function_proto(iface
, cur
, prefix_client
);
771 fprintf(header
, "/* server prototype */\n");
773 write_function_proto(iface
, cur
, prefix_server
);
777 void write_forward(type_t
*iface
)
779 /* C/C++ forwards should only be written for object interfaces, so if we
780 * have a full definition we only write one if we find [object] among the
781 * attributes - however, if we don't have a full definition at this point
782 * (i.e. this is an IDL forward), then we also assume that it is an object
783 * interface, since non-object interfaces shouldn't need forwards */
784 if ((!iface
->defined
|| is_object(iface
->attrs
) || is_attr(iface
->attrs
, ATTR_DISPINTERFACE
))
785 && !iface
->written
) {
786 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", iface
->name
);
787 fprintf(header
, "#define __%s_FWD_DEFINED__\n", iface
->name
);
788 fprintf(header
, "typedef interface %s %s;\n", iface
->name
, iface
->name
);
789 fprintf(header
, "#endif\n\n" );
790 iface
->written
= TRUE
;
794 static void write_iface_guid(const type_t
*iface
)
796 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
797 write_guid(header
, "IID", iface
->name
, uuid
);
800 static void write_dispiface_guid(const type_t
*iface
)
802 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
803 write_guid(header
, "DIID", iface
->name
, uuid
);
806 static void write_coclass_guid(type_t
*cocl
)
808 const UUID
*uuid
= get_attrp(cocl
->attrs
, ATTR_UUID
);
809 write_guid(header
, "CLSID", cocl
->name
, uuid
);
812 static void write_com_interface(type_t
*iface
)
814 if (!iface
->funcs
&& !iface
->ref
) {
815 parser_warning("%s has no methods", iface
->name
);
819 fprintf(header
, "/*****************************************************************************\n");
820 fprintf(header
, " * %s interface\n", iface
->name
);
821 fprintf(header
, " */\n");
822 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
823 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
824 write_iface_guid(iface
);
825 write_forward(iface
);
827 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
830 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
831 fprintf(header
, "{\n");
833 write_cpp_method_def(iface
);
835 fprintf(header
, "};\n");
839 fprintf(header
, "interface %s\n", iface
->name
);
840 fprintf(header
, "{\n");
841 fprintf(header
, " BEGIN_INTERFACE\n");
842 fprintf(header
, "\n");
844 write_cpp_method_def(iface
);
846 fprintf(header
, " END_INTERFACE\n");
847 fprintf(header
, "};\n");
849 fprintf(header
, "#else\n");
851 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
853 fprintf(header
, " BEGIN_INTERFACE\n");
854 fprintf(header
, "\n");
855 write_c_method_def(iface
);
857 fprintf(header
, " END_INTERFACE\n");
858 fprintf(header
, "} %sVtbl;\n", iface
->name
);
859 fprintf(header
, "interface %s {\n", iface
->name
);
860 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
861 fprintf(header
, "};\n");
862 fprintf(header
, "\n");
863 fprintf(header
, "#ifdef COBJMACROS\n");
864 write_method_macro(iface
, iface
->name
);
865 fprintf(header
, "#endif\n");
866 fprintf(header
, "\n");
867 fprintf(header
, "#endif\n");
868 fprintf(header
, "\n");
869 write_method_proto(iface
);
870 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
873 static void write_rpc_interface(const type_t
*iface
)
875 unsigned long ver
= get_attrv(iface
->attrs
, ATTR_VERSION
);
876 const char *var
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
877 static int allocate_written
= 0;
879 if (!allocate_written
)
881 allocate_written
= 1;
882 fprintf(header
, "void * __RPC_USER MIDL_user_allocate(size_t);\n");
883 fprintf(header
, "void __RPC_USER MIDL_user_free(void *);\n\n");
886 fprintf(header
, "/*****************************************************************************\n");
887 fprintf(header
, " * %s interface (v%d.%d)\n", iface
->name
, LOWORD(ver
), HIWORD(ver
));
888 fprintf(header
, " */\n");
889 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
890 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
893 write_iface_guid(iface
);
894 if (var
) fprintf(header
, "extern handle_t %s;\n", var
);
897 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ClientIfHandle;\n", prefix_client
, iface
->name
);
898 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ServerIfHandle;\n", prefix_server
, iface
->name
);
902 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n",
903 prefix_client
, iface
->name
, LOWORD(ver
), HIWORD(ver
));
904 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n",
905 prefix_server
, iface
->name
, LOWORD(ver
), HIWORD(ver
));
907 write_function_protos(iface
);
909 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
911 /* FIXME: server/client code */
914 void write_interface(type_t
*iface
)
916 if (is_object(iface
->attrs
))
917 write_com_interface(iface
);
919 write_rpc_interface(iface
);
922 void write_dispinterface(type_t
*iface
)
924 fprintf(header
, "/*****************************************************************************\n");
925 fprintf(header
, " * %s dispinterface\n", iface
->name
);
926 fprintf(header
, " */\n");
927 fprintf(header
,"#ifndef __%s_DISPINTERFACE_DEFINED__\n", iface
->name
);
928 fprintf(header
,"#define __%s_DISPINTERFACE_DEFINED__\n\n", iface
->name
);
929 write_dispiface_guid(iface
);
930 write_forward(iface
);
932 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
933 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
934 fprintf(header
, "{\n");
935 fprintf(header
, "};\n");
936 fprintf(header
, "#else\n");
938 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
940 fprintf(header
, " BEGIN_INTERFACE\n");
941 fprintf(header
, "\n");
942 write_c_disp_method_def(iface
);
944 fprintf(header
, " END_INTERFACE\n");
945 fprintf(header
, "} %sVtbl;\n", iface
->name
);
946 fprintf(header
, "interface %s {\n", iface
->name
);
947 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
948 fprintf(header
, "};\n");
949 fprintf(header
, "\n");
950 fprintf(header
, "#ifdef COBJMACROS\n");
951 write_method_macro(iface
->ref
, iface
->name
);
952 fprintf(header
, "#endif\n");
953 fprintf(header
, "\n");
954 fprintf(header
, "#endif\n");
955 fprintf(header
, "\n");
956 fprintf(header
,"#endif /* __%s_DISPINTERFACE_DEFINED__ */\n\n", iface
->name
);
959 void write_coclass(type_t
*cocl
)
961 fprintf(header
, "/*****************************************************************************\n");
962 fprintf(header
, " * %s coclass\n", cocl
->name
);
963 fprintf(header
, " */\n\n");
964 write_coclass_guid(cocl
);
965 fprintf(header
, "\n");
968 void write_coclass_forward(type_t
*cocl
)
970 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", cocl
->name
);
971 fprintf(header
, "#define __%s_FWD_DEFINED__\n", cocl
->name
);
972 fprintf(header
, "typedef struct %s %s;\n", cocl
->name
, cocl
->name
);
973 fprintf(header
, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl
->name
);