Line data Source code
1 : /* do not edit automatically generated by mc from P1SymBuild. */
2 : /* P1SymBuild.mod pass 1 symbol creation.
3 :
4 : Copyright (C) 2001-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 : #define _P1SymBuild_C
39 :
40 : #include "GP1SymBuild.h"
41 : # include "GASCII.h"
42 : # include "GNameKey.h"
43 : # include "GM2Debug.h"
44 : # include "GM2LexBuf.h"
45 : # include "GM2MetaError.h"
46 : # include "GDynamicStrings.h"
47 : # include "GM2Printf.h"
48 : # include "GM2Options.h"
49 : # include "GM2Reserved.h"
50 : # include "GFifoQueue.h"
51 : # include "GP0SymBuild.h"
52 : # include "Glibc.h"
53 : # include "GSymbolTable.h"
54 : # include "GM2Batch.h"
55 : # include "GM2Quads.h"
56 : # include "GM2Comp.h"
57 :
58 : # define Debugging false
59 : static unsigned int importStatementCount;
60 : extern "C" void P1SymBuild_P1StartBuildDefinitionModule (void);
61 : extern "C" void P1SymBuild_P1EndBuildDefinitionModule (void);
62 : extern "C" void P1SymBuild_P1StartBuildImplementationModule (void);
63 : extern "C" void P1SymBuild_P1EndBuildImplementationModule (void);
64 : extern "C" void P1SymBuild_P1StartBuildProgramModule (void);
65 : extern "C" void P1SymBuild_P1EndBuildProgramModule (void);
66 :
67 : /*
68 : StartBuildInnerModule - Creates an Inner module and starts
69 : a new scope.
70 :
71 : The Stack is expected:
72 :
73 : Entry Exit
74 :
75 : Ptr -> <- Ptr
76 : +------------+ +-----------+
77 : | NameStart | | NameStart |
78 : |------------| |-----------|
79 :
80 : */
81 :
82 : extern "C" void P1SymBuild_StartBuildInnerModule (void);
83 :
84 : /*
85 : EndBuildInnerModule - Destroys the Inner module scope and
86 : checks for correct name.
87 :
88 : The Stack is expected:
89 :
90 : Entry Exit
91 :
92 : Ptr ->
93 : +------------+ +-----------+
94 : | NameEnd | | |
95 : |------------| |-----------|
96 : | NameStart | | | <- Ptr
97 : |------------| |-----------|
98 : */
99 :
100 : extern "C" void P1SymBuild_EndBuildInnerModule (void);
101 :
102 : /*
103 : BuildImportOuterModule - Builds imported identifiers into an outer module
104 : from a definition module.
105 :
106 : The Stack is expected:
107 :
108 : Entry OR Entry
109 :
110 : Ptr -> Ptr ->
111 : +------------+ +-----------+
112 : | # | | # |
113 : |------------| |-----------|
114 : | Id1 | | Id1 |
115 : |------------| |-----------|
116 : . . . .
117 : . . . .
118 : . . . .
119 : |------------| |-----------|
120 : | Id# | | Id# |
121 : |------------| |-----------|
122 : | ImportTok | | Ident |
123 : |------------| |-----------|
124 :
125 : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
126 :
127 :
128 : Exit
129 :
130 : All above stack discarded
131 : */
132 :
133 : extern "C" void P1SymBuild_BuildImportOuterModule (bool definition);
134 :
135 : /*
136 : BuildExportOuterModule - Builds exported identifiers from an outer module
137 : to the outside world of library modules.
138 :
139 : The Stack is expected:
140 :
141 : Entry OR Entry
142 :
143 : Ptr -> Ptr ->
144 : +------------+ +--------------+
145 : | # | | # |
146 : |------------| |--------------|
147 : | Id1 | | Id1 |
148 : |------------| |--------------|
149 : . . . .
150 : . . . .
151 : . . . .
152 : |------------| |--------------|
153 : | Id# | | Id# |
154 : |------------| |--------------|
155 : | ExportTok | | QualifiedTok |
156 : |------------| |--------------|
157 :
158 : EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
159 :
160 : Error Condition
161 :
162 :
163 : Exit
164 :
165 : All above stack discarded
166 : */
167 :
168 : extern "C" void P1SymBuild_BuildExportOuterModule (void);
169 :
170 : /*
171 : CheckExplicitExported - checks to see whether we are compiling
172 : a definition module and whether the ident
173 : is implicitly export qualified or unqualified.
174 :
175 :
176 : The Stack is expected:
177 :
178 : Entry Exit
179 :
180 : Ptr -> Ptr ->
181 : +------------+ +-----------+
182 : | Identname | | Identname |
183 : |------------| |-----------|
184 :
185 : */
186 :
187 : extern "C" void P1SymBuild_CheckExplicitExported (void);
188 :
189 : /*
190 : BuildImportInnerModule - Builds imported identifiers into an inner module
191 : from the last level of module.
192 :
193 : The Stack is expected:
194 :
195 : Entry OR Entry
196 :
197 : Ptr -> Ptr ->
198 : +------------+ +-----------+
199 : | # | | # |
200 : |------------| |-----------|
201 : | Id1 | | Id1 |
202 : |------------| |-----------|
203 : . . . .
204 : . . . .
205 : . . . .
206 : |------------| |-----------|
207 : | Id# | | Id# |
208 : |------------| |-----------|
209 : | ImportTok | | Ident |
210 : |------------| |-----------|
211 :
212 : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
213 :
214 : Exit
215 :
216 : All above stack discarded
217 : */
218 :
219 : extern "C" void P1SymBuild_BuildImportInnerModule (void);
220 :
221 : /*
222 : BuildExportInnerModule - Builds exported identifiers from an inner module
223 : to the next layer module.
224 :
225 : The Stack is expected:
226 :
227 : Entry OR Entry
228 :
229 : Ptr -> Ptr ->
230 : +------------+ +--------------+
231 : | # | | # |
232 : |------------| |--------------|
233 : | Id1 | | Id1 |
234 : |------------| |--------------|
235 : . . . .
236 : . . . .
237 : . . . .
238 : |------------| |--------------|
239 : | Id# | | Id# |
240 : |------------| |--------------|
241 : | ExportTok | | QualifiedTok |
242 : |------------| |--------------|
243 :
244 : EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
245 :
246 :
247 : Exit
248 :
249 :
250 : All above stack discarded
251 : */
252 :
253 : extern "C" void P1SymBuild_BuildExportInnerModule (void);
254 :
255 : /*
256 : StartBuildEnumeration - Builds an Enumeration type Type.
257 :
258 :
259 : Stack
260 :
261 : Entry Exit
262 :
263 : Ptr ->
264 : +------------+
265 : | # |
266 : |------------|
267 : | en 1 |
268 : |------------|
269 : | en 2 |
270 : |------------|
271 : . .
272 : . .
273 : . . <- Ptr
274 : |------------| +------------+
275 : | en # | | Type |
276 : |------------| |------------|
277 : | Name | | Name |
278 : |------------| |------------|
279 : */
280 :
281 : extern "C" void P1SymBuild_StartBuildEnumeration (void);
282 :
283 : /*
284 : EndBuildEnumeration - completes the construction of the enumeration type.
285 :
286 :
287 : Stack
288 :
289 : Entry Exit
290 :
291 : Ptr ->
292 : +------------+
293 : | Type | <- Ptr
294 : |------------| +---------------+
295 : | Name | | Type | Name |
296 : |------------| |---------------|
297 :
298 : Empty
299 : */
300 :
301 : extern "C" void P1SymBuild_EndBuildEnumeration (void);
302 :
303 : /*
304 : BuildHiddenType - Builds a Hidden Type.
305 :
306 :
307 : Stack
308 :
309 : Entry Exit
310 :
311 : Ptr ->
312 : +------------+
313 : | Name | <- Ptr
314 : |------------| Empty
315 : */
316 :
317 : extern "C" void P1SymBuild_BuildHiddenType (void);
318 :
319 : /*
320 : StartBuildProcedure - Builds a Procedure.
321 :
322 : The Stack:
323 :
324 : Entry Exit
325 :
326 : Ptr -> <- Ptr
327 : +------------+ +------------+
328 : | Name | | ProcSym |
329 : |------------| |------------|
330 : | inlinetok | | |
331 : | or | | |
332 : | builtintok | | |
333 : | or name or | | Name |
334 : | NulTok | | |
335 : |------------| |------------|
336 : */
337 :
338 : extern "C" void P1SymBuild_StartBuildProcedure (void);
339 :
340 : /*
341 : EndBuildProcedure - Ends building a Procedure.
342 : It checks the start procedure name matches the end
343 : procedure name.
344 :
345 : The Stack:
346 :
347 : (Procedure Not Defined in definition module)
348 :
349 : Entry Exit
350 :
351 : Ptr ->
352 : +------------+
353 : | NameEnd |
354 : |------------|
355 : | ProcSym |
356 : |------------|
357 : | NameStart |
358 : |------------|
359 : Empty
360 : */
361 :
362 : extern "C" void P1SymBuild_EndBuildProcedure (void);
363 :
364 : /*
365 : BuildProcedureHeading - Builds a procedure heading for the definition
366 : module procedures.
367 :
368 : Operation only performed if compiling a
369 : definition module.
370 :
371 : The Stack:
372 :
373 : Entry Exit
374 :
375 : Ptr ->
376 : +------------+
377 : | ProcSym |
378 : |------------|
379 : | NameStart |
380 : |------------|
381 : Empty
382 :
383 : */
384 :
385 : extern "C" void P1SymBuild_BuildProcedureHeading (void);
386 :
387 : /*
388 : EndBuildForward - Ends building a forward procedure declaration.
389 :
390 : The Stack:
391 :
392 : (This procedure is not defined in definition module)
393 :
394 : Entry Exit
395 :
396 : Ptr ->
397 : +------------+
398 : | ProcSym |
399 : |------------|
400 : | NameStart |
401 : |------------|
402 : Empty
403 : */
404 :
405 : extern "C" void P1SymBuild_EndBuildForward (unsigned int forwardPos);
406 :
407 : /*
408 : BuildNulName - Pushes a NulName onto the top of the stack.
409 : The Stack:
410 :
411 :
412 : Entry Exit
413 :
414 : <- Ptr
415 : Empty +------------+
416 : | NulName |
417 : |------------|
418 : */
419 :
420 : extern "C" void P1SymBuild_BuildNulName (void);
421 :
422 : /*
423 : BuildTypeEnd - Pops the type Type and Name.
424 : The Stack:
425 :
426 :
427 : Entry Exit
428 :
429 :
430 : Ptr ->
431 : +-------------+
432 : | Type | Name | Empty
433 : |-------------|
434 : */
435 :
436 : extern "C" void P1SymBuild_BuildTypeEnd (void);
437 :
438 : /*
439 : BuildImportStatement - create a new import statement in the current module.
440 : It ignores local modules.
441 :
442 : The quadruple stack is not used.
443 : */
444 :
445 : extern "C" void P1SymBuild_BuildImportStatement (unsigned int tok);
446 :
447 : /*
448 : AddImportToImportStatement - the top of stack is expected to be a module name.
449 : This is looked up from the module universe and
450 : wrapped in an import symbol and placed into the
451 : current import statement.
452 :
453 : The quadruple stack is unchanged.
454 :
455 : Entry Exit
456 :
457 :
458 : Ptr -> <- Ptr
459 : +---------------------+ +---------------------+
460 : | ImportedModuleName | | ImportedModuleName |
461 : |---------------------| |---------------------|
462 : */
463 :
464 : extern "C" void P1SymBuild_AddImportToImportStatement (bool qualified);
465 :
466 166133 : extern "C" void P1SymBuild_P1StartBuildDefinitionModule (void)
467 : {
468 166133 : NameKey_Name name;
469 166133 : unsigned int language;
470 166133 : unsigned int ModuleSym;
471 :
472 : /*
473 : StartBuildDefinitionModule - Creates a definition module and starts
474 : a new scope.
475 :
476 : he Stack is expected:
477 :
478 : Entry Exit
479 :
480 : Ptr ->
481 : +------------+
482 : | NameStart | <- Ptr
483 : |------------| +------------+
484 : | NulName/"C"| | NameStart |
485 : |------------| |------------|
486 : */
487 166133 : importStatementCount = 0;
488 166133 : M2Quads_PopT (&name);
489 : /* CheckFileName(name, 'definition') ; */
490 166133 : ModuleSym = M2Batch_MakeDefinitionSource (M2LexBuf_GetTokenNo (), name);
491 166133 : SymbolTable_PutDoesNotNeedExportList (ModuleSym);
492 166133 : SymbolTable_SetCurrentModule (ModuleSym);
493 166133 : SymbolTable_SetFileModule (ModuleSym);
494 166133 : SymbolTable_StartScope (ModuleSym);
495 166133 : M2Debug_Assert (SymbolTable_IsDefImp (ModuleSym));
496 166133 : M2Debug_Assert (M2Comp_CompilingDefinitionModule ());
497 166133 : M2Quads_PopT (&language);
498 166133 : if ((language != SymbolTable_NulSym) && (SymbolTable_IsConstString (language)))
499 : {
500 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
501 13434 : if ((SymbolTable_GetSymName (language)) == (NameKey_MakeKey ((const char *) "C", 1)))
502 : {
503 13434 : SymbolTable_PutDefinitionForC (ModuleSym);
504 : }
505 0 : else if ((SymbolTable_GetSymName (language)) == NameKey_NulName)
506 : {
507 : /* avoid dangling else. */
508 0 : M2MetaError_MetaError0 ((const char *) "{%E}currently a non modula-2 definition module can only be declared as DEFINITION FOR {%k\"C\"}", 93);
509 : }
510 : else
511 : {
512 : /* avoid dangling else. */
513 0 : M2MetaError_MetaError1 ((const char *) "unknown definition module language {%1Ea}, currently a non modula-2 definition module can only be declared as DEFINITION FOR {%k\"C\"}", 132, language);
514 : }
515 : }
516 166133 : M2Quads_PushT (name);
517 166133 : P0SymBuild_EnterBlock (name);
518 166133 : }
519 :
520 166133 : extern "C" void P1SymBuild_P1EndBuildDefinitionModule (void)
521 : {
522 166133 : unsigned int start;
523 166133 : NameKey_Name NameStart;
524 166133 : NameKey_Name NameEnd;
525 :
526 : /*
527 : EndBuildDefinitionModule - Destroys the definition module scope and
528 : checks for correct name.
529 :
530 : The Stack is expected:
531 :
532 : Entry Exit
533 :
534 : Ptr ->
535 : +------------+ +-----------+
536 : | NameEnd | | |
537 : |------------| |-----------|
538 : | NameStart | | | <- Ptr
539 : |------------| |-----------|
540 : */
541 166133 : M2Debug_Assert (M2Comp_CompilingDefinitionModule ());
542 166133 : SymbolTable_EndScope ();
543 166133 : M2Quads_PopTtok (&NameStart, &start);
544 166133 : M2Quads_PopT (&NameEnd);
545 166133 : if (Debugging)
546 : {
547 : M2Printf_printf0 ((const char *) "pass 1: ", 8);
548 : SymbolTable_DisplayTrees (SymbolTable_GetCurrentModule ());
549 : }
550 166133 : if (NameStart != NameEnd)
551 : {
552 0 : M2MetaError_MetaError1 ((const char *) "inconsistent definition module name {%1Wa}", 42, SymbolTable_MakeError (start, NameStart));
553 : }
554 166133 : P0SymBuild_LeaveBlock ();
555 166133 : }
556 :
557 72788 : extern "C" void P1SymBuild_P1StartBuildImplementationModule (void)
558 : {
559 72788 : unsigned int tok;
560 72788 : NameKey_Name name;
561 72788 : unsigned int ModuleSym;
562 :
563 : /*
564 : StartBuildImplementationModule - Creates an implementation module and starts
565 : a new scope.
566 :
567 : The Stack is expected:
568 :
569 : Entry Exit
570 :
571 : Ptr -> <- Ptr
572 : +------------+ +-----------+
573 : | NameStart | | NameStart |
574 : |------------| |-----------|
575 :
576 : */
577 72788 : importStatementCount = 0;
578 72788 : M2Quads_PopTtok (&name, &tok);
579 : /* CheckFileName(name, 'implementation') ; */
580 72788 : ModuleSym = M2Batch_MakeImplementationSource (tok, name);
581 72788 : SymbolTable_SetCurrentModule (ModuleSym);
582 72788 : SymbolTable_SetFileModule (ModuleSym);
583 72788 : SymbolTable_StartScope (ModuleSym);
584 72788 : if (! (SymbolTable_IsDefImp (ModuleSym)))
585 : {
586 0 : M2MetaError_MetaError1 ((const char *) "cannot find corresponding definition module for {%1Ea}", 54, ModuleSym);
587 : }
588 72788 : M2Debug_Assert (M2Comp_CompilingImplementationModule ());
589 72788 : M2Quads_PushTtok (name, tok);
590 72788 : P0SymBuild_EnterBlock (name);
591 72788 : }
592 :
593 72788 : extern "C" void P1SymBuild_P1EndBuildImplementationModule (void)
594 : {
595 72788 : unsigned int start;
596 72788 : unsigned int end;
597 72788 : NameKey_Name NameStart;
598 72788 : NameKey_Name NameEnd;
599 :
600 : /*
601 : EndBuildImplementationModule - Destroys the implementation module scope and
602 : checks for correct name.
603 :
604 : The Stack is expected:
605 :
606 : Entry Exit
607 :
608 : Ptr ->
609 : +------------+ +-----------+
610 : | NameEnd | | |
611 : |------------| |-----------|
612 : | NameStart | | | <- Ptr
613 : |------------| |-----------|
614 : */
615 72788 : SymbolTable_ResolveImports ();
616 72788 : M2Debug_Assert (M2Comp_CompilingImplementationModule ());
617 72788 : SymbolTable_EndScope ();
618 72788 : M2Quads_PopTtok (&NameStart, &start);
619 72788 : M2Quads_PopTtok (&NameEnd, &end);
620 72788 : if (NameStart != NameEnd)
621 : {
622 0 : M2MetaError_MetaErrorT1 (end, (const char *) "inconsistent implementation module name {%1Wa}", 46, SymbolTable_MakeError (start, NameStart));
623 : }
624 72788 : P0SymBuild_LeaveBlock ();
625 72788 : }
626 :
627 11909 : extern "C" void P1SymBuild_P1StartBuildProgramModule (void)
628 : {
629 11909 : unsigned int tok;
630 11909 : NameKey_Name name;
631 11909 : unsigned int ModuleSym;
632 :
633 : /*
634 : StartBuildProgramModule - Creates a program module and starts
635 : a new scope.
636 :
637 : The Stack is expected:
638 :
639 : Entry Exit
640 :
641 : Ptr -> <- Ptr
642 : +------------+ +-----------+
643 : | NameStart | | NameStart |
644 : |------------| |-----------|
645 :
646 : */
647 11909 : importStatementCount = 0;
648 11909 : M2Quads_PopTtok (&name, &tok);
649 : /* CheckFileName(name, 'main') ; */
650 11909 : ModuleSym = M2Batch_MakeProgramSource (tok, name);
651 11909 : SymbolTable_SetCurrentModule (ModuleSym);
652 11909 : SymbolTable_SetFileModule (ModuleSym);
653 11909 : SymbolTable_StartScope (ModuleSym);
654 11909 : if ((! (M2Comp_CompilingProgramModule ())) || (SymbolTable_IsDefImp (ModuleSym)))
655 : {
656 6 : M2MetaError_MetaErrorT1 (tok, (const char *) "module {%1Ea} has a corresponding DEFINITION MODULE but no IMPLEMENTATION keyword in the main module", 100, ModuleSym);
657 : }
658 11909 : M2Quads_PushTtok (name, tok);
659 11909 : P0SymBuild_EnterBlock (name);
660 11909 : }
661 :
662 11909 : extern "C" void P1SymBuild_P1EndBuildProgramModule (void)
663 : {
664 11909 : unsigned int start;
665 11909 : unsigned int end;
666 11909 : NameKey_Name NameStart;
667 11909 : NameKey_Name NameEnd;
668 :
669 : /*
670 : EndBuildProgramModule - Destroys the program module scope and
671 : checks for correct name.
672 :
673 : The Stack is expected:
674 :
675 : Entry Exit
676 :
677 : Ptr ->
678 : +------------+ +-----------+
679 : | NameEnd | | |
680 : |------------| |-----------|
681 : | NameStart | | | <- Ptr
682 : |------------| |-----------|
683 : */
684 11909 : SymbolTable_ResolveImports ();
685 11909 : M2Debug_Assert (M2Comp_CompilingProgramModule ());
686 11903 : SymbolTable_EndScope ();
687 11903 : M2Quads_PopTtok (&NameStart, &start);
688 11903 : M2Quads_PopTtok (&NameEnd, &end);
689 11903 : if (Debugging)
690 : {
691 : M2Printf_printf0 ((const char *) "pass 1: ", 8);
692 : SymbolTable_DisplayTrees (SymbolTable_GetCurrentModule ());
693 : }
694 11903 : if (NameStart != NameEnd)
695 : {
696 0 : M2MetaError_MetaErrorT1 (end, (const char *) "inconsistent program module name {%1Wa}", 39, SymbolTable_MakeError (start, NameStart));
697 : }
698 11903 : P0SymBuild_LeaveBlock ();
699 11903 : }
700 :
701 :
702 : /*
703 : StartBuildInnerModule - Creates an Inner module and starts
704 : a new scope.
705 :
706 : The Stack is expected:
707 :
708 : Entry Exit
709 :
710 : Ptr -> <- Ptr
711 : +------------+ +-----------+
712 : | NameStart | | NameStart |
713 : |------------| |-----------|
714 :
715 : */
716 :
717 446 : extern "C" void P1SymBuild_StartBuildInnerModule (void)
718 : {
719 446 : unsigned int tok;
720 446 : NameKey_Name name;
721 446 : unsigned int ModuleSym;
722 :
723 446 : M2Quads_PopTtok (&name, &tok);
724 446 : ModuleSym = SymbolTable_GetSym (name);
725 446 : M2Debug_Assert (ModuleSym != SymbolTable_NulSym);
726 446 : SymbolTable_StartScope (ModuleSym);
727 446 : M2Debug_Assert (! (SymbolTable_IsDefImp (ModuleSym)));
728 446 : M2Quads_PushTtok (name, tok);
729 446 : P0SymBuild_EnterBlock (name);
730 446 : }
731 :
732 :
733 : /*
734 : EndBuildInnerModule - Destroys the Inner module scope and
735 : checks for correct name.
736 :
737 : The Stack is expected:
738 :
739 : Entry Exit
740 :
741 : Ptr ->
742 : +------------+ +-----------+
743 : | NameEnd | | |
744 : |------------| |-----------|
745 : | NameStart | | | <- Ptr
746 : |------------| |-----------|
747 : */
748 :
749 446 : extern "C" void P1SymBuild_EndBuildInnerModule (void)
750 : {
751 446 : unsigned int start;
752 446 : unsigned int end;
753 446 : NameKey_Name NameStart;
754 446 : NameKey_Name NameEnd;
755 :
756 446 : SymbolTable_EndScope ();
757 446 : M2Quads_PopTtok (&NameStart, &start);
758 446 : M2Quads_PopTtok (&NameEnd, &end);
759 446 : if (NameStart != NameEnd)
760 : {
761 0 : M2MetaError_MetaErrorT1 (end, (const char *) "inconsistent inner module name {%1Wa}", 37, SymbolTable_MakeError (start, NameStart));
762 : }
763 446 : P0SymBuild_LeaveBlock ();
764 446 : }
765 :
766 :
767 : /*
768 : BuildImportOuterModule - Builds imported identifiers into an outer module
769 : from a definition module.
770 :
771 : The Stack is expected:
772 :
773 : Entry OR Entry
774 :
775 : Ptr -> Ptr ->
776 : +------------+ +-----------+
777 : | # | | # |
778 : |------------| |-----------|
779 : | Id1 | | Id1 |
780 : |------------| |-----------|
781 : . . . .
782 : . . . .
783 : . . . .
784 : |------------| |-----------|
785 : | Id# | | Id# |
786 : |------------| |-----------|
787 : | ImportTok | | Ident |
788 : |------------| |-----------|
789 :
790 : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
791 :
792 :
793 : Exit
794 :
795 : All above stack discarded
796 : */
797 :
798 410873 : extern "C" void P1SymBuild_BuildImportOuterModule (bool definition)
799 : {
800 410873 : unsigned int Sym;
801 410873 : unsigned int ModSym;
802 410873 : unsigned int i;
803 410873 : unsigned int n;
804 :
805 410873 : M2Quads_PopT (&n); /* n = # of the Ident List */
806 410873 : if ((M2Quads_OperandT (n+1)) == M2Reserved_ImportTok)
807 : {
808 : /* Ident list contains Module Names */
809 : i = 1;
810 116162 : while (i <= n)
811 : {
812 65747 : ModSym = M2Batch_LookupModule (M2Quads_OperandTok ((n+1)-i), M2Quads_OperandT ((n+1)-i));
813 65747 : SymbolTable_PutImported (ModSym);
814 65747 : if (definition)
815 : {
816 10189 : SymbolTable_PutIncludedByDefinition (ModSym);
817 : }
818 65747 : i += 1;
819 : }
820 : }
821 : else
822 : {
823 : /* Ident List contains list of objects */
824 360458 : ModSym = M2Batch_LookupModule (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
825 360458 : i = 1;
826 1589918 : while (i <= n)
827 : {
828 869002 : Sym = SymbolTable_GetExported (M2Quads_OperandTok ((n+1)-i), ModSym, M2Quads_OperandT ((n+1)-i));
829 869002 : SymbolTable_PutImported (Sym);
830 869002 : i += 1;
831 : }
832 : }
833 410873 : M2Quads_PopN (n+1); /* clear stack */
834 410873 : }
835 :
836 :
837 : /*
838 : BuildExportOuterModule - Builds exported identifiers from an outer module
839 : to the outside world of library modules.
840 :
841 : The Stack is expected:
842 :
843 : Entry OR Entry
844 :
845 : Ptr -> Ptr ->
846 : +------------+ +--------------+
847 : | # | | # |
848 : |------------| |--------------|
849 : | Id1 | | Id1 |
850 : |------------| |--------------|
851 : . . . .
852 : . . . .
853 : . . . .
854 : |------------| |--------------|
855 : | Id# | | Id# |
856 : |------------| |--------------|
857 : | ExportTok | | QualifiedTok |
858 : |------------| |--------------|
859 :
860 : EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
861 :
862 : Error Condition
863 :
864 :
865 : Exit
866 :
867 : All above stack discarded
868 : */
869 :
870 87755 : extern "C" void P1SymBuild_BuildExportOuterModule (void)
871 : {
872 87755 : unsigned int i;
873 87755 : unsigned int n;
874 :
875 87755 : M2Quads_PopT (&n); /* n = # of the Ident List */
876 87755 : if (((M2Quads_OperandT (n+1)) == M2Reserved_QualifiedTok) && (M2Comp_CompilingDefinitionModule ())) /* n = # of the Ident List */
877 : {
878 75873 : SymbolTable_PutDoesNeedExportList (SymbolTable_GetCurrentModule ());
879 : /* Ident List contains list of export qualified objects */
880 75873 : i = 1;
881 1734197 : while (i <= n)
882 : {
883 1582451 : SymbolTable_PutExportQualified (M2Quads_OperandTok (i), M2Quads_OperandT (i));
884 1582451 : i += 1;
885 : }
886 : }
887 11882 : else if (((M2Quads_OperandT (n+1)) == M2Reserved_UnQualifiedTok) && (M2Comp_CompilingDefinitionModule ()))
888 : {
889 : /* avoid dangling else. */
890 11882 : SymbolTable_PutDoesNeedExportList (SymbolTable_GetCurrentModule ());
891 : /* Ident List contains list of export unqualified objects */
892 11882 : i = 1;
893 860424 : while (i <= n)
894 : {
895 836660 : SymbolTable_PutExportUnQualified (M2Quads_OperandTok (i), M2Quads_OperandT (i));
896 836660 : i += 1;
897 : }
898 : }
899 0 : else if (M2Comp_CompilingDefinitionModule ())
900 : {
901 : /* avoid dangling else. */
902 0 : M2MetaError_MetaError0 ((const char *) "the {%EkEXPORT} must be either {%kQUALIFIED} or {%kUNQUALIFIED} in a definition module", 86);
903 : }
904 : else
905 : {
906 : /* avoid dangling else. */
907 0 : M2MetaError_MetaError0 ((const char *) "{%E}only allowed inter module exports in a definition module", 60);
908 : }
909 87755 : M2Quads_PopN (n+1); /* clear stack */
910 87755 : }
911 :
912 :
913 : /*
914 : CheckExplicitExported - checks to see whether we are compiling
915 : a definition module and whether the ident
916 : is implicitly export qualified or unqualified.
917 :
918 :
919 : The Stack is expected:
920 :
921 : Entry Exit
922 :
923 : Ptr -> Ptr ->
924 : +------------+ +-----------+
925 : | Identname | | Identname |
926 : |------------| |-----------|
927 :
928 : */
929 :
930 7966423 : extern "C" void P1SymBuild_CheckExplicitExported (void)
931 : {
932 7966423 : if ((M2Comp_CompilingDefinitionModule ()) && (SymbolTable_DoesNotNeedExportList (SymbolTable_GetCurrentModule ())))
933 : {
934 : /* printf1('exporting identifier %a
935 : ', OperandT(1)) ; */
936 2184752 : SymbolTable_PutExportQualified (M2Quads_OperandTok (1), M2Quads_OperandT (1));
937 : }
938 7966423 : }
939 :
940 :
941 : /*
942 : BuildImportInnerModule - Builds imported identifiers into an inner module
943 : from the last level of module.
944 :
945 : The Stack is expected:
946 :
947 : Entry OR Entry
948 :
949 : Ptr -> Ptr ->
950 : +------------+ +-----------+
951 : | # | | # |
952 : |------------| |-----------|
953 : | Id1 | | Id1 |
954 : |------------| |-----------|
955 : . . . .
956 : . . . .
957 : . . . .
958 : |------------| |-----------|
959 : | Id# | | Id# |
960 : |------------| |-----------|
961 : | ImportTok | | Ident |
962 : |------------| |-----------|
963 :
964 : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
965 :
966 : Exit
967 :
968 : All above stack discarded
969 : */
970 :
971 248 : extern "C" void P1SymBuild_BuildImportInnerModule (void)
972 : {
973 248 : unsigned int Sym;
974 248 : unsigned int ModSym;
975 248 : unsigned int OuterMod;
976 248 : unsigned int i;
977 248 : unsigned int n;
978 :
979 248 : M2Quads_PopT (&n); /* n = # of the Ident List */
980 248 : if ((M2Quads_OperandT (n+1)) == M2Reserved_ImportTok) /* n = # of the Ident List */
981 : {
982 182 : OuterMod = SymbolTable_GetScope (SymbolTable_GetCurrentModuleScope ());
983 : /* Ident List contains list of objects. */
984 182 : i = 1;
985 552 : while (i <= n)
986 : {
987 188 : SymbolTable_AddNameToImportList (M2Quads_OperandTok (i), M2Quads_OperandT (i));
988 188 : M2Debug_Assert (OuterMod != SymbolTable_NulSym);
989 188 : ModSym = SymbolTable_GetLocalSym (OuterMod, M2Quads_OperandT (i));
990 188 : if ((ModSym != SymbolTable_NulSym) && ((SymbolTable_IsDefImp (ModSym)) || (SymbolTable_IsModule (ModSym))))
991 : {
992 12 : SymbolTable_PutImported (ModSym);
993 : }
994 188 : i += 1;
995 : }
996 : }
997 : else
998 : {
999 : /* Ident List contains list of objects. */
1000 66 : ModSym = M2Batch_LookupOuterModule (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
1001 66 : i = 1;
1002 198 : while (i <= n)
1003 : {
1004 66 : Sym = SymbolTable_GetExported (M2Quads_OperandTok ((n+1)-i), ModSym, M2Quads_OperandT ((n+1)-i));
1005 66 : SymbolTable_PutImported (Sym);
1006 66 : i += 1;
1007 : }
1008 : }
1009 248 : M2Quads_PopN (n+1); /* clear stack */
1010 248 : }
1011 :
1012 :
1013 : /*
1014 : BuildExportInnerModule - Builds exported identifiers from an inner module
1015 : to the next layer module.
1016 :
1017 : The Stack is expected:
1018 :
1019 : Entry OR Entry
1020 :
1021 : Ptr -> Ptr ->
1022 : +------------+ +--------------+
1023 : | # | | # |
1024 : |------------| |--------------|
1025 : | Id1 | | Id1 |
1026 : |------------| |--------------|
1027 : . . . .
1028 : . . . .
1029 : . . . .
1030 : |------------| |--------------|
1031 : | Id# | | Id# |
1032 : |------------| |--------------|
1033 : | ExportTok | | QualifiedTok |
1034 : |------------| |--------------|
1035 :
1036 : EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
1037 :
1038 :
1039 : Exit
1040 :
1041 :
1042 : All above stack discarded
1043 : */
1044 :
1045 282 : extern "C" void P1SymBuild_BuildExportInnerModule (void)
1046 : {
1047 282 : unsigned int tok;
1048 282 : unsigned int PrevMod;
1049 282 : unsigned int Sym;
1050 282 : unsigned int i;
1051 282 : unsigned int n;
1052 :
1053 282 : M2Quads_PopT (&n); /* n = # of the Ident List */
1054 282 : if ((M2Quads_OperandT (n+1)) == M2Reserved_ExportTok)
1055 : {
1056 : /* Ident List contains list of objects */
1057 282 : i = 1;
1058 282 : PrevMod = SymbolTable_GetScope (SymbolTable_GetCurrentScope ());
1059 870 : while (i <= n)
1060 : {
1061 306 : tok = static_cast<unsigned int> (M2Quads_OperandTok (i));
1062 306 : if ((PrevMod != SymbolTable_NulSym) && ((SymbolTable_IsModule (PrevMod)) || (SymbolTable_IsDefImp (PrevMod))))
1063 : {
1064 246 : Sym = SymbolTable_GetLocalSym (PrevMod, M2Quads_OperandT (i));
1065 246 : if (Sym == SymbolTable_NulSym)
1066 : {
1067 : /* avoid dangling else. */
1068 234 : Sym = SymbolTable_TryMoveUndeclaredSymToInnerModule (PrevMod, SymbolTable_GetCurrentScope (), M2Quads_OperandT (i));
1069 234 : if (Sym == SymbolTable_NulSym)
1070 : {
1071 216 : Sym = SymbolTable_RequestSym (tok, M2Quads_OperandT (i));
1072 216 : SymbolTable_PutExported (Sym);
1073 : }
1074 : }
1075 : else
1076 : {
1077 : /* use Sym which has already been created in outer scope */
1078 12 : SymbolTable_AddSymToModuleScope (SymbolTable_GetCurrentScope (), Sym);
1079 : }
1080 : }
1081 : else
1082 : {
1083 60 : Sym = SymbolTable_RequestSym (tok, M2Quads_OperandT (i));
1084 60 : SymbolTable_PutExported (Sym);
1085 : }
1086 306 : i += 1;
1087 : }
1088 : }
1089 : else
1090 : {
1091 0 : M2MetaError_MetaError0 ((const char *) "{%EkQUALIFIED} not allowed in an inner module", 45);
1092 : }
1093 282 : M2Quads_PopN (n+1); /* clear stack */
1094 282 : }
1095 :
1096 :
1097 : /*
1098 : StartBuildEnumeration - Builds an Enumeration type Type.
1099 :
1100 :
1101 : Stack
1102 :
1103 : Entry Exit
1104 :
1105 : Ptr ->
1106 : +------------+
1107 : | # |
1108 : |------------|
1109 : | en 1 |
1110 : |------------|
1111 : | en 2 |
1112 : |------------|
1113 : . .
1114 : . .
1115 : . . <- Ptr
1116 : |------------| +------------+
1117 : | en # | | Type |
1118 : |------------| |------------|
1119 : | Name | | Name |
1120 : |------------| |------------|
1121 : */
1122 :
1123 34916 : extern "C" void P1SymBuild_StartBuildEnumeration (void)
1124 : {
1125 34916 : NameKey_Name name;
1126 34916 : unsigned int n;
1127 34916 : unsigned int i;
1128 34916 : unsigned int Type;
1129 34916 : unsigned int tokno;
1130 :
1131 34916 : M2Quads_PopT (&n); /* No := # */
1132 34916 : name = static_cast<NameKey_Name> (M2Quads_OperandT (n+1)); /* No := # */
1133 34916 : tokno = static_cast<unsigned int> (M2Quads_OperandTok (n+1));
1134 34916 : Type = SymbolTable_MakeEnumeration (tokno, name);
1135 34916 : i = 1;
1136 543898 : while (i <= n)
1137 : {
1138 474066 : SymbolTable_PutFieldEnumeration (M2Quads_OperandTok ((n-i)+1), Type, M2Quads_OperandT ((n-i)+1));
1139 474066 : i += 1;
1140 : }
1141 34916 : FifoQueue_PutEnumerationIntoFifoQueue (Type); /* store enumeration away for pass 2 */
1142 34916 : M2Quads_PopN (n+1); /* store enumeration away for pass 2 */
1143 34916 : M2Quads_PushTtok (name, tokno);
1144 34916 : M2Quads_PushTtok (Type, tokno);
1145 34916 : }
1146 :
1147 :
1148 : /*
1149 : EndBuildEnumeration - completes the construction of the enumeration type.
1150 :
1151 :
1152 : Stack
1153 :
1154 : Entry Exit
1155 :
1156 : Ptr ->
1157 : +------------+
1158 : | Type | <- Ptr
1159 : |------------| +---------------+
1160 : | Name | | Type | Name |
1161 : |------------| |---------------|
1162 :
1163 : Empty
1164 : */
1165 :
1166 34916 : extern "C" void P1SymBuild_EndBuildEnumeration (void)
1167 : {
1168 34916 : unsigned int tokno;
1169 34916 : unsigned int Sym;
1170 34916 : unsigned int Type;
1171 34916 : NameKey_Name n1;
1172 34916 : NameKey_Name n2;
1173 34916 : NameKey_Name name;
1174 :
1175 : /*
1176 : Two cases
1177 :
1178 : - the type name the same as Name, or the name is nul. - do nothing.
1179 : - when type with a name that is different to Name. In which case
1180 : we create a new type.
1181 : */
1182 34916 : M2Quads_PopTtok (&Type, &tokno);
1183 34916 : M2Quads_PopT (&name);
1184 34916 : if (Debugging)
1185 : {
1186 : n1 = SymbolTable_GetSymName (SymbolTable_GetCurrentModule ());
1187 : M2Printf_printf2 ((const char *) "inside module %a declaring type name %a\\n", 41, (const unsigned char *) &n1, (sizeof (n1)-1), (const unsigned char *) &name, (sizeof (name)-1));
1188 : if (! (SymbolTable_IsUnknown (Type)))
1189 : {
1190 : n1 = SymbolTable_GetSymName (SymbolTable_GetScope (Type));
1191 : n2 = SymbolTable_GetSymName (Type);
1192 : M2Printf_printf2 ((const char *) "type was created inside scope %a as name %a\\n", 45, (const unsigned char *) &n1, (sizeof (n1)-1), (const unsigned char *) &n2, (sizeof (n2)-1));
1193 : }
1194 : }
1195 34916 : if ((name == NameKey_NulName) || ((SymbolTable_GetSymName (Type)) == name))
1196 : {
1197 : /*
1198 : Typically the declaration that causes this case is:
1199 :
1200 : VAR
1201 : a: (blue, green, red) ;
1202 : ^
1203 : |
1204 : +---- type has no name.
1205 :
1206 : in which case the constructed from StartBuildEnumeration is complete
1207 : */
1208 34916 : M2Quads_PushTFtok (Type, name, tokno);
1209 : }
1210 : else
1211 : {
1212 : /* in this case we are seeing:
1213 :
1214 : TYPE
1215 : name = (blue, green, red)
1216 :
1217 : so we construct the type name and define it to have the previously
1218 : created enumeration type
1219 : */
1220 0 : Sym = SymbolTable_MakeType (tokno, name);
1221 0 : SymbolTable_PutType (Sym, Type);
1222 0 : M2Quads_PushTFtok (Sym, name, tokno);
1223 : }
1224 34916 : }
1225 :
1226 :
1227 : /*
1228 : BuildHiddenType - Builds a Hidden Type.
1229 :
1230 :
1231 : Stack
1232 :
1233 : Entry Exit
1234 :
1235 : Ptr ->
1236 : +------------+
1237 : | Name | <- Ptr
1238 : |------------| Empty
1239 : */
1240 :
1241 29335 : extern "C" void P1SymBuild_BuildHiddenType (void)
1242 : {
1243 29335 : NameKey_Name name;
1244 29335 : unsigned int tokno;
1245 :
1246 29335 : M2Quads_PopTtok (&name, &tokno);
1247 : /* WriteKey(Name) ; WriteLn ; */
1248 29335 : M2Debug_Assert ((SymbolTable_MakeHiddenType (tokno, name)) != SymbolTable_NulSym);
1249 29335 : }
1250 :
1251 :
1252 : /*
1253 : StartBuildProcedure - Builds a Procedure.
1254 :
1255 : The Stack:
1256 :
1257 : Entry Exit
1258 :
1259 : Ptr -> <- Ptr
1260 : +------------+ +------------+
1261 : | Name | | ProcSym |
1262 : |------------| |------------|
1263 : | inlinetok | | |
1264 : | or | | |
1265 : | builtintok | | |
1266 : | or name or | | Name |
1267 : | NulTok | | |
1268 : |------------| |------------|
1269 : */
1270 :
1271 5303393 : extern "C" void P1SymBuild_StartBuildProcedure (void)
1272 : {
1273 5303393 : unsigned int tokno;
1274 5303393 : NameKey_Name builtin;
1275 5303393 : NameKey_Name name;
1276 5303393 : unsigned int ProcSym;
1277 :
1278 5303393 : M2Quads_PopTtok (&name, &tokno);
1279 5303393 : M2Quads_PopT (&builtin); /* was this procedure defined as a builtin? */
1280 5303393 : M2Quads_PushTtok (name, tokno); /* Name saved for the EndBuildProcedure name check */
1281 5303393 : ProcSym = SymbolTable_RequestSym (tokno, name); /* Name saved for the EndBuildProcedure name check */
1282 5303393 : if (SymbolTable_IsUnknown (ProcSym))
1283 : {
1284 : /* A procedure may be created in a definition or implementation module, remember
1285 : that an implementation module maybe compiled before the corresponding
1286 : definition module.
1287 :
1288 : The procedure can also be created during a forward declaration.
1289 : We record the forward declaration as the token of creation and adjust this
1290 : later when we see the proper procedure declaration. Likwwise when the forward
1291 : keyword is seen we assign the procedure forward token location. */
1292 4015286 : ProcSym = SymbolTable_MakeProcedure (tokno, name);
1293 : }
1294 1288107 : else if (SymbolTable_IsProcedure (ProcSym))
1295 : {
1296 : /* avoid dangling else. */
1297 : /* Declared in the other module or it could have been declared by a forward decl,
1298 : we overwrite the declaration to tokno. The forward location is assigned in
1299 : EndBuildForward. */
1300 1288107 : SymbolTable_PutDeclared (tokno, ProcSym);
1301 : }
1302 : else
1303 : {
1304 : /* avoid dangling else. */
1305 0 : M2MetaError_MetaError1 ((const char *) "expecting a procedure name and symbol {%1Ea} has been declared as a {%1dv}", 74, ProcSym);
1306 0 : M2Quads_PushT (ProcSym);
1307 0 : return;
1308 : }
1309 5303393 : if (builtin != M2Reserved_NulTok)
1310 : {
1311 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
1312 877990 : if (builtin == M2Reserved_BuiltinTok)
1313 : {
1314 425318 : SymbolTable_PutProcedureBuiltin (ProcSym, name);
1315 : }
1316 452672 : else if (builtin == M2Reserved_InlineTok)
1317 : {
1318 : /* avoid dangling else. */
1319 0 : SymbolTable_PutProcedureInline (ProcSym);
1320 : }
1321 : else
1322 : {
1323 : /* avoid dangling else. */
1324 452672 : SymbolTable_PutProcedureBuiltin (ProcSym, builtin);
1325 : }
1326 : }
1327 5303393 : M2Quads_PushTtok (ProcSym, tokno);
1328 5303393 : SymbolTable_StartScope (ProcSym);
1329 5303393 : if (M2Comp_CompilingDefinitionModule ())
1330 : {
1331 3356378 : if (SymbolTable_GetProcedureDefined (ProcSym, SymbolTable_DefProcedure))
1332 : {
1333 6 : M2MetaError_MetaErrorT1 (SymbolTable_GetProcedureDeclaredTok (ProcSym, SymbolTable_DefProcedure), (const char *) "first declaration of procedure {%1Ea} in the definition module", 62, ProcSym);
1334 6 : M2MetaError_MetaErrorT1 (tokno, (const char *) "duplicate declaration of procedure {%1Ea} in the definition module", 66, ProcSym);
1335 : }
1336 : else
1337 : {
1338 3356372 : SymbolTable_PutProcedureDeclaredTok (ProcSym, SymbolTable_DefProcedure, tokno);
1339 3356372 : SymbolTable_PutProcedureDefined (ProcSym, SymbolTable_DefProcedure);
1340 : }
1341 : }
1342 : else
1343 : {
1344 1947015 : P0SymBuild_EnterBlock (name);
1345 : }
1346 : }
1347 :
1348 :
1349 : /*
1350 : EndBuildProcedure - Ends building a Procedure.
1351 : It checks the start procedure name matches the end
1352 : procedure name.
1353 :
1354 : The Stack:
1355 :
1356 : (Procedure Not Defined in definition module)
1357 :
1358 : Entry Exit
1359 :
1360 : Ptr ->
1361 : +------------+
1362 : | NameEnd |
1363 : |------------|
1364 : | ProcSym |
1365 : |------------|
1366 : | NameStart |
1367 : |------------|
1368 : Empty
1369 : */
1370 :
1371 1946955 : extern "C" void P1SymBuild_EndBuildProcedure (void)
1372 : {
1373 1946955 : unsigned int tok;
1374 1946955 : unsigned int start;
1375 1946955 : unsigned int end;
1376 1946955 : unsigned int ProcSym;
1377 1946955 : NameKey_Name NameEnd;
1378 1946955 : NameKey_Name NameStart;
1379 :
1380 1946955 : M2Quads_PopTtok (&NameEnd, &end);
1381 1946955 : M2Quads_PopTtok (&ProcSym, &tok);
1382 1946955 : M2Quads_PopTtok (&NameStart, &start);
1383 1946955 : if (NameEnd != NameStart)
1384 : {
1385 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
1386 0 : if (end != M2LexBuf_UnknownTokenNo)
1387 : {
1388 0 : M2MetaError_MetaErrorT1 (end, (const char *) "procedure name at end does not match name at beginning {%1EDa}", 62, ProcSym);
1389 : }
1390 0 : else if (start != M2LexBuf_UnknownTokenNo)
1391 : {
1392 : /* avoid dangling else. */
1393 0 : M2MetaError_MetaErrorT2 (start, (const char *) "procedure name at end {%1EDa} does not match name at beginning {%2a}", 68, SymbolTable_MakeError (end, NameEnd), ProcSym);
1394 : }
1395 : else
1396 : {
1397 : /* avoid dangling else. */
1398 0 : M2MetaError_MetaError1 ((const char *) "procedure name at end does not match name at beginning {%1EDa}", 62, ProcSym);
1399 : }
1400 : }
1401 1946955 : SymbolTable_EndScope ();
1402 1946955 : if (SymbolTable_GetProcedureDefined (ProcSym, SymbolTable_ProperProcedure))
1403 : {
1404 0 : M2MetaError_MetaErrorT1 (SymbolTable_GetProcedureDeclaredTok (ProcSym, SymbolTable_ProperProcedure), (const char *) "first proper declaration of procedure {%1Ea}", 44, ProcSym);
1405 0 : M2MetaError_MetaErrorT1 (tok, (const char *) "procedure {%1Ea} has already been declared", 42, ProcSym);
1406 : }
1407 : else
1408 : {
1409 1946955 : SymbolTable_PutProcedureDeclaredTok (ProcSym, SymbolTable_ProperProcedure, tok);
1410 1946955 : SymbolTable_PutProcedureDefined (ProcSym, SymbolTable_ProperProcedure);
1411 : }
1412 1946955 : M2Debug_Assert (! (M2Comp_CompilingDefinitionModule ()));
1413 1946955 : P0SymBuild_LeaveBlock ();
1414 1946955 : }
1415 :
1416 :
1417 : /*
1418 : BuildProcedureHeading - Builds a procedure heading for the definition
1419 : module procedures.
1420 :
1421 : Operation only performed if compiling a
1422 : definition module.
1423 :
1424 : The Stack:
1425 :
1426 : Entry Exit
1427 :
1428 : Ptr ->
1429 : +------------+
1430 : | ProcSym |
1431 : |------------|
1432 : | NameStart |
1433 : |------------|
1434 : Empty
1435 :
1436 : */
1437 :
1438 5303393 : extern "C" void P1SymBuild_BuildProcedureHeading (void)
1439 : {
1440 5303393 : unsigned int ProcSym;
1441 5303393 : NameKey_Name NameStart;
1442 :
1443 5303393 : if (M2Comp_CompilingDefinitionModule ())
1444 : {
1445 3356378 : M2Quads_PopT (&ProcSym);
1446 3356378 : M2Quads_PopT (&NameStart);
1447 3356378 : SymbolTable_EndScope ();
1448 : }
1449 5303393 : }
1450 :
1451 :
1452 : /*
1453 : EndBuildForward - Ends building a forward procedure declaration.
1454 :
1455 : The Stack:
1456 :
1457 : (This procedure is not defined in definition module)
1458 :
1459 : Entry Exit
1460 :
1461 : Ptr ->
1462 : +------------+
1463 : | ProcSym |
1464 : |------------|
1465 : | NameStart |
1466 : |------------|
1467 : Empty
1468 : */
1469 :
1470 60 : extern "C" void P1SymBuild_EndBuildForward (unsigned int forwardPos)
1471 : {
1472 60 : unsigned int ProcSym;
1473 60 : unsigned int tok;
1474 :
1475 60 : ProcSym = static_cast<unsigned int> (M2Quads_OperandT (1));
1476 60 : tok = static_cast<unsigned int> (M2Quads_OperandTok (1));
1477 60 : if (! (M2Options_GetEnableForward ()))
1478 : {
1479 0 : M2MetaError_MetaErrorT0 (forwardPos, (const char *) "forward declaration has not been enabled, use -fiso or -fenable-forward to enable forward procedure declarations", 112);
1480 : }
1481 60 : if (SymbolTable_GetProcedureDefined (ProcSym, SymbolTable_ForwardProcedure))
1482 : {
1483 6 : M2MetaError_MetaErrorT1 (SymbolTable_GetProcedureDeclaredTok (ProcSym, SymbolTable_ForwardProcedure), (const char *) "first forward declaration of {%1Ea}", 35, ProcSym);
1484 6 : M2MetaError_MetaErrorT1 (tok, (const char *) "forward declaration of procedure {%1Ea} has already occurred", 60, ProcSym);
1485 : }
1486 : else
1487 : {
1488 54 : SymbolTable_PutProcedureDeclaredTok (ProcSym, SymbolTable_ForwardProcedure, tok);
1489 54 : SymbolTable_PutProcedureDefined (ProcSym, SymbolTable_ForwardProcedure);
1490 : }
1491 60 : M2Quads_PopN (2);
1492 60 : SymbolTable_EndScope ();
1493 60 : M2Debug_Assert (! (M2Comp_CompilingDefinitionModule ()));
1494 60 : P0SymBuild_LeaveBlock ();
1495 60 : }
1496 :
1497 :
1498 : /*
1499 : BuildNulName - Pushes a NulName onto the top of the stack.
1500 : The Stack:
1501 :
1502 :
1503 : Entry Exit
1504 :
1505 : <- Ptr
1506 : Empty +------------+
1507 : | NulName |
1508 : |------------|
1509 : */
1510 :
1511 1721432 : extern "C" void P1SymBuild_BuildNulName (void)
1512 : {
1513 1721432 : M2Quads_PushT (static_cast<unsigned int> (NameKey_NulName));
1514 1721432 : }
1515 :
1516 :
1517 : /*
1518 : BuildTypeEnd - Pops the type Type and Name.
1519 : The Stack:
1520 :
1521 :
1522 : Entry Exit
1523 :
1524 :
1525 : Ptr ->
1526 : +-------------+
1527 : | Type | Name | Empty
1528 : |-------------|
1529 : */
1530 :
1531 0 : extern "C" void P1SymBuild_BuildTypeEnd (void)
1532 : {
1533 0 : unsigned int Type;
1534 0 : NameKey_Name name;
1535 :
1536 0 : M2Quads_PopTF (&Type, &name);
1537 0 : }
1538 :
1539 :
1540 : /*
1541 : BuildImportStatement - create a new import statement in the current module.
1542 : It ignores local modules.
1543 :
1544 : The quadruple stack is not used.
1545 : */
1546 :
1547 411121 : extern "C" void P1SymBuild_BuildImportStatement (unsigned int tok)
1548 : {
1549 411121 : unsigned int scope;
1550 :
1551 411121 : scope = SymbolTable_GetCurrentScope ();
1552 411121 : if ((SymbolTable_IsDefImp (scope)) || ((SymbolTable_IsModule (scope)) && (! (SymbolTable_IsInnerModule (scope)))))
1553 : {
1554 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
1555 410873 : if ((M2Comp_CompilingDefinitionModule ()) && (! (SymbolTable_IsDefImp (scope))))
1556 : {
1557 0 : M2MetaError_MetaError1 ((const char *) "module scope should be a definition module rather than {%1EDa}", 62, scope);
1558 : }
1559 : else
1560 : {
1561 410873 : importStatementCount += 1;
1562 410873 : SymbolTable_AppendModuleImportStatement (scope, SymbolTable_MakeImportStatement (tok, importStatementCount));
1563 : }
1564 : }
1565 411121 : }
1566 :
1567 :
1568 : /*
1569 : AddImportToImportStatement - the top of stack is expected to be a module name.
1570 : This is looked up from the module universe and
1571 : wrapped in an import symbol and placed into the
1572 : current import statement.
1573 :
1574 : The quadruple stack is unchanged.
1575 :
1576 : Entry Exit
1577 :
1578 :
1579 : Ptr -> <- Ptr
1580 : +---------------------+ +---------------------+
1581 : | ImportedModuleName | | ImportedModuleName |
1582 : |---------------------| |---------------------|
1583 : */
1584 :
1585 426459 : extern "C" void P1SymBuild_AddImportToImportStatement (bool qualified)
1586 : {
1587 426459 : unsigned int scope;
1588 :
1589 426459 : scope = SymbolTable_GetCurrentScope ();
1590 426459 : if ((SymbolTable_IsDefImp (scope)) || ((SymbolTable_IsModule (scope)) && (! (SymbolTable_IsInnerModule (scope)))))
1591 : {
1592 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
1593 426205 : if ((M2Comp_CompilingDefinitionModule ()) && (! (SymbolTable_IsDefImp (scope))))
1594 : {
1595 0 : M2MetaError_MetaError1 ((const char *) "module scope should be a definition module rather than {%1EDa}", 62, scope);
1596 : }
1597 : else
1598 : {
1599 426205 : SymbolTable_AppendModuleOnImportStatement (scope, SymbolTable_MakeImport (M2Quads_OperandTok (1), M2Batch_LookupModule (M2Quads_OperandTok (1), M2Quads_OperandT (1)), importStatementCount, qualified));
1600 : }
1601 : }
1602 426459 : }
1603 :
1604 15451 : extern "C" void _M2_P1SymBuild_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
1605 : {
1606 15451 : }
1607 :
1608 0 : extern "C" void _M2_P1SymBuild_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
1609 : {
1610 0 : }
|