Update German and Hungarian keyboard layouts to better match X11
[wine/wine64.git] / tools / widl / header.c
blob72e7e72b4504cf697b9c314202fd8749e7f98d59
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(FILE *h, int delta)
43 int c;
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(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_guid(const char *guid_prefix, const char *name, UUID *uuid)
85 if (!uuid) return;
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, var_t *v)
95 int c;
96 for (c=0; c<v->ptr_level; c++) {
97 fprintf(h, "*");
99 if (v->name) fprintf(h, "%s", v->name);
102 void write_name(FILE *h, var_t *v)
104 if (is_attr( v->attrs, ATTR_PROPGET ))
105 fprintf(h, "get_" );
106 else if (is_attr( v->attrs, ATTR_PROPPUT ))
107 fprintf(h, "put_" );
108 fprintf(h, "%s", v->name);
111 char* get_name(var_t *v)
113 return v->name;
116 static void write_array(FILE *h, expr_t *v, int field)
118 if (!v) return;
119 while (NEXT_LINK(v)) v = NEXT_LINK(v);
120 fprintf(h, "[");
121 while (v) {
122 if (v->is_const)
123 fprintf(h, "%ld", v->cval); /* statically sized array */
124 else
125 if (field) fprintf(h, "1"); /* dynamically sized array */
126 if (PREV_LINK(v))
127 fprintf(h, ", ");
128 v = PREV_LINK(v);
130 fprintf(h, "]");
133 static void write_field(FILE *h, var_t *v)
135 if (!v) return;
136 if (v->type) {
137 indent(h, 0);
138 write_type(h, v->type, NULL, v->tname);
139 if (get_name(v)) {
140 fprintf(h, " ");
141 write_pident(h, v);
143 else {
144 /* not all C/C++ compilers support anonymous structs and unions */
145 switch (v->type->type) {
146 case RPC_FC_STRUCT:
147 case RPC_FC_CVSTRUCT:
148 case RPC_FC_CPSTRUCT:
149 case RPC_FC_CSTRUCT:
150 case RPC_FC_PSTRUCT:
151 case RPC_FC_BOGUS_STRUCT:
152 case RPC_FC_ENCAPSULATED_UNION:
153 fprintf(h, " DUMMYSTRUCTNAME");
154 break;
155 case RPC_FC_NON_ENCAPSULATED_UNION:
156 fprintf(h, " DUMMYUNIONNAME");
157 break;
158 default:
159 /* ? */
160 break;
163 write_array(h, v->array, 1);
164 fprintf(h, ";\n");
168 static void write_fields(FILE *h, var_t *v)
170 var_t *first = v;
171 if (!v) return;
172 while (NEXT_LINK(v)) v = NEXT_LINK(v);
173 while (v) {
174 write_field(h, v);
175 if (v == first) break;
176 v = PREV_LINK(v);
180 static void write_enums(FILE *h, var_t *v)
182 if (!v) return;
183 while (NEXT_LINK(v)) v = NEXT_LINK(v);
184 while (v) {
185 if (get_name(v)) {
186 indent(h, 0);
187 write_name(h, v);
188 if (v->eval) {
189 fprintf(h, " = ");
190 write_expr(h, v->eval);
193 if (PREV_LINK(v))
194 fprintf(h, ",\n");
195 v = PREV_LINK(v);
197 fprintf(h, "\n");
200 void write_type(FILE *h, type_t *t, var_t *v, const char *n)
202 int c;
204 if (n) fprintf(h, "%s", n);
205 else {
206 if (t->is_const) fprintf(h, "const ");
207 if (t->type) {
208 if (t->sign > 0) fprintf(h, "signed ");
209 else if (t->sign < 0) fprintf(h, "unsigned ");
210 switch (t->type) {
211 case RPC_FC_BYTE:
212 if (t->ref) fprintf(h, t->ref->name);
213 else fprintf(h, "byte");
214 break;
215 case RPC_FC_CHAR:
216 if (t->ref) fprintf(h, t->ref->name);
217 else fprintf(h, "char");
218 break;
219 case RPC_FC_WCHAR:
220 fprintf(h, "wchar_t");
221 break;
222 case RPC_FC_USHORT:
223 case RPC_FC_SHORT:
224 if (t->ref) fprintf(h, t->ref->name);
225 else fprintf(h, "short");
226 break;
227 case RPC_FC_ULONG:
228 case RPC_FC_LONG:
229 if (t->ref) fprintf(h, t->ref->name);
230 else fprintf(h, "long");
231 break;
232 case RPC_FC_HYPER:
233 if (t->ref) fprintf(h, t->ref->name);
234 else fprintf(h, "hyper");
235 break;
236 case RPC_FC_FLOAT:
237 fprintf(h, "float");
238 break;
239 case RPC_FC_DOUBLE:
240 fprintf(h, "double");
241 break;
242 case RPC_FC_ENUM16:
243 case RPC_FC_ENUM32:
244 if (t->defined && !t->written) {
245 if (t->name) fprintf(h, "enum %s {\n", t->name);
246 else fprintf(h, "enum {\n");
247 t->written = TRUE;
248 indentation++;
249 write_enums(h, t->fields);
250 indent(h, -1);
251 fprintf(h, "}");
253 else fprintf(h, "enum %s", t->name);
254 break;
255 case RPC_FC_ERROR_STATUS_T:
256 if (t->ref) fprintf(h, t->ref->name);
257 else fprintf(h, "error_status_t");
258 break;
259 case RPC_FC_BIND_PRIMITIVE:
260 if (t->ref) fprintf(h, t->ref->name);
261 else fprintf(h, "handle_t");
262 break;
263 case RPC_FC_STRUCT:
264 case RPC_FC_CVSTRUCT:
265 case RPC_FC_CPSTRUCT:
266 case RPC_FC_CSTRUCT:
267 case RPC_FC_PSTRUCT:
268 case RPC_FC_BOGUS_STRUCT:
269 case RPC_FC_ENCAPSULATED_UNION:
270 if (t->defined && !t->written) {
271 if (t->name) fprintf(h, "struct %s {\n", t->name);
272 else fprintf(h, "struct {\n");
273 t->written = TRUE;
274 indentation++;
275 write_fields(h, t->fields);
276 indent(h, -1);
277 fprintf(h, "}");
279 else fprintf(h, "struct %s", t->name);
280 break;
281 case RPC_FC_NON_ENCAPSULATED_UNION:
282 if (t->defined && !t->written) {
283 if (t->name) fprintf(h, "union %s {\n", t->name);
284 else fprintf(h, "union {\n");
285 t->written = TRUE;
286 indentation++;
287 write_fields(h, t->fields);
288 indent(h, -1);
289 fprintf(h, "}");
291 else fprintf(h, "union %s", t->name);
292 break;
293 default:
294 fprintf(h, "(unknown-type:%d)", t->type);
297 else {
298 if (t->ref) {
299 write_type(h, t->ref, NULL, t->name);
301 else fprintf(h, "void");
304 if (v) {
305 for (c=0; c<v->ptr_level; c++) {
306 fprintf(h, "*");
312 struct user_type
314 struct user_type *next;
315 char name[1];
318 static struct user_type *user_type_list;
320 static int user_type_registered(const char *name)
322 struct user_type *ut;
323 for (ut = user_type_list; ut; ut = ut->next)
324 if (!strcmp(name, ut->name))
325 return 1;
326 return 0;
329 static void check_for_user_types(var_t *v)
331 while (v) {
332 type_t *type = v->type;
333 const char *name = v->tname;
334 for (type = v->type; type; type = type->ref) {
335 if (type->user_types_registered) continue;
336 type->user_types_registered = 1;
337 if (is_attr(type->attrs, ATTR_WIREMARSHAL)) {
338 if (!user_type_registered(name))
340 struct user_type *ut = xmalloc(sizeof(struct user_type) + strlen(name));
341 strcpy(ut->name, name);
342 ut->next = user_type_list;
343 user_type_list = ut;
345 /* don't carry on parsing fields within this type as we are already
346 * using a wire marshaled type */
347 break;
349 else if (type->fields)
351 var_t *fields = type->fields;
352 while (NEXT_LINK(fields)) fields = NEXT_LINK(fields);
353 check_for_user_types(fields);
355 /* the wire_marshal attribute is always at least one reference away
356 * from the name of the type, so update it after the rest of the
357 * processing above */
358 if (type->name) name = type->name;
360 v = PREV_LINK(v);
364 void write_user_types(void)
366 struct user_type *ut;
367 for (ut = user_type_list; ut; ut = ut->next)
369 const char *name = ut->name;
370 fprintf(header, "unsigned long __RPC_USER %s_UserSize (unsigned long *, unsigned long, %s *);\n", name, name);
371 fprintf(header, "unsigned char * __RPC_USER %s_UserMarshal (unsigned long *, unsigned char *, %s *);\n", name, name);
372 fprintf(header, "unsigned char * __RPC_USER %s_UserUnmarshal(unsigned long *, unsigned char *, %s *);\n", name, name);
373 fprintf(header, "void __RPC_USER %s_UserFree (unsigned long *, %s *);\n", name, name);
377 void write_typedef(type_t *type, var_t *names)
379 char *tname = names->tname;
380 var_t *lname;
381 while (NEXT_LINK(names)) names = NEXT_LINK(names);
382 lname = names;
383 fprintf(header, "typedef ");
384 write_type(header, type, NULL, tname);
385 fprintf(header, " ");
386 while (names) {
387 write_pident(header, names);
388 if (PREV_LINK(names))
389 fprintf(header, ", ");
390 names = PREV_LINK(names);
392 fprintf(header, ";\n");
395 static void do_write_expr(FILE *h, expr_t *e, int p)
397 switch (e->type) {
398 case EXPR_VOID:
399 break;
400 case EXPR_NUM:
401 fprintf(h, "%ld", e->u.lval);
402 break;
403 case EXPR_HEXNUM:
404 fprintf(h, "0x%lx", e->u.lval);
405 break;
406 case EXPR_IDENTIFIER:
407 fprintf(h, "%s", e->u.sval);
408 break;
409 case EXPR_NEG:
410 fprintf(h, "-");
411 do_write_expr(h, e->ref, 1);
412 break;
413 case EXPR_NOT:
414 fprintf(h, "~");
415 do_write_expr(h, e->ref, 1);
416 break;
417 case EXPR_PPTR:
418 fprintf(h, "*");
419 do_write_expr(h, e->ref, 1);
420 break;
421 case EXPR_CAST:
422 fprintf(h, "(");
423 write_type(h, e->u.tref->ref, NULL, e->u.tref->name);
424 fprintf(h, ")");
425 do_write_expr(h, e->ref, 1);
426 break;
427 case EXPR_SIZEOF:
428 fprintf(h, "sizeof(");
429 write_type(h, e->u.tref->ref, NULL, e->u.tref->name);
430 fprintf(h, ")");
431 break;
432 case EXPR_SHL:
433 case EXPR_SHR:
434 case EXPR_MUL:
435 case EXPR_DIV:
436 case EXPR_ADD:
437 case EXPR_SUB:
438 case EXPR_AND:
439 case EXPR_OR:
440 if (p) fprintf(h, "(");
441 do_write_expr(h, e->ref, 1);
442 switch (e->type) {
443 case EXPR_SHL: fprintf(h, " << "); break;
444 case EXPR_SHR: fprintf(h, " >> "); break;
445 case EXPR_MUL: fprintf(h, " * "); break;
446 case EXPR_DIV: fprintf(h, " / "); break;
447 case EXPR_ADD: fprintf(h, " + "); break;
448 case EXPR_SUB: fprintf(h, " - "); break;
449 case EXPR_AND: fprintf(h, " & "); break;
450 case EXPR_OR: fprintf(h, " | "); break;
451 default: break;
453 do_write_expr(h, e->u.ext, 1);
454 if (p) fprintf(h, ")");
455 break;
456 case EXPR_COND:
457 if (p) fprintf(h, "(");
458 do_write_expr(h, e->ref, 1);
459 fprintf(h, " ? ");
460 do_write_expr(h, e->u.ext, 1);
461 fprintf(h, " : ");
462 do_write_expr(h, e->ext2, 1);
463 if (p) fprintf(h, ")");
464 break;
468 void write_expr(FILE *h, expr_t *e)
470 do_write_expr(h, e, 0);
473 void write_constdef(var_t *v)
475 fprintf(header, "#define %s (", get_name(v));
476 write_expr(header, v->eval);
477 fprintf(header, ")\n\n");
480 void write_externdef(var_t *v)
482 fprintf(header, "extern const ");
483 write_type(header, v->type, NULL, v->tname);
484 if (get_name(v)) {
485 fprintf(header, " ");
486 write_pident(header, v);
488 fprintf(header, ";\n\n");
491 void write_library(const char *name, attr_t *attr) {
492 UUID *uuid = get_attrp(attr, ATTR_UUID);
493 fprintf(header, "\n");
494 write_guid("LIBID", name, uuid);
495 fprintf(header, "\n");
498 /********** INTERFACES **********/
500 int is_object(attr_t *a)
502 while (a) {
503 if (a->type == ATTR_OBJECT || a->type == ATTR_ODL) return 1;
504 a = NEXT_LINK(a);
506 return 0;
509 int is_local(attr_t *a)
511 return is_attr(a, ATTR_LOCAL);
514 var_t *is_callas(attr_t *a)
516 return get_attrp(a, ATTR_CALLAS);
519 static int write_method_macro(type_t *iface, char *name)
521 int idx;
522 func_t *cur = iface->funcs;
524 if (iface->ref) idx = write_method_macro(iface->ref, name);
525 else idx = 0;
527 if (!cur) return idx;
528 while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
530 fprintf(header, "/*** %s methods ***/\n", iface->name);
531 while (cur) {
532 var_t *def = cur->def;
533 if (!is_callas(def->attrs)) {
534 var_t *arg = cur->args;
535 int argc = 0;
536 int c;
537 while (arg) {
538 arg = NEXT_LINK(arg);
539 argc++;
542 fprintf(header, "#define %s_", name);
543 write_name(header,def);
544 fprintf(header, "(p");
545 for (c=0; c<argc; c++)
546 fprintf(header, ",%c", c+'a');
547 fprintf(header, ") ");
549 fprintf(header, "(p)->lpVtbl->");
550 write_name(header, def);
551 fprintf(header, "(p");
552 for (c=0; c<argc; c++)
553 fprintf(header, ",%c", c+'a');
554 fprintf(header, ")\n");
555 if (cur->idx == -1) cur->idx = idx;
556 else if (cur->idx != idx) yyerror("BUG: method index mismatch in write_method_macro");
557 idx++;
559 cur = PREV_LINK(cur);
561 return idx;
564 void write_args(FILE *h, var_t *arg, const char *name, int method, int do_indent)
566 int count = 0;
567 if (arg) {
568 while (NEXT_LINK(arg))
569 arg = NEXT_LINK(arg);
571 if (do_indent)
573 indentation++;
574 indent(h, 0);
576 if (method == 1) {
577 fprintf(h, "%s* This", name);
578 count++;
580 while (arg) {
581 if (count) {
582 if (do_indent)
584 fprintf(h, ",\n");
585 indent(h, 0);
587 else fprintf(h, ",");
589 write_type(h, arg->type, arg, arg->tname);
590 if (arg->args)
592 fprintf(h, " (STDMETHODCALLTYPE *");
593 write_name(h,arg);
594 fprintf(h, ")(");
595 write_args(h, arg->args, NULL, 0, FALSE);
596 fprintf(h, ")");
598 else
600 fprintf(h, " ");
601 write_name(h, arg);
603 write_array(h, arg->array, 0);
604 arg = PREV_LINK(arg);
605 count++;
607 if (do_indent) indentation--;
610 static void write_cpp_method_def(type_t *iface)
612 func_t *cur = iface->funcs;
614 if (!cur) return;
615 while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
616 while (cur) {
617 var_t *def = cur->def;
618 if (!is_callas(def->attrs)) {
619 indent(header, 0);
620 fprintf(header, "virtual ");
621 write_type(header, def->type, def, def->tname);
622 fprintf(header, " STDMETHODCALLTYPE ");
623 write_name(header, def);
624 fprintf(header, "(\n");
625 write_args(header, cur->args, iface->name, 2, TRUE);
626 fprintf(header, ") = 0;\n");
627 fprintf(header, "\n");
629 cur = PREV_LINK(cur);
633 static void do_write_c_method_def(type_t *iface, char *name)
635 func_t *cur = iface->funcs;
637 if (iface->ref) do_write_c_method_def(iface->ref, name);
639 if (!cur) return;
640 while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
641 indent(header, 0);
642 fprintf(header, "/*** %s methods ***/\n", iface->name);
643 while (cur) {
644 var_t *def = cur->def;
645 if (!is_callas(def->attrs)) {
646 indent(header, 0);
647 write_type(header, def->type, def, def->tname);
648 fprintf(header, " (STDMETHODCALLTYPE *");
649 write_name(header, def);
650 fprintf(header, ")(\n");
651 write_args(header, cur->args, name, 1, TRUE);
652 fprintf(header, ");\n");
653 fprintf(header, "\n");
655 cur = PREV_LINK(cur);
659 static void write_c_method_def(type_t *iface)
661 do_write_c_method_def(iface, iface->name);
664 static void write_c_disp_method_def(type_t *iface)
666 do_write_c_method_def(iface->ref, iface->name);
669 static void write_method_proto(type_t *iface)
671 func_t *cur = iface->funcs;
673 if (!cur) return;
674 while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
675 while (cur) {
676 var_t *def = cur->def;
677 var_t *cas = is_callas(def->attrs);
678 var_t *args;
679 if (!is_local(def->attrs)) {
680 /* proxy prototype */
681 write_type(header, def->type, def, def->tname);
682 fprintf(header, " CALLBACK %s_", iface->name);
683 write_name(header, def);
684 fprintf(header, "_Proxy(\n");
685 write_args(header, cur->args, iface->name, 1, TRUE);
686 fprintf(header, ");\n");
687 /* stub prototype */
688 fprintf(header, "void __RPC_STUB %s_", iface->name);
689 write_name(header,def);
690 fprintf(header, "_Stub(\n");
691 fprintf(header, " struct IRpcStubBuffer* This,\n");
692 fprintf(header, " struct IRpcChannelBuffer* pRpcChannelBuffer,\n");
693 fprintf(header, " PRPC_MESSAGE pRpcMessage,\n");
694 fprintf(header, " DWORD* pdwStubPhase);\n");
696 args = cur->args;
697 if (args) {
698 while (NEXT_LINK(args))
699 args = NEXT_LINK(args);
701 check_for_user_types(args);
703 if (cas) {
704 func_t *m = iface->funcs;
705 while (m && strcmp(get_name(m->def), cas->name))
706 m = NEXT_LINK(m);
707 if (m) {
708 var_t *mdef = m->def;
709 /* proxy prototype - use local prototype */
710 write_type(header, mdef->type, mdef, mdef->tname);
711 fprintf(header, " CALLBACK %s_", iface->name);
712 write_name(header, mdef);
713 fprintf(header, "_Proxy(\n");
714 write_args(header, m->args, iface->name, 1, TRUE);
715 fprintf(header, ");\n");
716 /* stub prototype - use remotable prototype */
717 write_type(header, def->type, def, def->tname);
718 fprintf(header, " __RPC_STUB %s_", iface->name);
719 write_name(header, mdef);
720 fprintf(header, "_Stub(\n");
721 write_args(header, cur->args, iface->name, 1, TRUE);
722 fprintf(header, ");\n");
724 else {
725 yywarning("invalid call_as attribute (%s -> %s)\n", get_name(def), cas->name);
729 cur = PREV_LINK(cur);
733 static void write_function_proto(type_t *iface)
735 func_t *cur = iface->funcs;
736 while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
737 while (cur) {
738 var_t *def = cur->def;
739 /* FIXME: do we need to handle call_as? */
740 write_type(header, def->type, def, def->tname);
741 fprintf(header, " ");
742 write_name(header, def);
743 fprintf(header, "(\n");
744 if (cur->args)
745 write_args(header, cur->args, iface->name, 0, TRUE);
746 else
747 fprintf(header, " void");
748 fprintf(header, ");\n");
750 cur = PREV_LINK(cur);
754 void write_forward(type_t *iface)
756 /* C/C++ forwards should only be written for object interfaces, so if we
757 * have a full definition we only write one if we find [object] among the
758 * attributes - however, if we don't have a full definition at this point
759 * (i.e. this is an IDL forward), then we also assume that it is an object
760 * interface, since non-object interfaces shouldn't need forwards */
761 if ((!iface->defined || is_object(iface->attrs) || is_attr(iface->attrs, ATTR_DISPINTERFACE))
762 && !iface->written) {
763 fprintf(header,"#ifndef __%s_FWD_DEFINED__\n", iface->name);
764 fprintf(header,"#define __%s_FWD_DEFINED__\n", iface->name);
765 fprintf(header, "typedef struct %s %s;\n", iface->name, iface->name);
766 fprintf(header, "#endif\n\n" );
767 iface->written = TRUE;
771 static void write_iface_guid(type_t *iface)
773 UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
774 write_guid("IID", iface->name, uuid);
777 static void write_dispiface_guid(type_t *iface)
779 UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
780 write_guid("DIID", iface->name, uuid);
783 static void write_coclass_guid(class_t *cocl)
785 UUID *uuid = get_attrp(cocl->attrs, ATTR_UUID);
786 write_guid("CLSID", cocl->name, uuid);
789 static void write_com_interface(type_t *iface)
791 if (!iface->funcs && !iface->ref) {
792 yywarning("%s has no methods", iface->name);
793 return;
796 fprintf(header, "/*****************************************************************************\n");
797 fprintf(header, " * %s interface\n", iface->name);
798 fprintf(header, " */\n");
799 fprintf(header,"#ifndef __%s_INTERFACE_DEFINED__\n", iface->name);
800 fprintf(header,"#define __%s_INTERFACE_DEFINED__\n\n", iface->name);
801 write_iface_guid(iface);
802 write_forward(iface);
803 /* C++ interface */
804 fprintf(header, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
805 if (iface->ref)
807 fprintf(header, "struct %s : public %s\n", iface->name, iface->ref->name);
808 fprintf(header, "{\n");
809 indentation++;
810 write_cpp_method_def(iface);
811 indentation--;
812 fprintf(header, "};\n");
814 else
816 fprintf(header, "struct %s\n", iface->name);
817 fprintf(header, "{\n");
818 fprintf(header, " BEGIN_INTERFACE\n");
819 fprintf(header, "\n");
820 indentation++;
821 write_cpp_method_def(iface);
822 indentation--;
823 fprintf(header, " END_INTERFACE\n");
824 fprintf(header, "};\n");
826 fprintf(header, "#else\n");
827 /* C interface */
828 fprintf(header, "typedef struct %sVtbl %sVtbl;\n", iface->name, iface->name);
829 fprintf(header, "struct %s {\n", iface->name);
830 fprintf(header, " const %sVtbl* lpVtbl;\n", iface->name);
831 fprintf(header, "};\n");
832 fprintf(header, "struct %sVtbl {\n", iface->name);
833 indentation++;
834 fprintf(header, " BEGIN_INTERFACE\n");
835 fprintf(header, "\n");
836 write_c_method_def(iface);
837 indentation--;
838 fprintf(header, " END_INTERFACE\n");
839 fprintf(header, "};\n");
840 fprintf(header, "\n");
841 fprintf(header, "#ifdef COBJMACROS\n");
842 write_method_macro(iface, iface->name);
843 fprintf(header, "#endif\n");
844 fprintf(header, "\n");
845 fprintf(header, "#endif\n");
846 fprintf(header, "\n");
847 write_method_proto(iface);
848 fprintf(header,"\n#endif /* __%s_INTERFACE_DEFINED__ */\n\n", iface->name);
851 static void write_rpc_interface(type_t *iface)
853 unsigned long ver = get_attrv(iface->attrs, ATTR_VERSION);
854 char *var = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
856 if (!iface->funcs) return;
858 fprintf(header, "/*****************************************************************************\n");
859 fprintf(header, " * %s interface (v%d.%d)\n", iface->name, LOWORD(ver), HIWORD(ver));
860 fprintf(header, " */\n");
861 write_iface_guid(iface);
862 if (var) fprintf(header, "extern handle_t %s;\n", var);
863 fprintf(header, "extern RPC_IF_HANDLE %s_v%d_%d_c_ifspec;\n", iface->name, LOWORD(ver), HIWORD(ver));
864 fprintf(header, "extern RPC_IF_HANDLE %s_v%d_%d_s_ifspec;\n", iface->name, LOWORD(ver), HIWORD(ver));
865 write_function_proto(iface);
866 fprintf(header, "\n");
868 /* FIXME: server/client code */
871 void write_interface(type_t *iface)
873 if (is_object(iface->attrs))
874 write_com_interface(iface);
875 else
876 write_rpc_interface(iface);
879 void write_dispinterface(type_t *iface)
881 fprintf(header, "/*****************************************************************************\n");
882 fprintf(header, " * %s dispinterface\n", iface->name);
883 fprintf(header, " */\n");
884 fprintf(header,"#ifndef __%s_DISPINTERFACE_DEFINED__\n", iface->name);
885 fprintf(header,"#define __%s_DISPINTERFACE_DEFINED__\n\n", iface->name);
886 write_dispiface_guid(iface);
887 write_forward(iface);
888 /* C++ interface */
889 fprintf(header, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
890 fprintf(header, "struct %s : public %s\n", iface->name, iface->ref->name);
891 fprintf(header, "{\n");
892 fprintf(header, "};\n");
893 fprintf(header, "#else\n");
894 /* C interface */
895 fprintf(header, "typedef struct %sVtbl %sVtbl;\n", iface->name, iface->name);
896 fprintf(header, "struct %s {\n", iface->name);
897 fprintf(header, " const %sVtbl* lpVtbl;\n", iface->name);
898 fprintf(header, "};\n");
899 fprintf(header, "struct %sVtbl {\n", iface->name);
900 indentation++;
901 fprintf(header, " BEGIN_INTERFACE\n");
902 fprintf(header, "\n");
903 write_c_disp_method_def(iface);
904 indentation--;
905 fprintf(header, " END_INTERFACE\n");
906 fprintf(header, "};\n");
907 fprintf(header, "\n");
908 fprintf(header, "#ifdef COBJMACROS\n");
909 write_method_macro(iface->ref, iface->name);
910 fprintf(header, "#endif\n");
911 fprintf(header, "\n");
912 fprintf(header, "#endif\n");
913 fprintf(header, "\n");
914 fprintf(header,"#endif /* __%s_DISPINTERFACE_DEFINED__ */\n\n", iface->name);
917 void write_coclass(class_t *cocl)
919 fprintf(header, "/*****************************************************************************\n");
920 fprintf(header, " * %s coclass\n", cocl->name);
921 fprintf(header, " */\n\n");
922 write_coclass_guid(cocl);
923 fprintf(header, "\n");