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 const char* get_name(const var_t
*v
)
133 void write_array(FILE *h
, array_dims_t
*dims
, int field
)
139 LIST_FOR_EACH_ENTRY( v
, dims
, expr_t
, entry
)
142 fprintf(h
, "%ld", v
->cval
); /* statically sized array */
144 if (field
) fprintf(h
, "1"); /* dynamically sized array */
145 if (list_next( dims
, &v
->entry
))
151 static void write_field(FILE *h
, var_t
*v
)
156 write_type(h
, v
->type
, NULL
, v
->tname
);
162 /* not all C/C++ compilers support anonymous structs and unions */
163 switch (v
->type
->type
) {
165 case RPC_FC_CVSTRUCT
:
166 case RPC_FC_CPSTRUCT
:
169 case RPC_FC_BOGUS_STRUCT
:
170 case RPC_FC_ENCAPSULATED_UNION
:
171 fprintf(h
, " DUMMYSTRUCTNAME");
173 case RPC_FC_NON_ENCAPSULATED_UNION
:
174 fprintf(h
, " DUMMYUNIONNAME");
181 write_array(h
, v
->array
, 1);
186 static void write_fields(FILE *h
, var_list_t
*fields
)
190 LIST_FOR_EACH_ENTRY( v
, fields
, var_t
, entry
) write_field(h
, v
);
193 static void write_enums(FILE *h
, var_list_t
*enums
)
197 LIST_FOR_EACH_ENTRY( v
, enums
, var_t
, entry
)
204 write_expr(h
, v
->eval
, 0);
207 if (list_next( enums
, &v
->entry
)) fprintf(h
, ",\n");
212 int needs_space_after(type_t
*t
)
214 return t
->kind
== TKIND_ALIAS
|| ! is_ptr(t
);
217 void write_type(FILE *h
, type_t
*t
, const var_t
*v
, const char *n
)
221 if (t
->is_const
) fprintf(h
, "const ");
223 if (n
) fprintf(h
, "%s", n
);
224 else if (t
->kind
== TKIND_ALIAS
) fprintf(h
, "%s", t
->name
);
226 if (t
->sign
> 0) fprintf(h
, "signed ");
227 else if (t
->sign
< 0) fprintf(h
, "unsigned ");
231 if (t
->defined
&& !t
->written
&& !t
->ignore
) {
232 if (t
->name
) fprintf(h
, "enum %s {\n", t
->name
);
233 else fprintf(h
, "enum {\n");
236 write_enums(h
, t
->fields
);
240 else fprintf(h
, "enum %s", t
->name
);
243 case RPC_FC_CVSTRUCT
:
244 case RPC_FC_CPSTRUCT
:
247 case RPC_FC_BOGUS_STRUCT
:
248 case RPC_FC_ENCAPSULATED_UNION
:
249 if (t
->defined
&& !t
->written
&& !t
->ignore
) {
250 if (t
->name
) fprintf(h
, "struct %s {\n", t
->name
);
251 else fprintf(h
, "struct {\n");
254 write_fields(h
, t
->fields
);
258 else fprintf(h
, "struct %s", t
->name
);
260 case RPC_FC_NON_ENCAPSULATED_UNION
:
261 if (t
->defined
&& !t
->written
&& !t
->ignore
) {
262 if (t
->name
) fprintf(h
, "union %s {\n", t
->name
);
263 else fprintf(h
, "union {\n");
266 write_fields(h
, t
->fields
);
270 else fprintf(h
, "union %s", t
->name
);
276 if (t
->ref
) write_type(h
, t
->ref
, NULL
, t
->name
);
277 fprintf(h
, "%s*", needs_space_after(t
->ref
) ? " " : "");
280 fprintf(h
, "%s", t
->name
);
284 for (c
=0; c
<v
->ptr_level
; c
++) {
293 struct user_type
*next
;
297 static struct user_type
*user_type_list
;
299 static int user_type_registered(const char *name
)
301 struct user_type
*ut
;
302 for (ut
= user_type_list
; ut
; ut
= ut
->next
)
303 if (!strcmp(name
, ut
->name
))
308 static void check_for_user_types(const var_list_t
*list
)
313 LIST_FOR_EACH_ENTRY( v
, list
, const var_t
, entry
)
316 for (type
= v
->type
; type
; type
= type
->kind
== TKIND_ALIAS
? type
->orig
: type
->ref
) {
317 const char *name
= type
->name
;
318 if (type
->user_types_registered
) continue;
319 type
->user_types_registered
= 1;
320 if (is_attr(type
->attrs
, ATTR_WIREMARSHAL
)) {
321 if (!user_type_registered(name
))
323 struct user_type
*ut
= xmalloc(sizeof(struct user_type
) + strlen(name
));
324 strcpy(ut
->name
, name
);
325 ut
->next
= user_type_list
;
328 /* don't carry on parsing fields within this type as we are already
329 * using a wire marshaled type */
334 check_for_user_types(type
->fields
);
340 void write_user_types(void)
342 struct user_type
*ut
;
343 for (ut
= user_type_list
; ut
; ut
= ut
->next
)
345 const char *name
= ut
->name
;
346 fprintf(header
, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name
, name
);
347 fprintf(header
, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name
, name
);
348 fprintf(header
, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name
, name
);
349 fprintf(header
, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name
, name
);
353 void write_typedef(type_t
*type
)
355 fprintf(header
, "typedef ");
356 write_type(header
, type
->orig
, NULL
, NULL
);
357 fprintf(header
, "%s%s;\n", needs_space_after(type
->orig
) ? " " : "", type
->name
);
360 void write_expr(FILE *h
, const expr_t
*e
, int brackets
)
366 fprintf(h
, "%lu", e
->u
.lval
);
369 fprintf(h
, "0x%lx", e
->u
.lval
);
377 case EXPR_IDENTIFIER
:
378 fprintf(h
, "%s", e
->u
.sval
);
382 write_expr(h
, e
->ref
, 1);
386 write_expr(h
, e
->ref
, 1);
390 write_expr(h
, e
->ref
, 1);
394 write_type(h
, e
->u
.tref
->ref
, NULL
, e
->u
.tref
->name
);
396 write_expr(h
, e
->ref
, 1);
399 fprintf(h
, "sizeof(");
400 write_type(h
, e
->u
.tref
->ref
, NULL
, e
->u
.tref
->name
);
411 if (brackets
) fprintf(h
, "(");
412 write_expr(h
, e
->ref
, 1);
414 case EXPR_SHL
: fprintf(h
, " << "); break;
415 case EXPR_SHR
: fprintf(h
, " >> "); break;
416 case EXPR_MUL
: fprintf(h
, " * "); break;
417 case EXPR_DIV
: fprintf(h
, " / "); break;
418 case EXPR_ADD
: fprintf(h
, " + "); break;
419 case EXPR_SUB
: fprintf(h
, " - "); break;
420 case EXPR_AND
: fprintf(h
, " & "); break;
421 case EXPR_OR
: fprintf(h
, " | "); break;
424 write_expr(h
, e
->u
.ext
, 1);
425 if (brackets
) fprintf(h
, ")");
428 if (brackets
) fprintf(h
, "(");
429 write_expr(h
, e
->ref
, 1);
431 write_expr(h
, e
->u
.ext
, 1);
433 write_expr(h
, e
->ext2
, 1);
434 if (brackets
) fprintf(h
, ")");
439 void write_constdef(const var_t
*v
)
441 fprintf(header
, "#define %s (", get_name(v
));
442 write_expr(header
, v
->eval
, 0);
443 fprintf(header
, ")\n\n");
446 void write_externdef(const var_t
*v
)
448 fprintf(header
, "extern const ");
449 write_type(header
, v
->type
, NULL
, v
->tname
);
451 fprintf(header
, " ");
452 write_pident(header
, v
);
454 fprintf(header
, ";\n\n");
457 void write_library(const char *name
, const attr_list_t
*attr
)
459 const UUID
*uuid
= get_attrp(attr
, ATTR_UUID
);
460 fprintf(header
, "\n");
461 write_guid(header
, "LIBID", name
, uuid
);
462 fprintf(header
, "\n");
466 const var_t
* get_explicit_handle_var(const func_t
* func
)
473 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
474 if (var
->type
->type
== RPC_FC_BIND_PRIMITIVE
)
480 int has_out_arg_or_return(const func_t
*func
)
484 if (!is_void(func
->def
->type
, NULL
))
490 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
491 if (is_attr(var
->attrs
, ATTR_OUT
))
498 /********** INTERFACES **********/
500 int is_object(const attr_list_t
*list
)
503 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
504 if (attr
->type
== ATTR_OBJECT
|| attr
->type
== ATTR_ODL
) return 1;
508 int is_local(const attr_list_t
*a
)
510 return is_attr(a
, ATTR_LOCAL
);
513 const var_t
*is_callas(const attr_list_t
*a
)
515 return get_attrp(a
, ATTR_CALLAS
);
518 static void write_method_macro(const type_t
*iface
, const char *name
)
522 if (iface
->ref
) write_method_macro(iface
->ref
, name
);
524 if (!iface
->funcs
) return;
526 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
527 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
529 var_t
*def
= cur
->def
;
530 if (!is_callas(def
->attrs
)) {
535 if (cur
->args
) LIST_FOR_EACH_ENTRY( arg
, cur
->args
, const var_t
, entry
) argc
++;
537 fprintf(header
, "#define %s_", name
);
538 write_name(header
,def
);
539 fprintf(header
, "(p");
540 for (c
=0; c
<argc
; c
++)
541 fprintf(header
, ",%c", c
+'a');
542 fprintf(header
, ") ");
544 fprintf(header
, "(p)->lpVtbl->");
545 write_name(header
, def
);
546 fprintf(header
, "(p");
547 for (c
=0; c
<argc
; c
++)
548 fprintf(header
, ",%c", c
+'a');
549 fprintf(header
, ")\n");
554 void write_args(FILE *h
, const var_list_t
*args
, const char *name
, int method
, int do_indent
)
565 fprintf(h
, "%s* This", name
);
568 if (args
) LIST_FOR_EACH_ENTRY( arg
, args
, const var_t
, entry
) {
575 else fprintf(h
, ",");
577 write_type(h
, arg
->type
, arg
, arg
->tname
);
580 fprintf(h
, " (STDMETHODCALLTYPE *");
583 write_args(h
, arg
->args
, NULL
, 0, FALSE
);
588 if (needs_space_after(arg
->type
))
592 write_array(h
, arg
->array
, 0);
595 if (do_indent
) indentation
--;
598 static void write_cpp_method_def(const type_t
*iface
)
602 if (!iface
->funcs
) return;
604 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
606 var_t
*def
= cur
->def
;
607 if (!is_callas(def
->attrs
)) {
609 fprintf(header
, "virtual ");
610 write_type(header
, def
->type
, def
, def
->tname
);
611 fprintf(header
, " STDMETHODCALLTYPE ");
612 write_name(header
, def
);
613 fprintf(header
, "(\n");
614 write_args(header
, cur
->args
, iface
->name
, 2, TRUE
);
615 fprintf(header
, ") = 0;\n");
616 fprintf(header
, "\n");
621 static void do_write_c_method_def(const type_t
*iface
, const char *name
)
625 if (iface
->ref
) do_write_c_method_def(iface
->ref
, name
);
627 if (!iface
->funcs
) return;
629 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
630 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
632 const var_t
*def
= cur
->def
;
633 if (!is_callas(def
->attrs
)) {
635 write_type(header
, def
->type
, def
, def
->tname
);
636 fprintf(header
, " (STDMETHODCALLTYPE *");
637 write_name(header
, def
);
638 fprintf(header
, ")(\n");
639 write_args(header
, cur
->args
, name
, 1, TRUE
);
640 fprintf(header
, ");\n");
641 fprintf(header
, "\n");
646 static void write_c_method_def(const type_t
*iface
)
648 do_write_c_method_def(iface
, iface
->name
);
651 static void write_c_disp_method_def(const type_t
*iface
)
653 do_write_c_method_def(iface
->ref
, iface
->name
);
656 static void write_method_proto(const type_t
*iface
)
660 if (!iface
->funcs
) return;
661 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
663 const var_t
*def
= cur
->def
;
664 const var_t
*cas
= is_callas(def
->attrs
);
666 if (!is_local(def
->attrs
)) {
667 /* proxy prototype */
668 write_type(header
, def
->type
, def
, def
->tname
);
669 fprintf(header
, " CALLBACK %s_", iface
->name
);
670 write_name(header
, def
);
671 fprintf(header
, "_Proxy(\n");
672 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
673 fprintf(header
, ");\n");
675 fprintf(header
, "void __RPC_STUB %s_", iface
->name
);
676 write_name(header
,def
);
677 fprintf(header
, "_Stub(\n");
678 fprintf(header
, " IRpcStubBuffer* This,\n");
679 fprintf(header
, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
680 fprintf(header
, " PRPC_MESSAGE pRpcMessage,\n");
681 fprintf(header
, " DWORD* pdwStubPhase);\n");
682 check_for_user_types(cur
->args
);
686 LIST_FOR_EACH_ENTRY( m
, iface
->funcs
, const func_t
, entry
)
687 if (!strcmp(get_name(m
->def
), cas
->name
)) break;
688 if (&m
->entry
!= iface
->funcs
) {
689 const var_t
*mdef
= m
->def
;
690 /* proxy prototype - use local prototype */
691 write_type(header
, mdef
->type
, mdef
, mdef
->tname
);
692 fprintf(header
, " CALLBACK %s_", iface
->name
);
693 write_name(header
, mdef
);
694 fprintf(header
, "_Proxy(\n");
695 write_args(header
, m
->args
, iface
->name
, 1, TRUE
);
696 fprintf(header
, ");\n");
697 /* stub prototype - use remotable prototype */
698 write_type(header
, def
->type
, def
, def
->tname
);
699 fprintf(header
, " __RPC_STUB %s_", iface
->name
);
700 write_name(header
, mdef
);
701 fprintf(header
, "_Stub(\n");
702 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
703 fprintf(header
, ");\n");
706 parser_warning("invalid call_as attribute (%s -> %s)\n", get_name(def
), cas
->name
);
712 static void write_function_proto(const type_t
*iface
)
714 const char *implicit_handle
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
715 int explicit_handle
= is_attr(iface
->attrs
, ATTR_EXPLICIT_HANDLE
);
716 const var_t
* explicit_handle_var
;
719 if (!iface
->funcs
) return;
720 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
722 var_t
*def
= cur
->def
;
724 /* check for a defined binding handle */
725 explicit_handle_var
= get_explicit_handle_var(cur
);
726 if (explicit_handle
) {
727 if (!explicit_handle_var
) {
728 error("%s() does not define an explicit binding handle!\n", def
->name
);
731 } else if (implicit_handle
) {
732 if (explicit_handle_var
) {
733 error("%s() must not define a binding handle!\n", def
->name
);
738 /* FIXME: do we need to handle call_as? */
739 write_type(header
, def
->type
, def
, def
->tname
);
740 fprintf(header
, " ");
741 write_name(header
, def
);
742 fprintf(header
, "(\n");
744 write_args(header
, cur
->args
, iface
->name
, 0, TRUE
);
746 fprintf(header
, " void");
747 fprintf(header
, ");\n");
751 void write_forward(type_t
*iface
)
753 /* C/C++ forwards should only be written for object interfaces, so if we
754 * have a full definition we only write one if we find [object] among the
755 * attributes - however, if we don't have a full definition at this point
756 * (i.e. this is an IDL forward), then we also assume that it is an object
757 * interface, since non-object interfaces shouldn't need forwards */
758 if ((!iface
->defined
|| is_object(iface
->attrs
) || is_attr(iface
->attrs
, ATTR_DISPINTERFACE
))
759 && !iface
->written
) {
760 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", iface
->name
);
761 fprintf(header
, "#define __%s_FWD_DEFINED__\n", iface
->name
);
762 fprintf(header
, "typedef interface %s %s;\n", iface
->name
, iface
->name
);
763 fprintf(header
, "#endif\n\n" );
764 iface
->written
= TRUE
;
768 static void write_iface_guid(const type_t
*iface
)
770 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
771 write_guid(header
, "IID", iface
->name
, uuid
);
774 static void write_dispiface_guid(const type_t
*iface
)
776 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
777 write_guid(header
, "DIID", iface
->name
, uuid
);
780 static void write_coclass_guid(type_t
*cocl
)
782 const UUID
*uuid
= get_attrp(cocl
->attrs
, ATTR_UUID
);
783 write_guid(header
, "CLSID", cocl
->name
, uuid
);
786 static void write_com_interface(type_t
*iface
)
788 if (!iface
->funcs
&& !iface
->ref
) {
789 parser_warning("%s has no methods", iface
->name
);
793 fprintf(header
, "/*****************************************************************************\n");
794 fprintf(header
, " * %s interface\n", iface
->name
);
795 fprintf(header
, " */\n");
796 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
797 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
798 write_iface_guid(iface
);
799 write_forward(iface
);
801 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
804 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
805 fprintf(header
, "{\n");
807 write_cpp_method_def(iface
);
809 fprintf(header
, "};\n");
813 fprintf(header
, "interface %s\n", iface
->name
);
814 fprintf(header
, "{\n");
815 fprintf(header
, " BEGIN_INTERFACE\n");
816 fprintf(header
, "\n");
818 write_cpp_method_def(iface
);
820 fprintf(header
, " END_INTERFACE\n");
821 fprintf(header
, "};\n");
823 fprintf(header
, "#else\n");
825 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
827 fprintf(header
, " BEGIN_INTERFACE\n");
828 fprintf(header
, "\n");
829 write_c_method_def(iface
);
831 fprintf(header
, " END_INTERFACE\n");
832 fprintf(header
, "} %sVtbl;\n", iface
->name
);
833 fprintf(header
, "interface %s {\n", iface
->name
);
834 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
835 fprintf(header
, "};\n");
836 fprintf(header
, "\n");
837 fprintf(header
, "#ifdef COBJMACROS\n");
838 write_method_macro(iface
, iface
->name
);
839 fprintf(header
, "#endif\n");
840 fprintf(header
, "\n");
841 fprintf(header
, "#endif\n");
842 fprintf(header
, "\n");
843 write_method_proto(iface
);
844 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
847 static void write_rpc_interface(const type_t
*iface
)
849 unsigned long ver
= get_attrv(iface
->attrs
, ATTR_VERSION
);
850 const char *var
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
851 static int allocate_written
= 0;
853 if (!allocate_written
)
855 allocate_written
= 1;
856 fprintf(header
, "void * __RPC_USER MIDL_user_allocate(size_t);\n");
857 fprintf(header
, "void __RPC_USER MIDL_user_free(void *);\n\n");
860 fprintf(header
, "/*****************************************************************************\n");
861 fprintf(header
, " * %s interface (v%d.%d)\n", iface
->name
, LOWORD(ver
), HIWORD(ver
));
862 fprintf(header
, " */\n");
863 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
864 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
867 write_iface_guid(iface
);
868 if (var
) fprintf(header
, "extern handle_t %s;\n", var
);
871 fprintf(header
, "extern RPC_IF_HANDLE %s_ClientIfHandle;\n", iface
->name
);
872 fprintf(header
, "extern RPC_IF_HANDLE %s_ServerIfHandle;\n", iface
->name
);
876 fprintf(header
, "extern RPC_IF_HANDLE %s_v%d_%d_c_ifspec;\n", iface
->name
, LOWORD(ver
), HIWORD(ver
));
877 fprintf(header
, "extern RPC_IF_HANDLE %s_v%d_%d_s_ifspec;\n", iface
->name
, LOWORD(ver
), HIWORD(ver
));
879 write_function_proto(iface
);
881 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
883 /* FIXME: server/client code */
886 void write_interface(type_t
*iface
)
888 if (is_object(iface
->attrs
))
889 write_com_interface(iface
);
891 write_rpc_interface(iface
);
894 void write_dispinterface(type_t
*iface
)
896 fprintf(header
, "/*****************************************************************************\n");
897 fprintf(header
, " * %s dispinterface\n", iface
->name
);
898 fprintf(header
, " */\n");
899 fprintf(header
,"#ifndef __%s_DISPINTERFACE_DEFINED__\n", iface
->name
);
900 fprintf(header
,"#define __%s_DISPINTERFACE_DEFINED__\n\n", iface
->name
);
901 write_dispiface_guid(iface
);
902 write_forward(iface
);
904 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
905 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
906 fprintf(header
, "{\n");
907 fprintf(header
, "};\n");
908 fprintf(header
, "#else\n");
910 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
912 fprintf(header
, " BEGIN_INTERFACE\n");
913 fprintf(header
, "\n");
914 write_c_disp_method_def(iface
);
916 fprintf(header
, " END_INTERFACE\n");
917 fprintf(header
, "} %sVtbl;\n", iface
->name
);
918 fprintf(header
, "interface %s {\n", iface
->name
);
919 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
920 fprintf(header
, "};\n");
921 fprintf(header
, "\n");
922 fprintf(header
, "#ifdef COBJMACROS\n");
923 write_method_macro(iface
->ref
, iface
->name
);
924 fprintf(header
, "#endif\n");
925 fprintf(header
, "\n");
926 fprintf(header
, "#endif\n");
927 fprintf(header
, "\n");
928 fprintf(header
,"#endif /* __%s_DISPINTERFACE_DEFINED__ */\n\n", iface
->name
);
931 void write_coclass(type_t
*cocl
)
933 fprintf(header
, "/*****************************************************************************\n");
934 fprintf(header
, " * %s coclass\n", cocl
->name
);
935 fprintf(header
, " */\n\n");
936 write_coclass_guid(cocl
);
937 fprintf(header
, "\n");
940 void write_coclass_forward(type_t
*cocl
)
942 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", cocl
->name
);
943 fprintf(header
, "#define __%s_FWD_DEFINED__\n", cocl
->name
);
944 fprintf(header
, "typedef struct %s %s;\n", cocl
->name
, cocl
->name
);
945 fprintf(header
, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl
->name
);