push 212f1dad91f15aefd8e676124180e0b86d7c9ee6
[wine/hacks.git] / tools / widl / typetree.c
blob2b56bb8e6ffb1b1ab2d79ee1729a675e2e2af4c7
1 /*
2 * IDL Type Tree
4 * Copyright 2008 Robert Shearman
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
21 #include "config.h"
23 #include <stdio.h>
24 #include <stdlib.h>
26 #include "widl.h"
27 #include "utils.h"
28 #include "parser.h"
29 #include "typetree.h"
30 #include "header.h"
32 type_t *type_new_function(var_list_t *args)
34 type_t *t = make_type(RPC_FC_FUNCTION, NULL);
35 t->details.function = xmalloc(sizeof(*t->details.function));
36 t->details.function->args = args;
37 return t;
40 type_t *type_new_pointer(type_t *ref, attr_list_t *attrs)
42 type_t *t = make_type(pointer_default, ref);
43 t->attrs = attrs;
44 return t;
47 static int compute_method_indexes(type_t *iface)
49 int idx;
50 func_t *f;
52 if (iface->ref)
53 idx = compute_method_indexes(iface->ref);
54 else
55 idx = 0;
57 if (!iface->funcs)
58 return idx;
60 LIST_FOR_EACH_ENTRY( f, iface->funcs, func_t, entry )
61 if (! is_callas(f->def->attrs))
62 f->idx = idx++;
64 return idx;
67 void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts)
69 iface->ref = inherit;
70 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
71 iface->funcs = gen_function_list(stmts);
72 iface->details.iface->disp_props = NULL;
73 iface->details.iface->disp_methods = NULL;
74 iface->stmts = stmts;
75 iface->defined = TRUE;
76 check_functions(iface);
77 compute_method_indexes(iface);
80 void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods)
82 iface->ref = find_type("IDispatch", 0);
83 if (!iface->ref) error_loc("IDispatch is undefined\n");
84 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
85 iface->funcs = NULL;
86 iface->details.iface->disp_props = props;
87 iface->details.iface->disp_methods = methods;
88 iface->stmts = NULL;
89 iface->defined = TRUE;
90 check_functions(iface);
91 compute_method_indexes(iface);
94 void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface)
96 type_dispinterface_define(dispiface, iface->details.iface->disp_props,
97 iface->details.iface->disp_methods);