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 typedef struct _user_type_t generic_handle_t;
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);
42 static struct list generic_handle_list = LIST_INIT(generic_handle_list);
44 static void indent(FILE *h, int delta)
47 if (delta < 0) indentation += delta;
48 for (c=0; c<indentation; c++) fprintf(h, " ");
49 if (delta > 0) indentation += delta;
52 int is_ptrchain_attr(const var_t *var, enum attr_type t)
54 if (is_attr(var->attrs, t))
58 type_t *type = var->type;
61 if (is_attr(type->attrs, t))
63 else if (type->kind == TKIND_ALIAS)
65 else if (is_ptr(type))
72 int is_aliaschain_attr(const type_t *type, enum attr_type attr)
74 const type_t *t = type;
77 if (is_attr(t->attrs, attr))
79 else if (t->kind == TKIND_ALIAS)
85 int is_attr(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 1;
93 void *get_attrp(const attr_list_t *list, enum attr_type t)
96 if (list) LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
97 if (attr->type == t) return attr->u.pval;
101 unsigned long get_attrv(const attr_list_t *list, enum attr_type t)
104 if (list) LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
105 if (attr->type == t) return attr->u.ival;
109 int is_void(const type_t *t)
111 if (!t->type && !t->ref) return 1;
115 int is_conformant_array(const type_t *t)
117 return t->type == RPC_FC_CARRAY
118 || t->type == RPC_FC_CVARRAY
119 || (t->type == RPC_FC_BOGUS_ARRAY && t->size_is);
122 void write_guid(FILE *f, const char *guid_prefix, const char *name, const UUID *uuid)
125 fprintf(f, "DEFINE_GUID(%s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
126 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
127 guid_prefix, name, uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0],
128 uuid->Data4[1], uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5],
129 uuid->Data4[6], uuid->Data4[7]);
132 void write_name(FILE *h, const var_t *v)
134 if (is_attr( v->attrs, ATTR_PROPGET ))
136 else if (is_attr( v->attrs, ATTR_PROPPUT ))
138 else if (is_attr( v->attrs, ATTR_PROPPUTREF ))
139 fprintf(h, "putref_" );
140 fprintf(h, "%s", v->name);
143 void write_prefix_name(FILE *h, const char *prefix, const var_t *v)
145 fprintf(h, "%s", prefix);
149 static void write_field(FILE *h, var_t *v)
153 const char *name = v->name;
155 switch (v->type->type) {
157 case RPC_FC_CVSTRUCT:
158 case RPC_FC_CPSTRUCT:
161 case RPC_FC_BOGUS_STRUCT:
162 case RPC_FC_ENCAPSULATED_UNION:
163 name = "DUMMYSTRUCTNAME";
165 case RPC_FC_NON_ENCAPSULATED_UNION:
166 name = "DUMMYUNIONNAME";
174 write_type_def_or_decl(h, v->type, TRUE, "%s", name);
179 static void write_fields(FILE *h, var_list_t *fields)
183 LIST_FOR_EACH_ENTRY( v, fields, var_t, entry ) write_field(h, v);
186 static void write_enums(FILE *h, var_list_t *enums)
190 LIST_FOR_EACH_ENTRY( v, enums, var_t, entry )
197 write_expr(h, v->eval, 0);
200 if (list_next( enums, &v->entry )) fprintf(h, ",\n");
205 int needs_space_after(type_t *t)
207 return (t->kind == TKIND_ALIAS
208 || (!is_ptr(t) && (!is_conformant_array(t) || t->declarray)));
211 void write_type_left(FILE *h, type_t *t, int declonly)
215 if (t->is_const) fprintf(h, "const ");
217 if (t->kind == TKIND_ALIAS) fprintf(h, "%s", t->name);
218 else if (t->declarray) write_type_left(h, t->ref, declonly);
220 if (t->sign > 0) fprintf(h, "signed ");
221 else if (t->sign < 0) fprintf(h, "unsigned ");
225 if (!declonly && t->defined && !t->written && !t->ignore) {
226 if (t->name) fprintf(h, "enum %s {\n", t->name);
227 else fprintf(h, "enum {\n");
230 write_enums(h, t->fields);
234 else fprintf(h, "enum %s", t->name ? t->name : "");
237 case RPC_FC_CVSTRUCT:
238 case RPC_FC_CPSTRUCT:
241 case RPC_FC_BOGUS_STRUCT:
242 case RPC_FC_ENCAPSULATED_UNION:
243 if (!declonly && t->defined && !t->written && !t->ignore) {
244 if (t->name) fprintf(h, "struct %s {\n", t->name);
245 else fprintf(h, "struct {\n");
248 write_fields(h, t->fields);
252 else fprintf(h, "struct %s", t->name ? t->name : "");
254 case RPC_FC_NON_ENCAPSULATED_UNION:
255 if (!declonly && t->defined && !t->written && !t->ignore) {
256 if (t->name) fprintf(h, "union %s {\n", t->name);
257 else fprintf(h, "union {\n");
260 write_fields(h, t->fields);
264 else fprintf(h, "union %s", t->name ? t->name : "");
272 case RPC_FC_BOGUS_ARRAY:
273 write_type_left(h, t->ref, declonly);
274 fprintf(h, "%s*", needs_space_after(t->ref) ? " " : "");
277 fprintf(h, "%s", t->name);
282 void write_type_right(FILE *h, type_t *t, int is_field)
287 if (is_conformant_array(t)) {
288 fprintf(h, "[%s]", is_field ? "1" : "");
291 for ( ; t->declarray; t = t->ref)
292 fprintf(h, "[%lu]", t->dim);
296 void write_type_v(FILE *h, type_t *t, int is_field, int declonly,
297 const char *fmt, va_list args)
301 write_type_left(h, t, declonly);
303 if (needs_space_after(t))
305 vfprintf(h, fmt, args);
307 write_type_right(h, t, is_field);
310 void write_type_def_or_decl(FILE *f, type_t *t, int field, const char *fmt, ...)
314 write_type_v(f, t, field, FALSE, fmt, args);
318 void write_type_decl(FILE *f, type_t *t, const char *fmt, ...)
322 write_type_v(f, t, FALSE, TRUE, fmt, args);
326 void write_type_decl_left(FILE *f, type_t *t)
328 write_type_left(f, t, TRUE);
331 static int user_type_registered(const char *name)
334 LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
335 if (!strcmp(name, ut->name))
340 static int context_handle_registered(const char *name)
342 context_handle_t *ch;
343 LIST_FOR_EACH_ENTRY(ch, &context_handle_list, context_handle_t, entry)
344 if (!strcmp(name, ch->name))
349 static int generic_handle_registered(const char *name)
351 generic_handle_t *gh;
352 LIST_FOR_EACH_ENTRY(gh, &generic_handle_list, generic_handle_t, entry)
353 if (!strcmp(name, gh->name))
358 /* check for types which require additional prototypes to be generated in the
360 void check_for_additional_prototype_types(const var_list_t *list)
365 LIST_FOR_EACH_ENTRY( v, list, const var_t, entry )
368 for (type = v->type; type; type = type->kind == TKIND_ALIAS ? type->orig : type->ref) {
369 const char *name = type->name;
370 if (type->user_types_registered) continue;
371 type->user_types_registered = 1;
372 if (is_attr(type->attrs, ATTR_CONTEXTHANDLE)) {
373 if (!context_handle_registered(name))
375 context_handle_t *ch = xmalloc(sizeof(*ch));
376 ch->name = xstrdup(name);
377 list_add_tail(&context_handle_list, &ch->entry);
379 /* don't carry on parsing fields within this type */
382 if (type->type != RPC_FC_BIND_PRIMITIVE && is_attr(type->attrs, ATTR_HANDLE)) {
383 if (!generic_handle_registered(name))
385 generic_handle_t *gh = xmalloc(sizeof(*gh));
386 gh->name = xstrdup(name);
387 list_add_tail(&generic_handle_list, &gh->entry);
389 /* don't carry on parsing fields within this type */
392 if (is_attr(type->attrs, ATTR_WIREMARSHAL)) {
393 if (!user_type_registered(name))
395 user_type_t *ut = xmalloc(sizeof *ut);
396 ut->name = xstrdup(name);
397 list_add_tail(&user_type_list, &ut->entry);
399 /* don't carry on parsing fields within this type as we are already
400 * using a wire marshaled type */
405 check_for_additional_prototype_types(type->fields);
411 void write_user_types(void)
414 LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
416 const char *name = ut->name;
417 fprintf(header, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name, name);
418 fprintf(header, "unsigned char * __RPC_USER %s_UserMarshal (ULONG *, unsigned char *, %s *);\n", name, name);
419 fprintf(header, "unsigned char * __RPC_USER %s_UserUnmarshal(ULONG *, unsigned char *, %s *);\n", name, name);
420 fprintf(header, "void __RPC_USER %s_UserFree (ULONG *, %s *);\n", name, name);
424 void write_context_handle_rundowns(void)
426 context_handle_t *ch;
427 LIST_FOR_EACH_ENTRY(ch, &context_handle_list, context_handle_t, entry)
429 const char *name = ch->name;
430 fprintf(header, "void __RPC_USER %s_rundown(%s);\n", name, name);
434 void write_generic_handle_routines(void)
436 generic_handle_t *gh;
437 LIST_FOR_EACH_ENTRY(gh, &generic_handle_list, generic_handle_t, entry)
439 const char *name = gh->name;
440 fprintf(header, "handle_t __RPC_USER %s_bind(%s);\n", name, name);
441 fprintf(header, "void __RPC_USER %s_unbind(%s, handle_t);\n", name, name);
445 void write_typedef(type_t *type)
447 fprintf(header, "typedef ");
448 write_type_def_or_decl(header, type->orig, FALSE, "%s", type->name);
449 fprintf(header, ";\n");
452 void write_expr(FILE *h, const expr_t *e, int brackets)
458 fprintf(h, "%lu", e->u.lval);
461 fprintf(h, "0x%lx", e->u.lval);
464 fprintf(h, "%#.15g", e->u.dval);
472 case EXPR_IDENTIFIER:
473 fprintf(h, "%s", e->u.sval);
477 write_expr(h, e->ref, 1);
481 write_expr(h, e->ref, 1);
485 write_expr(h, e->ref, 1);
489 write_type_decl(h, e->u.tref, NULL);
491 write_expr(h, e->ref, 1);
494 fprintf(h, "sizeof(");
495 write_type_decl(h, e->u.tref, NULL);
506 if (brackets) fprintf(h, "(");
507 write_expr(h, e->ref, 1);
509 case EXPR_SHL: fprintf(h, " << "); break;
510 case EXPR_SHR: fprintf(h, " >> "); break;
511 case EXPR_MUL: fprintf(h, " * "); break;
512 case EXPR_DIV: fprintf(h, " / "); break;
513 case EXPR_ADD: fprintf(h, " + "); break;
514 case EXPR_SUB: fprintf(h, " - "); break;
515 case EXPR_AND: fprintf(h, " & "); break;
516 case EXPR_OR: fprintf(h, " | "); break;
519 write_expr(h, e->u.ext, 1);
520 if (brackets) fprintf(h, ")");
523 if (brackets) fprintf(h, "(");
524 write_expr(h, e->ref, 1);
526 write_expr(h, e->u.ext, 1);
528 write_expr(h, e->ext2, 1);
529 if (brackets) fprintf(h, ")");
533 write_expr(h, e->ref, 1);
538 void write_constdef(const var_t *v)
540 fprintf(header, "#define %s (", v->name);
541 write_expr(header, v->eval, 0);
542 fprintf(header, ")\n\n");
545 void write_externdef(const var_t *v)
547 fprintf(header, "extern const ");
548 write_type_def_or_decl(header, v->type, FALSE, "%s", v->name);
549 fprintf(header, ";\n\n");
552 void write_library(const char *name, const attr_list_t *attr)
554 const UUID *uuid = get_attrp(attr, ATTR_UUID);
555 fprintf(header, "\n");
556 write_guid(header, "LIBID", name, uuid);
557 fprintf(header, "\n");
561 const var_t* get_explicit_handle_var(const func_t* func)
568 LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
569 if (var->type->type == RPC_FC_BIND_PRIMITIVE)
575 const type_t* get_explicit_generic_handle_type(const var_t* var)
578 for (t = var->type; is_ptr(t); t = t->ref)
579 if (t->type != RPC_FC_BIND_PRIMITIVE && is_attr(t->attrs, ATTR_HANDLE))
584 const var_t* get_explicit_generic_handle_var(const func_t* func)
591 LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
592 if (get_explicit_generic_handle_type(var))
598 int has_out_arg_or_return(const func_t *func)
602 if (!is_void(func->def->type))
608 LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
609 if (is_attr(var->attrs, ATTR_OUT))
616 /********** INTERFACES **********/
618 int is_object(const attr_list_t *list)
621 if (list) LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
622 if (attr->type == ATTR_OBJECT || attr->type == ATTR_ODL) return 1;
626 int is_local(const attr_list_t *a)
628 return is_attr(a, ATTR_LOCAL);
631 const var_t *is_callas(const attr_list_t *a)
633 return get_attrp(a, ATTR_CALLAS);
636 static void write_method_macro(const type_t *iface, const char *name)
640 if (iface->ref) write_method_macro(iface->ref, name);
642 if (!iface->funcs) return;
644 fprintf(header, "/*** %s methods ***/\n", iface->name);
645 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
647 var_t *def = cur->def;
648 if (!is_callas(def->attrs)) {
651 fprintf(header, "#define %s_", name);
652 write_name(header,def);
653 fprintf(header, "(This");
655 LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
656 fprintf(header, ",%s", arg->name);
657 fprintf(header, ") ");
659 fprintf(header, "(This)->lpVtbl->");
660 write_name(header, def);
661 fprintf(header, "(This");
663 LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
664 fprintf(header, ",%s", arg->name);
665 fprintf(header, ")\n");
670 void write_args(FILE *h, const var_list_t *args, const char *name, int method, int do_indent)
681 fprintf(h, "%s* This", name);
684 if (args) LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry ) {
691 else fprintf(h, ",");
695 write_type_decl_left(h, arg->type);
696 fprintf(h, " (STDMETHODCALLTYPE *");
699 write_args(h, arg->args, NULL, 0, FALSE);
703 write_type_decl(h, arg->type, "%s", arg->name);
706 if (do_indent) indentation--;
709 static void write_cpp_method_def(const type_t *iface)
713 if (!iface->funcs) return;
715 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
717 var_t *def = cur->def;
718 if (!is_callas(def->attrs)) {
720 fprintf(header, "virtual ");
721 write_type_decl_left(header, def->type);
722 fprintf(header, " STDMETHODCALLTYPE ");
723 write_name(header, def);
724 fprintf(header, "(\n");
725 write_args(header, cur->args, iface->name, 2, TRUE);
726 fprintf(header, ") = 0;\n");
727 fprintf(header, "\n");
732 static void do_write_c_method_def(const type_t *iface, const char *name)
736 if (iface->ref) do_write_c_method_def(iface->ref, name);
738 if (!iface->funcs) return;
740 fprintf(header, "/*** %s methods ***/\n", iface->name);
741 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
743 const var_t *def = cur->def;
744 if (!is_callas(def->attrs)) {
746 write_type_decl_left(header, def->type);
747 fprintf(header, " (STDMETHODCALLTYPE *");
748 write_name(header, def);
749 fprintf(header, ")(\n");
750 write_args(header, cur->args, name, 1, TRUE);
751 fprintf(header, ");\n");
752 fprintf(header, "\n");
757 static void write_c_method_def(const type_t *iface)
759 do_write_c_method_def(iface, iface->name);
762 static void write_c_disp_method_def(const type_t *iface)
764 do_write_c_method_def(iface->ref, iface->name);
767 static void write_method_proto(const type_t *iface)
771 if (!iface->funcs) return;
772 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
774 const var_t *def = cur->def;
776 if (!is_local(def->attrs)) {
777 /* proxy prototype */
778 write_type_decl_left(header, def->type);
779 fprintf(header, " CALLBACK %s_", iface->name);
780 write_name(header, def);
781 fprintf(header, "_Proxy(\n");
782 write_args(header, cur->args, iface->name, 1, TRUE);
783 fprintf(header, ");\n");
785 fprintf(header, "void __RPC_STUB %s_", iface->name);
786 write_name(header,def);
787 fprintf(header, "_Stub(\n");
788 fprintf(header, " IRpcStubBuffer* This,\n");
789 fprintf(header, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
790 fprintf(header, " PRPC_MESSAGE pRpcMessage,\n");
791 fprintf(header, " DWORD* pdwStubPhase);\n");
796 void write_locals(FILE *fp, const type_t *iface, int body)
798 static const char comment[]
799 = "/* WIDL-generated stub. You must provide an implementation for this. */";
800 const func_list_t *funcs = iface->funcs;
803 if (!is_object(iface->attrs) || !funcs)
806 LIST_FOR_EACH_ENTRY(cur, funcs, const func_t, entry) {
807 const var_t *def = cur->def;
808 const var_t *cas = is_callas(def->attrs);
812 LIST_FOR_EACH_ENTRY(m, iface->funcs, const func_t, entry)
813 if (!strcmp(m->def->name, cas->name))
815 if (&m->entry != iface->funcs) {
816 const var_t *mdef = m->def;
817 /* proxy prototype - use local prototype */
818 write_type_decl_left(fp, mdef->type);
819 fprintf(fp, " CALLBACK %s_", iface->name);
820 write_name(fp, mdef);
821 fprintf(fp, "_Proxy(\n");
822 write_args(fp, m->args, iface->name, 1, TRUE);
825 type_t *rt = mdef->type;
826 fprintf(fp, "\n{\n");
827 fprintf(fp, " %s\n", comment);
828 if (rt->name && strcmp(rt->name, "HRESULT") == 0)
829 fprintf(fp, " return E_NOTIMPL;\n");
832 write_type_decl(fp, rt, "rv");
834 fprintf(fp, " memset(&rv, 0, sizeof rv);\n");
835 fprintf(fp, " return rv;\n");
837 fprintf(fp, "}\n\n");
841 /* stub prototype - use remotable prototype */
842 write_type_decl_left(fp, def->type);
843 fprintf(fp, " __RPC_STUB %s_", iface->name);
844 write_name(fp, mdef);
845 fprintf(fp, "_Stub(\n");
846 write_args(fp, cur->args, iface->name, 1, TRUE);
849 /* Remotable methods must all return HRESULTs. */
850 fprintf(fp, "\n{\n %s\n return E_NOTIMPL;\n}\n\n", comment);
855 error_loc("invalid call_as attribute (%s -> %s)\n", def->name, cas->name);
860 static void write_function_proto(const type_t *iface, const func_t *fun, const char *prefix)
862 var_t *def = fun->def;
864 /* FIXME: do we need to handle call_as? */
865 write_type_decl_left(header, def->type);
866 fprintf(header, " ");
867 write_prefix_name(header, prefix, def);
868 fprintf(header, "(\n");
870 write_args(header, fun->args, iface->name, 0, TRUE);
872 fprintf(header, " void");
873 fprintf(header, ");\n");
876 static void write_function_protos(const type_t *iface)
878 const char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
879 int explicit_handle = is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE);
880 const var_t* explicit_handle_var;
882 int prefixes_differ = strcmp(prefix_client, prefix_server);
884 if (!iface->funcs) return;
885 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
887 var_t *def = cur->def;
889 /* check for a defined binding handle */
890 explicit_handle_var = get_explicit_handle_var(cur);
891 if (explicit_handle) {
892 if (!explicit_handle_var) {
893 error("%s() does not define an explicit binding handle!\n", def->name);
896 } else if (implicit_handle) {
897 if (explicit_handle_var) {
898 error("%s() must not define a binding handle!\n", def->name);
903 if (prefixes_differ) {
904 fprintf(header, "/* client prototype */\n");
905 write_function_proto(iface, cur, prefix_client);
906 fprintf(header, "/* server prototype */\n");
908 write_function_proto(iface, cur, prefix_server);
912 void write_forward(type_t *iface)
914 /* C/C++ forwards should only be written for object interfaces, so if we
915 * have a full definition we only write one if we find [object] among the
916 * attributes - however, if we don't have a full definition at this point
917 * (i.e. this is an IDL forward), then we also assume that it is an object
918 * interface, since non-object interfaces shouldn't need forwards */
919 if ((!iface->defined || is_object(iface->attrs) || is_attr(iface->attrs, ATTR_DISPINTERFACE))
920 && !iface->written) {
921 fprintf(header, "#ifndef __%s_FWD_DEFINED__\n", iface->name);
922 fprintf(header, "#define __%s_FWD_DEFINED__\n", iface->name);
923 fprintf(header, "typedef interface %s %s;\n", iface->name, iface->name);
924 fprintf(header, "#endif\n\n" );
925 iface->written = TRUE;
929 static void write_iface_guid(const type_t *iface)
931 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
932 write_guid(header, "IID", iface->name, uuid);
935 static void write_dispiface_guid(const type_t *iface)
937 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
938 write_guid(header, "DIID", iface->name, uuid);
941 static void write_coclass_guid(type_t *cocl)
943 const UUID *uuid = get_attrp(cocl->attrs, ATTR_UUID);
944 write_guid(header, "CLSID", cocl->name, uuid);
947 static void write_com_interface(type_t *iface)
949 if (!iface->funcs && !iface->ref) {
950 parser_warning("%s has no methods\n", iface->name);
954 fprintf(header, "/*****************************************************************************\n");
955 fprintf(header, " * %s interface\n", iface->name);
956 fprintf(header, " */\n");
957 fprintf(header,"#ifndef __%s_INTERFACE_DEFINED__\n", iface->name);
958 fprintf(header,"#define __%s_INTERFACE_DEFINED__\n\n", iface->name);
959 write_iface_guid(iface);
960 write_forward(iface);
962 fprintf(header, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
965 fprintf(header, "interface %s : public %s\n", iface->name, iface->ref->name);
966 fprintf(header, "{\n");
968 write_cpp_method_def(iface);
970 fprintf(header, "};\n");
974 fprintf(header, "interface %s\n", iface->name);
975 fprintf(header, "{\n");
976 fprintf(header, " BEGIN_INTERFACE\n");
977 fprintf(header, "\n");
979 write_cpp_method_def(iface);
981 fprintf(header, " END_INTERFACE\n");
982 fprintf(header, "};\n");
984 fprintf(header, "#else\n");
986 fprintf(header, "typedef struct %sVtbl {\n", iface->name);
988 fprintf(header, " BEGIN_INTERFACE\n");
989 fprintf(header, "\n");
990 write_c_method_def(iface);
992 fprintf(header, " END_INTERFACE\n");
993 fprintf(header, "} %sVtbl;\n", iface->name);
994 fprintf(header, "interface %s {\n", iface->name);
995 fprintf(header, " CONST_VTBL %sVtbl* lpVtbl;\n", iface->name);
996 fprintf(header, "};\n");
997 fprintf(header, "\n");
998 fprintf(header, "#ifdef COBJMACROS\n");
999 write_method_macro(iface, iface->name);
1000 fprintf(header, "#endif\n");
1001 fprintf(header, "\n");
1002 fprintf(header, "#endif\n");
1003 fprintf(header, "\n");
1004 write_method_proto(iface);
1005 write_locals(header, iface, FALSE);
1006 fprintf(header,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface->name);
1009 static void write_rpc_interface(const type_t *iface)
1011 unsigned int ver = get_attrv(iface->attrs, ATTR_VERSION);
1012 const char *var = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
1013 static int allocate_written = 0;
1015 if (!allocate_written)
1017 allocate_written = 1;
1018 fprintf(header, "void * __RPC_USER MIDL_user_allocate(size_t);\n");
1019 fprintf(header, "void __RPC_USER MIDL_user_free(void *);\n\n");
1022 fprintf(header, "/*****************************************************************************\n");
1023 fprintf(header, " * %s interface (v%d.%d)\n", iface->name, MAJORVERSION(ver), MINORVERSION(ver));
1024 fprintf(header, " */\n");
1025 fprintf(header,"#ifndef __%s_INTERFACE_DEFINED__\n", iface->name);
1026 fprintf(header,"#define __%s_INTERFACE_DEFINED__\n\n", iface->name);
1029 write_iface_guid(iface);
1030 if (var) fprintf(header, "extern handle_t %s;\n", var);
1033 fprintf(header, "extern RPC_IF_HANDLE %s%s_ClientIfHandle;\n", prefix_client, iface->name);
1034 fprintf(header, "extern RPC_IF_HANDLE %s%s_ServerIfHandle;\n", prefix_server, iface->name);
1038 fprintf(header, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n",
1039 prefix_client, iface->name, MAJORVERSION(ver), MINORVERSION(ver));
1040 fprintf(header, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n",
1041 prefix_server, iface->name, MAJORVERSION(ver), MINORVERSION(ver));
1043 write_function_protos(iface);
1045 fprintf(header,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface->name);
1047 /* FIXME: server/client code */
1050 void write_interface(type_t *iface)
1052 if (is_object(iface->attrs))
1053 write_com_interface(iface);
1055 write_rpc_interface(iface);
1058 void write_dispinterface(type_t *iface)
1060 fprintf(header, "/*****************************************************************************\n");
1061 fprintf(header, " * %s dispinterface\n", iface->name);
1062 fprintf(header, " */\n");
1063 fprintf(header,"#ifndef __%s_DISPINTERFACE_DEFINED__\n", iface->name);
1064 fprintf(header,"#define __%s_DISPINTERFACE_DEFINED__\n\n", iface->name);
1065 write_dispiface_guid(iface);
1066 write_forward(iface);
1068 fprintf(header, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
1069 fprintf(header, "interface %s : public %s\n", iface->name, iface->ref->name);
1070 fprintf(header, "{\n");
1071 fprintf(header, "};\n");
1072 fprintf(header, "#else\n");
1074 fprintf(header, "typedef struct %sVtbl {\n", iface->name);
1076 fprintf(header, " BEGIN_INTERFACE\n");
1077 fprintf(header, "\n");
1078 write_c_disp_method_def(iface);
1080 fprintf(header, " END_INTERFACE\n");
1081 fprintf(header, "} %sVtbl;\n", iface->name);
1082 fprintf(header, "interface %s {\n", iface->name);
1083 fprintf(header, " CONST_VTBL %sVtbl* lpVtbl;\n", iface->name);
1084 fprintf(header, "};\n");
1085 fprintf(header, "\n");
1086 fprintf(header, "#ifdef COBJMACROS\n");
1087 write_method_macro(iface->ref, iface->name);
1088 fprintf(header, "#endif\n");
1089 fprintf(header, "\n");
1090 fprintf(header, "#endif\n");
1091 fprintf(header, "\n");
1092 fprintf(header,"#endif /* __%s_DISPINTERFACE_DEFINED__ */\n\n", iface->name);
1095 void write_coclass(type_t *cocl)
1097 fprintf(header, "/*****************************************************************************\n");
1098 fprintf(header, " * %s coclass\n", cocl->name);
1099 fprintf(header, " */\n\n");
1100 write_coclass_guid(cocl);
1101 fprintf(header, "\n");
1104 void write_coclass_forward(type_t *cocl)
1106 fprintf(header, "#ifndef __%s_FWD_DEFINED__\n", cocl->name);
1107 fprintf(header, "#define __%s_FWD_DEFINED__\n", cocl->name);
1108 fprintf(header, "typedef struct %s %s;\n", cocl->name, cocl->name);
1109 fprintf(header, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl->name );