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