bison
[m6w6/ext-psi] / src / types / decl_type.h
1 /*******************************************************************************
2 Copyright (c) 2016, Michael Wallner <mike@php.net>.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *******************************************************************************/
25
26 #ifndef PSI_TYPES_DECL_TYPE_H
27 #define PSI_TYPES_DECL_TYPE_H
28
29 #include "token.h"
30
31 struct psi_data;
32 struct psi_token;
33 struct psi_plist;
34 struct psi_decl_arg;
35 struct psi_decl_struct;
36 struct psi_decl_union;
37 struct psi_decl_enum;
38 struct psi_decl;
39
40 struct psi_decl_type {
41 struct psi_token *token;
42 char *name;
43 token_t type;
44 union {
45 struct psi_decl_arg *def;
46 struct psi_decl_struct *strct;
47 struct psi_decl_union *unn;
48 struct psi_decl_enum *enm;
49 struct psi_decl *func;
50 } real;
51 };
52
53 #include <string.h>
54 #define psi_decl_type_is_anon(name, type) !strncmp(name, type "@", sizeof(type))
55
56 struct psi_decl_type *psi_decl_type_init(token_t type, const char *name);
57 struct psi_decl_type *psi_decl_type_copy(struct psi_decl_type *src);
58 void psi_decl_type_free(struct psi_decl_type **type_ptr);
59 void psi_decl_type_dump(int fd, struct psi_decl_type *t, unsigned level);
60 bool psi_decl_type_validate(struct psi_data *data, struct psi_decl_type *type, struct psi_decl_arg *def);
61
62 bool psi_decl_type_validate_args(struct psi_data *data, struct psi_decl_type *decl_type, token_t type, void *current);
63
64 size_t psi_decl_type_get_size(struct psi_decl_type *dtyp, struct psi_decl_type **real_typ_ptr);
65 size_t psi_decl_type_get_align(struct psi_decl_type *t);
66 int psi_decl_type_is_weak(struct psi_decl_type *type);
67 struct psi_decl_type *psi_decl_type_get_real(struct psi_decl_type *type);
68
69 struct psi_plist *psi_decl_type_get_args(struct psi_decl_type *dtyp, struct psi_decl_type **real_typ_ptr);
70 void psi_decl_type_dump_args_with_layout(int fd, struct psi_plist *args, unsigned level);
71 size_t psi_decl_type_get_args_align(struct psi_plist *args);
72
73
74 bool psi_decl_type_get_alias(struct psi_decl_type *type, struct psi_plist *typedefs);
75 bool psi_decl_type_get_struct(struct psi_decl_type *type, struct psi_plist *structs);
76 bool psi_decl_type_get_union(struct psi_decl_type *type, struct psi_plist *unions);
77 bool psi_decl_type_get_enum(struct psi_decl_type *type, struct psi_plist *enums);
78 bool psi_decl_type_get_decl(struct psi_decl_type *type, struct psi_plist *decls);
79
80 #endif