tests: blacklist sqlite3_str and sqlite3_win32 functions
[m6w6/ext-psi] / src / data.c
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 #include "php_psi_stdinc.h"
27 #include "data.h"
28
29 #include "php_globals.h"
30
31 #include <dlfcn.h>
32 #include <ctype.h>
33
34 struct psi_data *psi_data_ctor_with_dtors(struct psi_data *data,
35 psi_error_cb error, unsigned flags)
36 {
37 if (!data) {
38 data = calloc(1, sizeof(*data));
39 }
40
41 data->error = error;
42 data->flags = flags;
43 if (!data->file.libnames) {
44 data->file.libnames = psi_plist_init((psi_plist_dtor) psi_names_free);
45 }
46 if (!data->file.dlopened) {
47 data->file.dlopened = psi_plist_init((psi_plist_dtor) psi_libs_free);
48 }
49
50 if (!data->consts) {
51 data->consts = psi_plist_init((psi_plist_dtor) psi_const_free);
52 }
53 if (!data->types) {
54 data->types = psi_plist_init((psi_plist_dtor) psi_decl_arg_free);
55 }
56 if (!data->structs) {
57 data->structs = psi_plist_init((psi_plist_dtor) psi_decl_struct_free);
58 }
59 if (!data->unions) {
60 data->unions = psi_plist_init((psi_plist_dtor) psi_decl_union_free);
61 }
62 if (!data->enums) {
63 data->enums = psi_plist_init((psi_plist_dtor) psi_decl_enum_free);
64 }
65 if (!data->decls) {
66 data->decls = psi_plist_init((psi_plist_dtor) psi_decl_free);
67 }
68 if (!data->vars) {
69 data->vars = psi_plist_init((psi_plist_dtor) psi_decl_extvar_free);
70 }
71 if (!data->impls) {
72 data->impls = psi_plist_init((psi_plist_dtor) psi_impl_free);
73 }
74 return data;
75 }
76
77 struct psi_data *psi_data_ctor(struct psi_data *data, psi_error_cb error,
78 unsigned flags)
79 {
80 if (!data) {
81 data = calloc(1, sizeof(*data));
82 }
83
84 data->error = error;
85 data->flags = flags;
86
87 if (!data->file.libnames) {
88 data->file.libnames = psi_plist_init(NULL);
89 }
90 if (!data->file.dlopened) {
91 data->file.dlopened = psi_plist_init(NULL);
92 }
93
94 if (!data->consts) {
95 data->consts = psi_plist_init(NULL);
96 }
97 if (!data->types) {
98 data->types = psi_plist_init(NULL);
99 }
100 if (!data->structs) {
101 data->structs = psi_plist_init(NULL);
102 }
103 if (!data->unions) {
104 data->unions = psi_plist_init(NULL);
105 }
106 if (!data->enums) {
107 data->enums = psi_plist_init(NULL);
108 }
109 if (!data->decls) {
110 data->decls = psi_plist_init(NULL);
111 }
112 if (!data->vars) {
113 data->vars = psi_plist_init(NULL);
114 }
115 if (!data->impls) {
116 data->impls = psi_plist_init(NULL);
117 }
118 return data;
119 }
120
121 struct psi_data *psi_data_exchange(struct psi_data *dest, struct psi_data *src)
122 {
123 if (!dest) {
124 dest = malloc(sizeof(*dest));
125 }
126 *dest = *src;
127 memset(src, 0, sizeof(*src));
128 return dest;
129 }
130
131 void psi_data_dtor(struct psi_data *data)
132 {
133 if (data->consts) {
134 psi_plist_free(data->consts);
135 }
136 if (data->types) {
137 psi_plist_free(data->types);
138 }
139 if (data->structs) {
140 psi_plist_free(data->structs);
141 }
142 if (data->unions) {
143 psi_plist_free(data->unions);
144 }
145 if (data->enums) {
146 psi_plist_free(data->enums);
147 }
148 if (data->decls) {
149 psi_plist_free(data->decls);
150 }
151 if (data->vars) {
152 psi_plist_free(data->vars);
153 }
154 if (data->impls) {
155 psi_plist_free(data->impls);
156 }
157
158 psi_decl_file_dtor(&data->file);
159 }
160
161 void psi_data_dump(int fd, struct psi_data *D)
162 {
163 size_t i = 0;
164 char *libname;
165
166 if (D->file.filename) {
167 size_t i = 0;
168 char *libname;
169
170 dprintf(fd, "// filename=%s (%u errors)\n", D->file.filename, D->errors);
171 }
172 while (psi_plist_get(D->file.libnames, i++, &libname)) {
173 dprintf(fd, "lib \"%s\";\n", libname);
174 }
175 if (psi_plist_count(D->types)) {
176 size_t i = 0;
177 struct psi_decl_arg *def;
178
179 while (psi_plist_get(D->types, i++, &def)) {
180 dprintf(fd, "typedef ");
181 psi_decl_arg_dump(fd, def, 0);
182 dprintf(fd, ";\n");
183 }
184 dprintf(fd, "\n");
185 }
186 if (psi_plist_count(D->unions)) {
187 size_t i = 0;
188 struct psi_decl_union *unn;
189
190 while (psi_plist_get(D->unions, i++, &unn)) {
191 if (!psi_decl_type_is_anon(unn->name, "union")) {
192 psi_decl_union_dump(fd, unn);
193 dprintf(fd, "\n");
194 }
195 }
196 dprintf(fd, "\n");
197 }
198 if (psi_plist_count(D->structs)) {
199 size_t i = 0;
200 struct psi_decl_struct *strct;
201
202 while (psi_plist_get(D->structs, i++, &strct)) {
203 if (!psi_decl_type_is_anon(strct->name, "struct")) {
204 psi_decl_struct_dump(fd, strct);
205 dprintf(fd, "\n");
206 }
207 }
208 dprintf(fd, "\n");
209 }
210 if (psi_plist_count(D->enums)) {
211 size_t i = 0;
212 struct psi_decl_enum *enm;
213
214 while (psi_plist_get(D->enums, i++, &enm)) {
215 if (!psi_decl_type_is_anon(enm->name, "enum")) {
216 psi_decl_enum_dump(fd, enm, 0);
217 dprintf(fd, "\n");
218 }
219 }
220 dprintf(fd, "\n");
221 }
222 if (psi_plist_count(D->consts)) {
223 size_t i = 0;
224 struct psi_const *c;
225
226 while (psi_plist_get(D->consts, i++, &c)) {
227 psi_const_dump(fd, c);
228 dprintf(fd, "\n");
229 }
230 dprintf(fd, "\n");
231 }
232 if (psi_plist_count(D->decls)) {
233 size_t i = 0;
234 struct psi_decl *decl;
235
236 while (psi_plist_get(D->decls, i++, &decl)) {
237 psi_decl_dump(fd, decl);
238 dprintf(fd, "// %p \n", decl->sym);
239 }
240 dprintf(fd, "\n");
241 }
242 if (psi_plist_count(D->vars)) {
243 size_t i = 0;
244 struct psi_decl_extvar *evar;
245
246 while (psi_plist_get(D->vars, i++, &evar)) {
247 psi_decl_extvar_dump(fd, evar);
248 }
249 dprintf(fd, "\n");
250 }
251 if (psi_plist_count(D->impls)) {
252 size_t i = 0;
253 struct psi_impl *impl;
254
255 while (psi_plist_get(D->impls, i++, &impl)) {
256 psi_impl_dump(fd, impl);
257 dprintf(fd, "\n");
258 }
259 dprintf(fd, "\n");
260 }
261 }