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