ReactOS 0.4.16-dev-1946-g52006dd
typetree.h
Go to the documentation of this file.
1/*
2 * IDL Type Tree
3 *
4 * Copyright 2008 Robert Shearman
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include "widltypes.h"
22#include <assert.h>
23#include <stdio.h>
24
25#include "utils.h"
26
27#ifndef WIDL_TYPE_TREE_H
28#define WIDL_TYPE_TREE_H
29
32 NAME_C
33};
34
36
39type_t *type_new_alias(const decl_spec_t *t, const char *name);
41type_t *type_new_array(const char *name, const decl_spec_t *element, int declptr,
42 unsigned int dim, expr_t *size_is, expr_t *length_is);
43type_t *type_new_basic(enum type_basic_type basic_type);
44type_t *type_new_int(enum type_basic_type basic_type, int sign);
47type_t *type_new_enum(const char *name, struct namespace *namespace,
48 int defined, var_list_t *enums, const struct location *where);
49type_t *type_new_struct(char *name, struct namespace *namespace,
50 int defined, var_list_t *fields, const struct location *where);
51type_t *type_new_nonencapsulated_union(const char *name, struct namespace *namespace,
52 int defined, var_list_t *fields, const struct location *where);
53type_t *type_new_encapsulated_union(char *name, var_t *switch_field,
54 var_t *union_field, var_list_t *cases, const struct location *where);
55type_t *type_new_bitfield(type_t *field_type, const expr_t *bits);
56type_t *type_runtimeclass_declare(char *name, struct namespace *namespace);
57type_t *type_interface_declare(char *name, struct namespace *namespace);
58type_t *type_interface_define(type_t *iface, attr_list_t *attrs, type_t *inherit,
59 statement_list_t *stmts, typeref_list_t *requires, const struct location *where);
62 var_list_t *props, var_list_t *methods, const struct location *where);
64 attr_list_t *attrs, type_t *iface, const struct location *where);
66 statement_list_t *stmts, const struct location *where);
68 typeref_list_t *ifaces, const struct location *where);
70 typeref_list_t *ifaces, const struct location *where);
71type_t *type_apicontract_declare(char *name, struct namespace *namespace);
72type_t *type_apicontract_define(type_t *apicontract, attr_list_t *attrs, const struct location *where);
73type_t *type_delegate_declare(char *name, struct namespace *namespace);
75 statement_list_t *stmts, const struct location *where);
76type_t *type_parameterized_interface_declare(char *name, struct namespace *namespace, typeref_list_t *params);
78 statement_list_t *stmts, typeref_list_t *requires, const struct location *where);
79type_t *type_parameterized_delegate_declare(char *name, struct namespace *namespace, typeref_list_t *params);
81 statement_list_t *stmts, const struct location *where);
85int type_is_equal(const type_t *type1, const type_t *type2);
86const char *type_get_decl_name(const type_t *type, enum name_type name_type);
87const char *type_get_name(const type_t *type, enum name_type name_type);
88char *gen_name(void);
89
92
93/* FIXME: shouldn't need to export this */
94type_t *duptype(type_t *t, int dupname);
95
96/* un-alias the type until finding the non-alias type */
97static inline type_t *type_get_real_type(const type_t *type)
98{
99 if (type->type_type == TYPE_ALIAS)
100 return type_get_real_type(type->details.alias.aliasee.type);
101 else
102 return (type_t *)type;
103}
104
106{
107 if (type->type_type == TYPE_PARAMETERIZED_TYPE)
108 return type_parameterized_type_get_real_type(type->details.parameterized.type);
109 else
110 return (type_t *)type;
111}
112
113static inline enum type_type type_get_type(const type_t *type)
114{
116}
117
119{
122 return type->details.basic.type;
123}
124
125static inline int type_basic_get_sign(const type_t *type)
126{
129 return type->details.basic.sign;
130}
131
133{
136 return type->details.structure->fields;
137}
138
140{
143 return type->details.function->args;
144}
145
147{
150 return type->details.function->retval;
151}
152
153static inline const decl_spec_t *type_function_get_ret(const type_t *type)
154{
156}
157
159{
161}
162
164{
167 return type->details.enumeration->enums;
168}
169
171{
174 return LIST_ENTRY(list_head(type->details.structure->fields), var_t, entry);
175}
176
178{
181 return type->details.structure->fields;
182}
183
185{
186 enum type_type type_type;
187
190
193 {
194 const var_t *uv = LIST_ENTRY(list_tail(type->details.structure->fields), const var_t, entry);
195 return uv->declspec.type->details.structure->fields;
196 }
197 else
198 return type->details.structure->fields;
199}
200
202{
205 return type->details.iface->stmts;
206}
207
209{
212 return type->details.iface->inherit;
213}
214
216{
219 return type->details.iface->requires;
220}
221
223{
226 return type->details.iface->async_iface;
227}
228
230{
233 return type->details.iface->disp_props;
234}
235
237{
240 return type->details.iface->disp_methods;
241}
242
244{
247 return type->details.iface->disp_inherit;
248}
249
250static inline int type_is_defined(const type_t *type)
251{
252 return type->defined;
253}
254
255static inline int type_is_complete(const type_t *type)
256{
258 {
259 case TYPE_FUNCTION:
260 return (type->details.function != NULL);
261 case TYPE_INTERFACE:
262 return (type->details.iface != NULL);
263 case TYPE_ENUM:
264 return (type->details.enumeration != NULL);
265 case TYPE_UNION:
267 case TYPE_STRUCT:
268 return (type->details.structure != NULL);
269 case TYPE_VOID:
270 case TYPE_BASIC:
271 case TYPE_ALIAS:
272 case TYPE_MODULE:
273 case TYPE_COCLASS:
274 case TYPE_POINTER:
275 case TYPE_ARRAY:
276 case TYPE_BITFIELD:
278 case TYPE_DELEGATE:
279 return TRUE;
280 case TYPE_APICONTRACT:
282 case TYPE_PARAMETER:
283 assert(0);
284 break;
285 }
286 return FALSE;
287}
288
289static inline int type_array_has_conformance(const type_t *type)
290{
293 return (type->details.array.size_is != NULL);
294}
295
296static inline int type_array_has_variance(const type_t *type)
297{
300 return (type->details.array.length_is != NULL);
301}
302
303static inline unsigned int type_array_get_dim(const type_t *type)
304{
307 return type->details.array.dim;
308}
309
311{
314 return type->details.array.size_is;
315}
316
318{
321 return type->details.array.length_is;
322}
323
324static inline unsigned short type_array_get_ptr_tfsoff(const type_t *type)
325{
328 return type->details.array.ptr_tfsoff;
329}
330
331static inline void type_array_set_ptr_tfsoff(type_t *type, unsigned short ptr_tfsoff)
332{
335 type->details.array.ptr_tfsoff = ptr_tfsoff;
336}
337
338static inline const decl_spec_t *type_array_get_element(const type_t *type)
339{
342 return &type->details.array.elem;
343}
344
346{
348}
349
350static inline int type_array_is_decl_as_ptr(const type_t *type)
351{
354 return type->details.array.declptr;
355}
356
357static inline int type_is_alias(const type_t *type)
358{
359 return type->type_type == TYPE_ALIAS;
360}
361
362static inline int type_is_ptr( const type_t *type )
363{
364 return type->type_type == TYPE_POINTER;
365}
366
367static inline const decl_spec_t *type_alias_get_aliasee(const type_t *type)
368{
370 return &type->details.alias.aliasee;
371}
372
374{
376 return type->details.alias.aliasee.type;
377}
378
380{
383 return type->details.coclass.ifaces;
384}
385
387{
390 return type->details.runtimeclass.ifaces;
391}
392
394{
396 typeref_t *ref;
397
398 if (ifaces) LIST_FOR_EACH_ENTRY(ref, ifaces, typeref_t, entry)
399 if (is_attr(ref->attrs, ATTR_DEFAULT))
400 return ref->type;
401
402 if (!check) return NULL;
403 error_at( &type->where, "runtimeclass %s needs a default interface\n", type->name );
404
405#ifdef __REACTOS__
406 return NULL;
407#endif
408}
409
411{
414 return type->details.delegate.iface;
415}
416
417static inline const decl_spec_t *type_pointer_get_ref(const type_t *type)
418{
421 return &type->details.pointer.ref;
422}
423
425{
427}
428
430{
431 for (; type && type->type_type == TYPE_POINTER; type = type_pointer_get_ref_type(type)) {}
432 return type;
433}
434
436{
439 return type->details.bitfield.field;
440}
441
442static inline const expr_t *type_bitfield_get_bits(const type_t *type)
443{
446 return type->details.bitfield.bits;
447}
448
449#endif /* WIDL_TYPE_TREE_H */
Definition: list.h:37
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define assert(x)
Definition: debug.h:53
#define check(expected, result)
Definition: dplayx.c:32
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLdouble GLdouble t
Definition: gl.h:2047
GLenum const GLfloat * params
Definition: glext.h:5645
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
uint32_t entry
Definition: isohybrid.c:63
#define sign(x)
Definition: mapdesc.cc:613
static const struct encodedInt enums[]
Definition: encode.c:361
const char * fields[10]
Definition: parser.c:313
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
__WINE_SERVER_LIST_INLINE struct list * list_tail(const struct list *list)
Definition: list.h:137
int is_attr(const attr_list_t *list, enum attr_type attr_type)
Definition: attribute.c:45
void error_at(const struct location *where, const char *s,...)
Definition: utils.c:35
type_t * type
Definition: widltypes.h:334
union _type_t::@5357 details
struct struct_details * structure
Definition: widltypes.h:506
decl_spec_t declspec
Definition: widltypes.h:542
Definition: match.c:390
Definition: list.h:15
Definition: name.c:39
Definition: send.c:48
#define LIST_ENTRY(type)
Definition: queue.h:175
static int type_array_is_decl_as_ptr(const type_t *type)
Definition: typetree.h:350
type_t * type_module_define(type_t *module, attr_list_t *attrs, statement_list_t *stmts, const struct location *where)
Definition: typetree.c:813
static enum type_type type_get_type(const type_t *type)
Definition: typetree.h:113
type_t * find_parameterized_type(type_t *type, typeref_list_t *params)
static type_t * type_runtimeclass_get_default_iface(const type_t *type, int check)
Definition: typetree.h:393
typeref_t * make_typeref(type_t *type)
static unsigned short type_array_get_ptr_tfsoff(const type_t *type)
Definition: typetree.h:324
type_t * type_parameterized_type_specialize_partial(type_t *type, typeref_list_t *params)
Definition: typetree.c:1032
type_t * type_dispinterface_define_from_iface(type_t *dispiface, attr_list_t *attrs, type_t *iface, const struct location *where)
Definition: typetree.c:786
type_t * type_runtimeclass_define(type_t *runtimeclass, attr_list_t *attrs, typeref_list_t *ifaces, const struct location *where)
Definition: typetree.c:850
int type_is_equal(const type_t *type1, const type_t *type2)
Definition: typetree.c:1319
type_t * type_apicontract_declare(char *name, struct namespace *namespace)
Definition: typetree.c:887
type_t * type_new_function(var_list_t *args)
Definition: typetree.c:420
type_t * type_parameterized_delegate_declare(char *name, struct namespace *namespace, typeref_list_t *params)
Definition: typetree.c:992
static const decl_spec_t * type_function_get_ret(const type_t *type)
Definition: typetree.h:153
static typeref_list_t * type_coclass_get_ifaces(const type_t *type)
Definition: typetree.h:379
typeref_list_t * append_typeref(typeref_list_t *list, typeref_t *ref)
static const expr_t * type_bitfield_get_bits(const type_t *type)
Definition: typetree.h:442
type_t * type_runtimeclass_declare(char *name, struct namespace *namespace)
Definition: typetree.c:841
static type_t * type_delegate_get_iface(const type_t *type)
Definition: typetree.h:410
static type_t * type_get_real_type(const type_t *type)
Definition: typetree.h:97
static int type_is_ptr(const type_t *type)
Definition: typetree.h:362
static void type_array_set_ptr_tfsoff(type_t *type, unsigned short ptr_tfsoff)
Definition: typetree.h:331
type_t * type_coclass_declare(char *name)
Definition: typetree.c:823
type_t * type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases, const struct location *where)
Definition: typetree.c:627
static int type_basic_get_sign(const type_t *type)
Definition: typetree.h:125
static var_t * type_union_get_switch_value(const type_t *type)
Definition: typetree.h:170
static type_t * type_function_get_rettype(const type_t *type)
Definition: typetree.h:158
static expr_t * type_array_get_variance(const type_t *type)
Definition: typetree.h:317
type_t * type_new_nonencapsulated_union(const char *name, struct namespace *namespace, int defined, var_list_t *fields, const struct location *where)
Definition: typetree.c:600
type_t * type_parameterized_interface_define(type_t *type, attr_list_t *attrs, type_t *inherit, statement_list_t *stmts, typeref_list_t *requires, const struct location *where)
Definition: typetree.c:964
type_t * type_new_array(const char *name, const decl_spec_t *element, int declptr, unsigned int dim, expr_t *size_is, expr_t *length_is)
Definition: typetree.c:489
static int type_array_has_conformance(const type_t *type)
Definition: typetree.h:289
type_t * type_delegate_declare(char *name, struct namespace *namespace)
Definition: typetree.c:915
type_t * type_parameterized_interface_declare(char *name, struct namespace *namespace, typeref_list_t *params)
Definition: typetree.c:953
static type_t * type_pointer_get_root_type(type_t *type)
Definition: typetree.h:429
static var_list_t * type_union_get_cases(const type_t *type)
Definition: typetree.h:184
type_t * type_parameterized_delegate_define(type_t *type, attr_list_t *attrs, statement_list_t *stmts, const struct location *where)
Definition: typetree.c:1003
type_t * type_module_declare(char *name)
Definition: typetree.c:804
static var_list_t * type_dispiface_get_methods(const type_t *type)
Definition: typetree.h:236
static type_t * type_array_get_element_type(const type_t *type)
Definition: typetree.h:345
type_t * type_interface_define(type_t *iface, attr_list_t *attrs, type_t *inherit, statement_list_t *stmts, typeref_list_t *requires, const struct location *where)
Definition: typetree.c:739
static typeref_list_t * type_iface_get_requires(const type_t *type)
Definition: typetree.h:215
static type_t * type_bitfield_get_field(const type_t *type)
Definition: typetree.h:435
type_t * type_new_bitfield(type_t *field_type, const expr_t *bits)
Definition: typetree.c:689
type_t * type_new_basic(enum type_basic_type basic_type)
Definition: typetree.c:505
name_type
Definition: typetree.h:30
@ NAME_C
Definition: typetree.h:32
@ NAME_DEFAULT
Definition: typetree.h:31
static type_t * type_alias_get_aliasee_type(const type_t *type)
Definition: typetree.h:373
static enum type_basic_type type_basic_get_type(const type_t *type)
Definition: typetree.h:118
const char * type_get_decl_name(const type_t *type, enum name_type name_type)
Definition: typetree.c:88
static var_t * type_function_get_retval(const type_t *type)
Definition: typetree.h:146
static type_t * type_dispiface_get_inherit(const type_t *type)
Definition: typetree.h:243
static type_t * type_iface_get_async_iface(const type_t *type)
Definition: typetree.h:222
type_t * type_new_pointer(type_t *ref)
Definition: typetree.c:470
static const decl_spec_t * type_pointer_get_ref(const type_t *type)
Definition: typetree.h:417
static expr_t * type_array_get_conformance(const type_t *type)
Definition: typetree.h:310
type_t * type_parameterized_type_specialize_define(type_t *type)
Definition: typetree.c:1282
static int type_is_defined(const type_t *type)
Definition: typetree.h:250
type_t * type_new_void(void)
Definition: typetree.c:528
type_t * type_interface_declare(char *name, struct namespace *namespace)
Definition: typetree.c:730
static var_list_t * type_struct_get_fields(const type_t *type)
Definition: typetree.h:132
type_t * type_delegate_define(type_t *delegate, attr_list_t *attrs, statement_list_t *stmts, const struct location *where)
Definition: typetree.c:924
static int type_is_complete(const type_t *type)
Definition: typetree.h:255
static const decl_spec_t * type_alias_get_aliasee(const type_t *type)
Definition: typetree.h:367
static typeref_list_t * type_runtimeclass_get_ifaces(const type_t *type)
Definition: typetree.h:386
static var_list_t * type_encapsulated_union_get_fields(const type_t *type)
Definition: typetree.h:177
const char * type_get_name(const type_t *type, enum name_type name_type)
Definition: typetree.c:101
static type_t * type_pointer_get_ref_type(const type_t *type)
Definition: typetree.h:424
type_t * type_new_struct(char *name, struct namespace *namespace, int defined, var_list_t *fields, const struct location *where)
Definition: typetree.c:573
static int type_is_alias(const type_t *type)
Definition: typetree.h:357
static type_t * type_iface_get_inherit(const type_t *type)
Definition: typetree.h:208
type_t * type_new_int(enum type_basic_type basic_type, int sign)
Definition: typetree.c:513
static var_list_t * type_function_get_args(const type_t *type)
Definition: typetree.h:139
char * gen_name(void)
type_t * duptype(type_t *t, int dupname)
Definition: typetree.c:37
static type_t * type_parameterized_type_get_real_type(const type_t *type)
Definition: typetree.h:105
type_t * type_apicontract_define(type_t *apicontract, attr_list_t *attrs, const struct location *where)
Definition: typetree.c:896
type_t * type_new_enum(const char *name, struct namespace *namespace, int defined, var_list_t *enums, const struct location *where)
Definition: typetree.c:546
type_t * type_dispinterface_declare(char *name)
Definition: typetree.c:759
type_t * type_parameterized_type_specialize_declare(type_t *type, typeref_list_t *params)
Definition: typetree.c:1222
static unsigned int type_array_get_dim(const type_t *type)
Definition: typetree.h:303
type_t * type_dispinterface_define(type_t *iface, attr_list_t *attrs, var_list_t *props, var_list_t *methods, const struct location *where)
Definition: typetree.c:768
type_t * type_new_alias(const decl_spec_t *t, const char *name)
Definition: typetree.c:477
static statement_list_t * type_iface_get_stmts(const type_t *type)
Definition: typetree.h:201
static var_list_t * type_enum_get_values(const type_t *type)
Definition: typetree.h:163
static int type_array_has_variance(const type_t *type)
Definition: typetree.h:296
type_t * type_coclass_define(type_t *coclass, attr_list_t *attrs, typeref_list_t *ifaces, const struct location *where)
Definition: typetree.c:832
static var_list_t * type_dispiface_get_props(const type_t *type)
Definition: typetree.h:229
static const decl_spec_t * type_array_get_element(const type_t *type)
Definition: typetree.h:338
static const WCHAR props[]
Definition: wbemdisp.c:288
type_type
Definition: widltypes.h:477
@ TYPE_PARAMETER
Definition: widltypes.h:495
@ TYPE_ENUM
Definition: widltypes.h:480
@ TYPE_BITFIELD
Definition: widltypes.h:491
@ TYPE_BASIC
Definition: widltypes.h:479
@ TYPE_UNION
Definition: widltypes.h:483
@ TYPE_ALIAS
Definition: widltypes.h:484
@ TYPE_PARAMETERIZED_TYPE
Definition: widltypes.h:494
@ TYPE_POINTER
Definition: widltypes.h:489
@ TYPE_VOID
Definition: widltypes.h:478
@ TYPE_ENCAPSULATED_UNION
Definition: widltypes.h:482
@ TYPE_COCLASS
Definition: widltypes.h:486
@ TYPE_STRUCT
Definition: widltypes.h:481
@ TYPE_MODULE
Definition: widltypes.h:485
@ TYPE_DELEGATE
Definition: widltypes.h:496
@ TYPE_RUNTIMECLASS
Definition: widltypes.h:493
@ TYPE_INTERFACE
Definition: widltypes.h:488
@ TYPE_ARRAY
Definition: widltypes.h:490
@ TYPE_FUNCTION
Definition: widltypes.h:487
@ TYPE_APICONTRACT
Definition: widltypes.h:492
@ ATTR_DEFAULT
Definition: widltypes.h:95
static enum type_type type_get_type_detect_alias(const type_t *type)
Definition: widltypes.h:679
type_basic_type
Definition: widltypes.h:295