Fixed potential crash in fd_dump function.
[wine/multimedia.git] / tools / widl / header.c
blob67ea841dbdbd5c7b3b55aa6598ecf97f1e978124
1 /*
2 * IDL Compiler
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28 #include <string.h>
29 #include <assert.h>
30 #include <ctype.h>
31 #include <signal.h>
33 #include "windef.h"
34 #include "widl.h"
35 #include "utils.h"
36 #include "parser.h"
37 #include "header.h"
39 static int indentation = 0;
41 static void indent(int delta)
43 int c;
44 if (delta < 0) indentation += delta;
45 for (c=0; c<indentation; c++) fprintf(header, " ");
46 if (delta > 0) indentation += delta;
49 int is_attr(attr_t *a, enum attr_type t)
51 while (a) {
52 if (a->type == t) return 1;
53 a = NEXT_LINK(a);
55 return 0;
58 void *get_attrp(attr_t *a, enum attr_type t)
60 while (a) {
61 if (a->type == t) return a->u.pval;
62 a = NEXT_LINK(a);
64 return NULL;
67 unsigned long get_attrv(attr_t *a, enum attr_type t)
69 while (a) {
70 if (a->type == t) return a->u.ival;
71 a = NEXT_LINK(a);
73 return 0;
76 int is_void(type_t *t, var_t *v)
78 if (v && v->ptr_level) return 0;
79 if (!t->type && !t->ref) return 1;
80 return 0;
83 static void write_pident(FILE *h, var_t *v)
85 int c;
86 for (c=0; c<v->ptr_level; c++) {
87 fprintf(h, "*");
89 if (v->name) fprintf(h, "%s", v->name);
92 void write_name(FILE *h, var_t *v)
94 if (is_attr( v->attrs, ATTR_PROPGET ))
95 fprintf(h, "get_" );
96 else if (is_attr( v->attrs, ATTR_PROPPUT ))
97 fprintf(h, "put_" );
98 fprintf(h, "%s", v->name);
101 char* get_name(var_t *v)
103 return v->name;
106 static void write_array(FILE *h, expr_t *v, int field)
108 if (!v) return;
109 while (NEXT_LINK(v)) v = NEXT_LINK(v);
110 fprintf(h, "[");
111 while (v) {
112 if (v->is_const)
113 fprintf(h, "%ld", v->cval); /* statically sized array */
114 else
115 if (field) fprintf(h, "1"); /* dynamically sized array */
116 if (PREV_LINK(v))
117 fprintf(h, ", ");
118 v = PREV_LINK(v);
120 fprintf(h, "]");
123 static void write_field(FILE *h, var_t *v)
125 if (!v) return;
126 if (v->type) {
127 indent(0);
128 write_type(h, v->type, NULL, v->tname);
129 if (get_name(v)) {
130 fprintf(h, " ");
131 write_pident(h, v);
133 else {
134 /* not all C/C++ compilers support anonymous structs and unions */
135 switch (v->type->type) {
136 case RPC_FC_STRUCT:
137 case RPC_FC_CVSTRUCT:
138 case RPC_FC_CPSTRUCT:
139 case RPC_FC_CSTRUCT:
140 case RPC_FC_PSTRUCT:
141 case RPC_FC_BOGUS_STRUCT:
142 case RPC_FC_ENCAPSULATED_UNION:
143 fprintf(h, " DUMMYSTRUCTNAME");
144 break;
145 case RPC_FC_NON_ENCAPSULATED_UNION:
146 fprintf(h, " DUMMYUNIONNAME");
147 break;
148 default:
149 /* ? */
150 break;
153 write_array(h, v->array, 1);
154 fprintf(h, ";\n");
158 static void write_fields(FILE *h, var_t *v)
160 var_t *first = v;
161 if (!v) return;
162 while (NEXT_LINK(v)) v = NEXT_LINK(v);
163 while (v) {
164 write_field(h, v);
165 if (v == first) break;
166 v = PREV_LINK(v);
170 static void write_enums(FILE *h, var_t *v)
172 if (!v) return;
173 while (NEXT_LINK(v)) v = NEXT_LINK(v);
174 while (v) {
175 if (get_name(v)) {
176 indent(0);
177 write_name(h, v);
178 if (v->eval) {
179 fprintf(h, " = ");
180 write_expr(h, v->eval);
183 if (PREV_LINK(v))
184 fprintf(h, ",\n");
185 v = PREV_LINK(v);
187 fprintf(h, "\n");
190 void write_type(FILE *h, type_t *t, var_t *v, char *n)
192 int c;
194 if (n) fprintf(h, "%s", n);
195 else {
196 if (t->is_const) fprintf(h, "const ");
197 if (t->type) {
198 if (t->sign > 0) fprintf(h, "signed ");
199 else if (t->sign < 0) fprintf(h, "unsigned ");
200 switch (t->type) {
201 case RPC_FC_BYTE:
202 if (t->ref) fprintf(h, t->ref->name);
203 else fprintf(h, "byte");
204 break;
205 case RPC_FC_CHAR:
206 if (t->ref) fprintf(h, t->ref->name);
207 else fprintf(h, "char");
208 break;
209 case RPC_FC_WCHAR:
210 fprintf(h, "wchar_t");
211 break;
212 case RPC_FC_USHORT:
213 case RPC_FC_SHORT:
214 if (t->ref) fprintf(h, t->ref->name);
215 else fprintf(h, "short");
216 break;
217 case RPC_FC_ULONG:
218 case RPC_FC_LONG:
219 if (t->ref) fprintf(h, t->ref->name);
220 else fprintf(h, "long");
221 break;
222 case RPC_FC_HYPER:
223 if (t->ref) fprintf(h, t->ref->name);
224 else fprintf(h, "hyper");
225 break;
226 case RPC_FC_FLOAT:
227 fprintf(h, "float");
228 break;
229 case RPC_FC_DOUBLE:
230 fprintf(h, "double");
231 break;
232 case RPC_FC_ENUM16:
233 case RPC_FC_ENUM32:
234 if (t->defined && !t->written) {
235 if (t->name) fprintf(h, "enum %s {\n", t->name);
236 else fprintf(h, "enum {\n");
237 t->written = TRUE;
238 indentation++;
239 write_enums(h, t->fields);
240 indent(-1);
241 fprintf(h, "}");
243 else fprintf(h, "enum %s", t->name);
244 break;
245 case RPC_FC_ERROR_STATUS_T:
246 if (t->ref) fprintf(h, t->ref->name);
247 else fprintf(h, "error_status_t");
248 break;
249 case RPC_FC_BIND_PRIMITIVE:
250 if (t->ref) fprintf(h, t->ref->name);
251 else fprintf(h, "handle_t");
252 break;
253 case RPC_FC_STRUCT:
254 case RPC_FC_CVSTRUCT:
255 case RPC_FC_CPSTRUCT:
256 case RPC_FC_CSTRUCT:
257 case RPC_FC_PSTRUCT:
258 case RPC_FC_BOGUS_STRUCT:
259 case RPC_FC_ENCAPSULATED_UNION:
260 if (t->defined && !t->written) {
261 if (t->name) fprintf(h, "struct %s {\n", t->name);
262 else fprintf(h, "struct {\n");
263 t->written = TRUE;
264 indentation++;
265 write_fields(h, t->fields);
266 indent(-1);
267 fprintf(h, "}");
269 else fprintf(h, "struct %s", t->name);
270 break;
271 case RPC_FC_NON_ENCAPSULATED_UNION:
272 if (t->defined && !t->written) {
273 if (t->name) fprintf(h, "union %s {\n", t->name);
274 else fprintf(h, "union {\n");
275 t->written = TRUE;
276 indentation++;
277 write_fields(h, t->fields);
278 indent(-1);
279 fprintf(h, "}");
281 else fprintf(h, "union %s", t->name);
282 break;
283 default:
284 fprintf(h, "(unknown-type:%d)", t->type);
287 else {
288 if (t->ref) {
289 write_type(h, t->ref, NULL, t->name);
291 else fprintf(h, "void");
294 if (v) {
295 for (c=0; c<v->ptr_level; c++) {
296 fprintf(h, "*");
301 void write_typedef(type_t *type, var_t *names)
303 char *tname = names->tname;
304 var_t *lname;
305 while (NEXT_LINK(names)) names = NEXT_LINK(names);
306 lname = names;
307 fprintf(header, "typedef ");
308 write_type(header, type, NULL, tname);
309 fprintf(header, " ");
310 while (names) {
311 write_pident(header, names);
312 if (PREV_LINK(names))
313 fprintf(header, ", ");
314 names = PREV_LINK(names);
316 fprintf(header, ";\n");
318 if (get_attrp(type->attrs, ATTR_WIREMARSHAL)) {
319 names = lname;
320 while (names) {
321 char *name = get_name(names);
322 fprintf(header, "unsigned long __RPC_USER %s_UserSize (unsigned long *, unsigned long, %s *);\n", name, name);
323 fprintf(header, "unsigned char * __RPC_USER %s_UserMarshal (unsigned long *, unsigned char *, %s *);\n", name, name);
324 fprintf(header, "unsigned char * __RPC_USER %s_UserUnmarshal(unsigned long *, unsigned char *, %s *);\n", name, name);
325 fprintf(header, "void __RPC_USER %s_UserFree (unsigned long *, %s *);\n", name, name);
326 if (PREV_LINK(names))
327 fprintf(header, ", ");
328 names = PREV_LINK(names);
332 fprintf(header, "\n");
335 static void do_write_expr(FILE *h, expr_t *e, int p)
337 switch (e->type) {
338 case EXPR_VOID:
339 break;
340 case EXPR_NUM:
341 fprintf(h, "%ld", e->u.lval);
342 break;
343 case EXPR_HEXNUM:
344 fprintf(h, "0x%lx", e->u.lval);
345 break;
346 case EXPR_IDENTIFIER:
347 fprintf(h, "%s", e->u.sval);
348 break;
349 case EXPR_NEG:
350 fprintf(h, "-");
351 do_write_expr(h, e->ref, 1);
352 break;
353 case EXPR_NOT:
354 fprintf(h, "~");
355 do_write_expr(h, e->ref, 1);
356 break;
357 case EXPR_PPTR:
358 fprintf(h, "*");
359 do_write_expr(h, e->ref, 1);
360 break;
361 case EXPR_CAST:
362 fprintf(h, "(");
363 write_type(h, e->u.tref->ref, NULL, e->u.tref->name);
364 fprintf(h, ")");
365 do_write_expr(h, e->ref, 1);
366 break;
367 case EXPR_SIZEOF:
368 fprintf(h, "sizeof(");
369 write_type(h, e->u.tref->ref, NULL, e->u.tref->name);
370 fprintf(h, ")");
371 break;
372 case EXPR_SHL:
373 case EXPR_SHR:
374 case EXPR_MUL:
375 case EXPR_DIV:
376 case EXPR_ADD:
377 case EXPR_SUB:
378 case EXPR_AND:
379 case EXPR_OR:
380 if (p) fprintf(h, "(");
381 do_write_expr(h, e->ref, 1);
382 switch (e->type) {
383 case EXPR_SHL: fprintf(h, " << "); break;
384 case EXPR_SHR: fprintf(h, " >> "); break;
385 case EXPR_MUL: fprintf(h, " * "); break;
386 case EXPR_DIV: fprintf(h, " / "); break;
387 case EXPR_ADD: fprintf(h, " + "); break;
388 case EXPR_SUB: fprintf(h, " - "); break;
389 case EXPR_AND: fprintf(h, " & "); break;
390 case EXPR_OR: fprintf(h, " | "); break;
391 default: break;
393 do_write_expr(h, e->u.ext, 1);
394 if (p) fprintf(h, ")");
395 break;
396 case EXPR_COND:
397 if (p) fprintf(h, "(");
398 do_write_expr(h, e->ref, 1);
399 fprintf(h, " ? ");
400 do_write_expr(h, e->u.ext, 1);
401 fprintf(h, " : ");
402 do_write_expr(h, e->ext2, 1);
403 if (p) fprintf(h, ")");
404 break;
408 void write_expr(FILE *h, expr_t *e)
410 do_write_expr(h, e, 0);
413 void write_constdef(var_t *v)
415 fprintf(header, "#define %s (", get_name(v));
416 write_expr(header, v->eval);
417 fprintf(header, ")\n\n");
420 void write_externdef(var_t *v)
422 fprintf(header, "extern const ");
423 write_type(header, v->type, NULL, v->tname);
424 if (get_name(v)) {
425 fprintf(header, " ");
426 write_pident(header, v);
428 fprintf(header, ";\n\n");
431 /********** INTERFACES **********/
433 int is_object(attr_t *a)
435 while (a) {
436 if (a->type == ATTR_OBJECT || a->type == ATTR_ODL) return 1;
437 a = NEXT_LINK(a);
439 return 0;
442 int is_local(attr_t *a)
444 return is_attr(a, ATTR_LOCAL);
447 var_t *is_callas(attr_t *a)
449 return get_attrp(a, ATTR_CALLAS);
452 static int write_method_macro(type_t *iface, char *name)
454 int idx;
455 func_t *cur = iface->funcs;
457 if (iface->ref) idx = write_method_macro(iface->ref, name);
458 else idx = 0;
460 if (!cur) return idx;
461 while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
463 fprintf(header, "/*** %s methods ***/\n", iface->name);
464 while (cur) {
465 var_t *def = cur->def;
466 if (!is_callas(def->attrs)) {
467 var_t *arg = cur->args;
468 int argc = 0;
469 int c;
470 while (arg) {
471 arg = NEXT_LINK(arg);
472 argc++;
475 fprintf(header, "#define %s_", name);
476 write_name(header,def);
477 fprintf(header, "(p");
478 for (c=0; c<argc; c++)
479 fprintf(header, ",%c", c+'a');
480 fprintf(header, ") ");
482 fprintf(header, "(p)->lpVtbl->");
483 write_name(header, def);
484 fprintf(header, "(p");
485 for (c=0; c<argc; c++)
486 fprintf(header, ",%c", c+'a');
487 fprintf(header, ")\n");
488 if (cur->idx == -1) cur->idx = idx;
489 else if (cur->idx != idx) yyerror("BUG: method index mismatch in write_method_macro");
490 idx++;
492 cur = PREV_LINK(cur);
494 return idx;
497 void write_args(FILE *h, var_t *arg, char *name, int method, int do_indent)
499 int count = 0;
500 if (arg) {
501 while (NEXT_LINK(arg))
502 arg = NEXT_LINK(arg);
504 if (do_indent)
506 if (h == header) {
507 indentation++;
508 indent(0);
509 } else fprintf(h, " ");
511 if (method == 1) {
512 fprintf(h, "%s* This", name);
513 count++;
515 while (arg) {
516 if (count) {
517 if (do_indent)
519 fprintf(h, ",\n");
520 if (h == header) indent(0);
521 else fprintf(h, " ");
523 else fprintf(h, ",");
525 write_type(h, arg->type, arg, arg->tname);
526 if (arg->args)
528 fprintf(h, " (STDMETHODCALLTYPE *");
529 write_name(h,arg);
530 fprintf(h, ")(");
531 write_args(h, arg->args, NULL, 0, FALSE);
532 fprintf(h, ")");
534 else
536 fprintf(h, " ");
537 write_name(h, arg);
539 write_array(h, arg->array, 0);
540 arg = PREV_LINK(arg);
541 count++;
543 if (do_indent && h == header) indentation--;
546 static void write_cpp_method_def(type_t *iface)
548 func_t *cur = iface->funcs;
550 if (!cur) return;
551 while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
552 while (cur) {
553 var_t *def = cur->def;
554 if (!is_callas(def->attrs)) {
555 indent(0);
556 fprintf(header, "virtual ");
557 write_type(header, def->type, def, def->tname);
558 fprintf(header, " STDMETHODCALLTYPE ");
559 write_name(header, def);
560 fprintf(header, "(\n");
561 write_args(header, cur->args, iface->name, 2, TRUE);
562 fprintf(header, ") = 0;\n");
563 fprintf(header, "\n");
565 cur = PREV_LINK(cur);
569 static void do_write_c_method_def(type_t *iface, char *name)
571 func_t *cur = iface->funcs;
573 if (iface->ref) do_write_c_method_def(iface->ref, name);
575 if (!cur) return;
576 while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
577 indent(0);
578 fprintf(header, "/*** %s methods ***/\n", iface->name);
579 while (cur) {
580 var_t *def = cur->def;
581 if (!is_callas(def->attrs)) {
582 indent(0);
583 write_type(header, def->type, def, def->tname);
584 fprintf(header, " (STDMETHODCALLTYPE *");
585 write_name(header, def);
586 fprintf(header, ")(\n");
587 write_args(header, cur->args, name, 1, TRUE);
588 fprintf(header, ");\n");
589 fprintf(header, "\n");
591 cur = PREV_LINK(cur);
595 static void write_c_method_def(type_t *iface)
597 do_write_c_method_def(iface, iface->name);
600 static void write_c_disp_method_def(type_t *iface)
602 do_write_c_method_def(iface->ref, iface->name);
605 static void write_method_proto(type_t *iface)
607 func_t *cur = iface->funcs;
609 if (!cur) return;
610 while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
611 while (cur) {
612 var_t *def = cur->def;
613 var_t *cas = is_callas(def->attrs);
614 if (!is_local(def->attrs)) {
615 /* proxy prototype */
616 write_type(header, def->type, def, def->tname);
617 fprintf(header, " CALLBACK %s_", iface->name);
618 write_name(header, def);
619 fprintf(header, "_Proxy(\n");
620 write_args(header, cur->args, iface->name, 1, TRUE);
621 fprintf(header, ");\n");
622 /* stub prototype */
623 fprintf(header, "void __RPC_STUB %s_", iface->name);
624 write_name(header,def);
625 fprintf(header, "_Stub(\n");
626 fprintf(header, " struct IRpcStubBuffer* This,\n");
627 fprintf(header, " struct IRpcChannelBuffer* pRpcChannelBuffer,\n");
628 fprintf(header, " PRPC_MESSAGE pRpcMessage,\n");
629 fprintf(header, " DWORD* pdwStubPhase);\n");
631 if (cas) {
632 func_t *m = iface->funcs;
633 while (m && strcmp(get_name(m->def), cas->name))
634 m = NEXT_LINK(m);
635 if (m) {
636 var_t *mdef = m->def;
637 /* proxy prototype - use local prototype */
638 write_type(header, mdef->type, mdef, mdef->tname);
639 fprintf(header, " CALLBACK %s_", iface->name);
640 write_name(header, mdef);
641 fprintf(header, "_Proxy(\n");
642 write_args(header, m->args, iface->name, 1, TRUE);
643 fprintf(header, ");\n");
644 /* stub prototype - use remotable prototype */
645 write_type(header, def->type, def, def->tname);
646 fprintf(header, " __RPC_STUB %s_", iface->name);
647 write_name(header, mdef);
648 fprintf(header, "_Stub(\n");
649 write_args(header, cur->args, iface->name, 1, TRUE);
650 fprintf(header, ");\n");
652 else {
653 yywarning("invalid call_as attribute (%s -> %s)\n", get_name(def), cas->name);
657 cur = PREV_LINK(cur);
661 static void write_function_proto(type_t *iface)
663 func_t *cur = iface->funcs;
664 while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
665 while (cur) {
666 var_t *def = cur->def;
667 /* FIXME: do we need to handle call_as? */
668 write_type(header, def->type, def, def->tname);
669 fprintf(header, " ");
670 write_name(header, def);
671 fprintf(header, "(\n");
672 write_args(header, cur->args, iface->name, 0, TRUE);
673 fprintf(header, ");\n");
675 cur = PREV_LINK(cur);
679 void write_forward(type_t *iface)
681 /* C/C++ forwards should only be written for object interfaces, so if we
682 * have a full definition we only write one if we find [object] among the
683 * attributes - however, if we don't have a full definition at this point
684 * (i.e. this is an IDL forward), then we also assume that it is an object
685 * interface, since non-object interfaces shouldn't need forwards */
686 if ((!iface->defined || is_object(iface->attrs) || is_attr(iface->attrs, ATTR_DISPINTERFACE))
687 && !iface->written) {
688 fprintf(header,"#ifndef __%s_FWD_DEFINED__\n", iface->name);
689 fprintf(header,"#define __%s_FWD_DEFINED__\n", iface->name);
690 fprintf(header, "typedef struct %s %s;\n", iface->name, iface->name);
691 fprintf(header, "#endif\n\n" );
692 iface->written = TRUE;
696 void write_guid(const char *guid_prefix, const char *name, UUID *uuid)
698 if (!uuid) return;
699 fprintf(header, "DEFINE_GUID(%s_%s, 0x%08lx, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
700 guid_prefix, name, uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0], uuid->Data4[1],
701 uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5], uuid->Data4[6], uuid->Data4[7]);
704 void write_iface_guid(type_t *iface)
706 UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
707 write_guid("IID", iface->name, uuid);
710 void write_dispiface_guid(type_t *iface)
712 UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
713 write_guid("DIID", iface->name, uuid);
716 void write_coclass_guid(class_t *cocl)
718 UUID *uuid = get_attrp(cocl->attrs, ATTR_UUID);
719 write_guid("CLSID", cocl->name, uuid);
722 void write_com_interface(type_t *iface)
724 if (!iface->funcs && !iface->ref) {
725 yywarning("%s has no methods", iface->name);
726 return;
729 fprintf(header, "/*****************************************************************************\n");
730 fprintf(header, " * %s interface\n", iface->name);
731 fprintf(header, " */\n");
732 fprintf(header,"#ifndef __%s_INTERFACE_DEFINED__\n", iface->name);
733 fprintf(header,"#define __%s_INTERFACE_DEFINED__\n\n", iface->name);
734 write_iface_guid(iface);
735 write_forward(iface);
736 /* C++ interface */
737 fprintf(header, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
738 if (iface->ref)
740 fprintf(header, "struct %s : public %s\n", iface->name, iface->ref->name);
741 fprintf(header, "{\n");
742 indentation++;
743 write_cpp_method_def(iface);
744 indentation--;
745 fprintf(header, "};\n");
747 else
749 fprintf(header, "struct %s\n", iface->name);
750 fprintf(header, "{\n");
751 fprintf(header, " BEGIN_INTERFACE\n");
752 fprintf(header, "\n");
753 indentation++;
754 write_cpp_method_def(iface);
755 indentation--;
756 fprintf(header, " END_INTERFACE\n");
757 fprintf(header, "};\n");
759 fprintf(header, "#else\n");
760 /* C interface */
761 fprintf(header, "typedef struct %sVtbl %sVtbl;\n", iface->name, iface->name);
762 fprintf(header, "struct %s {\n", iface->name);
763 fprintf(header, " const %sVtbl* lpVtbl;\n", iface->name);
764 fprintf(header, "};\n");
765 fprintf(header, "struct %sVtbl {\n", iface->name);
766 indentation++;
767 fprintf(header, " BEGIN_INTERFACE\n");
768 fprintf(header, "\n");
769 write_c_method_def(iface);
770 indentation--;
771 fprintf(header, " END_INTERFACE\n");
772 fprintf(header, "};\n");
773 fprintf(header, "\n");
774 fprintf(header, "#ifdef COBJMACROS\n");
775 write_method_macro(iface, iface->name);
776 fprintf(header, "#endif\n");
777 fprintf(header, "\n");
778 fprintf(header, "#endif\n");
779 fprintf(header, "\n");
780 write_method_proto(iface);
781 fprintf(header,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface->name);
784 void write_rpc_interface(type_t *iface)
786 unsigned long ver = get_attrv(iface->attrs, ATTR_VERSION);
788 if (!iface->funcs) return;
790 fprintf(header, "/*****************************************************************************\n");
791 fprintf(header, " * %s interface (v%d.%d)\n", iface->name, LOWORD(ver), HIWORD(ver));
792 fprintf(header, " */\n");
793 write_iface_guid(iface);
794 fprintf(header, "extern RPC_IF_HANDLE %s_v%d_%d_c_ifspec;\n", iface->name, LOWORD(ver), HIWORD(ver));
795 fprintf(header, "extern RPC_IF_HANDLE %s_v%d_%d_s_ifspec;\n", iface->name, LOWORD(ver), HIWORD(ver));
796 write_function_proto(iface);
797 fprintf(header, "\n");
799 /* FIXME: server/client code */
802 void write_interface(type_t *iface)
804 if (is_object(iface->attrs))
805 write_com_interface(iface);
806 else
807 write_rpc_interface(iface);
810 void write_dispinterface(type_t *iface)
812 fprintf(header, "/*****************************************************************************\n");
813 fprintf(header, " * %s dispinterface\n", iface->name);
814 fprintf(header, " */\n");
815 fprintf(header,"#ifndef __%s_DISPINTERFACE_DEFINED__\n", iface->name);
816 fprintf(header,"#define __%s_DISPINTERFACE_DEFINED__\n\n", iface->name);
817 write_dispiface_guid(iface);
818 write_forward(iface);
819 /* C++ interface */
820 fprintf(header, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
821 fprintf(header, "struct %s : public %s\n", iface->name, iface->ref->name);
822 fprintf(header, "{\n");
823 fprintf(header, "};\n");
824 fprintf(header, "#else\n");
825 /* C interface */
826 fprintf(header, "typedef struct %sVtbl %sVtbl;\n", iface->name, iface->name);
827 fprintf(header, "struct %s {\n", iface->name);
828 fprintf(header, " const %sVtbl* lpVtbl;\n", iface->name);
829 fprintf(header, "};\n");
830 fprintf(header, "struct %sVtbl {\n", iface->name);
831 indentation++;
832 fprintf(header, " BEGIN_INTERFACE\n");
833 fprintf(header, "\n");
834 write_c_disp_method_def(iface);
835 indentation--;
836 fprintf(header, " END_INTERFACE\n");
837 fprintf(header, "};\n");
838 fprintf(header, "\n");
839 fprintf(header, "#ifdef COBJMACROS\n");
840 write_method_macro(iface->ref, iface->name);
841 fprintf(header, "#endif\n");
842 fprintf(header, "\n");
843 fprintf(header, "#endif\n");
844 fprintf(header, "\n");
845 fprintf(header,"#endif /* __%s_DISPINTERFACE_DEFINED__ */\n\n", iface->name);
848 void write_coclass(class_t *cocl)
850 fprintf(header, "/*****************************************************************************\n");
851 fprintf(header, " * %s coclass\n", cocl->name);
852 fprintf(header, " */\n\n");
853 write_coclass_guid(cocl);
854 fprintf(header, "\n");