Line data Source code
1 : /* do not edit automatically generated by mc from M2StateCheck. */
2 : /* M2StateCheck.mod provide state check tracking for declarations.
3 :
4 : Copyright (C) 2024-2026 Free Software Foundation, Inc.
5 : Contributed by Gaius Mulley <gaiusmod2@gmail.com>.
6 :
7 : This file is part of GNU Modula-2.
8 :
9 : GNU Modula-2 is free software; you can redistribute it and/or modify
10 : it under the terms of the GNU General Public License as published by
11 : the Free Software Foundation; either version 3, or (at your option)
12 : any later version.
13 :
14 : GNU Modula-2 is distributed in the hope that it will be useful, but
15 : WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : General Public License for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with GNU Modula-2; see the file COPYING3. If not see
21 : <http://www.gnu.org/licenses/>. */
22 :
23 : #include "config.h"
24 : #include "system.h"
25 : #include "gcc-consolidation.h"
26 :
27 : #include <stdbool.h>
28 : # if !defined (PROC_D)
29 : # define PROC_D
30 : typedef void (*PROC_t) (void);
31 : typedef struct { PROC_t proc; } PROC;
32 : # endif
33 :
34 : # include "GStorage.h"
35 : #if defined(__cplusplus)
36 : # undef NULL
37 : # define NULL 0
38 : #endif
39 : #define _M2StateCheck_C
40 :
41 : #include "GM2StateCheck.h"
42 : # include "GStorage.h"
43 : # include "GM2MetaError.h"
44 : # include "GDynamicStrings.h"
45 : # include "GSymbolTable.h"
46 :
47 : typedef struct M2StateCheck__T1_r M2StateCheck__T1;
48 :
49 : typedef enum {M2StateCheck_const, M2StateCheck_var, M2StateCheck_type, M2StateCheck_constfunc, M2StateCheck_varparam, M2StateCheck_constructor} M2StateCheck_State;
50 :
51 : typedef M2StateCheck__T1 *M2StateCheck_StateCheck__opaque;
52 :
53 : typedef unsigned int M2StateCheck_StateSet;
54 :
55 : struct M2StateCheck__T1_r {
56 : M2StateCheck_StateSet state;
57 : M2StateCheck_StateCheck__opaque stack;
58 : M2StateCheck_StateCheck__opaque next;
59 : };
60 :
61 : static M2StateCheck_StateCheck__opaque FreeList;
62 :
63 : /*
64 : InitState - returns a new initialized StateCheck.
65 : */
66 :
67 : extern "C" M2StateCheck_StateCheck M2StateCheck_InitState (void);
68 :
69 : /*
70 : KillState - destructor for StateCheck.
71 : */
72 :
73 : extern "C" void M2StateCheck_KillState (M2StateCheck_StateCheck *s);
74 :
75 : /*
76 : PushState - duplicates the StateCheck s and chains the new copy to s.
77 : Return the copy.
78 : */
79 :
80 : extern "C" void M2StateCheck_PushState (M2StateCheck_StateCheck *s);
81 :
82 : /*
83 : PopState - pops the current state.
84 : */
85 :
86 : extern "C" void M2StateCheck_PopState (M2StateCheck_StateCheck *s);
87 :
88 : /*
89 : InclVar - s := s + {var}.
90 : */
91 :
92 : extern "C" void M2StateCheck_InclVar (M2StateCheck_StateCheck s);
93 :
94 : /*
95 : InclConst - s := s + {const}.
96 : */
97 :
98 : extern "C" void M2StateCheck_InclConst (M2StateCheck_StateCheck s);
99 :
100 : /*
101 : InclType - s := s + {type}.
102 : */
103 :
104 : extern "C" void M2StateCheck_InclType (M2StateCheck_StateCheck s);
105 :
106 : /*
107 : InclConstFunc - s := s + {constfunc}.
108 : */
109 :
110 : extern "C" void M2StateCheck_InclConstFunc (M2StateCheck_StateCheck s);
111 :
112 : /*
113 : InclVarParam - s := s + {varparam}.
114 : */
115 :
116 : extern "C" void M2StateCheck_InclVarParam (M2StateCheck_StateCheck s);
117 :
118 : /*
119 : InclConstructor - s := s + {constructor}.
120 : */
121 :
122 : extern "C" void M2StateCheck_InclConstructor (M2StateCheck_StateCheck s);
123 :
124 : /*
125 : ExclVar - s := s - {var}.
126 : */
127 :
128 : extern "C" void M2StateCheck_ExclVar (M2StateCheck_StateCheck s);
129 :
130 : /*
131 : ExclConst - s := s - {const}.
132 : */
133 :
134 : extern "C" void M2StateCheck_ExclConst (M2StateCheck_StateCheck s);
135 :
136 : /*
137 : ExclType - s := s - {type}.
138 : */
139 :
140 : extern "C" void M2StateCheck_ExclType (M2StateCheck_StateCheck s);
141 :
142 : /*
143 : ExclConstFunc - s := s - {constfunc}.
144 : */
145 :
146 : extern "C" void M2StateCheck_ExclConstFunc (M2StateCheck_StateCheck s);
147 :
148 : /*
149 : ExclVarParam - s := s - {varparam}.
150 : */
151 :
152 : extern "C" void M2StateCheck_ExclVarParam (M2StateCheck_StateCheck s);
153 :
154 : /*
155 : ExclConstructor - s := s - {varparam}.
156 : */
157 :
158 : extern "C" void M2StateCheck_ExclConstructor (M2StateCheck_StateCheck s);
159 :
160 : /*
161 : CheckQualident - checks to see that qualident sym is allowed in the state s.
162 : */
163 :
164 : extern "C" void M2StateCheck_CheckQualident (unsigned int tok, M2StateCheck_StateCheck s, unsigned int sym);
165 :
166 : /*
167 : New - returns an uninitialized StateCheck.
168 : */
169 :
170 : static M2StateCheck_StateCheck__opaque New (void);
171 :
172 : /*
173 : Dispose - place s onto the FreeList and set s to NIL.
174 : */
175 :
176 : static void Dispose (M2StateCheck_StateCheck__opaque *s);
177 :
178 : /*
179 : GenerateError - generates an unrecoverable error string based on the state and sym.
180 : */
181 :
182 : static void GenerateError (unsigned int tok, M2StateCheck_StateCheck__opaque s, unsigned int sym);
183 :
184 : /*
185 : init - initialize the global variables in the module.
186 : */
187 :
188 : static void init (void);
189 :
190 :
191 : /*
192 : New - returns an uninitialized StateCheck.
193 : */
194 :
195 38960 : static M2StateCheck_StateCheck__opaque New (void)
196 : {
197 38960 : M2StateCheck_StateCheck__opaque s;
198 :
199 38960 : if (FreeList == NULL)
200 : {
201 33468 : Storage_ALLOCATE ((void **) &s, sizeof (M2StateCheck__T1));
202 : }
203 : else
204 : {
205 5492 : s = FreeList;
206 5492 : FreeList = FreeList->next;
207 : }
208 38960 : return s;
209 : /* static analysis guarentees a RETURN statement will be used before here. */
210 : __builtin_unreachable ();
211 : }
212 :
213 :
214 : /*
215 : Dispose - place s onto the FreeList and set s to NIL.
216 : */
217 :
218 9056 : static void Dispose (M2StateCheck_StateCheck__opaque *s)
219 : {
220 9056 : (*s)->next = FreeList;
221 9056 : FreeList = (*s);
222 0 : }
223 :
224 :
225 : /*
226 : GenerateError - generates an unrecoverable error string based on the state and sym.
227 : */
228 :
229 36 : static void GenerateError (unsigned int tok, M2StateCheck_StateCheck__opaque s, unsigned int sym)
230 : {
231 36 : DynamicStrings_String str;
232 :
233 36 : str = DynamicStrings_InitString ((const char *) "not expecting the {%1Ad} {%1a} in a ", 36);
234 36 : if ((((1 << (M2StateCheck_const-M2StateCheck_const)) & (s->state)) != 0))
235 : {
236 12 : str = DynamicStrings_ConCat (str, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "{%kCONST} block", 15)));
237 : }
238 24 : else if ((((1 << (M2StateCheck_type-M2StateCheck_const)) & (s->state)) != 0))
239 : {
240 : /* avoid dangling else. */
241 6 : str = DynamicStrings_ConCat (str, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "{%kTYPE} block", 14)));
242 : }
243 18 : else if ((((1 << (M2StateCheck_var-M2StateCheck_const)) & (s->state)) != 0))
244 : {
245 : /* avoid dangling else. */
246 18 : str = DynamicStrings_ConCat (str, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "{%kVAR} block", 13)));
247 : }
248 36 : if ((((1 << (M2StateCheck_constfunc-M2StateCheck_const)) & (s->state)) != 0))
249 : {
250 0 : str = DynamicStrings_ConCat (str, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) " and within a constant procedure function actual parameter", 58)));
251 : }
252 36 : if ((((1 << (M2StateCheck_constructor-M2StateCheck_const)) & (s->state)) != 0))
253 : {
254 0 : str = DynamicStrings_ConCat (str, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) " and within a constructor", 25)));
255 : }
256 36 : M2MetaError_MetaErrorStringT1 (tok, str, sym);
257 0 : }
258 :
259 :
260 : /*
261 : init - initialize the global variables in the module.
262 : */
263 :
264 14952 : static void init (void)
265 : {
266 14952 : FreeList = static_cast<M2StateCheck_StateCheck__opaque> (NULL);
267 0 : }
268 :
269 :
270 : /*
271 : InitState - returns a new initialized StateCheck.
272 : */
273 :
274 38960 : extern "C" M2StateCheck_StateCheck M2StateCheck_InitState (void)
275 : {
276 38960 : M2StateCheck_StateCheck__opaque s;
277 :
278 38960 : s = New ();
279 38960 : s->state = (M2StateCheck_StateSet) 0;
280 38960 : s->stack = static_cast<M2StateCheck_StateCheck__opaque> (NULL);
281 38960 : s->next = static_cast<M2StateCheck_StateCheck__opaque> (NULL);
282 38960 : return static_cast<M2StateCheck_StateCheck> (s);
283 : /* static analysis guarentees a RETURN statement will be used before here. */
284 : __builtin_unreachable ();
285 : }
286 :
287 :
288 : /*
289 : KillState - destructor for StateCheck.
290 : */
291 :
292 0 : extern "C" void M2StateCheck_KillState (M2StateCheck_StateCheck *s)
293 : {
294 0 : M2StateCheck_StateCheck__opaque t;
295 :
296 0 : while (static_cast<M2StateCheck_StateCheck__opaque> ((*s))->stack != NULL)
297 : {
298 0 : t = static_cast<M2StateCheck_StateCheck__opaque> ((*s))->stack;
299 0 : static_cast<M2StateCheck_StateCheck__opaque> ((*s))->stack = t->stack;
300 0 : Dispose (&t);
301 : }
302 0 : Dispose (reinterpret_cast<M2StateCheck_StateCheck__opaque *> (&(*s)));
303 0 : }
304 :
305 :
306 : /*
307 : PushState - duplicates the StateCheck s and chains the new copy to s.
308 : Return the copy.
309 : */
310 :
311 9056 : extern "C" void M2StateCheck_PushState (M2StateCheck_StateCheck *s)
312 : {
313 9056 : M2StateCheck_StateCheck__opaque copy;
314 :
315 9056 : copy = static_cast<M2StateCheck_StateCheck__opaque> (M2StateCheck_InitState ());
316 9056 : copy->state = static_cast<M2StateCheck_StateCheck__opaque> ((*s))->state;
317 9056 : copy->stack = static_cast<M2StateCheck_StateCheck__opaque> ((*s));
318 9056 : (*s) = static_cast<M2StateCheck_StateCheck> (copy);
319 9056 : }
320 :
321 :
322 : /*
323 : PopState - pops the current state.
324 : */
325 :
326 9056 : extern "C" void M2StateCheck_PopState (M2StateCheck_StateCheck *s)
327 : {
328 9056 : M2StateCheck_StateCheck__opaque t;
329 :
330 9056 : t = static_cast<M2StateCheck_StateCheck__opaque> ((*s));
331 9056 : (*s) = static_cast<M2StateCheck_StateCheck> (static_cast<M2StateCheck_StateCheck__opaque> ((*s))->stack);
332 9056 : t->stack = static_cast<M2StateCheck_StateCheck__opaque> (NULL);
333 9056 : Dispose (&t);
334 9056 : }
335 :
336 :
337 : /*
338 : InclVar - s := s + {var}.
339 : */
340 :
341 46062 : extern "C" void M2StateCheck_InclVar (M2StateCheck_StateCheck s)
342 : {
343 46062 : static_cast<M2StateCheck_StateCheck__opaque> (s)->state |= (1 << (M2StateCheck_var-M2StateCheck_const ));
344 46062 : }
345 :
346 :
347 : /*
348 : InclConst - s := s + {const}.
349 : */
350 :
351 484901 : extern "C" void M2StateCheck_InclConst (M2StateCheck_StateCheck s)
352 : {
353 484901 : static_cast<M2StateCheck_StateCheck__opaque> (s)->state |= (1 << (M2StateCheck_const-M2StateCheck_const ));
354 484901 : }
355 :
356 :
357 : /*
358 : InclType - s := s + {type}.
359 : */
360 :
361 7844 : extern "C" void M2StateCheck_InclType (M2StateCheck_StateCheck s)
362 : {
363 7844 : static_cast<M2StateCheck_StateCheck__opaque> (s)->state |= (1 << (M2StateCheck_type-M2StateCheck_const ));
364 7844 : }
365 :
366 :
367 : /*
368 : InclConstFunc - s := s + {constfunc}.
369 : */
370 :
371 9056 : extern "C" void M2StateCheck_InclConstFunc (M2StateCheck_StateCheck s)
372 : {
373 9056 : static_cast<M2StateCheck_StateCheck__opaque> (s)->state |= (1 << (M2StateCheck_constfunc-M2StateCheck_const ));
374 9056 : }
375 :
376 :
377 : /*
378 : InclVarParam - s := s + {varparam}.
379 : */
380 :
381 0 : extern "C" void M2StateCheck_InclVarParam (M2StateCheck_StateCheck s)
382 : {
383 0 : static_cast<M2StateCheck_StateCheck__opaque> (s)->state |= (1 << (M2StateCheck_varparam-M2StateCheck_const ));
384 0 : }
385 :
386 :
387 : /*
388 : InclConstructor - s := s + {constructor}.
389 : */
390 :
391 47472 : extern "C" void M2StateCheck_InclConstructor (M2StateCheck_StateCheck s)
392 : {
393 47472 : static_cast<M2StateCheck_StateCheck__opaque> (s)->state |= (1 << (M2StateCheck_constructor-M2StateCheck_const ));
394 47472 : }
395 :
396 :
397 : /*
398 : ExclVar - s := s - {var}.
399 : */
400 :
401 46044 : extern "C" void M2StateCheck_ExclVar (M2StateCheck_StateCheck s)
402 : {
403 46044 : static_cast<M2StateCheck_StateCheck__opaque> (s)->state &= (~(1 << (M2StateCheck_var-M2StateCheck_const )));
404 46044 : }
405 :
406 :
407 : /*
408 : ExclConst - s := s - {const}.
409 : */
410 :
411 484877 : extern "C" void M2StateCheck_ExclConst (M2StateCheck_StateCheck s)
412 : {
413 484877 : static_cast<M2StateCheck_StateCheck__opaque> (s)->state &= (~(1 << (M2StateCheck_const-M2StateCheck_const )));
414 484877 : }
415 :
416 :
417 : /*
418 : ExclType - s := s - {type}.
419 : */
420 :
421 7838 : extern "C" void M2StateCheck_ExclType (M2StateCheck_StateCheck s)
422 : {
423 7838 : static_cast<M2StateCheck_StateCheck__opaque> (s)->state &= (~(1 << (M2StateCheck_type-M2StateCheck_const )));
424 7838 : }
425 :
426 :
427 : /*
428 : ExclConstFunc - s := s - {constfunc}.
429 : */
430 :
431 0 : extern "C" void M2StateCheck_ExclConstFunc (M2StateCheck_StateCheck s)
432 : {
433 0 : static_cast<M2StateCheck_StateCheck__opaque> (s)->state &= (~(1 << (M2StateCheck_constfunc-M2StateCheck_const )));
434 0 : }
435 :
436 :
437 : /*
438 : ExclVarParam - s := s - {varparam}.
439 : */
440 :
441 0 : extern "C" void M2StateCheck_ExclVarParam (M2StateCheck_StateCheck s)
442 : {
443 0 : static_cast<M2StateCheck_StateCheck__opaque> (s)->state &= (~(1 << (M2StateCheck_varparam-M2StateCheck_const )));
444 0 : }
445 :
446 :
447 : /*
448 : ExclConstructor - s := s - {varparam}.
449 : */
450 :
451 47472 : extern "C" void M2StateCheck_ExclConstructor (M2StateCheck_StateCheck s)
452 : {
453 47472 : static_cast<M2StateCheck_StateCheck__opaque> (s)->state &= (~(1 << (M2StateCheck_constructor-M2StateCheck_const )));
454 47472 : }
455 :
456 :
457 : /*
458 : CheckQualident - checks to see that qualident sym is allowed in the state s.
459 : */
460 :
461 8248733 : extern "C" void M2StateCheck_CheckQualident (unsigned int tok, M2StateCheck_StateCheck s, unsigned int sym)
462 : {
463 8248733 : if (sym == SymbolTable_NulSym)
464 : {} /* empty. */
465 8248679 : else if (SymbolTable_IsType (sym))
466 : {
467 : /* avoid dangling else. */
468 5130737 : if (((((1 << (M2StateCheck_constfunc-M2StateCheck_const)) & (static_cast<M2StateCheck_StateCheck__opaque> (s)->state)) != 0)) || ((((1 << (M2StateCheck_constructor-M2StateCheck_const)) & (static_cast<M2StateCheck_StateCheck__opaque> (s)->state)) != 0)))
469 : {} /* empty. */
470 : /* Ok. */
471 5123065 : else if ((((1 << (M2StateCheck_const-M2StateCheck_const)) & (static_cast<M2StateCheck_StateCheck__opaque> (s)->state)) != 0))
472 : {
473 : /* avoid dangling else. */
474 0 : GenerateError (tok, static_cast<M2StateCheck_StateCheck__opaque> (s), sym);
475 : }
476 : }
477 3117942 : else if (SymbolTable_IsConst (sym))
478 : {
479 : /* avoid dangling else. */
480 228078 : if (((((1 << (M2StateCheck_constfunc-M2StateCheck_const)) & (static_cast<M2StateCheck_StateCheck__opaque> (s)->state)) != 0)) || ((((1 << (M2StateCheck_constructor-M2StateCheck_const)) & (static_cast<M2StateCheck_StateCheck__opaque> (s)->state)) != 0)))
481 : {} /* empty. */
482 : /* Ok. */
483 216952 : else if (((((1 << (M2StateCheck_var-M2StateCheck_const)) & (static_cast<M2StateCheck_StateCheck__opaque> (s)->state)) != 0)) || ((((1 << (M2StateCheck_type-M2StateCheck_const)) & (static_cast<M2StateCheck_StateCheck__opaque> (s)->state)) != 0)))
484 : {
485 : /* avoid dangling else. */
486 0 : GenerateError (tok, static_cast<M2StateCheck_StateCheck__opaque> (s), sym);
487 : }
488 : }
489 2889864 : else if (SymbolTable_IsVar (sym))
490 : {
491 : /* avoid dangling else. */
492 89453 : if ((((1 << (M2StateCheck_constfunc-M2StateCheck_const)) & (static_cast<M2StateCheck_StateCheck__opaque> (s)->state)) != 0))
493 : {} /* empty. */
494 : /* Ok. */
495 89333 : else if ((((((1 << (M2StateCheck_const-M2StateCheck_const)) & (static_cast<M2StateCheck_StateCheck__opaque> (s)->state)) != 0)) || ((((1 << (M2StateCheck_type-M2StateCheck_const)) & (static_cast<M2StateCheck_StateCheck__opaque> (s)->state)) != 0))) || ((((1 << (M2StateCheck_var-M2StateCheck_const)) & (static_cast<M2StateCheck_StateCheck__opaque> (s)->state)) != 0)))
496 : {
497 : /* avoid dangling else. */
498 36 : GenerateError (tok, static_cast<M2StateCheck_StateCheck__opaque> (s), sym);
499 : }
500 : }
501 8248697 : }
502 :
503 14952 : extern "C" void _M2_M2StateCheck_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
504 : {
505 14952 : init ();
506 14952 : }
507 :
508 0 : extern "C" void _M2_M2StateCheck_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
509 : {
510 0 : }
|