Line data Source code
1 : /* do not edit automatically generated by mc from M2GCCDeclare. */
2 : /* M2GCCDeclare.mod declares Modula-2 types to GCC.
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 _M2GCCDeclare_C
49 :
50 : #include "GM2GCCDeclare.h"
51 : # include "GSYSTEM.h"
52 : # include "GASCII.h"
53 : # include "GStorage.h"
54 : # include "GM2Debug.h"
55 : # include "GM2Quads.h"
56 : # include "Gm2pp.h"
57 : # include "GFIO.h"
58 : # include "GM2Options.h"
59 : # include "GM2AsmUtil.h"
60 : # include "GFormatStrings.h"
61 : # include "GM2Batch.h"
62 : # include "GNameKey.h"
63 : # include "GM2FileName.h"
64 : # include "GDynamicStrings.h"
65 : # include "GM2LexBuf.h"
66 : # include "GM2MetaError.h"
67 : # include "GM2Error.h"
68 : # include "GM2LangDump.h"
69 : # include "GM2Diagnostic.h"
70 : # include "GM2Printf.h"
71 : # include "GIndexing.h"
72 : # include "GLists.h"
73 : # include "GSets.h"
74 : # include "GM2BasicBlock.h"
75 : # include "GSymbolTable.h"
76 : # include "GM2Base.h"
77 : # include "GM2System.h"
78 : # include "GM2Bitset.h"
79 : # include "GSymbolConversion.h"
80 : # include "GM2GenGCC.h"
81 : # include "GM2Scope.h"
82 : # include "GM2ALU.h"
83 : # include "Ggcctypes.h"
84 : # include "Gm2linemap.h"
85 : # include "Gm2decl.h"
86 : # include "Gm2type.h"
87 : # include "Gm2convert.h"
88 : # include "Gm2expr.h"
89 : # include "Gm2block.h"
90 :
91 : # define Debugging false
92 : # define Progress false
93 : # define EnableSSA false
94 : # define EnableWatch true
95 : # define TraceQuadruples false
96 : typedef struct M2GCCDeclare_StartProcedure_p M2GCCDeclare_StartProcedure;
97 :
98 : typedef struct M2GCCDeclare_doDeclareProcedure_p M2GCCDeclare_doDeclareProcedure;
99 :
100 : typedef struct M2GCCDeclare__T1_r M2GCCDeclare__T1;
101 :
102 : typedef M2GCCDeclare__T1 *M2GCCDeclare_Group;
103 :
104 : typedef enum {M2GCCDeclare_fullydeclared, M2GCCDeclare_partiallydeclared, M2GCCDeclare_niltypedarrays, M2GCCDeclare_heldbyalignment, M2GCCDeclare_finishedalignment, M2GCCDeclare_todolist, M2GCCDeclare_tobesolvedbyquads, M2GCCDeclare_finishedsetarray} M2GCCDeclare_ListType;
105 :
106 : typedef enum {M2GCCDeclare_norule, M2GCCDeclare_partialtype, M2GCCDeclare_arraynil, M2GCCDeclare_pointernilarray, M2GCCDeclare_arraypartial, M2GCCDeclare_pointerfully, M2GCCDeclare_recordkind, M2GCCDeclare_recordfully, M2GCCDeclare_typeconstfully, M2GCCDeclare_pointerfrompartial, M2GCCDeclare_typefrompartial, M2GCCDeclare_partialfrompartial, M2GCCDeclare_partialtofully, M2GCCDeclare_circulartodo, M2GCCDeclare_circularpartial, M2GCCDeclare_circularniltyped, M2GCCDeclare_setarraynul, M2GCCDeclare_setfully} M2GCCDeclare_Rule;
107 :
108 : # define DebugLoop 1000
109 : typedef tree (*M2GCCDeclare_StartProcedure_t) (location_t, void *);
110 : struct M2GCCDeclare_StartProcedure_p { M2GCCDeclare_StartProcedure_t proc; };
111 :
112 : typedef void (*M2GCCDeclare_doDeclareProcedure_t) (unsigned int, unsigned int);
113 : struct M2GCCDeclare_doDeclareProcedure_p { M2GCCDeclare_doDeclareProcedure_t proc; };
114 :
115 : struct M2GCCDeclare__T1_r {
116 : Sets_Set ToBeSolvedByQuads;
117 : Sets_Set FinishedSetArray;
118 : Sets_Set NilTypedArrays;
119 : Sets_Set FullyDeclared;
120 : Sets_Set PartiallyDeclared;
121 : Sets_Set HeldByAlignment;
122 : Sets_Set FinishedAlignment;
123 : Sets_Set ToDoList;
124 : M2GCCDeclare_Group Next;
125 : };
126 :
127 : static M2GCCDeclare_Group FreeGroup;
128 : static M2GCCDeclare_Group GlobalGroup;
129 : static Sets_Set ErrorDepList;
130 : static Sets_Set VisitedList;
131 : static Sets_Set ChainedList;
132 : static bool HaveInitDefaultTypes;
133 : static Sets_Set WatchList;
134 : static Indexing_Index EnumerationIndex;
135 : static M2GCCDeclare_IsAction action;
136 : static bool ConstantResolved;
137 : static bool enumDeps;
138 : static unsigned int tempset;
139 : static M2GCCDeclare_WalkAction bodyp;
140 : static M2GCCDeclare_IsAction bodyq;
141 : static M2GCCDeclare_ListType bodyt;
142 : static M2GCCDeclare_Rule bodyr;
143 : static bool recursionCaught;
144 : static bool oneResolved;
145 : static bool noMoreWritten;
146 : static M2GCCDeclare_WalkAction unboundedp;
147 : static unsigned int MaxEnumerationField;
148 : static unsigned int MinEnumerationField;
149 : static M2Diagnostic_Diagnostic DeclaredOutstandingTypesDiag;
150 : static M2Diagnostic_Diagnostic DeclareTypesConstantsProceduresDiag;
151 : static M2Diagnostic_Diagnostic DeclareTypesConstantsProceduresInRangeDiag;
152 :
153 : /*
154 : FoldConstants - a wrapper for ResolveConstantExpressions.
155 : */
156 :
157 : extern "C" void M2GCCDeclare_FoldConstants (M2BasicBlock_BasicBlock bb);
158 :
159 : /*
160 : StartDeclareScope - declares types, variables associated with this scope.
161 : */
162 :
163 : extern "C" void M2GCCDeclare_StartDeclareScope (unsigned int scope);
164 :
165 : /*
166 : EndDeclareScope -
167 : */
168 :
169 : extern "C" void M2GCCDeclare_EndDeclareScope (void);
170 :
171 : /*
172 : DeclareParameters -
173 : */
174 :
175 : extern "C" void M2GCCDeclare_DeclareParameters (unsigned int sym);
176 :
177 : /*
178 : DeclareConstant - checks to see whether, sym, is a constant and
179 : declares the constant to gcc.
180 : */
181 :
182 : extern "C" void M2GCCDeclare_DeclareConstant (unsigned int tokenno, unsigned int sym);
183 :
184 : /*
185 : DeclareConstructor - declares a constructor.
186 : */
187 :
188 : extern "C" void M2GCCDeclare_DeclareConstructor (unsigned int tokenno, unsigned int quad, unsigned int sym);
189 :
190 : /*
191 : TryDeclareConstant - try and declare a constant. If, sym, is a
192 : constant try and declare it, if we cannot
193 : then enter it into the to do list.
194 : */
195 :
196 : extern "C" void M2GCCDeclare_TryDeclareConstant (unsigned int tokenno, unsigned int sym);
197 :
198 : /*
199 : TryDeclareType - try and declare a type. If sym is a
200 : type try and declare it, if we cannot
201 : then enter it into the to do list.
202 : */
203 :
204 : extern "C" void M2GCCDeclare_TryDeclareType (unsigned int type);
205 :
206 : /*
207 : TryDeclareConstructor - try and declare a constructor. If, sym, is a
208 : constructor try and declare it, if we cannot
209 : then enter it into the to do list.
210 : */
211 :
212 : extern "C" void M2GCCDeclare_TryDeclareConstructor (unsigned int tokenno, unsigned int sym);
213 :
214 : /*
215 : DeclareLocalVariables - declares Local variables for procedure.
216 : */
217 :
218 : extern "C" void M2GCCDeclare_DeclareLocalVariables (unsigned int procedure);
219 :
220 : /*
221 : DeclareLocalVariable - declare a local variable var.
222 : */
223 :
224 : extern "C" void M2GCCDeclare_DeclareLocalVariable (unsigned int var);
225 :
226 : /*
227 : DeclareProcedure - declares procedure, sym, or all procedures inside
228 : module sym.
229 : */
230 :
231 : extern "C" void M2GCCDeclare_DeclareProcedure (unsigned int sym);
232 :
233 : /*
234 : DeclareModuleVariables - declares Module variables for a module
235 : which was declared inside a procedure.
236 : */
237 :
238 : extern "C" void M2GCCDeclare_DeclareModuleVariables (unsigned int sym);
239 :
240 : /*
241 : IsProcedureGccNested - returns TRUE if procedure, sym, will be considered
242 : as nested by GCC.
243 : This will occur if either its outer defining scope
244 : is a procedure or is a module which is inside a
245 : procedure.
246 : */
247 :
248 : extern "C" bool M2GCCDeclare_IsProcedureGccNested (unsigned int sym);
249 :
250 : /*
251 : PoisonSymbols - poisons all gcc symbols from procedure, sym.
252 : A debugging aid.
253 : */
254 :
255 : extern "C" void M2GCCDeclare_PoisonSymbols (unsigned int sym);
256 :
257 : /*
258 : PromoteToString - declare, sym, and then promote it to a string.
259 : Note that if sym is a single character we do
260 : *not* record it as a string
261 : but as a char however we always
262 : return a string constant.
263 : */
264 :
265 : extern "C" tree M2GCCDeclare_PromoteToString (unsigned int tokenno, unsigned int sym);
266 :
267 : /*
268 : PromoteToCString - declare, sym, and then promote it to a string.
269 : Note that if sym is a single character we do
270 : *not* record it as a string
271 : but as a char however we always
272 : return a string constant.
273 : */
274 :
275 : extern "C" tree M2GCCDeclare_PromoteToCString (unsigned int tokenno, unsigned int sym);
276 :
277 : /*
278 : CompletelyResolved - returns TRUE if a symbols has been completely resolved
279 : and is not partically declared (such as a record).
280 : */
281 :
282 : extern "C" bool M2GCCDeclare_CompletelyResolved (unsigned int sym);
283 :
284 : /*
285 : ConstantKnownAndUsed -
286 : */
287 :
288 : extern "C" void M2GCCDeclare_ConstantKnownAndUsed (unsigned int sym, tree t);
289 :
290 : /*
291 : PutToBeSolvedByQuads - places, sym, to this list and returns,
292 : sym.
293 : */
294 :
295 : extern "C" void M2GCCDeclare_PutToBeSolvedByQuads (unsigned int sym);
296 :
297 : /*
298 : MarkExported - tell GCC to mark all exported procedures in module sym.
299 : */
300 :
301 : extern "C" void M2GCCDeclare_MarkExported (unsigned int sym);
302 :
303 : /*
304 : GetTypeMin -
305 : */
306 :
307 : extern "C" unsigned int M2GCCDeclare_GetTypeMin (unsigned int type);
308 :
309 : /*
310 : GetTypeMax -
311 : */
312 :
313 : extern "C" unsigned int M2GCCDeclare_GetTypeMax (unsigned int type);
314 :
315 : /*
316 : PrintSym - prints limited information about a symbol.
317 : This procedure is externally visible.
318 : */
319 :
320 : extern "C" void M2GCCDeclare_PrintSym (unsigned int sym);
321 :
322 : /*
323 : IncludeDumpSymbol - include sym into the watch list and all syms dependants.
324 : */
325 :
326 : extern "C" void M2GCCDeclare_IncludeDumpSymbol (unsigned int sym);
327 :
328 : /*
329 : DumpFilteredResolver - dumps the gimple or tree representation of all watched symbols.
330 : */
331 :
332 : extern "C" void M2GCCDeclare_DumpFilteredResolver (void);
333 :
334 : /*
335 : DumpFilteredDefinitive - dumps the gimple or tree representation of all watched symbols.
336 : */
337 :
338 : extern "C" void M2GCCDeclare_DumpFilteredDefinitive (void);
339 :
340 : /*
341 : InitDeclarations - initializes default types and the source filename.
342 : */
343 :
344 : extern "C" void M2GCCDeclare_InitDeclarations (void);
345 :
346 : /*
347 : PrintNum -
348 : */
349 :
350 : static void PrintNum (unsigned int sym);
351 :
352 : /*
353 : DebugSet -
354 : */
355 :
356 : static void DebugSet (const char *a_, unsigned int _a_high, Sets_Set l);
357 :
358 : /*
359 : DebugSets -
360 : */
361 :
362 : static void DebugSets (void);
363 :
364 : /*
365 : DebugNumber -
366 : */
367 :
368 : static void DebugNumber (const char *a_, unsigned int _a_high, Sets_Set s);
369 : static void DebugSetNumbers (void);
370 :
371 : /*
372 : AddSymToWatch - adds symbol, sym, to the list of symbols
373 : to watch and annotate their movement between
374 : lists.
375 : */
376 :
377 : static void AddSymToWatch (unsigned int sym);
378 :
379 : /*
380 : doInclude -
381 : */
382 :
383 : static void doInclude (Sets_Set l, const char *a_, unsigned int _a_high, unsigned int sym);
384 :
385 : /*
386 : WatchIncludeList - include a symbol onto the set first checking
387 : whether it is already on the set and
388 : displaying a debug message if the set is
389 : changed.
390 : */
391 :
392 : static void WatchIncludeList (unsigned int sym, M2GCCDeclare_ListType lt);
393 :
394 : /*
395 : doExclude -
396 : */
397 :
398 : static void doExclude (Sets_Set l, const char *a_, unsigned int _a_high, unsigned int sym);
399 :
400 : /*
401 : WatchRemoveList - remove a symbol onto the list first checking
402 : whether it is already on the list and
403 : displaying a debug message if the list is
404 : changed.
405 : */
406 :
407 : static void WatchRemoveList (unsigned int sym, M2GCCDeclare_ListType lt);
408 :
409 : /*
410 : NewGroup -
411 : */
412 :
413 : static void NewGroup (M2GCCDeclare_Group *g);
414 :
415 : /*
416 : DisposeGroup -
417 : */
418 :
419 : static void DisposeGroup (M2GCCDeclare_Group *g);
420 :
421 : /*
422 : InitGroup - initialize all sets in group and return the group.
423 : */
424 :
425 : static M2GCCDeclare_Group InitGroup (void);
426 :
427 : /*
428 : KillGroup - delete all sets in group and deallocate g.
429 : */
430 :
431 : static void KillGroup (M2GCCDeclare_Group *g);
432 :
433 : /*
434 : DupGroup - If g is not NIL then destroy g.
435 : Return a duplicate of GlobalGroup.
436 : */
437 :
438 : static M2GCCDeclare_Group DupGroup (M2GCCDeclare_Group g);
439 :
440 : /*
441 : EqualGroup - return TRUE if group left = right.
442 : */
443 :
444 : static bool EqualGroup (M2GCCDeclare_Group left, M2GCCDeclare_Group right);
445 :
446 : /*
447 : LookupSet -
448 : */
449 :
450 : static Sets_Set LookupSet (M2GCCDeclare_ListType listtype);
451 :
452 : /*
453 : GetEnumList -
454 : */
455 :
456 : static tree GetEnumList (unsigned int sym);
457 :
458 : /*
459 : PutEnumList -
460 : */
461 :
462 : static void PutEnumList (unsigned int sym, tree enumlist);
463 :
464 : /*
465 : Chained - checks to see that, sym, has not already been placed on a chain.
466 : It returns the symbol, sym.
467 : */
468 :
469 : static unsigned int Chained (unsigned int sym);
470 :
471 : /*
472 : DoStartDeclaration - returns a tree representing a symbol which has
473 : not yet been finished. Used when declaring
474 : recursive types.
475 : */
476 :
477 : static tree DoStartDeclaration (unsigned int sym, M2GCCDeclare_StartProcedure p);
478 :
479 : /*
480 : ArrayComponentsDeclared - returns TRUE if array, sym,
481 : subscripts and type are known.
482 : */
483 :
484 : static bool ArrayComponentsDeclared (unsigned int sym);
485 :
486 : /*
487 : GetRecordOfVarient -
488 : */
489 :
490 : static unsigned int GetRecordOfVarient (unsigned int sym);
491 :
492 : /*
493 : CanDeclareRecordKind -
494 : */
495 :
496 : static bool CanDeclareRecordKind (unsigned int sym);
497 :
498 : /*
499 : DeclareRecordKind - works out whether record, sym, is packed or not.
500 : */
501 :
502 : static void DeclareRecordKind (unsigned int sym);
503 :
504 : /*
505 : CanDeclareRecord -
506 : */
507 :
508 : static bool CanDeclareRecord (unsigned int sym);
509 :
510 : /*
511 : FinishDeclareRecord -
512 : */
513 :
514 : static void FinishDeclareRecord (unsigned int sym);
515 :
516 : /*
517 : CanDeclareTypePartially - return TRUE if we are able to make a
518 : gcc partially created type.
519 : */
520 :
521 : static bool CanDeclareTypePartially (unsigned int sym);
522 :
523 : /*
524 : DeclareTypePartially - create the gcc partial type symbol from, sym.
525 : */
526 :
527 : static void DeclareTypePartially (unsigned int sym);
528 :
529 : /*
530 : CanDeclareArrayAsNil -
531 : */
532 :
533 : static bool CanDeclareArrayAsNil (unsigned int sym);
534 :
535 : /*
536 : DeclareArrayAsNil -
537 : */
538 :
539 : static void DeclareArrayAsNil (unsigned int sym);
540 :
541 : /*
542 : CanDeclareArrayPartially -
543 : */
544 :
545 : static bool CanDeclareArrayPartially (unsigned int sym);
546 :
547 : /*
548 : DeclareArrayPartially -
549 : */
550 :
551 : static void DeclareArrayPartially (unsigned int sym);
552 :
553 : /*
554 : CanDeclarePointerToNilArray -
555 : */
556 :
557 : static bool CanDeclarePointerToNilArray (unsigned int sym);
558 :
559 : /*
560 : DeclarePointerToNilArray -
561 : */
562 :
563 : static void DeclarePointerToNilArray (unsigned int sym);
564 :
565 : /*
566 : CanPromotePointerFully -
567 : */
568 :
569 : static bool CanPromotePointerFully (unsigned int sym);
570 :
571 : /*
572 : PromotePointerFully -
573 : */
574 :
575 : static void PromotePointerFully (unsigned int sym);
576 :
577 : /*
578 : IsTypeQ - returns TRUE if all q(dependants) of, sym,
579 : return TRUE.
580 : */
581 :
582 : static bool IsTypeQ (unsigned int sym, M2GCCDeclare_IsAction q);
583 :
584 : /*
585 : IsNilTypedArrays - returns TRUE if, sym, is dependant upon a NIL typed array
586 : */
587 :
588 : static bool IsNilTypedArrays (unsigned int sym);
589 :
590 : /*
591 : IsFullyDeclared - returns TRUE if, sym, is fully declared.
592 : */
593 :
594 : static bool IsFullyDeclared (unsigned int sym);
595 :
596 : /*
597 : AllDependantsFullyDeclared - returns TRUE if all dependants of,
598 : sym, are declared.
599 : */
600 :
601 : static bool AllDependantsFullyDeclared (unsigned int sym);
602 :
603 : /*
604 : NotAllDependantsFullyDeclared - returns TRUE if any dependants of,
605 : sym, are not declared.
606 : */
607 :
608 : static bool NotAllDependantsFullyDeclared (unsigned int sym);
609 :
610 : /*
611 : IsPartiallyDeclared - returns TRUE if, sym, is partially declared.
612 : */
613 :
614 : static bool IsPartiallyDeclared (unsigned int sym);
615 :
616 : /*
617 : AllDependantsPartiallyDeclared - returns TRUE if all dependants of,
618 : sym, are partially declared.
619 : */
620 :
621 : static bool AllDependantsPartiallyDeclared (unsigned int sym);
622 :
623 : /*
624 : NotAllDependantsPartiallyDeclared - returns TRUE if any dependants of,
625 : sym, are not partially declared.
626 : */
627 :
628 : static bool NotAllDependantsPartiallyDeclared (unsigned int sym);
629 :
630 : /*
631 : IsPartiallyOrFullyDeclared - returns TRUE if, sym, is partially or fully declared.
632 : */
633 :
634 : static bool IsPartiallyOrFullyDeclared (unsigned int sym);
635 :
636 : /*
637 : AllDependantsPartiallyOrFullyDeclared - returns TRUE if all dependants of,
638 : sym, are partially or fully declared.
639 : */
640 :
641 : static bool AllDependantsPartiallyOrFullyDeclared (unsigned int sym);
642 :
643 : /*
644 : TypeConstDependantsFullyDeclared - returns TRUE if sym is a constant or
645 : type and its dependants are fully
646 : declared.
647 : */
648 :
649 : static bool TypeConstDependantsFullyDeclared (unsigned int sym);
650 :
651 : /*
652 : CanBeDeclaredViaPartialDependants - returns TRUE if this symbol
653 : can be declared by partial
654 : dependants. Such a symbol must
655 : be a record, proctype or
656 : an array.
657 : */
658 :
659 : static bool CanBeDeclaredViaPartialDependants (unsigned int sym);
660 :
661 : /*
662 : DeclareConstFully - will add, sym, to the fully declared list and
663 : also remove it from the to do list. This is
664 : called indirectly from M2GenGCC as it calculates
665 : constants during quadruple processing.
666 : */
667 :
668 : static void DeclareConstFully (unsigned int sym);
669 :
670 : /*
671 : DeclareTypeConstFully - declare the GCC type and add the double
672 : book keeping entry.
673 : */
674 :
675 : static void DeclareTypeConstFully (unsigned int sym);
676 :
677 : /*
678 : DeclareTypeFromPartial - declare the full GCC type from a partial type
679 : and add the double book keeping entry.
680 : */
681 :
682 : static void DeclareTypeFromPartial (unsigned int sym);
683 :
684 : /*
685 : CanCreateSetArray - return true if we need to create a set array.
686 : All sets will have a set array created even
687 : if it is not required.
688 : */
689 :
690 : static bool CanCreateSetArray (unsigned int sym);
691 :
692 : /*
693 : CreateSetArray - declare the set array for a set type.
694 : */
695 :
696 : static void CreateSetArray (unsigned int set);
697 :
698 : /*
699 : CanCreateSet - returns TRUE if the set can be created.
700 : All dependents of sym have been declared to GCC.
701 : */
702 :
703 : static bool CanCreateSet (unsigned int set);
704 :
705 : /*
706 : CreateSet -
707 : */
708 :
709 : static void CreateSet (unsigned int set);
710 :
711 : /*
712 : CanBeDeclaredPartiallyViaPartialDependants - returns TRUE if, sym,
713 : can be partially declared via
714 : another partially declared type.
715 : */
716 :
717 : static bool CanBeDeclaredPartiallyViaPartialDependants (unsigned int sym);
718 :
719 : /*
720 : EmitCircularDependencyError - issue a dependency error.
721 : */
722 :
723 : static void EmitCircularDependencyError (unsigned int sym);
724 :
725 : /*
726 : WriteRule - writes out the name of the rule.
727 : */
728 :
729 : static void WriteRule (void);
730 :
731 : /*
732 : Body -
733 : */
734 :
735 : static void Body (unsigned int sym);
736 :
737 : /*
738 : ForeachTryDeclare - while q (of one sym in set t) is true
739 : for each symbol in set t,
740 : if q (sym)
741 : then
742 : p (sym)
743 : end
744 : end
745 : end
746 : */
747 :
748 : static bool ForeachTryDeclare (M2GCCDeclare_ListType t, M2GCCDeclare_Rule r, M2GCCDeclare_IsAction q, M2GCCDeclare_WalkAction p);
749 : static bool DeclaredOutstandingTypes (bool ForceComplete);
750 :
751 : /*
752 : CompleteDeclarationOf - returns the GCC Tree for, sym, if it can
753 : be created from partially or fully declared
754 : dependents.
755 : */
756 :
757 : static tree CompleteDeclarationOf (unsigned int sym);
758 :
759 : /*
760 : DeclareType - here a type has been created via TYPE foo = bar,
761 : we must tell GCC about it.
762 : */
763 :
764 : static tree DeclareType (unsigned int sym);
765 : static void DeclareConstantFromTree (unsigned int sym, tree value);
766 :
767 : /*
768 : DeclareCharConstant - declares a character constant.
769 : */
770 :
771 : static void DeclareCharConstant (unsigned int tokenno, unsigned int sym);
772 :
773 : /*
774 : DeclareStringConstant - declares a string constant the sym will be known.
775 : */
776 :
777 : static void DeclareStringConstant (unsigned int tokenno, unsigned int sym);
778 :
779 : /*
780 : WalkConstructor - walks all dependants of, sym.
781 : */
782 :
783 : static void WalkConstructor (unsigned int sym, M2GCCDeclare_WalkAction p);
784 :
785 : /*
786 : WalkConst - walks all dependants of, sym.
787 : */
788 :
789 : static void WalkConst (unsigned int sym, M2GCCDeclare_WalkAction p);
790 :
791 : /*
792 : IsConstDependants - returns TRUE if the symbol, sym,
793 : q(dependants) all return TRUE.
794 : */
795 :
796 : static bool IsConstDependants (unsigned int sym, M2GCCDeclare_IsAction q);
797 :
798 : /*
799 : IsAnyType - return TRUE if sym is any Modula-2 type.
800 : */
801 :
802 : static bool IsAnyType (unsigned int sym);
803 :
804 : /*
805 : DeclareConstString -
806 : */
807 :
808 : static bool DeclareConstString (unsigned int tokenno, unsigned int sym);
809 :
810 : /*
811 : TryDeclareConst - try to declare a const to gcc. If it cannot
812 : declare the symbol it places it into the
813 : todolist.
814 : */
815 :
816 : static void TryDeclareConst (unsigned int tokenno, unsigned int sym);
817 :
818 : /*
819 : DeclareConst - declares a const to gcc and returns a Tree.
820 : */
821 :
822 : static tree DeclareConst (unsigned int tokenno, unsigned int sym);
823 :
824 : /*
825 : WalkFamilyOfUnbounded -
826 : */
827 :
828 : static void WalkFamilyOfUnbounded (unsigned int oaf __attribute__((unused)), unsigned int dim __attribute__((unused)), unsigned int unbounded);
829 :
830 : /*
831 : WalkAssociatedUnbounded -
832 : */
833 :
834 : static void WalkAssociatedUnbounded (unsigned int sym, M2GCCDeclare_WalkAction p);
835 :
836 : /*
837 : WalkDependants - walks through all dependants of, Sym,
838 : calling, p, for each dependant.
839 : */
840 :
841 : static void WalkDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
842 :
843 : /*
844 : TraverseDependantsInner -
845 : */
846 :
847 : static void TraverseDependantsInner (unsigned int sym);
848 :
849 : /*
850 : TraverseDependants - walks, sym, dependants. But it checks
851 : to see that, sym, is not on the
852 : FullyDeclared and not on the ToDoList.
853 : */
854 :
855 : static void TraverseDependants (unsigned int sym);
856 :
857 : /*
858 : WalkUnbounded -
859 : */
860 :
861 : static void WalkUnbounded (unsigned int sym);
862 :
863 : /*
864 : WalkTypeInfo - walks type sym and its dependants.
865 : */
866 :
867 : static void WalkTypeInfo (unsigned int sym);
868 :
869 : /*
870 : DeclareUnboundedProcedureParameters -
871 : */
872 :
873 : static void DeclareUnboundedProcedureParameters (unsigned int sym);
874 :
875 : /*
876 : WalkUnboundedProcedureParameters -
877 : */
878 :
879 : static void WalkUnboundedProcedureParameters (unsigned int sym);
880 :
881 : /*
882 : WalkTypesInProcedure - walk all types in procedure, Sym.
883 : */
884 :
885 : static void WalkTypesInProcedure (unsigned int sym);
886 :
887 : /*
888 : WalkTypesInModule - declare all types in module, Sym, to GCC.
889 : */
890 :
891 : static void WalkTypesInModule (unsigned int sym);
892 :
893 : /*
894 : IsRecordFieldDependants - returns TRUE if the record field
895 : symbol, sym, p(dependants) all return TRUE.
896 : */
897 :
898 : static bool IsRecordFieldDependants (unsigned int sym, M2GCCDeclare_IsAction q);
899 :
900 : /*
901 : GetModuleWhereDeclared - returns the module where, Sym, was created.
902 : */
903 :
904 : static unsigned int GetModuleWhereDeclared (unsigned int sym);
905 :
906 : /*
907 : IsPseudoProcFunc - returns TRUE if Sym is a pseudo function or procedure.
908 : */
909 :
910 : static bool IsPseudoProcFunc (unsigned int Sym);
911 :
912 : /*
913 : IsExternal -
914 : */
915 :
916 : static bool IsExternal (unsigned int sym);
917 :
918 : /*
919 : IsExternalToWholeProgram - return TRUE if the symbol, sym, is external to the
920 : sources that we have parsed.
921 : */
922 :
923 : static bool IsExternalToWholeProgram (unsigned int sym);
924 :
925 : /*
926 : DeclareProcedureToGccWholeProgram -
927 : */
928 :
929 : static void DeclareProcedureToGccWholeProgram (unsigned int ProcedureSym);
930 :
931 : /*
932 : DeclareProcedureToGccSeparateProgram -
933 : */
934 :
935 : static void DeclareProcedureToGccSeparateProgram (unsigned int ProcedureSym);
936 :
937 : /*
938 : DeclareProcedureToGcc - traverses all parameters and interfaces to gm2gcc.
939 : */
940 :
941 : static void DeclareProcedureToGcc (unsigned int sym);
942 :
943 : /*
944 : ActivateWatch - activate a watch for any symbol (lista xor listb).
945 : */
946 :
947 : static void ActivateWatch (Sets_Set lista, Sets_Set listb);
948 :
949 : /*
950 : DeclareTypesConstantsProceduresInRange -
951 : */
952 :
953 : static void DeclareTypesConstantsProceduresInRange (unsigned int scope, unsigned int start, unsigned int end);
954 :
955 : /*
956 : SkipModuleScope - skips all module scopes for, scope.
957 : It returns either NulSym or a procedure sym.
958 : */
959 :
960 : static unsigned int SkipModuleScope (unsigned int scope);
961 :
962 : /*
963 : PushBinding -
964 : */
965 :
966 : static void PushBinding (unsigned int scope);
967 :
968 : /*
969 : PopBinding -
970 : */
971 :
972 : static void PopBinding (unsigned int scope);
973 :
974 : /*
975 : DeclareTypesConstantsProcedures -
976 : */
977 :
978 : static void DeclareTypesConstantsProcedures (unsigned int scope);
979 :
980 : /*
981 : AssertAllTypesDeclared - asserts that all types for variables are declared in, scope.
982 : */
983 :
984 : static void AssertAllTypesDeclared (unsigned int scope);
985 :
986 : /*
987 : DeclareModuleInit - declare all the ctor related functions within
988 : a module.
989 : */
990 :
991 : static void DeclareModuleInit (unsigned int moduleSym);
992 :
993 : /*
994 : StartDeclareProcedureScope -
995 : */
996 :
997 : static void StartDeclareProcedureScope (unsigned int scope);
998 :
999 : /*
1000 : StartDeclareModuleScopeSeparate -
1001 : */
1002 :
1003 : static void StartDeclareModuleScopeSeparate (unsigned int scope);
1004 :
1005 : /*
1006 : StartDeclareModuleScopeWholeProgram -
1007 : */
1008 :
1009 : static void StartDeclareModuleScopeWholeProgram (unsigned int scope);
1010 :
1011 : /*
1012 : StartDeclareModuleScope -
1013 : */
1014 :
1015 : static void StartDeclareModuleScope (unsigned int scope);
1016 :
1017 : /*
1018 : DumpResolver - dumps the m2 representation of sym.
1019 : */
1020 :
1021 : static void DumpResolver (unsigned int sym);
1022 :
1023 : /*
1024 : DumpDefinitive - dumps the m2 and m2 gimple representation of sym.
1025 : */
1026 :
1027 : static void DumpDefinitive (unsigned int sym);
1028 :
1029 : /*
1030 : PreAddModGcc - adds a relationship between sym and tree.
1031 : */
1032 :
1033 : static void PreAddModGcc (unsigned int sym, tree tree);
1034 :
1035 : /*
1036 : DeclareDefaultType - declares a default type, sym, with, name.
1037 : */
1038 :
1039 : static void DeclareDefaultType (unsigned int sym, const char *name_, unsigned int _name_high, tree gcctype);
1040 :
1041 : /*
1042 : DeclareBoolean - declares the Boolean type together with true and false.
1043 : */
1044 :
1045 : static void DeclareBoolean (void);
1046 :
1047 : /*
1048 : DeclareFixedSizedType - declares the GNU Modula-2 fixed types
1049 : (if the back end support such a type).
1050 : */
1051 :
1052 : static void DeclareFixedSizedType (const char *name_, unsigned int _name_high, unsigned int type, tree t);
1053 :
1054 : /*
1055 : DeclareDefaultSimpleTypes - declares the simple types.
1056 : */
1057 :
1058 : static void DeclareDefaultSimpleTypes (void);
1059 :
1060 : /*
1061 : DeclarePackedBoolean -
1062 : */
1063 :
1064 : static void DeclarePackedBoolean (void);
1065 :
1066 : /*
1067 : DeclarePackedDefaultSimpleTypes -
1068 : */
1069 :
1070 : static void DeclarePackedDefaultSimpleTypes (void);
1071 :
1072 : /*
1073 : DeclareDefaultTypes - makes default types known to GCC
1074 : */
1075 :
1076 : static void DeclareDefaultTypes (void);
1077 :
1078 : /*
1079 : DeclareDefaultConstants - make default constants known to GCC
1080 : */
1081 :
1082 : static void DeclareDefaultConstants (void);
1083 :
1084 : /*
1085 : FindContext - returns the scope where the symbol
1086 : should be created.
1087 :
1088 : Symbols created in a module will
1089 : return the global context tree, but symbols created
1090 : in a module which is declared inside
1091 : a procedure will return the procedure Tree.
1092 : */
1093 :
1094 : static tree FindContext (unsigned int sym);
1095 :
1096 : /*
1097 : IsEffectivelyImported - returns TRUE if symbol, Sym, was
1098 : effectively imported into ModSym.
1099 : */
1100 :
1101 : static bool IsEffectivelyImported (unsigned int ModSym, unsigned int sym);
1102 :
1103 : /*
1104 : FindOuterModule - returns the out most module where, sym,
1105 : was declared. It returns NulSym if the
1106 : symbol or the module was declared inside
1107 : a procedure.
1108 : */
1109 :
1110 : static unsigned int FindOuterModule (unsigned int sym);
1111 :
1112 : /*
1113 : DoVariableDeclaration - create a corresponding gcc variable and add the association
1114 : between the front end symbol var and the gcc tree.
1115 : */
1116 :
1117 : static void DoVariableDeclaration (unsigned int var, void * name, bool isImported, bool isExported, bool isTemporary, bool isGlobal, tree scope);
1118 :
1119 : /*
1120 : TypeDependentsDeclared - return TRUE if all type dependents of variable
1121 : have been declared.
1122 : */
1123 :
1124 : static bool TypeDependentsDeclared (unsigned int variable, bool errorMessage);
1125 :
1126 : /*
1127 : PrepareGCCVarDeclaration -
1128 : */
1129 :
1130 : static void PrepareGCCVarDeclaration (unsigned int var, void * name, bool isImported, bool isExported, bool isTemporary, bool isGlobal, tree scope);
1131 :
1132 : /*
1133 : IsGlobal - is the variable not in a procedure scope.
1134 : */
1135 :
1136 : static bool IsGlobal (unsigned int sym);
1137 :
1138 : /*
1139 : DeclareVariable - declares a global variable to GCC.
1140 : */
1141 :
1142 : static void DeclareVariable (unsigned int ModSym, unsigned int variable);
1143 :
1144 : /*
1145 : DeclareVariableWholeProgram - declares a global variable to GCC when using -fm2-whole-program.
1146 : */
1147 :
1148 : static void DeclareVariableWholeProgram (unsigned int mainModule, unsigned int variable);
1149 :
1150 : /*
1151 : DeclareGlobalVariablesWholeProgram -
1152 : */
1153 :
1154 : static void DeclareGlobalVariablesWholeProgram (unsigned int ModSym);
1155 :
1156 : /*
1157 : DeclareGlobalVariables - lists the Global variables for
1158 : Module ModSym together with their offset.
1159 : */
1160 :
1161 : static void DeclareGlobalVariables (unsigned int ModSym);
1162 :
1163 : /*
1164 : DeclareImportedVariables - declares all imported variables to GM2.
1165 : */
1166 :
1167 : static void DeclareImportedVariables (unsigned int sym);
1168 :
1169 : /*
1170 : DeclareImportedVariablesWholeProgram - declares all imported variables.
1171 : */
1172 :
1173 : static void DeclareImportedVariablesWholeProgram (unsigned int sym);
1174 :
1175 : /*
1176 : DeclareFieldValue -
1177 : */
1178 :
1179 : static tree DeclareFieldValue (unsigned int sym, tree value, tree *list);
1180 :
1181 : /*
1182 : DeclareFieldEnumeration - declares an enumerator within the current enumeration type.
1183 : */
1184 :
1185 : static tree DeclareFieldEnumeration (unsigned int sym);
1186 :
1187 : /*
1188 : DeclareEnumeration - declare an enumerated type.
1189 : */
1190 :
1191 : static tree DeclareEnumeration (unsigned int sym);
1192 :
1193 : /*
1194 : DeclareSubrangeNarrow - will return cardinal, integer, or type depending on whether
1195 : low..high fits in the C data type.
1196 : */
1197 :
1198 : static tree DeclareSubrangeNarrow (location_t location, unsigned int high, unsigned int low, tree type);
1199 :
1200 : /*
1201 : DeclareSubrange - declare a subrange type.
1202 : */
1203 :
1204 : static tree DeclareSubrange (unsigned int sym);
1205 :
1206 : /*
1207 : IncludeGetNth -
1208 : */
1209 :
1210 : static void IncludeGetNth (Lists_List l, unsigned int sym);
1211 :
1212 : /*
1213 : IncludeType -
1214 : */
1215 :
1216 : static void IncludeType (Lists_List l, unsigned int sym);
1217 :
1218 : /*
1219 : IncludeSubscript -
1220 : */
1221 :
1222 : static void IncludeSubscript (Lists_List l, unsigned int sym);
1223 :
1224 : /*
1225 : PrintLocalSymbol -
1226 : */
1227 :
1228 : static void PrintLocalSymbol (unsigned int sym);
1229 :
1230 : /*
1231 : PrintLocalSymbols -
1232 : */
1233 :
1234 : static void PrintLocalSymbols (unsigned int sym);
1235 :
1236 : /*
1237 : IncludeGetVarient -
1238 : */
1239 :
1240 : static void IncludeGetVarient (Lists_List l, unsigned int sym);
1241 :
1242 : /*
1243 : IncludeUnbounded - includes the record component of an unbounded type.
1244 : */
1245 :
1246 : static void IncludeUnbounded (Lists_List l, unsigned int sym);
1247 :
1248 : /*
1249 : IncludePartialUnbounded - includes the type component of a partial unbounded symbol.
1250 : */
1251 :
1252 : static void IncludePartialUnbounded (Lists_List l, unsigned int sym);
1253 :
1254 : /*
1255 : PrintDeclared - prints out where, sym, was declared.
1256 : */
1257 :
1258 : static void PrintDeclared (unsigned int sym);
1259 :
1260 : /*
1261 : PrintAlignment -
1262 : */
1263 :
1264 : static void PrintAlignment (unsigned int sym);
1265 :
1266 : /*
1267 : IncludeGetParent -
1268 : */
1269 :
1270 : static void IncludeGetParent (Lists_List l, unsigned int sym);
1271 :
1272 : /*
1273 : PrintDecl -
1274 : */
1275 :
1276 : static void PrintDecl (unsigned int sym);
1277 :
1278 : /*
1279 : PrintScope - displays the scope and line number of declaration of symbol, sym.
1280 : */
1281 :
1282 : static void PrintScope (unsigned int sym);
1283 :
1284 : /*
1285 : PrintKind -
1286 : */
1287 :
1288 : static void PrintKind (SymbolTable_ProcedureKind kind);
1289 :
1290 : /*
1291 : PrintProcedureParameters -
1292 : */
1293 :
1294 : static void PrintProcedureParameters (unsigned int sym, SymbolTable_ProcedureKind kind);
1295 :
1296 : /*
1297 : PrintProcedureReturnType -
1298 : */
1299 :
1300 : static void PrintProcedureReturnType (unsigned int sym);
1301 :
1302 : /*
1303 : PrintProcedure -
1304 : */
1305 :
1306 : static void PrintProcedure (unsigned int sym);
1307 :
1308 : /*
1309 : PrintProcTypeParameters -
1310 : */
1311 :
1312 : static void PrintProcTypeParameters (unsigned int sym);
1313 :
1314 : /*
1315 : PrintProcType -
1316 : */
1317 :
1318 : static void PrintProcType (unsigned int sym);
1319 :
1320 : /*
1321 : PrintString -
1322 : */
1323 :
1324 : static void PrintString (unsigned int sym);
1325 :
1326 : /*
1327 : PrintVerboseFromList - prints the, i, th element in the list, l.
1328 : */
1329 :
1330 : static void PrintVerboseFromList (Lists_List l, unsigned int i);
1331 :
1332 : /*
1333 : PrintVerbose - prints limited information about a symbol.
1334 : */
1335 :
1336 : static void PrintVerbose (unsigned int sym);
1337 :
1338 : /*
1339 : PrintTerse -
1340 : */
1341 :
1342 : static void PrintTerse (unsigned int sym);
1343 :
1344 : /*
1345 : CheckAlignment -
1346 : */
1347 :
1348 : static tree CheckAlignment (tree type, unsigned int sym);
1349 :
1350 : /*
1351 : CheckPragma -
1352 : */
1353 :
1354 : static tree CheckPragma (tree type, unsigned int sym);
1355 :
1356 : /*
1357 : IsZero - returns TRUE if symbol, sym, is zero.
1358 : */
1359 :
1360 : static bool IsZero (unsigned int sym);
1361 :
1362 : /*
1363 : SetFieldPacked - sets Varient, VarientField and RecordField symbols
1364 : as packed.
1365 : */
1366 :
1367 : static void SetFieldPacked (unsigned int field);
1368 :
1369 : /*
1370 : RecordPacked - indicates that record, sym, and its fields
1371 : are all packed.
1372 : */
1373 :
1374 : static void RecordPacked (unsigned int sym);
1375 :
1376 : /*
1377 : SetFieldNotPacked - sets Varient, VarientField and RecordField symbols
1378 : as not packed.
1379 : */
1380 :
1381 : static void SetFieldNotPacked (unsigned int field);
1382 :
1383 : /*
1384 : RecordNotPacked - indicates that record, sym, and its fields
1385 : are all not packed.
1386 : */
1387 :
1388 : static void RecordNotPacked (unsigned int sym);
1389 :
1390 : /*
1391 : DetermineIfRecordPacked -
1392 : */
1393 :
1394 : static void DetermineIfRecordPacked (unsigned int sym);
1395 :
1396 : /*
1397 : DeclarePackedSubrange -
1398 : */
1399 :
1400 : static void DeclarePackedSubrange (unsigned int equiv, unsigned int sym);
1401 :
1402 : /*
1403 : DeclarePackedSet -
1404 : */
1405 :
1406 : static void DeclarePackedSet (unsigned int equiv, unsigned int sym);
1407 : static void DeclarePackedFieldEnumeration (unsigned int sym);
1408 :
1409 : /*
1410 : DeclarePackedEnumeration -
1411 : */
1412 :
1413 : static void DeclarePackedEnumeration (unsigned int equiv, unsigned int sym);
1414 :
1415 : /*
1416 : DeclarePackedType -
1417 : */
1418 :
1419 : static void DeclarePackedType (unsigned int equiv, unsigned int sym);
1420 :
1421 : /*
1422 : doDeclareEquivalent -
1423 : */
1424 :
1425 : static tree doDeclareEquivalent (unsigned int sym, M2GCCDeclare_doDeclareProcedure p);
1426 :
1427 : /*
1428 : PossiblyPacked -
1429 : */
1430 :
1431 : static tree PossiblyPacked (unsigned int sym, bool isPacked);
1432 :
1433 : /*
1434 : GetPackedType - returns a possibly packed type for field.
1435 : */
1436 :
1437 : static tree GetPackedType (unsigned int sym);
1438 :
1439 : /*
1440 : MaybeAlignField - checks to see whether, field, is packed or aligned and it updates
1441 : the offsets if appropriate.
1442 : */
1443 :
1444 : static tree MaybeAlignField (unsigned int field, tree *byteOffset, tree *bitOffset);
1445 :
1446 : /*
1447 : DeclareRecord - declares a record and its fields to gcc.
1448 : The final gcc record type is returned.
1449 : */
1450 :
1451 : static tree DeclareRecord (unsigned int Sym);
1452 :
1453 : /*
1454 : DeclareRecordField -
1455 : */
1456 :
1457 : static tree DeclareRecordField (unsigned int sym);
1458 :
1459 : /*
1460 : DeclareVarient - declares a record and its fields to gcc.
1461 : The final gcc record type is returned.
1462 : */
1463 :
1464 : static tree DeclareVarient (unsigned int sym);
1465 :
1466 : /*
1467 : DeclareFieldVarient -
1468 : */
1469 :
1470 : static tree DeclareFieldVarient (unsigned int sym);
1471 :
1472 : /*
1473 : DeclarePointer - declares a pointer type to gcc and returns the Tree.
1474 : */
1475 :
1476 : static tree DeclarePointer (unsigned int sym);
1477 :
1478 : /*
1479 : DeclareUnbounded - builds an unbounded type and returns the gcc tree.
1480 : */
1481 :
1482 : static tree DeclareUnbounded (unsigned int sym);
1483 :
1484 : /*
1485 : BuildIndex -
1486 : */
1487 :
1488 : static tree BuildIndex (unsigned int tokenno, unsigned int array, bool isset);
1489 :
1490 : /*
1491 : DeclareArray - declares an array to gcc and returns the gcc tree.
1492 : */
1493 :
1494 : static tree DeclareArray (unsigned int Sym);
1495 :
1496 : /*
1497 : DeclareProcType - declares a procedure type to gcc and returns the gcc type tree.
1498 : */
1499 :
1500 : static tree DeclareProcType (unsigned int Sym);
1501 :
1502 : /*
1503 : FindMinMaxEnum - finds the minimum and maximum enumeration fields.
1504 : */
1505 :
1506 : static void FindMinMaxEnum (unsigned int field);
1507 :
1508 : /*
1509 : PushNoOfBits - pushes the integer value of the number of bits required
1510 : to maintain a set of type.
1511 : */
1512 :
1513 : static void PushNoOfBits (unsigned int type, unsigned int low, unsigned int high);
1514 :
1515 : /*
1516 : DeclareSetArrayOrBitSet - works out whether the set will exceed SIZE (BITSET).
1517 : If it does we manufacture a set using:
1518 :
1519 : settype = ARRAY [0..totalBits DIV SIZE (BITSET)] OF BITSET ;
1520 :
1521 : When GCC supports dwarf5 set types this code should be revised.
1522 : If the set will fit into a WORD then we call gccgm2 directly.
1523 : */
1524 :
1525 : static tree DeclareSetArrayOrBitSet (unsigned int sym, NameKey_Name n, unsigned int type, unsigned int low, unsigned int high);
1526 :
1527 : /*
1528 : DeclareSet - declares a set type to gcc and returns a Tree.
1529 : */
1530 :
1531 : static tree DeclareSet (unsigned int sym);
1532 :
1533 : /*
1534 : CheckResolveSubrange - checks to see whether we can determine
1535 : the subrange type. We are able to do
1536 : this once low, high and the type are known.
1537 : */
1538 :
1539 : static void CheckResolveSubrange (unsigned int sym);
1540 :
1541 : /*
1542 : TypeConstFullyDeclared - all, sym, dependents are declared, so create and
1543 : return the GCC Tree equivalent.
1544 : */
1545 :
1546 : static tree TypeConstFullyDeclared (unsigned int sym);
1547 :
1548 : /*
1549 : IsBaseType - returns true if a type, Sym, is a base type and
1550 : we use predefined GDB information to represent this
1551 : type.
1552 : */
1553 :
1554 : static bool IsBaseType (unsigned int Sym);
1555 :
1556 : /*
1557 : IsFieldEnumerationDependants - sets enumDeps to FALSE if action(Sym)
1558 : is also FALSE.
1559 : */
1560 :
1561 : static void IsFieldEnumerationDependants (unsigned int Sym);
1562 :
1563 : /*
1564 : IsEnumerationDependants - returns true if the enumeration
1565 : p(dependants) all return true.
1566 : */
1567 :
1568 : static bool IsEnumerationDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1569 :
1570 : /*
1571 : WalkEnumerationDependants - returns walks all dependants of Sym.
1572 : */
1573 :
1574 : static void WalkEnumerationDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1575 :
1576 : /*
1577 : WalkSubrangeDependants - calls p(dependants) for each dependant of, sym.
1578 : */
1579 :
1580 : static void WalkSubrangeDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1581 :
1582 : /*
1583 : IsSubrangeDependants - returns TRUE if the subrange
1584 : q(dependants) all return TRUE.
1585 : */
1586 :
1587 : static bool IsSubrangeDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1588 :
1589 : /*
1590 : WalkComponentDependants -
1591 : */
1592 :
1593 : static void WalkComponentDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1594 :
1595 : /*
1596 : IsComponentDependants -
1597 : */
1598 :
1599 : static bool IsComponentDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1600 :
1601 : /*
1602 : WalkVarDependants - walks all dependants of sym.
1603 : */
1604 :
1605 : static void WalkVarDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1606 :
1607 : /*
1608 : IsVarDependants - returns TRUE if the pointer symbol, sym,
1609 : p(dependants) all return TRUE.
1610 : */
1611 :
1612 : static bool IsVarDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1613 :
1614 : /*
1615 : WalkPointerDependants - walks all dependants of sym.
1616 : */
1617 :
1618 : static void WalkPointerDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1619 :
1620 : /*
1621 : IsPointerDependants - returns TRUE if the pointer symbol, sym,
1622 : p(dependants) all return TRUE.
1623 : */
1624 :
1625 : static bool IsPointerDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1626 :
1627 : /*
1628 : IsRecordAlignment -
1629 : */
1630 :
1631 : static bool IsRecordAlignment (unsigned int sym, M2GCCDeclare_IsAction q);
1632 :
1633 : /*
1634 : IsRecordDependants - returns TRUE if the symbol, sym,
1635 : q(dependants) all return TRUE.
1636 : */
1637 :
1638 : static bool IsRecordDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1639 :
1640 : /*
1641 : WalkRecordAlignment - walks the alignment constant associated with
1642 : record, sym.
1643 : */
1644 :
1645 : static void WalkRecordAlignment (unsigned int sym, M2GCCDeclare_WalkAction p);
1646 :
1647 : /*
1648 : WalkRecordDependants - walks symbol, sym, dependants. It only
1649 : walks the fields if the alignment is
1650 : unused or fully declared.
1651 : */
1652 :
1653 : static void WalkRecordDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1654 :
1655 : /*
1656 : WalkRecordFieldDependants -
1657 : */
1658 :
1659 : static void WalkRecordFieldDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1660 :
1661 : /*
1662 : WalkRecordDependants2 - walks the fields of record, sym, calling
1663 : p on every dependant.
1664 : */
1665 :
1666 : static void WalkRecordDependants2 (unsigned int sym, M2GCCDeclare_WalkAction p);
1667 :
1668 : /*
1669 : IsVarientAlignment -
1670 : */
1671 :
1672 : static bool IsVarientAlignment (unsigned int sym, M2GCCDeclare_IsAction q);
1673 :
1674 : /*
1675 : IsVarientDependants - returns TRUE if the symbol, sym,
1676 : q(dependants) all return TRUE.
1677 : */
1678 :
1679 : static bool IsVarientDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1680 :
1681 : /*
1682 : WalkVarientAlignment -
1683 : */
1684 :
1685 : static void WalkVarientAlignment (unsigned int sym, M2GCCDeclare_WalkAction p);
1686 :
1687 : /*
1688 : WalkVarientDependants - walks symbol, sym, dependants.
1689 : */
1690 :
1691 : static void WalkVarientDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1692 :
1693 : /*
1694 : IsVarientFieldDependants - returns TRUE if the symbol, sym,
1695 : q(dependants) all return TRUE.
1696 : */
1697 :
1698 : static bool IsVarientFieldDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1699 :
1700 : /*
1701 : WalkVarientFieldDependants -
1702 : */
1703 :
1704 : static void WalkVarientFieldDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1705 :
1706 : /*
1707 : IsArrayDependants - returns TRUE if the symbol, sym,
1708 : q(dependants) all return TRUE.
1709 :
1710 : */
1711 :
1712 : static bool IsArrayDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1713 :
1714 : /*
1715 : WalkArrayDependants - walks symbol, sym, dependants.
1716 : */
1717 :
1718 : static void WalkArrayDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1719 :
1720 : /*
1721 : DeclareSetArray -
1722 : */
1723 :
1724 : static unsigned int DeclareSetArray (unsigned int sym, unsigned int low, unsigned int high);
1725 :
1726 : /*
1727 : IsSetDependants - returns TRUE if the symbol, sym,
1728 : q(dependants) all return TRUE.
1729 : */
1730 :
1731 : static bool IsSetDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1732 :
1733 : /*
1734 : WalkSetDependants - walks dependants, sym.
1735 : */
1736 :
1737 : static void WalkSetDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1738 :
1739 : /*
1740 : IsProcTypeDependants -
1741 : */
1742 :
1743 : static bool IsProcTypeDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1744 :
1745 : /*
1746 : WalkProcTypeDependants - walks dependants, sym.
1747 : */
1748 :
1749 : static void WalkProcTypeDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1750 :
1751 : /*
1752 : IsProcedureDependants -
1753 : */
1754 :
1755 : static bool IsProcedureDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1756 :
1757 : /*
1758 : WalkProcedureDependants - walks dependants, sym.
1759 : */
1760 :
1761 : static void WalkProcedureDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1762 :
1763 : /*
1764 : IsUnboundedDependants - returns TRUE if the symbol, sym,
1765 : q (dependants) all return TRUE.
1766 : */
1767 :
1768 : static bool IsUnboundedDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1769 :
1770 : /*
1771 : WalkUnboundedDependants - walks the dependants of, sym.
1772 : */
1773 :
1774 : static void WalkUnboundedDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1775 :
1776 : /*
1777 : IsTypeDependants - returns TRUE if all q(dependants) return
1778 : TRUE.
1779 : */
1780 :
1781 : static bool IsTypeDependants (unsigned int sym, M2GCCDeclare_IsAction q);
1782 :
1783 : /*
1784 : WalkTypeDependants - walks all dependants of, sym.
1785 : */
1786 :
1787 : static void WalkTypeDependants (unsigned int sym, M2GCCDeclare_WalkAction p);
1788 :
1789 :
1790 : /*
1791 : PrintNum -
1792 : */
1793 :
1794 0 : static void PrintNum (unsigned int sym)
1795 : {
1796 0 : M2Printf_printf1 ((const char *) "%d, ", 4, (const unsigned char *) &sym, (sizeof (sym)-1));
1797 0 : }
1798 :
1799 :
1800 : /*
1801 : DebugSet -
1802 : */
1803 :
1804 0 : static void DebugSet (const char *a_, unsigned int _a_high, Sets_Set l)
1805 : {
1806 0 : char a[_a_high+1];
1807 :
1808 : /* make a local copy of each unbounded array. */
1809 0 : memcpy (a, a_, _a_high+1);
1810 :
1811 0 : M2Printf_printf0 ((const char *) a, _a_high);
1812 0 : M2Printf_printf0 ((const char *) " {", 2);
1813 0 : Sets_ForeachElementInSetDo (l, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) PrintNum});
1814 0 : M2Printf_printf0 ((const char *) "}\\n", 3);
1815 0 : }
1816 :
1817 :
1818 : /*
1819 : DebugSets -
1820 : */
1821 :
1822 0 : static void DebugSets (void)
1823 : {
1824 0 : DebugSet ((const char *) "ToDoList", 8, GlobalGroup->ToDoList);
1825 0 : DebugSet ((const char *) "HeldByAlignment", 15, GlobalGroup->HeldByAlignment);
1826 0 : DebugSet ((const char *) "FinishedAlignment", 17, GlobalGroup->FinishedAlignment);
1827 0 : DebugSet ((const char *) "PartiallyDeclared", 17, GlobalGroup->PartiallyDeclared);
1828 0 : DebugSet ((const char *) "FullyDeclared", 13, GlobalGroup->FullyDeclared);
1829 0 : DebugSet ((const char *) "NilTypedArrays", 14, GlobalGroup->NilTypedArrays);
1830 0 : DebugSet ((const char *) "ToBeSolvedByQuads", 17, GlobalGroup->ToBeSolvedByQuads);
1831 0 : DebugSet ((const char *) "FinishedSetArray", 16, GlobalGroup->FinishedSetArray);
1832 0 : }
1833 :
1834 :
1835 : /*
1836 : DebugNumber -
1837 : */
1838 :
1839 0 : static void DebugNumber (const char *a_, unsigned int _a_high, Sets_Set s)
1840 : {
1841 0 : unsigned int n;
1842 0 : char a[_a_high+1];
1843 :
1844 : /* make a local copy of each unbounded array. */
1845 0 : memcpy (a, a_, _a_high+1);
1846 :
1847 0 : n = Sets_NoOfElementsInSet (s);
1848 0 : M2Printf_printf1 ((const char *) a, _a_high, (const unsigned char *) &n, (sizeof (n)-1));
1849 0 : FIO_FlushBuffer (FIO_StdOut);
1850 0 : }
1851 :
1852 0 : static void DebugSetNumbers (void)
1853 : {
1854 : /*
1855 : DebugSets -
1856 : */
1857 0 : DebugNumber ((const char *) "ToDoList : %d\\n", 15, GlobalGroup->ToDoList);
1858 0 : DebugNumber ((const char *) "HeldByAlignment : %d\\n", 22, GlobalGroup->HeldByAlignment);
1859 0 : DebugNumber ((const char *) "PartiallyDeclared : %d\\n", 24, GlobalGroup->PartiallyDeclared);
1860 0 : DebugNumber ((const char *) "FullyDeclared : %d\\n", 20, GlobalGroup->FullyDeclared);
1861 0 : DebugNumber ((const char *) "NilTypedArrays : %d\\n", 21, GlobalGroup->NilTypedArrays);
1862 0 : DebugNumber ((const char *) "ToBeSolvedByQuads : %d\\n", 24, GlobalGroup->ToBeSolvedByQuads);
1863 0 : DebugNumber ((const char *) "FinishedSetArray : %d\\n", 23, GlobalGroup->FinishedSetArray);
1864 0 : }
1865 :
1866 :
1867 : /*
1868 : AddSymToWatch - adds symbol, sym, to the list of symbols
1869 : to watch and annotate their movement between
1870 : lists.
1871 : */
1872 :
1873 0 : static void AddSymToWatch (unsigned int sym)
1874 : {
1875 0 : if ((sym != SymbolTable_NulSym) && (! (Sets_IsElementInSet (WatchList, sym))))
1876 : {
1877 0 : Sets_IncludeElementIntoSet (WatchList, sym);
1878 0 : WalkDependants (sym, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) AddSymToWatch});
1879 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) "%d, ", 4, (const unsigned char *) &sym, (sizeof (sym)-1));
1880 : }
1881 0 : }
1882 :
1883 :
1884 : /*
1885 : doInclude -
1886 : */
1887 :
1888 0 : static void doInclude (Sets_Set l, const char *a_, unsigned int _a_high, unsigned int sym)
1889 : {
1890 0 : char a[_a_high+1];
1891 :
1892 : /* make a local copy of each unbounded array. */
1893 0 : memcpy (a, a_, _a_high+1);
1894 :
1895 0 : if (! (Sets_IsElementInSet (l, sym)))
1896 : {
1897 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "rule: ", 6);
1898 0 : WriteRule ();
1899 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " ", 2);
1900 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) a, _a_high, (const unsigned char *) &sym, (sizeof (sym)-1));
1901 0 : Sets_IncludeElementIntoSet (l, sym);
1902 : }
1903 0 : }
1904 :
1905 :
1906 : /*
1907 : WatchIncludeList - include a symbol onto the set first checking
1908 : whether it is already on the set and
1909 : displaying a debug message if the set is
1910 : changed.
1911 : */
1912 :
1913 19977561 : static void WatchIncludeList (unsigned int sym, M2GCCDeclare_ListType lt)
1914 : {
1915 19977561 : if (Sets_IsElementInSet (WatchList, sym))
1916 : {
1917 0 : switch (lt)
1918 : {
1919 0 : case M2GCCDeclare_tobesolvedbyquads:
1920 0 : doInclude (GlobalGroup->ToBeSolvedByQuads, (const char *) "symbol %d -> ToBeSolvedByQuads\\n", 32, sym);
1921 0 : break;
1922 :
1923 0 : case M2GCCDeclare_fullydeclared:
1924 0 : doInclude (GlobalGroup->FullyDeclared, (const char *) "symbol %d -> FullyDeclared\\n", 28, sym);
1925 0 : break;
1926 :
1927 0 : case M2GCCDeclare_partiallydeclared:
1928 0 : doInclude (GlobalGroup->PartiallyDeclared, (const char *) "symbol %d -> PartiallyDeclared\\n", 32, sym);
1929 0 : break;
1930 :
1931 0 : case M2GCCDeclare_heldbyalignment:
1932 0 : doInclude (GlobalGroup->HeldByAlignment, (const char *) "symbol %d -> HeldByAlignment\\n", 30, sym);
1933 0 : break;
1934 :
1935 0 : case M2GCCDeclare_finishedalignment:
1936 0 : doInclude (GlobalGroup->FinishedAlignment, (const char *) "symbol %d -> FinishedAlignment\\n", 32, sym);
1937 0 : break;
1938 :
1939 0 : case M2GCCDeclare_todolist:
1940 0 : doInclude (GlobalGroup->ToDoList, (const char *) "symbol %d -> ToDoList\\n", 23, sym);
1941 0 : break;
1942 :
1943 0 : case M2GCCDeclare_niltypedarrays:
1944 0 : doInclude (GlobalGroup->NilTypedArrays, (const char *) "symbol %d -> NilTypedArrays\\n", 29, sym);
1945 0 : break;
1946 :
1947 0 : case M2GCCDeclare_finishedsetarray:
1948 0 : doInclude (GlobalGroup->FinishedSetArray, (const char *) "symbol %d -> FinishedSetArray\\n", 31, sym);
1949 0 : break;
1950 :
1951 :
1952 0 : default:
1953 0 : M2Error_InternalError ((const char *) "unknown list", 12);
1954 : break;
1955 : }
1956 : }
1957 : else
1958 : {
1959 19977561 : switch (lt)
1960 : {
1961 362084 : case M2GCCDeclare_tobesolvedbyquads:
1962 362084 : Sets_IncludeElementIntoSet (GlobalGroup->ToBeSolvedByQuads, sym);
1963 362084 : break;
1964 :
1965 15034472 : case M2GCCDeclare_fullydeclared:
1966 15034472 : Sets_IncludeElementIntoSet (GlobalGroup->FullyDeclared, sym);
1967 15034472 : break;
1968 :
1969 173405 : case M2GCCDeclare_partiallydeclared:
1970 173405 : Sets_IncludeElementIntoSet (GlobalGroup->PartiallyDeclared, sym);
1971 173405 : break;
1972 :
1973 108431 : case M2GCCDeclare_heldbyalignment:
1974 108431 : Sets_IncludeElementIntoSet (GlobalGroup->HeldByAlignment, sym);
1975 108431 : break;
1976 :
1977 542140 : case M2GCCDeclare_finishedalignment:
1978 542140 : Sets_IncludeElementIntoSet (GlobalGroup->FinishedAlignment, sym);
1979 542140 : break;
1980 :
1981 3744761 : case M2GCCDeclare_todolist:
1982 3744761 : Sets_IncludeElementIntoSet (GlobalGroup->ToDoList, sym);
1983 3744761 : break;
1984 :
1985 7604 : case M2GCCDeclare_niltypedarrays:
1986 7604 : Sets_IncludeElementIntoSet (GlobalGroup->NilTypedArrays, sym);
1987 7604 : break;
1988 :
1989 4664 : case M2GCCDeclare_finishedsetarray:
1990 4664 : Sets_IncludeElementIntoSet (GlobalGroup->FinishedSetArray, sym);
1991 4664 : break;
1992 :
1993 :
1994 0 : default:
1995 0 : M2Error_InternalError ((const char *) "unknown list", 12);
1996 19977561 : break;
1997 : }
1998 : }
1999 19977561 : }
2000 :
2001 :
2002 : /*
2003 : doExclude -
2004 : */
2005 :
2006 0 : static void doExclude (Sets_Set l, const char *a_, unsigned int _a_high, unsigned int sym)
2007 : {
2008 0 : char a[_a_high+1];
2009 :
2010 : /* make a local copy of each unbounded array. */
2011 0 : memcpy (a, a_, _a_high+1);
2012 :
2013 0 : if (Sets_IsElementInSet (l, sym))
2014 : {
2015 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "rule: ", 6);
2016 0 : WriteRule ();
2017 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " ", 2);
2018 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) a, _a_high, (const unsigned char *) &sym, (sizeof (sym)-1));
2019 0 : Sets_ExcludeElementFromSet (l, sym);
2020 : }
2021 0 : }
2022 :
2023 :
2024 : /*
2025 : WatchRemoveList - remove a symbol onto the list first checking
2026 : whether it is already on the list and
2027 : displaying a debug message if the list is
2028 : changed.
2029 : */
2030 :
2031 24038928 : static void WatchRemoveList (unsigned int sym, M2GCCDeclare_ListType lt)
2032 : {
2033 24038928 : if (Sets_IsElementInSet (WatchList, sym))
2034 : {
2035 0 : switch (lt)
2036 : {
2037 0 : case M2GCCDeclare_tobesolvedbyquads:
2038 0 : doExclude (GlobalGroup->ToBeSolvedByQuads, (const char *) "symbol %d off ToBeSolvedByQuads\\n", 33, sym);
2039 0 : break;
2040 :
2041 0 : case M2GCCDeclare_fullydeclared:
2042 0 : doExclude (GlobalGroup->FullyDeclared, (const char *) "symbol %d off FullyDeclared\\n", 29, sym);
2043 0 : break;
2044 :
2045 0 : case M2GCCDeclare_partiallydeclared:
2046 0 : doExclude (GlobalGroup->PartiallyDeclared, (const char *) "symbol %d off PartiallyDeclared\\n", 33, sym);
2047 0 : break;
2048 :
2049 0 : case M2GCCDeclare_heldbyalignment:
2050 0 : doExclude (GlobalGroup->HeldByAlignment, (const char *) "symbol %d -> HeldByAlignment\\n", 30, sym);
2051 0 : break;
2052 :
2053 0 : case M2GCCDeclare_finishedalignment:
2054 0 : doExclude (GlobalGroup->FinishedAlignment, (const char *) "symbol %d -> FinishedAlignment\\n", 32, sym);
2055 0 : break;
2056 :
2057 0 : case M2GCCDeclare_todolist:
2058 0 : doExclude (GlobalGroup->ToDoList, (const char *) "symbol %d off ToDoList\\n", 24, sym);
2059 0 : break;
2060 :
2061 0 : case M2GCCDeclare_niltypedarrays:
2062 0 : doExclude (GlobalGroup->NilTypedArrays, (const char *) "symbol %d off NilTypedArrays\\n", 30, sym);
2063 0 : break;
2064 :
2065 0 : case M2GCCDeclare_finishedsetarray:
2066 0 : doExclude (GlobalGroup->FinishedSetArray, (const char *) "symbol %d off FinishedSetArray\\n", 32, sym);
2067 0 : break;
2068 :
2069 :
2070 0 : default:
2071 0 : M2Error_InternalError ((const char *) "unknown list", 12);
2072 : break;
2073 : }
2074 : }
2075 : else
2076 : {
2077 24038928 : switch (lt)
2078 : {
2079 510049 : case M2GCCDeclare_tobesolvedbyquads:
2080 510049 : Sets_ExcludeElementFromSet (GlobalGroup->ToBeSolvedByQuads, sym);
2081 510049 : break;
2082 :
2083 0 : case M2GCCDeclare_fullydeclared:
2084 0 : Sets_ExcludeElementFromSet (GlobalGroup->FullyDeclared, sym);
2085 0 : break;
2086 :
2087 2417971 : case M2GCCDeclare_partiallydeclared:
2088 2417971 : Sets_ExcludeElementFromSet (GlobalGroup->PartiallyDeclared, sym);
2089 2417971 : break;
2090 :
2091 2174327 : case M2GCCDeclare_heldbyalignment:
2092 2174327 : Sets_ExcludeElementFromSet (GlobalGroup->HeldByAlignment, sym);
2093 2174327 : break;
2094 :
2095 2056944 : case M2GCCDeclare_finishedalignment:
2096 2056944 : Sets_ExcludeElementFromSet (GlobalGroup->FinishedAlignment, sym);
2097 2056944 : break;
2098 :
2099 16862753 : case M2GCCDeclare_todolist:
2100 16862753 : Sets_ExcludeElementFromSet (GlobalGroup->ToDoList, sym);
2101 16862753 : break;
2102 :
2103 7556 : case M2GCCDeclare_niltypedarrays:
2104 7556 : Sets_ExcludeElementFromSet (GlobalGroup->NilTypedArrays, sym);
2105 7556 : break;
2106 :
2107 9328 : case M2GCCDeclare_finishedsetarray:
2108 9328 : Sets_ExcludeElementFromSet (GlobalGroup->FinishedSetArray, sym);
2109 9328 : break;
2110 :
2111 :
2112 0 : default:
2113 0 : M2Error_InternalError ((const char *) "unknown list", 12);
2114 24038928 : break;
2115 : }
2116 : }
2117 24038928 : }
2118 :
2119 :
2120 : /*
2121 : NewGroup -
2122 : */
2123 :
2124 1883557 : static void NewGroup (M2GCCDeclare_Group *g)
2125 : {
2126 1883557 : if (FreeGroup == NULL)
2127 : {
2128 56730 : Storage_ALLOCATE ((void **) &(*g), sizeof (M2GCCDeclare__T1));
2129 : }
2130 : else
2131 : {
2132 1826827 : (*g) = FreeGroup;
2133 1826827 : FreeGroup = FreeGroup->Next;
2134 : }
2135 1883557 : }
2136 :
2137 :
2138 : /*
2139 : DisposeGroup -
2140 : */
2141 :
2142 1868521 : static void DisposeGroup (M2GCCDeclare_Group *g)
2143 : {
2144 1868521 : (*g)->Next = FreeGroup;
2145 1868521 : FreeGroup = (*g);
2146 1868521 : (*g) = NULL;
2147 1868521 : }
2148 :
2149 :
2150 : /*
2151 : InitGroup - initialize all sets in group and return the group.
2152 : */
2153 :
2154 14952 : static M2GCCDeclare_Group InitGroup (void)
2155 : {
2156 14952 : M2GCCDeclare_Group g;
2157 :
2158 14952 : NewGroup (&g);
2159 : /* Initialize all sets in group. */
2160 14952 : g->FinishedSetArray = Sets_InitSet (1);
2161 14952 : g->ToDoList = Sets_InitSet (1);
2162 14952 : g->FullyDeclared = Sets_InitSet (1);
2163 14952 : g->PartiallyDeclared = Sets_InitSet (1);
2164 14952 : g->NilTypedArrays = Sets_InitSet (1);
2165 14952 : g->HeldByAlignment = Sets_InitSet (1);
2166 14952 : g->FinishedAlignment = Sets_InitSet (1);
2167 14952 : g->ToBeSolvedByQuads = Sets_InitSet (1);
2168 14952 : g->Next = NULL;
2169 14952 : return g;
2170 : /* static analysis guarentees a RETURN statement will be used before here. */
2171 : __builtin_unreachable ();
2172 : }
2173 :
2174 :
2175 : /*
2176 : KillGroup - delete all sets in group and deallocate g.
2177 : */
2178 :
2179 1868521 : static void KillGroup (M2GCCDeclare_Group *g)
2180 : {
2181 : /* Delete all sets in group. */
2182 1868521 : if ((*g) != NULL)
2183 : {
2184 1868521 : (*g)->FinishedSetArray = Sets_KillSet ((*g)->FinishedSetArray);
2185 1868521 : (*g)->ToDoList = Sets_KillSet ((*g)->ToDoList);
2186 1868521 : (*g)->FullyDeclared = Sets_KillSet ((*g)->FullyDeclared);
2187 1868521 : (*g)->PartiallyDeclared = Sets_KillSet ((*g)->PartiallyDeclared);
2188 1868521 : (*g)->NilTypedArrays = Sets_KillSet ((*g)->NilTypedArrays);
2189 1868521 : (*g)->HeldByAlignment = Sets_KillSet ((*g)->HeldByAlignment);
2190 1868521 : (*g)->FinishedAlignment = Sets_KillSet ((*g)->FinishedAlignment);
2191 1868521 : (*g)->ToBeSolvedByQuads = Sets_KillSet ((*g)->ToBeSolvedByQuads);
2192 1868521 : (*g)->Next = NULL;
2193 1868521 : DisposeGroup (g);
2194 : }
2195 1868521 : }
2196 :
2197 :
2198 : /*
2199 : DupGroup - If g is not NIL then destroy g.
2200 : Return a duplicate of GlobalGroup.
2201 : */
2202 :
2203 1868605 : static M2GCCDeclare_Group DupGroup (M2GCCDeclare_Group g)
2204 : {
2205 1868605 : if (g != NULL)
2206 : {
2207 : /* Kill old group. */
2208 162174 : KillGroup (&g);
2209 : }
2210 1868605 : NewGroup (&g);
2211 : /* Copy all sets. */
2212 1868605 : g->FinishedSetArray = Sets_DuplicateSet (GlobalGroup->FinishedSetArray);
2213 1868605 : g->ToDoList = Sets_DuplicateSet (GlobalGroup->ToDoList);
2214 1868605 : g->FullyDeclared = Sets_DuplicateSet (GlobalGroup->FullyDeclared);
2215 1868605 : g->PartiallyDeclared = Sets_DuplicateSet (GlobalGroup->PartiallyDeclared);
2216 1868605 : g->NilTypedArrays = Sets_DuplicateSet (GlobalGroup->NilTypedArrays);
2217 1868605 : g->HeldByAlignment = Sets_DuplicateSet (GlobalGroup->HeldByAlignment);
2218 1868605 : g->FinishedAlignment = Sets_DuplicateSet (GlobalGroup->FinishedAlignment);
2219 1868605 : g->ToBeSolvedByQuads = Sets_DuplicateSet (GlobalGroup->ToBeSolvedByQuads);
2220 1868605 : g->Next = NULL;
2221 1868605 : return g;
2222 : /* static analysis guarentees a RETURN statement will be used before here. */
2223 : __builtin_unreachable ();
2224 : }
2225 :
2226 :
2227 : /*
2228 : EqualGroup - return TRUE if group left = right.
2229 : */
2230 :
2231 921634 : static bool EqualGroup (M2GCCDeclare_Group left, M2GCCDeclare_Group right)
2232 : {
2233 921634 : return (left == right) || ((((((((Sets_EqualSet (left->FullyDeclared, right->FullyDeclared)) && (Sets_EqualSet (left->PartiallyDeclared, right->PartiallyDeclared))) && (Sets_EqualSet (left->NilTypedArrays, right->NilTypedArrays))) && (Sets_EqualSet (left->HeldByAlignment, right->HeldByAlignment))) && (Sets_EqualSet (left->FinishedAlignment, right->FinishedAlignment))) && (Sets_EqualSet (left->ToDoList, right->ToDoList))) && (Sets_EqualSet (left->ToBeSolvedByQuads, right->ToBeSolvedByQuads))) && (Sets_EqualSet (left->FinishedSetArray, right->FinishedSetArray)));
2234 : /* static analysis guarentees a RETURN statement will be used before here. */
2235 : __builtin_unreachable ();
2236 : }
2237 :
2238 :
2239 : /*
2240 : LookupSet -
2241 : */
2242 :
2243 13850700 : static Sets_Set LookupSet (M2GCCDeclare_ListType listtype)
2244 : {
2245 13850700 : switch (listtype)
2246 : {
2247 0 : case M2GCCDeclare_fullydeclared:
2248 0 : return GlobalGroup->FullyDeclared;
2249 1659304 : break;
2250 :
2251 1659304 : case M2GCCDeclare_partiallydeclared:
2252 1659304 : return GlobalGroup->PartiallyDeclared;
2253 1846696 : break;
2254 :
2255 1846696 : case M2GCCDeclare_niltypedarrays:
2256 1846696 : return GlobalGroup->NilTypedArrays;
2257 1035300 : break;
2258 :
2259 1035300 : case M2GCCDeclare_heldbyalignment:
2260 1035300 : return GlobalGroup->HeldByAlignment;
2261 1021780 : break;
2262 :
2263 1021780 : case M2GCCDeclare_finishedalignment:
2264 1021780 : return GlobalGroup->FinishedAlignment;
2265 7351829 : break;
2266 :
2267 7351829 : case M2GCCDeclare_todolist:
2268 7351829 : return GlobalGroup->ToDoList;
2269 0 : break;
2270 :
2271 0 : case M2GCCDeclare_tobesolvedbyquads:
2272 0 : return GlobalGroup->ToBeSolvedByQuads;
2273 935791 : break;
2274 :
2275 935791 : case M2GCCDeclare_finishedsetarray:
2276 935791 : return GlobalGroup->FinishedSetArray;
2277 0 : break;
2278 :
2279 :
2280 0 : default:
2281 0 : M2Error_InternalError ((const char *) "unknown ListType", 16);
2282 : break;
2283 : }
2284 : return static_cast<Sets_Set> (NULL);
2285 : /* static analysis guarentees a RETURN statement will be used before here. */
2286 : __builtin_unreachable ();
2287 : }
2288 :
2289 :
2290 : /*
2291 : GetEnumList -
2292 : */
2293 :
2294 497038 : static tree GetEnumList (unsigned int sym)
2295 : {
2296 497038 : if (Indexing_InBounds (EnumerationIndex, sym))
2297 : {
2298 469300 : return (tree) (Indexing_GetIndice (EnumerationIndex, sym));
2299 : }
2300 : else
2301 : {
2302 : return NULL;
2303 : }
2304 : /* static analysis guarentees a RETURN statement will be used before here. */
2305 : __builtin_unreachable ();
2306 : }
2307 :
2308 :
2309 : /*
2310 : PutEnumList -
2311 : */
2312 :
2313 462948 : static void PutEnumList (unsigned int sym, tree enumlist)
2314 : {
2315 0 : Indexing_PutIndice (EnumerationIndex, sym, enumlist);
2316 0 : }
2317 :
2318 :
2319 : /*
2320 : Chained - checks to see that, sym, has not already been placed on a chain.
2321 : It returns the symbol, sym.
2322 : */
2323 :
2324 411218 : static unsigned int Chained (unsigned int sym)
2325 : {
2326 411218 : if (Sets_IsElementInSet (ChainedList, sym))
2327 : {
2328 0 : M2Error_InternalError ((const char *) "symbol has already been chained onto a previous list", 52);
2329 : }
2330 411218 : Sets_IncludeElementIntoSet (ChainedList, sym);
2331 411218 : return sym;
2332 : /* static analysis guarentees a RETURN statement will be used before here. */
2333 : __builtin_unreachable ();
2334 : }
2335 :
2336 :
2337 : /*
2338 : DoStartDeclaration - returns a tree representing a symbol which has
2339 : not yet been finished. Used when declaring
2340 : recursive types.
2341 : */
2342 :
2343 331842 : static tree DoStartDeclaration (unsigned int sym, M2GCCDeclare_StartProcedure p)
2344 : {
2345 331842 : location_t location;
2346 :
2347 331842 : if (! (SymbolConversion_GccKnowsAbout (sym)))
2348 : {
2349 165921 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
2350 165921 : PreAddModGcc (sym, (tree) ((*p.proc) (location, NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (sym)))));
2351 : }
2352 331842 : return SymbolConversion_Mod2Gcc (sym);
2353 : /* static analysis guarentees a RETURN statement will be used before here. */
2354 : __builtin_unreachable ();
2355 : }
2356 :
2357 :
2358 : /*
2359 : ArrayComponentsDeclared - returns TRUE if array, sym,
2360 : subscripts and type are known.
2361 : */
2362 :
2363 395404 : static bool ArrayComponentsDeclared (unsigned int sym)
2364 : {
2365 395404 : unsigned int Subscript;
2366 395404 : unsigned int Type;
2367 395404 : unsigned int High;
2368 395404 : unsigned int Low;
2369 :
2370 395404 : Subscript = SymbolTable_GetArraySubscript (sym);
2371 395404 : M2Debug_Assert (SymbolTable_IsSubscript (Subscript));
2372 395404 : Type = SymbolTable_GetDType (Subscript);
2373 395404 : Low = M2GCCDeclare_GetTypeMin (Type);
2374 395404 : High = M2GCCDeclare_GetTypeMax (Type);
2375 410474 : return ((IsFullyDeclared (Type)) && (IsFullyDeclared (Low))) && (IsFullyDeclared (High));
2376 : /* static analysis guarentees a RETURN statement will be used before here. */
2377 : __builtin_unreachable ();
2378 : }
2379 :
2380 :
2381 : /*
2382 : GetRecordOfVarient -
2383 : */
2384 :
2385 2395119 : static unsigned int GetRecordOfVarient (unsigned int sym)
2386 : {
2387 2395119 : if ((SymbolTable_IsVarient (sym)) || (SymbolTable_IsFieldVarient (sym)))
2388 : {
2389 2297170 : do {
2390 2297170 : sym = SymbolTable_GetParent (sym);
2391 2297170 : } while (! (SymbolTable_IsRecord (sym)));
2392 : }
2393 2395119 : return sym;
2394 : /* static analysis guarentees a RETURN statement will be used before here. */
2395 : __builtin_unreachable ();
2396 : }
2397 :
2398 :
2399 : /*
2400 : CanDeclareRecordKind -
2401 : */
2402 :
2403 108431 : static bool CanDeclareRecordKind (unsigned int sym)
2404 : {
2405 108431 : sym = GetRecordOfVarient (sym);
2406 108467 : return (SymbolTable_IsRecord (sym)) && (((SymbolTable_GetDefaultRecordFieldAlignment (sym)) == SymbolTable_NulSym) || (IsFullyDeclared (SymbolTable_GetDefaultRecordFieldAlignment (sym))));
2407 : /* static analysis guarentees a RETURN statement will be used before here. */
2408 : __builtin_unreachable ();
2409 : }
2410 :
2411 :
2412 : /*
2413 : DeclareRecordKind - works out whether record, sym, is packed or not.
2414 : */
2415 :
2416 108431 : static void DeclareRecordKind (unsigned int sym)
2417 : {
2418 108431 : if (SymbolTable_IsRecord (sym))
2419 : {
2420 99353 : DetermineIfRecordPacked (sym);
2421 : }
2422 108431 : WatchIncludeList (sym, M2GCCDeclare_todolist);
2423 108431 : WatchRemoveList (sym, M2GCCDeclare_heldbyalignment);
2424 108431 : WatchIncludeList (sym, M2GCCDeclare_finishedalignment);
2425 216862 : if (AllDependantsFullyDeclared (sym))
2426 : {} /* empty. */
2427 : /* All good and ready to be solved. */
2428 108431 : }
2429 :
2430 :
2431 : /*
2432 : CanDeclareRecord -
2433 : */
2434 :
2435 533188 : static bool CanDeclareRecord (unsigned int sym)
2436 : {
2437 533188 : TraverseDependants (sym);
2438 533188 : if (AllDependantsFullyDeclared (sym))
2439 : {
2440 : return true;
2441 : }
2442 : else
2443 : {
2444 433709 : WatchIncludeList (sym, M2GCCDeclare_finishedalignment);
2445 433709 : return false;
2446 : }
2447 : /* static analysis guarentees a RETURN statement will be used before here. */
2448 : __builtin_unreachable ();
2449 : }
2450 :
2451 :
2452 : /*
2453 : FinishDeclareRecord -
2454 : */
2455 :
2456 99479 : static void FinishDeclareRecord (unsigned int sym)
2457 : {
2458 99479 : DeclareTypeConstFully (sym);
2459 99479 : WatchRemoveList (sym, M2GCCDeclare_heldbyalignment);
2460 99479 : WatchRemoveList (sym, M2GCCDeclare_finishedalignment);
2461 99479 : WatchRemoveList (sym, M2GCCDeclare_todolist);
2462 99479 : WatchIncludeList (sym, M2GCCDeclare_fullydeclared);
2463 99479 : }
2464 :
2465 :
2466 : /*
2467 : CanDeclareTypePartially - return TRUE if we are able to make a
2468 : gcc partially created type.
2469 : */
2470 :
2471 26414507 : static bool CanDeclareTypePartially (unsigned int sym)
2472 : {
2473 26414507 : unsigned int type;
2474 :
2475 26414507 : if (Sets_IsElementInSet (GlobalGroup->PartiallyDeclared, sym))
2476 : {
2477 : return false;
2478 : }
2479 25481335 : else if ((((SymbolTable_IsProcType (sym)) || (SymbolTable_IsRecord (sym))) || (SymbolTable_IsVarient (sym))) || (SymbolTable_IsFieldVarient (sym)))
2480 : {
2481 : /* avoid dangling else. */
2482 165921 : return true;
2483 : }
2484 25315414 : else if (SymbolTable_IsType (sym))
2485 : {
2486 : /* avoid dangling else. */
2487 76748 : type = SymbolTable_GetSType (sym);
2488 153496 : if ((type != SymbolTable_NulSym) && (IsNilTypedArrays (type)))
2489 : {
2490 : return true;
2491 : }
2492 : }
2493 : return false;
2494 : /* static analysis guarentees a RETURN statement will be used before here. */
2495 : __builtin_unreachable ();
2496 : }
2497 :
2498 :
2499 : /*
2500 : DeclareTypePartially - create the gcc partial type symbol from, sym.
2501 : */
2502 :
2503 165927 : static void DeclareTypePartially (unsigned int sym)
2504 : {
2505 165927 : location_t location;
2506 :
2507 : /* check to see if we have already partially declared the symbol */
2508 165927 : if (! (Sets_IsElementInSet (GlobalGroup->PartiallyDeclared, sym)))
2509 : {
2510 165927 : if (SymbolTable_IsRecord (sym))
2511 : {
2512 99353 : M2Debug_Assert (! (Sets_IsElementInSet (GlobalGroup->HeldByAlignment, sym)));
2513 99353 : M2Debug_Assert ((DoStartDeclaration (sym, (M2GCCDeclare_StartProcedure) {(M2GCCDeclare_StartProcedure_t) m2type_BuildStartRecord})) != NULL);
2514 99353 : WatchIncludeList (sym, M2GCCDeclare_heldbyalignment);
2515 : }
2516 66574 : else if (SymbolTable_IsVarient (sym))
2517 : {
2518 : /* avoid dangling else. */
2519 2988 : M2Debug_Assert (! (Sets_IsElementInSet (GlobalGroup->HeldByAlignment, sym)));
2520 2988 : M2Debug_Assert ((DoStartDeclaration (sym, (M2GCCDeclare_StartProcedure) {(M2GCCDeclare_StartProcedure_t) m2type_BuildStartVarient})) != NULL);
2521 2988 : WatchIncludeList (sym, M2GCCDeclare_heldbyalignment);
2522 : }
2523 63586 : else if (SymbolTable_IsFieldVarient (sym))
2524 : {
2525 : /* avoid dangling else. */
2526 6090 : M2Debug_Assert (! (Sets_IsElementInSet (GlobalGroup->HeldByAlignment, sym)));
2527 6090 : M2Debug_Assert ((DoStartDeclaration (sym, (M2GCCDeclare_StartProcedure) {(M2GCCDeclare_StartProcedure_t) m2type_BuildStartFieldVarient})) != NULL);
2528 6090 : WatchIncludeList (sym, M2GCCDeclare_heldbyalignment);
2529 : }
2530 57496 : else if (SymbolTable_IsProcType (sym))
2531 : {
2532 : /* avoid dangling else. */
2533 57490 : M2Debug_Assert ((DoStartDeclaration (sym, (M2GCCDeclare_StartProcedure) {(M2GCCDeclare_StartProcedure_t) m2type_BuildStartFunctionType})) != NULL);
2534 : }
2535 6 : else if (SymbolTable_IsType (sym))
2536 : {
2537 : /* avoid dangling else. */
2538 6 : if (! (SymbolConversion_GccKnowsAbout (sym)))
2539 : {
2540 6 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
2541 6 : PreAddModGcc (sym, m2type_BuildStartType (location, reinterpret_cast <char * > (NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (sym))), SymbolConversion_Mod2Gcc (SymbolTable_GetSType (sym))));
2542 : }
2543 : }
2544 : else
2545 : {
2546 : /* avoid dangling else. */
2547 0 : M2Error_InternalError ((const char *) "do not know how to create a partial type from this symbol", 57);
2548 : }
2549 165927 : WatchIncludeList (sym, M2GCCDeclare_partiallydeclared);
2550 165927 : TraverseDependants (sym);
2551 : }
2552 165927 : }
2553 :
2554 :
2555 : /*
2556 : CanDeclareArrayAsNil -
2557 : */
2558 :
2559 26149809 : static bool CanDeclareArrayAsNil (unsigned int sym)
2560 : {
2561 26149809 : return (SymbolTable_IsArray (sym)) && (ArrayComponentsDeclared (sym));
2562 : /* static analysis guarentees a RETURN statement will be used before here. */
2563 : __builtin_unreachable ();
2564 : }
2565 :
2566 :
2567 : /*
2568 : DeclareArrayAsNil -
2569 : */
2570 :
2571 7520 : static void DeclareArrayAsNil (unsigned int sym)
2572 : {
2573 7520 : unsigned int tokenno;
2574 7520 : unsigned int typeOfArray;
2575 :
2576 7520 : typeOfArray = SymbolTable_GetDType (sym);
2577 7520 : tokenno = SymbolTable_GetDeclaredMod (sym);
2578 7520 : PreAddModGcc (sym, m2type_BuildStartArrayType (BuildIndex (tokenno, sym, false), NULL, static_cast<int> (typeOfArray)));
2579 7520 : WatchIncludeList (sym, M2GCCDeclare_niltypedarrays);
2580 7520 : }
2581 :
2582 :
2583 : /*
2584 : CanDeclareArrayPartially -
2585 : */
2586 :
2587 27382 : static bool CanDeclareArrayPartially (unsigned int sym)
2588 : {
2589 27382 : unsigned int type;
2590 :
2591 27382 : if (SymbolTable_IsArray (sym))
2592 : {
2593 27118 : type = SymbolTable_GetSType (sym);
2594 46608 : if ((IsPartiallyOrFullyDeclared (type)) || ((SymbolTable_IsPointer (type)) && (IsNilTypedArrays (type))))
2595 : {
2596 7478 : return true;
2597 : }
2598 : }
2599 : return false;
2600 : /* static analysis guarentees a RETURN statement will be used before here. */
2601 : __builtin_unreachable ();
2602 : }
2603 :
2604 :
2605 : /*
2606 : DeclareArrayPartially -
2607 : */
2608 :
2609 7478 : static void DeclareArrayPartially (unsigned int sym)
2610 : {
2611 7478 : M2Debug_Assert ((SymbolTable_IsArray (sym)) && (SymbolConversion_GccKnowsAbout (sym)));
2612 7478 : m2type_PutArrayType (SymbolConversion_Mod2Gcc (sym), SymbolConversion_Mod2Gcc (SymbolTable_GetSType (sym)));
2613 7478 : WatchIncludeList (sym, M2GCCDeclare_partiallydeclared);
2614 7478 : }
2615 :
2616 :
2617 : /*
2618 : CanDeclarePointerToNilArray -
2619 : */
2620 :
2621 25666145 : static bool CanDeclarePointerToNilArray (unsigned int sym)
2622 : {
2623 26201579 : return (SymbolTable_IsPointer (sym)) && (IsNilTypedArrays (SymbolTable_GetSType (sym)));
2624 : /* static analysis guarentees a RETURN statement will be used before here. */
2625 : __builtin_unreachable ();
2626 : }
2627 :
2628 :
2629 : /*
2630 : DeclarePointerToNilArray -
2631 : */
2632 :
2633 84 : static void DeclarePointerToNilArray (unsigned int sym)
2634 : {
2635 84 : PreAddModGcc (sym, m2type_BuildPointerType (SymbolConversion_Mod2Gcc (SymbolTable_GetSType (sym))));
2636 84 : WatchIncludeList (sym, M2GCCDeclare_niltypedarrays);
2637 84 : }
2638 :
2639 :
2640 : /*
2641 : CanPromotePointerFully -
2642 : */
2643 :
2644 14074 : static bool CanPromotePointerFully (unsigned int sym)
2645 : {
2646 14074 : return (SymbolTable_IsPointer (sym)) && (IsPartiallyOrFullyDeclared (SymbolTable_GetSType (sym)));
2647 : /* static analysis guarentees a RETURN statement will be used before here. */
2648 : __builtin_unreachable ();
2649 : }
2650 :
2651 :
2652 : /*
2653 : PromotePointerFully -
2654 : */
2655 :
2656 78 : static void PromotePointerFully (unsigned int sym)
2657 : {
2658 78 : WatchIncludeList (sym, M2GCCDeclare_fullydeclared);
2659 78 : }
2660 :
2661 :
2662 : /*
2663 : IsTypeQ - returns TRUE if all q(dependants) of, sym,
2664 : return TRUE.
2665 : */
2666 :
2667 6236232 : static bool IsTypeQ (unsigned int sym, M2GCCDeclare_IsAction q)
2668 : {
2669 6236232 : if (SymbolTable_IsVar (sym))
2670 : {
2671 0 : return IsVarDependants (sym, q);
2672 : }
2673 6236232 : else if (SymbolTable_IsEnumeration (sym))
2674 : {
2675 : /* avoid dangling else. */
2676 133437 : return IsEnumerationDependants (sym, q);
2677 : }
2678 6102795 : else if (SymbolTable_IsFieldEnumeration (sym))
2679 : {
2680 : /* avoid dangling else. */
2681 : return true;
2682 : }
2683 5639967 : else if (SymbolTable_IsSubrange (sym))
2684 : {
2685 : /* avoid dangling else. */
2686 338738 : return IsSubrangeDependants (sym, q);
2687 : }
2688 5301229 : else if (SymbolTable_IsPointer (sym))
2689 : {
2690 : /* avoid dangling else. */
2691 1170131 : return IsPointerDependants (sym, q);
2692 : }
2693 4131098 : else if (SymbolTable_IsRecord (sym))
2694 : {
2695 : /* avoid dangling else. */
2696 717025 : return IsRecordDependants (sym, q);
2697 : }
2698 3414073 : else if (SymbolTable_IsRecordField (sym))
2699 : {
2700 : /* avoid dangling else. */
2701 1360404 : return IsRecordFieldDependants (sym, q);
2702 : }
2703 2053669 : else if (SymbolTable_IsVarient (sym))
2704 : {
2705 : /* avoid dangling else. */
2706 34884 : return IsVarientDependants (sym, q);
2707 : }
2708 2018785 : else if (SymbolTable_IsFieldVarient (sym))
2709 : {
2710 : /* avoid dangling else. */
2711 63618 : return IsVarientFieldDependants (sym, q);
2712 : }
2713 1955167 : else if (SymbolTable_IsArray (sym))
2714 : {
2715 : /* avoid dangling else. */
2716 471588 : return IsArrayDependants (sym, q);
2717 : }
2718 1483579 : else if (SymbolTable_IsProcType (sym))
2719 : {
2720 : /* avoid dangling else. */
2721 283242 : return IsProcTypeDependants (sym, q);
2722 : }
2723 1200337 : else if (SymbolTable_IsUnbounded (sym))
2724 : {
2725 : /* avoid dangling else. */
2726 196734 : return IsUnboundedDependants (sym, q);
2727 : }
2728 1003603 : else if (SymbolTable_IsPartialUnbounded (sym))
2729 : {
2730 : /* avoid dangling else. */
2731 0 : M2Error_InternalError ((const char *) "should not be declaring a partial unbounded symbol", 50);
2732 : }
2733 1003603 : else if (SymbolTable_IsSet (sym))
2734 : {
2735 : /* avoid dangling else. */
2736 38972 : return IsSetDependants (sym, q);
2737 : }
2738 964631 : else if (SymbolTable_IsType (sym))
2739 : {
2740 : /* avoid dangling else. */
2741 593657 : return IsTypeDependants (sym, q);
2742 : }
2743 370974 : else if (SymbolTable_IsConst (sym))
2744 : {
2745 : /* avoid dangling else. */
2746 370404 : return IsConstDependants (sym, q);
2747 : }
2748 570 : else if ((SymbolTable_IsConstructor (sym)) || (SymbolTable_IsConstSet (sym)))
2749 : {
2750 : /* avoid dangling else. */
2751 : /* sym can be a constructor, but at present we have not resolved whether
2752 : all dependants are constants.
2753 : */
2754 0 : return M2ALU_IsConstructorDependants (sym, q);
2755 : }
2756 570 : else if (SymbolTable_IsProcedure (sym))
2757 : {
2758 : /* avoid dangling else. */
2759 426 : return IsProcedureDependants (sym, q);
2760 : }
2761 : else
2762 : {
2763 : /* avoid dangling else. */
2764 : return true;
2765 : }
2766 : ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2GCCDeclare.def", 20, 1);
2767 : __builtin_unreachable ();
2768 : }
2769 :
2770 :
2771 : /*
2772 : IsNilTypedArrays - returns TRUE if, sym, is dependant upon a NIL typed array
2773 : */
2774 :
2775 631672 : static bool IsNilTypedArrays (unsigned int sym)
2776 : {
2777 631672 : return Sets_IsElementInSet (GlobalGroup->NilTypedArrays, sym);
2778 : /* static analysis guarentees a RETURN statement will be used before here. */
2779 : __builtin_unreachable ();
2780 : }
2781 :
2782 :
2783 : /*
2784 : IsFullyDeclared - returns TRUE if, sym, is fully declared.
2785 : */
2786 :
2787 13765270 : static bool IsFullyDeclared (unsigned int sym)
2788 : {
2789 11675221 : return Sets_IsElementInSet (GlobalGroup->FullyDeclared, sym);
2790 : /* static analysis guarentees a RETURN statement will be used before here. */
2791 : __builtin_unreachable ();
2792 : }
2793 :
2794 :
2795 : /*
2796 : AllDependantsFullyDeclared - returns TRUE if all dependants of,
2797 : sym, are declared.
2798 : */
2799 :
2800 6197998 : static bool AllDependantsFullyDeclared (unsigned int sym)
2801 : {
2802 4598035 : return IsTypeQ (sym, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) IsFullyDeclared});
2803 : /* static analysis guarentees a RETURN statement will be used before here. */
2804 : __builtin_unreachable ();
2805 : }
2806 :
2807 :
2808 : /*
2809 : NotAllDependantsFullyDeclared - returns TRUE if any dependants of,
2810 : sym, are not declared.
2811 : */
2812 :
2813 0 : static bool NotAllDependantsFullyDeclared (unsigned int sym)
2814 : {
2815 0 : return ! (IsTypeQ (sym, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) IsFullyDeclared}));
2816 : /* static analysis guarentees a RETURN statement will be used before here. */
2817 : __builtin_unreachable ();
2818 : }
2819 :
2820 :
2821 : /*
2822 : IsPartiallyDeclared - returns TRUE if, sym, is partially declared.
2823 : */
2824 :
2825 0 : static bool IsPartiallyDeclared (unsigned int sym)
2826 : {
2827 0 : return Sets_IsElementInSet (GlobalGroup->PartiallyDeclared, sym);
2828 : /* static analysis guarentees a RETURN statement will be used before here. */
2829 : __builtin_unreachable ();
2830 : }
2831 :
2832 :
2833 : /*
2834 : AllDependantsPartiallyDeclared - returns TRUE if all dependants of,
2835 : sym, are partially declared.
2836 : */
2837 :
2838 0 : static bool AllDependantsPartiallyDeclared (unsigned int sym)
2839 : {
2840 0 : return IsTypeQ (sym, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) IsPartiallyDeclared});
2841 : /* static analysis guarentees a RETURN statement will be used before here. */
2842 : __builtin_unreachable ();
2843 : }
2844 :
2845 :
2846 : /*
2847 : NotAllDependantsPartiallyDeclared - returns TRUE if any dependants of,
2848 : sym, are not partially declared.
2849 : */
2850 :
2851 0 : static bool NotAllDependantsPartiallyDeclared (unsigned int sym)
2852 : {
2853 0 : return ! (IsTypeQ (sym, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) IsPartiallyDeclared}));
2854 : /* static analysis guarentees a RETURN statement will be used before here. */
2855 : __builtin_unreachable ();
2856 : }
2857 :
2858 :
2859 : /*
2860 : IsPartiallyOrFullyDeclared - returns TRUE if, sym, is partially or fully declared.
2861 : */
2862 :
2863 77066 : static bool IsPartiallyOrFullyDeclared (unsigned int sym)
2864 : {
2865 77066 : return (Sets_IsElementInSet (GlobalGroup->PartiallyDeclared, sym)) || (Sets_IsElementInSet (GlobalGroup->FullyDeclared, sym));
2866 : /* static analysis guarentees a RETURN statement will be used before here. */
2867 : __builtin_unreachable ();
2868 : }
2869 :
2870 :
2871 : /*
2872 : AllDependantsPartiallyOrFullyDeclared - returns TRUE if all dependants of,
2873 : sym, are partially or fully declared.
2874 : */
2875 :
2876 38234 : static bool AllDependantsPartiallyOrFullyDeclared (unsigned int sym)
2877 : {
2878 38234 : return IsTypeQ (sym, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) IsPartiallyOrFullyDeclared});
2879 : /* static analysis guarentees a RETURN statement will be used before here. */
2880 : __builtin_unreachable ();
2881 : }
2882 :
2883 :
2884 : /*
2885 : TypeConstDependantsFullyDeclared - returns TRUE if sym is a constant or
2886 : type and its dependants are fully
2887 : declared.
2888 : */
2889 :
2890 27240716 : static bool TypeConstDependantsFullyDeclared (unsigned int sym)
2891 : {
2892 31197132 : return (((! (SymbolTable_IsVar (sym))) && (! (SymbolTable_IsRecord (sym)))) && (! (SymbolTable_IsParameter (sym)))) && (AllDependantsFullyDeclared (sym));
2893 : /* static analysis guarentees a RETURN statement will be used before here. */
2894 : __builtin_unreachable ();
2895 : }
2896 :
2897 :
2898 : /*
2899 : CanBeDeclaredViaPartialDependants - returns TRUE if this symbol
2900 : can be declared by partial
2901 : dependants. Such a symbol must
2902 : be a record, proctype or
2903 : an array.
2904 : */
2905 :
2906 18639868 : static bool CanBeDeclaredViaPartialDependants (unsigned int sym)
2907 : {
2908 18678102 : return ((SymbolTable_IsPointer (sym)) || (SymbolTable_IsProcType (sym))) && (AllDependantsPartiallyOrFullyDeclared (sym));
2909 : /* static analysis guarentees a RETURN statement will be used before here. */
2910 : __builtin_unreachable ();
2911 : }
2912 :
2913 :
2914 : /*
2915 : DeclareConstFully - will add, sym, to the fully declared list and
2916 : also remove it from the to do list. This is
2917 : called indirectly from M2GenGCC as it calculates
2918 : constants during quadruple processing.
2919 : */
2920 :
2921 510049 : static void DeclareConstFully (unsigned int sym)
2922 : {
2923 510049 : WatchIncludeList (sym, M2GCCDeclare_fullydeclared);
2924 510049 : WatchRemoveList (sym, M2GCCDeclare_todolist);
2925 510049 : WatchRemoveList (sym, M2GCCDeclare_partiallydeclared);
2926 510049 : WatchRemoveList (sym, M2GCCDeclare_tobesolvedbyquads);
2927 510049 : }
2928 :
2929 :
2930 : /*
2931 : DeclareTypeConstFully - declare the GCC type and add the double
2932 : book keeping entry.
2933 : */
2934 :
2935 1756197 : static void DeclareTypeConstFully (unsigned int sym)
2936 : {
2937 1756197 : tree t;
2938 :
2939 1756197 : if (! (Sets_IsElementInSet (GlobalGroup->ToBeSolvedByQuads, sym)))
2940 : {
2941 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
2942 1756197 : if ((SymbolTable_IsModule (sym)) || (SymbolTable_IsDefImp (sym)))
2943 : {
2944 144 : WatchIncludeList (sym, M2GCCDeclare_fullydeclared);
2945 144 : WatchRemoveList (sym, M2GCCDeclare_partiallydeclared);
2946 144 : WatchRemoveList (sym, M2GCCDeclare_todolist);
2947 : }
2948 1756053 : else if (SymbolTable_IsProcedure (sym))
2949 : {
2950 : /* avoid dangling else. */
2951 408 : DeclareProcedureToGcc (sym);
2952 408 : WatchIncludeList (sym, M2GCCDeclare_fullydeclared);
2953 408 : WatchRemoveList (sym, M2GCCDeclare_partiallydeclared);
2954 408 : WatchRemoveList (sym, M2GCCDeclare_todolist);
2955 : }
2956 1755645 : else if (! (IsFullyDeclared (sym)))
2957 : {
2958 : /* avoid dangling else. */
2959 1755645 : t = TypeConstFullyDeclared (sym);
2960 1755645 : if (t != NULL)
2961 : {
2962 : /* add relationship between gccsym and sym */
2963 3511290 : PreAddModGcc (sym, t);
2964 1755645 : WatchIncludeList (sym, M2GCCDeclare_fullydeclared);
2965 1755645 : WatchRemoveList (sym, M2GCCDeclare_partiallydeclared);
2966 1755645 : WatchRemoveList (sym, M2GCCDeclare_heldbyalignment);
2967 1755645 : WatchRemoveList (sym, M2GCCDeclare_finishedalignment);
2968 1755645 : WatchRemoveList (sym, M2GCCDeclare_todolist);
2969 : }
2970 : }
2971 : }
2972 1756197 : }
2973 :
2974 :
2975 : /*
2976 : DeclareTypeFromPartial - declare the full GCC type from a partial type
2977 : and add the double book keeping entry.
2978 : */
2979 :
2980 36740 : static void DeclareTypeFromPartial (unsigned int sym)
2981 : {
2982 36740 : tree t;
2983 :
2984 36740 : t = CompleteDeclarationOf (sym);
2985 36740 : if (t == NULL)
2986 : {
2987 0 : M2Error_InternalError ((const char *) "expecting to be able to create a gcc type", 41);
2988 : }
2989 : else
2990 : {
2991 36740 : SymbolConversion_AddModGcc (sym, t);
2992 36740 : WatchIncludeList (sym, M2GCCDeclare_fullydeclared);
2993 36740 : WatchRemoveList (sym, M2GCCDeclare_partiallydeclared);
2994 : }
2995 36740 : }
2996 :
2997 :
2998 : /*
2999 : CanCreateSetArray - return true if we need to create a set array.
3000 : All sets will have a set array created even
3001 : if it is not required.
3002 : */
3003 :
3004 26663713 : static bool CanCreateSetArray (unsigned int sym)
3005 : {
3006 26663713 : unsigned int setarray;
3007 :
3008 26663713 : if ((SymbolTable_IsSet (sym)) && (CanCreateSet (sym)))
3009 : {
3010 4664 : setarray = SymbolTable_GetSetArray (sym);
3011 4664 : if (setarray == SymbolTable_NulSym)
3012 : {
3013 : return true;
3014 : }
3015 : else
3016 : {
3017 : /* Set array already exists, this can occur if the set is a base type
3018 : (bitset for example).
3019 : So we just move the symbol to the correct state. */
3020 0 : WatchRemoveList (sym, M2GCCDeclare_todolist);
3021 0 : WatchIncludeList (sym, M2GCCDeclare_finishedsetarray);
3022 : }
3023 : /* WatchIncludeList (setarray, todolist) */
3024 : }
3025 : return false;
3026 : /* static analysis guarentees a RETURN statement will be used before here. */
3027 : __builtin_unreachable ();
3028 : }
3029 :
3030 :
3031 : /*
3032 : CreateSetArray - declare the set array for a set type.
3033 : */
3034 :
3035 4664 : static void CreateSetArray (unsigned int set)
3036 : {
3037 4664 : unsigned int type;
3038 4664 : unsigned int array;
3039 4664 : unsigned int high;
3040 4664 : unsigned int low;
3041 :
3042 4664 : type = SymbolTable_GetSType (set);
3043 4664 : low = M2GCCDeclare_GetTypeMin (type);
3044 4664 : high = M2GCCDeclare_GetTypeMax (type);
3045 4664 : M2GCCDeclare_DeclareConstant (SymbolTable_GetDeclaredMod (set), high);
3046 4664 : M2GCCDeclare_DeclareConstant (SymbolTable_GetDeclaredMod (set), low);
3047 4664 : array = DeclareSetArray (set, low, high);
3048 4664 : SymbolTable_PutSetArray (set, array);
3049 4664 : WatchRemoveList (set, M2GCCDeclare_todolist);
3050 4664 : WatchIncludeList (set, M2GCCDeclare_finishedsetarray);
3051 4664 : }
3052 :
3053 :
3054 : /*
3055 : CanCreateSet - returns TRUE if the set can be created.
3056 : All dependents of sym have been declared to GCC.
3057 : */
3058 :
3059 18734 : static bool CanCreateSet (unsigned int set)
3060 : {
3061 18734 : unsigned int type;
3062 18734 : unsigned int low;
3063 18734 : unsigned int high;
3064 :
3065 18734 : type = SymbolTable_GetSType (set);
3066 18734 : if (! (SymbolConversion_GccKnowsAbout (type)))
3067 : {
3068 : return false;
3069 : }
3070 9666 : low = M2GCCDeclare_GetTypeMin (type);
3071 9666 : high = M2GCCDeclare_GetTypeMax (type);
3072 9666 : if (! (SymbolConversion_GccKnowsAbout (low)))
3073 : {
3074 : return false;
3075 : }
3076 9328 : if (! (SymbolConversion_GccKnowsAbout (high)))
3077 : {
3078 : return false;
3079 : }
3080 : return true;
3081 : /* static analysis guarentees a RETURN statement will be used before here. */
3082 : __builtin_unreachable ();
3083 : }
3084 :
3085 :
3086 : /*
3087 : CreateSet -
3088 : */
3089 :
3090 4664 : static void CreateSet (unsigned int set)
3091 : {
3092 4664 : tree gccset;
3093 :
3094 4664 : gccset = DeclareSet (set);
3095 4664 : if (gccset == NULL)
3096 : {
3097 0 : M2Error_InternalError ((const char *) "expecting to be able to create a gcc type", 41);
3098 : }
3099 : else
3100 : {
3101 4664 : SymbolConversion_AddModGcc (set, gccset);
3102 4664 : WatchIncludeList (set, M2GCCDeclare_fullydeclared);
3103 4664 : WatchRemoveList (set, M2GCCDeclare_finishedsetarray);
3104 : }
3105 4664 : }
3106 :
3107 :
3108 : /*
3109 : CanBeDeclaredPartiallyViaPartialDependants - returns TRUE if, sym,
3110 : can be partially declared via
3111 : another partially declared type.
3112 : */
3113 :
3114 6580 : static bool CanBeDeclaredPartiallyViaPartialDependants (unsigned int sym)
3115 : {
3116 6580 : return (SymbolTable_IsType (sym)) && (AllDependantsPartiallyDeclared (sym));
3117 : /* static analysis guarentees a RETURN statement will be used before here. */
3118 : __builtin_unreachable ();
3119 : }
3120 :
3121 :
3122 : /*
3123 : EmitCircularDependencyError - issue a dependency error.
3124 : */
3125 :
3126 144 : static void EmitCircularDependencyError (unsigned int sym)
3127 : {
3128 : /* Ensure we only issue one dependency message per symbol for this
3129 : error classification. */
3130 144 : if (! (Sets_IsElementInSet (ErrorDepList, sym)))
3131 : {
3132 114 : Sets_IncludeElementIntoSet (ErrorDepList, sym);
3133 114 : if ((SymbolTable_IsVar (sym)) || (SymbolTable_IsParameter (sym)))
3134 : {
3135 24 : M2MetaError_MetaError1 ((const char *) "circular dependency error found when trying to resolve {%1Had}", 62, sym);
3136 : }
3137 : else
3138 : {
3139 90 : M2MetaError_MetaError1 ((const char *) "circular dependency error found when trying to resolve {%1Dad}", 62, sym);
3140 : }
3141 : }
3142 144 : }
3143 :
3144 :
3145 : /*
3146 : WriteRule - writes out the name of the rule.
3147 : */
3148 :
3149 0 : static void WriteRule (void)
3150 : {
3151 0 : if (Debugging)
3152 : {
3153 : switch (bodyr)
3154 : {
3155 : case M2GCCDeclare_norule:
3156 : M2Printf_printf0 ((const char *) "norule", 6);
3157 : break;
3158 :
3159 : case M2GCCDeclare_partialtype:
3160 : M2Printf_printf0 ((const char *) "partialtype", 11);
3161 : break;
3162 :
3163 : case M2GCCDeclare_arraynil:
3164 : M2Printf_printf0 ((const char *) "arraynil", 8);
3165 : break;
3166 :
3167 : case M2GCCDeclare_pointernilarray:
3168 : M2Printf_printf0 ((const char *) "pointernilarray", 15);
3169 : break;
3170 :
3171 : case M2GCCDeclare_arraypartial:
3172 : M2Printf_printf0 ((const char *) "arraypartial", 12);
3173 : break;
3174 :
3175 : case M2GCCDeclare_pointerfully:
3176 : M2Printf_printf0 ((const char *) "pointerfully", 12);
3177 : break;
3178 :
3179 : case M2GCCDeclare_recordkind:
3180 : M2Printf_printf0 ((const char *) "recordkind", 10);
3181 : break;
3182 :
3183 : case M2GCCDeclare_recordfully:
3184 : M2Printf_printf0 ((const char *) "recordfully", 11);
3185 : break;
3186 :
3187 : case M2GCCDeclare_typeconstfully:
3188 : M2Printf_printf0 ((const char *) "typeconstfully", 14);
3189 : break;
3190 :
3191 : case M2GCCDeclare_pointerfrompartial:
3192 : M2Printf_printf0 ((const char *) "pointerfrompartial", 18);
3193 : break;
3194 :
3195 : case M2GCCDeclare_typefrompartial:
3196 : M2Printf_printf0 ((const char *) "typefrompartial", 15);
3197 : break;
3198 :
3199 : case M2GCCDeclare_partialfrompartial:
3200 : M2Printf_printf0 ((const char *) "partialfrompartial", 18);
3201 : break;
3202 :
3203 : case M2GCCDeclare_partialtofully:
3204 : M2Printf_printf0 ((const char *) "partialtofully", 14);
3205 : break;
3206 :
3207 : case M2GCCDeclare_circulartodo:
3208 : M2Printf_printf0 ((const char *) "circulartodo", 12);
3209 : break;
3210 :
3211 : case M2GCCDeclare_circularpartial:
3212 : M2Printf_printf0 ((const char *) "circularpartial", 15);
3213 : break;
3214 :
3215 : case M2GCCDeclare_circularniltyped:
3216 : M2Printf_printf0 ((const char *) "circularniltyped", 16);
3217 : break;
3218 :
3219 : case M2GCCDeclare_setarraynul:
3220 : M2Printf_printf0 ((const char *) "setarraynul", 11);
3221 : break;
3222 :
3223 : case M2GCCDeclare_setfully:
3224 : M2Printf_printf0 ((const char *) "setfully", 8);
3225 : break;
3226 :
3227 :
3228 : default:
3229 : M2Error_InternalError ((const char *) "unknown rule", 12);
3230 : break;
3231 : }
3232 : }
3233 0 : }
3234 :
3235 :
3236 : /*
3237 : Body -
3238 : */
3239 :
3240 151469077 : static void Body (unsigned int sym)
3241 : {
3242 151469077 : if ((*bodyq.proc) (sym))
3243 : {
3244 2091783 : WatchRemoveList (sym, bodyt);
3245 2091783 : (*bodyp.proc) (sym);
3246 : /* The bodyp (sym) procedure function might have replaced sym into the set. */
3247 2091783 : if (! (Sets_IsElementInSet (LookupSet (bodyt), sym)))
3248 : {
3249 1925856 : noMoreWritten = false;
3250 1925856 : oneResolved = true;
3251 : }
3252 : }
3253 151469077 : }
3254 :
3255 :
3256 : /*
3257 : ForeachTryDeclare - while q (of one sym in set t) is true
3258 : for each symbol in set t,
3259 : if q (sym)
3260 : then
3261 : p (sym)
3262 : end
3263 : end
3264 : end
3265 : */
3266 :
3267 11630429 : static bool ForeachTryDeclare (M2GCCDeclare_ListType t, M2GCCDeclare_Rule r, M2GCCDeclare_IsAction q, M2GCCDeclare_WalkAction p)
3268 : {
3269 11630429 : if (recursionCaught)
3270 : {
3271 0 : M2Error_InternalError ((const char *) "caught recursive cycle in ForeachTryDeclare", 43);
3272 : }
3273 11630429 : bodyt = t;
3274 11630429 : bodyq = q;
3275 11630429 : bodyp = p;
3276 11630429 : bodyr = r;
3277 11630429 : recursionCaught = true;
3278 11630429 : oneResolved = false;
3279 11758917 : do {
3280 11758917 : noMoreWritten = true;
3281 11758917 : Sets_ForeachElementInSetDo (LookupSet (t), (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) Body});
3282 11758917 : } while (! (noMoreWritten));
3283 11630429 : bodyr = M2GCCDeclare_norule;
3284 11630429 : recursionCaught = false;
3285 11630429 : return oneResolved;
3286 : /* static analysis guarentees a RETURN statement will be used before here. */
3287 : __builtin_unreachable ();
3288 : }
3289 :
3290 821455 : static bool DeclaredOutstandingTypes (bool ForceComplete)
3291 : {
3292 821455 : bool finished;
3293 821455 : M2GCCDeclare_Group copy;
3294 :
3295 : /*
3296 : DeclaredOutandingTypes - writes out any types that have their
3297 : dependants solved. It returns TRUE if
3298 : all outstanding types have been written.
3299 : */
3300 821455 : M2Diagnostic_EnterDiagnostic (DeclaredOutstandingTypesDiag);
3301 821455 : copy = NULL;
3302 821455 : finished = false;
3303 931127 : do {
3304 931127 : if (Progress && (copy != NULL))
3305 : {
3306 : if (! (EqualGroup (copy, GlobalGroup)))
3307 : {
3308 : DebugSetNumbers ();
3309 : DebugSets ();
3310 : }
3311 : }
3312 931127 : copy = DupGroup (copy);
3313 931127 : if (ForeachTryDeclare (M2GCCDeclare_todolist, M2GCCDeclare_partialtype, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) CanDeclareTypePartially}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) DeclareTypePartially}))
3314 : {} /* empty. */
3315 : /* Continue looping. */
3316 931127 : else if (ForeachTryDeclare (M2GCCDeclare_todolist, M2GCCDeclare_setarraynul, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) CanCreateSetArray}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) CreateSetArray}))
3317 : {
3318 : /* avoid dangling else. */
3319 : }
3320 927249 : else if (ForeachTryDeclare (M2GCCDeclare_finishedsetarray, M2GCCDeclare_setfully, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) CanCreateSet}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) CreateSet}))
3321 : {
3322 : /* avoid dangling else. */
3323 : }
3324 923371 : else if (ForeachTryDeclare (M2GCCDeclare_todolist, M2GCCDeclare_arraynil, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) CanDeclareArrayAsNil}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) DeclareArrayAsNil}))
3325 : {
3326 : /* avoid dangling else. */
3327 : }
3328 919573 : else if (ForeachTryDeclare (M2GCCDeclare_todolist, M2GCCDeclare_pointernilarray, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) CanDeclarePointerToNilArray}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) DeclarePointerToNilArray}))
3329 : {
3330 : /* avoid dangling else. */
3331 : }
3332 919507 : else if (ForeachTryDeclare (M2GCCDeclare_niltypedarrays, M2GCCDeclare_arraypartial, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) CanDeclareArrayPartially}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) DeclareArrayPartially}))
3333 : {
3334 : /* avoid dangling else. */
3335 : }
3336 913037 : else if (ForeachTryDeclare (M2GCCDeclare_niltypedarrays, M2GCCDeclare_pointerfully, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) CanPromotePointerFully}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) PromotePointerFully}))
3337 : {
3338 : /* avoid dangling else. */
3339 : }
3340 912977 : else if (ForeachTryDeclare (M2GCCDeclare_heldbyalignment, M2GCCDeclare_recordkind, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) CanDeclareRecordKind}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) DeclareRecordKind}))
3341 : {
3342 : /* avoid dangling else. */
3343 : }
3344 899085 : else if (ForeachTryDeclare (M2GCCDeclare_finishedalignment, M2GCCDeclare_recordfully, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) CanDeclareRecord}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) FinishDeclareRecord}))
3345 : {
3346 : /* avoid dangling else. */
3347 : }
3348 875869 : else if (ForeachTryDeclare (M2GCCDeclare_todolist, M2GCCDeclare_typeconstfully, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) TypeConstDependantsFullyDeclared}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) DeclareTypeConstFully}))
3349 : {
3350 : /* avoid dangling else. */
3351 : }
3352 828081 : else if (ForeachTryDeclare (M2GCCDeclare_todolist, M2GCCDeclare_typefrompartial, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) CanBeDeclaredViaPartialDependants}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) DeclareTypeFromPartial}))
3353 : {
3354 : /* avoid dangling else. */
3355 : }
3356 824713 : else if (ForeachTryDeclare (M2GCCDeclare_partiallydeclared, M2GCCDeclare_partialfrompartial, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) CanBeDeclaredPartiallyViaPartialDependants}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) DeclareTypePartially}))
3357 : {
3358 : /* avoid dangling else. */
3359 : }
3360 824713 : else if (ForeachTryDeclare (M2GCCDeclare_partiallydeclared, M2GCCDeclare_partialtofully, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) TypeConstDependantsFullyDeclared}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) DeclareTypeConstFully}))
3361 : {
3362 : /* avoid dangling else. */
3363 : }
3364 : else
3365 : {
3366 : /* avoid dangling else. */
3367 : /* Nothing left to do (and constants are resolved elsewhere). */
3368 931127 : finished = true;
3369 : }
3370 931127 : } while (! (finished));
3371 821455 : KillGroup (©);
3372 821455 : if (ForceComplete)
3373 : {
3374 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
3375 0 : if (ForeachTryDeclare (M2GCCDeclare_todolist, M2GCCDeclare_circulartodo, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) NotAllDependantsFullyDeclared}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) EmitCircularDependencyError}))
3376 : {} /* empty. */
3377 0 : else if (ForeachTryDeclare (M2GCCDeclare_partiallydeclared, M2GCCDeclare_circularpartial, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) NotAllDependantsPartiallyDeclared}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) EmitCircularDependencyError}))
3378 : {
3379 : /* avoid dangling else. */
3380 : }
3381 0 : else if (ForeachTryDeclare (M2GCCDeclare_niltypedarrays, M2GCCDeclare_circularniltyped, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) NotAllDependantsPartiallyDeclared}, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) EmitCircularDependencyError}))
3382 : {
3383 : /* avoid dangling else. */
3384 : }
3385 : }
3386 821455 : M2Diagnostic_ExitDiagnostic (DeclaredOutstandingTypesDiag);
3387 821455 : return (Sets_NoOfElementsInSet (GlobalGroup->ToDoList)) == 0;
3388 : /* static analysis guarentees a RETURN statement will be used before here. */
3389 : __builtin_unreachable ();
3390 : }
3391 :
3392 :
3393 : /*
3394 : CompleteDeclarationOf - returns the GCC Tree for, sym, if it can
3395 : be created from partially or fully declared
3396 : dependents.
3397 : */
3398 :
3399 36740 : static tree CompleteDeclarationOf (unsigned int sym)
3400 : {
3401 36740 : if (SymbolTable_IsArray (sym))
3402 : {
3403 0 : return DeclareArray (sym);
3404 : }
3405 36740 : else if (SymbolTable_IsProcType (sym))
3406 : {
3407 : /* avoid dangling else. */
3408 9262 : return DeclareProcType (sym);
3409 : }
3410 27478 : else if (SymbolTable_IsRecordField (sym))
3411 : {
3412 : /* avoid dangling else. */
3413 0 : return DeclareRecordField (sym);
3414 : }
3415 27478 : else if (SymbolTable_IsPointer (sym))
3416 : {
3417 : /* avoid dangling else. */
3418 27478 : return DeclarePointer (sym);
3419 : }
3420 : else
3421 : {
3422 : /* avoid dangling else. */
3423 : return NULL;
3424 : }
3425 : /* static analysis guarentees a RETURN statement will be used before here. */
3426 : __builtin_unreachable ();
3427 : }
3428 :
3429 :
3430 : /*
3431 : DeclareType - here a type has been created via TYPE foo = bar,
3432 : we must tell GCC about it.
3433 : */
3434 :
3435 33794 : static tree DeclareType (unsigned int sym)
3436 : {
3437 33794 : tree t;
3438 33794 : location_t location;
3439 :
3440 33794 : if ((SymbolTable_GetSType (sym)) == SymbolTable_NulSym)
3441 : {
3442 0 : M2MetaError_MetaError1 ((const char *) "base type {%1Ua} not understood", 31, sym);
3443 0 : M2Error_InternalError ((const char *) "base type should have been declared", 35);
3444 : }
3445 : else
3446 : {
3447 33794 : if ((SymbolTable_GetSymName (sym)) == NameKey_NulName)
3448 : {
3449 0 : return (tree) (SymbolConversion_Mod2Gcc (SymbolTable_GetSType (sym)));
3450 : }
3451 : else
3452 : {
3453 33794 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
3454 33794 : if (SymbolConversion_GccKnowsAbout (sym))
3455 : {
3456 6 : t = SymbolConversion_Mod2Gcc (sym);
3457 : }
3458 : else
3459 : {
3460 : /* Not partially declared therefore start it. */
3461 33788 : t = m2type_BuildStartType (location, reinterpret_cast <char * > (NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (sym))), SymbolConversion_Mod2Gcc (SymbolTable_GetSType (sym)));
3462 : }
3463 33794 : t = m2type_BuildEndType (location, t); /* Now finish it. */
3464 33794 : return t; /* Now finish it. */
3465 : }
3466 : }
3467 : ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2GCCDeclare.def", 20, 1);
3468 : __builtin_unreachable ();
3469 : }
3470 :
3471 635216 : static void DeclareConstantFromTree (unsigned int sym, tree value)
3472 : {
3473 : /*
3474 : DeclareIntegerFromTree - declares an integer constant from a Tree, value.
3475 : */
3476 1270432 : PreAddModGcc (sym, value);
3477 635216 : WatchRemoveList (sym, M2GCCDeclare_todolist);
3478 635216 : WatchIncludeList (sym, M2GCCDeclare_fullydeclared);
3479 635216 : }
3480 :
3481 :
3482 : /*
3483 : DeclareCharConstant - declares a character constant.
3484 : */
3485 :
3486 17494 : static void DeclareCharConstant (unsigned int tokenno, unsigned int sym)
3487 : {
3488 17494 : location_t location;
3489 :
3490 17494 : M2Debug_Assert (SymbolTable_IsConstStringKnown (sym));
3491 17494 : location = M2LexBuf_TokenToLocation (tokenno);
3492 17494 : PreAddModGcc (sym, m2type_BuildCharConstant (location, const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetString (sym))))));
3493 17494 : WatchRemoveList (sym, M2GCCDeclare_todolist);
3494 17494 : WatchIncludeList (sym, M2GCCDeclare_fullydeclared);
3495 17494 : }
3496 :
3497 :
3498 : /*
3499 : DeclareStringConstant - declares a string constant the sym will be known.
3500 : */
3501 :
3502 231472 : static void DeclareStringConstant (unsigned int tokenno, unsigned int sym)
3503 : {
3504 231472 : tree symtree;
3505 :
3506 231472 : M2Debug_Assert (SymbolTable_IsConstStringKnown (sym));
3507 231472 : if ((SymbolTable_IsConstStringM2nul (sym)) || (SymbolTable_IsConstStringCnul (sym)))
3508 : {
3509 : /* in either case the string needs a nul terminator. If the string
3510 : is a C variant it will already have had any escape characters applied.
3511 : The BuildCStringConstant only adds the nul terminator. */
3512 231460 : symtree = m2decl_BuildCStringConstant (const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetString (sym)))), static_cast<int> (SymbolTable_GetStringLength (tokenno, sym)));
3513 : }
3514 : else
3515 : {
3516 12 : symtree = m2decl_BuildStringConstant (const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetString (sym)))), static_cast<int> (SymbolTable_GetStringLength (tokenno, sym)));
3517 : }
3518 462944 : PreAddModGcc (sym, symtree);
3519 231472 : WatchRemoveList (sym, M2GCCDeclare_todolist);
3520 231472 : WatchIncludeList (sym, M2GCCDeclare_fullydeclared);
3521 231472 : }
3522 :
3523 :
3524 : /*
3525 : WalkConstructor - walks all dependants of, sym.
3526 : */
3527 :
3528 1345902 : static void WalkConstructor (unsigned int sym, M2GCCDeclare_WalkAction p)
3529 : {
3530 1345902 : unsigned int type;
3531 :
3532 1345902 : type = SymbolTable_GetSType (sym);
3533 1345902 : if (type != SymbolTable_NulSym)
3534 : {
3535 1344624 : WalkDependants (type, p);
3536 1344624 : M2ALU_WalkConstructorDependants (sym, p);
3537 : }
3538 1345902 : }
3539 :
3540 :
3541 : /*
3542 : WalkConst - walks all dependants of, sym.
3543 : */
3544 :
3545 67976351 : static void WalkConst (unsigned int sym, M2GCCDeclare_WalkAction p)
3546 : {
3547 67976351 : unsigned int type;
3548 :
3549 67976351 : M2Debug_Assert (SymbolTable_IsConst (sym));
3550 67976351 : type = SymbolTable_GetSType (sym);
3551 67976351 : if (type != SymbolTable_NulSym)
3552 : {
3553 65094286 : (*p.proc) (type);
3554 : }
3555 67976351 : if ((SymbolTable_IsConstSet (sym)) || (SymbolTable_IsConstructor (sym)))
3556 : {
3557 1284078 : WalkConstructor (sym, p);
3558 : }
3559 67976351 : }
3560 :
3561 :
3562 : /*
3563 : IsConstDependants - returns TRUE if the symbol, sym,
3564 : q(dependants) all return TRUE.
3565 : */
3566 :
3567 370404 : static bool IsConstDependants (unsigned int sym, M2GCCDeclare_IsAction q)
3568 : {
3569 370404 : unsigned int type;
3570 :
3571 370404 : M2Debug_Assert (SymbolTable_IsConst (sym));
3572 370404 : type = SymbolTable_GetSType (sym);
3573 370404 : if (type != SymbolTable_NulSym)
3574 : {
3575 363300 : if (! ((*q.proc) (type)))
3576 : {
3577 : return false;
3578 : }
3579 : }
3580 320958 : if ((SymbolTable_IsConstSet (sym)) || (SymbolTable_IsConstructor (sym)))
3581 : {
3582 47664 : return M2ALU_IsConstructorDependants (sym, q);
3583 : }
3584 273294 : return SymbolTable_IsValueSolved (sym);
3585 : /* static analysis guarentees a RETURN statement will be used before here. */
3586 : __builtin_unreachable ();
3587 : }
3588 :
3589 :
3590 : /*
3591 : IsAnyType - return TRUE if sym is any Modula-2 type.
3592 : */
3593 :
3594 6388 : static bool IsAnyType (unsigned int sym)
3595 : {
3596 6388 : return (((((((SymbolTable_IsRecord (sym)) || (SymbolTable_IsType (sym))) || (SymbolTable_IsRecordField (sym))) || (SymbolTable_IsPointer (sym))) || (SymbolTable_IsArray (sym))) || (SymbolTable_IsSet (sym))) || (SymbolTable_IsEnumeration (sym))) || (SymbolTable_IsPointer (sym));
3597 : /* static analysis guarentees a RETURN statement will be used before here. */
3598 : __builtin_unreachable ();
3599 : }
3600 :
3601 :
3602 : /*
3603 : DeclareConstString -
3604 : */
3605 :
3606 248966 : static bool DeclareConstString (unsigned int tokenno, unsigned int sym)
3607 : {
3608 248966 : unsigned int size;
3609 :
3610 248966 : if (SymbolTable_IsConstStringKnown (sym))
3611 : {
3612 248966 : size = SymbolTable_GetStringLength (tokenno, sym);
3613 248966 : if (size == 1)
3614 : {
3615 17494 : DeclareCharConstant (tokenno, sym);
3616 : }
3617 : else
3618 : {
3619 231472 : DeclareStringConstant (tokenno, sym);
3620 : }
3621 248966 : return true;
3622 : }
3623 : return false;
3624 : /* static analysis guarentees a RETURN statement will be used before here. */
3625 : __builtin_unreachable ();
3626 : }
3627 :
3628 :
3629 : /*
3630 : TryDeclareConst - try to declare a const to gcc. If it cannot
3631 : declare the symbol it places it into the
3632 : todolist.
3633 : */
3634 :
3635 11096028 : static void TryDeclareConst (unsigned int tokenno, unsigned int sym)
3636 : {
3637 11096028 : unsigned int type;
3638 :
3639 11096028 : if (! (SymbolConversion_GccKnowsAbout (sym)))
3640 : {
3641 499978 : if ((SymbolTable_IsConstructor (sym)) || (SymbolTable_IsConstSet (sym)))
3642 : {
3643 12 : M2ALU_WalkConstructorDependants (sym, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) TraverseDependants});
3644 12 : M2ALU_TryEvaluateValue (sym);
3645 12 : if (! (M2ALU_IsConstructorDependants (sym, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) IsFullyDeclared})))
3646 : {
3647 0 : TraverseDependants (sym);
3648 0 : return;
3649 : }
3650 12 : if (! (SymbolTable_IsConstructorConstant (sym)))
3651 : {
3652 : return;
3653 : }
3654 : }
3655 499978 : if ((SymbolTable_IsConstString (sym)) && (SymbolTable_IsConstStringKnown (sym)))
3656 : {
3657 : /* avoid dangling else. */
3658 91110 : if (DeclareConstString (tokenno, sym))
3659 : {} /* empty. */
3660 : }
3661 408868 : else if (SymbolTable_IsValueSolved (sym))
3662 : {
3663 : /* avoid dangling else. */
3664 399766 : SymbolTable_PushValue (sym);
3665 399766 : if (SymbolTable_IsConstSet (sym))
3666 : {
3667 12 : DeclareConstantFromTree (sym, M2ALU_PopSetTree (tokenno));
3668 : }
3669 399754 : else if (SymbolTable_IsConstructor (sym))
3670 : {
3671 : /* avoid dangling else. */
3672 0 : DeclareConstantFromTree (sym, M2ALU_PopConstructorTree (tokenno));
3673 : }
3674 399754 : else if ((M2Base_IsRealType (SymbolTable_GetDType (sym))) || (M2System_IsRealN (SymbolTable_GetDType (sym))))
3675 : {
3676 : /* avoid dangling else. */
3677 5056 : type = SymbolTable_GetDType (sym);
3678 5056 : DeclareConstantFromTree (sym, m2convert_BuildConvert (M2LexBuf_TokenToLocation (tokenno), SymbolConversion_Mod2Gcc (type), M2ALU_PopRealTree (), true));
3679 : }
3680 394698 : else if (M2Base_IsComplexType (SymbolTable_GetDType (sym)))
3681 : {
3682 : /* avoid dangling else. */
3683 330 : type = SymbolTable_GetDType (sym);
3684 330 : DeclareConstantFromTree (sym, m2convert_BuildConvert (M2LexBuf_TokenToLocation (tokenno), SymbolConversion_Mod2Gcc (type), M2ALU_PopComplexTree (), true));
3685 : }
3686 : else
3687 : {
3688 : /* avoid dangling else. */
3689 394368 : if ((SymbolTable_GetSType (sym)) == SymbolTable_NulSym)
3690 : {
3691 0 : type = M2Base_ZType;
3692 : }
3693 : else
3694 : {
3695 394368 : type = SymbolTable_GetDType (sym);
3696 : }
3697 394368 : DeclareConstantFromTree (sym, m2convert_BuildConvert (M2LexBuf_TokenToLocation (tokenno), SymbolConversion_Mod2Gcc (type), M2ALU_PopIntegerTree (), true));
3698 : }
3699 : }
3700 : else
3701 : {
3702 : /* avoid dangling else. */
3703 9102 : TraverseDependants (sym);
3704 : }
3705 : }
3706 : }
3707 :
3708 :
3709 : /*
3710 : DeclareConst - declares a const to gcc and returns a Tree.
3711 : */
3712 :
3713 1221577 : static tree DeclareConst (unsigned int tokenno, unsigned int sym)
3714 : {
3715 1221577 : unsigned int type;
3716 :
3717 1221577 : if (SymbolConversion_GccKnowsAbout (sym))
3718 : {
3719 834985 : return SymbolConversion_Mod2Gcc (sym);
3720 : }
3721 386592 : if ((SymbolTable_IsConstructor (sym)) || (SymbolTable_IsConstSet (sym)))
3722 : {
3723 8434 : M2ALU_EvaluateValue (sym);
3724 : }
3725 386592 : if (SymbolTable_IsConstString (sym))
3726 : {
3727 : /* avoid dangling else. */
3728 157856 : if (DeclareConstString (tokenno, sym))
3729 : {} /* empty. */
3730 : }
3731 228736 : else if (SymbolTable_IsValueSolved (sym))
3732 : {
3733 : /* avoid dangling else. */
3734 228736 : SymbolTable_PushValue (sym);
3735 228736 : if (SymbolTable_IsConstSet (sym))
3736 : {
3737 5824 : DeclareConstantFromTree (sym, M2ALU_PopSetTree (tokenno));
3738 : }
3739 222912 : else if (SymbolTable_IsConstructor (sym))
3740 : {
3741 : /* avoid dangling else. */
3742 2610 : DeclareConstantFromTree (sym, M2ALU_PopConstructorTree (tokenno));
3743 : }
3744 220302 : else if (M2Base_IsRealType (SymbolTable_GetDType (sym)))
3745 : {
3746 : /* avoid dangling else. */
3747 1566 : type = SymbolTable_GetDType (sym);
3748 1566 : DeclareConstantFromTree (sym, m2convert_BuildConvert (M2LexBuf_TokenToLocation (tokenno), SymbolConversion_Mod2Gcc (type), M2ALU_PopRealTree (), true));
3749 : }
3750 218736 : else if (M2Base_IsComplexType (SymbolTable_GetDType (sym)))
3751 : {
3752 : /* avoid dangling else. */
3753 0 : type = SymbolTable_GetDType (sym);
3754 0 : DeclareConstantFromTree (sym, m2convert_BuildConvert (M2LexBuf_TokenToLocation (tokenno), SymbolConversion_Mod2Gcc (type), M2ALU_PopComplexTree (), true));
3755 : }
3756 : else
3757 : {
3758 : /* avoid dangling else. */
3759 218736 : if ((SymbolTable_GetSType (sym)) == SymbolTable_NulSym)
3760 : {
3761 13940 : type = M2Base_ZType;
3762 : }
3763 : else
3764 : {
3765 204796 : type = SymbolTable_GetDType (sym);
3766 : }
3767 218736 : DeclareConstantFromTree (sym, m2convert_BuildConvert (M2LexBuf_TokenToLocation (tokenno), SymbolConversion_Mod2Gcc (type), M2ALU_PopIntegerTree (), true));
3768 : }
3769 : }
3770 386592 : if (SymbolConversion_GccKnowsAbout (sym))
3771 : {
3772 386592 : return SymbolConversion_Mod2Gcc (sym);
3773 : }
3774 : else
3775 : {
3776 : return NULL;
3777 : }
3778 : /* static analysis guarentees a RETURN statement will be used before here. */
3779 : __builtin_unreachable ();
3780 : }
3781 :
3782 :
3783 : /*
3784 : WalkFamilyOfUnbounded -
3785 : */
3786 :
3787 26046975 : static void WalkFamilyOfUnbounded (unsigned int oaf __attribute__((unused)), unsigned int dim __attribute__((unused)), unsigned int unbounded)
3788 : {
3789 26046975 : if (unbounded != SymbolTable_NulSym)
3790 : {
3791 25941489 : (*unboundedp.proc) (unbounded);
3792 : }
3793 26046975 : }
3794 :
3795 :
3796 : /*
3797 : WalkAssociatedUnbounded -
3798 : */
3799 :
3800 412285564 : static void WalkAssociatedUnbounded (unsigned int sym, M2GCCDeclare_WalkAction p)
3801 : {
3802 412285564 : unsigned int oaf;
3803 412285564 : M2GCCDeclare_WalkAction o;
3804 :
3805 412285564 : oaf = SymbolTable_GetOAFamily (sym);
3806 412285564 : o = unboundedp;
3807 412285564 : unboundedp = p;
3808 412285564 : SymbolTable_ForeachOAFamily (oaf, (SymbolTable_FamilyOperation) {(SymbolTable_FamilyOperation_t) WalkFamilyOfUnbounded});
3809 412285564 : unboundedp = o;
3810 412285564 : }
3811 :
3812 :
3813 : /*
3814 : WalkDependants - walks through all dependants of, Sym,
3815 : calling, p, for each dependant.
3816 : */
3817 :
3818 411630384 : static void WalkDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
3819 : {
3820 411630384 : WalkAssociatedUnbounded (sym, p);
3821 411630384 : if (SymbolTable_IsComponent (sym))
3822 : {
3823 116314 : WalkComponentDependants (sym, p);
3824 : }
3825 411514070 : else if (SymbolTable_IsEnumeration (sym))
3826 : {
3827 : /* avoid dangling else. */
3828 11339597 : WalkEnumerationDependants (sym, p);
3829 : }
3830 400174473 : else if (SymbolTable_IsSubrange (sym))
3831 : {
3832 : /* avoid dangling else. */
3833 5497576 : WalkSubrangeDependants (sym, p);
3834 : }
3835 394676897 : else if (SymbolTable_IsPointer (sym))
3836 : {
3837 : /* avoid dangling else. */
3838 48175334 : WalkPointerDependants (sym, p);
3839 : }
3840 346501563 : else if (SymbolTable_IsRecord (sym))
3841 : {
3842 : /* avoid dangling else. */
3843 41100772 : WalkRecordDependants (sym, p);
3844 : }
3845 305400791 : else if (SymbolTable_IsVarient (sym))
3846 : {
3847 : /* avoid dangling else. */
3848 287720 : WalkVarientDependants (sym, p);
3849 : }
3850 305113071 : else if (SymbolTable_IsRecordField (sym))
3851 : {
3852 : /* avoid dangling else. */
3853 114846774 : WalkRecordFieldDependants (sym, p);
3854 : }
3855 190266297 : else if (SymbolTable_IsFieldVarient (sym))
3856 : {
3857 : /* avoid dangling else. */
3858 579604 : WalkVarientFieldDependants (sym, p);
3859 : }
3860 189686693 : else if (SymbolTable_IsArray (sym))
3861 : {
3862 : /* avoid dangling else. */
3863 4737188 : WalkArrayDependants (sym, p);
3864 : }
3865 184949505 : else if (SymbolTable_IsProcType (sym))
3866 : {
3867 : /* avoid dangling else. */
3868 4705800 : WalkProcTypeDependants (sym, p);
3869 : }
3870 180243705 : else if (SymbolTable_IsUnbounded (sym))
3871 : {
3872 : /* avoid dangling else. */
3873 25913411 : WalkUnboundedDependants (sym, p);
3874 : }
3875 154330294 : else if (SymbolTable_IsSet (sym))
3876 : {
3877 : /* avoid dangling else. */
3878 1622972 : WalkSetDependants (sym, p);
3879 : }
3880 152707322 : else if (SymbolTable_IsType (sym))
3881 : {
3882 : /* avoid dangling else. */
3883 84054196 : WalkTypeDependants (sym, p);
3884 : }
3885 68653126 : else if (SymbolTable_IsConst (sym))
3886 : {
3887 : /* avoid dangling else. */
3888 67976351 : WalkConst (sym, p);
3889 : }
3890 676775 : else if (SymbolTable_IsVar (sym))
3891 : {
3892 : /* avoid dangling else. */
3893 676211 : WalkVarDependants (sym, p);
3894 : }
3895 564 : else if (SymbolTable_IsProcedure (sym))
3896 : {
3897 : /* avoid dangling else. */
3898 408 : WalkProcedureDependants (sym, p);
3899 : }
3900 411630384 : }
3901 :
3902 :
3903 : /*
3904 : TraverseDependantsInner -
3905 : */
3906 :
3907 727610278 : static void TraverseDependantsInner (unsigned int sym)
3908 : {
3909 727610278 : if ((! (Sets_IsElementInSet (GlobalGroup->FullyDeclared, sym))) && (! (Sets_IsElementInSet (GlobalGroup->ToDoList, sym))))
3910 : {
3911 3636330 : WatchIncludeList (sym, M2GCCDeclare_todolist);
3912 : }
3913 727610278 : if (! (Sets_IsElementInSet (VisitedList, sym)))
3914 : {
3915 410285760 : Sets_IncludeElementIntoSet (VisitedList, sym);
3916 410285760 : WalkDependants (sym, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) TraverseDependantsInner});
3917 : }
3918 727610278 : }
3919 :
3920 :
3921 : /*
3922 : TraverseDependants - walks, sym, dependants. But it checks
3923 : to see that, sym, is not on the
3924 : FullyDeclared and not on the ToDoList.
3925 : */
3926 :
3927 55716631 : static void TraverseDependants (unsigned int sym)
3928 : {
3929 55716631 : if (VisitedList == NULL)
3930 : {
3931 55716631 : VisitedList = Sets_InitSet (1);
3932 55716631 : TraverseDependantsInner (sym);
3933 55716631 : VisitedList = Sets_KillSet (VisitedList);
3934 : }
3935 : else
3936 : {
3937 0 : M2Error_InternalError ((const char *) "recursive call to TraverseDependants caught", 43);
3938 : }
3939 55716631 : }
3940 :
3941 :
3942 : /*
3943 : WalkUnbounded -
3944 : */
3945 :
3946 2824777 : static void WalkUnbounded (unsigned int sym)
3947 : {
3948 2824777 : M2Debug_Assert (SymbolTable_IsUnbounded (sym));
3949 2824777 : TraverseDependants (sym);
3950 2824777 : WalkTypeInfo (SymbolTable_GetUnboundedRecordType (sym));
3951 2824777 : WalkTypeInfo (SymbolTable_GetSType (sym));
3952 2824777 : }
3953 :
3954 :
3955 : /*
3956 : WalkTypeInfo - walks type sym and its dependants.
3957 : */
3958 :
3959 48163998 : static void WalkTypeInfo (unsigned int sym)
3960 : {
3961 48167208 : if (SymbolTable_IsVarient (sym))
3962 : {
3963 0 : M2Error_InternalError ((const char *) "why have we reached here?", 25);
3964 : }
3965 48167208 : else if (SymbolTable_IsVar (sym))
3966 : {
3967 : /* avoid dangling else. */
3968 285976 : WalkTypeInfo (SymbolTable_GetSType (sym));
3969 285976 : if ((SymbolTable_GetVarBackEndType (sym)) != SymbolTable_NulSym)
3970 : {
3971 3210 : WalkTypeInfo (SymbolTable_GetVarBackEndType (sym));
3972 : }
3973 : }
3974 47881232 : else if (SymbolTable_IsUnbounded (sym))
3975 : {
3976 : /* avoid dangling else. */
3977 2824777 : WalkUnbounded (sym);
3978 : }
3979 45056455 : else if (SymbolTable_IsAModula2Type (sym))
3980 : {
3981 : /* avoid dangling else. */
3982 37493183 : TraverseDependants (sym);
3983 : }
3984 7563272 : else if (SymbolTable_IsProcedure (sym))
3985 : {
3986 : /* avoid dangling else. */
3987 6205652 : WalkProcedureDependants (sym, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) WalkTypeInfo});
3988 : }
3989 1357620 : else if (SymbolTable_IsProcType (sym))
3990 : {
3991 : /* avoid dangling else. */
3992 0 : WalkProcTypeDependants (sym, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) WalkTypeInfo});
3993 : }
3994 48163998 : }
3995 :
3996 :
3997 : /*
3998 : DeclareUnboundedProcedureParameters -
3999 : */
4000 :
4001 205633 : static void DeclareUnboundedProcedureParameters (unsigned int sym)
4002 : {
4003 205633 : unsigned int param;
4004 205633 : unsigned int type;
4005 205633 : unsigned int p;
4006 205633 : unsigned int i;
4007 205633 : location_t location;
4008 :
4009 205633 : if (SymbolTable_IsProcedure (sym))
4010 : {
4011 204909 : p = SymbolTable_NoOfParamAny (sym);
4012 204909 : i = p;
4013 916105 : while (i > 0)
4014 : {
4015 506287 : if (SymbolTable_IsUnboundedParamAny (sym, i))
4016 : {
4017 : /* avoid dangling else. */
4018 45668 : param = SymbolTable_GetNthParamAny (sym, i);
4019 45668 : type = SymbolTable_GetSType (param);
4020 45668 : TraverseDependants (type);
4021 45668 : if (SymbolConversion_GccKnowsAbout (type))
4022 : {
4023 45668 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (type));
4024 45668 : m2type_BuildTypeDeclaration (location, SymbolConversion_Mod2Gcc (type));
4025 : }
4026 : }
4027 : else
4028 : {
4029 460619 : param = SymbolTable_GetNth (sym, i);
4030 460619 : type = SymbolTable_GetSType (param);
4031 460619 : TraverseDependants (type);
4032 : }
4033 506287 : i -= 1;
4034 : }
4035 : }
4036 205633 : }
4037 :
4038 :
4039 : /*
4040 : WalkUnboundedProcedureParameters -
4041 : */
4042 :
4043 9029181 : static void WalkUnboundedProcedureParameters (unsigned int sym)
4044 : {
4045 9029181 : unsigned int param;
4046 9029181 : unsigned int type;
4047 9029181 : unsigned int p;
4048 9029181 : unsigned int i;
4049 :
4050 9029181 : if (SymbolTable_IsProcedure (sym))
4051 : {
4052 6205652 : p = SymbolTable_NoOfParamAny (sym);
4053 6205652 : i = p;
4054 23367342 : while (i > 0)
4055 : {
4056 10956038 : if (SymbolTable_IsUnboundedParamAny (sym, i))
4057 : {
4058 1259723 : param = SymbolTable_GetNthParamAny (sym, i);
4059 : }
4060 : else
4061 : {
4062 9696315 : param = SymbolTable_GetNth (sym, i);
4063 : }
4064 10956038 : type = SymbolTable_GetSType (param);
4065 10956038 : WalkTypeInfo (type);
4066 10956038 : i -= 1;
4067 : }
4068 : }
4069 9029181 : }
4070 :
4071 :
4072 : /*
4073 : WalkTypesInProcedure - walk all types in procedure, Sym.
4074 : */
4075 :
4076 76761 : static void WalkTypesInProcedure (unsigned int sym)
4077 : {
4078 0 : SymbolTable_ForeachLocalSymDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) TraverseDependants});
4079 0 : }
4080 :
4081 :
4082 : /*
4083 : WalkTypesInModule - declare all types in module, Sym, to GCC.
4084 : */
4085 :
4086 201043 : static void WalkTypesInModule (unsigned int sym)
4087 : {
4088 201043 : NameKey_Name n;
4089 :
4090 201043 : if (Debugging)
4091 : {
4092 : n = SymbolTable_GetSymName (sym);
4093 : M2Printf_printf1 ((const char *) "Declaring types in MODULE %a\\n", 30, (const unsigned char *) &n, (sizeof (n)-1));
4094 : }
4095 201043 : SymbolTable_ForeachLocalSymDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) WalkTypeInfo});
4096 201043 : SymbolTable_ForeachLocalSymDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) WalkUnboundedProcedureParameters});
4097 201043 : SymbolTable_ForeachInnerModuleDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) WalkTypesInModule});
4098 201043 : }
4099 :
4100 :
4101 : /*
4102 : IsRecordFieldDependants - returns TRUE if the record field
4103 : symbol, sym, p(dependants) all return TRUE.
4104 : */
4105 :
4106 1360404 : static bool IsRecordFieldDependants (unsigned int sym, M2GCCDeclare_IsAction q)
4107 : {
4108 1360404 : unsigned int align;
4109 1360404 : bool final;
4110 :
4111 1360404 : final = true;
4112 1360404 : if (! ((*q.proc) (SymbolTable_GetSType (sym))))
4113 : {
4114 : final = false;
4115 : }
4116 1360404 : align = SymbolTable_GetAlignment (sym);
4117 1360404 : if ((align != SymbolTable_NulSym) && (! ((*q.proc) (align))))
4118 : {
4119 : final = false;
4120 : }
4121 1360404 : return final;
4122 : /* static analysis guarentees a RETURN statement will be used before here. */
4123 : __builtin_unreachable ();
4124 : }
4125 :
4126 :
4127 : /*
4128 : GetModuleWhereDeclared - returns the module where, Sym, was created.
4129 : */
4130 :
4131 16947306 : static unsigned int GetModuleWhereDeclared (unsigned int sym)
4132 : {
4133 16953612 : unsigned int s;
4134 :
4135 16953612 : s = SymbolTable_GetScope (sym);
4136 16953612 : if (((s == SymbolTable_NulSym) || (SymbolTable_IsDefImp (s))) || ((SymbolTable_IsModule (s)) && ((SymbolTable_GetScope (s)) == SymbolTable_NulSym)))
4137 : {
4138 16947306 : return s;
4139 : }
4140 : else
4141 : {
4142 6306 : return GetModuleWhereDeclared (s);
4143 : }
4144 : /* static analysis guarentees a RETURN statement will be used before here. */
4145 : __builtin_unreachable ();
4146 : }
4147 :
4148 :
4149 : /*
4150 : IsPseudoProcFunc - returns TRUE if Sym is a pseudo function or procedure.
4151 : */
4152 :
4153 4909326 : static bool IsPseudoProcFunc (unsigned int Sym)
4154 : {
4155 4909326 : return ((M2Base_IsPseudoBaseProcedure (Sym)) || (M2Base_IsPseudoBaseFunction (Sym))) || (M2System_IsPseudoSystemFunction (Sym));
4156 : /* static analysis guarentees a RETURN statement will be used before here. */
4157 : __builtin_unreachable ();
4158 : }
4159 :
4160 :
4161 : /*
4162 : IsExternal -
4163 : */
4164 :
4165 3640546 : static bool IsExternal (unsigned int sym)
4166 : {
4167 3640546 : unsigned int mod;
4168 :
4169 3640546 : M2Debug_Assert (! (SymbolTable_IsDefImp (sym)));
4170 3640546 : if ((SymbolTable_IsProcedure (sym)) && (SymbolTable_IsExtern (sym)))
4171 : {
4172 : return true;
4173 : }
4174 3302010 : mod = SymbolTable_GetScope (sym);
4175 3304014 : do {
4176 3304014 : if (mod == SymbolTable_NulSym)
4177 : {
4178 : return false;
4179 : }
4180 3304014 : else if (SymbolTable_IsDefImp (mod))
4181 : {
4182 : /* avoid dangling else. */
4183 3213526 : return mod != (SymbolTable_GetMainModule ());
4184 : }
4185 90488 : mod = SymbolTable_GetScope (mod);
4186 90488 : } while (! (mod == SymbolTable_NulSym));
4187 : return false;
4188 : /* static analysis guarentees a RETURN statement will be used before here. */
4189 : __builtin_unreachable ();
4190 : }
4191 :
4192 :
4193 : /*
4194 : IsExternalToWholeProgram - return TRUE if the symbol, sym, is external to the
4195 : sources that we have parsed.
4196 : */
4197 :
4198 24696 : static bool IsExternalToWholeProgram (unsigned int sym)
4199 : {
4200 24696 : unsigned int mod;
4201 :
4202 24696 : mod = SymbolTable_GetScope (sym);
4203 24696 : do {
4204 24696 : if (mod == SymbolTable_NulSym)
4205 : {
4206 : return false;
4207 : }
4208 24696 : else if (SymbolTable_IsDefImp (mod))
4209 : {
4210 : /* avoid dangling else. */
4211 : /* return TRUE if we have no source file. */
4212 24432 : return (M2Batch_GetModuleFile (mod)) == NULL;
4213 : }
4214 264 : mod = SymbolTable_GetScope (mod);
4215 264 : } while (! (mod == SymbolTable_NulSym));
4216 : return false;
4217 : /* static analysis guarentees a RETURN statement will be used before here. */
4218 : __builtin_unreachable ();
4219 : }
4220 :
4221 :
4222 : /*
4223 : DeclareProcedureToGccWholeProgram -
4224 : */
4225 :
4226 672864 : static void DeclareProcedureToGccWholeProgram (unsigned int ProcedureSym)
4227 : {
4228 672864 : tree returnType;
4229 672864 : tree GccParam;
4230 672864 : unsigned int scope;
4231 672864 : unsigned int Variable;
4232 672864 : unsigned int p;
4233 672864 : unsigned int i;
4234 672864 : unsigned int b;
4235 672864 : unsigned int e;
4236 672864 : location_t begin;
4237 672864 : location_t end;
4238 672864 : location_t location;
4239 :
4240 672864 : M2Debug_Assert (SymbolTable_IsProcedure (ProcedureSym));
4241 672864 : if ((! (SymbolConversion_GccKnowsAbout (ProcedureSym))) && (! (IsPseudoProcFunc (ProcedureSym))))
4242 : {
4243 24696 : m2decl_BuildStartFunctionDeclaration (SymbolTable_UsesVarArgs (ProcedureSym));
4244 24696 : p = SymbolTable_NoOfParamAny (ProcedureSym);
4245 24696 : i = p;
4246 : /* note we dont use GetNthParamAny as we want the parameter that is seen by the procedure block
4247 : remember that this is treated exactly the same as a variable, just its position on
4248 : the activation record is special (ie a parameter)
4249 : */
4250 92064 : while (i > 0)
4251 : {
4252 42672 : Variable = SymbolTable_GetNth (ProcedureSym, i);
4253 42672 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (Variable));
4254 42672 : if (SymbolTable_IsUnboundedParamAny (ProcedureSym, i))
4255 : {
4256 3696 : GccParam = m2decl_BuildParameterDeclaration (location, const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetSymName (Variable)))), SymbolConversion_Mod2Gcc (SymbolTable_GetLType (Variable)), false);
4257 : }
4258 : else
4259 : {
4260 38976 : GccParam = m2decl_BuildParameterDeclaration (location, const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetSymName (Variable)))), SymbolConversion_Mod2Gcc (SymbolTable_GetLType (Variable)), SymbolTable_IsVarParamAny (ProcedureSym, i));
4261 : }
4262 85344 : PreAddModGcc (Variable, GccParam);
4263 42672 : WatchRemoveList (Variable, M2GCCDeclare_todolist);
4264 42672 : WatchIncludeList (Variable, M2GCCDeclare_fullydeclared);
4265 42672 : i -= 1;
4266 : }
4267 24696 : SymbolTable_GetProcedureBeginEnd (ProcedureSym, &b, &e);
4268 24696 : begin = M2LexBuf_TokenToLocation (b);
4269 24696 : end = M2LexBuf_TokenToLocation (e);
4270 24696 : scope = SymbolTable_GetScope (ProcedureSym);
4271 24696 : PushBinding (scope);
4272 24696 : if ((SymbolTable_GetSType (ProcedureSym)) == SymbolTable_NulSym)
4273 : {
4274 : returnType = NULL;
4275 : }
4276 : else
4277 : {
4278 15408 : returnType = SymbolConversion_Mod2Gcc (SymbolTable_GetSType (ProcedureSym));
4279 : }
4280 24696 : PreAddModGcc (ProcedureSym, m2decl_BuildEndFunctionDeclaration (begin, end, const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (ProcedureSym)))), returnType, IsExternalToWholeProgram (ProcedureSym), M2GCCDeclare_IsProcedureGccNested (ProcedureSym), SymbolTable_IsExported (GetModuleWhereDeclared (ProcedureSym), ProcedureSym), SymbolTable_IsProcedureAnyNoReturn (ProcedureSym)));
4281 24696 : PopBinding (scope);
4282 24696 : WatchRemoveList (ProcedureSym, M2GCCDeclare_todolist);
4283 24696 : WatchIncludeList (ProcedureSym, M2GCCDeclare_fullydeclared);
4284 : }
4285 672864 : }
4286 :
4287 :
4288 : /*
4289 : DeclareProcedureToGccSeparateProgram -
4290 : */
4291 :
4292 5182400 : static void DeclareProcedureToGccSeparateProgram (unsigned int ProcedureSym)
4293 : {
4294 5182400 : tree returnType;
4295 5182400 : tree GccParam;
4296 5182400 : unsigned int scope;
4297 5182400 : unsigned int Variable;
4298 5182400 : unsigned int p;
4299 5182400 : unsigned int i;
4300 5182400 : unsigned int b;
4301 5182400 : unsigned int e;
4302 5182400 : location_t begin;
4303 5182400 : location_t end;
4304 5182400 : location_t location;
4305 5182400 : unsigned int tok;
4306 :
4307 5182400 : M2Debug_Assert (SymbolTable_IsProcedure (ProcedureSym));
4308 5182400 : tok = SymbolTable_GetDeclaredMod (ProcedureSym);
4309 5182400 : if (((! (SymbolConversion_GccKnowsAbout (ProcedureSym))) && (! (IsPseudoProcFunc (ProcedureSym)))) && ((((((IsEffectivelyImported (SymbolTable_GetMainModule (), ProcedureSym)) || ((GetModuleWhereDeclared (ProcedureSym)) == (SymbolTable_GetMainModule ()))) || (M2Base_IsNeededAtRunTime (tok, ProcedureSym))) || (SymbolTable_IsImported (SymbolTable_GetBaseModule (), ProcedureSym))) || (SymbolTable_IsExported (GetModuleWhereDeclared (ProcedureSym), ProcedureSym))) || (SymbolTable_IsExtern (ProcedureSym))))
4310 : {
4311 3640546 : m2decl_BuildStartFunctionDeclaration (SymbolTable_UsesVarArgs (ProcedureSym));
4312 3640546 : p = SymbolTable_NoOfParamAny (ProcedureSym);
4313 3640546 : i = p;
4314 : /* Note we dont use GetNthParamAny as we want the parameter that is seen by
4315 : the procedure block remember that this is treated exactly the same as
4316 : a variable, just its position on the activation record is special (ie
4317 : a parameter). */
4318 14692939 : while (i > 0)
4319 : {
4320 7411847 : Variable = SymbolTable_GetNth (ProcedureSym, i);
4321 7411847 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (Variable));
4322 7411847 : if ((SymbolTable_GetSType (Variable)) == SymbolTable_NulSym)
4323 : {
4324 0 : M2MetaError_MetaError1 ((const char *) "internal error: the type of parameter {%1Ead} is nulsym", 55, Variable);
4325 0 : M2Error_FlushErrors ();
4326 : }
4327 7411847 : if ((SymbolConversion_Mod2Gcc (SymbolTable_GetSType (Variable))) == NULL)
4328 : {
4329 0 : M2MetaError_MetaError2 ((const char *) "internal error: the type of parameter {%1Ead} in procedure {%2ad} has not been declared to GCC", 94, Variable, ProcedureSym);
4330 0 : M2Error_FlushErrors ();
4331 0 : M2Debug_Assert (AllDependantsFullyDeclared (ProcedureSym));
4332 : }
4333 7411847 : if (SymbolTable_IsUnboundedParamAny (ProcedureSym, i))
4334 : {
4335 821028 : GccParam = m2decl_BuildParameterDeclaration (location, const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetSymName (Variable)))), SymbolConversion_Mod2Gcc (SymbolTable_GetLType (Variable)), false);
4336 : }
4337 : else
4338 : {
4339 6590819 : GccParam = m2decl_BuildParameterDeclaration (location, const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetSymName (Variable)))), SymbolConversion_Mod2Gcc (SymbolTable_GetLType (Variable)), SymbolTable_IsVarParamAny (ProcedureSym, i));
4340 : }
4341 14823694 : PreAddModGcc (Variable, GccParam);
4342 7411847 : WatchRemoveList (Variable, M2GCCDeclare_todolist);
4343 7411847 : WatchIncludeList (Variable, M2GCCDeclare_fullydeclared);
4344 7411847 : i -= 1;
4345 : }
4346 3640546 : SymbolTable_GetProcedureBeginEnd (ProcedureSym, &b, &e);
4347 3640546 : begin = M2LexBuf_TokenToLocation (b);
4348 3640546 : end = M2LexBuf_TokenToLocation (e);
4349 3640546 : scope = SymbolTable_GetScope (ProcedureSym);
4350 3640546 : PushBinding (scope);
4351 3640546 : if ((SymbolTable_GetSType (ProcedureSym)) == SymbolTable_NulSym)
4352 : {
4353 : returnType = NULL;
4354 : }
4355 : else
4356 : {
4357 2050147 : returnType = SymbolConversion_Mod2Gcc (SymbolTable_GetSType (ProcedureSym));
4358 : }
4359 : /* Exported from the module where it was declared. */
4360 7166237 : PreAddModGcc (ProcedureSym, m2decl_BuildEndFunctionDeclaration (begin, end, const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (ProcedureSym)))), returnType, IsExternal (ProcedureSym), M2GCCDeclare_IsProcedureGccNested (ProcedureSym), (SymbolTable_IsExported (GetModuleWhereDeclared (ProcedureSym), ProcedureSym)) || (SymbolTable_IsExtern (ProcedureSym)), SymbolTable_IsProcedureAnyNoReturn (ProcedureSym)));
4361 3640546 : PopBinding (scope);
4362 3640546 : WatchRemoveList (ProcedureSym, M2GCCDeclare_todolist);
4363 3640546 : WatchIncludeList (ProcedureSym, M2GCCDeclare_fullydeclared);
4364 : }
4365 5182400 : }
4366 :
4367 :
4368 : /*
4369 : DeclareProcedureToGcc - traverses all parameters and interfaces to gm2gcc.
4370 : */
4371 :
4372 5880456 : static void DeclareProcedureToGcc (unsigned int sym)
4373 : {
4374 5880456 : if (sym != SymbolTable_NulSym)
4375 : {
4376 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
4377 5855264 : if (M2Options_WholeProgram)
4378 : {
4379 672864 : DeclareProcedureToGccWholeProgram (sym);
4380 : }
4381 : else
4382 : {
4383 5182400 : DeclareProcedureToGccSeparateProgram (sym);
4384 : }
4385 : }
4386 5880456 : }
4387 :
4388 :
4389 : /*
4390 : ActivateWatch - activate a watch for any symbol (lista xor listb).
4391 : */
4392 :
4393 0 : static void ActivateWatch (Sets_Set lista, Sets_Set listb)
4394 : {
4395 0 : Sets_Set smallest;
4396 0 : Sets_Set largest;
4397 0 : unsigned int n;
4398 0 : unsigned int sym;
4399 :
4400 0 : if ((Sets_NoOfElementsInSet (lista)) != (Sets_NoOfElementsInSet (listb)))
4401 : {
4402 0 : if ((Sets_NoOfElementsInSet (lista)) > (Sets_NoOfElementsInSet (listb)))
4403 : {
4404 : largest = lista;
4405 : smallest = listb;
4406 : }
4407 : else
4408 : {
4409 0 : largest = listb;
4410 0 : smallest = lista;
4411 : }
4412 0 : M2Printf_printf0 ((const char *) "adding the following symbols to the watch list as the declarator has detected an internal bug: ", 95);
4413 0 : sym = 1;
4414 0 : n = SymbolTable_FinalSymbol ();
4415 0 : while (sym <= n)
4416 : {
4417 0 : if (((Sets_IsElementInSet (largest, sym)) && (! (Sets_IsElementInSet (smallest, sym)))) || ((! (Sets_IsElementInSet (largest, sym))) && (Sets_IsElementInSet (smallest, sym))))
4418 : {
4419 0 : AddSymToWatch (sym);
4420 0 : M2Printf_printf1 ((const char *) "%d ", 3, (const unsigned char *) &sym, (sizeof (sym)-1));
4421 : }
4422 0 : sym += 1;
4423 : }
4424 0 : M2Printf_printf0 ((const char *) "\\n", 2);
4425 : }
4426 0 : }
4427 :
4428 :
4429 : /*
4430 : DeclareTypesConstantsProceduresInRange -
4431 : */
4432 :
4433 792973 : static void DeclareTypesConstantsProceduresInRange (unsigned int scope, unsigned int start, unsigned int end)
4434 : {
4435 792973 : M2GCCDeclare_Group copy;
4436 792973 : unsigned int loop;
4437 792973 : M2Scope_ScopeBlock sb;
4438 792973 : M2BasicBlock_BasicBlock bb;
4439 :
4440 792973 : if (TraceQuadruples)
4441 : {
4442 : M2Quads_DisplayQuadRange (scope, start, end);
4443 : }
4444 792973 : M2Diagnostic_EnterDiagnostic (DeclareTypesConstantsProceduresInRangeDiag);
4445 792973 : loop = 0;
4446 792973 : copy = NULL;
4447 792973 : sb = M2Scope_InitScopeBlock (scope);
4448 : /* Throw away any unreachable quad. */
4449 821497 : do {
4450 821497 : bb = M2BasicBlock_InitBasicBlocks (sb);
4451 821497 : M2BasicBlock_KillBasicBlocks (&bb);
4452 : /* Now iterate over remaining quads in scope attempting to resolve constants. */
4453 821497 : copy = DupGroup (copy);
4454 821497 : bb = M2BasicBlock_InitBasicBlocks (sb);
4455 821497 : ConstantResolved = false;
4456 821497 : M2BasicBlock_ForeachBasicBlockDo (bb, (M2BasicBlock_BasicBlockProc) {(M2BasicBlock_BasicBlockProc_t) M2GCCDeclare_FoldConstants});
4457 821455 : M2BasicBlock_KillBasicBlocks (&bb);
4458 : /* And now types. */
4459 821455 : if (DeclaredOutstandingTypes (false))
4460 : {} /* empty. */
4461 821455 : if (loop == DebugLoop)
4462 : {
4463 0 : if (TraceQuadruples)
4464 : {
4465 : M2Quads_DisplayQuadRange (scope, start, end);
4466 : }
4467 0 : ActivateWatch (copy->ToDoList, GlobalGroup->ToDoList);
4468 0 : loop = 0;
4469 : }
4470 821455 : loop += 1;
4471 849979 : } while (! (! ConstantResolved && (EqualGroup (copy, GlobalGroup))));
4472 792931 : KillGroup (©);
4473 792931 : bb = M2BasicBlock_InitBasicBlocks (sb);
4474 792931 : M2BasicBlock_KillBasicBlocks (&bb);
4475 792931 : M2Scope_KillScopeBlock (&sb);
4476 792931 : M2Diagnostic_ExitDiagnostic (DeclareTypesConstantsProceduresInRangeDiag);
4477 792931 : }
4478 :
4479 :
4480 : /*
4481 : SkipModuleScope - skips all module scopes for, scope.
4482 : It returns either NulSym or a procedure sym.
4483 : */
4484 :
4485 7725608 : static unsigned int SkipModuleScope (unsigned int scope)
4486 : {
4487 15299590 : if ((scope == SymbolTable_NulSym) || (SymbolTable_IsProcedure (scope)))
4488 : {
4489 7725608 : return scope;
4490 : }
4491 : else
4492 : {
4493 7573982 : return SkipModuleScope (SymbolTable_GetScope (scope));
4494 : }
4495 : /* static analysis guarentees a RETURN statement will be used before here. */
4496 : __builtin_unreachable ();
4497 : }
4498 :
4499 :
4500 : /*
4501 : PushBinding -
4502 : */
4503 :
4504 3862825 : static void PushBinding (unsigned int scope)
4505 : {
4506 3862825 : scope = SkipModuleScope (scope);
4507 3862825 : if (scope == SymbolTable_NulSym)
4508 : {
4509 3785020 : m2block_pushGlobalScope ();
4510 : }
4511 : else
4512 : {
4513 77805 : m2block_pushFunctionScope (SymbolConversion_Mod2Gcc (scope));
4514 : }
4515 3862825 : }
4516 :
4517 :
4518 : /*
4519 : PopBinding -
4520 : */
4521 :
4522 3862783 : static void PopBinding (unsigned int scope)
4523 : {
4524 3862783 : scope = SkipModuleScope (scope);
4525 3862783 : if (scope == SymbolTable_NulSym)
4526 : {
4527 3784978 : m2block_popGlobalScope ();
4528 : }
4529 : else
4530 : {
4531 77805 : M2Debug_Assert (SymbolTable_IsProcedure (scope));
4532 77805 : m2block_finishFunctionDecl (M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (scope)), SymbolConversion_Mod2Gcc (scope));
4533 77805 : M2Debug_Assert ((m2block_popFunctionScope ()) != NULL);
4534 : }
4535 3862783 : }
4536 :
4537 :
4538 : /*
4539 : DeclareTypesConstantsProcedures -
4540 : */
4541 :
4542 92003 : static void DeclareTypesConstantsProcedures (unsigned int scope)
4543 : {
4544 92003 : M2GCCDeclare_Group copy;
4545 92003 : M2Scope_ScopeBlock sb;
4546 :
4547 92003 : if (Debugging)
4548 : {
4549 : M2Printf_printf0 ((const char *) "declaring types constants in: ", 30);
4550 : PrintTerse (scope);
4551 : }
4552 92003 : M2Diagnostic_EnterDiagnostic (DeclareTypesConstantsProceduresDiag);
4553 92003 : copy = NULL;
4554 92003 : sb = M2Scope_InitScopeBlock (scope);
4555 92003 : PushBinding (scope);
4556 115981 : do {
4557 115981 : copy = DupGroup (copy);
4558 115981 : M2Scope_ForeachScopeBlockDo3 (sb, (M2Scope_ScopeProcedure3) {(M2Scope_ScopeProcedure3_t) DeclareTypesConstantsProceduresInRange});
4559 115939 : } while (! (EqualGroup (copy, GlobalGroup)));
4560 91961 : KillGroup (©);
4561 91961 : PopBinding (scope);
4562 91961 : M2Scope_KillScopeBlock (&sb);
4563 91961 : M2Diagnostic_ExitDiagnostic (DeclareTypesConstantsProceduresDiag);
4564 91961 : }
4565 :
4566 :
4567 : /*
4568 : AssertAllTypesDeclared - asserts that all types for variables are declared in, scope.
4569 : */
4570 :
4571 91595 : static void AssertAllTypesDeclared (unsigned int scope)
4572 : {
4573 91595 : unsigned int n;
4574 91595 : unsigned int Var;
4575 91595 : bool failed;
4576 :
4577 91595 : failed = false;
4578 91595 : n = 1;
4579 91595 : Var = SymbolTable_GetNth (scope, n);
4580 1040007 : while (Var != SymbolTable_NulSym)
4581 : {
4582 856817 : if (! (TypeDependentsDeclared (Var, true)))
4583 : {
4584 24 : failed = true;
4585 : }
4586 856817 : n += 1;
4587 856817 : Var = SymbolTable_GetNth (scope, n);
4588 : }
4589 91595 : if (failed)
4590 : {
4591 24 : M2Error_FlushErrors ();
4592 : }
4593 91571 : }
4594 :
4595 :
4596 : /*
4597 : DeclareModuleInit - declare all the ctor related functions within
4598 : a module.
4599 : */
4600 :
4601 33584 : static void DeclareModuleInit (unsigned int moduleSym)
4602 : {
4603 33584 : unsigned int ctor;
4604 33584 : unsigned int init;
4605 33584 : unsigned int fini;
4606 33584 : unsigned int dep;
4607 :
4608 33584 : SymbolTable_GetModuleCtors (moduleSym, &ctor, &init, &fini, &dep);
4609 33584 : DeclareProcedureToGcc (ctor);
4610 33584 : DeclareProcedureToGcc (init);
4611 33584 : DeclareProcedureToGcc (fini);
4612 33584 : DeclareProcedureToGcc (dep);
4613 33584 : }
4614 :
4615 :
4616 : /*
4617 : StartDeclareProcedureScope -
4618 : */
4619 :
4620 76761 : static void StartDeclareProcedureScope (unsigned int scope)
4621 : {
4622 76761 : WalkTypesInProcedure (scope);
4623 76761 : M2GCCDeclare_DeclareProcedure (scope);
4624 76761 : SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) WalkTypesInModule});
4625 76761 : DeclareTypesConstantsProcedures (scope);
4626 76761 : SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DeclareTypesConstantsProcedures});
4627 76761 : M2GCCDeclare_DeclareLocalVariables (scope);
4628 76761 : SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_DeclareModuleVariables});
4629 76761 : AssertAllTypesDeclared (scope);
4630 76755 : SymbolTable_ForeachProcedureDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_DeclareProcedure});
4631 76755 : SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_StartDeclareScope});
4632 76755 : }
4633 :
4634 :
4635 : /*
4636 : StartDeclareModuleScopeSeparate -
4637 : */
4638 :
4639 14324 : static void StartDeclareModuleScopeSeparate (unsigned int scope)
4640 : {
4641 14324 : if (scope == (SymbolTable_GetMainModule ()))
4642 : {
4643 13916 : SymbolTable_ForeachModuleDo ((SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) WalkTypesInModule}); /* will populate the TYPE and CONST ToDo list */
4644 13916 : DeclareTypesConstantsProcedures (scope); /* will resolved TYPEs and CONSTs on the ToDo */
4645 : /* lists. */
4646 13874 : SymbolTable_ForeachModuleDo ((SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_DeclareProcedure});
4647 : /* Now that all types have been resolved it is safe to declare
4648 : variables. */
4649 13874 : AssertAllTypesDeclared (scope);
4650 13856 : DeclareGlobalVariables (scope);
4651 13856 : SymbolTable_ForeachImportedDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DeclareImportedVariables});
4652 : /* Now it is safe to declare all procedures. */
4653 13856 : SymbolTable_ForeachProcedureDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_DeclareProcedure});
4654 13856 : SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) WalkTypesInModule});
4655 13856 : SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DeclareTypesConstantsProcedures});
4656 13856 : SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_StartDeclareScope});
4657 13856 : DeclareModuleInit (scope);
4658 : }
4659 : else
4660 : {
4661 408 : DeclareTypesConstantsProcedures (scope);
4662 408 : AssertAllTypesDeclared (scope);
4663 408 : SymbolTable_ForeachProcedureDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_DeclareProcedure});
4664 408 : DeclareModuleInit (scope);
4665 408 : SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_StartDeclareScope});
4666 : }
4667 14264 : }
4668 :
4669 :
4670 : /*
4671 : StartDeclareModuleScopeWholeProgram -
4672 : */
4673 :
4674 552 : static void StartDeclareModuleScopeWholeProgram (unsigned int scope)
4675 : {
4676 552 : if (M2Batch_IsSourceSeen (scope))
4677 : {
4678 552 : SymbolTable_ForeachModuleDo ((SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) WalkTypesInModule}); /* will populate the TYPE and CONST ToDo list */
4679 552 : DeclareTypesConstantsProcedures (scope); /* will resolved TYPEs and CONSTs on the ToDo */
4680 : /* lists. */
4681 552 : SymbolTable_ForeachModuleDo ((SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_DeclareProcedure});
4682 552 : SymbolTable_ForeachModuleDo ((SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DeclareModuleInit});
4683 : /* Now that all types have been resolved it is safe to declare
4684 : variables. */
4685 552 : AssertAllTypesDeclared (scope);
4686 552 : DeclareGlobalVariablesWholeProgram (scope);
4687 552 : SymbolTable_ForeachImportedDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DeclareImportedVariablesWholeProgram});
4688 : /* Now it is safe to declare all procedures. */
4689 552 : SymbolTable_ForeachProcedureDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_DeclareProcedure});
4690 552 : SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) WalkTypesInModule});
4691 552 : SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DeclareTypesConstantsProcedures});
4692 552 : SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_StartDeclareScope});
4693 552 : DeclareModuleInit (scope);
4694 : }
4695 : else
4696 : {
4697 0 : DeclareTypesConstantsProcedures (scope);
4698 0 : AssertAllTypesDeclared (scope);
4699 0 : SymbolTable_ForeachProcedureDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_DeclareProcedure});
4700 0 : DeclareModuleInit (scope);
4701 0 : SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_StartDeclareScope});
4702 : }
4703 552 : }
4704 :
4705 :
4706 : /*
4707 : StartDeclareModuleScope -
4708 : */
4709 :
4710 14876 : static void StartDeclareModuleScope (unsigned int scope)
4711 : {
4712 14876 : if (M2Options_WholeProgram)
4713 : {
4714 552 : StartDeclareModuleScopeWholeProgram (scope);
4715 : }
4716 : else
4717 : {
4718 14324 : StartDeclareModuleScopeSeparate (scope);
4719 : }
4720 14816 : }
4721 :
4722 :
4723 : /*
4724 : DumpResolver - dumps the m2 representation of sym.
4725 : */
4726 :
4727 0 : static void DumpResolver (unsigned int sym)
4728 : {
4729 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) "dump filtered symbol %d and dependants\\n", 40, (const unsigned char *) &sym, (sizeof (sym)-1));
4730 0 : PrintVerbose (sym);
4731 0 : }
4732 :
4733 :
4734 : /*
4735 : DumpDefinitive - dumps the m2 and m2 gimple representation of sym.
4736 : */
4737 :
4738 0 : static void DumpDefinitive (unsigned int sym)
4739 : {
4740 0 : int fd;
4741 :
4742 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) "\\nm2 symbol synopsis: %d\\n", 26, (const unsigned char *) &sym, (sizeof (sym)-1));
4743 0 : PrintVerbose (sym);
4744 0 : if (SymbolConversion_GccKnowsAbout (sym))
4745 : {
4746 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) "\\nm2 gimple: %d", 15, (const unsigned char *) &sym, (sizeof (sym)-1));
4747 0 : FIO_FlushBuffer (M2LangDump_GetDumpFile ());
4748 0 : fd = FIO_GetUnixFileDescriptor (M2LangDump_GetDumpFile ());
4749 0 : m2pp_DumpGimpleFd (fd, SymbolConversion_Mod2Gcc (sym));
4750 : }
4751 : else
4752 : {
4753 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) "\\nno m2 gimple for %d\\n", 23, (const unsigned char *) &sym, (sizeof (sym)-1));
4754 : }
4755 0 : }
4756 :
4757 :
4758 : /*
4759 : PreAddModGcc - adds a relationship between sym and tree.
4760 : */
4761 :
4762 14992939 : static void PreAddModGcc (unsigned int sym, tree tree)
4763 : {
4764 13933119 : SymbolConversion_AddModGcc (sym, tree);
4765 319031 : }
4766 :
4767 :
4768 : /*
4769 : DeclareDefaultType - declares a default type, sym, with, name.
4770 : */
4771 :
4772 599420 : static void DeclareDefaultType (unsigned int sym, const char *name_, unsigned int _name_high, tree gcctype)
4773 : {
4774 599420 : tree t;
4775 599420 : unsigned int array;
4776 599420 : unsigned int high;
4777 599420 : unsigned int low;
4778 599420 : location_t location;
4779 599420 : char name[_name_high+1];
4780 :
4781 : /* make a local copy of each unbounded array. */
4782 599420 : memcpy (name, name_, _name_high+1);
4783 :
4784 : /* DeclareDefaultType will declare a new identifier as a type of gcctype
4785 : if it has not already been declared. */
4786 1198840 : location = m2linemap_BuiltinsLocation ();
4787 599420 : t = m2type_GetDefaultType (location, reinterpret_cast <char * > (NameKey_KeyToCharStar (NameKey_MakeKey ((const char *) name, _name_high))), gcctype);
4788 599420 : SymbolConversion_AddModGcc (sym, t);
4789 599420 : Sets_IncludeElementIntoSet (GlobalGroup->FullyDeclared, sym);
4790 599420 : WalkAssociatedUnbounded (sym, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) TraverseDependants});
4791 : /* This is very simplistic and assumes that the caller only uses Subranges,
4792 : Sets and GCC types. We need to declare any constants with the types so
4793 : that AllDependantsFullyDeclared works. */
4794 599420 : if (SymbolTable_IsSubrange (sym))
4795 : {
4796 13940 : SymbolTable_GetSubrange (sym, &high, &low);
4797 13940 : M2GCCDeclare_DeclareConstant (SymbolTable_GetDeclaredMod (sym), high);
4798 13940 : M2GCCDeclare_DeclareConstant (SymbolTable_GetDeclaredMod (sym), low);
4799 : }
4800 585480 : else if (SymbolTable_IsSet (sym))
4801 : {
4802 : /* avoid dangling else. */
4803 55760 : if (SymbolTable_IsSubrange (SymbolTable_GetSType (sym)))
4804 : {
4805 55760 : if (! (SymbolConversion_GccKnowsAbout (SymbolTable_GetSType (sym))))
4806 : {
4807 : /* Only true for internal types of course. */
4808 0 : M2Error_InternalError ((const char *) "subrange type within the set type must be declared before the set type", 70);
4809 : }
4810 55760 : SymbolTable_GetSubrange (SymbolTable_GetSType (sym), &high, &low);
4811 55760 : M2GCCDeclare_DeclareConstant (SymbolTable_GetDeclaredMod (sym), high);
4812 55760 : M2GCCDeclare_DeclareConstant (SymbolTable_GetDeclaredMod (sym), low);
4813 55760 : array = DeclareSetArray (sym, low, high);
4814 : /* IncludeElementIntoSet (FullyDeclared, array) ; */
4815 55760 : SymbolTable_PutSetArray (sym, array);
4816 : }
4817 0 : else if (SymbolTable_IsEnumeration (SymbolTable_GetSType (sym)))
4818 : {
4819 : /* avoid dangling else. */
4820 0 : if (! (SymbolConversion_GccKnowsAbout (SymbolTable_GetSType (sym))))
4821 : {
4822 : /* Only true for internal types of course. */
4823 0 : M2Error_InternalError ((const char *) "enumeration type within the set type must be declared before the set type", 73);
4824 : }
4825 : }
4826 : }
4827 599420 : }
4828 :
4829 :
4830 : /*
4831 : DeclareBoolean - declares the Boolean type together with true and false.
4832 : */
4833 :
4834 13940 : static void DeclareBoolean (void)
4835 : {
4836 13940 : SymbolConversion_AddModGcc (M2Base_Boolean, m2type_GetBooleanType ());
4837 13940 : SymbolConversion_AddModGcc (M2Base_True, m2type_GetBooleanTrue ());
4838 13940 : SymbolConversion_AddModGcc (M2Base_False, m2type_GetBooleanFalse ());
4839 13940 : Sets_IncludeElementIntoSet (GlobalGroup->FullyDeclared, M2Base_Boolean);
4840 13940 : Sets_IncludeElementIntoSet (GlobalGroup->FullyDeclared, M2Base_True);
4841 13940 : Sets_IncludeElementIntoSet (GlobalGroup->FullyDeclared, M2Base_False);
4842 13940 : WalkAssociatedUnbounded (M2Base_Boolean, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) TraverseDependants});
4843 13940 : }
4844 :
4845 :
4846 : /*
4847 : DeclareFixedSizedType - declares the GNU Modula-2 fixed types
4848 : (if the back end support such a type).
4849 : */
4850 :
4851 306680 : static void DeclareFixedSizedType (const char *name_, unsigned int _name_high, unsigned int type, tree t)
4852 : {
4853 306680 : location_t location;
4854 306680 : unsigned int typetype;
4855 306680 : unsigned int low;
4856 306680 : unsigned int high;
4857 306680 : char name[_name_high+1];
4858 :
4859 : /* make a local copy of each unbounded array. */
4860 306680 : memcpy (name, name_, _name_high+1);
4861 :
4862 306680 : if (type != SymbolTable_NulSym)
4863 : {
4864 278800 : if ((SymbolTable_IsSet (type)) && (! (SymbolConversion_GccKnowsAbout (SymbolTable_GetSType (type)))))
4865 : {
4866 41820 : typetype = SymbolTable_GetSType (type);
4867 41820 : SymbolTable_GetSubrange (typetype, &high, &low);
4868 41820 : M2GCCDeclare_DeclareConstant (SymbolTable_GetDeclaredMod (type), high);
4869 41820 : M2GCCDeclare_DeclareConstant (SymbolTable_GetDeclaredMod (type), low);
4870 41820 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (typetype));
4871 41820 : PreAddModGcc (typetype, m2type_BuildSubrangeType (location, reinterpret_cast <char * > (NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (typetype))), SymbolConversion_Mod2Gcc (SymbolTable_GetSType (typetype)), SymbolConversion_Mod2Gcc (low), SymbolConversion_Mod2Gcc (high)));
4872 41820 : Sets_IncludeElementIntoSet (GlobalGroup->FullyDeclared, typetype);
4873 41820 : WalkAssociatedUnbounded (typetype, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) TraverseDependants});
4874 : }
4875 : /* gcc back end supports, type */
4876 278800 : DeclareDefaultType (type, (const char *) name, _name_high, t);
4877 : }
4878 306680 : }
4879 :
4880 :
4881 : /*
4882 : DeclareDefaultSimpleTypes - declares the simple types.
4883 : */
4884 :
4885 13940 : static void DeclareDefaultSimpleTypes (void)
4886 : {
4887 13940 : SymbolConversion_AddModGcc (M2Base_ZType, m2type_GetM2ZType ());
4888 13940 : SymbolConversion_AddModGcc (M2Base_RType, m2type_GetM2RType ());
4889 13940 : SymbolConversion_AddModGcc (M2Base_CType, m2type_GetM2CType ());
4890 13940 : Sets_IncludeElementIntoSet (GlobalGroup->FullyDeclared, M2Base_ZType);
4891 13940 : Sets_IncludeElementIntoSet (GlobalGroup->FullyDeclared, M2Base_RType);
4892 13940 : Sets_IncludeElementIntoSet (GlobalGroup->FullyDeclared, M2Base_CType);
4893 13940 : DeclareDefaultType (M2Base_Cardinal, (const char *) "CARDINAL", 8, m2type_GetM2CardinalType ());
4894 13940 : DeclareDefaultType (M2Base_Integer, (const char *) "INTEGER", 7, m2type_GetM2IntegerType ());
4895 13940 : DeclareDefaultType (M2Base_Char, (const char *) "CHAR", 4, m2type_GetM2CharType ());
4896 13940 : DeclareDefaultType (M2System_Loc, (const char *) "LOC", 3, m2type_GetISOLocType ());
4897 13940 : if (M2Options_Iso)
4898 : {
4899 3596 : DeclareDefaultType (M2System_Byte, (const char *) "BYTE", 4, m2type_GetISOByteType ());
4900 3596 : DeclareDefaultType (M2System_Word, (const char *) "WORD", 4, m2type_GetISOWordType ());
4901 : }
4902 : else
4903 : {
4904 10344 : DeclareDefaultType (M2System_Byte, (const char *) "BYTE", 4, m2type_GetByteType ());
4905 10344 : DeclareDefaultType (M2System_Word, (const char *) "WORD", 4, m2type_GetWordType ());
4906 : }
4907 13940 : DeclareDefaultType (M2Base_Proc, (const char *) "PROC", 4, m2type_GetProcType ());
4908 13940 : DeclareDefaultType (M2System_Address, (const char *) "ADDRESS", 7, m2type_GetPointerType ());
4909 13940 : DeclareDefaultType (M2Base_LongInt, (const char *) "LONGINT", 7, m2type_GetM2LongIntType ());
4910 13940 : DeclareDefaultType (M2Base_LongCard, (const char *) "LONGCARD", 8, m2type_GetM2LongCardType ());
4911 13940 : DeclareDefaultType (M2Base_ShortInt, (const char *) "SHORTINT", 8, m2type_GetM2ShortIntType ());
4912 13940 : DeclareDefaultType (M2Base_ShortCard, (const char *) "SHORTCARD", 9, m2type_GetM2ShortCardType ());
4913 13940 : DeclareDefaultType (M2Base_ShortReal, (const char *) "SHORTREAL", 9, m2type_GetM2ShortRealType ());
4914 13940 : DeclareDefaultType (M2Base_Real, (const char *) "REAL", 4, m2type_GetM2RealType ());
4915 13940 : DeclareDefaultType (M2Base_LongReal, (const char *) "LONGREAL", 8, m2type_GetM2LongRealType ());
4916 13940 : DeclareDefaultType (M2Bitset_Bitnum, (const char *) "BITNUM", 6, m2type_GetBitnumType ());
4917 13940 : DeclareDefaultType (M2Bitset_Bitset, (const char *) "BITSET", 6, m2type_GetBitsetType ());
4918 13940 : DeclareDefaultType (M2Base_Complex, (const char *) "COMPLEX", 7, m2type_GetM2ComplexType ());
4919 13940 : DeclareDefaultType (M2Base_LongComplex, (const char *) "LONGCOMPLEX", 11, m2type_GetM2LongComplexType ());
4920 13940 : DeclareDefaultType (M2Base_ShortComplex, (const char *) "SHORTCOMPLEX", 12, m2type_GetM2ShortComplexType ());
4921 13940 : DeclareDefaultType (M2System_CSizeT, (const char *) "CSIZE_T", 7, m2type_GetCSizeTType ());
4922 13940 : DeclareDefaultType (M2System_CSSizeT, (const char *) "CSSIZE_T", 8, m2type_GetCSSizeTType ());
4923 13940 : DeclareDefaultType (M2System_COffT, (const char *) "COFF_T", 6, m2type_GetCOffTType ());
4924 13940 : DeclareBoolean ();
4925 13940 : DeclareFixedSizedType ((const char *) "INTEGER8", 8, M2System_IntegerN (8), m2type_GetM2Integer8 ());
4926 13940 : DeclareFixedSizedType ((const char *) "INTEGER16", 9, M2System_IntegerN (16), m2type_GetM2Integer16 ());
4927 13940 : DeclareFixedSizedType ((const char *) "INTEGER32", 9, M2System_IntegerN (32), m2type_GetM2Integer32 ());
4928 13940 : DeclareFixedSizedType ((const char *) "INTEGER64", 9, M2System_IntegerN (64), m2type_GetM2Integer64 ());
4929 13940 : DeclareFixedSizedType ((const char *) "CARDINAL8", 9, M2System_CardinalN (8), m2type_GetM2Cardinal8 ());
4930 13940 : DeclareFixedSizedType ((const char *) "CARDINAL16", 10, M2System_CardinalN (16), m2type_GetM2Cardinal16 ());
4931 13940 : DeclareFixedSizedType ((const char *) "CARDINAL32", 10, M2System_CardinalN (32), m2type_GetM2Cardinal32 ());
4932 13940 : DeclareFixedSizedType ((const char *) "CARDINAL64", 10, M2System_CardinalN (64), m2type_GetM2Cardinal64 ());
4933 13940 : DeclareFixedSizedType ((const char *) "WORD16", 6, M2System_WordN (16), m2type_GetM2Word16 ());
4934 13940 : DeclareFixedSizedType ((const char *) "WORD32", 6, M2System_WordN (32), m2type_GetM2Word32 ());
4935 13940 : DeclareFixedSizedType ((const char *) "WORD64", 6, M2System_WordN (64), m2type_GetM2Word64 ());
4936 13940 : DeclareFixedSizedType ((const char *) "BITSET8", 7, M2System_SetN (8), m2type_GetM2Bitset8 ());
4937 13940 : DeclareFixedSizedType ((const char *) "BITSET16", 8, M2System_SetN (16), m2type_GetM2Bitset16 ());
4938 13940 : DeclareFixedSizedType ((const char *) "BITSET32", 8, M2System_SetN (32), m2type_GetM2Bitset32 ());
4939 13940 : DeclareFixedSizedType ((const char *) "REAL32", 6, M2System_RealN (32), m2type_GetM2Real32 ());
4940 13940 : DeclareFixedSizedType ((const char *) "REAL64", 6, M2System_RealN (64), m2type_GetM2Real64 ());
4941 13940 : DeclareFixedSizedType ((const char *) "REAL96", 6, M2System_RealN (96), m2type_GetM2Real96 ());
4942 13940 : DeclareFixedSizedType ((const char *) "REAL128", 7, M2System_RealN (128), m2type_GetM2Real128 ());
4943 13940 : DeclareFixedSizedType ((const char *) "COMPLEX32", 9, M2System_ComplexN (32), m2type_GetM2Complex32 ());
4944 13940 : DeclareFixedSizedType ((const char *) "COMPLEX64", 9, M2System_ComplexN (64), m2type_GetM2Complex64 ());
4945 13940 : DeclareFixedSizedType ((const char *) "COMPLEX96", 9, M2System_ComplexN (96), m2type_GetM2Complex96 ());
4946 13940 : DeclareFixedSizedType ((const char *) "COMPLEX128", 10, M2System_ComplexN (128), m2type_GetM2Complex128 ());
4947 13940 : }
4948 :
4949 :
4950 : /*
4951 : DeclarePackedBoolean -
4952 : */
4953 :
4954 13940 : static void DeclarePackedBoolean (void)
4955 : {
4956 13940 : unsigned int e;
4957 :
4958 13940 : e = SymbolTable_GetPackedEquivalent (M2Base_Boolean);
4959 13940 : SymbolConversion_AddModGcc (e, m2type_GetPackedBooleanType ());
4960 13940 : Sets_IncludeElementIntoSet (GlobalGroup->FullyDeclared, e);
4961 13940 : }
4962 :
4963 :
4964 : /*
4965 : DeclarePackedDefaultSimpleTypes -
4966 : */
4967 :
4968 13940 : static void DeclarePackedDefaultSimpleTypes (void)
4969 : {
4970 0 : DeclarePackedBoolean ();
4971 0 : }
4972 :
4973 :
4974 : /*
4975 : DeclareDefaultTypes - makes default types known to GCC
4976 : */
4977 :
4978 13940 : static void DeclareDefaultTypes (void)
4979 : {
4980 13940 : if (! HaveInitDefaultTypes)
4981 : {
4982 13940 : HaveInitDefaultTypes = true;
4983 13940 : m2block_pushGlobalScope ();
4984 13940 : DeclareDefaultSimpleTypes ();
4985 13940 : DeclarePackedDefaultSimpleTypes ();
4986 13940 : m2block_popGlobalScope ();
4987 : }
4988 13940 : }
4989 :
4990 :
4991 : /*
4992 : DeclareDefaultConstants - make default constants known to GCC
4993 : */
4994 :
4995 13940 : static void DeclareDefaultConstants (void)
4996 : {
4997 13940 : SymbolConversion_AddModGcc (M2Base_Nil, m2expr_GetPointerZero (m2linemap_BuiltinsLocation ()));
4998 13940 : Sets_IncludeElementIntoSet (GlobalGroup->FullyDeclared, M2Base_Nil);
4999 13940 : }
5000 :
5001 :
5002 : /*
5003 : FindContext - returns the scope where the symbol
5004 : should be created.
5005 :
5006 : Symbols created in a module will
5007 : return the global context tree, but symbols created
5008 : in a module which is declared inside
5009 : a procedure will return the procedure Tree.
5010 : */
5011 :
5012 105580 : static tree FindContext (unsigned int sym)
5013 : {
5014 105580 : sym = SymbolTable_GetProcedureScope (sym);
5015 105580 : if (sym == SymbolTable_NulSym)
5016 : {
5017 105580 : return m2block_GetGlobalContext ();
5018 : }
5019 : else
5020 : {
5021 0 : return SymbolConversion_Mod2Gcc (sym);
5022 : }
5023 : /* static analysis guarentees a RETURN statement will be used before here. */
5024 : __builtin_unreachable ();
5025 : }
5026 :
5027 :
5028 : /*
5029 : IsEffectivelyImported - returns TRUE if symbol, Sym, was
5030 : effectively imported into ModSym.
5031 : */
5032 :
5033 4483744 : static bool IsEffectivelyImported (unsigned int ModSym, unsigned int sym)
5034 : {
5035 4483744 : return (SymbolTable_IsImported (ModSym, sym)) || ((SymbolTable_IsImported (ModSym, GetModuleWhereDeclared (sym))) && (SymbolTable_IsExported (GetModuleWhereDeclared (sym), sym)));
5036 : /* static analysis guarentees a RETURN statement will be used before here. */
5037 : __builtin_unreachable ();
5038 : }
5039 :
5040 :
5041 : /*
5042 : FindOuterModule - returns the out most module where, sym,
5043 : was declared. It returns NulSym if the
5044 : symbol or the module was declared inside
5045 : a procedure.
5046 : */
5047 :
5048 105658 : static unsigned int FindOuterModule (unsigned int sym)
5049 : {
5050 105658 : sym = SymbolTable_GetScope (sym);
5051 211418 : while (! (SymbolTable_IsDefImp (sym)))
5052 : {
5053 101184 : if (SymbolTable_IsModule (sym))
5054 : {
5055 101184 : if ((SymbolTable_GetScope (sym)) == SymbolTable_NulSym)
5056 : {
5057 : return sym;
5058 : }
5059 : else
5060 : {
5061 102 : sym = SymbolTable_GetScope (sym);
5062 : }
5063 : }
5064 0 : else if (SymbolTable_IsProcedure (sym))
5065 : {
5066 : /* avoid dangling else. */
5067 0 : sym = SymbolTable_GetScope (sym);
5068 : }
5069 : }
5070 : return sym;
5071 : /* static analysis guarentees a RETURN statement will be used before here. */
5072 : __builtin_unreachable ();
5073 : }
5074 :
5075 :
5076 : /*
5077 : DoVariableDeclaration - create a corresponding gcc variable and add the association
5078 : between the front end symbol var and the gcc tree.
5079 : */
5080 :
5081 768552 : static void DoVariableDeclaration (unsigned int var, void * name, bool isImported, bool isExported, bool isTemporary, bool isGlobal, tree scope)
5082 : {
5083 768552 : if (! ((SymbolTable_IsComponent (var)) || (SymbolTable_IsVarHeap (var))))
5084 : {
5085 623328 : if (TypeDependentsDeclared (var, true))
5086 : {
5087 623322 : PrepareGCCVarDeclaration (var, name, isImported, isExported, isTemporary, isGlobal, scope);
5088 : }
5089 : }
5090 768552 : }
5091 :
5092 :
5093 : /*
5094 : TypeDependentsDeclared - return TRUE if all type dependents of variable
5095 : have been declared.
5096 : */
5097 :
5098 1480145 : static bool TypeDependentsDeclared (unsigned int variable, bool errorMessage)
5099 : {
5100 1480145 : unsigned int type;
5101 :
5102 1480145 : type = SymbolTable_GetSType (variable);
5103 1480145 : if (AllDependantsFullyDeclared (type))
5104 : {
5105 : return true;
5106 : }
5107 : else
5108 : {
5109 30 : if (errorMessage)
5110 : {
5111 30 : EmitCircularDependencyError (variable);
5112 30 : Sets_ForeachElementInSetDo (GlobalGroup->ToDoList, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) EmitCircularDependencyError});
5113 : }
5114 : }
5115 : return false;
5116 : /* static analysis guarentees a RETURN statement will be used before here. */
5117 : __builtin_unreachable ();
5118 : }
5119 :
5120 :
5121 : /*
5122 : PrepareGCCVarDeclaration -
5123 : */
5124 :
5125 623322 : static void PrepareGCCVarDeclaration (unsigned int var, void * name, bool isImported, bool isExported, bool isTemporary, bool isGlobal, tree scope)
5126 : {
5127 623322 : tree type;
5128 623322 : unsigned int varType;
5129 623322 : location_t location;
5130 :
5131 623322 : if ((SymbolTable_GetMode (var)) == SymbolTable_LeftValue)
5132 : {
5133 : /*
5134 : There are two issues to deal with:
5135 :
5136 : (i) LeftValue is really a pointer to GetSType (var), which is built
5137 : here.
5138 : (ii) Front end might have specified the back end use a particular
5139 : data type, in which case we use the specified type.
5140 : We do not add an extra pointer if this is the case.
5141 : */
5142 91800 : varType = SymbolTable_SkipType (SymbolTable_GetVarBackEndType (var));
5143 91800 : if (varType == SymbolTable_NulSym)
5144 : {
5145 : /* We have not explicity told back end the type, so build it. */
5146 35554 : varType = SymbolTable_GetSType (var);
5147 35554 : if (SymbolTable_IsVariableAtAddress (var))
5148 : {
5149 54 : type = m2type_BuildConstPointerType (SymbolConversion_Mod2Gcc (varType));
5150 : }
5151 : else
5152 : {
5153 35500 : type = m2type_BuildPointerType (SymbolConversion_Mod2Gcc (varType));
5154 : }
5155 : }
5156 : else
5157 : {
5158 : /* We have been requested to use varType. */
5159 56246 : type = SymbolConversion_Mod2Gcc (varType);
5160 : }
5161 91800 : M2Debug_Assert (AllDependantsFullyDeclared (varType));
5162 : }
5163 : else
5164 : {
5165 531522 : type = SymbolConversion_Mod2Gcc (SymbolTable_GetDType (var));
5166 : }
5167 623322 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (var));
5168 623322 : PreAddModGcc (var, m2decl_DeclareKnownVariable (location, const_cast <const char * > (static_cast <char * > (name)), type, isExported, isImported, isTemporary, isGlobal, scope, NULL));
5169 623322 : WatchRemoveList (var, M2GCCDeclare_todolist);
5170 623322 : WatchIncludeList (var, M2GCCDeclare_fullydeclared);
5171 623322 : }
5172 :
5173 :
5174 : /*
5175 : IsGlobal - is the variable not in a procedure scope.
5176 : */
5177 :
5178 105580 : static bool IsGlobal (unsigned int sym)
5179 : {
5180 105580 : unsigned int s;
5181 :
5182 105580 : s = SymbolTable_GetScope (sym);
5183 211160 : while (((s != SymbolTable_NulSym) && (! (SymbolTable_IsDefImp (s)))) && (! (SymbolTable_IsModule (s))))
5184 : {
5185 0 : if (SymbolTable_IsProcedure (s))
5186 : {
5187 : return false;
5188 : }
5189 0 : s = SymbolTable_GetScope (s);
5190 : }
5191 : return true;
5192 : /* static analysis guarentees a RETURN statement will be used before here. */
5193 : __builtin_unreachable ();
5194 : }
5195 :
5196 :
5197 : /*
5198 : DeclareVariable - declares a global variable to GCC.
5199 : */
5200 :
5201 104394 : static void DeclareVariable (unsigned int ModSym, unsigned int variable)
5202 : {
5203 104394 : tree scope;
5204 104394 : unsigned int decl;
5205 :
5206 104394 : if (! (SymbolConversion_GccKnowsAbout (variable)))
5207 : {
5208 104320 : scope = FindContext (ModSym);
5209 104320 : decl = FindOuterModule (variable);
5210 104320 : PushBinding (ModSym);
5211 : /* in Modula-2 we are allowed to import from ourselves, but we do not present this to GCC */
5212 207588 : DoVariableDeclaration (variable, NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (variable)), (IsEffectivelyImported (ModSym, variable)) && ((SymbolTable_GetMainModule ()) != decl), SymbolTable_IsExported (ModSym, variable), SymbolTable_IsTemporary (variable), IsGlobal (variable), scope);
5213 104320 : PopBinding (ModSym);
5214 : }
5215 104394 : }
5216 :
5217 :
5218 : /*
5219 : DeclareVariableWholeProgram - declares a global variable to GCC when using -fm2-whole-program.
5220 : */
5221 :
5222 1260 : static void DeclareVariableWholeProgram (unsigned int mainModule, unsigned int variable)
5223 : {
5224 1260 : tree scope;
5225 1260 : unsigned int decl;
5226 :
5227 1260 : if (! (SymbolConversion_GccKnowsAbout (variable)))
5228 : {
5229 1260 : scope = FindContext (mainModule);
5230 1260 : decl = FindOuterModule (variable);
5231 1260 : PushBinding (mainModule);
5232 2520 : DoVariableDeclaration (variable, NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (variable)), ((! (M2Batch_IsSourceSeen (decl))) && (IsEffectivelyImported (mainModule, variable))) && ((SymbolTable_GetMainModule ()) != decl), SymbolTable_IsExported (mainModule, variable), SymbolTable_IsTemporary (variable), IsGlobal (variable), scope);
5233 1260 : PopBinding (mainModule);
5234 : }
5235 1260 : }
5236 :
5237 :
5238 : /*
5239 : DeclareGlobalVariablesWholeProgram -
5240 : */
5241 :
5242 552 : static void DeclareGlobalVariablesWholeProgram (unsigned int ModSym)
5243 : {
5244 552 : unsigned int n;
5245 552 : unsigned int Variable;
5246 :
5247 552 : n = 1;
5248 552 : Variable = SymbolTable_GetNth (ModSym, n);
5249 2364 : while (Variable != SymbolTable_NulSym)
5250 : {
5251 1260 : DeclareVariableWholeProgram (ModSym, Variable);
5252 1260 : n += 1;
5253 1260 : Variable = SymbolTable_GetNth (ModSym, n);
5254 : }
5255 552 : SymbolTable_ForeachInnerModuleDo (ModSym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DeclareGlobalVariablesWholeProgram});
5256 552 : }
5257 :
5258 :
5259 : /*
5260 : DeclareGlobalVariables - lists the Global variables for
5261 : Module ModSym together with their offset.
5262 : */
5263 :
5264 14108 : static void DeclareGlobalVariables (unsigned int ModSym)
5265 : {
5266 14108 : unsigned int n;
5267 14108 : unsigned int Variable;
5268 :
5269 14108 : n = 1;
5270 14108 : Variable = SymbolTable_GetNth (ModSym, n);
5271 131490 : while (Variable != SymbolTable_NulSym)
5272 : {
5273 103274 : DeclareVariable (ModSym, Variable);
5274 103274 : n += 1;
5275 103274 : Variable = SymbolTable_GetNth (ModSym, n);
5276 : }
5277 14108 : SymbolTable_ForeachInnerModuleDo (ModSym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DeclareGlobalVariables});
5278 14108 : }
5279 :
5280 :
5281 : /*
5282 : DeclareImportedVariables - declares all imported variables to GM2.
5283 : */
5284 :
5285 88765 : static void DeclareImportedVariables (unsigned int sym)
5286 : {
5287 88765 : if (SymbolTable_IsVar (sym))
5288 : {
5289 1120 : DeclareVariable (SymbolTable_GetMainModule (), sym);
5290 : }
5291 87645 : else if (SymbolTable_IsDefImp (sym))
5292 : {
5293 : /* avoid dangling else. */
5294 2146 : SymbolTable_ForeachExportedDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DeclareImportedVariables});
5295 : }
5296 88765 : }
5297 :
5298 :
5299 : /*
5300 : DeclareImportedVariablesWholeProgram - declares all imported variables.
5301 : */
5302 :
5303 18612 : static void DeclareImportedVariablesWholeProgram (unsigned int sym)
5304 : {
5305 18612 : if (SymbolTable_IsVar (sym))
5306 : {
5307 : /* avoid dangling else. */
5308 78 : if (! (M2Batch_IsSourceSeen (FindOuterModule (sym))))
5309 : {
5310 : /* import is necessary, even for -fm2-whole-program as we
5311 : cannot see the source. */
5312 0 : DeclareVariableWholeProgram (SymbolTable_GetMainModule (), sym);
5313 : }
5314 : }
5315 18534 : else if (SymbolTable_IsDefImp (sym))
5316 : {
5317 : /* avoid dangling else. */
5318 312 : SymbolTable_ForeachExportedDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DeclareImportedVariablesWholeProgram});
5319 : }
5320 18612 : }
5321 :
5322 :
5323 : /*
5324 : DeclareFieldValue -
5325 : */
5326 :
5327 462948 : static tree DeclareFieldValue (unsigned int sym, tree value, tree *list)
5328 : {
5329 462948 : location_t location;
5330 :
5331 462948 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
5332 462948 : if (((GetModuleWhereDeclared (sym)) == SymbolTable_NulSym) || ((GetModuleWhereDeclared (sym)) == (SymbolTable_GetMainModule ())))
5333 : {
5334 9828 : return m2type_BuildEnumerator (location, const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetSymName (sym)))), value, list);
5335 : }
5336 : else
5337 : {
5338 453120 : return m2type_BuildEnumerator (location, const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (M2AsmUtil_GetFullScopeAsmName (sym)))), value, list);
5339 : }
5340 : /* static analysis guarentees a RETURN statement will be used before here. */
5341 : __builtin_unreachable ();
5342 : }
5343 :
5344 :
5345 : /*
5346 : DeclareFieldEnumeration - declares an enumerator within the current enumeration type.
5347 : */
5348 :
5349 462828 : static tree DeclareFieldEnumeration (unsigned int sym)
5350 : {
5351 462828 : unsigned int type;
5352 462828 : tree field;
5353 462828 : tree enumlist;
5354 :
5355 : /* add relationship between gccSym and sym */
5356 462828 : type = SymbolTable_GetSType (sym);
5357 462828 : enumlist = GetEnumList (type);
5358 462828 : SymbolTable_PushValue (sym);
5359 462828 : field = DeclareFieldValue (sym, M2ALU_PopIntegerTree (), &enumlist);
5360 462828 : PutEnumList (type, enumlist);
5361 462828 : return field;
5362 : /* static analysis guarentees a RETURN statement will be used before here. */
5363 : __builtin_unreachable ();
5364 : }
5365 :
5366 :
5367 : /*
5368 : DeclareEnumeration - declare an enumerated type.
5369 : */
5370 :
5371 34054 : static tree DeclareEnumeration (unsigned int sym)
5372 : {
5373 34054 : tree enumlist;
5374 34054 : tree gccenum;
5375 34054 : location_t location;
5376 :
5377 34054 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
5378 34054 : gccenum = m2type_BuildStartEnumeration (location, reinterpret_cast <char * > (NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (sym))), false);
5379 34054 : enumlist = GetEnumList (sym);
5380 34054 : return m2type_BuildEndEnumeration (location, gccenum, enumlist);
5381 : /* static analysis guarentees a RETURN statement will be used before here. */
5382 : __builtin_unreachable ();
5383 : }
5384 :
5385 :
5386 : /*
5387 : DeclareSubrangeNarrow - will return cardinal, integer, or type depending on whether
5388 : low..high fits in the C data type.
5389 : */
5390 :
5391 100800 : static tree DeclareSubrangeNarrow (location_t location, unsigned int high, unsigned int low, tree type)
5392 : {
5393 100800 : tree m2low;
5394 100800 : tree m2high;
5395 100800 : tree lowtree;
5396 100800 : tree hightree;
5397 :
5398 : /* No zero alignment, therefore the front end will prioritize subranges to match
5399 : unsigned int, int, or ZTYPE assuming the low..high range fits. */
5400 100800 : lowtree = SymbolConversion_Mod2Gcc (low);
5401 100800 : hightree = SymbolConversion_Mod2Gcc (high);
5402 100800 : if ((m2expr_CompareTrees (lowtree, m2expr_GetIntegerZero (location))) >= 0)
5403 : {
5404 : /* avoid dangling else. */
5405 : /* low..high is always positive, can we use unsigned int? */
5406 100544 : m2high = m2type_GetMaxFrom (location, m2type_GetM2CardinalType ());
5407 100544 : if ((m2expr_CompareTrees (hightree, m2high)) <= 0)
5408 : {
5409 100544 : return m2type_GetM2CardinalType ();
5410 : }
5411 : }
5412 : else
5413 : {
5414 : /* Must be a signed subrange base, can we use int? */
5415 256 : m2high = m2type_GetMaxFrom (location, m2type_GetM2IntegerType ());
5416 256 : m2low = m2type_GetMinFrom (location, m2type_GetM2IntegerType ());
5417 256 : if (((m2expr_CompareTrees (lowtree, m2low)) >= 0) && ((m2expr_CompareTrees (hightree, m2high)) <= 0))
5418 : {
5419 256 : return m2type_GetM2IntegerType ();
5420 : }
5421 : }
5422 : /* Fall back to the ZType. */
5423 : return type;
5424 : /* static analysis guarentees a RETURN statement will be used before here. */
5425 : __builtin_unreachable ();
5426 : }
5427 :
5428 :
5429 : /*
5430 : DeclareSubrange - declare a subrange type.
5431 : */
5432 :
5433 161518 : static tree DeclareSubrange (unsigned int sym)
5434 : {
5435 161518 : tree type;
5436 161518 : tree gccsym;
5437 161518 : unsigned int align;
5438 161518 : unsigned int high;
5439 161518 : unsigned int low;
5440 161518 : location_t location;
5441 :
5442 161518 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
5443 161518 : SymbolTable_GetSubrange (sym, &high, &low);
5444 161518 : align = SymbolTable_GetAlignment (sym);
5445 161518 : type = SymbolConversion_Mod2Gcc (SymbolTable_GetSType (sym));
5446 161518 : if (align != SymbolTable_NulSym)
5447 : {
5448 12 : if (m2expr_AreConstantsEqual (m2expr_GetIntegerZero (location), SymbolConversion_Mod2Gcc (align)))
5449 : {
5450 12 : type = m2type_BuildSmallestTypeRange (location, SymbolConversion_Mod2Gcc (low), SymbolConversion_Mod2Gcc (high));
5451 : }
5452 : else
5453 : {
5454 0 : M2MetaError_MetaError1 ((const char *) "a non-zero alignment in a subrange type {%1Wa} is currently not implemented and will be ignored", 95, sym);
5455 : }
5456 : }
5457 161506 : else if ((SymbolTable_GetSType (sym)) == M2Base_ZType)
5458 : {
5459 : /* avoid dangling else. */
5460 : /* Can we narrow the ZType subrange to CARDINAL or INTEGER? */
5461 100800 : type = DeclareSubrangeNarrow (location, high, low, type);
5462 : }
5463 161518 : gccsym = m2type_BuildSubrangeType (location, reinterpret_cast <char * > (NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (sym))), type, SymbolConversion_Mod2Gcc (low), SymbolConversion_Mod2Gcc (high));
5464 161518 : return gccsym;
5465 : /* static analysis guarentees a RETURN statement will be used before here. */
5466 : __builtin_unreachable ();
5467 : }
5468 :
5469 :
5470 : /*
5471 : IncludeGetNth -
5472 : */
5473 :
5474 0 : static void IncludeGetNth (Lists_List l, unsigned int sym)
5475 : {
5476 0 : unsigned int i;
5477 :
5478 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " ListOfFields [", 15);
5479 0 : i = 1;
5480 0 : while ((SymbolTable_GetNth (sym, i)) != SymbolTable_NulSym)
5481 : {
5482 0 : if (i > 1)
5483 : {
5484 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) ", ", 2);
5485 : }
5486 0 : Lists_IncludeItemIntoList (l, SymbolTable_GetNth (sym, i));
5487 0 : PrintTerse (SymbolTable_GetNth (sym, i));
5488 0 : i += 1;
5489 : }
5490 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "]", 1);
5491 0 : }
5492 :
5493 :
5494 : /*
5495 : IncludeType -
5496 : */
5497 :
5498 0 : static void IncludeType (Lists_List l, unsigned int sym)
5499 : {
5500 0 : unsigned int t;
5501 :
5502 0 : t = SymbolTable_GetSType (sym);
5503 0 : if (t != SymbolTable_NulSym)
5504 : {
5505 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " type [", 7);
5506 0 : PrintTerse (t);
5507 0 : Lists_IncludeItemIntoList (l, t);
5508 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "]", 1);
5509 0 : t = SymbolTable_GetVarBackEndType (sym);
5510 0 : if (t != SymbolTable_NulSym)
5511 : {
5512 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " gcc type [", 11);
5513 0 : PrintTerse (t);
5514 0 : Lists_IncludeItemIntoList (l, t);
5515 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "]", 1);
5516 : }
5517 : }
5518 0 : }
5519 :
5520 :
5521 : /*
5522 : IncludeSubscript -
5523 : */
5524 :
5525 0 : static void IncludeSubscript (Lists_List l, unsigned int sym)
5526 : {
5527 0 : unsigned int t;
5528 :
5529 0 : t = SymbolTable_GetArraySubscript (sym);
5530 0 : if (t != SymbolTable_NulSym)
5531 : {
5532 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " subrange [", 11);
5533 0 : PrintTerse (t);
5534 0 : Lists_IncludeItemIntoList (l, t);
5535 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "]", 1);
5536 : }
5537 0 : }
5538 :
5539 :
5540 : /*
5541 : PrintLocalSymbol -
5542 : */
5543 :
5544 0 : static void PrintLocalSymbol (unsigned int sym)
5545 : {
5546 0 : PrintTerse (sym);
5547 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) ", ", 2);
5548 0 : }
5549 :
5550 :
5551 : /*
5552 : PrintLocalSymbols -
5553 : */
5554 :
5555 0 : static void PrintLocalSymbols (unsigned int sym)
5556 : {
5557 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "Local Symbols {", 15);
5558 0 : SymbolTable_ForeachLocalSymDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) PrintLocalSymbol});
5559 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "}", 1);
5560 0 : }
5561 :
5562 :
5563 : /*
5564 : IncludeGetVarient -
5565 : */
5566 :
5567 0 : static void IncludeGetVarient (Lists_List l, unsigned int sym)
5568 : {
5569 0 : if ((SymbolTable_GetVarient (sym)) != SymbolTable_NulSym)
5570 : {
5571 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " Varient [", 10);
5572 0 : PrintTerse (SymbolTable_GetVarient (sym));
5573 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "]", 1);
5574 0 : Lists_IncludeItemIntoList (l, SymbolTable_GetVarient (sym));
5575 : }
5576 0 : }
5577 :
5578 :
5579 : /*
5580 : IncludeUnbounded - includes the record component of an unbounded type.
5581 : */
5582 :
5583 0 : static void IncludeUnbounded (Lists_List l, unsigned int sym)
5584 : {
5585 0 : if ((SymbolTable_GetUnboundedRecordType (sym)) != SymbolTable_NulSym)
5586 : {
5587 0 : Lists_IncludeItemIntoList (l, SymbolTable_GetUnboundedRecordType (sym));
5588 : }
5589 0 : }
5590 :
5591 :
5592 : /*
5593 : IncludePartialUnbounded - includes the type component of a partial unbounded symbol.
5594 : */
5595 :
5596 0 : static void IncludePartialUnbounded (Lists_List l, unsigned int sym)
5597 : {
5598 0 : if ((SymbolTable_GetSType (sym)) != SymbolTable_NulSym)
5599 : {
5600 0 : Lists_IncludeItemIntoList (l, SymbolTable_GetSType (sym));
5601 : }
5602 0 : }
5603 :
5604 :
5605 : /*
5606 : PrintDeclared - prints out where, sym, was declared.
5607 : */
5608 :
5609 0 : static void PrintDeclared (unsigned int sym)
5610 : {
5611 0 : DynamicStrings_String filename;
5612 0 : unsigned int lineno;
5613 0 : unsigned int tokenno;
5614 :
5615 0 : tokenno = SymbolTable_GetDeclaredMod (sym);
5616 0 : filename = M2LexBuf_FindFileNameFromToken (tokenno, 0);
5617 0 : lineno = M2LexBuf_TokenToLineNo (tokenno, 0);
5618 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) " declared in %s:%d", 18, (const unsigned char *) &filename, (sizeof (filename)-1), (const unsigned char *) &lineno, (sizeof (lineno)-1));
5619 0 : }
5620 :
5621 :
5622 : /*
5623 : PrintAlignment -
5624 : */
5625 :
5626 0 : static void PrintAlignment (unsigned int sym)
5627 : {
5628 0 : unsigned int align;
5629 :
5630 0 : if (((((SymbolTable_IsRecord (sym)) || (SymbolTable_IsType (sym))) || (SymbolTable_IsRecordField (sym))) || (SymbolTable_IsPointer (sym))) || (SymbolTable_IsArray (sym)))
5631 : {
5632 0 : align = SymbolTable_GetAlignment (sym);
5633 0 : if (align != SymbolTable_NulSym)
5634 : {
5635 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) " aligned [%d]", 13, (const unsigned char *) &align, (sizeof (align)-1));
5636 : }
5637 : }
5638 0 : }
5639 :
5640 :
5641 : /*
5642 : IncludeGetParent -
5643 : */
5644 :
5645 0 : static void IncludeGetParent (Lists_List l, unsigned int sym)
5646 : {
5647 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " Parent [", 9);
5648 0 : Lists_IncludeItemIntoList (l, SymbolTable_GetParent (sym));
5649 0 : PrintTerse (SymbolTable_GetParent (sym));
5650 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "]", 1);
5651 0 : }
5652 :
5653 :
5654 : /*
5655 : PrintDecl -
5656 : */
5657 :
5658 0 : static void PrintDecl (unsigned int sym)
5659 : {
5660 0 : if (SymbolTable_IsDeclaredPackedResolved (sym))
5661 : {
5662 0 : if (SymbolTable_IsDeclaredPacked (sym))
5663 : {
5664 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " packed", 7);
5665 : }
5666 : else
5667 : {
5668 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " unpacked", 9);
5669 : }
5670 : }
5671 : else
5672 : {
5673 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " unknown if packed", 18);
5674 : }
5675 0 : }
5676 :
5677 :
5678 : /*
5679 : PrintScope - displays the scope and line number of declaration of symbol, sym.
5680 : */
5681 :
5682 0 : static void PrintScope (unsigned int sym)
5683 : {
5684 0 : NameKey_Name name;
5685 0 : unsigned int scope;
5686 0 : unsigned int line;
5687 :
5688 0 : line = M2LexBuf_TokenToLineNo (SymbolTable_GetDeclaredMod (sym), 0);
5689 0 : scope = SymbolTable_GetScope (sym);
5690 0 : name = SymbolTable_GetSymName (scope);
5691 0 : M2Printf_fprintf3 (M2LangDump_GetDumpFile (), (const char *) " scope %a:%d %d", 15, (const unsigned char *) &name, (sizeof (name)-1), (const unsigned char *) &line, (sizeof (line)-1), (const unsigned char *) &scope, (sizeof (scope)-1));
5692 0 : }
5693 :
5694 :
5695 : /*
5696 : PrintKind -
5697 : */
5698 :
5699 0 : static void PrintKind (SymbolTable_ProcedureKind kind)
5700 : {
5701 0 : DynamicStrings_String s;
5702 :
5703 0 : s = SymbolTable_GetProcedureKindDesc (kind);
5704 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) "%s", 2, (const unsigned char *) &s, (sizeof (s)-1));
5705 0 : s = DynamicStrings_KillString (s);
5706 0 : }
5707 :
5708 :
5709 : /*
5710 : PrintProcedureParameters -
5711 : */
5712 :
5713 0 : static void PrintProcedureParameters (unsigned int sym, SymbolTable_ProcedureKind kind)
5714 : {
5715 0 : NameKey_Name typeName;
5716 0 : NameKey_Name paramName;
5717 0 : unsigned int p;
5718 0 : unsigned int i;
5719 0 : unsigned int n;
5720 0 : unsigned int type;
5721 :
5722 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " (", 2);
5723 0 : n = SymbolTable_NoOfParam (sym, kind);
5724 0 : i = 1;
5725 0 : while (i <= n)
5726 : {
5727 0 : if (i > 1)
5728 : {
5729 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "; ", 2);
5730 : }
5731 0 : if (SymbolTable_IsVarParam (sym, kind, i))
5732 : {
5733 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "VAR ", 4);
5734 : }
5735 0 : p = SymbolTable_GetNthParam (sym, kind, i);
5736 0 : paramName = SymbolTable_GetSymName (p);
5737 0 : type = SymbolTable_GetType (p);
5738 0 : typeName = SymbolTable_GetSymName (type);
5739 0 : if (SymbolTable_IsUnboundedParam (sym, kind, i))
5740 : {
5741 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "%a: ARRAY OF %a", 15, (const unsigned char *) ¶mName, (sizeof (paramName)-1), (const unsigned char *) &typeName, (sizeof (typeName)-1));
5742 : }
5743 : else
5744 : {
5745 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "%a: %a", 6, (const unsigned char *) ¶mName, (sizeof (paramName)-1), (const unsigned char *) &typeName, (sizeof (typeName)-1));
5746 : }
5747 0 : i += 1;
5748 : }
5749 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) ")", 1);
5750 0 : }
5751 :
5752 :
5753 : /*
5754 : PrintProcedureReturnType -
5755 : */
5756 :
5757 0 : static void PrintProcedureReturnType (unsigned int sym)
5758 : {
5759 0 : NameKey_Name typeName;
5760 :
5761 0 : if ((SymbolTable_GetType (sym)) != SymbolTable_NulSym)
5762 : {
5763 0 : typeName = SymbolTable_GetSymName (SymbolTable_GetType (sym));
5764 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) " : %a", 5, (const unsigned char *) &typeName, (sizeof (typeName)-1));
5765 : }
5766 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " ;", 2);
5767 0 : }
5768 :
5769 :
5770 : /*
5771 : PrintProcedure -
5772 : */
5773 :
5774 0 : static void PrintProcedure (unsigned int sym)
5775 : {
5776 0 : NameKey_Name n;
5777 0 : SymbolTable_ProcedureKind kind;
5778 :
5779 0 : n = SymbolTable_GetSymName (sym);
5780 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsProcedure (%a)", 23, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
5781 0 : if (SymbolTable_IsProcedureReachable (sym))
5782 : {
5783 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " IsProcedureReachable", 21);
5784 : }
5785 0 : PrintScope (sym);
5786 0 : if (SymbolTable_IsExtern (sym))
5787 : {
5788 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " extern", 7);
5789 : }
5790 0 : if (SymbolTable_IsPublic (sym))
5791 : {
5792 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " public", 7);
5793 : }
5794 0 : if (SymbolTable_IsCtor (sym))
5795 : {
5796 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " ctor", 5);
5797 : }
5798 0 : PrintDeclared (sym);
5799 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "\\n", 2);
5800 0 : for (kind=SymbolTable_ProperProcedure; kind<=SymbolTable_DefProcedure; kind= static_cast<SymbolTable_ProcedureKind>(static_cast<int>(kind+1)))
5801 : {
5802 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " parameters ", 12);
5803 0 : PrintKind (kind);
5804 0 : if (SymbolTable_GetProcedureParametersDefined (sym, kind))
5805 : {
5806 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " defined", 8);
5807 0 : PrintProcedureParameters (sym, kind);
5808 0 : PrintProcedureReturnType (sym);
5809 : }
5810 : else
5811 : {
5812 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " undefined", 10);
5813 : }
5814 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "\\n", 2);
5815 : }
5816 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " Associated proctype: ", 22);
5817 0 : PrintProcType (SymbolTable_GetProcedureProcType (sym));
5818 0 : }
5819 :
5820 :
5821 : /*
5822 : PrintProcTypeParameters -
5823 : */
5824 :
5825 0 : static void PrintProcTypeParameters (unsigned int sym)
5826 : {
5827 0 : NameKey_Name typeName;
5828 0 : unsigned int p;
5829 0 : unsigned int i;
5830 0 : unsigned int n;
5831 0 : unsigned int type;
5832 :
5833 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " (", 2);
5834 0 : n = SymbolTable_NoOfParam (sym, SymbolTable_ProperProcedure);
5835 0 : i = 1;
5836 0 : while (i <= n)
5837 : {
5838 0 : if (i > 1)
5839 : {
5840 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "; ", 2);
5841 : }
5842 0 : if (SymbolTable_IsVarParam (sym, SymbolTable_ProperProcedure, i))
5843 : {
5844 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "VAR ", 4);
5845 : }
5846 0 : p = SymbolTable_GetNthParam (sym, SymbolTable_ProperProcedure, i);
5847 0 : type = SymbolTable_GetType (p);
5848 0 : typeName = SymbolTable_GetSymName (type);
5849 0 : if (SymbolTable_IsUnboundedParam (sym, SymbolTable_ProperProcedure, i))
5850 : {
5851 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) "ARRAY OF %a", 11, (const unsigned char *) &typeName, (sizeof (typeName)-1));
5852 : }
5853 : else
5854 : {
5855 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) "%a", 2, (const unsigned char *) &typeName, (sizeof (typeName)-1));
5856 : }
5857 0 : i += 1;
5858 : }
5859 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) ")", 1);
5860 0 : }
5861 :
5862 :
5863 : /*
5864 : PrintProcType -
5865 : */
5866 :
5867 0 : static void PrintProcType (unsigned int sym)
5868 : {
5869 0 : NameKey_Name n;
5870 :
5871 0 : n = SymbolTable_GetSymName (sym);
5872 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsProcType (%a)", 22, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
5873 0 : PrintScope (sym);
5874 0 : PrintDeclared (sym);
5875 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "\\n", 2);
5876 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "parameters ", 11);
5877 0 : PrintProcTypeParameters (sym);
5878 0 : PrintProcedureReturnType (sym);
5879 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "\\n", 2);
5880 0 : }
5881 :
5882 :
5883 : /*
5884 : PrintString -
5885 : */
5886 :
5887 0 : static void PrintString (unsigned int sym)
5888 : {
5889 0 : unsigned int len;
5890 0 : unsigned int tokenno;
5891 :
5892 0 : if (SymbolTable_IsConstStringKnown (sym))
5893 : {
5894 0 : if (SymbolTable_IsConstStringM2 (sym))
5895 : {
5896 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "a Modula-2 string", 17);
5897 : }
5898 0 : else if (SymbolTable_IsConstStringC (sym))
5899 : {
5900 : /* avoid dangling else. */
5901 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " a C string", 11);
5902 : }
5903 0 : else if (SymbolTable_IsConstStringM2nul (sym))
5904 : {
5905 : /* avoid dangling else. */
5906 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " a nul terminated Modula-2 string", 33);
5907 : }
5908 0 : else if (SymbolTable_IsConstStringCnul (sym))
5909 : {
5910 : /* avoid dangling else. */
5911 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " a nul terminated C string", 26);
5912 : }
5913 0 : tokenno = SymbolTable_GetDeclaredMod (sym);
5914 0 : len = SymbolTable_GetStringLength (tokenno, sym);
5915 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) " length %d", 10, (const unsigned char *) &len, (sizeof (len)-1));
5916 : }
5917 : else
5918 : {
5919 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "is not currently known", 22);
5920 : }
5921 0 : }
5922 :
5923 :
5924 : /*
5925 : PrintVerboseFromList - prints the, i, th element in the list, l.
5926 : */
5927 :
5928 0 : static void PrintVerboseFromList (Lists_List l, unsigned int i)
5929 : {
5930 0 : unsigned int type;
5931 0 : unsigned int low;
5932 0 : unsigned int high;
5933 0 : unsigned int sym;
5934 0 : NameKey_Name n;
5935 0 : NameKey_Name n2;
5936 :
5937 0 : sym = static_cast<unsigned int> (Lists_GetItemFromList (l, i));
5938 0 : n = SymbolTable_GetSymName (sym);
5939 0 : if (SymbolTable_IsError (sym))
5940 : {
5941 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsError (%a)", 19, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
5942 : }
5943 0 : else if (SymbolTable_IsDefImp (sym))
5944 : {
5945 : /* avoid dangling else. */
5946 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsDefImp (%a)", 20, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
5947 0 : if (SymbolTable_IsDefinitionForC (sym))
5948 : {
5949 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "and IsDefinitionForC", 20);
5950 : }
5951 0 : if (SymbolTable_IsHiddenTypeDeclared (sym))
5952 : {
5953 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " IsHiddenTypeDeclared", 21);
5954 : }
5955 0 : SymbolTable_ForeachProcedureDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) PrintProcedure});
5956 : }
5957 0 : else if (SymbolTable_IsModule (sym))
5958 : {
5959 : /* avoid dangling else. */
5960 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsModule (%a)", 20, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
5961 0 : if (SymbolTable_IsModuleWithinProcedure (sym))
5962 : {
5963 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " and IsModuleWithinProcedure", 28);
5964 : }
5965 : }
5966 0 : else if (SymbolTable_IsInnerModule (sym))
5967 : {
5968 : /* avoid dangling else. */
5969 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsInnerModule (%a)", 25, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
5970 : }
5971 0 : else if (SymbolTable_IsUnknown (sym))
5972 : {
5973 : /* avoid dangling else. */
5974 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsUnknown (%a)", 21, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
5975 : }
5976 0 : else if (SymbolTable_IsType (sym))
5977 : {
5978 : /* avoid dangling else. */
5979 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsType (%a)", 18, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
5980 0 : IncludeType (l, sym);
5981 0 : PrintAlignment (sym);
5982 : }
5983 0 : else if (SymbolTable_IsProcedure (sym))
5984 : {
5985 : /* avoid dangling else. */
5986 0 : PrintProcedure (sym);
5987 : }
5988 0 : else if (SymbolTable_IsParameter (sym))
5989 : {
5990 : /* avoid dangling else. */
5991 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsParameter (%a)", 23, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
5992 0 : if ((SymbolTable_GetParameterShadowVar (sym)) == SymbolTable_NulSym)
5993 : {
5994 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " no shadow local variable", 25);
5995 : }
5996 : else
5997 : {
5998 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " shadow ", 8);
5999 : /* PrintVerboseFromList(l, GetParameterShadowVar(sym)) */
6000 0 : IncludeType (l, SymbolTable_GetParameterShadowVar (sym));
6001 : }
6002 0 : IncludeType (l, sym);
6003 : }
6004 0 : else if (SymbolTable_IsPointer (sym))
6005 : {
6006 : /* avoid dangling else. */
6007 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsPointer (%a)", 21, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6008 0 : IncludeType (l, sym);
6009 0 : PrintAlignment (sym);
6010 : }
6011 0 : else if (SymbolTable_IsRecord (sym))
6012 : {
6013 : /* avoid dangling else. */
6014 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsRecord (%a)", 20, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6015 0 : PrintLocalSymbols (sym);
6016 0 : IncludeGetNth (l, sym);
6017 0 : PrintAlignment (sym);
6018 0 : PrintDecl (sym);
6019 : }
6020 0 : else if (SymbolTable_IsVarient (sym))
6021 : {
6022 : /* avoid dangling else. */
6023 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsVarient (%a)", 21, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6024 0 : PrintDecl (sym);
6025 0 : IncludeGetNth (l, sym);
6026 0 : IncludeGetVarient (l, sym);
6027 0 : IncludeGetParent (l, sym);
6028 : }
6029 0 : else if (SymbolTable_IsFieldVarient (sym))
6030 : {
6031 : /* avoid dangling else. */
6032 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsFieldVarient (%a)", 26, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6033 0 : PrintDecl (sym);
6034 0 : IncludeGetNth (l, sym);
6035 0 : IncludeGetVarient (l, sym);
6036 0 : IncludeGetParent (l, sym);
6037 : }
6038 0 : else if (SymbolTable_IsFieldEnumeration (sym))
6039 : {
6040 : /* avoid dangling else. */
6041 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsFieldEnumeration (%a)", 30, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6042 : }
6043 0 : else if (SymbolTable_IsArray (sym))
6044 : {
6045 : /* avoid dangling else. */
6046 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsArray (%a)", 19, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6047 0 : IncludeSubscript (l, sym);
6048 0 : IncludeType (l, sym);
6049 0 : PrintAlignment (sym);
6050 : }
6051 0 : else if (SymbolTable_IsEnumeration (sym))
6052 : {
6053 : /* avoid dangling else. */
6054 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsEnumeration (%a)", 25, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6055 : }
6056 0 : else if (SymbolTable_IsSet (sym))
6057 : {
6058 : /* avoid dangling else. */
6059 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsSet (%a)", 17, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6060 0 : IncludeType (l, sym);
6061 : }
6062 0 : else if (SymbolTable_IsUnbounded (sym))
6063 : {
6064 : /* avoid dangling else. */
6065 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsUnbounded (%a)", 23, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6066 0 : IncludeUnbounded (l, sym);
6067 : }
6068 0 : else if (SymbolTable_IsPartialUnbounded (sym))
6069 : {
6070 : /* avoid dangling else. */
6071 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsPartialUnbounded (%a)", 30, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6072 0 : IncludePartialUnbounded (l, sym);
6073 : }
6074 0 : else if (SymbolTable_IsRecordField (sym))
6075 : {
6076 : /* avoid dangling else. */
6077 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsRecordField (%a)", 25, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6078 0 : if (SymbolTable_IsRecordFieldAVarientTag (sym))
6079 : {
6080 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " variant tag", 12);
6081 : }
6082 0 : IncludeType (l, sym);
6083 0 : IncludeGetVarient (l, sym);
6084 0 : IncludeGetParent (l, sym);
6085 0 : PrintAlignment (sym);
6086 0 : PrintDecl (sym);
6087 : }
6088 0 : else if (SymbolTable_IsProcType (sym))
6089 : {
6090 : /* avoid dangling else. */
6091 0 : PrintProcType (sym);
6092 : }
6093 0 : else if (SymbolTable_IsVar (sym))
6094 : {
6095 : /* avoid dangling else. */
6096 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsVar (%a) declared in ", 30, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6097 0 : PrintScope (sym);
6098 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "mode ", 5);
6099 0 : switch (SymbolTable_GetMode (sym))
6100 : {
6101 0 : case SymbolTable_LeftValue:
6102 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "l ", 2);
6103 0 : break;
6104 :
6105 0 : case SymbolTable_RightValue:
6106 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "r ", 2);
6107 0 : break;
6108 :
6109 0 : case SymbolTable_ImmediateValue:
6110 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "i ", 2);
6111 0 : break;
6112 :
6113 0 : case SymbolTable_NoValue:
6114 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "n ", 2);
6115 0 : break;
6116 :
6117 :
6118 0 : default:
6119 0 : CaseException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2GCCDeclare.def", 20, 1);
6120 0 : __builtin_unreachable ();
6121 : }
6122 0 : if (SymbolTable_IsTemporary (sym))
6123 : {
6124 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "temporary ", 10);
6125 : }
6126 0 : if (SymbolTable_IsComponent (sym))
6127 : {
6128 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "component ", 10);
6129 : }
6130 0 : if (SymbolTable_IsVarHeap (sym))
6131 : {
6132 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "heap ", 5);
6133 : }
6134 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "\\n", 2);
6135 0 : SymbolTable_PrintInitialized (sym);
6136 0 : IncludeType (l, sym);
6137 : }
6138 0 : else if (SymbolTable_IsConst (sym))
6139 : {
6140 : /* avoid dangling else. */
6141 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsConst (%a)", 19, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6142 0 : if (SymbolTable_IsConstString (sym))
6143 : {
6144 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) " also IsConstString (%a)", 25, (const unsigned char *) &n, (sizeof (n)-1));
6145 0 : PrintString (sym);
6146 : }
6147 0 : else if (SymbolTable_IsConstructor (sym))
6148 : {
6149 : /* avoid dangling else. */
6150 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " constant constructor ", 22);
6151 0 : IncludeType (l, sym);
6152 : }
6153 0 : else if (SymbolTable_IsConstSet (sym))
6154 : {
6155 : /* avoid dangling else. */
6156 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " constant constructor set ", 26);
6157 0 : IncludeType (l, sym);
6158 : }
6159 : else
6160 : {
6161 : /* avoid dangling else. */
6162 0 : IncludeType (l, sym);
6163 : }
6164 : }
6165 0 : else if (SymbolTable_IsConstructor (sym))
6166 : {
6167 : /* avoid dangling else. */
6168 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsConstructor (non constant) (%a)", 40, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6169 0 : IncludeType (l, sym);
6170 : }
6171 0 : else if (SymbolTable_IsConstLit (sym))
6172 : {
6173 : /* avoid dangling else. */
6174 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsConstLit (%a)", 22, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6175 : }
6176 0 : else if (SymbolTable_IsDummy (sym))
6177 : {
6178 : /* avoid dangling else. */
6179 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsDummy (%a)", 19, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6180 : }
6181 0 : else if (SymbolTable_IsTemporary (sym))
6182 : {
6183 : /* avoid dangling else. */
6184 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsTemporary (%a)", 23, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6185 : }
6186 0 : else if (SymbolTable_IsVarAParam (sym))
6187 : {
6188 : /* avoid dangling else. */
6189 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsVarAParam (%a)", 23, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6190 : }
6191 0 : else if (SymbolTable_IsSubscript (sym))
6192 : {
6193 : /* avoid dangling else. */
6194 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsSubscript (%a)", 23, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6195 : }
6196 0 : else if (SymbolTable_IsSubrange (sym))
6197 : {
6198 : /* avoid dangling else. */
6199 0 : SymbolTable_GetSubrange (sym, &high, &low);
6200 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsSubrange (%a)", 22, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6201 0 : if ((low != SymbolTable_NulSym) && (high != SymbolTable_NulSym))
6202 : {
6203 0 : type = SymbolTable_GetSType (sym);
6204 0 : if (type != SymbolTable_NulSym)
6205 : {
6206 0 : IncludeType (l, sym);
6207 0 : n = SymbolTable_GetSymName (type);
6208 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) " %a", 3, (const unsigned char *) &n, (sizeof (n)-1));
6209 : }
6210 0 : n = SymbolTable_GetSymName (low);
6211 0 : n2 = SymbolTable_GetSymName (high);
6212 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "[%a..%a]", 8, (const unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) &n2, (sizeof (n2)-1));
6213 : }
6214 : }
6215 0 : else if (SymbolTable_IsProcedureVariable (sym))
6216 : {
6217 : /* avoid dangling else. */
6218 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsProcedureVariable (%a)", 31, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6219 : }
6220 0 : else if (SymbolTable_IsProcedureNested (sym))
6221 : {
6222 : /* avoid dangling else. */
6223 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsProcedureNested (%a)", 29, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6224 : }
6225 0 : else if (SymbolTable_IsAModula2Type (sym))
6226 : {
6227 : /* avoid dangling else. */
6228 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsAModula2Type (%a)", 26, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6229 : }
6230 0 : else if (SymbolTable_IsObject (sym))
6231 : {
6232 : /* avoid dangling else. */
6233 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsObject (%a)", 20, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6234 : }
6235 0 : else if (SymbolTable_IsTuple (sym))
6236 : {
6237 : /* avoid dangling else. */
6238 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsTuple (%a)", 19, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6239 0 : low = SymbolTable_GetNth (sym, 1);
6240 0 : high = SymbolTable_GetNth (sym, 2);
6241 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "%d, %d\\n", 8, (const unsigned char *) &low, (sizeof (low)-1), (const unsigned char *) &high, (sizeof (high)-1));
6242 : }
6243 0 : else if (SymbolTable_IsGnuAsm (sym))
6244 : {
6245 : /* avoid dangling else. */
6246 0 : if (SymbolTable_IsGnuAsmVolatile (sym))
6247 : {
6248 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsGnuAsmVolatile (%a)", 28, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6249 : }
6250 : else
6251 : {
6252 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsGnuAsm (%a)", 20, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6253 : }
6254 : }
6255 0 : else if (SymbolTable_IsComponent (sym))
6256 : {
6257 : /* avoid dangling else. */
6258 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsComponent (%a) ", 24, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6259 0 : i = 1;
6260 0 : do {
6261 0 : type = SymbolTable_GetNth (sym, i);
6262 0 : if (type != SymbolTable_NulSym)
6263 : {
6264 0 : Lists_IncludeItemIntoList (l, type);
6265 0 : n = SymbolTable_GetSymName (type);
6266 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "[%a %d] ", 8, (const unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) &type, (sizeof (type)-1));
6267 0 : i += 1;
6268 : }
6269 0 : } while (! (type == SymbolTable_NulSym));
6270 : }
6271 0 : if (SymbolTable_IsHiddenType (sym))
6272 : {
6273 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " IsHiddenType", 13);
6274 : }
6275 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "\\n", 2);
6276 0 : }
6277 :
6278 :
6279 : /*
6280 : PrintVerbose - prints limited information about a symbol.
6281 : */
6282 :
6283 0 : static void PrintVerbose (unsigned int sym)
6284 : {
6285 0 : Lists_List l;
6286 0 : unsigned int i;
6287 :
6288 0 : Lists_InitList (&l);
6289 0 : Lists_IncludeItemIntoList (l, sym);
6290 0 : i = 1;
6291 0 : while (i <= (Lists_NoOfItemsInList (l)))
6292 : {
6293 0 : PrintVerboseFromList (l, i);
6294 0 : i += 1;
6295 : }
6296 0 : Lists_KillList (&l);
6297 0 : }
6298 :
6299 :
6300 : /*
6301 : PrintTerse -
6302 : */
6303 :
6304 0 : static void PrintTerse (unsigned int sym)
6305 : {
6306 0 : NameKey_Name n;
6307 :
6308 0 : n = SymbolTable_GetSymName (sym);
6309 0 : if (SymbolTable_IsError (sym))
6310 : {
6311 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsError (%a)", 19, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6312 : }
6313 0 : else if (SymbolTable_IsDefImp (sym))
6314 : {
6315 : /* avoid dangling else. */
6316 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsDefImp (%a)", 20, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6317 0 : if (SymbolTable_IsDefinitionForC (sym))
6318 : {
6319 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "and IsDefinitionForC", 20);
6320 : }
6321 0 : if (SymbolTable_IsHiddenTypeDeclared (sym))
6322 : {
6323 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " IsHiddenTypeDeclared", 21);
6324 : }
6325 : }
6326 0 : else if (SymbolTable_IsModule (sym))
6327 : {
6328 : /* avoid dangling else. */
6329 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsModule (%a)", 20, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6330 0 : if (SymbolTable_IsModuleWithinProcedure (sym))
6331 : {
6332 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " and IsModuleWithinProcedure", 28);
6333 : }
6334 : }
6335 0 : else if (SymbolTable_IsInnerModule (sym))
6336 : {
6337 : /* avoid dangling else. */
6338 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsInnerModule (%a)", 25, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6339 : }
6340 0 : else if (SymbolTable_IsUnknown (sym))
6341 : {
6342 : /* avoid dangling else. */
6343 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsUnknown (%a)", 21, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6344 : }
6345 0 : else if (SymbolTable_IsType (sym))
6346 : {
6347 : /* avoid dangling else. */
6348 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsType (%a)", 18, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6349 : }
6350 0 : else if (SymbolTable_IsProcedure (sym))
6351 : {
6352 : /* avoid dangling else. */
6353 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsProcedure (%a)", 23, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6354 0 : if (SymbolTable_IsProcedureReachable (sym))
6355 : {
6356 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " and IsProcedureReachable", 25);
6357 : }
6358 : }
6359 0 : else if (SymbolTable_IsParameter (sym))
6360 : {
6361 : /* avoid dangling else. */
6362 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsParameter (%a)", 23, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6363 : }
6364 0 : else if (SymbolTable_IsPointer (sym))
6365 : {
6366 : /* avoid dangling else. */
6367 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsPointer (%a)", 21, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6368 : }
6369 0 : else if (SymbolTable_IsRecord (sym))
6370 : {
6371 : /* avoid dangling else. */
6372 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsRecord (%a)", 20, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6373 : }
6374 0 : else if (SymbolTable_IsVarient (sym))
6375 : {
6376 : /* avoid dangling else. */
6377 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsVarient (%a)", 21, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6378 : }
6379 0 : else if (SymbolTable_IsFieldVarient (sym))
6380 : {
6381 : /* avoid dangling else. */
6382 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsFieldVarient (%a)", 26, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6383 : }
6384 0 : else if (SymbolTable_IsFieldEnumeration (sym))
6385 : {
6386 : /* avoid dangling else. */
6387 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsFieldEnumeration (%a)", 30, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6388 : }
6389 0 : else if (SymbolTable_IsArray (sym))
6390 : {
6391 : /* avoid dangling else. */
6392 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsArray (%a)", 19, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6393 : }
6394 0 : else if (SymbolTable_IsEnumeration (sym))
6395 : {
6396 : /* avoid dangling else. */
6397 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsEnumeration (%a)", 25, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6398 : }
6399 0 : else if (SymbolTable_IsSet (sym))
6400 : {
6401 : /* avoid dangling else. */
6402 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsSet (%a)", 17, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6403 : }
6404 0 : else if (SymbolTable_IsUnbounded (sym))
6405 : {
6406 : /* avoid dangling else. */
6407 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsUnbounded (%a)", 23, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6408 : }
6409 0 : else if (SymbolTable_IsRecordField (sym))
6410 : {
6411 : /* avoid dangling else. */
6412 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsRecordField (%a)", 25, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6413 : }
6414 0 : else if (SymbolTable_IsProcType (sym))
6415 : {
6416 : /* avoid dangling else. */
6417 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsProcType (%a)", 22, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6418 : }
6419 0 : else if (SymbolTable_IsVar (sym))
6420 : {
6421 : /* avoid dangling else. */
6422 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsVar (%a)", 17, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6423 : }
6424 0 : else if (SymbolTable_IsConstString (sym))
6425 : {
6426 : /* avoid dangling else. */
6427 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsConstString (%a)", 25, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6428 : }
6429 0 : else if (SymbolTable_IsConst (sym))
6430 : {
6431 : /* avoid dangling else. */
6432 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsConst (%a)", 19, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6433 : }
6434 0 : else if (SymbolTable_IsConstLit (sym))
6435 : {
6436 : /* avoid dangling else. */
6437 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsConstLit (%a)", 22, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6438 : }
6439 0 : else if (SymbolTable_IsDummy (sym))
6440 : {
6441 : /* avoid dangling else. */
6442 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsDummy (%a)", 19, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6443 : }
6444 0 : else if (SymbolTable_IsTemporary (sym))
6445 : {
6446 : /* avoid dangling else. */
6447 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsTemporary (%a)", 23, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6448 : }
6449 0 : else if (SymbolTable_IsVarAParam (sym))
6450 : {
6451 : /* avoid dangling else. */
6452 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsVarAParam (%a)", 23, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6453 : }
6454 0 : else if (SymbolTable_IsSubscript (sym))
6455 : {
6456 : /* avoid dangling else. */
6457 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsSubscript (%a)", 23, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6458 : }
6459 0 : else if (SymbolTable_IsSubrange (sym))
6460 : {
6461 : /* avoid dangling else. */
6462 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsSubrange (%a)", 22, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6463 : }
6464 0 : else if (SymbolTable_IsProcedureVariable (sym))
6465 : {
6466 : /* avoid dangling else. */
6467 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsProcedureVariable (%a)", 31, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6468 : }
6469 0 : else if (SymbolTable_IsProcedureNested (sym))
6470 : {
6471 : /* avoid dangling else. */
6472 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsProcedureNested (%a)", 29, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6473 : }
6474 0 : else if (SymbolTable_IsAModula2Type (sym))
6475 : {
6476 : /* avoid dangling else. */
6477 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsAModula2Type (%a)", 26, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6478 : }
6479 0 : else if (SymbolTable_IsGnuAsm (sym))
6480 : {
6481 : /* avoid dangling else. */
6482 0 : M2Printf_fprintf2 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsGnuAsm (%a)", 20, (const unsigned char *) &sym, (sizeof (sym)-1), (const unsigned char *) &n, (sizeof (n)-1));
6483 : }
6484 0 : else if (SymbolTable_IsImport (sym))
6485 : {
6486 : /* avoid dangling else. */
6487 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsImport", 15, (const unsigned char *) &sym, (sizeof (sym)-1));
6488 : }
6489 0 : else if (SymbolTable_IsImportStatement (sym))
6490 : {
6491 : /* avoid dangling else. */
6492 0 : M2Printf_fprintf1 (M2LangDump_GetDumpFile (), (const char *) "sym %d IsImportStatement", 24, (const unsigned char *) &sym, (sizeof (sym)-1));
6493 : }
6494 0 : if (SymbolTable_IsHiddenType (sym))
6495 : {
6496 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) " IsHiddenType", 13);
6497 : }
6498 0 : }
6499 :
6500 :
6501 : /*
6502 : CheckAlignment -
6503 : */
6504 :
6505 1260315 : static tree CheckAlignment (tree type, unsigned int sym)
6506 : {
6507 1260315 : unsigned int align;
6508 :
6509 1260315 : align = SymbolTable_GetAlignment (sym);
6510 1260315 : if (align != SymbolTable_NulSym)
6511 : {
6512 192 : M2ALU_PushInt (0);
6513 192 : SymbolTable_PushValue (align);
6514 192 : if (! (M2ALU_Equ (SymbolTable_GetDeclaredMod (sym))))
6515 : {
6516 84 : return m2type_SetAlignment (type, SymbolConversion_Mod2Gcc (SymbolTable_GetAlignment (sym)));
6517 : }
6518 : }
6519 : return type;
6520 : /* static analysis guarentees a RETURN statement will be used before here. */
6521 : __builtin_unreachable ();
6522 : }
6523 :
6524 :
6525 : /*
6526 : CheckPragma -
6527 : */
6528 :
6529 501523 : static tree CheckPragma (tree type, unsigned int sym)
6530 : {
6531 501523 : if (SymbolTable_IsDeclaredPacked (sym))
6532 : {
6533 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
6534 144 : if ((SymbolTable_IsRecordField (sym)) || (SymbolTable_IsFieldVarient (sym)))
6535 : {
6536 108 : type = m2type_SetDeclPacked (type);
6537 : }
6538 36 : else if ((SymbolTable_IsRecord (sym)) || (SymbolTable_IsVarient (sym)))
6539 : {
6540 : /* avoid dangling else. */
6541 36 : type = m2type_SetTypePacked (type);
6542 : }
6543 : }
6544 501523 : return CheckAlignment (type, sym);
6545 : /* static analysis guarentees a RETURN statement will be used before here. */
6546 : __builtin_unreachable ();
6547 : }
6548 :
6549 :
6550 : /*
6551 : IsZero - returns TRUE if symbol, sym, is zero.
6552 : */
6553 :
6554 36 : static bool IsZero (unsigned int sym)
6555 : {
6556 36 : M2ALU_PushIntegerTree (SymbolConversion_Mod2Gcc (sym));
6557 36 : M2ALU_PushInt (0);
6558 36 : return M2ALU_Equ (SymbolTable_GetDeclaredMod (sym));
6559 : /* static analysis guarentees a RETURN statement will be used before here. */
6560 : __builtin_unreachable ();
6561 : }
6562 :
6563 :
6564 : /*
6565 : SetFieldPacked - sets Varient, VarientField and RecordField symbols
6566 : as packed.
6567 : */
6568 :
6569 360 : static void SetFieldPacked (unsigned int field)
6570 : {
6571 360 : if (((SymbolTable_IsVarient (field)) || (SymbolTable_IsFieldVarient (field))) || (SymbolTable_IsRecordField (field)))
6572 : {
6573 108 : SymbolTable_PutDeclaredPacked (field, true);
6574 : }
6575 360 : }
6576 :
6577 :
6578 : /*
6579 : RecordPacked - indicates that record, sym, and its fields
6580 : are all packed.
6581 : */
6582 :
6583 36 : static void RecordPacked (unsigned int sym)
6584 : {
6585 36 : SymbolTable_PutDeclaredPacked (sym, true);
6586 36 : WalkRecordDependants (sym, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) SetFieldPacked});
6587 36 : }
6588 :
6589 :
6590 : /*
6591 : SetFieldNotPacked - sets Varient, VarientField and RecordField symbols
6592 : as not packed.
6593 : */
6594 :
6595 815920 : static void SetFieldNotPacked (unsigned int field)
6596 : {
6597 815920 : if (((SymbolTable_IsVarient (field)) || (SymbolTable_IsFieldVarient (field))) || (SymbolTable_IsRecordField (field)))
6598 : {
6599 413930 : SymbolTable_PutDeclaredPacked (field, false);
6600 : }
6601 815920 : }
6602 :
6603 :
6604 : /*
6605 : RecordNotPacked - indicates that record, sym, and its fields
6606 : are all not packed.
6607 : */
6608 :
6609 99317 : static void RecordNotPacked (unsigned int sym)
6610 : {
6611 99317 : SymbolTable_PutDeclaredPacked (sym, false);
6612 99317 : WalkRecordDependants (sym, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) SetFieldNotPacked});
6613 99317 : }
6614 :
6615 :
6616 : /*
6617 : DetermineIfRecordPacked -
6618 : */
6619 :
6620 99353 : static void DetermineIfRecordPacked (unsigned int sym)
6621 : {
6622 99353 : unsigned int defaultAlignment;
6623 :
6624 99353 : defaultAlignment = SymbolTable_GetDefaultRecordFieldAlignment (sym);
6625 99353 : if ((defaultAlignment != SymbolTable_NulSym) && (IsZero (defaultAlignment)))
6626 : {
6627 36 : RecordPacked (sym);
6628 : }
6629 : else
6630 : {
6631 99317 : RecordNotPacked (sym);
6632 : }
6633 99353 : }
6634 :
6635 :
6636 : /*
6637 : DeclarePackedSubrange -
6638 : */
6639 :
6640 60 : static void DeclarePackedSubrange (unsigned int equiv, unsigned int sym)
6641 : {
6642 60 : tree type;
6643 60 : tree gccsym;
6644 60 : unsigned int high;
6645 60 : unsigned int low;
6646 60 : location_t location;
6647 :
6648 60 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
6649 60 : SymbolTable_GetSubrange (sym, &high, &low);
6650 60 : type = m2type_BuildSmallestTypeRange (location, SymbolConversion_Mod2Gcc (low), SymbolConversion_Mod2Gcc (high));
6651 60 : gccsym = m2type_BuildSubrangeType (location, reinterpret_cast <char * > (NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (sym))), type, SymbolConversion_Mod2Gcc (low), SymbolConversion_Mod2Gcc (high));
6652 60 : SymbolConversion_AddModGcc (equiv, gccsym);
6653 60 : }
6654 :
6655 :
6656 : /*
6657 : DeclarePackedSet -
6658 : */
6659 :
6660 0 : static void DeclarePackedSet (unsigned int equiv, unsigned int sym)
6661 : {
6662 0 : tree highLimit;
6663 0 : tree range;
6664 0 : tree gccsym;
6665 0 : unsigned int type;
6666 0 : unsigned int high;
6667 0 : unsigned int low;
6668 0 : location_t location;
6669 :
6670 0 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
6671 0 : M2Debug_Assert (SymbolTable_IsSet (sym));
6672 0 : type = SymbolTable_GetDType (sym); /* Was GetSType. */
6673 0 : low = M2GCCDeclare_GetTypeMin (type); /* Was GetSType. */
6674 0 : high = M2GCCDeclare_GetTypeMax (type);
6675 0 : highLimit = m2expr_BuildSub (location, SymbolConversion_Mod2Gcc (high), SymbolConversion_Mod2Gcc (low), false);
6676 : /* --fixme-- we need to check that low <= WORDLENGTH. */
6677 0 : highLimit = m2expr_BuildLSL (location, m2expr_GetIntegerOne (location), highLimit, false);
6678 0 : range = m2type_BuildSmallestTypeRange (location, m2expr_GetIntegerZero (location), highLimit);
6679 0 : gccsym = m2type_BuildSubrangeType (location, reinterpret_cast <char * > (NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (sym))), range, m2expr_GetIntegerZero (location), highLimit);
6680 0 : SymbolConversion_AddModGcc (equiv, gccsym);
6681 0 : }
6682 :
6683 120 : static void DeclarePackedFieldEnumeration (unsigned int sym)
6684 : {
6685 120 : unsigned int equiv;
6686 120 : unsigned int type;
6687 120 : tree field;
6688 120 : tree enumlist;
6689 :
6690 : /* add relationship between gccSym and sym */
6691 120 : type = SymbolTable_GetSType (sym);
6692 120 : equiv = SymbolTable_GetPackedEquivalent (type);
6693 120 : enumlist = GetEnumList (equiv);
6694 120 : SymbolTable_PushValue (sym);
6695 120 : field = DeclareFieldValue (sym, M2ALU_PopIntegerTree (), &enumlist);
6696 120 : M2Debug_Assert (field != NULL);
6697 120 : PutEnumList (equiv, enumlist);
6698 120 : }
6699 :
6700 :
6701 : /*
6702 : DeclarePackedEnumeration -
6703 : */
6704 :
6705 36 : static void DeclarePackedEnumeration (unsigned int equiv, unsigned int sym)
6706 : {
6707 36 : tree enumlist;
6708 36 : tree gccenum;
6709 36 : location_t location;
6710 :
6711 36 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
6712 36 : gccenum = m2type_BuildStartEnumeration (location, reinterpret_cast <char * > (NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (sym))), true);
6713 36 : SymbolTable_ForeachLocalSymDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DeclarePackedFieldEnumeration});
6714 36 : enumlist = GetEnumList (equiv);
6715 36 : gccenum = m2type_BuildEndEnumeration (location, gccenum, enumlist);
6716 36 : SymbolConversion_AddModGcc (equiv, gccenum);
6717 36 : }
6718 :
6719 :
6720 : /*
6721 : DeclarePackedType -
6722 : */
6723 :
6724 0 : static void DeclarePackedType (unsigned int equiv, unsigned int sym)
6725 : {
6726 0 : unsigned int type;
6727 :
6728 0 : type = SymbolTable_GetSType (sym);
6729 0 : if (type == SymbolTable_NulSym)
6730 : {
6731 0 : if (sym == M2Base_Boolean)
6732 : {
6733 0 : SymbolConversion_AddModGcc (equiv, m2type_GetPackedBooleanType ());
6734 : }
6735 : else
6736 : {
6737 0 : SymbolConversion_AddModGcc (equiv, SymbolConversion_Mod2Gcc (sym));
6738 : }
6739 : }
6740 : else
6741 : {
6742 0 : DeclarePackedType (SymbolTable_GetPackedEquivalent (type), type);
6743 0 : SymbolConversion_AddModGcc (equiv, SymbolConversion_Mod2Gcc (SymbolTable_GetPackedEquivalent (type)));
6744 : }
6745 0 : }
6746 :
6747 :
6748 : /*
6749 : doDeclareEquivalent -
6750 : */
6751 :
6752 216 : static tree doDeclareEquivalent (unsigned int sym, M2GCCDeclare_doDeclareProcedure p)
6753 : {
6754 216 : unsigned int equiv;
6755 :
6756 216 : equiv = SymbolTable_GetPackedEquivalent (sym);
6757 216 : if (! (SymbolConversion_GccKnowsAbout (equiv)))
6758 : {
6759 96 : (*p.proc) (equiv, sym);
6760 96 : Sets_IncludeElementIntoSet (GlobalGroup->FullyDeclared, equiv);
6761 : }
6762 216 : return SymbolConversion_Mod2Gcc (equiv);
6763 : /* static analysis guarentees a RETURN statement will be used before here. */
6764 : __builtin_unreachable ();
6765 : }
6766 :
6767 :
6768 : /*
6769 : PossiblyPacked -
6770 : */
6771 :
6772 402170 : static tree PossiblyPacked (unsigned int sym, bool isPacked)
6773 : {
6774 402170 : if (isPacked)
6775 : {
6776 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
6777 108 : if (SymbolTable_IsSubrange (sym))
6778 : {
6779 60 : return doDeclareEquivalent (sym, (M2GCCDeclare_doDeclareProcedure) {(M2GCCDeclare_doDeclareProcedure_t) DeclarePackedSubrange});
6780 : }
6781 48 : else if (SymbolTable_IsType (sym))
6782 : {
6783 : /* avoid dangling else. */
6784 0 : return doDeclareEquivalent (sym, (M2GCCDeclare_doDeclareProcedure) {(M2GCCDeclare_doDeclareProcedure_t) DeclarePackedType});
6785 : }
6786 48 : else if (SymbolTable_IsEnumeration (sym))
6787 : {
6788 : /* avoid dangling else. */
6789 48 : return doDeclareEquivalent (sym, (M2GCCDeclare_doDeclareProcedure) {(M2GCCDeclare_doDeclareProcedure_t) DeclarePackedEnumeration});
6790 : }
6791 0 : else if (SymbolTable_IsSet (sym))
6792 : {
6793 : /* avoid dangling else. */
6794 0 : return doDeclareEquivalent (sym, (M2GCCDeclare_doDeclareProcedure) {(M2GCCDeclare_doDeclareProcedure_t) DeclarePackedSet});
6795 : }
6796 : }
6797 402062 : return SymbolConversion_Mod2Gcc (sym);
6798 : /* static analysis guarentees a RETURN statement will be used before here. */
6799 : __builtin_unreachable ();
6800 : }
6801 :
6802 :
6803 : /*
6804 : GetPackedType - returns a possibly packed type for field.
6805 : */
6806 :
6807 108 : static tree GetPackedType (unsigned int sym)
6808 : {
6809 108 : if (SymbolTable_IsSubrange (sym))
6810 : {
6811 60 : return doDeclareEquivalent (sym, (M2GCCDeclare_doDeclareProcedure) {(M2GCCDeclare_doDeclareProcedure_t) DeclarePackedSubrange});
6812 : }
6813 48 : else if (SymbolTable_IsType (sym))
6814 : {
6815 : /* avoid dangling else. */
6816 0 : return doDeclareEquivalent (sym, (M2GCCDeclare_doDeclareProcedure) {(M2GCCDeclare_doDeclareProcedure_t) DeclarePackedType});
6817 : }
6818 48 : else if (SymbolTable_IsEnumeration (sym))
6819 : {
6820 : /* avoid dangling else. */
6821 48 : return doDeclareEquivalent (sym, (M2GCCDeclare_doDeclareProcedure) {(M2GCCDeclare_doDeclareProcedure_t) DeclarePackedEnumeration});
6822 : }
6823 0 : return SymbolConversion_Mod2Gcc (sym);
6824 : /* static analysis guarentees a RETURN statement will be used before here. */
6825 : __builtin_unreachable ();
6826 : }
6827 :
6828 :
6829 : /*
6830 : MaybeAlignField - checks to see whether, field, is packed or aligned and it updates
6831 : the offsets if appropriate.
6832 : */
6833 :
6834 408266 : static tree MaybeAlignField (unsigned int field, tree *byteOffset, tree *bitOffset)
6835 : {
6836 408266 : tree f;
6837 408266 : tree ftype;
6838 408266 : tree nbits;
6839 408266 : location_t location;
6840 :
6841 408266 : f = SymbolConversion_Mod2Gcc (field);
6842 408266 : if (SymbolTable_IsDeclaredPacked (field))
6843 : {
6844 108 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (field));
6845 108 : f = m2type_SetDeclPacked (f);
6846 108 : ftype = GetPackedType (SymbolTable_GetSType (field));
6847 108 : nbits = m2expr_BuildTBitSize (location, ftype);
6848 108 : f = m2type_SetRecordFieldOffset (f, (*byteOffset), (*bitOffset), ftype, nbits);
6849 108 : (*bitOffset) = m2expr_BuildAdd (location, (*bitOffset), nbits, false);
6850 108 : return f;
6851 : }
6852 : else
6853 : {
6854 408158 : return CheckAlignment (f, field);
6855 : }
6856 : /* static analysis guarentees a RETURN statement will be used before here. */
6857 : __builtin_unreachable ();
6858 : }
6859 :
6860 :
6861 : /*
6862 : DeclareRecord - declares a record and its fields to gcc.
6863 : The final gcc record type is returned.
6864 : */
6865 :
6866 99353 : static tree DeclareRecord (unsigned int Sym)
6867 : {
6868 99353 : unsigned int Field;
6869 99353 : unsigned int i;
6870 99353 : tree nbits;
6871 99353 : tree ftype;
6872 99353 : tree field;
6873 99353 : tree byteOffset;
6874 99353 : tree bitOffset;
6875 99353 : tree FieldList;
6876 99353 : tree RecordType;
6877 99353 : location_t location;
6878 :
6879 99353 : i = 1;
6880 99353 : FieldList = (tree) (NULL);
6881 99353 : RecordType = DoStartDeclaration (Sym, (M2GCCDeclare_StartProcedure) {(M2GCCDeclare_StartProcedure_t) m2type_BuildStartRecord});
6882 99353 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (Sym));
6883 99353 : byteOffset = m2expr_GetIntegerZero (location);
6884 99353 : bitOffset = m2expr_GetIntegerZero (location);
6885 498385 : do {
6886 498385 : Field = SymbolTable_GetNth (Sym, i);
6887 498385 : if (Field != SymbolTable_NulSym)
6888 : {
6889 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
6890 399032 : if (((SymbolTable_IsRecordField (Field)) && (SymbolTable_IsRecordFieldAVarientTag (Field))) && ((SymbolTable_GetSymName (Field)) == NameKey_NulName))
6891 : {} /* empty. */
6892 : /* do not include a nameless tag into the C struct */
6893 399002 : else if (SymbolTable_IsVarient (Field))
6894 : {
6895 : /* avoid dangling else. */
6896 2952 : Field = Chained (Field);
6897 2952 : field = SymbolConversion_Mod2Gcc (Field);
6898 2952 : if (SymbolTable_IsDeclaredPacked (Field))
6899 : {
6900 0 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (Field));
6901 0 : field = m2type_SetDeclPacked (field);
6902 0 : ftype = GetPackedType (SymbolTable_GetSType (Field));
6903 0 : nbits = m2expr_BuildTBitSize (location, ftype);
6904 0 : field = m2type_SetRecordFieldOffset (field, byteOffset, bitOffset, ftype, nbits);
6905 0 : bitOffset = m2expr_BuildAdd (location, bitOffset, nbits, false);
6906 0 : byteOffset = m2expr_BuildAdd (location, byteOffset, m2expr_BuildDivTrunc (location, bitOffset, m2decl_BuildIntegerConstant (8), false), false);
6907 0 : bitOffset = m2expr_BuildModTrunc (location, bitOffset, m2decl_BuildIntegerConstant (8), false);
6908 : }
6909 2952 : FieldList = m2type_ChainOn (FieldList, field);
6910 : }
6911 : else
6912 : {
6913 : /* avoid dangling else. */
6914 396050 : if (Debugging)
6915 : {
6916 : M2Printf_printf0 ((const char *) "chaining ", 9);
6917 : PrintTerse (Field);
6918 : M2Printf_printf0 ((const char *) "\\n", 2);
6919 : }
6920 396050 : FieldList = m2type_ChainOn (FieldList, MaybeAlignField (Chained (Field), &byteOffset, &bitOffset));
6921 : }
6922 : }
6923 498385 : i += 1;
6924 498385 : } while (! (Field == SymbolTable_NulSym));
6925 99353 : WatchRemoveList (Sym, M2GCCDeclare_partiallydeclared);
6926 99353 : WatchRemoveList (Sym, M2GCCDeclare_heldbyalignment);
6927 99353 : WatchRemoveList (Sym, M2GCCDeclare_finishedalignment);
6928 99353 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (Sym));
6929 99353 : return m2type_BuildEndRecord (location, RecordType, FieldList, SymbolTable_IsDeclaredPacked (Sym));
6930 : /* static analysis guarentees a RETURN statement will be used before here. */
6931 : __builtin_unreachable ();
6932 : }
6933 :
6934 :
6935 : /*
6936 : DeclareRecordField -
6937 : */
6938 :
6939 402170 : static tree DeclareRecordField (unsigned int sym)
6940 : {
6941 402170 : tree field;
6942 402170 : tree GccFieldType;
6943 402170 : location_t location;
6944 :
6945 402170 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
6946 402170 : GccFieldType = PossiblyPacked (SymbolTable_GetSType (sym), SymbolTable_IsDeclaredPacked (sym));
6947 402170 : field = m2type_BuildFieldRecord (location, reinterpret_cast <char * > (NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (sym))), GccFieldType);
6948 402170 : return field;
6949 : /* static analysis guarentees a RETURN statement will be used before here. */
6950 : __builtin_unreachable ();
6951 : }
6952 :
6953 :
6954 : /*
6955 : DeclareVarient - declares a record and its fields to gcc.
6956 : The final gcc record type is returned.
6957 : */
6958 :
6959 2988 : static tree DeclareVarient (unsigned int sym)
6960 : {
6961 2988 : unsigned int Field;
6962 2988 : unsigned int i;
6963 2988 : tree byteOffset;
6964 2988 : tree bitOffset;
6965 2988 : tree FieldList;
6966 2988 : tree VarientType;
6967 2988 : location_t location;
6968 :
6969 2988 : i = 1;
6970 2988 : FieldList = (tree) (NULL);
6971 2988 : VarientType = DoStartDeclaration (sym, (M2GCCDeclare_StartProcedure) {(M2GCCDeclare_StartProcedure_t) m2type_BuildStartVarient});
6972 2988 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
6973 2988 : byteOffset = m2expr_GetIntegerZero (location);
6974 2988 : bitOffset = m2expr_GetIntegerZero (location);
6975 9078 : while ((SymbolTable_GetNth (sym, i)) != SymbolTable_NulSym)
6976 : {
6977 6090 : Field = SymbolTable_GetNth (sym, i);
6978 6090 : if (((SymbolTable_IsRecordField (Field)) && (SymbolTable_IsRecordFieldAVarientTag (Field))) && ((SymbolTable_GetSymName (Field)) == NameKey_NulName))
6979 : {} /* empty. */
6980 : else
6981 : {
6982 : /* do not include a nameless tag into the C struct */
6983 6090 : if (Debugging)
6984 : {
6985 : M2Printf_printf0 ((const char *) "chaining ", 9);
6986 : PrintTerse (Field);
6987 : M2Printf_printf0 ((const char *) "\\n", 2);
6988 : }
6989 6090 : FieldList = m2type_ChainOn (FieldList, MaybeAlignField (Chained (Field), &byteOffset, &bitOffset));
6990 : }
6991 6090 : i += 1;
6992 : }
6993 2988 : WatchRemoveList (sym, M2GCCDeclare_partiallydeclared);
6994 2988 : WatchRemoveList (sym, M2GCCDeclare_heldbyalignment);
6995 2988 : WatchRemoveList (sym, M2GCCDeclare_finishedalignment);
6996 2988 : VarientType = m2type_BuildEndVarient (location, VarientType, FieldList, SymbolTable_IsDeclaredPacked (sym));
6997 2988 : return VarientType;
6998 : /* static analysis guarentees a RETURN statement will be used before here. */
6999 : __builtin_unreachable ();
7000 : }
7001 :
7002 :
7003 : /*
7004 : DeclareFieldVarient -
7005 : */
7006 :
7007 6090 : static tree DeclareFieldVarient (unsigned int sym)
7008 : {
7009 6090 : unsigned int i;
7010 6090 : unsigned int f;
7011 6090 : tree VarientList;
7012 6090 : tree VarientType;
7013 6090 : tree byteOffset;
7014 6090 : tree bitOffset;
7015 6090 : tree GccFieldType;
7016 6090 : location_t location;
7017 :
7018 6090 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
7019 6090 : i = 1;
7020 6090 : VarientList = (tree) (NULL);
7021 6090 : VarientType = DoStartDeclaration (sym, (M2GCCDeclare_StartProcedure) {(M2GCCDeclare_StartProcedure_t) m2type_BuildStartFieldVarient});
7022 : /* no need to store the [sym, RecordType] tuple as it is stored by DeclareRecord which calls us */
7023 6090 : byteOffset = m2expr_GetIntegerZero (location);
7024 6090 : bitOffset = m2expr_GetIntegerZero (location);
7025 12216 : while ((SymbolTable_GetNth (sym, i)) != SymbolTable_NulSym)
7026 : {
7027 6126 : f = SymbolTable_GetNth (sym, i);
7028 6126 : if ((SymbolTable_IsFieldVarient (f)) && (SymbolTable_IsEmptyFieldVarient (f)))
7029 : {} /* empty. */
7030 : else
7031 : {
7032 : /* do not include empty varient fields (created via 'else end' in variant records */
7033 6126 : if (Debugging)
7034 : {
7035 : M2Printf_printf0 ((const char *) "chaining ", 9);
7036 : PrintTerse (f);
7037 : M2Printf_printf0 ((const char *) "\\n", 2);
7038 : }
7039 6126 : VarientList = m2type_ChainOn (VarientList, MaybeAlignField (Chained (f), &byteOffset, &bitOffset));
7040 : }
7041 6126 : i += 1;
7042 : }
7043 6090 : WatchRemoveList (sym, M2GCCDeclare_partiallydeclared);
7044 6090 : GccFieldType = m2type_BuildEndFieldVarient (location, VarientType, VarientList, SymbolTable_IsDeclaredPacked (sym));
7045 6090 : return GccFieldType;
7046 : /* static analysis guarentees a RETURN statement will be used before here. */
7047 : __builtin_unreachable ();
7048 : }
7049 :
7050 :
7051 : /*
7052 : DeclarePointer - declares a pointer type to gcc and returns the Tree.
7053 : */
7054 :
7055 184522 : static tree DeclarePointer (unsigned int sym)
7056 : {
7057 184522 : return m2type_BuildPointerType (SymbolConversion_Mod2Gcc (SymbolTable_GetSType (sym)));
7058 : /* static analysis guarentees a RETURN statement will be used before here. */
7059 : __builtin_unreachable ();
7060 : }
7061 :
7062 :
7063 : /*
7064 : DeclareUnbounded - builds an unbounded type and returns the gcc tree.
7065 : */
7066 :
7067 28018 : static tree DeclareUnbounded (unsigned int sym)
7068 : {
7069 28018 : unsigned int record;
7070 :
7071 28018 : M2Debug_Assert (SymbolTable_IsUnbounded (sym));
7072 28018 : if (SymbolConversion_GccKnowsAbout (sym))
7073 : {
7074 0 : return SymbolConversion_Mod2Gcc (sym);
7075 : }
7076 : else
7077 : {
7078 28018 : record = SymbolTable_GetUnboundedRecordType (sym);
7079 28018 : M2Debug_Assert (SymbolTable_IsRecord (record));
7080 28018 : M2Debug_Assert (AllDependantsFullyDeclared (record));
7081 28018 : if (! (SymbolConversion_GccKnowsAbout (record)))
7082 : {
7083 0 : DeclareTypeConstFully (record);
7084 0 : WatchRemoveList (record, M2GCCDeclare_todolist);
7085 : }
7086 28018 : return SymbolConversion_Mod2Gcc (record);
7087 : }
7088 : /* static analysis guarentees a RETURN statement will be used before here. */
7089 : __builtin_unreachable ();
7090 : }
7091 :
7092 :
7093 : /*
7094 : BuildIndex -
7095 : */
7096 :
7097 168094 : static tree BuildIndex (unsigned int tokenno, unsigned int array, bool isset)
7098 : {
7099 168094 : unsigned int Subscript;
7100 168094 : unsigned int Type;
7101 168094 : unsigned int High;
7102 168094 : unsigned int Low;
7103 168094 : tree indexType;
7104 168094 : tree n;
7105 168094 : tree low;
7106 168094 : tree high;
7107 168094 : location_t location;
7108 :
7109 168094 : location = M2LexBuf_TokenToLocation (tokenno);
7110 168094 : Subscript = SymbolTable_GetArraySubscript (array);
7111 168094 : M2Debug_Assert (SymbolTable_IsSubscript (Subscript));
7112 168094 : Type = SymbolTable_GetDType (Subscript);
7113 168094 : Low = M2GCCDeclare_GetTypeMin (Type);
7114 168094 : High = M2GCCDeclare_GetTypeMax (Type);
7115 168094 : M2GCCDeclare_DeclareConstant (tokenno, Low);
7116 168094 : M2GCCDeclare_DeclareConstant (tokenno, High);
7117 168094 : low = SymbolConversion_Mod2Gcc (Low);
7118 168094 : high = SymbolConversion_Mod2Gcc (High);
7119 168094 : if (m2type_ExceedsTypeRange (m2type_GetIntegerType (), low, high))
7120 : {
7121 24 : location = M2LexBuf_TokenToLocation (tokenno);
7122 24 : n = m2convert_BuildConvert (location, m2type_GetIntegerType (), m2expr_BuildSub (location, high, low, false), false);
7123 24 : if ((m2expr_TreeOverflow (n)) || (m2type_ValueOutOfTypeRange (m2type_GetIntegerType (), n)))
7124 : {
7125 0 : if (isset)
7126 : {
7127 0 : M2MetaError_MetaError3 ((const char *) "implementation restriction, set is too large {%1EDM}, the range {%2ad}..{%3ad} exceeds the integer range", 104, array, Low, High);
7128 : }
7129 : else
7130 : {
7131 0 : M2MetaError_MetaError3 ((const char *) "implementation restriction, array is too large {%1EDM}, the range {%2ad}..{%3ad} exceeds the integer range", 106, array, Low, High);
7132 : }
7133 0 : indexType = m2type_BuildArrayIndexType (m2expr_GetIntegerZero (location), m2expr_GetIntegerZero (location));
7134 : }
7135 : else
7136 : {
7137 24 : SymbolTable_PutArrayLarge (array);
7138 24 : indexType = m2type_BuildArrayIndexType (m2expr_GetIntegerZero (location), n);
7139 : }
7140 : }
7141 : else
7142 : {
7143 168070 : low = m2convert_BuildConvert (location, m2type_GetIntegerType (), low, false);
7144 168070 : high = m2convert_BuildConvert (location, m2type_GetIntegerType (), high, false);
7145 168070 : indexType = m2type_BuildArrayIndexType (low, high);
7146 : }
7147 168094 : return indexType;
7148 : /* static analysis guarentees a RETURN statement will be used before here. */
7149 : __builtin_unreachable ();
7150 : }
7151 :
7152 :
7153 : /*
7154 : DeclareArray - declares an array to gcc and returns the gcc tree.
7155 : */
7156 :
7157 160574 : static tree DeclareArray (unsigned int Sym)
7158 : {
7159 160574 : unsigned int typeOfArray;
7160 160574 : tree ArrayType;
7161 160574 : tree GccArray;
7162 160574 : tree GccIndex;
7163 160574 : unsigned int Subscript;
7164 160574 : unsigned int tokenno;
7165 160574 : location_t location;
7166 :
7167 160574 : M2Debug_Assert (SymbolTable_IsArray (Sym));
7168 160574 : tokenno = SymbolTable_GetDeclaredMod (Sym);
7169 160574 : location = M2LexBuf_TokenToLocation (tokenno);
7170 160574 : Subscript = SymbolTable_GetArraySubscript (Sym);
7171 160574 : typeOfArray = SymbolTable_GetDType (Sym);
7172 160574 : GccArray = SymbolConversion_Mod2Gcc (typeOfArray);
7173 160574 : GccIndex = BuildIndex (tokenno, Sym, false);
7174 160574 : if (SymbolConversion_GccKnowsAbout (Sym))
7175 : {
7176 7470 : ArrayType = SymbolConversion_Mod2Gcc (Sym);
7177 : }
7178 : else
7179 : {
7180 153104 : ArrayType = m2type_BuildStartArrayType (GccIndex, GccArray, static_cast<int> (typeOfArray));
7181 153104 : PreAddModGcc (Sym, ArrayType);
7182 : }
7183 160574 : PreAddModGcc (Subscript, GccArray); /* we save the type of this array as the subscript */
7184 160574 : M2ALU_PushIntegerTree (m2expr_BuildSize (location, GccArray, false)); /* and the size of this array so far */
7185 160574 : SymbolTable_PopSize (Subscript); /* and the size of this array so far */
7186 160574 : GccArray = m2type_BuildEndArrayType (ArrayType, GccArray, GccIndex, static_cast<int> (typeOfArray));
7187 160574 : M2Debug_Assert (GccArray == ArrayType);
7188 160574 : return GccArray;
7189 : /* static analysis guarentees a RETURN statement will be used before here. */
7190 : __builtin_unreachable ();
7191 : }
7192 :
7193 :
7194 : /*
7195 : DeclareProcType - declares a procedure type to gcc and returns the gcc type tree.
7196 : */
7197 :
7198 57490 : static tree DeclareProcType (unsigned int Sym)
7199 : {
7200 57490 : unsigned int i;
7201 57490 : unsigned int p;
7202 57490 : unsigned int Parameter;
7203 57490 : unsigned int ReturnType;
7204 57490 : tree func;
7205 57490 : tree GccParam;
7206 57490 : location_t location;
7207 :
7208 57490 : ReturnType = SymbolTable_GetSType (Sym);
7209 57490 : func = DoStartDeclaration (Sym, (M2GCCDeclare_StartProcedure) {(M2GCCDeclare_StartProcedure_t) m2type_BuildStartFunctionType});
7210 57490 : m2type_InitFunctionTypeParameters ();
7211 57490 : p = SymbolTable_NoOfParamAny (Sym);
7212 57490 : i = p;
7213 195980 : while (i > 0)
7214 : {
7215 81000 : Parameter = SymbolTable_GetNthParamAny (Sym, i);
7216 81000 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (Parameter));
7217 81000 : GccParam = m2type_BuildProcTypeParameterDeclaration (location, SymbolConversion_Mod2Gcc (SymbolTable_GetSType (Parameter)), SymbolTable_IsVarParamAny (Sym, i));
7218 81000 : PreAddModGcc (Parameter, GccParam);
7219 81000 : i -= 1;
7220 : }
7221 57490 : if (ReturnType == SymbolTable_NulSym)
7222 : {
7223 49662 : return m2type_BuildEndFunctionType (func, NULL, SymbolTable_UsesVarArgs (Sym));
7224 : }
7225 : else
7226 : {
7227 7828 : return m2type_BuildEndFunctionType (func, SymbolConversion_Mod2Gcc (ReturnType), SymbolTable_UsesVarArgs (Sym));
7228 : }
7229 : /* static analysis guarentees a RETURN statement will be used before here. */
7230 : __builtin_unreachable ();
7231 : }
7232 :
7233 :
7234 : /*
7235 : FindMinMaxEnum - finds the minimum and maximum enumeration fields.
7236 : */
7237 :
7238 5787020 : static void FindMinMaxEnum (unsigned int field)
7239 : {
7240 5787020 : if (MaxEnumerationField == SymbolTable_NulSym)
7241 : {
7242 863508 : MaxEnumerationField = static_cast<unsigned int> (field);
7243 : }
7244 : else
7245 : {
7246 4923512 : SymbolTable_PushValue (field);
7247 4923512 : SymbolTable_PushValue (MaxEnumerationField);
7248 4923512 : if (M2ALU_Gre (SymbolTable_GetDeclaredMod (field)))
7249 : {
7250 221952 : MaxEnumerationField = static_cast<unsigned int> (field);
7251 : }
7252 : }
7253 5787020 : if (MinEnumerationField == SymbolTable_NulSym)
7254 : {
7255 863508 : MinEnumerationField = static_cast<unsigned int> (field);
7256 : }
7257 : else
7258 : {
7259 4923512 : SymbolTable_PushValue (field);
7260 4923512 : SymbolTable_PushValue (MinEnumerationField);
7261 4923512 : if (M2ALU_Less (SymbolTable_GetDeclaredMod (field)))
7262 : {
7263 3891072 : MinEnumerationField = static_cast<unsigned int> (field);
7264 : }
7265 : }
7266 5787020 : }
7267 :
7268 :
7269 : /*
7270 : PushNoOfBits - pushes the integer value of the number of bits required
7271 : to maintain a set of type.
7272 : */
7273 :
7274 4664 : static void PushNoOfBits (unsigned int type, unsigned int low, unsigned int high)
7275 : {
7276 4664 : SymbolTable_PushValue (high);
7277 4664 : M2ALU_ConvertToType (type);
7278 4664 : SymbolTable_PushValue (low);
7279 4664 : M2ALU_ConvertToType (type);
7280 4664 : M2ALU_Sub ();
7281 4664 : M2ALU_ConvertToType (M2Base_Cardinal);
7282 4664 : }
7283 :
7284 :
7285 : /*
7286 : DeclareSetArrayOrBitSet - works out whether the set will exceed SIZE (BITSET).
7287 : If it does we manufacture a set using:
7288 :
7289 : settype = ARRAY [0..totalBits DIV SIZE (BITSET)] OF BITSET ;
7290 :
7291 : When GCC supports dwarf5 set types this code should be revised.
7292 : If the set will fit into a WORD then we call gccgm2 directly.
7293 : */
7294 :
7295 4664 : static tree DeclareSetArrayOrBitSet (unsigned int sym, NameKey_Name n, unsigned int type, unsigned int low, unsigned int high)
7296 : {
7297 4664 : location_t location;
7298 :
7299 4664 : PushNoOfBits (type, low, high);
7300 4664 : M2ALU_PushCard (static_cast<unsigned int> (m2decl_GetBitsPerBitset ()));
7301 4664 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
7302 4664 : if (M2ALU_Less (SymbolTable_GetDeclaredMod (type)))
7303 : {
7304 3886 : SymbolTable_PutSetInWord (sym, true);
7305 3886 : return m2type_BuildSetType (location, reinterpret_cast <char * > (NameKey_KeyToCharStar (n)), SymbolConversion_Mod2Gcc (type), SymbolConversion_Mod2Gcc (low), SymbolConversion_Mod2Gcc (high), true);
7306 : }
7307 : else
7308 : {
7309 778 : SymbolTable_PutSetInWord (sym, false);
7310 778 : return DeclareArray (SymbolTable_GetSetArray (sym));
7311 : }
7312 : /* static analysis guarentees a RETURN statement will be used before here. */
7313 : __builtin_unreachable ();
7314 : }
7315 :
7316 :
7317 : /*
7318 : DeclareSet - declares a set type to gcc and returns a Tree.
7319 : */
7320 :
7321 4664 : static tree DeclareSet (unsigned int sym)
7322 : {
7323 4664 : tree gccsym;
7324 4664 : unsigned int type;
7325 4664 : unsigned int high;
7326 4664 : unsigned int low;
7327 :
7328 4664 : type = SymbolTable_GetSType (sym);
7329 4664 : if (SymbolTable_IsSubrange (type))
7330 : {
7331 3780 : SymbolTable_GetSubrange (type, &high, &low);
7332 3780 : gccsym = DeclareSetArrayOrBitSet (sym, M2AsmUtil_GetFullSymName (sym), SymbolTable_GetSType (type), low, high);
7333 : }
7334 : else
7335 : {
7336 884 : gccsym = DeclareSetArrayOrBitSet (sym, M2AsmUtil_GetFullSymName (sym), type, M2GCCDeclare_GetTypeMin (type), M2GCCDeclare_GetTypeMax (type));
7337 : }
7338 4664 : return gccsym;
7339 : /* static analysis guarentees a RETURN statement will be used before here. */
7340 : __builtin_unreachable ();
7341 : }
7342 :
7343 :
7344 : /*
7345 : CheckResolveSubrange - checks to see whether we can determine
7346 : the subrange type. We are able to do
7347 : this once low, high and the type are known.
7348 : */
7349 :
7350 5836314 : static void CheckResolveSubrange (unsigned int sym)
7351 : {
7352 5836314 : unsigned int tokenno;
7353 5836314 : unsigned int size;
7354 5836314 : unsigned int high;
7355 5836314 : unsigned int low;
7356 5836314 : unsigned int type;
7357 :
7358 5836314 : SymbolTable_GetSubrange (sym, &high, &low);
7359 5836314 : tokenno = SymbolTable_GetDeclaredMod (sym);
7360 5836314 : type = SymbolTable_GetSType (sym);
7361 5836314 : if (type == SymbolTable_NulSym)
7362 : {
7363 2339446 : if ((SymbolConversion_GccKnowsAbout (low)) && (SymbolConversion_GccKnowsAbout (high)))
7364 : {
7365 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
7366 101682 : if ((SymbolTable_IsConstString (low)) && (SymbolTable_IsConstStringKnown (low)))
7367 : {
7368 72 : size = SymbolTable_GetStringLength (tokenno, low);
7369 72 : if (size <= 1)
7370 : {
7371 72 : SymbolTable_PutSubrange (sym, low, high, M2Base_Char);
7372 : }
7373 : else
7374 : {
7375 0 : M2MetaError_MetaError1 ((const char *) "cannot have a subrange of a string type {%1Uad}", 47, sym);
7376 : }
7377 : }
7378 101610 : else if (SymbolTable_IsFieldEnumeration (low))
7379 : {
7380 : /* avoid dangling else. */
7381 368 : if ((SymbolTable_GetSType (low)) == (SymbolTable_GetSType (high)))
7382 : {
7383 368 : SymbolTable_PutSubrange (sym, low, high, SymbolTable_GetSType (low));
7384 : }
7385 : else
7386 : {
7387 0 : M2MetaError_MetaError1 ((const char *) "subrange limits must be of the same type {%1Uad}", 48, sym);
7388 : }
7389 : }
7390 101242 : else if (SymbolTable_IsValueSolved (low))
7391 : {
7392 : /* avoid dangling else. */
7393 101242 : if ((SymbolTable_GetSType (low)) == M2Base_LongReal)
7394 : {
7395 0 : M2MetaError_MetaError1 ((const char *) "cannot have a subrange of a SHORTREAL, REAL or LONGREAL type {%1Uad}", 68, sym);
7396 : }
7397 : else
7398 : {
7399 101242 : SymbolTable_PutSubrange (sym, low, high, M2Base_MixTypes (SymbolTable_GetSType (low), SymbolTable_GetSType (high), SymbolTable_GetDeclaredMod (sym)));
7400 : }
7401 : }
7402 : }
7403 : }
7404 5836314 : }
7405 :
7406 :
7407 : /*
7408 : TypeConstFullyDeclared - all, sym, dependents are declared, so create and
7409 : return the GCC Tree equivalent.
7410 : */
7411 :
7412 1755645 : static tree TypeConstFullyDeclared (unsigned int sym)
7413 : {
7414 1755645 : tree t;
7415 :
7416 1755645 : if (SymbolTable_IsEnumeration (sym))
7417 : {
7418 34054 : t = DeclareEnumeration (sym);
7419 : }
7420 1721591 : else if (SymbolTable_IsFieldEnumeration (sym))
7421 : {
7422 : /* avoid dangling else. */
7423 462828 : t = DeclareFieldEnumeration (sym);
7424 : }
7425 1258763 : else if (SymbolTable_IsSubrange (sym))
7426 : {
7427 : /* avoid dangling else. */
7428 161518 : t = DeclareSubrange (sym);
7429 : }
7430 1097245 : else if (SymbolTable_IsRecord (sym))
7431 : {
7432 : /* avoid dangling else. */
7433 99353 : t = CheckPragma (DeclareRecord (sym), sym);
7434 : }
7435 997892 : else if (SymbolTable_IsRecordField (sym))
7436 : {
7437 : /* avoid dangling else. */
7438 402170 : t = CheckPragma (DeclareRecordField (sym), sym);
7439 : }
7440 595722 : else if (SymbolTable_IsFieldVarient (sym))
7441 : {
7442 : /* avoid dangling else. */
7443 6090 : t = DeclareFieldVarient (sym);
7444 : }
7445 589632 : else if (SymbolTable_IsVarient (sym))
7446 : {
7447 : /* avoid dangling else. */
7448 2988 : t = DeclareVarient (sym);
7449 : }
7450 586644 : else if (SymbolTable_IsPointer (sym))
7451 : {
7452 : /* avoid dangling else. */
7453 157044 : t = CheckAlignment (DeclarePointer (sym), sym);
7454 : }
7455 429600 : else if (SymbolTable_IsUnbounded (sym))
7456 : {
7457 : /* avoid dangling else. */
7458 28018 : t = DeclareUnbounded (sym);
7459 : }
7460 401582 : else if (SymbolTable_IsArray (sym))
7461 : {
7462 : /* avoid dangling else. */
7463 159796 : t = CheckAlignment (DeclareArray (sym), sym);
7464 : }
7465 241786 : else if (SymbolTable_IsProcType (sym))
7466 : {
7467 : /* avoid dangling else. */
7468 48228 : t = DeclareProcType (sym);
7469 : }
7470 193558 : else if (SymbolTable_IsSet (sym))
7471 : {
7472 : /* avoid dangling else. */
7473 0 : t = CheckAlignment (DeclareSet (sym), sym);
7474 : }
7475 193558 : else if (SymbolTable_IsConst (sym))
7476 : {
7477 : /* avoid dangling else. */
7478 159764 : if (SymbolTable_IsConstructor (sym))
7479 : {
7480 8434 : SymbolTable_PushValue (sym);
7481 8434 : M2ALU_ChangeToConstructor (SymbolTable_GetDeclaredMod (sym), SymbolTable_GetSType (sym));
7482 8434 : SymbolTable_PopValue (sym);
7483 8434 : M2ALU_EvaluateValue (sym);
7484 8434 : M2ALU_PutConstructorSolved (sym);
7485 : }
7486 151330 : else if (SymbolTable_IsConstSet (sym))
7487 : {
7488 : /* avoid dangling else. */
7489 0 : M2ALU_EvaluateValue (sym);
7490 : }
7491 159764 : if (! (SymbolTable_IsValueSolved (sym)))
7492 : {
7493 : return NULL;
7494 : }
7495 159764 : t = DeclareConst (SymbolTable_GetDeclaredMod (sym), sym);
7496 159764 : M2Debug_Assert (t != NULL);
7497 : }
7498 33794 : else if (SymbolTable_IsConstructor (sym))
7499 : {
7500 : /* avoid dangling else. */
7501 : /* not yet known as a constant */
7502 : return NULL;
7503 : }
7504 : else
7505 : {
7506 : /* avoid dangling else. */
7507 33794 : t = DeclareType (sym);
7508 33794 : if (SymbolTable_IsType (sym))
7509 : {
7510 33794 : t = CheckAlignment (t, sym);
7511 : }
7512 : }
7513 1755645 : return m2block_RememberType (t);
7514 : /* static analysis guarentees a RETURN statement will be used before here. */
7515 : __builtin_unreachable ();
7516 : }
7517 :
7518 :
7519 : /*
7520 : IsBaseType - returns true if a type, Sym, is a base type and
7521 : we use predefined GDB information to represent this
7522 : type.
7523 : */
7524 :
7525 34438 : static bool IsBaseType (unsigned int Sym)
7526 : {
7527 34438 : return (((Sym == M2Base_Cardinal) || (Sym == M2Base_Integer)) || (Sym == M2Base_Char)) || (Sym == M2Base_Proc);
7528 : /* static analysis guarentees a RETURN statement will be used before here. */
7529 : __builtin_unreachable ();
7530 : }
7531 :
7532 :
7533 : /*
7534 : IsFieldEnumerationDependants - sets enumDeps to FALSE if action(Sym)
7535 : is also FALSE.
7536 : */
7537 :
7538 1107614 : static void IsFieldEnumerationDependants (unsigned int Sym)
7539 : {
7540 1107614 : if (! ((*action.proc) (Sym)))
7541 : {
7542 462628 : enumDeps = false;
7543 : }
7544 1107614 : }
7545 :
7546 :
7547 : /*
7548 : IsEnumerationDependants - returns true if the enumeration
7549 : p(dependants) all return true.
7550 : */
7551 :
7552 133437 : static bool IsEnumerationDependants (unsigned int sym, M2GCCDeclare_IsAction q)
7553 : {
7554 133437 : action = q;
7555 133437 : enumDeps = true;
7556 133437 : SymbolTable_ForeachLocalSymDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) IsFieldEnumerationDependants});
7557 133437 : return enumDeps;
7558 : /* static analysis guarentees a RETURN statement will be used before here. */
7559 : __builtin_unreachable ();
7560 : }
7561 :
7562 :
7563 : /*
7564 : WalkEnumerationDependants - returns walks all dependants of Sym.
7565 : */
7566 :
7567 11339597 : static void WalkEnumerationDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
7568 : {
7569 11339597 : SymbolTable_ForeachLocalSymDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) p.proc});
7570 0 : }
7571 :
7572 :
7573 : /*
7574 : WalkSubrangeDependants - calls p(dependants) for each dependant of, sym.
7575 : */
7576 :
7577 5497576 : static void WalkSubrangeDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
7578 : {
7579 5497576 : unsigned int type;
7580 5497576 : unsigned int align;
7581 5497576 : unsigned int high;
7582 5497576 : unsigned int low;
7583 :
7584 5497576 : SymbolTable_GetSubrange (sym, &high, &low);
7585 5497576 : CheckResolveSubrange (sym);
7586 5497576 : type = SymbolTable_GetSType (sym);
7587 5497576 : if (type != SymbolTable_NulSym)
7588 : {
7589 3429804 : (*p.proc) (type);
7590 : }
7591 : /* low and high are not types but constants and they are resolved by M2GenGCC */
7592 5497576 : (*p.proc) (low);
7593 5497576 : (*p.proc) (high);
7594 5497576 : align = SymbolTable_GetAlignment (sym);
7595 5497576 : if (align != SymbolTable_NulSym)
7596 : {
7597 9948 : (*p.proc) (align);
7598 : }
7599 5497576 : }
7600 :
7601 :
7602 : /*
7603 : IsSubrangeDependants - returns TRUE if the subrange
7604 : q(dependants) all return TRUE.
7605 : */
7606 :
7607 338738 : static bool IsSubrangeDependants (unsigned int sym, M2GCCDeclare_IsAction q)
7608 : {
7609 338738 : bool result;
7610 338738 : unsigned int align;
7611 338738 : unsigned int type;
7612 338738 : unsigned int high;
7613 338738 : unsigned int low;
7614 :
7615 338738 : SymbolTable_GetSubrange (sym, &high, &low);
7616 : /* low and high are not types but constants and they are resolved by M2GenGCC */
7617 338738 : CheckResolveSubrange (sym);
7618 338738 : result = true;
7619 338738 : type = SymbolTable_GetSType (sym);
7620 338738 : if ((type == SymbolTable_NulSym) || (! ((*q.proc) (type))))
7621 : {
7622 : result = false;
7623 : }
7624 338738 : if (! ((*q.proc) (low)))
7625 : {
7626 105690 : result = false;
7627 : }
7628 338738 : if (! ((*q.proc) (high)))
7629 : {
7630 99264 : result = false;
7631 : }
7632 338738 : align = SymbolTable_GetAlignment (sym);
7633 338738 : if ((align != SymbolTable_NulSym) && (! ((*q.proc) (align))))
7634 : {
7635 : result = false;
7636 : }
7637 338738 : return result;
7638 : /* static analysis guarentees a RETURN statement will be used before here. */
7639 : __builtin_unreachable ();
7640 : }
7641 :
7642 :
7643 : /*
7644 : WalkComponentDependants -
7645 : */
7646 :
7647 116314 : static void WalkComponentDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
7648 : {
7649 116314 : unsigned int i;
7650 116314 : unsigned int type;
7651 :
7652 : /* need to walk record and field */
7653 116314 : i = 1;
7654 348942 : do {
7655 348942 : type = SymbolTable_GetNth (sym, i);
7656 348942 : if (type != SymbolTable_NulSym)
7657 : {
7658 232628 : if (SymbolTable_IsVar (type))
7659 : {
7660 116314 : (*p.proc) (SymbolTable_GetSType (type));
7661 : }
7662 : else
7663 : {
7664 116314 : (*p.proc) (type);
7665 : }
7666 232628 : i += 1;
7667 : }
7668 348942 : } while (! (type == SymbolTable_NulSym));
7669 116314 : }
7670 :
7671 :
7672 : /*
7673 : IsComponentDependants -
7674 : */
7675 :
7676 0 : static bool IsComponentDependants (unsigned int sym, M2GCCDeclare_IsAction q)
7677 : {
7678 0 : unsigned int type;
7679 0 : unsigned int i;
7680 0 : bool result;
7681 :
7682 : /* need to check record is completely resolved */
7683 0 : result = true;
7684 0 : i = 1;
7685 0 : do {
7686 0 : type = SymbolTable_GetNth (sym, i);
7687 0 : if (type != SymbolTable_NulSym)
7688 : {
7689 0 : if (SymbolTable_IsVar (type))
7690 : {
7691 0 : type = SymbolTable_GetSType (type);
7692 : }
7693 0 : if (! ((*q.proc) (type)))
7694 : {
7695 0 : result = false;
7696 : }
7697 0 : i += 1;
7698 : }
7699 0 : } while (! (type == SymbolTable_NulSym));
7700 0 : return result;
7701 : /* static analysis guarentees a RETURN statement will be used before here. */
7702 : __builtin_unreachable ();
7703 : }
7704 :
7705 :
7706 : /*
7707 : WalkVarDependants - walks all dependants of sym.
7708 : */
7709 :
7710 676211 : static void WalkVarDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
7711 : {
7712 676211 : unsigned int type;
7713 :
7714 676211 : (*p.proc) (SymbolTable_GetSType (sym));
7715 676211 : if (SymbolTable_IsComponent (sym))
7716 : {
7717 0 : WalkComponentDependants (sym, p);
7718 : }
7719 676211 : type = SymbolTable_GetVarBackEndType (sym);
7720 676211 : if (type != SymbolTable_NulSym)
7721 : {
7722 53036 : (*p.proc) (type);
7723 : }
7724 676211 : }
7725 :
7726 :
7727 : /*
7728 : IsVarDependants - returns TRUE if the pointer symbol, sym,
7729 : p(dependants) all return TRUE.
7730 : */
7731 :
7732 0 : static bool IsVarDependants (unsigned int sym, M2GCCDeclare_IsAction q)
7733 : {
7734 0 : unsigned int type;
7735 0 : bool result;
7736 :
7737 0 : result = true;
7738 0 : if (! ((*q.proc) (SymbolTable_GetSType (sym))))
7739 : {
7740 : result = false;
7741 : }
7742 0 : if (SymbolTable_IsComponent (sym))
7743 : {
7744 0 : if (! (IsComponentDependants (sym, q)))
7745 : {
7746 0 : result = false;
7747 : }
7748 : }
7749 0 : type = SymbolTable_GetVarBackEndType (sym);
7750 0 : if (type != SymbolTable_NulSym)
7751 : {
7752 0 : if (! ((*q.proc) (type)))
7753 : {
7754 0 : result = false;
7755 : }
7756 : }
7757 0 : return result;
7758 : /* static analysis guarentees a RETURN statement will be used before here. */
7759 : __builtin_unreachable ();
7760 : }
7761 :
7762 :
7763 : /*
7764 : WalkPointerDependants - walks all dependants of sym.
7765 : */
7766 :
7767 48175334 : static void WalkPointerDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
7768 : {
7769 48175334 : unsigned int align;
7770 :
7771 48175334 : if ((SymbolTable_GetSType (sym)) == SymbolTable_NulSym)
7772 : {
7773 0 : M2MetaError_MetaError1 ((const char *) "pointer type {%1Ua} is unresolved", 33, sym);
7774 0 : M2Error_InternalError ((const char *) "pointer type should have been declared", 38);
7775 : }
7776 : else
7777 : {
7778 48175334 : (*p.proc) (SymbolTable_GetSType (sym));
7779 48175334 : align = SymbolTable_GetAlignment (sym);
7780 48175334 : if (align != SymbolTable_NulSym)
7781 : {
7782 24 : (*p.proc) (align);
7783 : }
7784 : }
7785 48175334 : }
7786 :
7787 :
7788 : /*
7789 : IsPointerDependants - returns TRUE if the pointer symbol, sym,
7790 : p(dependants) all return TRUE.
7791 : */
7792 :
7793 1170131 : static bool IsPointerDependants (unsigned int sym, M2GCCDeclare_IsAction q)
7794 : {
7795 1170131 : unsigned int align;
7796 1170131 : bool final;
7797 :
7798 1170131 : final = true;
7799 1170131 : if (! ((*q.proc) (SymbolTable_GetSType (sym))))
7800 : {
7801 : final = false;
7802 : }
7803 1170131 : align = SymbolTable_GetAlignment (sym);
7804 1170131 : if (final && (align != SymbolTable_NulSym))
7805 : {
7806 36 : if (! ((*q.proc) (align)))
7807 : {
7808 : final = false;
7809 : }
7810 : }
7811 1170131 : return final;
7812 : /* static analysis guarentees a RETURN statement will be used before here. */
7813 : __builtin_unreachable ();
7814 : }
7815 :
7816 :
7817 : /*
7818 : IsRecordAlignment -
7819 : */
7820 :
7821 717025 : static bool IsRecordAlignment (unsigned int sym, M2GCCDeclare_IsAction q)
7822 : {
7823 717025 : if ((SymbolTable_GetDefaultRecordFieldAlignment (sym)) != SymbolTable_NulSym)
7824 : {
7825 180 : if (! ((*q.proc) (SymbolTable_GetDefaultRecordFieldAlignment (sym))))
7826 : {
7827 : return false;
7828 : }
7829 : }
7830 : return true;
7831 : /* static analysis guarentees a RETURN statement will be used before here. */
7832 : __builtin_unreachable ();
7833 : }
7834 :
7835 :
7836 : /*
7837 : IsRecordDependants - returns TRUE if the symbol, sym,
7838 : q(dependants) all return TRUE.
7839 : */
7840 :
7841 717025 : static bool IsRecordDependants (unsigned int sym, M2GCCDeclare_IsAction q)
7842 : {
7843 717025 : bool result;
7844 717025 : unsigned int i;
7845 717025 : unsigned int field;
7846 :
7847 717025 : result = IsRecordAlignment (sym, q);
7848 717025 : i = 1;
7849 3740301 : do {
7850 3740301 : field = SymbolTable_GetNth (sym, i);
7851 3740301 : if (field != SymbolTable_NulSym)
7852 : {
7853 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
7854 3023276 : if (SymbolTable_IsRecordField (field))
7855 : {
7856 : /* avoid dangling else. */
7857 2986986 : if ((! (SymbolTable_IsRecordFieldAVarientTag (field))) || ((SymbolTable_GetSymName (field)) != NameKey_NulName))
7858 : {
7859 2986812 : if (! ((*q.proc) (field)))
7860 : {
7861 1467582 : result = false;
7862 : }
7863 : }
7864 : }
7865 36290 : else if (SymbolTable_IsVarient (field))
7866 : {
7867 : /* avoid dangling else. */
7868 36290 : if (! ((*q.proc) (field)))
7869 : {
7870 1467582 : result = false;
7871 : }
7872 : }
7873 0 : else if (SymbolTable_IsFieldVarient (field))
7874 : {
7875 : /* avoid dangling else. */
7876 0 : M2Error_InternalError ((const char *) "should not see a field varient", 30);
7877 : }
7878 : else
7879 : {
7880 : /* avoid dangling else. */
7881 0 : M2Error_InternalError ((const char *) "unknown symbol in record", 24);
7882 : }
7883 : }
7884 3740301 : i += 1;
7885 3740301 : } while (! (field == SymbolTable_NulSym));
7886 717025 : return result;
7887 : /* static analysis guarentees a RETURN statement will be used before here. */
7888 : __builtin_unreachable ();
7889 : }
7890 :
7891 :
7892 : /*
7893 : WalkRecordAlignment - walks the alignment constant associated with
7894 : record, sym.
7895 : */
7896 :
7897 41200125 : static void WalkRecordAlignment (unsigned int sym, M2GCCDeclare_WalkAction p)
7898 : {
7899 41200125 : if ((SymbolTable_GetDefaultRecordFieldAlignment (sym)) != SymbolTable_NulSym)
7900 : {
7901 216 : (*p.proc) (SymbolTable_GetDefaultRecordFieldAlignment (sym));
7902 : }
7903 41200125 : }
7904 :
7905 :
7906 : /*
7907 : WalkRecordDependants - walks symbol, sym, dependants. It only
7908 : walks the fields if the alignment is
7909 : unused or fully declared.
7910 : */
7911 :
7912 41200125 : static void WalkRecordDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
7913 : {
7914 41200125 : WalkRecordAlignment (sym, p);
7915 41200125 : WalkRecordDependants2 (sym, p);
7916 41200125 : }
7917 :
7918 :
7919 : /*
7920 : WalkRecordFieldDependants -
7921 : */
7922 :
7923 232451638 : static void WalkRecordFieldDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
7924 : {
7925 232451638 : unsigned int v;
7926 232451638 : unsigned int align;
7927 :
7928 232451638 : M2Debug_Assert (SymbolTable_IsRecordField (sym));
7929 232451638 : (*p.proc) (SymbolTable_GetSType (sym));
7930 232451638 : v = SymbolTable_GetVarient (sym);
7931 232451638 : if (v != SymbolTable_NulSym)
7932 : {
7933 1068560 : (*p.proc) (v);
7934 : }
7935 232451638 : align = SymbolTable_GetAlignment (sym);
7936 232451638 : if (align != SymbolTable_NulSym)
7937 : {
7938 1320 : (*p.proc) (align);
7939 : }
7940 232451638 : }
7941 :
7942 :
7943 : /*
7944 : WalkRecordDependants2 - walks the fields of record, sym, calling
7945 : p on every dependant.
7946 : */
7947 :
7948 41200125 : static void WalkRecordDependants2 (unsigned int sym, M2GCCDeclare_WalkAction p)
7949 : {
7950 41200125 : unsigned int i;
7951 41200125 : unsigned int Field;
7952 :
7953 41200125 : i = 1;
7954 159051333 : while ((SymbolTable_GetNth (sym, i)) != SymbolTable_NulSym)
7955 : {
7956 117851208 : Field = SymbolTable_GetNth (sym, i);
7957 117851208 : (*p.proc) (Field);
7958 117851208 : if (SymbolTable_IsRecordField (Field))
7959 : {
7960 117604864 : WalkRecordFieldDependants (Field, p);
7961 : }
7962 246344 : else if (SymbolTable_IsVarient (Field))
7963 : {
7964 : /* avoid dangling else. */
7965 246344 : WalkVarientDependants (Field, p);
7966 : }
7967 0 : else if (SymbolTable_IsFieldVarient (Field))
7968 : {
7969 : /* avoid dangling else. */
7970 0 : M2Error_InternalError ((const char *) "should not see a field varient", 30);
7971 : }
7972 : else
7973 : {
7974 : /* avoid dangling else. */
7975 0 : M2Error_InternalError ((const char *) "unknown symbol in record", 24);
7976 : }
7977 117851208 : i += 1;
7978 : }
7979 41200125 : }
7980 :
7981 :
7982 : /*
7983 : IsVarientAlignment -
7984 : */
7985 :
7986 98502 : static bool IsVarientAlignment (unsigned int sym, M2GCCDeclare_IsAction q)
7987 : {
7988 98502 : unsigned int align;
7989 :
7990 98502 : sym = GetRecordOfVarient (sym);
7991 98502 : align = SymbolTable_GetDefaultRecordFieldAlignment (sym);
7992 98502 : if ((align != SymbolTable_NulSym) && (! ((*q.proc) (align))))
7993 : {
7994 : return false;
7995 : }
7996 : return true;
7997 : /* static analysis guarentees a RETURN statement will be used before here. */
7998 : __builtin_unreachable ();
7999 : }
8000 :
8001 :
8002 : /*
8003 : IsVarientDependants - returns TRUE if the symbol, sym,
8004 : q(dependants) all return TRUE.
8005 : */
8006 :
8007 34884 : static bool IsVarientDependants (unsigned int sym, M2GCCDeclare_IsAction q)
8008 : {
8009 34884 : bool result;
8010 34884 : unsigned int i;
8011 34884 : unsigned int Field;
8012 :
8013 34884 : result = IsVarientAlignment (sym, q);
8014 34884 : i = 1;
8015 140394 : while ((SymbolTable_GetNth (sym, i)) != SymbolTable_NulSym)
8016 : {
8017 70626 : Field = SymbolTable_GetNth (sym, i);
8018 70626 : M2Debug_Assert (SymbolTable_IsFieldVarient (Field));
8019 70626 : if (! ((*q.proc) (Field)))
8020 : {
8021 63618 : result = false;
8022 : }
8023 70626 : i += 1;
8024 : }
8025 34884 : return result;
8026 : /* static analysis guarentees a RETURN statement will be used before here. */
8027 : __builtin_unreachable ();
8028 : }
8029 :
8030 :
8031 : /*
8032 : WalkVarientAlignment -
8033 : */
8034 :
8035 2188186 : static void WalkVarientAlignment (unsigned int sym, M2GCCDeclare_WalkAction p)
8036 : {
8037 2188186 : unsigned int align;
8038 :
8039 2188186 : sym = GetRecordOfVarient (sym);
8040 2188186 : align = SymbolTable_GetDefaultRecordFieldAlignment (sym);
8041 2188186 : if (align != SymbolTable_NulSym)
8042 : {
8043 0 : (*p.proc) (align);
8044 : }
8045 2188186 : }
8046 :
8047 :
8048 : /*
8049 : WalkVarientDependants - walks symbol, sym, dependants.
8050 : */
8051 :
8052 534064 : static void WalkVarientDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
8053 : {
8054 534064 : unsigned int i;
8055 534064 : unsigned int v;
8056 534064 : unsigned int Field;
8057 :
8058 534064 : WalkVarientAlignment (sym, p);
8059 534064 : if ((SymbolTable_GetSType (sym)) != SymbolTable_NulSym)
8060 : {
8061 0 : (*p.proc) (SymbolTable_GetSType (sym));
8062 : }
8063 534064 : v = SymbolTable_GetVarient (sym);
8064 534064 : if (v != SymbolTable_NulSym)
8065 : {
8066 1128 : (*p.proc) (v);
8067 : }
8068 : i = 1;
8069 1608582 : while ((SymbolTable_GetNth (sym, i)) != SymbolTable_NulSym)
8070 : {
8071 1074518 : Field = SymbolTable_GetNth (sym, i);
8072 1074518 : M2Debug_Assert (SymbolTable_IsFieldVarient (Field)); /* field varients do _not_ have a type */
8073 1074518 : (*p.proc) (Field); /* field varients do _not_ have a type */
8074 1074518 : WalkVarientFieldDependants (Field, p);
8075 1074518 : i += 1;
8076 : }
8077 534064 : }
8078 :
8079 :
8080 : /*
8081 : IsVarientFieldDependants - returns TRUE if the symbol, sym,
8082 : q(dependants) all return TRUE.
8083 : */
8084 :
8085 63618 : static bool IsVarientFieldDependants (unsigned int sym, M2GCCDeclare_IsAction q)
8086 : {
8087 63618 : unsigned int i;
8088 63618 : unsigned int type;
8089 63618 : unsigned int Field;
8090 63618 : bool result;
8091 :
8092 63618 : i = 1;
8093 63618 : result = IsVarientAlignment (sym, q);
8094 191658 : while ((SymbolTable_GetNth (sym, i)) != SymbolTable_NulSym)
8095 : {
8096 64422 : Field = SymbolTable_GetNth (sym, i);
8097 64422 : if (! ((*q.proc) (Field)))
8098 : {
8099 58086 : result = false;
8100 : }
8101 64422 : type = SymbolTable_GetSType (Field);
8102 64422 : if (type != SymbolTable_NulSym)
8103 : {
8104 64146 : if (! ((*q.proc) (type)))
8105 : {
8106 64422 : result = false;
8107 : }
8108 : }
8109 64422 : i += 1;
8110 : }
8111 63618 : return result;
8112 : /* static analysis guarentees a RETURN statement will be used before here. */
8113 : __builtin_unreachable ();
8114 : }
8115 :
8116 :
8117 : /*
8118 : WalkVarientFieldDependants -
8119 : */
8120 :
8121 1654122 : static void WalkVarientFieldDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
8122 : {
8123 1654122 : unsigned int i;
8124 1654122 : unsigned int type;
8125 1654122 : unsigned int Field;
8126 :
8127 1654122 : WalkVarientAlignment (sym, p);
8128 1654122 : i = 1;
8129 4963956 : while ((SymbolTable_GetNth (sym, i)) != SymbolTable_NulSym)
8130 : {
8131 1655712 : Field = SymbolTable_GetNth (sym, i);
8132 1655712 : (*p.proc) (Field);
8133 1655712 : type = SymbolTable_GetSType (Field);
8134 1655712 : if (type != SymbolTable_NulSym)
8135 : {
8136 1652964 : (*p.proc) (type);
8137 : }
8138 1655712 : i += 1;
8139 : }
8140 1654122 : }
8141 :
8142 :
8143 : /*
8144 : IsArrayDependants - returns TRUE if the symbol, sym,
8145 : q(dependants) all return TRUE.
8146 :
8147 : */
8148 :
8149 471588 : static bool IsArrayDependants (unsigned int sym, M2GCCDeclare_IsAction q)
8150 : {
8151 471588 : bool result;
8152 471588 : unsigned int align;
8153 471588 : unsigned int subscript;
8154 471588 : unsigned int high;
8155 471588 : unsigned int low;
8156 471588 : unsigned int type;
8157 :
8158 471588 : result = true;
8159 471588 : M2Debug_Assert (SymbolTable_IsArray (sym));
8160 471588 : type = SymbolTable_GetSType (sym);
8161 471588 : if (! ((*q.proc) (type)))
8162 : {
8163 : result = false;
8164 : }
8165 471588 : subscript = SymbolTable_GetArraySubscript (sym);
8166 471588 : if (subscript != SymbolTable_NulSym)
8167 : {
8168 471588 : M2Debug_Assert (SymbolTable_IsSubscript (subscript));
8169 471588 : type = SymbolTable_GetSType (subscript);
8170 471588 : if (! ((*q.proc) (type)))
8171 : {
8172 271538 : result = false;
8173 : }
8174 471588 : type = SymbolTable_SkipType (type);
8175 : /* the array might be declared as ARRAY type OF foo */
8176 471588 : low = M2GCCDeclare_GetTypeMin (type);
8177 471588 : high = M2GCCDeclare_GetTypeMax (type);
8178 471588 : if (! ((*q.proc) (low)))
8179 : {
8180 100458 : result = false;
8181 : }
8182 471588 : if (! ((*q.proc) (high)))
8183 : {
8184 95092 : result = false;
8185 : }
8186 471588 : align = SymbolTable_GetAlignment (sym);
8187 471588 : if ((align != SymbolTable_NulSym) && (! ((*q.proc) (align))))
8188 : {
8189 : result = false;
8190 : }
8191 : }
8192 471588 : return result;
8193 : /* static analysis guarentees a RETURN statement will be used before here. */
8194 : __builtin_unreachable ();
8195 : }
8196 :
8197 :
8198 : /*
8199 : WalkArrayDependants - walks symbol, sym, dependants.
8200 : */
8201 :
8202 4737188 : static void WalkArrayDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
8203 : {
8204 4737188 : unsigned int align;
8205 4737188 : unsigned int subscript;
8206 4737188 : unsigned int high;
8207 4737188 : unsigned int low;
8208 4737188 : unsigned int type;
8209 :
8210 4737188 : M2Debug_Assert (SymbolTable_IsArray (sym));
8211 4737188 : type = SymbolTable_GetSType (sym);
8212 4737188 : (*p.proc) (type);
8213 4737188 : subscript = SymbolTable_GetArraySubscript (sym);
8214 4737188 : if (subscript != SymbolTable_NulSym)
8215 : {
8216 4737188 : M2Debug_Assert (SymbolTable_IsSubscript (subscript));
8217 4737188 : type = SymbolTable_GetSType (subscript);
8218 4737188 : (*p.proc) (type);
8219 4737188 : align = SymbolTable_GetAlignment (sym);
8220 4737188 : if (align != SymbolTable_NulSym)
8221 : {
8222 42 : (*p.proc) (align);
8223 : }
8224 4737188 : type = SymbolTable_SkipType (type);
8225 : /* the array might be declared as ARRAY type OF foo */
8226 4737188 : low = M2GCCDeclare_GetTypeMin (type);
8227 4737188 : high = M2GCCDeclare_GetTypeMax (type);
8228 4737188 : (*p.proc) (low);
8229 4737188 : (*p.proc) (high);
8230 : }
8231 4737188 : }
8232 :
8233 :
8234 : /*
8235 : DeclareSetArray -
8236 : */
8237 :
8238 60424 : static unsigned int DeclareSetArray (unsigned int sym, unsigned int low, unsigned int high)
8239 : {
8240 60424 : unsigned int tok;
8241 60424 : unsigned int subrange;
8242 60424 : unsigned int highbyte;
8243 60424 : tree bytes;
8244 60424 : NameKey_Name name;
8245 :
8246 60424 : tok = SymbolTable_GetDeclaredMod (sym);
8247 60424 : SymbolTable_PushValue (high);
8248 60424 : M2ALU_ConvertToInt ();
8249 60424 : SymbolTable_PushValue (low);
8250 60424 : M2ALU_ConvertToInt ();
8251 60424 : M2ALU_Sub ();
8252 60424 : M2ALU_PushCard (8);
8253 60424 : M2ALU_DivTrunc ();
8254 60424 : bytes = M2ALU_PopIntegerTree ();
8255 60424 : subrange = SymbolTable_MakeSubrange (tok, NameKey_NulName);
8256 60424 : tempset += 1;
8257 60424 : name = NameKey_makekey (DynamicStrings_string (FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "_Tset%d", 7)), (const unsigned char *) &tempset, (sizeof (tempset)-1))));
8258 60424 : highbyte = SymbolTable_MakeConstVar (tok, name);
8259 60424 : SymbolTable_PutConst (highbyte, M2Base_Cardinal);
8260 60424 : SymbolConversion_AddModGcc (highbyte, bytes);
8261 60424 : SymbolTable_PushValue (high);
8262 60424 : M2ALU_ConvertToInt ();
8263 60424 : SymbolTable_PushValue (low);
8264 60424 : M2ALU_ConvertToInt ();
8265 60424 : M2ALU_Sub ();
8266 60424 : M2ALU_PushCard (static_cast<unsigned int> (m2decl_GetBitsPerBitset ()));
8267 60424 : SymbolTable_PutSetInWord (sym, M2ALU_Less (tok));
8268 60424 : DeclareConstFully (highbyte);
8269 60424 : SymbolTable_PutSubrange (subrange, SymbolTable_MakeConstLit (tok, NameKey_MakeKey ((const char *) "0", 1), M2Base_Cardinal), highbyte, M2Base_Cardinal);
8270 60424 : return SymbolTable_MakeSetArray (tok, subrange);
8271 : /* static analysis guarentees a RETURN statement will be used before here. */
8272 : __builtin_unreachable ();
8273 : }
8274 :
8275 :
8276 : /*
8277 : IsSetDependants - returns TRUE if the symbol, sym,
8278 : q(dependants) all return TRUE.
8279 : */
8280 :
8281 38972 : static bool IsSetDependants (unsigned int sym, M2GCCDeclare_IsAction q)
8282 : {
8283 38972 : bool result;
8284 38972 : unsigned int type;
8285 38972 : unsigned int low;
8286 38972 : unsigned int high;
8287 38972 : unsigned int array;
8288 :
8289 38972 : result = true;
8290 38972 : M2Debug_Assert (SymbolTable_IsSet (sym));
8291 38972 : type = SymbolTable_GetDType (sym);
8292 38972 : if (! ((*q.proc) (type)))
8293 : {
8294 : result = false;
8295 : }
8296 38972 : low = M2GCCDeclare_GetTypeMin (type);
8297 38972 : high = M2GCCDeclare_GetTypeMax (type);
8298 38972 : if (! ((*q.proc) (low)))
8299 : {
8300 3802 : result = false;
8301 : }
8302 38972 : if (! ((*q.proc) (high)))
8303 : {
8304 3406 : result = false;
8305 : }
8306 38972 : array = SymbolTable_GetSetArray (sym);
8307 38972 : if (array == SymbolTable_NulSym)
8308 : {
8309 17748 : result = false;
8310 : }
8311 38972 : return result;
8312 : /* static analysis guarentees a RETURN statement will be used before here. */
8313 : __builtin_unreachable ();
8314 : }
8315 :
8316 :
8317 : /*
8318 : WalkSetDependants - walks dependants, sym.
8319 : */
8320 :
8321 1622972 : static void WalkSetDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
8322 : {
8323 1622972 : unsigned int type;
8324 1622972 : unsigned int low;
8325 1622972 : unsigned int high;
8326 1622972 : unsigned int array;
8327 :
8328 1622972 : M2Debug_Assert (SymbolTable_IsSet (sym));
8329 1622972 : type = SymbolTable_GetDType (sym);
8330 1622972 : (*p.proc) (type);
8331 1622972 : low = M2GCCDeclare_GetTypeMin (type);
8332 1622972 : (*p.proc) (low);
8333 1622972 : high = M2GCCDeclare_GetTypeMax (type);
8334 1622972 : (*p.proc) (high);
8335 1622972 : array = SymbolTable_GetSetArray (sym);
8336 1622972 : if (array != SymbolTable_NulSym)
8337 : {
8338 1232210 : (*p.proc) (array);
8339 : }
8340 1622972 : }
8341 :
8342 :
8343 : /*
8344 : IsProcTypeDependants -
8345 : */
8346 :
8347 283242 : static bool IsProcTypeDependants (unsigned int sym, M2GCCDeclare_IsAction q)
8348 : {
8349 283242 : unsigned int i;
8350 283242 : unsigned int p;
8351 283242 : unsigned int son;
8352 283242 : unsigned int ParamType;
8353 283242 : unsigned int ReturnType;
8354 283242 : bool result;
8355 :
8356 283242 : result = true;
8357 283242 : M2Debug_Assert (SymbolTable_IsProcType (sym));
8358 283242 : i = 1;
8359 283242 : ReturnType = SymbolTable_GetSType (sym);
8360 283242 : p = SymbolTable_NoOfParamAny (sym);
8361 846616 : while (i <= p)
8362 : {
8363 280132 : son = SymbolTable_GetNthParamAny (sym, i);
8364 280132 : ParamType = SymbolTable_GetSType (son);
8365 280132 : if (! ((*q.proc) (ParamType)))
8366 : {
8367 120638 : result = false;
8368 : }
8369 280132 : i += 1;
8370 : }
8371 283242 : if ((ReturnType == SymbolTable_NulSym) || ((*q.proc) (ReturnType)))
8372 : {
8373 283242 : return result;
8374 : }
8375 : else
8376 : {
8377 : return false;
8378 : }
8379 : /* static analysis guarentees a RETURN statement will be used before here. */
8380 : __builtin_unreachable ();
8381 : }
8382 :
8383 :
8384 : /*
8385 : WalkProcTypeDependants - walks dependants, sym.
8386 : */
8387 :
8388 4705800 : static void WalkProcTypeDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
8389 : {
8390 4705800 : unsigned int i;
8391 4705800 : unsigned int n;
8392 4705800 : unsigned int son;
8393 4705800 : unsigned int ParamType;
8394 4705800 : unsigned int ReturnType;
8395 :
8396 4705800 : M2Debug_Assert (SymbolTable_IsProcType (sym));
8397 4705800 : i = 1;
8398 4705800 : ReturnType = SymbolTable_GetSType (sym);
8399 4705800 : n = SymbolTable_NoOfParamAny (sym);
8400 17476170 : while (i <= n)
8401 : {
8402 8064570 : son = SymbolTable_GetNthParamAny (sym, i);
8403 8064570 : ParamType = SymbolTable_GetSType (son);
8404 8064570 : (*p.proc) (ParamType);
8405 8064570 : i += 1;
8406 : }
8407 4705800 : if (ReturnType != SymbolTable_NulSym)
8408 : {
8409 570134 : (*p.proc) (ReturnType);
8410 : }
8411 4705800 : }
8412 :
8413 :
8414 : /*
8415 : IsProcedureDependants -
8416 : */
8417 :
8418 426 : static bool IsProcedureDependants (unsigned int sym, M2GCCDeclare_IsAction q)
8419 : {
8420 426 : unsigned int i;
8421 426 : unsigned int son;
8422 426 : unsigned int type;
8423 426 : unsigned int ReturnType;
8424 426 : bool result;
8425 :
8426 426 : result = true;
8427 426 : M2Debug_Assert (SymbolTable_IsProcedure (sym));
8428 426 : i = 1;
8429 426 : ReturnType = SymbolTable_GetSType (sym);
8430 1434 : while ((SymbolTable_GetNth (sym, i)) != SymbolTable_NulSym)
8431 : {
8432 582 : son = SymbolTable_GetNth (sym, i);
8433 582 : type = SymbolTable_GetSType (son);
8434 582 : if (! ((*q.proc) (type)))
8435 : {
8436 36 : result = false;
8437 : }
8438 582 : i += 1;
8439 : }
8440 426 : if ((ReturnType == SymbolTable_NulSym) || ((*q.proc) (ReturnType)))
8441 : {
8442 426 : return result;
8443 : }
8444 : else
8445 : {
8446 : return false;
8447 : }
8448 : /* static analysis guarentees a RETURN statement will be used before here. */
8449 : __builtin_unreachable ();
8450 : }
8451 :
8452 :
8453 : /*
8454 : WalkProcedureDependants - walks dependants, sym.
8455 : */
8456 :
8457 6206060 : static void WalkProcedureDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
8458 : {
8459 6206060 : unsigned int i;
8460 6206060 : unsigned int son;
8461 6206060 : unsigned int type;
8462 6206060 : unsigned int ReturnType;
8463 :
8464 6206060 : M2Debug_Assert (SymbolTable_IsProcedure (sym));
8465 6206060 : i = 1;
8466 6206060 : ReturnType = SymbolTable_GetSType (sym);
8467 31142816 : while ((SymbolTable_GetNth (sym, i)) != SymbolTable_NulSym)
8468 : {
8469 18730696 : son = SymbolTable_GetNth (sym, i);
8470 18730696 : type = SymbolTable_GetSType (son);
8471 18730696 : (*p.proc) (type);
8472 18730696 : i += 1;
8473 : }
8474 6206060 : if (ReturnType != SymbolTable_NulSym)
8475 : {
8476 3513141 : (*p.proc) (ReturnType);
8477 : }
8478 6206060 : }
8479 :
8480 :
8481 : /*
8482 : IsUnboundedDependants - returns TRUE if the symbol, sym,
8483 : q (dependants) all return TRUE.
8484 : */
8485 :
8486 196734 : static bool IsUnboundedDependants (unsigned int sym, M2GCCDeclare_IsAction q)
8487 : {
8488 196734 : bool result;
8489 :
8490 196734 : result = true;
8491 196734 : if (! ((*q.proc) (SymbolTable_GetUnboundedRecordType (sym))))
8492 : {
8493 : result = false;
8494 : }
8495 196734 : if (! ((*q.proc) (M2Base_Cardinal)))
8496 : {
8497 0 : result = false;
8498 : }
8499 196734 : if (! ((*q.proc) (SymbolTable_GetSType (sym))))
8500 : {
8501 54 : result = false;
8502 : }
8503 196734 : return result;
8504 : /* static analysis guarentees a RETURN statement will be used before here. */
8505 : __builtin_unreachable ();
8506 : }
8507 :
8508 :
8509 : /*
8510 : WalkUnboundedDependants - walks the dependants of, sym.
8511 : */
8512 :
8513 25913411 : static void WalkUnboundedDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
8514 : {
8515 25913411 : (*p.proc) (SymbolTable_GetUnboundedRecordType (sym));
8516 25913411 : (*p.proc) (M2Base_Cardinal);
8517 25913411 : (*p.proc) (SymbolTable_GetSType (sym));
8518 25913411 : }
8519 :
8520 :
8521 : /*
8522 : IsTypeDependants - returns TRUE if all q(dependants) return
8523 : TRUE.
8524 : */
8525 :
8526 593657 : static bool IsTypeDependants (unsigned int sym, M2GCCDeclare_IsAction q)
8527 : {
8528 593657 : unsigned int align;
8529 593657 : unsigned int type;
8530 593657 : bool final;
8531 :
8532 593657 : type = SymbolTable_GetSType (sym);
8533 593657 : final = true;
8534 593657 : if ((type != SymbolTable_NulSym) && (! ((*q.proc) (type))))
8535 : {
8536 : final = false;
8537 : }
8538 593657 : align = SymbolTable_GetAlignment (sym);
8539 593657 : if ((align != SymbolTable_NulSym) && (! ((*q.proc) (align))))
8540 : {
8541 : final = false;
8542 : }
8543 593657 : return final;
8544 : /* static analysis guarentees a RETURN statement will be used before here. */
8545 : __builtin_unreachable ();
8546 : }
8547 :
8548 :
8549 : /*
8550 : WalkTypeDependants - walks all dependants of, sym.
8551 : */
8552 :
8553 84054196 : static void WalkTypeDependants (unsigned int sym, M2GCCDeclare_WalkAction p)
8554 : {
8555 84054196 : unsigned int align;
8556 84054196 : unsigned int type;
8557 :
8558 84054196 : type = SymbolTable_GetSType (sym);
8559 84054196 : if (type != SymbolTable_NulSym)
8560 : {
8561 2344484 : (*p.proc) (type);
8562 : }
8563 84054196 : align = SymbolTable_GetAlignment (sym);
8564 84054196 : if (align != SymbolTable_NulSym)
8565 : {
8566 36 : (*p.proc) (align);
8567 : }
8568 84054196 : }
8569 :
8570 :
8571 : /*
8572 : FoldConstants - a wrapper for ResolveConstantExpressions.
8573 : */
8574 :
8575 91413565 : extern "C" void M2GCCDeclare_FoldConstants (M2BasicBlock_BasicBlock bb)
8576 : {
8577 91413565 : if (M2GenGCC_ResolveConstantExpressions ((M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) DeclareConstFully}, bb))
8578 : {
8579 140457 : ConstantResolved = true;
8580 : }
8581 91413391 : }
8582 :
8583 :
8584 : /*
8585 : StartDeclareScope - declares types, variables associated with this scope.
8586 : */
8587 :
8588 91637 : extern "C" void M2GCCDeclare_StartDeclareScope (unsigned int scope)
8589 : {
8590 91637 : NameKey_Name n;
8591 :
8592 91637 : if (Debugging)
8593 : {
8594 : n = SymbolTable_GetSymName (scope);
8595 : M2Printf_printf1 ((const char *) "declaring symbols in BLOCK %a\\n", 31, (const unsigned char *) &n, (sizeof (n)-1));
8596 : }
8597 91637 : if (SymbolTable_IsProcedure (scope))
8598 : {
8599 76761 : StartDeclareProcedureScope (scope);
8600 : }
8601 : else
8602 : {
8603 14876 : StartDeclareModuleScope (scope);
8604 : }
8605 91571 : if (Debugging)
8606 : {
8607 : n = SymbolTable_GetSymName (scope);
8608 : M2Printf_printf1 ((const char *) "\\nEND declaring symbols in BLOCK %a\\n", 37, (const unsigned char *) &n, (sizeof (n)-1));
8609 : }
8610 91571 : }
8611 :
8612 :
8613 : /*
8614 : EndDeclareScope -
8615 : */
8616 :
8617 0 : extern "C" void M2GCCDeclare_EndDeclareScope (void)
8618 : {
8619 0 : }
8620 :
8621 :
8622 : /*
8623 : DeclareParameters -
8624 : */
8625 :
8626 205633 : extern "C" void M2GCCDeclare_DeclareParameters (unsigned int sym)
8627 : {
8628 205633 : DeclareUnboundedProcedureParameters (sym);
8629 205633 : }
8630 :
8631 :
8632 : /*
8633 : DeclareConstant - checks to see whether, sym, is a constant and
8634 : declares the constant to gcc.
8635 : */
8636 :
8637 1959305 : extern "C" void M2GCCDeclare_DeclareConstant (unsigned int tokenno, unsigned int sym)
8638 : {
8639 1959305 : unsigned int type;
8640 1959305 : tree t;
8641 :
8642 1959305 : if (SymbolTable_IsConst (sym))
8643 : {
8644 1061813 : TraverseDependants (sym);
8645 1061813 : type = SymbolTable_GetSType (sym);
8646 2123626 : M2Debug_Assert ((type == SymbolTable_NulSym) || (M2GCCDeclare_CompletelyResolved (type)));
8647 2123626 : M2Debug_Assert ((! (SymbolTable_IsConstructor (sym))) || (SymbolTable_IsConstructorConstant (sym)));
8648 2123626 : M2Debug_Assert ((type != SymbolTable_NulSym) || (! ((SymbolTable_IsConstructor (sym)) || (SymbolTable_IsConstSet (sym)))));
8649 1061813 : t = DeclareConst (tokenno, sym);
8650 1061813 : M2Debug_Assert (t != NULL);
8651 : }
8652 1959305 : }
8653 :
8654 :
8655 : /*
8656 : DeclareConstructor - declares a constructor.
8657 : */
8658 :
8659 1429854 : extern "C" void M2GCCDeclare_DeclareConstructor (unsigned int tokenno, unsigned int quad, unsigned int sym)
8660 : {
8661 1429854 : if (sym == SymbolTable_NulSym)
8662 : {
8663 0 : M2Error_InternalError ((const char *) "trying to declare the NulSym", 28);
8664 : }
8665 1429854 : if ((SymbolTable_IsConstructor (sym)) && (! (SymbolConversion_GccKnowsAbout (sym))))
8666 : {
8667 0 : WalkConstructor (sym, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) TraverseDependants});
8668 0 : DeclareTypesConstantsProceduresInRange (SymbolTable_GetScope (sym), quad, quad);
8669 0 : M2Debug_Assert (M2ALU_IsConstructorDependants (sym, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) IsFullyDeclared}));
8670 0 : SymbolTable_PushValue (sym);
8671 0 : DeclareConstantFromTree (sym, M2ALU_PopConstructorTree (tokenno));
8672 : }
8673 1429854 : }
8674 :
8675 :
8676 : /*
8677 : TryDeclareConstant - try and declare a constant. If, sym, is a
8678 : constant try and declare it, if we cannot
8679 : then enter it into the to do list.
8680 : */
8681 :
8682 36077023 : extern "C" void M2GCCDeclare_TryDeclareConstant (unsigned int tokenno, unsigned int sym)
8683 : {
8684 36077023 : unsigned int type;
8685 :
8686 36077023 : M2GCCDeclare_TryDeclareConstructor (tokenno, sym);
8687 36077017 : if (SymbolTable_IsConst (sym))
8688 : {
8689 11471202 : TraverseDependants (sym);
8690 11471202 : type = SymbolTable_GetSType (sym);
8691 11471202 : if ((type != SymbolTable_NulSym) && (! (M2GCCDeclare_CompletelyResolved (type))))
8692 : {
8693 40392 : TraverseDependants (sym);
8694 40392 : return;
8695 : }
8696 11430810 : if ((SymbolTable_IsConstructor (sym)) && (! (SymbolTable_IsConstructorConstant (sym))))
8697 : {
8698 0 : TraverseDependants (sym);
8699 0 : return;
8700 : }
8701 11430810 : if (((SymbolTable_IsConstructor (sym)) || (SymbolTable_IsConstSet (sym))) && (type == SymbolTable_NulSym))
8702 : {
8703 378 : TraverseDependants (sym);
8704 378 : return;
8705 : }
8706 11430432 : if (Sets_IsElementInSet (GlobalGroup->ToBeSolvedByQuads, sym))
8707 : {
8708 : /* we allow the above rules to be executed even if it is fully declared
8709 : so to ensure that types of compiler builtin constants (BitsetSize
8710 : etc) are fully declared.
8711 :
8712 : However at this point if, sym, is fully declared we return
8713 : */
8714 334404 : if (IsFullyDeclared (sym))
8715 : {
8716 : return;
8717 : }
8718 334374 : TraverseDependants (sym);
8719 : }
8720 : else
8721 : {
8722 11096028 : TryDeclareConst (tokenno, sym);
8723 : }
8724 : }
8725 : }
8726 :
8727 :
8728 : /*
8729 : TryDeclareType - try and declare a type. If sym is a
8730 : type try and declare it, if we cannot
8731 : then enter it into the to do list.
8732 : */
8733 :
8734 6388 : extern "C" void M2GCCDeclare_TryDeclareType (unsigned int type)
8735 : {
8736 6388 : if ((type != SymbolTable_NulSym) && (IsAnyType (type)))
8737 : {
8738 6388 : TraverseDependants (type);
8739 : }
8740 6388 : }
8741 :
8742 :
8743 : /*
8744 : TryDeclareConstructor - try and declare a constructor. If, sym, is a
8745 : constructor try and declare it, if we cannot
8746 : then enter it into the to do list.
8747 : */
8748 :
8749 41154114 : extern "C" void M2GCCDeclare_TryDeclareConstructor (unsigned int tokenno, unsigned int sym)
8750 : {
8751 41154114 : if (sym != SymbolTable_NulSym)
8752 : {
8753 41154114 : if ((SymbolTable_IsConstructor (sym)) && (! (SymbolConversion_GccKnowsAbout (sym))))
8754 : {
8755 61824 : WalkConstructor (sym, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) TraverseDependants});
8756 61824 : if (! (Sets_IsElementInSet (GlobalGroup->ToBeSolvedByQuads, sym)))
8757 : {
8758 49882 : M2ALU_TryEvaluateValue (sym);
8759 49876 : if (M2ALU_IsConstructorDependants (sym, (M2GCCDeclare_IsAction) {(M2GCCDeclare_IsAction_t) IsFullyDeclared}))
8760 : {
8761 6684 : SymbolTable_PushValue (sym);
8762 6684 : DeclareConstantFromTree (sym, M2ALU_PopConstructorTree (tokenno));
8763 : }
8764 : }
8765 : }
8766 : }
8767 41154108 : }
8768 :
8769 :
8770 : /*
8771 : DeclareLocalVariables - declares Local variables for procedure.
8772 : */
8773 :
8774 76761 : extern "C" void M2GCCDeclare_DeclareLocalVariables (unsigned int procedure)
8775 : {
8776 76761 : unsigned int i;
8777 76761 : unsigned int var;
8778 :
8779 76761 : i = (SymbolTable_NoOfParamAny (procedure))+1;
8780 76761 : var = SymbolTable_GetNth (procedure, i);
8781 816416 : while (var != SymbolTable_NulSym)
8782 : {
8783 662894 : M2Debug_Assert (procedure == (SymbolTable_GetScope (var)));
8784 662894 : M2GCCDeclare_DeclareLocalVariable (var);
8785 662894 : i += 1;
8786 662894 : var = SymbolTable_GetNth (procedure, i);
8787 : }
8788 76761 : }
8789 :
8790 :
8791 : /*
8792 : DeclareLocalVariable - declare a local variable var.
8793 : */
8794 :
8795 662894 : extern "C" void M2GCCDeclare_DeclareLocalVariable (unsigned int var)
8796 : {
8797 662894 : DoVariableDeclaration (var, NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (var)), false, false, SymbolTable_IsTemporary (var), false, SymbolConversion_Mod2Gcc (SymbolTable_GetScope (var))); /* and are not global */
8798 662894 : }
8799 :
8800 :
8801 : /*
8802 : DeclareProcedure - declares procedure, sym, or all procedures inside
8803 : module sym.
8804 : */
8805 :
8806 5956811 : extern "C" void M2GCCDeclare_DeclareProcedure (unsigned int sym)
8807 : {
8808 5956811 : if (SymbolTable_IsProcedure (sym))
8809 : {
8810 5745712 : DeclareProcedureToGcc (sym);
8811 : }
8812 211099 : else if ((SymbolTable_IsModule (sym)) || (SymbolTable_IsDefImp (sym)))
8813 : {
8814 : /* avoid dangling else. */
8815 211099 : SymbolTable_ForeachProcedureDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_DeclareProcedure});
8816 : }
8817 : else
8818 : {
8819 : /* avoid dangling else. */
8820 0 : M2Error_InternalError ((const char *) "expecting procedure", 19);
8821 : }
8822 5956811 : }
8823 :
8824 :
8825 : /*
8826 : DeclareModuleVariables - declares Module variables for a module
8827 : which was declared inside a procedure.
8828 : */
8829 :
8830 144 : extern "C" void M2GCCDeclare_DeclareModuleVariables (unsigned int sym)
8831 : {
8832 144 : tree scope;
8833 144 : unsigned int i;
8834 144 : unsigned int Var;
8835 :
8836 144 : i = 1;
8837 144 : scope = SymbolConversion_Mod2Gcc (SymbolTable_GetProcedureScope (sym));
8838 144 : Var = SymbolTable_GetNth (sym, i);
8839 366 : while (Var != SymbolTable_NulSym)
8840 : {
8841 78 : DoVariableDeclaration (Var, NameKey_KeyToCharStar (M2AsmUtil_GetFullSymName (Var)), false, false, SymbolTable_IsTemporary (Var), false, scope); /* and are not global */
8842 78 : i += 1;
8843 78 : Var = SymbolTable_GetNth (sym, i);
8844 : }
8845 144 : }
8846 :
8847 :
8848 : /*
8849 : IsProcedureGccNested - returns TRUE if procedure, sym, will be considered
8850 : as nested by GCC.
8851 : This will occur if either its outer defining scope
8852 : is a procedure or is a module which is inside a
8853 : procedure.
8854 : */
8855 :
8856 3741991 : extern "C" bool M2GCCDeclare_IsProcedureGccNested (unsigned int sym)
8857 : {
8858 3741991 : return (SymbolTable_IsProcedureNested (sym)) || ((SymbolTable_IsModule (SymbolTable_GetScope (sym))) && (SymbolTable_IsModuleWithinProcedure (SymbolTable_GetScope (sym))));
8859 : /* static analysis guarentees a RETURN statement will be used before here. */
8860 : __builtin_unreachable ();
8861 : }
8862 :
8863 :
8864 : /*
8865 : PoisonSymbols - poisons all gcc symbols from procedure, sym.
8866 : A debugging aid.
8867 : */
8868 :
8869 76749 : extern "C" void M2GCCDeclare_PoisonSymbols (unsigned int sym)
8870 : {
8871 76749 : if (SymbolTable_IsProcedure (sym))
8872 : {
8873 76749 : SymbolTable_ForeachLocalSymDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) SymbolConversion_Poison});
8874 : }
8875 76749 : }
8876 :
8877 :
8878 : /*
8879 : PromoteToString - declare, sym, and then promote it to a string.
8880 : Note that if sym is a single character we do
8881 : *not* record it as a string
8882 : but as a char however we always
8883 : return a string constant.
8884 : */
8885 :
8886 24745 : extern "C" tree M2GCCDeclare_PromoteToString (unsigned int tokenno, unsigned int sym)
8887 : {
8888 24745 : unsigned int size;
8889 24745 : char ch;
8890 :
8891 24745 : M2GCCDeclare_DeclareConstant (tokenno, sym);
8892 24745 : if ((SymbolTable_IsConst (sym)) && ((SymbolTable_GetSType (sym)) == M2Base_Char))
8893 : {
8894 1960 : SymbolTable_PushValue (sym);
8895 1960 : ch = M2ALU_PopChar (tokenno);
8896 1960 : return m2decl_BuildCStringConstant (const_cast <const char * > (static_cast <char * > (DynamicStrings_string (DynamicStrings_InitStringChar (ch)))), 1);
8897 : }
8898 : else
8899 : {
8900 22785 : M2Debug_Assert (SymbolTable_IsConstStringKnown (sym));
8901 22785 : size = SymbolTable_GetStringLength (tokenno, sym);
8902 22785 : if (size > 1)
8903 : {
8904 : /* It will be already be declared as a string, so return it. */
8905 22187 : return (tree) (SymbolConversion_Mod2Gcc (sym));
8906 : }
8907 : else
8908 : {
8909 598 : return m2decl_BuildStringConstant (const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetString (sym)))), static_cast<int> (SymbolTable_GetStringLength (tokenno, sym)));
8910 : }
8911 : }
8912 : /* static analysis guarentees a RETURN statement will be used before here. */
8913 : __builtin_unreachable ();
8914 : }
8915 :
8916 :
8917 : /*
8918 : PromoteToCString - declare, sym, and then promote it to a string.
8919 : Note that if sym is a single character we do
8920 : *not* record it as a string
8921 : but as a char however we always
8922 : return a string constant.
8923 : */
8924 :
8925 60 : extern "C" tree M2GCCDeclare_PromoteToCString (unsigned int tokenno, unsigned int sym)
8926 : {
8927 60 : unsigned int size;
8928 60 : char ch;
8929 :
8930 60 : M2GCCDeclare_DeclareConstant (tokenno, sym);
8931 60 : M2Debug_Assert (SymbolTable_IsConstStringKnown (sym));
8932 60 : if ((SymbolTable_IsConst (sym)) && ((SymbolTable_GetSType (sym)) == M2Base_Char))
8933 : {
8934 12 : SymbolTable_PushValue (sym);
8935 12 : ch = M2ALU_PopChar (tokenno);
8936 12 : return m2decl_BuildCStringConstant (const_cast <const char * > (static_cast <char * > (DynamicStrings_string (DynamicStrings_InitStringChar (ch)))), 1);
8937 : }
8938 : else
8939 : {
8940 48 : size = SymbolTable_GetStringLength (tokenno, sym);
8941 48 : return m2decl_BuildCStringConstant (const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetString (sym)))), static_cast<int> (size));
8942 : }
8943 : /* static analysis guarentees a RETURN statement will be used before here. */
8944 : __builtin_unreachable ();
8945 : }
8946 :
8947 :
8948 : /*
8949 : CompletelyResolved - returns TRUE if a symbols has been completely resolved
8950 : and is not partically declared (such as a record).
8951 : */
8952 :
8953 12481601 : extern "C" bool M2GCCDeclare_CompletelyResolved (unsigned int sym)
8954 : {
8955 12481601 : return Sets_IsElementInSet (GlobalGroup->FullyDeclared, sym);
8956 : /* static analysis guarentees a RETURN statement will be used before here. */
8957 : __builtin_unreachable ();
8958 : }
8959 :
8960 :
8961 : /*
8962 : ConstantKnownAndUsed -
8963 : */
8964 :
8965 30 : extern "C" void M2GCCDeclare_ConstantKnownAndUsed (unsigned int sym, tree t)
8966 : {
8967 30 : DeclareConstantFromTree (sym, m2block_RememberConstant (t));
8968 30 : }
8969 :
8970 :
8971 : /*
8972 : PutToBeSolvedByQuads - places, sym, to this list and returns,
8973 : sym.
8974 : */
8975 :
8976 362084 : extern "C" void M2GCCDeclare_PutToBeSolvedByQuads (unsigned int sym)
8977 : {
8978 362084 : WatchIncludeList (sym, M2GCCDeclare_tobesolvedbyquads);
8979 362084 : }
8980 :
8981 :
8982 : /*
8983 : MarkExported - tell GCC to mark all exported procedures in module sym.
8984 : */
8985 :
8986 22268 : extern "C" void M2GCCDeclare_MarkExported (unsigned int sym)
8987 : {
8988 22268 : if (M2Options_Optimizing)
8989 : {
8990 14911 : m2type_MarkFunctionReferenced (SymbolConversion_Mod2Gcc (sym));
8991 14911 : if ((SymbolTable_IsDefImp (sym)) || (SymbolTable_IsModule (sym)))
8992 : {
8993 6295 : SymbolTable_ForeachExportedDo (sym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2GCCDeclare_MarkExported});
8994 : }
8995 : }
8996 22268 : }
8997 :
8998 :
8999 : /*
9000 : GetTypeMin -
9001 : */
9002 :
9003 7574330 : extern "C" unsigned int M2GCCDeclare_GetTypeMin (unsigned int type)
9004 : {
9005 7575972 : unsigned int min;
9006 7575972 : unsigned int max;
9007 :
9008 7575972 : if (SymbolTable_IsSubrange (type))
9009 : {
9010 7124866 : SymbolTable_GetSubrange (type, &max, &min);
9011 7124866 : return min;
9012 : }
9013 451106 : else if (SymbolTable_IsSet (type))
9014 : {
9015 : /* avoid dangling else. */
9016 1624 : return M2GCCDeclare_GetTypeMin (SymbolTable_GetSType (type));
9017 : }
9018 449482 : else if (SymbolTable_IsEnumeration (type))
9019 : {
9020 : /* avoid dangling else. */
9021 432254 : MinEnumerationField = SymbolTable_NulSym;
9022 432254 : MaxEnumerationField = SymbolTable_NulSym;
9023 432254 : SymbolTable_ForeachLocalSymDo (type, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) FindMinMaxEnum});
9024 432254 : return MinEnumerationField;
9025 : }
9026 17228 : else if (IsBaseType (type))
9027 : {
9028 : /* avoid dangling else. */
9029 17210 : M2Base_GetBaseTypeMinMax (type, &min, &max);
9030 17210 : return min;
9031 : }
9032 18 : else if (M2System_IsSystemType (type))
9033 : {
9034 : /* avoid dangling else. */
9035 0 : M2System_GetSystemTypeMinMax (type, &min, &max);
9036 0 : return min;
9037 : }
9038 18 : else if ((SymbolTable_GetSType (type)) == SymbolTable_NulSym)
9039 : {
9040 : /* avoid dangling else. */
9041 0 : M2MetaError_MetaError1 ((const char *) "unable to obtain the MIN value for type {%1as}", 46, type);
9042 0 : return SymbolTable_NulSym;
9043 : }
9044 : else
9045 : {
9046 : /* avoid dangling else. */
9047 18 : return M2GCCDeclare_GetTypeMin (SymbolTable_GetSType (type));
9048 : }
9049 : /* static analysis guarentees a RETURN statement will be used before here. */
9050 : __builtin_unreachable ();
9051 : }
9052 :
9053 :
9054 : /*
9055 : GetTypeMax -
9056 : */
9057 :
9058 7527596 : extern "C" unsigned int M2GCCDeclare_GetTypeMax (unsigned int type)
9059 : {
9060 7529238 : unsigned int min;
9061 7529238 : unsigned int max;
9062 :
9063 7529238 : if (SymbolTable_IsSubrange (type))
9064 : {
9065 7079150 : SymbolTable_GetSubrange (type, &max, &min);
9066 7079150 : return max;
9067 : }
9068 450088 : else if (SymbolTable_IsSet (type))
9069 : {
9070 : /* avoid dangling else. */
9071 1624 : return M2GCCDeclare_GetTypeMax (SymbolTable_GetSType (type));
9072 : }
9073 448464 : else if (SymbolTable_IsEnumeration (type))
9074 : {
9075 : /* avoid dangling else. */
9076 431254 : MinEnumerationField = SymbolTable_NulSym;
9077 431254 : MaxEnumerationField = SymbolTable_NulSym;
9078 431254 : SymbolTable_ForeachLocalSymDo (type, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) FindMinMaxEnum});
9079 431254 : return MaxEnumerationField;
9080 : }
9081 17210 : else if (IsBaseType (type))
9082 : {
9083 : /* avoid dangling else. */
9084 17192 : M2Base_GetBaseTypeMinMax (type, &min, &max);
9085 17192 : return max;
9086 : }
9087 18 : else if (M2System_IsSystemType (type))
9088 : {
9089 : /* avoid dangling else. */
9090 0 : M2System_GetSystemTypeMinMax (type, &min, &max);
9091 0 : return max;
9092 : }
9093 18 : else if ((SymbolTable_GetSType (type)) == SymbolTable_NulSym)
9094 : {
9095 : /* avoid dangling else. */
9096 0 : M2MetaError_MetaError1 ((const char *) "unable to obtain the MAX value for type {%1as}", 46, type);
9097 0 : return SymbolTable_NulSym;
9098 : }
9099 : else
9100 : {
9101 : /* avoid dangling else. */
9102 18 : return M2GCCDeclare_GetTypeMax (SymbolTable_GetSType (type));
9103 : }
9104 : /* static analysis guarentees a RETURN statement will be used before here. */
9105 : __builtin_unreachable ();
9106 : }
9107 :
9108 :
9109 : /*
9110 : PrintSym - prints limited information about a symbol.
9111 : This procedure is externally visible.
9112 : */
9113 :
9114 0 : extern "C" void M2GCCDeclare_PrintSym (unsigned int sym)
9115 : {
9116 0 : M2Printf_printf1 ((const char *) "information about symbol: %d\\n", 30, (const unsigned char *) &sym, (sizeof (sym)-1));
9117 0 : M2Printf_fprintf0 (M2LangDump_GetDumpFile (), (const char *) "==============================\\n", 32);
9118 0 : PrintVerbose (sym);
9119 0 : }
9120 :
9121 :
9122 : /*
9123 : IncludeDumpSymbol - include sym into the watch list and all syms dependants.
9124 : */
9125 :
9126 0 : extern "C" void M2GCCDeclare_IncludeDumpSymbol (unsigned int sym)
9127 : {
9128 0 : if (sym != SymbolTable_NulSym)
9129 : {
9130 : /*
9131 : fprintf0 (GetDumpFile (), "
9132 : ") ;
9133 : PrintVerbose (sym) ;
9134 : fprintf0 (GetDumpFile (), "
9135 : ")
9136 : */
9137 0 : AddSymToWatch (sym);
9138 : }
9139 0 : }
9140 :
9141 :
9142 : /*
9143 : DumpFilteredResolver - dumps the gimple or tree representation of all watched symbols.
9144 : */
9145 :
9146 0 : extern "C" void M2GCCDeclare_DumpFilteredResolver (void)
9147 : {
9148 0 : Sets_ForeachElementInSetDo (WatchList, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DumpResolver});
9149 0 : }
9150 :
9151 :
9152 : /*
9153 : DumpFilteredDefinitive - dumps the gimple or tree representation of all watched symbols.
9154 : */
9155 :
9156 0 : extern "C" void M2GCCDeclare_DumpFilteredDefinitive (void)
9157 : {
9158 0 : Sets_ForeachElementInSetDo (WatchList, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) DumpDefinitive});
9159 0 : }
9160 :
9161 :
9162 : /*
9163 : InitDeclarations - initializes default types and the source filename.
9164 : */
9165 :
9166 13940 : extern "C" void M2GCCDeclare_InitDeclarations (void)
9167 : {
9168 13940 : DeclareDefaultTypes ();
9169 13940 : DeclareDefaultConstants ();
9170 13940 : }
9171 :
9172 14952 : extern "C" void _M2_M2GCCDeclare_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
9173 : {
9174 14952 : DeclaredOutstandingTypesDiag = M2Diagnostic_InitTimeDiagnostic ((const char *) "M2GCCDeclare:DeclaredOutstandingTypes", 37, (const char *) "{1N} called {1C} times consuming {1T} ({1P})", 44);
9175 14952 : DeclareTypesConstantsProceduresInRangeDiag = M2Diagnostic_InitTimeDiagnostic ((const char *) "M2GCCDeclare:DeclareTypesConstantsProceduresInRangeDiag", 55, (const char *) "{1N} called {1C} times consuming {1T} ({1P})", 44);
9176 14952 : DeclareTypesConstantsProceduresDiag = M2Diagnostic_InitTimeDiagnostic ((const char *) "M2GCCDeclare:DeclareTypesConstantsProceduresDiag", 48, (const char *) "{1N} called {1C} times consuming {1T} ({1P})", 44);
9177 14952 : FreeGroup = NULL;
9178 14952 : GlobalGroup = InitGroup ();
9179 14952 : ChainedList = Sets_InitSet (1);
9180 14952 : ErrorDepList = Sets_InitSet (1);
9181 14952 : WatchList = Sets_InitSet (1);
9182 14952 : VisitedList = static_cast<Sets_Set> (NULL);
9183 14952 : EnumerationIndex = Indexing_InitIndex (1);
9184 14952 : HaveInitDefaultTypes = false;
9185 14952 : recursionCaught = false;
9186 14952 : tempset = 0;
9187 14952 : }
9188 :
9189 0 : extern "C" void _M2_M2GCCDeclare_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
9190 : {
9191 0 : }
|