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;
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_attr(const attr_t
*a
, enum attr_type t
)
52 if (a
->type
== t
) return 1;
58 void *get_attrp(const attr_t
*a
, enum attr_type t
)
61 if (a
->type
== t
) return a
->u
.pval
;
67 unsigned long get_attrv(const attr_t
*a
, enum attr_type t
)
70 if (a
->type
== t
) return a
->u
.ival
;
76 int is_void(const type_t
*t
, const var_t
*v
)
78 if (v
&& v
->ptr_level
) return 0;
79 if (!t
->type
&& !t
->ref
) return 1;
83 static void write_guid(const char *guid_prefix
, const char *name
, const UUID
*uuid
)
86 fprintf(header
, "DEFINE_GUID(%s_%s, 0x%08lx, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
87 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
88 guid_prefix
, name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0],
89 uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5],
90 uuid
->Data4
[6], uuid
->Data4
[7]);
93 static void write_pident(FILE *h
, const var_t
*v
)
96 for (c
=0; c
<v
->ptr_level
; c
++) {
99 if (v
->name
) fprintf(h
, "%s", v
->name
);
102 void write_name(FILE *h
, const var_t
*v
)
104 if (is_attr( v
->attrs
, ATTR_PROPGET
))
106 else if (is_attr( v
->attrs
, ATTR_PROPPUT
))
108 else if (is_attr( v
->attrs
, ATTR_PROPPUTREF
))
109 fprintf(h
, "putref_" );
110 fprintf(h
, "%s", v
->name
);
113 const char* get_name(const var_t
*v
)
118 void write_array(FILE *h
, const expr_t
*v
, int field
)
121 while (NEXT_LINK(v
)) v
= NEXT_LINK(v
);
125 fprintf(h
, "%ld", v
->cval
); /* statically sized array */
127 if (field
) fprintf(h
, "1"); /* dynamically sized array */
135 static void write_field(FILE *h
, var_t
*v
)
140 write_type(h
, v
->type
, NULL
, v
->tname
);
146 /* not all C/C++ compilers support anonymous structs and unions */
147 switch (v
->type
->type
) {
149 case RPC_FC_CVSTRUCT
:
150 case RPC_FC_CPSTRUCT
:
153 case RPC_FC_BOGUS_STRUCT
:
154 case RPC_FC_ENCAPSULATED_UNION
:
155 fprintf(h
, " DUMMYSTRUCTNAME");
157 case RPC_FC_NON_ENCAPSULATED_UNION
:
158 fprintf(h
, " DUMMYUNIONNAME");
165 write_array(h
, v
->array
, 1);
170 static void write_fields(FILE *h
, var_t
*v
)
174 while (NEXT_LINK(v
)) v
= NEXT_LINK(v
);
177 if (v
== first
) break;
182 static void write_enums(FILE *h
, var_t
*v
)
185 while (NEXT_LINK(v
)) v
= NEXT_LINK(v
);
192 write_expr(h
, v
->eval
, 0);
202 void write_type(FILE *h
, type_t
*t
, const var_t
*v
, const char *n
)
206 if (n
) fprintf(h
, "%s", n
);
208 if (t
->is_const
) fprintf(h
, "const ");
210 if (t
->sign
> 0) fprintf(h
, "signed ");
211 else if (t
->sign
< 0) fprintf(h
, "unsigned ");
214 if (t
->ref
) fprintf(h
, t
->ref
->name
);
215 else fprintf(h
, "byte");
218 if (t
->ref
) fprintf(h
, t
->ref
->name
);
219 else fprintf(h
, "char");
226 if (t
->ref
) fprintf(h
, t
->ref
->name
);
227 else fprintf(h
, "small");
231 if (t
->ref
) fprintf(h
, t
->ref
->name
);
232 else fprintf(h
, "short");
236 if (t
->ref
) fprintf(h
, t
->ref
->name
);
237 else fprintf(h
, "long");
240 if (t
->ref
) fprintf(h
, t
->ref
->name
);
241 else fprintf(h
, "hyper");
247 fprintf(h
, "double");
251 if (t
->defined
&& !t
->written
) {
252 if (t
->name
) fprintf(h
, "enum %s {\n", t
->name
);
253 else fprintf(h
, "enum {\n");
256 write_enums(h
, t
->fields
);
260 else fprintf(h
, "enum %s", t
->name
);
262 case RPC_FC_ERROR_STATUS_T
:
263 if (t
->ref
) fprintf(h
, t
->ref
->name
);
264 else fprintf(h
, "error_status_t");
266 case RPC_FC_BIND_PRIMITIVE
:
267 if (t
->ref
) fprintf(h
, t
->ref
->name
);
268 else fprintf(h
, "handle_t");
271 case RPC_FC_CVSTRUCT
:
272 case RPC_FC_CPSTRUCT
:
275 case RPC_FC_BOGUS_STRUCT
:
276 case RPC_FC_ENCAPSULATED_UNION
:
277 if (t
->defined
&& !t
->written
) {
278 if (t
->name
) fprintf(h
, "struct %s {\n", t
->name
);
279 else fprintf(h
, "struct {\n");
282 write_fields(h
, t
->fields
);
286 else fprintf(h
, "struct %s", t
->name
);
288 case RPC_FC_NON_ENCAPSULATED_UNION
:
289 if (t
->defined
&& !t
->written
) {
290 if (t
->name
) fprintf(h
, "union %s {\n", t
->name
);
291 else fprintf(h
, "union {\n");
294 write_fields(h
, t
->fields
);
298 else fprintf(h
, "union %s", t
->name
);
301 fprintf(h
, "(unknown-type:%d)", t
->type
);
306 write_type(h
, t
->ref
, NULL
, t
->name
);
308 else fprintf(h
, "void");
312 for (c
=0; c
<v
->ptr_level
; c
++) {
321 struct user_type
*next
;
325 static struct user_type
*user_type_list
;
327 static int user_type_registered(const char *name
)
329 struct user_type
*ut
;
330 for (ut
= user_type_list
; ut
; ut
= ut
->next
)
331 if (!strcmp(name
, ut
->name
))
336 static void check_for_user_types(const var_t
*v
)
339 type_t
*type
= v
->type
;
340 const char *name
= v
->tname
;
341 for (type
= v
->type
; type
; type
= type
->ref
) {
342 if (type
->user_types_registered
) continue;
343 type
->user_types_registered
= 1;
344 if (is_attr(type
->attrs
, ATTR_WIREMARSHAL
)) {
345 if (!user_type_registered(name
))
347 struct user_type
*ut
= xmalloc(sizeof(struct user_type
) + strlen(name
));
348 strcpy(ut
->name
, name
);
349 ut
->next
= user_type_list
;
352 /* don't carry on parsing fields within this type as we are already
353 * using a wire marshaled type */
356 else if (type
->fields
)
358 const var_t
*fields
= type
->fields
;
359 while (NEXT_LINK(fields
)) fields
= NEXT_LINK(fields
);
360 check_for_user_types(fields
);
362 /* the wire_marshal attribute is always at least one reference away
363 * from the name of the type, so update it after the rest of the
364 * processing above */
365 if (type
->name
) name
= type
->name
;
371 void write_user_types(void)
373 struct user_type
*ut
;
374 for (ut
= user_type_list
; ut
; ut
= ut
->next
)
376 const char *name
= ut
->name
;
377 fprintf(header
, "unsigned long __RPC_USER %s_UserSize (unsigned long *, unsigned long, %s *);\n", name
, name
);
378 fprintf(header
, "unsigned char * __RPC_USER %s_UserMarshal (unsigned long *, unsigned char *, %s *);\n", name
, name
);
379 fprintf(header
, "unsigned char * __RPC_USER %s_UserUnmarshal(unsigned long *, unsigned char *, %s *);\n", name
, name
);
380 fprintf(header
, "void __RPC_USER %s_UserFree (unsigned long *, %s *);\n", name
, name
);
384 void write_typedef(type_t
*type
, const var_t
*names
)
386 const char *tname
= names
->tname
;
388 while (NEXT_LINK(names
)) names
= NEXT_LINK(names
);
390 fprintf(header
, "typedef ");
391 write_type(header
, type
, NULL
, tname
);
392 fprintf(header
, " ");
394 write_pident(header
, names
);
395 if (PREV_LINK(names
))
396 fprintf(header
, ", ");
397 names
= PREV_LINK(names
);
399 fprintf(header
, ";\n");
402 void write_expr(FILE *h
, const expr_t
*e
, int brackets
)
408 fprintf(h
, "%ld", e
->u
.lval
);
411 fprintf(h
, "0x%lx", e
->u
.lval
);
419 case EXPR_IDENTIFIER
:
420 fprintf(h
, "%s", e
->u
.sval
);
424 write_expr(h
, e
->ref
, 1);
428 write_expr(h
, e
->ref
, 1);
432 write_expr(h
, e
->ref
, 1);
436 write_type(h
, e
->u
.tref
->ref
, NULL
, e
->u
.tref
->name
);
438 write_expr(h
, e
->ref
, 1);
441 fprintf(h
, "sizeof(");
442 write_type(h
, e
->u
.tref
->ref
, NULL
, e
->u
.tref
->name
);
453 if (brackets
) fprintf(h
, "(");
454 write_expr(h
, e
->ref
, 1);
456 case EXPR_SHL
: fprintf(h
, " << "); break;
457 case EXPR_SHR
: fprintf(h
, " >> "); break;
458 case EXPR_MUL
: fprintf(h
, " * "); break;
459 case EXPR_DIV
: fprintf(h
, " / "); break;
460 case EXPR_ADD
: fprintf(h
, " + "); break;
461 case EXPR_SUB
: fprintf(h
, " - "); break;
462 case EXPR_AND
: fprintf(h
, " & "); break;
463 case EXPR_OR
: fprintf(h
, " | "); break;
466 write_expr(h
, e
->u
.ext
, 1);
467 if (brackets
) fprintf(h
, ")");
470 if (brackets
) fprintf(h
, "(");
471 write_expr(h
, e
->ref
, 1);
473 write_expr(h
, e
->u
.ext
, 1);
475 write_expr(h
, e
->ext2
, 1);
476 if (brackets
) fprintf(h
, ")");
481 void write_constdef(const var_t
*v
)
483 fprintf(header
, "#define %s (", get_name(v
));
484 write_expr(header
, v
->eval
, 0);
485 fprintf(header
, ")\n\n");
488 void write_externdef(const var_t
*v
)
490 fprintf(header
, "extern const ");
491 write_type(header
, v
->type
, NULL
, v
->tname
);
493 fprintf(header
, " ");
494 write_pident(header
, v
);
496 fprintf(header
, ";\n\n");
499 void write_library(const char *name
, const attr_t
*attr
) {
500 const UUID
*uuid
= get_attrp(attr
, ATTR_UUID
);
501 fprintf(header
, "\n");
502 write_guid("LIBID", name
, uuid
);
503 fprintf(header
, "\n");
507 const var_t
* get_explicit_handle_var(const func_t
* func
)
515 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
518 if (var
->type
->type
== RPC_FC_BIND_PRIMITIVE
)
521 var
= PREV_LINK(var
);
527 int has_out_arg_or_return(const func_t
*func
)
531 if (!is_void(func
->def
->type
, NULL
))
538 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
541 if (is_attr(var
->attrs
, ATTR_OUT
))
544 var
= PREV_LINK(var
);
550 /********** INTERFACES **********/
552 int is_object(const attr_t
*a
)
555 if (a
->type
== ATTR_OBJECT
|| a
->type
== ATTR_ODL
) return 1;
561 int is_local(const attr_t
*a
)
563 return is_attr(a
, ATTR_LOCAL
);
566 const var_t
*is_callas(const attr_t
*a
)
568 return get_attrp(a
, ATTR_CALLAS
);
571 static int write_method_macro(const type_t
*iface
, const char *name
)
574 func_t
*cur
= iface
->funcs
;
576 if (iface
->ref
) idx
= write_method_macro(iface
->ref
, name
);
579 if (!cur
) return idx
;
580 while (NEXT_LINK(cur
)) cur
= NEXT_LINK(cur
);
582 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
584 var_t
*def
= cur
->def
;
585 if (!is_callas(def
->attrs
)) {
586 var_t
*arg
= cur
->args
;
590 arg
= NEXT_LINK(arg
);
594 fprintf(header
, "#define %s_", name
);
595 write_name(header
,def
);
596 fprintf(header
, "(p");
597 for (c
=0; c
<argc
; c
++)
598 fprintf(header
, ",%c", c
+'a');
599 fprintf(header
, ") ");
601 fprintf(header
, "(p)->lpVtbl->");
602 write_name(header
, def
);
603 fprintf(header
, "(p");
604 for (c
=0; c
<argc
; c
++)
605 fprintf(header
, ",%c", c
+'a');
606 fprintf(header
, ")\n");
607 if (cur
->idx
== -1) cur
->idx
= idx
;
608 else if (cur
->idx
!= idx
) yyerror("BUG: method index mismatch in write_method_macro");
611 cur
= PREV_LINK(cur
);
616 void write_args(FILE *h
, var_t
*arg
, const char *name
, int method
, int do_indent
)
620 while (NEXT_LINK(arg
))
621 arg
= NEXT_LINK(arg
);
629 fprintf(h
, "%s* This", name
);
639 else fprintf(h
, ",");
641 write_type(h
, arg
->type
, arg
, arg
->tname
);
644 fprintf(h
, " (STDMETHODCALLTYPE *");
647 write_args(h
, arg
->args
, NULL
, 0, FALSE
);
655 write_array(h
, arg
->array
, 0);
656 arg
= PREV_LINK(arg
);
659 if (do_indent
) indentation
--;
662 static void write_cpp_method_def(const type_t
*iface
)
664 func_t
*cur
= iface
->funcs
;
667 while (NEXT_LINK(cur
)) cur
= NEXT_LINK(cur
);
669 var_t
*def
= cur
->def
;
670 if (!is_callas(def
->attrs
)) {
672 fprintf(header
, "virtual ");
673 write_type(header
, def
->type
, def
, def
->tname
);
674 fprintf(header
, " STDMETHODCALLTYPE ");
675 write_name(header
, def
);
676 fprintf(header
, "(\n");
677 write_args(header
, cur
->args
, iface
->name
, 2, TRUE
);
678 fprintf(header
, ") = 0;\n");
679 fprintf(header
, "\n");
681 cur
= PREV_LINK(cur
);
685 static void do_write_c_method_def(const type_t
*iface
, const char *name
)
687 const func_t
*cur
= iface
->funcs
;
689 if (iface
->ref
) do_write_c_method_def(iface
->ref
, name
);
692 while (NEXT_LINK(cur
)) cur
= NEXT_LINK(cur
);
694 fprintf(header
, "/*** %s methods ***/\n", iface
->name
);
696 const var_t
*def
= cur
->def
;
697 if (!is_callas(def
->attrs
)) {
699 write_type(header
, def
->type
, def
, def
->tname
);
700 fprintf(header
, " (STDMETHODCALLTYPE *");
701 write_name(header
, def
);
702 fprintf(header
, ")(\n");
703 write_args(header
, cur
->args
, name
, 1, TRUE
);
704 fprintf(header
, ");\n");
705 fprintf(header
, "\n");
707 cur
= PREV_LINK(cur
);
711 static void write_c_method_def(const type_t
*iface
)
713 do_write_c_method_def(iface
, iface
->name
);
716 static void write_c_disp_method_def(const type_t
*iface
)
718 do_write_c_method_def(iface
->ref
, iface
->name
);
721 static void write_method_proto(const type_t
*iface
)
723 const func_t
*cur
= iface
->funcs
;
726 while (NEXT_LINK(cur
)) cur
= NEXT_LINK(cur
);
728 const var_t
*def
= cur
->def
;
729 const var_t
*cas
= is_callas(def
->attrs
);
731 if (!is_local(def
->attrs
)) {
732 /* proxy prototype */
733 write_type(header
, def
->type
, def
, def
->tname
);
734 fprintf(header
, " CALLBACK %s_", iface
->name
);
735 write_name(header
, def
);
736 fprintf(header
, "_Proxy(\n");
737 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
738 fprintf(header
, ");\n");
740 fprintf(header
, "void __RPC_STUB %s_", iface
->name
);
741 write_name(header
,def
);
742 fprintf(header
, "_Stub(\n");
743 fprintf(header
, " IRpcStubBuffer* This,\n");
744 fprintf(header
, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
745 fprintf(header
, " PRPC_MESSAGE pRpcMessage,\n");
746 fprintf(header
, " DWORD* pdwStubPhase);\n");
750 while (NEXT_LINK(args
))
751 args
= NEXT_LINK(args
);
753 check_for_user_types(args
);
756 const func_t
*m
= iface
->funcs
;
757 while (m
&& strcmp(get_name(m
->def
), cas
->name
))
760 const var_t
*mdef
= m
->def
;
761 /* proxy prototype - use local prototype */
762 write_type(header
, mdef
->type
, mdef
, mdef
->tname
);
763 fprintf(header
, " CALLBACK %s_", iface
->name
);
764 write_name(header
, mdef
);
765 fprintf(header
, "_Proxy(\n");
766 write_args(header
, m
->args
, iface
->name
, 1, TRUE
);
767 fprintf(header
, ");\n");
768 /* stub prototype - use remotable prototype */
769 write_type(header
, def
->type
, def
, def
->tname
);
770 fprintf(header
, " __RPC_STUB %s_", iface
->name
);
771 write_name(header
, mdef
);
772 fprintf(header
, "_Stub(\n");
773 write_args(header
, cur
->args
, iface
->name
, 1, TRUE
);
774 fprintf(header
, ");\n");
777 yywarning("invalid call_as attribute (%s -> %s)\n", get_name(def
), cas
->name
);
781 cur
= PREV_LINK(cur
);
785 static void write_function_proto(const type_t
*iface
)
787 const char *implicit_handle
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
788 int explicit_handle
= is_attr(iface
->attrs
, ATTR_EXPLICIT_HANDLE
);
789 const var_t
* explicit_handle_var
;
791 func_t
*cur
= iface
->funcs
;
792 while (NEXT_LINK(cur
)) cur
= NEXT_LINK(cur
);
794 var_t
*def
= cur
->def
;
796 /* check for a defined binding handle */
797 explicit_handle_var
= get_explicit_handle_var(cur
);
798 if (explicit_handle
) {
799 if (!explicit_handle_var
) {
800 error("%s() does not define an explicit binding handle!\n", def
->name
);
803 } else if (implicit_handle
) {
804 if (explicit_handle_var
) {
805 error("%s() must not define a binding handle!\n", def
->name
);
810 /* FIXME: do we need to handle call_as? */
811 write_type(header
, def
->type
, def
, def
->tname
);
812 fprintf(header
, " ");
813 write_name(header
, def
);
814 fprintf(header
, "(\n");
816 write_args(header
, cur
->args
, iface
->name
, 0, TRUE
);
818 fprintf(header
, " void");
819 fprintf(header
, ");\n");
821 cur
= PREV_LINK(cur
);
825 void write_forward(type_t
*iface
)
827 /* C/C++ forwards should only be written for object interfaces, so if we
828 * have a full definition we only write one if we find [object] among the
829 * attributes - however, if we don't have a full definition at this point
830 * (i.e. this is an IDL forward), then we also assume that it is an object
831 * interface, since non-object interfaces shouldn't need forwards */
832 if ((!iface
->defined
|| is_object(iface
->attrs
) || is_attr(iface
->attrs
, ATTR_DISPINTERFACE
))
833 && !iface
->written
) {
834 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", iface
->name
);
835 fprintf(header
, "#define __%s_FWD_DEFINED__\n", iface
->name
);
836 fprintf(header
, "typedef interface %s %s;\n", iface
->name
, iface
->name
);
837 fprintf(header
, "#endif\n\n" );
838 iface
->written
= TRUE
;
842 static void write_iface_guid(const type_t
*iface
)
844 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
845 write_guid("IID", iface
->name
, uuid
);
848 static void write_dispiface_guid(const type_t
*iface
)
850 const UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
851 write_guid("DIID", iface
->name
, uuid
);
854 static void write_coclass_guid(class_t
*cocl
)
856 const UUID
*uuid
= get_attrp(cocl
->attrs
, ATTR_UUID
);
857 write_guid("CLSID", cocl
->name
, uuid
);
860 static void write_com_interface(type_t
*iface
)
862 if (!iface
->funcs
&& !iface
->ref
) {
863 yywarning("%s has no methods", iface
->name
);
867 fprintf(header
, "/*****************************************************************************\n");
868 fprintf(header
, " * %s interface\n", iface
->name
);
869 fprintf(header
, " */\n");
870 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
871 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
872 write_iface_guid(iface
);
873 write_forward(iface
);
875 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
878 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
879 fprintf(header
, "{\n");
881 write_cpp_method_def(iface
);
883 fprintf(header
, "};\n");
887 fprintf(header
, "interface %s\n", iface
->name
);
888 fprintf(header
, "{\n");
889 fprintf(header
, " BEGIN_INTERFACE\n");
890 fprintf(header
, "\n");
892 write_cpp_method_def(iface
);
894 fprintf(header
, " END_INTERFACE\n");
895 fprintf(header
, "};\n");
897 fprintf(header
, "#else\n");
899 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
901 fprintf(header
, " BEGIN_INTERFACE\n");
902 fprintf(header
, "\n");
903 write_c_method_def(iface
);
905 fprintf(header
, " END_INTERFACE\n");
906 fprintf(header
, "} %sVtbl;\n", iface
->name
);
907 fprintf(header
, "interface %s {\n", iface
->name
);
908 fprintf(header
, " const %sVtbl* lpVtbl;\n", iface
->name
);
909 fprintf(header
, "};\n");
910 fprintf(header
, "\n");
911 fprintf(header
, "#ifdef COBJMACROS\n");
912 write_method_macro(iface
, iface
->name
);
913 fprintf(header
, "#endif\n");
914 fprintf(header
, "\n");
915 fprintf(header
, "#endif\n");
916 fprintf(header
, "\n");
917 write_method_proto(iface
);
918 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
921 static void write_rpc_interface(const type_t
*iface
)
923 unsigned long ver
= get_attrv(iface
->attrs
, ATTR_VERSION
);
924 const char *var
= get_attrp(iface
->attrs
, ATTR_IMPLICIT_HANDLE
);
925 static int allocate_written
= 0;
927 if (!allocate_written
)
929 allocate_written
= 1;
930 fprintf(header
, "void * __RPC_USER MIDL_user_allocate(size_t);\n");
931 fprintf(header
, "void __RPC_USER MIDL_user_free(void *);\n\n");
934 fprintf(header
, "/*****************************************************************************\n");
935 fprintf(header
, " * %s interface (v%d.%d)\n", iface
->name
, LOWORD(ver
), HIWORD(ver
));
936 fprintf(header
, " */\n");
937 fprintf(header
,"#ifndef __%s_INTERFACE_DEFINED__\n", iface
->name
);
938 fprintf(header
,"#define __%s_INTERFACE_DEFINED__\n\n", iface
->name
);
941 write_iface_guid(iface
);
942 if (var
) fprintf(header
, "extern handle_t %s;\n", var
);
945 fprintf(header
, "extern RPC_IF_HANDLE %s_ClientIfHandle;\n", iface
->name
);
946 fprintf(header
, "extern RPC_IF_HANDLE %s_ServerIfHandle;\n", iface
->name
);
950 fprintf(header
, "extern RPC_IF_HANDLE %s_v%d_%d_c_ifspec;\n", iface
->name
, LOWORD(ver
), HIWORD(ver
));
951 fprintf(header
, "extern RPC_IF_HANDLE %s_v%d_%d_s_ifspec;\n", iface
->name
, LOWORD(ver
), HIWORD(ver
));
953 write_function_proto(iface
);
955 fprintf(header
,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface
->name
);
957 /* FIXME: server/client code */
960 void write_interface(type_t
*iface
)
962 if (is_object(iface
->attrs
))
963 write_com_interface(iface
);
965 write_rpc_interface(iface
);
968 void write_dispinterface(type_t
*iface
)
970 fprintf(header
, "/*****************************************************************************\n");
971 fprintf(header
, " * %s dispinterface\n", iface
->name
);
972 fprintf(header
, " */\n");
973 fprintf(header
,"#ifndef __%s_DISPINTERFACE_DEFINED__\n", iface
->name
);
974 fprintf(header
,"#define __%s_DISPINTERFACE_DEFINED__\n\n", iface
->name
);
975 write_dispiface_guid(iface
);
976 write_forward(iface
);
978 fprintf(header
, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
979 fprintf(header
, "interface %s : public %s\n", iface
->name
, iface
->ref
->name
);
980 fprintf(header
, "{\n");
981 fprintf(header
, "};\n");
982 fprintf(header
, "#else\n");
984 fprintf(header
, "typedef struct %sVtbl {\n", iface
->name
);
986 fprintf(header
, " BEGIN_INTERFACE\n");
987 fprintf(header
, "\n");
988 write_c_disp_method_def(iface
);
990 fprintf(header
, " END_INTERFACE\n");
991 fprintf(header
, "} %sVtbl;\n", iface
->name
);
992 fprintf(header
, "interface %s {\n", iface
->name
);
993 fprintf(header
, " const %sVtbl* lpVtbl;\n", iface
->name
);
994 fprintf(header
, "};\n");
995 fprintf(header
, "\n");
996 fprintf(header
, "#ifdef COBJMACROS\n");
997 write_method_macro(iface
->ref
, iface
->name
);
998 fprintf(header
, "#endif\n");
999 fprintf(header
, "\n");
1000 fprintf(header
, "#endif\n");
1001 fprintf(header
, "\n");
1002 fprintf(header
,"#endif /* __%s_DISPINTERFACE_DEFINED__ */\n\n", iface
->name
);
1005 void write_coclass(class_t
*cocl
)
1007 fprintf(header
, "/*****************************************************************************\n");
1008 fprintf(header
, " * %s coclass\n", cocl
->name
);
1009 fprintf(header
, " */\n\n");
1010 write_coclass_guid(cocl
);
1011 fprintf(header
, "\n");
1014 void write_coclass_forward(class_t
*cocl
)
1016 fprintf(header
, "#ifndef __%s_FWD_DEFINED__\n", cocl
->name
);
1017 fprintf(header
, "#define __%s_FWD_DEFINED__\n", cocl
->name
);
1018 fprintf(header
, "typedef struct %s %s;\n", cocl
->name
, cocl
->name
);
1019 fprintf(header
, "#endif /* defined __%s_FWD_DEFINED__\n\n", cocl
->name
);