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
38 typedef struct _user_type_t generic_handle_t
;
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
);
43 static struct list generic_handle_list
= LIST_INIT(generic_handle_list
);
45 static void indent(FILE *h
, int delta
)
48 if (delta
< 0) indentation
+= delta
;
49 for (c
=0; c
<indentation
; c
++) fprintf(h
, " ");
50 if (delta
> 0) indentation
+= delta
;
53 int is_ptrchain_attr(const var_t
*var
, enum attr_type t
)
55 if (is_attr(var
->attrs
, t
))
59 type_t
*type
= var
->type
;
62 if (is_attr(type
->attrs
, t
))
64 else if (type
->kind
== TKIND_ALIAS
)
66 else if (is_ptr(type
))
73 int is_aliaschain_attr(const type_t
*type
, enum attr_type attr
)
75 const type_t
*t
= type
;
78 if (is_attr(t
->attrs
, attr
))
80 else if (t
->kind
== TKIND_ALIAS
)
86 int is_attr(const attr_list_t
*list
, enum attr_type t
)
89 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
90 if (attr
->type
== t
) return 1;
94 void *get_attrp(const attr_list_t
*list
, enum attr_type t
)
97 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
98 if (attr
->type
== t
) return attr
->u
.pval
;
102 unsigned long get_attrv(const attr_list_t
*list
, enum attr_type t
)
105 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
106 if (attr
->type
== t
) return attr
->u
.ival
;
110 int is_void(const type_t
*t
)
112 if (!t
->type
&& !t
->ref
) return 1;
116 int is_conformant_array(const type_t
*t
)
118 return t
->type
== RPC_FC_CARRAY
119 || t
->type
== RPC_FC_CVARRAY
120 || (t
->type
== RPC_FC_BOGUS_ARRAY
&& t
->size_is
);
123 void write_guid(FILE *f
, const char *guid_prefix
, const char *name
, const UUID
*uuid
)
126 fprintf(f
, "DEFINE_GUID(%s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
127 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
128 guid_prefix
, name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0],
129 uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5],
130 uuid
->Data4
[6], uuid
->Data4
[7]);
133 void write_name(FILE *h
, const var_t
*v
)
135 if (is_attr( v
->attrs
, ATTR_PROPGET
))
137 else if (is_attr( v
->attrs
, ATTR_PROPPUT
))
139 else if (is_attr( v
->attrs
, ATTR_PROPPUTREF
))
140 fprintf(h
, "putref_" );
141 fprintf(h
, "%s", v
->name
);
144 void write_prefix_name(FILE *h
, const char *prefix
, const var_t
*v
)
146 fprintf(h
, "%s", prefix
);
150 static void write_field(FILE *h
, var_t
*v
)
154 const char *name
= v
->name
;
156 switch (v
->type
->type
) {
158 case RPC_FC_CVSTRUCT
:
159 case RPC_FC_CPSTRUCT
:
162 case RPC_FC_BOGUS_STRUCT
:
163 case RPC_FC_ENCAPSULATED_UNION
:
164 name
= "DUMMYSTRUCTNAME";
166 case RPC_FC_NON_ENCAPSULATED_UNION
:
167 name
= "DUMMYUNIONNAME";
175 write_type_def_or_decl(h
, v
->type
, TRUE
, "%s", name
);
180 static void write_fields(FILE *h
, var_list_t
*fields
)
184 LIST_FOR_EACH_ENTRY( v
, fields
, var_t
, entry
) write_field(h
, v
);
187 static void write_enums(FILE *h
, var_list_t
*enums
)
191 LIST_FOR_EACH_ENTRY( v
, enums
, var_t
, entry
)
198 write_expr(h
, v
->eval
, 0, 1, NULL
, NULL
);
201 if (list_next( enums
, &v
->entry
)) fprintf(h
, ",\n");
206 int needs_space_after(type_t
*t
)
208 return (t
->kind
== TKIND_ALIAS
209 || (!is_ptr(t
) && (!is_conformant_array(t
) || t
->declarray
)));
212 void write_type_left(FILE *h
, type_t
*t
, int declonly
)
216 if (t
->is_const
) fprintf(h
, "const ");
218 if (t
->kind
== TKIND_ALIAS
) fprintf(h
, "%s", t
->name
);
219 else if (t
->declarray
) write_type_left(h
, t
->ref
, declonly
);
221 if (t
->sign
> 0) fprintf(h
, "signed ");
222 else if (t
->sign
< 0) fprintf(h
, "unsigned ");
226 if (!declonly
&& t
->defined
&& !t
->written
&& !t
->ignore
) {
227 if (t
->name
) fprintf(h
, "enum %s {\n", t
->name
);
228 else fprintf(h
, "enum {\n");
231 write_enums(h
, t
->fields_or_args
);
235 else fprintf(h
, "enum %s", t
->name
? t
->name
: "");
238 case RPC_FC_CVSTRUCT
:
239 case RPC_FC_CPSTRUCT
:
242 case RPC_FC_BOGUS_STRUCT
:
243 case RPC_FC_ENCAPSULATED_UNION
:
244 if (!declonly
&& t
->defined
&& !t
->written
&& !t
->ignore
) {
245 if (t
->name
) fprintf(h
, "struct %s {\n", t
->name
);
246 else fprintf(h
, "struct {\n");
249 write_fields(h
, t
->fields_or_args
);
253 else fprintf(h
, "struct %s", t
->name
? t
->name
: "");
255 case RPC_FC_NON_ENCAPSULATED_UNION
:
256 if (!declonly
&& t
->defined
&& !t
->written
&& !t
->ignore
) {
257 if (t
->name
) fprintf(h
, "union %s {\n", t
->name
);
258 else fprintf(h
, "union {\n");
261 write_fields(h
, t
->fields_or_args
);
265 else fprintf(h
, "union %s", t
->name
? t
->name
: "");
273 case RPC_FC_BOGUS_ARRAY
:
274 write_type_left(h
, t
->ref
, declonly
);
275 fprintf(h
, "%s*", needs_space_after(t
->ref
) ? " " : "");
278 fprintf(h
, "%s", t
->name
);
283 void write_type_right(FILE *h
, type_t
*t
, int is_field
)
288 if (is_conformant_array(t
)) {
289 fprintf(h
, "[%s]", is_field
? "1" : "");
292 for ( ; t
->declarray
; t
= t
->ref
)
293 fprintf(h
, "[%lu]", t
->dim
);
297 void write_type_v(FILE *h
, type_t
*t
, int is_field
, int declonly
,
298 const char *fmt
, va_list args
)
305 for (pt
= t
; is_ptr(pt
); pt
= pt
->ref
, ptr_level
++)
308 if (pt
->type
== RPC_FC_FUNCTION
) {
310 const char *callconv
= get_attrp(pt
->attrs
, ATTR_CALLCONV
);
311 if (!callconv
) callconv
= "";
312 write_type_left(h
, pt
->ref
, declonly
);
314 if (ptr_level
) fputc('(', h
);
315 fprintf(h
, "%s ", callconv
);
316 for (i
= 0; i
< ptr_level
; i
++)
319 write_type_left(h
, t
, declonly
);
321 if (needs_space_after(t
))
323 vfprintf(h
, fmt
, args
);
325 if (pt
->type
== RPC_FC_FUNCTION
) {
326 if (ptr_level
) fputc(')', h
);
328 write_args(h
, pt
->fields_or_args
, NULL
, 0, FALSE
);
331 write_type_right(h
, t
, is_field
);
334 void write_type_def_or_decl(FILE *f
, type_t
*t
, int field
, const char *fmt
, ...)
338 write_type_v(f
, t
, field
, FALSE
, fmt
, args
);
342 void write_type_decl(FILE *f
, type_t
*t
, const char *fmt
, ...)
346 write_type_v(f
, t
, FALSE
, TRUE
, fmt
, args
);
350 void write_type_decl_left(FILE *f
, type_t
*t
)
352 write_type_left(f
, t
, TRUE
);
355 static int user_type_registered(const char *name
)
358 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
359 if (!strcmp(name
, ut
->name
))
364 static int context_handle_registered(const char *name
)
366 context_handle_t
*ch
;
367 LIST_FOR_EACH_ENTRY(ch
, &context_handle_list
, context_handle_t
, entry
)
368 if (!strcmp(name
, ch
->name
))
373 static int generic_handle_registered(const char *name
)
375 generic_handle_t
*gh
;
376 LIST_FOR_EACH_ENTRY(gh
, &generic_handle_list
, generic_handle_t
, entry
)
377 if (!strcmp(name
, gh
->name
))
382 /* check for types which require additional prototypes to be generated in the
384 void check_for_additional_prototype_types(const var_list_t
*list
)
389 LIST_FOR_EACH_ENTRY( v
, list
, const var_t
, entry
)
392 for (type
= v
->type
; type
; type
= type
->kind
== TKIND_ALIAS
? type
->orig
: type
->ref
) {
393 const char *name
= type
->name
;
394 if (type
->user_types_registered
) continue;
395 type
->user_types_registered
= 1;
396 if (is_attr(type
->attrs
, ATTR_CONTEXTHANDLE
)) {
397 if (!context_handle_registered(name
))
399 context_handle_t
*ch
= xmalloc(sizeof(*ch
));
400 ch
->name
= xstrdup(name
);
401 list_add_tail(&context_handle_list
, &ch
->entry
);
403 /* don't carry on parsing fields within this type */
406 if (type
->type
!= RPC_FC_BIND_PRIMITIVE
&& is_attr(type
->attrs
, ATTR_HANDLE
)) {
407 if (!generic_handle_registered(name
))
409 generic_handle_t
*gh
= xmalloc(sizeof(*gh
));
410 gh
->name
= xstrdup(name
);
411 list_add_tail(&generic_handle_list
, &gh
->entry
);
413 /* don't carry on parsing fields within this type */
416 if (is_attr(type
->attrs
, ATTR_WIREMARSHAL
)) {
417 if (!user_type_registered(name
))
419 user_type_t
*ut
= xmalloc(sizeof *ut
);
420 ut
->name
= xstrdup(name
);
421 list_add_tail(&user_type_list
, &ut
->entry
);
423 /* don't carry on parsing fields within this type as we are already
424 * using a wire marshaled type */
429 check_for_additional_prototype_types(type
->fields_or_args
);
435 void write_user_types(void)
438 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
440 const char *name
= ut
->name
;
441 fprintf(header
, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name
, name
);
442 fprintf(header
, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name
, name
);
443 fprintf(header
, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name
, name
);
444 fprintf(header
, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name
, name
);
448 void write_context_handle_rundowns(void)
450 context_handle_t
*ch
;
451 LIST_FOR_EACH_ENTRY(ch
, &context_handle_list
, context_handle_t
, entry
)
453 const char *name
= ch
->name
;
454 fprintf(header
, "void __RPC_USER %s_rundown(%s);\n", name
, name
);
458 void write_generic_handle_routines(void)
460 generic_handle_t
*gh
;
461 LIST_FOR_EACH_ENTRY(gh
, &generic_handle_list
, generic_handle_t
, entry
)
463 const char *name
= gh
->name
;
464 fprintf(header
, "handle_t __RPC_USER %s_bind(%s);\n", name
, name
);
465 fprintf(header
, "void __RPC_USER %s_unbind(%s, handle_t);\n", name
, name
);
469 void write_typedef(type_t
*type
)
471 fprintf(header
, "typedef ");
472 write_type_def_or_decl(header
, type
->orig
, FALSE
, "%s", type
->name
);
473 fprintf(header
, ";\n");
476 void write_constdef(const var_t
*v
)
478 fprintf(header
, "#define %s (", v
->name
);
479 write_expr(header
, v
->eval
, 0, 1, NULL
, NULL
);
480 fprintf(header
, ")\n\n");
483 void write_externdef(const var_t
*v
)
485 fprintf(header
, "extern const ");
486 write_type_def_or_decl(header
, v
->type
, FALSE
, "%s", v
->name
);
487 fprintf(header
, ";\n\n");
490 void write_library(const typelib_t
*typelib
)
492 const UUID
*uuid
= get_attrp(typelib
->attrs
, ATTR_UUID
);
493 fprintf(header
, "\n");
494 write_guid(header
, "LIBID", typelib
->name
, uuid
);
495 fprintf(header
, "\n");
499 const var_t
* get_explicit_handle_var(const func_t
* func
)
506 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
507 if (var
->type
->type
== RPC_FC_BIND_PRIMITIVE
)
513 const type_t
* get_explicit_generic_handle_type(const var_t
* var
)
516 for (t
= var
->type
; is_ptr(t
); t
= t
->ref
)
517 if (t
->type
!= RPC_FC_BIND_PRIMITIVE
&& is_attr(t
->attrs
, ATTR_HANDLE
))
522 const var_t
* get_explicit_generic_handle_var(const func_t
* func
)
529 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
530 if (get_explicit_generic_handle_type(var
))
536 const var_t
* get_context_handle_var(const func_t
* func
)
543 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
544 if (is_attr(var
->attrs
, ATTR_IN
) && is_context_handle(var
->type
))
550 int has_out_arg_or_return(const func_t
*func
)
554 if (!is_void(get_func_return_type(func
)))
560 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
561 if (is_attr(var
->attrs
, ATTR_OUT
))
568 /********** INTERFACES **********/
570 int is_object(const attr_list_t
*list
)
573 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
574 if (attr
->type
== ATTR_OBJECT
|| attr
->type
== ATTR_ODL
) return 1;
578 int is_local(const attr_list_t
*a
)
580 return is_attr(a
, ATTR_LOCAL
);
583 const var_t
*is_callas(const attr_list_t
*a
)
585 return get_attrp(a
, ATTR_CALLAS
);
588 static void write_method_macro(const type_t
*iface
, const char *name
)
592 if (iface
->ref
) write_method_macro(iface
->ref
, name
);
594 if (!iface
->funcs
) return;
596 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
597 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
599 var_t
*def
= cur
->def
;
600 if (!is_callas(def
->attrs
)) {
603 fprintf(header
, "#define %s_", name
);
604 write_name(header
,def
);
605 fprintf(header
, "(This");
607 LIST_FOR_EACH_ENTRY( arg
, cur
->args
, const var_t
, entry
)
608 fprintf(header
, ",%s", arg
->name
);
609 fprintf(header
, ") ");
611 fprintf(header
, "(This)->lpVtbl->");
612 write_name(header
, def
);
613 fprintf(header
, "(This");
615 LIST_FOR_EACH_ENTRY( arg
, cur
->args
, const var_t
, entry
)
616 fprintf(header
, ",%s", arg
->name
);
617 fprintf(header
, ")\n");
622 void write_args(FILE *h
, const var_list_t
*args
, const char *name
, int method
, int do_indent
)
633 fprintf(h
, "%s* This", name
);
636 if (args
) LIST_FOR_EACH_ENTRY( arg
, args
, const var_t
, entry
) {
643 else fprintf(h
, ",");
645 write_type_decl(h
, arg
->type
, "%s", arg
->name
);
648 if (do_indent
) indentation
--;
651 static void write_cpp_method_def(const type_t
*iface
)
655 if (!iface
->funcs
) return;
657 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
659 var_t
*def
= cur
->def
;
660 if (!is_callas(def
->attrs
)) {
661 const char *callconv
= get_attrp(def
->type
->attrs
, ATTR_CALLCONV
);
662 if (!callconv
) callconv
= "";
664 fprintf(header
, "virtual ");
665 write_type_decl_left(header
, get_func_return_type(cur
));
666 fprintf(header
, " %s ", callconv
);
667 write_name(header
, def
);
668 fprintf(header
, "(\n");
669 write_args(header
, cur
->args
, iface
->name
, 2, TRUE
);
670 fprintf(header
, ") = 0;\n");
671 fprintf(header
, "\n");
676 static void do_write_c_method_def(const type_t
*iface
, const char *name
)
680 if (iface
->ref
) do_write_c_method_def(iface
->ref
, name
);
682 if (!iface
->funcs
) return;
684 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
685 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
687 const var_t
*def
= cur
->def
;
688 if (!is_callas(def
->attrs
)) {
689 const char *callconv
= get_attrp(def
->type
->attrs
, ATTR_CALLCONV
);
690 if (!callconv
) callconv
= "";
692 write_type_decl_left(header
, get_func_return_type(cur
));
693 fprintf(header
, " (%s *", callconv
);
694 write_name(header
, def
);
695 fprintf(header
, ")(\n");
696 write_args(header
, cur
->args
, name
, 1, TRUE
);
697 fprintf(header
, ");\n");
698 fprintf(header
, "\n");
703 static void write_c_method_def(const type_t
*iface
)
705 do_write_c_method_def(iface
, iface
->name
);
708 static void write_c_disp_method_def(const type_t
*iface
)
710 do_write_c_method_def(iface
->ref
, iface
->name
);
713 static void write_method_proto(const type_t
*iface
)
717 if (!iface
->funcs
) return;
718 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
720 const var_t
*def
= cur
->def
;
722 if (!is_local(def
->attrs
)) {
723 const char *callconv
= get_attrp(def
->type
->attrs
, ATTR_CALLCONV
);
724 if (!callconv
) callconv
= "";
725 /* proxy prototype */
726 write_type_decl_left(header
, get_func_return_type(cur
));
727 fprintf(header
, " %s %s_", callconv
, iface
->name
);
728 write_name(header
, def
);
729 fprintf(header
, "_Proxy(\n");
730 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
731 fprintf(header
, ");\n");
733 fprintf(header
, "void __RPC_STUB %s_", iface
->name
);
734 write_name(header
,def
);
735 fprintf(header
, "_Stub(\n");
736 fprintf(header
, " IRpcStubBuffer* This,\n");
737 fprintf(header
, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
738 fprintf(header
, " PRPC_MESSAGE pRpcMessage,\n");
739 fprintf(header
, " DWORD* pdwStubPhase);\n");
744 void write_locals(FILE *fp
, const type_t
*iface
, int body
)
746 static const char comment
[]
747 = "/* WIDL-generated stub. You must provide an implementation for this. */";
748 const func_list_t
*funcs
= iface
->funcs
;
751 if (!is_object(iface
->attrs
) || !funcs
)
754 LIST_FOR_EACH_ENTRY(cur
, funcs
, const func_t
, entry
) {
755 const var_t
*def
= cur
->def
;
756 const var_t
*cas
= is_callas(def
->attrs
);
760 LIST_FOR_EACH_ENTRY(m
, iface
->funcs
, const func_t
, entry
)
761 if (!strcmp(m
->def
->name
, cas
->name
))
763 if (&m
->entry
!= iface
->funcs
) {
764 const var_t
*mdef
= m
->def
;
765 /* proxy prototype - use local prototype */
766 write_type_decl_left(fp
, get_func_return_type(m
));
767 fprintf(fp
, " CALLBACK %s_", iface
->name
);
768 write_name(fp
, mdef
);
769 fprintf(fp
, "_Proxy(\n");
770 write_args(fp
, m
->args
, iface
->name
, 1, TRUE
);
773 type_t
*rt
= get_func_return_type(m
);
774 fprintf(fp
, "\n{\n");
775 fprintf(fp
, " %s\n", comment
);
776 if (rt
->name
&& strcmp(rt
->name
, "HRESULT") == 0)
777 fprintf(fp
, " return E_NOTIMPL;\n");
780 write_type_decl(fp
, rt
, "rv");
782 fprintf(fp
, " memset(&rv, 0, sizeof rv);\n");
783 fprintf(fp
, " return rv;\n");
785 fprintf(fp
, "}\n\n");
789 /* stub prototype - use remotable prototype */
790 write_type_decl_left(fp
, get_func_return_type(cur
));
791 fprintf(fp
, " __RPC_STUB %s_", iface
->name
);
792 write_name(fp
, mdef
);
793 fprintf(fp
, "_Stub(\n");
794 write_args(fp
, cur
->args
, iface
->name
, 1, TRUE
);
797 /* Remotable methods must all return HRESULTs. */
798 fprintf(fp
, "\n{\n %s\n return E_NOTIMPL;\n}\n\n", comment
);
803 error_loc("invalid call_as attribute (%s -> %s)\n", def
->name
, cas
->name
);
808 static void write_function_proto(const type_t
*iface
, const func_t
*fun
, const char *prefix
)
810 var_t
*def
= fun
->def
;
811 const char *callconv
= get_attrp(def
->type
->attrs
, ATTR_CALLCONV
);
813 /* FIXME: do we need to handle call_as? */
814 write_type_decl_left(header
, get_func_return_type(fun
));
815 fprintf(header
, " ");
816 if (callconv
) fprintf(header
, "%s ", callconv
);
817 write_prefix_name(header
, prefix
, def
);
818 fprintf(header
, "(\n");
820 write_args(header
, fun
->args
, iface
->name
, 0, TRUE
);
822 fprintf(header
, " void");
823 fprintf(header
, ");\n\n");
826 static void write_function_protos(const type_t
*iface
)
829 int prefixes_differ
= strcmp(prefix_client
, prefix_server
);
831 if (!iface
->funcs
) return;
832 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
834 if (prefixes_differ
) {
835 fprintf(header
, "/* client prototype */\n");
836 write_function_proto(iface
, cur
, prefix_client
);
837 fprintf(header
, "/* server prototype */\n");
839 write_function_proto(iface
, cur
, prefix_server
);
843 void write_forward(type_t
*iface
)
845 /* C/C++ forwards should only be written for object interfaces, so if we
846 * have a full definition we only write one if we find [object] among the
847 * attributes - however, if we don't have a full definition at this point
848 * (i.e. this is an IDL forward), then we also assume that it is an object
849 * interface, since non-object interfaces shouldn't need forwards */
850 if ((!iface
->defined
|| is_object(iface
->attrs
) || is_attr(iface
->attrs
, ATTR_DISPINTERFACE
))
851 && !iface
->written
) {
852 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", iface
->name
);
853 fprintf(header
, "#define __%s_FWD_DEFINED__\n", iface
->name
);
854 fprintf(header
, "typedef interface %s %s;\n", iface
->name
, iface
->name
);
855 fprintf(header
, "#endif\n\n" );
856 iface
->written
= TRUE
;
860 static void write_iface_guid(const type_t
*iface
)
862 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
863 write_guid(header
, "IID", iface
->name
, uuid
);
866 static void write_dispiface_guid(const type_t
*iface
)
868 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
869 write_guid(header
, "DIID", iface
->name
, uuid
);
872 static void write_coclass_guid(type_t
*cocl
)
874 const UUID
*uuid
= get_attrp(cocl
->attrs
, ATTR_UUID
);
875 write_guid(header
, "CLSID", cocl
->name
, uuid
);
878 static void write_com_interface(type_t
*iface
)
880 if (!iface
->funcs
&& !iface
->ref
) {
881 parser_warning("%s has no methods\n", iface
->name
);
885 fprintf(header
, "/*****************************************************************************\n");
886 fprintf(header
, " * %s interface\n", iface
->name
);
887 fprintf(header
, " */\n");
888 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
889 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
890 write_iface_guid(iface
);
891 write_forward(iface
);
893 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
896 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
897 fprintf(header
, "{\n");
899 write_cpp_method_def(iface
);
901 fprintf(header
, "};\n");
905 fprintf(header
, "interface %s\n", iface
->name
);
906 fprintf(header
, "{\n");
907 fprintf(header
, " BEGIN_INTERFACE\n");
908 fprintf(header
, "\n");
910 write_cpp_method_def(iface
);
912 fprintf(header
, " END_INTERFACE\n");
913 fprintf(header
, "};\n");
915 fprintf(header
, "#else\n");
917 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
919 fprintf(header
, " BEGIN_INTERFACE\n");
920 fprintf(header
, "\n");
921 write_c_method_def(iface
);
923 fprintf(header
, " END_INTERFACE\n");
924 fprintf(header
, "} %sVtbl;\n", iface
->name
);
925 fprintf(header
, "interface %s {\n", iface
->name
);
926 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
927 fprintf(header
, "};\n");
928 fprintf(header
, "\n");
929 fprintf(header
, "#ifdef COBJMACROS\n");
930 write_method_macro(iface
, iface
->name
);
931 fprintf(header
, "#endif\n");
932 fprintf(header
, "\n");
933 fprintf(header
, "#endif\n");
934 fprintf(header
, "\n");
935 write_method_proto(iface
);
936 write_locals(header
, iface
, FALSE
);
937 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
940 static void write_rpc_interface(const type_t
*iface
)
942 unsigned int ver
= get_attrv(iface
->attrs
, ATTR_VERSION
);
943 const char *var
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
944 static int allocate_written
= 0;
946 if (!allocate_written
)
948 allocate_written
= 1;
949 fprintf(header
, "void * __RPC_USER MIDL_user_allocate(size_t);\n");
950 fprintf(header
, "void __RPC_USER MIDL_user_free(void *);\n\n");
953 fprintf(header
, "/*****************************************************************************\n");
954 fprintf(header
, " * %s interface (v%d.%d)\n", iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
955 fprintf(header
, " */\n");
956 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
957 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
960 write_iface_guid(iface
);
961 if (var
) fprintf(header
, "extern handle_t %s;\n", var
);
964 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ClientIfHandle;\n", prefix_client
, iface
->name
);
965 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ServerIfHandle;\n", prefix_server
, iface
->name
);
969 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n",
970 prefix_client
, iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
971 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n",
972 prefix_server
, iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
974 write_function_protos(iface
);
976 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
978 /* FIXME: server/client code */
981 void write_interface(type_t
*iface
)
983 if (is_object(iface
->attrs
))
984 write_com_interface(iface
);
986 write_rpc_interface(iface
);
989 void write_dispinterface(type_t
*iface
)
991 fprintf(header
, "/*****************************************************************************\n");
992 fprintf(header
, " * %s dispinterface\n", iface
->name
);
993 fprintf(header
, " */\n");
994 fprintf(header
,"#ifndef __%s_DISPINTERFACE_DEFINED__\n", iface
->name
);
995 fprintf(header
,"#define __%s_DISPINTERFACE_DEFINED__\n\n", iface
->name
);
996 write_dispiface_guid(iface
);
997 write_forward(iface
);
999 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
1000 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
1001 fprintf(header
, "{\n");
1002 fprintf(header
, "};\n");
1003 fprintf(header
, "#else\n");
1005 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
1007 fprintf(header
, " BEGIN_INTERFACE\n");
1008 fprintf(header
, "\n");
1009 write_c_disp_method_def(iface
);
1011 fprintf(header
, " END_INTERFACE\n");
1012 fprintf(header
, "} %sVtbl;\n", iface
->name
);
1013 fprintf(header
, "interface %s {\n", iface
->name
);
1014 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
1015 fprintf(header
, "};\n");
1016 fprintf(header
, "\n");
1017 fprintf(header
, "#ifdef COBJMACROS\n");
1018 write_method_macro(iface
->ref
, iface
->name
);
1019 fprintf(header
, "#endif\n");
1020 fprintf(header
, "\n");
1021 fprintf(header
, "#endif\n");
1022 fprintf(header
, "\n");
1023 fprintf(header
,"#endif /* __%s_DISPINTERFACE_DEFINED__ */\n\n", iface
->name
);
1026 void write_coclass(type_t
*cocl
)
1028 fprintf(header
, "/*****************************************************************************\n");
1029 fprintf(header
, " * %s coclass\n", cocl
->name
);
1030 fprintf(header
, " */\n\n");
1031 write_coclass_guid(cocl
);
1032 fprintf(header
, "\n");
1035 void write_coclass_forward(type_t
*cocl
)
1037 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", cocl
->name
);
1038 fprintf(header
, "#define __%s_FWD_DEFINED__\n", cocl
->name
);
1039 fprintf(header
, "typedef struct %s %s;\n", cocl
->name
, cocl
->name
);
1040 fprintf(header
, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl
->name
);