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)) {
582 fprintf(header, "#define %s_", name);
583 write_name(header,def);
584 fprintf(header, "(This");
586 LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
587 fprintf(header, ",%s", arg->name);
588 fprintf(header, ") ");
590 fprintf(header, "(This)->lpVtbl->");
591 write_name(header, def);
592 fprintf(header, "(This");
594 LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
595 fprintf(header, ",%s", arg->name);
596 fprintf(header, ")\n");
601 void write_args(FILE *h, const var_list_t *args, const char *name, int method, int do_indent)
612 fprintf(h, "%s* This", name);
615 if (args) LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry ) {
622 else fprintf(h, ",");
626 write_type_decl_left(h, arg->type);
627 fprintf(h, " (STDMETHODCALLTYPE *");
630 write_args(h, arg->args, NULL, 0, FALSE);
634 write_type_decl(h, arg->type, "%s", arg->name);
637 if (do_indent) indentation--;
640 static void write_cpp_method_def(const type_t *iface)
644 if (!iface->funcs) return;
646 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
648 var_t *def = cur->def;
649 if (!is_callas(def->attrs)) {
651 fprintf(header, "virtual ");
652 write_type_decl_left(header, def->type);
653 fprintf(header, " STDMETHODCALLTYPE ");
654 write_name(header, def);
655 fprintf(header, "(\n");
656 write_args(header, cur->args, iface->name, 2, TRUE);
657 fprintf(header, ") = 0;\n");
658 fprintf(header, "\n");
663 static void do_write_c_method_def(const type_t *iface, const char *name)
667 if (iface->ref) do_write_c_method_def(iface->ref, name);
669 if (!iface->funcs) return;
671 fprintf(header, "/*** %s methods ***/\n", iface->name);
672 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
674 const var_t *def = cur->def;
675 if (!is_callas(def->attrs)) {
677 write_type_decl_left(header, def->type);
678 fprintf(header, " (STDMETHODCALLTYPE *");
679 write_name(header, def);
680 fprintf(header, ")(\n");
681 write_args(header, cur->args, name, 1, TRUE);
682 fprintf(header, ");\n");
683 fprintf(header, "\n");
688 static void write_c_method_def(const type_t *iface)
690 do_write_c_method_def(iface, iface->name);
693 static void write_c_disp_method_def(const type_t *iface)
695 do_write_c_method_def(iface->ref, iface->name);
698 static void write_method_proto(const type_t *iface)
702 if (!iface->funcs) return;
703 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
705 const var_t *def = cur->def;
707 if (!is_local(def->attrs)) {
708 /* proxy prototype */
709 write_type_decl_left(header, def->type);
710 fprintf(header, " CALLBACK %s_", iface->name);
711 write_name(header, def);
712 fprintf(header, "_Proxy(\n");
713 write_args(header, cur->args, iface->name, 1, TRUE);
714 fprintf(header, ");\n");
716 fprintf(header, "void __RPC_STUB %s_", iface->name);
717 write_name(header,def);
718 fprintf(header, "_Stub(\n");
719 fprintf(header, " IRpcStubBuffer* This,\n");
720 fprintf(header, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
721 fprintf(header, " PRPC_MESSAGE pRpcMessage,\n");
722 fprintf(header, " DWORD* pdwStubPhase);\n");
727 void write_locals(FILE *fp, const type_t *iface, int body)
729 static const char comment[]
730 = "/* WIDL-generated stub. You must provide an implementation for this. */";
731 const func_list_t *funcs = iface->funcs;
734 if (!is_object(iface->attrs) || !funcs)
737 LIST_FOR_EACH_ENTRY(cur, funcs, const func_t, entry) {
738 const var_t *def = cur->def;
739 const var_t *cas = is_callas(def->attrs);
743 LIST_FOR_EACH_ENTRY(m, iface->funcs, const func_t, entry)
744 if (!strcmp(m->def->name, cas->name))
746 if (&m->entry != iface->funcs) {
747 const var_t *mdef = m->def;
748 /* proxy prototype - use local prototype */
749 write_type_decl_left(fp, mdef->type);
750 fprintf(fp, " CALLBACK %s_", iface->name);
751 write_name(fp, mdef);
752 fprintf(fp, "_Proxy(\n");
753 write_args(fp, m->args, iface->name, 1, TRUE);
756 type_t *rt = mdef->type;
757 fprintf(fp, "\n{\n");
758 fprintf(fp, " %s\n", comment);
759 if (rt->name && strcmp(rt->name, "HRESULT") == 0)
760 fprintf(fp, " return E_NOTIMPL;\n");
763 write_type_decl(fp, rt, "rv");
765 fprintf(fp, " memset(&rv, 0, sizeof rv);\n");
766 fprintf(fp, " return rv;\n");
768 fprintf(fp, "}\n\n");
772 /* stub prototype - use remotable prototype */
773 write_type_decl_left(fp, def->type);
774 fprintf(fp, " __RPC_STUB %s_", iface->name);
775 write_name(fp, mdef);
776 fprintf(fp, "_Stub(\n");
777 write_args(fp, cur->args, iface->name, 1, TRUE);
780 /* Remotable methods must all return HRESULTs. */
781 fprintf(fp, "\n{\n %s\n return E_NOTIMPL;\n}\n\n", comment);
786 error_loc("invalid call_as attribute (%s -> %s)\n", def->name, cas->name);
791 static void write_function_proto(const type_t *iface, const func_t *fun, const char *prefix)
793 var_t *def = fun->def;
795 /* FIXME: do we need to handle call_as? */
796 write_type_decl_left(header, def->type);
797 fprintf(header, " ");
798 write_prefix_name(header, prefix, def);
799 fprintf(header, "(\n");
801 write_args(header, fun->args, iface->name, 0, TRUE);
803 fprintf(header, " void");
804 fprintf(header, ");\n");
807 static void write_function_protos(const type_t *iface)
809 const char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
810 int explicit_handle = is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE);
811 const var_t* explicit_handle_var;
813 int prefixes_differ = strcmp(prefix_client, prefix_server);
815 if (!iface->funcs) return;
816 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
818 var_t *def = cur->def;
820 /* check for a defined binding handle */
821 explicit_handle_var = get_explicit_handle_var(cur);
822 if (explicit_handle) {
823 if (!explicit_handle_var) {
824 error("%s() does not define an explicit binding handle!\n", def->name);
827 } else if (implicit_handle) {
828 if (explicit_handle_var) {
829 error("%s() must not define a binding handle!\n", def->name);
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 );