Branch data Line data Source code
1 : : /* do not edit automatically generated by mc from P2SymBuild. */
2 : : /* P2SymBuild.mod pass 2 symbol creation.
3 : :
4 : : Copyright (C) 2001-2025 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 (TRUE)
35 : : # define TRUE (1==1)
36 : : # endif
37 : :
38 : : # if !defined (FALSE)
39 : : # define FALSE (1==0)
40 : : # endif
41 : :
42 : : #if defined(__cplusplus)
43 : : # undef NULL
44 : : # define NULL 0
45 : : #endif
46 : : #define _P2SymBuild_C
47 : :
48 : : #include "GP2SymBuild.h"
49 : : # include "Glibc.h"
50 : : # include "GNameKey.h"
51 : : # include "GStrLib.h"
52 : : # include "GM2Debug.h"
53 : : # include "GM2LexBuf.h"
54 : : # include "GM2Error.h"
55 : : # include "GDynamicStrings.h"
56 : : # include "GFormatStrings.h"
57 : : # include "GM2Printf.h"
58 : : # include "GM2StackWord.h"
59 : : # include "GM2Options.h"
60 : : # include "GStrIO.h"
61 : : # include "GM2Base.h"
62 : : # include "GStorage.h"
63 : : # include "Ggcctypes.h"
64 : : # include "GM2Reserved.h"
65 : : # include "GM2MetaError.h"
66 : : # include "GFifoQueue.h"
67 : : # include "GSymbolTable.h"
68 : : # include "GM2Batch.h"
69 : : # include "GM2Quads.h"
70 : : # include "GM2Comp.h"
71 : : # include "GM2Const.h"
72 : : # include "GM2Students.h"
73 : :
74 : : # define Debugging false
75 : : static unsigned int alignTypeNo;
76 : : static unsigned int castType;
77 : : static M2Const_constType type;
78 : : static unsigned int RememberedConstant;
79 : : static M2StackWord_StackOfWord RememberStack;
80 : : static M2StackWord_StackOfWord TypeStack;
81 : : static unsigned int curModuleSym;
82 : : static unsigned int curBeginTok;
83 : : static unsigned int curFinallyTok;
84 : : static unsigned int curStartTok;
85 : : static unsigned int curEndTok;
86 : : static M2StackWord_StackOfWord BlockStack;
87 : :
88 : : /*
89 : : BlockStart - tokno is the module/procedure/implementation/definition token
90 : : */
91 : :
92 : : extern "C" void P2SymBuild_BlockStart (unsigned int tokno);
93 : :
94 : : /*
95 : : BlockEnd - declare module ctor/init/fini/dep procedures.
96 : : */
97 : :
98 : : extern "C" void P2SymBuild_BlockEnd (unsigned int tokno);
99 : :
100 : : /*
101 : : BlockBegin - assign curBeginTok to tokno.
102 : : */
103 : :
104 : : extern "C" void P2SymBuild_BlockBegin (unsigned int tokno);
105 : :
106 : : /*
107 : : BlockFinally - assign curFinallyTok to tokno.
108 : : */
109 : :
110 : : extern "C" void P2SymBuild_BlockFinally (unsigned int tokno);
111 : : extern "C" void P2SymBuild_P2StartBuildDefModule (void);
112 : : extern "C" void P2SymBuild_P2EndBuildDefModule (void);
113 : : extern "C" void P2SymBuild_P2StartBuildImplementationModule (void);
114 : : extern "C" void P2SymBuild_P2EndBuildImplementationModule (void);
115 : : extern "C" void P2SymBuild_P2StartBuildProgramModule (void);
116 : : extern "C" void P2SymBuild_P2EndBuildProgramModule (void);
117 : :
118 : : /*
119 : : StartBuildInnerModule - Creates an Inner module and starts
120 : : a new scope.
121 : :
122 : : The Stack is expected:
123 : :
124 : : Entry Exit
125 : :
126 : : Ptr -> <- Ptr
127 : : +------------+ +-----------+
128 : : | NameStart | | NameStart |
129 : : |------------| |-----------|
130 : :
131 : : */
132 : :
133 : : extern "C" void P2SymBuild_StartBuildInnerModule (void);
134 : :
135 : : /*
136 : : EndBuildInnerModule - Destroys the Inner module scope and
137 : : checks for correct name.
138 : :
139 : : The Stack is expected:
140 : :
141 : : Entry Exit
142 : :
143 : : Ptr ->
144 : : +------------+ +-----------+
145 : : | NameEnd | | |
146 : : |------------| |-----------|
147 : : | NameStart | | | <- Ptr
148 : : |------------| |-----------|
149 : : */
150 : :
151 : : extern "C" void P2SymBuild_EndBuildInnerModule (void);
152 : :
153 : : /*
154 : : BuildImportOuterModule - Builds imported identifiers into an outer module
155 : : from a definition module.
156 : :
157 : : The Stack is expected:
158 : :
159 : : Entry OR Entry
160 : :
161 : : Ptr -> Ptr ->
162 : : +------------+ +-----------+
163 : : | # | | # |
164 : : |------------| |-----------|
165 : : | Id1 | | Id1 |
166 : : |------------| |-----------|
167 : : . . . .
168 : : . . . .
169 : : . . . .
170 : : |------------| |-----------|
171 : : | Id# | | Id# |
172 : : |------------| |-----------|
173 : : | ImportTok | | Ident |
174 : : |------------| |-----------|
175 : :
176 : : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
177 : :
178 : :
179 : : Exit
180 : :
181 : : All above stack discarded
182 : : */
183 : :
184 : : extern "C" void P2SymBuild_BuildImportOuterModule (void);
185 : :
186 : : /*
187 : : BuildExportOuterModule - Builds exported identifiers from an outer module
188 : : to the outside world of library modules.
189 : :
190 : : The Stack is expected:
191 : :
192 : : Entry OR Entry
193 : :
194 : : Ptr -> Ptr ->
195 : : +------------+ +--------------+
196 : : | # | | # |
197 : : |------------| |--------------|
198 : : | Id1 | | Id1 |
199 : : |------------| |--------------|
200 : : . . . .
201 : : . . . .
202 : : . . . .
203 : : |------------| |--------------|
204 : : | Id# | | Id# |
205 : : |------------| |--------------|
206 : : | ExportTok | | QualifiedTok |
207 : : |------------| |--------------|
208 : :
209 : : EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
210 : :
211 : : Error Condition
212 : :
213 : :
214 : : Exit
215 : :
216 : : All above stack discarded
217 : : */
218 : :
219 : : extern "C" void P2SymBuild_BuildExportOuterModule (void);
220 : :
221 : : /*
222 : : BuildImportInnerModule - Builds imported identifiers into an inner module
223 : : from the last level of 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 : : | ImportTok | | Ident |
242 : : |------------| |-----------|
243 : :
244 : : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
245 : :
246 : : Exit
247 : :
248 : : All above stack discarded
249 : : */
250 : :
251 : : extern "C" void P2SymBuild_BuildImportInnerModule (void);
252 : :
253 : : /*
254 : : BuildExportInnerModule - Builds exported identifiers from an inner module
255 : : to the next layer module.
256 : :
257 : : The Stack is expected:
258 : :
259 : : Entry OR Entry
260 : :
261 : : Ptr -> Ptr ->
262 : : +------------+ +--------------+
263 : : | # | | # |
264 : : |------------| |--------------|
265 : : | Id1 | | Id1 |
266 : : |------------| |--------------|
267 : : . . . .
268 : : . . . .
269 : : . . . .
270 : : |------------| |--------------|
271 : : | Id# | | Id# |
272 : : |------------| |--------------|
273 : : | ExportTok | | QualifiedTok |
274 : : |------------| |--------------|
275 : :
276 : : EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
277 : :
278 : :
279 : : Exit
280 : :
281 : : All above stack discarded
282 : : */
283 : :
284 : : extern "C" void P2SymBuild_BuildExportInnerModule (void);
285 : :
286 : : /*
287 : : BuildNumber - Converts a number into a symbol.
288 : :
289 : :
290 : : Stack
291 : :
292 : : Entry Exit
293 : :
294 : : Ptr -> <- Ptr
295 : : +------------+ +-------------------+
296 : : | Name | tok | | Sym | Type | tok |
297 : : |------------+ |-------------------|
298 : : */
299 : :
300 : : extern "C" void P2SymBuild_BuildNumber (void);
301 : :
302 : : /*
303 : : BuildString - Converts a string into a symbol.
304 : :
305 : :
306 : : Stack
307 : :
308 : : Entry Exit
309 : :
310 : : Ptr -> <- Ptr
311 : : +-------------+ +--------------------+
312 : : | Name | | tok| | Sym | NulSym | tok |
313 : : |-------------+ |--------------------|
314 : : */
315 : :
316 : : extern "C" void P2SymBuild_BuildString (void);
317 : :
318 : : /*
319 : : BuildConst - builds a constant.
320 : : Stack
321 : :
322 : : Entry Exit
323 : :
324 : : Ptr ->
325 : : +------------+
326 : : | Name |
327 : : |------------+ <- Ptr
328 : : */
329 : :
330 : : extern "C" void P2SymBuild_BuildConst (void);
331 : :
332 : : /*
333 : : StartBuildEnumeration - Builds an Enumeration type Type.
334 : :
335 : :
336 : : Stack
337 : :
338 : : Entry Exit
339 : :
340 : : Ptr ->
341 : : +------------+
342 : : | # |
343 : : |------------|
344 : : | en 1 |
345 : : |------------|
346 : : | en 2 |
347 : : |------------|
348 : : . .
349 : : . .
350 : : . . <- Ptr
351 : : |------------| +------------+
352 : : | en # | | Type |
353 : : |------------| |------------|
354 : : | Name | | Name |
355 : : |------------| |------------|
356 : : */
357 : :
358 : : extern "C" void P2SymBuild_StartBuildEnumeration (void);
359 : :
360 : : /*
361 : : BuildSubrange - Builds a Subrange type Symbol, the base type can also be
362 : : supplied if known.
363 : :
364 : : Stack
365 : :
366 : : Entry Exit
367 : :
368 : :
369 : : <- Ptr
370 : : +------------+
371 : : Ptr -> | Type |
372 : : +------------+ |------------|
373 : : | Name | | Name |
374 : : |------------| |------------|
375 : : */
376 : :
377 : : extern "C" void P2SymBuild_BuildSubrange (unsigned int tok, unsigned int Base);
378 : :
379 : : /*
380 : : BuildAligned - builds an alignment constant symbol which is placed onto
381 : : the stack. It expects the ident ALIGNED to be on the
382 : : stack.
383 : :
384 : : Stack
385 : :
386 : : Entry Exit
387 : :
388 : :
389 : : Ptr -> <- Ptr
390 : : +---------------+ +-----------------+
391 : : | bytealignment | | AlignmentConst |
392 : : +---------------+ |-----------------|
393 : : */
394 : :
395 : : extern "C" void P2SymBuild_BuildAligned (void);
396 : :
397 : : /*
398 : : BuildVarAlignment - the AlignmentConst is either a temporary or NulSym.
399 : : A type may only have one alignment value and
400 : : error checking is performed.
401 : :
402 : : Stack
403 : :
404 : : Entry Exit
405 : :
406 : :
407 : : Ptr ->
408 : : +-----------------+
409 : : | AlignmentConst | <- Ptr
410 : : |-----------------| +------------------+
411 : : | Type | | Type | TypeName |
412 : : |-----------------| |------------------|
413 : : */
414 : :
415 : : extern "C" void P2SymBuild_BuildVarAlignment (void);
416 : :
417 : : /*
418 : : BuildTypeAlignment - the AlignmentConst is either a temporary or NulSym.
419 : : In the case of NulSym it is popped from the stack
420 : : and the procedure returns. Otherwise the temporary
421 : : is popped and recorded as the alignment value for this
422 : : type. A type may only have one alignment value and
423 : : error checking is performed.
424 : :
425 : : Stack
426 : :
427 : : Entry Exit
428 : :
429 : :
430 : : Ptr ->
431 : : +-----------------+
432 : : | AlignmentConst |
433 : : |-----------------|
434 : : | Type | Empty
435 : : |-----------------|
436 : : */
437 : :
438 : : extern "C" void P2SymBuild_BuildTypeAlignment (void);
439 : : extern "C" void P2SymBuild_P2BuildDefaultFieldAlignment (void);
440 : :
441 : : /*
442 : : BuildPragmaConst - pushes a constant to the stack and stores it away into the
443 : : const fifo queue ready for pass 3.
444 : : */
445 : :
446 : : extern "C" void P2SymBuild_BuildPragmaConst (void);
447 : :
448 : : /*
449 : : BuildVariable - Builds variables listed in an IdentList with a Type.
450 : :
451 : : Stack
452 : :
453 : : Entry Exit
454 : :
455 : : Ptr ->
456 : : +------------+ +------------+
457 : : | Type | Name| | |
458 : : |------------| |------------|
459 : : | # | | |
460 : : |------------| |------------|
461 : : | Ident 1 | | |
462 : : |------------| |------------|
463 : : | Ident 2 | | |
464 : : |------------| |------------|
465 : : . . . .
466 : : . . . .
467 : : . . . .
468 : : |------------| |------------|
469 : : | Ident # | | | <- Ptr
470 : : |------------| |------------|
471 : :
472 : : Empty
473 : : */
474 : :
475 : : extern "C" void P2SymBuild_BuildVariable (void);
476 : :
477 : : /*
478 : : BuildType - Builds a Type.
479 : :
480 : :
481 : : Stack
482 : :
483 : : Entry Exit
484 : :
485 : : Ptr ->
486 : : +------------+
487 : : | Type | <- Ptr
488 : : |------------| +---------------+
489 : : | Name | | Type | Name |
490 : : |------------| |---------------|
491 : :
492 : : Empty
493 : : */
494 : :
495 : : extern "C" void P2SymBuild_BuildType (void);
496 : :
497 : : /*
498 : : StartBuildFormalParameters - Initialises the quadruple stack for
499 : : Formal Parameters.
500 : :
501 : : The Stack:
502 : :
503 : : Entry Exit
504 : :
505 : : <- Ptr
506 : : +------------+
507 : : Empty | 0 |
508 : : |------------|
509 : : */
510 : :
511 : : extern "C" void P2SymBuild_StartBuildFormalParameters (void);
512 : :
513 : : /*
514 : : EndBuildFormalParameters - Resets the quadruple stack after building
515 : : Formal Parameters.
516 : :
517 : : The Stack:
518 : :
519 : : Entry Exit
520 : :
521 : : Ptr ->
522 : : +------------+
523 : : | NoOfParam | <- Ptr
524 : : |------------| +------------+
525 : : | ProcSym | | ProcSym |
526 : : |------------| |------------|
527 : : */
528 : :
529 : : extern "C" void P2SymBuild_EndBuildFormalParameters (void);
530 : :
531 : : /*
532 : : BuildProcedureHeading - Builds a procedure heading for the definition
533 : : module procedures.
534 : :
535 : : Operation only performed if compiling a
536 : : definition module.
537 : :
538 : : The Stack:
539 : :
540 : : Entry Exit
541 : :
542 : : Ptr ->
543 : : +------------+
544 : : | ProcSym |
545 : : |------------|
546 : : | NameStart |
547 : : |------------|
548 : : Empty
549 : :
550 : : */
551 : :
552 : : extern "C" void P2SymBuild_BuildProcedureHeading (void);
553 : :
554 : : /*
555 : : BuildFunction - Builds a procedures return type.
556 : : Procedure becomes a function.
557 : :
558 : : The Stack:
559 : :
560 : : Entry Exit
561 : :
562 : : Ptr ->
563 : : +------------+
564 : : | TypeSym | <- Ptr
565 : : |------------| +------------+
566 : : | ProcSym | | ProcSym |
567 : : |------------| |------------|
568 : : */
569 : :
570 : : extern "C" void P2SymBuild_BuildFunction (void);
571 : :
572 : : /*
573 : : BuildOptFunction - Builds a procedures optional return type.
574 : : Procedure becomes a function and the user
575 : : can either call it as a function or a procedure.
576 : :
577 : : The Stack:
578 : :
579 : : Entry Exit
580 : :
581 : : Ptr ->
582 : : +------------+
583 : : | TypeSym | <- Ptr
584 : : |------------| +------------+
585 : : | ProcSym | | ProcSym |
586 : : |------------| |------------|
587 : : */
588 : :
589 : : extern "C" void P2SymBuild_BuildOptFunction (void);
590 : :
591 : : /*
592 : : BuildFPSection - Builds a Formal Parameter in a procedure.
593 : :
594 : : The Stack:
595 : :
596 : : Entry Exit
597 : :
598 : : Ptr ->
599 : : +------------+
600 : : | ParamTotal |
601 : : |------------|
602 : : | TypeSym |
603 : : |------------|
604 : : | Array/Nul |
605 : : |------------|
606 : : | NoOfIds |
607 : : |------------|
608 : : | Id 1 |
609 : : |------------|
610 : : . .
611 : : . .
612 : : . .
613 : : |------------|
614 : : | Id n | <- Ptr
615 : : |------------| +------------+
616 : : | Var / Nul | | ParamTotal |
617 : : |------------| |------------|
618 : : | ProcSym | | ProcSym |
619 : : |------------| |------------|
620 : : */
621 : :
622 : : extern "C" void P2SymBuild_BuildFPSection (void);
623 : :
624 : : /*
625 : : BuildVarArgs - indicates that the ProcSym takes varargs
626 : : after ParamTotal.
627 : : <- Ptr
628 : : +------------+ +------------+
629 : : | ParamTotal | | ParamTotal |
630 : : |------------| |------------|
631 : : | ProcSym | | ProcSym |
632 : : |------------| |------------|
633 : :
634 : : */
635 : :
636 : : extern "C" void P2SymBuild_BuildVarArgs (void);
637 : :
638 : : /*
639 : : BuildFormalVarArgs - indicates that the procedure type takes varargs.
640 : :
641 : : <- Ptr
642 : : +------------+ +------------+
643 : : | ProcSym | | ProcSym |
644 : : |------------| |------------|
645 : :
646 : : */
647 : :
648 : : extern "C" void P2SymBuild_BuildFormalVarArgs (void);
649 : :
650 : : /*
651 : : BuildOptArg - indicates that the ProcSym takes a single optarg
652 : : after ParamTotal.
653 : :
654 : : <- Ptr
655 : : +------------+ +------------+
656 : : | ParamTotal | | ParamTotal |
657 : : |------------| |------------|
658 : : | ProcSym | | ProcSym |
659 : : |------------| |------------|
660 : : */
661 : :
662 : : extern "C" void P2SymBuild_BuildOptArg (void);
663 : :
664 : : /*
665 : : StartBuildProcedure - Builds a Procedure.
666 : :
667 : : The Stack:
668 : :
669 : : Entry Exit
670 : :
671 : : <- Ptr
672 : : +------------+
673 : : Ptr -> | ProcSym |
674 : : +------------+ |------------|
675 : : | Name | | Name |
676 : : |------------| |------------|
677 : : */
678 : :
679 : : extern "C" void P2SymBuild_StartBuildProcedure (void);
680 : :
681 : : /*
682 : : EndBuildProcedure - Ends building a Procedure.
683 : : It checks the start procedure name matches the end
684 : : procedure name.
685 : :
686 : : The Stack:
687 : :
688 : : (Procedure Not Defined in definition module)
689 : :
690 : : Entry Exit
691 : :
692 : : Ptr ->
693 : : +------------+
694 : : | NameEnd |
695 : : |------------|
696 : : | ProcSym |
697 : : |------------|
698 : : | NameStart |
699 : : |------------|
700 : : Empty
701 : : */
702 : :
703 : : extern "C" void P2SymBuild_EndBuildProcedure (void);
704 : :
705 : : /*
706 : : EndBuildForward - ends building a forward procedure.
707 : : */
708 : :
709 : : extern "C" void P2SymBuild_EndBuildForward (void);
710 : :
711 : : /*
712 : : BuildNoReturnAttribute - provide an interface to the symbol table module.
713 : : */
714 : :
715 : : extern "C" void P2SymBuild_BuildNoReturnAttribute (void);
716 : :
717 : : /*
718 : : CheckProcedure - checks to see that the top of stack procedure
719 : : has not been declared as a procedure function.
720 : :
721 : : The Stack:
722 : :
723 : : Entry Exit
724 : :
725 : : Ptr -> <- Ptr
726 : : +------------+ +------------+
727 : : | ProcSym | | ProcSym |
728 : : |------------| |------------|
729 : : */
730 : :
731 : : extern "C" void P2SymBuild_CheckProcedure (void);
732 : :
733 : : /*
734 : : BuildPointerType - builds a pointer type.
735 : : The Stack:
736 : :
737 : : Entry Exit
738 : : ===== ====
739 : :
740 : :
741 : : Ptr -> <- Ptr
742 : : +------------+ +-------------+
743 : : | Type | | PointerType |
744 : : |------------| |-------------|
745 : : | Name | | Name |
746 : : |------------| |-------------|
747 : : */
748 : :
749 : : extern "C" void P2SymBuild_BuildPointerType (unsigned int pointerpos);
750 : :
751 : : /*
752 : : BuildSetType - builds a set type.
753 : : The Stack:
754 : :
755 : : Entry Exit
756 : : ===== ====
757 : :
758 : :
759 : : Ptr -> <- Ptr
760 : : +------------+ +-------------+
761 : : | Type | | SetType |
762 : : |------------| |-------------|
763 : : | Name | | Name |
764 : : |------------| |-------------|
765 : : */
766 : :
767 : : extern "C" void P2SymBuild_BuildSetType (unsigned int setpos, bool ispacked);
768 : :
769 : : /*
770 : : BuildRecord - Builds a record type.
771 : : The Stack:
772 : :
773 : : Entry Exit
774 : : ===== ====
775 : :
776 : :
777 : : <- Ptr
778 : : +-----------+
779 : : Ptr -> | RecordSym |
780 : : +------------------+ |-----------|
781 : : | Name | | Name |
782 : : |------------------| |-----------|
783 : : */
784 : :
785 : : extern "C" void P2SymBuild_BuildRecord (void);
786 : :
787 : : /*
788 : : BuildFieldRecord - Builds a field into a record sym.
789 : : The Stack:
790 : :
791 : :
792 : : Entry Exit
793 : : ===== ====
794 : :
795 : : Ptr ->
796 : : +-------------+
797 : : | NoOfPragmas |
798 : : |-------------|
799 : : | Const1 |
800 : : |-------------|
801 : : | PragmaName1 |
802 : : |-------------|
803 : : | Type | Name |
804 : : |-------------|
805 : : | n |
806 : : |-------------|
807 : : | Id 1 |
808 : : |-------------|
809 : : . .
810 : : . .
811 : : . .
812 : : |-------------|
813 : : | Id n | <- Ptr
814 : : |-------------| +-------------+
815 : : | RecordSym | | RecordSym |
816 : : |-------------| |-------------|
817 : : | RecordName | | RecordName |
818 : : |-------------| |-------------|
819 : : */
820 : :
821 : : extern "C" void P2SymBuild_BuildFieldRecord (void);
822 : :
823 : : /*
824 : : StartBuildVarient - Builds a varient symbol on top of a record sym.
825 : : The Stack:
826 : :
827 : :
828 : : Entry Exit
829 : : ===== ====
830 : :
831 : : <- Ptr
832 : : +-------------+
833 : : Ptr -> | VarientSym |
834 : : +-------------+ |-------------|
835 : : | RecordSym | | RecordSym |
836 : : |-------------| |-------------|
837 : : | RecordName | | RecordName |
838 : : |-------------| |-------------|
839 : : */
840 : :
841 : : extern "C" void P2SymBuild_StartBuildVarient (void);
842 : :
843 : : /*
844 : : EndBuildVarient - Removes the varient symbol from the stack.
845 : : The Stack:
846 : :
847 : : Entry Exit
848 : : ===== ====
849 : :
850 : : Ptr ->
851 : : +-------------+
852 : : | VarientSym | <- Ptr
853 : : |-------------| +-------------+
854 : : | RecordSym | | RecordSym |
855 : : |-------------| |-------------|
856 : : | RecordName | | RecordName |
857 : : |-------------| |-------------|
858 : : */
859 : :
860 : : extern "C" void P2SymBuild_EndBuildVarient (void);
861 : :
862 : : /*
863 : : BuildVarientSelector - Builds a field into a record sym.
864 : : The Stack:
865 : :
866 : :
867 : : Entry Exit
868 : : ===== ====
869 : :
870 : : Ptr ->
871 : : +-------------+
872 : : | Type |
873 : : |-------------|
874 : : | Tag | <- Ptr
875 : : |-------------| +-------------+
876 : : | RecordSym | | RecordSym |
877 : : |-------------| |-------------|
878 : : */
879 : :
880 : : extern "C" void P2SymBuild_BuildVarientSelector (void);
881 : :
882 : : /*
883 : : StartBuildVarientFieldRecord - Builds a varient field into a varient sym.
884 : : The Stack:
885 : :
886 : :
887 : : Entry Exit
888 : : ===== ====
889 : :
890 : : <- Ptr
891 : : +-------------+
892 : : Ptr -> | VarientField|
893 : : +-------------+ |-------------|
894 : : | VarientSym | | VarientSym |
895 : : |-------------| |-------------|
896 : : */
897 : :
898 : : extern "C" void P2SymBuild_StartBuildVarientFieldRecord (void);
899 : :
900 : : /*
901 : : EndBuildVarientFieldRecord - Removes a varient field from the stack.
902 : : The Stack:
903 : :
904 : :
905 : : Entry Exit
906 : : ===== ====
907 : :
908 : : Ptr ->
909 : : +-------------+
910 : : | VarientField| <- Ptr
911 : : |-------------| +-------------+
912 : : | VarientSym | | VarientSym |
913 : : |-------------| |-------------|
914 : : */
915 : :
916 : : extern "C" void P2SymBuild_EndBuildVarientFieldRecord (void);
917 : :
918 : : /*
919 : : BuildNulName - Pushes a NulName onto the top of the stack.
920 : : The Stack:
921 : :
922 : :
923 : : Entry Exit
924 : :
925 : : <- Ptr
926 : : Empty +------------+
927 : : | NulName |
928 : : |------------|
929 : : */
930 : :
931 : : extern "C" void P2SymBuild_BuildNulName (void);
932 : :
933 : : /*
934 : : BuildTypeEnd - Pops the type Type and Name.
935 : : The Stack:
936 : :
937 : :
938 : : Entry Exit
939 : :
940 : :
941 : : Ptr ->
942 : : +-------------+
943 : : | Type | Name | Empty
944 : : |-------------|
945 : : */
946 : :
947 : : extern "C" void P2SymBuild_BuildTypeEnd (void);
948 : :
949 : : /*
950 : : StartBuildArray - Builds an array type.
951 : : The Stack:
952 : :
953 : : Entry Exit
954 : : ===== ====
955 : :
956 : : <- Ptr
957 : : +-----------+
958 : : Ptr -> | ArraySym |
959 : : +------------+ |-----------|
960 : : | Name | | Name |
961 : : |------------| |-----------|
962 : : */
963 : :
964 : : extern "C" void P2SymBuild_StartBuildArray (void);
965 : :
966 : : /*
967 : : EndBuildArray - Builds an array type.
968 : : The Stack:
969 : :
970 : : Entry Exit
971 : : ===== ====
972 : :
973 : : Ptr ->
974 : : +------------+
975 : : | TypeSym | <- Ptr
976 : : |------------| +------------+
977 : : | ArraySym | | ArraySym |
978 : : |------------| |------------|
979 : : | Name | | Name |
980 : : |------------| |------------|
981 : : */
982 : :
983 : : extern "C" void P2SymBuild_EndBuildArray (void);
984 : :
985 : : /*
986 : : BuildFieldArray - Builds a field into an array sym.
987 : : The Stack:
988 : :
989 : :
990 : : Entry Exit
991 : : ===== ====
992 : :
993 : : Ptr ->
994 : : +-------------+
995 : : | Type | Name | <- Ptr
996 : : |-------------| +-------------+
997 : : | ArraySym | | ArraySym |
998 : : |-------------| |-------------|
999 : : | ArrayName | | ArrayName |
1000 : : |-------------| |-------------|
1001 : : */
1002 : :
1003 : : extern "C" void P2SymBuild_BuildFieldArray (void);
1004 : :
1005 : : /*
1006 : : BuildArrayComma - converts ARRAY [..], [..] OF into ARRAY [..] OF ARRAY [..]
1007 : :
1008 : :
1009 : : Ptr -> <- Ptr
1010 : : +-------------+ +-------------+
1011 : : | ArraySym1 | | ArraySym2 |
1012 : : |-------------| |-------------|
1013 : : | ArrayName | | ArrayName |
1014 : : |-------------| |-------------|
1015 : : */
1016 : :
1017 : : extern "C" void P2SymBuild_BuildArrayComma (void);
1018 : :
1019 : : /*
1020 : : BuildProcedureType - builds a procedure type symbol.
1021 : : The Stack:
1022 : :
1023 : :
1024 : : <- Ptr
1025 : : +-------------+
1026 : : Ptr -> | ProcTypeSym |
1027 : : +-------------+ |-------------|
1028 : : | Name | | Name |
1029 : : |-------------| |-------------|
1030 : : */
1031 : :
1032 : : extern "C" void P2SymBuild_BuildProcedureType (void);
1033 : :
1034 : : /*
1035 : : BuildFormalType - Builds a Formal Parameter in a procedure type.
1036 : :
1037 : : The Stack:
1038 : :
1039 : : Entry Exit
1040 : :
1041 : : Ptr ->
1042 : : +------------+
1043 : : | TypeSym |
1044 : : |------------|
1045 : : | Array/Nul |
1046 : : |------------|
1047 : : | Var / Nul | <- Ptr
1048 : : |------------| +--------------+
1049 : : | ProcTypeSym| | ProcTypeSym |
1050 : : |------------| |--------------|
1051 : : */
1052 : :
1053 : : extern "C" void P2SymBuild_BuildFormalType (void);
1054 : :
1055 : : /*
1056 : : SeenUnknown - sets the operand type to unknown.
1057 : : */
1058 : :
1059 : : extern "C" void P2SymBuild_SeenUnknown (void);
1060 : :
1061 : : /*
1062 : : SeenCast - sets the operand type to cast.
1063 : : */
1064 : :
1065 : : extern "C" void P2SymBuild_SeenCast (unsigned int sym);
1066 : :
1067 : : /*
1068 : : SeenSet - sets the operand type to set.
1069 : : */
1070 : :
1071 : : extern "C" void P2SymBuild_SeenSet (void);
1072 : :
1073 : : /*
1074 : : SeenConstructor - sets the operand type to constructor.
1075 : : */
1076 : :
1077 : : extern "C" void P2SymBuild_SeenConstructor (void);
1078 : :
1079 : : /*
1080 : : SeenArray - sets the operand type to array.
1081 : : */
1082 : :
1083 : : extern "C" void P2SymBuild_SeenArray (void);
1084 : :
1085 : : /*
1086 : : SeenString - sets the operand type to string.
1087 : : */
1088 : :
1089 : : extern "C" void P2SymBuild_SeenString (void);
1090 : :
1091 : : /*
1092 : : SeenBoolean - sets the operand type to a BOOLEAN.
1093 : : */
1094 : :
1095 : : extern "C" void P2SymBuild_SeenBoolean (void);
1096 : :
1097 : : /*
1098 : : SeenZType - sets the operand type to a Z type.
1099 : : */
1100 : :
1101 : : extern "C" void P2SymBuild_SeenZType (void);
1102 : :
1103 : : /*
1104 : : SeenRType - sets the operand type to a R type.
1105 : : */
1106 : :
1107 : : extern "C" void P2SymBuild_SeenRType (void);
1108 : :
1109 : : /*
1110 : : SeenCType - sets the operand type to a C type.
1111 : : */
1112 : :
1113 : : extern "C" void P2SymBuild_SeenCType (void);
1114 : :
1115 : : /*
1116 : : DetermineType - assigns the top of stack symbol with the type of
1117 : : constant expression, if known.
1118 : : */
1119 : :
1120 : : extern "C" void P2SymBuild_DetermineType (void);
1121 : :
1122 : : /*
1123 : : PushType -
1124 : : */
1125 : :
1126 : : extern "C" void P2SymBuild_PushType (void);
1127 : :
1128 : : /*
1129 : : PopType -
1130 : : */
1131 : :
1132 : : extern "C" void P2SymBuild_PopType (void);
1133 : :
1134 : : /*
1135 : : PushRememberConstant -
1136 : : */
1137 : :
1138 : : extern "C" void P2SymBuild_PushRememberConstant (void);
1139 : :
1140 : : /*
1141 : : PopRememberConstant -
1142 : : */
1143 : :
1144 : : extern "C" void P2SymBuild_PopRememberConstant (void);
1145 : :
1146 : : /*
1147 : : RememberConstant -
1148 : : */
1149 : :
1150 : : extern "C" void P2SymBuild_RememberConstant (unsigned int sym);
1151 : : static void stop (void);
1152 : :
1153 : : /*
1154 : : propageteTokenPosition - if laterTokPos is unknown then return knownTokPos.
1155 : : else return laterTokPos.
1156 : : */
1157 : :
1158 : : static unsigned int propageteTokenPosition (unsigned int knownTokPos, unsigned int laterTokPos);
1159 : :
1160 : : /*
1161 : : PushBlock - push the block variables to the block stack.
1162 : : */
1163 : :
1164 : : static void PushBlock (unsigned int tokno);
1165 : :
1166 : : /*
1167 : : PopBlock - pop the block variables from the block stack.
1168 : : */
1169 : :
1170 : : static void PopBlock (void);
1171 : :
1172 : : /*
1173 : : BuildFormalParameterSection - Builds a Formal Parameter in a procedure.
1174 : :
1175 : : The Stack:
1176 : :
1177 : : Entry and Exit
1178 : :
1179 : : Ptr -> <- Ptr
1180 : : +------------+
1181 : : | ParamTotal |
1182 : : |------------|
1183 : : | TypeSym |
1184 : : |------------|
1185 : : | Array/Nul |
1186 : : |------------|
1187 : : | NoOfIds |
1188 : : |------------|
1189 : : | Id 1 |
1190 : : |------------|
1191 : : . .
1192 : : . .
1193 : : . .
1194 : : |------------|
1195 : : | Id n |
1196 : : |------------|
1197 : : | Var / Nul |
1198 : : |------------|
1199 : : | ProcSym |
1200 : : |------------|
1201 : : */
1202 : :
1203 : : static void BuildFormalParameterSection (SymbolTable_ProcedureKind kind);
1204 : :
1205 : : /*
1206 : : CheckFormalParameterSection - Checks a Formal Parameter in a procedure.
1207 : : The stack is unaffected.
1208 : :
1209 : : The Stack:
1210 : :
1211 : : Entry and Exit
1212 : :
1213 : : Ptr ->
1214 : : +------------+
1215 : : | ParamTotal |
1216 : : |------------|
1217 : : | TypeSym |
1218 : : |------------|
1219 : : | Array/Nul |
1220 : : |------------|
1221 : : | NoOfIds |
1222 : : |------------|
1223 : : | Id 1 |
1224 : : |------------|
1225 : : . .
1226 : : . .
1227 : : . .
1228 : : |------------|
1229 : : | Id n |
1230 : : |------------|
1231 : : | Var / Nul |
1232 : : |------------|
1233 : : | ProcSym |
1234 : : |------------|
1235 : : */
1236 : :
1237 : : static void CheckFormalParameterSection (SymbolTable_ProcedureKind curkind, SymbolTable_ProcedureKind prevkind);
1238 : :
1239 : : /*
1240 : : RemoveFPParameters - remove the FPSection parameters from the stack and
1241 : : increment the param total with the NoOfIds.
1242 : :
1243 : : The Stack:
1244 : :
1245 : : Entry Exit
1246 : :
1247 : : Ptr ->
1248 : : +------------+
1249 : : | ParamTotal |
1250 : : |------------|
1251 : : | TypeSym |
1252 : : |------------|
1253 : : | Array/Nul |
1254 : : |------------|
1255 : : | NoOfIds |
1256 : : |------------|
1257 : : | Id 1 |
1258 : : |------------|
1259 : : . .
1260 : : . .
1261 : : . .
1262 : : |------------|
1263 : : | Id n | <- Ptr
1264 : : |------------| +------------+
1265 : : | Var / Nul | | ParamTotal |
1266 : : |------------| |------------|
1267 : : | ProcSym | | ProcSym |
1268 : : |------------| |------------|
1269 : : */
1270 : :
1271 : : static void RemoveFPParameters (void);
1272 : :
1273 : : /*
1274 : : ParameterError - create two error strings chained together.
1275 : : */
1276 : :
1277 : : static void ParameterError (const char *FmtHeader_, unsigned int _FmtHeader_high, const char *PrevDesc_, unsigned int _PrevDesc_high, const char *CurDesc_, unsigned int _CurDesc_high, unsigned int ParamNo, unsigned int ProcSym, SymbolTable_ProcedureKind curkind, SymbolTable_ProcedureKind prevkind);
1278 : :
1279 : : /*
1280 : : ParameterMismatch - generate a parameter mismatch error between the current
1281 : : declaration at tok and a previous ProcSym declaration.
1282 : : NoOfPar is the current number of parameters.
1283 : : */
1284 : :
1285 : : static void ParameterMismatch (unsigned int tok, unsigned int ProcSym, unsigned int NoOfPar, SymbolTable_ProcedureKind prevkind, SymbolTable_ProcedureKind curkind);
1286 : :
1287 : : /*
1288 : : GetComparison - return a simple description from the result of
1289 : : a comparison between left and right.
1290 : : */
1291 : :
1292 : : static DynamicStrings_String GetComparison (unsigned int left, unsigned int right);
1293 : :
1294 : : /*
1295 : : ReturnTypeMismatch - generate two errors showing the return type mismatches between
1296 : : ProcSym and ReturnType at procedure location tok.
1297 : : */
1298 : :
1299 : : static void ReturnTypeMismatch (unsigned int curtok, unsigned int ProcSym, unsigned int CurRetType, unsigned int curtypetok, SymbolTable_ProcedureKind curkind, SymbolTable_ProcedureKind prevkind, unsigned int PrevRetType);
1300 : :
1301 : : /*
1302 : : CheckOptFunction - checks to see whether the optional return value
1303 : : has been set before and if it differs it will
1304 : : generate an error message. It will set the
1305 : : new value to isopt.
1306 : : */
1307 : :
1308 : : static void CheckOptFunction (unsigned int tok, unsigned int sym, SymbolTable_ProcedureKind kind, bool isopt);
1309 : :
1310 : : /*
1311 : : CheckProcedure - checks to see that the top of stack procedure
1312 : : has not been declared as a procedure function.
1313 : :
1314 : : The Stack:
1315 : :
1316 : : Entry Exit
1317 : :
1318 : : Ptr -> <- Ptr
1319 : : +------------+ +------------+
1320 : : | ProcSym | | ProcSym |
1321 : : |------------| |------------|
1322 : : */
1323 : :
1324 : : static void CheckProcedureReturn (unsigned int RetType, unsigned int typetok);
1325 : :
1326 : : /*
1327 : : HandleRecordFieldPragmas -
1328 : :
1329 : : Entry Exit
1330 : : ===== ====
1331 : :
1332 : : Ptr -> <- Ptr
1333 : :
1334 : : |-------------| |-------------|
1335 : : | Const1 | | Const1 |
1336 : : |-------------| |-------------|
1337 : : | PragmaName1 | | PragmaName1 |
1338 : : |-------------| |-------------|
1339 : : */
1340 : :
1341 : : static void HandleRecordFieldPragmas (unsigned int record, unsigned int field, unsigned int n);
1342 : :
1343 : : /*
1344 : : SaveRememberedConstructor -
1345 : : */
1346 : :
1347 : : static void SaveRememberedConstructor (void);
1348 : :
1349 : : /*
1350 : : GetSeenString - returns a string corresponding to, s.
1351 : : */
1352 : :
1353 : : static DynamicStrings_String GetSeenString (M2Const_constType s);
1354 : :
1355 : : /*
1356 : : SetTypeTo - attempts to set, type, to, s.
1357 : : */
1358 : :
1359 : : static void SetTypeTo (M2Const_constType s);
1360 : :
1361 : 0 : static void stop (void)
1362 : : {
1363 : 0 : }
1364 : :
1365 : :
1366 : : /*
1367 : : propageteTokenPosition - if laterTokPos is unknown then return knownTokPos.
1368 : : else return laterTokPos.
1369 : : */
1370 : :
1371 : 132218 : static unsigned int propageteTokenPosition (unsigned int knownTokPos, unsigned int laterTokPos)
1372 : : {
1373 : 0 : if (laterTokPos == M2LexBuf_UnknownTokenNo)
1374 : : {
1375 : : return knownTokPos;
1376 : : }
1377 : : else
1378 : : {
1379 : 42623 : return laterTokPos;
1380 : : }
1381 : : /* static analysis guarentees a RETURN statement will be used before here. */
1382 : : __builtin_unreachable ();
1383 : : }
1384 : :
1385 : :
1386 : : /*
1387 : : PushBlock - push the block variables to the block stack.
1388 : : */
1389 : :
1390 : 66127 : static void PushBlock (unsigned int tokno)
1391 : : {
1392 : 66127 : M2StackWord_PushWord (BlockStack, curStartTok); /* module/implementation/definition/procedure token pos. */
1393 : 66127 : M2StackWord_PushWord (BlockStack, curBeginTok); /* BEGIN keyword pos. */
1394 : 66127 : M2StackWord_PushWord (BlockStack, curEndTok); /* END keyword pos. */
1395 : 66127 : M2StackWord_PushWord (BlockStack, curFinallyTok); /* FINALLY keyword pos. */
1396 : 66127 : M2StackWord_PushWord (BlockStack, curModuleSym); /* current module. */
1397 : 66127 : curStartTok = tokno; /* current module. */
1398 : 66127 : curBeginTok = M2LexBuf_UnknownTokenNo;
1399 : 66127 : curEndTok = M2LexBuf_UnknownTokenNo;
1400 : 66127 : curFinallyTok = M2LexBuf_UnknownTokenNo;
1401 : 66127 : curModuleSym = SymbolTable_NulSym;
1402 : 66127 : }
1403 : :
1404 : :
1405 : : /*
1406 : : PopBlock - pop the block variables from the block stack.
1407 : : */
1408 : :
1409 : 66109 : static void PopBlock (void)
1410 : : {
1411 : 66109 : curModuleSym = static_cast<unsigned int> (M2StackWord_PopWord (BlockStack));
1412 : 66109 : curFinallyTok = static_cast<unsigned int> (M2StackWord_PopWord (BlockStack));
1413 : 66109 : curEndTok = static_cast<unsigned int> (M2StackWord_PopWord (BlockStack));
1414 : 66109 : curBeginTok = static_cast<unsigned int> (M2StackWord_PopWord (BlockStack));
1415 : 66109 : curStartTok = static_cast<unsigned int> (M2StackWord_PopWord (BlockStack));
1416 : 66109 : }
1417 : :
1418 : :
1419 : : /*
1420 : : BuildFormalParameterSection - Builds a Formal Parameter in a procedure.
1421 : :
1422 : : The Stack:
1423 : :
1424 : : Entry and Exit
1425 : :
1426 : : Ptr -> <- Ptr
1427 : : +------------+
1428 : : | ParamTotal |
1429 : : |------------|
1430 : : | TypeSym |
1431 : : |------------|
1432 : : | Array/Nul |
1433 : : |------------|
1434 : : | NoOfIds |
1435 : : |------------|
1436 : : | Id 1 |
1437 : : |------------|
1438 : : . .
1439 : : . .
1440 : : . .
1441 : : |------------|
1442 : : | Id n |
1443 : : |------------|
1444 : : | Var / Nul |
1445 : : |------------|
1446 : : | ProcSym |
1447 : : |------------|
1448 : : */
1449 : :
1450 : 5085803 : static void BuildFormalParameterSection (SymbolTable_ProcedureKind kind)
1451 : : {
1452 : 5085803 : NameKey_Name ParamName;
1453 : 5085803 : NameKey_Name Var;
1454 : 5085803 : NameKey_Name Array;
1455 : 5085803 : unsigned int tok;
1456 : 5085803 : unsigned int pi;
1457 : 5085803 : unsigned int TypeTok;
1458 : 5085803 : unsigned int ParamTotal;
1459 : 5085803 : unsigned int TypeSym;
1460 : 5085803 : unsigned int UnBoundedSym;
1461 : 5085803 : unsigned int NoOfIds;
1462 : 5085803 : unsigned int ProcSym;
1463 : 5085803 : unsigned int i;
1464 : 5085803 : unsigned int ndim;
1465 : :
1466 : 5085803 : M2Quads_PopT (&ParamTotal);
1467 : 5085803 : M2Quads_PopTtok (&TypeSym, &TypeTok);
1468 : 5085803 : M2Quads_PopTF (&Array, &ndim);
1469 : 10171606 : M2Debug_Assert ((Array == M2Reserved_ArrayTok) || (Array == M2Reserved_NulTok));
1470 : 5085803 : M2Quads_PopT (&NoOfIds);
1471 : 5085803 : ProcSym = static_cast<unsigned int> (M2Quads_OperandT (NoOfIds+2));
1472 : 5085803 : M2Debug_Assert (SymbolTable_IsProcedure (ProcSym));
1473 : 5085803 : Var = static_cast<NameKey_Name> (M2Quads_OperandT (NoOfIds+1));
1474 : 5085803 : tok = static_cast<unsigned int> (M2Quads_OperandTok (NoOfIds+2));
1475 : 10171606 : M2Debug_Assert ((Var == M2Reserved_VarTok) || (Var == M2Reserved_NulTok));
1476 : : /* Restore popped elements. */
1477 : 5085803 : M2Quads_PushT (NoOfIds);
1478 : 5085803 : M2Quads_PushTF (Array, ndim);
1479 : 5085803 : M2Quads_PushTtok (TypeSym, TypeTok);
1480 : 5085803 : M2Quads_PushT (ParamTotal);
1481 : 5085803 : if (Array == M2Reserved_ArrayTok)
1482 : : {
1483 : 522315 : UnBoundedSym = SymbolTable_MakeUnbounded (tok, TypeSym, ndim);
1484 : 522315 : TypeSym = UnBoundedSym;
1485 : : }
1486 : 5085803 : i = 1;
1487 : : /* +4 to skip over the top restored elements. */
1488 : 5085803 : pi = NoOfIds+4; /* Stack index referencing stacked parameter i. */
1489 : 11790465 : while (i <= NoOfIds) /* Stack index referencing stacked parameter i. */
1490 : : {
1491 : 6704662 : if (((M2Comp_CompilingDefinitionModule ()) && ! M2Options_PedanticParamNames) && (((SymbolTable_GetMainModule ()) == (SymbolTable_GetCurrentModule ())) || ((SymbolTable_IsHiddenTypeDeclared (SymbolTable_GetCurrentModule ())) && M2Options_ExtendedOpaque)))
1492 : : {
1493 : : /* We will see the parameters in the implementation module. */
1494 : : ParamName = NameKey_NulName;
1495 : : }
1496 : : else
1497 : : {
1498 : 6659478 : ParamName = static_cast<NameKey_Name> (M2Quads_OperandT (pi));
1499 : : }
1500 : 6704662 : tok = static_cast<unsigned int> (M2Quads_OperandTok (pi));
1501 : 6704662 : if (Var == M2Reserved_VarTok)
1502 : : {
1503 : : /* avoid dangling else. */
1504 : : /* VAR parameter. */
1505 : 568993 : if (! (SymbolTable_PutVarParam (tok, ProcSym, kind, ParamTotal+i, ParamName, TypeSym, Array == M2Reserved_ArrayTok, TypeTok)))
1506 : : {
1507 : 0 : M2Error_InternalError ((const char *) "problems adding a VarParameter - wrong param number?", 52);
1508 : : }
1509 : : }
1510 : : else
1511 : : {
1512 : : /* Non VAR parameter. */
1513 : 6135669 : if (! (SymbolTable_PutParam (tok, ProcSym, kind, ParamTotal+i, ParamName, TypeSym, Array == M2Reserved_ArrayTok, TypeTok)))
1514 : : {
1515 : 0 : M2Error_InternalError ((const char *) "problems adding a Parameter - wrong param number?", 49);
1516 : : }
1517 : : }
1518 : : /*
1519 : : IF kind = ProperProcedure
1520 : : THEN
1521 : : PutDeclared (OperandTok (pi), GetParameterShadowVar (GetNthParam (ProcSym, kind, ParamTotal + i)))
1522 : : END ;
1523 : : */
1524 : 6704662 : i += 1;
1525 : 6704662 : pi -= 1;
1526 : : }
1527 : 5085803 : }
1528 : :
1529 : :
1530 : : /*
1531 : : CheckFormalParameterSection - Checks a Formal Parameter in a procedure.
1532 : : The stack is unaffected.
1533 : :
1534 : : The Stack:
1535 : :
1536 : : Entry and Exit
1537 : :
1538 : : Ptr ->
1539 : : +------------+
1540 : : | ParamTotal |
1541 : : |------------|
1542 : : | TypeSym |
1543 : : |------------|
1544 : : | Array/Nul |
1545 : : |------------|
1546 : : | NoOfIds |
1547 : : |------------|
1548 : : | Id 1 |
1549 : : |------------|
1550 : : . .
1551 : : . .
1552 : : . .
1553 : : |------------|
1554 : : | Id n |
1555 : : |------------|
1556 : : | Var / Nul |
1557 : : |------------|
1558 : : | ProcSym |
1559 : : |------------|
1560 : : */
1561 : :
1562 : 1019558 : static void CheckFormalParameterSection (SymbolTable_ProcedureKind curkind, SymbolTable_ProcedureKind prevkind)
1563 : : {
1564 : 1019558 : NameKey_Name Array;
1565 : 1019558 : NameKey_Name Var;
1566 : 1019558 : bool isVarParam;
1567 : 1019558 : bool Unbounded;
1568 : 1019558 : unsigned int ParamI;
1569 : 1019558 : unsigned int ParamIType;
1570 : 1019558 : unsigned int ParamTotal;
1571 : 1019558 : unsigned int TypeTok;
1572 : 1019558 : unsigned int TypeSym;
1573 : 1019558 : unsigned int NoOfIds;
1574 : 1019558 : unsigned int ProcSym;
1575 : 1019558 : unsigned int pi;
1576 : 1019558 : unsigned int i;
1577 : 1019558 : unsigned int ndim;
1578 : :
1579 : 1019558 : M2Quads_PopT (&ParamTotal);
1580 : 1019558 : M2Quads_PopTtok (&TypeSym, &TypeTok);
1581 : 1019558 : M2Quads_PopTF (&Array, &ndim);
1582 : 2039116 : M2Debug_Assert ((Array == M2Reserved_ArrayTok) || (Array == M2Reserved_NulTok));
1583 : 1019558 : M2Quads_PopT (&NoOfIds);
1584 : 1019558 : ProcSym = static_cast<unsigned int> (M2Quads_OperandT (NoOfIds+2));
1585 : 1019558 : M2Debug_Assert (SymbolTable_IsProcedure (ProcSym));
1586 : 1019558 : Var = static_cast<NameKey_Name> (M2Quads_OperandT (NoOfIds+1));
1587 : 2039116 : M2Debug_Assert ((Var == NameKey_NulName) || (Var == M2Reserved_VarTok));
1588 : 1019558 : isVarParam = Var != NameKey_NulName;
1589 : : /* Restore popped elements. */
1590 : 1019558 : M2Quads_PushT (NoOfIds);
1591 : 1019558 : M2Quads_PushTF (Array, ndim);
1592 : 1019558 : M2Quads_PushTtok (TypeSym, TypeTok);
1593 : 1019558 : M2Quads_PushT (ParamTotal);
1594 : 2039116 : M2Debug_Assert ((Var == M2Reserved_VarTok) || (Var == M2Reserved_NulTok));
1595 : 1019558 : Unbounded = Array == M2Reserved_ArrayTok; /* ARRAY OF Type, parameter. */
1596 : 1019558 : i = 1;
1597 : : /* +4 to skip over the top restored elements. */
1598 : 1019558 : pi = NoOfIds+4; /* Stack index referencing stacked parameter i. */
1599 : : /* If there are an incorrect number of parameters specified then this
1600 : : will be detcted by EndBuildFormalParameters. */
1601 : 2304890 : while (i <= NoOfIds)
1602 : : {
1603 : 1285332 : if ((ParamTotal+i) <= (SymbolTable_NoOfParam (ProcSym, prevkind)))
1604 : : {
1605 : : /* WarnStringAt (InitString ('parampos?'), OperandTok (pi)) ; */
1606 : 1285326 : if (Unbounded && (! (SymbolTable_IsUnboundedParam (ProcSym, prevkind, ParamTotal+i))))
1607 : : {
1608 : 0 : ParameterError ((const char *) "declaration of procedure {%%1a} in the %s differs from the %s, {%%2N} parameter is inconsistant, %s", 99, (const char *) "the parameter {%3EHa} was not declared as an ARRAY OF type", 58, (const char *) "the parameter {%3EVa} was declared as an ARRAY OF type", 54, ParamTotal+i, ProcSym, curkind, prevkind);
1609 : : }
1610 : 1285326 : else if (! Unbounded && (SymbolTable_IsUnboundedParam (ProcSym, prevkind, ParamTotal+i)))
1611 : : {
1612 : : /* avoid dangling else. */
1613 : 6 : ParameterError ((const char *) "declaration of procedure {%%1a} in the %s differs from the %s, {%%2N} parameter is inconsistant, %s", 99, (const char *) "the parameter {%3EHa} was declared as an ARRAY OF type", 54, (const char *) "the parameter {%3EVa} was not declared as an ARRAY OF type", 58, ParamTotal+i, ProcSym, curkind, prevkind);
1614 : : }
1615 : 1285326 : if (Unbounded)
1616 : : {
1617 : 173874 : if ((SymbolTable_GetDimension (SymbolTable_GetNthParam (ProcSym, prevkind, ParamTotal+1))) != ndim)
1618 : : {
1619 : 0 : ParameterError ((const char *) "declaration of procedure {%%1a} in the %s differs from the %s, {%%2N} parameter is inconsistant, %s", 99, (const char *) "the dynamic array parameter {%3EHa} was declared with a different of dimensions", 79, (const char *) "the dynamic array parameter {%3EVa} was declared with a different of dimensions", 79, ParamTotal+i, ProcSym, curkind, prevkind);
1620 : : }
1621 : : }
1622 : 1285326 : if (isVarParam && (! (SymbolTable_IsVarParam (ProcSym, prevkind, ParamTotal+i))))
1623 : : {
1624 : : /* Expecting non VAR parameter. */
1625 : 6 : ParameterError ((const char *) "declaration of procedure {%%1a} in the %s differs from the %s, {%%2N} parameter is inconsistant, %s", 99, (const char *) "{%3EHa} was not declared as a {%kVAR} parameter", 47, (const char *) "{%3EVa} was declared as a {%kVAR} parameter", 43, ParamTotal+i, ProcSym, curkind, prevkind);
1626 : : }
1627 : 1285320 : else if (! isVarParam && (SymbolTable_IsVarParam (ProcSym, prevkind, ParamTotal+i)))
1628 : : {
1629 : : /* avoid dangling else. */
1630 : : /* Expecting VAR pamarater. */
1631 : 6 : ParameterError ((const char *) "declaration of procedure {%%1a} in the %s differs from the %s, {%%2N} parameter is inconsistant, %s", 99, (const char *) "{%3EHa} was declared as a {%kVAR} parameter", 43, (const char *) "{%3EVa} was not declared as a {%kVAR} parameter", 47, ParamTotal+i, ProcSym, curkind, prevkind);
1632 : : }
1633 : 1285326 : ParamI = SymbolTable_GetNthParam (ProcSym, prevkind, ParamTotal+i);
1634 : 1285326 : if (M2Options_PedanticParamNames)
1635 : : {
1636 : 30 : if ((SymbolTable_GetSymName (ParamI)) != (M2Quads_OperandT (pi)))
1637 : : {
1638 : : /* Different parameter names. */
1639 : 24 : ParameterError ((const char *) "procedure {%%1a} in the %s differs from the %s, {%%2N} parameter name is inconsistant, %s", 89, (const char *) "named as {%3EVa}", 16, (const char *) "named as {%3EVa}", 16, ParamTotal+i, ProcSym, curkind, prevkind);
1640 : : }
1641 : : }
1642 : 1285326 : if (Unbounded)
1643 : : {
1644 : : /* GetType(ParamI) yields an UnboundedSym or a PartialUnboundedSym,
1645 : : depending whether it has been resolved.. */
1646 : 173874 : ParamIType = SymbolTable_GetType (SymbolTable_GetType (ParamI));
1647 : : }
1648 : : else
1649 : : {
1650 : 1111452 : ParamIType = SymbolTable_GetType (ParamI);
1651 : : }
1652 : 1285326 : if (((((SymbolTable_SkipType (ParamIType)) != (SymbolTable_SkipType (TypeSym))) || (M2Options_PedanticParamNames && (ParamIType != TypeSym))) && (! (SymbolTable_IsUnknown (SymbolTable_SkipType (TypeSym))))) && (! (SymbolTable_IsUnknown (SymbolTable_SkipType (ParamIType)))))
1653 : : {
1654 : : /* Different parameter types. */
1655 : 18 : ParameterError ((const char *) "declaration in the %s differs from the %s, {%%2N} parameter is inconsistant, %s", 79, (const char *) "the parameter {%3EHa} was declared with a different type", 56, (const char *) "the parameter {%3EVa} was declared with a different type", 56, ParamTotal+i, ProcSym, curkind, prevkind);
1656 : : }
1657 : : }
1658 : 1285332 : i += 1;
1659 : 1285332 : pi -= 1;
1660 : : }
1661 : 1019558 : }
1662 : :
1663 : :
1664 : : /*
1665 : : RemoveFPParameters - remove the FPSection parameters from the stack and
1666 : : increment the param total with the NoOfIds.
1667 : :
1668 : : The Stack:
1669 : :
1670 : : Entry Exit
1671 : :
1672 : : Ptr ->
1673 : : +------------+
1674 : : | ParamTotal |
1675 : : |------------|
1676 : : | TypeSym |
1677 : : |------------|
1678 : : | Array/Nul |
1679 : : |------------|
1680 : : | NoOfIds |
1681 : : |------------|
1682 : : | Id 1 |
1683 : : |------------|
1684 : : . .
1685 : : . .
1686 : : . .
1687 : : |------------|
1688 : : | Id n | <- Ptr
1689 : : |------------| +------------+
1690 : : | Var / Nul | | ParamTotal |
1691 : : |------------| |------------|
1692 : : | ProcSym | | ProcSym |
1693 : : |------------| |------------|
1694 : : */
1695 : :
1696 : 5085803 : static void RemoveFPParameters (void)
1697 : : {
1698 : 5085803 : unsigned int ParamTotal;
1699 : 5085803 : unsigned int Array;
1700 : 5085803 : unsigned int TypeSym;
1701 : 5085803 : unsigned int NoOfIds;
1702 : 5085803 : unsigned int ProcSym;
1703 : :
1704 : 5085803 : M2Quads_PopT (&ParamTotal);
1705 : 5085803 : M2Quads_PopT (&TypeSym);
1706 : 5085803 : M2Quads_PopT (&Array);
1707 : 10171606 : M2Debug_Assert ((Array == M2Reserved_ArrayTok) || (Array == M2Reserved_NulTok));
1708 : 5085803 : M2Quads_PopT (&NoOfIds);
1709 : 5085803 : ProcSym = static_cast<unsigned int> (M2Quads_OperandT (NoOfIds+2));
1710 : 5085803 : M2Debug_Assert (SymbolTable_IsProcedure (ProcSym));
1711 : 5085803 : M2Quads_PopN (NoOfIds+1); /* +1 for the Var/Nul. */
1712 : 5085803 : M2Quads_PushT (ParamTotal+NoOfIds); /* +1 for the Var/Nul. */
1713 : 5085803 : M2Quads_Annotate ((const char *) "%1d||running total of no. of parameters", 39);
1714 : 5085803 : M2Debug_Assert (SymbolTable_IsProcedure (M2Quads_OperandT (2)));
1715 : 5085803 : }
1716 : :
1717 : :
1718 : : /*
1719 : : ParameterError - create two error strings chained together.
1720 : : */
1721 : :
1722 : 60 : static void ParameterError (const char *FmtHeader_, unsigned int _FmtHeader_high, const char *PrevDesc_, unsigned int _PrevDesc_high, const char *CurDesc_, unsigned int _CurDesc_high, unsigned int ParamNo, unsigned int ProcSym, SymbolTable_ProcedureKind curkind, SymbolTable_ProcedureKind prevkind)
1723 : : {
1724 : 60 : unsigned int PrevParam;
1725 : 60 : unsigned int CurParam;
1726 : 60 : DynamicStrings_String CurStr;
1727 : 60 : DynamicStrings_String PrevStr;
1728 : 60 : DynamicStrings_String Msg;
1729 : 60 : DynamicStrings_String CurKindStr;
1730 : 60 : DynamicStrings_String PrevKindStr;
1731 : 60 : char FmtHeader[_FmtHeader_high+1];
1732 : 60 : char PrevDesc[_PrevDesc_high+1];
1733 : 60 : char CurDesc[_CurDesc_high+1];
1734 : :
1735 : : /* make a local copy of each unbounded array. */
1736 : 60 : memcpy (FmtHeader, FmtHeader_, _FmtHeader_high+1);
1737 : 60 : memcpy (PrevDesc, PrevDesc_, _PrevDesc_high+1);
1738 : 60 : memcpy (CurDesc, CurDesc_, _CurDesc_high+1);
1739 : :
1740 : 120 : CurParam = SymbolTable_GetNthParam (ProcSym, curkind, ParamNo);
1741 : 60 : CurKindStr = SymbolTable_GetProcedureKindDesc (curkind);
1742 : 60 : PrevKindStr = SymbolTable_GetProcedureKindDesc (prevkind);
1743 : 60 : PrevParam = SymbolTable_GetNthParam (ProcSym, prevkind, ParamNo);
1744 : 60 : PrevStr = DynamicStrings_InitString ((const char *) PrevDesc, _PrevDesc_high);
1745 : 60 : CurStr = DynamicStrings_InitString ((const char *) CurDesc, _CurDesc_high);
1746 : 60 : Msg = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) FmtHeader, _FmtHeader_high)), (const unsigned char *) &CurKindStr, (sizeof (CurKindStr)-1), (const unsigned char *) &PrevKindStr, (sizeof (PrevKindStr)-1), (const unsigned char *) &PrevStr, (sizeof (PrevStr)-1));
1747 : 60 : M2MetaError_MetaErrorString3 (Msg, ProcSym, ParamNo, PrevParam);
1748 : 60 : Msg = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) FmtHeader, _FmtHeader_high)), (const unsigned char *) &CurKindStr, (sizeof (CurKindStr)-1), (const unsigned char *) &PrevKindStr, (sizeof (PrevKindStr)-1), (const unsigned char *) &CurStr, (sizeof (CurStr)-1));
1749 : 60 : M2MetaError_MetaErrorString3 (Msg, ProcSym, ParamNo, CurParam);
1750 : 60 : }
1751 : :
1752 : :
1753 : : /*
1754 : : ParameterMismatch - generate a parameter mismatch error between the current
1755 : : declaration at tok and a previous ProcSym declaration.
1756 : : NoOfPar is the current number of parameters.
1757 : : */
1758 : :
1759 : 18 : static void ParameterMismatch (unsigned int tok, unsigned int ProcSym, unsigned int NoOfPar, SymbolTable_ProcedureKind prevkind, SymbolTable_ProcedureKind curkind)
1760 : : {
1761 : 18 : DynamicStrings_String MsgCurrent;
1762 : 18 : DynamicStrings_String MsgPrev;
1763 : 18 : DynamicStrings_String CompCur;
1764 : 18 : DynamicStrings_String CompPrev;
1765 : 18 : DynamicStrings_String CurDesc;
1766 : 18 : DynamicStrings_String PrevDesc;
1767 : :
1768 : 18 : CurDesc = SymbolTable_GetProcedureKindDesc (curkind);
1769 : 18 : PrevDesc = SymbolTable_GetProcedureKindDesc (prevkind);
1770 : 18 : CompPrev = GetComparison (SymbolTable_NoOfParam (ProcSym, prevkind), NoOfPar);
1771 : 18 : CompCur = GetComparison (NoOfPar, SymbolTable_NoOfParam (ProcSym, prevkind));
1772 : 18 : MsgCurrent = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "the %s for {%%1ad} has %s parameters than the %s", 48)), (const unsigned char *) &CurDesc, (sizeof (CurDesc)-1), (const unsigned char *) &CompCur, (sizeof (CompCur)-1), (const unsigned char *) &PrevDesc, (sizeof (PrevDesc)-1));
1773 : 18 : MsgPrev = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "the %s for {%%1ad} has %s parameters than the %s", 48)), (const unsigned char *) &PrevDesc, (sizeof (PrevDesc)-1), (const unsigned char *) &CompPrev, (sizeof (CompPrev)-1), (const unsigned char *) &CurDesc, (sizeof (CurDesc)-1));
1774 : 18 : M2MetaError_MetaErrorStringT1 (SymbolTable_GetProcedureDeclaredTok (ProcSym, prevkind), MsgPrev, ProcSym);
1775 : 18 : M2MetaError_MetaErrorStringT1 (tok, MsgCurrent, ProcSym);
1776 : 18 : CurDesc = DynamicStrings_KillString (CurDesc);
1777 : 18 : PrevDesc = DynamicStrings_KillString (PrevDesc);
1778 : 18 : CompCur = DynamicStrings_KillString (CompCur);
1779 : 18 : CompPrev = DynamicStrings_KillString (CompPrev);
1780 : 18 : }
1781 : :
1782 : :
1783 : : /*
1784 : : GetComparison - return a simple description from the result of
1785 : : a comparison between left and right.
1786 : : */
1787 : :
1788 : 36 : static DynamicStrings_String GetComparison (unsigned int left, unsigned int right)
1789 : : {
1790 : 36 : if (left < right)
1791 : : {
1792 : 18 : return DynamicStrings_InitString ((const char *) "fewer", 5);
1793 : : }
1794 : 18 : else if (left > right)
1795 : : {
1796 : : /* avoid dangling else. */
1797 : 18 : return DynamicStrings_InitString ((const char *) "more", 4);
1798 : : }
1799 : : else
1800 : : {
1801 : : /* avoid dangling else. */
1802 : 0 : return DynamicStrings_InitString ((const char *) "same", 4);
1803 : : }
1804 : : /* static analysis guarentees a RETURN statement will be used before here. */
1805 : : __builtin_unreachable ();
1806 : : }
1807 : :
1808 : :
1809 : : /*
1810 : : ReturnTypeMismatch - generate two errors showing the return type mismatches between
1811 : : ProcSym and ReturnType at procedure location tok.
1812 : : */
1813 : :
1814 : 6 : static void ReturnTypeMismatch (unsigned int curtok, unsigned int ProcSym, unsigned int CurRetType, unsigned int curtypetok, SymbolTable_ProcedureKind curkind, SymbolTable_ProcedureKind prevkind, unsigned int PrevRetType)
1815 : : {
1816 : 6 : unsigned int prevtok;
1817 : 6 : DynamicStrings_String CurDesc;
1818 : 6 : DynamicStrings_String PrevDesc;
1819 : 6 : DynamicStrings_String MsgCurrent;
1820 : 6 : DynamicStrings_String MsgPrev;
1821 : :
1822 : 6 : CurDesc = SymbolTable_GetProcedureKindDesc (curkind);
1823 : 6 : PrevDesc = SymbolTable_GetProcedureKindDesc (prevkind);
1824 : 6 : prevtok = SymbolTable_GetProcedureDeclaredTok (ProcSym, prevkind);
1825 : 6 : if (CurRetType == SymbolTable_NulSym)
1826 : : {
1827 : 6 : MsgCurrent = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "there is no return type for {%%1ad} specified in the %s whereas a return type is specified in the %s", 100)), (const unsigned char *) &CurDesc, (sizeof (CurDesc)-1), (const unsigned char *) &PrevDesc, (sizeof (PrevDesc)-1));
1828 : 6 : MsgPrev = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "there is no return type for {%%1ad} specified in the %s whereas a return type is specified in the %s", 100)), (const unsigned char *) &CurDesc, (sizeof (CurDesc)-1), (const unsigned char *) &PrevDesc, (sizeof (PrevDesc)-1));
1829 : 6 : prevtok = SymbolTable_GetReturnTypeTok (ProcSym, prevkind);
1830 : : }
1831 : 0 : else if (PrevRetType == SymbolTable_NulSym)
1832 : : {
1833 : : /* avoid dangling else. */
1834 : 0 : MsgCurrent = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "there is no return type for {%%1ad} specified in the %s whereas a return type is specified in the %s", 100)), (const unsigned char *) &PrevDesc, (sizeof (PrevDesc)-1), (const unsigned char *) &CurDesc, (sizeof (CurDesc)-1));
1835 : 0 : MsgPrev = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "there is no return type for {%%1ad} specified in the %s whereas a return type is specified in the %s", 100)), (const unsigned char *) &PrevDesc, (sizeof (PrevDesc)-1), (const unsigned char *) &CurDesc, (sizeof (CurDesc)-1));
1836 : 0 : curtok = curtypetok;
1837 : : }
1838 : : else
1839 : : {
1840 : : /* avoid dangling else. */
1841 : 0 : MsgCurrent = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "the return type for {%%1ad} specified in the %s differs in the %s", 65)), (const unsigned char *) &CurDesc, (sizeof (CurDesc)-1), (const unsigned char *) &PrevDesc, (sizeof (PrevDesc)-1));
1842 : 0 : MsgPrev = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "the return type for {%%1ad} specified in the %s differs in the %s", 65)), (const unsigned char *) &CurDesc, (sizeof (CurDesc)-1), (const unsigned char *) &PrevDesc, (sizeof (PrevDesc)-1));
1843 : 0 : curtok = curtypetok;
1844 : 0 : prevtok = SymbolTable_GetReturnTypeTok (ProcSym, prevkind);
1845 : : }
1846 : 6 : M2MetaError_MetaErrorStringT1 (curtok, MsgCurrent, ProcSym);
1847 : 6 : M2MetaError_MetaErrorStringT1 (prevtok, MsgPrev, ProcSym);
1848 : 6 : }
1849 : :
1850 : :
1851 : : /*
1852 : : CheckOptFunction - checks to see whether the optional return value
1853 : : has been set before and if it differs it will
1854 : : generate an error message. It will set the
1855 : : new value to isopt.
1856 : : */
1857 : :
1858 : 1319358 : static void CheckOptFunction (unsigned int tok, unsigned int sym, SymbolTable_ProcedureKind kind, bool isopt)
1859 : : {
1860 : 1319358 : SymbolTable_ProcedureKind other;
1861 : :
1862 : 1319358 : if ((SymbolTable_GetType (sym)) != SymbolTable_NulSym)
1863 : : {
1864 : 5277432 : for (other=SymbolTable_ProperProcedure; other<=SymbolTable_DefProcedure; other= static_cast<SymbolTable_ProcedureKind>(static_cast<int>(other+1)))
1865 : : {
1866 : : /* Procedure sym has been declared as a function. */
1867 : 3958074 : if ((kind != other) && (SymbolTable_GetProcedureParametersDefined (sym, other)))
1868 : : {
1869 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
1870 : 274966 : if ((SymbolTable_IsReturnOptional (sym, kind)) && ! isopt)
1871 : : {
1872 : 0 : M2MetaError_MetaErrorT1 (tok, (const char *) "procedure {%1Ea} is not declared with an optional return type here", 66, sym);
1873 : 0 : M2MetaError_MetaErrorT1 (SymbolTable_GetReturnTypeTok (sym, kind), (const char *) "previously procedure {%1Ea} was declared with an optional return type", 69, sym);
1874 : : }
1875 : 274966 : else if ((! (SymbolTable_IsReturnOptional (sym, kind))) && isopt)
1876 : : {
1877 : : /* avoid dangling else. */
1878 : 0 : M2MetaError_MetaErrorT1 (tok, (const char *) "procedure {%1Ea} is declared with an optional return type here", 62, sym);
1879 : 0 : M2MetaError_MetaErrorT1 (SymbolTable_GetReturnTypeTok (sym, kind), (const char *) "previously procedure {%1Ea} was declared without an optional return type", 72, sym);
1880 : : }
1881 : : }
1882 : : }
1883 : : }
1884 : 1319358 : SymbolTable_SetReturnOptional (sym, kind, isopt);
1885 : 1319358 : }
1886 : :
1887 : :
1888 : : /*
1889 : : CheckProcedure - checks to see that the top of stack procedure
1890 : : has not been declared as a procedure function.
1891 : :
1892 : : The Stack:
1893 : :
1894 : : Entry Exit
1895 : :
1896 : : Ptr -> <- Ptr
1897 : : +------------+ +------------+
1898 : : | ProcSym | | ProcSym |
1899 : : |------------| |------------|
1900 : : */
1901 : :
1902 : 2733550 : static void CheckProcedureReturn (unsigned int RetType, unsigned int typetok)
1903 : : {
1904 : 2733550 : SymbolTable_ProcedureKind curkind;
1905 : 2733550 : SymbolTable_ProcedureKind kind;
1906 : 2733550 : unsigned int tok;
1907 : 2733550 : unsigned int PrevRetType;
1908 : 2733550 : unsigned int ProcSym;
1909 : :
1910 : 2733550 : M2Quads_PopTtok (&ProcSym, &tok);
1911 : 2733550 : M2Quads_PushTtok (ProcSym, tok);
1912 : 2733550 : M2Quads_Annotate ((const char *) "%1s(%1d)||procedure start symbol", 32);
1913 : 2733550 : if (SymbolTable_IsProcedure (ProcSym))
1914 : : {
1915 : 2692553 : curkind = SymbolTable_GetProcedureKind (ProcSym, tok);
1916 : 13462765 : for (kind=SymbolTable_ProperProcedure; kind<=SymbolTable_DefProcedure; kind= static_cast<SymbolTable_ProcedureKind>(static_cast<int>(kind+1)))
1917 : : {
1918 : : /* Check against any previously declared kinds. */
1919 : 8077659 : if ((kind != curkind) && (SymbolTable_GetProcedureParametersDefined (ProcSym, kind)))
1920 : : {
1921 : 589750 : PrevRetType = SymbolTable_GetType (ProcSym);
1922 : 589750 : if (PrevRetType != RetType)
1923 : : {
1924 : 6 : ReturnTypeMismatch (tok, ProcSym, RetType, typetok, curkind, kind, PrevRetType);
1925 : : }
1926 : : }
1927 : : }
1928 : 2692553 : SymbolTable_PutFunction (tok, ProcSym, curkind, RetType);
1929 : : }
1930 : 2733550 : }
1931 : :
1932 : :
1933 : : /*
1934 : : HandleRecordFieldPragmas -
1935 : :
1936 : : Entry Exit
1937 : : ===== ====
1938 : :
1939 : : Ptr -> <- Ptr
1940 : :
1941 : : |-------------| |-------------|
1942 : : | Const1 | | Const1 |
1943 : : |-------------| |-------------|
1944 : : | PragmaName1 | | PragmaName1 |
1945 : : |-------------| |-------------|
1946 : : */
1947 : :
1948 : 261852 : static void HandleRecordFieldPragmas (unsigned int record, unsigned int field, unsigned int n)
1949 : : {
1950 : 261852 : bool seenAlignment;
1951 : 261852 : unsigned int defaultAlignment;
1952 : 261852 : unsigned int sym;
1953 : 261852 : unsigned int i;
1954 : 261852 : NameKey_Name name;
1955 : 261852 : DynamicStrings_String s;
1956 : :
1957 : 261852 : seenAlignment = false;
1958 : 261852 : defaultAlignment = SymbolTable_GetDefaultRecordFieldAlignment (record);
1959 : 261852 : i = 1;
1960 : 523716 : while (i <= n)
1961 : : {
1962 : 12 : name = static_cast<NameKey_Name> (M2Quads_OperandT (i*2));
1963 : 12 : sym = static_cast<unsigned int> (M2Quads_OperandT ((i*2)-1));
1964 : 12 : if (name == (NameKey_MakeKey ((const char *) "unused", 6)))
1965 : : {
1966 : 0 : if (sym == SymbolTable_NulSym)
1967 : : {
1968 : 0 : SymbolTable_PutUnused (field);
1969 : : }
1970 : : else
1971 : : {
1972 : 0 : M2Error_WriteFormat0 ((const char *) "not expecting pragma 'unused' to contain an expression", 54);
1973 : : }
1974 : : }
1975 : 12 : else if (name == (NameKey_MakeKey ((const char *) "bytealignment", 13)))
1976 : : {
1977 : : /* avoid dangling else. */
1978 : 12 : if (sym == SymbolTable_NulSym)
1979 : : {
1980 : 0 : M2Error_WriteFormat0 ((const char *) "expecting an expression with the pragma 'bytealignment'", 55);
1981 : : }
1982 : : else
1983 : : {
1984 : 12 : SymbolTable_PutAlignment (field, sym);
1985 : 12 : seenAlignment = true;
1986 : : }
1987 : : }
1988 : : else
1989 : : {
1990 : : /* avoid dangling else. */
1991 : 0 : s = DynamicStrings_InitString ((const char *) "cannot use pragma '", 19);
1992 : 0 : s = DynamicStrings_ConCat (s, DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (name))));
1993 : 0 : s = DynamicStrings_ConCat (s, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "' on record field {%1ad}", 24)));
1994 : 0 : M2MetaError_MetaErrorString1 (s, field);
1995 : : }
1996 : 12 : i += 1;
1997 : : }
1998 : 261852 : if (! seenAlignment && (defaultAlignment != SymbolTable_NulSym))
1999 : : {
2000 : 108 : SymbolTable_PutAlignment (field, defaultAlignment);
2001 : : }
2002 : 261852 : }
2003 : :
2004 : :
2005 : : /*
2006 : : SaveRememberedConstructor -
2007 : : */
2008 : :
2009 : 0 : static void SaveRememberedConstructor (void)
2010 : : {
2011 : 0 : }
2012 : :
2013 : :
2014 : : /*
2015 : : GetSeenString - returns a string corresponding to, s.
2016 : : */
2017 : :
2018 : 0 : static DynamicStrings_String GetSeenString (M2Const_constType s)
2019 : : {
2020 : 0 : switch (s)
2021 : : {
2022 : 0 : case M2Const_unknown:
2023 : 0 : return DynamicStrings_InitString ((const char *) "unknown", 7);
2024 : 0 : break;
2025 : :
2026 : 0 : case M2Const_set:
2027 : 0 : return DynamicStrings_InitString ((const char *) "SET", 3);
2028 : 0 : break;
2029 : :
2030 : 0 : case M2Const_str:
2031 : 0 : return DynamicStrings_InitString ((const char *) "string", 6);
2032 : 0 : break;
2033 : :
2034 : 0 : case M2Const_constructor:
2035 : 0 : return DynamicStrings_InitString ((const char *) "constructor", 11);
2036 : 0 : break;
2037 : :
2038 : 0 : case M2Const_array:
2039 : 0 : return DynamicStrings_InitString ((const char *) "ARRAY", 5);
2040 : 0 : break;
2041 : :
2042 : 0 : case M2Const_cast:
2043 : 0 : return DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (SymbolTable_GetSymName (castType)));
2044 : 0 : break;
2045 : :
2046 : 0 : case M2Const_boolean:
2047 : 0 : return DynamicStrings_InitString ((const char *) "BOOLEAN", 7);
2048 : 0 : break;
2049 : :
2050 : 0 : case M2Const_ztype:
2051 : 0 : return DynamicStrings_InitString ((const char *) "Z type", 6);
2052 : 0 : break;
2053 : :
2054 : 0 : case M2Const_rtype:
2055 : 0 : return DynamicStrings_InitString ((const char *) "R type", 6);
2056 : 0 : break;
2057 : :
2058 : 0 : case M2Const_ctype:
2059 : 0 : return DynamicStrings_InitString ((const char *) "C type", 6);
2060 : 0 : break;
2061 : :
2062 : 0 : case M2Const_procedure:
2063 : 0 : return DynamicStrings_InitString ((const char *) "PROCEDURE", 9);
2064 : 0 : break;
2065 : :
2066 : :
2067 : 0 : default:
2068 : 0 : M2Error_InternalError ((const char *) "unexpected value of type", 24);
2069 : : break;
2070 : : }
2071 : : return static_cast<DynamicStrings_String> (NULL);
2072 : : /* static analysis guarentees a RETURN statement will be used before here. */
2073 : : __builtin_unreachable ();
2074 : : }
2075 : :
2076 : :
2077 : : /*
2078 : : SetTypeTo - attempts to set, type, to, s.
2079 : : */
2080 : :
2081 : 35117 : static void SetTypeTo (M2Const_constType s)
2082 : : {
2083 : 35117 : DynamicStrings_String s1;
2084 : 35117 : DynamicStrings_String s2;
2085 : 35117 : DynamicStrings_String s3;
2086 : :
2087 : 35117 : if (type == M2Const_unknown)
2088 : : {
2089 : 34575 : type = s;
2090 : : }
2091 : : /* leave it alone */
2092 : 542 : else if ((type == M2Const_constructor) && (s != M2Const_str))
2093 : : {
2094 : : /* avoid dangling else. */
2095 : 308 : type = s;
2096 : : }
2097 : 234 : else if ((s == M2Const_constructor) && ((type == M2Const_array) || (type == M2Const_set)))
2098 : : {
2099 : : /* avoid dangling else. */
2100 : : }
2101 : 222 : else if (type != s)
2102 : : {
2103 : : /* avoid dangling else. */
2104 : 0 : s1 = GetSeenString (type);
2105 : 0 : s2 = GetSeenString (s);
2106 : 0 : s3 = FormatStrings_Sprintf2 (DynamicStrings_InitString ((const char *) "cannot create a %s constant together with a %s constant", 55), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) &s2, (sizeof (s2)-1));
2107 : 0 : M2Error_ErrorStringAt (s3, M2LexBuf_GetTokenNo ());
2108 : 0 : s1 = DynamicStrings_KillString (s1);
2109 : 0 : s2 = DynamicStrings_KillString (s2);
2110 : : }
2111 : 35117 : }
2112 : :
2113 : :
2114 : : /*
2115 : : BlockStart - tokno is the module/procedure/implementation/definition token
2116 : : */
2117 : :
2118 : 66127 : extern "C" void P2SymBuild_BlockStart (unsigned int tokno)
2119 : : {
2120 : 66127 : PushBlock (tokno);
2121 : 66127 : }
2122 : :
2123 : :
2124 : : /*
2125 : : BlockEnd - declare module ctor/init/fini/dep procedures.
2126 : : */
2127 : :
2128 : 66109 : extern "C" void P2SymBuild_BlockEnd (unsigned int tokno)
2129 : : {
2130 : 66109 : curBeginTok = propageteTokenPosition (curStartTok, curBeginTok);
2131 : 66109 : curFinallyTok = propageteTokenPosition (tokno, curFinallyTok);
2132 : 66109 : M2Debug_Assert (curModuleSym != SymbolTable_NulSym);
2133 : 66109 : SymbolTable_MakeModuleCtor (curStartTok, curBeginTok, curFinallyTok, curModuleSym);
2134 : 66109 : PopBlock ();
2135 : 66109 : }
2136 : :
2137 : :
2138 : : /*
2139 : : BlockBegin - assign curBeginTok to tokno.
2140 : : */
2141 : :
2142 : 36859 : extern "C" void P2SymBuild_BlockBegin (unsigned int tokno)
2143 : : {
2144 : 36859 : curBeginTok = tokno;
2145 : 36859 : }
2146 : :
2147 : :
2148 : : /*
2149 : : BlockFinally - assign curFinallyTok to tokno.
2150 : : */
2151 : :
2152 : 5764 : extern "C" void P2SymBuild_BlockFinally (unsigned int tokno)
2153 : : {
2154 : 5764 : curFinallyTok = tokno;
2155 : 5764 : }
2156 : :
2157 : 120929 : extern "C" void P2SymBuild_P2StartBuildDefModule (void)
2158 : : {
2159 : 120929 : NameKey_Name name;
2160 : 120929 : unsigned int ModuleSym;
2161 : 120929 : unsigned int tokno;
2162 : :
2163 : : /*
2164 : : StartBuildDefinitionModule - Creates a definition module and starts
2165 : : a new scope.
2166 : :
2167 : : he Stack is expected:
2168 : :
2169 : : Entry Exit
2170 : :
2171 : : Ptr -> <- Ptr
2172 : : +------------+ +-----------+
2173 : : | NameStart | | NameStart |
2174 : : |------------| |-----------|
2175 : :
2176 : : */
2177 : 120929 : M2Quads_PopTtok (&name, &tokno);
2178 : 120929 : ModuleSym = M2Batch_MakeDefinitionSource (tokno, name);
2179 : 120929 : curModuleSym = ModuleSym;
2180 : 120929 : SymbolTable_SetCurrentModule (ModuleSym);
2181 : 120929 : SymbolTable_SetFileModule (ModuleSym);
2182 : 120929 : SymbolTable_StartScope (ModuleSym);
2183 : 120929 : M2Debug_Assert (SymbolTable_IsDefImp (ModuleSym));
2184 : 120929 : M2Debug_Assert (M2Comp_CompilingDefinitionModule ());
2185 : 120929 : M2Quads_PushT (name);
2186 : 120929 : M2Quads_Annotate ((const char *) "%1n||definition module name", 27);
2187 : 120929 : M2Error_EnterDefinitionScope (name);
2188 : 120929 : }
2189 : :
2190 : 120929 : extern "C" void P2SymBuild_P2EndBuildDefModule (void)
2191 : : {
2192 : 120929 : NameKey_Name NameStart;
2193 : 120929 : NameKey_Name NameEnd;
2194 : :
2195 : : /*
2196 : : EndBuildDefinitionModule - Destroys the definition module scope and
2197 : : checks for correct name.
2198 : :
2199 : : The Stack is expected:
2200 : :
2201 : : Entry Exit
2202 : :
2203 : : Ptr ->
2204 : : +------------+ +-----------+
2205 : : | NameEnd | | |
2206 : : |------------| |-----------|
2207 : : | NameStart | | | <- Ptr
2208 : : |------------| |-----------|
2209 : : */
2210 : 120929 : M2Debug_Assert (M2Comp_CompilingDefinitionModule ());
2211 : 120929 : SymbolTable_CheckForUndeclaredExports (SymbolTable_GetCurrentModule ());
2212 : 120929 : SymbolTable_EndScope ();
2213 : 120929 : M2Quads_PopT (&NameStart);
2214 : 120929 : M2Quads_PopT (&NameEnd);
2215 : 120929 : if (Debugging)
2216 : : {
2217 : : M2Printf_printf0 ((const char *) "pass 2: ", 8);
2218 : : SymbolTable_DisplayTrees (SymbolTable_GetCurrentModule ());
2219 : : }
2220 : 120929 : if (NameStart != NameEnd)
2221 : : {
2222 : 0 : M2Error_WriteFormat2 ((const char *) "inconsistant definition module name, module began as (%a) and ended with (%a)", 77, (const unsigned char *) &NameStart, (sizeof (NameStart)-1), (const unsigned char *) &NameEnd, (sizeof (NameEnd)-1));
2223 : : }
2224 : 120929 : M2Error_LeaveErrorScope ();
2225 : 120929 : }
2226 : :
2227 : 54223 : extern "C" void P2SymBuild_P2StartBuildImplementationModule (void)
2228 : : {
2229 : 54223 : NameKey_Name name;
2230 : 54223 : unsigned int ModuleSym;
2231 : 54223 : unsigned int tokno;
2232 : :
2233 : : /*
2234 : : StartBuildImplementationModule - Creates an implementation module and starts
2235 : : a new scope.
2236 : :
2237 : : The Stack is expected:
2238 : :
2239 : : Entry Exit
2240 : :
2241 : : Ptr -> <- Ptr
2242 : : +------------+ +-----------+
2243 : : | NameStart | | NameStart |
2244 : : |------------| |-----------|
2245 : :
2246 : : */
2247 : 54223 : M2Quads_PopTtok (&name, &tokno);
2248 : 54223 : ModuleSym = M2Batch_MakeImplementationSource (tokno, name);
2249 : 54223 : curModuleSym = ModuleSym;
2250 : 54223 : SymbolTable_SetCurrentModule (ModuleSym);
2251 : 54223 : SymbolTable_SetFileModule (ModuleSym);
2252 : 54223 : SymbolTable_StartScope (ModuleSym);
2253 : 54223 : M2Debug_Assert (SymbolTable_IsDefImp (ModuleSym));
2254 : 54223 : M2Debug_Assert (M2Comp_CompilingImplementationModule ());
2255 : 54223 : M2Quads_PushT (name);
2256 : 54223 : M2Quads_Annotate ((const char *) "%1n||implementation module name", 31);
2257 : 54223 : M2Error_EnterImplementationScope (name);
2258 : 54223 : }
2259 : :
2260 : 54217 : extern "C" void P2SymBuild_P2EndBuildImplementationModule (void)
2261 : : {
2262 : 54217 : NameKey_Name NameStart;
2263 : 54217 : NameKey_Name NameEnd;
2264 : :
2265 : : /*
2266 : : EndBuildImplementationModule - Destroys the implementation module scope and
2267 : : checks for correct name.
2268 : :
2269 : : The Stack is expected:
2270 : :
2271 : : Entry Exit
2272 : :
2273 : : Ptr ->
2274 : : +------------+ +-----------+
2275 : : | NameEnd | | |
2276 : : |------------| |-----------|
2277 : : | NameStart | | | <- Ptr
2278 : : |------------| |-----------|
2279 : : */
2280 : 54217 : M2Debug_Assert (M2Comp_CompilingImplementationModule ());
2281 : 54217 : SymbolTable_CheckForUnImplementedExports ();
2282 : 54217 : SymbolTable_EndScope ();
2283 : 54217 : M2Quads_PopT (&NameStart);
2284 : 54217 : M2Quads_PopT (&NameEnd);
2285 : 54217 : if (NameStart != NameEnd)
2286 : : {
2287 : 0 : M2Error_WriteFormat1 ((const char *) "inconsistant implementation module name %a", 42, (const unsigned char *) &NameStart, (sizeof (NameStart)-1));
2288 : : }
2289 : 54217 : M2Error_LeaveErrorScope ();
2290 : 54217 : }
2291 : :
2292 : 11484 : extern "C" void P2SymBuild_P2StartBuildProgramModule (void)
2293 : : {
2294 : 11484 : NameKey_Name name;
2295 : 11484 : unsigned int ModuleSym;
2296 : 11484 : unsigned int tokno;
2297 : :
2298 : : /*
2299 : : StartBuildProgramModule - Creates a program module and starts
2300 : : a new scope.
2301 : :
2302 : : The Stack is expected:
2303 : :
2304 : : Entry Exit
2305 : :
2306 : : Ptr -> <- Ptr
2307 : : +------------+ +-----------+
2308 : : | NameStart | | NameStart |
2309 : : |------------| |-----------|
2310 : :
2311 : : */
2312 : 11484 : M2Quads_PopTtok (&name, &tokno);
2313 : 11484 : ModuleSym = M2Batch_MakeProgramSource (tokno, name);
2314 : 11484 : curModuleSym = ModuleSym;
2315 : 11484 : SymbolTable_SetCurrentModule (ModuleSym);
2316 : 11484 : SymbolTable_SetFileModule (ModuleSym);
2317 : 11484 : SymbolTable_StartScope (ModuleSym);
2318 : 11484 : M2Debug_Assert (M2Comp_CompilingProgramModule ());
2319 : 11484 : M2Debug_Assert (! (SymbolTable_IsDefImp (ModuleSym)));
2320 : 11484 : M2Quads_PushT (name);
2321 : 11484 : M2Quads_Annotate ((const char *) "%1n||program module name", 24);
2322 : 11484 : M2Error_EnterProgramScope (name);
2323 : 11484 : }
2324 : :
2325 : 11472 : extern "C" void P2SymBuild_P2EndBuildProgramModule (void)
2326 : : {
2327 : 11472 : NameKey_Name NameStart;
2328 : 11472 : NameKey_Name NameEnd;
2329 : :
2330 : : /*
2331 : : EndBuildProgramModule - Destroys the program module scope and
2332 : : checks for correct name.
2333 : :
2334 : : The Stack is expected:
2335 : :
2336 : : Entry Exit
2337 : :
2338 : : Ptr ->
2339 : : +------------+ +-----------+
2340 : : | NameEnd | | |
2341 : : |------------| |-----------|
2342 : : | NameStart | | | <- Ptr
2343 : : |------------| |-----------|
2344 : : */
2345 : 11472 : M2Debug_Assert (M2Comp_CompilingProgramModule ());
2346 : 11472 : SymbolTable_CheckForUndeclaredExports (SymbolTable_GetCurrentModule ()); /* Not really allowed exports here though! */
2347 : 11472 : SymbolTable_EndScope (); /* Not really allowed exports here though! */
2348 : 11472 : M2Quads_PopT (&NameStart);
2349 : 11472 : M2Quads_PopT (&NameEnd);
2350 : 11472 : if (Debugging)
2351 : : {
2352 : : M2Printf_printf0 ((const char *) "pass 2: ", 8);
2353 : : SymbolTable_DisplayTrees (SymbolTable_GetCurrentModule ());
2354 : : }
2355 : 11472 : if (NameStart != NameEnd)
2356 : : {
2357 : 0 : M2Error_WriteFormat2 ((const char *) "inconsistant program module name %a does not match %a", 53, (const unsigned char *) &NameStart, (sizeof (NameStart)-1), (const unsigned char *) &NameEnd, (sizeof (NameEnd)-1));
2358 : : }
2359 : 11472 : M2Error_LeaveErrorScope ();
2360 : 11472 : }
2361 : :
2362 : :
2363 : : /*
2364 : : StartBuildInnerModule - Creates an Inner module and starts
2365 : : a new scope.
2366 : :
2367 : : The Stack is expected:
2368 : :
2369 : : Entry Exit
2370 : :
2371 : : Ptr -> <- Ptr
2372 : : +------------+ +-----------+
2373 : : | NameStart | | NameStart |
2374 : : |------------| |-----------|
2375 : :
2376 : : */
2377 : :
2378 : 420 : extern "C" void P2SymBuild_StartBuildInnerModule (void)
2379 : : {
2380 : 420 : NameKey_Name name;
2381 : 420 : unsigned int tok;
2382 : 420 : unsigned int ModuleSym;
2383 : :
2384 : 420 : M2Quads_PopTtok (&name, &tok);
2385 : 420 : ModuleSym = SymbolTable_GetDeclareSym (tok, name);
2386 : 420 : curModuleSym = ModuleSym;
2387 : 420 : SymbolTable_StartScope (ModuleSym);
2388 : 420 : M2Debug_Assert (! (SymbolTable_IsDefImp (ModuleSym)));
2389 : 420 : M2Quads_PushTtok (name, tok);
2390 : 420 : M2Quads_Annotate ((const char *) "%1n||inner module name", 22);
2391 : 420 : M2Error_EnterModuleScope (name);
2392 : 420 : }
2393 : :
2394 : :
2395 : : /*
2396 : : EndBuildInnerModule - Destroys the Inner module scope and
2397 : : checks for correct name.
2398 : :
2399 : : The Stack is expected:
2400 : :
2401 : : Entry Exit
2402 : :
2403 : : Ptr ->
2404 : : +------------+ +-----------+
2405 : : | NameEnd | | |
2406 : : |------------| |-----------|
2407 : : | NameStart | | | <- Ptr
2408 : : |------------| |-----------|
2409 : : */
2410 : :
2411 : 420 : extern "C" void P2SymBuild_EndBuildInnerModule (void)
2412 : : {
2413 : 420 : NameKey_Name NameStart;
2414 : 420 : NameKey_Name NameEnd;
2415 : :
2416 : 420 : SymbolTable_CheckForUndeclaredExports (SymbolTable_GetCurrentModule ());
2417 : 420 : SymbolTable_EndScope ();
2418 : 420 : M2Quads_PopT (&NameStart);
2419 : 420 : M2Quads_PopT (&NameEnd);
2420 : 420 : if (NameStart != NameEnd)
2421 : : {
2422 : 0 : M2Error_WriteFormat2 ((const char *) "inconsistant inner module name %a does not match %a", 51, (const unsigned char *) &NameStart, (sizeof (NameStart)-1), (const unsigned char *) &NameEnd, (sizeof (NameEnd)-1));
2423 : : }
2424 : 420 : M2Error_LeaveErrorScope ();
2425 : 420 : }
2426 : :
2427 : :
2428 : : /*
2429 : : BuildImportOuterModule - Builds imported identifiers into an outer module
2430 : : from a definition module.
2431 : :
2432 : : The Stack is expected:
2433 : :
2434 : : Entry OR Entry
2435 : :
2436 : : Ptr -> Ptr ->
2437 : : +------------+ +-----------+
2438 : : | # | | # |
2439 : : |------------| |-----------|
2440 : : | Id1 | | Id1 |
2441 : : |------------| |-----------|
2442 : : . . . .
2443 : : . . . .
2444 : : . . . .
2445 : : |------------| |-----------|
2446 : : | Id# | | Id# |
2447 : : |------------| |-----------|
2448 : : | ImportTok | | Ident |
2449 : : |------------| |-----------|
2450 : :
2451 : : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
2452 : :
2453 : :
2454 : : Exit
2455 : :
2456 : : All above stack discarded
2457 : : */
2458 : :
2459 : 289025 : extern "C" void P2SymBuild_BuildImportOuterModule (void)
2460 : : {
2461 : 289025 : unsigned int Sym;
2462 : 289025 : unsigned int ModSym;
2463 : 289025 : unsigned int i;
2464 : 289025 : unsigned int n;
2465 : :
2466 : 289025 : M2Quads_PopT (&n); /* n = # of the Ident List */
2467 : 289025 : if ((M2Quads_OperandT (n+1)) != M2Reserved_ImportTok)
2468 : : {
2469 : : /* Ident List contains list of objects imported from ModSym */
2470 : 254531 : ModSym = M2Batch_LookupModule (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
2471 : 254531 : i = 1;
2472 : 1124783 : while (i <= n)
2473 : : {
2474 : 615721 : Sym = SymbolTable_GetExported (M2Quads_OperandTok (i), ModSym, M2Quads_OperandT (i));
2475 : 615721 : SymbolTable_CheckForEnumerationInCurrentModule (Sym);
2476 : 615721 : i += 1;
2477 : : }
2478 : : }
2479 : 289025 : M2Quads_PopN (n+1); /* clear stack */
2480 : 289025 : }
2481 : :
2482 : :
2483 : : /*
2484 : : BuildExportOuterModule - Builds exported identifiers from an outer module
2485 : : to the outside world of library modules.
2486 : :
2487 : : The Stack is expected:
2488 : :
2489 : : Entry OR Entry
2490 : :
2491 : : Ptr -> Ptr ->
2492 : : +------------+ +--------------+
2493 : : | # | | # |
2494 : : |------------| |--------------|
2495 : : | Id1 | | Id1 |
2496 : : |------------| |--------------|
2497 : : . . . .
2498 : : . . . .
2499 : : . . . .
2500 : : |------------| |--------------|
2501 : : | Id# | | Id# |
2502 : : |------------| |--------------|
2503 : : | ExportTok | | QualifiedTok |
2504 : : |------------| |--------------|
2505 : :
2506 : : EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
2507 : :
2508 : : Error Condition
2509 : :
2510 : :
2511 : : Exit
2512 : :
2513 : : All above stack discarded
2514 : : */
2515 : :
2516 : 70761 : extern "C" void P2SymBuild_BuildExportOuterModule (void)
2517 : : {
2518 : 70761 : unsigned int n;
2519 : :
2520 : 70761 : M2Quads_PopT (&n); /* n = # of the Ident List */
2521 : 70761 : M2Quads_PopN (n+1); /* n = # of the Ident List */
2522 : 70761 : }
2523 : :
2524 : :
2525 : : /*
2526 : : BuildImportInnerModule - Builds imported identifiers into an inner module
2527 : : from the last level of module.
2528 : :
2529 : : The Stack is expected:
2530 : :
2531 : : Entry OR Entry
2532 : :
2533 : : Ptr -> Ptr ->
2534 : : +------------+ +-----------+
2535 : : | # | | # |
2536 : : |------------| |-----------|
2537 : : | Id1 | | Id1 |
2538 : : |------------| |-----------|
2539 : : . . . .
2540 : : . . . .
2541 : : . . . .
2542 : : |------------| |-----------|
2543 : : | Id# | | Id# |
2544 : : |------------| |-----------|
2545 : : | ImportTok | | Ident |
2546 : : |------------| |-----------|
2547 : :
2548 : : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
2549 : :
2550 : : Exit
2551 : :
2552 : : All above stack discarded
2553 : : */
2554 : :
2555 : 222 : extern "C" void P2SymBuild_BuildImportInnerModule (void)
2556 : : {
2557 : 222 : unsigned int Sym;
2558 : 222 : unsigned int ModSym;
2559 : 222 : unsigned int n;
2560 : 222 : unsigned int i;
2561 : :
2562 : 222 : M2Quads_PopT (&n); /* i = # of the Ident List */
2563 : 222 : if ((M2Quads_OperandT (n+1)) == M2Reserved_ImportTok)
2564 : : {
2565 : : /* Ident List contains list of objects */
2566 : : i = 1;
2567 : 318 : while (i <= n)
2568 : : {
2569 : 162 : Sym = SymbolTable_GetFromOuterModule (M2Quads_OperandTok (i), M2Quads_OperandT (i));
2570 : 162 : SymbolTable_CheckForEnumerationInCurrentModule (Sym);
2571 : 162 : i += 1;
2572 : : }
2573 : : }
2574 : : else
2575 : : {
2576 : : /* Ident List contains list of objects from ModSym */
2577 : 66 : ModSym = M2Batch_LookupOuterModule (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
2578 : 66 : i = 1;
2579 : 198 : while (i <= n)
2580 : : {
2581 : 66 : Sym = SymbolTable_GetExported (M2Quads_OperandTok (i), ModSym, M2Quads_OperandT (i));
2582 : 66 : SymbolTable_CheckForEnumerationInCurrentModule (Sym);
2583 : 66 : i += 1;
2584 : : }
2585 : : }
2586 : 222 : M2Quads_PopN (n+1); /* Clear Stack */
2587 : 222 : }
2588 : :
2589 : :
2590 : : /*
2591 : : BuildExportInnerModule - Builds exported identifiers from an inner module
2592 : : to the next layer module.
2593 : :
2594 : : The Stack is expected:
2595 : :
2596 : : Entry OR Entry
2597 : :
2598 : : Ptr -> Ptr ->
2599 : : +------------+ +--------------+
2600 : : | # | | # |
2601 : : |------------| |--------------|
2602 : : | Id1 | | Id1 |
2603 : : |------------| |--------------|
2604 : : . . . .
2605 : : . . . .
2606 : : . . . .
2607 : : |------------| |--------------|
2608 : : | Id# | | Id# |
2609 : : |------------| |--------------|
2610 : : | ExportTok | | QualifiedTok |
2611 : : |------------| |--------------|
2612 : :
2613 : : EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
2614 : :
2615 : :
2616 : : Exit
2617 : :
2618 : : All above stack discarded
2619 : : */
2620 : :
2621 : 282 : extern "C" void P2SymBuild_BuildExportInnerModule (void)
2622 : : {
2623 : 282 : unsigned int n;
2624 : :
2625 : 282 : M2Quads_PopT (&n);
2626 : 282 : M2Quads_PopN (n+1); /* clear stack */
2627 : 282 : }
2628 : :
2629 : :
2630 : : /*
2631 : : BuildNumber - Converts a number into a symbol.
2632 : :
2633 : :
2634 : : Stack
2635 : :
2636 : : Entry Exit
2637 : :
2638 : : Ptr -> <- Ptr
2639 : : +------------+ +-------------------+
2640 : : | Name | tok | | Sym | Type | tok |
2641 : : |------------+ |-------------------|
2642 : : */
2643 : :
2644 : 721351 : extern "C" void P2SymBuild_BuildNumber (void)
2645 : : {
2646 : 721351 : NameKey_Name name;
2647 : 721351 : unsigned int Sym;
2648 : 721351 : unsigned int tok;
2649 : :
2650 : 721351 : M2Quads_PopTtok (&name, &tok);
2651 : 721351 : Sym = SymbolTable_MakeConstLit (tok, name, SymbolTable_NulSym);
2652 : 721351 : M2Quads_PushTFtok (Sym, SymbolTable_GetType (Sym), tok);
2653 : 721351 : M2Quads_Annotate ((const char *) "%1s(%1d)||constant number", 25);
2654 : 721351 : }
2655 : :
2656 : :
2657 : : /*
2658 : : BuildString - Converts a string into a symbol.
2659 : :
2660 : :
2661 : : Stack
2662 : :
2663 : : Entry Exit
2664 : :
2665 : : Ptr -> <- Ptr
2666 : : +-------------+ +--------------------+
2667 : : | Name | | tok| | Sym | NulSym | tok |
2668 : : |-------------+ |--------------------|
2669 : : */
2670 : :
2671 : 93160 : extern "C" void P2SymBuild_BuildString (void)
2672 : : {
2673 : 93160 : NameKey_Name name;
2674 : 93160 : unsigned int Sym;
2675 : 93160 : unsigned int tok;
2676 : :
2677 : 93160 : M2Quads_PopTtok (&name, &tok);
2678 : : /* slice off the leading and trailing quotes */
2679 : 93160 : if (name == 1140)
2680 : : {
2681 : 93160 : stop ();
2682 : : }
2683 : 93160 : Sym = SymbolTable_MakeConstString (tok, NameKey_makekey (DynamicStrings_string (DynamicStrings_Mark (DynamicStrings_Slice (DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (name))), 1, -1)))));
2684 : 93160 : M2Quads_PushTFtok (Sym, static_cast<unsigned int> (SymbolTable_NulSym), tok);
2685 : 93160 : M2Quads_Annotate ((const char *) "%1s(%1d)|%3d||constant string", 29);
2686 : 93160 : }
2687 : :
2688 : :
2689 : : /*
2690 : : BuildConst - builds a constant.
2691 : : Stack
2692 : :
2693 : : Entry Exit
2694 : :
2695 : : Ptr ->
2696 : : +------------+
2697 : : | Name |
2698 : : |------------+ <- Ptr
2699 : : */
2700 : :
2701 : 246752 : extern "C" void P2SymBuild_BuildConst (void)
2702 : : {
2703 : 246752 : NameKey_Name name;
2704 : 246752 : unsigned int sym;
2705 : 246752 : unsigned int tok;
2706 : :
2707 : 246752 : M2Quads_PopTtok (&name, &tok);
2708 : 246752 : sym = SymbolTable_MakeConstVar (tok, name);
2709 : 246752 : M2Quads_PushTtok (sym, tok);
2710 : 246752 : P2SymBuild_RememberConstant (sym);
2711 : 246752 : M2Quads_Annotate ((const char *) "%1s(%1d)|%3d||remembered constant", 33);
2712 : 246752 : }
2713 : :
2714 : :
2715 : : /*
2716 : : StartBuildEnumeration - Builds an Enumeration type Type.
2717 : :
2718 : :
2719 : : Stack
2720 : :
2721 : : Entry Exit
2722 : :
2723 : : Ptr ->
2724 : : +------------+
2725 : : | # |
2726 : : |------------|
2727 : : | en 1 |
2728 : : |------------|
2729 : : | en 2 |
2730 : : |------------|
2731 : : . .
2732 : : . .
2733 : : . . <- Ptr
2734 : : |------------| +------------+
2735 : : | en # | | Type |
2736 : : |------------| |------------|
2737 : : | Name | | Name |
2738 : : |------------| |------------|
2739 : : */
2740 : :
2741 : 23322 : extern "C" void P2SymBuild_StartBuildEnumeration (void)
2742 : : {
2743 : 23322 : unsigned int n;
2744 : 23322 : unsigned int Type;
2745 : 23322 : unsigned int tok;
2746 : :
2747 : 23322 : M2Quads_PopT (&n); /* n := # */
2748 : : /* name is in OperandT(n+1) but we dont need it here. */
2749 : 23322 : tok = static_cast<unsigned int> (M2Quads_OperandTok (n+1));
2750 : 23322 : FifoQueue_GetEnumerationFromFifoQueue (&Type);
2751 : 23322 : SymbolTable_CheckForExportedImplementation (Type); /* May be an exported hidden type */
2752 : 23322 : M2Quads_PopN (n); /* May be an exported hidden type */
2753 : 23322 : M2Quads_PushTtok (Type, tok);
2754 : 23322 : M2Quads_Annotate ((const char *) "%1s(%1d)|%3d||enumerated type", 29);
2755 : 23322 : }
2756 : :
2757 : :
2758 : : /*
2759 : : BuildSubrange - Builds a Subrange type Symbol, the base type can also be
2760 : : supplied if known.
2761 : :
2762 : : Stack
2763 : :
2764 : : Entry Exit
2765 : :
2766 : :
2767 : : <- Ptr
2768 : : +------------+
2769 : : Ptr -> | Type |
2770 : : +------------+ |------------|
2771 : : | Name | | Name |
2772 : : |------------| |------------|
2773 : : */
2774 : :
2775 : 84620 : extern "C" void P2SymBuild_BuildSubrange (unsigned int tok, unsigned int Base)
2776 : : {
2777 : 84620 : NameKey_Name name;
2778 : 84620 : unsigned int Type;
2779 : :
2780 : 84620 : M2Quads_PopT (&name);
2781 : 84620 : Type = SymbolTable_MakeSubrange (tok, name);
2782 : 84620 : FifoQueue_PutSubrangeIntoFifoQueue (Type); /* Store Subrange away so that we can fill in */
2783 : : /* its bounds during pass 3. */
2784 : 84620 : FifoQueue_PutSubrangeIntoFifoQueue (Base); /* store Base type of subrange away as well. */
2785 : 84620 : SymbolTable_CheckForExportedImplementation (Type); /* May be an exported hidden type */
2786 : 84620 : M2Quads_PushTtok (name, tok); /* May be an exported hidden type */
2787 : 84620 : M2Quads_Annotate ((const char *) "%1n|%3d||subrange name|token no", 31);
2788 : 84620 : M2Quads_PushTtok (Type, tok);
2789 : 84620 : M2Quads_Annotate ((const char *) "%1s(%1d)|%3d||subrange type|token no", 36);
2790 : 84620 : }
2791 : :
2792 : :
2793 : : /*
2794 : : BuildAligned - builds an alignment constant symbol which is placed onto
2795 : : the stack. It expects the ident ALIGNED to be on the
2796 : : stack.
2797 : :
2798 : : Stack
2799 : :
2800 : : Entry Exit
2801 : :
2802 : :
2803 : : Ptr -> <- Ptr
2804 : : +---------------+ +-----------------+
2805 : : | bytealignment | | AlignmentConst |
2806 : : +---------------+ |-----------------|
2807 : : */
2808 : :
2809 : 72 : extern "C" void P2SymBuild_BuildAligned (void)
2810 : : {
2811 : 72 : unsigned int tok;
2812 : 72 : NameKey_Name name;
2813 : 72 : unsigned int align;
2814 : :
2815 : 72 : M2Quads_PopTtok (&name, &tok);
2816 : 72 : if (name == (NameKey_MakeKey ((const char *) "bytealignment", 13)))
2817 : : {
2818 : 72 : align = SymbolTable_MakeTemporary (tok, SymbolTable_ImmediateValue);
2819 : 72 : SymbolTable_PutConst (align, M2Base_ZType);
2820 : 72 : FifoQueue_PutConstIntoFifoQueue (align); /* Store align away so that we can fill in its */
2821 : 72 : M2Quads_PushT (align); /* value during pass 3. */
2822 : 72 : M2Quads_Annotate ((const char *) "%1s(%1d)|%3d||bytealignment constant generated from <* *>|token no", 66); /* value during pass 3. */
2823 : 72 : M2Quads_PushTtok (name, tok);
2824 : : }
2825 : : else
2826 : : {
2827 : 0 : M2Error_WriteFormat1 ((const char *) "expecting bytealignment identifier, rather than %a", 50, (const unsigned char *) &name, (sizeof (name)-1));
2828 : 0 : M2Quads_PushT (static_cast<unsigned int> (SymbolTable_NulSym));
2829 : : }
2830 : 72 : M2Quads_Annotate ((const char *) "%1n(%1d)||bytealignment constant generated from <* *>", 53);
2831 : 72 : }
2832 : :
2833 : :
2834 : : /*
2835 : : BuildVarAlignment - the AlignmentConst is either a temporary or NulSym.
2836 : : A type may only have one alignment value and
2837 : : error checking is performed.
2838 : :
2839 : : Stack
2840 : :
2841 : : Entry Exit
2842 : :
2843 : :
2844 : : Ptr ->
2845 : : +-----------------+
2846 : : | AlignmentConst | <- Ptr
2847 : : |-----------------| +------------------+
2848 : : | Type | | Type | TypeName |
2849 : : |-----------------| |------------------|
2850 : : */
2851 : :
2852 : 827078 : extern "C" void P2SymBuild_BuildVarAlignment (void)
2853 : : {
2854 : 827078 : unsigned int tokno;
2855 : 827078 : NameKey_Name alignment;
2856 : 827078 : NameKey_Name newname;
2857 : 827078 : unsigned int new_;
2858 : 827078 : unsigned int type;
2859 : 827078 : unsigned int align;
2860 : 827078 : DynamicStrings_String s;
2861 : :
2862 : 827078 : M2Quads_PopT (&alignment);
2863 : 827078 : if (alignment == (NameKey_MakeKey ((const char *) "bytealignment", 13)))
2864 : : {
2865 : 42 : M2Quads_PopT (&align);
2866 : 42 : M2Quads_PopTtok (&type, &tokno);
2867 : 42 : if (((((SymbolTable_IsRecord (type)) || (SymbolTable_IsRecordField (type))) || (SymbolTable_IsType (type))) || (SymbolTable_IsArray (type))) || (SymbolTable_IsPointer (type)))
2868 : : {
2869 : 42 : stop ();
2870 : 42 : if (SymbolTable_IsNameAnonymous (type))
2871 : : {
2872 : 30 : SymbolTable_PutAlignment (type, align);
2873 : 30 : M2Quads_PushTFtok (type, SymbolTable_GetSymName (type), tokno);
2874 : 30 : M2Quads_Annotate ((const char *) "%1s(%1d)|%2n|%3d||aligned type|aligned type name|token no", 57);
2875 : : }
2876 : : else
2877 : : {
2878 : : /* create a pseudonym */
2879 : 12 : s = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "_$A%d", 5)), (const unsigned char *) &alignTypeNo, (sizeof (alignTypeNo)-1));
2880 : 12 : alignTypeNo += 1;
2881 : 12 : newname = NameKey_makekey (DynamicStrings_string (s));
2882 : 12 : if (SymbolTable_IsPointer (type))
2883 : : {
2884 : 0 : new_ = SymbolTable_MakePointer (tokno, newname);
2885 : : }
2886 : : else
2887 : : {
2888 : 12 : new_ = SymbolTable_MakeType (tokno, newname);
2889 : : }
2890 : 12 : s = DynamicStrings_KillString (s);
2891 : 12 : SymbolTable_PutType (new_, type);
2892 : 12 : SymbolTable_PutAlignment (new_, align);
2893 : 12 : M2Quads_PushTFtok (new_, SymbolTable_GetSymName (new_), tokno);
2894 : 12 : M2Quads_Annotate ((const char *) "%1s(%1d)|%2n|%3d||aligned type|aligned type name", 48);
2895 : : }
2896 : : }
2897 : : else
2898 : : {
2899 : 0 : M2MetaError_MetaError1 ((const char *) "not allowed to add an alignment attribute to type {%1ad}", 56, type);
2900 : 0 : M2Quads_PushTFtok (type, SymbolTable_GetSymName (type), tokno);
2901 : 0 : M2Quads_Annotate ((const char *) "%1s(%1d)|%2n|%3d||error aligned type|error aligned type name", 60);
2902 : : }
2903 : : }
2904 : 827036 : else if (alignment != NameKey_NulName)
2905 : : {
2906 : : /* avoid dangling else. */
2907 : 0 : M2Error_WriteFormat1 ((const char *) "unknown variable alignment attribute, %a", 40, (const unsigned char *) &alignment, (sizeof (alignment)-1));
2908 : : }
2909 : 827078 : }
2910 : :
2911 : :
2912 : : /*
2913 : : BuildTypeAlignment - the AlignmentConst is either a temporary or NulSym.
2914 : : In the case of NulSym it is popped from the stack
2915 : : and the procedure returns. Otherwise the temporary
2916 : : is popped and recorded as the alignment value for this
2917 : : type. A type may only have one alignment value and
2918 : : error checking is performed.
2919 : :
2920 : : Stack
2921 : :
2922 : : Entry Exit
2923 : :
2924 : :
2925 : : Ptr ->
2926 : : +-----------------+
2927 : : | AlignmentConst |
2928 : : |-----------------|
2929 : : | Type | Empty
2930 : : |-----------------|
2931 : : */
2932 : :
2933 : 74386 : extern "C" void P2SymBuild_BuildTypeAlignment (void)
2934 : : {
2935 : 74386 : NameKey_Name alignment;
2936 : 74386 : unsigned int type;
2937 : 74386 : unsigned int align;
2938 : :
2939 : 74386 : M2Quads_PopT (&alignment);
2940 : 74386 : if (alignment == (NameKey_MakeKey ((const char *) "bytealignment", 13)))
2941 : : {
2942 : : /* avoid dangling else. */
2943 : 30 : M2Quads_PopT (&align);
2944 : 30 : M2Quads_PopT (&type);
2945 : 30 : if (align != SymbolTable_NulSym)
2946 : : {
2947 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
2948 : 30 : if ((((((SymbolTable_IsRecord (type)) || (SymbolTable_IsRecordField (type))) || (SymbolTable_IsType (type))) || (SymbolTable_IsArray (type))) || (SymbolTable_IsPointer (type))) || (SymbolTable_IsSubrange (type)))
2949 : : {
2950 : 30 : SymbolTable_PutAlignment (type, align);
2951 : : }
2952 : : else
2953 : : {
2954 : 0 : M2MetaError_MetaError1 ((const char *) "not allowed to add an alignment attribute to type {%1ad}", 56, type);
2955 : : }
2956 : : }
2957 : : }
2958 : 74356 : else if (alignment != NameKey_NulName)
2959 : : {
2960 : : /* avoid dangling else. */
2961 : 0 : M2Error_WriteFormat1 ((const char *) "unknown type alignment attribute, %a", 36, (const unsigned char *) &alignment, (sizeof (alignment)-1));
2962 : : }
2963 : : else
2964 : : {
2965 : : /* avoid dangling else. */
2966 : 74356 : M2Quads_PopT (&type);
2967 : : }
2968 : 74386 : }
2969 : :
2970 : 36 : extern "C" void P2SymBuild_P2BuildDefaultFieldAlignment (void)
2971 : : {
2972 : 36 : unsigned int tok;
2973 : 36 : NameKey_Name alignment;
2974 : 36 : unsigned int align;
2975 : :
2976 : : /*
2977 : : BuildDefaultFieldAlignment -
2978 : :
2979 : : The Stack:
2980 : :
2981 : : Entry Exit
2982 : : ===== ====
2983 : :
2984 : :
2985 : : Ptr ->
2986 : : +-----------+
2987 : : | Alignment |
2988 : : |-----------| +-----------+
2989 : : | RecordSym | | RecordSym |
2990 : : |-----------| |-----------|
2991 : : | Name | | Name |
2992 : : |-----------| |-----------|
2993 : :
2994 : : */
2995 : 36 : M2Quads_PopTtok (&alignment, &tok);
2996 : 36 : align = SymbolTable_MakeTemporary (tok, SymbolTable_ImmediateValue);
2997 : 36 : SymbolTable_PutConst (align, M2Base_ZType);
2998 : 36 : FifoQueue_PutConstIntoFifoQueue (align); /* store align away ready for pass 3 */
2999 : 36 : SymbolTable_PutDefaultRecordFieldAlignment (M2Quads_OperandT (1), align); /* store align away ready for pass 3 */
3000 : 36 : }
3001 : :
3002 : :
3003 : : /*
3004 : : BuildPragmaConst - pushes a constant to the stack and stores it away into the
3005 : : const fifo queue ready for pass 3.
3006 : : */
3007 : :
3008 : 12 : extern "C" void P2SymBuild_BuildPragmaConst (void)
3009 : : {
3010 : 12 : unsigned int value;
3011 : :
3012 : 12 : value = SymbolTable_MakeTemporary (M2LexBuf_GetTokenNo (), SymbolTable_ImmediateValue);
3013 : 12 : SymbolTable_PutConst (value, M2Base_ZType);
3014 : 12 : FifoQueue_PutConstIntoFifoQueue (value); /* Store value away so that we can fill it in */
3015 : 12 : M2Quads_PushT (value); /* during pass 3. */
3016 : 12 : M2Quads_Annotate ((const char *) "%1s(%1d)||pragma constant", 25); /* during pass 3. */
3017 : 12 : }
3018 : :
3019 : :
3020 : : /*
3021 : : BuildVariable - Builds variables listed in an IdentList with a Type.
3022 : :
3023 : : Stack
3024 : :
3025 : : Entry Exit
3026 : :
3027 : : Ptr ->
3028 : : +------------+ +------------+
3029 : : | Type | Name| | |
3030 : : |------------| |------------|
3031 : : | # | | |
3032 : : |------------| |------------|
3033 : : | Ident 1 | | |
3034 : : |------------| |------------|
3035 : : | Ident 2 | | |
3036 : : |------------| |------------|
3037 : : . . . .
3038 : : . . . .
3039 : : . . . .
3040 : : |------------| |------------|
3041 : : | Ident # | | | <- Ptr
3042 : : |------------| |------------|
3043 : :
3044 : : Empty
3045 : : */
3046 : :
3047 : 722824 : extern "C" void P2SymBuild_BuildVariable (void)
3048 : : {
3049 : 722824 : NameKey_Name name;
3050 : 722824 : unsigned int tok;
3051 : 722824 : unsigned int typetok;
3052 : 722824 : unsigned int AtAddress;
3053 : 722824 : unsigned int Type;
3054 : 722824 : unsigned int Var;
3055 : 722824 : unsigned int i;
3056 : 722824 : unsigned int n;
3057 : :
3058 : 722824 : M2Quads_PopTFtok (&Type, &name, &typetok);
3059 : 722824 : M2Quads_PopT (&n);
3060 : 722824 : i = 1;
3061 : 2408894 : while (i <= n)
3062 : : {
3063 : 963258 : M2Students_CheckVariableAgainstKeyword (M2Quads_OperandT ((n+1)-i));
3064 : 963258 : tok = static_cast<unsigned int> (M2Quads_OperandTok ((n+1)-i));
3065 : 963258 : Var = SymbolTable_MakeVar (tok, M2Quads_OperandT ((n+1)-i));
3066 : 963258 : AtAddress = static_cast<unsigned int> (M2Quads_OperandA ((n+1)-i));
3067 : 963258 : if (AtAddress != SymbolTable_NulSym)
3068 : : {
3069 : 54 : SymbolTable_PutVariableAtAddress (Var, SymbolTable_NulSym);
3070 : 54 : SymbolTable_PutMode (Var, SymbolTable_LeftValue);
3071 : : }
3072 : 963258 : SymbolTable_PutVarTok (Var, Type, typetok);
3073 : 963246 : if (tok != M2LexBuf_UnknownTokenNo)
3074 : : {
3075 : 963246 : SymbolTable_PutDeclared (tok, Var);
3076 : 963246 : SymbolTable_PutVarDeclTok (Var, tok);
3077 : : }
3078 : 963246 : i += 1;
3079 : : }
3080 : 722812 : M2Quads_PopN (n);
3081 : 722812 : }
3082 : :
3083 : :
3084 : : /*
3085 : : BuildType - Builds a Type.
3086 : :
3087 : :
3088 : : Stack
3089 : :
3090 : : Entry Exit
3091 : :
3092 : : Ptr ->
3093 : : +------------+
3094 : : | Type | <- Ptr
3095 : : |------------| +---------------+
3096 : : | Name | | Type | Name |
3097 : : |------------| |---------------|
3098 : :
3099 : : Empty
3100 : : */
3101 : :
3102 : 1381290 : extern "C" void P2SymBuild_BuildType (void)
3103 : : {
3104 : 1381290 : bool isunknown;
3105 : 1381290 : NameKey_Name n1;
3106 : 1381290 : NameKey_Name n2;
3107 : 1381290 : unsigned int Sym;
3108 : 1381290 : unsigned int Type;
3109 : 1381290 : NameKey_Name name;
3110 : 1381290 : unsigned int nametokno;
3111 : 1381290 : unsigned int typetokno;
3112 : :
3113 : : /*
3114 : : Two cases
3115 : :
3116 : : - the type name the same as Name, or the name is nul. - do nothing.
3117 : : - when type with a name that is different to Name. In which case
3118 : : we create a new type.
3119 : : */
3120 : 1381290 : M2Quads_PopTtok (&Type, &typetokno);
3121 : 1381290 : M2Quads_PopTtok (&name, &nametokno);
3122 : 1381290 : if (Debugging)
3123 : : {
3124 : : n1 = SymbolTable_GetSymName (SymbolTable_GetCurrentModule ());
3125 : : 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));
3126 : : if (! (SymbolTable_IsUnknown (Type)))
3127 : : {
3128 : : n1 = SymbolTable_GetSymName (SymbolTable_GetScope (Type));
3129 : : n2 = SymbolTable_GetSymName (Type);
3130 : : 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));
3131 : : }
3132 : : }
3133 : 1381290 : if (name == NameKey_NulName)
3134 : : {
3135 : : /* WriteString('Blank name type') ; WriteLn ; */
3136 : 1171084 : M2Quads_PushTFtok (Type, name, typetokno);
3137 : 1171084 : M2Quads_Annotate ((const char *) "%1s(%1d)|%2n|%3d||type|type name|token no", 41);
3138 : : }
3139 : 210206 : else if (SymbolTable_IsError (Type))
3140 : : {
3141 : : /* avoid dangling else. */
3142 : 0 : M2Quads_PushTFtok (Type, name, typetokno);
3143 : 0 : M2Quads_Annotate ((const char *) "%1s(%1d)|%2n|%3d||error type|error type name|token no", 53);
3144 : : }
3145 : 210206 : else if ((SymbolTable_GetSymName (Type)) == name)
3146 : : {
3147 : : /* avoid dangling else. */
3148 : 195302 : isunknown = SymbolTable_IsUnknown (Type);
3149 : 195302 : if (isunknown || (! (SymbolTable_IsDeclaredIn (SymbolTable_GetCurrentScope (), Type))))
3150 : : {
3151 : 1428 : Sym = SymbolTable_MakeType (typetokno, name);
3152 : 1428 : if (! (SymbolTable_IsError (Sym)))
3153 : : {
3154 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
3155 : 1422 : if (Sym == Type)
3156 : : {
3157 : 0 : if (isunknown)
3158 : : {
3159 : 0 : M2MetaError_MetaError2 ((const char *) "attempting to declare a type {%1ad} to a type which is itself and also unknown {%2ad}", 85, Sym, Type);
3160 : : }
3161 : : else
3162 : : {
3163 : 0 : M2MetaError_MetaError1 ((const char *) "attempting to declare a type {%1ad} as itself", 45, Sym);
3164 : : }
3165 : : }
3166 : : else
3167 : : {
3168 : 1422 : SymbolTable_PutType (Sym, Type);
3169 : 1422 : SymbolTable_CheckForExportedImplementation (Sym); /* May be an exported hidden type */
3170 : : /* if Type is an enumerated type then add its contents to the pseudo scope */
3171 : 1422 : SymbolTable_CheckForEnumerationInCurrentModule (Type);
3172 : : }
3173 : : }
3174 : 1428 : M2Quads_PushTFtok (Sym, name, typetokno);
3175 : 1428 : M2Quads_Annotate ((const char *) "%1s(%1d)|%2n|%3d||type|type name|token no", 41);
3176 : : }
3177 : : else
3178 : : {
3179 : 193874 : M2Quads_PushTFtok (Type, name, typetokno);
3180 : 193874 : M2Quads_Annotate ((const char *) "%1s(%1d)|%2n|%3d||type|type name|token no", 41);
3181 : : }
3182 : : }
3183 : : else
3184 : : {
3185 : : /* avoid dangling else. */
3186 : : /* example TYPE a = CARDINAL */
3187 : 14904 : Sym = SymbolTable_MakeType (nametokno, name);
3188 : 14904 : SymbolTable_PutType (Sym, Type);
3189 : 14904 : SymbolTable_CheckForExportedImplementation (Sym); /* May be an exported hidden type */
3190 : 14904 : M2Quads_PushTFtok (Sym, name, nametokno); /* May be an exported hidden type */
3191 : 14904 : M2Quads_Annotate ((const char *) "%1s(%1d)|%2n|%3d||type|type name|token no", 41);
3192 : 14904 : if (Debugging)
3193 : : {
3194 : : M2MetaError_MetaErrorT1 (nametokno, (const char *) "type pos {%1Wa}", 15, Sym);
3195 : : }
3196 : : }
3197 : 1381290 : }
3198 : :
3199 : :
3200 : : /*
3201 : : StartBuildFormalParameters - Initialises the quadruple stack for
3202 : : Formal Parameters.
3203 : :
3204 : : The Stack:
3205 : :
3206 : : Entry Exit
3207 : :
3208 : : <- Ptr
3209 : : +------------+
3210 : : Empty | 0 |
3211 : : |------------|
3212 : : */
3213 : :
3214 : 3002758 : extern "C" void P2SymBuild_StartBuildFormalParameters (void)
3215 : : {
3216 : 3002758 : M2Quads_PushT (static_cast<unsigned int> (0));
3217 : 3002758 : M2Quads_Annotate ((const char *) "%1d||running total of no. of parameters", 39);
3218 : 3002758 : }
3219 : :
3220 : :
3221 : : /*
3222 : : EndBuildFormalParameters - Resets the quadruple stack after building
3223 : : Formal Parameters.
3224 : :
3225 : : The Stack:
3226 : :
3227 : : Entry Exit
3228 : :
3229 : : Ptr ->
3230 : : +------------+
3231 : : | NoOfParam | <- Ptr
3232 : : |------------| +------------+
3233 : : | ProcSym | | ProcSym |
3234 : : |------------| |------------|
3235 : : */
3236 : :
3237 : 3002758 : extern "C" void P2SymBuild_EndBuildFormalParameters (void)
3238 : : {
3239 : 3002758 : SymbolTable_ProcedureKind kind;
3240 : 3002758 : SymbolTable_ProcedureKind curkind;
3241 : 3002758 : unsigned int tok;
3242 : 3002758 : unsigned int NoOfPar;
3243 : 3002758 : unsigned int ProcSym;
3244 : :
3245 : 3002758 : M2Quads_PopT (&NoOfPar);
3246 : 3002758 : M2Quads_PopTtok (&ProcSym, &tok);
3247 : 3002758 : M2Quads_PushTtok (ProcSym, tok);
3248 : 3002758 : M2Quads_Annotate ((const char *) "%1s(%1d)||procedure start symbol", 32);
3249 : 3002758 : M2Debug_Assert (SymbolTable_IsProcedure (ProcSym));
3250 : 3002758 : curkind = SymbolTable_GetProcedureKind (ProcSym, tok);
3251 : 15013790 : for (kind=SymbolTable_ProperProcedure; kind<=SymbolTable_DefProcedure; kind= static_cast<SymbolTable_ProcedureKind>(static_cast<int>(kind+1)))
3252 : : {
3253 : 9008274 : if (((SymbolTable_GetProcedureParametersDefined (ProcSym, kind)) && (curkind != kind)) && ((SymbolTable_NoOfParam (ProcSym, kind)) != NoOfPar))
3254 : : {
3255 : 18 : ParameterMismatch (tok, ProcSym, NoOfPar, kind, curkind);
3256 : : }
3257 : : }
3258 : : /* All parameter seen so set procedure defined. */
3259 : 3002758 : SymbolTable_PutProcedureParametersDefined (ProcSym, curkind);
3260 : 3002758 : M2Debug_Assert (SymbolTable_IsProcedure (M2Quads_OperandT (1)));
3261 : 3002758 : }
3262 : :
3263 : :
3264 : : /*
3265 : : BuildProcedureHeading - Builds a procedure heading for the definition
3266 : : module procedures.
3267 : :
3268 : : Operation only performed if compiling a
3269 : : definition module.
3270 : :
3271 : : The Stack:
3272 : :
3273 : : Entry Exit
3274 : :
3275 : : Ptr ->
3276 : : +------------+
3277 : : | ProcSym |
3278 : : |------------|
3279 : : | NameStart |
3280 : : |------------|
3281 : : Empty
3282 : :
3283 : : */
3284 : :
3285 : 3002758 : extern "C" void P2SymBuild_BuildProcedureHeading (void)
3286 : : {
3287 : 3002758 : unsigned int tok;
3288 : 3002758 : unsigned int ProcSym;
3289 : 3002758 : NameKey_Name NameStart;
3290 : :
3291 : 3002758 : ProcSym = static_cast<unsigned int> (M2Quads_OperandT (1));
3292 : 3002758 : tok = static_cast<unsigned int> (M2Quads_OperandTok (1));
3293 : 3002758 : SymbolTable_PutProcedureParametersDefined (ProcSym, SymbolTable_GetProcedureKind (ProcSym, tok));
3294 : 3002758 : if (M2Comp_CompilingDefinitionModule ())
3295 : : {
3296 : 2030336 : M2Quads_PopT (&ProcSym);
3297 : 2030336 : M2Debug_Assert (SymbolTable_IsProcedure (ProcSym));
3298 : 2030336 : M2Quads_PopT (&NameStart);
3299 : 2030336 : SymbolTable_EndScope ();
3300 : : }
3301 : 3002758 : }
3302 : :
3303 : :
3304 : : /*
3305 : : BuildFunction - Builds a procedures return type.
3306 : : Procedure becomes a function.
3307 : :
3308 : : The Stack:
3309 : :
3310 : : Entry Exit
3311 : :
3312 : : Ptr ->
3313 : : +------------+
3314 : : | TypeSym | <- Ptr
3315 : : |------------| +------------+
3316 : : | ProcSym | | ProcSym |
3317 : : |------------| |------------|
3318 : : */
3319 : :
3320 : 1194394 : extern "C" void P2SymBuild_BuildFunction (void)
3321 : : {
3322 : 1194394 : unsigned int tok;
3323 : 1194394 : unsigned int ProcSym;
3324 : 1194394 : unsigned int typetok;
3325 : 1194394 : unsigned int RetType;
3326 : :
3327 : 1194394 : M2Quads_PopTtok (&RetType, &typetok);
3328 : 1194394 : M2Quads_PopTtok (&ProcSym, &tok);
3329 : 1194394 : M2Quads_PushTtok (ProcSym, tok);
3330 : 1194394 : SymbolTable_PutFunction (typetok, ProcSym, SymbolTable_GetProcedureKind (ProcSym, tok), RetType);
3331 : 1194394 : CheckOptFunction (tok, ProcSym, SymbolTable_GetProcedureKind (ProcSym, tok), false);
3332 : 1194394 : CheckProcedureReturn (RetType, typetok);
3333 : 1194394 : }
3334 : :
3335 : :
3336 : : /*
3337 : : BuildOptFunction - Builds a procedures optional return type.
3338 : : Procedure becomes a function and the user
3339 : : can either call it as a function or a procedure.
3340 : :
3341 : : The Stack:
3342 : :
3343 : : Entry Exit
3344 : :
3345 : : Ptr ->
3346 : : +------------+
3347 : : | TypeSym | <- Ptr
3348 : : |------------| +------------+
3349 : : | ProcSym | | ProcSym |
3350 : : |------------| |------------|
3351 : : */
3352 : :
3353 : 124964 : extern "C" void P2SymBuild_BuildOptFunction (void)
3354 : : {
3355 : 124964 : unsigned int typetok;
3356 : 124964 : unsigned int tok;
3357 : 124964 : unsigned int RetType;
3358 : 124964 : unsigned int ProcSym;
3359 : :
3360 : 124964 : M2Quads_PopTtok (&RetType, &typetok);
3361 : 124964 : M2Quads_PopTtok (&ProcSym, &tok);
3362 : 124964 : SymbolTable_PutOptFunction (typetok, ProcSym, SymbolTable_GetProcedureKind (ProcSym, tok), RetType);
3363 : 124964 : CheckOptFunction (tok, ProcSym, SymbolTable_GetProcedureKind (ProcSym, tok), true);
3364 : 124964 : M2Quads_PushTtok (ProcSym, tok);
3365 : 124964 : }
3366 : :
3367 : :
3368 : : /*
3369 : : BuildFPSection - Builds a Formal Parameter in a procedure.
3370 : :
3371 : : The Stack:
3372 : :
3373 : : Entry Exit
3374 : :
3375 : : Ptr ->
3376 : : +------------+
3377 : : | ParamTotal |
3378 : : |------------|
3379 : : | TypeSym |
3380 : : |------------|
3381 : : | Array/Nul |
3382 : : |------------|
3383 : : | NoOfIds |
3384 : : |------------|
3385 : : | Id 1 |
3386 : : |------------|
3387 : : . .
3388 : : . .
3389 : : . .
3390 : : |------------|
3391 : : | Id n | <- Ptr
3392 : : |------------| +------------+
3393 : : | Var / Nul | | ParamTotal |
3394 : : |------------| |------------|
3395 : : | ProcSym | | ProcSym |
3396 : : |------------| |------------|
3397 : : */
3398 : :
3399 : 5085803 : extern "C" void P2SymBuild_BuildFPSection (void)
3400 : : {
3401 : 5085803 : SymbolTable_ProcedureKind kind;
3402 : 5085803 : SymbolTable_ProcedureKind curkind;
3403 : 5085803 : unsigned int tok;
3404 : 5085803 : unsigned int top;
3405 : 5085803 : unsigned int ProcSym;
3406 : 5085803 : unsigned int ParamTotal;
3407 : :
3408 : 5085803 : top = M2Quads_Top ();
3409 : 5085803 : M2Quads_PopT (&ParamTotal);
3410 : 5085803 : ProcSym = (unsigned int ) (M2Quads_OperandT ((3+((unsigned int ) (M2Quads_OperandT (3))))+2));
3411 : 5085803 : tok = (unsigned int ) (M2Quads_OperandTok ((3+((unsigned int ) (M2Quads_OperandT (3))))+2));
3412 : : /* Debug (tok, ProcSym, 'foo') ; */
3413 : 5085803 : curkind = SymbolTable_GetProcedureKind (ProcSym, tok);
3414 : 5085803 : M2Quads_PushT (ParamTotal);
3415 : 5085803 : M2Quads_Annotate ((const char *) "%1d||running total of no. of parameters", 39);
3416 : 10171606 : M2Debug_Assert ((SymbolTable_IsProcedure (ProcSym)) || (SymbolTable_IsProcType (ProcSym)));
3417 : 5085803 : M2Debug_Assert (top == (M2Quads_Top ()));
3418 : 5085803 : ProcSym = (unsigned int ) (M2Quads_OperandT (((3+((unsigned int ) (M2Quads_OperandT (3+1))))+2)+1));
3419 : 10171606 : M2Debug_Assert ((SymbolTable_IsProcedure (ProcSym)) || (SymbolTable_IsProcType (ProcSym)));
3420 : 5085803 : if (! (SymbolTable_GetProcedureParametersDefined (ProcSym, curkind)))
3421 : : {
3422 : 5085803 : BuildFormalParameterSection (curkind);
3423 : : }
3424 : 20343212 : for (kind=SymbolTable_ProperProcedure; kind<=SymbolTable_DefProcedure; kind= static_cast<SymbolTable_ProcedureKind>(static_cast<int>(kind+1)))
3425 : : {
3426 : : /* Check against any previous declaration. */
3427 : 15257409 : if ((kind != curkind) && (SymbolTable_GetProcedureParametersDefined (ProcSym, kind)))
3428 : : {
3429 : 1019558 : M2Debug_Assert (top == (M2Quads_Top ()));
3430 : 1019558 : CheckFormalParameterSection (curkind, kind);
3431 : 1019558 : M2Debug_Assert (top == (M2Quads_Top ()));
3432 : : }
3433 : 15257409 : ProcSym = (unsigned int ) (M2Quads_OperandT (((3+((unsigned int ) (M2Quads_OperandT (3+1))))+2)+1));
3434 : 30514818 : M2Debug_Assert ((SymbolTable_IsProcedure (ProcSym)) || (SymbolTable_IsProcType (ProcSym)));
3435 : : }
3436 : 5085803 : RemoveFPParameters ();
3437 : 5085803 : M2Debug_Assert (SymbolTable_IsProcedure (M2Quads_OperandT (2)));
3438 : 5085803 : }
3439 : :
3440 : :
3441 : : /*
3442 : : BuildVarArgs - indicates that the ProcSym takes varargs
3443 : : after ParamTotal.
3444 : : <- Ptr
3445 : : +------------+ +------------+
3446 : : | ParamTotal | | ParamTotal |
3447 : : |------------| |------------|
3448 : : | ProcSym | | ProcSym |
3449 : : |------------| |------------|
3450 : :
3451 : : */
3452 : :
3453 : 11072 : extern "C" void P2SymBuild_BuildVarArgs (void)
3454 : : {
3455 : 11072 : SymbolTable_ProcedureKind kind;
3456 : 11072 : unsigned int tok;
3457 : 11072 : unsigned int ProcSym;
3458 : 11072 : unsigned int ParamTotal;
3459 : :
3460 : 11072 : M2Quads_PopT (&ParamTotal);
3461 : 11072 : M2Quads_PopTtok (&ProcSym, &tok);
3462 : 11072 : kind = SymbolTable_GetProcedureKind (ProcSym, tok);
3463 : 11072 : if (SymbolTable_UsesOptArg (ProcSym, kind))
3464 : : {
3465 : 0 : M2Error_WriteFormat0 ((const char *) "procedure can use either a single optional argument or a single vararg section ... at the end of the formal parameter list", 122);
3466 : : }
3467 : 11072 : if (SymbolTable_UsesVarArgs (ProcSym))
3468 : : {
3469 : 0 : M2Error_WriteFormat0 ((const char *) "procedure can only have one vararg section ... at the end of the formal parameter list", 86);
3470 : : }
3471 : 11072 : SymbolTable_PutUseVarArgs (ProcSym);
3472 : 11072 : if (SymbolTable_IsDefImp (SymbolTable_GetCurrentModule ()))
3473 : : {
3474 : : /* avoid dangling else. */
3475 : 11072 : if (! (SymbolTable_IsDefinitionForC (SymbolTable_GetCurrentModule ())))
3476 : : {
3477 : 0 : M2Error_WriteFormat0 ((const char *) "the definition module must be declared as DEFINITION MODULE FOR \"C\" if varargs are to be used", 93);
3478 : : }
3479 : : }
3480 : : else
3481 : : {
3482 : 0 : M2Error_WriteFormat0 ((const char *) "varargs can only be used in the module declared as DEFINITION MODULE FOR \"C\"", 76);
3483 : : }
3484 : 11072 : M2Quads_PushTtok (ProcSym, tok);
3485 : 11072 : M2Quads_PushT (ParamTotal);
3486 : 11072 : }
3487 : :
3488 : :
3489 : : /*
3490 : : BuildFormalVarArgs - indicates that the procedure type takes varargs.
3491 : :
3492 : : <- Ptr
3493 : : +------------+ +------------+
3494 : : | ProcSym | | ProcSym |
3495 : : |------------| |------------|
3496 : :
3497 : : */
3498 : :
3499 : 0 : extern "C" void P2SymBuild_BuildFormalVarArgs (void)
3500 : : {
3501 : 0 : unsigned int ProcSym;
3502 : :
3503 : 0 : M2Quads_PopT (&ProcSym);
3504 : 0 : if (SymbolTable_UsesVarArgs (ProcSym))
3505 : : {
3506 : 0 : M2Error_WriteFormat0 ((const char *) "procedure type can only have one vararg section ... at the end of the formal parameter list", 91);
3507 : : }
3508 : 0 : SymbolTable_PutUseVarArgs (ProcSym);
3509 : 0 : if (SymbolTable_IsDefImp (SymbolTable_GetCurrentModule ()))
3510 : : {
3511 : : /* avoid dangling else. */
3512 : 0 : if (! (SymbolTable_IsDefinitionForC (SymbolTable_GetCurrentModule ())))
3513 : : {
3514 : 0 : M2Error_WriteFormat0 ((const char *) "the definition module must be declared as DEFINITION MODULE FOR \"C\" if varargs are to be used", 93);
3515 : : }
3516 : : }
3517 : : else
3518 : : {
3519 : 0 : M2Error_WriteFormat0 ((const char *) "varargs can only be used in the module declared as DEFINITION MODULE FOR \"C\"", 76);
3520 : : }
3521 : 0 : M2Quads_PushT (ProcSym);
3522 : 0 : }
3523 : :
3524 : :
3525 : : /*
3526 : : BuildOptArg - indicates that the ProcSym takes a single optarg
3527 : : after ParamTotal.
3528 : :
3529 : : <- Ptr
3530 : : +------------+ +------------+
3531 : : | ParamTotal | | ParamTotal |
3532 : : |------------| |------------|
3533 : : | ProcSym | | ProcSym |
3534 : : |------------| |------------|
3535 : : */
3536 : :
3537 : 17849 : extern "C" void P2SymBuild_BuildOptArg (void)
3538 : : {
3539 : 17849 : SymbolTable_ProcedureKind kind;
3540 : 17849 : unsigned int tok;
3541 : 17849 : unsigned int ProcSym;
3542 : 17849 : unsigned int ParamTotal;
3543 : :
3544 : 17849 : M2Quads_PopT (&ParamTotal);
3545 : 17849 : M2Quads_PopTtok (&ProcSym, &tok);
3546 : 17849 : kind = SymbolTable_GetProcedureKind (ProcSym, tok);
3547 : 17849 : if (SymbolTable_UsesVarArgs (ProcSym))
3548 : : {
3549 : 0 : M2Error_WriteFormat0 ((const char *) "procedure can not use an optional argument after a vararg ...", 61);
3550 : : }
3551 : 17849 : SymbolTable_PutUseOptArg (ProcSym, kind);
3552 : 17849 : M2Quads_PushTtok (ProcSym, tok);
3553 : 17849 : M2Quads_PushT (ParamTotal);
3554 : 17849 : }
3555 : :
3556 : :
3557 : : /*
3558 : : StartBuildProcedure - Builds a Procedure.
3559 : :
3560 : : The Stack:
3561 : :
3562 : : Entry Exit
3563 : :
3564 : : <- Ptr
3565 : : +------------+
3566 : : Ptr -> | ProcSym |
3567 : : +------------+ |------------|
3568 : : | Name | | Name |
3569 : : |------------| |------------|
3570 : : */
3571 : :
3572 : 3002758 : extern "C" void P2SymBuild_StartBuildProcedure (void)
3573 : : {
3574 : 3002758 : NameKey_Name name;
3575 : 3002758 : unsigned int ProcSym;
3576 : 3002758 : unsigned int tokno;
3577 : :
3578 : 3002758 : M2Quads_PopTtok (&name, &tokno);
3579 : 3002758 : M2Quads_PushTtok (name, tokno); /* name saved for the EndBuildProcedure name check */
3580 : 3002758 : M2Quads_Annotate ((const char *) "%1n|(%1d)||procedure name saved by StartBuildProcedure", 54); /* name saved for the EndBuildProcedure name check */
3581 : 3002758 : ProcSym = SymbolTable_GetDeclareSym (tokno, name);
3582 : 3002758 : if (SymbolTable_IsUnknown (ProcSym))
3583 : : {
3584 : : /* May have been compiled in the definition or implementation module.
3585 : : Note we always see an implementation module before its corresponding
3586 : : definition module. */
3587 : 0 : ProcSym = SymbolTable_MakeProcedure (tokno, name);
3588 : : }
3589 : 3002758 : else if (SymbolTable_IsProcedure (ProcSym))
3590 : : {
3591 : : /* avoid dangling else. */
3592 : 3002758 : SymbolTable_PutDeclared (tokno, ProcSym);
3593 : : }
3594 : : else
3595 : : {
3596 : : /* avoid dangling else. */
3597 : 0 : M2Error_ErrorStringAt2 (FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "procedure name (%a) has been declared as another object elsewhere", 65)), (const unsigned char *) &name, (sizeof (name)-1)), tokno, SymbolTable_GetDeclaredMod (ProcSym));
3598 : : }
3599 : 3002758 : if (M2Comp_CompilingDefinitionModule ())
3600 : : {
3601 : 2030336 : SymbolTable_PutExportUnImplemented (tokno, ProcSym); /* Defined but not yet implemented */
3602 : : }
3603 : : else
3604 : : {
3605 : 972422 : SymbolTable_CheckForExportedImplementation (ProcSym); /* May be exported procedure */
3606 : : }
3607 : 3002758 : M2Quads_PushTtok (ProcSym, tokno);
3608 : 3002758 : M2Quads_Annotate ((const char *) "%1s(%1d)||procedure start symbol", 32);
3609 : 3002758 : SymbolTable_StartScope (ProcSym);
3610 : 3002758 : M2Error_EnterProcedureScope (name);
3611 : 3002758 : }
3612 : :
3613 : :
3614 : : /*
3615 : : EndBuildProcedure - Ends building a Procedure.
3616 : : It checks the start procedure name matches the end
3617 : : procedure name.
3618 : :
3619 : : The Stack:
3620 : :
3621 : : (Procedure Not Defined in definition module)
3622 : :
3623 : : Entry Exit
3624 : :
3625 : : Ptr ->
3626 : : +------------+
3627 : : | NameEnd |
3628 : : |------------|
3629 : : | ProcSym |
3630 : : |------------|
3631 : : | NameStart |
3632 : : |------------|
3633 : : Empty
3634 : : */
3635 : :
3636 : 972374 : extern "C" void P2SymBuild_EndBuildProcedure (void)
3637 : : {
3638 : 972374 : NameKey_Name NameEnd;
3639 : 972374 : NameKey_Name NameStart;
3640 : 972374 : unsigned int tok;
3641 : 972374 : unsigned int ProcSym;
3642 : 972374 : SymbolTable_ProcedureKind kind;
3643 : :
3644 : 972374 : M2Quads_PopT (&NameEnd);
3645 : 972374 : M2Quads_PopTtok (&ProcSym, &tok);
3646 : 972374 : M2Debug_Assert (SymbolTable_IsProcedure (ProcSym));
3647 : 972374 : kind = SymbolTable_GetProcedureKind (ProcSym, tok);
3648 : 972374 : M2Quads_PopT (&NameStart);
3649 : 972374 : if (NameEnd != NameStart)
3650 : : {
3651 : 0 : M2Error_WriteFormat2 ((const char *) "end procedure name does not match beginning %a name %a", 54, (const unsigned char *) &NameStart, (sizeof (NameStart)-1), (const unsigned char *) &NameEnd, (sizeof (NameEnd)-1));
3652 : : }
3653 : 972374 : SymbolTable_PutProcedureParameterHeapVars (ProcSym);
3654 : 972374 : SymbolTable_PutProcedureDefined (ProcSym, kind);
3655 : 972374 : SymbolTable_EndScope ();
3656 : 972374 : M2Error_LeaveErrorScope ();
3657 : 972374 : }
3658 : :
3659 : :
3660 : : /*
3661 : : EndBuildForward - ends building a forward procedure.
3662 : : */
3663 : :
3664 : 48 : extern "C" void P2SymBuild_EndBuildForward (void)
3665 : : {
3666 : 48 : M2Quads_PopN (2);
3667 : 48 : SymbolTable_EndScope ();
3668 : 48 : M2Error_LeaveErrorScope ();
3669 : 48 : }
3670 : :
3671 : :
3672 : : /*
3673 : : BuildNoReturnAttribute - provide an interface to the symbol table module.
3674 : : */
3675 : :
3676 : 477712 : extern "C" void P2SymBuild_BuildNoReturnAttribute (void)
3677 : : {
3678 : 477712 : SymbolTable_ProcedureKind kind;
3679 : 477712 : unsigned int ProcSym;
3680 : 477712 : unsigned int tok;
3681 : :
3682 : 477712 : M2Quads_PopTtok (&ProcSym, &tok);
3683 : 477712 : M2Quads_PushTtok (ProcSym, tok);
3684 : 477712 : kind = SymbolTable_GetProcedureKind (ProcSym, tok);
3685 : 477712 : M2Debug_Assert (SymbolTable_IsProcedure (ProcSym));
3686 : 477712 : SymbolTable_PutProcedureNoReturn (ProcSym, kind, true);
3687 : 477712 : }
3688 : :
3689 : :
3690 : : /*
3691 : : CheckProcedure - checks to see that the top of stack procedure
3692 : : has not been declared as a procedure function.
3693 : :
3694 : : The Stack:
3695 : :
3696 : : Entry Exit
3697 : :
3698 : : Ptr -> <- Ptr
3699 : : +------------+ +------------+
3700 : : | ProcSym | | ProcSym |
3701 : : |------------| |------------|
3702 : : */
3703 : :
3704 : 1539156 : extern "C" void P2SymBuild_CheckProcedure (void)
3705 : : {
3706 : 1539156 : CheckProcedureReturn (SymbolTable_NulSym, M2LexBuf_UnknownTokenNo);
3707 : 1539156 : }
3708 : :
3709 : :
3710 : : /*
3711 : : BuildPointerType - builds a pointer type.
3712 : : The Stack:
3713 : :
3714 : : Entry Exit
3715 : : ===== ====
3716 : :
3717 : :
3718 : : Ptr -> <- Ptr
3719 : : +------------+ +-------------+
3720 : : | Type | | PointerType |
3721 : : |------------| |-------------|
3722 : : | Name | | Name |
3723 : : |------------| |-------------|
3724 : : */
3725 : :
3726 : 78670 : extern "C" void P2SymBuild_BuildPointerType (unsigned int pointerpos)
3727 : : {
3728 : 78670 : unsigned int combined;
3729 : 78670 : unsigned int namepos;
3730 : 78670 : unsigned int typepos;
3731 : 78670 : NameKey_Name name;
3732 : 78670 : unsigned int Type;
3733 : 78670 : unsigned int PtrToType;
3734 : :
3735 : 78670 : M2Quads_PopTtok (&Type, &typepos);
3736 : 78670 : M2Quads_PopTtok (&name, &namepos);
3737 : 78670 : name = SymbolTable_CheckAnonymous (name);
3738 : 78670 : combined = M2LexBuf_MakeVirtual2Tok (pointerpos, typepos);
3739 : 78670 : PtrToType = SymbolTable_MakePointer (combined, name);
3740 : 78670 : SymbolTable_PutPointer (PtrToType, Type);
3741 : 78670 : SymbolTable_CheckForExportedImplementation (PtrToType); /* May be an exported hidden type */
3742 : 78670 : M2Quads_PushTtok (name, namepos); /* May be an exported hidden type */
3743 : 78670 : M2Quads_Annotate ((const char *) "%1n|%3d||pointer type name", 26);
3744 : 78670 : M2Quads_PushTtok (PtrToType, combined);
3745 : 78670 : M2Quads_Annotate ((const char *) "%1s(%1d)|%3d||pointer type", 26);
3746 : 78670 : }
3747 : :
3748 : :
3749 : : /*
3750 : : BuildSetType - builds a set type.
3751 : : The Stack:
3752 : :
3753 : : Entry Exit
3754 : : ===== ====
3755 : :
3756 : :
3757 : : Ptr -> <- Ptr
3758 : : +------------+ +-------------+
3759 : : | Type | | SetType |
3760 : : |------------| |-------------|
3761 : : | Name | | Name |
3762 : : |------------| |-------------|
3763 : : */
3764 : :
3765 : 1898 : extern "C" void P2SymBuild_BuildSetType (unsigned int setpos, bool ispacked)
3766 : : {
3767 : 1898 : unsigned int combined;
3768 : 1898 : unsigned int namepos;
3769 : 1898 : unsigned int typepos;
3770 : 1898 : NameKey_Name name;
3771 : 1898 : unsigned int Type;
3772 : 1898 : unsigned int SetType;
3773 : :
3774 : 1898 : M2Quads_PopTtok (&Type, &typepos);
3775 : 1898 : M2Quads_PopTtok (&name, &namepos);
3776 : 1898 : combined = M2LexBuf_MakeVirtual2Tok (setpos, typepos);
3777 : 1898 : SetType = SymbolTable_MakeSet (combined, name);
3778 : 1898 : SymbolTable_CheckForExportedImplementation (SetType); /* May be an exported hidden type */
3779 : 1898 : SymbolTable_PutSet (SetType, Type, ispacked); /* May be an exported hidden type */
3780 : 1898 : M2Quads_PushTtok (name, namepos);
3781 : 1898 : M2Quads_Annotate ((const char *) "%1n||set type name", 18);
3782 : 1898 : M2Quads_PushTtok (SetType, combined);
3783 : 1898 : M2Quads_Annotate ((const char *) "%1s(%1d)|%3d||set type|token no", 31);
3784 : 1898 : }
3785 : :
3786 : :
3787 : : /*
3788 : : BuildRecord - Builds a record type.
3789 : : The Stack:
3790 : :
3791 : : Entry Exit
3792 : : ===== ====
3793 : :
3794 : :
3795 : : <- Ptr
3796 : : +-----------+
3797 : : Ptr -> | RecordSym |
3798 : : +------------------+ |-----------|
3799 : : | Name | | Name |
3800 : : |------------------| |-----------|
3801 : : */
3802 : :
3803 : 50093 : extern "C" void P2SymBuild_BuildRecord (void)
3804 : : {
3805 : 50093 : unsigned int tokno;
3806 : 50093 : NameKey_Name name;
3807 : 50093 : unsigned int RecordType;
3808 : :
3809 : 50093 : name = static_cast<NameKey_Name> (M2Quads_OperandT (1));
3810 : 50093 : name = SymbolTable_CheckAnonymous (name);
3811 : 50093 : tokno = static_cast<unsigned int> (M2Quads_OperandTok (1));
3812 : 50093 : RecordType = SymbolTable_MakeRecord (tokno, name);
3813 : 50093 : SymbolTable_CheckForExportedImplementation (RecordType); /* May be an exported hidden type */
3814 : 50093 : M2Quads_PushT (RecordType);
3815 : : /* ; WriteKey(name) ; WriteString(' RECORD made') ; WriteLn */
3816 : 50093 : M2Quads_Annotate ((const char *) "%1s(%1d)||record type", 21);
3817 : 50093 : }
3818 : :
3819 : :
3820 : : /*
3821 : : BuildFieldRecord - Builds a field into a record sym.
3822 : : The Stack:
3823 : :
3824 : :
3825 : : Entry Exit
3826 : : ===== ====
3827 : :
3828 : : Ptr ->
3829 : : +-------------+
3830 : : | NoOfPragmas |
3831 : : |-------------|
3832 : : | Const1 |
3833 : : |-------------|
3834 : : | PragmaName1 |
3835 : : |-------------|
3836 : : | Type | Name |
3837 : : |-------------|
3838 : : | n |
3839 : : |-------------|
3840 : : | Id 1 |
3841 : : |-------------|
3842 : : . .
3843 : : . .
3844 : : . .
3845 : : |-------------|
3846 : : | Id n | <- Ptr
3847 : : |-------------| +-------------+
3848 : : | RecordSym | | RecordSym |
3849 : : |-------------| |-------------|
3850 : : | RecordName | | RecordName |
3851 : : |-------------| |-------------|
3852 : : */
3853 : :
3854 : 228482 : extern "C" void P2SymBuild_BuildFieldRecord (void)
3855 : : {
3856 : 228482 : NameKey_Name n1;
3857 : 228482 : unsigned int tok;
3858 : 228482 : unsigned int fsym;
3859 : 228482 : unsigned int Field;
3860 : 228482 : unsigned int Varient;
3861 : 228482 : unsigned int Parent;
3862 : 228482 : unsigned int Type;
3863 : 228482 : unsigned int NoOfPragmas;
3864 : 228482 : unsigned int NoOfFields;
3865 : 228482 : unsigned int Record;
3866 : 228482 : unsigned int i;
3867 : :
3868 : 228482 : M2Quads_PopT (&NoOfPragmas);
3869 : 228482 : Type = static_cast<unsigned int> (M2Quads_OperandT ((NoOfPragmas*2)+1));
3870 : : /* name := OperandF(NoOfPragmas*2+1) ; */
3871 : 228482 : NoOfFields = static_cast<unsigned int> (M2Quads_OperandT ((NoOfPragmas*2)+2));
3872 : 228482 : Record = static_cast<unsigned int> (M2Quads_OperandT (((NoOfPragmas*2)+NoOfFields)+3));
3873 : 228482 : if (SymbolTable_IsRecord (Record))
3874 : : {
3875 : : Parent = Record;
3876 : : Varient = SymbolTable_NulSym;
3877 : : }
3878 : : else
3879 : : {
3880 : : /* Record maybe FieldVarient */
3881 : 576 : Parent = SymbolTable_GetRecord (SymbolTable_GetParent (Record));
3882 : 570 : M2Debug_Assert (SymbolTable_IsFieldVarient (Record));
3883 : 570 : Varient = static_cast<unsigned int> (M2Quads_OperandT (((NoOfPragmas*2)+NoOfFields)+4));
3884 : 570 : M2Debug_Assert (SymbolTable_IsVarient (Varient));
3885 : 570 : SymbolTable_PutFieldVarient (Record, Varient);
3886 : 570 : if (Debugging)
3887 : : {
3888 : : n1 = SymbolTable_GetSymName (Record);
3889 : : StrIO_WriteString ((const char *) "Record ", 7);
3890 : : NameKey_WriteKey (n1);
3891 : : StrIO_WriteString ((const char *) " has varient ", 13);
3892 : : n1 = SymbolTable_GetSymName (Varient);
3893 : : NameKey_WriteKey (n1);
3894 : : StrIO_WriteLn ();
3895 : : }
3896 : : }
3897 : 228476 : Field = SymbolTable_NulSym;
3898 : 228476 : i = 1;
3899 : 490334 : while (i <= NoOfFields)
3900 : : {
3901 : 261858 : if (Debugging)
3902 : : {
3903 : : n1 = SymbolTable_GetSymName (Record);
3904 : : StrIO_WriteString ((const char *) "Record ", 7);
3905 : : NameKey_WriteKey (n1);
3906 : : StrIO_WriteString ((const char *) " ", 2);
3907 : : NameKey_WriteKey (M2Quads_OperandT ((((NoOfPragmas*2)+NoOfFields)+3)-i));
3908 : : StrIO_WriteString ((const char *) " is a Field with type ", 22);
3909 : : NameKey_WriteKey (SymbolTable_GetSymName (Type));
3910 : : StrIO_WriteLn ();
3911 : : }
3912 : 261858 : fsym = SymbolTable_GetLocalSym (Parent, M2Quads_OperandT ((((NoOfPragmas*2)+NoOfFields)+3)-i));
3913 : 261858 : if (fsym == SymbolTable_NulSym)
3914 : : {
3915 : 261852 : Field = SymbolTable_PutFieldRecord (Record, M2Quads_OperandT ((((NoOfPragmas*2)+NoOfFields)+3)-i), Type, Varient);
3916 : 261852 : HandleRecordFieldPragmas (Record, Field, NoOfPragmas);
3917 : : }
3918 : : else
3919 : : {
3920 : 6 : M2MetaError_MetaErrors2 ((const char *) "record field {%1ad} has already been declared inside a {%2Dd} {%2a}", 67, (const char *) "attempting to declare a duplicate record field", 46, fsym, Parent);
3921 : : }
3922 : : /* adjust the location of declaration to the one on the stack (rather than GetTokenNo). */
3923 : 261858 : tok = static_cast<unsigned int> (M2Quads_OperandTok ((((NoOfPragmas*2)+NoOfFields)+3)-i));
3924 : 261858 : if ((tok != M2LexBuf_UnknownTokenNo) && (Field != SymbolTable_NulSym))
3925 : : {
3926 : 261852 : SymbolTable_PutDeclared (tok, Field);
3927 : : }
3928 : 261858 : i += 1;
3929 : : }
3930 : 228476 : M2Quads_PopN (((NoOfPragmas*2)+NoOfFields)+3);
3931 : 228476 : M2Quads_PushT (Record);
3932 : 228476 : if (SymbolTable_IsRecord (Record))
3933 : : {
3934 : 227906 : M2Quads_Annotate ((const char *) "%1s(%1d)||record type", 21);
3935 : : }
3936 : : else
3937 : : {
3938 : 570 : M2Debug_Assert (SymbolTable_IsFieldVarient (Record));
3939 : 570 : M2Quads_Annotate ((const char *) "%1s(%1d)||varient field type", 28);
3940 : : }
3941 : 228476 : }
3942 : :
3943 : :
3944 : : /*
3945 : : StartBuildVarient - Builds a varient symbol on top of a record sym.
3946 : : The Stack:
3947 : :
3948 : :
3949 : : Entry Exit
3950 : : ===== ====
3951 : :
3952 : : <- Ptr
3953 : : +-------------+
3954 : : Ptr -> | VarientSym |
3955 : : +-------------+ |-------------|
3956 : : | RecordSym | | RecordSym |
3957 : : |-------------| |-------------|
3958 : : | RecordName | | RecordName |
3959 : : |-------------| |-------------|
3960 : : */
3961 : :
3962 : 276 : extern "C" void P2SymBuild_StartBuildVarient (void)
3963 : : {
3964 : 276 : unsigned int tokno;
3965 : 276 : unsigned int RecordSym;
3966 : 276 : unsigned int Sym;
3967 : :
3968 : 276 : RecordSym = static_cast<unsigned int> (M2Quads_OperandT (1));
3969 : 276 : tokno = static_cast<unsigned int> (M2Quads_OperandTok (1));
3970 : 276 : Sym = SymbolTable_MakeVarient (tokno, RecordSym);
3971 : 276 : M2Quads_PushT (Sym);
3972 : 276 : M2Quads_Annotate ((const char *) "%1s(%1d)||varient type", 22);
3973 : 276 : }
3974 : :
3975 : :
3976 : : /*
3977 : : EndBuildVarient - Removes the varient symbol from the stack.
3978 : : The Stack:
3979 : :
3980 : : Entry Exit
3981 : : ===== ====
3982 : :
3983 : : Ptr ->
3984 : : +-------------+
3985 : : | VarientSym | <- Ptr
3986 : : |-------------| +-------------+
3987 : : | RecordSym | | RecordSym |
3988 : : |-------------| |-------------|
3989 : : | RecordName | | RecordName |
3990 : : |-------------| |-------------|
3991 : : */
3992 : :
3993 : 276 : extern "C" void P2SymBuild_EndBuildVarient (void)
3994 : : {
3995 : 276 : unsigned int Sym;
3996 : :
3997 : 276 : M2Quads_PopT (&Sym);
3998 : 276 : }
3999 : :
4000 : :
4001 : : /*
4002 : : BuildVarientSelector - Builds a field into a record sym.
4003 : : The Stack:
4004 : :
4005 : :
4006 : : Entry Exit
4007 : : ===== ====
4008 : :
4009 : : Ptr ->
4010 : : +-------------+
4011 : : | Type |
4012 : : |-------------|
4013 : : | Tag | <- Ptr
4014 : : |-------------| +-------------+
4015 : : | RecordSym | | RecordSym |
4016 : : |-------------| |-------------|
4017 : : */
4018 : :
4019 : 276 : extern "C" void P2SymBuild_BuildVarientSelector (void)
4020 : : {
4021 : 276 : unsigned int tagtok;
4022 : 276 : NameKey_Name tag;
4023 : 276 : unsigned int Field;
4024 : 276 : unsigned int Type;
4025 : 276 : unsigned int Varient;
4026 : 276 : unsigned int VarField;
4027 : 276 : unsigned int Record;
4028 : :
4029 : 276 : M2Quads_PopT (&Type);
4030 : 276 : M2Quads_PopTtok (&tag, &tagtok);
4031 : 276 : Record = static_cast<unsigned int> (M2Quads_OperandT (1));
4032 : 276 : if (SymbolTable_IsRecord (Record))
4033 : : {
4034 : 0 : Varient = SymbolTable_NulSym;
4035 : 0 : M2Error_InternalError ((const char *) "not expecting a record symbol", 29);
4036 : : }
4037 : 276 : else if (SymbolTable_IsVarient (Record))
4038 : : {
4039 : : /* avoid dangling else. */
4040 : 276 : Varient = Record;
4041 : 276 : VarField = SymbolTable_GetParent (Varient);
4042 : 276 : if ((Type == SymbolTable_NulSym) && (tag == NameKey_NulName))
4043 : : {
4044 : 0 : M2MetaError_MetaError1 ((const char *) "expecting a tag field in the declaration of a varient record {%1Ua}", 67, Record);
4045 : : }
4046 : 276 : else if (Type == SymbolTable_NulSym)
4047 : : {
4048 : : /* avoid dangling else. */
4049 : 12 : SymbolTable_PutVarientTag (Varient, SymbolTable_RequestSym (tagtok, tag));
4050 : : }
4051 : : else
4052 : : {
4053 : : /* avoid dangling else. */
4054 : 264 : Field = SymbolTable_PutFieldRecord (VarField, tag, Type, Varient);
4055 : 264 : SymbolTable_PutVarientTag (Varient, Field);
4056 : 264 : if (Debugging)
4057 : : {
4058 : : StrIO_WriteString ((const char *) "varient field ", 14);
4059 : : NameKey_WriteKey (SymbolTable_GetSymName (VarField));
4060 : : StrIO_WriteString ((const char *) "varient ", 8);
4061 : : NameKey_WriteKey (SymbolTable_GetSymName (Varient));
4062 : : StrIO_WriteLn ();
4063 : : }
4064 : : }
4065 : : }
4066 : : else
4067 : : {
4068 : : /* avoid dangling else. */
4069 : : /* Record maybe FieldVarient */
4070 : 0 : M2Debug_Assert (SymbolTable_IsFieldVarient (Record));
4071 : 0 : Varient = static_cast<unsigned int> (M2Quads_OperandT (1+2));
4072 : 0 : M2Debug_Assert (SymbolTable_IsVarient (Varient));
4073 : 0 : SymbolTable_PutFieldVarient (Record, Varient);
4074 : 0 : if (Debugging)
4075 : : {
4076 : : StrIO_WriteString ((const char *) "record ", 7);
4077 : : NameKey_WriteKey (SymbolTable_GetSymName (Record));
4078 : : StrIO_WriteString ((const char *) "varient ", 8);
4079 : : NameKey_WriteKey (SymbolTable_GetSymName (Varient));
4080 : : StrIO_WriteLn ();
4081 : : }
4082 : 0 : if ((Type == SymbolTable_NulSym) && (tag == NameKey_NulName))
4083 : : {
4084 : 0 : M2MetaError_MetaError1 ((const char *) "expecting a tag field in the declaration of a varient record {%1Ua}", 67, Record);
4085 : : }
4086 : 0 : else if (Type == SymbolTable_NulSym)
4087 : : {
4088 : : /* avoid dangling else. */
4089 : 0 : SymbolTable_PutVarientTag (Varient, SymbolTable_RequestSym (tagtok, tag));
4090 : : }
4091 : : else
4092 : : {
4093 : : /* avoid dangling else. */
4094 : 0 : Field = SymbolTable_PutFieldRecord (Record, tag, Type, Varient);
4095 : 0 : SymbolTable_PutVarientTag (Varient, Field);
4096 : 0 : if (Debugging)
4097 : : {
4098 : : StrIO_WriteString ((const char *) "record ", 7);
4099 : : NameKey_WriteKey (SymbolTable_GetSymName (Record));
4100 : : StrIO_WriteString ((const char *) "varient ", 8);
4101 : : NameKey_WriteKey (SymbolTable_GetSymName (Varient));
4102 : : StrIO_WriteLn ();
4103 : : }
4104 : : }
4105 : : }
4106 : 276 : }
4107 : :
4108 : :
4109 : : /*
4110 : : StartBuildVarientFieldRecord - Builds a varient field into a varient sym.
4111 : : The Stack:
4112 : :
4113 : :
4114 : : Entry Exit
4115 : : ===== ====
4116 : :
4117 : : <- Ptr
4118 : : +-------------+
4119 : : Ptr -> | VarientField|
4120 : : +-------------+ |-------------|
4121 : : | VarientSym | | VarientSym |
4122 : : |-------------| |-------------|
4123 : : */
4124 : :
4125 : 666 : extern "C" void P2SymBuild_StartBuildVarientFieldRecord (void)
4126 : : {
4127 : 666 : unsigned int VarientSym;
4128 : 666 : unsigned int FieldSym;
4129 : :
4130 : 666 : VarientSym = static_cast<unsigned int> (M2Quads_OperandT (1));
4131 : 666 : FieldSym = SymbolTable_MakeFieldVarient (SymbolTable_CheckAnonymous (NameKey_NulName), VarientSym);
4132 : 666 : M2Quads_Annotate ((const char *) "%1s(%1d)||varient sym", 21);
4133 : 666 : M2Quads_PushT (FieldSym);
4134 : 666 : M2Quads_Annotate ((const char *) "%1s(%1d)||varient field type", 28);
4135 : 666 : M2Debug_Assert (SymbolTable_IsFieldVarient (FieldSym));
4136 : 666 : SymbolTable_PutFieldVarient (FieldSym, VarientSym);
4137 : 666 : M2Quads_AddVarientFieldToList (FieldSym);
4138 : 666 : }
4139 : :
4140 : :
4141 : : /*
4142 : : EndBuildVarientFieldRecord - Removes a varient field from the stack.
4143 : : The Stack:
4144 : :
4145 : :
4146 : : Entry Exit
4147 : : ===== ====
4148 : :
4149 : : Ptr ->
4150 : : +-------------+
4151 : : | VarientField| <- Ptr
4152 : : |-------------| +-------------+
4153 : : | VarientSym | | VarientSym |
4154 : : |-------------| |-------------|
4155 : : */
4156 : :
4157 : 666 : extern "C" void P2SymBuild_EndBuildVarientFieldRecord (void)
4158 : : {
4159 : 666 : unsigned int FieldSym;
4160 : :
4161 : 666 : M2Quads_PopT (&FieldSym);
4162 : 666 : }
4163 : :
4164 : :
4165 : : /*
4166 : : BuildNulName - Pushes a NulName onto the top of the stack.
4167 : : The Stack:
4168 : :
4169 : :
4170 : : Entry Exit
4171 : :
4172 : : <- Ptr
4173 : : Empty +------------+
4174 : : | NulName |
4175 : : |------------|
4176 : : */
4177 : :
4178 : 1202692 : extern "C" void P2SymBuild_BuildNulName (void)
4179 : : {
4180 : 1202692 : M2Quads_PushTtok (static_cast<unsigned int> (NameKey_NulName), M2LexBuf_GetTokenNo ());
4181 : 1202692 : M2Quads_Annotate ((const char *) "%1n|%3d||NulName|token no", 25);
4182 : 1202692 : }
4183 : :
4184 : :
4185 : : /*
4186 : : BuildTypeEnd - Pops the type Type and Name.
4187 : : The Stack:
4188 : :
4189 : :
4190 : : Entry Exit
4191 : :
4192 : :
4193 : : Ptr ->
4194 : : +-------------+
4195 : : | Type | Name | Empty
4196 : : |-------------|
4197 : : */
4198 : :
4199 : 127607 : extern "C" void P2SymBuild_BuildTypeEnd (void)
4200 : : {
4201 : 127607 : unsigned int Type;
4202 : 127607 : NameKey_Name name;
4203 : :
4204 : 127607 : M2Quads_PopTF (&Type, &name);
4205 : 127607 : }
4206 : :
4207 : :
4208 : : /*
4209 : : StartBuildArray - Builds an array type.
4210 : : The Stack:
4211 : :
4212 : : Entry Exit
4213 : : ===== ====
4214 : :
4215 : : <- Ptr
4216 : : +-----------+
4217 : : Ptr -> | ArraySym |
4218 : : +------------+ |-----------|
4219 : : | Name | | Name |
4220 : : |------------| |-----------|
4221 : : */
4222 : :
4223 : 85458 : extern "C" void P2SymBuild_StartBuildArray (void)
4224 : : {
4225 : 85458 : unsigned int tok;
4226 : 85458 : NameKey_Name name;
4227 : 85458 : unsigned int ArrayType;
4228 : :
4229 : 85458 : name = static_cast<NameKey_Name> (M2Quads_OperandT (1));
4230 : 85458 : tok = static_cast<unsigned int> (M2Quads_OperandTok (1));
4231 : 85458 : ArrayType = SymbolTable_MakeArray (tok, name);
4232 : 85458 : SymbolTable_CheckForExportedImplementation (ArrayType); /* May be an exported hidden type */
4233 : 85458 : M2Quads_PushTtok (ArrayType, tok); /* May be an exported hidden type */
4234 : : /* ; WriteKey(Name) ; WriteString(' ARRAY made') ; WriteLn */
4235 : 85458 : M2Quads_Annotate ((const char *) "%1s(%1d)|%3d||array type|token no", 33);
4236 : 85458 : }
4237 : :
4238 : :
4239 : : /*
4240 : : EndBuildArray - Builds an array type.
4241 : : The Stack:
4242 : :
4243 : : Entry Exit
4244 : : ===== ====
4245 : :
4246 : : Ptr ->
4247 : : +------------+
4248 : : | TypeSym | <- Ptr
4249 : : |------------| +------------+
4250 : : | ArraySym | | ArraySym |
4251 : : |------------| |------------|
4252 : : | Name | | Name |
4253 : : |------------| |------------|
4254 : : */
4255 : :
4256 : 85458 : extern "C" void P2SymBuild_EndBuildArray (void)
4257 : : {
4258 : 85458 : unsigned int typetok;
4259 : 85458 : unsigned int arraytok;
4260 : 85458 : unsigned int combinedtok;
4261 : 85458 : unsigned int TypeSym;
4262 : 85458 : unsigned int ArraySym;
4263 : :
4264 : 85458 : M2Quads_PopTtok (&TypeSym, &typetok);
4265 : 85458 : M2Quads_PopTtok (&ArraySym, &arraytok);
4266 : 85458 : M2Debug_Assert (SymbolTable_IsArray (ArraySym));
4267 : 85458 : combinedtok = M2LexBuf_MakeVirtual2Tok (arraytok, typetok);
4268 : 85458 : SymbolTable_PutArray (ArraySym, TypeSym);
4269 : 85458 : SymbolTable_PutDeclared (combinedtok, ArraySym);
4270 : 85458 : M2Quads_PushTtok (ArraySym, combinedtok);
4271 : 85458 : M2Quads_Annotate ((const char *) "%1s(%1d)||array type", 20);
4272 : 85458 : }
4273 : :
4274 : :
4275 : : /*
4276 : : BuildFieldArray - Builds a field into an array sym.
4277 : : The Stack:
4278 : :
4279 : :
4280 : : Entry Exit
4281 : : ===== ====
4282 : :
4283 : : Ptr ->
4284 : : +-------------+
4285 : : | Type | Name | <- Ptr
4286 : : |-------------| +-------------+
4287 : : | ArraySym | | ArraySym |
4288 : : |-------------| |-------------|
4289 : : | ArrayName | | ArrayName |
4290 : : |-------------| |-------------|
4291 : : */
4292 : :
4293 : 85458 : extern "C" void P2SymBuild_BuildFieldArray (void)
4294 : : {
4295 : 85458 : unsigned int typetok;
4296 : 85458 : unsigned int arraytok;
4297 : 85458 : unsigned int Subscript;
4298 : 85458 : unsigned int Type;
4299 : 85458 : unsigned int Array;
4300 : 85458 : NameKey_Name name;
4301 : :
4302 : 85458 : M2Quads_PopTFtok (&Type, &name, &typetok);
4303 : 85458 : M2Quads_PopTtok (&Array, &arraytok);
4304 : 85458 : M2Debug_Assert (SymbolTable_IsArray (Array));
4305 : 85458 : Subscript = SymbolTable_MakeSubscript ();
4306 : : /*
4307 : : We cannot Assert(IsSubrange(Type)) as the subrange type might be
4308 : : declared later on in the file.
4309 : : We also note it could be an ordinal type or enumerated type.
4310 : : Therefore we must save this information and deal with the
4311 : : different cases in M2GCCDeclare.mod and M2GenGCC.mod.
4312 : : However this works to our advantage as it preserves the
4313 : : actual declaration as specified by the source file.
4314 : : */
4315 : 85458 : SymbolTable_PutSubscript (Subscript, Type);
4316 : 85458 : SymbolTable_PutArraySubscript (Array, Subscript);
4317 : 85458 : M2Quads_PushTtok (Array, arraytok);
4318 : : /* ; WriteString('Field Placed in Array') ; WriteLn */
4319 : 85458 : M2Quads_Annotate ((const char *) "%1s(%1d)||array type", 20);
4320 : 85458 : }
4321 : :
4322 : :
4323 : : /*
4324 : : BuildArrayComma - converts ARRAY [..], [..] OF into ARRAY [..] OF ARRAY [..]
4325 : :
4326 : :
4327 : : Ptr -> <- Ptr
4328 : : +-------------+ +-------------+
4329 : : | ArraySym1 | | ArraySym2 |
4330 : : |-------------| |-------------|
4331 : : | ArrayName | | ArrayName |
4332 : : |-------------| |-------------|
4333 : : */
4334 : :
4335 : 140 : extern "C" void P2SymBuild_BuildArrayComma (void)
4336 : : {
4337 : 140 : unsigned int Nothing;
4338 : 140 : unsigned int ArraySym1;
4339 : 140 : unsigned int ArraySym2;
4340 : :
4341 : 140 : M2Quads_PushT (static_cast<unsigned int> (NameKey_NulName));
4342 : 140 : P2SymBuild_StartBuildArray ();
4343 : 140 : M2Quads_PopT (&ArraySym2);
4344 : 140 : M2Quads_PopT (&Nothing);
4345 : 140 : M2Quads_PushT (ArraySym2);
4346 : 140 : P2SymBuild_EndBuildArray ();
4347 : 140 : M2Quads_PopT (&ArraySym1);
4348 : 140 : M2Quads_PushT (ArraySym2);
4349 : 140 : M2Quads_Annotate ((const char *) "%1s(%1d)||array type comma", 26);
4350 : 140 : }
4351 : :
4352 : :
4353 : : /*
4354 : : BuildProcedureType - builds a procedure type symbol.
4355 : : The Stack:
4356 : :
4357 : :
4358 : : <- Ptr
4359 : : +-------------+
4360 : : Ptr -> | ProcTypeSym |
4361 : : +-------------+ |-------------|
4362 : : | Name | | Name |
4363 : : |-------------| |-------------|
4364 : : */
4365 : :
4366 : 56096 : extern "C" void P2SymBuild_BuildProcedureType (void)
4367 : : {
4368 : 56096 : unsigned int tok;
4369 : 56096 : NameKey_Name name;
4370 : 56096 : unsigned int ProcTypeSym;
4371 : :
4372 : 56096 : name = static_cast<NameKey_Name> (M2Quads_OperandT (1));
4373 : 56096 : tok = static_cast<unsigned int> (M2Quads_OperandTok (1));
4374 : 56096 : ProcTypeSym = SymbolTable_MakeProcType (tok, name);
4375 : 56096 : SymbolTable_CheckForExportedImplementation (ProcTypeSym); /* May be an exported hidden type */
4376 : 56096 : M2Quads_Annotate ((const char *) "%1n||procedure type name", 24); /* May be an exported hidden type */
4377 : 56096 : M2Quads_PushTtok (ProcTypeSym, tok);
4378 : 56096 : M2Quads_Annotate ((const char *) "%1s(%1d)|%3d||proc type|token no", 32);
4379 : 56096 : }
4380 : :
4381 : :
4382 : : /*
4383 : : BuildFormalType - Builds a Formal Parameter in a procedure type.
4384 : :
4385 : : The Stack:
4386 : :
4387 : : Entry Exit
4388 : :
4389 : : Ptr ->
4390 : : +------------+
4391 : : | TypeSym |
4392 : : |------------|
4393 : : | Array/Nul |
4394 : : |------------|
4395 : : | Var / Nul | <- Ptr
4396 : : |------------| +--------------+
4397 : : | ProcTypeSym| | ProcTypeSym |
4398 : : |------------| |--------------|
4399 : : */
4400 : :
4401 : 79861 : extern "C" void P2SymBuild_BuildFormalType (void)
4402 : : {
4403 : 79861 : unsigned int tok;
4404 : 79861 : NameKey_Name Array;
4405 : 79861 : NameKey_Name Var;
4406 : 79861 : unsigned int TypeSym;
4407 : 79861 : unsigned int UnboundedSym;
4408 : 79861 : unsigned int ProcTypeSym;
4409 : :
4410 : 79861 : M2Quads_PopT (&TypeSym);
4411 : 79861 : M2Quads_PopT (&Array);
4412 : 79861 : M2Quads_PopT (&Var);
4413 : 79861 : M2Quads_PopT (&ProcTypeSym);
4414 : 79861 : tok = M2LexBuf_GetTokenNo ();
4415 : 159722 : M2Debug_Assert ((Array == M2Reserved_ArrayTok) || (Array == M2Reserved_NulTok));
4416 : 79861 : M2Debug_Assert (SymbolTable_IsProcType (ProcTypeSym));
4417 : 159722 : M2Debug_Assert ((Var == M2Reserved_VarTok) || (Var == M2Reserved_NulTok));
4418 : 79861 : if (Array == M2Reserved_ArrayTok)
4419 : : {
4420 : 360 : UnboundedSym = SymbolTable_MakeUnbounded (tok, TypeSym, 1);
4421 : 360 : TypeSym = UnboundedSym;
4422 : : }
4423 : 79861 : if (Var == M2Reserved_VarTok)
4424 : : {
4425 : : /* VAR parameter */
4426 : 6108 : SymbolTable_PutProcTypeVarParam (ProcTypeSym, TypeSym, SymbolTable_IsUnbounded (TypeSym));
4427 : : }
4428 : : else
4429 : : {
4430 : : /* Non VAR parameter */
4431 : 73753 : SymbolTable_PutProcTypeParam (ProcTypeSym, TypeSym, SymbolTable_IsUnbounded (TypeSym));
4432 : : }
4433 : 79861 : M2Quads_PushT (ProcTypeSym);
4434 : 79861 : M2Quads_Annotate ((const char *) "%1s(%1d)||proc type", 19);
4435 : 79861 : }
4436 : :
4437 : :
4438 : : /*
4439 : : SeenUnknown - sets the operand type to unknown.
4440 : : */
4441 : :
4442 : 13974779 : extern "C" void P2SymBuild_SeenUnknown (void)
4443 : : {
4444 : 13974779 : type = M2Const_unknown;
4445 : 13974779 : }
4446 : :
4447 : :
4448 : : /*
4449 : : SeenCast - sets the operand type to cast.
4450 : : */
4451 : :
4452 : 0 : extern "C" void P2SymBuild_SeenCast (unsigned int sym)
4453 : : {
4454 : 0 : type = M2Const_cast;
4455 : 0 : castType = sym;
4456 : 0 : M2Debug_Assert (SymbolTable_IsAModula2Type (sym));
4457 : 0 : }
4458 : :
4459 : :
4460 : : /*
4461 : : SeenSet - sets the operand type to set.
4462 : : */
4463 : :
4464 : 350 : extern "C" void P2SymBuild_SeenSet (void)
4465 : : {
4466 : 350 : SetTypeTo (M2Const_set);
4467 : 350 : SaveRememberedConstructor ();
4468 : 350 : }
4469 : :
4470 : :
4471 : : /*
4472 : : SeenConstructor - sets the operand type to constructor.
4473 : : */
4474 : :
4475 : 22046 : extern "C" void P2SymBuild_SeenConstructor (void)
4476 : : {
4477 : 22046 : SetTypeTo (M2Const_constructor);
4478 : 22046 : SaveRememberedConstructor ();
4479 : 22046 : }
4480 : :
4481 : :
4482 : : /*
4483 : : SeenArray - sets the operand type to array.
4484 : : */
4485 : :
4486 : 30 : extern "C" void P2SymBuild_SeenArray (void)
4487 : : {
4488 : 30 : SetTypeTo (M2Const_array);
4489 : 30 : }
4490 : :
4491 : :
4492 : : /*
4493 : : SeenString - sets the operand type to string.
4494 : : */
4495 : :
4496 : 12691 : extern "C" void P2SymBuild_SeenString (void)
4497 : : {
4498 : 12691 : SetTypeTo (M2Const_str);
4499 : 12691 : }
4500 : :
4501 : :
4502 : : /*
4503 : : SeenBoolean - sets the operand type to a BOOLEAN.
4504 : : */
4505 : :
4506 : 0 : extern "C" void P2SymBuild_SeenBoolean (void)
4507 : : {
4508 : 0 : type = M2Const_boolean;
4509 : 0 : }
4510 : :
4511 : :
4512 : : /*
4513 : : SeenZType - sets the operand type to a Z type.
4514 : : */
4515 : :
4516 : 0 : extern "C" void P2SymBuild_SeenZType (void)
4517 : : {
4518 : 0 : type = M2Const_ztype;
4519 : 0 : }
4520 : :
4521 : :
4522 : : /*
4523 : : SeenRType - sets the operand type to a R type.
4524 : : */
4525 : :
4526 : 0 : extern "C" void P2SymBuild_SeenRType (void)
4527 : : {
4528 : 0 : type = M2Const_rtype;
4529 : 0 : }
4530 : :
4531 : :
4532 : : /*
4533 : : SeenCType - sets the operand type to a C type.
4534 : : */
4535 : :
4536 : 0 : extern "C" void P2SymBuild_SeenCType (void)
4537 : : {
4538 : 0 : type = M2Const_ctype;
4539 : 0 : }
4540 : :
4541 : :
4542 : : /*
4543 : : DetermineType - assigns the top of stack symbol with the type of
4544 : : constant expression, if known.
4545 : : */
4546 : :
4547 : 246752 : extern "C" void P2SymBuild_DetermineType (void)
4548 : : {
4549 : 246752 : unsigned int Sym;
4550 : :
4551 : 246752 : Sym = static_cast<unsigned int> (M2Quads_OperandT (1));
4552 : 246752 : switch (type)
4553 : : {
4554 : 12 : case M2Const_set:
4555 : 12 : SymbolTable_PutConstSet (Sym);
4556 : 12 : break;
4557 : :
4558 : 1390 : case M2Const_str:
4559 : 1390 : SymbolTable_PutConstStringKnown (M2LexBuf_GetTokenNo (), Sym, NameKey_MakeKey ((const char *) "", 0), false, false);
4560 : 1390 : break;
4561 : :
4562 : 4100 : case M2Const_array:
4563 : 4100 : case M2Const_constructor:
4564 : 4100 : SymbolTable_PutConstructor (Sym);
4565 : 4100 : break;
4566 : :
4567 : 0 : case M2Const_cast:
4568 : 0 : SymbolTable_PutConst (Sym, castType);
4569 : 0 : break;
4570 : :
4571 : : case M2Const_unknown:
4572 : : break;
4573 : :
4574 : :
4575 : : default:
4576 : : break;
4577 : : }
4578 : 246752 : }
4579 : :
4580 : :
4581 : : /*
4582 : : PushType -
4583 : : */
4584 : :
4585 : 12750279 : extern "C" void P2SymBuild_PushType (void)
4586 : : {
4587 : 12750279 : M2StackWord_PushWord (TypeStack, static_cast<unsigned int> (type));
4588 : 12750279 : }
4589 : :
4590 : :
4591 : : /*
4592 : : PopType -
4593 : : */
4594 : :
4595 : 12750279 : extern "C" void P2SymBuild_PopType (void)
4596 : : {
4597 : 12750279 : type = static_cast<M2Const_constType> (M2StackWord_PopWord (TypeStack));
4598 : 12750279 : }
4599 : :
4600 : :
4601 : : /*
4602 : : PushRememberConstant -
4603 : : */
4604 : :
4605 : 27890 : extern "C" void P2SymBuild_PushRememberConstant (void)
4606 : : {
4607 : 27890 : M2StackWord_PushWord (RememberStack, RememberedConstant);
4608 : 27890 : P2SymBuild_RememberConstant (SymbolTable_NulSym);
4609 : 27890 : }
4610 : :
4611 : :
4612 : : /*
4613 : : PopRememberConstant -
4614 : : */
4615 : :
4616 : 27890 : extern "C" void P2SymBuild_PopRememberConstant (void)
4617 : : {
4618 : 27890 : RememberedConstant = static_cast<unsigned int> (M2StackWord_PopWord (RememberStack));
4619 : 27890 : }
4620 : :
4621 : :
4622 : : /*
4623 : : RememberConstant -
4624 : : */
4625 : :
4626 : 274642 : extern "C" void P2SymBuild_RememberConstant (unsigned int sym)
4627 : : {
4628 : 274642 : RememberedConstant = sym;
4629 : 274642 : }
4630 : :
4631 : 15260 : extern "C" void _M2_P2SymBuild_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
4632 : : {
4633 : 15260 : alignTypeNo = 0;
4634 : 15260 : TypeStack = M2StackWord_InitStackWord ();
4635 : 15260 : RememberStack = M2StackWord_InitStackWord ();
4636 : 15260 : BlockStack = M2StackWord_InitStackWord ();
4637 : 15260 : castType = SymbolTable_NulSym;
4638 : 15260 : }
4639 : :
4640 : 0 : extern "C" void _M2_P2SymBuild_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
4641 : : {
4642 : 0 : }
|