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