Line data Source code
1 : /* do not edit automatically generated by mc from P0SymBuild. */
2 : /* P0SymBuild.mod pass 0 symbol creation.
3 :
4 : Copyright (C) 2011-2026 Free Software Foundation, Inc.
5 : Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
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 : # if !defined (FALSE)
35 : # define FALSE (1==0)
36 : # endif
37 :
38 : # include "GStorage.h"
39 : #if defined(__cplusplus)
40 : # undef NULL
41 : # define NULL 0
42 : #endif
43 : #define _P0SymBuild_C
44 :
45 : #include "GP0SymBuild.h"
46 : # include "GStorage.h"
47 : # include "GM2Printf.h"
48 : # include "GLists.h"
49 : # include "GIndexing.h"
50 : # include "GM2Batch.h"
51 : # include "GSymbolTable.h"
52 : # include "GNameKey.h"
53 : # include "GM2Quads.h"
54 : # include "GM2Reserved.h"
55 : # include "GM2Debug.h"
56 : # include "GM2MetaError.h"
57 : # include "GM2LexBuf.h"
58 : # include "GM2Error.h"
59 : # include "GM2RTS.h"
60 :
61 : # define Debugging false
62 : typedef struct P0SymBuild__T1_r P0SymBuild__T1;
63 :
64 : typedef P0SymBuild__T1 *P0SymBuild_BlockInfoPtr;
65 :
66 : typedef struct P0SymBuild__T2_r P0SymBuild__T2;
67 :
68 : typedef P0SymBuild__T2 *P0SymBuild_ModuleDesc;
69 :
70 : typedef enum {P0SymBuild_module, P0SymBuild_program, P0SymBuild_defimp, P0SymBuild_inner, P0SymBuild_procedure, P0SymBuild_universe, P0SymBuild_unknown} P0SymBuild_Kind;
71 :
72 : struct P0SymBuild__T1_r {
73 : NameKey_Name name;
74 : P0SymBuild_Kind kind;
75 : unsigned int sym;
76 : int level;
77 : unsigned int token;
78 : Lists_List LocalModules;
79 : Indexing_Index ImportedModules;
80 : P0SymBuild_BlockInfoPtr toPC;
81 : P0SymBuild_BlockInfoPtr toReturn;
82 : P0SymBuild_BlockInfoPtr toNext;
83 : P0SymBuild_BlockInfoPtr toUp;
84 : P0SymBuild_BlockInfoPtr toDown;
85 : };
86 :
87 : struct P0SymBuild__T2_r {
88 : NameKey_Name name;
89 : unsigned int tok;
90 : };
91 :
92 : static P0SymBuild_BlockInfoPtr headBP;
93 : static P0SymBuild_BlockInfoPtr curBP;
94 : static int Level;
95 :
96 : /*
97 : EndModule -
98 : */
99 :
100 : extern "C" void P0SymBuild_EndModule (void);
101 :
102 : /*
103 : RegisterImports -
104 : */
105 :
106 : extern "C" void P0SymBuild_RegisterImports (void);
107 :
108 : /*
109 : RegisterProgramModule - register the top of stack as a program module.
110 : */
111 :
112 : extern "C" void P0SymBuild_RegisterProgramModule (void);
113 :
114 : /*
115 : RegisterImplementationModule - register the top of stack as an implementation module.
116 : */
117 :
118 : extern "C" void P0SymBuild_RegisterImplementationModule (void);
119 :
120 : /*
121 : RegisterDefinitionModule - register the top of stack as a definition module.
122 : */
123 :
124 : extern "C" void P0SymBuild_RegisterDefinitionModule (bool forC);
125 :
126 : /*
127 : RegisterInnerModule - register the top of stack as an inner module, this module name
128 : will be removed from the list of outstanding imports in the
129 : current module block.
130 : */
131 :
132 : extern "C" void P0SymBuild_RegisterInnerModule (void);
133 :
134 : /*
135 : RegisterInnerImports -
136 : */
137 :
138 : extern "C" void P0SymBuild_RegisterInnerImports (void);
139 :
140 : /*
141 : RegisterProcedure - register the top of stack as a procedure.
142 : */
143 :
144 : extern "C" void P0SymBuild_RegisterProcedure (void);
145 : extern "C" void P0SymBuild_EndProcedure (void);
146 :
147 : /*
148 : EndForward - ends building a forward procedure.
149 : */
150 :
151 : extern "C" void P0SymBuild_EndForward (void);
152 :
153 : /*
154 : P0Init -
155 : */
156 :
157 : extern "C" void P0SymBuild_P0Init (void);
158 :
159 : /*
160 : P1Init -
161 : */
162 :
163 : extern "C" void P0SymBuild_P1Init (void);
164 :
165 : /*
166 : EnterBlock -
167 : */
168 :
169 : extern "C" void P0SymBuild_EnterBlock (NameKey_Name n);
170 :
171 : /*
172 : LeaveBlock -
173 : */
174 :
175 : extern "C" void P0SymBuild_LeaveBlock (void);
176 :
177 : /*
178 : nSpaces -
179 : */
180 :
181 : static void nSpaces (unsigned int n);
182 :
183 : /*
184 : DisplayB -
185 : */
186 :
187 : static void DisplayB (P0SymBuild_BlockInfoPtr b);
188 :
189 : /*
190 : DisplayBlock -
191 : */
192 :
193 : static void DisplayBlock (P0SymBuild_BlockInfoPtr b, unsigned int l);
194 :
195 : /*
196 : Display -
197 : */
198 :
199 : static void Display (void);
200 :
201 : /*
202 : addDown - adds, b, to the down link of, a.
203 : */
204 :
205 : static void addDown (P0SymBuild_BlockInfoPtr a, P0SymBuild_BlockInfoPtr b);
206 :
207 : /*
208 : GraftBlock - add a new block, b, into the tree in the correct order.
209 : */
210 :
211 : static void GraftBlock (P0SymBuild_BlockInfoPtr b);
212 :
213 : /*
214 : BeginBlock - denotes the start of the next block. We remember all imports and
215 : local modules and procedures created in this block.
216 : */
217 :
218 : static void BeginBlock (NameKey_Name n, P0SymBuild_Kind k, unsigned int s, unsigned int tok);
219 :
220 : /*
221 : InitUniverse -
222 : */
223 :
224 : static void InitUniverse (void);
225 :
226 : /*
227 : FlushImports -
228 : */
229 :
230 : static void FlushImports (P0SymBuild_BlockInfoPtr b);
231 :
232 : /*
233 : EndBlock - shutdown the module and create definition symbols for all imported
234 : modules.
235 : */
236 :
237 : static void EndBlock (void);
238 :
239 : /*
240 : RegisterLocalModule - register, n, as a local module.
241 : */
242 :
243 : static void RegisterLocalModule (NameKey_Name modname);
244 :
245 : /*
246 : RegisterImport - register, n, as a module imported from either a local scope or definition module.
247 : */
248 :
249 : static void RegisterImport (unsigned int tok, NameKey_Name modname);
250 :
251 : /*
252 : DeclareModules - declare all inner modules seen at the current block level.
253 : */
254 :
255 : static void DeclareModules (void);
256 :
257 : /*
258 : Move -
259 : */
260 :
261 : static void Move (void);
262 :
263 :
264 : /*
265 : nSpaces -
266 : */
267 :
268 0 : static void nSpaces (unsigned int n)
269 : {
270 0 : while (n > 0)
271 : {
272 0 : M2Printf_printf0 ((const char *) " ", 1);
273 0 : n -= 1;
274 : }
275 0 : }
276 :
277 :
278 : /*
279 : DisplayB -
280 : */
281 :
282 0 : static void DisplayB (P0SymBuild_BlockInfoPtr b)
283 : {
284 0 : switch (b->kind)
285 : {
286 0 : case P0SymBuild_program:
287 0 : M2Printf_printf1 ((const char *) "MODULE %a ;\\n", 13, (const unsigned char *) &b->name, (sizeof (b->name)-1));
288 0 : break;
289 :
290 0 : case P0SymBuild_defimp:
291 0 : M2Printf_printf1 ((const char *) "DEFIMP %a ;\\n", 13, (const unsigned char *) &b->name, (sizeof (b->name)-1));
292 0 : break;
293 :
294 0 : case P0SymBuild_inner:
295 0 : M2Printf_printf1 ((const char *) "INNER MODULE %a ;\\n", 19, (const unsigned char *) &b->name, (sizeof (b->name)-1));
296 0 : break;
297 :
298 0 : case P0SymBuild_procedure:
299 0 : M2Printf_printf1 ((const char *) "PROCEDURE %a ;\\n", 16, (const unsigned char *) &b->name, (sizeof (b->name)-1));
300 0 : break;
301 :
302 :
303 0 : default:
304 0 : M2RTS_HALT (-1);
305 : __builtin_unreachable ();
306 0 : break;
307 : }
308 0 : }
309 :
310 :
311 : /*
312 : DisplayBlock -
313 : */
314 :
315 0 : static void DisplayBlock (P0SymBuild_BlockInfoPtr b, unsigned int l)
316 : {
317 0 : P0SymBuild_BlockInfoPtr a;
318 :
319 0 : nSpaces (l);
320 0 : DisplayB (b);
321 0 : a = b->toDown;
322 0 : l += 3;
323 0 : while (a != NULL)
324 : {
325 0 : DisplayBlock (a, l);
326 0 : a = a->toNext;
327 : }
328 0 : l -= 3;
329 0 : nSpaces (l);
330 0 : M2Printf_printf1 ((const char *) "END %a\\n", 8, (const unsigned char *) &b->name, (sizeof (b->name)-1));
331 0 : }
332 :
333 :
334 : /*
335 : Display -
336 : */
337 :
338 0 : static void Display (void)
339 : {
340 0 : P0SymBuild_BlockInfoPtr b;
341 :
342 0 : M2Printf_printf0 ((const char *) "Universe of Modula-2 modules\\n", 30);
343 0 : if (headBP != NULL)
344 : {
345 0 : b = headBP->toDown;
346 0 : while (b != NULL)
347 : {
348 0 : DisplayBlock (b, 0);
349 0 : b = b->toNext;
350 : }
351 : }
352 0 : }
353 :
354 :
355 : /*
356 : addDown - adds, b, to the down link of, a.
357 : */
358 :
359 2150641 : static void addDown (P0SymBuild_BlockInfoPtr a, P0SymBuild_BlockInfoPtr b)
360 : {
361 0 : if (a->toDown == NULL)
362 : {
363 87984 : a->toDown = b;
364 : }
365 : else
366 : {
367 : a = a->toDown;
368 69624841 : while (a->toNext != NULL)
369 : {
370 : a = a->toNext;
371 : }
372 2062657 : a->toNext = b;
373 : }
374 0 : }
375 :
376 :
377 : /*
378 : GraftBlock - add a new block, b, into the tree in the correct order.
379 : */
380 :
381 2150641 : static void GraftBlock (P0SymBuild_BlockInfoPtr b)
382 : {
383 2150641 : M2Debug_Assert (curBP != NULL);
384 2150641 : M2Debug_Assert (abs (Level-curBP->level) <= 1);
385 2150641 : switch (Level-curBP->level)
386 : {
387 0 : case -1:
388 0 : curBP = curBP->toUp; /* returning up to the outer scope */
389 0 : M2Debug_Assert (curBP->toNext == NULL);
390 0 : curBP->toNext = b;
391 0 : break;
392 :
393 0 : case 0:
394 0 : M2Debug_Assert (curBP->toNext == NULL); /* add toNext */
395 0 : curBP->toNext = b;
396 0 : b->toUp = curBP->toUp;
397 0 : break;
398 :
399 2150641 : case 1:
400 2150641 : b->toUp = curBP; /* save return value */
401 2150641 : addDown (curBP, b); /* save return value */
402 : break;
403 :
404 :
405 0 : default:
406 0 : M2RTS_HALT (-1);
407 : __builtin_unreachable ();
408 2150641 : break;
409 : }
410 2150641 : curBP = b;
411 2150641 : }
412 :
413 :
414 : /*
415 : BeginBlock - denotes the start of the next block. We remember all imports and
416 : local modules and procedures created in this block.
417 : */
418 :
419 2150641 : static void BeginBlock (NameKey_Name n, P0SymBuild_Kind k, unsigned int s, unsigned int tok)
420 : {
421 2150641 : P0SymBuild_BlockInfoPtr b;
422 :
423 2150641 : Storage_ALLOCATE ((void **) &b, sizeof (P0SymBuild__T1));
424 2150641 : b->name = n;
425 2150641 : b->kind = k;
426 2150641 : b->sym = s;
427 2150641 : Lists_InitList (&b->LocalModules);
428 2150641 : b->ImportedModules = Indexing_InitIndex (1);
429 2150641 : b->toPC = NULL;
430 2150641 : b->toReturn = NULL;
431 2150641 : b->toNext = NULL;
432 2150641 : b->toDown = NULL;
433 2150641 : b->toUp = NULL;
434 2150641 : b->level = Level;
435 2150641 : b->token = tok;
436 2150641 : GraftBlock (b);
437 2150641 : }
438 :
439 :
440 : /*
441 : InitUniverse -
442 : */
443 :
444 17024 : static void InitUniverse (void)
445 : {
446 17024 : Storage_ALLOCATE ((void **) &curBP, sizeof (P0SymBuild__T1));
447 17024 : curBP->name = NameKey_NulName;
448 17024 : curBP->kind = P0SymBuild_universe;
449 17024 : curBP->sym = SymbolTable_NulSym;
450 17024 : Lists_InitList (&curBP->LocalModules);
451 17024 : curBP->ImportedModules = Indexing_InitIndex (1);
452 17024 : curBP->toNext = NULL;
453 17024 : curBP->toDown = NULL;
454 17024 : curBP->toUp = curBP;
455 17024 : curBP->level = Level;
456 17024 : headBP = curBP;
457 17024 : }
458 :
459 :
460 : /*
461 : FlushImports -
462 : */
463 :
464 2409367 : static void FlushImports (P0SymBuild_BlockInfoPtr b)
465 : {
466 2409367 : unsigned int i;
467 2409367 : unsigned int n;
468 2409367 : P0SymBuild_ModuleDesc desc;
469 :
470 2409367 : i = Indexing_LowIndice (b->ImportedModules);
471 2409367 : n = Indexing_HighIndice (b->ImportedModules);
472 16073186 : while (i <= n)
473 : {
474 11254452 : desc = static_cast<P0SymBuild_ModuleDesc> (Indexing_GetIndice (b->ImportedModules, i));
475 11254452 : b->sym = M2Batch_MakeDefinitionSource (desc->tok, desc->name);
476 11254452 : M2Debug_Assert (b->sym != SymbolTable_NulSym);
477 11254452 : i += 1;
478 : }
479 2409367 : }
480 :
481 :
482 : /*
483 : EndBlock - shutdown the module and create definition symbols for all imported
484 : modules.
485 : */
486 :
487 2150617 : static void EndBlock (void)
488 : {
489 2150617 : FlushImports (curBP);
490 2150617 : curBP = curBP->toUp;
491 2150617 : Level -= 1;
492 2150617 : if (Level == 0)
493 : {
494 258750 : FlushImports (curBP);
495 : }
496 2150617 : }
497 :
498 :
499 : /*
500 : RegisterLocalModule - register, n, as a local module.
501 : */
502 :
503 434 : static void RegisterLocalModule (NameKey_Name modname)
504 : {
505 434 : unsigned int i;
506 434 : unsigned int n;
507 434 : P0SymBuild_ModuleDesc desc;
508 :
509 : /* printf1('seen local module %a
510 : ', n) ; */
511 434 : Lists_IncludeItemIntoList (curBP->LocalModules, modname);
512 434 : i = Indexing_LowIndice (curBP->ImportedModules);
513 434 : n = Indexing_HighIndice (curBP->ImportedModules);
514 880 : while (i <= n)
515 : {
516 12 : desc = static_cast<P0SymBuild_ModuleDesc> (Indexing_GetIndice (curBP->ImportedModules, i));
517 12 : if (desc->name == modname)
518 : {
519 12 : Indexing_RemoveIndiceFromIndex (curBP->ImportedModules, reinterpret_cast <void *> (desc));
520 12 : Storage_DEALLOCATE ((void **) &desc, sizeof (P0SymBuild__T2));
521 : /* Continue checking in case a user imported the same module again. */
522 12 : n -= 1;
523 : }
524 : else
525 : {
526 0 : i += 1;
527 : }
528 : }
529 434 : }
530 :
531 :
532 : /*
533 : RegisterImport - register, n, as a module imported from either a local scope or definition module.
534 : */
535 :
536 425991 : static void RegisterImport (unsigned int tok, NameKey_Name modname)
537 : {
538 425991 : P0SymBuild_BlockInfoPtr bp;
539 425991 : P0SymBuild_ModuleDesc desc;
540 :
541 : /* printf1('register import from module %a
542 : ', n) ; */
543 425991 : M2Debug_Assert (curBP != NULL);
544 425991 : M2Debug_Assert (curBP->toUp != NULL);
545 425991 : bp = curBP->toUp; /* skip over current module */
546 425991 : if (! (Lists_IsItemInList (bp->LocalModules, modname))) /* skip over current module */
547 : {
548 425967 : Storage_ALLOCATE ((void **) &desc, sizeof (P0SymBuild__T2));
549 425967 : desc->name = modname;
550 425967 : desc->tok = tok;
551 425967 : Indexing_IncludeIndiceIntoIndex (bp->ImportedModules, reinterpret_cast <void *> (desc));
552 : }
553 425991 : }
554 :
555 :
556 : /*
557 : DeclareModules - declare all inner modules seen at the current block level.
558 : */
559 :
560 2148122 : static void DeclareModules (void)
561 : {
562 2148122 : P0SymBuild_BlockInfoPtr b;
563 2148122 : unsigned int s;
564 :
565 2148122 : b = curBP->toDown;
566 4038309 : while (b != NULL)
567 : {
568 1890187 : if (b->kind == P0SymBuild_inner)
569 : {
570 428 : if (Debugging)
571 : {
572 : M2Printf_printf1 ((const char *) "*** declaring inner module %a\\n", 32, (const unsigned char *) &b->name, (sizeof (b->name)-1));
573 : }
574 428 : s = SymbolTable_MakeInnerModule (curBP->token, b->name);
575 428 : M2Debug_Assert (s != SymbolTable_NulSym);
576 : }
577 1890187 : b = b->toNext;
578 : }
579 2148122 : }
580 :
581 :
582 : /*
583 : Move -
584 : */
585 :
586 4296238 : static void Move (void)
587 : {
588 4296238 : P0SymBuild_BlockInfoPtr b;
589 :
590 4296238 : if (Level == curBP->level)
591 : {
592 0 : b = curBP->toReturn;
593 : /* moving to next */
594 0 : curBP = curBP->toNext;
595 : /* remember our return */
596 0 : curBP->toReturn = b;
597 : }
598 : else
599 : {
600 8592476 : while (Level != curBP->level)
601 : {
602 4296238 : if (Level < curBP->level)
603 : {
604 : /* move up to the outer scope */
605 2148116 : b = curBP;
606 2148116 : curBP = curBP->toReturn;
607 2148116 : curBP->toPC = b->toNext;
608 : }
609 : else
610 : {
611 : /* remember where we came from */
612 2148122 : b = curBP;
613 2148122 : if (curBP->toPC == NULL)
614 : {
615 70871 : M2Debug_Assert (curBP->toDown != NULL);
616 70871 : curBP->toPC = curBP->toDown;
617 : }
618 2148122 : M2Debug_Assert (curBP->toPC != NULL);
619 2148122 : curBP = curBP->toPC;
620 2148122 : curBP->toReturn = b;
621 : }
622 : }
623 : }
624 4296238 : }
625 :
626 :
627 : /*
628 : EndModule -
629 : */
630 :
631 259178 : extern "C" void P0SymBuild_EndModule (void)
632 : {
633 259178 : NameKey_Name NameEnd;
634 259178 : NameKey_Name NameStart;
635 259178 : unsigned int end;
636 259178 : unsigned int start;
637 :
638 259178 : M2Quads_PopTtok (&NameEnd, &end);
639 259178 : M2Quads_PopTtok (&NameStart, &start);
640 259178 : M2Debug_Assert (start != M2LexBuf_UnknownTokenNo);
641 259178 : M2Debug_Assert (end != M2LexBuf_UnknownTokenNo);
642 259178 : if (NameEnd != NameStart)
643 : {
644 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
645 30 : if (NameEnd == NameKey_NulName)
646 : {
647 18 : M2MetaError_MetaErrorT1 (start, (const char *) "module name at beginning {%1Ea} does not match the name at end", 62, SymbolTable_MakeError (start, NameStart));
648 18 : M2MetaError_MetaError1 ((const char *) "module name at end does not match the name at beginning {%1Ea}", 62, SymbolTable_MakeError (start, NameStart));
649 : }
650 : else
651 : {
652 12 : M2MetaError_MetaErrorT2 (start, (const char *) "module name at beginning {%1Ea} does not match the name at end {%2a}", 68, SymbolTable_MakeError (start, curBP->name), SymbolTable_MakeError (end, NameEnd));
653 12 : M2MetaError_MetaErrorT2 (end, (const char *) "module name at end {%1Ea} does not match the name at beginning {%2Ea}", 69, SymbolTable_MakeError (end, NameEnd), SymbolTable_MakeError (start, curBP->name));
654 : }
655 : }
656 259178 : EndBlock ();
657 259178 : M2Error_LeaveErrorScope ();
658 259178 : }
659 :
660 :
661 : /*
662 : RegisterImports -
663 : */
664 :
665 410725 : extern "C" void P0SymBuild_RegisterImports (void)
666 : {
667 410725 : unsigned int index;
668 410725 : unsigned int i;
669 410725 : unsigned int n;
670 :
671 410725 : M2Quads_PopT (&n); /* n = # of the Ident List */
672 410725 : if ((M2Quads_OperandT (n+1)) == M2Reserved_ImportTok)
673 : {
674 : /* Ident list contains Module Names */
675 : i = 1;
676 113694 : while (i <= n)
677 : {
678 64447 : index = (n+1)-i;
679 64447 : RegisterImport (M2Quads_OperandTok (index), M2Quads_OperandT (index));
680 64447 : i += 1;
681 : }
682 : }
683 : else
684 : {
685 : /* Ident List contains list of objects */
686 361478 : RegisterImport (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
687 : }
688 410725 : M2Quads_PopN (n+1); /* clear stack */
689 410725 : }
690 :
691 :
692 : /*
693 : RegisterProgramModule - register the top of stack as a program module.
694 : */
695 :
696 11878 : extern "C" void P0SymBuild_RegisterProgramModule (void)
697 : {
698 11878 : NameKey_Name n;
699 11878 : unsigned int sym;
700 11878 : unsigned int tok;
701 :
702 11878 : M2Debug_Assert (Level == 0);
703 11878 : Level += 1;
704 11878 : M2Quads_PopTtok (&n, &tok);
705 11878 : M2Quads_PushTtok (n, tok);
706 11878 : sym = M2Batch_MakeProgramSource (tok, n);
707 11878 : SymbolTable_SetCurrentModule (sym);
708 11878 : SymbolTable_SetFileModule (sym);
709 11878 : BeginBlock (n, P0SymBuild_program, sym, tok);
710 11878 : M2Error_EnterProgramScope (n);
711 11878 : }
712 :
713 :
714 : /*
715 : RegisterImplementationModule - register the top of stack as an implementation module.
716 : */
717 :
718 73013 : extern "C" void P0SymBuild_RegisterImplementationModule (void)
719 : {
720 73013 : NameKey_Name n;
721 73013 : unsigned int sym;
722 73013 : unsigned int tok;
723 :
724 73013 : M2Debug_Assert (Level == 0);
725 73013 : Level += 1;
726 73013 : M2Quads_PopTtok (&n, &tok);
727 73013 : M2Quads_PushTtok (n, tok);
728 73013 : sym = M2Batch_MakeImplementationSource (tok, n);
729 73013 : SymbolTable_SetCurrentModule (sym);
730 73013 : SymbolTable_SetFileModule (sym);
731 73013 : BeginBlock (n, P0SymBuild_defimp, sym, tok);
732 73013 : M2Error_EnterImplementationScope (n);
733 73013 : }
734 :
735 :
736 : /*
737 : RegisterDefinitionModule - register the top of stack as a definition module.
738 : */
739 :
740 173871 : extern "C" void P0SymBuild_RegisterDefinitionModule (bool forC)
741 : {
742 173871 : NameKey_Name n;
743 173871 : unsigned int sym;
744 173871 : unsigned int tok;
745 :
746 173871 : M2Debug_Assert (Level == 0);
747 173871 : Level += 1;
748 173871 : M2Quads_PopTtok (&n, &tok);
749 173871 : M2Quads_PushTtok (n, tok);
750 173871 : sym = M2Batch_MakeDefinitionSource (tok, n);
751 173871 : SymbolTable_SetCurrentModule (sym);
752 173871 : SymbolTable_SetFileModule (sym);
753 173871 : if (forC)
754 : {
755 13260 : SymbolTable_PutDefinitionForC (sym);
756 : }
757 173871 : BeginBlock (n, P0SymBuild_defimp, sym, tok);
758 173871 : M2Error_EnterDefinitionScope (n);
759 173871 : }
760 :
761 :
762 : /*
763 : RegisterInnerModule - register the top of stack as an inner module, this module name
764 : will be removed from the list of outstanding imports in the
765 : current module block.
766 : */
767 :
768 434 : extern "C" void P0SymBuild_RegisterInnerModule (void)
769 : {
770 434 : NameKey_Name n;
771 434 : unsigned int tok;
772 :
773 434 : Level += 1;
774 434 : M2Quads_PopTtok (&n, &tok);
775 434 : M2Quads_PushTtok (n, tok);
776 434 : RegisterLocalModule (n);
777 434 : BeginBlock (n, P0SymBuild_inner, SymbolTable_NulSym, tok);
778 434 : M2Error_EnterModuleScope (n);
779 434 : }
780 :
781 :
782 : /*
783 : RegisterInnerImports -
784 : */
785 :
786 230 : extern "C" void P0SymBuild_RegisterInnerImports (void)
787 : {
788 230 : unsigned int n;
789 :
790 230 : M2Quads_PopT (&n); /* n = # of the Ident List */
791 230 : if ((M2Quads_OperandT (n+1)) == M2Reserved_ImportTok)
792 : {} /* empty. */
793 : else
794 : {
795 : /* Ident List contains list of objects, but we are importing directly from a module OperandT(n+1) */
796 66 : RegisterImport (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
797 : }
798 230 : M2Quads_PopN (n+1); /* clear stack */
799 230 : }
800 :
801 :
802 : /*
803 : RegisterProcedure - register the top of stack as a procedure.
804 : */
805 :
806 1891445 : extern "C" void P0SymBuild_RegisterProcedure (void)
807 : {
808 1891445 : NameKey_Name n;
809 1891445 : unsigned int tok;
810 :
811 1891445 : Level += 1;
812 1891445 : M2Quads_PopTtok (&n, &tok);
813 1891445 : M2Quads_PushTtok (n, tok);
814 1891445 : BeginBlock (n, P0SymBuild_procedure, SymbolTable_NulSym, tok);
815 1891445 : M2Error_EnterProcedureScope (n);
816 1891445 : }
817 :
818 1891379 : extern "C" void P0SymBuild_EndProcedure (void)
819 : {
820 1891379 : NameKey_Name NameEnd;
821 1891379 : NameKey_Name NameStart;
822 1891379 : unsigned int end;
823 1891379 : unsigned int start;
824 :
825 : /*
826 : EndBuildProcedure - ends building a Procedure.
827 : */
828 1891379 : M2Quads_PopTtok (&NameEnd, &end);
829 1891379 : M2Quads_PopTtok (&NameStart, &start);
830 1891379 : M2Debug_Assert (start != M2LexBuf_UnknownTokenNo);
831 1891379 : M2Debug_Assert (end != M2LexBuf_UnknownTokenNo);
832 1891379 : if (NameEnd != NameStart)
833 : {
834 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
835 6 : if (NameEnd == NameKey_NulName)
836 : {
837 0 : M2MetaError_MetaErrorT1 (start, (const char *) "procedure name at beginning {%1Ea} does not match the name at end", 65, SymbolTable_MakeError (start, NameStart));
838 0 : M2MetaError_MetaError1 ((const char *) "procedure name at end does not match the name at beginning {%1Ea}", 65, SymbolTable_MakeError (start, NameStart));
839 : }
840 : else
841 : {
842 6 : M2MetaError_MetaErrorT2 (start, (const char *) "procedure name at beginning {%1Ea} does not match the name at end {%2a}", 71, SymbolTable_MakeError (start, curBP->name), SymbolTable_MakeError (end, NameEnd));
843 6 : M2MetaError_MetaErrorT2 (end, (const char *) "procedure name at end {%1Ea} does not match the name at beginning {%2Ea}", 72, SymbolTable_MakeError (end, NameEnd), SymbolTable_MakeError (start, curBP->name));
844 : }
845 : }
846 1891379 : EndBlock ();
847 1891379 : M2Error_LeaveErrorScope ();
848 1891379 : }
849 :
850 :
851 : /*
852 : EndForward - ends building a forward procedure.
853 : */
854 :
855 60 : extern "C" void P0SymBuild_EndForward (void)
856 : {
857 60 : M2Quads_PopN (1);
858 60 : EndBlock ();
859 60 : M2Error_LeaveErrorScope ();
860 60 : }
861 :
862 :
863 : /*
864 : P0Init -
865 : */
866 :
867 17024 : extern "C" void P0SymBuild_P0Init (void)
868 : {
869 17024 : headBP = NULL;
870 17024 : curBP = NULL;
871 17024 : Level = 0;
872 17024 : InitUniverse ();
873 17024 : }
874 :
875 :
876 : /*
877 : P1Init -
878 : */
879 :
880 16892 : extern "C" void P0SymBuild_P1Init (void)
881 : {
882 16892 : if (Debugging)
883 : {
884 : Display ();
885 : }
886 : /* curBP := headBP^.toDown ; */
887 16892 : curBP = headBP;
888 16892 : M2Debug_Assert (curBP != NULL);
889 16892 : curBP->toPC = curBP->toDown;
890 16892 : curBP->toReturn = curBP;
891 16892 : Level = 0;
892 16892 : }
893 :
894 :
895 : /*
896 : EnterBlock -
897 : */
898 :
899 2148122 : extern "C" void P0SymBuild_EnterBlock (NameKey_Name n)
900 : {
901 2148122 : M2Debug_Assert (curBP != NULL);
902 2148122 : Level += 1;
903 2148122 : Move ();
904 2148122 : if (Debugging)
905 : {
906 : nSpaces (static_cast<unsigned int> (Level*3));
907 : if (n == curBP->name)
908 : {
909 : M2Printf_printf1 ((const char *) "block %a\\n", 10, (const unsigned char *) &n, (sizeof (n)-1));
910 : }
911 : else
912 : {
913 : M2Printf_printf2 ((const char *) "seen block %a but tree has recorded %a\\n", 40, (const unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) &curBP->name, (sizeof (curBP->name)-1));
914 : }
915 : }
916 4296244 : M2Debug_Assert ((n == curBP->name) || (curBP->name == NameKey_NulName));
917 2148122 : DeclareModules ();
918 2148122 : }
919 :
920 :
921 : /*
922 : LeaveBlock -
923 : */
924 :
925 2148116 : extern "C" void P0SymBuild_LeaveBlock (void)
926 : {
927 2148116 : if (Debugging)
928 : {
929 : M2Printf_printf1 ((const char *) "leaving block %a ", 17, (const unsigned char *) &curBP->name, (sizeof (curBP->name)-1));
930 : }
931 2148116 : Level -= 1;
932 2148116 : Move ();
933 2148116 : }
934 :
935 0 : extern "C" void _M2_P0SymBuild_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
936 : {
937 0 : }
938 :
939 0 : extern "C" void _M2_P0SymBuild_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
940 : {
941 0 : }
|