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 const char *get_name(const var_t *v)
135 static char buffer[256];
137 if (is_attr( v->attrs, ATTR_PROPGET ))
138 strcpy( buffer, "get_" );
139 else if (is_attr( v->attrs, ATTR_PROPPUT ))
140 strcpy( buffer, "put_" );
141 else if (is_attr( v->attrs, ATTR_PROPPUTREF ))
142 strcpy( buffer, "putref_" );
145 strcat( buffer, v->name );
149 static void write_field(FILE *h, var_t *v)
154 write_type_def_or_decl(h, v->type, TRUE, "%s", v->name);
159 static void write_fields(FILE *h, var_list_t *fields)
163 LIST_FOR_EACH_ENTRY( v, fields, var_t, entry ) write_field(h, v);
166 static void write_enums(FILE *h, var_list_t *enums)
170 LIST_FOR_EACH_ENTRY( v, enums, var_t, entry )
174 fprintf(h, "%s", get_name(v));
177 write_expr(h, v->eval, 0, 1, NULL, NULL, "");
180 if (list_next( enums, &v->entry )) fprintf(h, ",\n");
185 int needs_space_after(type_t *t)
187 return (t->kind == TKIND_ALIAS
188 || (!is_ptr(t) && (!is_conformant_array(t) || t->declarray)));
191 void write_type_left(FILE *h, type_t *t, int declonly)
195 if (is_attr(t->attrs, ATTR_CONST) &&
196 (t->kind == TKIND_ALIAS || t->declarray || !is_ptr(t)))
197 fprintf(h, "const ");
199 if (t->kind == TKIND_ALIAS) fprintf(h, "%s", t->name);
200 else if (t->declarray) write_type_left(h, t->ref, declonly);
202 if (t->sign > 0) fprintf(h, "signed ");
203 else if (t->sign < 0) fprintf(h, "unsigned ");
207 if (!declonly && t->defined && !t->written && !t->ignore) {
208 if (t->name) fprintf(h, "enum %s {\n", t->name);
209 else fprintf(h, "enum {\n");
212 write_enums(h, t->fields_or_args);
216 else fprintf(h, "enum %s", t->name ? t->name : "");
219 case RPC_FC_CVSTRUCT:
220 case RPC_FC_CPSTRUCT:
223 case RPC_FC_BOGUS_STRUCT:
224 case RPC_FC_ENCAPSULATED_UNION:
225 if (!declonly && t->defined && !t->written && !t->ignore) {
226 if (t->name) fprintf(h, "struct %s {\n", t->name);
227 else fprintf(h, "struct {\n");
230 write_fields(h, t->fields_or_args);
234 else fprintf(h, "struct %s", t->name ? t->name : "");
236 case RPC_FC_NON_ENCAPSULATED_UNION:
237 if (!declonly && t->defined && !t->written && !t->ignore) {
238 if (t->name) fprintf(h, "union %s {\n", t->name);
239 else fprintf(h, "union {\n");
242 write_fields(h, t->fields_or_args);
246 else fprintf(h, "union %s", t->name ? t->name : "");
254 case RPC_FC_BOGUS_ARRAY:
255 write_type_left(h, t->ref, declonly);
256 fprintf(h, "%s*", needs_space_after(t->ref) ? " " : "");
257 if (is_ptr(t) && is_attr(t->attrs, ATTR_CONST)) fprintf(h, "const ");
260 fprintf(h, "%s", t->name);
265 void write_type_right(FILE *h, type_t *t, int is_field)
270 if (is_conformant_array(t)) {
271 fprintf(h, "[%s]", is_field ? "1" : "");
274 for ( ; t->declarray; t = t->ref)
275 fprintf(h, "[%lu]", t->dim);
279 void write_type_v(FILE *h, type_t *t, int is_field, int declonly,
280 const char *fmt, va_list args)
287 for (pt = t; is_ptr(pt); pt = pt->ref, ptr_level++)
290 if (pt->type == RPC_FC_FUNCTION) {
292 const char *callconv = get_attrp(pt->attrs, ATTR_CALLCONV);
293 if (!callconv) callconv = "";
294 if (is_attr(pt->attrs, ATTR_INLINE)) fprintf(h, "inline ");
295 write_type_left(h, pt->ref, declonly);
297 if (ptr_level) fputc('(', h);
298 fprintf(h, "%s ", callconv);
299 for (i = 0; i < ptr_level; i++)
302 write_type_left(h, t, declonly);
304 if (needs_space_after(t))
306 vfprintf(h, fmt, args);
308 if (pt->type == RPC_FC_FUNCTION) {
309 if (ptr_level) fputc(')', h);
311 write_args(h, pt->fields_or_args, NULL, 0, FALSE);
314 write_type_right(h, t, is_field);
317 void write_type_def_or_decl(FILE *f, type_t *t, int field, const char *fmt, ...)
321 write_type_v(f, t, field, FALSE, fmt, args);
325 void write_type_decl(FILE *f, type_t *t, const char *fmt, ...)
329 write_type_v(f, t, FALSE, TRUE, fmt, args);
333 void write_type_decl_left(FILE *f, type_t *t)
335 write_type_left(f, t, TRUE);
338 static int user_type_registered(const char *name)
341 LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
342 if (!strcmp(name, ut->name))
347 static int context_handle_registered(const char *name)
349 context_handle_t *ch;
350 LIST_FOR_EACH_ENTRY(ch, &context_handle_list, context_handle_t, entry)
351 if (!strcmp(name, ch->name))
356 static int generic_handle_registered(const char *name)
358 generic_handle_t *gh;
359 LIST_FOR_EACH_ENTRY(gh, &generic_handle_list, generic_handle_t, entry)
360 if (!strcmp(name, gh->name))
365 /* check for types which require additional prototypes to be generated in the
367 void check_for_additional_prototype_types(const var_list_t *list)
372 LIST_FOR_EACH_ENTRY( v, list, const var_t, entry )
375 for (type = v->type; type; type = type->kind == TKIND_ALIAS ? type->orig : type->ref) {
376 const char *name = type->name;
377 if (type->user_types_registered) continue;
378 type->user_types_registered = 1;
379 if (is_attr(type->attrs, ATTR_CONTEXTHANDLE)) {
380 if (!context_handle_registered(name))
382 context_handle_t *ch = xmalloc(sizeof(*ch));
383 ch->name = xstrdup(name);
384 list_add_tail(&context_handle_list, &ch->entry);
386 /* don't carry on parsing fields within this type */
389 if (type->type != RPC_FC_BIND_PRIMITIVE && is_attr(type->attrs, ATTR_HANDLE)) {
390 if (!generic_handle_registered(name))
392 generic_handle_t *gh = xmalloc(sizeof(*gh));
393 gh->name = xstrdup(name);
394 list_add_tail(&generic_handle_list, &gh->entry);
396 /* don't carry on parsing fields within this type */
399 if (is_attr(type->attrs, ATTR_WIREMARSHAL)) {
400 if (!user_type_registered(name))
402 user_type_t *ut = xmalloc(sizeof *ut);
403 ut->name = xstrdup(name);
404 list_add_tail(&user_type_list, &ut->entry);
406 /* don't carry on parsing fields within this type as we are already
407 * using a wire marshaled type */
412 check_for_additional_prototype_types(type->fields_or_args);
418 void write_user_types(void)
421 LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
423 const char *name = ut->name;
424 fprintf(header, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name, name);
425 fprintf(header, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name, name);
426 fprintf(header, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name, name);
427 fprintf(header, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name, name);
431 void write_context_handle_rundowns(void)
433 context_handle_t *ch;
434 LIST_FOR_EACH_ENTRY(ch, &context_handle_list, context_handle_t, entry)
436 const char *name = ch->name;
437 fprintf(header, "void __RPC_USER %s_rundown(%s);\n", name, name);
441 void write_generic_handle_routines(void)
443 generic_handle_t *gh;
444 LIST_FOR_EACH_ENTRY(gh, &generic_handle_list, generic_handle_t, entry)
446 const char *name = gh->name;
447 fprintf(header, "handle_t __RPC_USER %s_bind(%s);\n", name, name);
448 fprintf(header, "void __RPC_USER %s_unbind(%s, handle_t);\n", name, name);
452 void write_typedef(type_t *type)
454 fprintf(header, "typedef ");
455 write_type_def_or_decl(header, type->orig, FALSE, "%s", type->name);
456 fprintf(header, ";\n");
459 int is_const_decl(const var_t *var)
462 /* strangely, MIDL accepts a const attribute on any pointer in the
463 * declaration to mean that data isn't being instantiated. this appears
464 * to be a bug, but there is no benefit to being incompatible with MIDL,
465 * so we'll do the same thing */
466 for (t = var->type; ; )
468 if (is_attr(t->attrs, ATTR_CONST))
477 void write_declaration(const var_t *v, int is_in_interface)
479 if (is_const_decl(v) && v->eval)
481 fprintf(header, "#define %s (", v->name);
482 write_expr(header, v->eval, 0, 1, NULL, NULL, "");
483 fprintf(header, ")\n\n");
485 else if (v->type->type != RPC_FC_FUNCTION || !is_in_interface)
490 case STG_REGISTER: /* ignored */
493 fprintf(header, "static ");
496 fprintf(header, "extern ");
499 write_type_def_or_decl(header, v->type, FALSE, "%s", v->name);
500 fprintf(header, ";\n\n");
504 void write_library(const typelib_t *typelib)
506 const UUID *uuid = get_attrp(typelib->attrs, ATTR_UUID);
507 fprintf(header, "\n");
508 write_guid(header, "LIBID", typelib->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 const type_t* get_explicit_generic_handle_type(const var_t* var)
530 for (t = var->type; is_ptr(t); t = t->ref)
531 if (t->type != RPC_FC_BIND_PRIMITIVE && is_attr(t->attrs, ATTR_HANDLE))
536 const var_t* get_explicit_generic_handle_var(const func_t* func)
543 LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
544 if (get_explicit_generic_handle_type(var))
550 const var_t* get_context_handle_var(const func_t* func)
557 LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
558 if (is_attr(var->attrs, ATTR_IN) && is_context_handle(var->type))
564 int has_out_arg_or_return(const func_t *func)
568 if (!is_void(get_func_return_type(func)))
574 LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
575 if (is_attr(var->attrs, ATTR_OUT))
582 /********** INTERFACES **********/
584 int is_object(const attr_list_t *list)
587 if (list) LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
588 if (attr->type == ATTR_OBJECT || attr->type == ATTR_ODL) return 1;
592 int is_local(const attr_list_t *a)
594 return is_attr(a, ATTR_LOCAL);
597 const var_t *is_callas(const attr_list_t *a)
599 return get_attrp(a, ATTR_CALLAS);
602 static void write_method_macro(FILE *header, const type_t *iface, const char *name)
606 if (iface->ref) write_method_macro(header, iface->ref, name);
608 if (!iface->funcs) return;
610 fprintf(header, "/*** %s methods ***/\n", iface->name);
611 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
613 var_t *def = cur->def;
614 if (!is_callas(def->attrs)) {
617 fprintf(header, "#define %s_%s(This", name, get_name(def));
619 LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
620 fprintf(header, ",%s", arg->name);
621 fprintf(header, ") ");
623 fprintf(header, "(This)->lpVtbl->%s(This", get_name(def));
625 LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
626 fprintf(header, ",%s", arg->name);
627 fprintf(header, ")\n");
632 void write_args(FILE *h, const var_list_t *args, const char *name, int method, int do_indent)
643 fprintf(h, "%s* This", name);
646 if (args) LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry ) {
653 else fprintf(h, ",");
655 write_type_decl(h, arg->type, "%s", arg->name);
658 if (do_indent) indentation--;
661 static void write_cpp_method_def(FILE *header, const type_t *iface)
665 if (!iface->funcs) return;
667 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
669 var_t *def = cur->def;
670 if (!is_callas(def->attrs)) {
671 const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV);
672 if (!callconv) callconv = "";
674 fprintf(header, "virtual ");
675 write_type_decl_left(header, get_func_return_type(cur));
676 fprintf(header, " %s %s(\n", callconv, get_name(def));
677 write_args(header, cur->args, iface->name, 2, TRUE);
678 fprintf(header, ") = 0;\n");
679 fprintf(header, "\n");
684 static void do_write_c_method_def(FILE *header, const type_t *iface, const char *name)
688 if (iface->ref) do_write_c_method_def(header, iface->ref, name);
690 if (!iface->funcs) return;
692 fprintf(header, "/*** %s methods ***/\n", iface->name);
693 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
695 const var_t *def = cur->def;
696 if (!is_callas(def->attrs)) {
697 const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV);
698 if (!callconv) callconv = "";
700 write_type_decl_left(header, get_func_return_type(cur));
701 fprintf(header, " (%s *%s)(\n", callconv, get_name(def));
702 write_args(header, cur->args, name, 1, TRUE);
703 fprintf(header, ");\n");
704 fprintf(header, "\n");
709 static void write_c_method_def(FILE *header, const type_t *iface)
711 do_write_c_method_def(header, iface, iface->name);
714 static void write_c_disp_method_def(FILE *header, const type_t *iface)
716 do_write_c_method_def(header, iface->ref, iface->name);
719 static void write_method_proto(FILE *header, const type_t *iface)
723 if (!iface->funcs) return;
724 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
726 const var_t *def = cur->def;
728 if (!is_local(def->attrs)) {
729 const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV);
730 if (!callconv) callconv = "";
731 /* proxy prototype */
732 write_type_decl_left(header, get_func_return_type(cur));
733 fprintf(header, " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(def));
734 write_args(header, cur->args, iface->name, 1, TRUE);
735 fprintf(header, ");\n");
737 fprintf(header, "void __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(def));
738 fprintf(header, " IRpcStubBuffer* This,\n");
739 fprintf(header, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
740 fprintf(header, " PRPC_MESSAGE pRpcMessage,\n");
741 fprintf(header, " DWORD* pdwStubPhase);\n");
746 void write_locals(FILE *fp, const type_t *iface, int body)
748 static const char comment[]
749 = "/* WIDL-generated stub. You must provide an implementation for this. */";
750 const func_list_t *funcs = iface->funcs;
753 if (!is_object(iface->attrs) || !funcs)
756 LIST_FOR_EACH_ENTRY(cur, funcs, const func_t, entry) {
757 const var_t *def = cur->def;
758 const var_t *cas = is_callas(def->attrs);
762 LIST_FOR_EACH_ENTRY(m, iface->funcs, const func_t, entry)
763 if (!strcmp(m->def->name, cas->name))
765 if (&m->entry != iface->funcs) {
766 const var_t *mdef = m->def;
767 /* proxy prototype - use local prototype */
768 write_type_decl_left(fp, get_func_return_type(m));
769 fprintf(fp, " CALLBACK %s_%s_Proxy(\n", iface->name, get_name(mdef));
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_%s_Stub(\n", iface->name, get_name(mdef));
792 write_args(fp, cur->args, iface->name, 1, TRUE);
795 /* Remotable methods must all return HRESULTs. */
796 fprintf(fp, "\n{\n %s\n return E_NOTIMPL;\n}\n\n", comment);
801 error_loc("invalid call_as attribute (%s -> %s)\n", def->name, cas->name);
806 static void write_function_proto(FILE *header, const type_t *iface, const func_t *fun, const char *prefix)
808 var_t *def = fun->def;
809 const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV);
811 /* FIXME: do we need to handle call_as? */
812 write_type_decl_left(header, get_func_return_type(fun));
813 fprintf(header, " ");
814 if (callconv) fprintf(header, "%s ", callconv);
815 fprintf(header, "%s%s(\n", prefix, get_name(def));
817 write_args(header, fun->args, iface->name, 0, TRUE);
819 fprintf(header, " void");
820 fprintf(header, ");\n\n");
823 static void write_function_protos(FILE *header, const type_t *iface)
826 int prefixes_differ = strcmp(prefix_client, prefix_server);
828 if (!iface->funcs) return;
829 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
831 if (prefixes_differ) {
832 fprintf(header, "/* client prototype */\n");
833 write_function_proto(header, iface, cur, prefix_client);
834 fprintf(header, "/* server prototype */\n");
836 write_function_proto(header, iface, cur, prefix_server);
840 void write_forward(type_t *iface)
842 /* C/C++ forwards should only be written for object interfaces, so if we
843 * have a full definition we only write one if we find [object] among the
844 * attributes - however, if we don't have a full definition at this point
845 * (i.e. this is an IDL forward), then we also assume that it is an object
846 * interface, since non-object interfaces shouldn't need forwards */
847 if ((!iface->defined || is_object(iface->attrs) || is_attr(iface->attrs, ATTR_DISPINTERFACE))
848 && !iface->written) {
849 fprintf(header, "#ifndef __%s_FWD_DEFINED__\n", iface->name);
850 fprintf(header, "#define __%s_FWD_DEFINED__\n", iface->name);
851 fprintf(header, "typedef interface %s %s;\n", iface->name, iface->name);
852 fprintf(header, "#endif\n\n" );
853 iface->written = TRUE;
857 static void write_iface_guid(FILE *header, const type_t *iface)
859 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
860 write_guid(header, "IID", iface->name, uuid);
863 static void write_dispiface_guid(FILE *header, const type_t *iface)
865 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
866 write_guid(header, "DIID", iface->name, uuid);
869 static void write_coclass_guid(FILE *header, const type_t *cocl)
871 const UUID *uuid = get_attrp(cocl->attrs, ATTR_UUID);
872 write_guid(header, "CLSID", cocl->name, uuid);
875 static void write_com_interface_start(FILE *header, const type_t *iface)
877 int dispinterface = is_attr(iface->attrs, ATTR_DISPINTERFACE);
878 fprintf(header, "/*****************************************************************************\n");
879 fprintf(header, " * %s %sinterface\n", iface->name, dispinterface ? "disp" : "");
880 fprintf(header, " */\n");
881 fprintf(header,"#ifndef __%s_%sINTERFACE_DEFINED__\n", iface->name, dispinterface ? "DISP" : "");
882 fprintf(header,"#define __%s_%sINTERFACE_DEFINED__\n\n", iface->name, dispinterface ? "DISP" : "");
885 static void write_com_interface_end(FILE *header, type_t *iface)
887 int dispinterface = is_attr(iface->attrs, ATTR_DISPINTERFACE);
889 write_dispiface_guid(header, iface);
891 write_iface_guid(header, 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");
901 fprintf(header, "interface %s\n", iface->name);
902 fprintf(header, "{\n");
903 fprintf(header, " BEGIN_INTERFACE\n");
904 fprintf(header, "\n");
906 /* dispinterfaces don't have real functions, so don't write C++ functions for
911 write_cpp_method_def(header, iface);
915 fprintf(header, " END_INTERFACE\n");
916 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");
924 write_c_disp_method_def(header, iface);
926 write_c_method_def(header, iface);
928 fprintf(header, " END_INTERFACE\n");
929 fprintf(header, "} %sVtbl;\n", iface->name);
930 fprintf(header, "interface %s {\n", iface->name);
931 fprintf(header, " CONST_VTBL %sVtbl* lpVtbl;\n", iface->name);
932 fprintf(header, "};\n");
933 fprintf(header, "\n");
934 fprintf(header, "#ifdef COBJMACROS\n");
935 /* dispinterfaces don't have real functions, so don't write macros for them,
936 * only for the interface this interface inherits from, i.e. IDispatch */
937 write_method_macro(header, dispinterface ? iface->ref : iface, iface->name);
938 fprintf(header, "#endif\n");
939 fprintf(header, "\n");
940 fprintf(header, "#endif\n");
941 fprintf(header, "\n");
942 /* dispinterfaces don't have real functions, so don't write prototypes for
946 write_method_proto(header, iface);
947 write_locals(header, iface, FALSE);
948 fprintf(header, "\n");
950 fprintf(header,"#endif /* __%s_%sINTERFACE_DEFINED__ */\n\n", iface->name, dispinterface ? "DISP" : "");
953 static void write_rpc_interface_start(FILE *header, const type_t *iface)
955 unsigned int ver = get_attrv(iface->attrs, ATTR_VERSION);
956 const char *var = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
957 static int allocate_written = 0;
959 if (!allocate_written)
961 allocate_written = 1;
962 fprintf(header, "void * __RPC_USER MIDL_user_allocate(size_t);\n");
963 fprintf(header, "void __RPC_USER MIDL_user_free(void *);\n\n");
966 fprintf(header, "/*****************************************************************************\n");
967 fprintf(header, " * %s interface (v%d.%d)\n", iface->name, MAJORVERSION(ver), MINORVERSION(ver));
968 fprintf(header, " */\n");
969 fprintf(header,"#ifndef __%s_INTERFACE_DEFINED__\n", iface->name);
970 fprintf(header,"#define __%s_INTERFACE_DEFINED__\n\n", iface->name);
971 if (var) fprintf(header, "extern handle_t %s;\n", var);
974 fprintf(header, "extern RPC_IF_HANDLE %s%s_ClientIfHandle;\n", prefix_client, iface->name);
975 fprintf(header, "extern RPC_IF_HANDLE %s%s_ServerIfHandle;\n", prefix_server, iface->name);
979 fprintf(header, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n",
980 prefix_client, iface->name, MAJORVERSION(ver), MINORVERSION(ver));
981 fprintf(header, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n",
982 prefix_server, iface->name, MAJORVERSION(ver), MINORVERSION(ver));
986 static void write_rpc_interface_end(FILE *header, const type_t *iface)
988 fprintf(header,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface->name);
991 void write_interface(type_t *iface)
993 if (is_attr(iface->attrs, ATTR_DISPINTERFACE) || is_object(iface->attrs))
995 write_com_interface_start(header, iface);
996 write_com_interface_end(header, iface);
1000 write_rpc_interface_start(header, iface);
1001 write_function_protos(header, iface);
1002 write_rpc_interface_end(header, iface);
1006 void write_coclass(type_t *cocl)
1008 fprintf(header, "/*****************************************************************************\n");
1009 fprintf(header, " * %s coclass\n", cocl->name);
1010 fprintf(header, " */\n\n");
1011 write_coclass_guid(header, cocl);
1012 fprintf(header, "\n");
1015 void write_coclass_forward(type_t *cocl)
1017 fprintf(header, "#ifndef __%s_FWD_DEFINED__\n", cocl->name);
1018 fprintf(header, "#define __%s_FWD_DEFINED__\n", cocl->name);
1019 fprintf(header, "typedef struct %s %s;\n", cocl->name, cocl->name);
1020 fprintf(header, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl->name );
1023 void write_import(const char *fname)
1027 hname = dup_basename(fname, ".idl");
1028 p = hname + strlen(hname) - 2;
1029 if (p <= hname || strcmp( p, ".h" )) strcat(hname, ".h");
1031 fprintf(header, "#include <%s>\n", hname);