Line data Source code
1 : /* do not edit automatically generated by mc from PCSymBuild. */
2 : /* PCSymBuild.mod pass C symbol creation.
3 :
4 : Copyright (C) 2001-2026 Free Software Foundation, Inc.
5 : Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 :
7 : This file is part of GNU Modula-2.
8 :
9 : GNU Modula-2 is free software; you can redistribute it and/or modify
10 : it under the terms of the GNU General Public License as published by
11 : the Free Software Foundation; either version 3, or (at your option)
12 : any later version.
13 :
14 : GNU Modula-2 is distributed in the hope that it will be useful, but
15 : WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : General Public License for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with GNU Modula-2; see the file COPYING3. If not see
21 : <http://www.gnu.org/licenses/>. */
22 :
23 : #include "config.h"
24 : #include "system.h"
25 : #include "gcc-consolidation.h"
26 :
27 : #include <stdbool.h>
28 : # if !defined (PROC_D)
29 : # define PROC_D
30 : typedef void (*PROC_t) (void);
31 : typedef struct { PROC_t proc; } PROC;
32 : # endif
33 :
34 : # if !defined (TRUE)
35 : # define TRUE (1==1)
36 : # endif
37 :
38 : # if !defined (FALSE)
39 : # define FALSE (1==0)
40 : # endif
41 :
42 : # include "GStorage.h"
43 : # include "Gmcrts.h"
44 : #if defined(__cplusplus)
45 : # undef NULL
46 : # define NULL 0
47 : #endif
48 : #define _PCSymBuild_C
49 :
50 : #include "GPCSymBuild.h"
51 : # include "GStorage.h"
52 : # include "GNameKey.h"
53 : # include "GStrIO.h"
54 : # include "GNumberIO.h"
55 : # include "GM2Debug.h"
56 : # include "GM2Error.h"
57 : # include "GM2MetaError.h"
58 : # include "GM2LexBuf.h"
59 : # include "GM2Reserved.h"
60 : # include "GM2Const.h"
61 : # include "GIndexing.h"
62 : # include "GM2Quads.h"
63 : # include "GM2Options.h"
64 : # include "GStdIO.h"
65 : # include "GM2System.h"
66 : # include "GM2Base.h"
67 : # include "GSymbolTable.h"
68 : # include "GM2Batch.h"
69 : # include "GM2Comp.h"
70 : # include "GM2StackAddress.h"
71 : # include "GM2StackWord.h"
72 : # include "GM2StackSpell.h"
73 :
74 : # define Debugging false
75 : typedef struct PCSymBuild_eDes_r PCSymBuild_eDes;
76 :
77 : typedef struct PCSymBuild_eLeaf_r PCSymBuild_eLeaf;
78 :
79 : typedef struct PCSymBuild_eUnary_r PCSymBuild_eUnary;
80 :
81 : typedef struct PCSymBuild_eBinary_r PCSymBuild_eBinary;
82 :
83 : typedef struct PCSymBuild_eExpr_r PCSymBuild_eExpr;
84 :
85 : typedef struct PCSymBuild_eFunction_r PCSymBuild_eFunction;
86 :
87 : typedef struct PCSymBuild_eConvert_r PCSymBuild_eConvert;
88 :
89 : typedef struct PCSymBuild_eNode_r PCSymBuild_eNode;
90 :
91 : typedef PCSymBuild_eNode *PCSymBuild_exprNode;
92 :
93 : typedef enum {PCSymBuild_leaf, PCSymBuild_unary, PCSymBuild_binary, PCSymBuild_designator, PCSymBuild_expr, PCSymBuild_convert, PCSymBuild_function} PCSymBuild_tagType;
94 :
95 : struct PCSymBuild_eDes_r {
96 : unsigned int type;
97 : M2Const_constType meta;
98 : unsigned int sym;
99 : PCSymBuild_exprNode left;
100 : };
101 :
102 : struct PCSymBuild_eLeaf_r {
103 : unsigned int type;
104 : M2Const_constType meta;
105 : unsigned int sym;
106 : };
107 :
108 : struct PCSymBuild_eUnary_r {
109 : unsigned int type;
110 : M2Const_constType meta;
111 : PCSymBuild_exprNode left;
112 : NameKey_Name op;
113 : };
114 :
115 : struct PCSymBuild_eBinary_r {
116 : unsigned int type;
117 : M2Const_constType meta;
118 : PCSymBuild_exprNode left;
119 : PCSymBuild_exprNode right;
120 : NameKey_Name op;
121 : };
122 :
123 : struct PCSymBuild_eExpr_r {
124 : unsigned int type;
125 : M2Const_constType meta;
126 : PCSymBuild_exprNode left;
127 : };
128 :
129 : struct PCSymBuild_eFunction_r {
130 : unsigned int type;
131 : M2Const_constType meta;
132 : unsigned int func;
133 : PCSymBuild_exprNode first;
134 : PCSymBuild_exprNode second;
135 : bool third;
136 : };
137 :
138 : struct PCSymBuild_eConvert_r {
139 : unsigned int type;
140 : M2Const_constType meta;
141 : PCSymBuild_exprNode totype;
142 : PCSymBuild_exprNode expr;
143 : };
144 :
145 : struct PCSymBuild_eNode_r {
146 : PCSymBuild_tagType tag; /* case tag */
147 : union {
148 : PCSymBuild_eDes edes;
149 : PCSymBuild_eLeaf eleaf;
150 : PCSymBuild_eUnary eunary;
151 : PCSymBuild_eBinary ebinary;
152 : PCSymBuild_eExpr eexpr;
153 : PCSymBuild_eFunction efunction;
154 : PCSymBuild_eConvert econvert;
155 : };
156 : };
157 :
158 : static M2StackAddress_StackOfAddress exprStack;
159 : static Indexing_Index constList;
160 : static unsigned int constToken;
161 : static M2StackWord_StackOfWord desStack;
162 : static bool inDesignator;
163 :
164 : /*
165 : CheckNotVar - checks to see that the top of stack is not a variable.
166 : */
167 :
168 : extern "C" void PCSymBuild_CheckNotVar (unsigned int tok);
169 : extern "C" void PCSymBuild_PCStartBuildDefModule (void);
170 : extern "C" void PCSymBuild_PCEndBuildDefModule (unsigned int tokno);
171 : extern "C" void PCSymBuild_PCStartBuildImpModule (void);
172 : extern "C" void PCSymBuild_PCEndBuildImpModule (unsigned int tokno);
173 : extern "C" void PCSymBuild_PCStartBuildProgModule (void);
174 : extern "C" void PCSymBuild_PCEndBuildProgModule (unsigned int tokno);
175 : extern "C" void PCSymBuild_PCStartBuildInnerModule (void);
176 : extern "C" void PCSymBuild_PCEndBuildInnerModule (unsigned int tokno);
177 : extern "C" void PCSymBuild_PCBuildProcedureHeading (void);
178 : extern "C" void PCSymBuild_PCStartBuildProcedure (void);
179 : extern "C" void PCSymBuild_PCEndBuildProcedure (void);
180 : extern "C" void PCSymBuild_PCEndBuildForward (void);
181 : extern "C" void PCSymBuild_PCBuildImportOuterModule (void);
182 : extern "C" void PCSymBuild_PCBuildImportInnerModule (void);
183 :
184 : /*
185 : BuildNulName - Pushes a NulKey onto the top of the stack.
186 : The Stack:
187 :
188 :
189 : Entry Exit
190 :
191 : <- Ptr
192 : Empty +------------+
193 : | NulKey |
194 : |------------|
195 : */
196 :
197 : extern "C" void PCSymBuild_BuildNulName (void);
198 :
199 : /*
200 : BuildConst - builds a constant.
201 : Stack
202 :
203 : Entry Exit
204 :
205 : Ptr -> <- Ptr
206 : +------------+ +------------+
207 : | Name | | Sym |
208 : |------------+ |------------|
209 : */
210 :
211 : extern "C" void PCSymBuild_BuildConst (void);
212 :
213 : /*
214 : StartDesConst -
215 : */
216 :
217 : extern "C" void PCSymBuild_StartDesConst (void);
218 :
219 : /*
220 : EndDesConst -
221 : */
222 :
223 : extern "C" void PCSymBuild_EndDesConst (void);
224 :
225 : /*
226 : BuildRelationConst - builds a relationship binary operation.
227 : */
228 :
229 : extern "C" void PCSymBuild_BuildRelationConst (void);
230 :
231 : /*
232 : BuildUnaryConst - builds a unary operator node.
233 : */
234 :
235 : extern "C" void PCSymBuild_BuildUnaryConst (void);
236 :
237 : /*
238 : BuildBinaryConst - builds a binary operator node.
239 : */
240 :
241 : extern "C" void PCSymBuild_BuildBinaryConst (void);
242 :
243 : /*
244 : PushConstFunctionType -
245 : */
246 :
247 : extern "C" void PCSymBuild_PushConstFunctionType (void);
248 :
249 : /*
250 : PushIntegerType -
251 : */
252 :
253 : extern "C" void PCSymBuild_PushIntegerType (void);
254 :
255 : /*
256 : PushRType -
257 : */
258 :
259 : extern "C" void PCSymBuild_PushRType (void);
260 :
261 : /*
262 : PushStringType -
263 : */
264 :
265 : extern "C" void PCSymBuild_PushStringType (void);
266 :
267 : /*
268 : SkipConst - returns an alias to constant, sym, if one exists.
269 : Otherwise sym is returned.
270 : */
271 :
272 : extern "C" unsigned int PCSymBuild_SkipConst (unsigned int sym);
273 :
274 : /*
275 : PushConstType - pushes a constant to the expression stack.
276 : */
277 :
278 : extern "C" void PCSymBuild_PushConstType (void);
279 :
280 : /*
281 : PushConstAttributeType -
282 : */
283 :
284 : extern "C" void PCSymBuild_PushConstAttributeType (void);
285 :
286 : /*
287 : PushConstAttributePairType -
288 : */
289 :
290 : extern "C" void PCSymBuild_PushConstAttributePairType (void);
291 :
292 : /*
293 : PushConstructorCastType -
294 : */
295 :
296 : extern "C" void PCSymBuild_PushConstructorCastType (void);
297 :
298 : /*
299 : PushInConstructor -
300 : */
301 :
302 : extern "C" void PCSymBuild_PushInConstructor (void);
303 :
304 : /*
305 : PopInConstructor -
306 : */
307 :
308 : extern "C" void PCSymBuild_PopInConstructor (void);
309 :
310 : /*
311 : ResolveConstTypes - resolves the types of all designator declared constants.
312 : */
313 :
314 : extern "C" void PCSymBuild_ResolveConstTypes (void);
315 :
316 : /*
317 : GetSkippedType -
318 : */
319 :
320 : static unsigned int GetSkippedType (unsigned int sym);
321 :
322 : /*
323 : InitDesExpr -
324 : */
325 :
326 : static void InitDesExpr (unsigned int des);
327 :
328 : /*
329 : DebugNode -
330 : */
331 :
332 : static void DebugNode (PCSymBuild_exprNode d);
333 :
334 : /*
335 : DebugDes -
336 : */
337 :
338 : static void DebugDes (PCSymBuild_exprNode d);
339 :
340 : /*
341 : DebugSym -
342 : */
343 :
344 : static void DebugSym (unsigned int sym);
345 :
346 : /*
347 : DebugMeta -
348 : */
349 :
350 : static void DebugMeta (M2Const_constType m);
351 :
352 : /*
353 : DebugType -
354 : */
355 :
356 : static void DebugType (unsigned int type);
357 :
358 : /*
359 : DebugExpr -
360 : */
361 :
362 : static void DebugExpr (PCSymBuild_exprNode e);
363 :
364 : /*
365 : DebugFunction -
366 : */
367 :
368 : static void DebugFunction (PCSymBuild_exprNode f);
369 :
370 : /*
371 : DebugConvert -
372 : */
373 :
374 : static void DebugConvert (PCSymBuild_exprNode f);
375 :
376 : /*
377 : DebugLeaf -
378 : */
379 :
380 : static void DebugLeaf (PCSymBuild_exprNode l);
381 :
382 : /*
383 : DebugUnary -
384 : */
385 :
386 : static void DebugUnary (PCSymBuild_exprNode l);
387 :
388 : /*
389 : DebugBinary -
390 : */
391 :
392 : static void DebugBinary (PCSymBuild_exprNode l);
393 :
394 : /*
395 : DebugOp -
396 : */
397 :
398 : static void DebugOp (NameKey_Name op);
399 :
400 : /*
401 : fixupProcedureType - creates a proctype from a procedure.
402 : */
403 :
404 : static unsigned int fixupProcedureType (unsigned int p);
405 :
406 : /*
407 : InitFunction -
408 : */
409 :
410 : static void InitFunction (M2Const_constType m, unsigned int p, unsigned int t, PCSymBuild_exprNode f, PCSymBuild_exprNode s, bool more);
411 :
412 : /*
413 : InitConvert -
414 : */
415 :
416 : static void InitConvert (M2Const_constType m, unsigned int t, PCSymBuild_exprNode to, PCSymBuild_exprNode e);
417 :
418 : /*
419 : InitLeaf -
420 : */
421 :
422 : static void InitLeaf (M2Const_constType m, unsigned int s, unsigned int t);
423 :
424 : /*
425 : InitProcedure -
426 : */
427 :
428 : static void InitProcedure (unsigned int s);
429 :
430 : /*
431 : InitCharType -
432 : */
433 :
434 : static void InitCharType (unsigned int s);
435 :
436 : /*
437 : InitZType -
438 : */
439 :
440 : static void InitZType (unsigned int s);
441 :
442 : /*
443 : InitRType -
444 : */
445 :
446 : static void InitRType (unsigned int s);
447 :
448 : /*
449 : InitUnknown -
450 : */
451 :
452 : static void InitUnknown (unsigned int s);
453 :
454 : /*
455 : InitBooleanType -
456 : */
457 :
458 : static void InitBooleanType (unsigned int s);
459 :
460 : /*
461 : TypeToMeta -
462 : */
463 :
464 : static M2Const_constType TypeToMeta (unsigned int type);
465 :
466 : /*
467 : buildConstFunction - we are only concerned about resolving the return type of
468 : a function, so we can ignore all parameters - except
469 : the first one in the case of VAL(type, foo)
470 : and the type of bar in MIN (bar) and MAX (bar).
471 : buildConstFunction uses a unary exprNode to represent
472 : a function.
473 : */
474 :
475 : static void buildConstFunction (unsigned int func, unsigned int n);
476 :
477 : /*
478 : ErrorConstFunction - generate an error message at functok using func in the
479 : error message providing it is not NulSym.
480 : */
481 :
482 : static void ErrorConstFunction (unsigned int func, unsigned int functok);
483 :
484 : /*
485 : InitBinary -
486 : */
487 :
488 : static void InitBinary (M2Const_constType m, unsigned int t, NameKey_Name o);
489 :
490 : /*
491 : InitUnary -
492 : */
493 :
494 : static void InitUnary (M2Const_constType m, unsigned int t, NameKey_Name o);
495 :
496 : /*
497 : isTypeResolved -
498 : */
499 :
500 : static bool isTypeResolved (PCSymBuild_exprNode e);
501 :
502 : /*
503 : getEtype -
504 : */
505 :
506 : static unsigned int getEtype (PCSymBuild_exprNode e);
507 :
508 : /*
509 : getEmeta -
510 : */
511 :
512 : static M2Const_constType getEmeta (PCSymBuild_exprNode e);
513 :
514 : /*
515 : assignTM -
516 : */
517 :
518 : static void assignTM (unsigned int *td, M2Const_constType *md, unsigned int te, M2Const_constType me);
519 :
520 : /*
521 : assignType -
522 : */
523 :
524 : static void assignType (PCSymBuild_exprNode d, PCSymBuild_exprNode e);
525 :
526 : /*
527 : deduceTypes - works out the type and metatype given, l, and, r.
528 : */
529 :
530 : static void deduceTypes (unsigned int *t, M2Const_constType *m, PCSymBuild_exprNode l, PCSymBuild_exprNode r, NameKey_Name op);
531 :
532 : /*
533 : WalkConvert -
534 : */
535 :
536 : static bool WalkConvert (PCSymBuild_exprNode e);
537 :
538 : /*
539 : WalkFunctionParam -
540 : */
541 :
542 : static bool WalkFunctionParam (unsigned int func, PCSymBuild_exprNode e);
543 :
544 : /*
545 : WalkFunction -
546 : */
547 :
548 : static bool WalkFunction (PCSymBuild_exprNode e);
549 :
550 : /*
551 : doWalkNode -
552 : */
553 :
554 : static bool doWalkNode (PCSymBuild_exprNode e);
555 :
556 : /*
557 : WalkLeaf -
558 : */
559 :
560 : static bool WalkLeaf (PCSymBuild_exprNode e);
561 :
562 : /*
563 : WalkUnary -
564 : */
565 :
566 : static bool WalkUnary (PCSymBuild_exprNode e);
567 :
568 : /*
569 : WalkBinary -
570 : */
571 :
572 : static bool WalkBinary (PCSymBuild_exprNode e);
573 :
574 : /*
575 : WalkExpr -
576 : */
577 :
578 : static bool WalkExpr (PCSymBuild_exprNode e);
579 :
580 : /*
581 : doWalkDesExpr - returns TRUE if the expression trees, d, or, e, are changed.
582 : */
583 :
584 : static bool doWalkDesExpr (PCSymBuild_exprNode d, PCSymBuild_exprNode e);
585 :
586 : /*
587 : doWalkDes - return TRUE if expression, e, is changed.
588 : */
589 :
590 : static bool doWalkDes (PCSymBuild_exprNode d);
591 :
592 : /*
593 : findConstDes -
594 : */
595 :
596 : static PCSymBuild_exprNode findConstDes (unsigned int sym);
597 :
598 : /*
599 : WalkDes - return TRUE if expression, e, is changed.
600 : */
601 :
602 : static bool WalkDes (PCSymBuild_exprNode d);
603 :
604 : /*
605 : WalkConsts - walk over the constant trees and return TRUE if any tree was changed.
606 : (As a result of a type resolution).
607 : */
608 :
609 : static bool WalkConsts (void);
610 :
611 : /*
612 : DebugNodes -
613 : */
614 :
615 : static void DebugNodes (void);
616 :
617 : /*
618 : findAlias -
619 : */
620 :
621 : static unsigned int findAlias (unsigned int sym, PCSymBuild_exprNode e);
622 :
623 : /*
624 : CheckConsts -
625 : */
626 :
627 : static void CheckConsts (void);
628 :
629 : /*
630 : Init -
631 : */
632 :
633 : static void Init (void);
634 :
635 :
636 : /*
637 : GetSkippedType -
638 : */
639 :
640 491055 : static unsigned int GetSkippedType (unsigned int sym)
641 : {
642 491055 : return SymbolTable_SkipType (SymbolTable_GetType (sym));
643 : /* static analysis guarentees a RETURN statement will be used before here. */
644 : __builtin_unreachable ();
645 : }
646 :
647 :
648 : /*
649 : InitDesExpr -
650 : */
651 :
652 299617 : static void InitDesExpr (unsigned int des)
653 : {
654 299617 : PCSymBuild_exprNode e;
655 :
656 299617 : Storage_ALLOCATE ((void **) &e, sizeof (PCSymBuild_eNode));
657 299617 : e->tag = PCSymBuild_designator;
658 299617 : switch (e->tag)
659 : {
660 299617 : case PCSymBuild_designator:
661 299617 : e->edes.type = SymbolTable_NulSym;
662 299617 : e->edes.meta = M2Const_unknown;
663 299617 : e->tag = PCSymBuild_designator;
664 299617 : e->edes.sym = des;
665 299617 : e->edes.left = NULL;
666 299617 : break;
667 :
668 :
669 : default:
670 : M2Error_InternalError ((const char *) "expecting designator", 20);
671 299617 : break;
672 : }
673 299617 : M2StackAddress_PushAddress (exprStack, reinterpret_cast <void *> (e));
674 299617 : }
675 :
676 :
677 : /*
678 : DebugNode -
679 : */
680 :
681 0 : static void DebugNode (PCSymBuild_exprNode d)
682 : {
683 0 : if (Debugging && (d != NULL))
684 : {
685 : switch (d->tag)
686 : {
687 : case PCSymBuild_designator:
688 : DebugDes (d);
689 : break;
690 :
691 : case PCSymBuild_expr:
692 : DebugExpr (d);
693 : break;
694 :
695 : case PCSymBuild_leaf:
696 : DebugLeaf (d);
697 : break;
698 :
699 : case PCSymBuild_unary:
700 : DebugUnary (d);
701 : break;
702 :
703 : case PCSymBuild_binary:
704 : DebugBinary (d);
705 : break;
706 :
707 : case PCSymBuild_function:
708 : DebugFunction (d);
709 : break;
710 :
711 : case PCSymBuild_convert:
712 : DebugConvert (d);
713 : break;
714 :
715 :
716 : default:
717 : CaseException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/PCSymBuild.def", 20, 1);
718 : __builtin_unreachable ();
719 : }
720 : }
721 0 : }
722 :
723 :
724 : /*
725 : DebugDes -
726 : */
727 :
728 0 : static void DebugDes (PCSymBuild_exprNode d)
729 : {
730 0 : DebugSym (d->edes.sym);
731 0 : StdIO_Write (':');
732 0 : DebugMeta (d->edes.meta);
733 0 : StdIO_Write (':');
734 0 : DebugType (d->edes.type);
735 0 : StrIO_WriteString ((const char *) " = ", 3);
736 0 : DebugNode (d->edes.left);
737 0 : StrIO_WriteLn ();
738 0 : }
739 :
740 :
741 : /*
742 : DebugSym -
743 : */
744 :
745 0 : static void DebugSym (unsigned int sym)
746 : {
747 0 : NameKey_Name n;
748 :
749 0 : n = SymbolTable_GetSymName (sym);
750 0 : if (n != NameKey_NulName)
751 : {
752 0 : NameKey_WriteKey (n);
753 : }
754 0 : StdIO_Write (':');
755 0 : NumberIO_WriteCard (sym, 0);
756 0 : }
757 :
758 :
759 : /*
760 : DebugMeta -
761 : */
762 :
763 0 : static void DebugMeta (M2Const_constType m)
764 : {
765 0 : switch (m)
766 : {
767 0 : case M2Const_unknown:
768 0 : StrIO_WriteString ((const char *) "unknown", 7);
769 0 : break;
770 :
771 0 : case M2Const_set:
772 0 : StrIO_WriteString ((const char *) "set", 3);
773 0 : break;
774 :
775 0 : case M2Const_str:
776 0 : StrIO_WriteString ((const char *) "str", 3);
777 0 : break;
778 :
779 0 : case M2Const_constructor:
780 0 : StrIO_WriteString ((const char *) "constructor", 11);
781 0 : break;
782 :
783 0 : case M2Const_array:
784 0 : StrIO_WriteString ((const char *) "array", 5);
785 0 : break;
786 :
787 0 : case M2Const_cast:
788 0 : StrIO_WriteString ((const char *) "cast", 4);
789 0 : break;
790 :
791 0 : case M2Const_boolean:
792 0 : StrIO_WriteString ((const char *) "boolean", 7);
793 0 : break;
794 :
795 0 : case M2Const_ztype:
796 0 : StrIO_WriteString ((const char *) "ztype", 5);
797 0 : break;
798 :
799 0 : case M2Const_rtype:
800 0 : StrIO_WriteString ((const char *) "rtype", 5);
801 0 : break;
802 :
803 0 : case M2Const_ctype:
804 0 : StrIO_WriteString ((const char *) "ctype", 5);
805 0 : break;
806 :
807 0 : case M2Const_procedure:
808 0 : StrIO_WriteString ((const char *) "procedure", 9);
809 0 : break;
810 :
811 0 : case M2Const_char:
812 0 : StrIO_WriteString ((const char *) "ctype", 5);
813 0 : break;
814 :
815 :
816 0 : default:
817 0 : CaseException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/PCSymBuild.def", 20, 1);
818 0 : __builtin_unreachable ();
819 : }
820 0 : }
821 :
822 :
823 : /*
824 : DebugType -
825 : */
826 :
827 0 : static void DebugType (unsigned int type)
828 : {
829 0 : NameKey_Name n;
830 :
831 0 : StrIO_WriteString ((const char *) "[type:", 6);
832 0 : if (type == SymbolTable_NulSym)
833 : {
834 0 : StrIO_WriteString ((const char *) "<nulsym>", 8);
835 : }
836 : else
837 : {
838 0 : n = SymbolTable_GetSymName (type);
839 0 : if (n != SymbolTable_NulSym)
840 : {
841 0 : NameKey_WriteKey (n);
842 : }
843 0 : StdIO_Write (':');
844 0 : NumberIO_WriteCard (type, 0);
845 : }
846 0 : StdIO_Write (']');
847 0 : }
848 :
849 :
850 : /*
851 : DebugExpr -
852 : */
853 :
854 0 : static void DebugExpr (PCSymBuild_exprNode e)
855 : {
856 0 : StrIO_WriteString ((const char *) "expr (", 6);
857 0 : DebugType (e->eexpr.type);
858 0 : StdIO_Write (':');
859 0 : DebugMeta (e->eexpr.meta);
860 0 : StdIO_Write (' ');
861 0 : DebugNode (e->eexpr.left);
862 0 : StrIO_WriteString ((const char *) ") ", 2);
863 0 : }
864 :
865 :
866 : /*
867 : DebugFunction -
868 : */
869 :
870 0 : static void DebugFunction (PCSymBuild_exprNode f)
871 : {
872 0 : NameKey_WriteKey (SymbolTable_GetSymName (f->efunction.func));
873 0 : StdIO_Write ('(');
874 0 : if (f->efunction.first != NULL)
875 : {
876 0 : DebugNode (f->efunction.first);
877 0 : if (f->efunction.second != NULL)
878 : {
879 0 : StrIO_WriteString ((const char *) ", ", 2);
880 0 : DebugNode (f->efunction.second);
881 0 : if (f->efunction.third)
882 : {
883 0 : StrIO_WriteString ((const char *) ", ...", 5);
884 : }
885 : }
886 : }
887 0 : StdIO_Write (')');
888 0 : }
889 :
890 :
891 : /*
892 : DebugConvert -
893 : */
894 :
895 0 : static void DebugConvert (PCSymBuild_exprNode f)
896 : {
897 0 : DebugNode (f->econvert.totype);
898 0 : StdIO_Write ('(');
899 0 : DebugNode (f->econvert.expr);
900 0 : StdIO_Write (')');
901 0 : }
902 :
903 :
904 : /*
905 : DebugLeaf -
906 : */
907 :
908 0 : static void DebugLeaf (PCSymBuild_exprNode l)
909 : {
910 0 : StrIO_WriteString ((const char *) "leaf (", 6);
911 0 : DebugType (l->eleaf.type);
912 0 : StdIO_Write (':');
913 0 : DebugMeta (l->eleaf.meta);
914 0 : StdIO_Write (':');
915 0 : DebugSym (l->eleaf.sym);
916 0 : StrIO_WriteString ((const char *) ") ", 2);
917 0 : }
918 :
919 :
920 : /*
921 : DebugUnary -
922 : */
923 :
924 0 : static void DebugUnary (PCSymBuild_exprNode l)
925 : {
926 0 : StrIO_WriteString ((const char *) "unary (", 7);
927 0 : DebugType (l->eunary.type);
928 0 : StdIO_Write (':');
929 0 : DebugMeta (l->eunary.meta);
930 0 : StdIO_Write (' ');
931 0 : DebugOp (l->eunary.op);
932 0 : StdIO_Write (' ');
933 0 : DebugNode (l->eunary.left);
934 0 : StrIO_WriteString ((const char *) ") ", 2);
935 0 : }
936 :
937 :
938 : /*
939 : DebugBinary -
940 : */
941 :
942 0 : static void DebugBinary (PCSymBuild_exprNode l)
943 : {
944 0 : StrIO_WriteString ((const char *) "unary (", 7);
945 0 : DebugType (l->ebinary.type);
946 0 : StdIO_Write (':');
947 0 : DebugMeta (l->ebinary.meta);
948 0 : StdIO_Write (' ');
949 0 : DebugNode (l->ebinary.left);
950 0 : DebugOp (l->ebinary.op);
951 0 : StdIO_Write (' ');
952 0 : DebugNode (l->ebinary.right);
953 0 : StrIO_WriteString ((const char *) ") ", 2);
954 0 : }
955 :
956 :
957 : /*
958 : DebugOp -
959 : */
960 :
961 0 : static void DebugOp (NameKey_Name op)
962 : {
963 0 : NameKey_WriteKey (op);
964 0 : }
965 :
966 :
967 : /*
968 : fixupProcedureType - creates a proctype from a procedure.
969 : */
970 :
971 18 : static unsigned int fixupProcedureType (unsigned int p)
972 : {
973 18 : unsigned int tok;
974 18 : unsigned int par;
975 18 : unsigned int t;
976 18 : unsigned int n;
977 18 : unsigned int i;
978 :
979 18 : if (SymbolTable_IsProcedure (p))
980 : {
981 18 : tok = M2LexBuf_GetTokenNo ();
982 18 : t = SymbolTable_MakeProcType (tok, SymbolTable_CheckAnonymous (NameKey_NulName));
983 18 : i = 1;
984 18 : n = SymbolTable_NoOfParamAny (p);
985 48 : while (i <= n)
986 : {
987 12 : par = SymbolTable_GetParam (p, i);
988 12 : if (SymbolTable_IsParameterVar (par))
989 : {
990 0 : SymbolTable_PutProcTypeVarParam (tok, t, SymbolTable_GetType (par), SymbolTable_IsParameterUnbounded (par));
991 : }
992 : else
993 : {
994 12 : SymbolTable_PutProcTypeParam (tok, t, SymbolTable_GetType (par), SymbolTable_IsParameterUnbounded (par));
995 : }
996 12 : i += 1;
997 : }
998 18 : if ((SymbolTable_GetType (p)) != SymbolTable_NulSym)
999 : {
1000 18 : SymbolTable_PutFunction (tok, t, SymbolTable_ProperProcedure, SymbolTable_GetType (p));
1001 : }
1002 18 : return t;
1003 : }
1004 : else
1005 : {
1006 0 : M2Error_InternalError ((const char *) "expecting a procedure", 21);
1007 : }
1008 : return SymbolTable_NulSym;
1009 : /* static analysis guarentees a RETURN statement will be used before here. */
1010 : __builtin_unreachable ();
1011 : }
1012 :
1013 :
1014 : /*
1015 : InitFunction -
1016 : */
1017 :
1018 6539 : static void InitFunction (M2Const_constType m, unsigned int p, unsigned int t, PCSymBuild_exprNode f, PCSymBuild_exprNode s, bool more)
1019 : {
1020 6539 : PCSymBuild_exprNode n;
1021 :
1022 6539 : Storage_ALLOCATE ((void **) &n, sizeof (PCSymBuild_eNode));
1023 6539 : n->tag = PCSymBuild_function;
1024 6539 : switch (n->tag)
1025 : {
1026 6539 : case PCSymBuild_function:
1027 6539 : n->efunction.meta = m;
1028 6539 : n->efunction.type = t;
1029 6539 : n->efunction.func = p;
1030 6539 : n->efunction.first = f;
1031 6539 : n->efunction.second = s;
1032 6539 : n->efunction.third = more;
1033 6539 : break;
1034 :
1035 :
1036 : default:
1037 : M2Error_InternalError ((const char *) "expecting function", 18);
1038 6539 : break;
1039 : }
1040 6539 : M2StackAddress_PushAddress (exprStack, reinterpret_cast <void *> (n));
1041 6539 : }
1042 :
1043 :
1044 : /*
1045 : InitConvert -
1046 : */
1047 :
1048 4471 : static void InitConvert (M2Const_constType m, unsigned int t, PCSymBuild_exprNode to, PCSymBuild_exprNode e)
1049 : {
1050 4471 : PCSymBuild_exprNode n;
1051 :
1052 4471 : Storage_ALLOCATE ((void **) &n, sizeof (PCSymBuild_eNode));
1053 4471 : n->tag = PCSymBuild_convert;
1054 4471 : switch (n->tag)
1055 : {
1056 4471 : case PCSymBuild_convert:
1057 4471 : n->econvert.type = t;
1058 4471 : n->econvert.meta = m;
1059 4471 : n->econvert.totype = to;
1060 4471 : n->econvert.expr = e;
1061 4471 : break;
1062 :
1063 :
1064 : default:
1065 : M2Error_InternalError ((const char *) "expecting convert", 17);
1066 4471 : break;
1067 : }
1068 4471 : M2StackAddress_PushAddress (exprStack, reinterpret_cast <void *> (n));
1069 4471 : }
1070 :
1071 :
1072 : /*
1073 : InitLeaf -
1074 : */
1075 :
1076 321078 : static void InitLeaf (M2Const_constType m, unsigned int s, unsigned int t)
1077 : {
1078 321078 : PCSymBuild_exprNode l;
1079 :
1080 321078 : Storage_ALLOCATE ((void **) &l, sizeof (PCSymBuild_eNode));
1081 321078 : l->tag = PCSymBuild_leaf;
1082 321078 : switch (l->tag)
1083 : {
1084 321078 : case PCSymBuild_leaf:
1085 321078 : l->eleaf.type = t;
1086 321078 : l->eleaf.meta = m;
1087 321078 : l->eleaf.sym = s;
1088 321078 : break;
1089 :
1090 :
1091 : default:
1092 : M2Error_InternalError ((const char *) "expecting leaf", 14);
1093 321078 : break;
1094 : }
1095 321078 : M2StackAddress_PushAddress (exprStack, reinterpret_cast <void *> (l));
1096 321078 : }
1097 :
1098 :
1099 : /*
1100 : InitProcedure -
1101 : */
1102 :
1103 18 : static void InitProcedure (unsigned int s)
1104 : {
1105 18 : InitLeaf (M2Const_procedure, s, fixupProcedureType (s));
1106 18 : }
1107 :
1108 :
1109 : /*
1110 : InitCharType -
1111 : */
1112 :
1113 121076 : static void InitCharType (unsigned int s)
1114 : {
1115 0 : InitLeaf (M2Const_char, s, M2Base_Char);
1116 0 : }
1117 :
1118 :
1119 : /*
1120 : InitZType -
1121 : */
1122 :
1123 119147 : static void InitZType (unsigned int s)
1124 : {
1125 0 : InitLeaf (M2Const_ztype, s, M2Base_ZType);
1126 0 : }
1127 :
1128 :
1129 : /*
1130 : InitRType -
1131 : */
1132 :
1133 1290 : static void InitRType (unsigned int s)
1134 : {
1135 0 : InitLeaf (M2Const_rtype, s, M2Base_RType);
1136 0 : }
1137 :
1138 :
1139 : /*
1140 : InitUnknown -
1141 : */
1142 :
1143 40979 : static void InitUnknown (unsigned int s)
1144 : {
1145 0 : InitLeaf (M2Const_unknown, s, SymbolTable_NulSym);
1146 0 : }
1147 :
1148 :
1149 : /*
1150 : InitBooleanType -
1151 : */
1152 :
1153 37159 : static void InitBooleanType (unsigned int s)
1154 : {
1155 0 : InitLeaf (M2Const_boolean, s, M2Base_Boolean);
1156 0 : }
1157 :
1158 :
1159 : /*
1160 : TypeToMeta -
1161 : */
1162 :
1163 216654 : static M2Const_constType TypeToMeta (unsigned int type)
1164 : {
1165 216654 : if (type == M2Base_Char)
1166 : {
1167 : return M2Const_char;
1168 : }
1169 95542 : else if (type == M2Base_Boolean)
1170 : {
1171 : /* avoid dangling else. */
1172 : return M2Const_boolean;
1173 : }
1174 95530 : else if (M2Base_IsRealType (type))
1175 : {
1176 : /* avoid dangling else. */
1177 : return M2Const_rtype;
1178 : }
1179 95452 : else if (M2Base_IsComplexType (type))
1180 : {
1181 : /* avoid dangling else. */
1182 : return M2Const_ctype;
1183 : }
1184 95038 : else if (M2Base_IsOrdinalType (type))
1185 : {
1186 : /* avoid dangling else. */
1187 : return M2Const_ztype;
1188 : }
1189 : else
1190 : {
1191 : /* avoid dangling else. */
1192 70 : return M2Const_unknown;
1193 : }
1194 : /* static analysis guarentees a RETURN statement will be used before here. */
1195 : __builtin_unreachable ();
1196 : }
1197 :
1198 :
1199 : /*
1200 : buildConstFunction - we are only concerned about resolving the return type of
1201 : a function, so we can ignore all parameters - except
1202 : the first one in the case of VAL(type, foo)
1203 : and the type of bar in MIN (bar) and MAX (bar).
1204 : buildConstFunction uses a unary exprNode to represent
1205 : a function.
1206 : */
1207 :
1208 6575 : static void buildConstFunction (unsigned int func, unsigned int n)
1209 : {
1210 6575 : unsigned int i;
1211 6575 : PCSymBuild_exprNode first;
1212 6575 : PCSymBuild_exprNode second;
1213 :
1214 6575 : first = NULL;
1215 6575 : second = NULL;
1216 6575 : if (n == 1)
1217 : {
1218 6125 : first = static_cast<PCSymBuild_exprNode> (M2StackAddress_PopAddress (exprStack));
1219 : }
1220 450 : else if (n >= 2)
1221 : {
1222 : /* avoid dangling else. */
1223 : i = n;
1224 450 : while (i > 2)
1225 : {
1226 0 : second = static_cast<PCSymBuild_exprNode> (M2StackAddress_PopAddress (exprStack));
1227 0 : Storage_DEALLOCATE ((void **) &second, sizeof (PCSymBuild_eNode));
1228 0 : i -= 1;
1229 : }
1230 450 : second = static_cast<PCSymBuild_exprNode> (M2StackAddress_PopAddress (exprStack));
1231 450 : first = static_cast<PCSymBuild_exprNode> (M2StackAddress_PopAddress (exprStack));
1232 : }
1233 6575 : if ((func == M2Base_Val) || (func == M2System_Cast))
1234 : {
1235 36 : InitConvert (M2Const_cast, SymbolTable_NulSym, first, second);
1236 : }
1237 6539 : else if ((func == M2Base_Max) || (func == M2Base_Min))
1238 : {
1239 : /* avoid dangling else. */
1240 271 : InitFunction (M2Const_unknown, func, SymbolTable_NulSym, first, second, false);
1241 : }
1242 : else
1243 : {
1244 : /* avoid dangling else. */
1245 6268 : InitFunction (TypeToMeta (GetSkippedType (func)), func, GetSkippedType (func), first, second, n > 2);
1246 : }
1247 6575 : }
1248 :
1249 :
1250 : /*
1251 : ErrorConstFunction - generate an error message at functok using func in the
1252 : error message providing it is not NulSym.
1253 : */
1254 :
1255 42 : static void ErrorConstFunction (unsigned int func, unsigned int functok)
1256 : {
1257 42 : if (func == SymbolTable_NulSym)
1258 : {
1259 24 : if (M2Options_Iso)
1260 : {
1261 12 : M2Error_ErrorFormat0 (M2Error_NewError (functok), (const char *) "the only functions permissible in a constant expression are: CAP, CAST, CHR, CMPLX, FLOAT, HIGH, IM, LENGTH, MAX, MIN, ODD, ORD, RE, SIZE, TSIZE, TRUNC, VAL and gcc builtins", 173);
1262 : }
1263 : else
1264 : {
1265 12 : M2Error_ErrorFormat0 (M2Error_NewError (functok), (const char *) "the only functions permissible in a constant expression are: CAP, CHR, FLOAT, HIGH, MAX, MIN, ODD, ORD, SIZE, TSIZE, TRUNC, VAL and gcc builtins", 144);
1266 : }
1267 : }
1268 : else
1269 : {
1270 18 : if (M2Options_Iso)
1271 : {
1272 12 : M2MetaError_MetaErrorT1 (functok, (const char *) "the only functions permissible in a constant expression are: CAP, CAST, CHR, CMPLX, FLOAT, HIGH, IM, LENGTH, MAX, MIN, ODD, ORD, RE, SIZE, TSIZE, TRUNC, VAL and gcc builtins, but not {%1Ead}", 190, func);
1273 : }
1274 : else
1275 : {
1276 6 : M2MetaError_MetaErrorT1 (functok, (const char *) "the only functions permissible in a constant expression are: CAP, CHR, FLOAT, HIGH, MAX, MIN, ODD, ORD, SIZE, TSIZE, TRUNC, VAL and gcc builtins, but not {%1Ead}", 161, func);
1277 : }
1278 : }
1279 42 : }
1280 :
1281 :
1282 : /*
1283 : InitBinary -
1284 : */
1285 :
1286 25470 : static void InitBinary (M2Const_constType m, unsigned int t, NameKey_Name o)
1287 : {
1288 25470 : PCSymBuild_exprNode l;
1289 25470 : PCSymBuild_exprNode r;
1290 25470 : PCSymBuild_exprNode b;
1291 :
1292 25470 : r = static_cast<PCSymBuild_exprNode> (M2StackAddress_PopAddress (exprStack));
1293 25470 : l = static_cast<PCSymBuild_exprNode> (M2StackAddress_PopAddress (exprStack));
1294 25470 : Storage_ALLOCATE ((void **) &b, sizeof (PCSymBuild_eNode));
1295 25470 : b->tag = PCSymBuild_binary;
1296 25470 : switch (b->tag)
1297 : {
1298 25470 : case PCSymBuild_binary:
1299 25470 : b->ebinary.meta = m;
1300 25470 : b->ebinary.type = t;
1301 25470 : b->ebinary.left = l;
1302 25470 : b->ebinary.right = r;
1303 25470 : b->ebinary.op = o;
1304 25470 : break;
1305 :
1306 :
1307 : default:
1308 : M2Error_InternalError ((const char *) "expecting binary", 16);
1309 25470 : break;
1310 : }
1311 25470 : M2StackAddress_PushAddress (exprStack, reinterpret_cast <void *> (b));
1312 25470 : }
1313 :
1314 :
1315 : /*
1316 : InitUnary -
1317 : */
1318 :
1319 294 : static void InitUnary (M2Const_constType m, unsigned int t, NameKey_Name o)
1320 : {
1321 294 : PCSymBuild_exprNode l;
1322 294 : PCSymBuild_exprNode b;
1323 :
1324 294 : l = static_cast<PCSymBuild_exprNode> (M2StackAddress_PopAddress (exprStack));
1325 294 : Storage_ALLOCATE ((void **) &b, sizeof (PCSymBuild_eNode));
1326 294 : b->tag = PCSymBuild_unary;
1327 294 : switch (b->tag)
1328 : {
1329 294 : case PCSymBuild_unary:
1330 294 : b->eunary.meta = m;
1331 294 : b->eunary.type = t;
1332 294 : b->eunary.left = l;
1333 294 : b->eunary.op = o;
1334 294 : break;
1335 :
1336 :
1337 : default:
1338 : M2Error_InternalError ((const char *) "expecting unary", 15);
1339 294 : break;
1340 : }
1341 294 : M2StackAddress_PushAddress (exprStack, reinterpret_cast <void *> (b));
1342 294 : }
1343 :
1344 :
1345 : /*
1346 : isTypeResolved -
1347 : */
1348 :
1349 2452742 : static bool isTypeResolved (PCSymBuild_exprNode e)
1350 : {
1351 2452742 : switch (e->tag)
1352 : {
1353 405907 : case PCSymBuild_leaf:
1354 405907 : return (e->eleaf.type != SymbolTable_NulSym) || (e->eleaf.meta == M2Const_str);
1355 600 : break;
1356 :
1357 600 : case PCSymBuild_unary:
1358 600 : return (e->eunary.type != SymbolTable_NulSym) || (e->eunary.meta == M2Const_str);
1359 110564 : break;
1360 :
1361 110564 : case PCSymBuild_binary:
1362 110564 : return (e->ebinary.type != SymbolTable_NulSym) || (e->ebinary.meta == M2Const_str);
1363 1923252 : break;
1364 :
1365 1923252 : case PCSymBuild_designator:
1366 1923252 : return (e->edes.type != SymbolTable_NulSym) || (e->edes.meta == M2Const_str);
1367 0 : break;
1368 :
1369 0 : case PCSymBuild_expr:
1370 0 : return (e->eexpr.type != SymbolTable_NulSym) || (e->eexpr.meta == M2Const_str);
1371 4616 : break;
1372 :
1373 4616 : case PCSymBuild_convert:
1374 4616 : return (e->econvert.type != SymbolTable_NulSym) || (e->econvert.meta == M2Const_str);
1375 7803 : break;
1376 :
1377 7803 : case PCSymBuild_function:
1378 7803 : return (e->efunction.type != SymbolTable_NulSym) || (e->efunction.meta == M2Const_str);
1379 0 : break;
1380 :
1381 :
1382 0 : default:
1383 0 : CaseException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/PCSymBuild.def", 20, 1);
1384 0 : __builtin_unreachable ();
1385 : }
1386 : /* static analysis guarentees a RETURN statement will be used before here. */
1387 : __builtin_unreachable ();
1388 : }
1389 :
1390 :
1391 : /*
1392 : getEtype -
1393 : */
1394 :
1395 350623 : static unsigned int getEtype (PCSymBuild_exprNode e)
1396 : {
1397 350623 : switch (e->tag)
1398 : {
1399 314078 : case PCSymBuild_leaf:
1400 314078 : return e->eleaf.type;
1401 228 : break;
1402 :
1403 228 : case PCSymBuild_unary:
1404 228 : return e->eunary.type;
1405 25266 : break;
1406 :
1407 25266 : case PCSymBuild_binary:
1408 25266 : return e->ebinary.type;
1409 96 : break;
1410 :
1411 96 : case PCSymBuild_designator:
1412 96 : return e->edes.type;
1413 0 : break;
1414 :
1415 0 : case PCSymBuild_expr:
1416 0 : return e->eexpr.type;
1417 4464 : break;
1418 :
1419 4464 : case PCSymBuild_convert:
1420 4464 : return e->econvert.type;
1421 6491 : break;
1422 :
1423 6491 : case PCSymBuild_function:
1424 6491 : return e->efunction.type;
1425 0 : break;
1426 :
1427 :
1428 0 : default:
1429 0 : CaseException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/PCSymBuild.def", 20, 1);
1430 0 : __builtin_unreachable ();
1431 : }
1432 : /* static analysis guarentees a RETURN statement will be used before here. */
1433 : __builtin_unreachable ();
1434 : }
1435 :
1436 :
1437 : /*
1438 : getEmeta -
1439 : */
1440 :
1441 67256 : static M2Const_constType getEmeta (PCSymBuild_exprNode e)
1442 : {
1443 67256 : switch (e->tag)
1444 : {
1445 60667 : case PCSymBuild_leaf:
1446 60667 : return e->eleaf.meta;
1447 0 : break;
1448 :
1449 0 : case PCSymBuild_unary:
1450 0 : return e->eunary.meta;
1451 721 : break;
1452 :
1453 721 : case PCSymBuild_binary:
1454 721 : return e->ebinary.meta;
1455 96 : break;
1456 :
1457 96 : case PCSymBuild_designator:
1458 96 : return e->edes.meta;
1459 0 : break;
1460 :
1461 0 : case PCSymBuild_expr:
1462 0 : return e->eexpr.meta;
1463 12 : break;
1464 :
1465 12 : case PCSymBuild_convert:
1466 12 : return e->econvert.meta;
1467 5760 : break;
1468 :
1469 5760 : case PCSymBuild_function:
1470 5760 : return e->efunction.meta;
1471 0 : break;
1472 :
1473 :
1474 0 : default:
1475 0 : CaseException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/PCSymBuild.def", 20, 1);
1476 0 : __builtin_unreachable ();
1477 : }
1478 : /* static analysis guarentees a RETURN statement will be used before here. */
1479 : __builtin_unreachable ();
1480 : }
1481 :
1482 :
1483 : /*
1484 : assignTM -
1485 : */
1486 :
1487 126 : static void assignTM (unsigned int *td, M2Const_constType *md, unsigned int te, M2Const_constType me)
1488 : {
1489 126 : (*md) = me;
1490 126 : (*td) = te;
1491 0 : }
1492 :
1493 :
1494 : /*
1495 : assignType -
1496 : */
1497 :
1498 126 : static void assignType (PCSymBuild_exprNode d, PCSymBuild_exprNode e)
1499 : {
1500 126 : unsigned int t;
1501 126 : M2Const_constType m;
1502 :
1503 126 : m = getEmeta (e);
1504 126 : t = getEtype (e);
1505 126 : switch (d->tag)
1506 : {
1507 96 : case PCSymBuild_leaf:
1508 96 : assignTM (&d->eleaf.type, &d->eleaf.meta, t, m);
1509 96 : break;
1510 :
1511 0 : case PCSymBuild_unary:
1512 0 : assignTM (&d->eunary.type, &d->eunary.meta, t, m);
1513 0 : break;
1514 :
1515 0 : case PCSymBuild_binary:
1516 0 : assignTM (&d->ebinary.type, &d->ebinary.meta, t, m);
1517 0 : break;
1518 :
1519 0 : case PCSymBuild_designator:
1520 0 : assignTM (&d->edes.type, &d->edes.meta, t, m);
1521 0 : break;
1522 :
1523 0 : case PCSymBuild_expr:
1524 0 : assignTM (&d->eexpr.type, &d->eexpr.meta, t, m);
1525 0 : break;
1526 :
1527 30 : case PCSymBuild_convert:
1528 30 : assignTM (&d->econvert.type, &d->econvert.meta, t, m);
1529 30 : break;
1530 :
1531 0 : case PCSymBuild_function:
1532 0 : assignTM (&d->efunction.type, &d->efunction.meta, t, m);
1533 0 : break;
1534 :
1535 :
1536 0 : default:
1537 0 : CaseException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/PCSymBuild.def", 20, 1);
1538 0 : __builtin_unreachable ();
1539 : }
1540 126 : }
1541 :
1542 :
1543 : /*
1544 : deduceTypes - works out the type and metatype given, l, and, r.
1545 : */
1546 :
1547 25368 : static void deduceTypes (unsigned int *t, M2Const_constType *m, PCSymBuild_exprNode l, PCSymBuild_exprNode r, NameKey_Name op)
1548 : {
1549 25368 : if (r == NULL)
1550 : {
1551 : /* function or cast */
1552 0 : (*t) = getEtype (l);
1553 0 : (*m) = getEmeta (l);
1554 : }
1555 25368 : else if ((((((((((((op == M2Reserved_EqualTok) || (op == M2Reserved_HashTok)) || (op == M2Reserved_LessGreaterTok)) || (op == M2Reserved_LessTok)) || (op == M2Reserved_LessEqualTok)) || (op == M2Reserved_GreaterTok)) || (op == M2Reserved_GreaterEqualTok)) || (op == M2Reserved_InTok)) || (op == M2Reserved_OrTok)) || (op == M2Reserved_AndTok)) || (op == M2Reserved_NotTok)) || (op == M2Reserved_AmbersandTok))
1556 : {
1557 : /* avoid dangling else. */
1558 6 : (*t) = M2Base_Boolean;
1559 6 : (*m) = M2Const_boolean;
1560 : }
1561 25362 : else if (((((((op == M2Reserved_PlusTok) || (op == M2Reserved_MinusTok)) || (op == M2Reserved_TimesTok)) || (op == M2Reserved_ModTok)) || (op == M2Reserved_DivTok)) || (op == M2Reserved_RemTok)) || (op == M2Reserved_DivideTok))
1562 : {
1563 : /* avoid dangling else. */
1564 25362 : (*t) = M2Base_MixTypes (getEtype (l), getEtype (r), constToken);
1565 25362 : (*m) = getEmeta (l);
1566 25362 : if ((*m) == M2Const_unknown)
1567 : {
1568 6127 : (*m) = getEmeta (r);
1569 : }
1570 19235 : else if (((getEmeta (r)) != M2Const_unknown) && ((*m) != (getEmeta (r))))
1571 : {
1572 : /* avoid dangling else. */
1573 0 : M2Error_ErrorFormat0 (M2Error_NewError (constToken), (const char *) "the operands to a binary constant expression have different types", 65);
1574 : }
1575 : }
1576 : else
1577 : {
1578 : /* avoid dangling else. */
1579 0 : M2Error_InternalError ((const char *) "unexpected operator", 19);
1580 : }
1581 25368 : }
1582 :
1583 :
1584 : /*
1585 : WalkConvert -
1586 : */
1587 :
1588 76 : static bool WalkConvert (PCSymBuild_exprNode e)
1589 : {
1590 76 : if (isTypeResolved (e))
1591 : {
1592 : return false;
1593 : }
1594 : else
1595 : {
1596 64 : if (e->econvert.totype == SymbolTable_NulSym)
1597 : {
1598 : return false;
1599 : }
1600 60 : else if (isTypeResolved (e->econvert.totype))
1601 : {
1602 : /* avoid dangling else. */
1603 30 : assignType (e, e->econvert.totype);
1604 30 : return true;
1605 : }
1606 30 : return doWalkNode (e->econvert.totype);
1607 : }
1608 : /* static analysis guarentees a RETURN statement will be used before here. */
1609 : __builtin_unreachable ();
1610 : }
1611 :
1612 :
1613 : /*
1614 : WalkFunctionParam -
1615 : */
1616 :
1617 265 : static bool WalkFunctionParam (unsigned int func, PCSymBuild_exprNode e)
1618 : {
1619 265 : if (isTypeResolved (e))
1620 : {
1621 : return false;
1622 : }
1623 : else
1624 : {
1625 265 : if (e->tag == PCSymBuild_leaf)
1626 : {
1627 265 : if ((e->eleaf.sym != SymbolTable_NulSym) && (e->eleaf.type == SymbolTable_NulSym))
1628 : {
1629 265 : if ((func == M2Base_Min) || (func == M2Base_Max))
1630 : {
1631 265 : if ((SymbolTable_IsSet (e->eleaf.sym)) || ((SymbolTable_IsType (e->eleaf.sym)) && (SymbolTable_IsSet (SymbolTable_SkipType (e->eleaf.sym)))))
1632 : {
1633 46 : e->eleaf.type = SymbolTable_GetType (SymbolTable_SkipType (e->eleaf.sym));
1634 : }
1635 : else
1636 : {
1637 : /* sym is the type required for MAX, MIN and VAL. */
1638 219 : e->eleaf.type = e->eleaf.sym;
1639 : }
1640 : }
1641 : else
1642 : {
1643 0 : M2Debug_Assert (func == M2Base_Val);
1644 0 : e->eleaf.type = e->eleaf.sym;
1645 : }
1646 265 : e->eleaf.meta = TypeToMeta (e->eleaf.sym);
1647 265 : return true;
1648 : }
1649 : }
1650 : }
1651 : return false;
1652 : /* static analysis guarentees a RETURN statement will be used before here. */
1653 : __builtin_unreachable ();
1654 : }
1655 :
1656 :
1657 : /*
1658 : WalkFunction -
1659 : */
1660 :
1661 692 : static bool WalkFunction (PCSymBuild_exprNode e)
1662 : {
1663 692 : if (isTypeResolved (e))
1664 : {
1665 : return false;
1666 : }
1667 : else
1668 : {
1669 530 : if (((e->efunction.func == M2Base_Max) || (e->efunction.func == M2Base_Min)) || (e->efunction.func == M2Base_Val))
1670 : {
1671 530 : if (isTypeResolved (e->efunction.first))
1672 : {
1673 265 : if ((getEmeta (e->efunction.first)) == M2Const_str)
1674 : {
1675 0 : M2MetaError_MetaError1 ((const char *) "a string parameter cannot be passed to function {%1Dad}", 55, e->efunction.func);
1676 0 : return false;
1677 : }
1678 265 : e->efunction.type = getEtype (e->efunction.first);
1679 265 : return true;
1680 : }
1681 265 : return WalkFunctionParam (e->efunction.func, e->efunction.first);
1682 : }
1683 : else
1684 : {
1685 0 : M2MetaError_MetaError1 ((const char *) "not expecting this function inside a constant expression {%1Dad}", 64, e->efunction.func);
1686 : }
1687 0 : return true;
1688 : }
1689 : /* static analysis guarentees a RETURN statement will be used before here. */
1690 : __builtin_unreachable ();
1691 : }
1692 :
1693 :
1694 : /*
1695 : doWalkNode -
1696 : */
1697 :
1698 95695 : static bool doWalkNode (PCSymBuild_exprNode e)
1699 : {
1700 95695 : switch (e->tag)
1701 : {
1702 0 : case PCSymBuild_expr:
1703 0 : return WalkExpr (e);
1704 52014 : break;
1705 :
1706 52014 : case PCSymBuild_leaf:
1707 52014 : return WalkLeaf (e);
1708 186 : break;
1709 :
1710 186 : case PCSymBuild_unary:
1711 186 : return WalkUnary (e);
1712 42727 : break;
1713 :
1714 42727 : case PCSymBuild_binary:
1715 42727 : return WalkBinary (e);
1716 76 : break;
1717 :
1718 76 : case PCSymBuild_convert:
1719 76 : return WalkConvert (e);
1720 692 : break;
1721 :
1722 692 : case PCSymBuild_function:
1723 692 : return WalkFunction (e);
1724 0 : break;
1725 :
1726 :
1727 0 : default:
1728 0 : M2Error_InternalError ((const char *) "unexpected tag value", 20);
1729 : break;
1730 : }
1731 : return false;
1732 : /* static analysis guarentees a RETURN statement will be used before here. */
1733 : __builtin_unreachable ();
1734 : }
1735 :
1736 :
1737 : /*
1738 : WalkLeaf -
1739 : */
1740 :
1741 52014 : static bool WalkLeaf (PCSymBuild_exprNode e)
1742 : {
1743 52014 : PCSymBuild_exprNode c;
1744 :
1745 52014 : if (isTypeResolved (e))
1746 : {
1747 : return false;
1748 : }
1749 : else
1750 : {
1751 41108 : if ((SymbolTable_IsConst (e->eleaf.sym)) && ((SymbolTable_GetType (e->eleaf.sym)) != SymbolTable_NulSym))
1752 : {
1753 34560 : e->eleaf.type = GetSkippedType (e->eleaf.sym);
1754 34560 : return true;
1755 : }
1756 6548 : if (SymbolTable_IsAModula2Type (e->eleaf.sym))
1757 : {
1758 42 : e->eleaf.type = e->eleaf.sym;
1759 42 : return true;
1760 : }
1761 6506 : c = findConstDes (e->eleaf.sym);
1762 6506 : if ((c != NULL) && (isTypeResolved (c)))
1763 : {
1764 96 : assignType (e, c);
1765 96 : return true;
1766 : }
1767 : }
1768 : return false;
1769 : /* static analysis guarentees a RETURN statement will be used before here. */
1770 : __builtin_unreachable ();
1771 : }
1772 :
1773 :
1774 : /*
1775 : WalkUnary -
1776 : */
1777 :
1778 186 : static bool WalkUnary (PCSymBuild_exprNode e)
1779 : {
1780 186 : if (isTypeResolved (e))
1781 : {
1782 : return false;
1783 : }
1784 : else
1785 : {
1786 186 : if (isTypeResolved (e->eunary.left))
1787 : {
1788 114 : deduceTypes (&e->eunary.type, &e->eunary.meta, e->eunary.left, e->eunary.left, e->eunary.op);
1789 114 : return true;
1790 : }
1791 72 : return doWalkNode (e->eunary.left);
1792 : }
1793 : /* static analysis guarentees a RETURN statement will be used before here. */
1794 : __builtin_unreachable ();
1795 : }
1796 :
1797 :
1798 : /*
1799 : WalkBinary -
1800 : */
1801 :
1802 42727 : static bool WalkBinary (PCSymBuild_exprNode e)
1803 : {
1804 42727 : bool changed;
1805 :
1806 42727 : if (isTypeResolved (e))
1807 : {
1808 : return false;
1809 : }
1810 : else
1811 : {
1812 42631 : if ((isTypeResolved (e->ebinary.left)) && (isTypeResolved (e->ebinary.right)))
1813 : {
1814 25254 : deduceTypes (&e->ebinary.type, &e->ebinary.meta, e->ebinary.left, e->ebinary.right, e->ebinary.op);
1815 25254 : return true;
1816 : }
1817 17377 : changed = doWalkNode (e->ebinary.left);
1818 17377 : return (doWalkNode (e->ebinary.right)) || changed;
1819 : }
1820 : /* static analysis guarentees a RETURN statement will be used before here. */
1821 : __builtin_unreachable ();
1822 : }
1823 :
1824 :
1825 : /*
1826 : WalkExpr -
1827 : */
1828 :
1829 0 : static bool WalkExpr (PCSymBuild_exprNode e)
1830 : {
1831 0 : if (isTypeResolved (e))
1832 : {
1833 : return false;
1834 : }
1835 : else
1836 : {
1837 0 : if (isTypeResolved (e->eexpr.left))
1838 : {
1839 0 : assignType (e, e->eexpr.left);
1840 0 : return true;
1841 : }
1842 0 : return doWalkNode (e->eexpr.left);
1843 : }
1844 : /* static analysis guarentees a RETURN statement will be used before here. */
1845 : __builtin_unreachable ();
1846 : }
1847 :
1848 :
1849 : /*
1850 : doWalkDesExpr - returns TRUE if the expression trees, d, or, e, are changed.
1851 : */
1852 :
1853 360347 : static bool doWalkDesExpr (PCSymBuild_exprNode d, PCSymBuild_exprNode e)
1854 : {
1855 360347 : if (isTypeResolved (e))
1856 : {
1857 299508 : d->edes.type = getEtype (e);
1858 299508 : if (d->edes.type == SymbolTable_NulSym)
1859 : {
1860 : /* avoid dangling else. */
1861 1295 : d->edes.meta = getEmeta (e);
1862 1295 : if (d->edes.meta == M2Const_str)
1863 : {} /* empty. */
1864 : /* PutConstString(sym, getString(e)) */
1865 : }
1866 : else
1867 : {
1868 298213 : SymbolTable_PutConst (d->edes.sym, d->edes.type);
1869 : }
1870 : return true;
1871 : }
1872 60839 : return doWalkNode (e);
1873 : /* static analysis guarentees a RETURN statement will be used before here. */
1874 : __builtin_unreachable ();
1875 : }
1876 :
1877 :
1878 : /*
1879 : doWalkDes - return TRUE if expression, e, is changed.
1880 : */
1881 :
1882 1617285 : static bool doWalkDes (PCSymBuild_exprNode d)
1883 : {
1884 1617285 : if (isTypeResolved (d))
1885 : {
1886 : return false;
1887 : }
1888 : else
1889 : {
1890 360347 : switch (d->tag)
1891 : {
1892 360347 : case PCSymBuild_designator:
1893 360347 : constToken = SymbolTable_GetDeclaredMod (d->edes.sym);
1894 360347 : return doWalkDesExpr (d, d->edes.left);
1895 0 : break;
1896 :
1897 :
1898 0 : default:
1899 0 : M2Error_InternalError ((const char *) "unexpected tag value", 20);
1900 : break;
1901 : }
1902 : }
1903 : ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/PCSymBuild.def", 20, 1);
1904 : __builtin_unreachable ();
1905 : }
1906 :
1907 :
1908 : /*
1909 : findConstDes -
1910 : */
1911 :
1912 6506 : static PCSymBuild_exprNode findConstDes (unsigned int sym)
1913 : {
1914 6506 : unsigned int i;
1915 6506 : PCSymBuild_exprNode e;
1916 :
1917 6506 : i = 1;
1918 401525 : while (i <= (Indexing_HighIndice (constList)))
1919 : {
1920 401465 : e = static_cast<PCSymBuild_exprNode> (Indexing_GetIndice (constList, i));
1921 401465 : switch (e->tag)
1922 : {
1923 401465 : case PCSymBuild_designator:
1924 401465 : if (e->edes.sym == sym)
1925 : {
1926 : return e;
1927 : }
1928 : break;
1929 :
1930 :
1931 : default:
1932 : break;
1933 : }
1934 395019 : i += 1;
1935 : }
1936 : return NULL;
1937 : /* static analysis guarentees a RETURN statement will be used before here. */
1938 : __builtin_unreachable ();
1939 : }
1940 :
1941 :
1942 : /*
1943 : WalkDes - return TRUE if expression, e, is changed.
1944 : */
1945 :
1946 1617285 : static bool WalkDes (PCSymBuild_exprNode d)
1947 : {
1948 0 : if (d == NULL)
1949 : {
1950 : return false;
1951 : }
1952 : else
1953 : {
1954 1617285 : if (Debugging)
1955 : {
1956 : DebugDes (d);
1957 : }
1958 1617285 : return doWalkDes (d);
1959 : }
1960 : /* static analysis guarentees a RETURN statement will be used before here. */
1961 : __builtin_unreachable ();
1962 : }
1963 :
1964 :
1965 : /*
1966 : WalkConsts - walk over the constant trees and return TRUE if any tree was changed.
1967 : (As a result of a type resolution).
1968 : */
1969 :
1970 49316 : static bool WalkConsts (void)
1971 : {
1972 49316 : bool changed;
1973 49316 : unsigned int i;
1974 :
1975 49316 : changed = false;
1976 49316 : i = 1;
1977 1666601 : while (i <= (Indexing_HighIndice (constList)))
1978 : {
1979 3234570 : if (WalkDes (reinterpret_cast <PCSymBuild_exprNode> (Indexing_GetIndice (constList, i))))
1980 : {
1981 1617285 : changed = true;
1982 : }
1983 1617285 : i += 1;
1984 : }
1985 49316 : return changed;
1986 : /* static analysis guarentees a RETURN statement will be used before here. */
1987 : __builtin_unreachable ();
1988 : }
1989 :
1990 :
1991 : /*
1992 : DebugNodes -
1993 : */
1994 :
1995 0 : static void DebugNodes (void)
1996 : {
1997 0 : unsigned int i;
1998 :
1999 0 : i = 1;
2000 0 : while (i <= (Indexing_HighIndice (constList)))
2001 : {
2002 0 : if (isTypeResolved (reinterpret_cast <PCSymBuild_exprNode> (Indexing_GetIndice (constList, i))))
2003 : {
2004 0 : StrIO_WriteString ((const char *) "resolved ", 9);
2005 : }
2006 : else
2007 : {
2008 0 : StrIO_WriteString ((const char *) "unresolved ", 11);
2009 : }
2010 0 : DebugNode (reinterpret_cast <PCSymBuild_exprNode> (Indexing_GetIndice (constList, i)));
2011 0 : StrIO_WriteLn ();
2012 0 : i += 1;
2013 : }
2014 0 : }
2015 :
2016 :
2017 : /*
2018 : findAlias -
2019 : */
2020 :
2021 84 : static unsigned int findAlias (unsigned int sym, PCSymBuild_exprNode e)
2022 : {
2023 168 : switch (e->tag)
2024 : {
2025 84 : case PCSymBuild_designator:
2026 84 : return findAlias (sym, e->edes.left);
2027 84 : break;
2028 :
2029 84 : case PCSymBuild_leaf:
2030 84 : return e->eleaf.sym;
2031 0 : break;
2032 :
2033 0 : case PCSymBuild_expr:
2034 0 : return findAlias (sym, e->eexpr.left);
2035 : break;
2036 :
2037 : case PCSymBuild_unary:
2038 : case PCSymBuild_binary:
2039 : return sym;
2040 0 : break;
2041 :
2042 :
2043 0 : default:
2044 0 : M2Error_InternalError ((const char *) "not expecting this tag value", 28);
2045 : break;
2046 : }
2047 : ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/PCSymBuild.def", 20, 1);
2048 : __builtin_unreachable ();
2049 : }
2050 :
2051 :
2052 : /*
2053 : CheckConsts -
2054 : */
2055 :
2056 15163 : static void CheckConsts (void)
2057 : {
2058 15163 : unsigned int i;
2059 15163 : PCSymBuild_exprNode e;
2060 :
2061 15163 : i = 1;
2062 314684 : while (i <= (Indexing_HighIndice (constList)))
2063 : {
2064 299521 : e = static_cast<PCSymBuild_exprNode> (Indexing_GetIndice (constList, i));
2065 299521 : if (! (isTypeResolved (e)))
2066 : {
2067 13 : switch (e->tag)
2068 : {
2069 13 : case PCSymBuild_designator:
2070 13 : M2MetaError_MetaError1 ((const char *) "the type of the constant declaration {%1Dad} cannot be determined", 65, e->edes.sym);
2071 13 : break;
2072 :
2073 :
2074 : default:
2075 : break;
2076 : }
2077 : }
2078 299521 : i += 1;
2079 : }
2080 15163 : }
2081 :
2082 :
2083 : /*
2084 : Init -
2085 : */
2086 :
2087 15451 : static void Init (void)
2088 : {
2089 15451 : exprStack = M2StackAddress_InitStackAddress ();
2090 15451 : constList = Indexing_InitIndex (1);
2091 15451 : desStack = M2StackWord_InitStackWord ();
2092 15451 : inDesignator = false;
2093 15451 : }
2094 :
2095 :
2096 : /*
2097 : CheckNotVar - checks to see that the top of stack is not a variable.
2098 : */
2099 :
2100 0 : extern "C" void PCSymBuild_CheckNotVar (unsigned int tok)
2101 : {
2102 0 : unsigned int const_;
2103 :
2104 0 : const_ = static_cast<unsigned int> (M2Quads_OperandT (1));
2105 0 : if ((const_ != SymbolTable_NulSym) && (SymbolTable_IsVar (const_)))
2106 : {
2107 0 : M2MetaError_MetaErrorT1 (tok, (const char *) "not expecting a variable {%Aad} as a term in a constant expression", 66, const_);
2108 : }
2109 0 : }
2110 :
2111 165455 : extern "C" void PCSymBuild_PCStartBuildDefModule (void)
2112 : {
2113 165455 : unsigned int tok;
2114 165455 : NameKey_Name name;
2115 165455 : unsigned int ModuleSym;
2116 :
2117 : /*
2118 : StartBuildDefinitionModule - Creates a definition module and starts
2119 : a new scope.
2120 :
2121 : The Stack is expected:
2122 :
2123 : Entry Exit
2124 :
2125 : Ptr -> <- Ptr
2126 : +------------+ +-----------+
2127 : | NameStart | | NameStart |
2128 : |------------| |-----------|
2129 :
2130 : */
2131 165455 : M2Quads_PopTtok (&name, &tok);
2132 165455 : ModuleSym = M2Batch_MakeDefinitionSource (tok, name);
2133 165455 : SymbolTable_SetCurrentModule (ModuleSym);
2134 165455 : SymbolTable_SetFileModule (ModuleSym);
2135 165455 : SymbolTable_StartScope (ModuleSym);
2136 165455 : M2Debug_Assert (SymbolTable_IsDefImp (ModuleSym));
2137 165455 : M2Debug_Assert (M2Comp_CompilingDefinitionModule ());
2138 165455 : M2StackSpell_Push (SymbolTable_GetBaseModule ());
2139 165455 : M2StackSpell_Push (ModuleSym);
2140 165455 : M2Quads_PushT (name);
2141 165455 : M2Error_EnterDefinitionScope (name);
2142 165455 : }
2143 :
2144 165455 : extern "C" void PCSymBuild_PCEndBuildDefModule (unsigned int tokno)
2145 : {
2146 165455 : unsigned int NameStart;
2147 165455 : unsigned int NameEnd;
2148 :
2149 : /*
2150 : EndBuildDefinitionModule - Destroys the definition module scope and
2151 : checks for correct name.
2152 :
2153 : The Stack is expected:
2154 :
2155 : Entry Exit
2156 :
2157 : Ptr ->
2158 : +------------+ +-----------+
2159 : | NameEnd | | |
2160 : |------------| |-----------|
2161 : | NameStart | | | <- Ptr
2162 : |------------| |-----------|
2163 : */
2164 165455 : M2Debug_Assert (M2Comp_CompilingDefinitionModule ());
2165 165455 : SymbolTable_CheckForUnknownInModule (tokno);
2166 165455 : SymbolTable_EndScope ();
2167 165455 : M2StackSpell_Pop ();
2168 165455 : M2StackSpell_Pop ();
2169 165455 : M2Quads_PopT (&NameEnd);
2170 165455 : M2Quads_PopT (&NameStart);
2171 165455 : if (NameStart != NameEnd)
2172 : {
2173 0 : M2Error_WriteFormat2 ((const char *) "inconsistent definition module was named (%a) and concluded as (%a)", 67, (const unsigned char *) &NameStart, (sizeof (NameStart)-1), (const unsigned char *) &NameEnd, (sizeof (NameEnd)-1));
2174 : }
2175 165455 : M2Error_LeaveErrorScope ();
2176 165455 : }
2177 :
2178 72662 : extern "C" void PCSymBuild_PCStartBuildImpModule (void)
2179 : {
2180 72662 : unsigned int tok;
2181 72662 : NameKey_Name name;
2182 72662 : unsigned int ModuleSym;
2183 :
2184 : /*
2185 : StartBuildImplementationModule - Creates an implementation module and starts
2186 : a new scope.
2187 :
2188 : The Stack is expected:
2189 :
2190 : Entry Exit
2191 :
2192 : Ptr -> <- Ptr
2193 : +------------+ +-----------+
2194 : | NameStart | | NameStart |
2195 : |------------| |-----------|
2196 :
2197 : */
2198 72662 : M2Quads_PopTtok (&name, &tok);
2199 72662 : ModuleSym = M2Batch_MakeImplementationSource (tok, name);
2200 72662 : SymbolTable_SetCurrentModule (ModuleSym);
2201 72662 : SymbolTable_SetFileModule (ModuleSym);
2202 72662 : SymbolTable_StartScope (ModuleSym);
2203 72662 : M2Debug_Assert (SymbolTable_IsDefImp (ModuleSym));
2204 72662 : M2Debug_Assert (M2Comp_CompilingImplementationModule ());
2205 72662 : M2Quads_PushTtok (name, tok);
2206 72662 : M2Error_EnterImplementationScope (name);
2207 72662 : M2StackSpell_Push (SymbolTable_GetBaseModule ());
2208 72662 : M2StackSpell_Push (ModuleSym);
2209 72662 : }
2210 :
2211 72650 : extern "C" void PCSymBuild_PCEndBuildImpModule (unsigned int tokno)
2212 : {
2213 72650 : NameKey_Name NameStart;
2214 72650 : NameKey_Name NameEnd;
2215 :
2216 : /*
2217 : EndBuildImplementationModule - Destroys the implementation module scope and
2218 : checks for correct name.
2219 :
2220 : The Stack is expected:
2221 :
2222 : Entry Exit
2223 :
2224 : Ptr ->
2225 : +------------+ +-----------+
2226 : | NameEnd | | |
2227 : |------------| |-----------|
2228 : | NameStart | | | <- Ptr
2229 : |------------| |-----------|
2230 : */
2231 72650 : M2Debug_Assert (M2Comp_CompilingImplementationModule ());
2232 72650 : SymbolTable_CheckForUnknownInModule (tokno);
2233 72650 : SymbolTable_EndScope ();
2234 72650 : M2StackSpell_Pop ();
2235 72650 : M2StackSpell_Pop ();
2236 72650 : M2Quads_PopT (&NameEnd);
2237 72650 : M2Quads_PopT (&NameStart);
2238 72650 : if (NameStart != NameEnd)
2239 : {
2240 : /* we dont issue an error based around incorrect module names as this is done in P1 and P2.
2241 : If we get here then something has gone wrong with our error recovery in PC, so we bail out.
2242 : */
2243 0 : M2Error_WriteFormat0 ((const char *) "too many errors in pass 3", 25);
2244 0 : M2Error_FlushErrors ();
2245 : }
2246 72650 : M2Error_LeaveErrorScope ();
2247 72650 : }
2248 :
2249 11831 : extern "C" void PCSymBuild_PCStartBuildProgModule (void)
2250 : {
2251 11831 : unsigned int tok;
2252 11831 : NameKey_Name name;
2253 11831 : unsigned int ModuleSym;
2254 :
2255 : /* WriteString('StartBuildProgramModule') ; WriteLn ; */
2256 11831 : M2Quads_PopTtok (&name, &tok);
2257 11831 : ModuleSym = M2Batch_MakeProgramSource (tok, name);
2258 11831 : SymbolTable_SetCurrentModule (ModuleSym);
2259 11831 : SymbolTable_SetFileModule (ModuleSym);
2260 : /* WriteString('MODULE - ') ; WriteKey(GetSymName(ModuleSym)) ; WriteLn ; */
2261 11831 : SymbolTable_StartScope (ModuleSym);
2262 11831 : M2Debug_Assert (M2Comp_CompilingProgramModule ());
2263 11831 : M2Debug_Assert (! (SymbolTable_IsDefImp (ModuleSym)));
2264 11831 : M2Quads_PushTtok (name, tok);
2265 11831 : M2Error_EnterProgramScope (name);
2266 11831 : M2StackSpell_Push (SymbolTable_GetBaseModule ());
2267 11831 : M2StackSpell_Push (ModuleSym);
2268 11831 : }
2269 :
2270 11819 : extern "C" void PCSymBuild_PCEndBuildProgModule (unsigned int tokno)
2271 : {
2272 11819 : NameKey_Name NameStart;
2273 11819 : NameKey_Name NameEnd;
2274 :
2275 : /*
2276 : EndBuildProgramModule - Destroys the program module scope and
2277 : checks for correct name.
2278 :
2279 : The Stack is expected:
2280 :
2281 : Entry Exit
2282 :
2283 : Ptr ->
2284 : +------------+ +-----------+
2285 : | NameEnd | | |
2286 : |------------| |-----------|
2287 : | NameStart | | | <- Ptr
2288 : |------------| |-----------|
2289 : */
2290 11819 : M2Debug_Assert (M2Comp_CompilingProgramModule ());
2291 11819 : SymbolTable_CheckForUnknownInModule (tokno);
2292 11819 : SymbolTable_EndScope ();
2293 11819 : M2Quads_PopT (&NameEnd);
2294 11819 : M2Quads_PopT (&NameStart);
2295 11819 : if (NameStart != NameEnd)
2296 : {
2297 : /* we dont issue an error based around incorrect module names this would be done in P1 and P2.
2298 : If we get here then something has gone wrong with our error recovery in PC, so we bail out.
2299 : */
2300 0 : M2Error_WriteFormat0 ((const char *) "too many errors in pass 3", 25);
2301 0 : M2Error_FlushErrors ();
2302 : }
2303 11819 : M2Error_LeaveErrorScope ();
2304 11819 : M2StackSpell_Pop ();
2305 11819 : M2StackSpell_Pop ();
2306 11819 : }
2307 :
2308 446 : extern "C" void PCSymBuild_PCStartBuildInnerModule (void)
2309 : {
2310 446 : NameKey_Name name;
2311 446 : unsigned int tok;
2312 446 : unsigned int ModuleSym;
2313 :
2314 : /*
2315 : StartBuildInnerModule - Creates an Inner module and starts
2316 : a new scope.
2317 :
2318 : The Stack is expected:
2319 :
2320 : Entry Exit
2321 :
2322 : Ptr -> <- Ptr
2323 : +------------+ +-----------+
2324 : | NameStart | | NameStart |
2325 : |------------| |-----------|
2326 :
2327 : */
2328 446 : M2Quads_PopTtok (&name, &tok);
2329 446 : ModuleSym = SymbolTable_RequestSym (tok, name);
2330 446 : M2Debug_Assert (SymbolTable_IsModule (ModuleSym));
2331 446 : SymbolTable_StartScope (ModuleSym);
2332 446 : M2Debug_Assert (! (SymbolTable_IsDefImp (ModuleSym)));
2333 446 : SymbolTable_SetCurrentModule (ModuleSym);
2334 446 : M2Quads_PushTtok (name, tok);
2335 446 : M2Error_EnterModuleScope (name);
2336 446 : M2StackSpell_Push (SymbolTable_GetBaseModule ());
2337 446 : M2StackSpell_Push (ModuleSym);
2338 446 : }
2339 :
2340 446 : extern "C" void PCSymBuild_PCEndBuildInnerModule (unsigned int tokno)
2341 : {
2342 446 : NameKey_Name NameStart;
2343 446 : NameKey_Name NameEnd;
2344 :
2345 : /*
2346 : EndBuildInnerModule - Destroys the Inner module scope and
2347 : checks for correct name.
2348 :
2349 : The Stack is expected:
2350 :
2351 : Entry Exit
2352 :
2353 : Ptr ->
2354 : +------------+ +-----------+
2355 : | NameEnd | | |
2356 : |------------| |-----------|
2357 : | NameStart | | | <- Ptr
2358 : |------------| |-----------|
2359 : */
2360 446 : SymbolTable_CheckForUnknownInModule (tokno);
2361 446 : SymbolTable_EndScope ();
2362 446 : M2Quads_PopT (&NameEnd);
2363 446 : M2Quads_PopT (&NameStart);
2364 446 : if (NameStart != NameEnd)
2365 : {
2366 : /* we dont issue an error based around incorrect module names this would be done in P1 and P2.
2367 : If we get here then something has gone wrong with our error recovery in PC, so we bail out.
2368 : */
2369 0 : M2Error_WriteFormat0 ((const char *) "too many errors in pass 3", 25);
2370 0 : M2Error_FlushErrors ();
2371 : }
2372 446 : SymbolTable_SetCurrentModule (SymbolTable_GetModuleScope (SymbolTable_GetCurrentModule ()));
2373 446 : M2Error_LeaveErrorScope ();
2374 446 : M2StackSpell_Pop ();
2375 446 : M2StackSpell_Pop ();
2376 446 : }
2377 :
2378 5289173 : extern "C" void PCSymBuild_PCBuildProcedureHeading (void)
2379 : {
2380 5289173 : unsigned int ProcSym;
2381 5289173 : NameKey_Name NameStart;
2382 :
2383 : /*
2384 : BuildProcedureHeading - Builds a procedure heading for the definition
2385 : module procedures.
2386 :
2387 : Operation only performed if compiling a
2388 : definition module.
2389 :
2390 : The Stack:
2391 :
2392 : Entry Exit
2393 :
2394 : Ptr ->
2395 : +------------+
2396 : | ProcSym |
2397 : |------------|
2398 : | NameStart |
2399 : |------------|
2400 : Empty
2401 :
2402 : */
2403 5289173 : if (M2Comp_CompilingDefinitionModule ())
2404 : {
2405 3344444 : M2Quads_PopT (&ProcSym);
2406 3344444 : M2Quads_PopT (&NameStart);
2407 3344444 : SymbolTable_EndScope ();
2408 3344444 : M2StackSpell_Pop ();
2409 : }
2410 5289173 : }
2411 :
2412 5289173 : extern "C" void PCSymBuild_PCStartBuildProcedure (void)
2413 : {
2414 5289173 : NameKey_Name name;
2415 5289173 : unsigned int ProcSym;
2416 5289173 : unsigned int tok;
2417 :
2418 : /*
2419 : StartBuildProcedure - Builds a Procedure.
2420 :
2421 : The Stack:
2422 :
2423 : Entry Exit
2424 :
2425 : <- Ptr
2426 : +------------+
2427 : Ptr -> | ProcSym |
2428 : +------------+ |------------|
2429 : | Name | | Name |
2430 : |------------| |------------|
2431 : */
2432 5289173 : M2Quads_PopTtok (&name, &tok);
2433 5289173 : M2Quads_PushTtok (name, tok); /* Name saved for the EndBuildProcedure name check */
2434 5289173 : ProcSym = SymbolTable_RequestSym (tok, name); /* Name saved for the EndBuildProcedure name check */
2435 5289173 : M2Debug_Assert (SymbolTable_IsProcedure (ProcSym));
2436 5289173 : M2Quads_PushTtok (ProcSym, tok);
2437 5289173 : SymbolTable_StartScope (ProcSym);
2438 5289173 : M2Error_EnterProcedureScope (name);
2439 5289173 : M2StackSpell_Push (ProcSym);
2440 5289173 : }
2441 :
2442 1944699 : extern "C" void PCSymBuild_PCEndBuildProcedure (void)
2443 : {
2444 1944699 : unsigned int ProcSym;
2445 1944699 : NameKey_Name NameEnd;
2446 1944699 : NameKey_Name NameStart;
2447 :
2448 : /*
2449 : EndBuildProcedure - Ends building a Procedure.
2450 : It checks the start procedure name matches the end
2451 : procedure name.
2452 :
2453 : The Stack:
2454 :
2455 : (Procedure Not Defined in definition module)
2456 :
2457 : Entry Exit
2458 :
2459 : Ptr ->
2460 : +------------+
2461 : | NameEnd |
2462 : |------------|
2463 : | ProcSym |
2464 : |------------|
2465 : | NameStart |
2466 : |------------|
2467 : Empty
2468 : */
2469 1944699 : M2Quads_PopT (&NameEnd);
2470 1944699 : M2Quads_PopT (&ProcSym);
2471 1944699 : M2Quads_PopT (&NameStart);
2472 1944699 : if (NameEnd != NameStart)
2473 : {
2474 : /* we dont issue an error based around incorrect module names this would be done in P1 and P2.
2475 : If we get here then something has gone wrong with our error recovery in PC, so we bail out.
2476 : */
2477 0 : M2Error_WriteFormat0 ((const char *) "too many errors in pass 3", 25);
2478 0 : M2Error_FlushErrors ();
2479 : }
2480 1944699 : SymbolTable_EndScope ();
2481 1944699 : M2Error_LeaveErrorScope ();
2482 1944699 : M2StackSpell_Pop ();
2483 1944699 : }
2484 :
2485 24 : extern "C" void PCSymBuild_PCEndBuildForward (void)
2486 : {
2487 : /*
2488 : EndBuildForward - Ends building a forward declaration.
2489 :
2490 : The Stack:
2491 :
2492 : Entry Exit
2493 :
2494 : Ptr ->
2495 : +------------+
2496 : | ProcSym |
2497 : |------------|
2498 : | NameStart |
2499 : |------------|
2500 : Empty
2501 : */
2502 24 : M2Quads_PopN (2);
2503 24 : SymbolTable_EndScope ();
2504 24 : M2Error_LeaveErrorScope ();
2505 24 : M2StackSpell_Pop ();
2506 24 : }
2507 :
2508 410195 : extern "C" void PCSymBuild_PCBuildImportOuterModule (void)
2509 : {
2510 410195 : unsigned int Sym;
2511 410195 : unsigned int ModSym;
2512 410195 : unsigned int i;
2513 410195 : unsigned int n;
2514 :
2515 : /*
2516 : BuildImportOuterModule - Builds imported identifiers into an outer module
2517 : from a definition module.
2518 :
2519 : The Stack is expected:
2520 :
2521 : Entry OR Entry
2522 :
2523 : Ptr -> Ptr ->
2524 : +------------+ +-----------+
2525 : | # | | # |
2526 : |------------| |-----------|
2527 : | Id1 | | Id1 |
2528 : |------------| |-----------|
2529 : . . . .
2530 : . . . .
2531 : . . . .
2532 : |------------| |-----------|
2533 : | Id# | | Id# |
2534 : |------------| |-----------|
2535 : | ImportTok | | Ident |
2536 : |------------| |-----------|
2537 :
2538 : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
2539 :
2540 :
2541 : Exit
2542 :
2543 : All above stack discarded
2544 : */
2545 410195 : M2Quads_PopT (&n); /* n = # of the Ident List */
2546 410195 : if ((M2Quads_OperandT (n+1)) != M2Reserved_ImportTok)
2547 : {
2548 : /* Ident List contains list of objects imported from ModSym */
2549 359834 : ModSym = M2Batch_LookupModule (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
2550 359834 : i = 1;
2551 1587800 : while (i <= n)
2552 : {
2553 868132 : Sym = SymbolTable_GetExported (M2Quads_OperandTok (i), ModSym, M2Quads_OperandT (i));
2554 868132 : SymbolTable_CheckForEnumerationInCurrentModule (Sym);
2555 868132 : i += 1;
2556 : }
2557 : }
2558 410195 : M2Quads_PopN (n+1); /* clear stack */
2559 410195 : }
2560 :
2561 248 : extern "C" void PCSymBuild_PCBuildImportInnerModule (void)
2562 : {
2563 248 : unsigned int Sym;
2564 248 : unsigned int ModSym;
2565 248 : unsigned int n;
2566 248 : unsigned int i;
2567 :
2568 : /*
2569 : BuildImportInnerModule - Builds imported identifiers into an inner module
2570 : from the last level of module.
2571 :
2572 : The Stack is expected:
2573 :
2574 : Entry OR Entry
2575 :
2576 : Ptr -> Ptr ->
2577 : +------------+ +-----------+
2578 : | # | | # |
2579 : |------------| |-----------|
2580 : | Id1 | | Id1 |
2581 : |------------| |-----------|
2582 : . . . .
2583 : . . . .
2584 : . . . .
2585 : |------------| |-----------|
2586 : | Id# | | Id# |
2587 : |------------| |-----------|
2588 : | ImportTok | | Ident |
2589 : |------------| |-----------|
2590 :
2591 : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
2592 :
2593 : Exit
2594 :
2595 : All above stack discarded
2596 : */
2597 248 : M2Quads_PopT (&n); /* i = # of the Ident List */
2598 248 : if ((M2Quads_OperandT (n+1)) == M2Reserved_ImportTok)
2599 : {
2600 : /* Ident List contains list of objects */
2601 : i = 1;
2602 370 : while (i <= n)
2603 : {
2604 188 : Sym = SymbolTable_GetFromOuterModule (M2Quads_OperandTok (i), M2Quads_OperandT (i));
2605 188 : SymbolTable_CheckForEnumerationInCurrentModule (Sym);
2606 188 : i += 1;
2607 : }
2608 : }
2609 : else
2610 : {
2611 : /* Ident List contains list of objects imported from ModSym */
2612 66 : ModSym = M2Batch_LookupOuterModule (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
2613 66 : i = 1;
2614 198 : while (i <= n)
2615 : {
2616 66 : Sym = SymbolTable_GetExported (M2Quads_OperandTok (i), ModSym, M2Quads_OperandT (i));
2617 66 : SymbolTable_CheckForEnumerationInCurrentModule (Sym);
2618 66 : i += 1;
2619 : }
2620 : }
2621 248 : M2Quads_PopN (n+1); /* Clear Stack */
2622 248 : }
2623 :
2624 :
2625 : /*
2626 : BuildNulName - Pushes a NulKey onto the top of the stack.
2627 : The Stack:
2628 :
2629 :
2630 : Entry Exit
2631 :
2632 : <- Ptr
2633 : Empty +------------+
2634 : | NulKey |
2635 : |------------|
2636 : */
2637 :
2638 0 : extern "C" void PCSymBuild_BuildNulName (void)
2639 : {
2640 0 : M2Quads_PushT (static_cast<unsigned int> (NameKey_NulName));
2641 0 : }
2642 :
2643 :
2644 : /*
2645 : BuildConst - builds a constant.
2646 : Stack
2647 :
2648 : Entry Exit
2649 :
2650 : Ptr -> <- Ptr
2651 : +------------+ +------------+
2652 : | Name | | Sym |
2653 : |------------+ |------------|
2654 : */
2655 :
2656 0 : extern "C" void PCSymBuild_BuildConst (void)
2657 : {
2658 0 : NameKey_Name name;
2659 0 : unsigned int tok;
2660 0 : unsigned int Sym;
2661 :
2662 0 : M2Quads_PopTtok (&name, &tok);
2663 0 : Sym = SymbolTable_RequestSym (tok, name);
2664 0 : M2Quads_PushTtok (Sym, tok);
2665 0 : }
2666 :
2667 :
2668 : /*
2669 : StartDesConst -
2670 : */
2671 :
2672 299617 : extern "C" void PCSymBuild_StartDesConst (void)
2673 : {
2674 299617 : NameKey_Name name;
2675 299617 : unsigned int tok;
2676 :
2677 299617 : inDesignator = true;
2678 299617 : exprStack = M2StackAddress_KillStackAddress (exprStack);
2679 299617 : exprStack = M2StackAddress_InitStackAddress ();
2680 299617 : M2Quads_PopTtok (&name, &tok);
2681 299617 : InitDesExpr (SymbolTable_RequestSym (tok, name));
2682 299617 : }
2683 :
2684 :
2685 : /*
2686 : EndDesConst -
2687 : */
2688 :
2689 299593 : extern "C" void PCSymBuild_EndDesConst (void)
2690 : {
2691 299593 : PCSymBuild_exprNode d;
2692 299593 : PCSymBuild_exprNode e;
2693 :
2694 299593 : e = static_cast<PCSymBuild_exprNode> (M2StackAddress_PopAddress (exprStack));
2695 299593 : d = static_cast<PCSymBuild_exprNode> (M2StackAddress_PopAddress (exprStack));
2696 299593 : M2Debug_Assert (d->tag == PCSymBuild_designator);
2697 299593 : d->edes.left = e;
2698 299593 : Indexing_IncludeIndiceIntoIndex (constList, reinterpret_cast <void *> (d));
2699 299593 : inDesignator = false;
2700 299593 : }
2701 :
2702 :
2703 : /*
2704 : BuildRelationConst - builds a relationship binary operation.
2705 : */
2706 :
2707 150 : extern "C" void PCSymBuild_BuildRelationConst (void)
2708 : {
2709 150 : NameKey_Name op;
2710 :
2711 150 : M2Quads_PopT (&op);
2712 150 : if (inDesignator)
2713 : {
2714 150 : InitBinary (M2Const_boolean, M2Base_Boolean, op);
2715 : }
2716 150 : }
2717 :
2718 :
2719 : /*
2720 : BuildUnaryConst - builds a unary operator node.
2721 : */
2722 :
2723 19039 : extern "C" void PCSymBuild_BuildUnaryConst (void)
2724 : {
2725 19039 : NameKey_Name op;
2726 :
2727 19039 : M2Quads_PopT (&op);
2728 19039 : if (inDesignator)
2729 : {
2730 180 : InitUnary (M2Const_unknown, SymbolTable_NulSym, op);
2731 : }
2732 19039 : }
2733 :
2734 :
2735 : /*
2736 : BuildBinaryConst - builds a binary operator node.
2737 : */
2738 :
2739 30016 : extern "C" void PCSymBuild_BuildBinaryConst (void)
2740 : {
2741 30016 : NameKey_Name op;
2742 :
2743 30016 : M2Quads_PopT (&op);
2744 30016 : if (inDesignator)
2745 : {
2746 25320 : InitBinary (M2Const_unknown, SymbolTable_NulSym, op);
2747 : }
2748 30016 : }
2749 :
2750 :
2751 : /*
2752 : PushConstFunctionType -
2753 : */
2754 :
2755 7537 : extern "C" void PCSymBuild_PushConstFunctionType (void)
2756 : {
2757 7537 : unsigned int functok;
2758 7537 : unsigned int func;
2759 7537 : unsigned int n;
2760 :
2761 7537 : M2Quads_PopT (&n);
2762 7537 : M2Quads_PopTtok (&func, &functok);
2763 7537 : if (inDesignator)
2764 : {
2765 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
2766 6731 : if (func == SymbolTable_NulSym)
2767 : {
2768 24 : ErrorConstFunction (func, functok);
2769 : }
2770 6707 : else if ((func != M2Base_Convert) && (((M2Base_IsPseudoBaseFunction (func)) || (M2System_IsPseudoSystemFunctionConstExpression (func))) || ((SymbolTable_IsProcedure (func)) && (SymbolTable_IsProcedureBuiltin (func)))))
2771 : {
2772 : /* avoid dangling else. */
2773 6575 : buildConstFunction (func, n);
2774 : }
2775 132 : else if (SymbolTable_IsAModula2Type (func))
2776 : {
2777 : /* avoid dangling else. */
2778 114 : if (n == 1)
2779 : {
2780 : /* the top element on the expression stack is the first and only parameter to the cast */
2781 114 : InitUnary (M2Const_cast, func, SymbolTable_GetSymName (func));
2782 : }
2783 : else
2784 : {
2785 0 : M2Error_WriteFormat0 ((const char *) "a constant type conversion can only have one argument", 53);
2786 : }
2787 : }
2788 : else
2789 : {
2790 : /* avoid dangling else. */
2791 18 : ErrorConstFunction (func, functok);
2792 : }
2793 : }
2794 7537 : M2Quads_PushTtok (func, functok);
2795 7537 : }
2796 :
2797 :
2798 : /*
2799 : PushIntegerType -
2800 : */
2801 :
2802 376461 : extern "C" void PCSymBuild_PushIntegerType (void)
2803 : {
2804 376461 : unsigned int sym;
2805 376461 : M2Const_constType m;
2806 :
2807 376461 : M2Quads_PopT (&sym);
2808 376461 : if (inDesignator)
2809 : {
2810 210121 : m = TypeToMeta (GetSkippedType (sym));
2811 210121 : if (m == M2Const_char)
2812 : {
2813 121076 : InitCharType (sym);
2814 : }
2815 : else
2816 : {
2817 89045 : InitZType (sym);
2818 : }
2819 : }
2820 376461 : }
2821 :
2822 :
2823 : /*
2824 : PushRType -
2825 : */
2826 :
2827 2916 : extern "C" void PCSymBuild_PushRType (void)
2828 : {
2829 2916 : unsigned int sym;
2830 :
2831 2916 : M2Quads_PopT (&sym);
2832 2916 : if (inDesignator)
2833 : {
2834 1242 : InitRType (sym);
2835 : }
2836 2916 : }
2837 :
2838 :
2839 : /*
2840 : PushStringType -
2841 : */
2842 :
2843 51789 : extern "C" void PCSymBuild_PushStringType (void)
2844 : {
2845 51789 : unsigned int sym;
2846 :
2847 51789 : M2Quads_PopT (&sym);
2848 51789 : if (inDesignator)
2849 : {
2850 1409 : InitLeaf (M2Const_str, sym, SymbolTable_NulSym);
2851 : }
2852 51789 : }
2853 :
2854 :
2855 : /*
2856 : SkipConst - returns an alias to constant, sym, if one exists.
2857 : Otherwise sym is returned.
2858 : */
2859 :
2860 1243236 : extern "C" unsigned int PCSymBuild_SkipConst (unsigned int sym)
2861 : {
2862 1243236 : unsigned int i;
2863 1243236 : PCSymBuild_exprNode e;
2864 :
2865 1243236 : i = 1;
2866 64182631 : while (i <= (Indexing_HighIndice (constList)))
2867 : {
2868 62939479 : e = static_cast<PCSymBuild_exprNode> (Indexing_GetIndice (constList, i));
2869 62939479 : if ((e->tag == PCSymBuild_designator) && (e->edes.sym == sym))
2870 : {
2871 84 : return findAlias (sym, e);
2872 : }
2873 62939395 : i += 1;
2874 : }
2875 : return sym;
2876 : /* static analysis guarentees a RETURN statement will be used before here. */
2877 : __builtin_unreachable ();
2878 : }
2879 :
2880 :
2881 : /*
2882 : PushConstType - pushes a constant to the expression stack.
2883 : */
2884 :
2885 240579 : extern "C" void PCSymBuild_PushConstType (void)
2886 : {
2887 240579 : unsigned int c;
2888 :
2889 240579 : M2Quads_PopT (&c);
2890 240579 : M2Quads_PushT (c);
2891 240579 : if (inDesignator)
2892 : {
2893 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
2894 77976 : if (c == SymbolTable_NulSym)
2895 : {
2896 12 : M2Error_WriteFormat0 ((const char *) "module or symbol in qualident is not known", 42);
2897 12 : M2Error_FlushErrors ();
2898 0 : InitUnknown (c);
2899 : }
2900 77964 : else if (SymbolTable_IsProcedure (c))
2901 : {
2902 : /* avoid dangling else. */
2903 18 : InitProcedure (c);
2904 : }
2905 77946 : else if ((GetSkippedType (c)) == M2Base_RType)
2906 : {
2907 : /* avoid dangling else. */
2908 0 : InitRType (c);
2909 : }
2910 77946 : else if ((GetSkippedType (c)) == M2Base_ZType)
2911 : {
2912 : /* avoid dangling else. */
2913 0 : InitZType (c);
2914 : }
2915 77946 : else if ((GetSkippedType (c)) == M2Base_Boolean)
2916 : {
2917 : /* avoid dangling else. */
2918 36967 : InitBooleanType (c);
2919 : }
2920 : else
2921 : {
2922 : /* avoid dangling else. */
2923 40979 : InitUnknown (c);
2924 : }
2925 : }
2926 240567 : }
2927 :
2928 :
2929 : /*
2930 : PushConstAttributeType -
2931 : */
2932 :
2933 29982 : extern "C" void PCSymBuild_PushConstAttributeType (void)
2934 : {
2935 29982 : NameKey_Name n;
2936 :
2937 29982 : M2Quads_PopT (&n);
2938 29982 : M2Quads_PushT (n);
2939 29982 : InitZType (SymbolTable_NulSym);
2940 29982 : if ((((n == (NameKey_MakeKey ((const char *) "BITS_PER_UNIT", 13))) || (n == (NameKey_MakeKey ((const char *) "BITS_PER_WORD", 13)))) || (n == (NameKey_MakeKey ((const char *) "BITS_PER_CHAR", 13)))) || (n == (NameKey_MakeKey ((const char *) "UNITS_PER_WORD", 14))))
2941 : {} /* empty. */
2942 : else
2943 : {
2944 : /* all ok */
2945 0 : M2Error_WriteFormat1 ((const char *) "unknown constant attribute value '%a'", 37, (const unsigned char *) &n, (sizeof (n)-1));
2946 : }
2947 29982 : }
2948 :
2949 :
2950 : /*
2951 : PushConstAttributePairType -
2952 : */
2953 :
2954 360 : extern "C" void PCSymBuild_PushConstAttributePairType (void)
2955 : {
2956 360 : NameKey_Name q;
2957 360 : NameKey_Name n;
2958 :
2959 360 : M2Quads_PopT (&n);
2960 360 : M2Quads_PopT (&q);
2961 360 : M2Quads_PushT (q);
2962 360 : M2Quads_PushT (n);
2963 360 : if ((((((((n == (NameKey_MakeKey ((const char *) "IEC559", 6))) || (n == (NameKey_MakeKey ((const char *) "LIA1", 4)))) || (n == (NameKey_MakeKey ((const char *) "IEEE", 4)))) || (n == (NameKey_MakeKey ((const char *) "ISO", 3)))) || (n == (NameKey_MakeKey ((const char *) "rounds", 6)))) || (n == (NameKey_MakeKey ((const char *) "gUnderflow", 10)))) || (n == (NameKey_MakeKey ((const char *) "exception", 9)))) || (n == (NameKey_MakeKey ((const char *) "extend", 6))))
2964 : {
2965 192 : InitBooleanType (SymbolTable_NulSym);
2966 : }
2967 168 : else if (((((n == (NameKey_MakeKey ((const char *) "radix", 5))) || (n == (NameKey_MakeKey ((const char *) "places", 6)))) || (n == (NameKey_MakeKey ((const char *) "expoMin", 7)))) || (n == (NameKey_MakeKey ((const char *) "expoMax", 7)))) || (n == (NameKey_MakeKey ((const char *) "nModes", 6))))
2968 : {
2969 : /* avoid dangling else. */
2970 120 : InitZType (SymbolTable_NulSym);
2971 : }
2972 48 : else if ((n == (NameKey_MakeKey ((const char *) "large", 5))) || (n == (NameKey_MakeKey ((const char *) "small", 5))))
2973 : {
2974 : /* avoid dangling else. */
2975 48 : InitRType (SymbolTable_NulSym);
2976 : }
2977 : else
2978 : {
2979 : /* avoid dangling else. */
2980 0 : M2Error_WriteFormat1 ((const char *) "unknown constant attribute value '%a'", 37, (const unsigned char *) &n, (sizeof (n)-1));
2981 0 : InitUnknown (SymbolTable_NulSym);
2982 : }
2983 360 : }
2984 :
2985 :
2986 : /*
2987 : PushConstructorCastType -
2988 : */
2989 :
2990 37185 : extern "C" void PCSymBuild_PushConstructorCastType (void)
2991 : {
2992 37185 : if (inDesignator)
2993 : {
2994 4435 : InitConvert (M2Const_cast, M2Quads_OperandT (1), NULL, NULL);
2995 : }
2996 37185 : }
2997 :
2998 :
2999 : /*
3000 : PushInConstructor -
3001 : */
3002 :
3003 37185 : extern "C" void PCSymBuild_PushInConstructor (void)
3004 : {
3005 37185 : M2StackWord_PushWord (desStack, static_cast<unsigned int> (inDesignator));
3006 37185 : inDesignator = false;
3007 37185 : }
3008 :
3009 :
3010 : /*
3011 : PopInConstructor -
3012 : */
3013 :
3014 37185 : extern "C" void PCSymBuild_PopInConstructor (void)
3015 : {
3016 37185 : inDesignator = static_cast<bool> (M2StackWord_PopWord (desStack));
3017 37185 : }
3018 :
3019 :
3020 : /*
3021 : ResolveConstTypes - resolves the types of all designator declared constants.
3022 : */
3023 :
3024 15163 : extern "C" void PCSymBuild_ResolveConstTypes (void)
3025 : {
3026 15163 : if (Debugging)
3027 : {
3028 : StrIO_WriteString ((const char *) "initially", 9);
3029 : StrIO_WriteLn ();
3030 : DebugNodes ();
3031 : }
3032 49316 : while (WalkConsts ())
3033 : {
3034 : if (Debugging)
3035 : {
3036 : StrIO_WriteString ((const char *) "iteration", 9);
3037 : StrIO_WriteLn ();
3038 : DebugNodes ();
3039 : }
3040 : }
3041 15163 : if (Debugging)
3042 : {
3043 : StrIO_WriteString ((const char *) "finally", 7);
3044 : StrIO_WriteLn ();
3045 : DebugNodes ();
3046 : }
3047 15163 : CheckConsts ();
3048 15163 : }
3049 :
3050 15451 : extern "C" void _M2_PCSymBuild_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
3051 : {
3052 15451 : Init ();
3053 15451 : }
3054 :
3055 0 : extern "C" void _M2_PCSymBuild_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
3056 : {
3057 0 : }
|