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
37 static int indentation
= 0;
38 user_type_list_t user_type_list
= LIST_INIT(user_type_list
);
39 static context_handle_list_t context_handle_list
= LIST_INIT(context_handle_list
);
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 type_t
*t
)
101 return t
->type
== RPC_FC_CARRAY
102 || t
->type
== RPC_FC_CVARRAY
103 || (t
->type
== RPC_FC_BOGUS_ARRAY
&& t
->size_is
);
106 void write_guid(FILE *f
, const char *guid_prefix
, const char *name
, const UUID
*uuid
)
109 fprintf(f
, "DEFINE_GUID(%s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
110 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
111 guid_prefix
, name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0],
112 uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5],
113 uuid
->Data4
[6], uuid
->Data4
[7]);
116 void write_name(FILE *h
, const var_t
*v
)
118 if (is_attr( v
->attrs
, ATTR_PROPGET
))
120 else if (is_attr( v
->attrs
, ATTR_PROPPUT
))
122 else if (is_attr( v
->attrs
, ATTR_PROPPUTREF
))
123 fprintf(h
, "putref_" );
124 fprintf(h
, "%s", v
->name
);
127 void write_prefix_name(FILE *h
, const char *prefix
, const var_t
*v
)
129 fprintf(h
, "%s", prefix
);
133 static void write_field(FILE *h
, var_t
*v
)
137 const char *name
= v
->name
;
139 switch (v
->type
->type
) {
141 case RPC_FC_CVSTRUCT
:
142 case RPC_FC_CPSTRUCT
:
145 case RPC_FC_BOGUS_STRUCT
:
146 case RPC_FC_ENCAPSULATED_UNION
:
147 name
= "DUMMYSTRUCTNAME";
149 case RPC_FC_NON_ENCAPSULATED_UNION
:
150 name
= "DUMMYUNIONNAME";
158 write_type_def_or_decl(h
, v
->type
, TRUE
, "%s", name
);
163 static void write_fields(FILE *h
, var_list_t
*fields
)
167 LIST_FOR_EACH_ENTRY( v
, fields
, var_t
, entry
) write_field(h
, v
);
170 static void write_enums(FILE *h
, var_list_t
*enums
)
174 LIST_FOR_EACH_ENTRY( v
, enums
, var_t
, entry
)
181 write_expr(h
, v
->eval
, 0);
184 if (list_next( enums
, &v
->entry
)) fprintf(h
, ",\n");
189 int needs_space_after(type_t
*t
)
191 return (t
->kind
== TKIND_ALIAS
192 || (!is_ptr(t
) && (!is_conformant_array(t
) || t
->declarray
)));
195 void write_type_left(FILE *h
, type_t
*t
, int declonly
)
199 if (t
->is_const
) fprintf(h
, "const ");
201 if (t
->kind
== TKIND_ALIAS
) fprintf(h
, "%s", t
->name
);
202 else if (t
->declarray
) write_type_left(h
, t
->ref
, declonly
);
204 if (t
->sign
> 0) fprintf(h
, "signed ");
205 else if (t
->sign
< 0) fprintf(h
, "unsigned ");
209 if (!declonly
&& t
->defined
&& !t
->written
&& !t
->ignore
) {
210 if (t
->name
) fprintf(h
, "enum %s {\n", t
->name
);
211 else fprintf(h
, "enum {\n");
214 write_enums(h
, t
->fields
);
218 else fprintf(h
, "enum %s", t
->name
? t
->name
: "");
221 case RPC_FC_CVSTRUCT
:
222 case RPC_FC_CPSTRUCT
:
225 case RPC_FC_BOGUS_STRUCT
:
226 case RPC_FC_ENCAPSULATED_UNION
:
227 if (!declonly
&& t
->defined
&& !t
->written
&& !t
->ignore
) {
228 if (t
->name
) fprintf(h
, "struct %s {\n", t
->name
);
229 else fprintf(h
, "struct {\n");
232 write_fields(h
, t
->fields
);
236 else fprintf(h
, "struct %s", t
->name
? t
->name
: "");
238 case RPC_FC_NON_ENCAPSULATED_UNION
:
239 if (!declonly
&& t
->defined
&& !t
->written
&& !t
->ignore
) {
240 if (t
->name
) fprintf(h
, "union %s {\n", t
->name
);
241 else fprintf(h
, "union {\n");
244 write_fields(h
, t
->fields
);
248 else fprintf(h
, "union %s", t
->name
? t
->name
: "");
256 case RPC_FC_BOGUS_ARRAY
:
257 write_type_left(h
, t
->ref
, declonly
);
258 fprintf(h
, "%s*", needs_space_after(t
->ref
) ? " " : "");
261 fprintf(h
, "%s", t
->name
);
266 void write_type_right(FILE *h
, type_t
*t
, int is_field
)
271 if (is_conformant_array(t
)) {
272 fprintf(h
, "[%s]", is_field
? "1" : "");
275 for ( ; t
->declarray
; t
= t
->ref
)
276 fprintf(h
, "[%lu]", t
->dim
);
280 void write_type_v(FILE *h
, type_t
*t
, int is_field
, int declonly
,
281 const char *fmt
, va_list args
)
285 write_type_left(h
, t
, declonly
);
287 if (needs_space_after(t
))
289 vfprintf(h
, fmt
, args
);
291 write_type_right(h
, t
, is_field
);
294 void write_type_def_or_decl(FILE *f
, type_t
*t
, int field
, const char *fmt
, ...)
298 write_type_v(f
, t
, field
, FALSE
, fmt
, args
);
302 void write_type_decl(FILE *f
, type_t
*t
, const char *fmt
, ...)
306 write_type_v(f
, t
, FALSE
, TRUE
, fmt
, args
);
310 void write_type_decl_left(FILE *f
, type_t
*t
)
312 write_type_left(f
, t
, TRUE
);
315 static int user_type_registered(const char *name
)
318 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
319 if (!strcmp(name
, ut
->name
))
324 static int context_handle_registered(const char *name
)
326 context_handle_t
*ch
;
327 LIST_FOR_EACH_ENTRY(ch
, &context_handle_list
, context_handle_t
, entry
)
328 if (!strcmp(name
, ch
->name
))
333 void check_for_user_types_and_context_handles(const var_list_t
*list
)
338 LIST_FOR_EACH_ENTRY( v
, list
, const var_t
, entry
)
341 for (type
= v
->type
; type
; type
= type
->kind
== TKIND_ALIAS
? type
->orig
: type
->ref
) {
342 const char *name
= type
->name
;
343 if (type
->user_types_registered
) continue;
344 type
->user_types_registered
= 1;
345 if (is_attr(type
->attrs
, ATTR_CONTEXTHANDLE
)) {
346 if (!context_handle_registered(name
))
348 context_handle_t
*ch
= xmalloc(sizeof(*ch
));
349 ch
->name
= xstrdup(name
);
350 list_add_tail(&context_handle_list
, &ch
->entry
);
352 /* don't carry on parsing fields within this type */
355 if (is_attr(type
->attrs
, ATTR_WIREMARSHAL
)) {
356 if (!user_type_registered(name
))
358 user_type_t
*ut
= xmalloc(sizeof *ut
);
359 ut
->name
= xstrdup(name
);
360 list_add_tail(&user_type_list
, &ut
->entry
);
362 /* don't carry on parsing fields within this type as we are already
363 * using a wire marshaled type */
368 check_for_user_types_and_context_handles(type
->fields
);
374 void write_user_types(void)
377 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
379 const char *name
= ut
->name
;
380 fprintf(header
, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name
, name
);
381 fprintf(header
, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name
, name
);
382 fprintf(header
, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name
, name
);
383 fprintf(header
, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name
, name
);
387 void write_context_handle_rundowns(void)
389 context_handle_t
*ch
;
390 LIST_FOR_EACH_ENTRY(ch
, &context_handle_list
, context_handle_t
, entry
)
392 const char *name
= ch
->name
;
393 fprintf(header
, "void __RPC_USER %s_rundown(%s);\n", name
, name
);
397 void write_typedef(type_t
*type
)
399 fprintf(header
, "typedef ");
400 write_type_def_or_decl(header
, type
->orig
, FALSE
, "%s", type
->name
);
401 fprintf(header
, ";\n");
404 void write_expr(FILE *h
, const expr_t
*e
, int brackets
)
410 fprintf(h
, "%lu", e
->u
.lval
);
413 fprintf(h
, "0x%lx", e
->u
.lval
);
416 fprintf(h
, "%#.15g", e
->u
.dval
);
424 case EXPR_IDENTIFIER
:
425 fprintf(h
, "%s", e
->u
.sval
);
429 write_expr(h
, e
->ref
, 1);
433 write_expr(h
, e
->ref
, 1);
437 write_expr(h
, e
->ref
, 1);
441 write_type_decl(h
, e
->u
.tref
, NULL
);
443 write_expr(h
, e
->ref
, 1);
446 fprintf(h
, "sizeof(");
447 write_type_decl(h
, e
->u
.tref
, NULL
);
458 if (brackets
) fprintf(h
, "(");
459 write_expr(h
, e
->ref
, 1);
461 case EXPR_SHL
: fprintf(h
, " << "); break;
462 case EXPR_SHR
: fprintf(h
, " >> "); break;
463 case EXPR_MUL
: fprintf(h
, " * "); break;
464 case EXPR_DIV
: fprintf(h
, " / "); break;
465 case EXPR_ADD
: fprintf(h
, " + "); break;
466 case EXPR_SUB
: fprintf(h
, " - "); break;
467 case EXPR_AND
: fprintf(h
, " & "); break;
468 case EXPR_OR
: fprintf(h
, " | "); break;
471 write_expr(h
, e
->u
.ext
, 1);
472 if (brackets
) fprintf(h
, ")");
475 if (brackets
) fprintf(h
, "(");
476 write_expr(h
, e
->ref
, 1);
478 write_expr(h
, e
->u
.ext
, 1);
480 write_expr(h
, e
->ext2
, 1);
481 if (brackets
) fprintf(h
, ")");
485 write_expr(h
, e
->ref
, 1);
490 void write_constdef(const var_t
*v
)
492 fprintf(header
, "#define %s (", v
->name
);
493 write_expr(header
, v
->eval
, 0);
494 fprintf(header
, ")\n\n");
497 void write_externdef(const var_t
*v
)
499 fprintf(header
, "extern const ");
500 write_type_def_or_decl(header
, v
->type
, FALSE
, "%s", v
->name
);
501 fprintf(header
, ";\n\n");
504 void write_library(const char *name
, const attr_list_t
*attr
)
506 const UUID
*uuid
= get_attrp(attr
, ATTR_UUID
);
507 fprintf(header
, "\n");
508 write_guid(header
, "LIBID", name
, uuid
);
509 fprintf(header
, "\n");
513 const var_t
* get_explicit_handle_var(const func_t
* func
)
520 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
521 if (var
->type
->type
== RPC_FC_BIND_PRIMITIVE
)
527 int has_out_arg_or_return(const func_t
*func
)
531 if (!is_void(func
->def
->type
))
537 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
538 if (is_attr(var
->attrs
, ATTR_OUT
))
545 /********** INTERFACES **********/
547 int is_object(const attr_list_t
*list
)
550 if (list
) LIST_FOR_EACH_ENTRY( attr
, list
, const attr_t
, entry
)
551 if (attr
->type
== ATTR_OBJECT
|| attr
->type
== ATTR_ODL
) return 1;
555 int is_local(const attr_list_t
*a
)
557 return is_attr(a
, ATTR_LOCAL
);
560 const var_t
*is_callas(const attr_list_t
*a
)
562 return get_attrp(a
, ATTR_CALLAS
);
565 static void write_method_macro(const type_t
*iface
, const char *name
)
569 if (iface
->ref
) write_method_macro(iface
->ref
, name
);
571 if (!iface
->funcs
) return;
573 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
574 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
576 var_t
*def
= cur
->def
;
577 if (!is_callas(def
->attrs
)) {
580 fprintf(header
, "#define %s_", name
);
581 write_name(header
,def
);
582 fprintf(header
, "(This");
584 LIST_FOR_EACH_ENTRY( arg
, cur
->args
, const var_t
, entry
)
585 fprintf(header
, ",%s", arg
->name
);
586 fprintf(header
, ") ");
588 fprintf(header
, "(This)->lpVtbl->");
589 write_name(header
, def
);
590 fprintf(header
, "(This");
592 LIST_FOR_EACH_ENTRY( arg
, cur
->args
, const var_t
, entry
)
593 fprintf(header
, ",%s", arg
->name
);
594 fprintf(header
, ")\n");
599 void write_args(FILE *h
, const var_list_t
*args
, const char *name
, int method
, int do_indent
)
610 fprintf(h
, "%s* This", name
);
613 if (args
) LIST_FOR_EACH_ENTRY( arg
, args
, const var_t
, entry
) {
620 else fprintf(h
, ",");
624 write_type_decl_left(h
, arg
->type
);
625 fprintf(h
, " (STDMETHODCALLTYPE *");
628 write_args(h
, arg
->args
, NULL
, 0, FALSE
);
632 write_type_decl(h
, arg
->type
, "%s", arg
->name
);
635 if (do_indent
) indentation
--;
638 static void write_cpp_method_def(const type_t
*iface
)
642 if (!iface
->funcs
) return;
644 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
646 var_t
*def
= cur
->def
;
647 if (!is_callas(def
->attrs
)) {
649 fprintf(header
, "virtual ");
650 write_type_decl_left(header
, def
->type
);
651 fprintf(header
, " STDMETHODCALLTYPE ");
652 write_name(header
, def
);
653 fprintf(header
, "(\n");
654 write_args(header
, cur
->args
, iface
->name
, 2, TRUE
);
655 fprintf(header
, ") = 0;\n");
656 fprintf(header
, "\n");
661 static void do_write_c_method_def(const type_t
*iface
, const char *name
)
665 if (iface
->ref
) do_write_c_method_def(iface
->ref
, name
);
667 if (!iface
->funcs
) return;
669 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
670 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
672 const var_t
*def
= cur
->def
;
673 if (!is_callas(def
->attrs
)) {
675 write_type_decl_left(header
, def
->type
);
676 fprintf(header
, " (STDMETHODCALLTYPE *");
677 write_name(header
, def
);
678 fprintf(header
, ")(\n");
679 write_args(header
, cur
->args
, name
, 1, TRUE
);
680 fprintf(header
, ");\n");
681 fprintf(header
, "\n");
686 static void write_c_method_def(const type_t
*iface
)
688 do_write_c_method_def(iface
, iface
->name
);
691 static void write_c_disp_method_def(const type_t
*iface
)
693 do_write_c_method_def(iface
->ref
, iface
->name
);
696 static void write_method_proto(const type_t
*iface
)
700 if (!iface
->funcs
) return;
701 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
703 const var_t
*def
= cur
->def
;
705 if (!is_local(def
->attrs
)) {
706 /* proxy prototype */
707 write_type_decl_left(header
, def
->type
);
708 fprintf(header
, " CALLBACK %s_", iface
->name
);
709 write_name(header
, def
);
710 fprintf(header
, "_Proxy(\n");
711 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
712 fprintf(header
, ");\n");
714 fprintf(header
, "void __RPC_STUB %s_", iface
->name
);
715 write_name(header
,def
);
716 fprintf(header
, "_Stub(\n");
717 fprintf(header
, " IRpcStubBuffer* This,\n");
718 fprintf(header
, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
719 fprintf(header
, " PRPC_MESSAGE pRpcMessage,\n");
720 fprintf(header
, " DWORD* pdwStubPhase);\n");
725 void write_locals(FILE *fp
, const type_t
*iface
, int body
)
727 static const char comment
[]
728 = "/* WIDL-generated stub. You must provide an implementation for this. */";
729 const func_list_t
*funcs
= iface
->funcs
;
732 if (!is_object(iface
->attrs
) || !funcs
)
735 LIST_FOR_EACH_ENTRY(cur
, funcs
, const func_t
, entry
) {
736 const var_t
*def
= cur
->def
;
737 const var_t
*cas
= is_callas(def
->attrs
);
741 LIST_FOR_EACH_ENTRY(m
, iface
->funcs
, const func_t
, entry
)
742 if (!strcmp(m
->def
->name
, cas
->name
))
744 if (&m
->entry
!= iface
->funcs
) {
745 const var_t
*mdef
= m
->def
;
746 /* proxy prototype - use local prototype */
747 write_type_decl_left(fp
, mdef
->type
);
748 fprintf(fp
, " CALLBACK %s_", iface
->name
);
749 write_name(fp
, mdef
);
750 fprintf(fp
, "_Proxy(\n");
751 write_args(fp
, m
->args
, iface
->name
, 1, TRUE
);
754 type_t
*rt
= mdef
->type
;
755 fprintf(fp
, "\n{\n");
756 fprintf(fp
, " %s\n", comment
);
757 if (rt
->name
&& strcmp(rt
->name
, "HRESULT") == 0)
758 fprintf(fp
, " return E_NOTIMPL;\n");
761 write_type_decl(fp
, rt
, "rv");
763 fprintf(fp
, " memset(&rv, 0, sizeof rv);\n");
764 fprintf(fp
, " return rv;\n");
766 fprintf(fp
, "}\n\n");
770 /* stub prototype - use remotable prototype */
771 write_type_decl_left(fp
, def
->type
);
772 fprintf(fp
, " __RPC_STUB %s_", iface
->name
);
773 write_name(fp
, mdef
);
774 fprintf(fp
, "_Stub(\n");
775 write_args(fp
, cur
->args
, iface
->name
, 1, TRUE
);
778 /* Remotable methods must all return HRESULTs. */
779 fprintf(fp
, "\n{\n %s\n return E_NOTIMPL;\n}\n\n", comment
);
784 error_loc("invalid call_as attribute (%s -> %s)\n", def
->name
, cas
->name
);
789 static void write_function_proto(const type_t
*iface
, const func_t
*fun
, const char *prefix
)
791 var_t
*def
= fun
->def
;
793 /* FIXME: do we need to handle call_as? */
794 write_type_decl_left(header
, def
->type
);
795 fprintf(header
, " ");
796 write_prefix_name(header
, prefix
, def
);
797 fprintf(header
, "(\n");
799 write_args(header
, fun
->args
, iface
->name
, 0, TRUE
);
801 fprintf(header
, " void");
802 fprintf(header
, ");\n");
805 static void write_function_protos(const type_t
*iface
)
807 const char *implicit_handle
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
808 int explicit_handle
= is_attr(iface
->attrs
, ATTR_EXPLICIT_HANDLE
);
809 const var_t
* explicit_handle_var
;
811 int prefixes_differ
= strcmp(prefix_client
, prefix_server
);
813 if (!iface
->funcs
) return;
814 LIST_FOR_EACH_ENTRY( cur
, iface
->funcs
, const func_t
, entry
)
816 var_t
*def
= cur
->def
;
818 /* check for a defined binding handle */
819 explicit_handle_var
= get_explicit_handle_var(cur
);
820 if (explicit_handle
) {
821 if (!explicit_handle_var
) {
822 error("%s() does not define an explicit binding handle!\n", def
->name
);
825 } else if (implicit_handle
) {
826 if (explicit_handle_var
) {
827 error("%s() must not define a binding handle!\n", def
->name
);
832 if (prefixes_differ
) {
833 fprintf(header
, "/* client prototype */\n");
834 write_function_proto(iface
, cur
, prefix_client
);
835 fprintf(header
, "/* server prototype */\n");
837 write_function_proto(iface
, cur
, prefix_server
);
841 void write_forward(type_t
*iface
)
843 /* C/C++ forwards should only be written for object interfaces, so if we
844 * have a full definition we only write one if we find [object] among the
845 * attributes - however, if we don't have a full definition at this point
846 * (i.e. this is an IDL forward), then we also assume that it is an object
847 * interface, since non-object interfaces shouldn't need forwards */
848 if ((!iface
->defined
|| is_object(iface
->attrs
) || is_attr(iface
->attrs
, ATTR_DISPINTERFACE
))
849 && !iface
->written
) {
850 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", iface
->name
);
851 fprintf(header
, "#define __%s_FWD_DEFINED__\n", iface
->name
);
852 fprintf(header
, "typedef interface %s %s;\n", iface
->name
, iface
->name
);
853 fprintf(header
, "#endif\n\n" );
854 iface
->written
= TRUE
;
858 static void write_iface_guid(const type_t
*iface
)
860 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
861 write_guid(header
, "IID", iface
->name
, uuid
);
864 static void write_dispiface_guid(const type_t
*iface
)
866 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
867 write_guid(header
, "DIID", iface
->name
, uuid
);
870 static void write_coclass_guid(type_t
*cocl
)
872 const UUID
*uuid
= get_attrp(cocl
->attrs
, ATTR_UUID
);
873 write_guid(header
, "CLSID", cocl
->name
, uuid
);
876 static void write_com_interface(type_t
*iface
)
878 if (!iface
->funcs
&& !iface
->ref
) {
879 parser_warning("%s has no methods\n", iface
->name
);
883 fprintf(header
, "/*****************************************************************************\n");
884 fprintf(header
, " * %s interface\n", iface
->name
);
885 fprintf(header
, " */\n");
886 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
887 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
888 write_iface_guid(iface
);
889 write_forward(iface
);
891 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
894 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
895 fprintf(header
, "{\n");
897 write_cpp_method_def(iface
);
899 fprintf(header
, "};\n");
903 fprintf(header
, "interface %s\n", iface
->name
);
904 fprintf(header
, "{\n");
905 fprintf(header
, " BEGIN_INTERFACE\n");
906 fprintf(header
, "\n");
908 write_cpp_method_def(iface
);
910 fprintf(header
, " END_INTERFACE\n");
911 fprintf(header
, "};\n");
913 fprintf(header
, "#else\n");
915 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
917 fprintf(header
, " BEGIN_INTERFACE\n");
918 fprintf(header
, "\n");
919 write_c_method_def(iface
);
921 fprintf(header
, " END_INTERFACE\n");
922 fprintf(header
, "} %sVtbl;\n", iface
->name
);
923 fprintf(header
, "interface %s {\n", iface
->name
);
924 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
925 fprintf(header
, "};\n");
926 fprintf(header
, "\n");
927 fprintf(header
, "#ifdef COBJMACROS\n");
928 write_method_macro(iface
, iface
->name
);
929 fprintf(header
, "#endif\n");
930 fprintf(header
, "\n");
931 fprintf(header
, "#endif\n");
932 fprintf(header
, "\n");
933 write_method_proto(iface
);
934 write_locals(header
, iface
, FALSE
);
935 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
938 static void write_rpc_interface(const type_t
*iface
)
940 unsigned int ver
= get_attrv(iface
->attrs
, ATTR_VERSION
);
941 const char *var
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
942 static int allocate_written
= 0;
944 if (!allocate_written
)
946 allocate_written
= 1;
947 fprintf(header
, "void * __RPC_USER MIDL_user_allocate(size_t);\n");
948 fprintf(header
, "void __RPC_USER MIDL_user_free(void *);\n\n");
951 fprintf(header
, "/*****************************************************************************\n");
952 fprintf(header
, " * %s interface (v%d.%d)\n", iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
953 fprintf(header
, " */\n");
954 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
955 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
958 write_iface_guid(iface
);
959 if (var
) fprintf(header
, "extern handle_t %s;\n", var
);
962 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ClientIfHandle;\n", prefix_client
, iface
->name
);
963 fprintf(header
, "extern RPC_IF_HANDLE %s%s_ServerIfHandle;\n", prefix_server
, iface
->name
);
967 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n",
968 prefix_client
, iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
969 fprintf(header
, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n",
970 prefix_server
, iface
->name
, MAJORVERSION(ver
), MINORVERSION(ver
));
972 write_function_protos(iface
);
974 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
976 /* FIXME: server/client code */
979 void write_interface(type_t
*iface
)
981 if (is_object(iface
->attrs
))
982 write_com_interface(iface
);
984 write_rpc_interface(iface
);
987 void write_dispinterface(type_t
*iface
)
989 fprintf(header
, "/*****************************************************************************\n");
990 fprintf(header
, " * %s dispinterface\n", iface
->name
);
991 fprintf(header
, " */\n");
992 fprintf(header
,"#ifndef __%s_DISPINTERFACE_DEFINED__\n", iface
->name
);
993 fprintf(header
,"#define __%s_DISPINTERFACE_DEFINED__\n\n", iface
->name
);
994 write_dispiface_guid(iface
);
995 write_forward(iface
);
997 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
998 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
999 fprintf(header
, "{\n");
1000 fprintf(header
, "};\n");
1001 fprintf(header
, "#else\n");
1003 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
1005 fprintf(header
, " BEGIN_INTERFACE\n");
1006 fprintf(header
, "\n");
1007 write_c_disp_method_def(iface
);
1009 fprintf(header
, " END_INTERFACE\n");
1010 fprintf(header
, "} %sVtbl;\n", iface
->name
);
1011 fprintf(header
, "interface %s {\n", iface
->name
);
1012 fprintf(header
, " CONST_VTBL %sVtbl* lpVtbl;\n", iface
->name
);
1013 fprintf(header
, "};\n");
1014 fprintf(header
, "\n");
1015 fprintf(header
, "#ifdef COBJMACROS\n");
1016 write_method_macro(iface
->ref
, iface
->name
);
1017 fprintf(header
, "#endif\n");
1018 fprintf(header
, "\n");
1019 fprintf(header
, "#endif\n");
1020 fprintf(header
, "\n");
1021 fprintf(header
,"#endif /* __%s_DISPINTERFACE_DEFINED__ */\n\n", iface
->name
);
1024 void write_coclass(type_t
*cocl
)
1026 fprintf(header
, "/*****************************************************************************\n");
1027 fprintf(header
, " * %s coclass\n", cocl
->name
);
1028 fprintf(header
, " */\n\n");
1029 write_coclass_guid(cocl
);
1030 fprintf(header
, "\n");
1033 void write_coclass_forward(type_t
*cocl
)
1035 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", cocl
->name
);
1036 fprintf(header
, "#define __%s_FWD_DEFINED__\n", cocl
->name
);
1037 fprintf(header
, "typedef struct %s %s;\n", cocl
->name
, cocl
->name
);
1038 fprintf(header
, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl
->name
);