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;
40 user_type_list_t user_type_list
= LIST_INIT(user_type_list
);
41 static context_handle_list_t context_handle_list
= LIST_INIT(context_handle_list
);
43 static void indent(FILE *h
, int delta
)
46 if (delta
< 0) indentation
+= delta
;
47 for (c
=0; c
<indentation
; c
++) fprintf(h
, " ");
48 if (delta
> 0) indentation
+= delta
;
51 int is_ptrchain_attr(const var_t
*var
, enum attr_type t
)
53 if (is_attr(var
->attrs
, t
))
57 type_t
*type
= var
->type
;
60 if (is_attr(type
->attrs
, t
))
62 else if (type
->kind
== TKIND_ALIAS
)
64 else if (is_ptr(type
))
71 int is_attr(const attr_list_t
*list
, enum attr_type t
)
74 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
75 if (attr
->type
== t
) return 1;
79 void *get_attrp(const attr_list_t
*list
, enum attr_type t
)
82 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
83 if (attr
->type
== t
) return attr
->u
.pval
;
87 unsigned long get_attrv(const attr_list_t
*list
, enum attr_type t
)
90 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
91 if (attr
->type
== t
) return attr
->u
.ival
;
95 int is_void(const type_t
*t
)
97 if (!t
->type
&& !t
->ref
) return 1;
101 int is_conformant_array(const type_t
*t
)
103 return t
->type
== RPC_FC_CARRAY
104 || t
->type
== RPC_FC_CVARRAY
105 || (t
->type
== RPC_FC_BOGUS_ARRAY
&& t
->size_is
);
108 void write_guid(FILE *f
, const char *guid_prefix
, const char *name
, const UUID
*uuid
)
111 fprintf(f
, "DEFINE_GUID(%s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
112 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
113 guid_prefix
, name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0],
114 uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5],
115 uuid
->Data4
[6], uuid
->Data4
[7]);
118 void write_name(FILE *h
, const var_t
*v
)
120 if (is_attr( v
->attrs
, ATTR_PROPGET
))
122 else if (is_attr( v
->attrs
, ATTR_PROPPUT
))
124 else if (is_attr( v
->attrs
, ATTR_PROPPUTREF
))
125 fprintf(h
, "putref_" );
126 fprintf(h
, "%s", v
->name
);
129 void write_prefix_name(FILE *h
, const char *prefix
, const var_t
*v
)
131 fprintf(h
, "%s", prefix
);
135 static void write_field(FILE *h
, var_t
*v
)
139 const char *name
= v
->name
;
141 switch (v
->type
->type
) {
143 case RPC_FC_CVSTRUCT
:
144 case RPC_FC_CPSTRUCT
:
147 case RPC_FC_BOGUS_STRUCT
:
148 case RPC_FC_ENCAPSULATED_UNION
:
149 name
= "DUMMYSTRUCTNAME";
151 case RPC_FC_NON_ENCAPSULATED_UNION
:
152 name
= "DUMMYUNIONNAME";
160 write_type_def_or_decl(h
, v
->type
, TRUE
, "%s", name
);
165 static void write_fields(FILE *h
, var_list_t
*fields
)
169 LIST_FOR_EACH_ENTRY( v
, fields
, var_t
, entry
) write_field(h
, v
);
172 static void write_enums(FILE *h
, var_list_t
*enums
)
176 LIST_FOR_EACH_ENTRY( v
, enums
, var_t
, entry
)
183 write_expr(h
, v
->eval
, 0);
186 if (list_next( enums
, &v
->entry
)) fprintf(h
, ",\n");
191 int needs_space_after(type_t
*t
)
193 return (t
->kind
== TKIND_ALIAS
194 || (!is_ptr(t
) && (!is_conformant_array(t
) || t
->declarray
)));
197 void write_type_left(FILE *h
, type_t
*t
, int declonly
)
201 if (t
->is_const
) fprintf(h
, "const ");
203 if (t
->kind
== TKIND_ALIAS
) fprintf(h
, "%s", t
->name
);
204 else if (t
->declarray
) write_type_left(h
, t
->ref
, declonly
);
206 if (t
->sign
> 0) fprintf(h
, "signed ");
207 else if (t
->sign
< 0) fprintf(h
, "unsigned ");
211 if (!declonly
&& t
->defined
&& !t
->written
&& !t
->ignore
) {
212 if (t
->name
) fprintf(h
, "enum %s {\n", t
->name
);
213 else fprintf(h
, "enum {\n");
216 write_enums(h
, t
->fields
);
220 else fprintf(h
, "enum %s", t
->name
? t
->name
: "");
223 case RPC_FC_CVSTRUCT
:
224 case RPC_FC_CPSTRUCT
:
227 case RPC_FC_BOGUS_STRUCT
:
228 case RPC_FC_ENCAPSULATED_UNION
:
229 if (!declonly
&& t
->defined
&& !t
->written
&& !t
->ignore
) {
230 if (t
->name
) fprintf(h
, "struct %s {\n", t
->name
);
231 else fprintf(h
, "struct {\n");
234 write_fields(h
, t
->fields
);
238 else fprintf(h
, "struct %s", t
->name
? t
->name
: "");
240 case RPC_FC_NON_ENCAPSULATED_UNION
:
241 if (!declonly
&& t
->defined
&& !t
->written
&& !t
->ignore
) {
242 if (t
->name
) fprintf(h
, "union %s {\n", t
->name
);
243 else fprintf(h
, "union {\n");
246 write_fields(h
, t
->fields
);
250 else fprintf(h
, "union %s", t
->name
? t
->name
: "");
258 case RPC_FC_BOGUS_ARRAY
:
259 write_type_left(h
, t
->ref
, declonly
);
260 fprintf(h
, "%s*", needs_space_after(t
->ref
) ? " " : "");
263 fprintf(h
, "%s", t
->name
);
268 void write_type_right(FILE *h
, type_t
*t
, int is_field
)
273 if (is_conformant_array(t
)) {
274 fprintf(h
, "[%s]", is_field
? "1" : "");
277 for ( ; t
->declarray
; t
= t
->ref
)
278 fprintf(h
, "[%lu]", t
->dim
);
282 void write_type_v(FILE *h
, type_t
*t
, int is_field
, int declonly
,
283 const char *fmt
, va_list args
)
287 write_type_left(h
, t
, declonly
);
289 if (needs_space_after(t
))
291 vfprintf(h
, fmt
, args
);
293 write_type_right(h
, t
, is_field
);
296 void write_type_def_or_decl(FILE *f
, type_t
*t
, int field
, const char *fmt
, ...)
300 write_type_v(f
, t
, field
, FALSE
, fmt
, args
);
304 void write_type_decl(FILE *f
, type_t
*t
, const char *fmt
, ...)
308 write_type_v(f
, t
, FALSE
, TRUE
, fmt
, args
);
312 void write_type_decl_left(FILE *f
, type_t
*t
)
314 write_type_left(f
, t
, TRUE
);
317 static int user_type_registered(const char *name
)
320 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
321 if (!strcmp(name
, ut
->name
))
326 static int context_handle_registered(const char *name
)
328 context_handle_t
*ch
;
329 LIST_FOR_EACH_ENTRY(ch
, &context_handle_list
, context_handle_t
, entry
)
330 if (!strcmp(name
, ch
->name
))
335 void check_for_user_types_and_context_handles(const var_list_t
*list
)
340 LIST_FOR_EACH_ENTRY( v
, list
, const var_t
, entry
)
343 for (type
= v
->type
; type
; type
= type
->kind
== TKIND_ALIAS
? type
->orig
: type
->ref
) {
344 const char *name
= type
->name
;
345 if (type
->user_types_registered
) continue;
346 type
->user_types_registered
= 1;
347 if (is_attr(type
->attrs
, ATTR_CONTEXTHANDLE
)) {
348 if (!context_handle_registered(name
))
350 context_handle_t
*ch
= xmalloc(sizeof(*ch
));
351 ch
->name
= xstrdup(name
);
352 list_add_tail(&context_handle_list
, &ch
->entry
);
354 /* don't carry on parsing fields within this type */
357 if (is_attr(type
->attrs
, ATTR_WIREMARSHAL
)) {
358 if (!user_type_registered(name
))
360 user_type_t
*ut
= xmalloc(sizeof *ut
);
361 ut
->name
= xstrdup(name
);
362 list_add_tail(&user_type_list
, &ut
->entry
);
364 /* don't carry on parsing fields within this type as we are already
365 * using a wire marshaled type */
370 check_for_user_types_and_context_handles(type
->fields
);
376 void write_user_types(void)
379 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
381 const char *name
= ut
->name
;
382 fprintf(header
, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name
, name
);
383 fprintf(header
, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name
, name
);
384 fprintf(header
, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name
, name
);
385 fprintf(header
, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name
, name
);
389 void write_context_handle_rundowns(void)
391 context_handle_t
*ch
;
392 LIST_FOR_EACH_ENTRY(ch
, &context_handle_list
, context_handle_t
, entry
)
394 const char *name
= ch
->name
;
395 fprintf(header
, "void __RPC_USER %s_rundown(%s);\n", name
, name
);
399 void write_typedef(type_t
*type
)
401 fprintf(header
, "typedef ");
402 write_type_def_or_decl(header
, type
->orig
, FALSE
, "%s", type
->name
);
403 fprintf(header
, ";\n");
406 void write_expr(FILE *h
, const expr_t
*e
, int brackets
)
412 fprintf(h
, "%lu", e
->u
.lval
);
415 fprintf(h
, "0x%lx", e
->u
.lval
);
418 fprintf(h
, "%#.15g", e
->u
.dval
);
426 case EXPR_IDENTIFIER
:
427 fprintf(h
, "%s", e
->u
.sval
);
431 write_expr(h
, e
->ref
, 1);
435 write_expr(h
, e
->ref
, 1);
439 write_expr(h
, e
->ref
, 1);
443 write_type_decl(h
, e
->u
.tref
, NULL
);
445 write_expr(h
, e
->ref
, 1);
448 fprintf(h
, "sizeof(");
449 write_type_decl(h
, e
->u
.tref
, NULL
);
460 if (brackets
) fprintf(h
, "(");
461 write_expr(h
, e
->ref
, 1);
463 case EXPR_SHL
: fprintf(h
, " << "); break;
464 case EXPR_SHR
: fprintf(h
, " >> "); break;
465 case EXPR_MUL
: fprintf(h
, " * "); break;
466 case EXPR_DIV
: fprintf(h
, " / "); break;
467 case EXPR_ADD
: fprintf(h
, " + "); break;
468 case EXPR_SUB
: fprintf(h
, " - "); break;
469 case EXPR_AND
: fprintf(h
, " & "); break;
470 case EXPR_OR
: fprintf(h
, " | "); break;
473 write_expr(h
, e
->u
.ext
, 1);
474 if (brackets
) fprintf(h
, ")");
477 if (brackets
) fprintf(h
, "(");
478 write_expr(h
, e
->ref
, 1);
480 write_expr(h
, e
->u
.ext
, 1);
482 write_expr(h
, e
->ext2
, 1);
483 if (brackets
) fprintf(h
, ")");
487 write_expr(h
, e
->ref
, 1);
492 void write_constdef(const var_t
*v
)
494 fprintf(header
, "#define %s (", v
->name
);
495 write_expr(header
, v
->eval
, 0);
496 fprintf(header
, ")\n\n");
499 void write_externdef(const var_t
*v
)
501 fprintf(header
, "extern const ");
502 write_type_def_or_decl(header
, v
->type
, FALSE
, "%s", v
->name
);
503 fprintf(header
, ";\n\n");
506 void write_library(const char *name
, const attr_list_t
*attr
)
508 const UUID
*uuid
= get_attrp(attr
, ATTR_UUID
);
509 fprintf(header
, "\n");
510 write_guid(header
, "LIBID", name
, uuid
);
511 fprintf(header
, "\n");
515 const var_t
* get_explicit_handle_var(const func_t
* func
)
522 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
523 if (var
->type
->type
== RPC_FC_BIND_PRIMITIVE
)
529 int has_out_arg_or_return(const func_t
*func
)
533 if (!is_void(func
->def
->type
))
539 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
540 if (is_attr(var
->attrs
, ATTR_OUT
))
547 /********** INTERFACES **********/
549 int is_object(const attr_list_t
*list
)
552 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
553 if (attr
->type
== ATTR_OBJECT
|| attr
->type
== ATTR_ODL
) return 1;
557 int is_local(const attr_list_t
*a
)
559 return is_attr(a
, ATTR_LOCAL
);
562 const var_t
*is_callas(const attr_list_t
*a
)
564 return get_attrp(a
, ATTR_CALLAS
);
567 static void write_method_macro(const type_t
*iface
, const char *name
)
571 if (iface
->ref
) write_method_macro(iface
->ref
, name
);
573 if (!iface
->funcs
) return;
575 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
576 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
578 var_t
*def
= cur
->def
;
579 if (!is_callas(def
->attrs
)) {
584 if (cur
->args
) LIST_FOR_EACH_ENTRY( arg
, cur
->args
, const var_t
, entry
) argc
++;
586 fprintf(header
, "#define %s_", name
);
587 write_name(header
,def
);
588 fprintf(header
, "(p");
589 for (c
=0; c
<argc
; c
++)
590 fprintf(header
, ",%c", c
+'a');
591 fprintf(header
, ") ");
593 fprintf(header
, "(p)->lpVtbl->");
594 write_name(header
, def
);
595 fprintf(header
, "(p");
596 for (c
=0; c
<argc
; c
++)
597 fprintf(header
, ",%c", c
+'a');
598 fprintf(header
, ")\n");
603 void write_args(FILE *h
, const var_list_t
*args
, const char *name
, int method
, int do_indent
)
614 fprintf(h
, "%s* This", name
);
617 if (args
) LIST_FOR_EACH_ENTRY( arg
, args
, const var_t
, entry
) {
624 else fprintf(h
, ",");
628 write_type_decl_left(h
, arg
->type
);
629 fprintf(h
, " (STDMETHODCALLTYPE *");
632 write_args(h
, arg
->args
, NULL
, 0, FALSE
);
636 write_type_decl(h
, arg
->type
, "%s", arg
->name
);
639 if (do_indent
) indentation
--;
642 static void write_cpp_method_def(const type_t
*iface
)
646 if (!iface
->funcs
) return;
648 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
650 var_t
*def
= cur
->def
;
651 if (!is_callas(def
->attrs
)) {
653 fprintf(header
, "virtual ");
654 write_type_decl_left(header
, def
->type
);
655 fprintf(header
, " STDMETHODCALLTYPE ");
656 write_name(header
, def
);
657 fprintf(header
, "(\n");
658 write_args(header
, cur
->args
, iface
->name
, 2, TRUE
);
659 fprintf(header
, ") = 0;\n");
660 fprintf(header
, "\n");
665 static void do_write_c_method_def(const type_t
*iface
, const char *name
)
669 if (iface
->ref
) do_write_c_method_def(iface
->ref
, name
);
671 if (!iface
->funcs
) return;
673 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
674 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
676 const var_t
*def
= cur
->def
;
677 if (!is_callas(def
->attrs
)) {
679 write_type_decl_left(header
, def
->type
);
680 fprintf(header
, " (STDMETHODCALLTYPE *");
681 write_name(header
, def
);
682 fprintf(header
, ")(\n");
683 write_args(header
, cur
->args
, name
, 1, TRUE
);
684 fprintf(header
, ");\n");
685 fprintf(header
, "\n");
690 static void write_c_method_def(const type_t
*iface
)
692 do_write_c_method_def(iface
, iface
->name
);
695 static void write_c_disp_method_def(const type_t
*iface
)
697 do_write_c_method_def(iface
->ref
, iface
->name
);
700 static void write_method_proto(const type_t
*iface
)
704 if (!iface
->funcs
) return;
705 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
707 const var_t
*def
= cur
->def
;
709 if (!is_local(def
->attrs
)) {
710 /* proxy prototype */
711 write_type_decl_left(header
, def
->type
);
712 fprintf(header
, " CALLBACK %s_", iface
->name
);
713 write_name(header
, def
);
714 fprintf(header
, "_Proxy(\n");
715 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
716 fprintf(header
, ");\n");
718 fprintf(header
, "void __RPC_STUB %s_", iface
->name
);
719 write_name(header
,def
);
720 fprintf(header
, "_Stub(\n");
721 fprintf(header
, " IRpcStubBuffer* This,\n");
722 fprintf(header
, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
723 fprintf(header
, " PRPC_MESSAGE pRpcMessage,\n");
724 fprintf(header
, " DWORD* pdwStubPhase);\n");
729 void write_locals(FILE *fp
, const type_t
*iface
, int body
)
731 static const char comment
[]
732 = "/* WIDL-generated stub. You must provide an implementation for this. */";
733 const func_list_t
*funcs
= iface
->funcs
;
736 if (!is_object(iface
->attrs
) || !funcs
)
739 LIST_FOR_EACH_ENTRY(cur
, funcs
, const func_t
, entry
) {
740 const var_t
*def
= cur
->def
;
741 const var_t
*cas
= is_callas(def
->attrs
);
745 LIST_FOR_EACH_ENTRY(m
, iface
->funcs
, const func_t
, entry
)
746 if (!strcmp(m
->def
->name
, cas
->name
))
748 if (&m
->entry
!= iface
->funcs
) {
749 const var_t
*mdef
= m
->def
;
750 /* proxy prototype - use local prototype */
751 write_type_decl_left(fp
, mdef
->type
);
752 fprintf(fp
, " CALLBACK %s_", iface
->name
);
753 write_name(fp
, mdef
);
754 fprintf(fp
, "_Proxy(\n");
755 write_args(fp
, m
->args
, iface
->name
, 1, TRUE
);
758 type_t
*rt
= mdef
->type
;
759 fprintf(fp
, "\n{\n");
760 fprintf(fp
, " %s\n", comment
);
761 if (rt
->name
&& strcmp(rt
->name
, "HRESULT") == 0)
762 fprintf(fp
, " return E_NOTIMPL;\n");
765 write_type_decl(fp
, rt
, "rv");
767 fprintf(fp
, " memset(&rv, 0, sizeof rv);\n");
768 fprintf(fp
, " return rv;\n");
770 fprintf(fp
, "}\n\n");
774 /* stub prototype - use remotable prototype */
775 write_type_decl_left(fp
, def
->type
);
776 fprintf(fp
, " __RPC_STUB %s_", iface
->name
);
777 write_name(fp
, mdef
);
778 fprintf(fp
, "_Stub(\n");
779 write_args(fp
, cur
->args
, iface
->name
, 1, TRUE
);
782 /* Remotable methods must all return HRESULTs. */
783 fprintf(fp
, "\n{\n %s\n return E_NOTIMPL;\n}\n\n", comment
);
788 error_loc("invalid call_as attribute (%s -> %s)\n", def
->name
, cas
->name
);
793 static void write_function_proto(const type_t
*iface
, const func_t
*fun
, const char *prefix
)
795 var_t
*def
= fun
->def
;
797 /* FIXME: do we need to handle call_as? */
798 write_type_decl_left(header
, def
->type
);
799 fprintf(header
, " ");
800 write_prefix_name(header
, prefix
, def
);
801 fprintf(header
, "(\n");
803 write_args(header
, fun
->args
, iface
->name
, 0, TRUE
);
805 fprintf(header
, " void");
806 fprintf(header
, ");\n");
809 static void write_function_protos(const type_t
*iface
)
811 const char *implicit_handle
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
812 int explicit_handle
= is_attr(iface
->attrs
, ATTR_EXPLICIT_HANDLE
);
813 const var_t
* explicit_handle_var
;
815 int prefixes_differ
= strcmp(prefix_client
, prefix_server
);
817 if (!iface
->funcs
) return;
818 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
820 var_t
*def
= cur
->def
;
822 /* check for a defined binding handle */
823 explicit_handle_var
= get_explicit_handle_var(cur
);
824 if (explicit_handle
) {
825 if (!explicit_handle_var
) {
826 error("%s() does not define an explicit binding handle!\n", def
->name
);
829 } else if (implicit_handle
) {
830 if (explicit_handle_var
) {
831 error("%s() must not define a binding handle!\n", def
->name
);
836 if (prefixes_differ
) {
837 fprintf(header
, "/* client prototype */\n");
838 write_function_proto(iface
, cur
, prefix_client
);
839 fprintf(header
, "/* server prototype */\n");
841 write_function_proto(iface
, cur
, prefix_server
);
845 void write_forward(type_t
*iface
)
847 /* C/C++ forwards should only be written for object interfaces, so if we
848 * have a full definition we only write one if we find [object] among the
849 * attributes - however, if we don't have a full definition at this point
850 * (i.e. this is an IDL forward), then we also assume that it is an object
851 * interface, since non-object interfaces shouldn't need forwards */
852 if ((!iface
->defined
|| is_object(iface
->attrs
) || is_attr(iface
->attrs
, ATTR_DISPINTERFACE
))
853 && !iface
->written
) {
854 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", iface
->name
);
855 fprintf(header
, "#define __%s_FWD_DEFINED__\n", iface
->name
);
856 fprintf(header
, "typedef interface %s %s;\n", iface
->name
, iface
->name
);
857 fprintf(header
, "#endif\n\n" );
858 iface
->written
= TRUE
;
862 static void write_iface_guid(const type_t
*iface
)
864 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
865 write_guid(header
, "IID", iface
->name
, uuid
);
868 static void write_dispiface_guid(const type_t
*iface
)
870 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
871 write_guid(header
, "DIID", iface
->name
, uuid
);
874 static void write_coclass_guid(type_t
*cocl
)
876 const UUID
*uuid
= get_attrp(cocl
->attrs
, ATTR_UUID
);
877 write_guid(header
, "CLSID", cocl
->name
, uuid
);
880 static void write_com_interface(type_t
*iface
)
882 if (!iface
->funcs
&& !iface
->ref
) {
883 parser_warning("%s has no methods\n", iface
->name
);
887 fprintf(header
, "/*****************************************************************************\n");
888 fprintf(header
, " * %s interface\n", iface
->name
);
889 fprintf(header
, " */\n");
890 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
891 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
892 write_iface_guid(iface
);
893 write_forward(iface
);
895 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
898 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
899 fprintf(header
, "{\n");
901 write_cpp_method_def(iface
);
903 fprintf(header
, "};\n");
907 fprintf(header
, "interface %s\n", iface
->name
);
908 fprintf(header
, "{\n");
909 fprintf(header
, " BEGIN_INTERFACE\n");
910 fprintf(header
, "\n");
912 write_cpp_method_def(iface
);
914 fprintf(header
, " END_INTERFACE\n");
915 fprintf(header
, "};\n");
917 fprintf(header
, "#else\n");
919 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
921 fprintf(header
, " BEGIN_INTERFACE\n");
922 fprintf(header
, "\n");
923 write_c_method_def(iface
);
925 fprintf(header
, " END_INTERFACE\n");
926 fprintf(header
, "} %sVtbl;\n", iface
->name
);
927 fprintf(header
, "interface %s {\n", iface
->name
);
928 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
929 fprintf(header
, "};\n");
930 fprintf(header
, "\n");
931 fprintf(header
, "#ifdef COBJMACROS\n");
932 write_method_macro(iface
, iface
->name
);
933 fprintf(header
, "#endif\n");
934 fprintf(header
, "\n");
935 fprintf(header
, "#endif\n");
936 fprintf(header
, "\n");
937 write_method_proto(iface
);
938 write_locals(header
, iface
, FALSE
);
939 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
942 static void write_rpc_interface(const type_t
*iface
)
944 unsigned int ver
= get_attrv(iface
->attrs
, ATTR_VERSION
);
945 const char *var
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
946 static int allocate_written
= 0;
948 if (!allocate_written
)
950 allocate_written
= 1;
951 fprintf(header
, "void * __RPC_USER MIDL_user_allocate(size_t);\n");
952 fprintf(header
, "void __RPC_USER MIDL_user_free(void *);\n\n");
955 fprintf(header
, "/*****************************************************************************\n");
956 fprintf(header
, " * %s interface (v%d.%d)\n", iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
957 fprintf(header
, " */\n");
958 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
959 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
962 write_iface_guid(iface
);
963 if (var
) fprintf(header
, "extern handle_t %s;\n", var
);
966 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ClientIfHandle;\n", prefix_client
, iface
->name
);
967 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ServerIfHandle;\n", prefix_server
, iface
->name
);
971 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n",
972 prefix_client
, iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
973 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n",
974 prefix_server
, iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
976 write_function_protos(iface
);
978 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
980 /* FIXME: server/client code */
983 void write_interface(type_t
*iface
)
985 if (is_object(iface
->attrs
))
986 write_com_interface(iface
);
988 write_rpc_interface(iface
);
991 void write_dispinterface(type_t
*iface
)
993 fprintf(header
, "/*****************************************************************************\n");
994 fprintf(header
, " * %s dispinterface\n", iface
->name
);
995 fprintf(header
, " */\n");
996 fprintf(header
,"#ifndef __%s_DISPINTERFACE_DEFINED__\n", iface
->name
);
997 fprintf(header
,"#define __%s_DISPINTERFACE_DEFINED__\n\n", iface
->name
);
998 write_dispiface_guid(iface
);
999 write_forward(iface
);
1001 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
1002 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
1003 fprintf(header
, "{\n");
1004 fprintf(header
, "};\n");
1005 fprintf(header
, "#else\n");
1007 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
1009 fprintf(header
, " BEGIN_INTERFACE\n");
1010 fprintf(header
, "\n");
1011 write_c_disp_method_def(iface
);
1013 fprintf(header
, " END_INTERFACE\n");
1014 fprintf(header
, "} %sVtbl;\n", iface
->name
);
1015 fprintf(header
, "interface %s {\n", iface
->name
);
1016 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
1017 fprintf(header
, "};\n");
1018 fprintf(header
, "\n");
1019 fprintf(header
, "#ifdef COBJMACROS\n");
1020 write_method_macro(iface
->ref
, iface
->name
);
1021 fprintf(header
, "#endif\n");
1022 fprintf(header
, "\n");
1023 fprintf(header
, "#endif\n");
1024 fprintf(header
, "\n");
1025 fprintf(header
,"#endif /* __%s_DISPINTERFACE_DEFINED__ */\n\n", iface
->name
);
1028 void write_coclass(type_t
*cocl
)
1030 fprintf(header
, "/*****************************************************************************\n");
1031 fprintf(header
, " * %s coclass\n", cocl
->name
);
1032 fprintf(header
, " */\n\n");
1033 write_coclass_guid(cocl
);
1034 fprintf(header
, "\n");
1037 void write_coclass_forward(type_t
*cocl
)
1039 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", cocl
->name
);
1040 fprintf(header
, "#define __%s_FWD_DEFINED__\n", cocl
->name
);
1041 fprintf(header
, "typedef struct %s %s;\n", cocl
->name
, cocl
->name
);
1042 fprintf(header
, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl
->name
);