Debian Codegraph @

gcc/m2/gm2-compiler/M2GCCDeclare.mod

raw
1 (* M2GCCDeclare.mod declares Modula-2 types to GCC.
2
3 Copyright (C) 2001-2025 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <[email protected]>.
5
6 This file is part of GNU Modula-2.
7
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Modula-2; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. *)
21
22 IMPLEMENTATION MODULE M2GCCDeclare ;
23
24 (*
25 Title : M2GCCDeclare
26 Author : Gaius Mulley
27 System : UNIX (gm2)
28 Date : Fri Jul 16 20:10:55 1999
29 Description: declares Modula-2 types to GCC, it attempts
30 to only declare a type once all subcomponents are known.
31 *)
32
33 FROM SYSTEM IMPORT ADDRESS, ADR, WORD ;
34 FROM ASCII IMPORT nul ;
35 FROM Storage IMPORT ALLOCATE ;
36 FROM M2Debug IMPORT Assert ;
37 FROM M2Quads IMPORT DisplayQuadRange ;
38 FROM m2pp IMPORT DumpGimpleFd ;
39
40 IMPORT FIO ;
41
42 FROM M2Options IMPORT GenerateDebugging, GenerateLineDebug, Iso, Optimizing, WholeProgram,
43 ScaffoldStatic, GetRuntimeModuleOverride ;
44
45 FROM M2AsmUtil IMPORT GetFullSymName, GetFullScopeAsmName ;
46
47 FROM M2Batch IMPORT MakeDefinitionSource ;
48 FROM NameKey IMPORT Name, MakeKey, NulName, KeyToCharStar, makekey ;
49 FROM M2FileName IMPORT CalculateFileName ;
50 FROM DynamicStrings IMPORT String, string, InitString, KillString, InitStringCharStar, InitStringChar, Mark ;
51 FROM M2LexBuf IMPORT TokenToLineNo, FindFileNameFromToken, TokenToLocation, UnknownTokenNo, BuiltinTokenNo ;
52 FROM M2MetaError IMPORT MetaError1, MetaError2, MetaError3 ;
53 FROM M2Error IMPORT FlushErrors, InternalError ;
54 FROM M2LangDump IMPORT GetDumpFile ;
55
56 FROM M2Printf IMPORT printf0, printf1, printf2, printf3,
57 fprintf0, fprintf1, fprintf2, fprintf3 ;
58
59 FROM Indexing IMPORT Index, InitIndex, PutIndice, GetIndice, InBounds,
60 IncludeIndiceIntoIndex, HighIndice,
61 DebugIndex ;
62
63 FROM Lists IMPORT List, InitList, IncludeItemIntoList,
64 PutItemIntoList, GetItemFromList,
65 RemoveItemFromList, ForeachItemInListDo,
66 IsItemInList, NoOfItemsInList, KillList ;
67
68 FROM Sets IMPORT Set, InitSet, KillSet,
69 IncludeElementIntoSet, ExcludeElementFromSet,
70 NoOfElementsInSet, IsElementInSet, ForeachElementInSetDo,
71 DuplicateSet, EqualSet ;
72
73 FROM M2BasicBlock IMPORT BasicBlock, InitBasicBlocks, KillBasicBlocks, ForeachBasicBlockDo ;
74
75 FROM SymbolTable IMPORT NulSym,
76 ModeOfAddr, ProcedureKind,
77 GetProcedureKindDesc,
78 GetProcedureParametersDefined,
79 GetMode,
80 GetScope,
81 GetNth, SkipType, GetVarBackEndType,
82 GetSType, GetLType, GetDType,
83 MakeType, PutType, GetLowestType,
84 GetSubrange, PutSubrange, GetArraySubscript,
85 NoOfParamAny, GetNthParamAny,
86 PushValue, PopValue, PopSize,
87 IsTemporary, IsUnbounded, IsPartialUnbounded,
88 IsEnumeration, IsVar,
89 IsSubrange, IsPointer, IsRecord, IsArray,
90 IsFieldEnumeration,
91 IsProcedure, IsProcedureNested, IsModule,
92 IsDefImp,
93 IsSubscript, IsVarient, IsFieldVarient,
94 IsType, IsProcType, IsSet, IsSetPacked,
95 IsConst, IsConstSet, IsConstructor,
96 IsFieldEnumeration,
97 IsExported, IsImported,
98 IsVarParamAny, IsRecordField, IsUnboundedParam,
99 IsValueSolved,
100 IsDefinitionForC, IsHiddenTypeDeclared,
101 IsInnerModule, IsUnknown,
102 IsProcedureReachable, IsParameter, IsConstLit,
103 IsDummy, IsVarAParam, IsProcedureVariable,
104 IsGnuAsm, IsGnuAsmVolatile, IsObject, IsTuple,
105 IsError, IsHiddenType, IsVarHeap,
106 IsComponent, IsPublic, IsExtern, IsCtor,
107 IsImport, IsImportStatement, IsConstStringKnown,
108 IsUnboundedParamAny,
109 GetMainModule, GetBaseModule, GetModule, GetLocalSym,
110 PutModuleFinallyFunction,
111 GetProcedureScope, GetProcedureQuads,
112 NoOfParam, IsVarParam, GetNthParam, GetType,
113 IsRecordFieldAVarientTag, IsEmptyFieldVarient,
114 GetVarient, GetUnbounded, PutArrayLarge,
115 IsAModula2Type, UsesVarArgs,
116 GetSymName, GetParent,
117 GetDeclaredMod, GetVarBackEndType,
118 GetProcedureBeginEnd, IsProcedureAnyNoReturn,
119 GetString, GetStringLength, IsConstString,
120 IsConstStringM2, IsConstStringC, IsConstStringM2nul, IsConstStringCnul,
121 GetAlignment, IsDeclaredPacked, PutDeclaredPacked,
122 GetDefaultRecordFieldAlignment, IsDeclaredPackedResolved,
123 GetPackedEquivalent,
124 GetParameterShadowVar,
125 GetUnboundedRecordType,
126 GetModuleCtors, GetProcedureProcType,
127 MakeSubrange, MakeConstVar, MakeConstLit,
128 PutConst,
129 ForeachOAFamily, GetOAFamily,
130 IsModuleWithinProcedure, IsVariableSSA,
131 IsVariableAtAddress, IsConstructorConstant,
132 ForeachLocalSymDo,
133 ForeachProcedureDo, ForeachModuleDo,
134 ForeachInnerModuleDo, ForeachImportedDo,
135 ForeachExportedDo, PrintInitialized,
136 FinalSymbol ;
137
138 FROM M2Base IMPORT IsPseudoBaseProcedure, IsPseudoBaseFunction,
139 GetBaseTypeMinMax, MixTypes,
140 Cardinal, Char, Proc, Integer,
141 LongInt, LongCard, ShortCard, ShortInt,
142 Real, LongReal, ShortReal, ZType, RType,
143 CType, Complex, LongComplex, ShortComplex,
144 Boolean, True, False, Nil,
145 IsRealType, IsNeededAtRunTime, IsComplexType ;
146
147 FROM M2System IMPORT IsPseudoSystemFunction, IsSystemType, IsRealN,
148 GetSystemTypeMinMax, Address, Word, Byte, Loc,
149 System, IntegerN, CardinalN, WordN, RealN, SetN, ComplexN,
150 CSizeT, CSSizeT, COffT ;
151
152 FROM M2Bitset IMPORT Bitset, Bitnum ;
153 FROM SymbolConversion IMPORT AddModGcc, Mod2Gcc, GccKnowsAbout, Poison, RemoveMod2Gcc ;
154 FROM M2GenGCC IMPORT ResolveConstantExpressions ;
155 FROM M2Scope IMPORT ScopeBlock, InitScopeBlock, KillScopeBlock, ForeachScopeBlockDo3 ;
156
157 FROM M2ALU IMPORT Addn, Sub, Equ, GreEqu, Gre, Less, PushInt, PushCard, ConvertToType,
158 PushIntegerTree, PopIntegerTree, PopRealTree, ConvertToInt, PopSetTree,
159 PopChar,
160 DivTrunc,
161 IsConstructorDependants, WalkConstructorDependants,
162 PopConstructorTree, PopComplexTree, PutConstructorSolved,
163 ChangeToConstructor, EvaluateValue, TryEvaluateValue ;
164
165 FROM M2Batch IMPORT IsSourceSeen, GetModuleFile, IsModuleSeen, LookupModule ;
166 FROM gcctypes IMPORT location_t, tree ;
167 FROM m2linemap IMPORT BuiltinsLocation ;
168
169 FROM m2decl IMPORT BuildIntegerConstant, BuildStringConstant, BuildCStringConstant,
170 BuildStartFunctionDeclaration,
171 BuildParameterDeclaration, BuildEndFunctionDeclaration,
172 DeclareKnownVariable, GetBitsPerBitset, BuildPtrToTypeString ;
173
174 FROM m2type IMPORT MarkFunctionReferenced, BuildStartRecord, BuildStartVarient, BuildStartFunctionType,
175 BuildStartFieldVarient, BuildStartVarient, BuildStartType, BuildStartArrayType,
176 PutArrayType, BuildPointerType, BuildEndType, BuildCharConstant,
177 BuildTypeDeclaration, GetDefaultType, GetBooleanType, GetBooleanTrue,
178 GetBooleanFalse, BuildSubrangeType, GetM2ZType, GetM2RType, GetM2CType,
179 GetM2CardinalType, GetM2IntegerType, GetM2CharType, GetISOLocType, GetIntegerType,
180 GetISOByteType, GetISOWordType, GetByteType, GetWordType, GetProcType, GetPointerType,
181 GetM2LongIntType, GetM2LongCardType, GetM2ShortIntType, GetM2ShortCardType,
182 GetM2LongRealType, GetM2ShortRealType, GetM2RealType, GetBitnumType, GetBitsetType,
183 GetM2ComplexType, GetM2ComplexType, GetM2LongComplexType, GetM2ShortComplexType,
184 GetM2Integer8, GetM2Integer16, GetM2Integer32, GetM2Integer64, GetM2Cardinal8,
185 GetM2Cardinal16, GetM2Cardinal32, GetM2Cardinal64, GetM2Word16, GetM2Word32,
186 GetM2Word64, GetM2Bitset8, GetM2Bitset16, GetM2Bitset32, GetM2Real32, GetM2Real64,
187 GetM2Real96, GetM2Real128, GetM2Complex32, GetM2Complex64, GetM2Complex96,
188 GetM2Complex128, GetCSizeTType, GetCSSizeTType, GetCOffTType,
189 GetPackedBooleanType, BuildConstPointerType,
190 BuildPointerType, BuildEnumerator, BuildStartEnumeration, BuildEndEnumeration,
191 SetAlignment, SetTypePacked, SetDeclPacked, BuildSmallestTypeRange,
192 SetRecordFieldOffset, ChainOn, BuildEndRecord, BuildFieldRecord,
193 BuildEndFieldVarient, BuildArrayIndexType, BuildEndFunctionType,
194 BuildSetType, BuildEndVarient, BuildEndArrayType, InitFunctionTypeParameters,
195 BuildProcTypeParameterDeclaration, DeclareKnownType,
196 ValueOutOfTypeRange, ExceedsTypeRange,
197 GetMaxFrom, GetMinFrom ;
198
199 FROM m2convert IMPORT BuildConvert ;
200
201 FROM m2expr IMPORT BuildSub, BuildLSL, BuildTBitSize, BuildAdd, BuildDivTrunc, BuildModTrunc,
202 BuildSize, TreeOverflow, AreConstantsEqual, CompareTrees,
203 GetPointerZero, GetIntegerZero, GetIntegerOne ;
204
205 FROM m2block IMPORT RememberType, pushGlobalScope, popGlobalScope,
206 pushFunctionScope, popFunctionScope,
207 finishFunctionDecl, RememberConstant, GetGlobalContext ;
208
209
210 TYPE
211 StartProcedure = PROCEDURE (location_t, ADDRESS) : tree ;
212 ListType = (fullydeclared, partiallydeclared, niltypedarrays,
213 heldbyalignment, finishedalignment, todolist,
214 tobesolvedbyquads, finishedsetarray) ;
215 doDeclareProcedure = PROCEDURE (CARDINAL, CARDINAL) ;
216
217 CONST
218 Debugging = FALSE ;
219 Progress = FALSE ;
220 EnableSSA = FALSE ;
221 EnableWatch = TRUE ;
222 TraceQuadruples = FALSE ;
223
224 TYPE
225 Group = POINTER TO RECORD
226 ToBeSolvedByQuads, (* Constants which must be solved *)
227 (* by processing the quadruples. *)
228 FinishedSetArray, (* Sets which have had their set *)
229 (* array created. *)
230 NilTypedArrays, (* Arrays which have NIL as their *)
231 (* type. *)
232 FullyDeclared, (* Those symbols which have been *)
233 (* fully declared. *)
234 PartiallyDeclared, (* Those types which have need to *)
235 (* be finished (but already *)
236 (* started: records, function *)
237 (* and array type). *)
238 HeldByAlignment, (* Types which have a user *)
239 (* specified alignment constant. *)
240 FinishedAlignment, (* Records for which we know *)
241 (* their alignment value. *)
242 ToDoList : Set ; (* Contains a set of all *)
243 (* outstanding types that need to *)
244 (* be declared to GCC once *)
245 (* its dependants have *)
246 (* been written. *)
247 Next : Group ;
248 END ;
249
250
251 VAR
252 FreeGroup,
253 GlobalGroup : Group ; (* The global group of all sets. *)
254 ErrorDepList, (* The set of symbols with dependency errors. *)
255 VisitedList,
256 ChainedList : Set ;
257 HaveInitDefaultTypes: BOOLEAN ; (* Have we initialized them yet? *)
258 WatchList : Set ; (* Set of symbols being watched. *)
259 EnumerationIndex : Index ;
260 action : IsAction ;
261 ConstantResolved,
262 enumDeps : BOOLEAN ;
263
264
265 (* *************************************************** *)
266 (*
267 PrintNum -
268 *)
269
270 PROCEDURE PrintNum (sym: WORD) ;
271 BEGIN
272 printf1 ('%d, ', sym)
273 END PrintNum ;
274
275
276 (*
277 DebugSet -
278 *)
279
280 PROCEDURE DebugSet (a: ARRAY OF CHAR; l: Set) ;
281 BEGIN
282 printf0 (a) ;
283 printf0 (' {') ;
284 ForeachElementInSetDo (l, PrintNum) ;
285 printf0 ('}\n')
286 END DebugSet ;
287
288
289 (*
290 DebugSets -
291 *)
292
293 PROCEDURE DebugSets ;
294 BEGIN
295 DebugSet ('ToDoList', GlobalGroup^.ToDoList) ;
296 DebugSet ('HeldByAlignment', GlobalGroup^.HeldByAlignment) ;
297 DebugSet ('FinishedAlignment', GlobalGroup^.FinishedAlignment) ;
298 DebugSet ('PartiallyDeclared', GlobalGroup^.PartiallyDeclared) ;
299 DebugSet ('FullyDeclared', GlobalGroup^.FullyDeclared) ;
300 DebugSet ('NilTypedArrays', GlobalGroup^.NilTypedArrays) ;
301 DebugSet ('ToBeSolvedByQuads', GlobalGroup^.ToBeSolvedByQuads) ;
302 DebugSet ('FinishedSetArray', GlobalGroup^.FinishedSetArray)
303 END DebugSets ;
304 (* ************************************************ *)
305
306
307 (*
308 DebugNumber -
309 *)
310
311 PROCEDURE DebugNumber (a: ARRAY OF CHAR; s: Set) ;
312 VAR
313 n: CARDINAL ;
314 BEGIN
315 n := NoOfElementsInSet (s) ;
316 printf1 (a, n) ;
317 FIO.FlushBuffer (FIO.StdOut)
318 END DebugNumber ;
319
320
321 (*
322 DebugSets -
323 *)
324
325 PROCEDURE DebugSetNumbers ;
326 BEGIN
327 DebugNumber ('ToDoList : %d\n', GlobalGroup^.ToDoList) ;
328 DebugNumber ('HeldByAlignment : %d\n', GlobalGroup^.HeldByAlignment) ;
329 DebugNumber ('PartiallyDeclared : %d\n', GlobalGroup^.PartiallyDeclared) ;
330 DebugNumber ('FullyDeclared : %d\n', GlobalGroup^.FullyDeclared) ;
331 DebugNumber ('NilTypedArrays : %d\n', GlobalGroup^.NilTypedArrays) ;
332 DebugNumber ('ToBeSolvedByQuads : %d\n', GlobalGroup^.ToBeSolvedByQuads) ;
333 DebugNumber ('FinishedSetArray : %d\n', GlobalGroup^.FinishedSetArray)
334 END DebugSetNumbers ;
335
336
337 (*
338 AddSymToWatch - adds symbol, sym, to the list of symbols
339 to watch and annotate their movement between
340 lists.
341 *)
342
343 PROCEDURE AddSymToWatch (sym: WORD) ;
344 BEGIN
345 IF (sym # NulSym) AND (NOT IsElementInSet (WatchList, sym))
346 THEN
347 IncludeElementIntoSet (WatchList, sym) ;
348 WalkDependants (sym, AddSymToWatch) ;
349 fprintf1 (GetDumpFile (), "%d, ", sym)
350 END
351 END AddSymToWatch ;
352
353
354 (*
355 TryFindSymbol -
356 *)
357
358 (*
359 PROCEDURE TryFindSymbol (module, symname: ARRAY OF CHAR) : CARDINAL ;
360 VAR
361 mn, sn: Name ;
362 mod : CARDINAL ;
363 BEGIN
364 mn := MakeKey(module) ;
365 sn := MakeKey(symname) ;
366 IF IsModuleSeen(mn)
367 THEN
368 mod := LookupModule (UnknownTokenNo, mn) ;
369 RETURN( GetLocalSym(mod, sn) )
370 ELSE
371 RETURN( NulSym )
372 END
373 END TryFindSymbol ;
374 *)
375
376
377 (*
378 doInclude -
379 *)
380
381 PROCEDURE doInclude (l: Set; a: ARRAY OF CHAR; sym: CARDINAL) ;
382 BEGIN
383 IF NOT IsElementInSet(l, sym)
384 THEN
385 fprintf0 (GetDumpFile (), 'rule: ') ;
386 WriteRule ;
387 fprintf0 (GetDumpFile (), ' ') ;
388 fprintf1 (GetDumpFile (), a, sym) ;
389 IncludeElementIntoSet (l, sym)
390 END
391 END doInclude ;
392
393
394 (*
395 WatchIncludeList - include a symbol onto the set first checking
396 whether it is already on the set and
397 displaying a debug message if the set is
398 changed.
399 *)
400
401 PROCEDURE WatchIncludeList (sym: CARDINAL; lt: ListType) ;
402 BEGIN
403 IF IsElementInSet (WatchList, sym)
404 THEN
405 CASE lt OF
406
407 tobesolvedbyquads : doInclude (GlobalGroup^.ToBeSolvedByQuads, "symbol %d -> ToBeSolvedByQuads\n", sym) |
408 fullydeclared : doInclude (GlobalGroup^.FullyDeclared, "symbol %d -> FullyDeclared\n", sym) |
409 partiallydeclared : doInclude (GlobalGroup^.PartiallyDeclared, "symbol %d -> PartiallyDeclared\n", sym) |
410 heldbyalignment : doInclude (GlobalGroup^.HeldByAlignment, "symbol %d -> HeldByAlignment\n", sym) |
411 finishedalignment : doInclude (GlobalGroup^.FinishedAlignment, "symbol %d -> FinishedAlignment\n", sym) |
412 todolist : doInclude (GlobalGroup^.ToDoList, "symbol %d -> ToDoList\n", sym) |
413 niltypedarrays : doInclude (GlobalGroup^.NilTypedArrays, "symbol %d -> NilTypedArrays\n", sym) |
414 finishedsetarray : doInclude (GlobalGroup^.FinishedSetArray, "symbol %d -> FinishedSetArray\n", sym)
415
416 ELSE
417 InternalError ('unknown list')
418 END
419 ELSE
420 CASE lt OF
421
422 tobesolvedbyquads : IncludeElementIntoSet (GlobalGroup^.ToBeSolvedByQuads, sym) |
423 fullydeclared : IncludeElementIntoSet (GlobalGroup^.FullyDeclared, sym) |
424 partiallydeclared : IncludeElementIntoSet (GlobalGroup^.PartiallyDeclared, sym) |
425 heldbyalignment : IncludeElementIntoSet (GlobalGroup^.HeldByAlignment, sym) |
426 finishedalignment : IncludeElementIntoSet (GlobalGroup^.FinishedAlignment, sym) |
427 todolist : IncludeElementIntoSet (GlobalGroup^.ToDoList, sym) |
428 niltypedarrays : IncludeElementIntoSet (GlobalGroup^.NilTypedArrays, sym) |
429 finishedsetarray : IncludeElementIntoSet (GlobalGroup^.FinishedSetArray, sym)
430
431 ELSE
432 InternalError ('unknown list')
433 END
434 END
435 END WatchIncludeList ;
436
437
438 (*
439 doExclude -
440 *)
441
442 PROCEDURE doExclude (l: Set; a: ARRAY OF CHAR; sym: CARDINAL) ;
443 BEGIN
444 IF IsElementInSet (l, sym)
445 THEN
446 fprintf0 (GetDumpFile (), 'rule: ') ;
447 WriteRule ;
448 fprintf0 (GetDumpFile (), ' ') ;
449 fprintf1 (GetDumpFile (), a, sym) ;
450 ExcludeElementFromSet (l, sym)
451 END
452 END doExclude ;
453
454
455 (*
456 WatchRemoveList - remove a symbol onto the list first checking
457 whether it is already on the list and
458 displaying a debug message if the list is
459 changed.
460 *)
461
462 PROCEDURE WatchRemoveList (sym: CARDINAL; lt: ListType) ;
463 BEGIN
464 IF IsElementInSet (WatchList, sym)
465 THEN
466 CASE lt OF
467
468 tobesolvedbyquads : doExclude (GlobalGroup^.ToBeSolvedByQuads, "symbol %d off ToBeSolvedByQuads\n", sym) |
469 fullydeclared : doExclude (GlobalGroup^.FullyDeclared, "symbol %d off FullyDeclared\n", sym) |
470 partiallydeclared : doExclude (GlobalGroup^.PartiallyDeclared, "symbol %d off PartiallyDeclared\n", sym) |
471 heldbyalignment : doExclude (GlobalGroup^.HeldByAlignment, "symbol %d -> HeldByAlignment\n", sym) |
472 finishedalignment : doExclude (GlobalGroup^.FinishedAlignment, "symbol %d -> FinishedAlignment\n", sym) |
473 todolist : doExclude (GlobalGroup^.ToDoList, "symbol %d off ToDoList\n", sym) |
474 niltypedarrays : doExclude (GlobalGroup^.NilTypedArrays, "symbol %d off NilTypedArrays\n", sym) |
475 finishedsetarray : doExclude (GlobalGroup^.FinishedSetArray, "symbol %d off FinishedSetArray\n", sym) |
476
477 ELSE
478 InternalError ('unknown list')
479 END
480 ELSE
481 CASE lt OF
482
483 tobesolvedbyquads : ExcludeElementFromSet (GlobalGroup^.ToBeSolvedByQuads, sym) |
484 fullydeclared : ExcludeElementFromSet (GlobalGroup^.FullyDeclared, sym) |
485 partiallydeclared : ExcludeElementFromSet (GlobalGroup^.PartiallyDeclared, sym) |
486 heldbyalignment : ExcludeElementFromSet (GlobalGroup^.HeldByAlignment, sym) |
487 finishedalignment : ExcludeElementFromSet (GlobalGroup^.FinishedAlignment, sym) |
488 todolist : ExcludeElementFromSet (GlobalGroup^.ToDoList, sym) |
489 niltypedarrays : ExcludeElementFromSet (GlobalGroup^.NilTypedArrays, sym) |
490 finishedsetarray : ExcludeElementFromSet (GlobalGroup^.FinishedSetArray, sym) |
491
492 ELSE
493 InternalError ('unknown list')
494 END
495 END
496 END WatchRemoveList ;
497
498
499 (*
500 NewGroup -
501 *)
502
503 PROCEDURE NewGroup (VAR g: Group) ;
504 BEGIN
505 IF FreeGroup = NIL
506 THEN
507 NEW (g)
508 ELSE
509 g := FreeGroup ;
510 FreeGroup := FreeGroup^.Next
511 END
512 END NewGroup ;
513
514
515 (*
516 DisposeGroup -
517 *)
518
519 PROCEDURE DisposeGroup (VAR g: Group) ;
520 BEGIN
521 g^.Next := FreeGroup ;
522 FreeGroup := g ;
523 g := NIL
524 END DisposeGroup ;
525
526
527 (*
528 InitGroup - initialize all sets in group and return the group.
529 *)
530
531 PROCEDURE InitGroup () : Group ;
532 VAR
533 g: Group ;
534 BEGIN
535 NewGroup (g) ;
536 (* Initialize all sets in group. *)
537 WITH g^ DO
538 FinishedSetArray := InitSet (1) ;
539 ToDoList := InitSet (1) ;
540 FullyDeclared := InitSet (1) ;
541 PartiallyDeclared := InitSet (1) ;
542 NilTypedArrays := InitSet (1) ;
543 HeldByAlignment := InitSet (1) ;
544 FinishedAlignment := InitSet (1) ;
545 ToBeSolvedByQuads := InitSet (1) ;
546 Next := NIL
547 END ;
548 RETURN g
549 END InitGroup ;
550
551
552 (*
553 KillGroup - delete all sets in group and deallocate g.
554 *)
555
556 PROCEDURE KillGroup (VAR g: Group) ;
557 BEGIN
558 (* Delete all sets in group. *)
559 IF g # NIL
560 THEN
561 WITH g^ DO
562 FinishedSetArray := KillSet (FinishedSetArray) ;
563 ToDoList := KillSet (ToDoList) ;
564 FullyDeclared := KillSet (FullyDeclared) ;
565 PartiallyDeclared := KillSet (PartiallyDeclared) ;
566 NilTypedArrays := KillSet (NilTypedArrays) ;
567 HeldByAlignment := KillSet (HeldByAlignment) ;
568 FinishedAlignment := KillSet (FinishedAlignment) ;
569 ToBeSolvedByQuads := KillSet (ToBeSolvedByQuads) ;
570 Next := NIL
571 END ;
572 DisposeGroup (g)
573 END
574 END KillGroup ;
575
576
577 (*
578 DupGroup - If g is not NIL then destroy g.
579 Return a duplicate of GlobalGroup.
580 *)
581
582 PROCEDURE DupGroup (g: Group) : Group ;
583 BEGIN
584 IF g # NIL
585 THEN
586 (* Kill old group. *)
587 KillGroup (g)
588 END ;
589 NewGroup (g) ;
590 WITH g^ DO
591 (* Copy all sets. *)
592 FinishedSetArray := DuplicateSet (GlobalGroup^.FinishedSetArray) ;
593 ToDoList := DuplicateSet (GlobalGroup^.ToDoList) ;
594 FullyDeclared := DuplicateSet (GlobalGroup^.FullyDeclared) ;
595 PartiallyDeclared := DuplicateSet (GlobalGroup^.PartiallyDeclared) ;
596 NilTypedArrays := DuplicateSet (GlobalGroup^.NilTypedArrays) ;
597 HeldByAlignment := DuplicateSet (GlobalGroup^.HeldByAlignment) ;
598 FinishedAlignment := DuplicateSet (GlobalGroup^.FinishedAlignment) ;
599 ToBeSolvedByQuads := DuplicateSet (GlobalGroup^.ToBeSolvedByQuads) ;
600 Next := NIL
601 END ;
602 RETURN g
603 END DupGroup ;
604
605
606 (*
607 EqualGroup - return TRUE if group left = right.
608 *)
609
610 PROCEDURE EqualGroup (left, right: Group) : BOOLEAN ;
611 BEGIN
612 RETURN ((left = right) OR
613 (EqualSet (left^.FullyDeclared, right^.FullyDeclared) AND
614 EqualSet (left^.PartiallyDeclared, right^.PartiallyDeclared) AND
615 EqualSet (left^.NilTypedArrays, right^.NilTypedArrays) AND
616 EqualSet (left^.HeldByAlignment, right^.HeldByAlignment) AND
617 EqualSet (left^.FinishedAlignment, right^.FinishedAlignment) AND
618 EqualSet (left^.ToDoList, right^.ToDoList) AND
619 EqualSet (left^.ToBeSolvedByQuads, right^.ToBeSolvedByQuads) AND
620 EqualSet (left^.FinishedSetArray, right^.FinishedSetArray)))
621 END EqualGroup ;
622
623
624 (*
625 LookupSet -
626 *)
627
628 PROCEDURE LookupSet (listtype: ListType) : Set ;
629 BEGIN
630 CASE listtype OF
631
632 fullydeclared : RETURN GlobalGroup^.FullyDeclared |
633 partiallydeclared : RETURN GlobalGroup^.PartiallyDeclared |
634 niltypedarrays : RETURN GlobalGroup^.NilTypedArrays |
635 heldbyalignment : RETURN GlobalGroup^.HeldByAlignment |
636 finishedalignment : RETURN GlobalGroup^.FinishedAlignment |
637 todolist : RETURN GlobalGroup^.ToDoList |
638 tobesolvedbyquads : RETURN GlobalGroup^.ToBeSolvedByQuads |
639 finishedsetarray : RETURN GlobalGroup^.FinishedSetArray
640
641 ELSE
642 InternalError ('unknown ListType')
643 END ;
644 RETURN NIL
645 END LookupSet ;
646
647
648 (*
649 GetEnumList -
650 *)
651
652 PROCEDURE GetEnumList (sym: CARDINAL) : tree ;
653 BEGIN
654 IF InBounds(EnumerationIndex, sym)
655 THEN
656 RETURN( tree (GetIndice(EnumerationIndex, sym)) )
657 ELSE
658 RETURN( NIL )
659 END
660 END GetEnumList ;
661
662
663 (*
664 PutEnumList -
665 *)
666
667 PROCEDURE PutEnumList (sym: CARDINAL; enumlist: tree) ;
668 BEGIN
669 PutIndice(EnumerationIndex, sym, enumlist)
670 END PutEnumList ;
671
672
673 (*
674 MarkExported - tell GCC to mark all exported procedures in module sym.
675 *)
676
677 PROCEDURE MarkExported (sym: CARDINAL) ;
678 BEGIN
679 IF Optimizing
680 THEN
681 MarkFunctionReferenced(Mod2Gcc(sym)) ;
682 IF IsDefImp(sym) OR IsModule(sym)
683 THEN
684 ForeachExportedDo(sym, MarkExported)
685 END
686 END
687 END MarkExported ;
688
689
690 (*
691 Chained - checks to see that, sym, has not already been placed on a chain.
692 It returns the symbol, sym.
693 *)
694
695 PROCEDURE Chained (sym: CARDINAL) : CARDINAL ;
696 BEGIN
697 IF IsElementInSet(ChainedList, sym)
698 THEN
699 InternalError ('symbol has already been chained onto a previous list')
700 END ;
701 IncludeElementIntoSet(ChainedList, sym) ;
702 RETURN( sym )
703 END Chained ;
704
705
706 (*
707 DoStartDeclaration - returns a tree representing a symbol which has
708 not yet been finished. Used when declaring
709 recursive types.
710 *)
711
712 PROCEDURE DoStartDeclaration (sym: CARDINAL; p: StartProcedure) : tree ;
713 VAR
714 location: location_t ;
715 BEGIN
716 IF NOT GccKnowsAbout (sym)
717 THEN
718 location := TokenToLocation (GetDeclaredMod (sym)) ;
719 PreAddModGcc(sym, p (location, KeyToCharStar (GetFullSymName (sym))))
720 END ;
721 RETURN Mod2Gcc (sym)
722 END DoStartDeclaration ;
723
724
725 (*
726 ArrayComponentsDeclared - returns TRUE if array, sym,
727 subscripts and type are known.
728 *)
729
730 PROCEDURE ArrayComponentsDeclared (sym: CARDINAL) : BOOLEAN ;
731 VAR
732 Subscript : CARDINAL ;
733 Type, High, Low: CARDINAL ;
734 BEGIN
735 Subscript := GetArraySubscript(sym) ;
736 Assert(IsSubscript(Subscript)) ;
737 Type := GetDType(Subscript) ;
738 Low := GetTypeMin(Type) ;
739 High := GetTypeMax(Type) ;
740 RETURN( IsFullyDeclared(Type) AND
741 IsFullyDeclared(Low) AND
742 IsFullyDeclared(High) )
743 END ArrayComponentsDeclared ;
744
745
746 (*
747 GetRecordOfVarient -
748 *)
749
750 PROCEDURE GetRecordOfVarient (sym: CARDINAL) : CARDINAL ;
751 BEGIN
752 IF IsVarient(sym) OR IsFieldVarient(sym)
753 THEN
754 REPEAT
755 sym := GetParent(sym)
756 UNTIL IsRecord(sym)
757 END ;
758 RETURN( sym )
759 END GetRecordOfVarient ;
760
761
762 (*
763 CanDeclareRecordKind -
764 *)
765
766 PROCEDURE CanDeclareRecordKind (sym: CARDINAL) : BOOLEAN ;
767 BEGIN
768 sym := GetRecordOfVarient(sym) ;
769 RETURN( IsRecord(sym) AND
770 ((GetDefaultRecordFieldAlignment(sym)=NulSym) OR
771 IsFullyDeclared(GetDefaultRecordFieldAlignment(sym))) )
772 END CanDeclareRecordKind ;
773
774
775 (*
776 DeclareRecordKind - works out whether record, sym, is packed or not.
777 *)
778
779 PROCEDURE DeclareRecordKind (sym: CARDINAL) ;
780 BEGIN
781 IF IsRecord(sym)
782 THEN
783 DetermineIfRecordPacked(sym)
784 END ;
785 WatchIncludeList(sym, todolist) ;
786 WatchRemoveList(sym, heldbyalignment) ;
787 WatchIncludeList(sym, finishedalignment) ;
788 IF AllDependantsFullyDeclared(sym)
789 THEN
790 (* All good and ready to be solved. *)
791 END
792 END DeclareRecordKind ;
793
794
795 (*
796 CanDeclareRecord -
797 *)
798
799 PROCEDURE CanDeclareRecord (sym: CARDINAL) : BOOLEAN ;
800 BEGIN
801 TraverseDependants(sym) ;
802 IF AllDependantsFullyDeclared(sym)
803 THEN
804 RETURN TRUE
805 ELSE
806 WatchIncludeList(sym, finishedalignment) ;
807 RETURN FALSE
808 END
809 END CanDeclareRecord ;
810
811
812 (*
813 FinishDeclareRecord -
814 *)
815
816 PROCEDURE FinishDeclareRecord (sym: CARDINAL) ;
817 BEGIN
818 DeclareTypeConstFully(sym) ;
819 WatchRemoveList(sym, heldbyalignment) ;
820 WatchRemoveList(sym, finishedalignment) ;
821 WatchRemoveList(sym, todolist) ;
822 WatchIncludeList(sym, fullydeclared)
823 END FinishDeclareRecord ;
824
825
826 (*
827 CanDeclareTypePartially - return TRUE if we are able to make a
828 gcc partially created type.
829 *)
830
831 PROCEDURE CanDeclareTypePartially (sym: CARDINAL) : BOOLEAN ;
832 VAR
833 type: CARDINAL ;
834 BEGIN
835 IF IsElementInSet(GlobalGroup^.PartiallyDeclared, sym)
836 THEN
837 RETURN( FALSE )
838 ELSIF IsProcType(sym) OR IsRecord(sym) OR IsVarient(sym) OR IsFieldVarient(sym)
839 THEN
840 RETURN( TRUE )
841 ELSIF IsType(sym)
842 THEN
843 type := GetSType(sym) ;
844 IF (type#NulSym) AND IsNilTypedArrays(type)
845 THEN
846 RETURN( TRUE )
847 END
848 END ;
849 RETURN( FALSE )
850 END CanDeclareTypePartially ;
851
852
853 (*
854 DeclareTypePartially - create the gcc partial type symbol from, sym.
855 *)
856
857 PROCEDURE DeclareTypePartially (sym: CARDINAL) ;
858 VAR
859 location: location_t ;
860 BEGIN
861 (* check to see if we have already partially declared the symbol *)
862 IF NOT IsElementInSet(GlobalGroup^.PartiallyDeclared, sym)
863 THEN
864 IF IsRecord(sym)
865 THEN
866 Assert (NOT IsElementInSet (GlobalGroup^.HeldByAlignment, sym)) ;
867 Assert (DoStartDeclaration (sym, BuildStartRecord) # NIL) ;
868 WatchIncludeList (sym, heldbyalignment)
869 ELSIF IsVarient (sym)
870 THEN
871 Assert(NOT IsElementInSet(GlobalGroup^.HeldByAlignment, sym)) ;
872 Assert (DoStartDeclaration(sym, BuildStartVarient) # NIL) ;
873 WatchIncludeList(sym, heldbyalignment)
874 ELSIF IsFieldVarient(sym)
875 THEN
876 Assert(NOT IsElementInSet(GlobalGroup^.HeldByAlignment, sym)) ;
877 Assert (DoStartDeclaration(sym, BuildStartFieldVarient) # NIL) ;
878 WatchIncludeList(sym, heldbyalignment)
879 ELSIF IsProcType(sym)
880 THEN
881 Assert (DoStartDeclaration(sym, BuildStartFunctionType) # NIL) ;
882 ELSIF IsType(sym)
883 THEN
884 IF NOT GccKnowsAbout(sym)
885 THEN
886 location := TokenToLocation(GetDeclaredMod(sym)) ;
887 PreAddModGcc(sym, BuildStartType(location,
888 KeyToCharStar(GetFullSymName(sym)),
889 Mod2Gcc(GetSType(sym))))
890 END
891 ELSE
892 InternalError ('do not know how to create a partial type from this symbol')
893 END ;
894 WatchIncludeList(sym, partiallydeclared) ;
895 TraverseDependants(sym)
896 END
897 END DeclareTypePartially ;
898
899
900 (*
901 CanDeclareArrayAsNil -
902 *)
903
904 PROCEDURE CanDeclareArrayAsNil (sym: CARDINAL) : BOOLEAN ;
905 BEGIN
906 RETURN( IsArray(sym) AND ArrayComponentsDeclared(sym) )
907 END CanDeclareArrayAsNil ;
908
909
910 (*
911 DeclareArrayAsNil -
912 *)
913
914 PROCEDURE DeclareArrayAsNil (sym: CARDINAL) ;
915 BEGIN
916 PreAddModGcc(sym, BuildStartArrayType(BuildIndex(GetDeclaredMod(sym), sym), NIL, GetDType(sym))) ;
917 WatchIncludeList(sym, niltypedarrays)
918 END DeclareArrayAsNil ;
919
920
921 (*
922 CanDeclareArrayPartially -
923 *)
924
925 PROCEDURE CanDeclareArrayPartially (sym: CARDINAL) : BOOLEAN ;
926 VAR
927 type: CARDINAL ;
928 BEGIN
929 IF IsArray(sym)
930 THEN
931 type := GetSType(sym) ;
932 IF IsPartiallyOrFullyDeclared(type) OR
933 (IsPointer(type) AND IsNilTypedArrays(type))
934 THEN
935 RETURN( TRUE )
936 END
937 END ;
938 RETURN( FALSE )
939 END CanDeclareArrayPartially ;
940
941
942 (*
943 DeclareArrayPartially -
944 *)
945
946 PROCEDURE DeclareArrayPartially (sym: CARDINAL) ;
947 BEGIN
948 Assert(IsArray(sym) AND GccKnowsAbout(sym)) ;
949 PutArrayType(Mod2Gcc(sym), Mod2Gcc(GetSType(sym))) ;
950 WatchIncludeList(sym, partiallydeclared)
951 END DeclareArrayPartially ;
952
953
954 (*
955 CanDeclarePointerToNilArray -
956 *)
957
958 PROCEDURE CanDeclarePointerToNilArray (sym: CARDINAL) : BOOLEAN ;
959 BEGIN
960 RETURN( IsPointer(sym) AND IsNilTypedArrays(GetSType(sym)) )
961 END CanDeclarePointerToNilArray ;
962
963
964 (*
965 DeclarePointerToNilArray -
966 *)
967
968 PROCEDURE DeclarePointerToNilArray (sym: CARDINAL) ;
969 BEGIN
970 PreAddModGcc(sym, BuildPointerType(Mod2Gcc(GetSType(sym)))) ;
971 WatchIncludeList(sym, niltypedarrays)
972 END DeclarePointerToNilArray ;
973
974
975 (*
976 CanPromotePointerFully -
977 *)
978
979 PROCEDURE CanPromotePointerFully (sym: CARDINAL) : BOOLEAN ;
980 BEGIN
981 RETURN( IsPointer(sym) AND IsPartiallyOrFullyDeclared(GetSType(sym)) )
982 END CanPromotePointerFully ;
983
984
985 (*
986 PromotePointerFully -
987 *)
988
989 PROCEDURE PromotePointerFully (sym: CARDINAL) ;
990 BEGIN
991 WatchIncludeList(sym, fullydeclared)
992 END PromotePointerFully ;
993
994
995 (*
996 CompletelyResolved - returns TRUE if a symbols has been completely resolved
997 and is not partically declared (such as a record).
998 *)
999
1000 PROCEDURE CompletelyResolved (sym: CARDINAL) : BOOLEAN ;
1001 BEGIN
1002 RETURN( IsElementInSet(GlobalGroup^.FullyDeclared, sym) )
1003 END CompletelyResolved ;
1004
1005
1006 (*
1007 IsTypeQ - returns TRUE if all q(dependants) of, sym,
1008 return TRUE.
1009 *)
1010
1011 PROCEDURE IsTypeQ (sym: CARDINAL; q: IsAction) : BOOLEAN ;
1012 BEGIN
1013 IF IsVar(sym)
1014 THEN
1015 RETURN( IsVarDependants(sym, q) )
1016 ELSIF IsEnumeration(sym)
1017 THEN
1018 RETURN( IsEnumerationDependants(sym, q) )
1019 ELSIF IsFieldEnumeration(sym)
1020 THEN
1021 RETURN( TRUE )
1022 ELSIF IsSubrange(sym)
1023 THEN
1024 RETURN( IsSubrangeDependants(sym, q) )
1025 ELSIF IsPointer(sym)
1026 THEN
1027 RETURN( IsPointerDependants(sym, q) )
1028 ELSIF IsRecord(sym)
1029 THEN
1030 RETURN( IsRecordDependants(sym, q) )
1031 ELSIF IsRecordField(sym)
1032 THEN
1033 RETURN( IsRecordFieldDependants(sym, q) )
1034 ELSIF IsVarient(sym)
1035 THEN
1036 RETURN( IsVarientDependants(sym, q) )
1037 ELSIF IsFieldVarient(sym)
1038 THEN
1039 RETURN( IsVarientFieldDependants(sym, q) )
1040 ELSIF IsArray(sym)
1041 THEN
1042 RETURN( IsArrayDependants(sym, q) )
1043 ELSIF IsProcType(sym)
1044 THEN
1045 RETURN( IsProcTypeDependants(sym, q) )
1046 ELSIF IsUnbounded(sym)
1047 THEN
1048 RETURN( IsUnboundedDependants(sym, q) )
1049 ELSIF IsPartialUnbounded(sym)
1050 THEN
1051 InternalError ('should not be declaring a partial unbounded symbol')
1052 ELSIF IsSet(sym)
1053 THEN
1054 RETURN( IsSetDependants(sym, q) )
1055 ELSIF IsType(sym)
1056 THEN
1057 RETURN( IsTypeDependants(sym, q) )
1058 ELSIF IsConst(sym)
1059 THEN
1060 RETURN( IsConstDependants(sym, q) )
1061 ELSIF IsConstructor(sym) OR IsConstSet(sym)
1062 THEN
1063 (* sym can be a constructor, but at present we have not resolved whether
1064 all dependants are constants.
1065 *)
1066 RETURN( IsConstructorDependants(sym, q) )
1067 ELSIF IsProcedure(sym)
1068 THEN
1069 RETURN( IsProcedureDependants(sym, q) )
1070 ELSE
1071 RETURN( TRUE )
1072 END
1073 END IsTypeQ ;
1074
1075
1076 (*
1077 IsNilTypedArrays - returns TRUE if, sym, is dependant upon a NIL typed array
1078 *)
1079
1080 PROCEDURE IsNilTypedArrays (sym: CARDINAL) : BOOLEAN ;
1081 BEGIN
1082 RETURN( IsElementInSet(GlobalGroup^.NilTypedArrays, sym) )
1083 END IsNilTypedArrays ;
1084
1085
1086 (*
1087 IsFullyDeclared - returns TRUE if, sym, is fully declared.
1088 *)
1089
1090 PROCEDURE IsFullyDeclared (sym: CARDINAL) : BOOLEAN ;
1091 BEGIN
1092 RETURN( IsElementInSet(GlobalGroup^.FullyDeclared, sym) )
1093 END IsFullyDeclared ;
1094
1095
1096 (*
1097 AllDependantsFullyDeclared - returns TRUE if all dependants of,
1098 sym, are declared.
1099 *)
1100
1101 PROCEDURE AllDependantsFullyDeclared (sym: CARDINAL) : BOOLEAN ;
1102 BEGIN
1103 RETURN( IsTypeQ(sym, IsFullyDeclared) )
1104 END AllDependantsFullyDeclared ;
1105
1106
1107 (*
1108 NotAllDependantsFullyDeclared - returns TRUE if any dependants of,
1109 sym, are not declared.
1110 *)
1111
1112 PROCEDURE NotAllDependantsFullyDeclared (sym: CARDINAL) : BOOLEAN ;
1113 BEGIN
1114 RETURN( NOT IsTypeQ(sym, IsFullyDeclared) )
1115 END NotAllDependantsFullyDeclared ;
1116
1117
1118 (*
1119 IsPartiallyDeclared - returns TRUE if, sym, is partially declared.
1120 *)
1121
1122 PROCEDURE IsPartiallyDeclared (sym: CARDINAL) : BOOLEAN ;
1123 BEGIN
1124 RETURN( IsElementInSet(GlobalGroup^.PartiallyDeclared, sym) )
1125 END IsPartiallyDeclared ;
1126
1127
1128 (*
1129 AllDependantsPartiallyDeclared - returns TRUE if all dependants of,
1130 sym, are partially declared.
1131 *)
1132
1133 PROCEDURE AllDependantsPartiallyDeclared (sym: CARDINAL) : BOOLEAN ;
1134 BEGIN
1135 RETURN( IsTypeQ(sym, IsPartiallyDeclared) )
1136 END AllDependantsPartiallyDeclared ;
1137
1138
1139 (*
1140 NotAllDependantsPartiallyDeclared - returns TRUE if any dependants of,
1141 sym, are not partially declared.
1142 *)
1143
1144 PROCEDURE NotAllDependantsPartiallyDeclared (sym: CARDINAL) : BOOLEAN ;
1145 BEGIN
1146 RETURN( NOT IsTypeQ(sym, IsPartiallyDeclared) )
1147 END NotAllDependantsPartiallyDeclared ;
1148
1149
1150 (*
1151 IsPartiallyOrFullyDeclared - returns TRUE if, sym, is partially or fully declared.
1152 *)
1153
1154 PROCEDURE IsPartiallyOrFullyDeclared (sym: CARDINAL) : BOOLEAN ;
1155 BEGIN
1156 RETURN( IsElementInSet(GlobalGroup^.PartiallyDeclared, sym) OR
1157 IsElementInSet(GlobalGroup^.FullyDeclared, sym) )
1158 END IsPartiallyOrFullyDeclared ;
1159
1160
1161 (*
1162 AllDependantsPartiallyOrFullyDeclared - returns TRUE if all dependants of,
1163 sym, are partially or fully declared.
1164 *)
1165
1166 PROCEDURE AllDependantsPartiallyOrFullyDeclared (sym: CARDINAL) : BOOLEAN ;
1167 BEGIN
1168 RETURN( IsTypeQ(sym, IsPartiallyOrFullyDeclared) )
1169 END AllDependantsPartiallyOrFullyDeclared ;
1170
1171
1172 (*
1173 NotAllDependantsPartiallyOrFullyDeclared - returns TRUE if all dependants of,
1174 sym, are not partially and not fully
1175 declared.
1176 *)
1177
1178 (*
1179 PROCEDURE NotAllDependantsPartiallyOrFullyDeclared (sym: CARDINAL) : BOOLEAN ;
1180 BEGIN
1181 RETURN( IsTypeQ(sym, IsPartiallyOrFullyDeclared) )
1182 END NotAllDependantsPartiallyOrFullyDeclared ;
1183 *)
1184
1185
1186 (*
1187 TypeConstDependantsFullyDeclared - returns TRUE if sym is a constant or
1188 type and its dependants are fully
1189 declared.
1190 *)
1191
1192 PROCEDURE TypeConstDependantsFullyDeclared (sym: CARDINAL) : BOOLEAN ;
1193 BEGIN
1194 RETURN( (NOT IsVar(sym)) AND
1195 (NOT IsRecord(sym)) AND
1196 (NOT IsParameter(sym)) AND
1197 AllDependantsFullyDeclared(sym) )
1198 END TypeConstDependantsFullyDeclared ;
1199
1200
1201 (*
1202 CanBeDeclaredViaPartialDependants - returns TRUE if this symbol
1203 can be declared by partial
1204 dependants. Such a symbol must
1205 be a record, proctype or
1206 an array.
1207 *)
1208
1209 PROCEDURE CanBeDeclaredViaPartialDependants (sym: CARDINAL) : BOOLEAN ;
1210 BEGIN
1211 RETURN( (IsPointer(sym) OR IsProcType(sym)) AND
1212 AllDependantsPartiallyOrFullyDeclared(sym) )
1213 END CanBeDeclaredViaPartialDependants ;
1214
1215
1216 (*
1217 DeclareConstFully - will add, sym, to the fully declared list and
1218 also remove it from the to do list. This is
1219 called indirectly from M2GenGCC as it calculates
1220 constants during quadruple processing.
1221 *)
1222
1223 PROCEDURE DeclareConstFully (sym: CARDINAL) ;
1224 BEGIN
1225 WatchIncludeList(sym, fullydeclared) ;
1226 WatchRemoveList(sym, todolist) ;
1227 WatchRemoveList(sym, partiallydeclared) ;
1228 WatchRemoveList(sym, tobesolvedbyquads)
1229 END DeclareConstFully ;
1230
1231
1232 (*
1233 PutToBeSolvedByQuads - places, sym, to this list and returns,
1234 sym.
1235 *)
1236
1237 PROCEDURE PutToBeSolvedByQuads (sym: CARDINAL) ;
1238 BEGIN
1239 WatchIncludeList(sym, tobesolvedbyquads)
1240 END PutToBeSolvedByQuads ;
1241
1242
1243 (*
1244 DeclareTypeConstFully - declare the GCC type and add the double
1245 book keeping entry.
1246 *)
1247
1248 PROCEDURE DeclareTypeConstFully (sym: CARDINAL) ;
1249 VAR
1250 t: tree ;
1251 BEGIN
1252 IF NOT IsElementInSet(GlobalGroup^.ToBeSolvedByQuads, sym)
1253 THEN
1254 IF IsModule(sym) OR IsDefImp(sym)
1255 THEN
1256 WatchIncludeList(sym, fullydeclared) ;
1257 WatchRemoveList(sym, partiallydeclared) ;
1258 WatchRemoveList(sym, todolist)
1259 ELSIF IsProcedure(sym)
1260 THEN
1261 DeclareProcedureToGcc(sym) ;
1262 WatchIncludeList(sym, fullydeclared) ;
1263 WatchRemoveList(sym, partiallydeclared) ;
1264 WatchRemoveList(sym, todolist)
1265 ELSE
1266 t := TypeConstFullyDeclared(sym) ;
1267 IF t#NIL
1268 THEN
1269 (* add relationship between gccsym and sym *)
1270 PreAddModGcc(sym, t) ;
1271 WatchIncludeList(sym, fullydeclared) ;
1272 WatchRemoveList(sym, partiallydeclared) ;
1273 WatchRemoveList(sym, heldbyalignment) ;
1274 WatchRemoveList(sym, finishedalignment) ;
1275 WatchRemoveList(sym, todolist)
1276 END
1277 END
1278 END
1279 END DeclareTypeConstFully ;
1280
1281
1282 (*
1283 DeclareTypeFromPartial - declare the full GCC type from a partial type
1284 and add the double book keeping entry.
1285 *)
1286
1287 PROCEDURE DeclareTypeFromPartial (sym: CARDINAL) ;
1288 VAR
1289 t: tree ;
1290 BEGIN
1291 t := CompleteDeclarationOf(sym) ;
1292 IF t=NIL
1293 THEN
1294 InternalError ('expecting to be able to create a gcc type')
1295 ELSE
1296 AddModGcc(sym, t) ;
1297 WatchIncludeList(sym, fullydeclared) ;
1298 WatchRemoveList(sym, partiallydeclared)
1299 END
1300 END DeclareTypeFromPartial ;
1301
1302
1303 (*
1304 CanBeDeclaredPartiallyViaPartialDependants - returns TRUE if, sym,
1305 can be partially declared via
1306 another partially declared type.
1307 *)
1308
1309 PROCEDURE CanBeDeclaredPartiallyViaPartialDependants (sym: CARDINAL) : BOOLEAN ;
1310 BEGIN
1311 RETURN( IsType(sym) AND AllDependantsPartiallyDeclared(sym) )
1312 END CanBeDeclaredPartiallyViaPartialDependants ;
1313
1314
1315 (*
1316 EmitCircularDependencyError - issue a dependency error.
1317 *)
1318
1319 PROCEDURE EmitCircularDependencyError (sym: CARDINAL) ;
1320 BEGIN
1321 (* Ensure we only issue one dependency message per symbol for this
1322 error classification. *)
1323 IF NOT IsElementInSet (ErrorDepList, sym)
1324 THEN
1325 IncludeElementIntoSet (ErrorDepList, sym) ;
1326 IF IsVar (sym) OR IsParameter (sym)
1327 THEN
1328 MetaError1 ('circular dependency error found when trying to resolve {%1Had}',
1329 sym)
1330 ELSE
1331 MetaError1 ('circular dependency error found when trying to resolve {%1Dad}',
1332 sym)
1333 END
1334 END
1335 END EmitCircularDependencyError ;
1336
1337
1338 TYPE
1339 Rule = (norule, partialtype, arraynil, pointernilarray, arraypartial,
1340 pointerfully, recordkind, recordfully, typeconstfully,
1341 pointerfrompartial, typefrompartial, partialfrompartial,
1342 partialtofully, circulartodo, circularpartial, circularniltyped) ;
1343
1344 VAR
1345 bodyp : WalkAction ;
1346 bodyq : IsAction ;
1347 bodyt : ListType ;
1348 bodyr : Rule ;
1349 recursionCaught,
1350 oneResolved,
1351 noMoreWritten : BOOLEAN ;
1352
1353
1354 (*
1355 WriteRule - writes out the name of the rule.
1356 *)
1357
1358 PROCEDURE WriteRule ;
1359 BEGIN
1360 IF Debugging
1361 THEN
1362 CASE bodyr OF
1363
1364 norule : printf0('norule') |
1365 partialtype : printf0('partialtype') |
1366 arraynil : printf0('arraynil') |
1367 pointernilarray : printf0('pointernilarray') |
1368 arraypartial : printf0('arraypartial') |
1369 pointerfully : printf0('pointerfully') |
1370 recordkind : printf0('recordkind') |
1371 recordfully : printf0('recordfully') |
1372 typeconstfully : printf0('typeconstfully') |
1373 pointerfrompartial: printf0('pointerfrompartial') |
1374 typefrompartial : printf0('typefrompartial') |
1375 partialfrompartial: printf0('partialfrompartial') |
1376 partialtofully : printf0('partialtofully') |
1377 circulartodo : printf0('circulartodo') |
1378 circularpartial : printf0('circularpartial') |
1379 circularniltyped : printf0('circularniltyped')
1380
1381 ELSE
1382 InternalError ('unknown rule')
1383 END
1384 END
1385 END WriteRule ;
1386
1387
1388 (*
1389 Body -
1390 *)
1391
1392 PROCEDURE Body (sym: CARDINAL) ;
1393 BEGIN
1394 IF bodyq (sym)
1395 THEN
1396 WatchRemoveList (sym, bodyt) ;
1397 bodyp (sym) ;
1398 (* The bodyp (sym) procedure function might have replaced sym into the set. *)
1399 IF NOT IsElementInSet (LookupSet (bodyt), sym)
1400 THEN
1401 noMoreWritten := FALSE ;
1402 oneResolved := TRUE
1403 END
1404 END
1405 END Body ;
1406
1407
1408 (*
1409 ForeachTryDeclare - while q (of one sym in set t) is true
1410 for each symbol in set t,
1411 if q (sym)
1412 then
1413 p (sym)
1414 end
1415 end
1416 end
1417 *)
1418
1419 PROCEDURE ForeachTryDeclare (t: ListType; r: Rule;
1420 q: IsAction; p: WalkAction) : BOOLEAN ;
1421 BEGIN
1422 IF recursionCaught
1423 THEN
1424 InternalError ('caught recursive cycle in ForeachTryDeclare')
1425 END ;
1426 bodyt := t ;
1427 bodyq := q ;
1428 bodyp := p ;
1429 bodyr := r ;
1430 recursionCaught := TRUE ;
1431 oneResolved := FALSE ;
1432 REPEAT
1433 noMoreWritten := TRUE ;
1434 ForeachElementInSetDo (LookupSet (t), Body)
1435 UNTIL noMoreWritten ;
1436 bodyr := norule ;
1437 recursionCaught := FALSE ;
1438 RETURN( oneResolved )
1439 END ForeachTryDeclare ;
1440
1441
1442 (*
1443 DeclaredOutandingTypes - writes out any types that have their
1444 dependants solved. It returns TRUE if
1445 all outstanding types have been written.
1446 *)
1447
1448 PROCEDURE DeclaredOutstandingTypes (ForceComplete: BOOLEAN) : BOOLEAN ;
1449 VAR
1450 finished: BOOLEAN ;
1451 copy : Group ;
1452 BEGIN
1453 copy := NIL ;
1454 finished := FALSE ;
1455 REPEAT
1456 IF Progress AND (copy # NIL)
1457 THEN
1458 IF NOT EqualGroup (copy, GlobalGroup)
1459 THEN
1460 DebugSetNumbers ;
1461 DebugSets
1462 END
1463 END ;
1464 copy := DupGroup (copy) ;
1465 IF ForeachTryDeclare (todolist,
1466 partialtype,
1467 CanDeclareTypePartially,
1468 DeclareTypePartially)
1469 THEN
1470 (* continue looping *)
1471 ELSIF ForeachTryDeclare (todolist,
1472 arraynil,
1473 CanDeclareArrayAsNil,
1474 DeclareArrayAsNil)
1475 THEN
1476 (* continue looping *)
1477 ELSIF ForeachTryDeclare (todolist,
1478 pointernilarray,
1479 CanDeclarePointerToNilArray,
1480 DeclarePointerToNilArray)
1481 THEN
1482 (* continue looping *)
1483 ELSIF ForeachTryDeclare (niltypedarrays,
1484 arraypartial,
1485 CanDeclareArrayPartially,
1486 DeclareArrayPartially)
1487 THEN
1488 (* continue looping *)
1489 ELSIF ForeachTryDeclare (niltypedarrays,
1490 pointerfully,
1491 CanPromotePointerFully,
1492 PromotePointerFully)
1493 THEN
1494 (* continue looping *)
1495 ELSIF ForeachTryDeclare (heldbyalignment,
1496 recordkind,
1497 CanDeclareRecordKind,
1498 DeclareRecordKind)
1499 THEN
1500 (* continue looping *)
1501 ELSIF ForeachTryDeclare (finishedalignment,
1502 recordfully,
1503 CanDeclareRecord,
1504 FinishDeclareRecord)
1505 THEN
1506 (* continue looping *)
1507 ELSIF ForeachTryDeclare (todolist,
1508 typeconstfully,
1509 TypeConstDependantsFullyDeclared,
1510 DeclareTypeConstFully)
1511 THEN
1512 (* Continue looping. *)
1513 ELSIF ForeachTryDeclare (todolist,
1514 typefrompartial,
1515 CanBeDeclaredViaPartialDependants,
1516 DeclareTypeFromPartial)
1517 THEN
1518 (* Continue looping. *)
1519 ELSIF ForeachTryDeclare (partiallydeclared,
1520 partialfrompartial,
1521 CanBeDeclaredPartiallyViaPartialDependants,
1522 DeclareTypePartially)
1523 THEN
1524 (* Continue looping. *)
1525 ELSIF ForeachTryDeclare (partiallydeclared,
1526 partialtofully,
1527 TypeConstDependantsFullyDeclared,
1528 DeclareTypeConstFully)
1529 THEN
1530 (* Continue looping. *)
1531 ELSE
1532 (* Nothing left to do (and constants are resolved elsewhere). *)
1533 finished := TRUE
1534 END
1535 UNTIL finished ;
1536 KillGroup (copy) ;
1537 IF ForceComplete
1538 THEN
1539 IF ForeachTryDeclare (todolist,
1540 circulartodo,
1541 NotAllDependantsFullyDeclared,
1542 EmitCircularDependencyError)
1543 THEN
1544 ELSIF ForeachTryDeclare (partiallydeclared,
1545 circularpartial,
1546 NotAllDependantsPartiallyDeclared,
1547 EmitCircularDependencyError)
1548 THEN
1549 ELSIF ForeachTryDeclare (niltypedarrays,
1550 circularniltyped,
1551 NotAllDependantsPartiallyDeclared,
1552 EmitCircularDependencyError)
1553 THEN
1554 END
1555 END ;
1556 RETURN NoOfElementsInSet (GlobalGroup^.ToDoList) = 0
1557 END DeclaredOutstandingTypes ;
1558
1559
1560 (*
1561 CompleteDeclarationOf - returns the GCC Tree for, sym, if it can
1562 be created from partially or fully declared
1563 dependents.
1564 *)
1565
1566 PROCEDURE CompleteDeclarationOf (sym: CARDINAL) : tree ;
1567 BEGIN
1568 IF IsArray(sym)
1569 THEN
1570 RETURN( DeclareArray(sym) )
1571 ELSIF IsProcType(sym)
1572 THEN
1573 RETURN( DeclareProcType(sym) )
1574 ELSIF IsRecordField(sym)
1575 THEN
1576 RETURN( DeclareRecordField(sym) )
1577 ELSIF IsPointer(sym)
1578 THEN
1579 RETURN( DeclarePointer(sym) )
1580 ELSE
1581 RETURN( NIL )
1582 END
1583 END CompleteDeclarationOf ;
1584
1585
1586 (*
1587 DeclareType - here a type has been created via TYPE foo = bar,
1588 we must tell GCC about it.
1589 *)
1590
1591 PROCEDURE DeclareType (sym: CARDINAL) : tree ;
1592 VAR
1593 t : tree ;
1594 location: location_t ;
1595 BEGIN
1596 IF GetSType(sym)=NulSym
1597 THEN
1598 MetaError1('base type {%1Ua} not understood', sym) ;
1599 InternalError ('base type should have been declared')
1600 ELSE
1601 IF GetSymName(sym)=NulName
1602 THEN
1603 RETURN( tree(Mod2Gcc(GetSType(sym))) )
1604 ELSE
1605 location := TokenToLocation(GetDeclaredMod(sym)) ;
1606 IF GccKnowsAbout(sym)
1607 THEN
1608 t := Mod2Gcc(sym)
1609 ELSE
1610 (* not partially declared therefore start it *)
1611 t := BuildStartType(location,
1612 KeyToCharStar(GetFullSymName(sym)), Mod2Gcc(GetSType(sym)))
1613 END ;
1614 t := BuildEndType(location, t) ; (* now finish it *)
1615 RETURN( t )
1616 END
1617 END
1618 END DeclareType ;
1619
1620
1621 (*
1622 DeclareIntegerConstant - declares an integer constant.
1623 *)
1624
1625 (*
1626 PROCEDURE DeclareIntegerConstant (sym: CARDINAL; value: INTEGER) ;
1627 BEGIN
1628 PreAddModGcc(sym, BuildIntegerConstant(value)) ;
1629 WatchRemoveList(sym, todolist) ;
1630 WatchIncludeList(sym, fullydeclared)
1631 END DeclareIntegerConstant ;
1632 *)
1633
1634
1635 (*
1636 DeclareIntegerFromTree - declares an integer constant from a Tree, value.
1637 *)
1638
1639 PROCEDURE DeclareConstantFromTree (sym: CARDINAL; value: tree) ;
1640 BEGIN
1641 PreAddModGcc(sym, value) ;
1642 WatchRemoveList(sym, todolist) ;
1643 WatchIncludeList(sym, fullydeclared)
1644 END DeclareConstantFromTree ;
1645
1646
1647 (*
1648 DeclareCharConstant - declares a character constant.
1649 *)
1650
1651 PROCEDURE DeclareCharConstant (tokenno: CARDINAL; sym: CARDINAL) ;
1652 VAR
1653 location: location_t ;
1654 BEGIN
1655 Assert (IsConstStringKnown (sym)) ;
1656 location := TokenToLocation(tokenno) ;
1657 PreAddModGcc(sym, BuildCharConstant(location, KeyToCharStar(GetString(sym)))) ;
1658 WatchRemoveList(sym, todolist) ;
1659 WatchIncludeList(sym, fullydeclared)
1660 END DeclareCharConstant ;
1661
1662
1663 (*
1664 DeclareStringConstant - declares a string constant the sym will be known.
1665 *)
1666
1667 PROCEDURE DeclareStringConstant (tokenno: CARDINAL; sym: CARDINAL) ;
1668 VAR
1669 symtree : tree ;
1670 BEGIN
1671 Assert (IsConstStringKnown (sym)) ;
1672 IF IsConstStringM2nul (sym) OR IsConstStringCnul (sym)
1673 THEN
1674 (* in either case the string needs a nul terminator. If the string
1675 is a C variant it will already have had any escape characters applied.
1676 The BuildCStringConstant only adds the nul terminator. *)
1677 symtree := BuildCStringConstant (KeyToCharStar (GetString (sym)),
1678 GetStringLength (tokenno, sym))
1679 ELSE
1680 symtree := BuildStringConstant (KeyToCharStar (GetString (sym)),
1681 GetStringLength (tokenno, sym))
1682 END ;
1683 PreAddModGcc (sym, symtree) ;
1684 WatchRemoveList (sym, todolist) ;
1685 WatchIncludeList (sym, fullydeclared)
1686 END DeclareStringConstant ;
1687
1688
1689 (*
1690 PromoteToString - declare, sym, and then promote it to a string.
1691 Note that if sym is a single character we do
1692 *not* record it as a string
1693 but as a char however we always
1694 return a string constant.
1695 *)
1696
1697 PROCEDURE PromoteToString (tokenno: CARDINAL; sym: CARDINAL) : tree ;
1698 VAR
1699 size: CARDINAL ;
1700 ch : CHAR ;
1701 BEGIN
1702 DeclareConstant (tokenno, sym) ;
1703 IF IsConst (sym) AND (GetSType (sym) = Char)
1704 THEN
1705 PushValue (sym) ;
1706 ch := PopChar (tokenno) ;
1707 RETURN BuildCStringConstant (string (InitStringChar (ch)), 1)
1708 ELSE
1709 Assert (IsConstStringKnown (sym)) ;
1710 size := GetStringLength (tokenno, sym) ;
1711 IF size > 1
1712 THEN
1713 (* It will be already be declared as a string, so return it. *)
1714 RETURN tree (Mod2Gcc (sym))
1715 ELSE
1716 RETURN BuildStringConstant (KeyToCharStar (GetString (sym)),
1717 GetStringLength (tokenno, sym))
1718 END
1719 END
1720 END PromoteToString ;
1721
1722
1723 (*
1724 PromoteToCString - declare, sym, and then promote it to a string.
1725 Note that if sym is a single character we do
1726 *not* record it as a string
1727 but as a char however we always
1728 return a string constant.
1729 *)
1730
1731 PROCEDURE PromoteToCString (tokenno: CARDINAL; sym: CARDINAL) : tree ;
1732 VAR
1733 size: CARDINAL ;
1734 ch : CHAR ;
1735 BEGIN
1736 DeclareConstant (tokenno, sym) ;
1737 Assert (IsConstStringKnown (sym)) ;
1738 IF IsConst (sym) AND (GetSType (sym) = Char)
1739 THEN
1740 PushValue (sym) ;
1741 ch := PopChar (tokenno) ;
1742 RETURN BuildCStringConstant (string (InitStringChar (ch)), 1)
1743 ELSE
1744 size := GetStringLength (tokenno, sym) ;
1745 RETURN BuildCStringConstant (KeyToCharStar (GetString (sym)),
1746 size)
1747 END
1748 END PromoteToCString ;
1749
1750
1751 (*
1752 WalkConstructor - walks all dependants of, sym.
1753 *)
1754
1755 PROCEDURE WalkConstructor (sym: CARDINAL; p: WalkAction) ;
1756 VAR
1757 type: CARDINAL ;
1758 BEGIN
1759 type := GetSType(sym) ;
1760 IF type#NulSym
1761 THEN
1762 WalkDependants(type, p) ;
1763 WalkConstructorDependants(sym, p)
1764 END
1765 END WalkConstructor ;
1766
1767
1768 (*
1769 DeclareConstructor - declares a constructor.
1770 *)
1771
1772 PROCEDURE DeclareConstructor (tokenno: CARDINAL; quad: CARDINAL; sym: CARDINAL) ;
1773 BEGIN
1774 IF sym=NulSym
1775 THEN
1776 InternalError ('trying to declare the NulSym')
1777 END ;
1778 IF IsConstructor (sym) AND (NOT GccKnowsAbout (sym))
1779 THEN
1780 WalkConstructor (sym, TraverseDependants) ;
1781 DeclareTypesConstantsProceduresInRange (GetScope (sym), quad, quad) ;
1782 Assert (IsConstructorDependants (sym, IsFullyDeclared)) ;
1783 PushValue (sym) ;
1784 DeclareConstantFromTree (sym, PopConstructorTree (tokenno))
1785 END
1786 END DeclareConstructor ;
1787
1788
1789 (*
1790 TryDeclareConstructor - try and declare a constructor. If, sym, is a
1791 constructor try and declare it, if we cannot
1792 then enter it into the to do list.
1793 *)
1794
1795 PROCEDURE TryDeclareConstructor (tokenno: CARDINAL; sym: CARDINAL) ;
1796 BEGIN
1797 IF sym#NulSym
1798 THEN
1799 IF IsConstructor(sym) AND (NOT GccKnowsAbout(sym))
1800 THEN
1801 WalkConstructor(sym, TraverseDependants) ;
1802 IF NOT IsElementInSet(GlobalGroup^.ToBeSolvedByQuads, sym)
1803 THEN
1804 TryEvaluateValue(sym) ;
1805 IF IsConstructorDependants(sym, IsFullyDeclared)
1806 THEN
1807 PushValue(sym) ;
1808 DeclareConstantFromTree(sym, PopConstructorTree(tokenno))
1809 END
1810 END
1811 END
1812 END
1813 END TryDeclareConstructor ;
1814
1815
1816 (*
1817 WalkConst - walks all dependants of, sym.
1818 *)
1819
1820 PROCEDURE WalkConst (sym: CARDINAL; p: WalkAction) ;
1821 VAR
1822 type: CARDINAL ;
1823 BEGIN
1824 Assert (IsConst (sym)) ;
1825 type := GetSType (sym) ;
1826 IF type # NulSym
1827 THEN
1828 p (type)
1829 END ;
1830 IF IsConstSet (sym) OR IsConstructor (sym)
1831 THEN
1832 WalkConstructor (sym, p)
1833 END
1834 END WalkConst ;
1835
1836
1837 (*
1838 IsConstDependants - returns TRUE if the symbol, sym,
1839 q(dependants) all return TRUE.
1840 *)
1841
1842 PROCEDURE IsConstDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
1843 VAR
1844 type: CARDINAL ;
1845 BEGIN
1846 Assert (IsConst (sym)) ;
1847 type := GetSType (sym) ;
1848 IF type # NulSym
1849 THEN
1850 IF NOT q (type)
1851 THEN
1852 RETURN FALSE
1853 END
1854 END ;
1855 IF IsConstSet (sym) OR IsConstructor (sym)
1856 THEN
1857 RETURN IsConstructorDependants (sym, q)
1858 END ;
1859 RETURN IsValueSolved (sym)
1860 END IsConstDependants ;
1861
1862
1863 (*
1864 TryDeclareConstant - try and declare a constant. If, sym, is a
1865 constant try and declare it, if we cannot
1866 then enter it into the to do list.
1867 *)
1868
1869 PROCEDURE TryDeclareConstant (tokenno: CARDINAL; sym: CARDINAL) ;
1870 VAR
1871 type: CARDINAL ;
1872 BEGIN
1873 TryDeclareConstructor(tokenno, sym) ;
1874 IF IsConst(sym)
1875 THEN
1876 TraverseDependants(sym) ;
1877 type := GetSType(sym) ;
1878 IF (type#NulSym) AND (NOT CompletelyResolved(type))
1879 THEN
1880 TraverseDependants(sym) ;
1881 RETURN
1882 END ;
1883 IF IsConstructor(sym) AND (NOT IsConstructorConstant(sym))
1884 THEN
1885 TraverseDependants(sym) ;
1886 RETURN
1887 END ;
1888 IF (IsConstructor(sym) OR IsConstSet(sym)) AND (type=NulSym)
1889 THEN
1890 TraverseDependants(sym) ;
1891 RETURN
1892 END ;
1893 IF IsElementInSet(GlobalGroup^.ToBeSolvedByQuads, sym)
1894 THEN
1895 (* we allow the above rules to be executed even if it is fully declared
1896 so to ensure that types of compiler builtin constants (BitsetSize
1897 etc) are fully declared.
1898
1899 However at this point if, sym, is fully declared we return
1900 *)
1901 IF IsFullyDeclared(sym)
1902 THEN
1903 RETURN
1904 END ;
1905 TraverseDependants(sym)
1906 ELSE
1907 TryDeclareConst(tokenno, sym)
1908 END
1909 END
1910 END TryDeclareConstant ;
1911
1912
1913 (*
1914 IsAnyType - return TRUE if sym is any Modula-2 type.
1915 *)
1916
1917 PROCEDURE IsAnyType (sym: CARDINAL) : BOOLEAN ;
1918 BEGIN
1919 RETURN (IsRecord(sym) OR IsType(sym) OR IsRecordField(sym) OR
1920 IsPointer(sym) OR IsArray(sym) OR IsSet (sym) OR IsEnumeration (sym) OR
1921 IsPointer (sym))
1922 END IsAnyType ;
1923
1924
1925 (*
1926 TryDeclareType - try and declare a type. If sym is a
1927 type try and declare it, if we cannot
1928 then enter it into the to do list.
1929 *)
1930
1931 PROCEDURE TryDeclareType (type: CARDINAL) ;
1932 BEGIN
1933 IF (type#NulSym) AND IsAnyType (type)
1934 THEN
1935 TraverseDependants (type)
1936 END
1937 END TryDeclareType ;
1938
1939
1940 (*
1941 DeclareConstant - checks to see whether, sym, is a constant and
1942 declares the constant to gcc.
1943 *)
1944
1945 PROCEDURE DeclareConstant (tokenno: CARDINAL; sym: CARDINAL) ;
1946 VAR
1947 type: CARDINAL ;
1948 t : tree ;
1949 BEGIN
1950 IF IsConst(sym)
1951 THEN
1952 TraverseDependants(sym) ;
1953 type := GetSType(sym) ;
1954 Assert((type=NulSym) OR CompletelyResolved(type)) ;
1955 Assert((NOT IsConstructor(sym)) OR IsConstructorConstant(sym)) ;
1956 Assert((type#NulSym) OR (NOT (IsConstructor(sym) OR IsConstSet(sym)))) ;
1957 t := DeclareConst(tokenno, sym) ;
1958 Assert(t#NIL)
1959 END
1960 END DeclareConstant ;
1961
1962
1963 (*
1964 DeclareConstString -
1965 *)
1966
1967 PROCEDURE DeclareConstString (tokenno: CARDINAL; sym: CARDINAL) : BOOLEAN ;
1968 VAR
1969 size: CARDINAL ;
1970 BEGIN
1971 IF IsConstStringKnown (sym)
1972 THEN
1973 size := GetStringLength (tokenno, sym) ;
1974 IF size = 1
1975 THEN
1976 DeclareCharConstant (tokenno, sym)
1977 ELSE
1978 DeclareStringConstant (tokenno, sym)
1979 END ;
1980 RETURN TRUE
1981 END ;
1982 RETURN FALSE
1983 END DeclareConstString ;
1984
1985
1986 (*
1987 TryDeclareConst - try to declare a const to gcc. If it cannot
1988 declare the symbol it places it into the
1989 todolist.
1990 *)
1991
1992 PROCEDURE TryDeclareConst (tokenno: CARDINAL; sym: CARDINAL) ;
1993 VAR
1994 type: CARDINAL ;
1995 BEGIN
1996 IF NOT GccKnowsAbout(sym)
1997 THEN
1998 IF IsConstructor(sym) OR IsConstSet(sym)
1999 THEN
2000 WalkConstructorDependants(sym, TraverseDependants) ;
2001 TryEvaluateValue(sym) ;
2002 IF NOT IsConstructorDependants(sym, IsFullyDeclared)
2003 THEN
2004 TraverseDependants(sym) ;
2005 RETURN
2006 END ;
2007 IF NOT IsConstructorConstant(sym)
2008 THEN
2009 RETURN
2010 END
2011 END ;
2012 IF IsConstString(sym) AND IsConstStringKnown (sym)
2013 THEN
2014 IF DeclareConstString (tokenno, sym)
2015 THEN
2016 END
2017 ELSIF IsValueSolved(sym)
2018 THEN
2019 PushValue(sym) ;
2020 IF IsConstSet(sym)
2021 THEN
2022 DeclareConstantFromTree(sym, PopSetTree(tokenno))
2023 ELSIF IsConstructor(sym)
2024 THEN
2025 DeclareConstantFromTree(sym, PopConstructorTree(tokenno))
2026 ELSIF IsRealType (GetDType (sym)) OR IsRealN (GetDType (sym))
2027 THEN
2028 type := GetDType(sym) ;
2029 DeclareConstantFromTree(sym, BuildConvert(TokenToLocation(tokenno), Mod2Gcc(type), PopRealTree(), TRUE))
2030 ELSIF IsComplexType(GetDType(sym))
2031 THEN
2032 type := GetDType(sym) ;
2033 DeclareConstantFromTree(sym, BuildConvert(TokenToLocation(tokenno), Mod2Gcc(type), PopComplexTree(), TRUE))
2034 ELSE
2035 IF GetSType(sym)=NulSym
2036 THEN
2037 type := ZType
2038 ELSE
2039 type := GetDType(sym)
2040 END ;
2041 DeclareConstantFromTree(sym, BuildConvert(TokenToLocation(tokenno), Mod2Gcc(type), PopIntegerTree(), TRUE))
2042 END
2043 ELSE
2044 TraverseDependants(sym)
2045 END
2046 END
2047 END TryDeclareConst ;
2048
2049
2050 (*
2051 DeclareConst - declares a const to gcc and returns a Tree.
2052 *)
2053
2054 PROCEDURE DeclareConst (tokenno: CARDINAL; sym: CARDINAL) : tree ;
2055 VAR
2056 type: CARDINAL ;
2057 BEGIN
2058 IF GccKnowsAbout(sym)
2059 THEN
2060 RETURN( Mod2Gcc(sym) )
2061 END ;
2062 IF IsConstructor(sym) OR IsConstSet(sym)
2063 THEN
2064 EvaluateValue(sym)
2065 END ;
2066 IF IsConstString(sym)
2067 THEN
2068 IF DeclareConstString (tokenno, sym)
2069 THEN
2070 END
2071 ELSIF IsValueSolved(sym)
2072 THEN
2073 PushValue(sym) ;
2074 IF IsConstSet(sym)
2075 THEN
2076 DeclareConstantFromTree(sym, PopSetTree(tokenno))
2077 ELSIF IsConstructor(sym)
2078 THEN
2079 DeclareConstantFromTree(sym, PopConstructorTree(tokenno))
2080 ELSIF IsRealType(GetDType(sym))
2081 THEN
2082 type := GetDType(sym) ;
2083 DeclareConstantFromTree(sym, BuildConvert(TokenToLocation(tokenno), Mod2Gcc(type), PopRealTree(), TRUE))
2084 ELSIF IsComplexType(GetDType(sym))
2085 THEN
2086 type := GetDType(sym) ;
2087 DeclareConstantFromTree(sym, BuildConvert(TokenToLocation(tokenno), Mod2Gcc(type), PopComplexTree(), TRUE))
2088 ELSE
2089 IF GetSType(sym)=NulSym
2090 THEN
2091 type := ZType
2092 ELSE
2093 type := GetDType(sym)
2094 END ;
2095 DeclareConstantFromTree(sym, BuildConvert(TokenToLocation(tokenno), Mod2Gcc(type), PopIntegerTree(), TRUE))
2096 END
2097 END ;
2098 IF GccKnowsAbout(sym)
2099 THEN
2100 RETURN( Mod2Gcc(sym) )
2101 ELSE
2102 RETURN( NIL )
2103 END
2104 END DeclareConst ;
2105
2106
2107 (*
2108 DeclareParameters -
2109 *)
2110
2111 PROCEDURE DeclareParameters (sym: CARDINAL) ;
2112 BEGIN
2113 DeclareUnboundedProcedureParameters(sym)
2114 END DeclareParameters ;
2115
2116
2117 VAR
2118 unboundedp: WalkAction ;
2119
2120
2121 (*
2122 WalkFamilyOfUnbounded -
2123 *)
2124
2125 PROCEDURE WalkFamilyOfUnbounded (oaf: CARDINAL <* unused *> ; dim: CARDINAL <* unused *> ; unbounded: CARDINAL) ;
2126 BEGIN
2127 IF unbounded # NulSym
2128 THEN
2129 unboundedp (unbounded)
2130 END
2131 END WalkFamilyOfUnbounded ;
2132
2133
2134 (*
2135 WalkAssociatedUnbounded -
2136 *)
2137
2138 PROCEDURE WalkAssociatedUnbounded (sym: CARDINAL; p: WalkAction) ;
2139 VAR
2140 oaf: CARDINAL ;
2141 o : WalkAction ;
2142 BEGIN
2143 oaf := GetOAFamily(sym) ;
2144 o := unboundedp ;
2145 unboundedp := p ;
2146 ForeachOAFamily (oaf, WalkFamilyOfUnbounded) ;
2147 unboundedp := o
2148 END WalkAssociatedUnbounded ;
2149
2150
2151 (*
2152 WalkDependants - walks through all dependants of, Sym,
2153 calling, p, for each dependant.
2154 *)
2155
2156 PROCEDURE WalkDependants (sym: CARDINAL; p: WalkAction) ;
2157 BEGIN
2158 WalkAssociatedUnbounded(sym, p) ;
2159 IF IsComponent(sym)
2160 THEN
2161 WalkComponentDependants(sym, p)
2162 ELSIF IsEnumeration(sym)
2163 THEN
2164 WalkEnumerationDependants(sym, p)
2165 ELSIF IsSubrange(sym)
2166 THEN
2167 WalkSubrangeDependants(sym, p)
2168 ELSIF IsPointer(sym)
2169 THEN
2170 WalkPointerDependants(sym, p)
2171 ELSIF IsRecord(sym)
2172 THEN
2173 WalkRecordDependants(sym, p)
2174 ELSIF IsVarient(sym)
2175 THEN
2176 WalkVarientDependants(sym, p)
2177 ELSIF IsRecordField(sym)
2178 THEN
2179 WalkRecordFieldDependants(sym, p)
2180 ELSIF IsFieldVarient(sym)
2181 THEN
2182 WalkVarientFieldDependants(sym, p)
2183 ELSIF IsArray(sym)
2184 THEN
2185 WalkArrayDependants(sym, p)
2186 ELSIF IsProcType(sym)
2187 THEN
2188 WalkProcTypeDependants(sym, p)
2189 ELSIF IsUnbounded(sym)
2190 THEN
2191 WalkUnboundedDependants(sym, p)
2192 ELSIF IsSet(sym)
2193 THEN
2194 WalkSetDependants(sym, p)
2195 ELSIF IsType(sym)
2196 THEN
2197 WalkTypeDependants(sym, p)
2198 ELSIF IsConst(sym)
2199 THEN
2200 WalkConst(sym, p)
2201 ELSIF IsVar(sym)
2202 THEN
2203 WalkVarDependants(sym, p)
2204 ELSIF IsProcedure(sym)
2205 THEN
2206 WalkProcedureDependants(sym, p)
2207 END
2208 END WalkDependants ;
2209
2210
2211 (*
2212 TraverseDependantsInner -
2213 *)
2214
2215 PROCEDURE TraverseDependantsInner (sym: WORD) ;
2216 BEGIN
2217 IF (NOT IsElementInSet(GlobalGroup^.FullyDeclared, sym)) AND
2218 (NOT IsElementInSet(GlobalGroup^.ToDoList, sym))
2219 THEN
2220 WatchIncludeList(sym, todolist)
2221 END ;
2222 IF NOT IsElementInSet(VisitedList, sym)
2223 THEN
2224 IncludeElementIntoSet(VisitedList, sym) ;
2225 WalkDependants(sym, TraverseDependantsInner)
2226 END
2227 END TraverseDependantsInner ;
2228
2229
2230 (*
2231 TraverseDependants - walks, sym, dependants. But it checks
2232 to see that, sym, is not on the
2233 FullyDeclared and not on the ToDoList.
2234 *)
2235
2236 PROCEDURE TraverseDependants (sym: WORD) ;
2237 BEGIN
2238 IF VisitedList=NIL
2239 THEN
2240 VisitedList := InitSet(1) ;
2241 TraverseDependantsInner(sym) ;
2242 VisitedList := KillSet(VisitedList)
2243 ELSE
2244 InternalError ('recursive call to TraverseDependants caught')
2245 END
2246 END TraverseDependants ;
2247
2248
2249 (*
2250 WalkTypeInfo - walks type, sym, and its dependants.
2251 *)
2252
2253 PROCEDURE WalkTypeInfo (sym: WORD) ;
2254 BEGIN
2255 IF IsVarient(sym)
2256 THEN
2257 InternalError ('why have we reached here?')
2258 ELSIF IsVar(sym)
2259 THEN
2260 WalkTypeInfo(GetSType(sym)) ;
2261 IF GetVarBackEndType(sym)#NulSym
2262 THEN
2263 WalkTypeInfo(GetVarBackEndType(sym))
2264 END
2265 ELSIF IsAModula2Type(sym)
2266 THEN
2267 TraverseDependants(sym)
2268 END
2269 END WalkTypeInfo ;
2270
2271
2272 (*
2273 DeclareUnboundedProcedureParameters -
2274 *)
2275
2276 PROCEDURE DeclareUnboundedProcedureParameters (sym: WORD) ;
2277 VAR
2278 param,
2279 type,
2280 p, i : CARDINAL ;
2281 location : location_t ;
2282 BEGIN
2283 IF IsProcedure(sym)
2284 THEN
2285 p := NoOfParamAny (sym) ;
2286 i := p ;
2287 WHILE i>0 DO
2288 IF IsUnboundedParamAny (sym, i)
2289 THEN
2290 param := GetNthParamAny (sym, i) ;
2291 type := GetSType(param) ;
2292 TraverseDependants(type) ;
2293 IF GccKnowsAbout(type)
2294 THEN
2295 location := TokenToLocation(GetDeclaredMod(type)) ;
2296 BuildTypeDeclaration(location, Mod2Gcc(type))
2297 END
2298 ELSE
2299 param := GetNth(sym, i) ;
2300 type := GetSType(param) ;
2301 TraverseDependants(type)
2302 END ;
2303 DEC(i)
2304 END
2305 END
2306 END DeclareUnboundedProcedureParameters ;
2307
2308
2309 (*
2310 WalkUnboundedProcedureParameters -
2311 *)
2312
2313 PROCEDURE WalkUnboundedProcedureParameters (sym: WORD) ;
2314 VAR
2315 param,
2316 type,
2317 p, i: CARDINAL ;
2318 BEGIN
2319 IF IsProcedure (sym)
2320 THEN
2321 p := NoOfParamAny (sym) ;
2322 i := p ;
2323 WHILE i>0 DO
2324 IF IsUnboundedParamAny (sym, i)
2325 THEN
2326 param := GetNthParamAny (sym, i)
2327 ELSE
2328 param := GetNth (sym, i)
2329 END ;
2330 type := GetSType (param) ;
2331 WalkTypeInfo (type) ;
2332 DEC (i)
2333 END
2334 END
2335 END WalkUnboundedProcedureParameters ;
2336
2337
2338 (*
2339 WalkTypesInProcedure - walk all types in procedure, Sym.
2340 *)
2341
2342 PROCEDURE WalkTypesInProcedure (sym: WORD) ;
2343 BEGIN
2344 ForeachLocalSymDo(sym, TraverseDependants)
2345 END WalkTypesInProcedure ;
2346
2347
2348 (*
2349 WalkTypesInModule - declare all types in module, Sym, to GCC.
2350 *)
2351
2352 PROCEDURE WalkTypesInModule (sym: WORD) ;
2353 VAR
2354 n: Name ;
2355 BEGIN
2356 IF Debugging
2357 THEN
2358 n := GetSymName(sym) ;
2359 printf1('Declaring types in MODULE %a\n', n)
2360 END ;
2361 ForeachLocalSymDo(sym, WalkTypeInfo) ;
2362 ForeachLocalSymDo(sym, WalkUnboundedProcedureParameters) ;
2363 ForeachInnerModuleDo(sym, WalkTypesInModule)
2364 END WalkTypesInModule ;
2365
2366
2367 (*
2368 IsRecordFieldDependants - returns TRUE if the record field
2369 symbol, sym, p(dependants) all return TRUE.
2370 *)
2371
2372 PROCEDURE IsRecordFieldDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
2373 VAR
2374 align: CARDINAL ;
2375 final: BOOLEAN ;
2376 BEGIN
2377 final := TRUE ;
2378 IF NOT q(GetSType(sym))
2379 THEN
2380 final := FALSE
2381 END ;
2382 align := GetAlignment(sym) ;
2383 IF (align#NulSym) AND (NOT q(align))
2384 THEN
2385 final := FALSE
2386 END ;
2387 RETURN( final )
2388 END IsRecordFieldDependants ;
2389
2390
2391 (*
2392 GetModuleWhereDeclared - returns the module where, Sym, was created.
2393 *)
2394
2395 PROCEDURE GetModuleWhereDeclared (sym: CARDINAL) : CARDINAL ;
2396 VAR
2397 s: CARDINAL ;
2398 BEGIN
2399 s := GetScope(sym) ;
2400 IF (s=NulSym) OR IsDefImp(s) OR
2401 (IsModule(s) AND (GetScope(s)=NulSym))
2402 THEN
2403 RETURN( s )
2404 ELSE
2405 RETURN( GetModuleWhereDeclared(s) )
2406 END
2407 END GetModuleWhereDeclared ;
2408
2409
2410 (*
2411 IsPseudoProcFunc - returns TRUE if Sym is a pseudo function or procedure.
2412 *)
2413
2414 PROCEDURE IsPseudoProcFunc (Sym: CARDINAL) : BOOLEAN ;
2415 BEGIN
2416 RETURN(
2417 IsPseudoBaseProcedure(Sym) OR IsPseudoBaseFunction(Sym) OR
2418 IsPseudoSystemFunction(Sym)
2419 )
2420 END IsPseudoProcFunc ;
2421
2422
2423 (*
2424 IsProcedureGccNested - returns TRUE if procedure, sym, will be considered
2425 as nested by GCC.
2426 This will occur if either its outer defining scope
2427 is a procedure or is a module which is inside a
2428 procedure.
2429 *)
2430
2431 PROCEDURE IsProcedureGccNested (sym: CARDINAL) : BOOLEAN ;
2432 BEGIN
2433 RETURN(
2434 IsProcedureNested(sym) OR
2435 (IsModule(GetScope(sym)) AND IsModuleWithinProcedure(GetScope(sym)))
2436 )
2437 END IsProcedureGccNested ;
2438
2439
2440 (*
2441 IsExternal -
2442 *)
2443
2444 PROCEDURE IsExternal (sym: CARDINAL) : BOOLEAN ;
2445 VAR
2446 mod: CARDINAL ;
2447 BEGIN
2448 Assert (NOT IsDefImp (sym)) ;
2449 IF IsProcedure (sym) AND IsExtern (sym)
2450 THEN
2451 RETURN TRUE
2452 END ;
2453 mod := GetScope(sym) ;
2454 REPEAT
2455 IF mod=NulSym
2456 THEN
2457 RETURN( FALSE )
2458 ELSIF IsDefImp(mod)
2459 THEN
2460 RETURN( mod#GetMainModule() )
2461 END ;
2462 mod := GetScope(mod)
2463 UNTIL mod=NulSym ;
2464 RETURN( FALSE )
2465 END IsExternal ;
2466
2467
2468 (*
2469 IsExternalToWholeProgram - return TRUE if the symbol, sym, is external to the
2470 sources that we have parsed.
2471 *)
2472
2473 PROCEDURE IsExternalToWholeProgram (sym: CARDINAL) : BOOLEAN ;
2474 VAR
2475 mod: CARDINAL ;
2476 BEGIN
2477 mod := GetScope(sym) ;
2478 REPEAT
2479 IF mod=NulSym
2480 THEN
2481 RETURN( FALSE )
2482 ELSIF IsDefImp(mod)
2483 THEN
2484 (* return TRUE if we have no source file. *)
2485 RETURN( GetModuleFile(mod)=NIL )
2486 END ;
2487 mod := GetScope(mod)
2488 UNTIL mod=NulSym ;
2489 RETURN( FALSE )
2490 END IsExternalToWholeProgram ;
2491
2492
2493 (*
2494 DeclareProcedureToGccWholeProgram -
2495 *)
2496
2497 PROCEDURE DeclareProcedureToGccWholeProgram (Sym: CARDINAL) ;
2498 VAR
2499 returnType,
2500 GccParam : tree ;
2501 scope,
2502 Variable,
2503 p, i : CARDINAL ;
2504 b, e : CARDINAL ;
2505 begin, end,
2506 location : location_t ;
2507 BEGIN
2508 IF (NOT GccKnowsAbout(Sym)) AND (NOT IsPseudoProcFunc(Sym))
2509 THEN
2510 BuildStartFunctionDeclaration(UsesVarArgs(Sym)) ;
2511 p := NoOfParamAny (Sym) ;
2512 i := p ;
2513 WHILE i>0 DO
2514 (* note we dont use GetNthParamAny as we want the parameter that is seen by the procedure block
2515 remember that this is treated exactly the same as a variable, just its position on
2516 the activation record is special (ie a parameter)
2517 *)
2518 Variable := GetNth(Sym, i) ;
2519 location := TokenToLocation(GetDeclaredMod(Variable)) ;
2520 IF IsUnboundedParamAny (Sym, i)
2521 THEN
2522 GccParam := BuildParameterDeclaration(location,
2523 KeyToCharStar(GetSymName(Variable)),
2524 Mod2Gcc(GetLType(Variable)),
2525 FALSE)
2526 ELSE
2527 GccParam := BuildParameterDeclaration(location,
2528 KeyToCharStar(GetSymName(Variable)),
2529 Mod2Gcc(GetLType(Variable)),
2530 IsVarParamAny (Sym, i))
2531 END ;
2532 PreAddModGcc(Variable, GccParam) ;
2533 WatchRemoveList(Variable, todolist) ;
2534 WatchIncludeList(Variable, fullydeclared) ;
2535 DEC(i)
2536 END ;
2537 GetProcedureBeginEnd(Sym, b, e) ;
2538 begin := TokenToLocation(b) ;
2539 end := TokenToLocation(e) ;
2540 scope := GetScope(Sym) ;
2541 PushBinding(scope) ;
2542 IF GetSType(Sym)=NulSym
2543 THEN
2544 returnType := NIL
2545 ELSE
2546 returnType := Mod2Gcc(GetSType(Sym))
2547 END ;
2548 PreAddModGcc(Sym, BuildEndFunctionDeclaration(begin, end,
2549 KeyToCharStar(GetFullSymName(Sym)),
2550 returnType,
2551 IsExternalToWholeProgram(Sym),
2552 IsProcedureGccNested(Sym),
2553 IsExported(GetModuleWhereDeclared(Sym), Sym),
2554 IsProcedureAnyNoReturn(Sym))) ;
2555 PopBinding(scope) ;
2556 WatchRemoveList(Sym, todolist) ;
2557 WatchIncludeList(Sym, fullydeclared)
2558 END
2559 END DeclareProcedureToGccWholeProgram ;
2560
2561
2562 (*
2563 DeclareProcedureToGccSeparateProgram -
2564 *)
2565
2566 PROCEDURE DeclareProcedureToGccSeparateProgram (Sym: CARDINAL) ;
2567 VAR
2568 returnType,
2569 GccParam : tree ;
2570 scope,
2571 Variable,
2572 p, i : CARDINAL ;
2573 b, e : CARDINAL ;
2574 begin, end,
2575 location : location_t ;
2576 tok : CARDINAL ;
2577 BEGIN
2578 tok := GetDeclaredMod(Sym) ;
2579 IF (NOT GccKnowsAbout(Sym)) AND (NOT IsPseudoProcFunc(Sym)) AND
2580 (IsEffectivelyImported(GetMainModule(), Sym) OR
2581 (GetModuleWhereDeclared (Sym) = GetMainModule()) OR
2582 IsNeededAtRunTime (tok, Sym) OR
2583 IsImported (GetBaseModule (), Sym) OR
2584 IsExported(GetModuleWhereDeclared (Sym), Sym) OR
2585 IsExtern (Sym))
2586 THEN
2587 BuildStartFunctionDeclaration(UsesVarArgs(Sym)) ;
2588 p := NoOfParamAny (Sym) ;
2589 i := p ;
2590 WHILE i>0 DO
2591 (* Note we dont use GetNthParamAny as we want the parameter that is seen by
2592 the procedure block remember that this is treated exactly the same as
2593 a variable, just its position on the activation record is special (ie
2594 a parameter). *)
2595 Variable := GetNth(Sym, i) ;
2596 location := TokenToLocation(GetDeclaredMod(Variable)) ;
2597 IF IsUnboundedParamAny (Sym, i)
2598 THEN
2599 GccParam := BuildParameterDeclaration(location,
2600 KeyToCharStar(GetSymName(Variable)),
2601 Mod2Gcc(GetLType(Variable)),
2602 FALSE)
2603 ELSE
2604 GccParam := BuildParameterDeclaration(location,
2605 KeyToCharStar(GetSymName(Variable)),
2606 Mod2Gcc(GetLType(Variable)),
2607 IsVarParamAny (Sym, i))
2608 END ;
2609 PreAddModGcc(Variable, GccParam) ;
2610 WatchRemoveList(Variable, todolist) ;
2611 WatchIncludeList(Variable, fullydeclared) ;
2612 DEC(i)
2613 END ;
2614 GetProcedureBeginEnd(Sym, b, e) ;
2615 begin := TokenToLocation(b) ;
2616 end := TokenToLocation(e) ;
2617 scope := GetScope(Sym) ;
2618 PushBinding(scope) ;
2619 IF GetSType(Sym)=NulSym
2620 THEN
2621 returnType := NIL
2622 ELSE
2623 returnType := Mod2Gcc(GetSType(Sym))
2624 END ;
2625 PreAddModGcc (Sym, BuildEndFunctionDeclaration (begin, end,
2626 KeyToCharStar (GetFullSymName (Sym)),
2627 returnType,
2628 IsExternal (Sym), (* Extern relative to the main module. *)
2629 IsProcedureGccNested (Sym),
2630 (* Exported from the module where it was declared. *)
2631 IsExported (GetModuleWhereDeclared (Sym), Sym) OR IsExtern (Sym),
2632 IsProcedureAnyNoReturn(Sym))) ;
2633 PopBinding(scope) ;
2634 WatchRemoveList(Sym, todolist) ;
2635 WatchIncludeList(Sym, fullydeclared)
2636 END
2637 END DeclareProcedureToGccSeparateProgram ;
2638
2639
2640 (*
2641 DeclareProcedureToGcc - traverses all parameters and interfaces to gm2gcc.
2642 *)
2643
2644 PROCEDURE DeclareProcedureToGcc (sym: CARDINAL) ;
2645 BEGIN
2646 IF sym # NulSym
2647 THEN
2648 IF WholeProgram
2649 THEN
2650 DeclareProcedureToGccWholeProgram (sym)
2651 ELSE
2652 DeclareProcedureToGccSeparateProgram (sym)
2653 END
2654 END
2655 END DeclareProcedureToGcc ;
2656
2657
2658 (*
2659 DeclareProcedure - declares procedure, sym, or all procedures inside
2660 module sym.
2661 *)
2662
2663 PROCEDURE DeclareProcedure (sym: WORD) ;
2664 BEGIN
2665 IF IsProcedure(sym)
2666 THEN
2667 DeclareProcedureToGcc(sym)
2668 ELSIF IsModule(sym) OR IsDefImp(sym)
2669 THEN
2670 ForeachProcedureDo(sym, DeclareProcedure)
2671 ELSE
2672 InternalError ('expecting procedure')
2673 END
2674 END DeclareProcedure ;
2675
2676
2677 (*
2678 FoldConstants - a wrapper for ResolveConstantExpressions.
2679 *)
2680
2681 PROCEDURE FoldConstants (bb: BasicBlock) ;
2682 BEGIN
2683 IF ResolveConstantExpressions (DeclareConstFully, bb)
2684 THEN
2685 ConstantResolved := TRUE
2686 END
2687 END FoldConstants ;
2688
2689
2690 (*
2691 ActivateWatch - activate a watch for any symbol (lista xor listb).
2692 *)
2693
2694 PROCEDURE ActivateWatch (lista, listb: Set) ;
2695 VAR
2696 smallest,
2697 largest : Set ;
2698 n, sym : CARDINAL ;
2699 BEGIN
2700 IF NoOfElementsInSet (lista) # NoOfElementsInSet (listb)
2701 THEN
2702 IF NoOfElementsInSet (lista) > NoOfElementsInSet (listb)
2703 THEN
2704 largest := lista ;
2705 smallest := listb
2706 ELSE
2707 largest := listb ;
2708 smallest := lista
2709 END ;
2710 printf0 ("adding the following symbols to the watch list as the declarator has detected an internal bug: ") ;
2711 sym := 1 ;
2712 n := FinalSymbol () ;
2713 WHILE sym <= n DO
2714 IF (IsElementInSet (largest, sym) AND (NOT IsElementInSet (smallest, sym))) OR
2715 ((NOT IsElementInSet (largest, sym)) AND IsElementInSet (smallest, sym))
2716 THEN
2717 AddSymToWatch (sym) ;
2718 printf1 ("%d ", sym)
2719 END ;
2720 INC (sym)
2721 END ;
2722 printf0 ("\n")
2723 END
2724 END ActivateWatch ;
2725
2726
2727 (*
2728 DeclareTypesConstantsProceduresInRange -
2729 *)
2730
2731 PROCEDURE DeclareTypesConstantsProceduresInRange (scope, start, end: CARDINAL) ;
2732 CONST
2733 DebugLoop = 1000 ;
2734 VAR
2735 copy: Group ;
2736 loop: CARDINAL ;
2737 sb : ScopeBlock ;
2738 bb : BasicBlock ;
2739 BEGIN
2740 IF TraceQuadruples
2741 THEN
2742 DisplayQuadRange (scope, start, end)
2743 END ;
2744 loop := 0 ;
2745 copy := NIL ;
2746 sb := InitScopeBlock (scope) ;
2747 REPEAT
2748 (* Throw away any unreachable quad. *)
2749 bb := InitBasicBlocks (sb) ;
2750 KillBasicBlocks (bb) ;
2751 (* Now iterate over remaining quads in scope attempting to resolve constants. *)
2752 copy := DupGroup (copy) ;
2753 bb := InitBasicBlocks (sb) ;
2754 ConstantResolved := FALSE ;
2755 ForeachBasicBlockDo (bb, FoldConstants) ;
2756 KillBasicBlocks (bb) ;
2757 (* And now types. *)
2758 IF DeclaredOutstandingTypes (FALSE)
2759 THEN
2760 END ;
2761 IF loop = DebugLoop
2762 THEN
2763 IF TraceQuadruples
2764 THEN
2765 DisplayQuadRange (scope, start, end)
2766 END ;
2767 ActivateWatch (copy^.ToDoList, GlobalGroup^.ToDoList) ;
2768 loop := 0
2769 END ;
2770 INC (loop)
2771 UNTIL (NOT ConstantResolved) AND EqualGroup (copy, GlobalGroup) ;
2772 KillGroup (copy) ;
2773 bb := InitBasicBlocks (sb) ;
2774 KillBasicBlocks (bb) ;
2775 KillScopeBlock (sb)
2776 END DeclareTypesConstantsProceduresInRange ;
2777
2778
2779 (*
2780 SkipModuleScope - skips all module scopes for, scope.
2781 It returns either NulSym or a procedure sym.
2782 *)
2783
2784 PROCEDURE SkipModuleScope (scope: CARDINAL) : CARDINAL ;
2785 BEGIN
2786 IF (scope=NulSym) OR IsProcedure(scope)
2787 THEN
2788 RETURN( scope )
2789 ELSE
2790 RETURN( SkipModuleScope(GetScope(scope)) )
2791 END
2792 END SkipModuleScope ;
2793
2794
2795 (*
2796 PushBinding -
2797 *)
2798
2799 PROCEDURE PushBinding (scope: CARDINAL) ;
2800 BEGIN
2801 scope := SkipModuleScope(scope) ;
2802 IF scope=NulSym
2803 THEN
2804 pushGlobalScope
2805 ELSE
2806 pushFunctionScope(Mod2Gcc(scope))
2807 END
2808 END PushBinding ;
2809
2810
2811 (*
2812 PopBinding -
2813 *)
2814
2815 PROCEDURE PopBinding (scope: CARDINAL) ;
2816 BEGIN
2817 scope := SkipModuleScope(scope) ;
2818 IF scope=NulSym
2819 THEN
2820 popGlobalScope
2821 ELSE
2822 Assert(IsProcedure(scope)) ;
2823 finishFunctionDecl(TokenToLocation(GetDeclaredMod(scope)), Mod2Gcc(scope)) ;
2824 Assert (popFunctionScope () # NIL)
2825 END
2826 END PopBinding ;
2827
2828
2829 (*
2830 DeclareTypesConstantsProcedures -
2831 *)
2832
2833 PROCEDURE DeclareTypesConstantsProcedures (scope: CARDINAL) ;
2834 VAR
2835 copy: Group ;
2836 sb : ScopeBlock ;
2837 BEGIN
2838 IF Debugging
2839 THEN
2840 printf0 ("declaring types constants in: ") ; PrintTerse (scope)
2841 END ;
2842 copy := NIL ;
2843 sb := InitScopeBlock (scope) ;
2844 PushBinding (scope) ;
2845 REPEAT
2846 copy := DupGroup (copy) ;
2847 ForeachScopeBlockDo3 (sb, DeclareTypesConstantsProceduresInRange)
2848 UNTIL EqualGroup (copy, GlobalGroup) ;
2849 KillGroup (copy) ;
2850 PopBinding (scope) ;
2851 KillScopeBlock (sb)
2852 END DeclareTypesConstantsProcedures ;
2853
2854
2855 (*
2856 AssertAllTypesDeclared - asserts that all types for variables are declared in, scope.
2857 *)
2858
2859 PROCEDURE AssertAllTypesDeclared (scope: CARDINAL) ;
2860 VAR
2861 n, Var: CARDINAL ;
2862 failed: BOOLEAN ;
2863 BEGIN
2864 failed := FALSE ;
2865 n := 1 ;
2866 Var := GetNth(scope, n) ;
2867 WHILE Var#NulSym DO
2868 IF NOT TypeDependentsDeclared (Var, TRUE)
2869 THEN
2870 failed := TRUE
2871 END ;
2872 INC(n) ;
2873 Var := GetNth(scope, n)
2874 END ;
2875 IF failed
2876 THEN
2877 FlushErrors
2878 END
2879 END AssertAllTypesDeclared ;
2880
2881
2882 (*
2883 DeclareModuleInit - declare all the ctor related functions within
2884 a module.
2885 *)
2886
2887 PROCEDURE DeclareModuleInit (moduleSym: WORD) ;
2888 VAR
2889 ctor, init, fini, dep: CARDINAL ;
2890 BEGIN
2891 GetModuleCtors (moduleSym, ctor, init, fini, dep) ;
2892 DeclareProcedureToGcc (ctor) ;
2893 DeclareProcedureToGcc (init) ;
2894 DeclareProcedureToGcc (fini) ;
2895 DeclareProcedureToGcc (dep)
2896 END DeclareModuleInit ;
2897
2898
2899 (*
2900 StartDeclareProcedureScope -
2901 *)
2902
2903 PROCEDURE StartDeclareProcedureScope (scope: CARDINAL) ;
2904 BEGIN
2905 WalkTypesInProcedure(scope) ;
2906 DeclareProcedure(scope) ;
2907 ForeachInnerModuleDo(scope, WalkTypesInModule) ;
2908 DeclareTypesConstantsProcedures (scope) ;
2909 ForeachInnerModuleDo(scope, DeclareTypesConstantsProcedures) ;
2910 DeclareLocalVariables(scope) ;
2911 ForeachInnerModuleDo(scope, DeclareModuleVariables) ;
2912 AssertAllTypesDeclared(scope) ;
2913 ForeachProcedureDo(scope, DeclareProcedure) ;
2914 ForeachInnerModuleDo(scope, StartDeclareScope)
2915 END StartDeclareProcedureScope ;
2916
2917
2918 (*
2919 StartDeclareModuleScopeSeparate -
2920 *)
2921
2922 PROCEDURE StartDeclareModuleScopeSeparate (scope: CARDINAL) ;
2923 BEGIN
2924 IF scope=GetMainModule()
2925 THEN
2926 ForeachModuleDo(WalkTypesInModule) ; (* will populate the TYPE and CONST ToDo list *)
2927 DeclareTypesConstantsProcedures(scope) ; (* will resolved TYPEs and CONSTs on the ToDo *)
2928 (* lists. *)
2929 ForeachModuleDo(DeclareProcedure) ;
2930 (* Now that all types have been resolved it is safe to declare
2931 variables. *)
2932 AssertAllTypesDeclared(scope) ;
2933 DeclareGlobalVariables(scope) ;
2934 ForeachImportedDo(scope, DeclareImportedVariables) ;
2935 (* Now it is safe to declare all procedures. *)
2936 ForeachProcedureDo(scope, DeclareProcedure) ;
2937 ForeachInnerModuleDo(scope, WalkTypesInModule) ;
2938 ForeachInnerModuleDo(scope, DeclareTypesConstantsProcedures) ;
2939 ForeachInnerModuleDo(scope, StartDeclareScope) ;
2940 DeclareModuleInit(scope)
2941 ELSE
2942 DeclareTypesConstantsProcedures(scope) ;
2943 AssertAllTypesDeclared(scope) ;
2944 ForeachProcedureDo(scope, DeclareProcedure) ;
2945 DeclareModuleInit(scope) ;
2946 ForeachInnerModuleDo(scope, StartDeclareScope)
2947 END
2948 END StartDeclareModuleScopeSeparate ;
2949
2950
2951 (*
2952 StartDeclareModuleScopeWholeProgram -
2953 *)
2954
2955 PROCEDURE StartDeclareModuleScopeWholeProgram (scope: CARDINAL) ;
2956 BEGIN
2957 IF IsSourceSeen(scope)
2958 THEN
2959 ForeachModuleDo(WalkTypesInModule) ; (* will populate the TYPE and CONST ToDo list *)
2960 DeclareTypesConstantsProcedures(scope) ; (* will resolved TYPEs and CONSTs on the ToDo *)
2961 (* lists. *)
2962 ForeachModuleDo(DeclareProcedure) ;
2963 ForeachModuleDo(DeclareModuleInit) ;
2964 (* Now that all types have been resolved it is safe to declare
2965 variables. *)
2966 AssertAllTypesDeclared(scope) ;
2967 DeclareGlobalVariablesWholeProgram(scope) ;
2968 ForeachImportedDo(scope, DeclareImportedVariablesWholeProgram) ;
2969 (* Now it is safe to declare all procedures. *)
2970 ForeachProcedureDo(scope, DeclareProcedure) ;
2971 ForeachInnerModuleDo(scope, WalkTypesInModule) ;
2972 ForeachInnerModuleDo(scope, DeclareTypesConstantsProcedures) ;
2973 ForeachInnerModuleDo(scope, StartDeclareScope) ;
2974 DeclareModuleInit(scope)
2975 ELSE
2976 DeclareTypesConstantsProcedures(scope) ;
2977 AssertAllTypesDeclared(scope) ;
2978 ForeachProcedureDo(scope, DeclareProcedure) ;
2979 DeclareModuleInit(scope) ;
2980 ForeachInnerModuleDo(scope, StartDeclareScope)
2981 END
2982 END StartDeclareModuleScopeWholeProgram ;
2983
2984
2985 (*
2986 StartDeclareModuleScope -
2987 *)
2988
2989 PROCEDURE StartDeclareModuleScope (scope: CARDINAL) ;
2990 BEGIN
2991 IF WholeProgram
2992 THEN
2993 StartDeclareModuleScopeWholeProgram(scope)
2994 ELSE
2995 StartDeclareModuleScopeSeparate(scope)
2996 END
2997 END StartDeclareModuleScope ;
2998
2999
3000 (*
3001 StartDeclareScope - declares types, variables associated with this scope.
3002 *)
3003
3004 PROCEDURE StartDeclareScope (scope: CARDINAL) ;
3005 VAR
3006 n: Name ;
3007 BEGIN
3008 IF Debugging
3009 THEN
3010 n := GetSymName (scope) ;
3011 printf1 ('declaring symbols in BLOCK %a\n', n)
3012 END ;
3013 IF IsProcedure (scope)
3014 THEN
3015 StartDeclareProcedureScope (scope)
3016 ELSE
3017 StartDeclareModuleScope (scope)
3018 END ;
3019 IF Debugging
3020 THEN
3021 n := GetSymName (scope) ;
3022 printf1('\nEND declaring symbols in BLOCK %a\n', n)
3023 END
3024 END StartDeclareScope ;
3025
3026
3027 (*
3028 EndDeclareScope -
3029 *)
3030
3031 PROCEDURE EndDeclareScope ;
3032 BEGIN
3033 (* no need to do anything *)
3034 END EndDeclareScope ;
3035
3036
3037 (*
3038 IncludeDumpSymbol - include sym into the watch list and all syms dependants.
3039 *)
3040
3041 PROCEDURE IncludeDumpSymbol (sym: CARDINAL) ;
3042 BEGIN
3043 IF sym # NulSym
3044 THEN
3045 AddSymToWatch (sym)
3046 (*
3047 fprintf0 (GetDumpFile (), "\n") ;
3048 PrintVerbose (sym) ;
3049 fprintf0 (GetDumpFile (), "\n")
3050 *)
3051 END
3052 END IncludeDumpSymbol ;
3053
3054
3055 (*
3056 DumpResolver - dumps the m2 representation of sym.
3057 *)
3058
3059 PROCEDURE DumpResolver (sym: CARDINAL) ;
3060 BEGIN
3061 fprintf1 (GetDumpFile (), "dump filtered symbol %d and dependants\n", sym) ;
3062 PrintVerbose (sym) ;
3063 END DumpResolver ;
3064
3065
3066 (*
3067 DumpFilteredResolver - dumps the gimple or tree representation of all watched symbols.
3068 *)
3069
3070 PROCEDURE DumpFilteredResolver ;
3071 BEGIN
3072 ForeachElementInSetDo (WatchList, DumpResolver)
3073 END DumpFilteredResolver ;
3074
3075
3076 (*
3077 DumpDefinitive - dumps the m2 and m2 gimple representation of sym.
3078 *)
3079
3080 PROCEDURE DumpDefinitive (sym: CARDINAL) ;
3081 VAR
3082 fd: INTEGER ;
3083 BEGIN
3084 fprintf1 (GetDumpFile (), "\nm2 symbol synopsis: %d\n", sym) ;
3085 PrintVerbose (sym) ;
3086 IF GccKnowsAbout (sym)
3087 THEN
3088 fprintf1 (GetDumpFile (), "\nm2 gimple: %d", sym) ;
3089 FIO.FlushBuffer (GetDumpFile ()) ;
3090 fd := FIO.GetUnixFileDescriptor (GetDumpFile ()) ;
3091 DumpGimpleFd (fd, Mod2Gcc (sym))
3092 ELSE
3093 fprintf1 (GetDumpFile (), "\nno m2 gimple for %d\n", sym)
3094 END
3095 END DumpDefinitive ;
3096
3097
3098 (*
3099 DumpFilteredDefinitive - dumps the gimple or tree representation of all watched symbols.
3100 *)
3101
3102 PROCEDURE DumpFilteredDefinitive ;
3103 BEGIN
3104 ForeachElementInSetDo (WatchList, DumpDefinitive)
3105 END DumpFilteredDefinitive ;
3106
3107
3108 (*
3109 PreAddModGcc - adds a relationship between sym and tree.
3110 *)
3111
3112 PROCEDURE PreAddModGcc (sym: CARDINAL; tree: tree) ;
3113 BEGIN
3114 AddModGcc (sym, tree)
3115 END PreAddModGcc ;
3116
3117
3118 (*
3119 DeclareDefaultType - declares a default type, sym, with, name.
3120 *)
3121
3122 PROCEDURE DeclareDefaultType (sym: CARDINAL; name: ARRAY OF CHAR; gcctype: tree) ;
3123 VAR
3124 t : tree ;
3125 high, low: CARDINAL ;
3126 location : location_t ;
3127 BEGIN
3128 (* DeclareDefaultType will declare a new identifier as a type of, gcctype, if it has not already been
3129 declared by gccgm2.c *)
3130 location := BuiltinsLocation () ;
3131 t := GetDefaultType(location, KeyToCharStar(MakeKey(name)), gcctype) ;
3132 AddModGcc(sym, t) ;
3133 IncludeElementIntoSet(GlobalGroup^.FullyDeclared, sym) ;
3134 WalkAssociatedUnbounded(sym, TraverseDependants) ;
3135 (*
3136 this is very simplistic and assumes that the caller only uses Subranges, Sets and GCC types.
3137 We need to declare any constants with the types so that AllDependantsFullyDeclared works.
3138 *)
3139 IF IsSubrange(sym)
3140 THEN
3141 GetSubrange(sym, high, low) ;
3142 DeclareConstant(GetDeclaredMod(sym), high) ;
3143 DeclareConstant(GetDeclaredMod(sym), low)
3144 ELSIF IsSet(sym)
3145 THEN
3146 IF IsSubrange(GetSType(sym))
3147 THEN
3148 IF NOT GccKnowsAbout(GetSType(sym))
3149 THEN
3150 (* only true for internal types of course *)
3151 InternalError ('subrange type within the set type must be declared before the set type')
3152 END ;
3153 GetSubrange(GetSType(sym), high, low) ;
3154 DeclareConstant(GetDeclaredMod(sym), high) ;
3155 DeclareConstant(GetDeclaredMod(sym), low)
3156 ELSIF IsEnumeration(GetSType(sym))
3157 THEN
3158 IF NOT GccKnowsAbout(GetSType(sym))
3159 THEN
3160 (* only true for internal types of course *)
3161 InternalError ('enumeration type within the set type must be declared before the set type')
3162 END
3163 END
3164 END
3165 END DeclareDefaultType ;
3166
3167
3168 (*
3169 DeclareBoolean - declares the Boolean type together with true and false.
3170 *)
3171
3172 PROCEDURE DeclareBoolean ;
3173 BEGIN
3174 AddModGcc(Boolean, GetBooleanType()) ;
3175 AddModGcc(True, GetBooleanTrue()) ;
3176 AddModGcc(False, GetBooleanFalse()) ;
3177 IncludeElementIntoSet(GlobalGroup^.FullyDeclared, Boolean) ;
3178 IncludeElementIntoSet(GlobalGroup^.FullyDeclared, True) ;
3179 IncludeElementIntoSet(GlobalGroup^.FullyDeclared, False) ;
3180 WalkAssociatedUnbounded(Boolean, TraverseDependants)
3181 END DeclareBoolean ;
3182
3183
3184 (*
3185 DeclareFixedSizedType - declares the GNU Modula-2 fixed types
3186 (if the back end support such a type).
3187 *)
3188
3189 PROCEDURE DeclareFixedSizedType (name: ARRAY OF CHAR; type: CARDINAL; t: tree) ;
3190 VAR
3191 location : location_t ;
3192 typetype,
3193 low, high: CARDINAL ;
3194 BEGIN
3195 IF type#NulSym
3196 THEN
3197 IF IsSet(type) AND (NOT GccKnowsAbout(GetSType(type)))
3198 THEN
3199 typetype := GetSType(type) ;
3200 GetSubrange(typetype, high, low) ;
3201 DeclareConstant(GetDeclaredMod(type), high) ;
3202 DeclareConstant(GetDeclaredMod(type), low) ;
3203 location := TokenToLocation(GetDeclaredMod(typetype)) ;
3204 PreAddModGcc(typetype, BuildSubrangeType(location,
3205 KeyToCharStar(GetFullSymName(typetype)),
3206 Mod2Gcc(GetSType(typetype)),
3207 Mod2Gcc(low), Mod2Gcc(high))) ;
3208 IncludeElementIntoSet(GlobalGroup^.FullyDeclared, typetype) ;
3209 WalkAssociatedUnbounded(typetype, TraverseDependants)
3210 END ;
3211 (* gcc back end supports, type *)
3212 DeclareDefaultType(type, name, t)
3213 END
3214 END DeclareFixedSizedType ;
3215
3216
3217 (*
3218 DeclareDefaultSimpleTypes - declares the simple types.
3219 *)
3220
3221 PROCEDURE DeclareDefaultSimpleTypes ;
3222 BEGIN
3223 AddModGcc(ZType, GetM2ZType()) ;
3224 AddModGcc(RType, GetM2RType()) ;
3225 AddModGcc(CType, GetM2CType()) ;
3226 IncludeElementIntoSet(GlobalGroup^.FullyDeclared, ZType) ;
3227 IncludeElementIntoSet(GlobalGroup^.FullyDeclared, RType) ;
3228 IncludeElementIntoSet(GlobalGroup^.FullyDeclared, CType) ;
3229
3230 DeclareDefaultType(Cardinal , "CARDINAL" , GetM2CardinalType()) ;
3231 DeclareDefaultType(Integer , "INTEGER" , GetM2IntegerType()) ;
3232 DeclareDefaultType(Char , "CHAR" , GetM2CharType()) ;
3233 DeclareDefaultType(Loc , "LOC" , GetISOLocType()) ;
3234
3235 IF Iso
3236 THEN
3237 DeclareDefaultType(Byte , "BYTE" , GetISOByteType()) ;
3238 DeclareDefaultType(Word , "WORD" , GetISOWordType())
3239 ELSE
3240 DeclareDefaultType(Byte , "BYTE" , GetByteType()) ;
3241 DeclareDefaultType(Word , "WORD" , GetWordType())
3242 END ;
3243
3244 DeclareDefaultType(Proc , "PROC" , GetProcType()) ;
3245 DeclareDefaultType(Address , "ADDRESS" , GetPointerType()) ;
3246 DeclareDefaultType(LongInt , "LONGINT" , GetM2LongIntType()) ;
3247 DeclareDefaultType(LongCard , "LONGCARD" , GetM2LongCardType()) ;
3248 DeclareDefaultType(ShortInt , "SHORTINT" , GetM2ShortIntType()) ;
3249 DeclareDefaultType(ShortCard , "SHORTCARD" , GetM2ShortCardType()) ;
3250 DeclareDefaultType(ShortReal , "SHORTREAL" , GetM2ShortRealType()) ;
3251 DeclareDefaultType(Real , "REAL" , GetM2RealType()) ;
3252 DeclareDefaultType(LongReal , "LONGREAL" , GetM2LongRealType()) ;
3253 DeclareDefaultType(Bitnum , "BITNUM" , GetBitnumType()) ;
3254 DeclareDefaultType(Bitset , "BITSET" , GetBitsetType()) ;
3255 DeclareDefaultType(Complex , "COMPLEX" , GetM2ComplexType()) ;
3256 DeclareDefaultType(LongComplex , "LONGCOMPLEX" , GetM2LongComplexType()) ;
3257 DeclareDefaultType(ShortComplex, "SHORTCOMPLEX", GetM2ShortComplexType()) ;
3258 DeclareDefaultType(CSizeT , "CSIZE_T" , GetCSizeTType()) ;
3259 DeclareDefaultType(CSSizeT , "CSSIZE_T" , GetCSSizeTType()) ;
3260 DeclareDefaultType(COffT , "COFF_T" , GetCOffTType()) ;
3261
3262 DeclareBoolean ;
3263
3264 DeclareFixedSizedType("INTEGER8" , IntegerN(8) , GetM2Integer8()) ;
3265 DeclareFixedSizedType("INTEGER16" , IntegerN(16) , GetM2Integer16()) ;
3266 DeclareFixedSizedType("INTEGER32" , IntegerN(32) , GetM2Integer32()) ;
3267 DeclareFixedSizedType("INTEGER64" , IntegerN(64) , GetM2Integer64()) ;
3268 DeclareFixedSizedType("CARDINAL8" , CardinalN(8) , GetM2Cardinal8()) ;
3269 DeclareFixedSizedType("CARDINAL16", CardinalN(16), GetM2Cardinal16()) ;
3270 DeclareFixedSizedType("CARDINAL32", CardinalN(32), GetM2Cardinal32()) ;
3271 DeclareFixedSizedType("CARDINAL64", CardinalN(64), GetM2Cardinal64()) ;
3272 DeclareFixedSizedType("WORD16" , WordN(16) , GetM2Word16()) ;
3273 DeclareFixedSizedType("WORD32" , WordN(32) , GetM2Word32()) ;
3274 DeclareFixedSizedType("WORD64" , WordN(64) , GetM2Word64()) ;
3275 DeclareFixedSizedType("BITSET8" , SetN(8) , GetM2Bitset8()) ;
3276 DeclareFixedSizedType("BITSET16" , SetN(16) , GetM2Bitset16()) ;
3277 DeclareFixedSizedType("BITSET32" , SetN(32) , GetM2Bitset32()) ;
3278 DeclareFixedSizedType("REAL32" , RealN(32) , GetM2Real32()) ;
3279 DeclareFixedSizedType("REAL64" , RealN(64) , GetM2Real64()) ;
3280 DeclareFixedSizedType("REAL96" , RealN(96) , GetM2Real96()) ;
3281 DeclareFixedSizedType("REAL128" , RealN(128) , GetM2Real128()) ;
3282 DeclareFixedSizedType("COMPLEX32" , ComplexN(32) , GetM2Complex32()) ;
3283 DeclareFixedSizedType("COMPLEX64" , ComplexN(64) , GetM2Complex64()) ;
3284 DeclareFixedSizedType("COMPLEX96" , ComplexN(96) , GetM2Complex96()) ;
3285 DeclareFixedSizedType("COMPLEX128", ComplexN(128), GetM2Complex128())
3286 END DeclareDefaultSimpleTypes ;
3287
3288
3289 (*
3290 DeclarePackedBoolean -
3291 *)
3292
3293 PROCEDURE DeclarePackedBoolean ;
3294 VAR
3295 e: CARDINAL ;
3296 BEGIN
3297 e := GetPackedEquivalent(Boolean) ;
3298 AddModGcc(e, GetPackedBooleanType()) ;
3299 IncludeElementIntoSet(GlobalGroup^.FullyDeclared, e)
3300 END DeclarePackedBoolean ;
3301
3302
3303 (*
3304 DeclarePackedDefaultSimpleTypes -
3305 *)
3306
3307 PROCEDURE DeclarePackedDefaultSimpleTypes ;
3308 BEGIN
3309 DeclarePackedBoolean
3310 END DeclarePackedDefaultSimpleTypes ;
3311
3312
3313 (*
3314 DeclareDefaultTypes - makes default types known to GCC
3315 *)
3316
3317 PROCEDURE DeclareDefaultTypes ;
3318 BEGIN
3319 IF NOT HaveInitDefaultTypes
3320 THEN
3321 HaveInitDefaultTypes := TRUE ;
3322 pushGlobalScope ;
3323 DeclareDefaultSimpleTypes ;
3324 DeclarePackedDefaultSimpleTypes ;
3325 popGlobalScope
3326 END
3327 END DeclareDefaultTypes ;
3328
3329
3330 (*
3331 DeclareDefaultConstants - make default constants known to GCC
3332 *)
3333
3334 PROCEDURE DeclareDefaultConstants ;
3335 BEGIN
3336 AddModGcc(Nil, GetPointerZero(BuiltinsLocation ())) ;
3337 IncludeElementIntoSet(GlobalGroup^.FullyDeclared, Nil)
3338 END DeclareDefaultConstants ;
3339
3340
3341 (*
3342 FindContext - returns the scope where the symbol
3343 should be created.
3344
3345 Symbols created in a module will
3346 return the global context tree, but symbols created
3347 in a module which is declared inside
3348 a procedure will return the procedure Tree.
3349 *)
3350
3351 PROCEDURE FindContext (sym: CARDINAL) : tree ;
3352 BEGIN
3353 sym := GetProcedureScope(sym) ;
3354 IF sym=NulSym
3355 THEN
3356 RETURN( GetGlobalContext() )
3357 ELSE
3358 RETURN( Mod2Gcc(sym) )
3359 END
3360 END FindContext ;
3361
3362
3363 (*
3364 IsEffectivelyImported - returns TRUE if symbol, Sym, was
3365 effectively imported into ModSym.
3366 *)
3367
3368 PROCEDURE IsEffectivelyImported (ModSym, sym: CARDINAL) : BOOLEAN ;
3369 BEGIN
3370 RETURN(
3371 IsImported(ModSym, sym) OR
3372 (IsImported(ModSym, GetModuleWhereDeclared(sym)) AND
3373 IsExported(GetModuleWhereDeclared(sym), sym))
3374 )
3375 END IsEffectivelyImported ;
3376
3377
3378 (*
3379 FindOuterModule - returns the out most module where, sym,
3380 was declared. It returns NulSym if the
3381 symbol or the module was declared inside
3382 a procedure.
3383 *)
3384
3385 PROCEDURE FindOuterModule (sym: CARDINAL) : CARDINAL ;
3386 BEGIN
3387 sym := GetScope(sym) ;
3388 WHILE (NOT IsDefImp(sym)) DO
3389 IF IsModule(sym)
3390 THEN
3391 IF GetScope(sym)=NulSym
3392 THEN
3393 RETURN( sym )
3394 ELSE
3395 sym := GetScope(sym)
3396 END
3397 ELSIF IsProcedure(sym)
3398 THEN
3399 sym := GetScope(sym)
3400 END
3401 END ;
3402 RETURN( sym )
3403 END FindOuterModule ;
3404
3405
3406 (*
3407 DoVariableDeclaration - create a corresponding gcc variable and add the association
3408 between the front end symbol var and the gcc tree.
3409 *)
3410
3411 PROCEDURE DoVariableDeclaration (var: CARDINAL; name: ADDRESS;
3412 isImported, isExported,
3413 isTemporary, isGlobal: BOOLEAN;
3414 scope: tree) ;
3415 BEGIN
3416 IF NOT (IsComponent (var) OR IsVarHeap (var))
3417 THEN
3418 IF TypeDependentsDeclared (var, TRUE)
3419 THEN
3420 PrepareGCCVarDeclaration (var, name, isImported, isExported,
3421 isTemporary, isGlobal, scope)
3422 END
3423 END
3424 END DoVariableDeclaration ;
3425
3426
3427 (*
3428 TypeDependentsDeclared - return TRUE if all type dependents of variable
3429 have been declared.
3430 *)
3431
3432 PROCEDURE TypeDependentsDeclared (variable: CARDINAL; errorMessage: BOOLEAN) : BOOLEAN ;
3433 VAR
3434 type: CARDINAL ;
3435 BEGIN
3436 type := GetSType (variable) ;
3437 IF AllDependantsFullyDeclared (type)
3438 THEN
3439 RETURN TRUE
3440 ELSE
3441 IF errorMessage
3442 THEN
3443 EmitCircularDependencyError (variable) ;
3444 ForeachElementInSetDo (GlobalGroup^.ToDoList, EmitCircularDependencyError)
3445 END
3446 END ;
3447 RETURN FALSE
3448 END TypeDependentsDeclared ;
3449
3450
3451 (*
3452 PrepareGCCVarDeclaration -
3453 *)
3454
3455 PROCEDURE PrepareGCCVarDeclaration (var: CARDINAL; name: ADDRESS;
3456 isImported, isExported,
3457 isTemporary, isGlobal: BOOLEAN;
3458 scope: tree) ;
3459 VAR
3460 type : tree ;
3461 varType : CARDINAL ;
3462 location: location_t ;
3463 BEGIN
3464 IF GetMode (var) = LeftValue
3465 THEN
3466 (*
3467 There are two issues to deal with:
3468
3469 (i) LeftValue is really a pointer to GetSType (var), which is built
3470 here.
3471 (ii) Front end might have specified the back end use a particular
3472 data type, in which case we use the specified type.
3473 We do not add an extra pointer if this is the case.
3474 *)
3475 varType := SkipType (GetVarBackEndType (var)) ;
3476 IF varType=NulSym
3477 THEN
3478 (* We have not explicity told back end the type, so build it. *)
3479 varType := GetSType (var) ;
3480 IF IsVariableAtAddress (var)
3481 THEN
3482 type := BuildConstPointerType (Mod2Gcc (varType))
3483 ELSE
3484 type := BuildPointerType (Mod2Gcc (varType))
3485 END
3486 ELSE
3487 (* We have been requested to use varType. *)
3488 type := Mod2Gcc (varType)
3489 END ;
3490 Assert (AllDependantsFullyDeclared (varType))
3491 ELSE
3492 type := Mod2Gcc (GetDType (var))
3493 END ;
3494 location := TokenToLocation (GetDeclaredMod (var)) ;
3495 PreAddModGcc (var, DeclareKnownVariable (location,
3496 name, type,
3497 isExported, isImported, isTemporary,
3498 isGlobal, scope, NIL)) ;
3499 WatchRemoveList (var, todolist) ;
3500 WatchIncludeList (var, fullydeclared)
3501 END PrepareGCCVarDeclaration ;
3502
3503
3504 (*
3505 IsGlobal - is the variable not in a procedure scope.
3506 *)
3507
3508 PROCEDURE IsGlobal (sym: CARDINAL) : BOOLEAN ;
3509 VAR
3510 s: CARDINAL ;
3511 BEGIN
3512 s := GetScope(sym) ;
3513 WHILE (s#NulSym) AND (NOT IsDefImp (s)) AND (NOT IsModule (s)) DO
3514 IF IsProcedure (s)
3515 THEN
3516 RETURN FALSE
3517 END ;
3518 s := GetScope (s)
3519 END ;
3520 RETURN TRUE
3521 END IsGlobal ;
3522
3523
3524 (*
3525 DeclareVariable - declares a global variable to GCC.
3526 *)
3527
3528 PROCEDURE DeclareVariable (ModSym, variable: CARDINAL) ;
3529 VAR
3530 scope: tree ;
3531 decl : CARDINAL ;
3532 BEGIN
3533 IF NOT GccKnowsAbout (variable)
3534 THEN
3535 scope := FindContext (ModSym) ;
3536 decl := FindOuterModule (variable) ;
3537 PushBinding (ModSym) ;
3538 DoVariableDeclaration (variable,
3539 KeyToCharStar (GetFullSymName (variable)),
3540 (* in Modula-2 we are allowed to import from ourselves, but we do not present this to GCC *)
3541 IsEffectivelyImported(ModSym, variable) AND (GetMainModule () # decl),
3542 IsExported(ModSym, variable),
3543 IsTemporary (variable),
3544 IsGlobal (variable),
3545 scope) ;
3546 PopBinding (ModSym)
3547 END
3548 END DeclareVariable ;
3549
3550
3551 (*
3552 DeclareVariableWholeProgram - declares a global variable to GCC when using -fm2-whole-program.
3553 *)
3554
3555 PROCEDURE DeclareVariableWholeProgram (mainModule, variable: CARDINAL) ;
3556 VAR
3557 scope: tree ;
3558 decl : CARDINAL ;
3559 BEGIN
3560 IF NOT GccKnowsAbout (variable)
3561 THEN
3562 scope := FindContext (mainModule) ;
3563 decl := FindOuterModule (variable) ;
3564 PushBinding (mainModule) ;
3565 DoVariableDeclaration (variable,
3566 KeyToCharStar (GetFullSymName (variable)),
3567 (NOT IsSourceSeen (decl)) AND
3568 IsEffectivelyImported (mainModule, variable) AND (GetMainModule () # decl),
3569 IsExported (mainModule, variable),
3570 IsTemporary (variable),
3571 IsGlobal (variable),
3572 scope) ;
3573 PopBinding (mainModule)
3574 END
3575 END DeclareVariableWholeProgram ;
3576
3577
3578 (*
3579 DeclareGlobalVariablesWholeProgram -
3580 *)
3581
3582 PROCEDURE DeclareGlobalVariablesWholeProgram (ModSym: CARDINAL) ;
3583 VAR
3584 n, Variable: CARDINAL ;
3585 BEGIN
3586 n := 1 ;
3587 Variable := GetNth (ModSym, n) ;
3588 WHILE Variable # NulSym DO
3589 DeclareVariableWholeProgram (ModSym, Variable) ;
3590 INC (n) ;
3591 Variable := GetNth (ModSym, n)
3592 END ;
3593 ForeachInnerModuleDo(ModSym, DeclareGlobalVariablesWholeProgram)
3594 END DeclareGlobalVariablesWholeProgram ;
3595
3596
3597 (*
3598 DeclareGlobalVariables - lists the Global variables for
3599 Module ModSym together with their offset.
3600 *)
3601
3602 PROCEDURE DeclareGlobalVariables (ModSym: CARDINAL) ;
3603 VAR
3604 n, Variable: CARDINAL ;
3605 BEGIN
3606 n := 1 ;
3607 Variable := GetNth (ModSym, n) ;
3608 WHILE Variable # NulSym DO
3609 DeclareVariable (ModSym, Variable) ;
3610 INC (n) ;
3611 Variable := GetNth (ModSym, n)
3612 END ;
3613 ForeachInnerModuleDo (ModSym, DeclareGlobalVariables)
3614 END DeclareGlobalVariables ;
3615
3616
3617 (*
3618 DeclareImportedVariables - declares all imported variables to GM2.
3619 *)
3620
3621 PROCEDURE DeclareImportedVariables (sym: WORD) ;
3622 BEGIN
3623 IF IsVar (sym)
3624 THEN
3625 DeclareVariable (GetMainModule (), sym)
3626 ELSIF IsDefImp (sym)
3627 THEN
3628 ForeachExportedDo (sym, DeclareImportedVariables)
3629 END
3630 END DeclareImportedVariables ;
3631
3632
3633 (*
3634 DeclareImportedVariablesWholeProgram - declares all imported variables.
3635 *)
3636
3637 PROCEDURE DeclareImportedVariablesWholeProgram (sym: WORD) ;
3638 BEGIN
3639 IF IsVar (sym)
3640 THEN
3641 IF NOT IsSourceSeen (FindOuterModule (sym))
3642 THEN
3643 (* import is necessary, even for -fm2-whole-program as we
3644 cannot see the source. *)
3645 DeclareVariableWholeProgram (GetMainModule (), sym)
3646 END
3647 ELSIF IsDefImp (sym)
3648 THEN
3649 ForeachExportedDo (sym, DeclareImportedVariablesWholeProgram)
3650 END
3651 END DeclareImportedVariablesWholeProgram ;
3652
3653
3654 (*
3655 DeclareLocalVariable - declare a local variable var.
3656 *)
3657
3658 PROCEDURE DeclareLocalVariable (var: CARDINAL) ;
3659 BEGIN
3660 DoVariableDeclaration (var,
3661 KeyToCharStar (GetFullSymName (var)),
3662 FALSE, (* local variables cannot be imported *)
3663 FALSE, (* or exported *)
3664 IsTemporary (var),
3665 FALSE, (* and are not global *)
3666 Mod2Gcc (GetScope (var)))
3667 END DeclareLocalVariable ;
3668
3669
3670 (*
3671 DeclareLocalVariables - declares Local variables for procedure.
3672 *)
3673
3674 PROCEDURE DeclareLocalVariables (procedure: CARDINAL) ;
3675 VAR
3676 i, var: CARDINAL ;
3677 BEGIN
3678 i := NoOfParamAny (procedure) + 1 ;
3679 var := GetNth (procedure, i) ;
3680 WHILE var # NulSym DO
3681 Assert (procedure = GetScope (var)) ;
3682 DeclareLocalVariable (var) ;
3683 INC (i) ;
3684 var := GetNth (procedure, i)
3685 END
3686 END DeclareLocalVariables ;
3687
3688
3689 (*
3690 DeclareModuleVariables - declares Module variables for a module
3691 which was declared inside a procedure.
3692 *)
3693
3694 PROCEDURE DeclareModuleVariables (sym: CARDINAL) ;
3695 VAR
3696 scope : tree ;
3697 i, Var: CARDINAL ;
3698 BEGIN
3699 i := 1 ;
3700 scope := Mod2Gcc (GetProcedureScope (sym)) ;
3701 Var := GetNth (sym, i) ;
3702 WHILE Var # NulSym DO
3703 DoVariableDeclaration (Var,
3704 KeyToCharStar (GetFullSymName (Var)),
3705 FALSE, (* inner module variables cannot be imported *)
3706 FALSE, (* or exported (as far as GCC is concerned) *)
3707 IsTemporary (Var),
3708 FALSE, (* and are not global *)
3709 scope) ;
3710 INC (i) ;
3711 Var := GetNth (sym, i)
3712 END
3713 END DeclareModuleVariables ;
3714
3715
3716 (*
3717 DeclareFieldValue -
3718 *)
3719
3720 PROCEDURE DeclareFieldValue (sym: CARDINAL; value: tree; VAR list: tree) : tree ;
3721 VAR
3722 location: location_t ;
3723 BEGIN
3724 location := TokenToLocation(GetDeclaredMod(sym)) ;
3725 IF (GetModuleWhereDeclared(sym)=NulSym) OR
3726 (GetModuleWhereDeclared(sym)=GetMainModule())
3727 THEN
3728 RETURN( BuildEnumerator(location, KeyToCharStar(GetSymName(sym)), value, list) )
3729 ELSE
3730 RETURN( BuildEnumerator(location, KeyToCharStar(GetFullScopeAsmName(sym)), value, list) )
3731 END
3732 END DeclareFieldValue ;
3733
3734
3735 (*
3736 DeclareFieldEnumeration - declares an enumerator within the current enumeration type.
3737 *)
3738
3739 PROCEDURE DeclareFieldEnumeration (sym: WORD) : tree ;
3740 VAR
3741 type : CARDINAL ;
3742 field,
3743 enumlist: tree ;
3744 BEGIN
3745 (* add relationship between gccSym and sym *)
3746 type := GetSType (sym) ;
3747 enumlist := GetEnumList (type) ;
3748 PushValue (sym) ;
3749 field := DeclareFieldValue (sym, PopIntegerTree (), enumlist) ;
3750 PutEnumList (type, enumlist) ;
3751 RETURN field
3752 END DeclareFieldEnumeration ;
3753
3754
3755 (*
3756 DeclareEnumeration - declare an enumerated type.
3757 *)
3758
3759 PROCEDURE DeclareEnumeration (sym: WORD) : tree ;
3760 VAR
3761 enumlist,
3762 gccenum : tree ;
3763 location: location_t ;
3764 BEGIN
3765 location := TokenToLocation (GetDeclaredMod (sym)) ;
3766 gccenum := BuildStartEnumeration (location, KeyToCharStar (GetFullSymName (sym)), FALSE) ;
3767 enumlist := GetEnumList (sym) ;
3768 RETURN BuildEndEnumeration (location, gccenum, enumlist)
3769 END DeclareEnumeration ;
3770
3771
3772 (*
3773 DeclareSubrangeNarrow - will return cardinal, integer, or type depending on whether
3774 low..high fits in the C data type.
3775 *)
3776
3777 PROCEDURE DeclareSubrangeNarrow (location: location_t;
3778 high, low: CARDINAL; type: tree) : tree ;
3779 VAR
3780 m2low, m2high,
3781 lowtree,
3782 hightree : tree ;
3783 BEGIN
3784 (* No zero alignment, therefore the front end will prioritize subranges to match
3785 unsigned int, int, or ZTYPE assuming the low..high range fits. *)
3786 lowtree := Mod2Gcc (low) ;
3787 hightree := Mod2Gcc (high) ;
3788 IF CompareTrees (lowtree, GetIntegerZero (location)) >= 0
3789 THEN
3790 (* low..high is always positive, can we use unsigned int? *)
3791 m2high := GetMaxFrom (location, GetM2CardinalType ()) ;
3792 IF CompareTrees (hightree, m2high) <= 0
3793 THEN
3794 RETURN GetM2CardinalType ()
3795 END
3796 ELSE
3797 (* Must be a signed subrange base, can we use int? *)
3798 m2high := GetMaxFrom (location, GetM2IntegerType ()) ;
3799 m2low := GetMinFrom (location, GetM2IntegerType ()) ;
3800 IF (CompareTrees (lowtree, m2low) >= 0) AND (CompareTrees (hightree, m2high) <= 0)
3801 THEN
3802 RETURN GetM2IntegerType ()
3803 END
3804 END ;
3805 (* Fall back to the ZType. *)
3806 RETURN type
3807 END DeclareSubrangeNarrow ;
3808
3809
3810 (*
3811 DeclareSubrange - declare a subrange type.
3812 *)
3813
3814 PROCEDURE DeclareSubrange (sym: CARDINAL) : tree ;
3815 VAR
3816 type,
3817 gccsym : tree ;
3818 align,
3819 high, low: CARDINAL ;
3820 location: location_t ;
3821 BEGIN
3822 location := TokenToLocation (GetDeclaredMod (sym)) ;
3823 GetSubrange (sym, high, low) ;
3824 align := GetAlignment (sym) ;
3825 type := Mod2Gcc (GetSType (sym)) ;
3826 IF align # NulSym
3827 THEN
3828 IF AreConstantsEqual (GetIntegerZero (location), Mod2Gcc (align))
3829 THEN
3830 type := BuildSmallestTypeRange (location, Mod2Gcc (low), Mod2Gcc (high))
3831 ELSE
3832 MetaError1 ('a non-zero alignment in a subrange type {%1Wa} is currently not implemented and will be ignored',
3833 sym)
3834 END
3835 ELSIF GetSType (sym) = ZType
3836 THEN
3837 (* Can we narrow the ZType subrange to CARDINAL or INTEGER? *)
3838 type := DeclareSubrangeNarrow (location, high, low, type)
3839 END ;
3840 gccsym := BuildSubrangeType (location,
3841 KeyToCharStar (GetFullSymName (sym)),
3842 type, Mod2Gcc (low), Mod2Gcc (high)) ;
3843 RETURN gccsym
3844 END DeclareSubrange ;
3845
3846
3847 (*
3848 IncludeGetNth -
3849 *)
3850
3851 PROCEDURE IncludeGetNth (l: List; sym: CARDINAL) ;
3852 VAR
3853 i: CARDINAL ;
3854 BEGIN
3855 fprintf0 (GetDumpFile (), ' ListOfFields [') ;
3856 i := 1 ;
3857 WHILE GetNth (sym, i) # NulSym DO
3858 IF i>1
3859 THEN
3860 fprintf0 (GetDumpFile (), ', ')
3861 END ;
3862 IncludeItemIntoList (l, GetNth(sym, i)) ;
3863 PrintTerse (GetNth (sym, i)) ;
3864 INC (i)
3865 END ;
3866 fprintf0 (GetDumpFile (), ']')
3867 END IncludeGetNth ;
3868
3869
3870 (*
3871 IncludeType -
3872 *)
3873
3874 PROCEDURE IncludeType (l: List; sym: CARDINAL) ;
3875 VAR
3876 t: CARDINAL ;
3877 BEGIN
3878 t := GetSType(sym) ;
3879 IF t#NulSym
3880 THEN
3881 fprintf0 (GetDumpFile(), ' type [') ;
3882 PrintTerse(t) ;
3883 IncludeItemIntoList(l, t) ;
3884 fprintf0 (GetDumpFile(), ']') ;
3885 t := GetVarBackEndType(sym) ;
3886 IF t#NulSym
3887 THEN
3888 fprintf0 (GetDumpFile(), ' gcc type [') ;
3889 PrintTerse(t) ;
3890 IncludeItemIntoList(l, t) ;
3891 fprintf0 (GetDumpFile(), ']')
3892 END
3893 END
3894 END IncludeType ;
3895
3896
3897 (*
3898 IncludeSubscript -
3899 *)
3900
3901 PROCEDURE IncludeSubscript (l: List; sym: CARDINAL) ;
3902 VAR
3903 t: CARDINAL ;
3904 BEGIN
3905 t := GetArraySubscript(sym) ;
3906 IF t#NulSym
3907 THEN
3908 fprintf0 (GetDumpFile(), ' subrange [') ;
3909 PrintTerse(t) ;
3910 IncludeItemIntoList(l, t) ;
3911 fprintf0 (GetDumpFile(), ']') ;
3912 END
3913 END IncludeSubscript ;
3914
3915
3916 (*
3917 PrintLocalSymbol -
3918 *)
3919
3920 PROCEDURE PrintLocalSymbol (sym: CARDINAL) ;
3921 BEGIN
3922 PrintTerse(sym) ; fprintf0 (GetDumpFile(), ', ')
3923 END PrintLocalSymbol ;
3924
3925
3926 (*
3927 PrintLocalSymbols -
3928 *)
3929
3930 PROCEDURE PrintLocalSymbols (sym: CARDINAL) ;
3931 BEGIN
3932 fprintf0 (GetDumpFile(), 'Local Symbols {') ;
3933 ForeachLocalSymDo(sym, PrintLocalSymbol) ;
3934 fprintf0 (GetDumpFile(), '}')
3935 END PrintLocalSymbols ;
3936
3937
3938 (*
3939 IncludeGetVarient -
3940 *)
3941
3942 PROCEDURE IncludeGetVarient (l: List; sym: CARDINAL) ;
3943 BEGIN
3944 IF GetVarient(sym)#NulSym
3945 THEN
3946 fprintf0 (GetDumpFile(), ' Varient [') ;
3947 PrintTerse(GetVarient(sym)) ;
3948 fprintf0 (GetDumpFile(), ']') ;
3949 IncludeItemIntoList(l, GetVarient(sym))
3950 END
3951 END IncludeGetVarient ;
3952
3953
3954 (*
3955 IncludeUnbounded - includes the record component of an unbounded type.
3956 *)
3957
3958 PROCEDURE IncludeUnbounded (l: List; sym: CARDINAL) ;
3959 BEGIN
3960 IF GetUnboundedRecordType(sym)#NulSym
3961 THEN
3962 IncludeItemIntoList(l, GetUnboundedRecordType(sym))
3963 END
3964 END IncludeUnbounded ;
3965
3966
3967 (*
3968 IncludePartialUnbounded - includes the type component of a partial unbounded symbol.
3969 *)
3970
3971 PROCEDURE IncludePartialUnbounded (l: List; sym: CARDINAL) ;
3972 BEGIN
3973 IF GetSType(sym)#NulSym
3974 THEN
3975 IncludeItemIntoList(l, GetSType(sym))
3976 END
3977 END IncludePartialUnbounded ;
3978
3979
3980 (*
3981 PrintDeclared - prints out where, sym, was declared.
3982 *)
3983
3984 PROCEDURE PrintDeclared (sym: CARDINAL) ;
3985 VAR
3986 filename: String ;
3987 lineno,
3988 tokenno : CARDINAL ;
3989 BEGIN
3990 tokenno := GetDeclaredMod(sym) ;
3991 filename := FindFileNameFromToken(tokenno, 0) ;
3992 lineno := TokenToLineNo(tokenno, 0) ;
3993 fprintf2 (GetDumpFile (), " declared in %s:%d", filename, lineno)
3994 END PrintDeclared ;
3995
3996
3997 (*
3998 PrintAlignment -
3999 *)
4000
4001 PROCEDURE PrintAlignment (sym: CARDINAL) ;
4002 VAR
4003 align: CARDINAL ;
4004 BEGIN
4005 IF IsRecord(sym) OR IsType(sym) OR IsRecordField(sym) OR IsPointer(sym) OR IsArray(sym)
4006 THEN
4007 align := GetAlignment(sym) ;
4008 IF align#NulSym
4009 THEN
4010 fprintf1 (GetDumpFile(), " aligned [%d]", align)
4011 END
4012 END
4013 END PrintAlignment ;
4014
4015
4016 (*
4017 IncludeGetParent -
4018 *)
4019
4020 PROCEDURE IncludeGetParent (l: List; sym: CARDINAL) ;
4021 BEGIN
4022 fprintf0 (GetDumpFile(), ' Parent [') ;
4023 IncludeItemIntoList(l, GetParent(sym)) ;
4024 PrintTerse(GetParent(sym)) ;
4025 fprintf0 (GetDumpFile(), ']')
4026 END IncludeGetParent ;
4027
4028
4029 (*
4030 PrintDecl -
4031 *)
4032
4033 PROCEDURE PrintDecl (sym: CARDINAL) ;
4034 BEGIN
4035 IF IsDeclaredPackedResolved(sym)
4036 THEN
4037 IF IsDeclaredPacked(sym)
4038 THEN
4039 fprintf0 (GetDumpFile(), ' packed')
4040 ELSE
4041 fprintf0 (GetDumpFile(), ' unpacked')
4042 END
4043 ELSE
4044 fprintf0 (GetDumpFile(), ' unknown if packed')
4045 END
4046 END PrintDecl ;
4047
4048
4049 (*
4050 PrintScope - displays the scope and line number of declaration of symbol, sym.
4051 *)
4052
4053 PROCEDURE PrintScope (sym: CARDINAL) ;
4054 VAR
4055 name : Name ;
4056 scope,
4057 line : CARDINAL ;
4058 BEGIN
4059 line := TokenToLineNo (GetDeclaredMod (sym), 0) ;
4060 scope := GetScope (sym) ;
4061 name := GetSymName (scope) ;
4062 fprintf3 (GetDumpFile (), ' scope %a:%d %d', name, line, scope)
4063 END PrintScope ;
4064
4065
4066 (*
4067 PrintKind -
4068 *)
4069
4070 PROCEDURE PrintKind (kind: ProcedureKind) ;
4071 VAR
4072 s: String ;
4073 BEGIN
4074 s := GetProcedureKindDesc (kind) ;
4075 fprintf1 (GetDumpFile (), "%s", s) ;
4076 s := KillString (s)
4077 END PrintKind ;
4078
4079
4080 (*
4081 PrintProcedureParameters -
4082 *)
4083
4084 PROCEDURE PrintProcedureParameters (sym: CARDINAL; kind: ProcedureKind) ;
4085 VAR
4086 typeName,
4087 paramName: Name ;
4088 p, i, n,
4089 type : CARDINAL ;
4090 BEGIN
4091 fprintf0 (GetDumpFile (), ' (') ;
4092 n := NoOfParam (sym, kind) ;
4093 i := 1 ;
4094 WHILE i <= n DO
4095 IF i > 1
4096 THEN
4097 fprintf0 (GetDumpFile (), '; ')
4098 END ;
4099 IF IsVarParam (sym, kind, i)
4100 THEN
4101 fprintf0 (GetDumpFile (), 'VAR ')
4102 END ;
4103 p := GetNthParam (sym, kind, i) ;
4104 paramName := GetSymName (p) ;
4105 type := GetType (p) ;
4106 typeName := GetSymName (type) ;
4107 IF IsUnboundedParam (sym, kind, i)
4108 THEN
4109 fprintf2 (GetDumpFile (), '%a: ARRAY OF %a', paramName, typeName)
4110 ELSE
4111 fprintf2 (GetDumpFile (), '%a: %a', paramName, typeName)
4112 END ;
4113 INC (i)
4114 END ;
4115 fprintf0 (GetDumpFile (), ')')
4116 END PrintProcedureParameters ;
4117
4118
4119 (*
4120 PrintProcedureReturnType -
4121 *)
4122
4123 PROCEDURE PrintProcedureReturnType (sym: CARDINAL) ;
4124 VAR
4125 typeName: Name ;
4126 BEGIN
4127 IF GetType (sym) # NulSym
4128 THEN
4129 typeName := GetSymName (GetType (sym)) ;
4130 fprintf1 (GetDumpFile (), ' : %a', typeName)
4131 END ;
4132 fprintf0 (GetDumpFile (), ' ;')
4133 END PrintProcedureReturnType ;
4134
4135
4136 (*
4137 PrintProcedure -
4138 *)
4139
4140 PROCEDURE PrintProcedure (sym: CARDINAL) ;
4141 VAR
4142 n : Name ;
4143 kind: ProcedureKind ;
4144 BEGIN
4145 n := GetSymName (sym) ;
4146 fprintf2 (GetDumpFile (), 'sym %d IsProcedure (%a)', sym, n);
4147 IF IsProcedureReachable(sym)
4148 THEN
4149 fprintf0 (GetDumpFile(), ' IsProcedureReachable')
4150 END ;
4151 PrintScope (sym) ;
4152 IF IsExtern (sym)
4153 THEN
4154 fprintf0 (GetDumpFile (), ' extern')
4155 END ;
4156 IF IsPublic (sym)
4157 THEN
4158 fprintf0 (GetDumpFile (), ' public')
4159 END ;
4160 IF IsCtor (sym)
4161 THEN
4162 fprintf0 (GetDumpFile (), ' ctor')
4163 END ;
4164 PrintDeclared (sym) ;
4165 fprintf0 (GetDumpFile (), '\n') ;
4166 FOR kind := MIN (ProcedureKind) TO MAX (ProcedureKind) DO
4167 fprintf0 (GetDumpFile (), 'parameters ') ;
4168 PrintKind (kind) ;
4169 IF GetProcedureParametersDefined (sym, kind)
4170 THEN
4171 fprintf0 (GetDumpFile (), ' defined') ;
4172 PrintProcedureParameters (sym, kind) ;
4173 PrintProcedureReturnType (sym)
4174 ELSE
4175 fprintf0 (GetDumpFile (), ' undefined')
4176 END ;
4177 fprintf0 (GetDumpFile (), '\n')
4178 END ;
4179 fprintf0 (GetDumpFile (), ' Associated proctype: ') ;
4180 PrintProcType (GetProcedureProcType (sym))
4181 END PrintProcedure ;
4182
4183
4184 (*
4185 PrintProcTypeParameters -
4186 *)
4187
4188 PROCEDURE PrintProcTypeParameters (sym: CARDINAL) ;
4189 VAR
4190 typeName : Name ;
4191 p, i, n,
4192 type : CARDINAL ;
4193 BEGIN
4194 fprintf0 (GetDumpFile (), ' (') ;
4195 n := NoOfParam (sym, ProperProcedure) ;
4196 i := 1 ;
4197 WHILE i <= n DO
4198 IF i > 1
4199 THEN
4200 fprintf0 (GetDumpFile (), '; ')
4201 END ;
4202 IF IsVarParam (sym, ProperProcedure, i)
4203 THEN
4204 fprintf0 (GetDumpFile (), 'VAR ')
4205 END ;
4206 p := GetNthParam (sym, ProperProcedure, i) ;
4207 type := GetType (p) ;
4208 typeName := GetSymName (type) ;
4209 IF IsUnboundedParam (sym, ProperProcedure, i)
4210 THEN
4211 fprintf1 (GetDumpFile (), 'ARRAY OF %a', typeName)
4212 ELSE
4213 fprintf1 (GetDumpFile (), '%a', typeName)
4214 END ;
4215 INC (i)
4216 END ;
4217 fprintf0 (GetDumpFile (), ')')
4218 END PrintProcTypeParameters ;
4219
4220
4221 (*
4222 PrintProcType -
4223 *)
4224
4225 PROCEDURE PrintProcType (sym: CARDINAL) ;
4226 VAR
4227 n: Name ;
4228 BEGIN
4229 n := GetSymName (sym) ;
4230 fprintf2 (GetDumpFile (), 'sym %d IsProcType (%a)', sym, n);
4231 PrintScope (sym) ;
4232 PrintDeclared (sym) ;
4233 fprintf0 (GetDumpFile (), '\n') ;
4234 fprintf0 (GetDumpFile (), 'parameters ') ;
4235 PrintProcTypeParameters (sym) ;
4236 PrintProcedureReturnType (sym) ;
4237 fprintf0 (GetDumpFile (), '\n')
4238 END PrintProcType ;
4239
4240
4241 (*
4242 PrintString -
4243 *)
4244
4245 PROCEDURE PrintString (sym: CARDINAL) ;
4246 VAR
4247 len : CARDINAL ;
4248 tokenno: CARDINAL ;
4249 BEGIN
4250 IF IsConstStringKnown (sym)
4251 THEN
4252 IF IsConstStringM2 (sym)
4253 THEN
4254 fprintf0 (GetDumpFile (), 'a Modula-2 string')
4255 ELSIF IsConstStringC (sym)
4256 THEN
4257 fprintf0 (GetDumpFile (), ' a C string')
4258 ELSIF IsConstStringM2nul (sym)
4259 THEN
4260 fprintf0 (GetDumpFile (), ' a nul terminated Modula-2 string')
4261 ELSIF IsConstStringCnul (sym)
4262 THEN
4263 fprintf0 (GetDumpFile (), ' a nul terminated C string')
4264 END ;
4265 tokenno := GetDeclaredMod (sym) ;
4266 len := GetStringLength (tokenno, sym) ;
4267 fprintf1 (GetDumpFile (), ' length %d', len)
4268 ELSE
4269 fprintf0 (GetDumpFile (), 'is not currently known')
4270 END
4271 END PrintString ;
4272
4273
4274 (*
4275 PrintVerboseFromList - prints the, i, th element in the list, l.
4276 *)
4277
4278 PROCEDURE PrintVerboseFromList (l: List; i: CARDINAL) ;
4279 VAR
4280 type,
4281 low,
4282 high,
4283 sym : CARDINAL ;
4284 n, n2 : Name ;
4285 BEGIN
4286 sym := GetItemFromList(l, i) ;
4287 n := GetSymName(sym) ;
4288 IF IsError(sym)
4289 THEN
4290 fprintf2 (GetDumpFile (), 'sym %d IsError (%a)', sym, n)
4291 ELSIF IsDefImp(sym)
4292 THEN
4293 fprintf2 (GetDumpFile (), 'sym %d IsDefImp (%a)', sym, n) ;
4294 IF IsDefinitionForC(sym)
4295 THEN
4296 fprintf0 (GetDumpFile(), 'and IsDefinitionForC')
4297 END ;
4298 IF IsHiddenTypeDeclared(sym)
4299 THEN
4300 fprintf0 (GetDumpFile(), ' IsHiddenTypeDeclared')
4301 END ;
4302 ForeachProcedureDo (sym, PrintProcedure)
4303 ELSIF IsModule(sym)
4304 THEN
4305 fprintf2 (GetDumpFile (), 'sym %d IsModule (%a)', sym, n) ;
4306 IF IsModuleWithinProcedure(sym)
4307 THEN
4308 fprintf0 (GetDumpFile(), ' and IsModuleWithinProcedure')
4309 END
4310 ELSIF IsInnerModule(sym)
4311 THEN
4312 fprintf2 (GetDumpFile (), 'sym %d IsInnerModule (%a)', sym, n)
4313 ELSIF IsUnknown(sym)
4314 THEN
4315 fprintf2 (GetDumpFile (), 'sym %d IsUnknown (%a)', sym, n)
4316 ELSIF IsType(sym)
4317 THEN
4318 fprintf2 (GetDumpFile (), 'sym %d IsType (%a)', sym, n) ;
4319 IncludeType(l, sym) ;
4320 PrintAlignment(sym)
4321 ELSIF IsProcedure(sym)
4322 THEN
4323 PrintProcedure (sym)
4324 ELSIF IsParameter(sym)
4325 THEN
4326 fprintf2 (GetDumpFile (), 'sym %d IsParameter (%a)', sym, n) ;
4327 IF GetParameterShadowVar(sym)=NulSym
4328 THEN
4329 fprintf0 (GetDumpFile(), ' no shadow local variable')
4330 ELSE
4331 fprintf0 (GetDumpFile(), ' shadow ') ;
4332 IncludeType(l, GetParameterShadowVar(sym))
4333 (* PrintVerboseFromList(l, GetParameterShadowVar(sym)) *)
4334 END ;
4335 IncludeType(l, sym)
4336 ELSIF IsPointer(sym)
4337 THEN
4338 fprintf2 (GetDumpFile (), 'sym %d IsPointer (%a)', sym, n) ;
4339 IncludeType(l, sym) ;
4340 PrintAlignment(sym)
4341 ELSIF IsRecord(sym)
4342 THEN
4343 fprintf2 (GetDumpFile (), 'sym %d IsRecord (%a)', sym, n) ;
4344 PrintLocalSymbols(sym) ;
4345 IncludeGetNth(l, sym) ;
4346 PrintAlignment(sym) ;
4347 PrintDecl(sym)
4348 ELSIF IsVarient(sym)
4349 THEN
4350 fprintf2 (GetDumpFile (), 'sym %d IsVarient (%a)', sym, n) ;
4351 PrintDecl(sym) ;
4352 IncludeGetNth(l, sym) ;
4353 IncludeGetVarient(l, sym) ;
4354 IncludeGetParent(l, sym)
4355 ELSIF IsFieldVarient(sym)
4356 THEN
4357 fprintf2 (GetDumpFile (), 'sym %d IsFieldVarient (%a)', sym, n) ;
4358 PrintDecl(sym) ;
4359 IncludeGetNth(l, sym) ;
4360 IncludeGetVarient(l, sym) ;
4361 IncludeGetParent(l, sym)
4362 ELSIF IsFieldEnumeration(sym)
4363 THEN
4364 fprintf2 (GetDumpFile (), 'sym %d IsFieldEnumeration (%a)', sym, n)
4365 ELSIF IsArray(sym)
4366 THEN
4367 fprintf2 (GetDumpFile (), 'sym %d IsArray (%a)', sym, n) ;
4368 IncludeSubscript(l, sym) ;
4369 IncludeType(l, sym) ;
4370 PrintAlignment(sym)
4371 ELSIF IsEnumeration(sym)
4372 THEN
4373 fprintf2 (GetDumpFile (), 'sym %d IsEnumeration (%a)', sym, n)
4374 ELSIF IsSet(sym)
4375 THEN
4376 fprintf2 (GetDumpFile (), 'sym %d IsSet (%a)', sym, n) ;
4377 IncludeType(l, sym)
4378 ELSIF IsUnbounded(sym)
4379 THEN
4380 fprintf2 (GetDumpFile (), 'sym %d IsUnbounded (%a)', sym, n) ;
4381 IncludeUnbounded(l, sym)
4382 ELSIF IsPartialUnbounded(sym)
4383 THEN
4384 fprintf2 (GetDumpFile (), 'sym %d IsPartialUnbounded (%a)', sym, n) ;
4385 IncludePartialUnbounded(l, sym)
4386 ELSIF IsRecordField(sym)
4387 THEN
4388 fprintf2 (GetDumpFile (), 'sym %d IsRecordField (%a)', sym, n) ;
4389 IF IsRecordFieldAVarientTag(sym)
4390 THEN
4391 fprintf0 (GetDumpFile(), ' variant tag')
4392 END ;
4393 IncludeType(l, sym) ;
4394 IncludeGetVarient(l, sym) ;
4395 IncludeGetParent(l, sym) ;
4396 PrintAlignment(sym) ;
4397 PrintDecl(sym)
4398 ELSIF IsProcType(sym)
4399 THEN
4400 PrintProcType (sym)
4401 ELSIF IsVar(sym)
4402 THEN
4403 fprintf2 (GetDumpFile (), 'sym %d IsVar (%a) declared in ', sym, n) ;
4404 PrintScope (sym) ;
4405 fprintf0 (GetDumpFile (), 'mode ') ;
4406 CASE GetMode(sym) OF
4407
4408 LeftValue : fprintf0 (GetDumpFile(), 'l ') |
4409 RightValue : fprintf0 (GetDumpFile(), 'r ') |
4410 ImmediateValue: fprintf0 (GetDumpFile(), 'i ') |
4411 NoValue : fprintf0 (GetDumpFile(), 'n ')
4412
4413 END ;
4414 IF IsTemporary(sym)
4415 THEN
4416 fprintf0 (GetDumpFile(), 'temporary ')
4417 END ;
4418 IF IsComponent(sym)
4419 THEN
4420 fprintf0 (GetDumpFile(), 'component ')
4421 END ;
4422 IF IsVarHeap (sym)
4423 THEN
4424 fprintf0 (GetDumpFile(), 'heap ')
4425 END ;
4426 fprintf0 (GetDumpFile (), '\n') ;
4427 PrintInitialized (sym) ;
4428 IncludeType(l, sym)
4429 ELSIF IsConst(sym)
4430 THEN
4431 fprintf2 (GetDumpFile (), 'sym %d IsConst (%a)', sym, n) ;
4432 IF IsConstString(sym)
4433 THEN
4434 fprintf1 (GetDumpFile(), ' also IsConstString (%a)', n) ;
4435 PrintString (sym)
4436 ELSIF IsConstructor(sym)
4437 THEN
4438 fprintf0 (GetDumpFile(), ' constant constructor ') ;
4439 IncludeType(l, sym)
4440 ELSIF IsConstSet(sym)
4441 THEN
4442 fprintf0 (GetDumpFile(), ' constant constructor set ') ;
4443 IncludeType(l, sym)
4444 ELSE
4445 IncludeType(l, sym)
4446 END
4447 ELSIF IsConstructor(sym)
4448 THEN
4449 fprintf2 (GetDumpFile(), 'sym %d IsConstructor (non constant) (%a)', sym, n) ;
4450 IncludeType(l, sym)
4451 ELSIF IsConstLit(sym)
4452 THEN
4453 fprintf2 (GetDumpFile(), 'sym %d IsConstLit (%a)', sym, n)
4454 ELSIF IsDummy(sym)
4455 THEN
4456 fprintf2 (GetDumpFile(), 'sym %d IsDummy (%a)', sym, n)
4457 ELSIF IsTemporary(sym)
4458 THEN
4459 fprintf2 (GetDumpFile(), 'sym %d IsTemporary (%a)', sym, n)
4460 ELSIF IsVarAParam(sym)
4461 THEN
4462 fprintf2 (GetDumpFile(), 'sym %d IsVarAParam (%a)', sym, n)
4463 ELSIF IsSubscript(sym)
4464 THEN
4465 fprintf2 (GetDumpFile(), 'sym %d IsSubscript (%a)', sym, n)
4466 ELSIF IsSubrange(sym)
4467 THEN
4468 GetSubrange(sym, high, low) ;
4469 fprintf2 (GetDumpFile(), 'sym %d IsSubrange (%a)', sym, n) ;
4470 IF (low#NulSym) AND (high#NulSym)
4471 THEN
4472 type := GetSType(sym) ;
4473 IF type#NulSym
4474 THEN
4475 IncludeType(l, sym) ;
4476 n := GetSymName(type) ;
4477 fprintf1 (GetDumpFile(), ' %a', n)
4478 END ;
4479 n := GetSymName(low) ;
4480 n2 := GetSymName(high) ;
4481 fprintf2 (GetDumpFile (), '[%a..%a]', n, n2)
4482 END
4483 ELSIF IsProcedureVariable(sym)
4484 THEN
4485 fprintf2 (GetDumpFile (), 'sym %d IsProcedureVariable (%a)', sym, n)
4486 ELSIF IsProcedureNested(sym)
4487 THEN
4488 fprintf2 (GetDumpFile (), 'sym %d IsProcedureNested (%a)', sym, n)
4489 ELSIF IsAModula2Type(sym)
4490 THEN
4491 fprintf2 (GetDumpFile (), 'sym %d IsAModula2Type (%a)', sym, n)
4492 ELSIF IsObject(sym)
4493 THEN
4494 fprintf2 (GetDumpFile (), 'sym %d IsObject (%a)', sym, n)
4495 ELSIF IsTuple(sym)
4496 THEN
4497 fprintf2 (GetDumpFile (), 'sym %d IsTuple (%a)', sym, n) ;
4498 low := GetNth(sym, 1) ;
4499 high := GetNth(sym, 2) ;
4500 fprintf2 (GetDumpFile (), '%d, %d\n', low, high)
4501 ELSIF IsGnuAsm(sym)
4502 THEN
4503 IF IsGnuAsmVolatile(sym)
4504 THEN
4505 fprintf2 (GetDumpFile (), 'sym %d IsGnuAsmVolatile (%a)', sym, n)
4506 ELSE
4507 fprintf2 (GetDumpFile (), 'sym %d IsGnuAsm (%a)', sym, n)
4508 END
4509 ELSIF IsComponent(sym)
4510 THEN
4511 fprintf2 (GetDumpFile (), 'sym %d IsComponent (%a) ', sym, n) ;
4512 i := 1 ;
4513 REPEAT
4514 type := GetNth(sym, i) ;
4515 IF type#NulSym
4516 THEN
4517 IncludeItemIntoList(l, type) ;
4518 n := GetSymName(type) ;
4519 fprintf2 (GetDumpFile (), "[%a %d] ", n, type) ;
4520 INC(i)
4521 END ;
4522 UNTIL type=NulSym
4523 END ;
4524
4525 IF IsHiddenType(sym)
4526 THEN
4527 fprintf0 (GetDumpFile(), ' IsHiddenType')
4528 END ;
4529 fprintf0 (GetDumpFile(), '\n')
4530 END PrintVerboseFromList ;
4531
4532
4533 (*
4534 PrintVerbose - prints limited information about a symbol.
4535 *)
4536
4537 PROCEDURE PrintVerbose (sym: CARDINAL) ;
4538 VAR
4539 l: List ;
4540 i: CARDINAL ;
4541 BEGIN
4542 InitList (l) ;
4543 IncludeItemIntoList (l, sym) ;
4544 i := 1 ;
4545 WHILE i<=NoOfItemsInList (l) DO
4546 PrintVerboseFromList (l, i) ;
4547 INC (i)
4548 END ;
4549 KillList (l)
4550 END PrintVerbose ;
4551
4552
4553 (*
4554 PrintSym - prints limited information about a symbol.
4555 This procedure is externally visible.
4556 *)
4557
4558 PROCEDURE PrintSym (sym: CARDINAL) ;
4559 BEGIN
4560 printf1 ('information about symbol: %d\n', sym) ;
4561 fprintf0 (GetDumpFile (), '==============================\n') ;
4562 PrintVerbose (sym)
4563 END PrintSym ;
4564
4565
4566 (* ********************************
4567 (*
4568 PrintSymbol - prints limited information about a symbol.
4569 *)
4570
4571 PROCEDURE PrintSymbol (sym: CARDINAL) ;
4572 BEGIN
4573 PrintTerse(sym) ;
4574 fprintf0 (GetDumpFile(), '\n')
4575 END PrintSymbol ;
4576 ******************************************* *)
4577
4578 (*
4579 PrintTerse -
4580 *)
4581
4582 PROCEDURE PrintTerse (sym: CARDINAL) ;
4583 VAR
4584 n: Name ;
4585 BEGIN
4586 n := GetSymName(sym) ;
4587 IF IsError(sym)
4588 THEN
4589 fprintf2 (GetDumpFile (), 'sym %d IsError (%a)', sym, n)
4590 ELSIF IsDefImp(sym)
4591 THEN
4592 fprintf2 (GetDumpFile (), 'sym %d IsDefImp (%a)', sym, n) ;
4593 IF IsDefinitionForC(sym)
4594 THEN
4595 fprintf0 (GetDumpFile(), 'and IsDefinitionForC')
4596 END ;
4597 IF IsHiddenTypeDeclared(sym)
4598 THEN
4599 fprintf0 (GetDumpFile(), ' IsHiddenTypeDeclared')
4600 END
4601 ELSIF IsModule(sym)
4602 THEN
4603 fprintf2 (GetDumpFile (), 'sym %d IsModule (%a)', sym, n) ;
4604 IF IsModuleWithinProcedure(sym)
4605 THEN
4606 fprintf0 (GetDumpFile(), ' and IsModuleWithinProcedure')
4607 END
4608 ELSIF IsInnerModule(sym)
4609 THEN
4610 fprintf2 (GetDumpFile (), 'sym %d IsInnerModule (%a)', sym, n)
4611 ELSIF IsUnknown(sym)
4612 THEN
4613 fprintf2 (GetDumpFile (), 'sym %d IsUnknown (%a)', sym, n)
4614 ELSIF IsType(sym)
4615 THEN
4616 fprintf2 (GetDumpFile (), 'sym %d IsType (%a)', sym, n)
4617 ELSIF IsProcedure(sym)
4618 THEN
4619 fprintf2 (GetDumpFile (), 'sym %d IsProcedure (%a)', sym, n);
4620 IF IsProcedureReachable(sym)
4621 THEN
4622 fprintf0 (GetDumpFile(), ' and IsProcedureReachable')
4623 END
4624 ELSIF IsParameter(sym)
4625 THEN
4626 fprintf2 (GetDumpFile (), 'sym %d IsParameter (%a)', sym, n)
4627 ELSIF IsPointer(sym)
4628 THEN
4629 fprintf2 (GetDumpFile (), 'sym %d IsPointer (%a)', sym, n)
4630 ELSIF IsRecord(sym)
4631 THEN
4632 fprintf2 (GetDumpFile (), 'sym %d IsRecord (%a)', sym, n)
4633 ELSIF IsVarient(sym)
4634 THEN
4635 fprintf2 (GetDumpFile (), 'sym %d IsVarient (%a)', sym, n)
4636 ELSIF IsFieldVarient(sym)
4637 THEN
4638 fprintf2 (GetDumpFile (), 'sym %d IsFieldVarient (%a)', sym, n)
4639 ELSIF IsFieldEnumeration(sym)
4640 THEN
4641 fprintf2 (GetDumpFile (), 'sym %d IsFieldEnumeration (%a)', sym, n)
4642 ELSIF IsArray(sym)
4643 THEN
4644 fprintf2 (GetDumpFile (), 'sym %d IsArray (%a)', sym, n)
4645 ELSIF IsEnumeration(sym)
4646 THEN
4647 fprintf2 (GetDumpFile (), 'sym %d IsEnumeration (%a)', sym, n)
4648 ELSIF IsSet(sym)
4649 THEN
4650 fprintf2 (GetDumpFile (), 'sym %d IsSet (%a)', sym, n)
4651 ELSIF IsUnbounded(sym)
4652 THEN
4653 fprintf2 (GetDumpFile (), 'sym %d IsUnbounded (%a)', sym, n)
4654 ELSIF IsRecordField(sym)
4655 THEN
4656 fprintf2 (GetDumpFile (), 'sym %d IsRecordField (%a)', sym, n)
4657 ELSIF IsProcType(sym)
4658 THEN
4659 fprintf2 (GetDumpFile (), 'sym %d IsProcType (%a)', sym, n)
4660 ELSIF IsVar(sym)
4661 THEN
4662 fprintf2 (GetDumpFile (), 'sym %d IsVar (%a)', sym, n)
4663 ELSIF IsConstString(sym)
4664 THEN
4665 fprintf2 (GetDumpFile (), 'sym %d IsConstString (%a)', sym, n)
4666 ELSIF IsConst(sym)
4667 THEN
4668 fprintf2 (GetDumpFile (), 'sym %d IsConst (%a)', sym, n)
4669 ELSIF IsConstLit(sym)
4670 THEN
4671 fprintf2 (GetDumpFile (), 'sym %d IsConstLit (%a)', sym, n)
4672 ELSIF IsDummy(sym)
4673 THEN
4674 fprintf2 (GetDumpFile (), 'sym %d IsDummy (%a)', sym, n)
4675 ELSIF IsTemporary(sym)
4676 THEN
4677 fprintf2 (GetDumpFile (), 'sym %d IsTemporary (%a)', sym, n)
4678 ELSIF IsVarAParam(sym)
4679 THEN
4680 fprintf2 (GetDumpFile (), 'sym %d IsVarAParam (%a)', sym, n)
4681 ELSIF IsSubscript(sym)
4682 THEN
4683 fprintf2 (GetDumpFile (), 'sym %d IsSubscript (%a)', sym, n)
4684 ELSIF IsSubrange(sym)
4685 THEN
4686 fprintf2 (GetDumpFile (), 'sym %d IsSubrange (%a)', sym, n)
4687 ELSIF IsProcedureVariable(sym)
4688 THEN
4689 fprintf2 (GetDumpFile (), 'sym %d IsProcedureVariable (%a)', sym, n)
4690 ELSIF IsProcedureNested(sym)
4691 THEN
4692 fprintf2 (GetDumpFile (), 'sym %d IsProcedureNested (%a)', sym, n)
4693 ELSIF IsAModula2Type(sym)
4694 THEN
4695 fprintf2 (GetDumpFile (), 'sym %d IsAModula2Type (%a)', sym, n)
4696 ELSIF IsGnuAsm(sym)
4697 THEN
4698 fprintf2 (GetDumpFile (), 'sym %d IsGnuAsm (%a)', sym, n)
4699 ELSIF IsImport (sym)
4700 THEN
4701 fprintf1 (GetDumpFile(), 'sym %d IsImport', sym)
4702 ELSIF IsImportStatement (sym)
4703 THEN
4704 fprintf1 (GetDumpFile(), 'sym %d IsImportStatement', sym)
4705 END ;
4706
4707 IF IsHiddenType(sym)
4708 THEN
4709 fprintf0 (GetDumpFile(), ' IsHiddenType')
4710 END
4711 END PrintTerse ;
4712
4713
4714 (*
4715 CheckAlignment -
4716 *)
4717
4718 PROCEDURE CheckAlignment (type: tree; sym: CARDINAL) : tree ;
4719 VAR
4720 align: CARDINAL ;
4721 BEGIN
4722 align := GetAlignment(sym) ;
4723 IF align#NulSym
4724 THEN
4725 PushInt(0) ;
4726 PushValue(align) ;
4727 IF NOT Equ(GetDeclaredMod(sym))
4728 THEN
4729 RETURN( SetAlignment(type, Mod2Gcc(GetAlignment(sym))) )
4730 END
4731 END ;
4732 RETURN( type )
4733 END CheckAlignment ;
4734
4735
4736 (*
4737 CheckPragma -
4738 *)
4739
4740 PROCEDURE CheckPragma (type: tree; sym: CARDINAL) : tree ;
4741 BEGIN
4742 IF IsDeclaredPacked (sym)
4743 THEN
4744 IF IsRecordField (sym) OR IsFieldVarient (sym)
4745 THEN
4746 type := SetDeclPacked (type)
4747 ELSIF IsRecord (sym) OR IsVarient (sym)
4748 THEN
4749 type := SetTypePacked (type)
4750 END
4751 END ;
4752 RETURN CheckAlignment (type, sym)
4753 END CheckPragma ;
4754
4755
4756 (*
4757 IsZero - returns TRUE if symbol, sym, is zero.
4758 *)
4759
4760 PROCEDURE IsZero (sym: CARDINAL) : BOOLEAN ;
4761 BEGIN
4762 PushIntegerTree(Mod2Gcc(sym)) ;
4763 PushInt(0) ;
4764 RETURN( Equ(GetDeclaredMod(sym)) )
4765 END IsZero ;
4766
4767
4768 (*
4769 SetFieldPacked - sets Varient, VarientField and RecordField symbols
4770 as packed.
4771 *)
4772
4773 PROCEDURE SetFieldPacked (field: CARDINAL) ;
4774 BEGIN
4775 IF IsVarient(field) OR IsFieldVarient(field) OR IsRecordField(field)
4776 THEN
4777 PutDeclaredPacked(field, TRUE)
4778 END
4779 END SetFieldPacked ;
4780
4781
4782 (*
4783 RecordPacked - indicates that record, sym, and its fields
4784 are all packed.
4785 *)
4786
4787 PROCEDURE RecordPacked (sym: CARDINAL) ;
4788 BEGIN
4789 PutDeclaredPacked(sym, TRUE) ;
4790 WalkRecordDependants(sym, SetFieldPacked)
4791 END RecordPacked ;
4792
4793
4794 (*
4795 SetFieldNotPacked - sets Varient, VarientField and RecordField symbols
4796 as not packed.
4797 *)
4798
4799 PROCEDURE SetFieldNotPacked (field: CARDINAL) ;
4800 BEGIN
4801 IF IsVarient(field) OR IsFieldVarient(field) OR IsRecordField(field)
4802 THEN
4803 PutDeclaredPacked(field, FALSE)
4804 END
4805 END SetFieldNotPacked ;
4806
4807
4808 (*
4809 RecordNotPacked - indicates that record, sym, and its fields
4810 are all not packed.
4811 *)
4812
4813 PROCEDURE RecordNotPacked (sym: CARDINAL) ;
4814 BEGIN
4815 PutDeclaredPacked(sym, FALSE) ;
4816 WalkRecordDependants(sym, SetFieldNotPacked)
4817 END RecordNotPacked ;
4818
4819
4820 (*
4821 DetermineIfRecordPacked -
4822 *)
4823
4824 PROCEDURE DetermineIfRecordPacked (sym: CARDINAL) ;
4825 VAR
4826 defaultAlignment: CARDINAL ;
4827 BEGIN
4828 defaultAlignment := GetDefaultRecordFieldAlignment(sym) ;
4829 IF (defaultAlignment#NulSym) AND IsZero(defaultAlignment)
4830 THEN
4831 RecordPacked(sym)
4832 ELSE
4833 RecordNotPacked(sym)
4834 END
4835 END DetermineIfRecordPacked ;
4836
4837
4838 (*
4839 DeclarePackedSubrange -
4840 *)
4841
4842 PROCEDURE DeclarePackedSubrange (equiv, sym: CARDINAL) ;
4843 VAR
4844 type,
4845 gccsym : tree ;
4846 high, low: CARDINAL ;
4847 location : location_t ;
4848 BEGIN
4849 location := TokenToLocation(GetDeclaredMod(sym)) ;
4850 GetSubrange(sym, high, low) ;
4851 type := BuildSmallestTypeRange(location, Mod2Gcc(low), Mod2Gcc(high)) ;
4852 gccsym := BuildSubrangeType(location, KeyToCharStar(GetFullSymName(sym)),
4853 type, Mod2Gcc(low), Mod2Gcc(high)) ;
4854 AddModGcc(equiv, gccsym)
4855 END DeclarePackedSubrange ;
4856
4857
4858 (*
4859 DeclarePackedSet -
4860 *)
4861
4862 PROCEDURE DeclarePackedSet (equiv, sym: CARDINAL) ;
4863 VAR
4864 highLimit,
4865 range,
4866 gccsym : tree ;
4867 type,
4868 high, low: CARDINAL ;
4869 location: location_t ;
4870 BEGIN
4871 location := TokenToLocation(GetDeclaredMod(sym)) ;
4872 Assert(IsSet(sym)) ;
4873 type := GetDType(sym) ;
4874 low := GetTypeMin(type) ;
4875 high := GetTypeMax(type) ;
4876 highLimit := BuildSub(location, Mod2Gcc(high), Mod2Gcc(low), FALSE) ;
4877 (* --fixme-- we need to check that low <= WORDLENGTH. *)
4878 highLimit := BuildLSL(location, GetIntegerOne(location), highLimit, FALSE) ;
4879 range := BuildSmallestTypeRange(location, GetIntegerZero(location), highLimit) ;
4880 gccsym := BuildSubrangeType(location, KeyToCharStar(GetFullSymName(sym)),
4881 range, GetIntegerZero(location), highLimit) ;
4882 AddModGcc(equiv, gccsym)
4883 END DeclarePackedSet ;
4884
4885
4886 (*
4887 DeclareFieldEnumeration - declares an enumerator within the current enumeration type.
4888 *)
4889
4890 PROCEDURE DeclarePackedFieldEnumeration (sym: WORD) ;
4891 VAR
4892 equiv,
4893 type : CARDINAL ;
4894 field,
4895 enumlist: tree ;
4896 BEGIN
4897 (* add relationship between gccSym and sym *)
4898 type := GetSType (sym) ;
4899 equiv := GetPackedEquivalent (type) ;
4900 enumlist := GetEnumList (equiv) ;
4901 PushValue (sym) ;
4902 field := DeclareFieldValue (sym, PopIntegerTree(), enumlist) ;
4903 Assert (field # NIL) ;
4904 PutEnumList (equiv, enumlist)
4905 END DeclarePackedFieldEnumeration ;
4906
4907
4908 (*
4909 DeclarePackedEnumeration -
4910 *)
4911
4912 PROCEDURE DeclarePackedEnumeration (equiv, sym: CARDINAL) ;
4913 VAR
4914 enumlist,
4915 gccenum : tree ;
4916 location: location_t ;
4917 BEGIN
4918 location := TokenToLocation(GetDeclaredMod(sym)) ;
4919 gccenum := BuildStartEnumeration(location, KeyToCharStar(GetFullSymName(sym)), TRUE) ;
4920 ForeachLocalSymDo(sym, DeclarePackedFieldEnumeration) ;
4921 enumlist := GetEnumList(equiv) ;
4922 gccenum := BuildEndEnumeration(location, gccenum, enumlist) ;
4923 AddModGcc(equiv, gccenum)
4924 END DeclarePackedEnumeration ;
4925
4926
4927 (*
4928 DeclarePackedType -
4929 *)
4930
4931 PROCEDURE DeclarePackedType (equiv, sym: CARDINAL) ;
4932 VAR
4933 type: CARDINAL ;
4934 BEGIN
4935 type := GetSType(sym) ;
4936 IF type=NulSym
4937 THEN
4938 IF sym=Boolean
4939 THEN
4940 AddModGcc(equiv, GetPackedBooleanType())
4941 ELSE
4942 AddModGcc(equiv, Mod2Gcc(sym))
4943 END
4944 ELSE
4945 DeclarePackedType(GetPackedEquivalent(type), type) ;
4946 AddModGcc(equiv, Mod2Gcc(GetPackedEquivalent(type)))
4947 END
4948 END DeclarePackedType ;
4949
4950
4951 (*
4952 doDeclareEquivalent -
4953 *)
4954
4955 PROCEDURE doDeclareEquivalent (sym: CARDINAL; p: doDeclareProcedure) : tree ;
4956 VAR
4957 equiv: CARDINAL ;
4958 BEGIN
4959 equiv := GetPackedEquivalent(sym) ;
4960 IF NOT GccKnowsAbout(equiv)
4961 THEN
4962 p(equiv, sym) ;
4963 IncludeElementIntoSet(GlobalGroup^.FullyDeclared, equiv)
4964 END ;
4965 RETURN( Mod2Gcc(equiv) )
4966 END doDeclareEquivalent ;
4967
4968
4969 (*
4970 PossiblyPacked -
4971 *)
4972
4973 PROCEDURE PossiblyPacked (sym: CARDINAL; isPacked: BOOLEAN) : tree ;
4974 BEGIN
4975 IF isPacked
4976 THEN
4977 IF IsSubrange(sym)
4978 THEN
4979 RETURN( doDeclareEquivalent(sym, DeclarePackedSubrange) )
4980 ELSIF IsType(sym)
4981 THEN
4982 RETURN( doDeclareEquivalent(sym, DeclarePackedType) )
4983 ELSIF IsEnumeration(sym)
4984 THEN
4985 RETURN( doDeclareEquivalent(sym, DeclarePackedEnumeration) )
4986 ELSIF IsSet(sym)
4987 THEN
4988 RETURN( doDeclareEquivalent(sym, DeclarePackedSet) )
4989 END
4990 END ;
4991 RETURN( Mod2Gcc(sym) )
4992 END PossiblyPacked ;
4993
4994
4995 (*
4996 GetPackedType - returns a possibly packed type for field.
4997 *)
4998
4999 PROCEDURE GetPackedType (sym: CARDINAL) : tree ;
5000 BEGIN
5001 IF IsSubrange(sym)
5002 THEN
5003 RETURN( doDeclareEquivalent(sym, DeclarePackedSubrange) )
5004 ELSIF IsType(sym)
5005 THEN
5006 RETURN( doDeclareEquivalent(sym, DeclarePackedType) )
5007 ELSIF IsEnumeration(sym)
5008 THEN
5009 RETURN( doDeclareEquivalent(sym, DeclarePackedEnumeration) )
5010 END ;
5011 RETURN( Mod2Gcc(sym) )
5012 END GetPackedType ;
5013
5014
5015 (*
5016 MaybeAlignField - checks to see whether, field, is packed or aligned and it updates
5017 the offsets if appropriate.
5018 *)
5019
5020 PROCEDURE MaybeAlignField (field: CARDINAL; VAR byteOffset, bitOffset: tree) : tree ;
5021 VAR
5022 f, ftype,
5023 nbits : tree ;
5024 location: location_t ;
5025 BEGIN
5026 f := Mod2Gcc(field) ;
5027 IF IsDeclaredPacked(field)
5028 THEN
5029 location := TokenToLocation(GetDeclaredMod(field)) ;
5030 f := SetDeclPacked(f) ;
5031 ftype := GetPackedType(GetSType(field)) ;
5032 nbits := BuildTBitSize(location, ftype) ;
5033 f := SetRecordFieldOffset(f, byteOffset, bitOffset, ftype, nbits) ;
5034 bitOffset := BuildAdd(location, bitOffset, nbits, FALSE) ;
5035 RETURN( f )
5036 ELSE
5037 RETURN( CheckAlignment(f, field) )
5038 END
5039 END MaybeAlignField ;
5040
5041
5042 (*
5043 DeclareRecord - declares a record and its fields to gcc.
5044 The final gcc record type is returned.
5045 *)
5046
5047 PROCEDURE DeclareRecord (Sym: CARDINAL) : tree ;
5048 VAR
5049 Field : CARDINAL ;
5050 i : CARDINAL ;
5051 nbits,
5052 ftype,
5053 field,
5054 byteOffset,
5055 bitOffset,
5056 FieldList,
5057 RecordType: tree ;
5058 location : location_t ;
5059 BEGIN
5060 i := 1 ;
5061 FieldList := tree(NIL) ;
5062 RecordType := DoStartDeclaration(Sym, BuildStartRecord) ;
5063 location := TokenToLocation(GetDeclaredMod(Sym)) ;
5064 byteOffset := GetIntegerZero(location) ;
5065 bitOffset := GetIntegerZero(location) ;
5066 REPEAT
5067 Field := GetNth(Sym, i) ;
5068 IF Field#NulSym
5069 THEN
5070 IF IsRecordField(Field) AND IsRecordFieldAVarientTag(Field) AND (GetSymName(Field)=NulName)
5071 THEN
5072 (* do not include a nameless tag into the C struct *)
5073 ELSIF IsVarient(Field)
5074 THEN
5075 Field := Chained(Field) ;
5076 field := Mod2Gcc(Field) ;
5077 IF IsDeclaredPacked(Field)
5078 THEN
5079 location := TokenToLocation(GetDeclaredMod(Field)) ;
5080 field := SetDeclPacked(field) ;
5081 ftype := GetPackedType(GetSType(Field)) ;
5082 nbits := BuildTBitSize(location, ftype) ;
5083 field := SetRecordFieldOffset(field, byteOffset, bitOffset, ftype, nbits) ;
5084 bitOffset := BuildAdd(location, bitOffset, nbits, FALSE) ;
5085 byteOffset := BuildAdd(location, byteOffset,
5086 BuildDivTrunc(location, bitOffset, BuildIntegerConstant(8), FALSE),
5087 FALSE) ;
5088 bitOffset := BuildModTrunc(location, bitOffset, BuildIntegerConstant(8), FALSE)
5089 END ;
5090 FieldList := ChainOn(FieldList, field)
5091 ELSE
5092 IF Debugging
5093 THEN
5094 printf0('chaining ') ; PrintTerse(Field) ; printf0('\n')
5095 END ;
5096 FieldList := ChainOn(FieldList, MaybeAlignField(Chained(Field), byteOffset, bitOffset))
5097 END
5098 END ;
5099 INC(i)
5100 UNTIL Field=NulSym ;
5101 WatchRemoveList(Sym, partiallydeclared) ;
5102 WatchRemoveList(Sym, heldbyalignment) ;
5103 WatchRemoveList(Sym, finishedalignment) ;
5104 location := TokenToLocation(GetDeclaredMod(Sym)) ;
5105 RETURN( BuildEndRecord(location, RecordType, FieldList, IsDeclaredPacked(Sym)) )
5106 END DeclareRecord ;
5107
5108
5109 (*
5110 DeclareRecordField -
5111 *)
5112
5113 PROCEDURE DeclareRecordField (sym: CARDINAL) : tree ;
5114 VAR
5115 field,
5116 GccFieldType: tree ;
5117 location : location_t ;
5118 BEGIN
5119 location := TokenToLocation(GetDeclaredMod(sym)) ;
5120 GccFieldType := PossiblyPacked(GetSType(sym), IsDeclaredPacked(sym)) ;
5121 field := BuildFieldRecord(location, KeyToCharStar(GetFullSymName(sym)), GccFieldType) ;
5122 RETURN( field )
5123 END DeclareRecordField ;
5124
5125
5126 (*
5127 DeclareVarient - declares a record and its fields to gcc.
5128 The final gcc record type is returned.
5129 *)
5130
5131 PROCEDURE DeclareVarient (sym: CARDINAL) : tree ;
5132 VAR
5133 Field : CARDINAL ;
5134 i : CARDINAL ;
5135 byteOffset,
5136 bitOffset,
5137 FieldList,
5138 VarientType : tree ;
5139 location : location_t ;
5140 BEGIN
5141 i := 1 ;
5142 FieldList := tree(NIL) ;
5143 VarientType := DoStartDeclaration(sym, BuildStartVarient) ;
5144 location := TokenToLocation(GetDeclaredMod(sym)) ;
5145 byteOffset := GetIntegerZero(location) ;
5146 bitOffset := GetIntegerZero(location) ;
5147 WHILE GetNth(sym, i)#NulSym DO
5148 Field := GetNth(sym, i) ;
5149 IF IsRecordField(Field) AND IsRecordFieldAVarientTag(Field) AND (GetSymName(Field)=NulName)
5150 THEN
5151 (* do not include a nameless tag into the C struct *)
5152 ELSE
5153 IF Debugging
5154 THEN
5155 printf0('chaining ') ; PrintTerse(Field) ; printf0('\n')
5156 END ;
5157 FieldList := ChainOn(FieldList, MaybeAlignField(Chained(Field), byteOffset, bitOffset))
5158 END ;
5159 INC(i)
5160 END ;
5161 WatchRemoveList(sym, partiallydeclared) ;
5162 WatchRemoveList(sym, heldbyalignment) ;
5163 WatchRemoveList(sym, finishedalignment) ;
5164 VarientType := BuildEndVarient(location, VarientType, FieldList, IsDeclaredPacked(sym)) ;
5165 RETURN( VarientType )
5166 END DeclareVarient ;
5167
5168
5169 (*
5170 DeclareFieldVarient -
5171 *)
5172
5173 PROCEDURE DeclareFieldVarient (sym: CARDINAL) : tree ;
5174 VAR
5175 i, f : CARDINAL ;
5176 VarientList,
5177 VarientType,
5178 byteOffset,
5179 bitOffset,
5180 GccFieldType: tree ;
5181 location : location_t ;
5182 BEGIN
5183 location := TokenToLocation(GetDeclaredMod(sym)) ;
5184 i := 1 ;
5185 VarientList := tree(NIL) ;
5186 VarientType := DoStartDeclaration(sym, BuildStartFieldVarient) ;
5187 (* no need to store the [sym, RecordType] tuple as it is stored by DeclareRecord which calls us *)
5188 byteOffset := GetIntegerZero(location) ;
5189 bitOffset := GetIntegerZero(location) ;
5190 WHILE GetNth(sym, i)#NulSym DO
5191 f := GetNth(sym, i) ;
5192 IF IsFieldVarient(f) AND IsEmptyFieldVarient(f)
5193 THEN
5194 (* do not include empty varient fields (created via 'else end' in variant records *)
5195 ELSE
5196 IF Debugging
5197 THEN
5198 printf0('chaining ') ; PrintTerse(f) ; printf0('\n')
5199 END ;
5200 VarientList := ChainOn(VarientList, MaybeAlignField(Chained(f), byteOffset, bitOffset))
5201 END ;
5202 INC(i)
5203 END ;
5204 WatchRemoveList(sym, partiallydeclared) ;
5205 GccFieldType := BuildEndFieldVarient(location, VarientType, VarientList, IsDeclaredPacked(sym)) ;
5206 RETURN( GccFieldType )
5207 END DeclareFieldVarient ;
5208
5209
5210 (*
5211 DeclarePointer - declares a pointer type to gcc and returns the Tree.
5212 *)
5213
5214 PROCEDURE DeclarePointer (sym: CARDINAL) : tree ;
5215 BEGIN
5216 RETURN( BuildPointerType(Mod2Gcc(GetSType(sym))) )
5217 END DeclarePointer ;
5218
5219
5220 (*
5221 DeclareUnbounded - builds an unbounded type and returns the gcc tree.
5222 *)
5223
5224 PROCEDURE DeclareUnbounded (sym: CARDINAL) : tree ;
5225 VAR
5226 record: CARDINAL ;
5227 BEGIN
5228 Assert(IsUnbounded(sym)) ;
5229 IF GccKnowsAbout(sym)
5230 THEN
5231 RETURN( Mod2Gcc(sym) )
5232 ELSE
5233 record := GetUnboundedRecordType(sym) ;
5234 Assert(IsRecord(record)) ;
5235 Assert(AllDependantsFullyDeclared(record)) ;
5236 IF (NOT GccKnowsAbout(record))
5237 THEN
5238 DeclareTypeConstFully(record) ;
5239 WatchRemoveList(record, todolist)
5240 END ;
5241 RETURN( Mod2Gcc(record) )
5242 END
5243 END DeclareUnbounded ;
5244
5245
5246 (*
5247 BuildIndex -
5248 *)
5249
5250 PROCEDURE BuildIndex (tokenno: CARDINAL; array: CARDINAL) : tree ;
5251 VAR
5252 Subscript: CARDINAL ;
5253 Type,
5254 High, Low: CARDINAL ;
5255 n,
5256 low, high: tree ;
5257 location : location_t ;
5258 BEGIN
5259 location := TokenToLocation(tokenno) ;
5260 Subscript := GetArraySubscript (array) ;
5261 Assert (IsSubscript (Subscript)) ;
5262 Type := GetDType (Subscript) ;
5263 Low := GetTypeMin (Type) ;
5264 High := GetTypeMax (Type) ;
5265 DeclareConstant (tokenno, Low) ;
5266 DeclareConstant (tokenno, High) ;
5267 low := Mod2Gcc (Low) ;
5268 high := Mod2Gcc (High) ;
5269 IF ExceedsTypeRange (GetIntegerType (), low, high)
5270 THEN
5271 location := TokenToLocation (tokenno) ;
5272 n := BuildConvert (location, GetIntegerType (), BuildSub (location, high, low, FALSE), FALSE) ;
5273 IF TreeOverflow(n) OR ValueOutOfTypeRange (GetIntegerType (), n)
5274 THEN
5275 MetaError3('implementation restriction, array is too large {%1EDM}, the range {%2ad}..{%3ad} exceeds the integer range',
5276 array, Low, High) ;
5277 RETURN BuildArrayIndexType (GetIntegerZero (location), GetIntegerZero (location))
5278 ELSE
5279 PutArrayLarge (array) ;
5280 RETURN BuildArrayIndexType (GetIntegerZero (location), n)
5281 END
5282 ELSE
5283 low := BuildConvert (location, GetIntegerType (), low, FALSE) ;
5284 high := BuildConvert (location, GetIntegerType (), high, FALSE) ;
5285 RETURN BuildArrayIndexType (low, high)
5286 END
5287 END BuildIndex ;
5288
5289
5290 (*
5291 DeclareArray - declares an array to gcc and returns the gcc tree.
5292 *)
5293
5294 PROCEDURE DeclareArray (Sym: CARDINAL) : tree ;
5295 VAR
5296 typeOfArray: CARDINAL ;
5297 ArrayType,
5298 GccArray,
5299 GccIndex : tree ;
5300 Subscript : CARDINAL ;
5301 tokenno : CARDINAL ;
5302 location : location_t ;
5303 BEGIN
5304 Assert(IsArray(Sym)) ;
5305
5306 tokenno := GetDeclaredMod(Sym) ;
5307 location := TokenToLocation(tokenno) ;
5308
5309 Subscript := GetArraySubscript(Sym) ;
5310 typeOfArray := GetDType(Sym) ;
5311 GccArray := Mod2Gcc(typeOfArray) ;
5312 GccIndex := BuildIndex(tokenno, Sym) ;
5313
5314 IF GccKnowsAbout(Sym)
5315 THEN
5316 ArrayType := Mod2Gcc(Sym)
5317 ELSE
5318 ArrayType := BuildStartArrayType(GccIndex, GccArray, typeOfArray) ;
5319 PreAddModGcc(Sym, ArrayType)
5320 END ;
5321
5322 PreAddModGcc(Subscript, GccArray) ; (* we save the type of this array as the subscript *)
5323 PushIntegerTree(BuildSize(location, GccArray, FALSE)) ; (* and the size of this array so far *)
5324 PopSize(Subscript) ;
5325
5326 GccArray := BuildEndArrayType(ArrayType, GccArray, GccIndex, typeOfArray) ;
5327 Assert(GccArray=ArrayType) ;
5328
5329 RETURN( GccArray )
5330 END DeclareArray ;
5331
5332
5333 (*
5334 DeclareProcType - declares a procedure type to gcc and returns the gcc type tree.
5335 *)
5336
5337 PROCEDURE DeclareProcType (Sym: CARDINAL) : tree ;
5338 VAR
5339 i, p,
5340 Parameter,
5341 ReturnType: CARDINAL ;
5342 func,
5343 GccParam : tree ;
5344 location : location_t ;
5345 BEGIN
5346 ReturnType := GetSType(Sym) ;
5347 func := DoStartDeclaration(Sym, BuildStartFunctionType) ;
5348 InitFunctionTypeParameters ;
5349 p := NoOfParamAny (Sym) ;
5350 i := p ;
5351 WHILE i > 0 DO
5352 Parameter := GetNthParamAny (Sym, i) ;
5353 location := TokenToLocation (GetDeclaredMod (Parameter)) ;
5354 GccParam := BuildProcTypeParameterDeclaration (location, Mod2Gcc (GetSType (Parameter)), IsVarParamAny (Sym, i)) ;
5355 PreAddModGcc(Parameter, GccParam) ;
5356 DEC(i)
5357 END ;
5358 IF ReturnType = NulSym
5359 THEN
5360 RETURN( BuildEndFunctionType (func, NIL, UsesVarArgs(Sym)) )
5361 ELSE
5362 RETURN( BuildEndFunctionType (func, Mod2Gcc(ReturnType), UsesVarArgs(Sym)) )
5363 END
5364 END DeclareProcType ;
5365
5366
5367 VAR
5368 MaxEnumerationField,
5369 MinEnumerationField: CARDINAL ;
5370
5371
5372 (*
5373 FindMinMaxEnum - finds the minimum and maximum enumeration fields.
5374 *)
5375
5376 PROCEDURE FindMinMaxEnum (field: WORD) ;
5377 BEGIN
5378 IF MaxEnumerationField=NulSym
5379 THEN
5380 MaxEnumerationField := field
5381 ELSE
5382 PushValue(field) ;
5383 PushValue(MaxEnumerationField) ;
5384 IF Gre(GetDeclaredMod(field))
5385 THEN
5386 MaxEnumerationField := field
5387 END
5388 END ;
5389 IF MinEnumerationField=NulSym
5390 THEN
5391 MinEnumerationField := field
5392 ELSE
5393 PushValue(field) ;
5394 PushValue(MinEnumerationField) ;
5395 IF Less(GetDeclaredMod(field))
5396 THEN
5397 MinEnumerationField := field
5398 END
5399 END
5400 END FindMinMaxEnum ;
5401
5402
5403 (*
5404 GetTypeMin -
5405 *)
5406
5407 PROCEDURE GetTypeMin (type: CARDINAL) : CARDINAL ;
5408 VAR
5409 min, max: CARDINAL ;
5410 BEGIN
5411 IF IsSubrange(type)
5412 THEN
5413 GetSubrange(type, max, min) ;
5414 RETURN( min )
5415 ELSIF IsSet(type)
5416 THEN
5417 RETURN( GetTypeMin(GetSType(type)) )
5418 ELSIF IsEnumeration(type)
5419 THEN
5420 MinEnumerationField := NulSym ;
5421 MaxEnumerationField := NulSym ;
5422 ForeachLocalSymDo (type, FindMinMaxEnum) ;
5423 RETURN( MinEnumerationField )
5424 ELSIF IsBaseType(type)
5425 THEN
5426 GetBaseTypeMinMax(type, min, max) ;
5427 RETURN( min )
5428 ELSIF IsSystemType(type)
5429 THEN
5430 GetSystemTypeMinMax(type, min, max) ;
5431 RETURN( min )
5432 ELSIF GetSType(type)=NulSym
5433 THEN
5434 MetaError1('unable to obtain the MIN value for type {%1as}', type) ;
5435 RETURN NulSym
5436 ELSE
5437 RETURN( GetTypeMin(GetSType(type)) )
5438 END
5439 END GetTypeMin ;
5440
5441
5442 (*
5443 GetTypeMax -
5444 *)
5445
5446 PROCEDURE GetTypeMax (type: CARDINAL) : CARDINAL ;
5447 VAR
5448 min, max: CARDINAL ;
5449 BEGIN
5450 IF IsSubrange(type)
5451 THEN
5452 GetSubrange(type, max, min) ;
5453 RETURN( max )
5454 ELSIF IsSet(type)
5455 THEN
5456 RETURN( GetTypeMax(GetSType(type)) )
5457 ELSIF IsEnumeration(type)
5458 THEN
5459 MinEnumerationField := NulSym ;
5460 MaxEnumerationField := NulSym ;
5461 ForeachLocalSymDo (type, FindMinMaxEnum) ;
5462 RETURN( MaxEnumerationField )
5463 ELSIF IsBaseType(type)
5464 THEN
5465 GetBaseTypeMinMax(type, min, max) ;
5466 RETURN( max )
5467 ELSIF IsSystemType(type)
5468 THEN
5469 GetSystemTypeMinMax(type, min, max) ;
5470 RETURN( max )
5471 ELSIF GetSType(type)=NulSym
5472 THEN
5473 MetaError1('unable to obtain the MAX value for type {%1as}', type) ;
5474 RETURN NulSym
5475 ELSE
5476 RETURN( GetTypeMax(GetSType(type)) )
5477 END
5478 END GetTypeMax ;
5479
5480
5481 (*
5482 PushNoOfBits - pushes the integer value of the number of bits required
5483 to maintain a set of type.
5484 *)
5485
5486 PROCEDURE PushNoOfBits (type: CARDINAL; low, high: CARDINAL) ;
5487 BEGIN
5488 PushValue(high) ;
5489 ConvertToType(type) ;
5490 PushValue(low) ;
5491 ConvertToType(type) ;
5492 Sub ;
5493 ConvertToType(Cardinal)
5494 END PushNoOfBits ;
5495
5496
5497 (*
5498 DeclareLargeSet - n is the name of the set.
5499 type is the subrange type (or simple type)
5500 low and high are the limits of the subrange.
5501 *)
5502
5503 PROCEDURE DeclareLargeSet (n: Name; type: CARDINAL; low, high: CARDINAL) : tree ;
5504 VAR
5505 lowtree,
5506 hightree,
5507 BitsInSet,
5508 RecordType,
5509 GccField,
5510 FieldList : tree ;
5511 bpw : CARDINAL ;
5512 location : location_t ;
5513 BEGIN
5514 location := TokenToLocation(GetDeclaredMod(type)) ;
5515 bpw := GetBitsPerBitset() ;
5516 PushValue(low) ;
5517 lowtree := PopIntegerTree() ;
5518 PushValue(high) ;
5519 hightree := PopIntegerTree() ;
5520 FieldList := tree(NIL) ;
5521 RecordType := BuildStartRecord(location, KeyToCharStar(n)) ; (* no problem with recursive types here *)
5522 PushNoOfBits(type, low, high) ;
5523 PushCard(1) ;
5524 Addn ;
5525 BitsInSet := PopIntegerTree() ;
5526 PushIntegerTree(BitsInSet) ;
5527 PushCard(0) ;
5528 WHILE Gre(GetDeclaredMod(type)) DO
5529 PushIntegerTree(BitsInSet) ;
5530 PushCard(bpw-1) ;
5531 IF GreEqu(GetDeclaredMod(type))
5532 THEN
5533 PushIntegerTree(lowtree) ;
5534 PushCard(bpw-1) ;
5535 Addn ;
5536 GccField := BuildFieldRecord(location, NIL, BuildSetType(location, NIL, Mod2Gcc(type), lowtree, PopIntegerTree(), FALSE)) ;
5537 PushIntegerTree(lowtree) ;
5538 PushCard(bpw) ;
5539 Addn ;
5540 lowtree := PopIntegerTree() ;
5541 PushIntegerTree(BitsInSet) ;
5542 PushCard(bpw) ;
5543 Sub ;
5544 BitsInSet := PopIntegerTree()
5545 ELSE
5546 (* printf2('range is %a..%a\n', GetSymName(low), GetSymName(high)) ; *)
5547 GccField := BuildFieldRecord(location, NIL, BuildSetType(location, NIL, Mod2Gcc(type), lowtree, hightree, FALSE)) ;
5548 PushCard(0) ;
5549 BitsInSet := PopIntegerTree()
5550 END ;
5551 FieldList := ChainOn(FieldList, GccField) ;
5552 PushIntegerTree(BitsInSet) ;
5553 PushCard(0)
5554 END ;
5555 RETURN( BuildEndRecord(location, RecordType, FieldList, FALSE) )
5556 END DeclareLargeSet ;
5557
5558
5559 (*
5560 DeclareLargeOrSmallSet - works out whether the set will exceed TSIZE(WORD). If it does
5561 we manufacture a set using:
5562
5563 settype = RECORD
5564 w1: SET OF [...]
5565 w2: SET OF [...]
5566 END
5567
5568 We do this as GCC and GDB (stabs) only knows about WORD sized sets.
5569 If the set will fit into a WORD then we call gccgm2 directly.
5570 *)
5571
5572 PROCEDURE DeclareLargeOrSmallSet (sym: CARDINAL;
5573 n: Name; type: CARDINAL; low, high: CARDINAL) : tree ;
5574 VAR
5575 location: location_t ;
5576 packed : BOOLEAN ;
5577 BEGIN
5578 PushNoOfBits(type, low, high) ;
5579 PushCard(GetBitsPerBitset()) ;
5580 packed := IsSetPacked (sym) ;
5581 IF Less(GetDeclaredMod(type))
5582 THEN
5583 location := TokenToLocation(GetDeclaredMod(sym)) ;
5584 (* small set *)
5585 (* PutSetSmall(sym) ; *)
5586 RETURN BuildSetType (location, KeyToCharStar(n),
5587 Mod2Gcc(type), Mod2Gcc(low), Mod2Gcc(high), packed)
5588 ELSE
5589 (* PutSetLarge(sym) ; *)
5590 RETURN DeclareLargeSet (n, type, low, high) (* --fixme-- finish packed here as well. *)
5591 END
5592 END DeclareLargeOrSmallSet ;
5593
5594
5595 (*
5596 DeclareSet - declares a set type to gcc and returns a Tree.
5597 *)
5598
5599 PROCEDURE DeclareSet (sym: CARDINAL) : tree ;
5600 VAR
5601 gccsym : tree ;
5602 type,
5603 high, low: CARDINAL ;
5604 BEGIN
5605 type := GetDType(sym) ;
5606 IF IsSubrange(type)
5607 THEN
5608 GetSubrange(type, high, low) ;
5609 gccsym := DeclareLargeOrSmallSet(sym, GetFullSymName(sym), GetSType(type), low, high)
5610 ELSE
5611 gccsym := DeclareLargeOrSmallSet(sym, GetFullSymName(sym), type, GetTypeMin(type), GetTypeMax(type))
5612 END ;
5613 RETURN( gccsym )
5614 END DeclareSet ;
5615
5616
5617 (*
5618 CheckResolveSubrange - checks to see whether we can determine
5619 the subrange type. We are able to do
5620 this once low, high and the type are known.
5621 *)
5622
5623 PROCEDURE CheckResolveSubrange (sym: CARDINAL) ;
5624 VAR
5625 tokenno : CARDINAL;
5626 size, high, low, type: CARDINAL ;
5627 BEGIN
5628 GetSubrange(sym, high, low) ;
5629 tokenno := GetDeclaredMod (sym) ;
5630 type := GetSType(sym) ;
5631 IF type=NulSym
5632 THEN
5633 IF GccKnowsAbout(low) AND GccKnowsAbout(high)
5634 THEN
5635 IF IsConstString (low) AND IsConstStringKnown (low)
5636 THEN
5637 size := GetStringLength (tokenno, low) ;
5638 IF size <= 1
5639 THEN
5640 PutSubrange(sym, low, high, Char)
5641 ELSE
5642 MetaError1 ('cannot have a subrange of a string type {%1Uad}',
5643 sym)
5644 END
5645 ELSIF IsFieldEnumeration(low)
5646 THEN
5647 IF GetSType(low)=GetSType(high)
5648 THEN
5649 PutSubrange(sym, low, high, GetSType(low))
5650 ELSE
5651 MetaError1('subrange limits must be of the same type {%1Uad}', sym)
5652 END
5653 ELSIF IsValueSolved(low)
5654 THEN
5655 IF GetSType(low)=LongReal
5656 THEN
5657 MetaError1('cannot have a subrange of a SHORTREAL, REAL or LONGREAL type {%1Uad}', sym)
5658 ELSE
5659 PutSubrange(sym, low, high, MixTypes(GetSType(low), GetSType(high), GetDeclaredMod(sym)))
5660 END
5661 END
5662 END
5663 END
5664 END CheckResolveSubrange ;
5665
5666
5667 (*
5668 TypeConstFullyDeclared - all, sym, dependents are declared, so create and
5669 return the GCC Tree equivalent.
5670 *)
5671
5672 PROCEDURE TypeConstFullyDeclared (sym: CARDINAL) : tree ;
5673 VAR
5674 t: tree ;
5675 BEGIN
5676 IF IsEnumeration(sym)
5677 THEN
5678 t := DeclareEnumeration(sym)
5679 ELSIF IsFieldEnumeration(sym)
5680 THEN
5681 t := DeclareFieldEnumeration(sym)
5682 ELSIF IsSubrange(sym)
5683 THEN
5684 t := DeclareSubrange(sym)
5685 ELSIF IsRecord(sym)
5686 THEN
5687 t := CheckPragma(DeclareRecord(sym), sym)
5688 ELSIF IsRecordField(sym)
5689 THEN
5690 t := CheckPragma(DeclareRecordField(sym), sym)
5691 ELSIF IsFieldVarient(sym)
5692 THEN
5693 t := DeclareFieldVarient(sym)
5694 ELSIF IsVarient(sym)
5695 THEN
5696 t := DeclareVarient(sym)
5697 ELSIF IsPointer(sym)
5698 THEN
5699 t := CheckAlignment(DeclarePointer(sym), sym)
5700 ELSIF IsUnbounded(sym)
5701 THEN
5702 t := DeclareUnbounded(sym)
5703 ELSIF IsArray(sym)
5704 THEN
5705 t := CheckAlignment(DeclareArray(sym), sym)
5706 ELSIF IsProcType(sym)
5707 THEN
5708 t := DeclareProcType(sym)
5709 ELSIF IsSet(sym)
5710 THEN
5711 t := DeclareSet(sym)
5712 ELSIF IsConst(sym)
5713 THEN
5714 IF IsConstructor(sym)
5715 THEN
5716 PushValue(sym) ;
5717 ChangeToConstructor(GetDeclaredMod(sym), GetSType(sym)) ;
5718 PopValue(sym) ;
5719 EvaluateValue(sym) ;
5720 PutConstructorSolved(sym) ;
5721 ELSIF IsConstSet(sym)
5722 THEN
5723 EvaluateValue(sym)
5724 END ;
5725 IF NOT IsValueSolved(sym)
5726 THEN
5727 RETURN( NIL )
5728 END ;
5729 t := DeclareConst(GetDeclaredMod(sym), sym) ;
5730 Assert(t#NIL)
5731 ELSIF IsConstructor(sym)
5732 THEN
5733 (* not yet known as a constant *)
5734 RETURN( NIL )
5735 ELSE
5736 t := DeclareType(sym) ;
5737 IF IsType(sym)
5738 THEN
5739 t := CheckAlignment(t, sym)
5740 END
5741 END ;
5742 RETURN RememberType (t)
5743 END TypeConstFullyDeclared ;
5744
5745
5746 (*
5747 IsBaseType - returns true if a type, Sym, is a base type and
5748 we use predefined GDB information to represent this
5749 type.
5750 *)
5751
5752 PROCEDURE IsBaseType (Sym: CARDINAL) : BOOLEAN ;
5753 BEGIN
5754 RETURN( (Sym=Cardinal) OR (Sym=Integer) OR
5755 (Sym=Char) OR (Sym=Proc) )
5756 END IsBaseType ;
5757
5758
5759 (*
5760 IsFieldEnumerationDependants - sets enumDeps to FALSE if action(Sym)
5761 is also FALSE.
5762 *)
5763
5764 PROCEDURE IsFieldEnumerationDependants (Sym: WORD) ;
5765 BEGIN
5766 IF NOT action(Sym)
5767 THEN
5768 enumDeps := FALSE
5769 END
5770 END IsFieldEnumerationDependants ;
5771
5772
5773 (*
5774 IsEnumerationDependants - returns true if the enumeration
5775 p(dependants) all return true.
5776 *)
5777
5778 PROCEDURE IsEnumerationDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
5779 BEGIN
5780 action := q ;
5781 enumDeps := TRUE ;
5782 ForeachLocalSymDo (sym, IsFieldEnumerationDependants) ;
5783 RETURN( enumDeps )
5784 END IsEnumerationDependants ;
5785
5786
5787 (*
5788 WalkEnumerationDependants - returns walks all dependants of Sym.
5789 *)
5790
5791 PROCEDURE WalkEnumerationDependants (sym: CARDINAL; p: WalkAction) ;
5792 BEGIN
5793 ForeachLocalSymDo (sym, p)
5794 END WalkEnumerationDependants ;
5795
5796
5797 (*
5798 WalkSubrangeDependants - calls p(dependants) for each dependant of, sym.
5799 *)
5800
5801 PROCEDURE WalkSubrangeDependants (sym: CARDINAL; p: WalkAction) ;
5802 VAR
5803 type, align,
5804 high, low : CARDINAL ;
5805 BEGIN
5806 GetSubrange(sym, high, low) ;
5807 CheckResolveSubrange (sym) ;
5808 type := GetSType(sym) ;
5809 IF type#NulSym
5810 THEN
5811 p(type)
5812 END ;
5813 (* low and high are not types but constants and they are resolved by M2GenGCC *)
5814 p(low) ;
5815 p(high) ;
5816 align := GetAlignment (sym) ;
5817 IF align # NulSym
5818 THEN
5819 p(align)
5820 END
5821 END WalkSubrangeDependants ;
5822
5823
5824 (*
5825 IsSubrangeDependants - returns TRUE if the subrange
5826 q(dependants) all return TRUE.
5827 *)
5828
5829 PROCEDURE IsSubrangeDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
5830 VAR
5831 result : BOOLEAN ;
5832 align,
5833 type,
5834 high, low: CARDINAL ;
5835 BEGIN
5836 GetSubrange(sym, high, low) ;
5837 (* low and high are not types but constants and they are resolved by M2GenGCC *)
5838 CheckResolveSubrange(sym) ;
5839 result := TRUE ;
5840 type := GetSType(sym) ;
5841 IF (type=NulSym) OR (NOT q(type))
5842 THEN
5843 result := FALSE
5844 END ;
5845 IF NOT q(low)
5846 THEN
5847 result := FALSE
5848 END ;
5849 IF NOT q(high)
5850 THEN
5851 result := FALSE
5852 END ;
5853 align := GetAlignment(sym) ;
5854 IF (align#NulSym) AND (NOT q(align))
5855 THEN
5856 result := FALSE
5857 END ;
5858 RETURN( result )
5859 END IsSubrangeDependants ;
5860
5861
5862 (*
5863 WalkComponentDependants -
5864 *)
5865
5866 PROCEDURE WalkComponentDependants (sym: CARDINAL; p: WalkAction) ;
5867 VAR
5868 i : CARDINAL ;
5869 type: CARDINAL ;
5870 BEGIN
5871 (* need to walk record and field *)
5872 i := 1 ;
5873 REPEAT
5874 type := GetNth(sym, i) ;
5875 IF type#NulSym
5876 THEN
5877 IF IsVar(type)
5878 THEN
5879 p(GetSType(type))
5880 ELSE
5881 p(type)
5882 END ;
5883 INC(i)
5884 END
5885 UNTIL type=NulSym
5886 END WalkComponentDependants ;
5887
5888
5889 (*
5890 IsComponentDependants -
5891 *)
5892
5893 PROCEDURE IsComponentDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
5894 VAR
5895 type : CARDINAL ;
5896 i : CARDINAL ;
5897 result: BOOLEAN ;
5898 BEGIN
5899 (* need to check record is completely resolved *)
5900 result := TRUE ;
5901 i := 1 ;
5902 REPEAT
5903 type := GetNth(sym, i) ;
5904 IF type#NulSym
5905 THEN
5906 IF IsVar(type)
5907 THEN
5908 type := GetSType(type)
5909 END ;
5910 IF NOT q(type)
5911 THEN
5912 result := FALSE
5913 END ;
5914 INC(i)
5915 END
5916 UNTIL type=NulSym ;
5917 RETURN( result )
5918 END IsComponentDependants ;
5919
5920
5921 (*
5922 WalkVarDependants - walks all dependants of sym.
5923 *)
5924
5925 PROCEDURE WalkVarDependants (sym: CARDINAL; p: WalkAction) ;
5926 VAR
5927 type: CARDINAL ;
5928 BEGIN
5929 p(GetSType(sym)) ;
5930 IF IsComponent(sym)
5931 THEN
5932 WalkComponentDependants(sym, p)
5933 END ;
5934 type := GetVarBackEndType(sym) ;
5935 IF type#NulSym
5936 THEN
5937 p(type)
5938 END
5939 END WalkVarDependants ;
5940
5941
5942 (*
5943 IsVarDependants - returns TRUE if the pointer symbol, sym,
5944 p(dependants) all return TRUE.
5945 *)
5946
5947 PROCEDURE IsVarDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
5948 VAR
5949 type : CARDINAL ;
5950 result: BOOLEAN ;
5951 BEGIN
5952 result := TRUE ;
5953 IF NOT q(GetSType(sym))
5954 THEN
5955 result := FALSE
5956 END ;
5957 IF IsComponent(sym)
5958 THEN
5959 IF NOT IsComponentDependants(sym, q)
5960 THEN
5961 result := FALSE
5962 END
5963 END ;
5964 type := GetVarBackEndType(sym) ;
5965 IF type#NulSym
5966 THEN
5967 IF NOT q(type)
5968 THEN
5969 result := FALSE
5970 END
5971 END ;
5972 RETURN( result )
5973 END IsVarDependants ;
5974
5975
5976 (*
5977 WalkPointerDependants - walks all dependants of sym.
5978 *)
5979
5980 PROCEDURE WalkPointerDependants (sym: CARDINAL; p: WalkAction) ;
5981 VAR
5982 align: CARDINAL ;
5983 BEGIN
5984 p(GetSType(sym)) ;
5985 align := GetAlignment(sym) ;
5986 IF align#NulSym
5987 THEN
5988 p(align)
5989 END
5990 END WalkPointerDependants ;
5991
5992
5993 (*
5994 IsPointerDependants - returns TRUE if the pointer symbol, sym,
5995 p(dependants) all return TRUE.
5996 *)
5997
5998 PROCEDURE IsPointerDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
5999 VAR
6000 align: CARDINAL ;
6001 final: BOOLEAN ;
6002 BEGIN
6003 final := TRUE ;
6004 IF NOT q(GetSType(sym))
6005 THEN
6006 final := FALSE
6007 END ;
6008 align := GetAlignment (sym) ;
6009 IF final AND (align # NulSym)
6010 THEN
6011 IF NOT q(align)
6012 THEN
6013 final := FALSE
6014 END
6015 END ;
6016 RETURN final
6017 END IsPointerDependants ;
6018
6019
6020 (*
6021 IsRecordAlignment -
6022 *)
6023
6024 PROCEDURE IsRecordAlignment (sym: CARDINAL; q: IsAction) : BOOLEAN ;
6025 BEGIN
6026 IF GetDefaultRecordFieldAlignment(sym)#NulSym
6027 THEN
6028 IF NOT q(GetDefaultRecordFieldAlignment(sym))
6029 THEN
6030 RETURN( FALSE )
6031 END
6032 END ;
6033 RETURN( TRUE )
6034 END IsRecordAlignment ;
6035
6036
6037 (*
6038 IsRecordDependants - returns TRUE if the symbol, sym,
6039 q(dependants) all return TRUE.
6040 *)
6041
6042 PROCEDURE IsRecordDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
6043 VAR
6044 result: BOOLEAN ;
6045 i : CARDINAL ;
6046 field : CARDINAL ;
6047 BEGIN
6048 result := IsRecordAlignment(sym, q) ;
6049 i := 1 ;
6050 REPEAT
6051 field := GetNth(sym, i) ;
6052 IF field#NulSym
6053 THEN
6054 IF IsRecordField(field)
6055 THEN
6056 IF (NOT IsRecordFieldAVarientTag(field)) OR (GetSymName(field)#NulName)
6057 THEN
6058 IF NOT q(field)
6059 THEN
6060 result := FALSE
6061 END
6062 END
6063 ELSIF IsVarient(field)
6064 THEN
6065 IF NOT q(field)
6066 THEN
6067 result := FALSE
6068 END
6069 ELSIF IsFieldVarient(field)
6070 THEN
6071 InternalError ('should not see a field varient')
6072 ELSE
6073 InternalError ('unknown symbol in record')
6074 END
6075 END ;
6076 INC(i)
6077 UNTIL field=NulSym ;
6078 RETURN( result )
6079 END IsRecordDependants ;
6080
6081
6082 (*
6083 WalkRecordAlignment - walks the alignment constant associated with
6084 record, sym.
6085 *)
6086
6087 PROCEDURE WalkRecordAlignment (sym: CARDINAL; p: WalkAction) ;
6088 BEGIN
6089 IF GetDefaultRecordFieldAlignment(sym)#NulSym
6090 THEN
6091 p(GetDefaultRecordFieldAlignment(sym))
6092 END
6093 END WalkRecordAlignment ;
6094
6095
6096 (*
6097 WalkRecordDependants - walks symbol, sym, dependants. It only
6098 walks the fields if the alignment is
6099 unused or fully declared.
6100 *)
6101
6102 PROCEDURE WalkRecordDependants (sym: CARDINAL; p: WalkAction) ;
6103 BEGIN
6104 WalkRecordAlignment(sym, p) ;
6105 WalkRecordDependants2(sym, p)
6106 END WalkRecordDependants ;
6107
6108
6109 (*
6110 WalkRecordFieldDependants -
6111 *)
6112
6113 PROCEDURE WalkRecordFieldDependants (sym: CARDINAL; p: WalkAction) ;
6114 VAR
6115 v : CARDINAL ;
6116 align: CARDINAL ;
6117 BEGIN
6118 Assert(IsRecordField(sym)) ;
6119 p(GetSType(sym)) ;
6120 v := GetVarient(sym) ;
6121 IF v#NulSym
6122 THEN
6123 p(v)
6124 END ;
6125 align := GetAlignment(sym) ;
6126 IF align#NulSym
6127 THEN
6128 p(align)
6129 END
6130 END WalkRecordFieldDependants ;
6131
6132
6133 (*
6134 WalkRecordDependants2 - walks the fields of record, sym, calling
6135 p on every dependant.
6136 *)
6137
6138 PROCEDURE WalkRecordDependants2 (sym: CARDINAL; p: WalkAction) ;
6139 VAR
6140 i : CARDINAL ;
6141 Field: CARDINAL ;
6142 BEGIN
6143 i := 1 ;
6144 WHILE GetNth(sym, i)#NulSym DO
6145 Field := GetNth(sym, i) ;
6146 p(Field) ;
6147 IF IsRecordField(Field)
6148 THEN
6149 WalkRecordFieldDependants(Field, p)
6150 ELSIF IsVarient(Field)
6151 THEN
6152 WalkVarientDependants(Field, p)
6153 ELSIF IsFieldVarient(Field)
6154 THEN
6155 InternalError ('should not see a field varient')
6156 ELSE
6157 InternalError ('unknown symbol in record')
6158 END ;
6159 INC(i)
6160 END
6161 END WalkRecordDependants2 ;
6162
6163
6164 (*
6165 IsVarientAlignment -
6166 *)
6167
6168 PROCEDURE IsVarientAlignment (sym: CARDINAL; q: IsAction) : BOOLEAN ;
6169 VAR
6170 align: CARDINAL ;
6171 BEGIN
6172 sym := GetRecordOfVarient(sym) ;
6173 align := GetDefaultRecordFieldAlignment(sym) ;
6174 IF (align#NulSym) AND (NOT q(align))
6175 THEN
6176 RETURN( FALSE )
6177 END ;
6178 RETURN( TRUE )
6179 END IsVarientAlignment ;
6180
6181
6182 (*
6183 IsVarientDependants - returns TRUE if the symbol, sym,
6184 q(dependants) all return TRUE.
6185 *)
6186
6187 PROCEDURE IsVarientDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
6188 VAR
6189 result: BOOLEAN ;
6190 i : CARDINAL ;
6191 Field : CARDINAL ;
6192 BEGIN
6193 result := IsVarientAlignment(sym, q) ;
6194 i := 1 ;
6195 WHILE GetNth(sym, i)#NulSym DO
6196 Field := GetNth(sym, i) ;
6197 Assert(IsFieldVarient(Field)) ;
6198 IF NOT q(Field)
6199 THEN
6200 result := FALSE
6201 END ;
6202 INC(i)
6203 END ;
6204 RETURN( result )
6205 END IsVarientDependants ;
6206
6207
6208 (*
6209 WalkVarientAlignment -
6210 *)
6211
6212 PROCEDURE WalkVarientAlignment (sym: CARDINAL; p: WalkAction) ;
6213 VAR
6214 align: CARDINAL ;
6215 BEGIN
6216 sym := GetRecordOfVarient(sym) ;
6217 align := GetDefaultRecordFieldAlignment(sym) ;
6218 IF align#NulSym
6219 THEN
6220 p(align)
6221 END
6222 END WalkVarientAlignment ;
6223
6224
6225 (*
6226 WalkVarientDependants - walks symbol, sym, dependants.
6227 *)
6228
6229 PROCEDURE WalkVarientDependants (sym: CARDINAL; p: WalkAction) ;
6230 VAR
6231 i : CARDINAL ;
6232 v,
6233 Field: CARDINAL ;
6234 BEGIN
6235 WalkVarientAlignment(sym, p) ;
6236 IF GetSType(sym)#NulSym
6237 THEN
6238 p(GetSType(sym))
6239 END ;
6240 v := GetVarient(sym) ;
6241 IF v#NulSym
6242 THEN
6243 p(v)
6244 END ;
6245 i := 1 ;
6246 WHILE GetNth(sym, i)#NulSym DO
6247 Field := GetNth(sym, i) ;
6248 Assert(IsFieldVarient(Field)) ; (* field varients do _not_ have a type *)
6249 p(Field) ;
6250 WalkVarientFieldDependants(Field, p) ;
6251 INC(i)
6252 END
6253 END WalkVarientDependants ;
6254
6255
6256 (*
6257 IsVarientFieldDependants - returns TRUE if the symbol, sym,
6258 q(dependants) all return TRUE.
6259 *)
6260
6261 PROCEDURE IsVarientFieldDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
6262 VAR
6263 i : CARDINAL ;
6264 type,
6265 Field : CARDINAL ;
6266 result: BOOLEAN ;
6267 BEGIN
6268 i := 1 ;
6269 result := IsVarientAlignment(sym, q) ;
6270 WHILE GetNth(sym, i)#NulSym DO
6271 Field := GetNth(sym, i) ;
6272 IF NOT q(Field)
6273 THEN
6274 result := FALSE
6275 END ;
6276 type := GetSType(Field) ;
6277 IF type#NulSym
6278 THEN
6279 IF NOT q(type)
6280 THEN
6281 result := FALSE
6282 END
6283 END ;
6284 INC(i)
6285 END ;
6286 RETURN( result )
6287 END IsVarientFieldDependants ;
6288
6289
6290 (*
6291 WalkVarientFieldDependants -
6292 *)
6293
6294 PROCEDURE WalkVarientFieldDependants (sym: CARDINAL; p: WalkAction) ;
6295 VAR
6296 i : CARDINAL ;
6297 type,
6298 Field: CARDINAL ;
6299 BEGIN
6300 WalkVarientAlignment(sym, p) ;
6301 i := 1 ;
6302 WHILE GetNth(sym, i)#NulSym DO
6303 Field := GetNth(sym, i) ;
6304 p(Field) ;
6305 type := GetSType(Field) ;
6306 IF type#NulSym
6307 THEN
6308 p(type)
6309 END ;
6310 INC(i)
6311 END
6312 END WalkVarientFieldDependants ;
6313
6314
6315 (*
6316 IsArrayDependants - returns TRUE if the symbol, sym,
6317 q(dependants) all return TRUE.
6318
6319 *)
6320
6321 PROCEDURE IsArrayDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
6322 VAR
6323 result : BOOLEAN ;
6324 align : CARDINAL ;
6325 subscript: CARDINAL ;
6326 high, low: CARDINAL ;
6327 type : CARDINAL ;
6328 BEGIN
6329 result := TRUE ;
6330 Assert(IsArray(sym)) ;
6331 type := GetSType(sym) ;
6332
6333 IF NOT q(type)
6334 THEN
6335 result := FALSE
6336 END ;
6337 subscript := GetArraySubscript(sym) ;
6338 IF subscript#NulSym
6339 THEN
6340 Assert(IsSubscript(subscript)) ;
6341 type := GetSType(subscript) ;
6342 IF NOT q(type)
6343 THEN
6344 result := FALSE
6345 END ;
6346 type := SkipType(type) ;
6347 (* the array might be declared as ARRAY type OF foo *)
6348 low := GetTypeMin(type) ;
6349 high := GetTypeMax(type) ;
6350 IF NOT q(low)
6351 THEN
6352 result := FALSE
6353 END ;
6354 IF NOT q(high)
6355 THEN
6356 result := FALSE
6357 END ;
6358 align := GetAlignment(sym) ;
6359 IF (align#NulSym) AND (NOT q(align))
6360 THEN
6361 result := FALSE
6362 END
6363 END ;
6364 RETURN( result )
6365 END IsArrayDependants ;
6366
6367
6368 (*
6369 WalkArrayDependants - walks symbol, sym, dependants.
6370 *)
6371
6372 PROCEDURE WalkArrayDependants (sym: CARDINAL; p: WalkAction) ;
6373 VAR
6374 align : CARDINAL ;
6375 subscript: CARDINAL ;
6376 high, low: CARDINAL ;
6377 type : CARDINAL ;
6378 BEGIN
6379 Assert(IsArray(sym)) ;
6380 type := GetSType(sym) ;
6381 p(type) ;
6382 subscript := GetArraySubscript(sym) ;
6383 IF subscript#NulSym
6384 THEN
6385 Assert(IsSubscript(subscript)) ;
6386 type := GetSType(subscript) ;
6387 p(type) ;
6388 type := SkipType(type) ;
6389 (* the array might be declared as ARRAY type OF foo *)
6390 low := GetTypeMin(type) ;
6391 high := GetTypeMax(type) ;
6392 p(low) ;
6393 p(high) ;
6394 align := GetAlignment (sym) ;
6395 IF align#NulSym
6396 THEN
6397 p(align)
6398 END
6399 END
6400 END WalkArrayDependants ;
6401
6402
6403 (*
6404 IsSetDependants - returns TRUE if the symbol, sym,
6405 q(dependants) all return TRUE.
6406 *)
6407
6408 PROCEDURE IsSetDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
6409 VAR
6410 result : BOOLEAN ;
6411 type, low, high: CARDINAL ;
6412 BEGIN
6413 result := TRUE ;
6414 Assert(IsSet(sym)) ;
6415
6416 type := GetDType(sym) ;
6417 IF NOT q(type)
6418 THEN
6419 result := FALSE
6420 END ;
6421 low := GetTypeMin(type) ;
6422 high := GetTypeMax(type) ;
6423 IF NOT q(low)
6424 THEN
6425 result := FALSE
6426 END ;
6427 IF NOT q(high)
6428 THEN
6429 result := FALSE
6430 END ;
6431 RETURN( result )
6432 END IsSetDependants ;
6433
6434
6435 (*
6436 WalkSetDependants - walks dependants, sym.
6437 *)
6438
6439 PROCEDURE WalkSetDependants (sym: CARDINAL; p: WalkAction) ;
6440 VAR
6441 type, low, high: CARDINAL ;
6442 BEGIN
6443 Assert(IsSet(sym)) ;
6444
6445 type := GetDType(sym) ;
6446 p(type) ;
6447 low := GetTypeMin(type) ;
6448 p(low) ;
6449 high := GetTypeMax(type) ;
6450 p(high)
6451 END WalkSetDependants ;
6452
6453
6454 (*
6455 IsProcTypeDependants -
6456 *)
6457
6458 PROCEDURE IsProcTypeDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
6459 VAR
6460 i, p, son : CARDINAL ;
6461 ParamType,
6462 ReturnType: CARDINAL ;
6463 result : BOOLEAN ;
6464 BEGIN
6465 result := TRUE ;
6466 Assert(IsProcType(sym)) ;
6467 i := 1 ;
6468 ReturnType := GetSType(sym) ;
6469 p := NoOfParamAny (sym) ;
6470 WHILE i<=p DO
6471 son := GetNthParamAny (sym, i) ;
6472 ParamType := GetSType(son) ;
6473 IF NOT q(ParamType)
6474 THEN
6475 result := FALSE
6476 END ;
6477 INC(i)
6478 END ;
6479 IF (ReturnType=NulSym) OR q(ReturnType)
6480 THEN
6481 RETURN( result )
6482 ELSE
6483 RETURN( FALSE )
6484 END
6485 END IsProcTypeDependants ;
6486
6487
6488 (*
6489 WalkProcTypeDependants - walks dependants, sym.
6490 *)
6491
6492 PROCEDURE WalkProcTypeDependants (sym: CARDINAL; p: WalkAction) ;
6493 VAR
6494 i, n, son : CARDINAL ;
6495 ParamType,
6496 ReturnType: CARDINAL ;
6497 BEGIN
6498 Assert(IsProcType(sym)) ;
6499 i := 1 ;
6500 ReturnType := GetSType(sym) ;
6501 n := NoOfParamAny (sym) ;
6502 WHILE i<=n DO
6503 son := GetNthParamAny (sym, i) ;
6504 ParamType := GetSType(son) ;
6505 p(ParamType) ;
6506 INC(i)
6507 END ;
6508 IF ReturnType#NulSym
6509 THEN
6510 p(ReturnType)
6511 END
6512 END WalkProcTypeDependants ;
6513
6514
6515 (*
6516 IsProcedureDependants -
6517 *)
6518
6519 PROCEDURE IsProcedureDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
6520 VAR
6521 i, son : CARDINAL ;
6522 type,
6523 ReturnType: CARDINAL ;
6524 result : BOOLEAN ;
6525 BEGIN
6526 result := TRUE ;
6527 Assert(IsProcedure(sym)) ;
6528 i := 1 ;
6529 ReturnType := GetSType(sym) ;
6530 WHILE GetNth(sym, i)#NulSym DO
6531 son := GetNth(sym, i) ;
6532 type := GetSType(son) ;
6533 IF NOT q(type)
6534 THEN
6535 result := FALSE
6536 END ;
6537 INC(i)
6538 END ;
6539 IF (ReturnType=NulSym) OR q(ReturnType)
6540 THEN
6541 RETURN( result )
6542 ELSE
6543 RETURN( FALSE )
6544 END
6545 END IsProcedureDependants ;
6546
6547
6548 (*
6549 WalkProcedureDependants - walks dependants, sym.
6550 *)
6551
6552 PROCEDURE WalkProcedureDependants (sym: CARDINAL; p: WalkAction) ;
6553 VAR
6554 i, son : CARDINAL ;
6555 type,
6556 ReturnType: CARDINAL ;
6557 BEGIN
6558 Assert(IsProcedure(sym)) ;
6559 i := 1 ;
6560 ReturnType := GetSType(sym) ;
6561 WHILE GetNth(sym, i)#NulSym DO
6562 son := GetNth(sym, i) ;
6563 type := GetSType(son) ;
6564 p(type) ;
6565 INC(i)
6566 END ;
6567 IF ReturnType#NulSym
6568 THEN
6569 p(ReturnType)
6570 END
6571 END WalkProcedureDependants ;
6572
6573
6574 (*
6575 IsUnboundedDependants - returns TRUE if the symbol, sym,
6576 q(dependants) all return TRUE.
6577 *)
6578
6579 PROCEDURE IsUnboundedDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
6580 VAR
6581 result: BOOLEAN ;
6582 BEGIN
6583 result := TRUE ;
6584 IF NOT q(GetUnboundedRecordType(sym))
6585 THEN
6586 result := FALSE
6587 END ;
6588 IF NOT q(Cardinal)
6589 THEN
6590 result := FALSE
6591 END ;
6592 IF NOT q(GetSType(sym))
6593 THEN
6594 result := FALSE
6595 END ;
6596 RETURN( result )
6597 END IsUnboundedDependants ;
6598
6599
6600 (*
6601 WalkUnboundedDependants - walks the dependants of, sym.
6602 *)
6603
6604 PROCEDURE WalkUnboundedDependants (sym: CARDINAL; p: WalkAction) ;
6605 BEGIN
6606 p(GetUnboundedRecordType(sym)) ;
6607 p(Cardinal) ;
6608 p(GetSType(sym))
6609 END WalkUnboundedDependants ;
6610
6611
6612 (*
6613 IsTypeDependants - returns TRUE if all q(dependants) return
6614 TRUE.
6615 *)
6616
6617 PROCEDURE IsTypeDependants (sym: CARDINAL; q: IsAction) : BOOLEAN ;
6618 VAR
6619 align: CARDINAL ;
6620 type : CARDINAL ;
6621 final: BOOLEAN ;
6622 BEGIN
6623 type := GetSType(sym) ;
6624 final := TRUE ;
6625 IF (type#NulSym) AND (NOT q(type))
6626 THEN
6627 final := FALSE
6628 END ;
6629 align := GetAlignment(sym) ;
6630 IF (align#NulSym) AND (NOT q(align))
6631 THEN
6632 final := FALSE
6633 END ;
6634 RETURN( final )
6635 END IsTypeDependants ;
6636
6637
6638 (*
6639 WalkTypeDependants - walks all dependants of, sym.
6640 *)
6641
6642 PROCEDURE WalkTypeDependants (sym: CARDINAL; p: WalkAction) ;
6643 VAR
6644 align: CARDINAL ;
6645 type : CARDINAL ;
6646 BEGIN
6647 type := GetSType(sym) ;
6648 IF type#NulSym
6649 THEN
6650 p(type)
6651 END ;
6652 align := GetAlignment(sym) ;
6653 IF align#NulSym
6654 THEN
6655 p(align)
6656 END
6657 END WalkTypeDependants ;
6658
6659
6660 (*
6661 PoisonSymbols - poisons all gcc symbols from procedure, sym.
6662 A debugging aid.
6663 *)
6664
6665 PROCEDURE PoisonSymbols (sym: CARDINAL) ;
6666 BEGIN
6667 IF IsProcedure(sym)
6668 THEN
6669 ForeachLocalSymDo(sym, Poison)
6670 END
6671 END PoisonSymbols ;
6672
6673
6674 (*
6675 ConstantKnownAndUsed -
6676 *)
6677
6678 PROCEDURE ConstantKnownAndUsed (sym: CARDINAL; t: tree) ;
6679 BEGIN
6680 DeclareConstantFromTree(sym, RememberConstant(t))
6681 END ConstantKnownAndUsed ;
6682
6683
6684 (*
6685 InitDeclarations - initializes default types and the source filename.
6686 *)
6687
6688 PROCEDURE InitDeclarations ;
6689 BEGIN
6690 DeclareDefaultTypes ;
6691 DeclareDefaultConstants
6692 END InitDeclarations ;
6693
6694
6695 BEGIN
6696 FreeGroup := NIL ;
6697 GlobalGroup := InitGroup () ;
6698 ErrorDepList := InitSet (1) ;
6699 ChainedList := InitSet(1) ;
6700 WatchList := InitSet(1) ;
6701 VisitedList := NIL ;
6702 EnumerationIndex := InitIndex(1) ;
6703 HaveInitDefaultTypes := FALSE ;
6704 recursionCaught := FALSE
6705 END M2GCCDeclare.