Debian Codegraph @

engine/read_only/marpa_ami.h

raw
1 /*
2 * Copyright 2022 Jeffrey Kegler
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included
11 * in all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19 * OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22 /*
23 * DO NOT EDIT DIRECTLY
24 * This file is written by the Marpa build process
25 * It is not intended to be modified directly
26 */
27
28 /*33:*/
29 #line 519 "./marpa_ami.w"
30
31
32 #ifndef _MARPA_AMI_H__
33 #define _MARPA_AMI_H__ 1
34
35 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
36 #define _MARPA_LIKELY(expr) (__builtin_expect ((expr), 1))
37 #define _MARPA_UNLIKELY(expr) (__builtin_expect ((expr), 0))
38 #else
39 #define _MARPA_LIKELY(expr) (expr)
40 #define _MARPA_UNLIKELY(expr) (expr)
41 #endif
42
43 /*20:*/
44 #line 364 "./marpa_ami.w"
45
46 #define MARPA_OFF_DEBUG1(a)
47 #define MARPA_OFF_DEBUG2(a, b)
48 #define MARPA_OFF_DEBUG3(a, b, c)
49 #define MARPA_OFF_DEBUG4(a, b, c, d)
50 #define MARPA_OFF_DEBUG5(a, b, c, d, e)
51 #define MARPA_OFF_ASSERT(expr)
52 /*:20*//*22:*/
53 #line 385 "./marpa_ami.w"
54
55
56 #ifndef MARPA_DEBUG
57 #define MARPA_DEBUG 0
58 #endif
59
60 #if MARPA_DEBUG
61
62 #define MARPA_DEBUG1(a) (void)(marpa__debug_level && \
63 (*marpa__debug_handler)(a))
64 #define MARPA_DEBUG2(a,b) (void)(marpa__debug_level && \
65 (*marpa__debug_handler)((a),(b)))
66 #define MARPA_DEBUG3(a,b,c) (void)(marpa__debug_level && \
67 (*marpa__debug_handler)((a),(b),(c)))
68 #define MARPA_DEBUG4(a,b,c,d) (void)(marpa__debug_level && \
69 (*marpa__debug_handler)((a),(b),(c),(d)))
70 #define MARPA_DEBUG5(a,b,c,d,e) (void)(marpa__debug_level && \
71 (*marpa__debug_handler)((a),(b),(c),(d),(e)))
72
73 #else
74
75 #define MARPA_DEBUG1(a)
76 #define MARPA_DEBUG2(a,b)
77 #define MARPA_DEBUG3(a,b,c)
78 #define MARPA_DEBUG4(a,b,c,d)
79 #define MARPA_DEBUG5(a,b,c,d,e)
80
81 #endif
82
83 #if MARPA_DEBUG
84 #undef MARPA_ENABLE_ASSERT
85 #define MARPA_ENABLE_ASSERT 1
86 #endif
87
88 #ifndef MARPA_ENABLE_ASSERT
89 #define MARPA_ENABLE_ASSERT 0
90 #endif
91
92 #if MARPA_ENABLE_ASSERT
93 #undef MARPA_ASSERT
94 #define MARPA_ASSERT(expr) do { if _MARPA_LIKELY (expr) ; else \
95 (*marpa__debug_handler) ("%s: assertion failed %s", STRLOC, #expr); } while (0);
96 #else
97 #define MARPA_ASSERT(exp)
98 #endif
99
100 /*:22*/
101 #line 532 "./marpa_ami.w"
102
103 /*23:*/
104 #line 432 "./marpa_ami.w"
105
106
107 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
108 #define UNUSED __attribute__((__unused__))
109 #else
110 #define UNUSED
111 #endif
112
113 #if defined (__GNUC__) && defined (__STRICT_ANSI__)
114 # undef inline
115 # define inline __inline__
116 #endif
117 #undef Dim
118 #define Dim(x) (sizeof(x)/sizeof(*x))
119
120 #undef MAX
121 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
122
123 #undef CLAMP
124 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
125
126 /*:23*//*24:*/
127 #line 455 "./marpa_ami.w"
128
129 #undef STRINGIFY_ARG
130 #define STRINGIFY_ARG(contents) #contents
131 #undef STRINGIFY
132 #define STRINGIFY(macro_or_string) STRINGIFY_ARG (macro_or_string)
133
134 /*:24*//*25:*/
135 #line 462 "./marpa_ami.w"
136
137 #if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
138 # define STRLOC __FILE__ ":" STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
139 #else
140 # define STRLOC __FILE__ ":" STRINGIFY (__LINE__)
141 #endif
142
143 /*:25*//*26:*/
144 #line 471 "./marpa_ami.w"
145
146 #if defined (__GNUC__)
147 # define STRFUNC ((const char*) (__PRETTY_FUNCTION__))
148 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 19901L
149 # define STRFUNC ((const char*) (__func__))
150 #else
151 # define STRFUNC ((const char*) ("???"))
152 #endif
153
154 /*:26*//*27:*/
155 #line 480 "./marpa_ami.w"
156
157 #if defined __GNUC__
158 # define alignof(type) (__alignof__(type))
159 #else
160 # define alignof(type) (offsetof (struct { char __slot1; type __slot2; }, __slot2))
161 #endif
162
163 /*:27*//*28:*/
164 #line 491 "./marpa_ami.w"
165
166 #if defined(__GNUC__) && __GNUC__ >= 7
167 # define FALL_THROUGH __attribute__ ((fallthrough))
168 #else
169 # define FALL_THROUGH ((void)0)
170 #endif
171
172 /*:28*/
173 #line 533 "./marpa_ami.w"
174
175 /*29:*/
176 #line 499 "./marpa_ami.w"
177
178 typedef unsigned int BITFIELD;
179 /*23:*/
180 #line 432 "./marpa_ami.w"
181
182
183 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
184 #define UNUSED __attribute__((__unused__))
185 #else
186 #define UNUSED
187 #endif
188
189 #if defined (__GNUC__) && defined (__STRICT_ANSI__)
190 # undef inline
191 # define inline __inline__
192 #endif
193 #undef Dim
194 #define Dim(x) (sizeof(x)/sizeof(*x))
195
196 #undef MAX
197 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
198
199 #undef CLAMP
200 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
201
202 /*:23*//*24:*/
203 #line 455 "./marpa_ami.w"
204
205 #undef STRINGIFY_ARG
206 #define STRINGIFY_ARG(contents) #contents
207 #undef STRINGIFY
208 #define STRINGIFY(macro_or_string) STRINGIFY_ARG (macro_or_string)
209
210 /*:24*//*25:*/
211 #line 462 "./marpa_ami.w"
212
213 #if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
214 # define STRLOC __FILE__ ":" STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
215 #else
216 # define STRLOC __FILE__ ":" STRINGIFY (__LINE__)
217 #endif
218
219 /*:25*//*26:*/
220 #line 471 "./marpa_ami.w"
221
222 #if defined (__GNUC__)
223 # define STRFUNC ((const char*) (__PRETTY_FUNCTION__))
224 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 19901L
225 # define STRFUNC ((const char*) (__func__))
226 #else
227 # define STRFUNC ((const char*) ("???"))
228 #endif
229
230 /*:26*//*27:*/
231 #line 480 "./marpa_ami.w"
232
233 #if defined __GNUC__
234 # define alignof(type) (__alignof__(type))
235 #else
236 # define alignof(type) (offsetof (struct { char __slot1; type __slot2; }, __slot2))
237 #endif
238
239 /*:27*//*28:*/
240 #line 491 "./marpa_ami.w"
241
242 #if defined(__GNUC__) && __GNUC__ >= 7
243 # define FALL_THROUGH __attribute__ ((fallthrough))
244 #else
245 # define FALL_THROUGH ((void)0)
246 #endif
247
248 /*:28*/
249 #line 501 "./marpa_ami.w"
250
251 #define Boolean(value) ((value) ? 1 : 0)
252
253 /*:29*/
254 #line 534 "./marpa_ami.w"
255
256
257 #define marpa_new(type,count) ((type*) my_malloc((sizeof(type) *((size_t) (count) ) ) ) )
258 #define marpa_renew(type,p,count) \
259 ((type*) my_realloc((p) ,(sizeof(type) *((size_t) (count) ) ) ) ) \
260
261 #define MARPA_DSTACK_DECLARE(this) struct marpa_dstack_s this
262 #define MARPA_DSTACK_INIT(this,type,initial_size) \
263 ( \
264 ((this) .t_count= 0) , \
265 ((this) .t_base= marpa_new(type,((this) .t_capacity= (initial_size) ) ) ) \
266 )
267 #define MARPA_DSTACK_INIT2(this,type) \
268 MARPA_DSTACK_INIT((this) ,type,MAX(4,1024/sizeof(this) ) ) \
269
270 #define MARPA_DSTACK_IS_INITIALIZED(this) ((this) .t_base)
271 #define MARPA_DSTACK_SAFE(this) \
272 (((this) .t_count= (this) .t_capacity= 0) ,((this) .t_base= NULL) ) \
273
274 #define MARPA_DSTACK_COUNT_SET(this,n) ((this) .t_count= (n) ) \
275
276 #define MARPA_DSTACK_CLEAR(this) MARPA_DSTACK_COUNT_SET((this) ,0)
277 #define MARPA_DSTACK_PUSH(this,type) ( \
278 (_MARPA_UNLIKELY((this) .t_count>=(this) .t_capacity) \
279 ?marpa_dstack_resize2(&(this) ,sizeof(type) ) \
280 :0) , \
281 ((type*) (this) .t_base+(this) .t_count++) \
282 )
283 #define MARPA_DSTACK_POP(this,type) ((this) .t_count<=0?NULL: \
284 ((type*) (this) .t_base+(--(this) .t_count) ) )
285 #define MARPA_DSTACK_INDEX(this,type,ix) (MARPA_DSTACK_BASE((this) ,type) +(ix) )
286 #define MARPA_DSTACK_TOP(this,type) (MARPA_DSTACK_LENGTH(this) <=0 \
287 ?NULL \
288 :MARPA_DSTACK_INDEX((this) ,type,MARPA_DSTACK_LENGTH(this) -1) )
289 #define MARPA_DSTACK_BASE(this,type) ((type*) (this) .t_base)
290 #define MARPA_DSTACK_LENGTH(this) ((this) .t_count)
291 #define MARPA_DSTACK_CAPACITY(this) ((this) .t_capacity) \
292
293 #define MARPA_STOLEN_DSTACK_DATA_FREE(data) (my_free(data) )
294 #define MARPA_DSTACK_DESTROY(this) MARPA_STOLEN_DSTACK_DATA_FREE(this.t_base)
295 #define MARPA_DSTACK_RESIZE(this,type,new_size) \
296 (marpa_dstack_resize((this) ,sizeof(type) ,(new_size) ) )
297
298 #line 536 "./marpa_ami.w"
299
300 /*14:*/
301 #line 320 "./marpa_ami.w"
302
303 struct marpa_dstack_s;
304 typedef struct marpa_dstack_s*MARPA_DSTACK;
305 /*:14*/
306 #line 537 "./marpa_ami.w"
307
308
309 /*:33*/
310 static inline void * marpa_dstack_resize2( struct marpa_dstack_s* this, int type_bytes);
311 static inline void * marpa_dstack_resize ( struct marpa_dstack_s *this, int type_bytes, int new_size);
312 /*34:*/
313 #line 540 "./marpa_ami.w"
314
315
316 /*15:*/
317 #line 323 "./marpa_ami.w"
318
319 struct marpa_dstack_s{int t_count;int t_capacity;void*t_base;};
320 /*:15*/
321 #line 542 "./marpa_ami.w"
322
323 /*7:*/
324 #line 200 "./marpa_ami.w"
325
326 static inline
327 void my_free(void*p)
328 {
329 free(p);
330 }
331
332 /*:7*//*8:*/
333 #line 207 "./marpa_ami.w"
334
335
336 static inline
337 void*my_malloc(size_t size)
338 {
339 void*newmem= malloc(size);
340 if(_MARPA_UNLIKELY(!newmem)){(*marpa__out_of_memory)();}
341 return newmem;
342 }
343
344 static inline
345 void*
346 my_malloc0(size_t size)
347 {
348 void*newmem= my_malloc(size);
349 memset(newmem,0,size);
350 return newmem;
351 }
352
353 static inline
354 void*
355 my_realloc(void*p,size_t size)
356 {
357 if(_MARPA_LIKELY(p!=NULL)){
358 void*newmem= realloc(p,size);
359 if(_MARPA_UNLIKELY(!newmem))(*marpa__out_of_memory)();
360 return newmem;
361 }
362 return my_malloc(size);
363 }
364
365 /*:8*//*16:*/
366 #line 325 "./marpa_ami.w"
367
368 static inline void*marpa_dstack_resize2(struct marpa_dstack_s*this,int type_bytes)
369 {
370 return marpa_dstack_resize(this,type_bytes,this->t_capacity*2);
371 }
372
373 /*:16*//*18:*/
374 #line 334 "./marpa_ami.w"
375
376 static inline void*
377 marpa_dstack_resize(struct marpa_dstack_s*this,int type_bytes,
378 int new_size)
379 {
380 if(new_size> this->t_capacity)
381 {
382
383 this->t_capacity= new_size;
384 this->t_base= my_realloc(this->t_base,(size_t)new_size*(size_t)type_bytes);
385 }
386 return this->t_base;
387 }
388
389 /*:18*/
390 #line 543 "./marpa_ami.w"
391
392
393 #endif
394
395 /*:34*/