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_ptrchain_attr(const var_t
*var
, enum attr_type t
)
51 if (is_attr(var
->attrs
, t
))
55 type_t
*type
= var
->type
;
58 if (is_attr(type
->attrs
, t
))
60 else if (type
->kind
== TKIND_ALIAS
)
62 else if (is_ptr(type
))
69 int is_attr(const attr_list_t
*list
, enum attr_type t
)
72 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
73 if (attr
->type
== t
) return 1;
77 void *get_attrp(const attr_list_t
*list
, enum attr_type t
)
80 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
81 if (attr
->type
== t
) return attr
->u
.pval
;
85 unsigned long get_attrv(const attr_list_t
*list
, enum attr_type t
)
88 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
89 if (attr
->type
== t
) return attr
->u
.ival
;
93 int is_void(const type_t
*t
)
95 if (!t
->type
&& !t
->ref
) return 1;
99 int is_conformant_array( const array_dims_t
*array
)
102 if (!array
) return 0;
103 dim
= LIST_ENTRY( list_head( array
), expr_t
, entry
);
104 return !dim
->is_const
;
107 int is_non_void(const expr_list_t
*list
)
112 LIST_FOR_EACH_ENTRY( expr
, list
, const expr_t
, entry
)
113 if (expr
->type
!= EXPR_VOID
) return 1;
117 void write_guid(FILE *f
, const char *guid_prefix
, const char *name
, const UUID
*uuid
)
120 fprintf(f
, "DEFINE_GUID(%s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
121 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
122 guid_prefix
, name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0],
123 uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5],
124 uuid
->Data4
[6], uuid
->Data4
[7]);
127 void write_name(FILE *h
, const var_t
*v
)
129 if (is_attr( v
->attrs
, ATTR_PROPGET
))
131 else if (is_attr( v
->attrs
, ATTR_PROPPUT
))
133 else if (is_attr( v
->attrs
, ATTR_PROPPUTREF
))
134 fprintf(h
, "putref_" );
135 fprintf(h
, "%s", v
->name
);
138 void write_prefix_name(FILE *h
, const char *prefix
, const var_t
*v
)
140 fprintf(h
, "%s", prefix
);
144 const char* get_name(const var_t
*v
)
149 void write_array(FILE *h
, array_dims_t
*dims
, int field
)
155 LIST_FOR_EACH_ENTRY( v
, dims
, expr_t
, entry
)
158 fprintf(h
, "%ld", v
->cval
); /* statically sized array */
160 if (field
) fprintf(h
, "1"); /* dynamically sized array */
161 if (list_next( dims
, &v
->entry
))
167 static void write_field(FILE *h
, var_t
*v
)
172 write_type(h
, v
->type
);
174 fprintf(h
, " %s", v
->name
);
176 /* not all C/C++ compilers support anonymous structs and unions */
177 switch (v
->type
->type
) {
179 case RPC_FC_CVSTRUCT
:
180 case RPC_FC_CPSTRUCT
:
183 case RPC_FC_BOGUS_STRUCT
:
184 case RPC_FC_ENCAPSULATED_UNION
:
185 fprintf(h
, " DUMMYSTRUCTNAME");
187 case RPC_FC_NON_ENCAPSULATED_UNION
:
188 fprintf(h
, " DUMMYUNIONNAME");
195 write_array(h
, v
->array
, 1);
200 static void write_fields(FILE *h
, var_list_t
*fields
)
204 LIST_FOR_EACH_ENTRY( v
, fields
, var_t
, entry
) write_field(h
, v
);
207 static void write_enums(FILE *h
, var_list_t
*enums
)
211 LIST_FOR_EACH_ENTRY( v
, enums
, var_t
, entry
)
218 write_expr(h
, v
->eval
, 0);
221 if (list_next( enums
, &v
->entry
)) fprintf(h
, ",\n");
226 static int needs_space_after(type_t
*t
)
228 return t
->kind
== TKIND_ALIAS
|| ! is_ptr(t
);
231 void write_type(FILE *h
, type_t
*t
)
233 if (t
->is_const
) fprintf(h
, "const ");
235 if (t
->kind
== TKIND_ALIAS
) fprintf(h
, "%s", t
->name
);
237 if (t
->sign
> 0) fprintf(h
, "signed ");
238 else if (t
->sign
< 0) fprintf(h
, "unsigned ");
242 if (t
->defined
&& !t
->written
&& !t
->ignore
) {
243 if (t
->name
) fprintf(h
, "enum %s {\n", t
->name
);
244 else fprintf(h
, "enum {\n");
247 write_enums(h
, t
->fields
);
251 else fprintf(h
, "enum %s", t
->name
);
254 case RPC_FC_CVSTRUCT
:
255 case RPC_FC_CPSTRUCT
:
258 case RPC_FC_BOGUS_STRUCT
:
259 case RPC_FC_ENCAPSULATED_UNION
:
260 if (t
->defined
&& !t
->written
&& !t
->ignore
) {
261 if (t
->name
) fprintf(h
, "struct %s {\n", t
->name
);
262 else fprintf(h
, "struct {\n");
265 write_fields(h
, t
->fields
);
269 else fprintf(h
, "struct %s", t
->name
);
271 case RPC_FC_NON_ENCAPSULATED_UNION
:
272 if (t
->defined
&& !t
->written
&& !t
->ignore
) {
273 if (t
->name
) fprintf(h
, "union %s {\n", t
->name
);
274 else fprintf(h
, "union {\n");
277 write_fields(h
, t
->fields
);
281 else fprintf(h
, "union %s", t
->name
);
287 if (t
->ref
) write_type(h
, t
->ref
);
288 fprintf(h
, "%s*", needs_space_after(t
->ref
) ? " " : "");
291 fprintf(h
, "%s", t
->name
);
299 struct user_type
*next
;
303 static struct user_type
*user_type_list
;
305 static int user_type_registered(const char *name
)
307 struct user_type
*ut
;
308 for (ut
= user_type_list
; ut
; ut
= ut
->next
)
309 if (!strcmp(name
, ut
->name
))
314 static void check_for_user_types(const var_list_t
*list
)
319 LIST_FOR_EACH_ENTRY( v
, list
, const var_t
, entry
)
322 for (type
= v
->type
; type
; type
= type
->kind
== TKIND_ALIAS
? type
->orig
: type
->ref
) {
323 const char *name
= type
->name
;
324 if (type
->user_types_registered
) continue;
325 type
->user_types_registered
= 1;
326 if (is_attr(type
->attrs
, ATTR_WIREMARSHAL
)) {
327 if (!user_type_registered(name
))
329 struct user_type
*ut
= xmalloc(sizeof(struct user_type
) + strlen(name
));
330 strcpy(ut
->name
, name
);
331 ut
->next
= user_type_list
;
334 /* don't carry on parsing fields within this type as we are already
335 * using a wire marshaled type */
340 check_for_user_types(type
->fields
);
346 void write_user_types(void)
348 struct user_type
*ut
;
349 for (ut
= user_type_list
; ut
; ut
= ut
->next
)
351 const char *name
= ut
->name
;
352 fprintf(header
, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name
, name
);
353 fprintf(header
, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name
, name
);
354 fprintf(header
, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name
, name
);
355 fprintf(header
, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name
, name
);
359 void write_typedef(type_t
*type
)
361 fprintf(header
, "typedef ");
362 write_type(header
, type
->orig
);
363 fprintf(header
, "%s%s;\n", needs_space_after(type
->orig
) ? " " : "", type
->name
);
366 void write_expr(FILE *h
, const expr_t
*e
, int brackets
)
372 fprintf(h
, "%lu", e
->u
.lval
);
375 fprintf(h
, "0x%lx", e
->u
.lval
);
383 case EXPR_IDENTIFIER
:
384 fprintf(h
, "%s", e
->u
.sval
);
388 write_expr(h
, e
->ref
, 1);
392 write_expr(h
, e
->ref
, 1);
396 write_expr(h
, e
->ref
, 1);
400 write_type(h
, e
->u
.tref
);
402 write_expr(h
, e
->ref
, 1);
405 fprintf(h
, "sizeof(");
406 write_type(h
, e
->u
.tref
);
417 if (brackets
) fprintf(h
, "(");
418 write_expr(h
, e
->ref
, 1);
420 case EXPR_SHL
: fprintf(h
, " << "); break;
421 case EXPR_SHR
: fprintf(h
, " >> "); break;
422 case EXPR_MUL
: fprintf(h
, " * "); break;
423 case EXPR_DIV
: fprintf(h
, " / "); break;
424 case EXPR_ADD
: fprintf(h
, " + "); break;
425 case EXPR_SUB
: fprintf(h
, " - "); break;
426 case EXPR_AND
: fprintf(h
, " & "); break;
427 case EXPR_OR
: fprintf(h
, " | "); break;
430 write_expr(h
, e
->u
.ext
, 1);
431 if (brackets
) fprintf(h
, ")");
434 if (brackets
) fprintf(h
, "(");
435 write_expr(h
, e
->ref
, 1);
437 write_expr(h
, e
->u
.ext
, 1);
439 write_expr(h
, e
->ext2
, 1);
440 if (brackets
) fprintf(h
, ")");
445 void write_constdef(const var_t
*v
)
447 fprintf(header
, "#define %s (", get_name(v
));
448 write_expr(header
, v
->eval
, 0);
449 fprintf(header
, ")\n\n");
452 void write_externdef(const var_t
*v
)
454 fprintf(header
, "extern const ");
455 write_type(header
, v
->type
);
457 fprintf(header
, " %s", v
->name
);
458 fprintf(header
, ";\n\n");
461 void write_library(const char *name
, const attr_list_t
*attr
)
463 const UUID
*uuid
= get_attrp(attr
, ATTR_UUID
);
464 fprintf(header
, "\n");
465 write_guid(header
, "LIBID", name
, uuid
);
466 fprintf(header
, "\n");
470 const var_t
* get_explicit_handle_var(const func_t
* func
)
477 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
478 if (var
->type
->type
== RPC_FC_BIND_PRIMITIVE
)
484 int has_out_arg_or_return(const func_t
*func
)
488 if (!is_void(func
->def
->type
))
494 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
495 if (is_attr(var
->attrs
, ATTR_OUT
))
502 /********** INTERFACES **********/
504 int is_object(const attr_list_t
*list
)
507 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
508 if (attr
->type
== ATTR_OBJECT
|| attr
->type
== ATTR_ODL
) return 1;
512 int is_local(const attr_list_t
*a
)
514 return is_attr(a
, ATTR_LOCAL
);
517 const var_t
*is_callas(const attr_list_t
*a
)
519 return get_attrp(a
, ATTR_CALLAS
);
522 static void write_method_macro(const type_t
*iface
, const char *name
)
526 if (iface
->ref
) write_method_macro(iface
->ref
, name
);
528 if (!iface
->funcs
) return;
530 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
531 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
533 var_t
*def
= cur
->def
;
534 if (!is_callas(def
->attrs
)) {
539 if (cur
->args
) LIST_FOR_EACH_ENTRY( arg
, cur
->args
, const var_t
, entry
) argc
++;
541 fprintf(header
, "#define %s_", name
);
542 write_name(header
,def
);
543 fprintf(header
, "(p");
544 for (c
=0; c
<argc
; c
++)
545 fprintf(header
, ",%c", c
+'a');
546 fprintf(header
, ") ");
548 fprintf(header
, "(p)->lpVtbl->");
549 write_name(header
, def
);
550 fprintf(header
, "(p");
551 for (c
=0; c
<argc
; c
++)
552 fprintf(header
, ",%c", c
+'a');
553 fprintf(header
, ")\n");
558 void write_args(FILE *h
, const var_list_t
*args
, const char *name
, int method
, int do_indent
)
569 fprintf(h
, "%s* This", name
);
572 if (args
) LIST_FOR_EACH_ENTRY( arg
, args
, const var_t
, entry
) {
579 else fprintf(h
, ",");
581 write_type(h
, arg
->type
);
584 fprintf(h
, " (STDMETHODCALLTYPE *");
587 write_args(h
, arg
->args
, NULL
, 0, FALSE
);
592 if (needs_space_after(arg
->type
))
596 write_array(h
, arg
->array
, 0);
599 if (do_indent
) indentation
--;
602 static void write_cpp_method_def(const type_t
*iface
)
606 if (!iface
->funcs
) return;
608 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
610 var_t
*def
= cur
->def
;
611 if (!is_callas(def
->attrs
)) {
613 fprintf(header
, "virtual ");
614 write_type(header
, def
->type
);
615 fprintf(header
, " STDMETHODCALLTYPE ");
616 write_name(header
, def
);
617 fprintf(header
, "(\n");
618 write_args(header
, cur
->args
, iface
->name
, 2, TRUE
);
619 fprintf(header
, ") = 0;\n");
620 fprintf(header
, "\n");
625 static void do_write_c_method_def(const type_t
*iface
, const char *name
)
629 if (iface
->ref
) do_write_c_method_def(iface
->ref
, name
);
631 if (!iface
->funcs
) return;
633 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
634 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
636 const var_t
*def
= cur
->def
;
637 if (!is_callas(def
->attrs
)) {
639 write_type(header
, def
->type
);
640 fprintf(header
, " (STDMETHODCALLTYPE *");
641 write_name(header
, def
);
642 fprintf(header
, ")(\n");
643 write_args(header
, cur
->args
, name
, 1, TRUE
);
644 fprintf(header
, ");\n");
645 fprintf(header
, "\n");
650 static void write_c_method_def(const type_t
*iface
)
652 do_write_c_method_def(iface
, iface
->name
);
655 static void write_c_disp_method_def(const type_t
*iface
)
657 do_write_c_method_def(iface
->ref
, iface
->name
);
660 static void write_method_proto(const type_t
*iface
)
664 if (!iface
->funcs
) return;
665 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
667 const var_t
*def
= cur
->def
;
668 const var_t
*cas
= is_callas(def
->attrs
);
670 if (!is_local(def
->attrs
)) {
671 /* proxy prototype */
672 write_type(header
, def
->type
);
673 fprintf(header
, " CALLBACK %s_", iface
->name
);
674 write_name(header
, def
);
675 fprintf(header
, "_Proxy(\n");
676 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
677 fprintf(header
, ");\n");
679 fprintf(header
, "void __RPC_STUB %s_", iface
->name
);
680 write_name(header
,def
);
681 fprintf(header
, "_Stub(\n");
682 fprintf(header
, " IRpcStubBuffer* This,\n");
683 fprintf(header
, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
684 fprintf(header
, " PRPC_MESSAGE pRpcMessage,\n");
685 fprintf(header
, " DWORD* pdwStubPhase);\n");
686 check_for_user_types(cur
->args
);
690 LIST_FOR_EACH_ENTRY( m
, iface
->funcs
, const func_t
, entry
)
691 if (!strcmp(get_name(m
->def
), cas
->name
)) break;
692 if (&m
->entry
!= iface
->funcs
) {
693 const var_t
*mdef
= m
->def
;
694 /* proxy prototype - use local prototype */
695 write_type(header
, mdef
->type
);
696 fprintf(header
, " CALLBACK %s_", iface
->name
);
697 write_name(header
, mdef
);
698 fprintf(header
, "_Proxy(\n");
699 write_args(header
, m
->args
, iface
->name
, 1, TRUE
);
700 fprintf(header
, ");\n");
701 /* stub prototype - use remotable prototype */
702 write_type(header
, def
->type
);
703 fprintf(header
, " __RPC_STUB %s_", iface
->name
);
704 write_name(header
, mdef
);
705 fprintf(header
, "_Stub(\n");
706 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
707 fprintf(header
, ");\n");
710 parser_warning("invalid call_as attribute (%s -> %s)\n", get_name(def
), cas
->name
);
716 static void write_function_proto(const type_t
*iface
, const func_t
*fun
, const char *prefix
)
718 var_t
*def
= fun
->def
;
720 /* FIXME: do we need to handle call_as? */
721 write_type(header
, def
->type
);
722 fprintf(header
, " ");
723 write_prefix_name(header
, prefix
, def
);
724 fprintf(header
, "(\n");
726 write_args(header
, fun
->args
, iface
->name
, 0, TRUE
);
728 fprintf(header
, " void");
729 fprintf(header
, ");\n");
732 static void write_function_protos(const type_t
*iface
)
734 const char *implicit_handle
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
735 int explicit_handle
= is_attr(iface
->attrs
, ATTR_EXPLICIT_HANDLE
);
736 const var_t
* explicit_handle_var
;
738 int prefixes_differ
= strcmp(prefix_client
, prefix_server
);
740 if (!iface
->funcs
) return;
741 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
743 var_t
*def
= cur
->def
;
745 /* check for a defined binding handle */
746 explicit_handle_var
= get_explicit_handle_var(cur
);
747 if (explicit_handle
) {
748 if (!explicit_handle_var
) {
749 error("%s() does not define an explicit binding handle!\n", def
->name
);
752 } else if (implicit_handle
) {
753 if (explicit_handle_var
) {
754 error("%s() must not define a binding handle!\n", def
->name
);
759 if (prefixes_differ
) {
760 fprintf(header
, "/* client prototype */\n");
761 write_function_proto(iface
, cur
, prefix_client
);
762 fprintf(header
, "/* server prototype */\n");
764 write_function_proto(iface
, cur
, prefix_server
);
768 void write_forward(type_t
*iface
)
770 /* C/C++ forwards should only be written for object interfaces, so if we
771 * have a full definition we only write one if we find [object] among the
772 * attributes - however, if we don't have a full definition at this point
773 * (i.e. this is an IDL forward), then we also assume that it is an object
774 * interface, since non-object interfaces shouldn't need forwards */
775 if ((!iface
->defined
|| is_object(iface
->attrs
) || is_attr(iface
->attrs
, ATTR_DISPINTERFACE
))
776 && !iface
->written
) {
777 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", iface
->name
);
778 fprintf(header
, "#define __%s_FWD_DEFINED__\n", iface
->name
);
779 fprintf(header
, "typedef interface %s %s;\n", iface
->name
, iface
->name
);
780 fprintf(header
, "#endif\n\n" );
781 iface
->written
= TRUE
;
785 static void write_iface_guid(const type_t
*iface
)
787 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
788 write_guid(header
, "IID", iface
->name
, uuid
);
791 static void write_dispiface_guid(const type_t
*iface
)
793 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
794 write_guid(header
, "DIID", iface
->name
, uuid
);
797 static void write_coclass_guid(type_t
*cocl
)
799 const UUID
*uuid
= get_attrp(cocl
->attrs
, ATTR_UUID
);
800 write_guid(header
, "CLSID", cocl
->name
, uuid
);
803 static void write_com_interface(type_t
*iface
)
805 if (!iface
->funcs
&& !iface
->ref
) {
806 parser_warning("%s has no methods", iface
->name
);
810 fprintf(header
, "/*****************************************************************************\n");
811 fprintf(header
, " * %s interface\n", iface
->name
);
812 fprintf(header
, " */\n");
813 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
814 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
815 write_iface_guid(iface
);
816 write_forward(iface
);
818 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
821 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
822 fprintf(header
, "{\n");
824 write_cpp_method_def(iface
);
826 fprintf(header
, "};\n");
830 fprintf(header
, "interface %s\n", iface
->name
);
831 fprintf(header
, "{\n");
832 fprintf(header
, " BEGIN_INTERFACE\n");
833 fprintf(header
, "\n");
835 write_cpp_method_def(iface
);
837 fprintf(header
, " END_INTERFACE\n");
838 fprintf(header
, "};\n");
840 fprintf(header
, "#else\n");
842 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
844 fprintf(header
, " BEGIN_INTERFACE\n");
845 fprintf(header
, "\n");
846 write_c_method_def(iface
);
848 fprintf(header
, " END_INTERFACE\n");
849 fprintf(header
, "} %sVtbl;\n", iface
->name
);
850 fprintf(header
, "interface %s {\n", iface
->name
);
851 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
852 fprintf(header
, "};\n");
853 fprintf(header
, "\n");
854 fprintf(header
, "#ifdef COBJMACROS\n");
855 write_method_macro(iface
, iface
->name
);
856 fprintf(header
, "#endif\n");
857 fprintf(header
, "\n");
858 fprintf(header
, "#endif\n");
859 fprintf(header
, "\n");
860 write_method_proto(iface
);
861 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
864 static void write_rpc_interface(const type_t
*iface
)
866 unsigned long ver
= get_attrv(iface
->attrs
, ATTR_VERSION
);
867 const char *var
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
868 static int allocate_written
= 0;
870 if (!allocate_written
)
872 allocate_written
= 1;
873 fprintf(header
, "void * __RPC_USER MIDL_user_allocate(size_t);\n");
874 fprintf(header
, "void __RPC_USER MIDL_user_free(void *);\n\n");
877 fprintf(header
, "/*****************************************************************************\n");
878 fprintf(header
, " * %s interface (v%d.%d)\n", iface
->name
, LOWORD(ver
), HIWORD(ver
));
879 fprintf(header
, " */\n");
880 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
881 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
884 write_iface_guid(iface
);
885 if (var
) fprintf(header
, "extern handle_t %s;\n", var
);
888 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ClientIfHandle;\n", prefix_client
, iface
->name
);
889 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ServerIfHandle;\n", prefix_server
, iface
->name
);
893 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n",
894 prefix_client
, iface
->name
, LOWORD(ver
), HIWORD(ver
));
895 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n",
896 prefix_server
, iface
->name
, LOWORD(ver
), HIWORD(ver
));
898 write_function_protos(iface
);
900 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
902 /* FIXME: server/client code */
905 void write_interface(type_t
*iface
)
907 if (is_object(iface
->attrs
))
908 write_com_interface(iface
);
910 write_rpc_interface(iface
);
913 void write_dispinterface(type_t
*iface
)
915 fprintf(header
, "/*****************************************************************************\n");
916 fprintf(header
, " * %s dispinterface\n", iface
->name
);
917 fprintf(header
, " */\n");
918 fprintf(header
,"#ifndef __%s_DISPINTERFACE_DEFINED__\n", iface
->name
);
919 fprintf(header
,"#define __%s_DISPINTERFACE_DEFINED__\n\n", iface
->name
);
920 write_dispiface_guid(iface
);
921 write_forward(iface
);
923 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
924 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
925 fprintf(header
, "{\n");
926 fprintf(header
, "};\n");
927 fprintf(header
, "#else\n");
929 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
931 fprintf(header
, " BEGIN_INTERFACE\n");
932 fprintf(header
, "\n");
933 write_c_disp_method_def(iface
);
935 fprintf(header
, " END_INTERFACE\n");
936 fprintf(header
, "} %sVtbl;\n", iface
->name
);
937 fprintf(header
, "interface %s {\n", iface
->name
);
938 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
939 fprintf(header
, "};\n");
940 fprintf(header
, "\n");
941 fprintf(header
, "#ifdef COBJMACROS\n");
942 write_method_macro(iface
->ref
, iface
->name
);
943 fprintf(header
, "#endif\n");
944 fprintf(header
, "\n");
945 fprintf(header
, "#endif\n");
946 fprintf(header
, "\n");
947 fprintf(header
,"#endif /* __%s_DISPINTERFACE_DEFINED__ */\n\n", iface
->name
);
950 void write_coclass(type_t
*cocl
)
952 fprintf(header
, "/*****************************************************************************\n");
953 fprintf(header
, " * %s coclass\n", cocl
->name
);
954 fprintf(header
, " */\n\n");
955 write_coclass_guid(cocl
);
956 fprintf(header
, "\n");
959 void write_coclass_forward(type_t
*cocl
)
961 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", cocl
->name
);
962 fprintf(header
, "#define __%s_FWD_DEFINED__\n", cocl
->name
);
963 fprintf(header
, "typedef struct %s %s;\n", cocl
->name
, cocl
->name
);
964 fprintf(header
, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl
->name
);