Debian Codegraph @

gcc/m2/gm2-compiler/SymbolTable.mod

raw
1 (* SymbolTable.mod provides access to the symbol table.
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 SymbolTable ;
23
24
25 FROM SYSTEM IMPORT ADDRESS, ADR ;
26 FROM Storage IMPORT ALLOCATE, DEALLOCATE ;
27 FROM M2Debug IMPORT Assert ;
28 FROM libc IMPORT printf ;
29 FROM ASCII IMPORT nul ;
30
31 IMPORT Indexing ;
32
33 FROM Indexing IMPORT InitIndex, InBounds, LowIndice, HighIndice,
34 PutIndice, GetIndice, InitIndexTuned ;
35
36 FROM Sets IMPORT Set, InitSet, IncludeElementIntoSet, IsElementInSet ;
37 FROM gcctypes IMPORT location_t ;
38
39 FROM M2Options IMPORT Pedantic, ExtendedOpaque,
40 GetDebugFunctionLineNumbers, ScaffoldDynamic,
41 DebugBuiltins ;
42
43 FROM M2LexBuf IMPORT UnknownTokenNo, TokenToLineNo,
44 FindFileNameFromToken, TokenToLocation,
45 MakeVirtual2Tok ;
46
47 FROM M2ALU IMPORT InitValue, PtrToValue, PushCard, PopInto,
48 PushString, PushFrom, PushChar, PushInt,
49 IsSolved, IsValueConst ;
50
51 FROM M2Error IMPORT Error, NewError, ChainError, InternalError,
52 ErrorFormat0, ErrorFormat1, ErrorFormat2,
53 WriteFormat0, WriteFormat1, WriteFormat2, ErrorString,
54 ErrorAbort0, FlushErrors, ErrorScope, GetCurrentErrorScope ;
55
56 FROM M2MetaError IMPORT MetaError1, MetaError2, MetaError3, MetaErrors1,
57 MetaErrorT0,
58 MetaErrorString1,
59 MetaErrorStringT0, MetaErrorStringT1,
60 MetaErrorT1, MetaErrorT2 ;
61
62 FROM M2LexBuf IMPORT GetTokenNo ;
63 FROM FormatStrings IMPORT Sprintf1 ;
64 FROM M2Printf IMPORT printf0, printf1, printf2, printf3, printf4 ;
65
66 FROM DynamicStrings IMPORT String, string, InitString,
67 InitStringCharStar, Mark, KillString, Length, ConCat,
68 Index, char ;
69
70 FROM Lists IMPORT List, InitList, GetItemFromList, PutItemIntoList,
71 IsItemInList, IncludeItemIntoList, NoOfItemsInList,
72 RemoveItemFromList, ForeachItemInListDo ;
73
74 FROM NameKey IMPORT Name, MakeKey, makekey, NulName, WriteKey, LengthKey, GetKey, KeyToCharStar ;
75
76 FROM SymbolKey IMPORT NulKey, SymbolTree, IsSymbol,
77 InitTree,
78 GetSymKey, PutSymKey, DelSymKey, IsEmptyTree,
79 DoesTreeContainAny, ForeachNodeDo, ForeachNodeConditionDo,
80 NoOfNodes ;
81
82 FROM M2Base IMPORT MixTypes, MixTypesDecl, InitBase, Char, Integer, LongReal,
83 Cardinal, LongInt, LongCard, ZType, RType ;
84
85 FROM M2System IMPORT Address ;
86 FROM m2expr IMPORT OverflowZType ;
87 FROM gcctypes IMPORT tree ;
88 FROM m2linemap IMPORT BuiltinsLocation ;
89 FROM StrLib IMPORT StrEqual ;
90 FROM m2builtins IMPORT BuiltinExists ;
91
92 FROM M2Comp IMPORT CompilingDefinitionModule,
93 CompilingImplementationModule ;
94
95 FROM FormatStrings IMPORT HandleEscape ;
96 FROM M2Scaffold IMPORT DeclareArgEnvParams ;
97
98 FROM M2SymInit IMPORT InitDesc, InitSymInit, GetInitialized, ConfigSymInit,
99 SetInitialized, SetFieldInitialized, GetFieldInitialized,
100 PrintSymInit ;
101
102 IMPORT Indexing ;
103
104
105 CONST
106 DebugUnknowns = FALSE ; (* Debug unknown symbols. *)
107 DebugUnknownToken = FALSE ; (* If enabled it will generate a warning every
108 time a symbol is created with an unknown
109 location. *)
110
111 (*
112 The Unbounded is a pseudo type used within the compiler
113 to implement dynamic parameter arrays. It is implmented
114 as a record structure which has the following fields:
115
116 RECORD
117 _m2_contents: POINTER TO type ;
118 _m2_high : CARDINAL ;
119 END ;
120 *)
121
122 UnboundedAddressName = "_m2_contents" ;
123 UnboundedHighName = "_m2_high_%d" ;
124
125 TYPE
126 ProcAnyBoolean = PROCEDURE (CARDINAL, ProcedureKind) : BOOLEAN ;
127 ProcAnyCardinal = PROCEDURE (CARDINAL, ProcedureKind) : CARDINAL ;
128
129 ConstLitPoolEntry = POINTER TO RECORD
130 sym : CARDINAL ;
131 tok : CARDINAL ;
132 constName: Name ;
133 constType: CARDINAL ;
134 next : ConstLitPoolEntry ;
135 END ;
136
137 LRLists = ARRAY [RightValue..LeftValue] OF List ;
138
139 LRInitDesc = ARRAY [RightValue..LeftValue] OF InitDesc ;
140
141 TypeOfSymbol = (RecordSym, VarientSym, DummySym,
142 VarSym, EnumerationSym, SubrangeSym, ArraySym,
143 ConstStringSym, ConstVarSym, ConstLitSym,
144 VarParamSym, ParamSym, PointerSym,
145 UndefinedSym, TypeSym,
146 RecordFieldSym, VarientFieldSym, EnumerationFieldSym,
147 DefImpSym, ModuleSym, SetSym, ProcedureSym, ProcTypeSym,
148 SubscriptSym, UnboundedSym, GnuAsmSym, InterfaceSym,
149 ObjectSym, PartialUnboundedSym, TupleSym, OAFamilySym,
150 ImportSym, ImportStatementSym,
151 EquivSym, ErrorSym) ;
152
153 Where = RECORD
154 DefDeclared,
155 FirstUsed,
156 ModDeclared: CARDINAL ;
157 END ;
158
159 VarDecl = RECORD
160 FullTok,
161 VarTok,
162 TypeTok: CARDINAL ; (* Variable and type token *)
163 END ; (* locations. *)
164
165 PackedInfo = RECORD
166 IsPacked : BOOLEAN ; (* is this type packed? *)
167 PackedEquiv : CARDINAL ; (* the equivalent packed type *)
168 END ;
169
170 PtrToAsmConstraint = POINTER TO RECORD
171 tokpos: CARDINAL ;
172 name : Name ;
173 str : CARDINAL ; (* regnames or constraints *)
174 obj : CARDINAL ; (* list of M2 syms *)
175 END ;
176
177 ModuleCtor = RECORD
178 ctor: CARDINAL ; (* Procedure which will become a ctor. *)
179 init: CARDINAL ; (* Module initialization block proc. *)
180 fini: CARDINAL ; (* Module Finalization block proc. *)
181 dep : CARDINAL ; (* Module dependency proc. *)
182 END ;
183
184 (* Each import list has a import statement symbol. *)
185
186 SymImportStatement = RECORD
187 listNo : CARDINAL ; (* The import list no. *)
188 ListOfImports: List ; (* Vector of SymImports. *)
189 at : Where ; (* The FROM or IMPORT token. *)
190 END ;
191
192 SymImport = RECORD
193 module : CARDINAL ; (* The module imported. *)
194 listNo : CARDINAL ; (* The import list no. *)
195 qualified: BOOLEAN ; (* Is the complete module imported? *)
196 at : Where ; (* token corresponding to the *)
197 (* module name in the import. *)
198 END ;
199
200 SymEquiv = RECORD
201 packedInfo: PackedInfo ;
202 nonPacked : CARDINAL ;
203 END ;
204
205 SymOAFamily = RECORD
206 MaxDimensions: CARDINAL ;
207 SimpleType : CARDINAL ;
208 Dimensions : Indexing.Index ;
209 END ;
210
211 SymTuple = RECORD
212 At : Where ;
213 nTuple: CARDINAL ;
214 list : Indexing.Index ;
215 END ;
216
217 SymError = RECORD
218 name : Name ;
219 Scope : CARDINAL ; (* Scope of declaration. *)
220 At : Where ; (* Where was sym declared/used *)
221 END ;
222
223 SymObject = RECORD
224 name : Name ;
225 At : Where ; (* Where was sym declared/used *)
226 END ;
227
228 SymUndefined = RECORD
229 name : Name ; (* Index into name array, name *)
230 (* of record. *)
231 oafamily : CARDINAL ; (* The oafamily for this sym *)
232 errorScope: ErrorScope ; (* Title scope used if an *)
233 (* error is emitted. *)
234 At : Where ; (* Where was sym declared/used *)
235 END ;
236
237 SymGnuAsm = RECORD
238 String : CARDINAL ; (* (ConstString) the assembly *)
239 (* instruction. *)
240 At : Where ; (* Where was sym declared/used *)
241 Inputs,
242 Outputs,
243 Trashed : CARDINAL ; (* The interface symbols. *)
244 Volatile : BOOLEAN ; (* Declared as ASM VOLATILE ? *)
245 Simple : BOOLEAN ; (* is a simple kind? *)
246 END ;
247
248 SymInterface = RECORD
249 Parameters: Indexing.Index ;
250 (* regnames or constraints *)
251 (* list of M2 syms. *)
252 At : Where ; (* Where was sym declared/used *)
253 END ;
254
255 SymVarient = RECORD
256 Size : PtrToValue ; (* Size at runtime of symbol. *)
257 ListOfSons : List ; (* ListOfSons contains a list *)
258 (* of SymRecordField and *)
259 (* SymVarients *)
260 (* declared by the source *)
261 (* file. *)
262 DeclPacked : BOOLEAN ; (* Is this varient packed? *)
263 DeclResolved: BOOLEAN ; (* has we resolved packed? *)
264 Parent : CARDINAL ; (* Points to the parent symbol *)
265 Varient : CARDINAL ; (* Index into symbol table to *)
266 (* determine the associated *)
267 (* varient symbol. *)
268 tag : CARDINAL ; (* The tag of the varient *)
269 (* this can either be a type *)
270 (* or a varient field. *)
271 Scope : CARDINAL ; (* Scope of declaration. *)
272 At : Where ; (* Where was sym declared/used *)
273 END ;
274
275 SymRecord = RECORD
276 name : Name ; (* Index into name array, name *)
277 (* of record. *)
278 LocalSymbols : SymbolTree ; (* Contains all record fields. *)
279 Size : PtrToValue ; (* Size at runtime of symbol. *)
280 ListOfSons : List ; (* ListOfSons contains a list *)
281 (* of SymRecordField and *)
282 (* SymVarients *)
283 (* declared by the source *)
284 (* file. *)
285 Align : CARDINAL ; (* The alignment of this type. *)
286 DefaultAlign : CARDINAL ; (* The default field alignment *)
287 DeclPacked : BOOLEAN ; (* Is this record packed? *)
288 DeclResolved : BOOLEAN ; (* has we resolved packed? *)
289 oafamily : CARDINAL ; (* The oafamily for this sym. *)
290 Parent : CARDINAL ; (* Points to the parent symbol *)
291 Scope : CARDINAL ; (* Scope of declaration. *)
292 At : Where ; (* Where was sym declared/used *)
293 END ;
294
295 SymSubrange = RECORD
296 name : Name ; (* Index into name array, name *)
297 (* of subrange. *)
298 Low : CARDINAL ; (* Index to symbol for lower *)
299 High : CARDINAL ; (* Index to symbol for higher *)
300 Size : PtrToValue ; (* Size of subrange type. *)
301 Type : CARDINAL ; (* Index to type symbol for *)
302 (* the type of subrange. *)
303 Align : CARDINAL ; (* Alignment for this type. *)
304 ConstLitTree: SymbolTree ; (* constants of this type. *)
305 packedInfo : PackedInfo ; (* the equivalent packed type *)
306 oafamily : CARDINAL ; (* The oafamily for this sym *)
307 Scope : CARDINAL ; (* Scope of declaration. *)
308 At : Where ; (* Where was sym declared/used *)
309 END ;
310
311 SymEnumeration =
312 RECORD
313 name : Name ; (* Index into name array, name *)
314 (* of enumeration. *)
315 NoOfElements: CARDINAL ; (* No elements in enumeration *)
316 LocalSymbols: SymbolTree ; (* Contains all enumeration *)
317 (* fields (alphabetical). *)
318 ListOfFields: List ; (* Ordered as declared. *)
319 Size : PtrToValue ; (* Size at runtime of symbol. *)
320 packedInfo : PackedInfo ; (* the equivalent packed type *)
321 oafamily : CARDINAL ; (* The oafamily for this sym *)
322 Scope : CARDINAL ; (* Scope of declaration. *)
323 At : Where ; (* Where was sym declared/used *)
324 END ;
325
326 SymArray = RECORD
327 name : Name ; (* Index into name array, name *)
328 (* of array. *)
329 Subscript : CARDINAL ; (* the subscript for this *)
330 (* array. *)
331 Size : PtrToValue ; (* Size at runtime of symbol. *)
332 Offset : PtrToValue ; (* Offset at runtime of symbol *)
333 Type : CARDINAL ; (* Type of the Array. *)
334 Align : CARDINAL ; (* Alignment for this type. *)
335 Large : BOOLEAN ; (* is this a large array? *)
336 oafamily : CARDINAL ; (* The oafamily for this sym *)
337 Scope : CARDINAL ; (* Scope of declaration. *)
338 At : Where ; (* Where was sym declared/used *)
339 END ;
340
341 SymSubscript = RECORD
342 Type : CARDINAL ; (* Index to a subrange symbol. *)
343 Size : PtrToValue ; (* Size of this indice in*Size *)
344 Offset : PtrToValue ; (* Offset at runtime of symbol *)
345 (* Pseudo ie: Offset+Size*i *)
346 (* 1..n. The array offset is *)
347 (* the real memory offset. *)
348 (* This offset allows the a[i] *)
349 (* to be calculated without *)
350 (* the need to perform *)
351 (* subtractions when a[4..10] *)
352 (* needs to be indexed. *)
353 At : Where ; (* Where was sym declared/used *)
354 END ;
355
356 SymUnbounded = RECORD
357 Type : CARDINAL ; (* Index to Simple type symbol *)
358 Size : PtrToValue ;(* Max No of words ever *)
359 (* passed to this type. *)
360 RecordType : CARDINAL ; (* Record type used to *)
361 (* implement the unbounded. *)
362 Dimensions : CARDINAL ; (* No of dimensions this
363 open array uses. *)
364 Scope : CARDINAL ; (* Scope of declaration. *)
365 At : Where ; (* Where was sym declared/used *)
366 END ;
367
368 SymPartialUnbounded = RECORD
369 Type: CARDINAL ; (* Index to Simple type symbol *)
370 NDim: CARDINAL ; (* dimensions associated *)
371 END ;
372
373 ProcedureDeclaration
374 = RECORD
375 ListOfParam : List ; (* Contains a list of all the *)
376 (* parameters in this procedure. *)
377 Defined : BOOLEAN ; (* Has the procedure been *)
378 (* declared yet? *)
379 ParamDefined : BOOLEAN ; (* Have the parameters been *)
380 (* defined yet? *)
381 HasVarArgs : BOOLEAN ; (* Does this procedure use ... ? *)
382 HasOptArg : BOOLEAN ; (* Does this procedure use [ ] ? *)
383 IsNoReturn : BOOLEAN ; (* Attribute noreturn ? *)
384 ReturnOptional: BOOLEAN ; (* Is the return value optional? *)
385 ReturnTypeTok,
386 ProcedureTok : CARDINAL ; (* Token pos of procedure name. *)
387 END ;
388
389 SymProcedure
390 = RECORD
391 name : Name ; (* Index into name array, name *)
392 (* of procedure. *)
393 Decl : ARRAY ProcedureKind OF ProcedureDeclaration ;
394 OptArgInit : CARDINAL ; (* The optarg initial value. *)
395 IsExtern : BOOLEAN ; (* Make this procedure extern. *)
396 IsPublic : BOOLEAN ; (* Make this procedure visible. *)
397 IsCtor : BOOLEAN ; (* Is this procedure a ctor? *)
398 IsMonoName : BOOLEAN ; (* Ignores module name prefix. *)
399 BuildProcType : BOOLEAN ; (* Are we building the *)
400 (* associated proctype? *)
401 Unresolved : SymbolTree ; (* All symbols currently *)
402 (* unresolved in this procedure. *)
403 ScopeQuad : CARDINAL ; (* Index into quads for scope *)
404 StartQuad : CARDINAL ; (* Index into quads for start *)
405 (* of procedure. *)
406 EndQuad : CARDINAL ; (* Index into quads for end of *)
407 (* procedure. *)
408 Reachable : BOOLEAN ; (* Defines if procedure will *)
409 (* ever be called by the main *)
410 (* Module. *)
411 SavePriority : BOOLEAN ; (* Does procedure need to save *)
412 (* and restore interrupts? *)
413 ReturnType : CARDINAL ; (* Return type for function. *)
414 ProcedureType : CARDINAL ; (* Proc type for this procedure. *)
415 IsBuiltin : BOOLEAN ; (* Was it declared __BUILTIN__ ? *)
416 BuiltinName : Name ; (* name of equivalent builtin *)
417 IsInline : BOOLEAN ; (* Was it declared __INLINE__ ? *)
418 LocalSymbols: SymbolTree ; (* Contains all symbols declared *)
419 (* within this procedure. *)
420 EnumerationScopeList: List ;
421 (* Enumeration scope list which *)
422 (* contains a list of all *)
423 (* enumerations which are *)
424 (* visable within this scope. *)
425 ListOfVars : List ; (* List of variables in this *)
426 (* scope. *)
427 ListOfProcs : List ; (* List of all procedures *)
428 (* declared within this *)
429 (* procedure. *)
430 NamedObjects : SymbolTree ; (* Names of all items declared. *)
431 Size : PtrToValue ; (* Activation record size. *)
432 TotalParamSize: PtrToValue ; (* size of all parameters. *)
433 ExceptionFinally,
434 ExceptionBlock: BOOLEAN ; (* does it have an exception? *)
435 Scope : CARDINAL ; (* Scope of declaration. *)
436 errorScope : ErrorScope ; (* The title scope. *)
437 ListOfModules : List ; (* List of all inner modules. *)
438 Begin, End : CARDINAL ; (* Tokens marking the BEGIN END *)
439 At : Where ; (* Where was sym declared/used *)
440 END ;
441
442 SymProcType
443 = RECORD
444 name : Name ; (* Index into name array, name *)
445 (* of procedure. *)
446 ListOfParam : List ; (* Contains a list of all the *)
447 (* parameters in this procedure. *)
448 HasVarArgs : BOOLEAN ; (* Does this proc type use ... ? *)
449 HasOptArg : BOOLEAN ; (* Does this procedure use [ ] ? *)
450 OptArgInit : CARDINAL ; (* The optarg initial value. *)
451 ReturnType : CARDINAL ; (* Return type for function. *)
452 ReturnOptional: BOOLEAN ; (* Is the return value optional? *)
453 ReturnTypeTok : CARDINAL ; (* Token of return type. *)
454 Scope : CARDINAL ; (* Scope of declaration. *)
455 Size : PtrToValue ; (* Runtime size of symbol. *)
456 TotalParamSize: PtrToValue ; (* size of all parameters. *)
457 oafamily : CARDINAL ; (* The oafamily for this sym *)
458 At : Where ; (* Where was sym declared/used *)
459 END ;
460
461 SymParam = RECORD
462 name : Name ; (* Index into name array, name *)
463 (* of param. *)
464 Type : CARDINAL ; (* Index to the type of param. *)
465 IsUnbounded : BOOLEAN ; (* Is it an ARRAY OF Type? *)
466 Scope : CARDINAL ; (* Procedure declaration. *)
467 ShadowVar : CARDINAL ; (* The local variable used to *)
468 (* shadow this parameter. *)
469 FullTok, (* name: type virtual token. *)
470 At : CARDINAL ; (* Where was sym declared. *)
471 END ;
472
473 SymVarParam = RECORD
474 name : Name ; (* Index into name array, name *)
475 (* of param. *)
476 Type : CARDINAL ;(* Index to the type of param. *)
477 IsUnbounded : BOOLEAN ; (* Is it an ARRAY OF Type? *)
478 HeapVar : CARDINAL ;(* The pointer value on heap. *)
479 (* Only used by static *)
480 (* analysis. *)
481 Scope : CARDINAL ;(* Procedure declaration. *)
482 ShadowVar : CARDINAL ;(* The local variable used to *)
483 (* shadow this parameter. *)
484 FullTok, (* name: type virtual token. *)
485 At : CARDINAL ;(* Where was sym declared. *)
486 END ;
487
488 ConstStringVariant = (m2str, cstr, m2nulstr, cnulstr) ;
489
490 SymConstString
491 = RECORD
492 name : Name ; (* Index into name array, name *)
493 (* of const. *)
494 Contents : Name ; (* Contents of the string. *)
495 Length : CARDINAL ; (* StrLen (Contents) *)
496 StringVariant : ConstStringVariant ;
497 Known : BOOLEAN ; (* Is Contents known? *)
498 Scope : CARDINAL ; (* Scope of declaration. *)
499 At : Where ; (* Where was sym declared/used *)
500 END ;
501
502 SymConstLit = RECORD
503 name : Name ; (* Index into name array, name *)
504 (* of const. *)
505 Value : PtrToValue ; (* Value of the constant. *)
506 Type : CARDINAL ; (* TYPE of constant, char etc *)
507 IsSet : BOOLEAN ; (* is the constant a set? *)
508 IsConstructor: BOOLEAN ; (* is it a constructor? *)
509 IsInternal : BOOLEAN ; (* Generated internally? *)
510 FromType : CARDINAL ; (* type is determined FromType *)
511 RangeError : BOOLEAN ; (* Have we reported an error? *)
512 UnresFromType: BOOLEAN ; (* is Type unresolved? *)
513 Scope : CARDINAL ; (* Scope of declaration. *)
514 At : Where ; (* Where was sym declared/used *)
515 END ;
516
517 SymConstVar = RECORD
518 name : Name ; (* Index into name array, name *)
519 (* of const. *)
520 Value : PtrToValue ; (* Value of the constant *)
521 Type : CARDINAL ; (* TYPE of constant, char etc *)
522 IsConditional, (* Is it the result of a *)
523 (* boolean conditional? *)
524 IsSet : BOOLEAN ; (* is the constant a set? *)
525 IsConstructor: BOOLEAN ; (* is the constant a set? *)
526 FromType : CARDINAL ; (* type is determined FromType *)
527 UnresFromType: BOOLEAN ; (* is Type resolved? *)
528 IsTemp : BOOLEAN ; (* is it a temporary? *)
529 Scope : CARDINAL ; (* Scope of declaration. *)
530 At : Where ; (* Where was sym declared/used *)
531 END ;
532
533 SymVar = RECORD
534 name : Name ; (* Index into name array, name *)
535 (* of const. *)
536 Type : CARDINAL ; (* Index to a type symbol. *)
537 BackType : CARDINAL ; (* specific back end symbol. *)
538 Size : PtrToValue ; (* Runtime size of symbol. *)
539 Offset : PtrToValue ; (* Offset at runtime of symbol *)
540 AddrMode : ModeOfAddr ; (* Type of Addressing mode. *)
541 Scope : CARDINAL ; (* Scope of declaration. *)
542 AtAddress : BOOLEAN ; (* Is declared at address? *)
543 Address : CARDINAL ; (* Address at which declared *)
544 IsComponentRef: BOOLEAN ; (* Is temporary referencing a *)
545 (* record field? *)
546 list : Indexing.Index ; (* the record and fields *)
547 IsConditional,
548 IsTemp : BOOLEAN ; (* Is variable a temporary? *)
549 IsParam : BOOLEAN ; (* Is variable a parameter? *)
550 IsPointerCheck: BOOLEAN ; (* Is variable used to *)
551 (* dereference a pointer? *)
552 IsWritten : BOOLEAN ; (* Is variable written to? *)
553 IsSSA : BOOLEAN ; (* Is variable a SSA? *)
554 IsConst : BOOLEAN ; (* Is variable read/only? *)
555 ArrayRef : BOOLEAN ; (* Is variable used to point *)
556 (* to an array? *)
557 Heap : BOOLEAN ; (* Is var on the heap? *)
558 InitState : LRInitDesc ; (* Initialization state. *)
559 Declared : VarDecl ; (* Var and type tokens. *)
560 At : Where ; (* Where was sym declared/used *)
561 ReadUsageList, (* list of var read quads *)
562 WriteUsageList: LRLists ; (* list of var write quads *)
563 END ;
564
565 SymType = RECORD
566 name : Name ; (* Index into name array, name *)
567 (* of type. *)
568 Type : CARDINAL ; (* Index to a type symbol. *)
569 IsHidden : BOOLEAN ; (* Was it declared as hidden? *)
570 ConstLitTree: SymbolTree ; (* constants of this type. *)
571 Size : PtrToValue ; (* Runtime size of symbol. *)
572 packedInfo : PackedInfo ; (* the equivalent packed type *)
573 oafamily : CARDINAL ; (* The oafamily for this sym *)
574 Align : CARDINAL ; (* The alignment of this type *)
575 Scope : CARDINAL ; (* Scope of declaration. *)
576 At : Where ; (* Where was sym declared/used *)
577 END ;
578
579 SymPointer
580 = RECORD
581 name : Name ; (* Index into name array, name *)
582 (* of pointer. *)
583 Type : CARDINAL ; (* Index to a type symbol. *)
584 Size : PtrToValue ; (* Runtime size of symbol. *)
585 Align : CARDINAL ; (* The alignment of this type *)
586 ConstLitTree: SymbolTree ; (* constants of this type. *)
587 oafamily : CARDINAL ; (* The oafamily for this sym *)
588 Scope : CARDINAL ; (* Scope of declaration. *)
589 At : Where ; (* Where was sym declared/used *)
590 END ;
591
592 SymRecordField =
593 RECORD
594 name : Name ; (* Index into name array, name *)
595 (* of record field. *)
596 Type : CARDINAL ; (* Index to a type symbol. *)
597 Tag : BOOLEAN ; (* is the record field really *)
598 (* a varient tag? *)
599 Size : PtrToValue ; (* Runtime size of symbol. *)
600 Offset : PtrToValue ; (* Offset at runtime of symbol *)
601 Parent : CARDINAL ; (* Index into symbol table to *)
602 (* determine the parent symbol *)
603 (* for this record field. Used *)
604 (* for BackPatching. *)
605 Varient : CARDINAL ; (* Index into symbol table to *)
606 (* determine the associated *)
607 (* varient symbol. *)
608 Align : CARDINAL ; (* The alignment of this type *)
609 Used : BOOLEAN ; (* pragma usused unsets this. *)
610 DeclPacked: BOOLEAN ; (* Is this declared packed? *)
611 DeclResolved: BOOLEAN ; (* has we resolved packed? *)
612 Scope : CARDINAL ; (* Scope of declaration. *)
613 At : Where ; (* Where was sym declared/used *)
614 END ;
615
616 SymVarientField =
617 RECORD
618 name : Name ; (* Index into name array, name *)
619 (* of varient field (internal) *)
620 Size : PtrToValue ; (* Runtime size of symbol. *)
621 Offset : PtrToValue ; (* Offset at runtime of symbol *)
622 Parent : CARDINAL ; (* Index into symbol table to *)
623 (* determine the parent symbol *)
624 (* for this record field. Used *)
625 (* for BackPatching. *)
626 Varient : CARDINAL ; (* Index into symbol table to *)
627 (* determine the associated *)
628 (* varient symbol. *)
629 ListOfSons: List ; (* Contains a list of the *)
630 (* RecordField symbols and *)
631 (* SymVarients *)
632 DeclPacked: BOOLEAN ; (* Is this varient field *)
633 (* packed? *)
634 DeclResolved: BOOLEAN ; (* is it resolved? *)
635 Scope : CARDINAL ; (* Scope of declaration. *)
636 At : Where ; (* Where was sym declared/used *)
637 END ;
638
639 SymEnumerationField =
640 RECORD
641 name : Name ; (* Index into name array, name *)
642 (* of enumeration field. *)
643 Value : PtrToValue ; (* Enumeration field value. *)
644 Type : CARDINAL ; (* Index to the enumeration. *)
645 Scope : CARDINAL ; (* Scope of declaration. *)
646 At : Where ; (* Where was sym declared/used *)
647 END ;
648
649 SymSet = RECORD
650 name : Name ; (* Index into name array, name *)
651 (* of set. *)
652 Type : CARDINAL ; (* Index to a type symbol. *)
653 (* (subrange or enumeration). *)
654 packedInfo: PackedInfo ; (* the equivalent packed type *)
655 ispacked : BOOLEAN ;
656 Size : PtrToValue ; (* Runtime size of symbol. *)
657 oafamily : CARDINAL ; (* The oafamily for this sym *)
658 Scope : CARDINAL ; (* Scope of declaration. *)
659 At : Where ; (* Where was sym declared/used *)
660 END ;
661
662 SymDefImp =
663 RECORD
664 name : Name ; (* Index into name array, name *)
665 (* of record field. *)
666 libname : Name ; (* Library (dialect) with module *)
667 ctors : ModuleCtor ; (* All the ctor functions. *)
668 DefListOfDep,
669 ModListOfDep : List ; (* Vector of SymDependency. *)
670 ExportQualifiedTree: SymbolTree ;
671 (* Holds all the export *)
672 (* Qualified identifiers. *)
673 (* This tree may be *)
674 (* deleted at the end of Pass 1. *)
675 ExportUnQualifiedTree: SymbolTree ;
676 (* Holds all the export *)
677 (* UnQualified identifiers. *)
678 (* This tree may be *)
679 (* deleted at the end of Pass 1. *)
680 ExportRequest : SymbolTree ; (* Contains all identifiers that *)
681 (* have been requested by other *)
682 (* modules before this module *)
683 (* declared its export list. *)
684 (* This tree should be empty at *)
685 (* the end of the compilation. *)
686 (* Each time a symbol is *)
687 (* exported it is removed from *)
688 (* this list. *)
689 IncludeList : List ; (* Contains all included symbols *)
690 (* which are included by *)
691 (* IMPORT modulename ; *)
692 (* modulename.Symbol *)
693 DefIncludeList: List ; (* Contains all included symbols *)
694 (* which are included by *)
695 (* IMPORT modulename ; *)
696 (* in the definition module only *)
697 ImportTree : SymbolTree ; (* Contains all IMPORTed *)
698 (* identifiers. *)
699 ExportUndeclared: SymbolTree ;
700 (* ExportUndeclared contains all *)
701 (* the identifiers which were *)
702 (* exported but have not yet *)
703 (* been declared. *)
704 NeedToBeImplemented: SymbolTree ;
705 (* NeedToBeImplemented contains *)
706 (* the identifiers which have *)
707 (* been exported and declared *)
708 (* but have not yet been *)
709 (* implemented. *)
710 LocalSymbols : SymbolTree ; (* The LocalSymbols hold all the *)
711 (* variables declared local to *)
712 (* the block. It contains the *)
713 (* IMPORT r ; *)
714 (* FROM _ IMPORT x, y, x ; *)
715 (* and also *)
716 (* MODULE WeAreHere ; *)
717 (* x y z visible by localsym *)
718 (* MODULE Inner ; *)
719 (* EXPORT x, y, z ; *)
720 (* END Inner ; *)
721 (* END WeAreHere. *)
722 EnumerationScopeList: List ; (* Enumeration scope list which *)
723 (* contains a list of all *)
724 (* enumerations which are *)
725 (* visible within this scope. *)
726 NamedObjects : SymbolTree ; (* Names of all items declared. *)
727 NamedImports : SymbolTree ; (* Names of items imported. *)
728 WhereImported : SymbolTree ; (* Sym to TokenNo where import *)
729 (* occurs. Error message use. *)
730 Priority : CARDINAL ; (* Priority of the module. This *)
731 (* is an index to a constant. *)
732 Unresolved : SymbolTree ; (* All symbols currently *)
733 (* unresolved in this module. *)
734 StartQuad : CARDINAL ; (* Signify the initialization *)
735 (* code. *)
736 EndQuad : CARDINAL ; (* EndQuad should point to a *)
737 (* goto quad. *)
738 StartFinishQuad: CARDINAL ; (* Signify the finalization *)
739 (* code. *)
740 EndFinishQuad : CARDINAL ; (* should point to a finish *)
741 FinallyFunction: tree ; (* The GCC function for finally *)
742 ExceptionFinally,
743 ExceptionBlock: BOOLEAN ; (* does it have an exception? *)
744 ContainsHiddenType: BOOLEAN ;(* True if this module *)
745 (* implements a hidden type. *)
746 ContainsBuiltin: BOOLEAN ; (* Does the module define a *)
747 (* builtin procedure? *)
748 ForC : BOOLEAN ; (* Is it a definition for "C" *)
749 NeedExportList: BOOLEAN ; (* Must user supply export list? *)
750 ModLink, (* Is the Def/Mod module parsed *)
751 DefLink : BOOLEAN ; (* for linkage only? *)
752 Builtin : BOOLEAN ; (* Is the module builtin? *)
753 ListOfVars : List ; (* List of variables in this *)
754 (* scope. *)
755 ListOfProcs : List ; (* List of all procedures *)
756 (* declared within this module. *)
757 ListOfModules : List ; (* List of all inner modules. *)
758 errorScope : ErrorScope ; (* The title scope. *)
759 At : Where ; (* Where was sym declared/used *)
760 END ;
761
762 SymModule =
763 RECORD
764 name : Name ; (* Index into name array, name *)
765 (* of record field. *)
766 libname : Name ; (* Library (dialect) with module *)
767 ctors : ModuleCtor ; (* All the ctor functions. *)
768 ModListOfDep : List ; (* Vector of SymDependency. *)
769 LocalSymbols : SymbolTree ; (* The LocalSymbols hold all the *)
770 (* variables declared local to *)
771 (* the block. It contains the *)
772 (* IMPORT r ; *)
773 (* FROM _ IMPORT x, y, x ; *)
774 (* and also *)
775 (* MODULE WeAreHere ; *)
776 (* x y z visible by localsym *)
777 (* MODULE Inner ; *)
778 (* EXPORT x, y, z ; *)
779 (* END Inner ; *)
780 (* END WeAreHere. *)
781 ExportTree : SymbolTree ; (* Holds all the exported *)
782 (* identifiers. *)
783 (* This tree may be *)
784 (* deleted at the end of Pass 1. *)
785 IncludeList : List ; (* Contains all included symbols *)
786 (* which are included by *)
787 (* IMPORT modulename ; *)
788 (* modulename.Symbol *)
789 ImportTree : SymbolTree ; (* Contains all IMPORTed *)
790 (* identifiers. *)
791 ExportUndeclared: SymbolTree ;
792 (* ExportUndeclared contains all *)
793 (* the identifiers which were *)
794 (* exported but have not yet *)
795 (* been declared. *)
796 EnumerationScopeList: List ; (* Enumeration scope list which *)
797 (* contains a list of all *)
798 (* enumerations which are *)
799 (* visable within this scope. *)
800 NamedObjects : SymbolTree ; (* Names of all items declared. *)
801 NamedImports : SymbolTree ; (* Names of items imported. *)
802 WhereImported : SymbolTree ; (* Sym to TokenNo where import *)
803 (* occurs. Error message use. *)
804 Scope : CARDINAL ; (* Scope of declaration. *)
805 Priority : CARDINAL ; (* Priority of the module. This *)
806 (* is an index to a constant. *)
807 Unresolved : SymbolTree ; (* All symbols currently *)
808 (* unresolved in this module. *)
809 StartQuad : CARDINAL ; (* Signify the initialization *)
810 (* code. *)
811 EndQuad : CARDINAL ; (* EndQuad should point to a *)
812 (* goto quad. *)
813 StartFinishQuad: CARDINAL ; (* Signify the finalization *)
814 (* code. *)
815 EndFinishQuad : CARDINAL ; (* should point to a finish *)
816 FinallyFunction: tree ; (* The GCC function for finally *)
817 ExceptionFinally,
818 ExceptionBlock: BOOLEAN ; (* does it have an exception? *)
819 ModLink : BOOLEAN ; (* Is the module parsed for *)
820 (* linkage only? *)
821 Builtin : BOOLEAN ; (* Is the module builtin? *)
822 ListOfVars : List ; (* List of variables in this *)
823 (* scope. *)
824 ListOfProcs : List ; (* List of all procedures *)
825 (* declared within this module. *)
826 ListOfModules : List ; (* List of all inner modules. *)
827 errorScope : ErrorScope ; (* The title scope. *)
828 At : Where ; (* Where was sym declared/used *)
829 END ;
830
831 SymDummy =
832 RECORD
833 NextFree : CARDINAL ; (* Link to the next free symbol. *)
834 END ;
835
836
837 Symbol = RECORD
838 CASE SymbolType : TypeOfSymbol OF
839 (* Determines the type of symbol *)
840
841 OAFamilySym : OAFamily : SymOAFamily |
842 ObjectSym : Object : SymObject |
843 EquivSym : Equiv : SymEquiv |
844 RecordSym : Record : SymRecord |
845 VarientSym : Varient : SymVarient |
846 VarSym : Var : SymVar |
847 EnumerationSym : Enumeration : SymEnumeration |
848 SubrangeSym : Subrange : SymSubrange |
849 SubscriptSym : Subscript : SymSubscript |
850 ArraySym : Array : SymArray |
851 UnboundedSym : Unbounded : SymUnbounded |
852 PartialUnboundedSym : PartialUnbounded : SymPartialUnbounded |
853 ConstVarSym : ConstVar : SymConstVar |
854 ConstLitSym : ConstLit : SymConstLit |
855 ConstStringSym : ConstString : SymConstString |
856 VarParamSym : VarParam : SymVarParam |
857 ParamSym : Param : SymParam |
858 ErrorSym : Error : SymError |
859 UndefinedSym : Undefined : SymUndefined |
860 TypeSym : Type : SymType |
861 PointerSym : Pointer : SymPointer |
862 RecordFieldSym : RecordField : SymRecordField |
863 VarientFieldSym : VarientField : SymVarientField |
864 EnumerationFieldSym : EnumerationField : SymEnumerationField |
865 DefImpSym : DefImp : SymDefImp |
866 ModuleSym : Module : SymModule |
867 SetSym : Set : SymSet |
868 ProcedureSym : Procedure : SymProcedure |
869 ProcTypeSym : ProcType : SymProcType |
870 ImportStatementSym : ImportStatement : SymImportStatement |
871 ImportSym : Import : SymImport |
872 GnuAsmSym : GnuAsm : SymGnuAsm |
873 InterfaceSym : Interface : SymInterface |
874 TupleSym : Tuple : SymTuple |
875 DummySym : Dummy : SymDummy
876
877 END
878 END ;
879
880 CallFrame = RECORD
881 Main : CARDINAL ; (* Main scope for insertions *)
882 Search: CARDINAL ; (* Search scope for symbol searches *)
883 Start : CARDINAL ; (* ScopePtr value before StartScope *)
884 (* was called. *)
885 END ;
886
887 PtrToSymbol = POINTER TO Symbol ;
888 PtrToCallFrame = POINTER TO CallFrame ;
889
890 CheckProcedure = PROCEDURE (CARDINAL) ;
891
892 VAR
893 Symbols : Indexing.Index ; (* ARRAY [1..MaxSymbols] OF Symbol. *)
894 ScopeCallFrame: Indexing.Index ; (* ARRAY [1..MaxScopes] OF CallFrame. *)
895 FreeSymbol : CARDINAL ; (* The next free symbol indice. *)
896 DefModuleTree : SymbolTree ;
897 ModuleTree : SymbolTree ; (* Tree of all modules ever used. *)
898 CurrentModule : CARDINAL ; (* Index into symbols determining the *)
899 (* current module being compiled. *)
900 (* This maybe an inner module. *)
901 MainModule : CARDINAL ; (* Index into symbols determining the *)
902 (* module the user requested to *)
903 (* compile. *)
904 FileModule : CARDINAL ; (* Index into symbols determining *)
905 (* which module (file) is being *)
906 (* compiled. (Maybe an import def) *)
907 ScopePtr : CARDINAL ; (* An index to the ScopeCallFrame. *)
908 (* ScopePtr determines the top of the *)
909 (* ScopeCallFrame. *)
910 BaseScopePtr : CARDINAL ; (* An index to the ScopeCallFrame of *)
911 (* the top of BaseModule. BaseModule *)
912 (* is always left at the bottom of *)
913 (* stack since it is used so *)
914 (* frequently. When the BaseModule *)
915 (* needs to be searched the ScopePtr *)
916 (* is temporarily altered to *)
917 (* BaseScopePtr and GetScopeSym is *)
918 (* called. *)
919 BaseModule : CARDINAL ; (* Index to the symbol table of the *)
920 (* Base pseudo modeule declaration. *)
921 TemporaryNo : CARDINAL ; (* The next temporary number. *)
922 CurrentError : Error ; (* Current error chain. *)
923 AddressTypes : List ; (* A list of type symbols which must *)
924 (* be declared as ADDRESS or pointer *)
925 UnresolvedConstructorType: List ; (* all constructors whose type *)
926 (* is not yet known. *)
927 AnonymousName : CARDINAL ; (* anonymous type name unique id *)
928 ReportedUnknowns : Set ; (* set of symbols already reported as *)
929 (* unknowns to the user. *)
930 ConstLitPoolTree : SymbolTree ; (* Pool of constants to ensure *)
931 (* constants are reused between *)
932 (* passes and reduce duplicate *)
933 (* errors. *)
934 ConstLitArray : Indexing.Index ;
935 BreakSym : CARDINAL ; (* Allows interactive debugging. *)
936
937
938 (*
939 CheckAnonymous - checks to see whether the name is NulName and if so
940 it creates a unique anonymous name.
941 *)
942
943 PROCEDURE CheckAnonymous (name: Name) : Name ;
944 BEGIN
945 IF name = NulName
946 THEN
947 INC (AnonymousName) ;
948 name := makekey (string (Mark (Sprintf1 (Mark (InitString ('__anon%d')), AnonymousName))))
949 END ;
950 RETURN name
951 END CheckAnonymous ;
952
953
954 (*
955 IsNameAnonymous - returns TRUE if the symbol, sym, has an anonymous name
956 or no name.
957 *)
958
959 PROCEDURE IsNameAnonymous (sym: CARDINAL) : BOOLEAN ;
960 VAR
961 a: ARRAY [0..5] OF CHAR ;
962 n: Name ;
963 BEGIN
964 n := GetSymName(sym) ;
965 IF n=NulName
966 THEN
967 RETURN( TRUE )
968 ELSE
969 GetKey(n, a) ;
970 RETURN( StrEqual(a, '__anon') )
971 END
972 END IsNameAnonymous ;
973
974
975 (*
976 InitWhereDeclared - sets the Declared and FirstUsed fields of record, at.
977 *)
978
979 PROCEDURE InitWhereDeclaredTok (tok: CARDINAL; VAR at: Where) ;
980 BEGIN
981 WITH at DO
982 IF CompilingDefinitionModule ()
983 THEN
984 DefDeclared := tok ;
985 ModDeclared := UnknownTokenNo
986 ELSE
987 DefDeclared := UnknownTokenNo ;
988 ModDeclared := tok
989 END ;
990 FirstUsed := tok (* we assign this field to something legal *)
991 END
992 END InitWhereDeclaredTok ;
993
994
995 (*
996 InitWhereDeclared - sets the Declared and FirstUsed fields of record, at.
997 *)
998
999 PROCEDURE InitWhereDeclared (VAR at: Where) ;
1000 BEGIN
1001 InitWhereDeclaredTok (GetTokenNo (), at)
1002 END InitWhereDeclared ;
1003
1004
1005 (*
1006 InitWhereFirstUsed - sets the FirstUsed field of record, at.
1007 *)
1008
1009 PROCEDURE InitWhereFirstUsed (VAR at: Where) ;
1010 BEGIN
1011 InitWhereFirstUsedTok (GetTokenNo (), at)
1012 END InitWhereFirstUsed ;
1013
1014
1015 (*
1016 InitWhereFirstUsedTok - sets the FirstUsed field of record, at.
1017 *)
1018
1019 PROCEDURE InitWhereFirstUsedTok (tok: CARDINAL; VAR at: Where) ;
1020 BEGIN
1021 WITH at DO
1022 FirstUsed := tok
1023 END
1024 END InitWhereFirstUsedTok ;
1025
1026
1027 (*
1028 FinalSymbol - returns the highest number symbol used.
1029 *)
1030
1031 PROCEDURE FinalSymbol () : CARDINAL ;
1032 BEGIN
1033 RETURN( FreeSymbol-1 )
1034 END FinalSymbol ;
1035
1036
1037 (*
1038 gdbhook - a debugger convenience hook.
1039 *)
1040
1041 PROCEDURE gdbhook ;
1042 END gdbhook ;
1043
1044
1045 (*
1046 BreakWhenSymCreated - to be called interactively by gdb.
1047 *)
1048
1049 PROCEDURE BreakWhenSymCreated (sym: CARDINAL) ;
1050 BEGIN
1051 BreakSym := sym
1052 END BreakWhenSymCreated ;
1053
1054
1055 (*
1056 CheckBreak - if sym = BreakSym then call gdbhook.
1057 *)
1058
1059 PROCEDURE CheckBreak (sym: CARDINAL) ;
1060 BEGIN
1061 IF sym = BreakSym
1062 THEN
1063 gdbhook
1064 END
1065 END CheckBreak ;
1066
1067
1068 (*
1069 NewSym - Sets Sym to a new symbol index.
1070 *)
1071
1072 PROCEDURE NewSym (VAR sym: CARDINAL) ;
1073 VAR
1074 pSym: PtrToSymbol ;
1075 BEGIN
1076 sym := FreeSymbol ;
1077 NEW(pSym) ;
1078 WITH pSym^ DO
1079 SymbolType := DummySym
1080 END ;
1081 PutIndice(Symbols, sym, pSym) ;
1082 CheckBreak (sym) ;
1083 INC(FreeSymbol)
1084 END NewSym ;
1085
1086
1087 (*
1088 GetPsym - returns the pointer to, sym.
1089 *)
1090
1091 PROCEDURE GetPsym (sym: CARDINAL) : PtrToSymbol ;
1092 VAR
1093 pSym: PtrToSymbol ;
1094 BEGIN
1095 IF InBounds(Symbols, sym)
1096 THEN
1097 pSym := GetIndice(Symbols, sym) ;
1098 RETURN( pSym )
1099 ELSE
1100 InternalError ('symbol out of bounds')
1101 END
1102 END GetPsym ;
1103
1104
1105 (*
1106 GetPcall - returns the pointer to the CallFrame.
1107 *)
1108
1109 PROCEDURE GetPcall (call: CARDINAL) : PtrToCallFrame ;
1110 VAR
1111 pCall: PtrToCallFrame ;
1112 BEGIN
1113 IF InBounds(ScopeCallFrame, call)
1114 THEN
1115 pCall := GetIndice(ScopeCallFrame, call) ;
1116 RETURN( pCall )
1117 ELSE
1118 InternalError ('symbol out of bounds')
1119 END
1120 END GetPcall ;
1121
1122
1123 (*
1124 MakeImport - create and return an import symbol.
1125 moduleSym is the symbol being imported.
1126 isqualified is FALSE if it were IMPORT modulename and
1127 TRUE for the qualified FROM modulename IMPORT etc.
1128 listno is the import list count for this module.
1129 tok should match this modulename position.
1130 *)
1131
1132 PROCEDURE MakeImport (tok: CARDINAL;
1133 moduleSym: CARDINAL;
1134 listno: CARDINAL;
1135 isqualified: BOOLEAN) : CARDINAL ;
1136 VAR
1137 importSym: CARDINAL ;
1138 pSym : PtrToSymbol ;
1139 BEGIN
1140 NewSym (importSym) ;
1141 pSym := GetPsym (importSym) ;
1142 WITH pSym^ DO
1143 SymbolType := ImportSym ;
1144 WITH Import DO
1145 module := moduleSym ;
1146 listNo := listno ;
1147 qualified := isqualified ;
1148 InitWhereDeclaredTok (tok, at)
1149 END
1150 END ;
1151 RETURN importSym
1152 END MakeImport ;
1153
1154
1155 (*
1156 MakeImportStatement - return a dependent symbol which represents an import statement
1157 or a qualified import statement. The tok should either match
1158 the FROM token or the IMPORT token. listno is the import list
1159 count for the module.
1160 *)
1161
1162 PROCEDURE MakeImportStatement (tok: CARDINAL; listno: CARDINAL) : CARDINAL ;
1163 VAR
1164 dependentSym: CARDINAL ;
1165 pSym : PtrToSymbol ;
1166 BEGIN
1167 NewSym (dependentSym) ;
1168 pSym := GetPsym (dependentSym) ;
1169 WITH pSym^ DO
1170 SymbolType := ImportStatementSym ;
1171 WITH ImportStatement DO
1172 listNo := listno ;
1173 InitList (ListOfImports) ;
1174 InitWhereDeclaredTok (tok, at)
1175 END
1176 END ;
1177 RETURN dependentSym
1178 END MakeImportStatement ;
1179
1180
1181 (*
1182 AppendModuleImportStatement - appends the ImportStatement symbol onto the
1183 module import list.
1184
1185 For example:
1186
1187 FROM x IMPORT y, z ;
1188 ^^^^
1189
1190 also:
1191
1192 IMPORT p, q, r;
1193 ^^^^^^
1194 will result in a new ImportStatement symbol added
1195 to the current module import list.
1196 The statement symbol is expected to be created
1197 by MakeImportStatement using the token positions
1198 outlined above.
1199 *)
1200
1201 PROCEDURE AppendModuleImportStatement (module, statement: CARDINAL) ;
1202 VAR
1203 pSym: PtrToSymbol ;
1204 BEGIN
1205 IF IsDefImp (module)
1206 THEN
1207 pSym := GetPsym (module) ;
1208 IF CompilingDefinitionModule ()
1209 THEN
1210 IncludeItemIntoList (pSym^.DefImp.DefListOfDep, statement)
1211 ELSE
1212 IncludeItemIntoList (pSym^.DefImp.ModListOfDep, statement)
1213 END
1214 ELSIF IsModule (module)
1215 THEN
1216 pSym := GetPsym (module) ;
1217 IncludeItemIntoList (pSym^.Module.ModListOfDep, statement)
1218 ELSE
1219 InternalError ('expecting DefImp or Module symbol')
1220 END
1221 END AppendModuleImportStatement ;
1222
1223
1224 (*
1225 AppendModuleOnImportStatement - appends the import symbol onto the
1226 dependent list (chain).
1227
1228 For example each:
1229
1230 FROM x IMPORT y, z ;
1231 ^
1232 x are added to the dependent list.
1233
1234 also:
1235
1236 IMPORT p, q, r;
1237 ^ ^ ^
1238 will result in p, q and r added to
1239 to the dependent list.
1240
1241 The import symbol is created by MakeImport
1242 and the token is expected to match the module
1243 name position outlined above.
1244 *)
1245
1246 PROCEDURE AppendModuleOnImportStatement (module, import: CARDINAL) ;
1247 VAR
1248 l : List ;
1249 lastImportStatement: CARDINAL ;
1250 BEGIN
1251 Assert (IsImport (import)) ;
1252 IF CompilingDefinitionModule ()
1253 THEN
1254 l := GetModuleDefImportStatementList (module)
1255 ELSE
1256 l := GetModuleModImportStatementList (module)
1257 END ;
1258 Assert (l # NIL) ;
1259 Assert (NoOfItemsInList (l) > 0) ; (* There should always be one on the list. *)
1260 lastImportStatement := GetItemFromList (l, NoOfItemsInList (l)) ;
1261 Assert (IsImportStatement (lastImportStatement)) ;
1262 l := GetImportStatementList (lastImportStatement) ;
1263 IncludeItemIntoList (l, import)
1264 END AppendModuleOnImportStatement ;
1265
1266
1267 (*
1268 IsImport - returns TRUE if sym is an import symbol.
1269 *)
1270
1271 PROCEDURE IsImport (sym: CARDINAL) : BOOLEAN ;
1272 VAR
1273 pSym: PtrToSymbol ;
1274 BEGIN
1275 pSym := GetPsym (sym) ;
1276 RETURN pSym^.SymbolType=ImportSym
1277 END IsImport ;
1278
1279
1280 (*
1281 IsImportStatement - returns TRUE if sym is a dependent symbol.
1282 *)
1283
1284 PROCEDURE IsImportStatement (sym: CARDINAL) : BOOLEAN ;
1285 VAR
1286 pSym: PtrToSymbol ;
1287 BEGIN
1288 pSym := GetPsym (sym) ;
1289 RETURN pSym^.SymbolType=ImportStatementSym
1290 END IsImportStatement ;
1291
1292
1293 (*
1294 GetImportModule - returns the module associated with the import symbol.
1295 *)
1296
1297 PROCEDURE GetImportModule (sym: CARDINAL) : CARDINAL ;
1298 VAR
1299 pSym: PtrToSymbol ;
1300 BEGIN
1301 Assert (IsImport (sym)) ;
1302 pSym := GetPsym (sym) ;
1303 RETURN pSym^.Import.module
1304 END GetImportModule ;
1305
1306
1307 (*
1308 GetImportDeclared - returns the token associated with the import symbol.
1309 *)
1310
1311 PROCEDURE GetImportDeclared (sym: CARDINAL) : CARDINAL ;
1312 VAR
1313 tok : CARDINAL ;
1314 BEGIN
1315 Assert (IsImport (sym)) ;
1316 tok := GetDeclaredDefinition (sym) ;
1317 IF tok = UnknownTokenNo
1318 THEN
1319 RETURN GetDeclaredModule (sym)
1320 END ;
1321 RETURN tok
1322 END GetImportDeclared ;
1323
1324
1325 (*
1326 GetImportStatementList - returns the list of imports for this dependent.
1327 Each import symbol corresponds to a module.
1328 *)
1329
1330 PROCEDURE GetImportStatementList (sym: CARDINAL) : List ;
1331 VAR
1332 pSym: PtrToSymbol ;
1333 BEGIN
1334 Assert (IsImportStatement (sym)) ;
1335 pSym := GetPsym (sym) ;
1336 RETURN pSym^.ImportStatement.ListOfImports
1337 END GetImportStatementList ;
1338
1339
1340 (*
1341 GetModuleDefImportStatementList - returns the list of dependents associated with
1342 the definition module.
1343 *)
1344
1345 PROCEDURE GetModuleDefImportStatementList (sym: CARDINAL) : List ;
1346 VAR
1347 pSym: PtrToSymbol ;
1348 BEGIN
1349 Assert (IsModule (sym) OR IsDefImp (sym)) ;
1350 IF IsDefImp (sym)
1351 THEN
1352 pSym := GetPsym (sym) ;
1353 RETURN pSym^.DefImp.DefListOfDep
1354 END ;
1355 RETURN NIL
1356 END GetModuleDefImportStatementList ;
1357
1358
1359 (*
1360 GetModuleModImportStatementList - returns the list of dependents associated with
1361 the implementation or program module.
1362 *)
1363
1364 PROCEDURE GetModuleModImportStatementList (sym: CARDINAL) : List ;
1365 VAR
1366 pSym: PtrToSymbol ;
1367 BEGIN
1368 Assert (IsModule (sym) OR IsDefImp (sym)) ;
1369 pSym := GetPsym (sym) ;
1370 IF IsDefImp (sym)
1371 THEN
1372 RETURN pSym^.DefImp.ModListOfDep
1373 ELSE
1374 RETURN pSym^.Module.ModListOfDep
1375 END
1376 END GetModuleModImportStatementList ;
1377
1378
1379 (*
1380 DebugProcedureLineNumber -
1381 *)
1382
1383 PROCEDURE DebugProcedureLineNumber (sym: CARDINAL) ;
1384 VAR
1385 begin, end: CARDINAL ;
1386 n : Name ;
1387 f : String ;
1388 l : CARDINAL ;
1389 BEGIN
1390 GetProcedureBeginEnd (sym, begin, end) ;
1391 n := GetSymName(sym) ;
1392 IF begin#0
1393 THEN
1394 f := FindFileNameFromToken (begin, 0) ;
1395 l := TokenToLineNo(begin, 0) ;
1396 printf3 ('%s:%d:%a:begin\n', f, l, n)
1397 END ;
1398 IF end#0
1399 THEN
1400 f := FindFileNameFromToken (end, 0) ;
1401 l := TokenToLineNo(end, 0) ;
1402 printf3 ('%s:%d:%a:end\n', f, l, n)
1403 END
1404 END DebugProcedureLineNumber ;
1405
1406
1407 (*
1408 DebugLineNumbers - internal debugging, emit all procedure names in this module
1409 together with the line numbers for the corresponding begin/end
1410 tokens.
1411 *)
1412
1413 PROCEDURE DebugLineNumbers (sym: CARDINAL) ;
1414 BEGIN
1415 IF GetDebugFunctionLineNumbers ()
1416 THEN
1417 printf0 ('<lines>\n') ;
1418 ForeachProcedureDo(sym, DebugProcedureLineNumber) ;
1419 printf0 ('</lines>\n')
1420 END
1421 END DebugLineNumbers ;
1422
1423
1424 (*
1425 IsPartialUnbounded - returns TRUE if, sym, is a partially unbounded symbol.
1426 *)
1427
1428 PROCEDURE IsPartialUnbounded (sym: CARDINAL) : BOOLEAN ;
1429 VAR
1430 pSym: PtrToSymbol ;
1431 BEGIN
1432 IF sym>0
1433 THEN
1434 pSym := GetPsym(sym) ;
1435 WITH pSym^ DO
1436 CASE SymbolType OF
1437
1438 PartialUnboundedSym: RETURN( TRUE )
1439
1440 ELSE
1441 RETURN( FALSE )
1442 END
1443 END
1444 ELSE
1445 RETURN( FALSE )
1446 END
1447 END IsPartialUnbounded ;
1448
1449
1450 (*
1451 PutPartialUnbounded -
1452 *)
1453
1454 PROCEDURE PutPartialUnbounded (sym: CARDINAL; type: CARDINAL; ndim: CARDINAL) ;
1455 VAR
1456 pSym: PtrToSymbol ;
1457 BEGIN
1458 pSym := GetPsym(sym) ;
1459 IF IsDummy(sym)
1460 THEN
1461 pSym^.SymbolType := PartialUnboundedSym
1462 END ;
1463 WITH pSym^ DO
1464 CASE SymbolType OF
1465
1466 PartialUnboundedSym: PartialUnbounded.Type := type ;
1467 PartialUnbounded.NDim := ndim
1468
1469 ELSE
1470 InternalError ('not expecting this type')
1471 END
1472 END
1473 END PutPartialUnbounded ;
1474
1475
1476 (*
1477 AlreadyDeclaredError - generate an error message, a, and two areas of code showing
1478 the places where the symbols were declared.
1479 *)
1480
1481 PROCEDURE AlreadyDeclaredError (s: String; name: Name; OtherOccurance: CARDINAL) ;
1482 VAR
1483 e: Error ;
1484 BEGIN
1485 IF (OtherOccurance=0) OR (OtherOccurance=GetTokenNo())
1486 THEN
1487 e := NewError(GetTokenNo()) ;
1488 ErrorString(e, s)
1489 ELSE
1490 e := NewError(GetTokenNo()) ;
1491 ErrorString(e, s) ;
1492 e := ChainError(OtherOccurance, e) ;
1493 ErrorFormat1(e, 'and symbol (%a) is also declared here', name)
1494 END
1495 END AlreadyDeclaredError ;
1496
1497
1498 (*
1499 AlreadyImportedError - generate an error message, a, and two areas of code showing
1500 the places where the symbols was imported and also declared.
1501 *)
1502
1503 (*
1504 PROCEDURE AlreadyImportedError (s: String; name: Name; OtherOccurance: CARDINAL) ;
1505 VAR
1506 e: Error ;
1507 BEGIN
1508 IF (OtherOccurance=0) OR (OtherOccurance=GetTokenNo())
1509 THEN
1510 e := NewError(GetTokenNo()) ;
1511 ErrorString(e, s)
1512 ELSE
1513 e := NewError(GetTokenNo()) ;
1514 ErrorString(e, s) ;
1515 e := ChainError(OtherOccurance, e) ;
1516 ErrorFormat1(e, 'and symbol (%a) was also seen here', name)
1517 END
1518 END AlreadyImportedError ;
1519 *)
1520
1521
1522 (*
1523 MakeError - creates an error node, which can be used in MetaError messages.
1524 It will be removed from ExportUndeclared and Unknown trees.
1525 *)
1526
1527 PROCEDURE MakeError (tok: CARDINAL; name: Name) : CARDINAL ;
1528 VAR
1529 pSym: PtrToSymbol ;
1530 Sym : CARDINAL ;
1531 BEGIN
1532 (* if Sym is present on the unknown tree then remove it *)
1533 Sym := FetchUnknownSym (name) ;
1534 IF Sym=NulSym
1535 THEN
1536 NewSym(Sym)
1537 ELSE
1538 (*
1539 remove symbol from this tree as we have already generated
1540 a meaningful error message
1541 *)
1542 RemoveExportUndeclared(GetCurrentModuleScope(), Sym)
1543 END ;
1544 pSym := GetPsym(Sym) ;
1545 WITH pSym^ DO
1546 SymbolType := ErrorSym ;
1547 Error.name := name ;
1548 Error.Scope := GetCurrentScope () ;
1549 InitWhereDeclaredTok(tok, Error.At) ;
1550 InitWhereFirstUsedTok(tok, Error.At)
1551 END ;
1552 RETURN( Sym )
1553 END MakeError ;
1554
1555
1556 (*
1557 MakeErrorS - creates an error node from a string, which can be used
1558 in MetaError messages.
1559 It will be removed from ExportUndeclared and Unknown trees.
1560 *)
1561
1562 PROCEDURE MakeErrorS (tok: CARDINAL; name: String) : CARDINAL ;
1563 BEGIN
1564 RETURN MakeError (tok, makekey (string (name)))
1565 END MakeErrorS ;
1566
1567
1568 (*
1569 IsError - returns TRUE if the symbol is an error symbol.
1570 *)
1571
1572 PROCEDURE IsError (Sym: CARDINAL) : BOOLEAN ;
1573 VAR
1574 pSym: PtrToSymbol ;
1575 BEGIN
1576 AssertInRange(Sym) ;
1577 pSym := GetPsym(Sym) ;
1578 RETURN( pSym^.SymbolType=ErrorSym )
1579 END IsError ;
1580
1581
1582 (*
1583 MakeObject - creates an object node.
1584 *)
1585
1586 PROCEDURE MakeObject (name: Name) : CARDINAL ;
1587 VAR
1588 pSym: PtrToSymbol ;
1589 Sym : CARDINAL ;
1590 BEGIN
1591 NewSym(Sym) ;
1592 pSym := GetPsym(Sym) ;
1593 WITH pSym^ DO
1594 SymbolType := ObjectSym ;
1595 Object.name := name ;
1596 InitWhereDeclared(Object.At) ;
1597 InitWhereFirstUsed(Object.At)
1598 END ;
1599 RETURN( Sym )
1600 END MakeObject ;
1601
1602
1603 (*
1604 IsTuple - returns TRUE if the symbol is a tuple symbol.
1605 *)
1606
1607 PROCEDURE IsTuple (Sym: CARDINAL) : BOOLEAN ;
1608 VAR
1609 pSym: PtrToSymbol ;
1610 BEGIN
1611 AssertInRange(Sym) ;
1612 pSym := GetPsym(Sym) ;
1613 RETURN( pSym^.SymbolType=TupleSym )
1614 END IsTuple ;
1615
1616
1617 (*
1618 IsObject - returns TRUE if the symbol is an object symbol.
1619 *)
1620
1621 PROCEDURE IsObject (Sym: CARDINAL) : BOOLEAN ;
1622 VAR
1623 pSym: PtrToSymbol ;
1624 BEGIN
1625 AssertInRange(Sym) ;
1626 pSym := GetPsym(Sym) ;
1627 RETURN( pSym^.SymbolType=ObjectSym )
1628 END IsObject ;
1629
1630
1631 (*
1632 DeclareSym - returns a symbol which was either in the unknown tree or
1633 a New symbol, since name is about to be declared.
1634 *)
1635
1636 PROCEDURE DeclareSym (tok: CARDINAL; name: Name) : CARDINAL ;
1637 VAR
1638 Sym: CARDINAL ;
1639 BEGIN
1640 IF name = NulName
1641 THEN
1642 NewSym (Sym)
1643 ELSIF IsAlreadyDeclaredSym (name)
1644 THEN
1645 Sym := GetSym (name) ;
1646 IF IsImported (GetCurrentModuleScope (), Sym)
1647 THEN
1648 MetaErrorT1 (GetWhereImported(Sym),
1649 'symbol {%1Rad} is already present in this scope, check both definition and implementation modules, use a different name or remove the import',
1650 Sym) ;
1651 MetaErrorT1 (tok, 'symbol {%1Cad} also declared in this module', Sym) ;
1652 IF Sym # GetVisibleSym (name)
1653 THEN
1654 MetaErrorT1 (tok, 'symbol {%1CMad} also declared in this module', GetVisibleSym (name))
1655 END
1656 ELSE
1657 MetaErrorT1 (tok, 'symbol {%1RMad} is already declared in this scope, use a different name or remove the declaration', Sym) ;
1658 MetaErrorT1 (tok, 'symbol {%1Cad} also declared in this module', Sym) ;
1659 IF Sym # GetVisibleSym(name)
1660 THEN
1661 MetaErrorT1(tok, 'symbol {%1CMad} also declared in this module', GetVisibleSym (name))
1662 END
1663 END ;
1664 Sym := MakeError (tok, name)
1665 ELSE
1666 Sym := FetchUnknownSym (name) ;
1667 IF Sym=NulSym
1668 THEN
1669 NewSym (Sym)
1670 END ;
1671 CheckForExportedDeclaration (Sym)
1672 END ;
1673 RETURN Sym
1674 END DeclareSym ;
1675
1676
1677 (*
1678 Init - Initializes the data structures and variables in this module.
1679 Initialize the trees.
1680 *)
1681
1682 PROCEDURE Init ;
1683 VAR
1684 pCall: PtrToCallFrame ;
1685 BEGIN
1686 BreakWhenSymCreated (NulSym) ; (* Disable the intereactive sym watch. *)
1687 (* To examine the symbol table when a symbol is created run cc1gm2 from gdb
1688 and set a break point on gdbhook.
1689 (gdb) break gdbhook
1690 (gdb) run
1691 Now below interactively call BreakWhenSymCreated with the symbol
1692 under investigation. *)
1693 gdbhook ;
1694 (* Now is the time to interactively call gdb, for example:
1695 (gdb) print BreakWhenSymCreated (1234)
1696 (gdb) cont
1697 and you will arrive at gdbhook when this symbol is created. *)
1698 AnonymousName := 0 ;
1699 CurrentError := NIL ;
1700 InitTree (ConstLitPoolTree) ;
1701 InitTree (DefModuleTree) ;
1702 InitTree (ModuleTree) ;
1703 Symbols := InitIndexTuned (1, 1024*1024 DIV 16, 16) ;
1704 ConstLitArray := InitIndex (1) ;
1705 FreeSymbol := 1 ;
1706 ScopePtr := 1 ;
1707 ScopeCallFrame := InitIndex(1) ;
1708 NEW(pCall) ;
1709 WITH pCall^ DO
1710 Main := NulSym ;
1711 Search := NulSym
1712 END ;
1713 PutIndice(ScopeCallFrame, ScopePtr, pCall) ;
1714 CurrentModule := NulSym ;
1715 MainModule := NulSym ;
1716 FileModule := NulSym ;
1717 TemporaryNo := 0 ;
1718 (*
1719 InitList(FreeFVarientList) ; (* Lists used to maintain GC of field *)
1720 InitList(UsedFVarientList) ; (* varients. *)
1721 *)
1722 InitList(UnresolvedConstructorType) ;
1723
1724 InitBase(BuiltinsLocation(), BaseModule) ;
1725 StartScope(BaseModule) ; (* BaseModule scope placed at the bottom of the stack *)
1726 BaseScopePtr := ScopePtr ; (* BaseScopePtr points to the top of the BaseModule scope *)
1727 InitList(AddressTypes) ;
1728 ReportedUnknowns := InitSet(1)
1729 END Init ;
1730
1731
1732 (*
1733 FromModuleGetSym - attempts to find a symbol of name, n, in the
1734 module, mod, scope. An unknown symbol is created
1735 at token position tok if necessary.
1736 *)
1737
1738 PROCEDURE FromModuleGetSym (tok: CARDINAL; n: Name; mod: CARDINAL) : CARDINAL ;
1739 VAR
1740 n1 : Name ;
1741 sym : CARDINAL ;
1742 OldScopePtr: CARDINAL ;
1743 BEGIN
1744 OldScopePtr := ScopePtr ;
1745 StartScope (mod) ;
1746 sym := RequestSym (tok, n) ;
1747 EndScope ;
1748 IF sym=NulSym
1749 THEN
1750 (* --fixme-- can sym ever be NulSym? *)
1751 n1 := GetSymName(mod) ;
1752 WriteFormat2('cannot find procedure %a in module, %a',
1753 n, n1)
1754 END ;
1755 ScopePtr := OldScopePtr ;
1756 RETURN( sym )
1757 END FromModuleGetSym ;
1758
1759
1760 (*
1761 AddSymToUnknown -
1762 *)
1763
1764 PROCEDURE AddSymToUnknown (scope: CARDINAL; name: Name; Sym: CARDINAL) ;
1765 VAR
1766 pSym: PtrToSymbol ;
1767 n : Name ;
1768 BEGIN
1769 IF DebugUnknowns
1770 THEN
1771 n := GetSymName(scope) ;
1772 printf3('adding unknown %a (%d) to scope %a\n', name, Sym, n)
1773 END ;
1774
1775 (* Add symbol to unknown tree *)
1776 pSym := GetPsym(scope) ;
1777 WITH pSym^ DO
1778 CASE SymbolType OF
1779
1780 DefImpSym : PutSymKey(DefImp.Unresolved, name, Sym) |
1781 ModuleSym : PutSymKey(Module.Unresolved, name, Sym) |
1782 ProcedureSym: PutSymKey(Procedure.Unresolved, name, Sym)
1783
1784 ELSE
1785 InternalError ('expecting DefImp, Module or Procedure symbol')
1786 END
1787 END
1788 END AddSymToUnknown ;
1789
1790
1791 (*
1792 AddSymToUnknownTree - adds a symbol with name, name, and Sym to the
1793 unknown tree.
1794 *)
1795
1796 PROCEDURE AddSymToUnknownTree (ScopeId: INTEGER; name: Name; Sym: CARDINAL) ;
1797 VAR
1798 pCall : PtrToCallFrame ;
1799 ScopeSym: CARDINAL ;
1800 BEGIN
1801 IF ScopeId>0
1802 THEN
1803 (* choose to place the unknown symbol in the first module scope
1804 outside the current scope *)
1805 REPEAT
1806 pCall := GetPcall(ScopeId) ;
1807 ScopeSym := pCall^.Main ;
1808 IF (ScopeSym>0) AND (IsDefImp(ScopeSym) OR IsModule(ScopeSym))
1809 THEN
1810 AddSymToUnknown(ScopeSym, name, Sym) ;
1811 RETURN
1812 END ;
1813 DEC(ScopeId)
1814 UNTIL ScopeId=0
1815 END ;
1816 AddSymToUnknown(CurrentModule, name, Sym)
1817 END AddSymToUnknownTree ;
1818
1819
1820 (*
1821 SubSymFromUnknownTree - removes a symbol with name, name, from the
1822 unknown tree.
1823 *)
1824
1825 PROCEDURE SubSymFromUnknownTree (name: Name) ;
1826 VAR
1827 pCall : PtrToCallFrame ;
1828 ScopeSym,
1829 ScopeId : CARDINAL ;
1830 BEGIN
1831 IF ScopePtr>0
1832 THEN
1833 ScopeId := ScopePtr ;
1834 REPEAT
1835 pCall := GetPcall(ScopeId) ;
1836 ScopeSym := pCall^.Search ;
1837 IF IsModule(ScopeSym) OR IsDefImp(ScopeSym) OR IsProcedure(ScopeSym)
1838 THEN
1839 IF RemoveFromUnresolvedTree(ScopeSym, name)
1840 THEN
1841 RETURN
1842 END
1843 END ;
1844 DEC(ScopeId) ;
1845 UNTIL (ScopeId>0) AND (IsModule(ScopeSym) OR IsDefImp(ScopeSym))
1846 END ;
1847 IF RemoveFromUnresolvedTree(CurrentModule, name)
1848 THEN
1849 END
1850 END SubSymFromUnknownTree ;
1851
1852
1853 (*
1854 GetSymFromUnknownTree - returns a symbol with name, name, from the
1855 unknown tree.
1856 If no symbol with name is found then NulSym
1857 is returned.
1858 *)
1859
1860 PROCEDURE GetSymFromUnknownTree (name: Name) : CARDINAL ;
1861 VAR
1862 pCall : PtrToCallFrame ;
1863 ScopeSym,
1864 ScopeId ,
1865 Sym : CARDINAL ;
1866 BEGIN
1867 IF ScopePtr>0
1868 THEN
1869 ScopeId := ScopePtr ;
1870 REPEAT
1871 pCall := GetPcall(ScopeId) ;
1872 ScopeSym := pCall^.Search ;
1873 IF IsModule(ScopeSym) OR IsDefImp(ScopeSym) OR IsProcedure(ScopeSym)
1874 THEN
1875 Sym := ExamineUnresolvedTree(ScopeSym, name) ;
1876 IF Sym#NulSym
1877 THEN
1878 RETURN( Sym )
1879 END
1880 END ;
1881 DEC(ScopeId) ;
1882 UNTIL (ScopeId>0) AND (IsModule(ScopeSym) OR IsDefImp(ScopeSym))
1883 END ;
1884 (* Get symbol from unknown tree *)
1885 RETURN( ExamineUnresolvedTree(CurrentModule, name) )
1886 END GetSymFromUnknownTree ;
1887
1888
1889 (*
1890 ExamineUnresolvedTree - returns a symbol with name, name, from the
1891 unresolved tree of module, ModSym.
1892 If no symbol with name is found then NulSym
1893 is returned.
1894 *)
1895
1896 PROCEDURE ExamineUnresolvedTree (ScopeSym: CARDINAL; name: Name) : CARDINAL ;
1897 VAR
1898 pSym: PtrToSymbol ;
1899 Sym : CARDINAL ;
1900 BEGIN
1901 (* Get symbol from unknown tree *)
1902 pSym := GetPsym(ScopeSym) ;
1903 WITH pSym^ DO
1904 CASE SymbolType OF
1905
1906 DefImpSym : Sym := GetSymKey(DefImp.Unresolved, name) |
1907 ModuleSym : Sym := GetSymKey(Module.Unresolved, name) |
1908 ProcedureSym: Sym := GetSymKey(Procedure.Unresolved, name)
1909
1910 ELSE
1911 InternalError ('expecting DefImp, Module or Procedure symbol')
1912 END
1913 END ;
1914 RETURN( Sym )
1915 END ExamineUnresolvedTree ;
1916
1917
1918 (*
1919 TryMoveUndeclaredSymToInnerModule - attempts to move a symbol of
1920 name, name, which is
1921 currently undefined in the
1922 outer scope to the inner scope.
1923 If successful then the symbol is
1924 returned otherwise NulSym is
1925 returned.
1926 *)
1927
1928 PROCEDURE TryMoveUndeclaredSymToInnerModule (OuterScope,
1929 InnerScope: CARDINAL;
1930 name: Name) : CARDINAL ;
1931 VAR
1932 pSym: PtrToSymbol ;
1933 sym : CARDINAL ;
1934 BEGIN
1935 (* assume this should not be called if OuterScope was a procedure
1936 as this case is handled by the caller (P1SymBuild)
1937 *)
1938 Assert(IsModule(OuterScope) OR IsDefImp(OuterScope)) ;
1939 sym := GetExportUndeclared(OuterScope, name) ;
1940 IF sym#NulSym
1941 THEN
1942 Assert(IsUnknown(sym)) ;
1943 RemoveExportUndeclared(OuterScope, sym) ;
1944 AddSymToModuleScope(OuterScope, sym) ;
1945 AddVarToScopeList(OuterScope, sym) ;
1946 pSym := GetPsym(OuterScope) ;
1947 WITH pSym^ DO
1948 CASE SymbolType OF
1949
1950 DefImpSym: IF GetSymKey(DefImp.Unresolved, name)=sym
1951 THEN
1952 DelSymKey(DefImp.Unresolved, name)
1953 END |
1954 ModuleSym: IF GetSymKey(Module.Unresolved, name)=sym
1955 THEN
1956 DelSymKey(Module.Unresolved, name)
1957 END
1958
1959 ELSE
1960 InternalError ('expecting DefImp, Module symbol')
1961 END
1962 END ;
1963 AddSymToUnknown(InnerScope, name, sym) ;
1964 PutExportUndeclared(InnerScope, sym)
1965 END ;
1966 RETURN( sym )
1967 END TryMoveUndeclaredSymToInnerModule ;
1968
1969
1970 (*
1971 RemoveFromUnresolvedTree - removes a symbol with name, name, from the
1972 unresolved tree of symbol, ScopeSym.
1973 *)
1974
1975 PROCEDURE RemoveFromUnresolvedTree (ScopeSym: CARDINAL; name: Name) : BOOLEAN ;
1976 VAR
1977 pSym: PtrToSymbol ;
1978 BEGIN
1979 (* Get symbol from unknown tree *)
1980 pSym := GetPsym(ScopeSym) ;
1981 WITH pSym^ DO
1982 CASE SymbolType OF
1983
1984 DefImpSym : IF GetSymKey(DefImp.Unresolved, name)#NulKey
1985 THEN
1986 DelSymKey(DefImp.Unresolved, name) ;
1987 RETURN( TRUE )
1988 END |
1989 ModuleSym : IF GetSymKey(Module.Unresolved, name)#NulKey
1990 THEN
1991 DelSymKey(Module.Unresolved, name) ;
1992 RETURN( TRUE )
1993 END |
1994 ProcedureSym: IF GetSymKey(Procedure.Unresolved, name)#NulKey
1995 THEN
1996 DelSymKey(Procedure.Unresolved, name) ;
1997 RETURN( TRUE )
1998 END
1999
2000 ELSE
2001 InternalError ('expecting DefImp, Module or Procedure symbol')
2002 END
2003 END ;
2004 RETURN( FALSE )
2005 END RemoveFromUnresolvedTree ;
2006
2007
2008 (*
2009 FetchUnknownSym - returns a symbol from the unknown tree if one is
2010 available. It also updates the unknown tree.
2011 *)
2012
2013 PROCEDURE FetchUnknownSym (name: Name) : CARDINAL ;
2014 VAR
2015 Sym: CARDINAL ;
2016 BEGIN
2017 Sym := GetSymFromUnknownTree(name) ;
2018 IF Sym#NulSym
2019 THEN
2020 SubSymFromUnknownTree(name)
2021 END ;
2022 RETURN( Sym )
2023 END FetchUnknownSym ;
2024
2025
2026 (*
2027 TransparentScope - returns true is the scope symbol Sym is allowed
2028 to look to an outer level for a symbol.
2029 ie is the symbol allowed to look to the parent
2030 scope for a symbol.
2031 *)
2032
2033 PROCEDURE TransparentScope (Sym: CARDINAL) : BOOLEAN ;
2034 VAR
2035 pSym: PtrToSymbol ;
2036 BEGIN
2037 pSym := GetPsym(Sym) ;
2038 WITH pSym^ DO
2039 RETURN( (SymbolType#DefImpSym) AND (SymbolType#ModuleSym) )
2040 END
2041 END TransparentScope ;
2042
2043
2044 (*
2045 AddSymToModuleScope - adds a symbol, Sym, to the scope of the module
2046 ModSym.
2047 *)
2048
2049 PROCEDURE AddSymToModuleScope (ModSym: CARDINAL; Sym: CARDINAL) ;
2050 VAR
2051 pSym: PtrToSymbol ;
2052 BEGIN
2053 pSym := GetPsym(ModSym) ;
2054 WITH pSym^ DO
2055 CASE SymbolType OF
2056
2057 DefImpSym : IF GetSymKey(DefImp.LocalSymbols, GetSymName(Sym))=NulKey
2058 THEN
2059 PutSymKey(DefImp.LocalSymbols, GetSymName(Sym), Sym)
2060 ELSE
2061 MetaError1 ('{%kIMPORT} name clash with symbol {%1Ead} symbol already declared ', Sym)
2062 END |
2063 ModuleSym : IF GetSymKey(Module.LocalSymbols, GetSymName(Sym))=NulKey
2064 THEN
2065 PutSymKey(Module.LocalSymbols, GetSymName(Sym), Sym)
2066 ELSE
2067 MetaError1 ('{%kIMPORT} name clash with symbol {%1Ead} symbol already declared ', Sym)
2068 END |
2069 ProcedureSym: IF GetSymKey(Procedure.LocalSymbols, GetSymName(Sym))=NulKey
2070 THEN
2071 PutSymKey(Procedure.LocalSymbols, GetSymName(Sym), Sym)
2072 ELSE
2073 MetaError1 ('{%kIMPORT} name clash with symbol {%1Ead} symbol already declared ', Sym)
2074 END
2075
2076 ELSE
2077 InternalError ('expecting Module or DefImp symbol')
2078 END
2079 END
2080 END AddSymToModuleScope ;
2081
2082
2083 (*
2084 GetCurrentModuleScope - returns the module symbol which forms the
2085 current (possibly inner most) module.
2086 *)
2087
2088 PROCEDURE GetCurrentModuleScope () : CARDINAL ;
2089 VAR
2090 pCall: PtrToCallFrame ;
2091 i : CARDINAL ;
2092 BEGIN
2093 i := ScopePtr ;
2094 pCall := GetPcall(i) ;
2095 WHILE (NOT IsModule(pCall^.Search)) AND
2096 (NOT IsDefImp(pCall^.Search)) DO
2097 Assert(i>0) ;
2098 DEC(i) ;
2099 pCall := GetPcall(i)
2100 END ;
2101 RETURN( pCall^.Search )
2102 END GetCurrentModuleScope ;
2103
2104
2105 (*
2106 GetLastModuleScope - returns the last module scope encountered,
2107 the module scope before the Current Module Scope.
2108 *)
2109
2110 PROCEDURE GetLastModuleScope () : CARDINAL ;
2111 VAR
2112 pCall: PtrToCallFrame ;
2113 i : CARDINAL ;
2114 BEGIN
2115 i := ScopePtr ;
2116 pCall := GetPcall(i) ;
2117 WHILE (NOT IsModule(pCall^.Search)) AND
2118 (NOT IsDefImp(pCall^.Search)) DO
2119 Assert(i>0) ;
2120 DEC(i) ;
2121 pCall := GetPcall(i)
2122 END ;
2123 (* Found module at position, i. *)
2124 DEC(i) ; (* Move to an outer level module scope *)
2125 pCall := GetPcall(i) ;
2126 WHILE (NOT IsModule(pCall^.Search)) AND
2127 (NOT IsDefImp(pCall^.Search)) DO
2128 Assert(i>0) ;
2129 DEC(i) ;
2130 pCall := GetPcall(i)
2131 END ;
2132 (* Found module at position, i. *)
2133 RETURN( pCall^.Search )
2134 END GetLastModuleScope ;
2135
2136
2137 (*
2138 GetLastModuleOrProcedureScope - returns the last module or procedure scope encountered,
2139 the scope before the current module scope.
2140 *)
2141
2142 PROCEDURE GetLastModuleOrProcedureScope () : CARDINAL ;
2143 VAR
2144 pCall: PtrToCallFrame ;
2145 i : CARDINAL ;
2146 BEGIN
2147 (* find current inner module *)
2148 i := ScopePtr ;
2149 pCall := GetPcall(i) ;
2150 WHILE (NOT IsModule(pCall^.Search)) AND
2151 (NOT IsDefImp(pCall^.Search)) DO
2152 Assert(i>0) ;
2153 DEC(i) ;
2154 pCall := GetPcall(i)
2155 END ;
2156 (* found module at position, i. *)
2157 DEC(i) ; (* Move to an outer level module or procedure scope *)
2158 pCall := GetPcall(i) ;
2159 WHILE (NOT IsModule(pCall^.Search)) AND
2160 (NOT IsDefImp(pCall^.Search)) AND
2161 (NOT IsProcedure(pCall^.Search)) DO
2162 Assert(i>0) ;
2163 DEC(i) ;
2164 pCall := GetPcall(i)
2165 END ;
2166 (* Found module at position, i. *)
2167 RETURN( pCall^.Search )
2168 END GetLastModuleOrProcedureScope ;
2169
2170
2171 (*
2172 AddSymToScope - adds a symbol Sym with name name to
2173 the current scope symbol tree.
2174 *)
2175
2176 PROCEDURE AddSymToScope (Sym: CARDINAL; name: Name) ;
2177 VAR
2178 pSym : PtrToSymbol ;
2179 pCall : PtrToCallFrame ;
2180 ScopeId: CARDINAL ;
2181 BEGIN
2182 pCall := GetPcall(ScopePtr) ;
2183 ScopeId := pCall^.Main ;
2184 (*
2185 WriteString('Adding ') ; WriteKey(name) ; WriteString(' :') ; WriteCard(Sym, 4) ; WriteString(' to scope: ') ;
2186 WriteKey(GetSymName(ScopeId)) ; WriteLn ;
2187 *)
2188 pSym := GetPsym(ScopeId) ;
2189 WITH pSym^ DO
2190 CASE SymbolType OF
2191
2192 DefImpSym : IF name#NulName
2193 THEN
2194 PutSymKey(DefImp.LocalSymbols, name, Sym)
2195 END ;
2196 IF IsEnumeration(Sym)
2197 THEN
2198 CheckEnumerationInList(DefImp.EnumerationScopeList, Sym)
2199 END |
2200 ModuleSym : IF name#NulName
2201 THEN
2202 PutSymKey(Module.LocalSymbols, name, Sym)
2203 END ;
2204 IF IsEnumeration(Sym)
2205 THEN
2206 CheckEnumerationInList(Module.EnumerationScopeList, Sym)
2207 END |
2208 ProcedureSym: IF name#NulName
2209 THEN
2210 PutSymKey(Procedure.LocalSymbols, name, Sym)
2211 END ;
2212 IF IsEnumeration(Sym)
2213 THEN
2214 CheckEnumerationInList(Procedure.EnumerationScopeList, Sym)
2215 END
2216
2217 ELSE
2218 InternalError ('should never get here')
2219 END
2220 END
2221 END AddSymToScope ;
2222
2223
2224 (*
2225 GetCurrentScope - returns the symbol who is responsible for the current
2226 scope. Note that it ignore pseudo scopes.
2227 *)
2228
2229 PROCEDURE GetCurrentScope () : CARDINAL ;
2230 VAR
2231 pCall: PtrToCallFrame ;
2232 BEGIN
2233 pCall := GetPcall(ScopePtr) ;
2234 RETURN( pCall^.Main )
2235 END GetCurrentScope ;
2236
2237
2238 (*
2239 StartScope - starts a block scope at Sym. Transparent determines
2240 whether the search for a symbol will look at the
2241 previous ScopeCallFrame if Sym does not contain the
2242 symbol that GetSym is searching.
2243
2244 WITH statements are partially implemented by calling
2245 StartScope. Therefore we must retain the old Main from
2246 the previous ScopePtr when a record is added to the scope
2247 stack. (Main contains the symbol where all identifiers
2248 should be added.)
2249 *)
2250
2251 PROCEDURE StartScope (Sym: CARDINAL) ;
2252 VAR
2253 oCall,
2254 pCall: PtrToCallFrame ;
2255 BEGIN
2256 Sym := SkipType(Sym) ;
2257 (*
2258 WriteString('New scope is: ') ; WriteKey(GetSymName(Sym)) ; WriteLn ;
2259 *)
2260 INC(ScopePtr) ;
2261 IF InBounds(ScopeCallFrame, ScopePtr)
2262 THEN
2263 pCall := GetPcall(ScopePtr)
2264 ELSE
2265 NEW(pCall) ;
2266 PutIndice(ScopeCallFrame, ScopePtr, pCall)
2267 END ;
2268 WITH pCall^ DO
2269 Start := ScopePtr-1 ; (* Previous ScopePtr value before StartScope *)
2270 Search := Sym ;
2271
2272 (* If Sym is a record then maintain the old Main scope for adding *)
2273 (* new symbols to ie temporary variables. *)
2274 IF IsRecord(Sym)
2275 THEN
2276 oCall := GetPcall(ScopePtr-1) ;
2277 Main := oCall^.Main
2278 ELSE
2279 Main := Sym ;
2280 PlaceMajorScopesEnumerationListOntoStack(Sym)
2281 END
2282 END
2283 (* ; DisplayScopes *)
2284 END StartScope ;
2285
2286
2287 (*
2288 PlaceMajorScopesEnumerationListOntoStack - places the DefImp, Module and
2289 Procedure symbols enumeration
2290 list onto the scope stack.
2291 *)
2292
2293 PROCEDURE PlaceMajorScopesEnumerationListOntoStack (Sym: CARDINAL) ;
2294 VAR
2295 pSym: PtrToSymbol ;
2296 BEGIN
2297 pSym := GetPsym(Sym) ;
2298 WITH pSym^ DO
2299 CASE SymbolType OF
2300
2301 DefImpSym : PlaceEnumerationListOntoScope(DefImp.EnumerationScopeList) |
2302 ModuleSym : PlaceEnumerationListOntoScope(Module.EnumerationScopeList) |
2303 ProcedureSym: PlaceEnumerationListOntoScope(Procedure.EnumerationScopeList)
2304
2305 ELSE
2306 InternalError ('expecting - DefImp, Module or Procedure symbol')
2307 END
2308 END
2309 END PlaceMajorScopesEnumerationListOntoStack ;
2310
2311
2312 (*
2313 PlaceEnumerationListOntoScope - places an enumeration list, l, onto the
2314 scope stack. This list will automatically
2315 removed via one call to EndScope which
2316 matches the StartScope by which this
2317 procedure is invoked.
2318 *)
2319
2320 PROCEDURE PlaceEnumerationListOntoScope (l: List) ;
2321 VAR
2322 i, n: CARDINAL ;
2323 BEGIN
2324 n := NoOfItemsInList(l) ;
2325 i := 1 ;
2326 WHILE i<=n DO
2327 PseudoScope(GetItemFromList(l, i)) ;
2328 INC(i)
2329 END
2330 END PlaceEnumerationListOntoScope ;
2331
2332
2333 (*
2334 EndScope - ends a block scope started by StartScope. The current
2335 head of the symbol scope reverts back to the symbol
2336 which was the Head of the symbol scope before the
2337 last StartScope was called.
2338 *)
2339
2340 PROCEDURE EndScope ;
2341 VAR
2342 pCall: PtrToCallFrame ;
2343 BEGIN
2344 (*
2345 ; WriteString('EndScope - ending scope: ') ;
2346 pCall := GetPcall(ScopePtr) ;
2347 ; WriteKey(GetSymName(pCall^.Search)) ; WriteLn ;
2348 *)
2349 pCall := GetPcall(ScopePtr) ;
2350 ScopePtr := pCall^.Start
2351 (* ; DisplayScopes *)
2352 END EndScope ;
2353
2354
2355 (*
2356 PseudoScope - starts a pseudo scope at Sym.
2357 We always connect parent up to the last scope,
2358 to determine the transparancy of a scope we call
2359 TransparentScope.
2360
2361 A Pseudo scope has no end block,
2362 but is terminated when the next EndScope is used.
2363 The function of the pseudo scope is to provide an
2364 automatic mechanism to solve enumeration types.
2365 A declared enumeration type is a Pseudo scope and
2366 identifiers used with the name of an enumeration
2367 type field will find the enumeration symbol by
2368 the scoping algorithm.
2369 *)
2370
2371 PROCEDURE PseudoScope (Sym: CARDINAL) ;
2372 VAR
2373 oCall,
2374 pCall: PtrToCallFrame ;
2375 BEGIN
2376 IF IsEnumeration(Sym)
2377 THEN
2378 INC(ScopePtr) ;
2379 IF InBounds(ScopeCallFrame, ScopePtr)
2380 THEN
2381 pCall := GetPcall(ScopePtr)
2382 ELSE
2383 NEW(pCall) ;
2384 PutIndice(ScopeCallFrame, ScopePtr, pCall)
2385 END ;
2386 WITH pCall^ DO
2387 oCall := GetPcall(ScopePtr-1) ;
2388 Main := oCall^.Main ;
2389 Start := oCall^.Start ;
2390 Search := Sym
2391 END
2392 ELSE
2393 InternalError ('expecting EnumerationSym')
2394 END
2395 END PseudoScope ;
2396
2397
2398 (*
2399 IsDeclaredIn - returns TRUE if a symbol was declared in, scope.
2400 *)
2401
2402 PROCEDURE IsDeclaredIn (scope, sym: CARDINAL) : BOOLEAN ;
2403 VAR
2404 s: CARDINAL ;
2405 BEGIN
2406 s := GetScope(sym) ;
2407 WHILE s#scope DO
2408 IF (s=NulSym) OR IsProcedure(s) OR IsModule(s) OR IsDefImp(s)
2409 THEN
2410 RETURN( FALSE )
2411 ELSE
2412 s := GetScope(s)
2413 END
2414 END ;
2415 RETURN( TRUE )
2416 END IsDeclaredIn ;
2417
2418
2419 (*
2420 SetFirstUsed - assigns the FirstUsed field in at to tok providing
2421 it has not already been set.
2422 *)
2423
2424 PROCEDURE SetFirstUsed (tok: CARDINAL; VAR at: Where) ;
2425 BEGIN
2426 IF at.FirstUsed = UnknownTokenNo
2427 THEN
2428 at.FirstUsed := tok
2429 END
2430 END SetFirstUsed ;
2431
2432
2433 (*
2434 PutFirstUsed - sets tok to the first used providing it has not already been set.
2435 It also includes the read and write quad into the usage list
2436 providing the quad numbers are not 0.
2437 *)
2438
2439 PROCEDURE PutFirstUsed (object: CARDINAL; tok: CARDINAL; read, write: CARDINAL) ;
2440 VAR
2441 pSym: PtrToSymbol ;
2442 BEGIN
2443 IF IsVar (object)
2444 THEN
2445 pSym := GetPsym (object) ;
2446 SetFirstUsed (tok, pSym^.Var.At) ;
2447 IF read # 0
2448 THEN
2449 PutReadQuad (object, GetMode (object), read)
2450 END ;
2451 IF write # 0
2452 THEN
2453 PutWriteQuad (object, GetMode (object), write)
2454 END
2455 END
2456 END PutFirstUsed ;
2457
2458
2459 (*
2460 MakeGnuAsm - create a GnuAsm symbol.
2461 *)
2462
2463 PROCEDURE MakeGnuAsm () : CARDINAL ;
2464 VAR
2465 pSym: PtrToSymbol ;
2466 Sym : CARDINAL ;
2467 BEGIN
2468 NewSym(Sym) ;
2469 pSym := GetPsym (Sym) ;
2470 WITH pSym^ DO
2471 SymbolType := GnuAsmSym ;
2472 WITH GnuAsm DO
2473 String := NulSym ;
2474 InitWhereDeclared (At) ;
2475 Inputs := NulSym ;
2476 Outputs := NulSym ;
2477 Trashed := NulSym ;
2478 Volatile := FALSE ;
2479 Simple := FALSE
2480 END
2481 END ;
2482 RETURN( Sym )
2483 END MakeGnuAsm ;
2484
2485
2486 (*
2487 PutGnuAsm - places the instruction textual name into the GnuAsm symbol.
2488 *)
2489
2490 PROCEDURE PutGnuAsm (sym: CARDINAL; string: CARDINAL) ;
2491 VAR
2492 pSym: PtrToSymbol ;
2493 BEGIN
2494 Assert (IsConstString (string)) ;
2495 pSym := GetPsym(sym) ;
2496 WITH pSym^ DO
2497 CASE SymbolType OF
2498
2499 GnuAsmSym: GnuAsm.String := string
2500
2501 ELSE
2502 InternalError ('expecting PutGnuAsm symbol')
2503 END
2504 END
2505 END PutGnuAsm ;
2506
2507
2508 (*
2509 GetGnuAsm - returns the string symbol, representing the instruction textual
2510 of the GnuAsm symbol. It will return a ConstString.
2511 *)
2512
2513 PROCEDURE GetGnuAsm (sym: CARDINAL) : CARDINAL ;
2514 VAR
2515 pSym: PtrToSymbol ;
2516 BEGIN
2517 pSym := GetPsym(sym) ;
2518 WITH pSym^ DO
2519 CASE SymbolType OF
2520
2521 GnuAsmSym: RETURN GnuAsm.String
2522
2523 ELSE
2524 InternalError ('expecting GnuAsm symbol')
2525 END
2526 END
2527 END GetGnuAsm ;
2528
2529
2530 (*
2531 PutGnuAsmOutput - places the interface object, out, into GnuAsm symbol, sym.
2532 *)
2533
2534 PROCEDURE PutGnuAsmOutput (sym: CARDINAL; out: CARDINAL) ;
2535 VAR
2536 pSym: PtrToSymbol ;
2537 BEGIN
2538 pSym := GetPsym(sym) ;
2539 WITH pSym^ DO
2540 CASE SymbolType OF
2541
2542 GnuAsmSym: GnuAsm.Outputs := out
2543
2544 ELSE
2545 InternalError ('expecting PutGnuAsm symbol')
2546 END
2547 END
2548 END PutGnuAsmOutput ;
2549
2550
2551 (*
2552 PutGnuAsmInput - places the interface object, in, into GnuAsm symbol, sym.
2553 *)
2554
2555 PROCEDURE PutGnuAsmInput (sym: CARDINAL; in: CARDINAL) ;
2556 VAR
2557 pSym: PtrToSymbol ;
2558 BEGIN
2559 pSym := GetPsym (sym) ;
2560 WITH pSym^ DO
2561 CASE SymbolType OF
2562
2563 GnuAsmSym: GnuAsm.Inputs := in
2564
2565 ELSE
2566 InternalError ('expecting PutGnuAsm symbol')
2567 END
2568 END
2569 END PutGnuAsmInput ;
2570
2571
2572 (*
2573 PutGnuAsmTrash - places the interface object, trash, into GnuAsm symbol, sym.
2574 *)
2575
2576 PROCEDURE PutGnuAsmTrash (sym: CARDINAL; trash: CARDINAL) ;
2577 VAR
2578 pSym: PtrToSymbol ;
2579 BEGIN
2580 pSym := GetPsym (sym) ;
2581 WITH pSym^ DO
2582 CASE SymbolType OF
2583
2584 GnuAsmSym: GnuAsm.Trashed := trash
2585
2586 ELSE
2587 InternalError ('expecting PutGnuAsm symbol')
2588 END
2589 END
2590 END PutGnuAsmTrash ;
2591
2592
2593 (*
2594 GetGnuAsmInput - returns the input list of registers.
2595 *)
2596
2597 PROCEDURE GetGnuAsmInput (sym: CARDINAL) : CARDINAL ;
2598 VAR
2599 pSym: PtrToSymbol ;
2600 BEGIN
2601 pSym := GetPsym (sym) ;
2602 WITH pSym^ DO
2603 CASE SymbolType OF
2604
2605 GnuAsmSym: RETURN GnuAsm.Inputs
2606
2607 ELSE
2608 InternalError ('expecting PutGnuAsm symbol')
2609 END
2610 END
2611 END GetGnuAsmInput ;
2612
2613
2614 (*
2615 GetGnuAsmOutput - returns the output list of registers.
2616 *)
2617
2618 PROCEDURE GetGnuAsmOutput (sym: CARDINAL) : CARDINAL ;
2619 VAR
2620 pSym: PtrToSymbol ;
2621 BEGIN
2622 pSym := GetPsym (sym) ;
2623 WITH pSym^ DO
2624 CASE SymbolType OF
2625
2626 GnuAsmSym: RETURN GnuAsm.Outputs
2627
2628 ELSE
2629 InternalError ('expecting PutGnuAsm symbol')
2630 END
2631 END
2632 END GetGnuAsmOutput ;
2633
2634
2635 (*
2636 GetGnuAsmTrash - returns the list of trashed registers.
2637 *)
2638
2639 PROCEDURE GetGnuAsmTrash (sym: CARDINAL) : CARDINAL ;
2640 VAR
2641 pSym: PtrToSymbol ;
2642 BEGIN
2643 pSym := GetPsym (sym) ;
2644 WITH pSym^ DO
2645 CASE SymbolType OF
2646
2647 GnuAsmSym: RETURN GnuAsm.Trashed
2648
2649 ELSE
2650 InternalError ('expecting PutGnuAsm symbol')
2651 END
2652 END
2653 END GetGnuAsmTrash ;
2654
2655
2656 (*
2657 PutGnuAsmVolatile - defines a GnuAsm symbol as VOLATILE.
2658 *)
2659
2660 PROCEDURE PutGnuAsmVolatile (Sym: CARDINAL) ;
2661 VAR
2662 pSym: PtrToSymbol ;
2663 BEGIN
2664 pSym := GetPsym (Sym) ;
2665 WITH pSym^ DO
2666 CASE SymbolType OF
2667
2668 GnuAsmSym: GnuAsm.Volatile := TRUE
2669
2670 ELSE
2671 InternalError ('expecting GnuAsm symbol')
2672 END
2673 END
2674 END PutGnuAsmVolatile ;
2675
2676
2677 (*
2678 PutGnuAsmSimple - defines a GnuAsm symbol as a simple kind.
2679 *)
2680
2681 PROCEDURE PutGnuAsmSimple (Sym: CARDINAL) ;
2682 VAR
2683 pSym: PtrToSymbol ;
2684 BEGIN
2685 pSym := GetPsym (Sym) ;
2686 WITH pSym^ DO
2687 CASE SymbolType OF
2688
2689 GnuAsmSym: GnuAsm.Simple := TRUE
2690
2691 ELSE
2692 InternalError ('expecting GnuAsm symbol')
2693 END
2694 END
2695 END PutGnuAsmSimple ;
2696
2697
2698 (*
2699 MakeRegInterface - creates and returns a register interface symbol.
2700 *)
2701
2702 PROCEDURE MakeRegInterface () : CARDINAL ;
2703 VAR
2704 pSym: PtrToSymbol ;
2705 Sym : CARDINAL ;
2706 BEGIN
2707 NewSym (Sym) ;
2708 pSym := GetPsym (Sym) ;
2709 WITH pSym^ DO
2710 SymbolType := InterfaceSym ;
2711 WITH Interface DO
2712 Parameters := InitIndex (1) ;
2713 InitWhereDeclared (At)
2714 END
2715 END ;
2716 RETURN( Sym )
2717 END MakeRegInterface ;
2718
2719
2720 (*
2721 PutRegInterface - places a, name, string, and, object, into the interface array,
2722 sym, at position, i.
2723 The string symbol will either be a register name or a constraint.
2724 The object is an optional Modula-2 variable or constant symbol.
2725 read and write are the quadruple numbers representing any read
2726 or write operation.
2727 *)
2728
2729 PROCEDURE PutRegInterface (tok: CARDINAL;
2730 sym: CARDINAL; i: CARDINAL; n: Name; string, object: CARDINAL;
2731 read, write: CARDINAL) ;
2732 VAR
2733 pSym : PtrToSymbol ;
2734 p : PtrToAsmConstraint ;
2735 BEGIN
2736 pSym := GetPsym(sym) ;
2737 WITH pSym^ DO
2738 CASE SymbolType OF
2739
2740 InterfaceSym: IF Indexing.InBounds(Interface.Parameters, i)
2741 THEN
2742 p := Indexing.GetIndice(Interface.Parameters, i)
2743 ELSIF i=Indexing.HighIndice(Interface.Parameters)+1
2744 THEN
2745 NEW(p) ;
2746 Indexing.PutIndice(Interface.Parameters, i, p)
2747 ELSE
2748 InternalError ('expecting to add parameters sequentially')
2749 END ;
2750 WITH p^ DO
2751 tokpos := tok ;
2752 name := n ;
2753 str := string ;
2754 obj := object
2755 END ;
2756 PutFirstUsed (object, tok, read, write)
2757
2758 ELSE
2759 InternalError ('expecting Interface symbol')
2760 END
2761 END
2762 END PutRegInterface ;
2763
2764
2765 (*
2766 GetRegInterface - gets a, name, string, and, object, from the interface array,
2767 sym, from position, i.
2768 *)
2769
2770 PROCEDURE GetRegInterface (sym: CARDINAL; i: CARDINAL;
2771 VAR tok: CARDINAL; VAR n: Name; VAR string, object: CARDINAL) ;
2772 VAR
2773 pSym: PtrToSymbol ;
2774 p : PtrToAsmConstraint ;
2775 BEGIN
2776 pSym := GetPsym(sym) ;
2777 WITH pSym^ DO
2778 CASE SymbolType OF
2779
2780 InterfaceSym: IF Indexing.InBounds(Interface.Parameters, i)
2781 THEN
2782 p := Indexing.GetIndice(Interface.Parameters, i) ;
2783 WITH p^ DO
2784 tok := tokpos ;
2785 n := name ;
2786 string := str ;
2787 object := obj
2788 END
2789 ELSE
2790 tok := UnknownTokenNo ;
2791 n := NulName ;
2792 string := NulSym ;
2793 object := NulSym
2794 END
2795
2796 ELSE
2797 InternalError ('expecting Interface symbol')
2798 END
2799 END
2800 END GetRegInterface ;
2801
2802
2803 (*
2804 GetSubrange - returns HighSym and LowSym - two constants which make up the
2805 subrange.
2806 *)
2807
2808 PROCEDURE GetSubrange (Sym: CARDINAL; VAR HighSym, LowSym: CARDINAL) ;
2809 VAR
2810 pSym: PtrToSymbol ;
2811 BEGIN
2812 pSym := GetPsym(Sym) ;
2813 WITH pSym^ DO
2814 CASE SymbolType OF
2815
2816 SubrangeSym: HighSym := Subrange.High ;
2817 LowSym := Subrange.Low
2818
2819 ELSE
2820 InternalError ('expecting Subrange symbol')
2821 END
2822 END
2823 END GetSubrange ;
2824
2825
2826 (*
2827 PutSubrange - places LowSym and HighSym as two symbols
2828 which provide the limits of the range.
2829 *)
2830
2831 PROCEDURE PutSubrange (Sym: CARDINAL; LowSym, HighSym: CARDINAL;
2832 TypeSymbol: CARDINAL) ;
2833 VAR
2834 pSym: PtrToSymbol ;
2835 BEGIN
2836 pSym := GetPsym(Sym) ;
2837 WITH pSym^ DO
2838 CASE SymbolType OF
2839
2840 SubrangeSym: Subrange.Low := LowSym ; (* Index to symbol for lower *)
2841 Subrange.High := HighSym ; (* Index to symbol for higher *)
2842 Subrange.Type := TypeSymbol ; (* Index to type symbol for *)
2843 (* the type of subrange. *)
2844 ELSE
2845 InternalError ('expecting Subrange symbol')
2846 END
2847 END
2848 END PutSubrange ;
2849
2850
2851 (*
2852 SetCurrentModule - Used to set the CurrentModule to a symbol, Sym.
2853 This Sym must represent the module name of the
2854 file currently being compiled.
2855 *)
2856
2857 PROCEDURE SetCurrentModule (Sym: CARDINAL) ;
2858 BEGIN
2859 CurrentModule := Sym
2860 END SetCurrentModule ;
2861
2862
2863 (*
2864 GetCurrentModule - returns the current module Sym that is being
2865 compiled.
2866 *)
2867
2868 PROCEDURE GetCurrentModule () : CARDINAL ;
2869 BEGIN
2870 RETURN( CurrentModule )
2871 END GetCurrentModule ;
2872
2873
2874 (*
2875 SetMainModule - Used to set the MainModule to a symbol, Sym.
2876 This Sym must represent the main module which was
2877 envoked by the user to be compiled.
2878 *)
2879
2880 PROCEDURE SetMainModule (Sym: CARDINAL) ;
2881 BEGIN
2882 MainModule := Sym
2883 END SetMainModule ;
2884
2885
2886 (*
2887 GetMainModule - returns the main module symbol that was requested by
2888 the user to be compiled.
2889 *)
2890
2891 PROCEDURE GetMainModule () : CARDINAL ;
2892 BEGIN
2893 RETURN( MainModule )
2894 END GetMainModule ;
2895
2896
2897 (*
2898 SetFileModule - Used to set the FileModule to a symbol, Sym.
2899 This Sym must represent the current program module
2900 file which is being parsed.
2901 *)
2902
2903 PROCEDURE SetFileModule (Sym: CARDINAL) ;
2904 BEGIN
2905 FileModule := Sym
2906 END SetFileModule ;
2907
2908
2909 (*
2910 GetFileModule - returns the FileModule symbol that was requested by
2911 the user to be compiled.
2912 *)
2913
2914 PROCEDURE GetFileModule () : CARDINAL ;
2915 BEGIN
2916 RETURN( FileModule )
2917 END GetFileModule ;
2918
2919
2920 (*
2921 GetBaseModule - returns the base module symbol that contains Modula-2
2922 base types, procedures and functions.
2923 *)
2924
2925 PROCEDURE GetBaseModule () : CARDINAL ;
2926 BEGIN
2927 RETURN( BaseModule )
2928 END GetBaseModule ;
2929
2930
2931 (*
2932 GetSym - searches the current scope (and previous scopes if the
2933 scope tranparent allows) for a symbol with name.
2934 *)
2935
2936 PROCEDURE GetSym (name: Name) : CARDINAL ;
2937 VAR
2938 Sym : CARDINAL ;
2939 OldScopePtr: CARDINAL ;
2940 BEGIN
2941 Sym := GetScopeSym(name, TRUE) ;
2942 IF Sym=NulSym
2943 THEN
2944 (* Check default base types for symbol *)
2945 OldScopePtr := ScopePtr ; (* Save ScopePtr *)
2946 ScopePtr := BaseScopePtr ; (* Alter ScopePtr to point to top of BaseModule *)
2947 Sym := GetScopeSym(name, FALSE) ; (* Search BaseModule for name *)
2948 ScopePtr := OldScopePtr (* Restored ScopePtr *)
2949 END ;
2950 RETURN( Sym )
2951 END GetSym ;
2952
2953
2954 (*
2955 CanLookThroughScope - by default this procedure returns TRUE. It only returns
2956 FALSE if, throughProcedure, is FALSE and the ScopeSym is
2957 a procedure.
2958 *)
2959
2960 PROCEDURE CanLookThroughScope (ScopeSym: CARDINAL; throughProcedure: BOOLEAN) : BOOLEAN ;
2961 BEGIN
2962 IF IsProcedure(ScopeSym)
2963 THEN
2964 RETURN( throughProcedure )
2965 ELSE
2966 RETURN( TRUE )
2967 END
2968 END CanLookThroughScope ;
2969
2970
2971 (*
2972 GetScopeSym - searches the current scope and below, providing that the
2973 scopes are transparent, for a symbol with name, name.
2974 It only passes over procedure scopes if, throughProcedure,
2975 is TRUE.
2976 *)
2977
2978 PROCEDURE GetScopeSym (name: Name; throughProcedure: BOOLEAN) : CARDINAL ;
2979 VAR
2980 pCall : PtrToCallFrame ;
2981 ScopeSym,
2982 ScopeId ,
2983 Sym : CARDINAL ;
2984 BEGIN
2985 (* DisplayScopes ; *)
2986 ScopeId := ScopePtr ;
2987 pCall := GetPcall(ScopeId) ;
2988 ScopeSym := pCall^.Search ;
2989 (* WriteString(' scope: ') ; WriteKey(GetSymName(ScopeSym)) ; *)
2990 Sym := CheckScopeForSym(ScopeSym, name) ;
2991 WHILE (ScopeId>0) AND (Sym=NulSym) AND TransparentScope(ScopeSym) AND
2992 CanLookThroughScope(ScopeSym, throughProcedure) DO
2993 DEC(ScopeId) ;
2994 pCall := GetPcall(ScopeId) ;
2995 ScopeSym := pCall^.Search ;
2996 Sym := CheckScopeForSym(ScopeSym, name) ;
2997 (* WriteString(' scope: ') ; WriteKey(GetSymName(ScopeSym)) *)
2998 END ;
2999 (* IF Sym#NulSym THEN WriteKey(GetSymName(Sym)) END ; WriteLn ; *)
3000 RETURN( Sym )
3001 END GetScopeSym ;
3002
3003
3004 (*
3005 CheckScopeForSym - checks the scope, ScopeSym, for an identifier
3006 of name, name. CheckScopeForSym checks for
3007 the symbol by the GetLocalSym and also
3008 ExamineUnresolvedTree.
3009 *)
3010
3011 PROCEDURE CheckScopeForSym (ScopeSym: CARDINAL; name: Name) : CARDINAL ;
3012 VAR
3013 Sym: CARDINAL ;
3014 BEGIN
3015 Sym := GetLocalSym(ScopeSym, name) ;
3016 IF (Sym=NulSym) AND (IsModule(ScopeSym) OR IsDefImp(ScopeSym) OR
3017 IsProcedure(ScopeSym))
3018 THEN
3019 Sym := ExamineUnresolvedTree(ScopeSym, name)
3020 END ;
3021 RETURN( Sym )
3022 END CheckScopeForSym ;
3023
3024
3025 (*
3026 DisplayScopes - displays the scopes that will be searched to find
3027 a requested symbol.
3028 *)
3029
3030 (*
3031 PROCEDURE DisplayScopes ;
3032 VAR
3033 pCall: PtrToCallFrame ;
3034 n : Name ;
3035 i : CARDINAL ;
3036 Sym : CARDINAL ;
3037 BEGIN
3038 i := ScopePtr ;
3039 printf0('Displaying scopes\n') ;
3040 WHILE i>=1 DO
3041 pCall := GetPcall(i) ;
3042 Sym := pCall^.Search ;
3043 printf1('Symbol %4d', Sym) ;
3044 IF Sym#NulSym
3045 THEN
3046 n := GetSymName(Sym) ;
3047 printf1(' : name %a is ', n) ;
3048 IF NOT TransparentScope(Sym)
3049 THEN
3050 printf0('not')
3051 END ;
3052 printf0(' transparent\n')
3053 END ;
3054 DEC(i)
3055 END ;
3056 printf0('\n')
3057 END DisplayScopes ;
3058 *)
3059
3060
3061 (*
3062 GetModuleScopeId - returns the scope index to the next module starting
3063 at index, Id.
3064 Id will either point to a null scope (NulSym) or
3065 alternatively point to a Module or DefImp symbol.
3066 *)
3067
3068 PROCEDURE GetModuleScopeId (Id: CARDINAL) : CARDINAL ;
3069 VAR
3070 pCall: PtrToCallFrame ;
3071 s : CARDINAL ;
3072 BEGIN
3073 pCall := GetPcall(Id) ;
3074 s := pCall^.Search ;
3075 WHILE (Id>0) AND (s#NulSym) AND
3076 ((NOT IsModule(s)) AND
3077 (NOT IsDefImp(s))) DO
3078 DEC(Id) ;
3079 pCall := GetPcall(Id) ;
3080 s := pCall^.Search ;
3081 END ;
3082 RETURN( Id )
3083 END GetModuleScopeId ;
3084
3085
3086 (*
3087 GetVisibleSym -
3088 *)
3089
3090 PROCEDURE GetVisibleSym (name: Name) : CARDINAL ;
3091 VAR
3092 pCall: PtrToCallFrame ;
3093 Sym,
3094 i : CARDINAL ;
3095 BEGIN
3096 i := ScopePtr ;
3097 WHILE i>=1 DO
3098 pCall := GetPcall(i) ;
3099 WITH pCall^ DO
3100 IF Search=Main
3101 THEN
3102 RETURN( GetLocalSym(Main, name) )
3103 ELSE
3104 IF IsEnumeration(Search)
3105 THEN
3106 Sym := GetLocalSym(Search, name) ;
3107 IF Sym#NulSym
3108 THEN
3109 RETURN( Sym )
3110 END
3111 END
3112 END
3113 END ;
3114 DEC(i)
3115 END ;
3116 RETURN( NulSym )
3117 END GetVisibleSym ;
3118
3119
3120 (*
3121 IsAlreadyDeclaredSym - returns true if Sym has already been declared
3122 in the current main scope.
3123 *)
3124
3125 PROCEDURE IsAlreadyDeclaredSym (name: Name) : BOOLEAN ;
3126 VAR
3127 pCall: PtrToCallFrame ;
3128 i : CARDINAL ;
3129 BEGIN
3130 i := ScopePtr ;
3131 WHILE i>=1 DO
3132 pCall := GetPcall(i) ;
3133 WITH pCall^ DO
3134 IF Search=Main
3135 THEN
3136 RETURN( GetLocalSym(Main, name)#NulSym )
3137 ELSE
3138 IF IsEnumeration(Search) AND (GetLocalSym(Search, name)#NulSym)
3139 THEN
3140 RETURN( TRUE )
3141 END
3142 END
3143 END ;
3144 DEC(i)
3145 END ;
3146 RETURN( FALSE )
3147 END IsAlreadyDeclaredSym ;
3148
3149
3150 (*
3151 IsImplicityExported - returns TRUE if, Sym, is implicitly exported from module, ModSym.
3152 ModSym must be a defimp symbol.
3153 *)
3154
3155 PROCEDURE IsImplicityExported (ModSym, Sym: CARDINAL) : BOOLEAN ;
3156 VAR
3157 type: CARDINAL ;
3158 pSym: PtrToSymbol ;
3159 BEGIN
3160 IF IsDefImp(ModSym) AND IsFieldEnumeration(Sym)
3161 THEN
3162 pSym := GetPsym(ModSym) ;
3163 type := SkipType(GetType(Sym)) ;
3164 RETURN( IsItemInList(pSym^.DefImp.EnumerationScopeList, type) )
3165 END ;
3166 RETURN( FALSE )
3167 END IsImplicityExported ;
3168
3169
3170 (*
3171 MakeProcedureCtorExtern - creates an extern ctor procedure
3172 *)
3173
3174 PROCEDURE MakeProcedureCtorExtern (tokenno: CARDINAL; libname, modulename: Name) : CARDINAL ;
3175 VAR
3176 ctor: CARDINAL ;
3177 BEGIN
3178 ctor := MakeProcedure (tokenno, GenName (libname, '_M2_', modulename, '_ctor')) ;
3179 PutExtern (ctor, TRUE) ;
3180 RETURN ctor
3181 END MakeProcedureCtorExtern ;
3182
3183
3184 (*
3185 GenName - returns a new name consisting of pre, name, post concatenation.
3186 *)
3187
3188 PROCEDURE GenName (libname: Name; pre: ARRAY OF CHAR; name: Name; post: ARRAY OF CHAR) : Name ;
3189 VAR
3190 str : String ;
3191 result: Name ;
3192 BEGIN
3193 str := InitStringCharStar (KeyToCharStar (libname)) ;
3194 str := ConCat (str, Mark (InitString (pre))) ;
3195 str := ConCat (str, Mark (InitStringCharStar (KeyToCharStar (name)))) ;
3196 str := ConCat (str, InitString (post)) ;
3197 result := makekey (string (str)) ;
3198 str := KillString (str) ;
3199 RETURN result
3200 END GenName ;
3201
3202
3203 (*
3204 InitCtor - initialize the ModuleCtor fields to NulSym.
3205 *)
3206
3207 PROCEDURE InitCtor (VAR ctor: ModuleCtor) ;
3208 BEGIN
3209 ctor.ctor := NulSym ;
3210 ctor.dep := NulSym ;
3211 ctor.init := NulSym ;
3212 ctor.fini := NulSym
3213 END InitCtor ;
3214
3215
3216 (*
3217 MakeModuleCtor - for a defimp or module symbol create all the ctor
3218 related procedures.
3219 *)
3220
3221 PROCEDURE MakeModuleCtor (moduleTok, beginTok, finallyTok: CARDINAL;
3222 moduleSym: CARDINAL) ;
3223 VAR
3224 pSym: PtrToSymbol ;
3225 BEGIN
3226 Assert (IsDefImp (moduleSym) OR IsModule (moduleSym)) ;
3227 pSym := GetPsym (moduleSym) ;
3228 IF IsDefImp (moduleSym)
3229 THEN
3230 InitCtorFields (moduleTok, beginTok, finallyTok,
3231 moduleSym,
3232 pSym^.DefImp.ctors, GetSymName (moduleSym),
3233 FALSE, TRUE)
3234 ELSE
3235 InitCtorFields (moduleTok, beginTok, finallyTok,
3236 moduleSym,
3237 pSym^.Module.ctors, GetSymName (moduleSym),
3238 IsInnerModule (moduleSym), TRUE)
3239 END
3240 END MakeModuleCtor ;
3241
3242
3243 (*
3244 InitCtorFields - initialize the ModuleCtor fields. An inner module has no
3245 ctor procedure.
3246 *)
3247
3248 PROCEDURE InitCtorFields (moduleTok, beginTok, finallyTok: CARDINAL;
3249 moduleSym: CARDINAL;
3250 VAR ctor: ModuleCtor; name: Name;
3251 inner, pub: BOOLEAN) ;
3252 BEGIN
3253 IF ScaffoldDynamic AND (NOT inner)
3254 THEN
3255 (* The ctor procedure must be public. *)
3256 ctor.ctor := MakeProcedure (moduleTok,
3257 GenName (GetLibName (moduleSym),
3258 "_M2_", name, "_ctor")) ;
3259 PutCtor (ctor.ctor, TRUE) ;
3260 Assert (pub) ;
3261 PutPublic (ctor.ctor, pub) ;
3262 PutExtern (ctor.ctor, NOT pub) ;
3263 PutMonoName (ctor.ctor, TRUE) ;
3264 (* The dep procedure is local to the module. *)
3265 ctor.dep := MakeProcedure (moduleTok,
3266 GenName (GetLibName (moduleSym),
3267 "_M2_", name, "_dep")) ;
3268 PutMonoName (ctor.dep, TRUE)
3269 ELSE
3270 ctor.ctor := NulSym ;
3271 ctor.dep := NulSym
3272 END ;
3273 (* The init/fini procedures must be public. *)
3274 ctor.init := MakeProcedure (beginTok,
3275 GenName (GetLibName (moduleSym),
3276 "_M2_", name, "_init")) ;
3277 PutPublic (ctor.init, pub) ;
3278 PutExtern (ctor.init, NOT pub) ;
3279 PutMonoName (ctor.init, NOT inner) ;
3280 DeclareArgEnvParams (beginTok, ctor.init) ;
3281 ctor.fini := MakeProcedure (finallyTok,
3282 GenName (GetLibName (moduleSym),
3283 "_M2_", name, "_fini")) ;
3284 PutPublic (ctor.fini, pub) ;
3285 PutExtern (ctor.fini, NOT pub) ;
3286 PutMonoName (ctor.fini, NOT inner) ;
3287 DeclareArgEnvParams (beginTok, ctor.fini)
3288 END InitCtorFields ;
3289
3290
3291 (*
3292 GetModuleCtors - mod can be a DefImp or Module symbol. ctor, init and fini
3293 are assigned for this module. An inner module ctor value will
3294 be NulSym.
3295 *)
3296
3297 PROCEDURE GetModuleCtors (mod: CARDINAL; VAR ctor, init, fini, dep: CARDINAL) ;
3298 VAR
3299 pSym : PtrToSymbol ;
3300 BEGIN
3301 pSym := GetPsym (mod) ;
3302 WITH pSym^ DO
3303 CASE SymbolType OF
3304
3305 ModuleSym: ctor := Module.ctors.ctor ;
3306 init := Module.ctors.init ;
3307 fini := Module.ctors.fini ;
3308 dep := Module.ctors.dep |
3309 DefImpSym: ctor := DefImp.ctors.ctor ;
3310 init := DefImp.ctors.init ;
3311 fini := DefImp.ctors.fini ;
3312 dep := DefImp.ctors.dep
3313
3314 ELSE
3315 InternalError ('expecting Module or DefImp symbol')
3316 END
3317 END
3318 END GetModuleCtors ;
3319
3320
3321 (*
3322 CheckTok - checks to see that tok is at a known location. If not
3323 it uses GetTokenNo as a fall back.
3324 *)
3325
3326 PROCEDURE CheckTok (tok: CARDINAL; name: ARRAY OF CHAR) : CARDINAL ;
3327 VAR
3328 s: String ;
3329 BEGIN
3330 IF tok = UnknownTokenNo
3331 THEN
3332 tok := GetTokenNo () ;
3333 IF DebugUnknownToken
3334 THEN
3335 s := InitString (name) ;
3336 s := ConCat (s, InitString (' symbol {%W} has been created with an unknown token location')) ;
3337 MetaErrorStringT0 (GetTokenNo (), s)
3338 END
3339 END ;
3340 RETURN tok
3341 END CheckTok ;
3342
3343
3344 (*
3345 MakeModule - creates a module sym with ModuleName. It returns the
3346 symbol index.
3347 *)
3348
3349 PROCEDURE MakeModule (tok: CARDINAL; ModuleName: Name) : CARDINAL ;
3350 VAR
3351 pSym : PtrToSymbol ;
3352 pCall: PtrToCallFrame ;
3353 Sym : CARDINAL ;
3354 BEGIN
3355 (* tok := CheckTok (tok, 'module') ; *)
3356 (*
3357 Make a new symbol since we are at the outer scope level.
3358 DeclareSym examines the current scope level for any symbols
3359 that have the correct name, but are yet undefined.
3360 Therefore we must not call DeclareSym but create a symbol
3361 directly.
3362 *)
3363 NewSym(Sym) ;
3364 pSym := GetPsym(Sym) ;
3365 WITH pSym^ DO
3366 SymbolType := ModuleSym ;
3367 WITH Module DO
3368 name := ModuleName ; (* Index into name array, name *)
3369 (* of record field. *)
3370 libname := NulName ; (* Library association. *)
3371 InitCtor (ctors) ; (* Init all ctor functions. *)
3372 InitList(ModListOfDep) ; (* Vector of SymDependency. *)
3373 InitTree(LocalSymbols) ; (* The LocalSymbols hold all the *)
3374 (* variables declared local to *)
3375 (* the block. It contains the *)
3376 (* FROM _ IMPORT x, y, x ; *)
3377 (* IMPORT A ; *)
3378 (* and also *)
3379 (* MODULE WeAreHere ; *)
3380 (* x y z visiable by localsym *)
3381 (* MODULE Inner ; *)
3382 (* EXPORT x, y, z ; *)
3383 (* END Inner ; *)
3384 (* END WeAreHere. *)
3385 InitTree(ExportTree) ; (* Holds all the exported *)
3386 (* identifiers. *)
3387 (* This tree may be *)
3388 (* deleted at the end of Pass 1. *)
3389 InitTree(ImportTree) ; (* Contains all IMPORTed *)
3390 (* identifiers. *)
3391 InitList(IncludeList) ; (* Contains all included symbols *)
3392 (* which are included by *)
3393 (* IMPORT modulename ; *)
3394 (* modulename.Symbol *)
3395 InitTree(ExportUndeclared) ; (* ExportUndeclared contains all *)
3396 (* the identifiers which were *)
3397 (* exported but have not yet *)
3398 (* been declared. *)
3399 InitList(EnumerationScopeList) ; (* Enumeration scope list which *)
3400 (* contains a list of all *)
3401 (* enumerations which are *)
3402 (* visable within this scope. *)
3403 (* Outer Module. *)
3404 InitTree(NamedObjects) ; (* Names of all items declared. *)
3405 InitTree(NamedImports) ; (* Names of items imported. *)
3406 InitTree(WhereImported) ; (* Sym to TokenNo where import *)
3407 (* occurs. Error message use. *)
3408 Priority := NulSym ; (* Priority of the module. This *)
3409 (* is an index to a constant. *)
3410 InitTree(Unresolved) ; (* All symbols currently *)
3411 (* unresolved in this module. *)
3412 StartQuad := 0 ; (* Signify the initialization *)
3413 (* code. *)
3414 EndQuad := 0 ; (* EndQuad should point to a *)
3415 (* goto quad. *)
3416 StartFinishQuad := 0 ; (* Signify the finalization *)
3417 (* code. *)
3418 EndFinishQuad := 0 ; (* should point to a finish *)
3419 FinallyFunction := NIL ; (* The GCC function for finally *)
3420 ExceptionFinally := FALSE ; (* does it have an exception? *)
3421 ExceptionBlock := FALSE ; (* does it have an exception? *)
3422 ModLink := GetLink () ; (* Is this parsed for linkage? *)
3423 Builtin := FALSE ; (* Is the module builtin? *)
3424 InitList(ListOfVars) ; (* List of variables in this *)
3425 (* scope. *)
3426 InitList(ListOfProcs) ; (* List of all procedures *)
3427 (* declared within this module. *)
3428 InitList(ListOfModules) ; (* List of all inner modules. *)
3429 InitWhereDeclaredTok(tok, At) ; (* Where symbol declared. *)
3430 InitWhereFirstUsedTok(tok, At) ; (* Where symbol first used. *)
3431 pCall := GetPcall(ScopePtr) ;
3432 IF pCall^.Main=GetBaseModule()
3433 THEN
3434 Scope := NulSym
3435 ELSE
3436 Scope := pCall^.Main
3437 END ;
3438 errorScope := GetCurrentErrorScope () ; (* Title error scope. *)
3439 END
3440 END ;
3441 PutSymKey(ModuleTree, ModuleName, Sym) ;
3442 RETURN Sym
3443 END MakeModule ;
3444
3445
3446 (*
3447 PutModLink - assigns link to module sym.
3448 *)
3449
3450 PROCEDURE PutModLink (sym: CARDINAL; link: BOOLEAN) ;
3451 VAR
3452 pSym: PtrToSymbol ;
3453 BEGIN
3454 IF IsModule (sym)
3455 THEN
3456 pSym := GetPsym (sym) ;
3457 pSym^.Module.ModLink := link
3458 ELSIF IsDefImp (sym)
3459 THEN
3460 pSym := GetPsym (sym) ;
3461 pSym^.DefImp.ModLink := link
3462 ELSE
3463 InternalError ('expecting a DefImp or Module symbol')
3464 END
3465 END PutModLink ;
3466
3467
3468 (*
3469 IsModLink - returns the ModLink value associated with the module symbol.
3470 *)
3471
3472 PROCEDURE IsModLink (sym: CARDINAL) : BOOLEAN ;
3473 VAR
3474 pSym: PtrToSymbol ;
3475 BEGIN
3476 IF IsModule (sym)
3477 THEN
3478 pSym := GetPsym (sym) ;
3479 RETURN pSym^.Module.ModLink
3480 ELSIF IsDefImp (sym)
3481 THEN
3482 pSym := GetPsym (sym) ;
3483 RETURN pSym^.DefImp.ModLink
3484 ELSE
3485 InternalError ('expecting a DefImp or Module symbol')
3486 END
3487 END IsModLink ;
3488
3489
3490 (*
3491 PutDefLink - assigns link to the definition module sym.
3492 *)
3493
3494 PROCEDURE PutDefLink (sym: CARDINAL; link: BOOLEAN) ;
3495 VAR
3496 pSym: PtrToSymbol ;
3497 BEGIN
3498 IF IsDefImp (sym)
3499 THEN
3500 pSym := GetPsym (sym) ;
3501 pSym^.DefImp.DefLink := link
3502 ELSE
3503 InternalError ('expecting a DefImp symbol')
3504 END
3505 END PutDefLink ;
3506
3507
3508 (*
3509 IsDefLink - returns the DefLink value associated with the definition module symbol.
3510 *)
3511
3512 PROCEDURE IsDefLink (sym: CARDINAL) : BOOLEAN ;
3513 VAR
3514 pSym: PtrToSymbol ;
3515 BEGIN
3516 IF IsDefImp (sym)
3517 THEN
3518 pSym := GetPsym (sym) ;
3519 RETURN pSym^.DefImp.DefLink
3520 ELSE
3521 InternalError ('expecting a DefImp symbol')
3522 END
3523 END IsDefLink ;
3524
3525
3526 (*
3527 GetLink - returns TRUE if the current module is only used for linkage.
3528 *)
3529
3530 PROCEDURE GetLink () : BOOLEAN ;
3531 VAR
3532 OuterModule: CARDINAL ;
3533 BEGIN
3534 OuterModule := GetCurrentModule () ;
3535 IF OuterModule # NulSym
3536 THEN
3537 IF CompilingDefinitionModule ()
3538 THEN
3539 RETURN IsDefLink (OuterModule)
3540 ELSE
3541 RETURN IsModLink (OuterModule)
3542 END
3543 END ;
3544 (* Default is that the module is for compiling. *)
3545 RETURN FALSE
3546 END GetLink ;
3547
3548
3549 (*
3550 IsModuleBuiltin - returns TRUE if the module is a builtin module.
3551 (For example _BaseTypes).
3552 *)
3553
3554 PROCEDURE IsModuleBuiltin (sym: CARDINAL) : BOOLEAN ;
3555 VAR
3556 pSym: PtrToSymbol ;
3557 BEGIN
3558 IF IsDefImp (sym)
3559 THEN
3560 pSym := GetPsym (sym) ;
3561 RETURN pSym^.DefImp.Builtin
3562 ELSIF IsModule (sym)
3563 THEN
3564 pSym := GetPsym (sym) ;
3565 RETURN pSym^.Module.Builtin
3566 END ;
3567 RETURN FALSE
3568 END IsModuleBuiltin ;
3569
3570
3571 (*
3572 PutModuleBuiltin - sets the Builtin flag to value.
3573 Currently the procedure expects sym to be a DefImp
3574 module only.
3575 *)
3576
3577 PROCEDURE PutModuleBuiltin (sym: CARDINAL; value: BOOLEAN) ;
3578 VAR
3579 pSym: PtrToSymbol ;
3580 BEGIN
3581 IF IsDefImp (sym)
3582 THEN
3583 pSym := GetPsym (sym) ;
3584 pSym^.DefImp.Builtin := value
3585 ELSIF IsModule (sym)
3586 THEN
3587 pSym := GetPsym (sym) ;
3588 pSym^.Module.Builtin := value
3589 ELSE
3590 InternalError ('expecting Module or DefImp symbol')
3591 END
3592 END PutModuleBuiltin ;
3593
3594
3595 (*
3596 AddModuleToParent - adds symbol, Sym, to module, Parent.
3597 *)
3598
3599 PROCEDURE AddModuleToParent (Sym: CARDINAL; Parent: CARDINAL) ;
3600 VAR
3601 pSym: PtrToSymbol ;
3602 BEGIN
3603 pSym := GetPsym(Parent) ;
3604 WITH pSym^ DO
3605 CASE SymbolType OF
3606
3607 DefImpSym : PutItemIntoList(DefImp.ListOfModules, Sym) |
3608 ModuleSym : PutItemIntoList(Module.ListOfModules, Sym) |
3609 ProcedureSym: PutItemIntoList(Procedure.ListOfModules, Sym)
3610
3611 ELSE
3612 InternalError ('expecting DefImp or Module symbol')
3613 END
3614 END
3615 END AddModuleToParent ;
3616
3617
3618 (*
3619 MakeInnerModule - creates an inner module sym with ModuleName. It returns the
3620 symbol index.
3621 *)
3622
3623 PROCEDURE MakeInnerModule (tok: CARDINAL; ModuleName: Name) : CARDINAL ;
3624 VAR
3625 pSym: PtrToSymbol ;
3626 Sym : CARDINAL ;
3627 BEGIN
3628 Sym := DeclareSym (tok, ModuleName) ;
3629 IF NOT IsError(Sym)
3630 THEN
3631 pSym := GetPsym(Sym) ;
3632 WITH pSym^ DO
3633 SymbolType := ModuleSym ;
3634 WITH Module DO
3635 name := ModuleName ; (* Index into name array, name *)
3636 (* of record field. *)
3637 libname := NulName ; (* Library association. *)
3638 InitCtor (ctors) ; (* Init all ctor functions. *)
3639 InitTree(LocalSymbols) ; (* The LocalSymbols hold all the *)
3640 (* variables declared local to *)
3641 (* the block. It contains the *)
3642 (* FROM _ IMPORT x, y, x ; *)
3643 (* IMPORT A ; *)
3644 (* and also *)
3645 (* MODULE WeAreHere ; *)
3646 (* x y z visiable by localsym *)
3647 (* MODULE Inner ; *)
3648 (* EXPORT x, y, z ; *)
3649 (* END Inner ; *)
3650 (* END WeAreHere. *)
3651 InitTree(ExportTree) ; (* Holds all the exported *)
3652 (* identifiers. *)
3653 (* This tree may be *)
3654 (* deleted at the end of Pass 1. *)
3655 InitTree(ImportTree) ; (* Contains all IMPORTed *)
3656 (* identifiers. *)
3657 InitList(IncludeList) ; (* Contains all included symbols *)
3658 (* which are included by *)
3659 (* IMPORT modulename ; *)
3660 (* modulename.Symbol *)
3661 InitTree(ExportUndeclared) ; (* ExportUndeclared contains all *)
3662 (* the identifiers which were *)
3663 (* exported but have not yet *)
3664 (* been declared. *)
3665 InitList(EnumerationScopeList) ;(* Enumeration scope list which *)
3666 (* contains a list of all *)
3667 (* enumerations which are *)
3668 (* visable within this scope. *)
3669 InitTree(NamedObjects) ; (* Names of all items declared. *)
3670 InitTree(NamedImports) ; (* Names of items imported. *)
3671 InitTree(WhereImported) ; (* Sym to TokenNo where import *)
3672 (* occurs. Error message use. *)
3673 Priority := NulSym ; (* Priority of the module. This *)
3674 (* is an index to a constant. *)
3675 InitTree(Unresolved) ; (* All symbols currently *)
3676 (* unresolved in this module. *)
3677 StartQuad := 0 ; (* Signify the initialization *)
3678 (* code. *)
3679 EndQuad := 0 ; (* EndQuad should point to a *)
3680 (* goto quad. *)
3681 StartFinishQuad := 0 ; (* Signify the finalization *)
3682 (* code. *)
3683 EndFinishQuad := 0 ; (* should point to a finish *)
3684 FinallyFunction := NIL ; (* The GCC function for finally *)
3685 ExceptionFinally := FALSE ; (* does it have an exception? *)
3686 ExceptionBlock := FALSE ; (* does it have an exception? *)
3687 ModLink := GetLink () ; (* Is this parsed for linkage? *)
3688 InitList(ListOfVars) ; (* List of variables in this *)
3689 (* scope. *)
3690 InitList(ListOfProcs) ; (* List of all procedures *)
3691 (* declared within this module. *)
3692 InitList(ListOfModules) ; (* List of all inner modules. *)
3693 InitWhereDeclaredTok(tok, At) ; (* Where symbol declared. *)
3694 InitWhereFirstUsedTok(tok, At) ; (* Where symbol first used. *)
3695 IF GetCurrentScope()=GetBaseModule()
3696 THEN
3697 Scope := NulSym
3698 ELSE
3699 Scope := GetCurrentScope() ;
3700 AddModuleToParent(Sym, Scope)
3701 END ;
3702 errorScope := GetCurrentErrorScope () ; (* Title error scope. *)
3703 END ;
3704 END ;
3705 AddSymToScope(Sym, ModuleName)
3706 END ;
3707 RETURN Sym
3708 END MakeInnerModule ;
3709
3710
3711 (*
3712 MakeDefImp - creates a definition and implementation module sym
3713 with name DefImpName. It returns the symbol index.
3714 *)
3715
3716 PROCEDURE MakeDefImp (tok: CARDINAL; DefImpName: Name) : CARDINAL ;
3717 VAR
3718 pSym: PtrToSymbol ;
3719 Sym : CARDINAL ;
3720 BEGIN
3721 (* Make a new symbol since we are at the outer scope level. *)
3722 (* We cannot use DeclareSym as it examines the current scope *)
3723 (* for any symbols which have the correct name, but are yet *)
3724 (* undefined. *)
3725 (* tok := CheckTok (tok, 'defimp') ; *)
3726 NewSym(Sym) ;
3727 pSym := GetPsym(Sym) ;
3728 WITH pSym^ DO
3729 SymbolType := DefImpSym ;
3730 WITH DefImp DO
3731 name := DefImpName ; (* Index into name array, name *)
3732 (* of record field. *)
3733 libname := NulName ; (* Library association. *)
3734 InitCtor (ctors) ;
3735 (* Init all ctor functions. *)
3736 InitList(DefListOfDep) ; (* Vector of SymDependency. *)
3737 InitList(ModListOfDep) ; (* Vector of SymDependency. *)
3738 InitTree(ExportQualifiedTree) ;
3739 (* Holds all the EXPORT *)
3740 (* QUALIFIED identifiers. *)
3741 (* This tree may be *)
3742 (* deleted at the end of Pass 1. *)
3743 InitTree(ExportUnQualifiedTree) ;
3744 (* Holds all the EXPORT *)
3745 (* UNQUALIFIED identifiers. *)
3746 (* This tree may be *)
3747 (* deleted at the end of Pass 1. *)
3748 InitTree(ExportRequest) ; (* Contains all identifiers that *)
3749 (* have been requested by other *)
3750 (* modules before this module *)
3751 (* declared its export list. *)
3752 (* This tree should be empty at *)
3753 (* the end of the compilation. *)
3754 (* Each time a symbol is *)
3755 (* exported it is removed from *)
3756 (* this list. *)
3757 InitTree(ImportTree) ; (* Contains all IMPORTed *)
3758 (* identifiers. *)
3759 InitList(IncludeList) ; (* Contains all included symbols *)
3760 (* which are included by *)
3761 (* IMPORT modulename ; *)
3762 (* modulename.Symbol *)
3763 InitList(DefIncludeList) ; (* Contains all included symbols *)
3764 (* which are included by *)
3765 (* IMPORT modulename ; *)
3766 (* in the definition module only *)
3767 InitTree(ExportUndeclared) ; (* ExportUndeclared contains all *)
3768 (* the identifiers which were *)
3769 (* exported but have not yet *)
3770 (* been declared. *)
3771 InitTree(NeedToBeImplemented) ;
3772 (* NeedToBeImplemented contains *)
3773 (* the identifiers which have *)
3774 (* been exported and declared *)
3775 (* but have not yet been *)
3776 (* implemented. *)
3777 InitTree(LocalSymbols) ; (* The LocalSymbols hold all the *)
3778 (* variables declared local to *)
3779 (* the block. It contains the *)
3780 (* IMPORT r ; *)
3781 (* FROM _ IMPORT x, y, x ; *)
3782 (* and also *)
3783 (* MODULE WeAreHere ; *)
3784 (* x y z visiable by localsym *)
3785 (* MODULE Inner ; *)
3786 (* EXPORT x, y, z ; *)
3787 (* END Inner ; *)
3788 (* END WeAreHere. *)
3789 InitList(EnumerationScopeList) ;
3790 (* Enumeration scope list which *)
3791 (* contains a list of all *)
3792 (* enumerations which are *)
3793 (* visable within this scope. *)
3794 InitTree(NamedObjects) ; (* names of all items declared. *)
3795 InitTree(NamedImports) ; (* Names of items imported. *)
3796 InitTree(WhereImported) ; (* Sym to TokenNo where import *)
3797 (* occurs. Error message use. *)
3798 Priority := NulSym ; (* Priority of the module. This *)
3799 (* is an index to a constant. *)
3800 InitTree(Unresolved) ; (* All symbols currently *)
3801 (* unresolved in this module. *)
3802 StartQuad := 0 ; (* Signify the initialization *)
3803 (* code. *)
3804 EndQuad := 0 ; (* EndQuad should point to a *)
3805 (* goto quad. *)
3806 StartFinishQuad := 0 ; (* Signify the finalization *)
3807 (* code. *)
3808 EndFinishQuad := 0 ; (* should point to a finish *)
3809 FinallyFunction := NIL ; (* The GCC function for finally *)
3810 ExceptionFinally := FALSE ; (* does it have an exception? *)
3811 ExceptionBlock := FALSE ; (* does it have an exception? *)
3812 ContainsHiddenType := FALSE ;(* True if this module *)
3813 (* implements a hidden type. *)
3814 ContainsBuiltin := FALSE ; (* Does module define a builtin *)
3815 (* procedure? *)
3816 ForC := FALSE ; (* Is it a definition for "C" *)
3817 NeedExportList := FALSE ; (* Must user supply export list? *)
3818 DefLink := GetLink () ; (* Is the def/mod file only *)
3819 ModLink := GetLink () ; (* parsed for linkage? *)
3820 Builtin := FALSE ; (* Is the module builtin? *)
3821 InitList(ListOfVars) ; (* List of variables in this *)
3822 (* scope. *)
3823 InitList(ListOfProcs) ; (* List of all procedures *)
3824 (* declared within this module. *)
3825 InitList(ListOfModules) ; (* List of all inner modules. *)
3826 InitWhereDeclaredTok(tok, At) ; (* Where symbol declared. *)
3827 InitWhereFirstUsedTok(tok, At) ; (* Where symbol first used. *)
3828 errorScope := GetCurrentErrorScope () ; (* Title error scope. *)
3829 END
3830 END ;
3831 PutSymKey(ModuleTree, DefImpName, Sym) ;
3832 RETURN Sym
3833 END MakeDefImp ;
3834
3835
3836 (*
3837 PutLibName - places libname into defimp or module sym.
3838 *)
3839
3840 PROCEDURE PutLibName (sym: CARDINAL; libname: Name) ;
3841 VAR
3842 pSym: PtrToSymbol ;
3843 BEGIN
3844 Assert (IsModule (sym) OR IsDefImp (sym)) ;
3845 pSym := GetPsym (sym) ;
3846 WITH pSym^ DO
3847 CASE SymbolType OF
3848
3849 DefImpSym: DefImp.libname := libname |
3850 ModuleSym: Module.libname := libname
3851
3852 ELSE
3853 InternalError ('expecting DefImp or Module symbol')
3854 END
3855 END
3856 END PutLibName ;
3857
3858
3859 (*
3860 GetLibName - returns libname associated with a defimp or module sym.
3861 *)
3862
3863 PROCEDURE GetLibName (sym: CARDINAL) : Name ;
3864 VAR
3865 pSym: PtrToSymbol ;
3866 BEGIN
3867 Assert (IsModule (sym) OR IsDefImp (sym)) ;
3868 pSym := GetPsym (sym) ;
3869 WITH pSym^ DO
3870 CASE SymbolType OF
3871
3872 DefImpSym: RETURN DefImp.libname |
3873 ModuleSym: RETURN Module.libname
3874
3875 ELSE
3876 InternalError ('expecting DefImp or Module symbol')
3877 END
3878 END
3879 END GetLibName ;
3880
3881
3882 (*
3883 PutProcedureExternPublic - if procedure is not NulSym set extern
3884 and public booleans.
3885 *)
3886
3887 PROCEDURE PutProcedureExternPublic (procedure: CARDINAL; extern, pub: BOOLEAN) ;
3888 BEGIN
3889 IF procedure # NulSym
3890 THEN
3891 PutExtern (procedure, extern) ;
3892 PutPublic (procedure, pub)
3893 END
3894 END PutProcedureExternPublic ;
3895
3896
3897 (*
3898 PutCtorExtern -
3899 *)
3900
3901 PROCEDURE PutCtorExtern (tok: CARDINAL; sym: CARDINAL;
3902 VAR ctor: ModuleCtor; extern: BOOLEAN) ;
3903 BEGIN
3904 (* If the ctor does not exist then make it extern/ (~extern) public. *)
3905 IF ctor.ctor = NulSym
3906 THEN
3907 ctor.ctor := MakeProcedure (tok, GenName (GetLibName (sym), "_M2_", GetSymName (sym), "_ctor")) ;
3908 PutMonoName (ctor.ctor, TRUE)
3909 END ;
3910 PutProcedureExternPublic (ctor.ctor, extern, NOT extern) ;
3911 PutCtor (ctor.ctor, TRUE) ;
3912 (* If the ctor does not exist then make it extern/ (~extern) public. *)
3913 IF ctor.dep = NulSym
3914 THEN
3915 ctor.dep := MakeProcedure (tok, GenName (GetLibName (sym), "_M2_", GetSymName (sym), "_dep")) ;
3916 PutMonoName (ctor.dep, TRUE)
3917 END ;
3918 PutProcedureExternPublic (ctor.dep, extern, NOT extern) ;
3919 (* If init/fini do not exist then create them. *)
3920 IF ctor.init = NulSym
3921 THEN
3922 ctor.init := MakeProcedure (tok, GenName (GetLibName (sym), "_M2_", GetSymName (sym), "_init")) ;
3923 DeclareArgEnvParams (tok, ctor.init) ;
3924 PutMonoName (ctor.init, NOT IsInnerModule (sym))
3925 END ;
3926 PutProcedureExternPublic (ctor.init, extern, NOT extern) ;
3927 IF ctor.fini = NulSym
3928 THEN
3929 ctor.fini := MakeProcedure (tok, GenName (GetLibName (sym), "_M2_", GetSymName (sym), "_fini")) ;
3930 DeclareArgEnvParams (tok, ctor.fini) ;
3931 PutMonoName (ctor.fini, NOT IsInnerModule (sym))
3932 END ;
3933 PutProcedureExternPublic (ctor.fini, extern, NOT extern)
3934 END PutCtorExtern ;
3935
3936
3937 (*
3938 PutModuleCtorExtern - for every ctor related procedure in module sym.
3939 Make it external. It will create any missing
3940 init/fini procedures but not any missing dep/ctor
3941 procedures.
3942 *)
3943
3944 PROCEDURE PutModuleCtorExtern (tok: CARDINAL; sym: CARDINAL; external: BOOLEAN) ;
3945 VAR
3946 pSym: PtrToSymbol ;
3947 BEGIN
3948 Assert (IsModule (sym) OR IsDefImp (sym)) ;
3949 pSym := GetPsym (sym) ;
3950 WITH pSym^ DO
3951 CASE SymbolType OF
3952
3953 DefImpSym: PutCtorExtern (tok, sym, DefImp.ctors, external) |
3954 ModuleSym: PutCtorExtern (tok, sym, Module.ctors, external)
3955
3956 ELSE
3957 InternalError ('expecting DefImp or Module symbol')
3958 END
3959 END
3960 END PutModuleCtorExtern ;
3961
3962
3963 (*
3964 InitProcedureDeclaration - initialize all the ProcedureDeclaration
3965 fields.
3966 *)
3967
3968 PROCEDURE InitProcedureDeclaration (VAR decl: ProcedureDeclaration) ;
3969 BEGIN
3970 WITH decl DO
3971 Defined := FALSE ; (* Has the procedure been *)
3972 (* declared yet? *)
3973 ParamDefined := FALSE ; (* Have the parameters been *)
3974 (* defined yet? *)
3975 HasVarArgs := FALSE ; (* Does the procedure use ... ? *)
3976 HasOptArg := FALSE ; (* Does this procedure use [ ] ? *)
3977 IsNoReturn := FALSE ; (* Declared attribute noreturn ? *)
3978 ReturnOptional := FALSE ; (* Is the return value optional? *)
3979 ProcedureTok := UnknownTokenNo
3980 END
3981 END InitProcedureDeclaration ;
3982
3983
3984 (*
3985 MakeProcedure - creates a procedure sym with name. It returns
3986 the symbol index.
3987 *)
3988
3989 PROCEDURE MakeProcedure (tok: CARDINAL; ProcedureName: Name) : CARDINAL ;
3990 VAR
3991 pSym: PtrToSymbol ;
3992 Sym : CARDINAL ;
3993 kind: ProcedureKind ;
3994 BEGIN
3995 tok := CheckTok (tok, 'procedure') ;
3996 Sym := DeclareSym(tok, ProcedureName) ;
3997 CheckBreak (Sym) ;
3998 IF NOT IsError(Sym)
3999 THEN
4000 pSym := GetPsym(Sym) ;
4001 WITH pSym^ DO
4002 SymbolType := ProcedureSym ;
4003 WITH Procedure DO
4004 name := ProcedureName ;
4005 FOR kind := MIN (ProcedureKind) TO MAX (ProcedureKind) DO
4006 InitProcedureDeclaration (Decl[kind]) ;
4007 InitList (Decl[kind].ListOfParam)
4008 END ;
4009 OptArgInit := NulSym ; (* The optional arg default *)
4010 (* value. *)
4011 IsExtern := FALSE ; (* Make this procedure external. *)
4012 IsPublic := FALSE ; (* Make this procedure visible. *)
4013 IsCtor := FALSE ; (* Is this procedure a ctor? *)
4014 IsMonoName := FALSE ; (* Overrides module name prefix. *)
4015 BuildProcType := TRUE ; (* Are we building the *)
4016 (* proctype associated with sym? *)
4017 Scope := GetCurrentScope() ; (* Scope of procedure. *)
4018 InitTree(Unresolved) ; (* All symbols currently *)
4019 (* unresolved in this procedure. *)
4020 ScopeQuad := 0 ; (* Index into list of quads, *)
4021 StartQuad := 0 ; (* defining the scope, start and *)
4022 EndQuad := 0 ; (* end of the procedure. *)
4023 Reachable := FALSE ; (* Procedure not known to be *)
4024 (* reachable. *)
4025 SavePriority := FALSE ; (* Does procedure need to save *)
4026 (* and restore interrupts? *)
4027 ReturnType := NulSym ; (* Not a function yet! *)
4028 (* The ProcType equivalent. *)
4029 ProcedureType := MakeProcType (tok, NulName) ;
4030 InitTree(LocalSymbols) ;
4031 InitList(EnumerationScopeList) ;
4032 (* Enumeration scope list which *)
4033 (* contains a list of all *)
4034 (* enumerations which are *)
4035 (* visable within this scope. *)
4036 InitTree(NamedObjects) ; (* Names of all items declared. *)
4037 InitList(ListOfVars) ; (* List of variables in this *)
4038 (* scope. *)
4039 InitList(ListOfProcs) ; (* List of all procedures *)
4040 (* declared within this *)
4041 (* procedure. *)
4042 InitList(ListOfModules) ; (* List of all inner modules. *)
4043 ExceptionFinally := FALSE ; (* does it have an exception? *)
4044 ExceptionBlock := FALSE ; (* does it have an exception? *)
4045 IsBuiltin := FALSE ; (* Was it declared __BUILTIN__ ? *)
4046 BuiltinName := NulName ; (* name of equivalent builtin *)
4047 IsInline := FALSE ; (* Was is declared __INLINE__ ? *)
4048 Size := InitValue() ; (* Activation record size. *)
4049 TotalParamSize
4050 := InitValue() ; (* size of all parameters. *)
4051 Begin := 0 ; (* token number for BEGIN *)
4052 End := 0 ; (* token number for END *)
4053 InitWhereDeclaredTok(tok, At) ; (* Where the symbol was declared. *)
4054 errorScope := GetCurrentErrorScope () ; (* Title error scope. *)
4055 END
4056 END ;
4057 (* Now add this procedure to the symbol table of the current scope *)
4058 AddSymToScope(Sym, ProcedureName) ;
4059 AddProcedureToList(GetCurrentScope(), Sym)
4060 END ;
4061 RETURN Sym
4062 END MakeProcedure ;
4063
4064
4065 (*
4066 PutProcedureNoReturn - places value into the no return attribute
4067 field of procedure sym.
4068 *)
4069
4070 PROCEDURE PutProcedureNoReturn (Sym: CARDINAL; kind: ProcedureKind;
4071 value: BOOLEAN) ;
4072 VAR
4073 pSym: PtrToSymbol ;
4074 BEGIN
4075 pSym := GetPsym (Sym) ;
4076 WITH pSym^ DO
4077 CASE SymbolType OF
4078
4079 ProcedureSym: Procedure.Decl[kind].IsNoReturn := value
4080
4081 ELSE
4082 InternalError ('expecting ProcedureSym symbol')
4083 END
4084 END
4085 END PutProcedureNoReturn ;
4086
4087
4088 (*
4089 IsProcedureNoReturn - returns TRUE if this procedure never returns.
4090 *)
4091
4092 PROCEDURE IsProcedureNoReturn (Sym: CARDINAL; kind: ProcedureKind) : BOOLEAN ;
4093 VAR
4094 pSym: PtrToSymbol ;
4095 BEGIN
4096 pSym := GetPsym (Sym) ;
4097 WITH pSym^ DO
4098 CASE SymbolType OF
4099
4100 ProcedureSym: RETURN Procedure.Decl[kind].IsNoReturn
4101
4102 ELSE
4103 InternalError ('expecting ProcedureSym symbol')
4104 END
4105 END
4106 END IsProcedureNoReturn ;
4107
4108
4109 (*
4110 PutMonoName - changes the IsMonoName boolean inside the procedure.
4111 *)
4112
4113 PROCEDURE PutMonoName (sym: CARDINAL; value: BOOLEAN) ;
4114 VAR
4115 pSym: PtrToSymbol ;
4116 BEGIN
4117 pSym := GetPsym (sym) ;
4118 WITH pSym^ DO
4119 CASE SymbolType OF
4120
4121 ProcedureSym: Procedure.IsMonoName := value
4122
4123 ELSE
4124 InternalError ('expecting ProcedureSym symbol')
4125 END
4126 END
4127 END PutMonoName ;
4128
4129
4130 (*
4131 IsMonoName - returns the public boolean associated with a procedure.
4132 *)
4133
4134 PROCEDURE IsMonoName (sym: CARDINAL) : BOOLEAN ;
4135 VAR
4136 pSym: PtrToSymbol ;
4137 BEGIN
4138 pSym := GetPsym (sym) ;
4139 WITH pSym^ DO
4140 CASE SymbolType OF
4141
4142 ProcedureSym: RETURN Procedure.IsMonoName
4143
4144 ELSE
4145 InternalError ('expecting ProcedureSym symbol')
4146 END
4147 END
4148 END IsMonoName ;
4149
4150
4151 (*
4152 PutExtern - changes the extern boolean inside the procedure.
4153 *)
4154
4155 PROCEDURE PutExtern (sym: CARDINAL; value: BOOLEAN) ;
4156 VAR
4157 pSym: PtrToSymbol ;
4158 BEGIN
4159 pSym := GetPsym (sym) ;
4160 WITH pSym^ DO
4161 CASE SymbolType OF
4162
4163 ProcedureSym: Procedure.IsExtern := value
4164
4165 ELSE
4166 InternalError ('expecting ProcedureSym symbol')
4167 END
4168 END
4169 END PutExtern ;
4170
4171
4172 (*
4173 IsExtern - returns the public boolean associated with a procedure.
4174 *)
4175
4176 PROCEDURE IsExtern (sym: CARDINAL) : BOOLEAN ;
4177 VAR
4178 pSym: PtrToSymbol ;
4179 BEGIN
4180 pSym := GetPsym (sym) ;
4181 WITH pSym^ DO
4182 CASE SymbolType OF
4183
4184 ProcedureSym: RETURN Procedure.IsExtern
4185
4186 ELSE
4187 InternalError ('expecting ProcedureSym symbol')
4188 END
4189 END
4190 END IsExtern ;
4191
4192
4193 (*
4194 PutPublic - changes the public boolean inside the procedure.
4195 *)
4196
4197 PROCEDURE PutPublic (sym: CARDINAL; value: BOOLEAN) ;
4198 VAR
4199 pSym: PtrToSymbol ;
4200 BEGIN
4201 pSym := GetPsym (sym) ;
4202 WITH pSym^ DO
4203 CASE SymbolType OF
4204
4205 ProcedureSym : Procedure.IsPublic := value
4206
4207 ELSE
4208 InternalError ('expecting ProcedureSym symbol')
4209 END
4210 END
4211 END PutPublic ;
4212
4213
4214 (*
4215 IsPublic - returns the public boolean associated with a procedure.
4216 *)
4217
4218 PROCEDURE IsPublic (sym: CARDINAL) : BOOLEAN ;
4219 VAR
4220 pSym: PtrToSymbol ;
4221 BEGIN
4222 pSym := GetPsym (sym) ;
4223 WITH pSym^ DO
4224 CASE SymbolType OF
4225
4226 ProcedureSym : RETURN Procedure.IsPublic
4227
4228 ELSE
4229 InternalError ('expecting ProcedureSym symbol')
4230 END
4231 END
4232 END IsPublic ;
4233
4234
4235 (*
4236 PutCtor - changes the ctor boolean inside the procedure.
4237 *)
4238
4239 PROCEDURE PutCtor (sym: CARDINAL; value: BOOLEAN) ;
4240 VAR
4241 pSym: PtrToSymbol ;
4242 BEGIN
4243 pSym := GetPsym (sym) ;
4244 WITH pSym^ DO
4245 CASE SymbolType OF
4246
4247 ProcedureSym : Procedure.IsCtor := value
4248
4249 ELSE
4250 InternalError ('expecting ProcedureSym symbol')
4251 END
4252 END
4253 END PutCtor ;
4254
4255
4256 (*
4257 IsCtor - returns the ctor boolean associated with a procedure.
4258 *)
4259
4260 PROCEDURE IsCtor (sym: CARDINAL) : BOOLEAN ;
4261 VAR
4262 pSym: PtrToSymbol ;
4263 BEGIN
4264 pSym := GetPsym (sym) ;
4265 WITH pSym^ DO
4266 CASE SymbolType OF
4267
4268 ProcedureSym : RETURN Procedure.IsCtor
4269
4270 ELSE
4271 InternalError ('expecting ProcedureSym symbol')
4272 END
4273 END
4274 END IsCtor ;
4275
4276
4277 (*
4278 AddProcedureToList - adds a procedure, Proc, to the list of procedures
4279 in module, Mod.
4280 *)
4281
4282 PROCEDURE AddProcedureToList (Mod, Proc: CARDINAL) ;
4283 VAR
4284 pSym: PtrToSymbol ;
4285 BEGIN
4286 pSym := GetPsym(Mod) ;
4287 WITH pSym^ DO
4288 CASE SymbolType OF
4289
4290 DefImpSym : PutItemIntoList(DefImp.ListOfProcs, Proc) |
4291 ModuleSym : PutItemIntoList(Module.ListOfProcs, Proc) |
4292 ProcedureSym: PutItemIntoList(Procedure.ListOfProcs, Proc)
4293
4294 ELSE
4295 InternalError ('expecting ModuleSym, DefImpSym or ProcedureSym symbol')
4296 END
4297 END
4298 END AddProcedureToList ;
4299
4300
4301 (*
4302 AddVarToScopeList - adds symbol, sym, to, scope.
4303 *)
4304
4305 PROCEDURE AddVarToScopeList (scope, sym: CARDINAL) ;
4306 VAR
4307 pSym: PtrToSymbol ;
4308 BEGIN
4309 pSym := GetPsym(scope) ;
4310 WITH pSym^ DO
4311 CASE SymbolType OF
4312
4313 ProcedureSym: PutItemIntoList(Procedure.ListOfVars, sym) |
4314 ModuleSym : PutItemIntoList(Module.ListOfVars, sym) |
4315 DefImpSym : PutItemIntoList(DefImp.ListOfVars, sym)
4316
4317 ELSE
4318 InternalError ('expecting Procedure or Module symbol')
4319 END
4320 END
4321 END AddVarToScopeList ;
4322
4323
4324 (*
4325 AddVarToList - add a variable symbol to the list of variables maintained
4326 by the inner most scope. (Procedure or Module).
4327 *)
4328
4329 PROCEDURE AddVarToList (Sym: CARDINAL) ;
4330 VAR
4331 pCall: PtrToCallFrame ;
4332 BEGIN
4333 pCall := GetPcall(ScopePtr) ;
4334 AddVarToScopeList(pCall^.Main, Sym)
4335 END AddVarToList ;
4336
4337
4338 (*
4339 InitVarDecl - initialize the variable and type token location positions.
4340 *)
4341
4342 PROCEDURE InitVarDecl (VAR decl: VarDecl; vartok: CARDINAL) ;
4343 BEGIN
4344 decl.FullTok := UnknownTokenNo ;
4345 decl.VarTok := vartok ;
4346 decl.TypeTok := UnknownTokenNo
4347 END InitVarDecl ;
4348
4349
4350 (*
4351 doPutVarDeclTypeTok - places typetok into decl.TypeTok.
4352 sym must be a variable.
4353 *)
4354
4355 PROCEDURE doPutVarDeclTypeTok (sym: CARDINAL; typetok: CARDINAL) ;
4356 VAR
4357 pSym: PtrToSymbol ;
4358 BEGIN
4359 Assert (IsVar (sym)) ;
4360 pSym := GetPsym (sym) ;
4361 WITH pSym^.Var DO
4362 Declared.TypeTok := typetok
4363 END
4364 END doPutVarDeclTypeTok ;
4365
4366
4367 (*
4368 PutVarDeclTypeTok - assigns the TypeTok field to typetok.
4369 sym can be a variable or parameter.
4370 *)
4371
4372 PROCEDURE PutVarDeclTypeTok (sym: CARDINAL; typetok: CARDINAL) ;
4373 VAR
4374 pSym: PtrToSymbol ;
4375 BEGIN
4376 IF IsParameter (sym)
4377 THEN
4378 pSym := GetPsym (sym) ;
4379 IF IsParameterVar (sym)
4380 THEN
4381 PutVarDeclTypeTok (pSym^.VarParam.ShadowVar, typetok)
4382 ELSE
4383 PutVarDeclTypeTok (pSym^.Param.ShadowVar, typetok)
4384 END
4385 ELSIF IsVar (sym)
4386 THEN
4387 doPutVarDeclTypeTok (sym, typetok)
4388 END
4389 END PutVarDeclTypeTok ;
4390
4391
4392 (*
4393 doPutVarDeclTok - places vartok into decl.VarTok.
4394 sym must be a variable.
4395 *)
4396
4397 PROCEDURE doPutVarDeclTok (sym: CARDINAL; vartok: CARDINAL) ;
4398 VAR
4399 pSym: PtrToSymbol ;
4400 BEGIN
4401 Assert (IsVar (sym)) ;
4402 pSym := GetPsym (sym) ;
4403 WITH pSym^.Var DO
4404 Declared.VarTok := vartok
4405 END
4406 END doPutVarDeclTok ;
4407
4408
4409 (*
4410 PutVarDeclTok - assigns the VarTok field to typetok.
4411 sym can be a variable or parameter.
4412 *)
4413
4414 PROCEDURE PutVarDeclTok (sym: CARDINAL; vartok: CARDINAL) ;
4415 VAR
4416 pSym: PtrToSymbol ;
4417 BEGIN
4418 IF IsParameter (sym)
4419 THEN
4420 pSym := GetPsym (sym) ;
4421 IF IsParameterVar (sym)
4422 THEN
4423 PutVarDeclTok (pSym^.VarParam.ShadowVar, vartok)
4424 ELSE
4425 PutVarDeclTok (pSym^.Param.ShadowVar, vartok)
4426 END
4427 ELSIF IsVar (sym)
4428 THEN
4429 doPutVarDeclTok (sym, vartok)
4430 END
4431 END PutVarDeclTok ;
4432
4433
4434 (*
4435 doGetVarDeclTok - return decl.VarTok for a variable.
4436 *)
4437
4438 PROCEDURE doGetVarDeclTok (sym: CARDINAL) : CARDINAL ;
4439 VAR
4440 pSym: PtrToSymbol ;
4441 BEGIN
4442 pSym := GetPsym (sym) ;
4443 Assert (IsVar (sym)) ;
4444 WITH pSym^.Var DO
4445 RETURN Declared.VarTok
4446 END
4447 END doGetVarDeclTok ;
4448
4449
4450 (*
4451 GetVarDeclTok - returns the TypeTok field associate with variable sym.
4452 *)
4453
4454 PROCEDURE GetVarDeclTok (sym: CARDINAL) : CARDINAL ;
4455 VAR
4456 pSym: PtrToSymbol ;
4457 BEGIN
4458 IF IsParameter (sym)
4459 THEN
4460 pSym := GetPsym (sym) ;
4461 IF IsParameterVar (sym)
4462 THEN
4463 IF pSym^.VarParam.ShadowVar = NulSym
4464 THEN
4465 RETURN pSym^.VarParam.At
4466 ELSE
4467 RETURN GetVarDeclTok (pSym^.VarParam.ShadowVar)
4468 END
4469 ELSE
4470 IF pSym^.Param.ShadowVar = NulSym
4471 THEN
4472 RETURN pSym^.Param.At
4473 ELSE
4474 RETURN GetVarDeclTok (pSym^.Param.ShadowVar)
4475 END
4476 END
4477 ELSIF IsVar (sym)
4478 THEN
4479 RETURN doGetVarDeclTok (sym)
4480 ELSE
4481 RETURN UnknownTokenNo
4482 END
4483 END GetVarDeclTok ;
4484
4485
4486 (*
4487 doGetVarDeclTypeTok - return decl.TypeTok for a variable.
4488 *)
4489
4490 PROCEDURE doGetVarDeclTypeTok (sym: CARDINAL) : CARDINAL ;
4491 VAR
4492 pSym: PtrToSymbol ;
4493 BEGIN
4494 pSym := GetPsym (sym) ;
4495 Assert (IsVar (sym)) ;
4496 WITH pSym^.Var DO
4497 RETURN Declared.TypeTok
4498 END
4499 END doGetVarDeclTypeTok ;
4500
4501
4502 (*
4503 GetVarDeclTypeTok - returns the TypeTok field associate with variable sym.
4504 *)
4505
4506 PROCEDURE GetVarDeclTypeTok (sym: CARDINAL) : CARDINAL ;
4507 VAR
4508 pSym: PtrToSymbol ;
4509 BEGIN
4510 IF IsParameter (sym)
4511 THEN
4512 pSym := GetPsym (sym) ;
4513 IF IsParameterVar (sym)
4514 THEN
4515 RETURN GetVarDeclTypeTok (pSym^.VarParam.ShadowVar)
4516 ELSE
4517 RETURN GetVarDeclTypeTok (pSym^.Param.ShadowVar)
4518 END
4519 ELSIF IsVar (sym)
4520 THEN
4521 RETURN doGetVarDeclTypeTok (sym)
4522 ELSE
4523 RETURN UnknownTokenNo
4524 END
4525 END GetVarDeclTypeTok ;
4526
4527
4528 (*
4529 doGetVarDeclFullTok - return the full declaration of var: type.
4530 *)
4531
4532 PROCEDURE doGetVarDeclFullTok (sym: CARDINAL) : CARDINAL ;
4533 VAR
4534 pSym: PtrToSymbol ;
4535 BEGIN
4536 pSym := GetPsym (sym) ;
4537 Assert (IsVar (sym)) ;
4538 WITH pSym^.Var DO
4539 IF Declared.FullTok = UnknownTokenNo
4540 THEN
4541 IF Declared.TypeTok = UnknownTokenNo
4542 THEN
4543 RETURN Declared.VarTok
4544 ELSE
4545 Declared.FullTok := MakeVirtual2Tok (Declared.VarTok, Declared.TypeTok)
4546 END
4547 END ;
4548 RETURN Declared.FullTok
4549 END
4550 END doGetVarDeclFullTok ;
4551
4552
4553 (*
4554 GetVarDeclFullTok - returns the full virtual token containing var: type.
4555 *)
4556
4557 PROCEDURE GetVarDeclFullTok (sym: CARDINAL) : CARDINAL ;
4558 VAR
4559 pSym: PtrToSymbol ;
4560 BEGIN
4561 pSym := GetPsym (sym) ;
4562 IF IsParameter (sym)
4563 THEN
4564 IF IsParameterVar (sym)
4565 THEN
4566 RETURN pSym^.VarParam.FullTok
4567 ELSE
4568 RETURN pSym^.Param.FullTok
4569 END
4570 ELSIF IsVar (sym)
4571 THEN
4572 RETURN doGetVarDeclFullTok (sym)
4573 ELSE
4574 RETURN UnknownTokenNo
4575 END
4576 END GetVarDeclFullTok ;
4577
4578
4579 (*
4580 MakeVar - creates a variable sym with VarName. It returns the
4581 symbol index.
4582 *)
4583
4584 PROCEDURE MakeVar (tok: CARDINAL; VarName: Name) : CARDINAL ;
4585 VAR
4586 pSym: PtrToSymbol ;
4587 Sym : CARDINAL ;
4588 BEGIN
4589 Sym := DeclareSym (tok, VarName) ;
4590 IF NOT IsError(Sym)
4591 THEN
4592 pSym := GetPsym(Sym) ;
4593 WITH pSym^ DO
4594 SymbolType := VarSym ;
4595 WITH Var DO
4596 name := VarName ;
4597 Type := NulSym ;
4598 BackType := NulSym ;
4599 Size := InitValue() ;
4600 Offset := InitValue() ;
4601 AddrMode := RightValue ;
4602 Scope := GetCurrentScope() ; (* Procedure or Module? *)
4603 AtAddress := FALSE ;
4604 Address := NulSym ; (* Address at which declared. *)
4605 IsConditional := FALSE ;
4606 IsTemp := FALSE ;
4607 IsComponentRef := FALSE ;
4608 IsParam := FALSE ;
4609 IsPointerCheck := FALSE ;
4610 IsWritten := FALSE ;
4611 IsSSA := FALSE ;
4612 IsConst := FALSE ;
4613 ArrayRef := FALSE ;
4614 Heap := FALSE ;
4615 InitVarDecl (Declared, tok) ;
4616 InitWhereDeclaredTok(tok, At) ;
4617 InitWhereFirstUsedTok(tok, At) ; (* Where symbol first used. *)
4618 InitList(ReadUsageList[RightValue]) ;
4619 InitList(WriteUsageList[RightValue]) ;
4620 InitList(ReadUsageList[LeftValue]) ;
4621 InitList(WriteUsageList[LeftValue]) ;
4622 InitState[LeftValue] := InitSymInit () ;
4623 InitState[RightValue] := InitSymInit ()
4624 END
4625 END ;
4626 (* Add Var to Procedure or Module variable list. *)
4627 AddVarToList(Sym) ;
4628 (* Now add this Var to the symbol table of the current scope. *)
4629 AddSymToScope(Sym, VarName)
4630 END ;
4631 RETURN Sym
4632 END MakeVar ;
4633
4634
4635 (*
4636 PutVarConditional - assign IsConditional to value.
4637 *)
4638
4639 PROCEDURE PutVarConditional (sym: CARDINAL; value: BOOLEAN) ;
4640 VAR
4641 pSym: PtrToSymbol ;
4642 BEGIN
4643 pSym := GetPsym(sym) ;
4644 WITH pSym^ DO
4645 CASE SymbolType OF
4646
4647 VarSym : Var.IsConditional := value |
4648 ConstVarSym: ConstVar.IsConditional := value
4649
4650 ELSE
4651 InternalError ('expecting Var')
4652 END
4653 END
4654 END PutVarConditional ;
4655
4656
4657 (*
4658 IsVarConditional - return TRUE if the symbol is a var symbol
4659 containing the result of a boolean conditional.
4660 *)
4661
4662 PROCEDURE IsVarConditional (sym: CARDINAL) : BOOLEAN ;
4663 VAR
4664 pSym: PtrToSymbol ;
4665 BEGIN
4666 pSym := GetPsym(sym) ;
4667 WITH pSym^ DO
4668 CASE SymbolType OF
4669
4670 VarSym : RETURN Var.IsConditional |
4671 ConstVarSym: RETURN ConstVar.IsConditional
4672
4673 ELSE
4674 RETURN FALSE
4675 END
4676 END ;
4677 RETURN FALSE
4678 END IsVarConditional ;
4679
4680
4681 (*
4682 PutExceptionBlock - sets a BOOLEAN in block module/procedure/defimp,
4683 sym, indicating that this block as an EXCEPT
4684 statement sequence.
4685 *)
4686
4687 PROCEDURE PutExceptionBlock (sym: CARDINAL) ;
4688 VAR
4689 pSym: PtrToSymbol ;
4690 BEGIN
4691 pSym := GetPsym(sym) ;
4692 WITH pSym^ DO
4693 CASE SymbolType OF
4694
4695 ProcedureSym: Procedure.ExceptionBlock := TRUE |
4696 ModuleSym : Module.ExceptionBlock := TRUE |
4697 DefImpSym : DefImp.ExceptionBlock := TRUE
4698
4699 ELSE
4700 InternalError ('expecting Procedure')
4701 END
4702 END
4703 END PutExceptionBlock ;
4704
4705
4706 (*
4707 HasExceptionBlock - returns a BOOLEAN determining whether
4708 module/procedure/defimp, sym, has
4709 an EXCEPT statement sequence.
4710 *)
4711
4712 PROCEDURE HasExceptionBlock (sym: CARDINAL) : BOOLEAN ;
4713 VAR
4714 pSym: PtrToSymbol ;
4715 BEGIN
4716 pSym := GetPsym(sym) ;
4717 WITH pSym^ DO
4718 CASE SymbolType OF
4719
4720 ProcedureSym: RETURN( Procedure.ExceptionBlock ) |
4721 ModuleSym : RETURN( Module.ExceptionBlock ) |
4722 DefImpSym : RETURN( DefImp.ExceptionBlock )
4723
4724 ELSE
4725 InternalError ('expecting Procedure')
4726 END
4727 END
4728 END HasExceptionBlock ;
4729
4730
4731 (*
4732 PutExceptionFinally - sets a BOOLEAN in block module/defimp,
4733 sym, indicating that this FINALLY block
4734 as an EXCEPT statement sequence.
4735 *)
4736
4737 PROCEDURE PutExceptionFinally (sym: CARDINAL) ;
4738 VAR
4739 pSym: PtrToSymbol ;
4740 BEGIN
4741 pSym := GetPsym(sym) ;
4742 WITH pSym^ DO
4743 CASE SymbolType OF
4744
4745 ProcedureSym: Procedure.ExceptionFinally := TRUE |
4746 ModuleSym : Module.ExceptionFinally := TRUE |
4747 DefImpSym : DefImp.ExceptionFinally := TRUE
4748
4749 ELSE
4750 InternalError ('expecting DefImp or Module symbol')
4751 END
4752 END
4753 END PutExceptionFinally ;
4754
4755
4756 (*
4757 HasExceptionFinally - returns a BOOLEAN determining whether
4758 module/defimp, sym, has
4759 an EXCEPT statement sequence.
4760 *)
4761
4762 PROCEDURE HasExceptionFinally (sym: CARDINAL) : BOOLEAN ;
4763 VAR
4764 pSym: PtrToSymbol ;
4765 BEGIN
4766 pSym := GetPsym(sym) ;
4767 WITH pSym^ DO
4768 CASE SymbolType OF
4769
4770 ProcedureSym: RETURN( Procedure.ExceptionFinally ) |
4771 ModuleSym : RETURN( Module.ExceptionFinally ) |
4772 DefImpSym : RETURN( DefImp.ExceptionFinally )
4773
4774 ELSE
4775 InternalError ('expecting DefImp or Module symbol')
4776 END
4777 END
4778 END HasExceptionFinally ;
4779
4780
4781 (*
4782 FillInRecordFields - given a new symbol, sym, make it a record symbol
4783 and initialize its fields.
4784 *)
4785
4786 PROCEDURE FillInRecordFields (tok: CARDINAL; sym: CARDINAL; RecordName: Name;
4787 scope: CARDINAL; oaf: CARDINAL) ;
4788 VAR
4789 pSym: PtrToSymbol ;
4790 BEGIN
4791 IF NOT IsError(sym)
4792 THEN
4793 pSym := GetPsym (sym) ;
4794 WITH pSym^ DO
4795 SymbolType := RecordSym ;
4796 WITH Record DO
4797 name := RecordName ;
4798 InitTree (LocalSymbols) ;
4799 Size := InitValue () ;
4800 InitList (ListOfSons) ; (* List of RecordFieldSym and VarientSym *)
4801 oafamily := oaf ;
4802 Parent := NulSym ;
4803 Align := NulSym ;
4804 DefaultAlign := NulSym ;
4805 DeclPacked := FALSE ;
4806 DeclResolved := FALSE ;
4807 Scope := scope ;
4808 InitWhereDeclaredTok (tok, At)
4809 END
4810 END
4811 END
4812 END FillInRecordFields ;
4813
4814
4815 (*
4816 HandleHiddenOrDeclare -
4817 *)
4818
4819 PROCEDURE HandleHiddenOrDeclare (tok: CARDINAL; name: Name; VAR oaf: CARDINAL) : CARDINAL ;
4820 VAR
4821 sym: CARDINAL ;
4822 BEGIN
4823 sym := CheckForHiddenType (name) ;
4824 IF sym=NulSym
4825 THEN
4826 sym := DeclareSym (tok, name) ;
4827 IF NOT IsError (sym)
4828 THEN
4829 (* Now add this type to the symbol table of the current scope *)
4830 AddSymToScope (sym, name)
4831 END
4832 END ;
4833 oaf := GetOAFamily (sym) ;
4834 RETURN sym
4835 END HandleHiddenOrDeclare ;
4836
4837
4838 (*
4839 MakeRecord - makes a Record symbol with name RecordName.
4840 *)
4841
4842 PROCEDURE MakeRecord (tok: CARDINAL; RecordName: Name) : CARDINAL ;
4843 VAR
4844 oaf, sym: CARDINAL ;
4845 BEGIN
4846 tok := CheckTok (tok, 'record') ;
4847 sym := HandleHiddenOrDeclare (tok, RecordName, oaf) ;
4848 FillInRecordFields (tok, sym, RecordName, GetCurrentScope (), oaf) ;
4849 ForeachOAFamily (oaf, doFillInOAFamily) ;
4850 RETURN sym
4851 END MakeRecord ;
4852
4853
4854 (*
4855 MakeVarient - creates a new symbol, a varient symbol for record or varient field
4856 symbol, RecOrVarFieldSym.
4857 *)
4858
4859 PROCEDURE MakeVarient (tok: CARDINAL; RecOrVarFieldSym: CARDINAL) : CARDINAL ;
4860 VAR
4861 pSym: PtrToSymbol ;
4862 Sym : CARDINAL ;
4863 BEGIN
4864 tok := CheckTok (tok, 'varient') ;
4865 NewSym (Sym) ;
4866 pSym := GetPsym(Sym) ;
4867 WITH pSym^ DO
4868 SymbolType := VarientSym ;
4869 WITH Varient DO
4870 Size := InitValue() ;
4871 Parent := RecOrVarFieldSym ; (* GetRecord(RecOrVarFieldSym) ; *)
4872 IF IsRecord(RecOrVarFieldSym)
4873 THEN
4874 Varient := NulSym
4875 ELSE
4876 Varient := RecOrVarFieldSym
4877 END ;
4878 tag := NulSym ;
4879 DeclPacked := FALSE ;
4880 Scope := GetCurrentScope() ;
4881 InitList(ListOfSons) ;
4882 InitWhereDeclaredTok(tok, At)
4883 END
4884 END ;
4885 (* Now add Sym to the record RecSym field list *)
4886 pSym := GetPsym(RecOrVarFieldSym) ;
4887 WITH pSym^ DO
4888 CASE SymbolType OF
4889
4890 RecordSym : PutItemIntoList(Record.ListOfSons, Sym) |
4891 VarientFieldSym: PutItemIntoList(VarientField.ListOfSons, Sym)
4892
4893 ELSE
4894 InternalError ('expecting Record or VarientField symbol')
4895 END
4896 END ;
4897 RETURN Sym
4898 END MakeVarient ;
4899
4900
4901 (*
4902 GetRecord - fetches the record symbol from the parent of Sym.
4903 Sym maybe a varient symbol in which case its parent is searched
4904 etc.
4905 *)
4906
4907 PROCEDURE GetRecord (Sym: CARDINAL) : CARDINAL ;
4908 VAR
4909 pSym: PtrToSymbol ;
4910 BEGIN
4911 pSym := GetPsym (Sym) ;
4912 WITH pSym^ DO
4913 CASE SymbolType OF
4914
4915 RecordSym : RETURN Sym |
4916 VarientSym : RETURN GetRecord(Varient.Parent) |
4917 VarientFieldSym: RETURN GetRecord(VarientField.Parent)
4918
4919 ELSE
4920 InternalError ('expecting Record or Varient symbol')
4921 END
4922 END
4923 END GetRecord ;
4924
4925
4926 (*
4927 PutDeclaredPacked - sets the Packed field of the record or record field symbol.
4928 *)
4929
4930 PROCEDURE PutDeclaredPacked (sym: CARDINAL; b: BOOLEAN) ;
4931 VAR
4932 pSym: PtrToSymbol ;
4933 BEGIN
4934 pSym := GetPsym(sym) ;
4935 WITH pSym^ DO
4936 CASE SymbolType OF
4937
4938 RecordSym : Record.DeclPacked := b ;
4939 Record.DeclResolved := TRUE |
4940 RecordFieldSym : RecordField.DeclPacked := b ;
4941 RecordField.DeclResolved := TRUE |
4942 VarientFieldSym: VarientField.DeclPacked := b ;
4943 VarientField.DeclResolved := TRUE |
4944 VarientSym : Varient.DeclPacked := b ;
4945 Varient.DeclResolved := TRUE
4946
4947 ELSE
4948 InternalError ('expecting a record or field record symbol')
4949 END
4950 END
4951 END PutDeclaredPacked ;
4952
4953
4954 (*
4955 IsDeclaredPacked - was the record symbol or record field, sym,
4956 declared as packed?
4957 *)
4958
4959 PROCEDURE IsDeclaredPacked (sym: CARDINAL) : BOOLEAN ;
4960 VAR
4961 pSym: PtrToSymbol ;
4962 BEGIN
4963 pSym := GetPsym (sym) ;
4964 WITH pSym^ DO
4965 CASE SymbolType OF
4966
4967 RecordSym : RETURN Record.DeclPacked |
4968 RecordFieldSym : RETURN RecordField.DeclPacked |
4969 VarientFieldSym: RETURN VarientField.DeclPacked |
4970 VarientSym : RETURN Varient.DeclPacked
4971
4972 ELSE
4973 InternalError ('expecting a record or a record field symbol')
4974 END
4975 END
4976 END IsDeclaredPacked ;
4977
4978
4979 (*
4980 IsDeclaredPackedResolved - do we know if the record symbol or record
4981 field, sym, declared as packed or not packed?
4982 *)
4983
4984 PROCEDURE IsDeclaredPackedResolved (sym: CARDINAL) : BOOLEAN ;
4985 VAR
4986 pSym: PtrToSymbol ;
4987 BEGIN
4988 pSym := GetPsym (sym) ;
4989 WITH pSym^ DO
4990 CASE SymbolType OF
4991
4992 RecordSym : RETURN Record.DeclResolved |
4993 RecordFieldSym : RETURN RecordField.DeclResolved |
4994 VarientFieldSym: RETURN VarientField.DeclResolved |
4995 VarientSym : RETURN Varient.DeclResolved
4996
4997 ELSE
4998 InternalError ('expecting a record or a record field symbol')
4999 END
5000 END
5001 END IsDeclaredPackedResolved ;
5002
5003
5004 (*
5005 MakeEnumeration - places a new symbol in the current scope, the symbol
5006 is an enumeration symbol. The symbol index is returned.
5007 *)
5008
5009 PROCEDURE MakeEnumeration (tok: CARDINAL; EnumerationName: Name) : CARDINAL ;
5010 VAR
5011 pSym : PtrToSymbol ;
5012 sym, oaf: CARDINAL ;
5013 BEGIN
5014 tok := CheckTok (tok, 'enumeration') ;
5015 sym := CheckForHiddenType (EnumerationName) ;
5016 IF sym=NulSym
5017 THEN
5018 sym := DeclareSym (tok, EnumerationName) ;
5019 oaf := GetOAFamily (sym) ;
5020 IF NOT IsError (sym)
5021 THEN
5022 pSym := GetPsym (sym) ;
5023 pSym^.SymbolType := EnumerationSym ; (* To satisfy AddSymToScope *)
5024 (* Now add this type to the symbol table of the current scope *)
5025 AddSymToScope (sym, EnumerationName)
5026 END
5027 ELSE
5028 oaf := GetOAFamily (sym)
5029 END ;
5030 IF NOT IsError (sym)
5031 THEN
5032 pSym := GetPsym (sym) ;
5033 WITH pSym^ DO
5034 SymbolType := EnumerationSym ;
5035 WITH Enumeration DO
5036 name := EnumerationName ; (* Name of enumeration. *)
5037 NoOfElements := 0 ; (* No of elements in the *)
5038 (* enumeration type. *)
5039 Size := InitValue () ; (* Size at runtime of sym *)
5040 InitTree (LocalSymbols) ; (* Enumeration fields. *)
5041 InitList (ListOfFields) ; (* Ordered as declared. *)
5042 InitPacked (packedInfo) ; (* not packed and no *)
5043 (* equivalent (yet). *)
5044 oafamily := oaf ; (* The open array family *)
5045 Scope := GetCurrentScope () ; (* Which scope created it *)
5046 InitWhereDeclaredTok (tok, At) (* Declared here *)
5047 END
5048 END ;
5049 CheckIfEnumerationExported (sym, ScopePtr)
5050 END ;
5051 ForeachOAFamily (oaf, doFillInOAFamily) ;
5052 RETURN sym
5053 END MakeEnumeration ;
5054
5055
5056 (*
5057 MakeType - makes a type symbol with name TypeName.
5058 *)
5059
5060 PROCEDURE MakeType (tok: CARDINAL; TypeName: Name) : CARDINAL ;
5061 VAR
5062 pSym : PtrToSymbol ;
5063 sym, oaf: CARDINAL ;
5064 BEGIN
5065 sym := HandleHiddenOrDeclare (tok, TypeName, oaf) ;
5066 IF NOT IsError(sym)
5067 THEN
5068 pSym := GetPsym(sym) ;
5069 WITH pSym^ DO
5070 SymbolType := TypeSym ;
5071 WITH Type DO
5072 name := TypeName ; (* Index into name array, name *)
5073 (* of type. *)
5074 Type := NulSym ; (* Index to a type symbol. *)
5075 IsHidden := FALSE ; (* Was it declared as hidden? *)
5076 InitTree(ConstLitTree) ; (* constants of this type. *)
5077 Size := InitValue() ; (* Runtime size of symbol. *)
5078 Align := NulSym ; (* Alignment of this type. *)
5079 InitPacked(packedInfo) ; (* not packed and no *)
5080 (* equivalent yet. *)
5081 oafamily := oaf ; (* The open array family. *)
5082 Scope := GetCurrentScope() ; (* Which scope created it *)
5083 InitWhereDeclaredTok(tok, At) (* Declared here *)
5084 END
5085 END
5086 END ;
5087 ForeachOAFamily(oaf, doFillInOAFamily) ;
5088 RETURN sym
5089 END MakeType ;
5090
5091
5092 (*
5093 MakeHiddenType - makes a type symbol that is hidden from the
5094 definition module.
5095 This symbol is placed into the UnImplemented list of
5096 the definition/implementation module.
5097 The type will be filled in when the implementation module
5098 is reached.
5099 *)
5100
5101 PROCEDURE MakeHiddenType (tok: CARDINAL; TypeName: Name) : CARDINAL ;
5102 VAR
5103 pSym: PtrToSymbol ;
5104 Sym : CARDINAL ;
5105 BEGIN
5106 tok := CheckTok (tok, 'hidden') ;
5107 Sym := DeclareSym (tok, TypeName) ;
5108 IF NOT IsError(Sym)
5109 THEN
5110 pSym := GetPsym(Sym) ;
5111 WITH pSym^ DO
5112 SymbolType := TypeSym ;
5113 WITH Type DO
5114 name := TypeName ; (* Index into name array, name *)
5115 (* of type. *)
5116 IsHidden := GetMainModule()#GetCurrentScope() ;
5117 IF ExtendedOpaque OR (NOT IsHidden)
5118 THEN
5119 Type := NulSym (* will be filled in later *)
5120 ELSE
5121 Type := Address
5122 END ;
5123 Align := NulSym ; (* Alignment of this type. *)
5124 Scope := GetCurrentScope() ; (* Which scope created it *)
5125 oafamily := NulSym ;
5126 IF NOT ExtendedOpaque
5127 THEN
5128 IncludeItemIntoList(AddressTypes, Sym)
5129 END ;
5130 Size := InitValue() ; (* Runtime size of symbol. *)
5131 InitWhereDeclaredTok(tok, At) (* Declared here *)
5132 END
5133 END ;
5134 PutExportUnImplemented (tok, Sym) ;
5135 IF ExtendedOpaque OR (GetMainModule()=GetCurrentScope())
5136 THEN
5137 PutHiddenTypeDeclared
5138 END ;
5139 (* Now add this type to the symbol table of the current scope *)
5140 AddSymToScope(Sym, TypeName)
5141 END ;
5142 RETURN Sym
5143 END MakeHiddenType ;
5144
5145
5146 (*
5147 GetConstFromTypeTree - return a constant symbol from the tree owned by constType.
5148 NulSym is returned if the symbol is unknown.
5149 *)
5150
5151 (*
5152 PROCEDURE GetConstFromTypeTree (constName: Name; constType: CARDINAL) : CARDINAL ;
5153 VAR
5154 pSym: PtrToSymbol ;
5155 BEGIN
5156 IF constType=NulSym
5157 THEN
5158 RETURN GetSymKey(ConstLitTree, constName)
5159 ELSE
5160 pSym := GetPsym(constType) ;
5161 Assert(IsType(constType) OR IsSubrange(constType) OR IsPointer(constType)) ;
5162 WITH pSym^ DO
5163 CASE SymbolType OF
5164
5165 TypeSym : RETURN GetSymKey (Type.ConstLitTree, constName) |
5166 SubrangeSym: RETURN GetSymKey (Subrange.ConstLitTree, constName) |
5167 PointerSym : RETURN GetSymKey (Pointer.ConstLitTree, constName)
5168
5169 ELSE
5170 InternalError ('expecting Type symbol')
5171 END
5172 END
5173 END
5174 END GetConstFromTypeTree ;
5175 *)
5176
5177
5178 (*
5179 PutConstIntoTypeTree - places, constSym, into the tree of constants owned by, constType.
5180 constName is the name of constSym.
5181 *)
5182
5183 (*
5184 PROCEDURE PutConstIntoTypeTree (constName: Name; constType: CARDINAL; constSym: CARDINAL) ;
5185 VAR
5186 pSym: PtrToSymbol ;
5187 BEGIN
5188 IF constType=NulSym
5189 THEN
5190 PutSymKey(ConstLitTree, constName, constSym)
5191 ELSE
5192 pSym := GetPsym(constType) ;
5193 Assert(IsType(constType) OR IsSubrange(constType) OR IsPointer(constType)) ;
5194 WITH pSym^ DO
5195 CASE SymbolType OF
5196
5197 TypeSym : PutSymKey (Type.ConstLitTree, constName, constSym) |
5198 SubrangeSym: PutSymKey (Subrange.ConstLitTree, constName, constSym) |
5199 PointerSym : PutSymKey (Pointer.ConstLitTree, constName, constSym)
5200
5201 ELSE
5202 InternalError ('expecting Type symbol')
5203 END
5204 END
5205 END
5206 END PutConstIntoTypeTree ;
5207 *)
5208
5209
5210 (*
5211 MakeConstant - create a constant cardinal and return the symbol.
5212 *)
5213
5214 PROCEDURE MakeConstant (tok: CARDINAL; value: CARDINAL) : CARDINAL ;
5215 VAR
5216 str: String ;
5217 sym: CARDINAL ;
5218 BEGIN
5219 tok := CheckTok (tok, 'constant') ;
5220 str := Sprintf1 (Mark (InitString ("%d")), value) ;
5221 sym := MakeConstLit (tok, makekey (string (str)), Cardinal) ;
5222 str := KillString (str) ;
5223 RETURN sym
5224 END MakeConstant ;
5225
5226
5227 (*
5228 CreateConstLit -
5229 *)
5230
5231 PROCEDURE CreateConstLit (tok: CARDINAL; constName: Name; constType: CARDINAL) : CARDINAL ;
5232 VAR
5233 pSym : PtrToSymbol ;
5234 Sym : CARDINAL ;
5235 overflow : BOOLEAN ;
5236 BEGIN
5237 overflow := FALSE ;
5238 IF constType=NulSym
5239 THEN
5240 constType := GetConstLitType (tok, constName, overflow, TRUE)
5241 END ;
5242 NewSym (Sym) ;
5243 pSym := GetPsym (Sym) ;
5244 WITH pSym^ DO
5245 SymbolType := ConstLitSym ;
5246 CASE SymbolType OF
5247
5248 ConstLitSym : ConstLit.name := constName ;
5249 ConstLit.Value := InitValue () ;
5250 PushString (tok, constName, NOT overflow) ;
5251 PopInto (ConstLit.Value) ;
5252 ConstLit.Type := constType ;
5253 ConstLit.IsSet := FALSE ;
5254 ConstLit.IsInternal := FALSE ; (* Is it a default BY constant
5255 expression? *)
5256 ConstLit.IsConstructor := FALSE ;
5257 ConstLit.FromType := NulSym ; (* type is determined FromType *)
5258 ConstLit.RangeError := overflow ;
5259 ConstLit.UnresFromType := FALSE ; (* is Type resolved? *)
5260 ConstLit.Scope := GetCurrentScope () ;
5261 InitWhereDeclaredTok (tok, ConstLit.At) ;
5262 InitWhereFirstUsedTok (tok, ConstLit.At)
5263
5264 ELSE
5265 InternalError ('expecting ConstLit symbol')
5266 END
5267 END ;
5268 RETURN Sym
5269 END CreateConstLit ;
5270
5271
5272 (*
5273 LookupConstLitPoolEntry - return a ConstLit symbol from the constant pool which
5274 matches tok, constName and constType.
5275 *)
5276
5277 PROCEDURE LookupConstLitPoolEntry (tok: CARDINAL;
5278 constName: Name; constType: CARDINAL) : CARDINAL ;
5279 VAR
5280 pe : ConstLitPoolEntry ;
5281 rootIndex: CARDINAL ;
5282 BEGIN
5283 rootIndex := GetSymKey (ConstLitPoolTree, constName) ;
5284 IF rootIndex # 0
5285 THEN
5286 pe := Indexing.GetIndice (ConstLitArray, rootIndex) ;
5287 WHILE pe # NIL DO
5288 IF (pe^.tok = tok) AND
5289 (pe^.constName = constName) AND
5290 (pe^.constType = constType)
5291 THEN
5292 RETURN pe^.sym
5293 END ;
5294 pe := pe^.next
5295 END
5296 END ;
5297 RETURN NulSym
5298 END LookupConstLitPoolEntry ;
5299
5300
5301 (*
5302 AddConstLitPoolEntry - adds sym to the constlit pool.
5303 *)
5304
5305 PROCEDURE AddConstLitPoolEntry (sym: CARDINAL; tok: CARDINAL;
5306 constName: Name; constType: CARDINAL) ;
5307 VAR
5308 pe, old : ConstLitPoolEntry ;
5309 rootIndex, high: CARDINAL ;
5310 BEGIN
5311 rootIndex := GetSymKey (ConstLitPoolTree, constName) ;
5312 IF rootIndex = NulKey
5313 THEN
5314 high := Indexing.HighIndice (ConstLitArray) ;
5315 NEW (pe) ;
5316 IF pe = NIL
5317 THEN
5318 InternalError ('out of memory')
5319 ELSE
5320 pe^.sym := sym ;
5321 pe^.tok := tok ;
5322 pe^.constName := constName ;
5323 pe^.constType := constType ;
5324 pe^.next := NIL ;
5325 PutSymKey (ConstLitPoolTree, constName, high+1) ;
5326 Indexing.PutIndice (ConstLitArray, high+1, pe)
5327 END
5328 ELSE
5329 NEW (pe) ;
5330 IF pe = NIL
5331 THEN
5332 InternalError ('out of memory')
5333 ELSE
5334 old := Indexing.GetIndice (ConstLitArray, rootIndex) ;
5335 pe^.sym := sym ;
5336 pe^.tok := tok ;
5337 pe^.constName := constName ;
5338 pe^.constType := constType ;
5339 pe^.next := old ;
5340 Indexing.PutIndice (ConstLitArray, rootIndex, pe)
5341 END
5342 END
5343 END AddConstLitPoolEntry ;
5344
5345
5346 (*
5347 MakeConstLit - returns a constant literal of type, constType, with a constName,
5348 at location, tok.
5349 *)
5350
5351 PROCEDURE MakeConstLit (tok: CARDINAL; constName: Name; constType: CARDINAL) : CARDINAL ;
5352 VAR
5353 sym: CARDINAL ;
5354 BEGIN
5355 tok := CheckTok (tok, 'constlit') ;
5356 sym := LookupConstLitPoolEntry (tok, constName, constType) ;
5357 IF sym = NulSym
5358 THEN
5359 sym := CreateConstLit (tok, constName, constType) ;
5360 AddConstLitPoolEntry (sym, tok, constName, constType)
5361 END ;
5362 RETURN sym
5363 END MakeConstLit ;
5364
5365
5366 (*
5367 MakeConstVar - makes a ConstVar type with
5368 name ConstVarName.
5369 *)
5370
5371 PROCEDURE MakeConstVar (tok: CARDINAL; ConstVarName: Name) : CARDINAL ;
5372 VAR
5373 pSym: PtrToSymbol ;
5374 Sym : CARDINAL ;
5375 temp: BOOLEAN ;
5376 BEGIN
5377 temp := (ConstVarName = NulName) ;
5378 ConstVarName := CheckAnonymous (ConstVarName) ;
5379 Sym := DeclareSym (tok, ConstVarName) ;
5380 IF NOT IsError(Sym)
5381 THEN
5382 pSym := GetPsym(Sym) ;
5383 WITH pSym^ DO
5384 SymbolType := ConstVarSym ;
5385 WITH ConstVar DO
5386 name := ConstVarName ;
5387 Value := InitValue() ;
5388 Type := NulSym ;
5389 IsSet := FALSE ;
5390 IsConditional := FALSE ;
5391 IsConstructor := FALSE ;
5392 FromType := NulSym ; (* type is determined FromType *)
5393 UnresFromType := FALSE ; (* is Type resolved? *)
5394 IsTemp := temp ;
5395 Scope := GetCurrentScope () ;
5396 InitWhereDeclaredTok (tok, At)
5397 END
5398 END ;
5399 (* Now add this constant to the symbol table of the current scope *)
5400 AddSymToScope(Sym, ConstVarName)
5401 END ;
5402 RETURN( Sym )
5403 END MakeConstVar ;
5404
5405
5406 (*
5407 InitConstString - initialize the constant string.
5408 *)
5409
5410 PROCEDURE InitConstString (tok: CARDINAL; sym: CARDINAL; name, contents: Name;
5411 kind: ConstStringVariant; escape, known: BOOLEAN) ;
5412 VAR
5413 pSym: PtrToSymbol ;
5414 BEGIN
5415 pSym := GetPsym (sym) ;
5416 WITH pSym^ DO
5417 SymbolType := ConstStringSym ;
5418 CASE SymbolType OF
5419
5420 ConstStringSym: ConstString.name := name ;
5421 ConstString.StringVariant := kind ;
5422 ConstString.Scope := GetCurrentScope() ;
5423 InitWhereDeclaredTok (tok, ConstString.At) ;
5424 PutConstStringKnown (tok, sym, contents, escape, known)
5425
5426 ELSE
5427 InternalError ('expecting ConstStringSym')
5428 END
5429 END
5430 END InitConstString ;
5431
5432
5433 (*
5434 IsConstStringNulTerminated - returns TRUE if the constant string, sym,
5435 should be created with a nul terminator.
5436 *)
5437
5438 PROCEDURE IsConstStringNulTerminated (sym: CARDINAL) : BOOLEAN ;
5439 VAR
5440 pSym: PtrToSymbol ;
5441 BEGIN
5442 pSym := GetPsym (sym) ;
5443 WITH pSym^ DO
5444 CASE SymbolType OF
5445
5446 ConstStringSym: RETURN ((ConstString.StringVariant = m2nulstr) OR
5447 (ConstString.StringVariant = cnulstr))
5448
5449 ELSE
5450 InternalError ('expecting ConstStringSym')
5451 END
5452 END
5453 END IsConstStringNulTerminated ;
5454
5455
5456 (*
5457 MakeConstStringCnul - creates a constant string nul terminated string suitable for C.
5458 If known is TRUE then name is assigned to the contents
5459 and the escape sequences will be converted into characters.
5460 *)
5461
5462 PROCEDURE MakeConstStringCnul (tok: CARDINAL; name: Name; known: BOOLEAN) : CARDINAL ;
5463 VAR
5464 newstr: CARDINAL ;
5465 BEGIN
5466 tok := CheckTok (tok, 'conststringcnul') ;
5467 NewSym (newstr) ;
5468 InitConstString (tok, newstr, name, name, cnulstr, TRUE, known) ;
5469 RETURN newstr
5470 END MakeConstStringCnul ;
5471
5472
5473 (*
5474 MakeConstStringM2nul - creates a constant string nul terminated string suitable for M2.
5475 If known is TRUE then name is assigned to the contents
5476 however the escape sequences are not converted into characters.
5477 *)
5478
5479 PROCEDURE MakeConstStringM2nul (tok: CARDINAL; name: Name; known: BOOLEAN) : CARDINAL ;
5480 VAR
5481 newstr: CARDINAL ;
5482 BEGIN
5483 NewSym (newstr) ;
5484 InitConstString (tok, newstr, name, name, m2nulstr, FALSE, known) ;
5485 RETURN newstr
5486 END MakeConstStringM2nul ;
5487
5488
5489 (*
5490 MakeConstString - create a string constant in the symboltable.
5491 *)
5492
5493 PROCEDURE MakeConstString (tok: CARDINAL; ConstName: Name) : CARDINAL ;
5494 VAR
5495 newstr: CARDINAL ;
5496 BEGIN
5497 NewSym (newstr) ;
5498 InitConstString (tok, newstr, ConstName, ConstName, m2nulstr, FALSE, TRUE) ;
5499 RETURN newstr
5500 END MakeConstString ;
5501
5502
5503 (*
5504 PutConstStringKnown - if sym is a constvar then convert it into a conststring.
5505 If known is FALSE then contents is ignored and NulName is
5506 stored. If escape is TRUE then the contents will have
5507 any escape sequences converted into single characters.
5508 *)
5509
5510 PROCEDURE PutConstStringKnown (tok: CARDINAL; sym: CARDINAL;
5511 contents: Name; escape, known: BOOLEAN) ;
5512 VAR
5513 pSym: PtrToSymbol ;
5514 s : String ;
5515 BEGIN
5516 pSym := GetPsym (sym) ;
5517 WITH pSym^ DO
5518 CASE SymbolType OF
5519
5520 ConstStringSym: IF known
5521 THEN
5522 IF escape
5523 THEN
5524 s := HandleEscape (InitStringCharStar (KeyToCharStar (contents))) ;
5525 contents := makekey (string (s)) ;
5526 s := KillString (s)
5527 END ;
5528 ConstString.Length := LengthKey (contents) ;
5529 ConstString.Contents := contents
5530 ELSE
5531 ConstString.Length := 0 ;
5532 ConstString.Contents := NulName
5533 END ;
5534 ConstString.Known := known ;
5535 InitWhereDeclaredTok (tok, ConstString.At) ;
5536 InitWhereFirstUsedTok (tok, ConstString.At) |
5537
5538 ConstVarSym : (* Change a ConstVar to a ConstString copy name
5539 and alter symboltype. *)
5540 InitConstString (tok, sym, ConstVar.name, contents,
5541 m2str, escape, known)
5542
5543 ELSE
5544 InternalError ('expecting ConstString symbol')
5545 END
5546 END
5547 END PutConstStringKnown ;
5548
5549
5550 (*
5551 CopyConstString - copies string contents from expr to des
5552 and retain the kind of string.
5553 *)
5554
5555 PROCEDURE CopyConstString (tok: CARDINAL; des, expr: CARDINAL) ;
5556 VAR
5557 pSym: PtrToSymbol ;
5558 BEGIN
5559 Assert (IsConstStringKnown (expr)) ;
5560 pSym := GetPsym (des) ;
5561 WITH pSym^ DO
5562 CASE SymbolType OF
5563
5564 ConstStringSym: InitConstString (tok, des, ConstString.name,
5565 GetString (expr),
5566 GetConstStringKind (expr), FALSE, TRUE) |
5567 ConstVarSym : (* Change a ConstVar to a ConstString copy name
5568 and alter symboltype. *)
5569 InitConstString (tok, des, ConstVar.name,
5570 GetString (expr),
5571 GetConstStringKind (expr), FALSE, TRUE)
5572
5573 ELSE
5574 InternalError ('expecting ConstString symbol')
5575 END
5576 END
5577 END CopyConstString ;
5578
5579
5580 (*
5581 IsConstStringKnown - returns TRUE if sym is a const string
5582 and the contents are known.
5583 *)
5584
5585 PROCEDURE IsConstStringKnown (sym: CARDINAL) : BOOLEAN ;
5586 VAR
5587 pSym: PtrToSymbol ;
5588 BEGIN
5589 pSym := GetPsym (sym) ;
5590 WITH pSym^ DO
5591 CASE SymbolType OF
5592
5593 ConstStringSym: RETURN ConstString.Known
5594
5595 ELSE
5596 RETURN FALSE
5597 END
5598 END
5599 END IsConstStringKnown ;
5600
5601
5602 (*
5603 IsConstStringM2 - returns whether this conststring is a
5604 Modula-2 string.
5605 *)
5606
5607 PROCEDURE IsConstStringM2 (sym: CARDINAL) : BOOLEAN ;
5608 BEGIN
5609 RETURN GetConstStringKind (sym) = m2str
5610 END IsConstStringM2 ;
5611
5612
5613 (*
5614 IsConstStringC - returns whether this conststring is a C style string
5615 which will have any escape translated.
5616 *)
5617
5618 PROCEDURE IsConstStringC (sym: CARDINAL) : BOOLEAN ;
5619 BEGIN
5620 RETURN GetConstStringKind (sym) = cstr
5621 END IsConstStringC ;
5622
5623
5624 (*
5625 IsConstStringM2nul - returns whether this conststring is a Modula-2 string which
5626 contains a nul terminator.
5627 *)
5628
5629 PROCEDURE IsConstStringM2nul (sym: CARDINAL) : BOOLEAN ;
5630 BEGIN
5631 RETURN GetConstStringKind (sym) = m2nulstr
5632 END IsConstStringM2nul ;
5633
5634
5635 (*
5636 IsConstStringCnul - returns whether this conststring is a C style string
5637 which will have any escape translated and also contains
5638 a nul terminator.
5639 *)
5640
5641 PROCEDURE IsConstStringCnul (sym: CARDINAL) : BOOLEAN ;
5642 BEGIN
5643 RETURN GetConstStringKind (sym) = cnulstr
5644 END IsConstStringCnul ;
5645
5646
5647 (*
5648 GetConstStringKind - return the StringVariant field associated with sym.
5649 *)
5650
5651 PROCEDURE GetConstStringKind (sym: CARDINAL) : ConstStringVariant ;
5652 VAR
5653 pSym: PtrToSymbol ;
5654 BEGIN
5655 pSym := GetPsym (sym) ;
5656 WITH pSym^ DO
5657 CASE SymbolType OF
5658
5659 ConstStringSym: RETURN ConstString.StringVariant
5660
5661 ELSE
5662 InternalError ('expecting ConstString symbol')
5663 END
5664 END
5665 END GetConstStringKind ;
5666
5667
5668
5669 (*
5670 GetString - returns the contents of the string symbol sym, note that
5671 this is not the same as GetName (unless it was a literal).
5672 *)
5673
5674 PROCEDURE GetString (Sym: CARDINAL) : Name ;
5675 VAR
5676 pSym: PtrToSymbol ;
5677 BEGIN
5678 pSym := GetPsym (Sym) ;
5679 WITH pSym^ DO
5680 CASE SymbolType OF
5681
5682 ConstStringSym: IF ConstString.Known
5683 THEN
5684 RETURN ConstString.Contents
5685 ELSE
5686 InternalError ('const string contents are unknown')
5687 END
5688
5689 ELSE
5690 InternalError ('expecting ConstString symbol')
5691 END
5692 END
5693 END GetString ;
5694
5695
5696 (*
5697 GetStringLength - returns the length of the string symbol Sym.
5698 *)
5699
5700 PROCEDURE GetStringLength (tok: CARDINAL; sym: CARDINAL) : CARDINAL ;
5701 VAR
5702 pSym: PtrToSymbol ;
5703 BEGIN
5704 pSym := GetPsym (sym) ;
5705 WITH pSym^ DO
5706 CASE SymbolType OF
5707
5708 ConstStringSym: IF ConstString.Known
5709 THEN
5710 RETURN ConstString.Length
5711 ELSE
5712 MetaErrorT0 (tok, 'const string contents are unknown') ;
5713 RETURN 0
5714 END
5715
5716 ELSE
5717 InternalError ('expecting ConstString symbol')
5718 END
5719 END
5720 END GetStringLength ;
5721
5722
5723 (*
5724 PutVariableAtAddress - determines that a variable, sym, is declared at
5725 a specific address.
5726 *)
5727
5728 PROCEDURE PutVariableAtAddress (sym: CARDINAL; address: CARDINAL) ;
5729 VAR
5730 pSym: PtrToSymbol ;
5731 BEGIN
5732 Assert(sym#NulSym) ;
5733 pSym := GetPsym(sym) ;
5734 WITH pSym^ DO
5735 CASE SymbolType OF
5736
5737 VarSym: Var.AtAddress := TRUE ;
5738 Var.Address := address
5739
5740 ELSE
5741 InternalError ('expecting a variable symbol')
5742 END
5743 END
5744 END PutVariableAtAddress ;
5745
5746
5747 (*
5748 GetVariableAtAddress - returns the address at which variable, sym, is declared.
5749 *)
5750
5751 PROCEDURE GetVariableAtAddress (sym: CARDINAL) : CARDINAL ;
5752 VAR
5753 pSym: PtrToSymbol ;
5754 BEGIN
5755 Assert(sym#NulSym) ;
5756 pSym := GetPsym(sym) ;
5757 WITH pSym^ DO
5758 CASE SymbolType OF
5759
5760 VarSym: RETURN( Var.Address )
5761
5762 ELSE
5763 InternalError ('expecting a variable symbol')
5764 END
5765 END
5766 END GetVariableAtAddress ;
5767
5768
5769 (*
5770 IsVariableAtAddress - returns TRUE if a variable, sym, was declared at
5771 a specific address.
5772 *)
5773
5774 PROCEDURE IsVariableAtAddress (sym: CARDINAL) : BOOLEAN ;
5775 VAR
5776 pSym: PtrToSymbol ;
5777 BEGIN
5778 Assert(sym#NulSym) ;
5779 pSym := GetPsym(sym) ;
5780 WITH pSym^ DO
5781 CASE SymbolType OF
5782
5783 VarSym: RETURN( Var.AtAddress )
5784
5785 ELSE
5786 InternalError ('expecting a variable symbol')
5787 END
5788 END
5789 END IsVariableAtAddress ;
5790
5791
5792 (*
5793 PutVariableSSA - assigns value to the SSA field within variable sym.
5794 *)
5795
5796 PROCEDURE PutVariableSSA (sym: CARDINAL; value: BOOLEAN) ;
5797 VAR
5798 pSym: PtrToSymbol ;
5799 BEGIN
5800 Assert (sym#NulSym) ;
5801 pSym := GetPsym (sym) ;
5802 WITH pSym^ DO
5803 CASE SymbolType OF
5804
5805 VarSym: Var.IsSSA := value
5806
5807 ELSE
5808 InternalError ('expecting a variable symbol')
5809 END
5810 END
5811 END PutVariableSSA ;
5812
5813
5814 (*
5815 IsVariableSSA - returns TRUE if variable is known to be a SSA.
5816 *)
5817
5818 PROCEDURE IsVariableSSA (sym: CARDINAL) : BOOLEAN ;
5819 VAR
5820 pSym: PtrToSymbol ;
5821 BEGIN
5822 Assert (sym#NulSym) ;
5823 pSym := GetPsym (sym) ;
5824 WITH pSym^ DO
5825 CASE SymbolType OF
5826
5827 VarSym: RETURN Var.IsSSA
5828
5829 ELSE
5830 InternalError ('expecting a variable symbol')
5831 END
5832 END
5833 END IsVariableSSA ;
5834
5835
5836 (*
5837 PutPriority - places a interrupt, priority, value into module, module.
5838 *)
5839
5840 PROCEDURE PutPriority (module: CARDINAL; priority: CARDINAL) ;
5841 VAR
5842 pSym: PtrToSymbol ;
5843 BEGIN
5844 Assert(module#NulSym) ;
5845 pSym := GetPsym(module) ;
5846 WITH pSym^ DO
5847 CASE SymbolType OF
5848
5849 DefImpSym: DefImp.Priority := priority |
5850 ModuleSym: Module.Priority := priority
5851
5852 ELSE
5853 InternalError ('expecting DefImp or Module symbol')
5854 END
5855 END
5856 END PutPriority ;
5857
5858
5859 (*
5860 GetPriority - returns the interrupt priority which was assigned to
5861 module, module.
5862 *)
5863
5864 PROCEDURE GetPriority (module: CARDINAL) : CARDINAL ;
5865 VAR
5866 pSym: PtrToSymbol ;
5867 BEGIN
5868 Assert(module#NulSym) ;
5869 pSym := GetPsym(module) ;
5870 WITH pSym^ DO
5871 CASE SymbolType OF
5872
5873 DefImpSym: RETURN( DefImp.Priority ) |
5874 ModuleSym: RETURN( Module.Priority )
5875
5876 ELSE
5877 InternalError ('expecting DefImp or Module symbol')
5878 END
5879 END
5880 END GetPriority ;
5881
5882
5883 (*
5884 PutNeedSavePriority - set a boolean flag indicating that this procedure
5885 needs to save and restore interrupts.
5886 *)
5887
5888 PROCEDURE PutNeedSavePriority (sym: CARDINAL) ;
5889 VAR
5890 pSym: PtrToSymbol ;
5891 BEGIN
5892 pSym := GetPsym(sym) ;
5893 WITH pSym^ DO
5894 CASE SymbolType OF
5895
5896 ProcedureSym: Procedure.SavePriority := TRUE
5897
5898 ELSE
5899 InternalError ('expecting procedure symbol')
5900 END
5901 END
5902 END PutNeedSavePriority ;
5903
5904
5905 (*
5906 GetNeedSavePriority - returns the boolean flag indicating whether this procedure
5907 needs to save and restore interrupts.
5908 *)
5909
5910 PROCEDURE GetNeedSavePriority (sym: CARDINAL) : BOOLEAN ;
5911 VAR
5912 pSym: PtrToSymbol ;
5913 BEGIN
5914 pSym := GetPsym(sym) ;
5915 WITH pSym^ DO
5916 CASE SymbolType OF
5917
5918 ProcedureSym: RETURN( Procedure.SavePriority )
5919
5920 ELSE
5921 InternalError ('expecting procedure symbol')
5922 END
5923 END
5924 END GetNeedSavePriority ;
5925
5926
5927 (*
5928 GetProcedureBuiltin - returns the builtin name for the equivalent procedure, Sym.
5929 *)
5930
5931 PROCEDURE GetProcedureBuiltin (Sym: CARDINAL) : Name ;
5932 VAR
5933 pSym: PtrToSymbol ;
5934 BEGIN
5935 pSym := GetPsym(Sym) ;
5936 WITH pSym^ DO
5937 CASE SymbolType OF
5938
5939 ProcedureSym: RETURN( Procedure.BuiltinName )
5940
5941 ELSE
5942 InternalError ('expecting procedure symbol')
5943 END
5944 END
5945 END GetProcedureBuiltin ;
5946
5947
5948 (*
5949 PutProcedureBuiltin - assigns the builtin name for the equivalent procedure, Sym.
5950 *)
5951
5952 PROCEDURE PutProcedureBuiltin (Sym: CARDINAL; name: Name) ;
5953 VAR
5954 pSym: PtrToSymbol ;
5955 BEGIN
5956 pSym := GetPsym(Sym) ;
5957 WITH pSym^ DO
5958 CASE SymbolType OF
5959
5960 ProcedureSym : Procedure.BuiltinName := name ;
5961 Procedure.IsBuiltin := TRUE ;
5962 (* we use the same extra pass method as hidden types for builtins *)
5963 PutHiddenTypeDeclared
5964
5965 ELSE
5966 InternalError ('expecting procedure symbol')
5967 END
5968 END
5969 END PutProcedureBuiltin ;
5970
5971
5972 (*
5973 IsProcedureBuiltin - returns TRUE if this procedure has a builtin equivalent.
5974 *)
5975
5976 PROCEDURE IsProcedureBuiltin (Sym: CARDINAL) : BOOLEAN ;
5977 VAR
5978 pSym: PtrToSymbol ;
5979 BEGIN
5980 pSym := GetPsym(Sym) ;
5981 WITH pSym^ DO
5982 CASE SymbolType OF
5983
5984 ProcedureSym : RETURN( Procedure.IsBuiltin )
5985
5986 ELSE
5987 InternalError ('expecting procedure symbol')
5988 END
5989 END
5990 END IsProcedureBuiltin ;
5991
5992
5993 (*
5994 CanUseBuiltin - returns TRUE if the procedure, Sym, can be
5995 inlined via a builtin function.
5996 *)
5997
5998 PROCEDURE CanUseBuiltin (Sym: CARDINAL) : BOOLEAN ;
5999 BEGIN
6000 RETURN( (NOT DebugBuiltins) AND
6001 (BuiltinExists (KeyToCharStar (GetProcedureBuiltin (Sym))) OR
6002 BuiltinExists (KeyToCharStar (GetSymName (Sym)))) )
6003 END CanUseBuiltin ;
6004
6005
6006 (*
6007 IsProcedureBuiltinAvailable - return TRUE if procedure is available as a builtin
6008 for the target architecture.
6009 *)
6010
6011 PROCEDURE IsProcedureBuiltinAvailable (procedure: CARDINAL) : BOOLEAN ;
6012 BEGIN
6013 RETURN IsProcedureBuiltin (procedure) AND CanUseBuiltin (procedure)
6014 END IsProcedureBuiltinAvailable ;
6015
6016
6017 (*
6018 PutProcedureInline - determines that procedure, Sym, has been requested to be inlined.
6019 *)
6020
6021 PROCEDURE PutProcedureInline (Sym: CARDINAL) ;
6022 VAR
6023 pSym: PtrToSymbol ;
6024 BEGIN
6025 pSym := GetPsym(Sym) ;
6026 WITH pSym^ DO
6027 CASE SymbolType OF
6028
6029 ProcedureSym : Procedure.IsInline := TRUE ;
6030
6031 ELSE
6032 InternalError ('expecting procedure symbol')
6033 END
6034 END
6035 END PutProcedureInline ;
6036
6037
6038 (*
6039 IsProcedureBuiltin - returns TRUE if this procedure was declared as inlined.
6040 *)
6041
6042 PROCEDURE IsProcedureInline (Sym: CARDINAL) : BOOLEAN ;
6043 VAR
6044 pSym: PtrToSymbol ;
6045 BEGIN
6046 pSym := GetPsym(Sym) ;
6047 WITH pSym^ DO
6048 CASE SymbolType OF
6049
6050 ProcedureSym : RETURN( Procedure.IsInline )
6051
6052 ELSE
6053 InternalError ('expecting procedure symbol')
6054 END
6055 END
6056 END IsProcedureInline ;
6057
6058
6059 (*
6060 PutConstSet - informs the const var symbol, sym, that it is or will contain
6061 a set value.
6062 *)
6063
6064 PROCEDURE PutConstSet (Sym: CARDINAL) ;
6065 VAR
6066 pSym: PtrToSymbol ;
6067 BEGIN
6068 pSym := GetPsym(Sym) ;
6069 WITH pSym^ DO
6070 CASE SymbolType OF
6071
6072 ConstVarSym: ConstVar.IsSet := TRUE |
6073 ConstLitSym: ConstLit.IsSet := TRUE
6074
6075 ELSE
6076 InternalError ('expecting ConstVar symbol')
6077 END
6078 END
6079 END PutConstSet ;
6080
6081
6082 (*
6083 IsConstSet - returns TRUE if the constant is declared as a set.
6084 *)
6085
6086 PROCEDURE IsConstSet (Sym: CARDINAL) : BOOLEAN ;
6087 VAR
6088 pSym: PtrToSymbol ;
6089 BEGIN
6090 pSym := GetPsym(Sym) ;
6091 WITH pSym^ DO
6092 CASE SymbolType OF
6093
6094 ConstVarSym: RETURN( ConstVar.IsSet ) |
6095 ConstLitSym: RETURN( ConstLit.IsSet )
6096
6097 ELSE
6098 RETURN( FALSE )
6099 END
6100 END
6101 END IsConstSet ;
6102
6103
6104 (*
6105 PutConstructor - informs the const var symbol, sym, that it is or
6106 will contain a constructor (record, set or array)
6107 value.
6108 *)
6109
6110 PROCEDURE PutConstructor (Sym: CARDINAL) ;
6111 VAR
6112 pSym: PtrToSymbol ;
6113 BEGIN
6114 pSym := GetPsym(Sym) ;
6115 WITH pSym^ DO
6116 CASE SymbolType OF
6117
6118 ConstVarSym: ConstVar.IsConstructor := TRUE |
6119 ConstLitSym: ConstLit.IsConstructor := TRUE
6120
6121 ELSE
6122 InternalError ('expecting ConstVar or ConstLit symbol')
6123 END
6124 END
6125 END PutConstructor ;
6126
6127
6128 (*
6129 IsConstructor - returns TRUE if the constant is declared as a
6130 constant set, array or record.
6131 *)
6132
6133 PROCEDURE IsConstructor (Sym: CARDINAL) : BOOLEAN ;
6134 VAR
6135 pSym: PtrToSymbol ;
6136 BEGIN
6137 pSym := GetPsym(Sym) ;
6138 WITH pSym^ DO
6139 CASE SymbolType OF
6140
6141 ConstVarSym: RETURN( ConstVar.IsConstructor ) |
6142 ConstLitSym: RETURN( ConstLit.IsConstructor )
6143
6144 ELSE
6145 RETURN( FALSE )
6146 END
6147 END
6148 END IsConstructor ;
6149
6150
6151 (*
6152 PutConstructorFrom - sets the from type field in constructor,
6153 Sym, to, from.
6154 *)
6155
6156 PROCEDURE PutConstructorFrom (Sym: CARDINAL; from: CARDINAL) ;
6157 VAR
6158 pSym: PtrToSymbol ;
6159 BEGIN
6160 pSym := GetPsym(Sym) ;
6161 WITH pSym^ DO
6162 CASE SymbolType OF
6163
6164 ConstVarSym: ConstVar.FromType := from ;
6165 ConstVar.UnresFromType := TRUE |
6166 ConstLitSym: ConstLit.FromType := from ;
6167 ConstLit.UnresFromType := TRUE
6168
6169 ELSE
6170 InternalError ('expecting ConstVar or ConstLit symbol')
6171 END
6172 END ;
6173 IncludeItemIntoList(UnresolvedConstructorType, Sym)
6174 END PutConstructorFrom ;
6175
6176
6177 (*
6178 InitPacked - initialise packedInfo to FALSE and NulSym.
6179 *)
6180
6181 PROCEDURE InitPacked (VAR packedInfo: PackedInfo) ;
6182 BEGIN
6183 WITH packedInfo DO
6184 IsPacked := FALSE ;
6185 PackedEquiv := NulSym
6186 END
6187 END InitPacked ;
6188
6189
6190 (*
6191 doEquivalent - create a packed equivalent symbol for, sym, and return the
6192 new symbol. It sets both fields in packedInfo to FALSE
6193 and the new symbol.
6194 *)
6195
6196 PROCEDURE doEquivalent (VAR packedInfo: PackedInfo; sym: CARDINAL) : CARDINAL ;
6197 VAR
6198 nSym: CARDINAL ;
6199 pSym: PtrToSymbol ;
6200 BEGIN
6201 NewSym(nSym) ;
6202 pSym := GetPsym(nSym) ;
6203 WITH pSym^ DO
6204 SymbolType := EquivSym ;
6205 WITH Equiv DO
6206 nonPacked := sym ;
6207 packedInfo.IsPacked := TRUE ;
6208 packedInfo.PackedEquiv := NulSym
6209 END
6210 END ;
6211 packedInfo.IsPacked := FALSE ;
6212 packedInfo.PackedEquiv := nSym ;
6213 RETURN( nSym )
6214 END doEquivalent ;
6215
6216
6217 (*
6218 MakeEquivalent - return the equivalent packed symbol for, sym.
6219 *)
6220
6221 PROCEDURE MakeEquivalent (sym: CARDINAL) : CARDINAL ;
6222 VAR
6223 pSym: PtrToSymbol ;
6224 BEGIN
6225 pSym := GetPsym(sym) ;
6226 WITH pSym^ DO
6227 CASE SymbolType OF
6228
6229 EnumerationSym: RETURN( doEquivalent(Enumeration.packedInfo, sym) ) |
6230 SubrangeSym : RETURN( doEquivalent(Subrange.packedInfo, sym) ) |
6231 TypeSym : RETURN( doEquivalent(Type.packedInfo, sym) ) |
6232 SetSym : RETURN( doEquivalent(Set.packedInfo, sym) )
6233
6234 ELSE
6235 InternalError ('expecting type, subrange or enumerated type symbol')
6236 END
6237 END
6238 END MakeEquivalent ;
6239
6240
6241 (*
6242 GetEquivalent -
6243 *)
6244
6245 PROCEDURE GetEquivalent (VAR packedInfo: PackedInfo; sym: CARDINAL) : CARDINAL ;
6246 BEGIN
6247 WITH packedInfo DO
6248 IF IsPacked
6249 THEN
6250 RETURN( sym )
6251 ELSIF PackedEquiv=NulSym
6252 THEN
6253 PackedEquiv := MakeEquivalent(sym)
6254 END ;
6255 RETURN( PackedEquiv )
6256 END
6257 END GetEquivalent ;
6258
6259
6260 (*
6261 GetPackedEquivalent - returns the packed equivalent of type, sym.
6262 sym must be a type, subrange or enumerated type.
6263 *)
6264
6265 PROCEDURE GetPackedEquivalent (sym: CARDINAL) : CARDINAL ;
6266 VAR
6267 pSym: PtrToSymbol ;
6268 BEGIN
6269 pSym := GetPsym(sym) ;
6270 WITH pSym^ DO
6271 CASE SymbolType OF
6272
6273 EnumerationSym: RETURN( GetEquivalent(Enumeration.packedInfo, sym) ) |
6274 SubrangeSym : RETURN( GetEquivalent(Subrange.packedInfo, sym) ) |
6275 TypeSym : RETURN( GetEquivalent(Type.packedInfo, sym) ) |
6276 SetSym : RETURN( GetEquivalent(Set.packedInfo, sym) )
6277
6278 ELSE
6279 InternalError ('expecting type, subrange or enumerated type symbol')
6280 END
6281 END
6282 END GetPackedEquivalent ;
6283
6284
6285 (*
6286 GetNonPackedEquivalent - returns the equivalent non packed symbol associated with, sym.
6287 *)
6288
6289 PROCEDURE GetNonPackedEquivalent (sym: CARDINAL) : CARDINAL ;
6290 VAR
6291 pSym: PtrToSymbol ;
6292 BEGIN
6293 pSym := GetPsym(sym) ;
6294 WITH pSym^ DO
6295 CASE SymbolType OF
6296
6297 EquivSym: RETURN( Equiv.nonPacked )
6298
6299 ELSE
6300 InternalError ('expecting equivalent symbol')
6301 END
6302 END
6303 END GetNonPackedEquivalent ;
6304
6305
6306 (*
6307 IsEquivalent - returns TRUE if, sym, is an equivalent symbol.
6308 *)
6309
6310 PROCEDURE IsEquivalent (sym: CARDINAL) : BOOLEAN ;
6311 VAR
6312 pSym: PtrToSymbol ;
6313 BEGIN
6314 pSym := GetPsym(sym) ;
6315 WITH pSym^ DO
6316 CASE SymbolType OF
6317
6318 EquivSym: RETURN( TRUE )
6319
6320 ELSE
6321 RETURN( FALSE )
6322 END
6323 END
6324 END IsEquivalent ;
6325
6326
6327 (*
6328 MakeSubrange - makes a new symbol into a subrange type with
6329 name SubrangeName.
6330 *)
6331
6332 PROCEDURE MakeSubrange (tok: CARDINAL; SubrangeName: Name) : CARDINAL ;
6333 VAR
6334 pSym : PtrToSymbol ;
6335 sym, oaf: CARDINAL ;
6336 BEGIN
6337 tok := CheckTok (tok, 'subrange') ;
6338 sym := HandleHiddenOrDeclare (tok, SubrangeName, oaf) ;
6339 IF NOT IsError(sym)
6340 THEN
6341 pSym := GetPsym(sym) ;
6342 WITH pSym^ DO
6343 SymbolType := SubrangeSym ;
6344 WITH Subrange DO
6345 name := SubrangeName ;
6346 Low := NulSym ; (* Index to a symbol determining *)
6347 (* the lower bound of subrange. *)
6348 (* Points to a constant - *)
6349 (* possibly created by *)
6350 (* ConstExpression. *)
6351 High := NulSym ; (* Index to a symbol determining *)
6352 (* the lower bound of subrange. *)
6353 (* Points to a constant - *)
6354 (* possibly created by *)
6355 (* ConstExpression. *)
6356 Type := NulSym ; (* Index to a type. Determines *)
6357 (* the type of subrange. *)
6358 Align := NulSym ; (* The alignment of this type. *)
6359 InitPacked(packedInfo) ; (* not packed and no equivalent *)
6360 InitTree(ConstLitTree) ; (* constants of this type. *)
6361 Size := InitValue() ; (* Size determines the type size *)
6362 oafamily := oaf ; (* The unbounded sym for this *)
6363 Scope := GetCurrentScope() ; (* Which scope created it *)
6364 InitWhereDeclaredTok(tok, At) (* Declared here *)
6365 END
6366 END
6367 END ;
6368 ForeachOAFamily(oaf, doFillInOAFamily) ;
6369 RETURN sym
6370 END MakeSubrange ;
6371
6372
6373 (*
6374 MakeArray - makes an Array symbol with name ArrayName.
6375 *)
6376
6377 PROCEDURE MakeArray (tok: CARDINAL; ArrayName: Name) : CARDINAL ;
6378 VAR
6379 pSym : PtrToSymbol ;
6380 sym, oaf: CARDINAL ;
6381 BEGIN
6382 sym := HandleHiddenOrDeclare (tok, ArrayName, oaf) ;
6383 IF NOT IsError(sym)
6384 THEN
6385 pSym := GetPsym(sym) ;
6386 WITH pSym^ DO
6387 SymbolType := ArraySym ;
6388 WITH Array DO
6389 name := ArrayName ;
6390 Subscript := NulSym ; (* Contains the array subscripts. *)
6391 Size := InitValue() ; (* Size of array. *)
6392 Offset := InitValue() ; (* Offset of array. *)
6393 Type := NulSym ; (* The Array Type. ARRAY OF Type. *)
6394 Large := FALSE ; (* is this array large? *)
6395 Align := NulSym ; (* The alignment of this type. *)
6396 oafamily := oaf ; (* The unbounded for this array *)
6397 Scope := GetCurrentScope() ; (* Which scope created it *)
6398 InitWhereDeclaredTok(tok, At) (* Declared here *)
6399 END
6400 END
6401 END ;
6402 ForeachOAFamily(oaf, doFillInOAFamily) ;
6403 RETURN( sym )
6404 END MakeArray ;
6405
6406
6407 (*
6408 PutArrayLarge - indicates that this is a large array in which case
6409 the interface to gcc maps this array from 0..high-low,
6410 using an integer indice.
6411 *)
6412
6413 PROCEDURE PutArrayLarge (array: CARDINAL) ;
6414 VAR
6415 pSym: PtrToSymbol ;
6416 BEGIN
6417 IF NOT IsError(array)
6418 THEN
6419 Assert(IsArray(array)) ;
6420 pSym := GetPsym(array) ;
6421 WITH pSym^.Array DO
6422 Large := TRUE
6423 END
6424 END
6425 END PutArrayLarge ;
6426
6427
6428 (*
6429 IsArrayLarge - returns TRUE if we need to treat this as a large array.
6430 *)
6431
6432 PROCEDURE IsArrayLarge (array: CARDINAL) : BOOLEAN ;
6433 VAR
6434 pSym: PtrToSymbol ;
6435 BEGIN
6436 Assert(IsArray(array)) ;
6437 pSym := GetPsym(array) ;
6438 RETURN( pSym^.Array.Large )
6439 END IsArrayLarge ;
6440
6441
6442 (*
6443 GetModule - Returns the Module symbol for the module with name, name.
6444 *)
6445
6446 PROCEDURE GetModule (name: Name) : CARDINAL ;
6447 BEGIN
6448 RETURN( GetSymKey(ModuleTree, name) )
6449 END GetModule ;
6450
6451
6452 (*
6453 GetLowestType - Returns the lowest type in the type chain of
6454 symbol Sym.
6455 If NulSym is returned then we assume type unknown or
6456 you have reqested the type of a base type.
6457 *)
6458
6459 PROCEDURE GetLowestType (Sym: CARDINAL) : CARDINAL ;
6460 VAR
6461 pSym: PtrToSymbol ;
6462 type: CARDINAL ;
6463 BEGIN
6464 Assert(Sym#NulSym) ;
6465 pSym := GetPsym(Sym) ;
6466 WITH pSym^ DO
6467 CASE SymbolType OF
6468
6469 VarSym : type := Var.Type |
6470 ConstLitSym : type := ConstLit.Type |
6471 ConstVarSym : type := ConstVar.Type |
6472 ConstStringSym : type := NulSym | (* No type for a string *)
6473 TypeSym : type := Type.Type |
6474 RecordFieldSym : type := RecordField.Type |
6475 RecordSym : type := NulSym | (* No type for a record *)
6476 EnumerationFieldSym : type := EnumerationField.Type |
6477 EnumerationSym : type := NulSym | (* No type for enumeration *)
6478 PointerSym : type := Sym | (* we don't go to Pointer.Type *)
6479 ProcedureSym : type := Procedure.ReturnType |
6480 ProcTypeSym : type := ProcType.ReturnType |
6481 ParamSym : type := Param.Type |
6482 VarParamSym : type := VarParam.Type |
6483 SubrangeSym : type := Subrange.Type |
6484 ArraySym : type := Array.Type |
6485 SubscriptSym : type := Subscript.Type |
6486 SetSym : type := Sym | (* Stop at the set type. *)
6487 UnboundedSym : type := Unbounded.Type |
6488 UndefinedSym : type := NulSym |
6489 DummySym : type := NulSym
6490
6491 ELSE
6492 InternalError ('not implemented yet')
6493 END
6494 END ;
6495 pSym := GetPsym(Sym) ;
6496 IF (pSym^.SymbolType=TypeSym) AND (type=NulSym)
6497 THEN
6498 type := Sym (* Base Type *)
6499 ELSIF (type#NulSym) AND IsType(type) AND (GetAlignment(type)=NulSym)
6500 THEN
6501 type := GetLowestType(type) (* Type def *)
6502 END ;
6503 RETURN( type )
6504 END GetLowestType ;
6505
6506
6507 (*
6508 doGetType - subsiduary helper procedure function of GetDType, GetSType and GetLType.
6509 *)
6510
6511 PROCEDURE doGetType (sym: CARDINAL; skipEquiv, skipAlign, skipHidden, skipBase: BOOLEAN) : CARDINAL ;
6512 VAR
6513 pSym: PtrToSymbol ;
6514 type: CARDINAL ;
6515 BEGIN
6516 type := NulSym ;
6517 Assert (sym # NulSym) ;
6518 pSym := GetPsym (sym) ;
6519 WITH pSym^ DO
6520 CASE SymbolType OF
6521
6522 OAFamilySym : type := OAFamily.SimpleType |
6523 VarSym : type := GetTypeOfVar(sym) |
6524 ConstLitSym : type := ConstLit.Type |
6525 ConstVarSym : type := ConstVar.Type |
6526 ConstStringSym : IF ConstString.Length=1
6527 THEN
6528 type := Char
6529 ELSE
6530 type := NulSym (* No type for a string *)
6531 END |
6532 TypeSym : type := Type.Type |
6533 RecordFieldSym : type := RecordField.Type |
6534 RecordSym : type := NulSym | (* No type for a record *)
6535 VarientSym : type := NulSym | (* No type for a record *)
6536 EnumerationFieldSym : type := EnumerationField.Type |
6537 EnumerationSym : type := NulSym | (* No type for enumeration *)
6538 PointerSym : type := Pointer.Type |
6539 ProcedureSym : type := Procedure.ReturnType |
6540 ProcTypeSym : type := ProcType.ReturnType |
6541 ParamSym : type := Param.Type |
6542 VarParamSym : type := VarParam.Type |
6543 SubrangeSym : type := Subrange.Type |
6544 ArraySym : type := Array.Type |
6545 SubscriptSym : type := Subscript.Type |
6546 SetSym : type := Set.Type |
6547 UnboundedSym : type := Unbounded.Type |
6548 UndefinedSym : type := NulSym |
6549 PartialUnboundedSym : type := PartialUnbounded.Type |
6550 ObjectSym : type := NulSym
6551
6552 ELSE
6553 InternalError ('not implemented yet')
6554 END
6555 END ;
6556 IF (type=NulSym) AND IsType(sym) AND (NOT skipBase)
6557 THEN
6558 RETURN sym (* sym is a base type *)
6559 ELSIF type#NulSym
6560 THEN
6561 IF IsType(type) AND skipEquiv
6562 THEN
6563 IF (NOT IsHiddenType(type)) OR skipHidden
6564 THEN
6565 IF (GetAlignment(type)=NulSym) OR skipAlign
6566 THEN
6567 RETURN doGetType (type, skipEquiv, skipAlign, skipHidden, skipBase)
6568 END
6569 END
6570 END
6571 END ;
6572 RETURN type
6573 END doGetType ;
6574
6575
6576 (*
6577 GetLType - get lowest type. It returns the lowest type
6578 of symbol, sym. It skips over type equivalences.
6579 It will not skip over base types.
6580 *)
6581
6582 PROCEDURE GetLType (sym: CARDINAL) : CARDINAL ;
6583 BEGIN
6584 (*
6585 Assert (doGetType (sym, TRUE, TRUE, TRUE, FALSE) = GetLowestType (sym)) ;
6586 *)
6587 RETURN doGetType (sym, TRUE, TRUE, TRUE, FALSE)
6588 END GetLType ;
6589
6590
6591 (*
6592 GetSType - get source type. It returns the type closest
6593 to the object. It does not skip over type
6594 equivalences. It will skip over base types.
6595 *)
6596
6597 PROCEDURE GetSType (sym: CARDINAL) : CARDINAL ;
6598 BEGIN
6599 Assert (doGetType (sym, FALSE, FALSE, FALSE, TRUE) = GetType (sym)) ;
6600 RETURN doGetType (sym, FALSE, FALSE, FALSE, TRUE)
6601 END GetSType ;
6602
6603
6604 (*
6605 GetDType - get gcc declared type. It returns the type
6606 of the object which is declared to GCC.
6607 It does skip over type equivalences but only
6608 if they do not contain a user alignment.
6609 It does not skip over hidden types.
6610 It does not skip over base types.
6611 *)
6612
6613 PROCEDURE GetDType (sym: CARDINAL) : CARDINAL ;
6614 BEGIN
6615 (*
6616 Assert (doGetType (sym, TRUE, FALSE, FALSE, FALSE) = SkipType(GetType(sym))) ;
6617 *)
6618 RETURN doGetType (sym, TRUE, FALSE, FALSE, FALSE)
6619 END GetDType ;
6620
6621
6622 (*
6623 GetTypeOfVar - returns the type of symbol, var.
6624 *)
6625
6626 PROCEDURE GetTypeOfVar (var: CARDINAL) : CARDINAL ;
6627 VAR
6628 pSym: PtrToSymbol ;
6629 high: CARDINAL ;
6630 BEGIN
6631 pSym := GetPsym(var) ;
6632 WITH pSym^ DO
6633 CASE SymbolType OF
6634
6635 VarSym: IF Var.IsTemp AND Var.IsComponentRef
6636 THEN
6637 high := Indexing.HighIndice(Var.list) ;
6638 RETURN( GetType(GetFromIndex(Var.list, high)) )
6639 ELSE
6640 RETURN( Var.Type )
6641 END
6642
6643 ELSE
6644 InternalError ('expecting a var symbol')
6645 END
6646 END
6647 END GetTypeOfVar ;
6648
6649
6650 (*
6651 GetType - Returns the symbol that is the TYPE symbol to Sym.
6652 If zero is returned then we assume type unknown.
6653 *)
6654
6655 PROCEDURE GetType (Sym: CARDINAL) : CARDINAL ;
6656 VAR
6657 pSym: PtrToSymbol ;
6658 type: CARDINAL ;
6659 BEGIN
6660 Assert(Sym#NulSym) ;
6661 pSym := GetPsym(Sym) ;
6662 WITH pSym^ DO
6663 CASE SymbolType OF
6664
6665 OAFamilySym : type := OAFamily.SimpleType |
6666 VarSym : type := GetTypeOfVar(Sym) |
6667 ConstLitSym : type := ConstLit.Type |
6668 ConstVarSym : type := ConstVar.Type |
6669 ConstStringSym : IF ConstString.Length=1
6670 THEN
6671 type := Char
6672 ELSE
6673 type := NulSym (* No type for a string *)
6674 END |
6675 TypeSym : type := Type.Type |
6676 RecordFieldSym : type := RecordField.Type |
6677 RecordSym : type := NulSym | (* No type for a record *)
6678 VarientSym : type := NulSym | (* No type for a record *)
6679 EnumerationFieldSym : type := EnumerationField.Type |
6680 EnumerationSym : type := NulSym | (* No type for enumeration *)
6681 PointerSym : type := Pointer.Type |
6682 ProcedureSym : type := Procedure.ReturnType |
6683 ProcTypeSym : type := ProcType.ReturnType |
6684 ParamSym : type := Param.Type |
6685 VarParamSym : type := VarParam.Type |
6686 SubrangeSym : type := Subrange.Type |
6687 ArraySym : type := Array.Type |
6688 SubscriptSym : type := Subscript.Type |
6689 SetSym : type := Set.Type |
6690 UnboundedSym : type := Unbounded.Type |
6691 UndefinedSym : type := NulSym |
6692 PartialUnboundedSym : type := PartialUnbounded.Type |
6693 ObjectSym : type := NulSym
6694
6695 ELSE
6696 InternalError ('not implemented yet')
6697 END
6698 END ;
6699 RETURN( type )
6700 END GetType ;
6701
6702
6703 (*
6704 SkipType - if sym is a TYPE foo = bar
6705 then call SkipType(bar)
6706 else return sym
6707
6708 it does not skip over hidden types.
6709 *)
6710
6711 PROCEDURE SkipType (Sym: CARDINAL) : CARDINAL ;
6712 BEGIN
6713 IF (Sym#NulSym) AND IsType(Sym) AND
6714 (NOT IsHiddenType(Sym)) AND (GetType(Sym)#NulSym)
6715 THEN
6716 RETURN( SkipType(GetType(Sym)) )
6717 ELSE
6718 RETURN( Sym )
6719 END
6720 END SkipType ;
6721
6722
6723 (*
6724 SkipTypeAndSubrange - if sym is a TYPE foo = bar OR
6725 sym is declared as a subrange of bar
6726 then call SkipTypeAndSubrange(bar)
6727 else return sym
6728
6729 it does not skip over hidden types.
6730 *)
6731
6732 PROCEDURE SkipTypeAndSubrange (Sym: CARDINAL) : CARDINAL ;
6733 BEGIN
6734 IF (Sym#NulSym) AND (IsType(Sym) OR IsSubrange(Sym)) AND
6735 (NOT IsHiddenType(Sym)) AND (GetType(Sym)#NulSym)
6736 THEN
6737 RETURN( SkipTypeAndSubrange(GetType(Sym)) )
6738 ELSE
6739 RETURN( Sym )
6740 END
6741 END SkipTypeAndSubrange ;
6742
6743
6744 (*
6745 IsHiddenType - returns TRUE if, Sym, is a Type and is also declared as a hidden type.
6746 *)
6747
6748 PROCEDURE IsHiddenType (Sym: CARDINAL) : BOOLEAN ;
6749 VAR
6750 pSym: PtrToSymbol ;
6751 BEGIN
6752 pSym := GetPsym(Sym) ;
6753 WITH pSym^ DO
6754 CASE SymbolType OF
6755
6756 TypeSym: RETURN( Type.IsHidden )
6757
6758 ELSE
6759 RETURN( FALSE )
6760 END
6761 END
6762 END IsHiddenType ;
6763
6764
6765 (*
6766 GetConstLitType - returns the type of the constant of, name.
6767 All floating point constants have type LONGREAL.
6768 Character constants are type CHAR.
6769 Integer values are INTEGER, LONGINT or LONGCARD
6770 depending upon their value.
6771 *)
6772
6773 PROCEDURE GetConstLitType (tok: CARDINAL; name: Name;
6774 VAR overflow: BOOLEAN; issueError: BOOLEAN) : CARDINAL ;
6775 VAR
6776 loc: location_t ;
6777 s : String ;
6778 BEGIN
6779 s := InitStringCharStar (KeyToCharStar (name)) ;
6780 IF char (s, -1) = 'C'
6781 THEN
6782 s := KillString (s) ;
6783 RETURN Char
6784 ELSE
6785 IF Index (s, '.', 0) # -1 (* found a '.' in our constant *)
6786 THEN
6787 s := KillString (s) ;
6788 RETURN RType
6789 END ;
6790 loc := TokenToLocation (tok) ;
6791 CASE char (s, -1) OF
6792
6793 'H': overflow := OverflowZType (loc, string (s), 16, issueError) |
6794 'B': overflow := OverflowZType (loc, string (s), 8, issueError) |
6795 'A': overflow := OverflowZType (loc, string (s), 2, issueError)
6796
6797 ELSE
6798 overflow := OverflowZType (loc, string (s), 10, issueError)
6799 END ;
6800 s := KillString (s) ;
6801 RETURN ZType
6802 END
6803 END GetConstLitType ;
6804
6805
6806 (*
6807 GetTypeMode - return the type of sym, it returns Address is the
6808 symbol is a LValue.
6809 *)
6810
6811 PROCEDURE GetTypeMode (sym: CARDINAL) : CARDINAL ;
6812 BEGIN
6813 IF GetMode (sym) = LeftValue
6814 THEN
6815 RETURN( Address )
6816 ELSE
6817 RETURN( GetType (sym) )
6818 END
6819 END GetTypeMode ;
6820
6821
6822 (*
6823 GetLocalSym - only searches the scope Sym for a symbol with name
6824 and returns the index to the symbol.
6825 *)
6826
6827 PROCEDURE GetLocalSym (Sym: CARDINAL; name: Name) : CARDINAL ;
6828 VAR
6829 pSym : PtrToSymbol ;
6830 LocalSym: CARDINAL ;
6831 BEGIN
6832 (*
6833 WriteString('Attempting to retrieve symbol from ') ; WriteKey(GetSymName(Sym)) ;
6834 WriteString(' local symbol table') ; WriteLn ;
6835 *)
6836 pSym := GetPsym(Sym) ;
6837 WITH pSym^ DO
6838 CASE SymbolType OF
6839
6840 EnumerationSym : LocalSym := GetSymKey(Enumeration.LocalSymbols, name) |
6841 RecordSym : LocalSym := GetSymKey(Record.LocalSymbols, name) |
6842 ProcedureSym : LocalSym := GetSymKey(Procedure.LocalSymbols, name) |
6843 ModuleSym : LocalSym := GetSymKey(Module.LocalSymbols, name) |
6844 DefImpSym : LocalSym := GetSymKey(DefImp.LocalSymbols, name)
6845
6846 ELSE
6847 InternalError ('symbol does not have a LocalSymbols field')
6848 END
6849 END ;
6850 RETURN( LocalSym )
6851 END GetLocalSym ;
6852
6853
6854 (*
6855 GetNthFromComponent -
6856 *)
6857
6858 PROCEDURE GetNthFromComponent (Sym: CARDINAL; n: CARDINAL) : CARDINAL ;
6859 VAR
6860 pSym: PtrToSymbol ;
6861 BEGIN
6862 pSym := GetPsym(Sym) ;
6863 WITH pSym^ DO
6864 CASE SymbolType OF
6865
6866 VarSym: IF IsComponent(Sym)
6867 THEN
6868 IF InBounds(Var.list, n)
6869 THEN
6870 RETURN( GetFromIndex(Var.list, n) )
6871 ELSE
6872 RETURN( NulSym )
6873 END
6874 ELSE
6875 InternalError ('cannot GetNth from this symbol')
6876 END
6877
6878 ELSE
6879 InternalError ('cannot GetNth from this symbol')
6880 END
6881 END
6882 END GetNthFromComponent ;
6883
6884
6885 (*
6886 GetNth - returns the n th symbol in the list associated with the scope
6887 of Sym. Sym may be a Module, DefImp, Procedure, Record or
6888 Enumeration symbol.
6889 *)
6890
6891 PROCEDURE GetNth (Sym: CARDINAL; n: CARDINAL) : CARDINAL ;
6892 VAR
6893 pSym: PtrToSymbol ;
6894 i : CARDINAL ;
6895 BEGIN
6896 pSym := GetPsym(Sym) ;
6897 WITH pSym^ DO
6898 CASE SymbolType OF
6899
6900 RecordSym : i := GetItemFromList (Record.ListOfSons, n) |
6901 VarientSym : i := GetItemFromList (Varient.ListOfSons, n) |
6902 VarientFieldSym : i := GetItemFromList (VarientField.ListOfSons, n) |
6903 ProcedureSym : i := GetItemFromList (Procedure.ListOfVars, n) |
6904 DefImpSym : i := GetItemFromList (DefImp.ListOfVars, n) |
6905 ModuleSym : i := GetItemFromList (Module.ListOfVars, n) |
6906 TupleSym : i := GetFromIndex (Tuple.list, n) |
6907 VarSym : i := GetNthFromComponent (Sym, n) |
6908 EnumerationSym : i := GetItemFromList (Enumeration.ListOfFields, n)
6909
6910 ELSE
6911 InternalError ('cannot GetNth from this symbol')
6912 END
6913 END ;
6914 RETURN( i )
6915 END GetNth ;
6916
6917
6918 (*
6919 GetNthParam - returns the n th parameter of a procedure Sym.
6920 *)
6921
6922 PROCEDURE GetNthParam (Sym: CARDINAL; kind: ProcedureKind;
6923 ParamNo: CARDINAL) : CARDINAL ;
6924 VAR
6925 pSym: PtrToSymbol ;
6926 i : CARDINAL ;
6927 BEGIN
6928 IF ParamNo=0
6929 THEN
6930 (* The return type of the function *)
6931 i := GetType(Sym)
6932 ELSE
6933 pSym := GetPsym(Sym) ;
6934 WITH pSym^ DO
6935 CASE SymbolType OF
6936
6937 ProcedureSym: i := GetItemFromList (Procedure.Decl[kind].ListOfParam,
6938 ParamNo) |
6939 ProcTypeSym : i := GetItemFromList (ProcType.ListOfParam, ParamNo)
6940
6941 ELSE
6942 InternalError ('expecting ProcedureSym or ProcTypeSym')
6943 END
6944 END
6945 END ;
6946 RETURN( i )
6947 END GetNthParam ;
6948
6949
6950 (*
6951 GetNthParamAny - returns the nth parameter from the order
6952 proper procedure, forward declaration
6953 or definition module procedure.
6954 *)
6955
6956 PROCEDURE GetNthParamAny (sym: CARDINAL; ParamNo: CARDINAL) : CARDINAL ;
6957 VAR
6958 kind: ProcedureKind ;
6959 BEGIN
6960 FOR kind := MIN (ProcedureKind) TO MAX (ProcedureKind) DO
6961 IF GetProcedureParametersDefined (sym, kind)
6962 THEN
6963 RETURN GetNthParam (sym, kind, ParamNo)
6964 END
6965 END ;
6966 InternalError ('no procedure kind exists')
6967 END GetNthParamAny ;
6968
6969
6970 (*
6971 GetNthParamChoice - returns the parameter definition from
6972 sym:ParamNo:kind or NulSym.
6973 *)
6974
6975 PROCEDURE GetNthParamChoice (sym: CARDINAL; ParamNo: CARDINAL;
6976 kind: ProcedureKind) : CARDINAL ;
6977 BEGIN
6978 IF GetProcedureParametersDefined (sym, kind)
6979 THEN
6980 RETURN GetNthParam (sym, kind, ParamNo)
6981 ELSE
6982 RETURN NulSym
6983 END
6984 END GetNthParamChoice ;
6985
6986
6987 (*
6988 GetNthParamOrdered - returns the parameter definition from list {a, b, c}
6989 in order.
6990 sym:ParamNo:{a,b,c} or NulSym.
6991 *)
6992
6993 PROCEDURE GetNthParamOrdered (sym: CARDINAL; ParamNo: CARDINAL;
6994 a, b, c: ProcedureKind) : CARDINAL ;
6995 VAR
6996 param: CARDINAL ;
6997 BEGIN
6998 param := GetNthParamChoice (sym, ParamNo, a) ;
6999 IF param = NulSym
7000 THEN
7001 param := GetNthParamChoice (sym, ParamNo, b) ;
7002 IF param = NulSym
7003 THEN
7004 param := GetNthParamChoice (sym, ParamNo, c)
7005 END
7006 END ;
7007 RETURN param
7008 END GetNthParamOrdered ;
7009
7010
7011 (*
7012 GetNthParamAnyClosest - returns the nth parameter from the order
7013 proper procedure, forward declaration
7014 or definition module procedure.
7015 It chooses the parameter which is closest
7016 in source terms to currentmodule.
7017 The same module will return using the order
7018 proper procedure, forward procedure, definition module.
7019 Whereas an imported procedure will choose from
7020 DefProcedure, ProperProcedure, ForwardProcedure.
7021 *)
7022
7023 PROCEDURE GetNthParamAnyClosest (sym: CARDINAL; ParamNo: CARDINAL;
7024 currentmodule: CARDINAL) : CARDINAL ;
7025 BEGIN
7026 IF GetOuterModuleScope (currentmodule) = GetOuterModuleScope (sym)
7027 THEN
7028 (* Same module. *)
7029 RETURN GetNthParamOrdered (sym, ParamNo,
7030 ProperProcedure, ForwardProcedure, DefProcedure)
7031 ELSE
7032 (* Procedure is imported. *)
7033 RETURN GetNthParamOrdered (sym, ParamNo,
7034 DefProcedure, ProperProcedure, ForwardProcedure)
7035 END
7036 END GetNthParamAnyClosest ;
7037
7038
7039 (*
7040 GetOuterModuleScope - returns the outer module symbol scope for sym.
7041 *)
7042
7043 PROCEDURE GetOuterModuleScope (sym: CARDINAL) : CARDINAL ;
7044 BEGIN
7045 WHILE NOT (IsDefImp (sym) OR
7046 (IsModule (sym) AND (GetScope (sym) = NulSym))) DO
7047 sym := GetScope (sym)
7048 END ;
7049 RETURN sym
7050 END GetOuterModuleScope ;
7051
7052
7053 (*
7054 The Following procedures fill in the symbol table with the
7055 symbol entities.
7056 *)
7057
7058 (*
7059 PutVar - gives the VarSym symbol Sym a type Type.
7060 *)
7061
7062 PROCEDURE PutVar (Sym: CARDINAL; VarType: CARDINAL) ;
7063 VAR
7064 pSym: PtrToSymbol ;
7065 BEGIN
7066 pSym := GetPsym(Sym) ;
7067 WITH pSym^ DO
7068 CASE SymbolType OF
7069
7070 VarSym : Var.Type := VarType ;
7071 ConfigSymInit (Var.InitState[LeftValue], Sym) ;
7072 ConfigSymInit (Var.InitState[RightValue], Sym) |
7073 ConstVarSym: ConstVar.Type := VarType
7074
7075 ELSE
7076 InternalError ('expecting VarSym or ConstVarSym')
7077 END
7078 END
7079 END PutVar ;
7080
7081
7082 (*
7083 PutVarTok - gives the VarSym symbol Sym a type Type at typetok.
7084 *)
7085
7086 PROCEDURE PutVarTok (Sym: CARDINAL; VarType: CARDINAL; typetok: CARDINAL) ;
7087 VAR
7088 pSym: PtrToSymbol ;
7089 BEGIN
7090 pSym := GetPsym(Sym) ;
7091 WITH pSym^ DO
7092 CASE SymbolType OF
7093
7094 VarSym : Var.Type := VarType ;
7095 Var.Declared.TypeTok := typetok ;
7096 ConfigSymInit (Var.InitState[LeftValue], Sym) ;
7097 ConfigSymInit (Var.InitState[RightValue], Sym) |
7098 ConstVarSym: ConstVar.Type := VarType
7099
7100 ELSE
7101 InternalError ('expecting VarSym or ConstVarSym')
7102 END
7103 END
7104 END PutVarTok ;
7105
7106
7107 (*
7108 PutLeftValueFrontBackType - gives the variable symbol a front and backend type.
7109 The variable must be a LeftValue.
7110 *)
7111
7112 PROCEDURE PutLeftValueFrontBackType (Sym: CARDINAL; FrontType, BackType: CARDINAL) ;
7113 VAR
7114 pSym: PtrToSymbol ;
7115 BEGIN
7116 Assert(GetMode(Sym)=LeftValue) ;
7117 pSym := GetPsym(Sym) ;
7118 WITH pSym^ DO
7119 CASE SymbolType OF
7120
7121 VarSym : Var.Type := FrontType ;
7122 Var.BackType := BackType ;
7123 PushSize(Address) ;
7124 PopInto(Var.Size)
7125
7126 ELSE
7127 InternalError ('expecting VarSym')
7128 END
7129 END
7130 END PutLeftValueFrontBackType ;
7131
7132
7133 (*
7134 GetVarBackEndType - returns the back end type if specified.
7135 *)
7136
7137 PROCEDURE GetVarBackEndType (Sym: CARDINAL) : CARDINAL ;
7138 VAR
7139 pSym: PtrToSymbol ;
7140 BEGIN
7141 Assert(Sym#NulSym) ;
7142 pSym := GetPsym(Sym) ;
7143 WITH pSym^ DO
7144 CASE SymbolType OF
7145
7146 VarSym: RETURN( Var.BackType )
7147
7148 ELSE
7149 RETURN( NulSym )
7150 END
7151 END
7152 END GetVarBackEndType ;
7153
7154
7155 (*
7156 PutVarPointerCheck - marks variable, sym, as requiring (or not
7157 depending upon the, value), a NIL pointer check
7158 when this symbol is dereferenced.
7159 *)
7160
7161 PROCEDURE PutVarPointerCheck (sym: CARDINAL; value: BOOLEAN) ;
7162 VAR
7163 pSym: PtrToSymbol ;
7164 BEGIN
7165 IF IsVar(sym)
7166 THEN
7167 pSym := GetPsym(sym) ;
7168 WITH pSym^.Var DO
7169 IsPointerCheck := value
7170 END
7171 END
7172 END PutVarPointerCheck ;
7173
7174
7175 (*
7176 GetVarPointerCheck - returns TRUE if this symbol is a variable and
7177 has been marked as needing a pointer via NIL check.
7178 *)
7179
7180 PROCEDURE GetVarPointerCheck (sym: CARDINAL) : BOOLEAN ;
7181 VAR
7182 pSym: PtrToSymbol ;
7183 BEGIN
7184 IF IsVar(sym)
7185 THEN
7186 pSym := GetPsym(sym) ;
7187 WITH pSym^.Var DO
7188 RETURN( IsPointerCheck )
7189 END
7190 END ;
7191 RETURN FALSE
7192 END GetVarPointerCheck ;
7193
7194
7195 (*
7196 PutVarWritten - marks variable, sym, as being written to (or not
7197 depending upon the, value).
7198 *)
7199
7200 PROCEDURE PutVarWritten (sym: CARDINAL; value: BOOLEAN) ;
7201 VAR
7202 pSym: PtrToSymbol ;
7203 BEGIN
7204 IF IsVar(sym)
7205 THEN
7206 pSym := GetPsym(sym) ;
7207 WITH pSym^.Var DO
7208 IsWritten := value
7209 END
7210 END
7211 END PutVarWritten ;
7212
7213
7214 (*
7215 GetVarWritten - returns TRUE if this symbol is a variable and
7216 has been marked as being written.
7217 *)
7218
7219 PROCEDURE GetVarWritten (sym: CARDINAL) : BOOLEAN ;
7220 VAR
7221 pSym: PtrToSymbol ;
7222 BEGIN
7223 pSym := GetPsym(sym) ;
7224 WITH pSym^ DO
7225 CASE SymbolType OF
7226
7227 VarSym: RETURN( Var.IsWritten )
7228
7229 ELSE
7230 InternalError ('expecting VarSym')
7231 END
7232 END
7233 END GetVarWritten ;
7234
7235
7236 (*
7237 PutVarConst - sets the IsConst field to value indicating the variable is read only.
7238 *)
7239
7240 PROCEDURE PutVarConst (sym: CARDINAL; value: BOOLEAN) ;
7241 VAR
7242 pSym: PtrToSymbol ;
7243 BEGIN
7244 IF IsVar (sym)
7245 THEN
7246 pSym := GetPsym (sym) ;
7247 pSym^.Var.IsConst := value
7248 END
7249 END PutVarConst ;
7250
7251
7252 (*
7253 IsVarConst - returns the IsConst field indicating the variable is read only.
7254 *)
7255
7256 PROCEDURE IsVarConst (sym: CARDINAL) : BOOLEAN ;
7257 VAR
7258 pSym: PtrToSymbol ;
7259 BEGIN
7260 pSym := GetPsym(sym) ;
7261 WITH pSym^ DO
7262 CASE SymbolType OF
7263
7264 VarSym: RETURN( Var.IsConst )
7265
7266 ELSE
7267 InternalError ('expecting VarSym')
7268 END
7269 END
7270 END IsVarConst ;
7271
7272
7273 (*
7274 PutConst - gives the constant symbol Sym a type ConstType.
7275 *)
7276
7277 PROCEDURE PutConst (Sym: CARDINAL; ConstType: CARDINAL) ;
7278 VAR
7279 pSym: PtrToSymbol ;
7280 BEGIN
7281 pSym := GetPsym(Sym) ;
7282 CheckBreak (Sym) ;
7283 WITH pSym^ DO
7284 CASE SymbolType OF
7285
7286 ConstVarSym: ConstVar.Type := ConstType
7287
7288 ELSE
7289 InternalError ('expecting ConstVarSym')
7290 END
7291 END
7292 END PutConst ;
7293
7294
7295 (*
7296 PutConstLitInternal - marks the sym as being an internal constant.
7297 Currently this is used when generating a default
7298 BY constant expression during a FOR loop.
7299 A constant marked as internal will always pass
7300 an expression type check.
7301 *)
7302
7303 PROCEDURE PutConstLitInternal (sym: CARDINAL; value: BOOLEAN) ;
7304 VAR
7305 pSym: PtrToSymbol ;
7306 BEGIN
7307 pSym := GetPsym (sym) ;
7308 WITH pSym^ DO
7309 CASE SymbolType OF
7310
7311 ConstLitSym: ConstLit.IsInternal := value
7312
7313 ELSE
7314 InternalError ('expecting ConstLitSym')
7315 END
7316 END
7317 END PutConstLitInternal ;
7318
7319
7320 (*
7321 IsConstLitInternal - returns the value of the IsInternal field within
7322 a constant expression.
7323 *)
7324
7325 PROCEDURE IsConstLitInternal (sym: CARDINAL) : BOOLEAN ;
7326 VAR
7327 pSym: PtrToSymbol ;
7328 BEGIN
7329 pSym := GetPsym (sym) ;
7330 WITH pSym^ DO
7331 CASE SymbolType OF
7332
7333 ConstLitSym: RETURN ConstLit.IsInternal
7334
7335 ELSE
7336 InternalError ('expecting ConstLitSym')
7337 END
7338 END
7339 END IsConstLitInternal ;
7340
7341
7342 (*
7343 PutVarArrayRef - assigns ArrayRef field with value.
7344 *)
7345
7346 PROCEDURE PutVarArrayRef (sym: CARDINAL; value: BOOLEAN) ;
7347 VAR
7348 pSym: PtrToSymbol ;
7349 BEGIN
7350 pSym := GetPsym(sym) ;
7351 WITH pSym^ DO
7352 CASE SymbolType OF
7353
7354 VarSym: Var.ArrayRef := value
7355
7356 ELSE
7357 InternalError ('expecting VarSym')
7358 END
7359 END
7360 END PutVarArrayRef ;
7361
7362
7363 (*
7364 IsVarArrayRef - returns ArrayRef field value.
7365 *)
7366
7367 PROCEDURE IsVarArrayRef (sym: CARDINAL) : BOOLEAN ;
7368 VAR
7369 pSym: PtrToSymbol ;
7370 BEGIN
7371 pSym := GetPsym(sym) ;
7372 WITH pSym^ DO
7373 CASE SymbolType OF
7374
7375 VarSym: RETURN (Var.ArrayRef)
7376
7377 ELSE
7378 InternalError ('expecting VarSym')
7379 END
7380 END
7381 END IsVarArrayRef ;
7382
7383
7384 (*
7385 PutVarHeap - assigns ArrayRef field with value.
7386 *)
7387
7388 PROCEDURE PutVarHeap (sym: CARDINAL; value: BOOLEAN) ;
7389 VAR
7390 pSym: PtrToSymbol ;
7391 BEGIN
7392 pSym := GetPsym(sym) ;
7393 WITH pSym^ DO
7394 CASE SymbolType OF
7395
7396 VarSym: Var.Heap := value
7397
7398 ELSE
7399 InternalError ('expecting VarSym')
7400 END
7401 END
7402 END PutVarHeap ;
7403
7404
7405 (*
7406 IsVarHeap - returns ArrayRef field value.
7407 *)
7408
7409 PROCEDURE IsVarHeap (sym: CARDINAL) : BOOLEAN ;
7410 VAR
7411 pSym: PtrToSymbol ;
7412 BEGIN
7413 pSym := GetPsym(sym) ;
7414 WITH pSym^ DO
7415 CASE SymbolType OF
7416
7417 VarSym: RETURN (Var.Heap)
7418
7419 ELSE
7420 InternalError ('expecting VarSym')
7421 END
7422 END
7423 END IsVarHeap ;
7424
7425
7426 (*
7427 PutFieldRecord - places a field, FieldName and FieldType into a record, Sym.
7428 VarSym is a optional varient symbol which can be returned
7429 by a call to GetVarient(fieldsymbol). The created field
7430 is returned.
7431 *)
7432
7433 PROCEDURE PutFieldRecord (Sym: CARDINAL;
7434 FieldName: Name; FieldType: CARDINAL;
7435 VarSym: CARDINAL) : CARDINAL ;
7436 VAR
7437 oSym,
7438 pSym : PtrToSymbol ;
7439 esym,
7440 ParSym,
7441 SonSym: CARDINAL ;
7442 BEGIN
7443 NewSym(SonSym) ; (* Cannot be used before declared since use occurs *)
7444 (* in pass 3 and it will be declared in pass 2. *)
7445 (* Fill in the SonSym and connect it to its brothers (if any) and *)
7446 (* ensure that it is connected its parent. *)
7447 pSym := GetPsym(Sym) ;
7448 WITH pSym^ DO
7449 CASE SymbolType OF
7450
7451 RecordSym : WITH Record DO
7452 PutItemIntoList(ListOfSons, SonSym) ;
7453 Assert(IsItemInList(Record.ListOfSons, SonSym)) ;
7454 (*
7455 n := NoOfItemsInList(ListOfSons) ;
7456 printf3('record %d no of fields in ListOfSons = %d, field %d\n', Sym, n, SonSym) ;
7457 *)
7458 (* Ensure that the Field is in the Parents Local Symbols *)
7459 IF FieldName#NulName
7460 THEN
7461 IF GetSymKey(LocalSymbols, FieldName)=NulKey
7462 THEN
7463 PutSymKey(LocalSymbols, FieldName, SonSym)
7464 ELSE
7465 esym := GetSymKey(LocalSymbols, FieldName) ;
7466 MetaErrors1('field record {%1Dad} has already been declared',
7467 'field record duplicate', esym)
7468 END
7469 END
7470 END ;
7471 CheckRecordConsistency(Sym) |
7472 VarientFieldSym : WITH VarientField DO
7473 PutItemIntoList(ListOfSons, SonSym) ;
7474 ParSym := GetRecord(Parent)
7475 END ;
7476 oSym := GetPsym(ParSym) ;
7477 Assert(oSym^.SymbolType=RecordSym) ;
7478 IF FieldName#NulName
7479 THEN
7480 oSym := GetPsym(ParSym) ;
7481 PutSymKey(oSym^.Record.LocalSymbols, FieldName, SonSym)
7482 END
7483
7484 ELSE
7485 InternalError ('expecting Record symbol')
7486 END
7487 END ;
7488 (* Fill in SonSym *)
7489 oSym := GetPsym(SonSym) ;
7490 WITH oSym^ DO
7491 SymbolType := RecordFieldSym ;
7492 WITH RecordField DO
7493 Type := FieldType ;
7494 name := FieldName ;
7495 Tag := FALSE ;
7496 Parent := Sym ;
7497 Varient := VarSym ;
7498 Align := NulSym ;
7499 Used := TRUE ;
7500 DeclPacked := FALSE ; (* not known as packed (yet). *)
7501 DeclResolved := FALSE ;
7502 Scope := GetScope(Sym) ;
7503 Size := InitValue() ;
7504 Offset := InitValue() ;
7505 InitWhereDeclared(At)
7506 END
7507 END ;
7508 RETURN( SonSym )
7509 END PutFieldRecord ;
7510
7511
7512 (*
7513 MakeFieldVarient - returns a FieldVarient symbol which has been
7514 assigned to the Varient symbol, Sym.
7515 *)
7516
7517 PROCEDURE MakeFieldVarient (n: Name; Sym: CARDINAL) : CARDINAL ;
7518 VAR
7519 pSym : PtrToSymbol ;
7520 SonSym: CARDINAL ;
7521 BEGIN
7522 NewSym(SonSym) ;
7523 (*
7524 IF NoOfItemsInList(FreeFVarientList)=0
7525 THEN
7526 NewSym(SonSym)
7527 ELSE
7528 SonSym := GetItemFromList(FreeFVarientList, 1) ;
7529 RemoveItemFromList(FreeFVarientList, SonSym)
7530 END ;
7531 *)
7532 (* Fill in Sym *)
7533 pSym := GetPsym(SonSym) ;
7534 WITH pSym^ DO
7535 SymbolType := VarientFieldSym ;
7536 WITH VarientField DO
7537 name := n ;
7538 InitList(ListOfSons) ;
7539 Parent := GetRecord(Sym) ;
7540 Varient := NulSym ;
7541 Size := InitValue() ;
7542 Offset := InitValue() ;
7543 DeclPacked := FALSE ;
7544 DeclResolved := FALSE ;
7545 Scope := GetCurrentScope() ;
7546 InitWhereDeclared(At)
7547 END
7548 END ;
7549 RETURN( SonSym )
7550 END MakeFieldVarient ;
7551
7552
7553 (*
7554 PutFieldVarient - places the field varient, Field, as a brother to, the
7555 varient symbol, sym, and also tells Field that its varient
7556 parent is Sym.
7557 *)
7558
7559 PROCEDURE PutFieldVarient (Field, Sym: CARDINAL) ;
7560 VAR
7561 pSym: PtrToSymbol ;
7562 BEGIN
7563 Assert(IsVarient(Sym)) ;
7564 Assert(IsFieldVarient(Field)) ;
7565 pSym := GetPsym(Sym) ;
7566 WITH pSym^ DO
7567 CASE SymbolType OF
7568
7569 VarientSym : IncludeItemIntoList(Varient.ListOfSons, Field)
7570
7571 ELSE
7572 InternalError ('expecting Varient symbol')
7573 END
7574 END ;
7575 pSym := GetPsym(Field) ;
7576 WITH pSym^ DO
7577 CASE SymbolType OF
7578
7579 VarientFieldSym : VarientField.Varient := Sym
7580
7581 ELSE
7582 InternalError ('expecting VarientField symbol')
7583 END
7584 END ;
7585 (* PutItemIntoList(UsedFVarientList, Field) *)
7586 END PutFieldVarient ;
7587
7588
7589 (*
7590 GetVarient - returns the varient symbol associated with the
7591 record or varient field symbol, Field.
7592 *)
7593
7594 PROCEDURE GetVarient (Field: CARDINAL) : CARDINAL ;
7595 VAR
7596 pSym: PtrToSymbol ;
7597 BEGIN
7598 pSym := GetPsym(Field) ;
7599 WITH pSym^ DO
7600 CASE SymbolType OF
7601
7602 VarientFieldSym : RETURN( VarientField.Varient ) |
7603 RecordFieldSym : RETURN( RecordField.Varient ) |
7604 VarientSym : RETURN( Varient.Varient )
7605
7606 ELSE
7607 RETURN( NulSym )
7608 END
7609 END
7610 END GetVarient ;
7611
7612
7613 (*
7614 EnsureOrder - providing that both symbols, a, and, b, exist in
7615 list, l. Ensure that, b, is placed after a.
7616 *)
7617
7618 PROCEDURE EnsureOrder (l: List; a, b: CARDINAL) ;
7619 VAR
7620 n: CARDINAL ;
7621 BEGIN
7622 n := NoOfItemsInList(l) ;
7623 IF IsItemInList(l, a) AND IsItemInList(l, b)
7624 THEN
7625 RemoveItemFromList(l, b) ;
7626 IncludeItemIntoList(l, b)
7627 END ;
7628 Assert(n=NoOfItemsInList(l))
7629 END EnsureOrder ;
7630
7631
7632 VAR
7633 recordConsist: CARDINAL ; (* is used by CheckRecordConsistency and friends. *)
7634
7635
7636 (*
7637 DumpSons -
7638 *)
7639
7640 PROCEDURE DumpSons (sym: CARDINAL) ;
7641 VAR
7642 pSym : PtrToSymbol ;
7643 f, n, i: CARDINAL ;
7644 BEGIN
7645 pSym := GetPsym(sym) ;
7646 WITH pSym^ DO
7647 CASE SymbolType OF
7648
7649 RecordSym: n := NoOfItemsInList(Record.ListOfSons) ;
7650 i := 1 ;
7651 WHILE i<=n DO
7652 f := GetItemFromList(Record.ListOfSons, i) ;
7653 printf3('record %d field %d is %d\n', sym, i, f) ;
7654 INC(i)
7655 END
7656
7657 ELSE
7658 InternalError ('expecting record symbol')
7659 END
7660 END
7661 END DumpSons ;
7662
7663
7664
7665 (*
7666 CheckListOfSons - checks to see that sym, is present in, recordConsist, ListOfSons.
7667 *)
7668
7669 PROCEDURE CheckListOfSons (sym: WORD) ;
7670 VAR
7671 pSym: PtrToSymbol ;
7672 BEGIN
7673 pSym := GetPsym(recordConsist) ;
7674 WITH pSym^ DO
7675 CASE SymbolType OF
7676
7677 RecordSym: IF NOT IsItemInList(Record.ListOfSons, sym)
7678 THEN
7679 DumpSons(recordConsist) ;
7680 MetaError1('internal error: expecting {%1ad} to exist in record ListOfSons', sym)
7681 END
7682
7683 ELSE
7684 InternalError ('expecting record symbol')
7685 END
7686 END
7687 END CheckListOfSons ;
7688
7689
7690 (*
7691 CheckRecordConsistency -
7692 *)
7693
7694 PROCEDURE CheckRecordConsistency (sym: CARDINAL) ;
7695 VAR
7696 pSym: PtrToSymbol ;
7697 BEGIN
7698 RETURN ;
7699 pSym := GetPsym(sym) ;
7700 WITH pSym^ DO
7701 CASE SymbolType OF
7702
7703 RecordSym: recordConsist := sym ;
7704 WITH Record DO
7705 ForeachNodeDo(LocalSymbols, CheckListOfSons)
7706 END |
7707
7708 ELSE
7709 InternalError ('record symbol expected')
7710 END
7711 END
7712 END CheckRecordConsistency ;
7713
7714
7715 (*
7716 IsEmptyFieldVarient - returns TRUE if the field variant has
7717 no fields. This will occur then the
7718 compiler constructs 'else end' variants.
7719 *)
7720
7721 PROCEDURE IsEmptyFieldVarient (sym: CARDINAL) : BOOLEAN ;
7722 VAR
7723 pSym: PtrToSymbol ;
7724 BEGIN
7725 pSym := GetPsym(sym) ;
7726 WITH pSym^ DO
7727 CASE SymbolType OF
7728
7729 VarientFieldSym: RETURN( NoOfItemsInList(VarientField.ListOfSons)=0 )
7730
7731 ELSE
7732 InternalError ('varient field symbol expected')
7733 END
7734 END
7735 END IsEmptyFieldVarient ;
7736
7737
7738 (*
7739 IsRecordFieldAVarientTag - returns TRUE if record field, sym, is
7740 a varient tag.
7741 *)
7742
7743 PROCEDURE IsRecordFieldAVarientTag (sym: CARDINAL) : BOOLEAN ;
7744 VAR
7745 pSym: PtrToSymbol ;
7746 BEGIN
7747 IF IsRecordField(sym)
7748 THEN
7749 pSym := GetPsym(sym) ;
7750 RETURN( pSym^.RecordField.Tag )
7751 ELSE
7752 InternalError ('record field symbol expected')
7753 END
7754 END IsRecordFieldAVarientTag ;
7755
7756
7757 (*
7758 PutVarientTag - places, Tag, into varient, Sym.
7759 *)
7760
7761 PROCEDURE PutVarientTag (Sym, Tag: CARDINAL) ;
7762 VAR
7763 pSym : PtrToSymbol ;
7764 parent: CARDINAL ;
7765 BEGIN
7766 pSym := GetPsym(Sym) ;
7767 WITH pSym^ DO
7768 CASE SymbolType OF
7769
7770 VarientSym: Varient.tag := Tag
7771
7772 ELSE
7773 InternalError ('varient symbol expected')
7774 END
7775 END ;
7776 (* now ensure that if Tag is a RecordField then it must be
7777 placed before the varient symbol in its parent ListOfSons.
7778 This allows M2GCCDeclare to declare record fields in order
7779 and preserve the order of fields. Otherwise it will add the
7780 tag field after the C union. *)
7781 IF IsRecordField(Tag)
7782 THEN
7783 pSym := GetPsym(Tag) ;
7784 pSym^.RecordField.Tag := TRUE ;
7785 parent := GetParent(Sym) ;
7786 pSym := GetPsym(parent) ;
7787 WITH pSym^ DO
7788 CASE SymbolType OF
7789
7790 ErrorSym: |
7791 VarientSym : EnsureOrder(Varient.ListOfSons, Tag, Sym) |
7792 VarientFieldSym: EnsureOrder(VarientField.ListOfSons, Tag, Sym) |
7793 RecordSym : EnsureOrder(Record.ListOfSons, Tag, Sym) ;
7794 CheckRecordConsistency(parent)
7795
7796 ELSE
7797 InternalError ('not expecting this symbol type')
7798 END
7799 END
7800 END
7801 END PutVarientTag ;
7802
7803
7804 (*
7805 GetVarientTag - returns the varient tag from, Sym.
7806 *)
7807
7808 PROCEDURE GetVarientTag (Sym: CARDINAL) : CARDINAL ;
7809 VAR
7810 pSym: PtrToSymbol ;
7811 BEGIN
7812 pSym := GetPsym(Sym) ;
7813 WITH pSym^ DO
7814 CASE SymbolType OF
7815
7816 VarientSym: RETURN( Varient.tag )
7817
7818 ELSE
7819 InternalError ('varient symbol expected')
7820 END
7821 END
7822 END GetVarientTag ;
7823
7824
7825 (*
7826 IsFieldVarient - returns true if the symbol, Sym, is a
7827 varient field.
7828 *)
7829
7830 PROCEDURE IsFieldVarient (Sym: CARDINAL) : BOOLEAN ;
7831 VAR
7832 pSym: PtrToSymbol ;
7833 BEGIN
7834 pSym := GetPsym(Sym) ;
7835 RETURN( pSym^.SymbolType=VarientFieldSym )
7836 END IsFieldVarient ;
7837
7838
7839 (*
7840 IsFieldEnumeration - returns true if the symbol, Sym, is an
7841 enumeration field.
7842 *)
7843
7844 PROCEDURE IsFieldEnumeration (Sym: CARDINAL) : BOOLEAN ;
7845 VAR
7846 pSym: PtrToSymbol ;
7847 BEGIN
7848 pSym := GetPsym(Sym) ;
7849 RETURN( pSym^.SymbolType=EnumerationFieldSym )
7850 END IsFieldEnumeration ;
7851
7852
7853 (*
7854 IsVarient - returns true if the symbol, Sym, is a
7855 varient symbol.
7856 *)
7857
7858 PROCEDURE IsVarient (Sym: CARDINAL) : BOOLEAN ;
7859 VAR
7860 pSym: PtrToSymbol ;
7861 BEGIN
7862 pSym := GetPsym(Sym) ;
7863 RETURN( pSym^.SymbolType=VarientSym )
7864 END IsVarient ;
7865
7866
7867 (*
7868 PutUnused - sets, sym, as unused. This is a gm2 pragma.
7869 *)
7870
7871 PROCEDURE PutUnused (sym: CARDINAL) ;
7872 VAR
7873 pSym: PtrToSymbol ;
7874 BEGIN
7875 pSym := GetPsym(sym) ;
7876 WITH pSym^ DO
7877 CASE SymbolType OF
7878
7879 RecordFieldSym: RecordField.Used := FALSE
7880
7881 ELSE
7882 MetaError1("cannot use pragma 'unused' on symbol {%1ad}", sym)
7883 END
7884 END
7885 END PutUnused ;
7886
7887
7888 (*
7889 IsUnused - returns TRUE if the symbol was declared as unused with a
7890 gm2 pragma.
7891 *)
7892
7893 PROCEDURE IsUnused (sym: CARDINAL) : BOOLEAN ;
7894 VAR
7895 pSym: PtrToSymbol ;
7896 BEGIN
7897 pSym := GetPsym(sym) ;
7898 WITH pSym^ DO
7899 CASE SymbolType OF
7900
7901 RecordFieldSym: RETURN( NOT RecordField.Used )
7902
7903 ELSE
7904 InternalError ('expecting a record field symbol')
7905 END
7906 END
7907 END IsUnused ;
7908
7909
7910 (*
7911 PutFieldEnumeration - places a field into the enumeration type
7912 Sym. The field has a name FieldName and a
7913 value FieldVal.
7914 *)
7915
7916 PROCEDURE PutFieldEnumeration (tok: CARDINAL; Sym: CARDINAL; FieldName: Name) ;
7917 VAR
7918 oSym,
7919 pSym : PtrToSymbol ;
7920 s : String ;
7921 Field: CARDINAL ;
7922 BEGIN
7923 Field := CheckForHiddenType(FieldName) ;
7924 IF Field=NulSym
7925 THEN
7926 Field := DeclareSym (tok, FieldName)
7927 END ;
7928 IF NOT IsError(Field)
7929 THEN
7930 pSym := GetPsym(Field) ;
7931 WITH pSym^ DO
7932 SymbolType := EnumerationFieldSym ;
7933 WITH EnumerationField DO
7934 name := FieldName ; (* Index into name array, name *)
7935 (* of type. *)
7936 oSym := GetPsym(Sym) ;
7937 PushCard(oSym^.Enumeration.NoOfElements) ;
7938 Value := InitValue() ;
7939 PopInto(Value) ;
7940 Type := Sym ;
7941 Scope := GetCurrentScope() ;
7942 InitWhereDeclaredTok (tok, At) (* Declared here *)
7943 END
7944 END ;
7945 pSym := GetPsym(Sym) ;
7946 WITH pSym^ DO
7947 CASE SymbolType OF
7948
7949 EnumerationSym: WITH Enumeration DO
7950 INC(NoOfElements) ;
7951 IF GetSymKey(LocalSymbols, FieldName)#NulSym
7952 THEN
7953 s := Mark(InitStringCharStar(KeyToCharStar(FieldName))) ;
7954 AlreadyDeclaredError(Sprintf1(Mark(InitString('enumeration field (%s) is already declared elsewhere, use a different name or remove the declaration')), s),
7955 FieldName,
7956 GetDeclaredMod(GetSymKey(LocalSymbols, FieldName)))
7957 ELSE
7958 PutSymKey(LocalSymbols, FieldName, Field) ;
7959 IncludeItemIntoList (ListOfFields, Field)
7960 END
7961 END
7962
7963 ELSE
7964 InternalError ('expecting Sym=Enumeration')
7965 END
7966 END
7967 END
7968 END PutFieldEnumeration ;
7969
7970
7971 (*
7972 PutType - gives a type symbol Sym type TypeSymbol.
7973 *)
7974
7975 PROCEDURE PutType (Sym: CARDINAL; TypeSymbol: CARDINAL) ;
7976 VAR
7977 pSym: PtrToSymbol ;
7978 BEGIN
7979 IF TypeSymbol=Sym
7980 THEN
7981 InternalError ('not expecting a type to be declared as itself')
7982 END ;
7983 pSym := GetPsym(Sym) ;
7984 WITH pSym^ DO
7985 CASE SymbolType OF
7986
7987 ErrorSym: |
7988 TypeSym : Type.Type := TypeSymbol
7989
7990 ELSE
7991 InternalError ('expecting a Type symbol')
7992 END
7993 END
7994 END PutType ;
7995
7996
7997 (*
7998 IsDefImp - returns true is the Sym is a DefImp symbol.
7999 Definition/Implementation module symbol.
8000 *)
8001
8002 PROCEDURE IsDefImp (Sym: CARDINAL) : BOOLEAN ;
8003 VAR
8004 pSym: PtrToSymbol ;
8005 BEGIN
8006 pSym := GetPsym(Sym) ;
8007 RETURN( pSym^.SymbolType=DefImpSym )
8008 END IsDefImp ;
8009
8010
8011 (*
8012 IsModule - returns true is the Sym is a Module symbol.
8013 Program module symbol.
8014 *)
8015
8016 PROCEDURE IsModule (Sym: CARDINAL) : BOOLEAN ;
8017 VAR
8018 pSym: PtrToSymbol ;
8019 BEGIN
8020 pSym := GetPsym(Sym) ;
8021 RETURN( pSym^.SymbolType=ModuleSym )
8022 END IsModule ;
8023
8024
8025 (*
8026 IsInnerModule - returns true if the symbol, Sym, is an inner module.
8027 *)
8028
8029 PROCEDURE IsInnerModule (Sym: CARDINAL) : BOOLEAN ;
8030 BEGIN
8031 IF IsModule(Sym)
8032 THEN
8033 RETURN( GetScope(Sym)#NulSym )
8034 ELSE
8035 RETURN( FALSE )
8036 END
8037 END IsInnerModule ;
8038
8039
8040 (*
8041 GetSymName - returns the symbol name.
8042 *)
8043
8044 PROCEDURE GetSymName (Sym: CARDINAL) : Name ;
8045 VAR
8046 pSym: PtrToSymbol ;
8047 n : Name ;
8048 BEGIN
8049 IF Sym=NulSym
8050 THEN
8051 n := NulKey
8052 ELSE
8053 pSym := GetPsym(Sym) ;
8054 WITH pSym^ DO
8055 CASE SymbolType OF
8056
8057 ErrorSym : n := Error.name |
8058 ObjectSym : n := Object.name |
8059 DefImpSym : n := DefImp.name |
8060 ModuleSym : n := Module.name |
8061 TypeSym : n := Type.name |
8062 VarSym : n := Var.name |
8063 ConstLitSym : n := ConstLit.name |
8064 ConstVarSym : n := ConstVar.name |
8065 ConstStringSym : n := ConstString.name |
8066 EnumerationSym : n := Enumeration.name |
8067 EnumerationFieldSym : n := EnumerationField.name |
8068 UndefinedSym : n := Undefined.name |
8069 ProcedureSym : n := Procedure.name |
8070 ProcTypeSym : n := ProcType.name |
8071 RecordFieldSym : n := RecordField.name |
8072 RecordSym : n := Record.name |
8073 VarientSym : n := NulName |
8074 VarientFieldSym : n := VarientField.name |
8075 VarParamSym : n := VarParam.name |
8076 ParamSym : n := Param.name |
8077 PointerSym : n := Pointer.name |
8078 ArraySym : n := Array.name |
8079 UnboundedSym : n := NulName |
8080 SubrangeSym : n := Subrange.name |
8081 SetSym : n := Set.name |
8082 SubscriptSym : n := NulName |
8083 DummySym : n := NulName |
8084 PartialUnboundedSym : n := GetSymName(PartialUnbounded.Type) |
8085 TupleSym : n := NulName |
8086 GnuAsmSym : n := NulName |
8087 InterfaceSym : n := NulName |
8088 ImportSym : n := NulName |
8089 ImportStatementSym : n := NulName
8090
8091 ELSE
8092 InternalError ('unexpected symbol type')
8093 END
8094 END
8095 END ;
8096 RETURN( n )
8097 END GetSymName ;
8098
8099
8100 (*
8101 PutConstVarTemporary - indicates that constant, sym, is a temporary.
8102 *)
8103
8104 PROCEDURE PutConstVarTemporary (sym: CARDINAL) ;
8105 VAR
8106 pSym: PtrToSymbol ;
8107 BEGIN
8108 pSym := GetPsym(sym) ;
8109 WITH pSym^ DO
8110 CASE SymbolType OF
8111
8112 ConstVarSym: ConstVar.IsTemp := TRUE
8113
8114 ELSE
8115 InternalError ('expecting a Var symbol')
8116 END
8117 END
8118 END PutConstVarTemporary ;
8119
8120
8121 (*
8122 buildTemporary - builds the temporary filling in componentRef, record and sets mode.
8123 *)
8124
8125 PROCEDURE buildTemporary (tok: CARDINAL;
8126 Mode: ModeOfAddr; componentRef: BOOLEAN; record: CARDINAL) : CARDINAL ;
8127 VAR
8128 pSym: PtrToSymbol ;
8129 s : String ;
8130 Sym : CARDINAL ;
8131 BEGIN
8132 INC(TemporaryNo) ;
8133 (* Make the name *)
8134 s := Sprintf1(Mark(InitString('_T%d')), TemporaryNo) ;
8135 IF Mode=ImmediateValue
8136 THEN
8137 Sym := MakeConstVar(tok, makekey(string(s))) ;
8138 PutConstVarTemporary(Sym)
8139 ELSE
8140 Sym := MakeVar(tok, makekey(string(s))) ;
8141 pSym := GetPsym(Sym) ;
8142 WITH pSym^ DO
8143 CASE SymbolType OF
8144
8145 VarSym : Var.AddrMode := Mode ;
8146 Var.IsComponentRef := componentRef ;
8147 Var.IsTemp := TRUE ; (* Variable is a temporary var *)
8148 IF componentRef
8149 THEN
8150 Var.list := Indexing.InitIndex(1) ;
8151 PutIntoIndex(Var.list, 1, record)
8152 END ;
8153 InitWhereDeclaredTok(tok, Var.At) ; (* Declared here *)
8154 InitWhereFirstUsedTok(tok, Var.At) ; (* Where symbol first used. *)
8155
8156 ELSE
8157 InternalError ('expecting a Var symbol')
8158 END
8159 END
8160 END ;
8161 s := KillString(s) ;
8162 RETURN Sym
8163 END buildTemporary ;
8164
8165
8166 (*
8167 MakeComponentRef - use, sym, to reference, field, sym is returned.
8168 *)
8169
8170 PROCEDURE MakeComponentRef (sym: CARDINAL; field: CARDINAL) : CARDINAL ;
8171 VAR
8172 pSym: PtrToSymbol ;
8173 high: CARDINAL ;
8174 BEGIN
8175 pSym := GetPsym (sym) ;
8176 WITH pSym^ DO
8177 CASE SymbolType OF
8178
8179 VarSym: IF NOT Var.IsTemp
8180 THEN
8181 InternalError ('variable must be a temporary')
8182 ELSIF Var.IsComponentRef
8183 THEN
8184 high := Indexing.HighIndice (Var.list) ;
8185 PutIntoIndex (Var.list, high+1, field)
8186 ELSE
8187 InternalError ('temporary is not a component reference')
8188 END
8189
8190 ELSE
8191 InternalError ('expecting a variable symbol')
8192 END
8193 END ;
8194 RETURN( sym )
8195 END MakeComponentRef ;
8196
8197
8198 (*
8199 MakeComponentRecord - make a temporary which will be used to reference and field
8200 (or sub field) of record.
8201 *)
8202
8203 PROCEDURE MakeComponentRecord (tok: CARDINAL; Mode: ModeOfAddr; record: CARDINAL) : CARDINAL ;
8204 BEGIN
8205 RETURN buildTemporary (tok, Mode, TRUE, record)
8206 END MakeComponentRecord ;
8207
8208
8209 (*
8210 IsComponent - returns TRUE if symbol, sym, is a temporary and a component
8211 reference.
8212 *)
8213
8214 PROCEDURE IsComponent (sym: CARDINAL) : BOOLEAN ;
8215 VAR
8216 pSym: PtrToSymbol ;
8217 BEGIN
8218 pSym := GetPsym(sym) ;
8219 WITH pSym^ DO
8220 CASE SymbolType OF
8221
8222 VarSym: RETURN( Var.IsComponentRef )
8223
8224 ELSE
8225 RETURN( FALSE )
8226 END
8227 END
8228 END IsComponent ;
8229
8230
8231 (*
8232 MakeTemporary - Makes a new temporary variable at the highest real scope.
8233 The addressing mode of the temporary is set to NoValue.
8234 *)
8235
8236 PROCEDURE MakeTemporary (tok: CARDINAL; Mode: ModeOfAddr) : CARDINAL ;
8237 BEGIN
8238 tok := CheckTok (tok, 'temporary') ;
8239 RETURN buildTemporary (tok, Mode, FALSE, NulSym)
8240 END MakeTemporary ;
8241
8242
8243 (*
8244 MakeTemporaryFromExpressions - makes a new temporary variable at the
8245 highest real scope. The addressing
8246 mode of the temporary is set and the
8247 type is determined by expressions,
8248 e1 and e2.
8249 *)
8250
8251 PROCEDURE MakeTemporaryFromExpressions (tok: CARDINAL;
8252 e1, e2: CARDINAL;
8253 mode: ModeOfAddr) : CARDINAL ;
8254 VAR
8255 pSym: PtrToSymbol ;
8256 s : String ;
8257 t,
8258 Sym : CARDINAL ;
8259 BEGIN
8260 INC(TemporaryNo) ;
8261 (* Make the name *)
8262 s := Sprintf1(Mark(InitString('_T%d')), TemporaryNo) ;
8263 IF mode=ImmediateValue
8264 THEN
8265 Sym := MakeConstVar(tok, makekey(string(s))) ;
8266 IF IsConstructor(e1)
8267 THEN
8268 PutConstructor(Sym) ;
8269 PutConstructorFrom(Sym, e1)
8270 ELSIF IsConstructor(e2)
8271 THEN
8272 PutConstructor(Sym) ;
8273 PutConstructorFrom(Sym, e2)
8274 ELSE
8275 PutVar(Sym, MixTypes(GetType(e1), GetType(e2), tok))
8276 END ;
8277 PutConstVarTemporary(Sym)
8278 ELSE
8279 Sym := MakeVar(tok, makekey(string(s))) ;
8280 pSym := GetPsym(Sym) ;
8281 WITH pSym^ DO
8282 CASE SymbolType OF
8283
8284 VarSym : Var.AddrMode := mode ;
8285 Var.IsComponentRef := FALSE ;
8286 Var.IsTemp := TRUE ; (* Variable is a temporary var *)
8287 InitWhereDeclaredTok(tok, Var.At)
8288 (* Declared here *)
8289
8290 ELSE
8291 InternalError ('expecting a Var symbol')
8292 END
8293 END ;
8294 t := MixTypesDecl (e1, e2, GetType(e1), GetType(e2), tok) ;
8295 IF t#NulSym
8296 THEN
8297 Assert(NOT IsConstructor(t)) ;
8298 PutVar(Sym, t)
8299 END
8300 END ;
8301 s := KillString(s) ;
8302 RETURN( Sym )
8303 END MakeTemporaryFromExpressions ;
8304
8305
8306 (*
8307 MakeTemporaryFromExpression - makes a new temporary variable at the
8308 highest real scope. The addressing
8309 mode of the temporary is set and the
8310 type is determined by expressions, e.
8311 *)
8312
8313 PROCEDURE MakeTemporaryFromExpression (tok: CARDINAL;
8314 e: CARDINAL;
8315 mode: ModeOfAddr) : CARDINAL ;
8316 BEGIN
8317 RETURN MakeTemporaryFromExpressions (tok, e, e, mode)
8318 END MakeTemporaryFromExpression ;
8319
8320
8321 (*
8322 PutMode - Puts the addressing mode, SymMode, into symbol Sym.
8323 The mode may only be altered if the mode
8324 is None.
8325 *)
8326
8327 PROCEDURE PutMode (Sym: CARDINAL; SymMode: ModeOfAddr) ;
8328 VAR
8329 pSym: PtrToSymbol ;
8330 BEGIN
8331 pSym := GetPsym(Sym) ;
8332 WITH pSym^ DO
8333 CASE SymbolType OF
8334
8335 ErrorSym: |
8336 VarSym : Var.AddrMode := SymMode
8337
8338 ELSE
8339 InternalError ('Expecting VarSym')
8340 END
8341 END
8342 END PutMode ;
8343
8344
8345 (*
8346 GetMode - Returns the addressing mode of a symbol.
8347 *)
8348
8349 PROCEDURE GetMode (Sym: CARDINAL) : ModeOfAddr ;
8350 VAR
8351 pSym: PtrToSymbol ;
8352 BEGIN
8353 pSym := GetPsym(Sym) ;
8354 WITH pSym^ DO
8355 CASE SymbolType OF
8356
8357 ErrorSym : ErrorAbort0('') |
8358 VarSym : RETURN( Var.AddrMode ) |
8359 ConstLitSym : RETURN( ImmediateValue ) |
8360 ConstVarSym : RETURN( ImmediateValue ) |
8361 ConstStringSym : RETURN( ImmediateValue ) |
8362 EnumerationFieldSym: RETURN( ImmediateValue ) |
8363 ProcedureSym : RETURN( ImmediateValue ) |
8364 RecordFieldSym : RETURN( ImmediateValue ) |
8365 VarientFieldSym : RETURN( ImmediateValue ) |
8366 TypeSym : RETURN( NoValue ) |
8367 ArraySym : RETURN( NoValue ) |
8368 SubrangeSym : RETURN( NoValue ) |
8369 EnumerationSym : RETURN( NoValue ) |
8370 RecordSym : RETURN( NoValue ) |
8371 PointerSym : RETURN( NoValue ) |
8372 SetSym : RETURN( NoValue ) |
8373 ProcTypeSym : RETURN( NoValue ) |
8374 UnboundedSym : RETURN( NoValue ) |
8375 UndefinedSym : RETURN( NoValue )
8376
8377 ELSE
8378 InternalError ('not expecting this type')
8379 END
8380 END
8381 END GetMode ;
8382
8383
8384 (*
8385 RenameSym - renames a symbol, Sym, with SymName.
8386 It also checks the unknown tree for a symbol
8387 with this new name. Must only be renamed in
8388 the same scope of being declared.
8389 *)
8390
8391 PROCEDURE RenameSym (Sym: CARDINAL; SymName: Name) ;
8392 VAR
8393 pSym: PtrToSymbol ;
8394 BEGIN
8395 IF GetSymName(Sym)=NulName
8396 THEN
8397 pSym := GetPsym(Sym) ;
8398 WITH pSym^ DO
8399 CASE SymbolType OF
8400
8401 ErrorSym : ErrorAbort0('') |
8402 TypeSym : Type.name := SymName |
8403 VarSym : Var.name := SymName |
8404 ConstLitSym : ConstLit.name := SymName |
8405 ConstVarSym : ConstVar.name := SymName |
8406 UndefinedSym : Undefined.name := SymName |
8407 RecordSym : Record.name := SymName |
8408 PointerSym : Pointer.name := SymName
8409
8410 ELSE
8411 InternalError ('not implemented yet')
8412 END
8413 END ;
8414 AddSymToScope(Sym, SymName)
8415 ELSE
8416 InternalError ('old name of symbol must be nul')
8417 END
8418 END RenameSym ;
8419
8420
8421 (*
8422 IsUnknown - returns true is the symbol Sym is unknown.
8423 *)
8424
8425 PROCEDURE IsUnknown (Sym: WORD) : BOOLEAN ;
8426 VAR
8427 pSym: PtrToSymbol ;
8428 BEGIN
8429 AssertInRange (Sym) ;
8430 pSym := GetPsym(Sym) ;
8431 RETURN pSym^.SymbolType=UndefinedSym
8432 END IsUnknown ;
8433
8434
8435 (*
8436 AssertInRange - determines whether the Sym is a legal symbol.
8437 *)
8438
8439 PROCEDURE AssertInRange (Sym: CARDINAL) ;
8440 BEGIN
8441 IF (Sym<1) OR (Sym>FinalSymbol())
8442 THEN
8443 InternalError ('illegal symbol')
8444 END
8445 END AssertInRange ;
8446
8447
8448 (*
8449 CheckForHiddenType - scans the NeedToBeImplemented tree providing
8450 that we are currently compiling an implementation
8451 module. If a symbol is found with TypeName
8452 then its Sym is returned.
8453 Otherwise NulSym is returned.
8454 CheckForHiddenType is called before any type is
8455 created, therefore the compiler allows hidden
8456 types to be implemented using any type.
8457 *)
8458
8459 PROCEDURE CheckForHiddenType (TypeName: Name) : CARDINAL ;
8460 VAR
8461 pSym: PtrToSymbol ;
8462 Sym : CARDINAL ;
8463 BEGIN
8464 Sym := NulSym ;
8465 IF CompilingImplementationModule() AND
8466 IsDefImp(CurrentModule) AND
8467 IsHiddenTypeDeclared(CurrentModule) AND
8468 (TypeName#NulName)
8469 THEN
8470 (* Check to see whether we are declaring a HiddenType. *)
8471 pSym := GetPsym(CurrentModule) ;
8472 WITH pSym^ DO
8473 CASE SymbolType OF
8474
8475 DefImpSym: Sym := GetSymKey(DefImp.NeedToBeImplemented, TypeName)
8476
8477 ELSE
8478 InternalError ('expecting a DefImp symbol')
8479 END
8480 END
8481 END ;
8482 RETURN( Sym )
8483 END CheckForHiddenType ;
8484
8485
8486 (*
8487 IsReallyPointer - returns TRUE is sym is a pointer, address or a
8488 type declared as a pointer or address.
8489 *)
8490
8491 PROCEDURE IsReallyPointer (Sym: CARDINAL) : BOOLEAN ;
8492 BEGIN
8493 IF IsVar (Sym)
8494 THEN
8495 Sym := GetType (Sym)
8496 END ;
8497 Sym := SkipType (Sym) ;
8498 RETURN IsPointer (Sym) OR (Sym = Address) OR IsHiddenReallyPointer (Sym)
8499 END IsReallyPointer ;
8500
8501
8502 (*
8503 IsHiddenReallyPointer - returns TRUE is sym is a pointer, address or a
8504 type declared as a pointer or address.
8505 *)
8506
8507 PROCEDURE IsHiddenReallyPointer (Sym: CARDINAL) : BOOLEAN ;
8508 BEGIN
8509 IF IsVar (Sym)
8510 THEN
8511 Sym := GetType (Sym)
8512 END ;
8513 WHILE (Sym # NulSym) AND IsType (Sym) DO
8514 Sym := SkipType (GetType (Sym))
8515 END ;
8516 RETURN (Sym # NulSym) AND (IsPointer (Sym) OR (Sym = Address))
8517 END IsHiddenReallyPointer ;
8518
8519
8520 (*
8521 CheckHiddenTypeAreAddress - checks to see that any hidden types
8522 which we have declared are actually
8523 of type ADDRESS or map onto a POINTER type.
8524 *)
8525
8526 PROCEDURE CheckHiddenTypeAreAddress ;
8527 VAR
8528 name: Name ;
8529 e : Error ;
8530 sym,
8531 i, n: CARDINAL ;
8532 BEGIN
8533 i := 1 ;
8534 n := NoOfItemsInList(AddressTypes) ;
8535 WHILE i<=n DO
8536 sym := GetItemFromList(AddressTypes, i) ;
8537 IF NOT IsHiddenReallyPointer(sym)
8538 THEN
8539 name := GetSymName(sym) ;
8540 e := NewError(GetDeclaredDef(sym)) ;
8541 ErrorFormat1(e, 'opaque type (%a) should be equivalent to a POINTER or an ADDRESS', name) ;
8542 e := NewError(GetDeclaredMod(sym)) ;
8543 ErrorFormat0(e, 'if you really need a non POINTER type use the -fextended-opaque switch')
8544 END ;
8545 INC(i)
8546 END
8547 END CheckHiddenTypeAreAddress ;
8548
8549
8550 (*
8551 GetLastMainScopeId - returns the, id, containing the last main scope.
8552 *)
8553
8554 (*
8555 PROCEDURE GetLastMainScopeId (id: CARDINAL) : CARDINAL ;
8556 VAR
8557 pCall: PtrToCallFrame ;
8558 sym : CARDINAL ;
8559 BEGIN
8560 IF id>0
8561 THEN
8562 pCall := GetPcall(id) ;
8563 sym := pCall^.Main ;
8564 WHILE id>1 DO
8565 DEC(id) ;
8566 pCall := GetPcall(id) ;
8567 IF sym#pCall^.Main
8568 THEN
8569 RETURN( id )
8570 END
8571 END
8572 END ;
8573 RETURN( 0 )
8574 END GetLastMainScopeId ;
8575 *)
8576
8577
8578 (*
8579 GetDeclareSym - searches for a symbol with a name SymName in the
8580 current and previous scopes.
8581 If the symbol is found then it is returned
8582 else an unknown symbol is returned.
8583 This procedure assumes that SymName is being
8584 declared at this point and therefore it does
8585 not examine the base scope (for pervasive
8586 identifiers).
8587 *)
8588
8589 PROCEDURE GetDeclareSym (tok: CARDINAL; SymName: Name) : CARDINAL ;
8590 VAR
8591 Sym: CARDINAL ;
8592 BEGIN
8593 Sym := GetScopeSym (SymName, FALSE) ; (* must not be allowed to fetch a symbol through a procedure scope *)
8594 IF Sym=NulSym
8595 THEN
8596 Sym := GetSymFromUnknownTree (SymName) ;
8597 IF Sym=NulSym
8598 THEN
8599 (* Make unknown *)
8600 NewSym (Sym) ;
8601 FillInUnknownFields (tok, Sym, SymName) ;
8602 (* Add to unknown tree *)
8603 AddSymToUnknownTree (ScopePtr, SymName, Sym)
8604 (*
8605 ; WriteKey(SymName) ; WriteString(' unknown demanded') ; WriteLn
8606 *)
8607 END
8608 END ;
8609 RETURN Sym
8610 END GetDeclareSym ;
8611
8612
8613 (*
8614 RequestSym - searches for a symbol with a name SymName in the
8615 current and previous scopes.
8616 If the symbol is found then it is returned
8617 else an unknown symbol is returned create at token
8618 position, tok.
8619 This procedure does search the base scope (for
8620 pervasive identifiers).
8621 *)
8622
8623 PROCEDURE RequestSym (tok: CARDINAL; SymName: Name) : CARDINAL ;
8624 VAR
8625 Sym: CARDINAL ;
8626 BEGIN
8627 (*
8628 WriteString('RequestSym for: ') ; WriteKey(SymName) ; WriteLn ;
8629 *)
8630 Sym := GetSym (SymName) ;
8631 IF Sym=NulSym
8632 THEN
8633 Sym := GetSymFromUnknownTree (SymName) ;
8634 IF Sym=NulSym
8635 THEN
8636 (* Make unknown *)
8637 NewSym (Sym) ;
8638 FillInUnknownFields (tok, Sym, SymName) ;
8639 (* Add to unknown tree *)
8640 AddSymToUnknownTree (ScopePtr, SymName, Sym)
8641 (*
8642 ; WriteKey(SymName) ; WriteString(' unknown demanded') ; WriteLn
8643 *)
8644 END
8645 END ;
8646 RETURN( Sym )
8647 END RequestSym ;
8648
8649
8650 (*
8651 PutImported - places a symbol, Sym, into the current main scope.
8652 *)
8653
8654 PROCEDURE PutImported (Sym: CARDINAL) ;
8655 VAR
8656 pSym : PtrToSymbol ;
8657 ModSym: CARDINAL ;
8658 n : Name ;
8659 BEGIN
8660 (*
8661 We have currently imported Sym, now place it into the current module.
8662 *)
8663 ModSym := GetCurrentModuleScope() ;
8664 Assert(IsDefImp(ModSym) OR IsModule(ModSym)) ;
8665 pSym := GetPsym(ModSym) ;
8666 WITH pSym^ DO
8667 CASE SymbolType OF
8668
8669 ModuleSym: IF GetSymKey(Module.ImportTree, GetSymName(Sym))=Sym
8670 THEN
8671 IF Pedantic
8672 THEN
8673 n := GetSymName(Sym) ;
8674 WriteFormat1('symbol (%a) has already been imported', n)
8675 END
8676 ELSIF GetSymKey(Module.ImportTree, GetSymName(Sym))=NulKey
8677 THEN
8678 IF GetSymKey(Module.WhereImported, Sym)=NulKey
8679 THEN
8680 PutSymKey(Module.WhereImported, Sym, GetTokenNo())
8681 END ;
8682 PutSymKey(Module.ImportTree, GetSymName(Sym), Sym) ;
8683 AddSymToModuleScope(ModSym, Sym)
8684 ELSE
8685 n := GetSymName(Sym) ;
8686 WriteFormat1('name clash when trying to import (%a)', n)
8687 END |
8688 DefImpSym: IF GetSymKey(DefImp.ImportTree, GetSymName(Sym))=Sym
8689 THEN
8690 IF Pedantic
8691 THEN
8692 n := GetSymName(Sym) ;
8693 WriteFormat1('symbol (%a) has already been imported', n)
8694 END
8695 ELSIF GetSymKey(DefImp.ImportTree, GetSymName(Sym))=NulKey
8696 THEN
8697 IF GetSymKey(DefImp.WhereImported, Sym)=NulKey
8698 THEN
8699 PutSymKey(DefImp.WhereImported, Sym, GetTokenNo())
8700 END ;
8701 PutSymKey(DefImp.ImportTree, GetSymName(Sym), Sym) ;
8702 AddSymToModuleScope(ModSym, Sym)
8703 ELSE
8704 n := GetSymName(Sym) ;
8705 WriteFormat1('name clash when trying to import (%a)', n)
8706 END
8707
8708 ELSE
8709 InternalError ('expecting a Module or DefImp symbol')
8710 END
8711 END
8712 END PutImported ;
8713
8714
8715 (*
8716 PutIncluded - places a symbol, Sym, into the included list of the
8717 current module.
8718 Symbols that are placed in this list are indirectly declared
8719 by:
8720
8721 IMPORT modulename ;
8722
8723 modulename.identifier
8724 *)
8725
8726 PROCEDURE PutIncluded (Sym: CARDINAL) ;
8727 VAR
8728 pSym : PtrToSymbol ;
8729 ModSym: CARDINAL ;
8730 n1, n2: Name ;
8731 BEGIN
8732 (*
8733 We have referenced Sym, via modulename.Sym
8734 now place it into the current module include list.
8735 *)
8736 ModSym := GetCurrentModuleScope() ;
8737 Assert(IsDefImp(ModSym) OR IsModule(ModSym)) ;
8738 IF DebugUnknowns
8739 THEN
8740 n1 := GetSymName(Sym) ;
8741 n2 := GetSymName(ModSym) ;
8742 printf2('including %a into scope %a\n', n1, n2)
8743 END ;
8744 pSym := GetPsym(ModSym) ;
8745 WITH pSym^ DO
8746 CASE SymbolType OF
8747
8748 ModuleSym: IncludeItemIntoList(Module.IncludeList, Sym) |
8749 DefImpSym: IncludeItemIntoList(DefImp.IncludeList, Sym)
8750
8751 ELSE
8752 InternalError ('expecting a Module or DefImp symbol')
8753 END
8754 END
8755 END PutIncluded ;
8756
8757
8758 (*
8759 PutExported - places a symbol, Sym into the next level out module.
8760 Sym is also placed in the ExportTree of the current inner
8761 module.
8762 *)
8763
8764 PROCEDURE PutExported (Sym: CARDINAL) ;
8765 VAR
8766 pSym: PtrToSymbol ;
8767 BEGIN
8768 (*
8769 WriteString('PutExported') ; WriteLn ;
8770 *)
8771 AddSymToModuleScope(GetLastModuleOrProcedureScope(), Sym) ;
8772 pSym := GetPsym(GetCurrentModuleScope()) ;
8773 WITH pSym^ DO
8774 CASE SymbolType OF
8775
8776 ModuleSym: PutSymKey(Module.ExportTree, GetSymName(Sym), Sym) ;
8777 IF IsUnknown(Sym)
8778 THEN
8779 PutExportUndeclared(GetCurrentModuleScope(), Sym)
8780 END
8781 (*
8782 ; WriteKey(Module.name) ; WriteString(' exports ') ;
8783 ; WriteKey(GetSymName(Sym)) ; WriteLn ;
8784 *)
8785
8786 ELSE
8787 InternalError ('expecting a Module symbol')
8788 END
8789 END
8790 END PutExported ;
8791
8792
8793 (*
8794 PutExportQualified - places a symbol with the name, SymName,
8795 into the export tree of the
8796 Definition module being compiled.
8797 The symbol with name has been EXPORT QUALIFIED
8798 by the definition module and therefore any reference
8799 to this symbol in the code generation phase
8800 will be in the form _Module_Name.
8801 *)
8802
8803 PROCEDURE PutExportQualified (tokenno: CARDINAL; SymName: Name) ;
8804 VAR
8805 pSym : PtrToSymbol ;
8806 n : Name ;
8807 Sym,
8808 ModSym: CARDINAL ;
8809 BEGIN
8810 ModSym := GetCurrentModule () ;
8811 Assert (IsDefImp (ModSym)) ;
8812 Assert (CompilingDefinitionModule () OR
8813 (GetSymName(ModSym) = MakeKey ('SYSTEM'))) ;
8814 (* printf2('module %a exporting %a\n', GetSymName(ModSym), SymName) ; *)
8815 (*
8816 WriteString('1st MODULE ') ; WriteKey(GetSymName(ModSym)) ;
8817 WriteString(' identifier ') ; WriteKey(SymName) ; WriteLn ;
8818 *)
8819 pSym := GetPsym (ModSym) ;
8820 WITH pSym^ DO
8821 CASE SymbolType OF
8822
8823 DefImpSym: WITH DefImp DO
8824 IF (GetSymKey (ExportQualifiedTree, SymName) # NulKey) AND
8825 (GetSymKey (ExportRequest, SymName) = NulKey)
8826 THEN
8827 n := GetSymName(ModSym) ;
8828 WriteFormat2('identifier (%a) has already been exported from MODULE %a',
8829 SymName, n)
8830 ELSIF GetSymKey(ExportRequest, SymName)#NulKey
8831 THEN
8832 Sym := GetSymKey(ExportRequest, SymName) ;
8833 DelSymKey(ExportRequest, SymName) ;
8834 PutSymKey(ExportQualifiedTree, SymName, Sym) ;
8835 PutExportUndeclared (ModSym, Sym)
8836 ELSE
8837 Sym := GetDeclareSym(tokenno, SymName) ;
8838 PutSymKey(ExportQualifiedTree, SymName, Sym) ;
8839 PutExportUndeclared (ModSym, Sym)
8840 END
8841 END
8842
8843 ELSE
8844 InternalError ('expecting a DefImp symbol')
8845 END
8846 END
8847 END PutExportQualified ;
8848
8849
8850 (*
8851 PutExportUnQualified - places a symbol with the name, SymName,
8852 into the export tree of the
8853 Definition module being compiled.
8854 The symbol with Name has been EXPORT UNQUALIFIED
8855 by the definition module and therefore any reference
8856 to this symbol in the code generation phase
8857 will be in the form _Name.
8858 *)
8859
8860 PROCEDURE PutExportUnQualified (tokenno: CARDINAL; SymName: Name) ;
8861 VAR
8862 pSym : PtrToSymbol ;
8863 n : Name ;
8864 Sym,
8865 ModSym: CARDINAL ;
8866 BEGIN
8867 ModSym := GetCurrentModule() ;
8868 Assert(IsDefImp(ModSym)) ;
8869 Assert(CompilingDefinitionModule() OR (GetSymName(ModSym)=MakeKey('SYSTEM'))) ;
8870 pSym := GetPsym(ModSym) ;
8871 WITH pSym^ DO
8872 CASE SymbolType OF
8873
8874 DefImpSym: WITH DefImp DO
8875 IF (GetSymKey(ExportUnQualifiedTree, SymName)#NulKey) AND
8876 (GetSymKey(ExportRequest, SymName)=NulKey)
8877 THEN
8878 n := GetSymName(ModSym) ;
8879 WriteFormat2('identifier (%a) has already been exported from MODULE %a',
8880 SymName, n)
8881 ELSIF GetSymKey(ExportRequest, SymName)#NulKey
8882 THEN
8883 Sym := GetSymKey(ExportRequest, SymName) ;
8884 DelSymKey(ExportRequest, SymName) ;
8885 PutSymKey(ExportUnQualifiedTree, SymName, Sym) ;
8886 PutExportUndeclared(ModSym, Sym)
8887 ELSE
8888 Sym := GetDeclareSym(tokenno, SymName) ;
8889 PutSymKey(ExportUnQualifiedTree, SymName, Sym) ;
8890 PutExportUndeclared(ModSym, Sym)
8891 END
8892 END
8893
8894 ELSE
8895 InternalError ('expecting a DefImp symbol')
8896 END
8897 END
8898 END PutExportUnQualified ;
8899
8900
8901 (*
8902 GetExported - returns the symbol which has a name SymName,
8903 and is exported from the definition module ModSym.
8904
8905 *)
8906
8907 PROCEDURE GetExported (tokenno: CARDINAL;
8908 ModSym: CARDINAL;
8909 SymName: Name) : CARDINAL ;
8910 VAR
8911 pSym: PtrToSymbol ;
8912 Sym : CARDINAL ;
8913 BEGIN
8914 pSym := GetPsym(ModSym) ;
8915 WITH pSym^ DO
8916 CASE SymbolType OF
8917
8918 DefImpSym: Sym := RequestFromDefinition (tokenno, ModSym, SymName) |
8919 ModuleSym: Sym := RequestFromModule (tokenno, ModSym, SymName)
8920
8921 ELSE
8922 InternalError ('expecting a DefImp symbol')
8923 END
8924 END ;
8925 RETURN( Sym )
8926 END GetExported ;
8927
8928
8929 (*
8930 RequestFromModule - returns a symbol from module ModSym with name, SymName.
8931 *)
8932
8933 PROCEDURE RequestFromModule (tok: CARDINAL; ModSym: CARDINAL; SymName: Name) : CARDINAL ;
8934 VAR
8935 pSym: PtrToSymbol ;
8936 Sym : CARDINAL ;
8937 BEGIN
8938 pSym := GetPsym(ModSym) ;
8939 WITH pSym^ DO
8940 CASE SymbolType OF
8941
8942 DefImpSym: WITH DefImp DO
8943 Sym := GetSymKey (LocalSymbols, SymName) ;
8944 IF Sym=NulSym
8945 THEN
8946 Sym := FetchUnknownFromDefImp (tok, ModSym, SymName)
8947 END
8948 END |
8949
8950 ModuleSym: WITH Module DO
8951 Sym := GetSymKey (LocalSymbols, SymName) ;
8952 IF Sym=NulSym
8953 THEN
8954 Sym := FetchUnknownFromModule (tok, ModSym, SymName)
8955 END
8956 END
8957
8958 ELSE
8959 InternalError ('expecting a DefImp or Module symbol')
8960 END
8961 END ;
8962 RETURN( Sym )
8963 END RequestFromModule ;
8964
8965
8966 (*
8967 RequestFromDefinition - returns a symbol from module ModSym with name,
8968 SymName.
8969 *)
8970
8971 PROCEDURE RequestFromDefinition (tok: CARDINAL;
8972 ModSym: CARDINAL; SymName: Name) : CARDINAL ;
8973 VAR
8974 pSym : PtrToSymbol ;
8975 Sym : CARDINAL ;
8976 OldScopePtr: CARDINAL ;
8977 BEGIN
8978 pSym := GetPsym(ModSym) ;
8979 WITH pSym^ DO
8980 CASE SymbolType OF
8981
8982 DefImpSym: WITH DefImp DO
8983 Sym := GetSymKey (ExportQualifiedTree, SymName) ;
8984 IF Sym=NulSym
8985 THEN
8986 Sym := GetSymKey (ExportUnQualifiedTree, SymName) ;
8987 IF Sym=NulSym
8988 THEN
8989 Sym := GetSymKey (ExportRequest, SymName) ;
8990 IF Sym=NulSym
8991 THEN
8992 OldScopePtr := ScopePtr ;
8993 StartScope (ModSym) ;
8994 Sym := GetScopeSym (SymName, TRUE) ;
8995 EndScope ;
8996 Assert (OldScopePtr=ScopePtr) ;
8997 IF Sym=NulSym
8998 THEN
8999 Sym := FetchUnknownFromDefImp (tok, ModSym, SymName)
9000 ELSE
9001 IF IsFieldEnumeration (Sym)
9002 THEN
9003 IF IsExported (ModSym, GetType (Sym))
9004 THEN
9005 RETURN( Sym )
9006 END
9007 END
9008 END ;
9009 PutSymKey (ExportRequest, SymName, Sym)
9010 END
9011 END
9012 END
9013 END
9014
9015 ELSE
9016 InternalError ('expecting a DefImp symbol')
9017 END
9018 END ;
9019 RETURN( Sym )
9020 END RequestFromDefinition ;
9021
9022
9023 (*
9024 PutIncludedByDefinition - places a module symbol, Sym, into the
9025 included list of the current definition module.
9026 *)
9027
9028 PROCEDURE PutIncludedByDefinition (Sym: CARDINAL) ;
9029 VAR
9030 pSym : PtrToSymbol ;
9031 ModSym: CARDINAL ;
9032 BEGIN
9033 ModSym := GetCurrentModuleScope() ;
9034 Assert(IsDefImp(ModSym)) ;
9035 Assert(IsDefImp(Sym)) ;
9036 pSym := GetPsym(ModSym) ;
9037 WITH pSym^ DO
9038 CASE SymbolType OF
9039
9040 DefImpSym: IncludeItemIntoList(DefImp.DefIncludeList, Sym)
9041
9042 ELSE
9043 InternalError ('expecting a DefImp symbol')
9044 END
9045 END
9046 END PutIncludedByDefinition ;
9047
9048
9049 (*
9050 IsIncludedByDefinition - returns TRUE if definition module symbol, Sym, was included
9051 by ModSym's definition module.
9052 *)
9053
9054 PROCEDURE IsIncludedByDefinition (ModSym, Sym: CARDINAL) : BOOLEAN ;
9055 VAR
9056 pSym: PtrToSymbol ;
9057 BEGIN
9058 Assert(IsDefImp(ModSym)) ;
9059 Assert(IsDefImp(Sym)) ;
9060 pSym := GetPsym(ModSym) ;
9061 WITH pSym^ DO
9062 CASE SymbolType OF
9063
9064 DefImpSym: RETURN( IsItemInList(DefImp.DefIncludeList, Sym) )
9065
9066 ELSE
9067 InternalError ('expecting a DefImp symbol')
9068 END
9069 END
9070 END IsIncludedByDefinition ;
9071
9072
9073 (*
9074 GetWhereImported - returns the token number where this symbol
9075 was imported into the current module.
9076 *)
9077
9078 PROCEDURE GetWhereImported (Sym: CARDINAL) : CARDINAL ;
9079 VAR
9080 pSym: PtrToSymbol ;
9081 BEGIN
9082 pSym := GetPsym(GetCurrentModuleScope()) ;
9083 WITH pSym^ DO
9084 CASE SymbolType OF
9085
9086 DefImpSym: RETURN( GetSymKey(DefImp.WhereImported, Sym) ) |
9087 ModuleSym: RETURN( GetSymKey(Module.WhereImported, Sym) )
9088
9089 ELSE
9090 InternalError ('expecting DefImp or Module symbol')
9091 END
9092 END
9093 END GetWhereImported ;
9094
9095
9096 (*
9097 DisplayName - displays the name.
9098 *)
9099
9100 PROCEDURE DisplayName (sym: WORD) ;
9101 BEGIN
9102 printf1(' %a', sym)
9103 END DisplayName ;
9104
9105
9106 (*
9107 DisplaySymbol - displays the name of a symbol
9108 *)
9109
9110 PROCEDURE DisplaySymbol (sym: WORD) ;
9111 VAR
9112 s: String ;
9113 BEGIN
9114 s := Mark(InitStringCharStar(KeyToCharStar(GetSymName(sym)))) ;
9115 printf2(' %s (%d)', s, sym)
9116 END DisplaySymbol ;
9117
9118
9119 (*
9120 DisplayTrees - displays the SymbolTrees for Module symbol, ModSym.
9121 *)
9122
9123 PROCEDURE DisplayTrees (ModSym: CARDINAL) ;
9124 VAR
9125 pSym: PtrToSymbol ;
9126 n : Name ;
9127 BEGIN
9128 n := GetSymName(ModSym) ;
9129 printf1('Symbol trees for module/procedure: %a\n', n) ;
9130 pSym := GetPsym(ModSym) ;
9131 WITH pSym^ DO
9132 CASE SymbolType OF
9133
9134 DefImpSym: WITH DefImp DO
9135 n := GetSymName(ModSym) ;
9136 printf1('%a UndefinedTree', n) ;
9137 ForeachNodeDo(Unresolved, DisplaySymbol) ; printf0('\n') ;
9138 printf1('%a Local symbols', n) ;
9139 ForeachNodeDo(LocalSymbols, DisplaySymbol) ; printf0('\n') ;
9140 printf1('%a ExportRequest', n) ;
9141 ForeachNodeDo(ExportRequest, DisplaySymbol) ; printf0('\n') ;
9142 printf1('%a ExportQualified', n) ;
9143 ForeachNodeDo(ExportQualifiedTree, DisplaySymbol) ; printf0('\n') ;
9144 printf1('%a ExportUnQualified', n) ;
9145 ForeachNodeDo(ExportUnQualifiedTree, DisplaySymbol) ; printf0('\n') ;
9146 printf1('%a ExportUndeclared', n) ;
9147 ForeachNodeDo(ExportUndeclared, DisplaySymbol) ; printf0('\n') ;
9148 printf1('%a DeclaredObjects', n) ;
9149 ForeachNodeDo(NamedObjects, DisplaySymbol) ; printf0('\n') ;
9150 printf1('%a ImportedObjects', n) ;
9151 ForeachNodeDo(NamedImports, DisplayName) ; printf0('\n')
9152 END |
9153 ModuleSym: WITH Module DO
9154 n := GetSymName(ModSym) ;
9155 printf1('%a UndefinedTree', n) ;
9156 ForeachNodeDo(Unresolved, DisplaySymbol) ; printf0('\n') ;
9157 printf1('%a Local symbols', n) ;
9158 ForeachNodeDo(LocalSymbols, DisplaySymbol) ; printf0('\n') ;
9159 printf1('%a ImportTree', n) ;
9160 ForeachNodeDo(ImportTree, DisplaySymbol) ; printf0('\n') ;
9161 printf1('%a ExportTree', n) ;
9162 ForeachNodeDo(ExportTree, DisplaySymbol) ; printf0('\n') ;
9163 printf1('%a ExportUndeclared', n) ;
9164 ForeachNodeDo(ExportUndeclared, DisplaySymbol) ; printf0('\n') ;
9165 printf1('%a DeclaredObjects', n) ;
9166 ForeachNodeDo(NamedObjects, DisplaySymbol) ; printf0('\n') ;
9167 printf1('%a ImportedObjects', n) ;
9168 ForeachNodeDo(NamedImports, DisplayName) ; printf0('\n')
9169 END |
9170 ProcedureSym: WITH Procedure DO
9171 n := GetSymName(ModSym) ;
9172 printf1('%a UndefinedTree', n) ;
9173 ForeachNodeDo(Unresolved, DisplaySymbol) ; printf0('\n') ;
9174 printf1('%a Local symbols', n) ;
9175 ForeachNodeDo(LocalSymbols, DisplaySymbol) ; printf0('\n') ;
9176 printf1('%a DeclaredObjects', n) ;
9177 ForeachNodeDo(NamedObjects, DisplayName) ; printf0('\n')
9178 END
9179
9180 ELSE
9181 InternalError ('expecting DefImp symbol')
9182 END
9183 END
9184 END DisplayTrees ;
9185
9186
9187 (*
9188 FetchUnknownFromModule - returns an Unknown symbol from module, ModSym.
9189 *)
9190
9191 PROCEDURE FetchUnknownFromModule (tok: CARDINAL;
9192 ModSym: CARDINAL;
9193 SymName: Name) : CARDINAL ;
9194 VAR
9195 pSym: PtrToSymbol ;
9196 Sym : CARDINAL ;
9197 BEGIN
9198 pSym := GetPsym (ModSym) ;
9199 WITH pSym^ DO
9200 CASE SymbolType OF
9201 ModuleSym: WITH Module DO
9202 Sym := GetSymKey (Unresolved, SymName) ;
9203 IF Sym=NulSym
9204 THEN
9205 NewSym (Sym) ;
9206 FillInUnknownFields (tok, Sym, SymName) ;
9207 PutSymKey (Unresolved, SymName, Sym)
9208 END
9209 END
9210 ELSE
9211 InternalError ('expecting a Module symbol')
9212 END
9213 END ;
9214 RETURN( Sym )
9215 END FetchUnknownFromModule ;
9216
9217
9218 (*
9219 FetchUnknownFromDefImp - returns an Unknown symbol from module, ModSym.
9220 *)
9221
9222 PROCEDURE FetchUnknownFromDefImp (tok: CARDINAL;
9223 ModSym: CARDINAL;
9224 SymName: Name) : CARDINAL ;
9225 VAR
9226 pSym: PtrToSymbol ;
9227 Sym : CARDINAL ;
9228 BEGIN
9229 pSym := GetPsym (ModSym) ;
9230 WITH pSym^ DO
9231 CASE SymbolType OF
9232 DefImpSym: WITH DefImp DO
9233 Sym := GetSymKey (Unresolved , SymName) ;
9234 IF Sym=NulSym
9235 THEN
9236 NewSym(Sym) ;
9237 FillInUnknownFields (tok, Sym, SymName) ;
9238 PutSymKey (Unresolved, SymName, Sym)
9239 END
9240 END
9241 ELSE
9242 InternalError ('expecting a DefImp symbol')
9243 END
9244 END ;
9245 RETURN( Sym )
9246 END FetchUnknownFromDefImp ;
9247
9248
9249 PROCEDURE FetchUnknownFrom (tok: CARDINAL;
9250 scope: CARDINAL;
9251 SymName: Name) : CARDINAL ;
9252 VAR
9253 pSym: PtrToSymbol ;
9254 Sym : CARDINAL ;
9255 BEGIN
9256 pSym := GetPsym(scope) ;
9257 WITH pSym^ DO
9258 CASE SymbolType OF
9259 DefImpSym: WITH DefImp DO
9260 Sym := GetSymKey(Unresolved, SymName) ;
9261 IF Sym=NulSym
9262 THEN
9263 NewSym(Sym) ;
9264 FillInUnknownFields (tok, Sym, SymName) ;
9265 PutSymKey(Unresolved, SymName, Sym)
9266 END
9267 END |
9268 ModuleSym: WITH Module DO
9269 Sym := GetSymKey(Unresolved, SymName) ;
9270 IF Sym=NulSym
9271 THEN
9272 NewSym(Sym) ;
9273 FillInUnknownFields (tok, Sym, SymName) ;
9274 PutSymKey(Unresolved, SymName, Sym)
9275 END
9276 END |
9277 ProcedureSym: WITH Procedure DO
9278 Sym := GetSymKey(Unresolved, SymName) ;
9279 IF Sym=NulSym
9280 THEN
9281 NewSym(Sym) ;
9282 FillInUnknownFields (tok, Sym, SymName) ;
9283 PutSymKey(Unresolved, SymName, Sym)
9284 END
9285 END
9286
9287 ELSE
9288 InternalError ('expecting a DefImp or Module or Procedure symbol')
9289 END
9290 END ;
9291 RETURN( Sym )
9292 END FetchUnknownFrom ;
9293
9294
9295 (*
9296 GetFromOuterModule - returns a symbol with name, SymName, which comes
9297 from outside the current module.
9298 *)
9299
9300 PROCEDURE GetFromOuterModule (tokenno: CARDINAL; SymName: Name) : CARDINAL ;
9301 VAR
9302 pCall : PtrToCallFrame ;
9303 ScopeId : CARDINAL ;
9304 Sym,
9305 ScopeSym: CARDINAL ;
9306 BEGIN
9307 ScopeId := ScopePtr ;
9308 pCall := GetPcall(ScopeId) ;
9309 WHILE (NOT IsModule(pCall^.Search)) AND
9310 (NOT IsDefImp(pCall^.Search)) DO
9311 Assert (ScopeId>0) ;
9312 DEC (ScopeId) ;
9313 pCall := GetPcall (ScopeId)
9314 END ;
9315 DEC (ScopeId) ;
9316 (* we are now below the current module *)
9317 WHILE ScopeId>0 DO
9318 pCall := GetPcall(ScopeId) ;
9319 ScopeSym := pCall^.Search ;
9320 IF ScopeSym#NulSym
9321 THEN
9322 Sym := GetLocalSym(ScopeSym, SymName) ;
9323 IF Sym=NulSym
9324 THEN
9325 IF IsModule(ScopeSym) OR IsProcedure(ScopeSym) OR IsDefImp(ScopeSym)
9326 THEN
9327 IF Sym=NulSym
9328 THEN
9329 Sym := ExamineUnresolvedTree(ScopeSym, SymName) ;
9330 IF Sym#NulSym
9331 THEN
9332 RETURN( Sym )
9333 END
9334 END
9335 END
9336 ELSE
9337 RETURN( Sym )
9338 END
9339 END ;
9340 DEC(ScopeId) ;
9341 pCall := GetPcall(ScopeId)
9342 END ;
9343 (* at this point we force an unknown from the last module scope *)
9344 RETURN( RequestFromModule (tokenno, GetLastModuleScope(), SymName) )
9345 END GetFromOuterModule ;
9346
9347
9348 (*
9349 IsExportUnQualified - returns true if a symbol, Sym, was defined as
9350 being EXPORT UNQUALIFIED.
9351 *)
9352
9353 PROCEDURE IsExportUnQualified (Sym: CARDINAL) : BOOLEAN ;
9354 VAR
9355 pSym : PtrToSymbol ;
9356 OuterModule: CARDINAL ;
9357 BEGIN
9358 OuterModule := Sym ;
9359 REPEAT
9360 OuterModule := GetScope(OuterModule)
9361 UNTIL GetScope(OuterModule)=NulSym ;
9362 pSym := GetPsym(OuterModule) ;
9363 WITH pSym^ DO
9364 CASE SymbolType OF
9365
9366 ModuleSym: RETURN( FALSE ) |
9367 DefImpSym: RETURN( GetSymKey(
9368 DefImp.ExportUnQualifiedTree,
9369 GetSymName(Sym)
9370 )=Sym
9371 )
9372
9373 ELSE
9374 InternalError ('expecting a DefImp or Module symbol')
9375 END
9376 END
9377 END IsExportUnQualified ;
9378
9379
9380 (*
9381 IsExportQualified - returns true if a symbol, Sym, was defined as
9382 being EXPORT QUALIFIED.
9383 Sym is expected to be either a procedure or a
9384 variable.
9385 *)
9386
9387 PROCEDURE IsExportQualified (Sym: CARDINAL) : BOOLEAN ;
9388 VAR
9389 pSym : PtrToSymbol ;
9390 OuterModule: CARDINAL ;
9391 BEGIN
9392 OuterModule := Sym ;
9393 REPEAT
9394 OuterModule := GetScope(OuterModule)
9395 UNTIL GetScope(OuterModule)=NulSym ;
9396 pSym := GetPsym(OuterModule) ;
9397 WITH pSym^ DO
9398 CASE SymbolType OF
9399
9400 ModuleSym: RETURN( FALSE ) |
9401 DefImpSym: RETURN( GetSymKey(DefImp.ExportQualifiedTree, GetSymName(Sym))=Sym )
9402
9403 ELSE
9404 InternalError ('expecting a DefImp or Module symbol')
9405 END
9406 END
9407 END IsExportQualified ;
9408
9409
9410 (*
9411 ForeachImportedDo - calls a procedure, P, foreach imported symbol
9412 in module, ModSym.
9413 *)
9414
9415 PROCEDURE ForeachImportedDo (ModSym: CARDINAL; P: PerformOperation) ;
9416 VAR
9417 pSym: PtrToSymbol ;
9418 BEGIN
9419 pSym := GetPsym(ModSym) ;
9420 WITH pSym^ DO
9421 CASE SymbolType OF
9422
9423 DefImpSym: WITH DefImp DO
9424 ForeachNodeDo( ImportTree, P ) ;
9425 ForeachItemInListDo( IncludeList, P )
9426 END |
9427 ModuleSym: WITH Module DO
9428 ForeachNodeDo( ImportTree, P ) ;
9429 ForeachItemInListDo( IncludeList, P )
9430 END
9431
9432 ELSE
9433 InternalError ('expecting a DefImp or Module symbol')
9434 END
9435 END
9436 END ForeachImportedDo ;
9437
9438
9439 (*
9440 ForeachExportedDo - calls a procedure, P, foreach imported symbol
9441 in module, ModSym.
9442 *)
9443
9444 PROCEDURE ForeachExportedDo (ModSym: CARDINAL; P: PerformOperation) ;
9445 VAR
9446 pSym: PtrToSymbol ;
9447 BEGIN
9448 pSym := GetPsym(ModSym) ;
9449 WITH pSym^ DO
9450 CASE SymbolType OF
9451
9452 DefImpSym: WITH DefImp DO
9453 ForeachNodeDo( ExportQualifiedTree, P ) ;
9454 ForeachNodeDo( ExportUnQualifiedTree, P )
9455 END |
9456 ModuleSym: WITH Module DO
9457 ForeachNodeDo( ExportTree, P )
9458 END
9459
9460 ELSE
9461 InternalError ('expecting a DefImp or Module symbol')
9462 END
9463 END
9464 END ForeachExportedDo ;
9465
9466
9467 (*
9468 ForeachLocalSymDo - foreach local symbol in module, Sym, or procedure, Sym,
9469 perform the procedure, P.
9470 *)
9471
9472 PROCEDURE ForeachLocalSymDo (Sym: CARDINAL; P: PerformOperation) ;
9473 VAR
9474 pSym: PtrToSymbol ;
9475 BEGIN
9476 pSym := GetPsym(Sym) ;
9477 WITH pSym^ DO
9478 CASE SymbolType OF
9479
9480 DefImpSym: WITH DefImp DO
9481 ForeachNodeDo( LocalSymbols, P )
9482 END |
9483 ModuleSym: WITH Module DO
9484 ForeachNodeDo( LocalSymbols, P )
9485 END |
9486 ProcedureSym: WITH Procedure DO
9487 ForeachNodeDo( LocalSymbols, P )
9488 END |
9489 RecordSym: WITH Record DO
9490 ForeachNodeDo( LocalSymbols, P )
9491 END |
9492 EnumerationSym: WITH Enumeration DO
9493 ForeachNodeDo( LocalSymbols, P )
9494 END
9495
9496 ELSE
9497 InternalError ('expecting a DefImp, Module or Procedure symbol')
9498 END
9499 END
9500 END ForeachLocalSymDo ;
9501
9502
9503 (*
9504 ForeachParamSymDo - foreach parameter symbol in procedure Sym
9505 perform the procedure P. Each symbol
9506 looked up will be VarParam or Param
9507 (not the shadow variable). Every parameter
9508 from each KindProcedure is iterated over.
9509 *)
9510
9511 PROCEDURE ForeachParamSymDo (Sym: CARDINAL; P: PerformOperation) ;
9512 VAR
9513 kind : ProcedureKind ;
9514 param: CARDINAL ;
9515 p, i : CARDINAL ;
9516 BEGIN
9517 IF IsProcedure (Sym)
9518 THEN
9519 FOR kind := MIN (ProcedureKind) TO MAX (ProcedureKind) DO
9520 p := NoOfParam (Sym, kind) ;
9521 i := p ;
9522 WHILE i>0 DO
9523 param := GetNthParam (Sym, kind, i) ;
9524 P (param) ;
9525 DEC(i)
9526 END
9527 END
9528 END
9529 END ForeachParamSymDo ;
9530
9531
9532 (*
9533 CheckForUnknownInModule - checks for any unknown symbols in the
9534 current module.
9535 If any unknown symbols are found then
9536 an error message is displayed.
9537 *)
9538
9539 PROCEDURE CheckForUnknownInModule ;
9540 VAR
9541 pSym: PtrToSymbol ;
9542 BEGIN
9543 pSym := GetPsym(GetCurrentModuleScope()) ;
9544 WITH pSym^ DO
9545 CASE SymbolType OF
9546
9547 DefImpSym: WITH DefImp DO
9548 CheckForUnknowns (name, ExportQualifiedTree,
9549 'EXPORT QUALIFIED') ;
9550 CheckForUnknowns (name, ExportUnQualifiedTree,
9551 'EXPORT UNQUALIFIED') ;
9552 CheckForSymbols (ExportRequest,
9553 'requested by another modules import (symbols have not been exported by the appropriate definition module)') ;
9554 CheckForUnknowns (name, Unresolved, 'unresolved') ;
9555 CheckForUnknowns (name, LocalSymbols, 'locally used')
9556 END |
9557 ModuleSym: WITH Module DO
9558 CheckForUnknowns (name, Unresolved, 'unresolved') ;
9559 CheckForUnknowns (name, ExportUndeclared, 'exported but undeclared') ;
9560 CheckForUnknowns (name, ExportTree, 'exported but undeclared') ;
9561 CheckForUnknowns (name, LocalSymbols, 'locally used')
9562 END
9563
9564 ELSE
9565 InternalError ('expecting a DefImp or Module symbol')
9566 END
9567 END
9568 END CheckForUnknownInModule ;
9569
9570
9571 (*
9572 UnknownSymbolError - displays symbol name for symbol, sym.
9573 *)
9574
9575 PROCEDURE UnknownSymbolError (sym: WORD) ;
9576 BEGIN
9577 IF IsUnreportedUnknown (sym)
9578 THEN
9579 IncludeElementIntoSet (ReportedUnknowns, sym) ;
9580 MetaErrorStringT1 (GetFirstUsed (sym), InitString ("unknown symbol {%1EUad}"), sym)
9581 END
9582 END UnknownSymbolError ;
9583
9584
9585 (*
9586 UnknownReported - if sym is an unknown symbol and has not been reported
9587 then include it into the set of reported unknowns.
9588 *)
9589
9590 PROCEDURE UnknownReported (sym: CARDINAL) ;
9591 BEGIN
9592 IF IsUnreportedUnknown (sym)
9593 THEN
9594 IncludeElementIntoSet (ReportedUnknowns, sym)
9595 END
9596 END UnknownReported ;
9597
9598
9599 (*
9600 IsUnreportedUnknown - returns TRUE if symbol, sym, has not been
9601 reported and is an unknown symbol.
9602 *)
9603
9604 PROCEDURE IsUnreportedUnknown (sym: CARDINAL) : BOOLEAN ;
9605 BEGIN
9606 RETURN IsUnknown (sym) AND (NOT IsElementInSet (ReportedUnknowns, sym))
9607 END IsUnreportedUnknown ;
9608
9609
9610 VAR
9611 ListifySentance : String ;
9612 ListifyTotal,
9613 ListifyWordCount: CARDINAL ;
9614
9615
9616 (*
9617 AddListify -
9618 *)
9619
9620 PROCEDURE AddListify (sym: CARDINAL) ;
9621 BEGIN
9622 INC (ListifyWordCount) ;
9623 (* printf ("AddListify: ListifyWordCount = %d, ListifyTotal = %d\n",
9624 ListifyWordCount, ListifyTotal) ; *)
9625 IF ListifyWordCount > 1
9626 THEN
9627 IF ListifyWordCount = ListifyTotal
9628 THEN
9629 ListifySentance := ConCat (ListifySentance, Mark (InitString (" and ")))
9630 ELSE
9631 ListifySentance := ConCat (ListifySentance, Mark (InitString (", ")))
9632 END
9633 END ;
9634 ListifySentance := ConCat (ListifySentance,
9635 Mark (InitStringCharStar (KeyToCharStar (GetSymName (sym)))))
9636 END AddListify ;
9637
9638
9639 (*
9640 Listify - convert tree into a string list and return the result.
9641 *)
9642
9643 PROCEDURE Listify (tree: SymbolTree; isCondition: IsSymbol) : String ;
9644 BEGIN
9645 ListifyTotal := NoOfNodes (tree, isCondition) ;
9646 ListifyWordCount := 0 ;
9647 ListifySentance := InitString ('') ;
9648 ForeachNodeConditionDo (tree, isCondition, AddListify) ;
9649 RETURN ListifySentance
9650 END Listify ;
9651
9652
9653 (*
9654 CheckForUnknowns - checks a binary tree, Tree, to see whether it contains
9655 an unknown symbol. All unknown symbols are displayed
9656 together with an error message.
9657 *)
9658
9659 PROCEDURE CheckForUnknowns (name: Name; Tree: SymbolTree;
9660 a: ARRAY OF CHAR) ;
9661 VAR
9662 s: String ;
9663 BEGIN
9664 IF DoesTreeContainAny(Tree, IsUnreportedUnknown)
9665 THEN
9666 CurrentError := NewError(GetTokenNo()) ;
9667 s := InitString("{%E} the following unknown symbols in module %<") ;
9668 s := ConCat(s, Mark(InitStringCharStar(KeyToCharStar(name)))) ;
9669 s := ConCat(s, Mark(InitString('%> were '))) ;
9670 s := ConCat(s, Mark(InitString(a))) ;
9671 s := ConCat (s, Mark (InitString (': '))) ;
9672 s := ConCat (s, Mark (Listify (Tree, IsUnreportedUnknown))) ;
9673 MetaErrorStringT0(GetTokenNo(), s) ;
9674 ForeachNodeDo(Tree, UnknownSymbolError)
9675 END
9676 END CheckForUnknowns ;
9677
9678
9679 (*
9680 SymbolError - displays symbol name for symbol, Sym.
9681 *)
9682
9683 PROCEDURE SymbolError (Sym: WORD) ;
9684 VAR
9685 e: Error ;
9686 n: Name ;
9687 BEGIN
9688 n := GetSymName(Sym) ;
9689 e := ChainError(GetFirstUsed(Sym), CurrentError) ;
9690 ErrorFormat1(e, "unknown symbol '%a' found", n)
9691 END SymbolError ;
9692
9693
9694 (*
9695 CheckForSymbols - checks a binary tree, Tree, to see whether it contains
9696 any symbol. The tree is expected to be empty, if not
9697 then an error has occurred.
9698 *)
9699
9700 PROCEDURE CheckForSymbols (Tree: SymbolTree; a: ARRAY OF CHAR) ;
9701 VAR
9702 s: String ;
9703 BEGIN
9704 IF NOT IsEmptyTree(Tree)
9705 THEN
9706 s := InitString ("the symbols are unknown at the end of module {%1Ea} when ") ;
9707 s := ConCat (s, Mark(InitString(a))) ;
9708 MetaErrorString1 (s, MainModule) ;
9709 ForeachNodeDo(Tree, SymbolError)
9710 END
9711 END CheckForSymbols ;
9712
9713
9714 (*
9715 PutExportUndeclared - places a symbol, Sym, into module, ModSym,
9716 ExportUndeclared list provided that Sym
9717 is unknown.
9718 *)
9719
9720 PROCEDURE PutExportUndeclared (ModSym: CARDINAL; Sym: CARDINAL) ;
9721 VAR
9722 pSym: PtrToSymbol ;
9723 BEGIN
9724 IF IsUnknown (Sym)
9725 THEN
9726 pSym := GetPsym (ModSym) ;
9727 WITH pSym^ DO
9728 CASE SymbolType OF
9729
9730 ModuleSym: PutSymKey (Module.ExportUndeclared, GetSymName (Sym), Sym) |
9731 DefImpSym: PutSymKey (DefImp.ExportUndeclared, GetSymName (Sym), Sym)
9732
9733 ELSE
9734 InternalError ('expecting a DefImp or Module symbol')
9735 END
9736 END
9737 END
9738 END PutExportUndeclared ;
9739
9740
9741 (*
9742 GetExportUndeclared - returns a symbol which has, name, from module, ModSym,
9743 which is in the ExportUndeclared list.
9744 *)
9745
9746 PROCEDURE GetExportUndeclared (ModSym: CARDINAL; name: Name) : CARDINAL ;
9747 VAR
9748 pSym: PtrToSymbol ;
9749 BEGIN
9750 pSym := GetPsym(ModSym) ;
9751 WITH pSym^ DO
9752 CASE SymbolType OF
9753
9754 ModuleSym: RETURN( GetSymKey(Module.ExportUndeclared, name) ) |
9755 DefImpSym: RETURN( GetSymKey(DefImp.ExportUndeclared, name) )
9756
9757 ELSE
9758 InternalError ('expecting a DefImp or Module symbol')
9759 END
9760 END
9761 END GetExportUndeclared ;
9762
9763
9764 (*
9765 RemoveExportUndeclared - removes a symbol, Sym, from the module, ModSym,
9766 ExportUndeclaredTree.
9767 *)
9768
9769 PROCEDURE RemoveExportUndeclared (ModSym: CARDINAL; Sym: CARDINAL) ;
9770 VAR
9771 pSym: PtrToSymbol ;
9772 BEGIN
9773 pSym := GetPsym(ModSym) ;
9774 WITH pSym^ DO
9775 CASE SymbolType OF
9776
9777 ModuleSym: IF GetSymKey(Module.ExportUndeclared, GetSymName(Sym))=Sym
9778 THEN
9779 DelSymKey(Module.ExportUndeclared, GetSymName(Sym))
9780 END |
9781 DefImpSym: IF GetSymKey(DefImp.ExportUndeclared, GetSymName(Sym))=Sym
9782 THEN
9783 DelSymKey(DefImp.ExportUndeclared, GetSymName(Sym))
9784 END
9785
9786 ELSE
9787 InternalError ('expecting a DefImp or Module symbol')
9788 END
9789 END
9790 END RemoveExportUndeclared ;
9791
9792
9793 (*
9794 CheckForExportedDeclaration - checks to see whether a definition module
9795 is currently being compiled, if so,
9796 symbol, Sym, is removed from the
9797 ExportUndeclared list.
9798 This procedure is called whenever a symbol
9799 is declared, thus attempting to reduce
9800 the ExportUndeclared list.
9801 *)
9802
9803 PROCEDURE CheckForExportedDeclaration (Sym: CARDINAL) ;
9804 BEGIN
9805 IF CompilingDefinitionModule ()
9806 THEN
9807 RemoveExportUndeclared(GetCurrentModule(), Sym)
9808 END
9809 END CheckForExportedDeclaration ;
9810
9811
9812 (*
9813 CheckForUndeclaredExports - displays an error and the offending symbols
9814 which have been exported but not declared
9815 from module, ModSym.
9816 *)
9817
9818 PROCEDURE CheckForUndeclaredExports (ModSym: CARDINAL) ;
9819 VAR
9820 pSym: PtrToSymbol ;
9821 BEGIN
9822 (* WriteString('Inside CheckForUndeclaredExports') ; WriteLn ; *)
9823 pSym := GetPsym(ModSym) ;
9824 WITH pSym^ DO
9825 CASE SymbolType OF
9826
9827 ModuleSym: IF NOT IsEmptyTree(Module.ExportUndeclared)
9828 THEN
9829 MetaError1('undeclared identifier(s) in EXPORT list of {%1ERd} {%1a}', ModSym) ;
9830 ForeachNodeDo(Module.ExportUndeclared, UndeclaredSymbolError)
9831 END |
9832 DefImpSym: IF NOT IsEmptyTree(DefImp.ExportUndeclared)
9833 THEN
9834 IF DoesNotNeedExportList(ModSym)
9835 THEN
9836 MetaError1('undeclared identifier(s) in {%1ERd} {%1a}', ModSym) ;
9837 ELSE
9838 MetaError1('undeclared identifier(s) in export list of {%1ERd} {%1a}', ModSym) ;
9839 END ;
9840 ForeachNodeDo(DefImp.ExportUndeclared, UndeclaredSymbolError)
9841 END
9842
9843 ELSE
9844 InternalError ('expecting a DefImp or Module symbol')
9845 END
9846 END
9847 END CheckForUndeclaredExports ;
9848
9849
9850 (*
9851 UndeclaredSymbolError - displays symbol name for symbol, Sym.
9852 *)
9853
9854 PROCEDURE UndeclaredSymbolError (Sym: WORD) ;
9855 BEGIN
9856 IF DebugUnknowns
9857 THEN
9858 printf1('undeclared symbol (%d)\n', Sym)
9859 END ;
9860 MetaError1('{%1UC} undeclared symbol {%1a}', Sym)
9861 END UndeclaredSymbolError ;
9862
9863
9864 (*
9865 PutExportUnImplemented - places a symbol, Sym, into the currently compiled
9866 DefImp module NeedToBeImplemented list.
9867 *)
9868
9869 PROCEDURE PutExportUnImplemented (tokenno: CARDINAL; Sym: CARDINAL) ;
9870 VAR
9871 pSym: PtrToSymbol ;
9872 BEGIN
9873 pSym := GetPsym (CurrentModule) ;
9874 WITH pSym^ DO
9875 CASE SymbolType OF
9876
9877 DefImpSym: IF GetSymKey (DefImp.NeedToBeImplemented, GetSymName (Sym)) = Sym
9878 THEN
9879 MetaErrorT2 (tokenno, 'symbol {%1a} is already exported from module {%2a}',
9880 Sym, CurrentModule)
9881 (*
9882 n1 := GetSymName (Sym) ;
9883 n2 := GetSymName (CurrentModule) ;
9884 WriteFormat2 ('symbol (%a) already exported from module (%a)', n1, n2)
9885 *)
9886 ELSE
9887 PutSymKey (DefImp.NeedToBeImplemented, GetSymName(Sym), Sym)
9888 END
9889
9890 ELSE
9891 InternalError ('expecting a DefImp symbol')
9892 END
9893 END
9894 END PutExportUnImplemented ;
9895
9896
9897 (*
9898 RemoveExportUnImplemented - removes a symbol, Sym, from the module, ModSym,
9899 NeedToBeImplemented list.
9900 *)
9901
9902 PROCEDURE RemoveExportUnImplemented (ModSym: CARDINAL; Sym: CARDINAL) ;
9903 VAR
9904 pSym: PtrToSymbol ;
9905 BEGIN
9906 pSym := GetPsym(ModSym) ;
9907 WITH pSym^ DO
9908 CASE SymbolType OF
9909
9910 DefImpSym: IF GetSymKey(DefImp.NeedToBeImplemented, GetSymName(Sym))=Sym
9911 THEN
9912 DelSymKey(DefImp.NeedToBeImplemented, GetSymName(Sym))
9913 END
9914
9915 ELSE
9916 InternalError ('expecting a DefImp symbol')
9917 END
9918 END
9919 END RemoveExportUnImplemented ;
9920
9921
9922 VAR
9923 ExportRequestModule: CARDINAL ;
9924
9925
9926 (*
9927 RemoveFromExportRequest -
9928 *)
9929
9930 PROCEDURE RemoveFromExportRequest (Sym: CARDINAL) ;
9931 VAR
9932 pSym: PtrToSymbol ;
9933 BEGIN
9934 pSym := GetPsym(ExportRequestModule) ;
9935 WITH pSym^ DO
9936 CASE SymbolType OF
9937
9938 DefImpSym: IF GetSymKey(DefImp.ExportRequest, GetSymName(Sym))=Sym
9939 THEN
9940 DelSymKey(DefImp.ExportRequest, GetSymName(Sym))
9941 END
9942
9943 ELSE
9944 InternalError ('expecting a DefImp symbol')
9945 END
9946 END
9947 END RemoveFromExportRequest ;
9948
9949
9950 (*
9951 RemoveEnumerationFromExportRequest - removes enumeration symbol, sym,
9952 (and its fields) from the ExportRequest tree.
9953 *)
9954
9955 PROCEDURE RemoveEnumerationFromExportRequest (ModSym: CARDINAL; Sym: CARDINAL) ;
9956 BEGIN
9957 IF IsEnumeration(Sym)
9958 THEN
9959 ExportRequestModule := ModSym ;
9960 RemoveFromExportRequest(Sym) ;
9961 ForeachLocalSymDo(Sym, RemoveFromExportRequest)
9962 END
9963 END RemoveEnumerationFromExportRequest ;
9964
9965
9966 (*
9967 CheckForExportedImplementation - checks to see whether an implementation
9968 module is currently being compiled, if so,
9969 symbol, Sym, is removed from the
9970 NeedToBeImplemented list.
9971 This procedure is called whenever a symbol
9972 is declared, thus attempting to reduce
9973 the NeedToBeImplemented list.
9974 Only needs to be called when a TYPE or
9975 PROCEDURE is built since the implementation
9976 module can only implement these objects
9977 declared in the definition module.
9978
9979 It also checks whether a definition module
9980 is currently being compiled and, if so,
9981 it will ensure that symbol, Sym, is removed
9982 from the ExportRequest list. If Sym is an
9983 enumerated type it ensures that its fields
9984 are also removed.
9985 *)
9986
9987 PROCEDURE CheckForExportedImplementation (Sym: CARDINAL) ;
9988 BEGIN
9989 IF CompilingImplementationModule()
9990 THEN
9991 RemoveExportUnImplemented(GetCurrentModule(), Sym)
9992 END ;
9993 IF CompilingDefinitionModule() AND IsEnumeration(Sym)
9994 THEN
9995 RemoveEnumerationFromExportRequest(GetCurrentModule(), Sym)
9996 END
9997 END CheckForExportedImplementation ;
9998
9999
10000 (*
10001 CheckForUnImplementedExports - displays an error and the offending symbols
10002 which have been exported but not implemented
10003 from the current compiled module.
10004 *)
10005
10006 PROCEDURE CheckForUnImplementedExports ;
10007 VAR
10008 pSym: PtrToSymbol ;
10009 BEGIN
10010 (* WriteString('Inside CheckForImplementedExports') ; WriteLn ; *)
10011 pSym := GetPsym (CurrentModule) ;
10012 WITH pSym^ DO
10013 CASE SymbolType OF
10014
10015 DefImpSym: IF NOT IsEmptyTree (DefImp.NeedToBeImplemented)
10016 THEN
10017 CurrentError := NewError (GetTokenNo ()) ;
10018 ErrorFormat1 (CurrentError, 'unimplemented identifier(s) in EXPORT list of DEFINITION MODULE %a\nthe implementation module fails to implement the following exported identifier(s)', DefImp.name) ;
10019 ForeachNodeDo (DefImp.NeedToBeImplemented, UnImplementedSymbolError)
10020 END
10021
10022 ELSE
10023 InternalError ('expecting a DefImp symbol')
10024 END
10025 END
10026 END CheckForUnImplementedExports ;
10027
10028
10029 (*
10030 UnImplementedSymbolError - displays symbol name for symbol, Sym.
10031 *)
10032
10033 PROCEDURE UnImplementedSymbolError (Sym: WORD) ;
10034 VAR
10035 n: Name ;
10036 BEGIN
10037 CurrentError := ChainError (GetFirstUsed (Sym), CurrentError) ;
10038 IF IsType (Sym)
10039 THEN
10040 n := GetSymName(Sym) ;
10041 ErrorFormat1 (CurrentError, 'hidden type is undeclared (%a)', n)
10042 ELSIF IsProcedure (Sym)
10043 THEN
10044 n := GetSymName(Sym) ;
10045 ErrorFormat1 (CurrentError, 'procedure is undeclared (%a)', n)
10046 ELSIF IsProcType (Sym)
10047 THEN
10048 n := GetSymName(Sym) ;
10049 ErrorFormat1 (CurrentError, 'procedure type is undeclared (%a)', n)
10050 ELSE
10051 ErrorFormat0 (CurrentError, 'undeclared symbol')
10052 END
10053 END UnImplementedSymbolError ;
10054
10055
10056 (*
10057 PutHiddenTypeDeclared - sets a flag in the current compiled module which
10058 indicates that a Hidden Type is declared within
10059 the implementation part of the module.
10060 This procedure is expected to be called while
10061 compiling the associated definition module.
10062 *)
10063
10064 PROCEDURE PutHiddenTypeDeclared ;
10065 VAR
10066 pSym: PtrToSymbol ;
10067 BEGIN
10068 pSym := GetPsym(CurrentModule) ;
10069 WITH pSym^ DO
10070 CASE SymbolType OF
10071
10072 DefImpSym: DefImp.ContainsHiddenType := TRUE
10073
10074 ELSE
10075 InternalError ('expecting a DefImp symbol')
10076 END
10077 END
10078 END PutHiddenTypeDeclared ;
10079
10080
10081 (*
10082 IsHiddenTypeDeclared - returns true if a Hidden Type was declared in
10083 the module, Sym.
10084 *)
10085
10086 PROCEDURE IsHiddenTypeDeclared (Sym: CARDINAL) : BOOLEAN ;
10087 VAR
10088 pSym: PtrToSymbol ;
10089 BEGIN
10090 pSym := GetPsym(Sym) ;
10091 WITH pSym^ DO
10092 CASE SymbolType OF
10093
10094 DefImpSym: RETURN( DefImp.ContainsHiddenType )
10095
10096 ELSE
10097 InternalError ('expecting a DefImp symbol')
10098 END
10099 END
10100 END IsHiddenTypeDeclared ;
10101
10102
10103 (*
10104 PutModuleContainsBuiltin - sets a flag in the current compiled module which
10105 indicates that a builtin procedure is being declared.
10106 This is only expected to be called when we are
10107 parsing the definition module.
10108 *)
10109
10110 PROCEDURE PutModuleContainsBuiltin ;
10111 VAR
10112 pSym: PtrToSymbol ;
10113 BEGIN
10114 PutHiddenTypeDeclared ;
10115 pSym := GetPsym(CurrentModule) ;
10116 WITH pSym^ DO
10117 CASE SymbolType OF
10118
10119 DefImpSym: DefImp.ContainsBuiltin := TRUE
10120
10121 ELSE
10122 InternalError ('expecting a DefImp symbol')
10123 END
10124 END
10125 END PutModuleContainsBuiltin ;
10126
10127
10128 (*
10129 IsBuiltinInModule - returns true if a module, Sym, has declared a builtin procedure.
10130 *)
10131
10132 PROCEDURE IsBuiltinInModule (Sym: CARDINAL) : BOOLEAN ;
10133 VAR
10134 pSym: PtrToSymbol ;
10135 BEGIN
10136 pSym := GetPsym(Sym) ;
10137 WITH pSym^ DO
10138 CASE SymbolType OF
10139
10140 DefImpSym: RETURN( DefImp.ContainsBuiltin )
10141
10142 ELSE
10143 InternalError ('expecting a DefImp symbol')
10144 END
10145 END
10146 END IsBuiltinInModule ;
10147
10148
10149 (*
10150 PutDefinitionForC - sets a flag in the current compiled module which
10151 indicates that this module is a wrapper for a C
10152 file. Parameters passes to procedures in this module
10153 will adopt the C calling convention.
10154 *)
10155
10156 PROCEDURE PutDefinitionForC (Sym: CARDINAL) ;
10157 VAR
10158 pSym: PtrToSymbol ;
10159 BEGIN
10160 pSym := GetPsym(Sym) ;
10161 WITH pSym^ DO
10162 CASE SymbolType OF
10163
10164 DefImpSym: DefImp.ForC := TRUE
10165
10166 ELSE
10167 InternalError ('expecting a DefImp symbol')
10168 END
10169 END
10170 END PutDefinitionForC ;
10171
10172
10173 (*
10174 IsDefinitionForC - returns true if this definition module was declared
10175 as a DEFINITION MODULE FOR "C".
10176 *)
10177
10178 PROCEDURE IsDefinitionForC (Sym: CARDINAL) : BOOLEAN ;
10179 VAR
10180 pSym: PtrToSymbol ;
10181 BEGIN
10182 pSym := GetPsym(Sym) ;
10183 WITH pSym^ DO
10184 CASE SymbolType OF
10185
10186 DefImpSym: RETURN( DefImp.ForC )
10187
10188 ELSE
10189 InternalError ('expecting a DefImp symbol')
10190 END
10191 END
10192 END IsDefinitionForC ;
10193
10194
10195 (*
10196 PutDoesNeedExportList - sets a flag in module, Sym, which
10197 indicates that this module requires an explicit
10198 EXPORT QUALIFIED or UNQUALIFIED list. PIM-2
10199 *)
10200
10201 PROCEDURE PutDoesNeedExportList (Sym: CARDINAL) ;
10202 VAR
10203 pSym: PtrToSymbol ;
10204 BEGIN
10205 pSym := GetPsym(Sym) ;
10206 WITH pSym^ DO
10207 CASE SymbolType OF
10208
10209 DefImpSym: DefImp.NeedExportList := TRUE
10210
10211 ELSE
10212 InternalError ('expecting a DefImp symbol')
10213 END
10214 END
10215 END PutDoesNeedExportList ;
10216
10217
10218 (*
10219 PutDoesNotNeedExportList - sets a flag in module, Sym, which
10220 indicates that this module does not require an explicit
10221 EXPORT QUALIFIED or UNQUALIFIED list. PIM-3|4
10222 *)
10223
10224 PROCEDURE PutDoesNotNeedExportList (Sym: CARDINAL) ;
10225 VAR
10226 pSym: PtrToSymbol ;
10227 BEGIN
10228 pSym := GetPsym(Sym) ;
10229 WITH pSym^ DO
10230 CASE SymbolType OF
10231
10232 DefImpSym: DefImp.NeedExportList := FALSE
10233
10234 ELSE
10235 InternalError ('expecting a DefImp symbol')
10236 END
10237 END
10238 END PutDoesNotNeedExportList ;
10239
10240
10241 (*
10242 DoesNotNeedExportList - returns TRUE if module, Sym, does not require an explicit
10243 EXPORT QUALIFIED list.
10244 *)
10245
10246 PROCEDURE DoesNotNeedExportList (Sym: CARDINAL) : BOOLEAN ;
10247 VAR
10248 pSym: PtrToSymbol ;
10249 BEGIN
10250 pSym := GetPsym(Sym) ;
10251 WITH pSym^ DO
10252 CASE SymbolType OF
10253
10254 DefImpSym: RETURN( NOT DefImp.NeedExportList )
10255
10256 ELSE
10257 InternalError ('expecting a DefImp symbol')
10258 END
10259 END
10260 END DoesNotNeedExportList ;
10261
10262
10263 (*
10264 CheckForEnumerationInCurrentModule - checks to see whether the enumeration
10265 type symbol, Sym, has been entered into
10266 the current modules scope list.
10267 *)
10268
10269 PROCEDURE CheckForEnumerationInCurrentModule (Sym: CARDINAL) ;
10270 VAR
10271 pSym : PtrToSymbol ;
10272 ModSym: CARDINAL ;
10273 BEGIN
10274 IF (SkipType(Sym)#NulSym) AND IsEnumeration(SkipType(Sym))
10275 THEN
10276 Sym := SkipType(Sym)
10277 END ;
10278
10279 IF IsEnumeration(Sym)
10280 THEN
10281 ModSym := GetCurrentModuleScope() ;
10282 pSym := GetPsym(ModSym) ;
10283 WITH pSym^ DO
10284 CASE SymbolType OF
10285
10286 DefImpSym: CheckEnumerationInList(DefImp.EnumerationScopeList, Sym) |
10287 ModuleSym: CheckEnumerationInList(Module.EnumerationScopeList, Sym)
10288
10289 ELSE
10290 InternalError ('expecting a DefImp or Module symbol')
10291 END
10292 END
10293 END
10294 END CheckForEnumerationInCurrentModule ;
10295
10296
10297 (*
10298 CheckEnumerationInList - places symbol, Sym, in the list, l,
10299 providing it does not already exist.
10300 PseudoScope(Sym) is called if Sym needs to
10301 be added to the enumeration list, l.
10302 *)
10303
10304 PROCEDURE CheckEnumerationInList (l: List; Sym: CARDINAL) ;
10305 BEGIN
10306 IF NOT IsItemInList(l, Sym)
10307 THEN
10308 PutItemIntoList(l, Sym) ;
10309 PseudoScope(Sym)
10310 END
10311 END CheckEnumerationInList ;
10312
10313
10314 (*
10315 CheckIfEnumerationExported - An outer module may use an enumeration that
10316 is declared inside an inner module. The usage
10317 may occur before definition. The first pass
10318 exports a symbol, later the symbol is declared
10319 as an emumeration type. At this stage the
10320 CheckIfEnumerationExported procedure should be
10321 called. This procedure ripples from the current
10322 (inner) module to outer module and every time
10323 it is exported it must be added to the outer
10324 module EnumerationScopeList.
10325 *)
10326
10327 PROCEDURE CheckIfEnumerationExported (Sym: CARDINAL; ScopeId: CARDINAL) ;
10328 VAR
10329 pCall : PtrToCallFrame ;
10330 InnerModId,
10331 OuterModId : CARDINAL ;
10332 InnerModSym,
10333 OuterModSym: CARDINAL ;
10334 BEGIN
10335 InnerModId := GetModuleScopeId(ScopeId) ;
10336 IF InnerModId>0
10337 THEN
10338 OuterModId := GetModuleScopeId(InnerModId-1) ;
10339 IF OuterModId>0
10340 THEN
10341 pCall := GetPcall(InnerModId) ;
10342 InnerModSym := pCall^.Search ;
10343 pCall := GetPcall(OuterModId) ;
10344 OuterModSym := pCall^.Search ;
10345 IF (InnerModSym#NulSym) AND (OuterModSym#NulSym)
10346 THEN
10347 IF IsExported(InnerModSym, Sym)
10348 THEN
10349 CheckForEnumerationInOuterModule(Sym, OuterModSym) ;
10350 CheckIfEnumerationExported(Sym, OuterModId)
10351 END
10352 END
10353 END
10354 END
10355 END CheckIfEnumerationExported ;
10356
10357
10358 (*
10359 CheckForEnumerationInOuterModule - checks to see whether the enumeration
10360 type symbol, Sym, has been entered into
10361 the outer module, OuterModule, scope list.
10362 OuterModule may be internal to the
10363 program module.
10364 *)
10365
10366 PROCEDURE CheckForEnumerationInOuterModule (Sym: CARDINAL;
10367 OuterModule: CARDINAL) ;
10368 VAR
10369 pSym: PtrToSymbol ;
10370 BEGIN
10371 pSym := GetPsym(OuterModule) ;
10372 WITH pSym^ DO
10373 CASE SymbolType OF
10374
10375 DefImpSym: IncludeItemIntoList(DefImp.EnumerationScopeList, Sym) |
10376 ModuleSym: IncludeItemIntoList(Module.EnumerationScopeList, Sym)
10377
10378 ELSE
10379 InternalError ('expecting a DefImp or Module symbol')
10380 END
10381 END
10382 END CheckForEnumerationInOuterModule ;
10383
10384
10385 (*
10386 IsExported - returns true if a symbol, Sym, is exported
10387 from module, ModSym.
10388 If ModSym is a DefImp symbol then its
10389 ExportQualified and ExportUnQualified lists are examined.
10390 *)
10391
10392 PROCEDURE IsExported (ModSym: CARDINAL; Sym: CARDINAL) : BOOLEAN ;
10393 VAR
10394 pSym : PtrToSymbol ;
10395 SymName: Name ;
10396 BEGIN
10397 SymName := GetSymName(Sym) ;
10398 pSym := GetPsym(ModSym) ;
10399 WITH pSym^ DO
10400 CASE SymbolType OF
10401
10402 DefImpSym: WITH DefImp DO
10403 RETURN(
10404 (GetSymKey(ExportQualifiedTree, SymName)=Sym) OR
10405 (GetSymKey(ExportUnQualifiedTree, SymName)=Sym)
10406 )
10407 END |
10408 ModuleSym: WITH Module DO
10409 RETURN( GetSymKey(ExportTree, SymName)=Sym )
10410 END
10411
10412 ELSE
10413 InternalError ('expecting a DefImp or Module symbol')
10414 END
10415 END
10416 END IsExported ;
10417
10418
10419 (*
10420 IsImported - returns true if a symbol, Sym, in module, ModSym,
10421 was imported.
10422 *)
10423
10424 PROCEDURE IsImported (ModSym: CARDINAL; Sym: CARDINAL) : BOOLEAN ;
10425 VAR
10426 pSym : PtrToSymbol ;
10427 SymName: Name ;
10428 BEGIN
10429 SymName := GetSymName(Sym) ;
10430 pSym := GetPsym(ModSym) ;
10431 WITH pSym^ DO
10432 CASE SymbolType OF
10433
10434 DefImpSym: WITH DefImp DO
10435 RETURN(
10436 (GetSymKey(ImportTree, SymName)=Sym) OR
10437 IsItemInList(IncludeList, Sym)
10438 )
10439 END |
10440 ModuleSym: WITH Module DO
10441 RETURN(
10442 (GetSymKey(ImportTree, SymName)=Sym) OR
10443 IsItemInList(IncludeList, Sym)
10444 )
10445 END
10446
10447 ELSE
10448 InternalError ('expecting a DefImp or Module symbol')
10449 END
10450 END
10451 END IsImported ;
10452
10453
10454 (*
10455 IsType - returns true if the Sym is a type symbol.
10456 *)
10457
10458 PROCEDURE IsType (Sym: CARDINAL) : BOOLEAN ;
10459 VAR
10460 pSym: PtrToSymbol ;
10461 BEGIN
10462 pSym := GetPsym(Sym) ;
10463 RETURN( pSym^.SymbolType=TypeSym )
10464 END IsType ;
10465
10466
10467 (*
10468 IsReturnOptional - returns TRUE if the return value for, sym, is
10469 optional.
10470 *)
10471
10472 PROCEDURE IsReturnOptional (sym: CARDINAL; kind: ProcedureKind) : BOOLEAN ;
10473 VAR
10474 pSym: PtrToSymbol ;
10475 BEGIN
10476 pSym := GetPsym(sym) ;
10477 WITH pSym^ DO
10478 CASE SymbolType OF
10479
10480 ProcedureSym: RETURN( Procedure.Decl[kind].ReturnOptional ) |
10481 ProcTypeSym : RETURN( ProcType.ReturnOptional )
10482
10483 ELSE
10484 InternalError ('expecting a Procedure or ProcType symbol')
10485 END
10486 END
10487 END IsReturnOptional ;
10488
10489
10490 (*
10491 SetReturnOptional - sets the ReturnOptional field in the Procedure:kind or
10492 ProcType symboltable entry.
10493 *)
10494
10495 PROCEDURE SetReturnOptional (sym: CARDINAL; kind: ProcedureKind;
10496 isopt: BOOLEAN) ;
10497 VAR
10498 pSym: PtrToSymbol ;
10499 BEGIN
10500 pSym := GetPsym(sym) ;
10501 WITH pSym^ DO
10502 CASE SymbolType OF
10503
10504 ProcedureSym: Procedure.Decl[kind].ReturnOptional := isopt |
10505 ProcTypeSym : ProcType.ReturnOptional := isopt
10506
10507 ELSE
10508 InternalError ('expecting a Procedure or ProcType symbol')
10509 END
10510 END
10511 END SetReturnOptional ;
10512
10513
10514 (*
10515 IsReturnOptionalAny - returns TRUE if the return value for sym is
10516 optional.
10517 *)
10518
10519 PROCEDURE IsReturnOptionalAny (sym: CARDINAL) : BOOLEAN ;
10520 VAR
10521 pSym: PtrToSymbol ;
10522 BEGIN
10523 pSym := GetPsym(sym) ;
10524 WITH pSym^ DO
10525 CASE SymbolType OF
10526
10527 ProcedureSym: RETURN IsProcedureAnyBoolean (sym, IsReturnOptional) |
10528 ProcTypeSym : RETURN ProcType.ReturnOptional
10529
10530 ELSE
10531 InternalError ('expecting a Procedure or ProcType symbol')
10532 END
10533 END
10534 END IsReturnOptionalAny ;
10535
10536
10537 (*
10538 PutFunction - Places a TypeSym as the return type to a procedure Sym.
10539 *)
10540
10541 PROCEDURE PutFunction (tok: CARDINAL; Sym: CARDINAL; kind: ProcedureKind;
10542 TypeSym: CARDINAL) ;
10543 VAR
10544 pSym: PtrToSymbol ;
10545 BEGIN
10546 pSym := GetPsym(Sym) ;
10547 WITH pSym^ DO
10548 CASE SymbolType OF
10549
10550 ErrorSym: |
10551 ProcedureSym: Procedure.ReturnType := TypeSym ;
10552 Procedure.Decl[kind].ReturnTypeTok := tok ;
10553 PutFunction (tok, Procedure.ProcedureType, kind, TypeSym) |
10554 ProcTypeSym : ProcType.ReturnType := TypeSym ;
10555 ProcType.ReturnTypeTok := tok ;
10556
10557 ELSE
10558 InternalError ('expecting a Procedure or ProcType symbol')
10559 END
10560 END
10561 END PutFunction ;
10562
10563
10564 (*
10565 PutOptFunction - places a TypeSym as the optional return type to a procedure Sym.
10566 *)
10567
10568 PROCEDURE PutOptFunction (tok: CARDINAL; Sym: CARDINAL; kind: ProcedureKind; TypeSym: CARDINAL) ;
10569 VAR
10570 pSym: PtrToSymbol ;
10571 BEGIN
10572 pSym := GetPsym (Sym) ;
10573 WITH pSym^ DO
10574 CASE SymbolType OF
10575
10576 ErrorSym: |
10577 ProcedureSym: Procedure.ReturnType := TypeSym ;
10578 Procedure.Decl[kind].ReturnOptional := TRUE ;
10579 Procedure.Decl[kind].ReturnTypeTok := tok ;
10580 PutOptFunction (tok, Procedure.ProcedureType, kind, TypeSym) |
10581 ProcTypeSym : ProcType.ReturnType := TypeSym ;
10582 ProcType.ReturnTypeTok := tok ;
10583
10584 ELSE
10585 InternalError ('expecting a Procedure or ProcType symbol')
10586 END
10587 END
10588 END PutOptFunction ;
10589
10590
10591 (*
10592 MakeVariableForParam -
10593 *)
10594
10595 PROCEDURE MakeVariableForParam (tok : CARDINAL;
10596 ParamName: Name;
10597 ProcSym : CARDINAL;
10598 kind : ProcedureKind;
10599 no : CARDINAL;
10600 ParmType : CARDINAL;
10601 typetok : CARDINAL) : CARDINAL ;
10602 VAR
10603 pSym : PtrToSymbol ;
10604 VariableSym: CARDINAL ;
10605 BEGIN
10606 tok := CheckTok (tok, 'parameter') ;
10607 VariableSym := MakeVar (tok, ParamName) ;
10608 pSym := GetPsym (VariableSym) ;
10609 WITH pSym^ DO
10610 CASE SymbolType OF
10611
10612 ErrorSym: RETURN( NulSym ) |
10613 VarSym : Var.IsParam := TRUE (* Variable is really a parameter. *)
10614
10615 ELSE
10616 InternalError ('expecting a Var symbol')
10617 END
10618 END ;
10619 (* Note that the parameter is now treated as a local variable. *)
10620 PutVarTok (VariableSym, ParmType, typetok) ;
10621 PutDeclared (tok, VariableSym) ;
10622 (*
10623 Normal VAR parameters have LeftValue,
10624 however Unbounded VAR parameters have RightValue.
10625 Non VAR parameters always have RightValue.
10626 *)
10627 IF IsVarParam (ProcSym, kind, no) AND (NOT IsUnboundedParam (ProcSym, kind, no))
10628 THEN
10629 PutMode (VariableSym, LeftValue)
10630 ELSE
10631 PutMode (VariableSym, RightValue)
10632 END ;
10633 RETURN( VariableSym )
10634 END MakeVariableForParam ;
10635
10636
10637 (*
10638 PutParam - Places a Non VAR parameter ParamName with type ParamType into
10639 procedure Sym:kind. The parameter number is ParamNo.
10640 If the procedure Sym already has this parameter then
10641 the parameter is checked for consistancy and the
10642 consistancy test is returned.
10643 *)
10644
10645 PROCEDURE PutParam (tok: CARDINAL; Sym: CARDINAL;
10646 kind: ProcedureKind; ParamNo: CARDINAL;
10647 ParamName: Name; ParamType: CARDINAL;
10648 isUnbounded: BOOLEAN; typetok: CARDINAL) : BOOLEAN ;
10649 VAR
10650 pSym : PtrToSymbol ;
10651 ParSym : CARDINAL ;
10652 VariableSym: CARDINAL ;
10653 BEGIN
10654 IF GetProcedureParametersDefined (Sym, kind)
10655 THEN
10656 (* ParamNo <= NoOfParamAny (Sym) *)
10657 InternalError ('why are we trying to put parameters again')
10658 ELSE
10659 (* Add a new parameter *)
10660 NewSym(ParSym) ;
10661 pSym := GetPsym(ParSym) ;
10662 WITH pSym^ DO
10663 SymbolType := ParamSym ;
10664 WITH Param DO
10665 name := ParamName ;
10666 Type := ParamType ;
10667 IsUnbounded := isUnbounded ;
10668 Scope := Sym ;
10669 ShadowVar := NulSym ;
10670 FullTok := MakeVirtual2Tok (tok, typetok) ;
10671 At := tok
10672 END
10673 END ;
10674 AddParameter (Sym, kind, ParSym) ;
10675 (* Only declare a parameter as a local variable if it has not been done before.
10676 It might be declared during the definition module, forward declaration or
10677 proper procedure. Name mismatches are checked in P2SymBuild.mod. *)
10678 IF (ParamName # NulName) AND (GetNth (Sym, ParamNo) = NulSym)
10679 THEN
10680 VariableSym := MakeVariableForParam (tok, ParamName, Sym, kind,
10681 ParamNo, ParamType, typetok) ;
10682 IF VariableSym=NulSym
10683 THEN
10684 RETURN( FALSE )
10685 ELSE
10686 pSym := GetPsym(ParSym) ;
10687 pSym^.Param.ShadowVar := VariableSym
10688 END
10689 END ;
10690 AddProcedureProcTypeParam (tok, Sym, ParamType, isUnbounded, FALSE)
10691 END ;
10692 RETURN( TRUE )
10693 END PutParam ;
10694
10695
10696 (*
10697 PutVarParam - Places a Non VAR parameter ParamName with type
10698 ParamType into procedure Sym:kind.
10699 The parameter number is ParamNo.
10700 If the procedure Sym already has this parameter then
10701 the parameter is checked for consistancy and the
10702 consistancy test is returned.
10703 *)
10704
10705 PROCEDURE PutVarParam (tok: CARDINAL; Sym: CARDINAL; kind: ProcedureKind;
10706 ParamNo: CARDINAL;
10707 ParamName: Name; ParamType: CARDINAL;
10708 isUnbounded: BOOLEAN; typetok: CARDINAL) : BOOLEAN ;
10709 VAR
10710 pSym : PtrToSymbol ;
10711 ParSym : CARDINAL ;
10712 VariableSym: CARDINAL ;
10713 BEGIN
10714 IF GetProcedureParametersDefined (Sym, kind)
10715 THEN
10716 InternalError ('why are we trying to put parameters again')
10717 ELSE
10718 (* Add a new parameter *)
10719 NewSym(ParSym) ;
10720 pSym := GetPsym(ParSym) ;
10721 WITH pSym^ DO
10722 SymbolType := VarParamSym ;
10723 WITH VarParam DO
10724 name := ParamName ;
10725 Type := ParamType ;
10726 IsUnbounded := isUnbounded ;
10727 Scope := Sym ;
10728 ShadowVar := NulSym ;
10729 HeapVar := NulSym ; (* Will contain a pointer value. *)
10730 FullTok := MakeVirtual2Tok (tok, typetok) ;
10731 At := tok
10732 END
10733 END ;
10734 AddParameter (Sym, kind, ParSym) ;
10735 (* Only declare a parameter as a local variable if it has not been done before.
10736 It might be declared during the definition module, forward declaration or
10737 proper procedure. Name mismatches are checked in P2SymBuild.mod. *)
10738 IF (ParamName # NulName) AND (GetNth (Sym, ParamNo) = NulSym)
10739 THEN
10740 VariableSym := MakeVariableForParam (tok, ParamName, Sym, kind,
10741 ParamNo, ParamType, typetok) ;
10742 IF VariableSym=NulSym
10743 THEN
10744 RETURN( FALSE )
10745 ELSE
10746 pSym := GetPsym(ParSym) ;
10747 pSym^.VarParam.ShadowVar := VariableSym
10748 END
10749 END ;
10750 AddProcedureProcTypeParam (tok, Sym, ParamType, isUnbounded, TRUE)
10751 END ;
10752 RETURN( TRUE )
10753 END PutVarParam ;
10754
10755
10756 (*
10757 PutParamName - assigns a name to paramater no of procedure ProcSym:kind.
10758 *)
10759
10760 PROCEDURE PutParamName (tok: CARDINAL; ProcSym: CARDINAL; kind: ProcedureKind;
10761 no: CARDINAL;
10762 name: Name; ParamType: CARDINAL; typetok: CARDINAL) ;
10763 VAR
10764 pSym : PtrToSymbol ;
10765 ParSym: CARDINAL ;
10766 BEGIN
10767 pSym := GetPsym(ProcSym) ;
10768 ParSym := NulSym ;
10769 WITH pSym^ DO
10770 CASE SymbolType OF
10771
10772 ErrorSym : RETURN |
10773 ProcedureSym: ParSym := GetItemFromList(Procedure.Decl[kind].ListOfParam,
10774 no) |
10775 ProcTypeSym : ParSym := GetItemFromList(ProcType.ListOfParam, no)
10776
10777 ELSE
10778 InternalError ('expecting a Procedure symbol')
10779 END
10780 END ;
10781 pSym := GetPsym(ParSym) ;
10782 WITH pSym^ DO
10783 CASE SymbolType OF
10784
10785 ParamSym: IF Param.name=NulName
10786 THEN
10787 Param.name := name ;
10788 Param.ShadowVar := MakeVariableForParam(tok, name, ProcSym, kind,
10789 no, ParamType, typetok)
10790 ELSE
10791 InternalError ('name of parameter has already been assigned')
10792 END |
10793 VarParamSym: IF VarParam.name=NulName
10794 THEN
10795 VarParam.name := name ;
10796 VarParam.ShadowVar := MakeVariableForParam(tok, name, ProcSym, kind,
10797 no, ParamType, typetok)
10798 ELSE
10799 InternalError ('name of parameter has already been assigned')
10800 END
10801
10802 ELSE
10803 InternalError ('expecting a VarParam or Param symbol')
10804 END
10805 END
10806 END PutParamName ;
10807
10808
10809 (*
10810 AddParameter - adds a parameter ParSym to a procedure Sym.
10811 *)
10812
10813 PROCEDURE AddParameter (Sym: CARDINAL; kind: ProcedureKind; ParSym: CARDINAL) ;
10814 VAR
10815 pSym: PtrToSymbol ;
10816 BEGIN
10817 pSym := GetPsym(Sym) ;
10818 WITH pSym^ DO
10819 CASE SymbolType OF
10820
10821 ErrorSym: |
10822 ProcedureSym: PutItemIntoList (Procedure.Decl[kind].ListOfParam, ParSym) |
10823 ProcTypeSym : PutItemIntoList (ProcType.ListOfParam, ParSym)
10824
10825 ELSE
10826 InternalError ('expecting a Procedure or ProcType symbol')
10827 END
10828 END
10829 END AddParameter ;
10830
10831
10832 (*
10833 AddProcedureProcTypeParam - adds ParamType to the parameter ProcType
10834 associated with procedure Sym.
10835 *)
10836
10837 PROCEDURE AddProcedureProcTypeParam (tok: CARDINAL;
10838 Sym, ParamType: CARDINAL;
10839 isUnbounded, isVarParam: BOOLEAN) ;
10840 VAR
10841 pSym: PtrToSymbol ;
10842 BEGIN
10843 pSym := GetPsym (Sym) ;
10844 WITH pSym^ DO
10845 CASE SymbolType OF
10846
10847 ProcedureSym: IF Procedure.BuildProcType
10848 THEN
10849 IF isVarParam
10850 THEN
10851 PutProcTypeVarParam (tok,
10852 Procedure.ProcedureType,
10853 ParamType, isUnbounded)
10854 ELSE
10855 PutProcTypeParam (tok,
10856 Procedure.ProcedureType,
10857 ParamType, isUnbounded)
10858 END
10859 END
10860
10861 ELSE
10862 InternalError ('expecting Sym to be a procedure')
10863 END
10864 END
10865 END AddProcedureProcTypeParam ;
10866
10867
10868 (*
10869 IsVarParam - Returns a conditional depending whether parameter ParamNo
10870 is a VAR parameter.
10871 *)
10872
10873 PROCEDURE IsVarParam (Sym: CARDINAL; kind: ProcedureKind;
10874 ParamNo: CARDINAL) : BOOLEAN ;
10875 VAR
10876 pSym : PtrToSymbol ;
10877 IsVar: BOOLEAN ;
10878 BEGIN
10879 IsVar := FALSE ;
10880 pSym := GetPsym(Sym) ;
10881 WITH pSym^ DO
10882 CASE SymbolType OF
10883
10884 ErrorSym : |
10885 ProcedureSym: IsVar := IsNthParamVar(Procedure.Decl[kind].ListOfParam,
10886 ParamNo) |
10887 ProcTypeSym : IsVar := IsNthParamVar(ProcType.ListOfParam, ParamNo)
10888
10889 ELSE
10890 InternalError ('expecting a Procedure or ProcType symbol')
10891 END
10892 END ;
10893 RETURN( IsVar )
10894 END IsVarParam ;
10895
10896
10897 (*
10898 IsVarParamAny - Returns a conditional depending whether parameter ParamNo
10899 is a VAR parameter.
10900 *)
10901
10902 PROCEDURE IsVarParamAny (Sym: CARDINAL; ParamNo: CARDINAL) : BOOLEAN ;
10903 VAR
10904 pSym: PtrToSymbol ;
10905 kind: ProcedureKind ;
10906 BEGIN
10907 pSym := GetPsym(Sym) ;
10908 WITH pSym^ DO
10909 CASE SymbolType OF
10910
10911 ErrorSym : |
10912 ProcedureSym: FOR kind := MIN (ProcedureKind) TO MAX (ProcedureKind) DO
10913 IF GetProcedureDefined (Sym, kind)
10914 THEN
10915 RETURN IsNthParamVar (Procedure.Decl[kind].ListOfParam,
10916 ParamNo)
10917 END
10918 END |
10919 ProcTypeSym : RETURN IsNthParamVar(ProcType.ListOfParam, ParamNo)
10920
10921 ELSE
10922 InternalError ('expecting a Procedure or ProcType symbol')
10923 END
10924 END ;
10925 RETURN FALSE
10926 END IsVarParamAny ;
10927
10928
10929 (*
10930 IsNthParamVar - returns true if the n th parameter of the parameter list,
10931 List, is a VAR parameter.
10932 *)
10933
10934 PROCEDURE IsNthParamVar (Head: List; n: CARDINAL) : BOOLEAN ;
10935 VAR
10936 pSym: PtrToSymbol ;
10937 p : CARDINAL ;
10938 BEGIN
10939 p := GetItemFromList(Head, n) ;
10940 IF p=NulSym
10941 THEN
10942 InternalError ('parameter does not exist')
10943 ELSE
10944 pSym := GetPsym(p) ;
10945 WITH pSym^ DO
10946 CASE SymbolType OF
10947
10948 ErrorSym : RETURN( FALSE ) |
10949 VarParamSym: RETURN( TRUE ) |
10950 ParamSym : RETURN( FALSE )
10951
10952 ELSE
10953 InternalError ('expecting Param or VarParam symbol')
10954 END
10955 END
10956 END
10957 END IsNthParamVar ;
10958
10959
10960 (*
10961 NoOfParam - Returns the number of parameters that procedure Sym contains.
10962 *)
10963
10964 PROCEDURE NoOfParam (Sym: CARDINAL; kind: ProcedureKind) : CARDINAL ;
10965 VAR
10966 pSym: PtrToSymbol ;
10967 n : CARDINAL ;
10968 BEGIN
10969 AssertInRange(Sym) ;
10970 pSym := GetPsym(Sym) ;
10971 WITH pSym^ DO
10972 CASE SymbolType OF
10973
10974 ErrorSym : n := 0 |
10975 ProcedureSym: n := NoOfItemsInList(Procedure.Decl[kind].ListOfParam) |
10976 ProcTypeSym : n := NoOfItemsInList(ProcType.ListOfParam)
10977
10978 ELSE
10979 InternalError ('expecting a Procedure or ProcType symbol')
10980 END
10981 END ;
10982 RETURN( n )
10983 END NoOfParam ;
10984
10985
10986 (*
10987 NoOfParamAny - return the number of parameters for sym.
10988 *)
10989
10990 PROCEDURE NoOfParamAny (sym: CARDINAL) : CARDINAL ;
10991 VAR
10992 kind: ProcedureKind ;
10993 pSym: PtrToSymbol ;
10994 BEGIN
10995 AssertInRange (sym) ;
10996 pSym := GetPsym (sym) ;
10997 WITH pSym^ DO
10998 CASE SymbolType OF
10999
11000 ErrorSym : RETURN 0 |
11001 ProcedureSym: FOR kind := MIN (ProcedureKind) TO MAX (ProcedureKind) DO
11002 IF GetProcedureParametersDefined (sym, kind)
11003 THEN
11004 RETURN NoOfParam (sym, kind)
11005 END
11006 END |
11007 ProcTypeSym : RETURN NoOfItemsInList(ProcType.ListOfParam)
11008
11009 ELSE
11010 InternalError ('expecting a Procedure or ProcType symbol')
11011 END
11012 END ;
11013 RETURN 0
11014 END NoOfParamAny ;
11015
11016
11017 (*
11018 HasVarParameters - returns TRUE if procedure, p, has any VAR parameters.
11019 *)
11020
11021 PROCEDURE HasVarParameters (p: CARDINAL) : BOOLEAN ;
11022 VAR
11023 i, n: CARDINAL ;
11024 BEGIN
11025 n := NoOfParamAny (p) ;
11026 i := 1 ;
11027 WHILE i <= n DO
11028 IF IsParameterVar (GetNthParamAny (p, i))
11029 THEN
11030 RETURN TRUE
11031 END ;
11032 INC(i)
11033 END ;
11034 RETURN FALSE
11035 END HasVarParameters ;
11036
11037
11038 (*
11039 PutUseVarArgs - tell the symbol table that this procedure, Sym,
11040 uses varargs.
11041 The procedure _must_ be declared inside a
11042 DEFINITION FOR "C"
11043
11044 *)
11045
11046 PROCEDURE PutUseVarArgs (Sym: CARDINAL) ;
11047 VAR
11048 pSym: PtrToSymbol ;
11049 BEGIN
11050 AssertInRange(Sym) ;
11051 pSym := GetPsym(Sym) ;
11052 WITH pSym^ DO
11053 CASE SymbolType OF
11054
11055 ErrorSym: |
11056 (* Currently can only declare var args in a definition module. *)
11057 ProcedureSym: Procedure.Decl[DefProcedure].HasVarArgs := TRUE |
11058 ProcTypeSym : ProcType.HasVarArgs := TRUE
11059
11060 ELSE
11061 InternalError ('expecting a Procedure or ProcType symbol')
11062 END
11063 END
11064 END PutUseVarArgs ;
11065
11066
11067 (*
11068 UsesVarArgs - returns TRUE if procedure, Sym, uses varargs.
11069 The procedure _must_ be declared inside a
11070 DEFINITION FOR "C"
11071 *)
11072
11073 PROCEDURE UsesVarArgs (Sym: CARDINAL) : BOOLEAN ;
11074 VAR
11075 pSym: PtrToSymbol ;
11076 BEGIN
11077 AssertInRange(Sym) ;
11078 pSym := GetPsym(Sym) ;
11079 WITH pSym^ DO
11080 CASE SymbolType OF
11081
11082 ErrorSym : RETURN( FALSE ) |
11083 (* Currently can only declare var args in a definition module. *)
11084 ProcedureSym: RETURN( Procedure.Decl[DefProcedure].HasVarArgs ) |
11085 ProcTypeSym : RETURN( ProcType.HasVarArgs )
11086
11087 ELSE
11088 InternalError ('expecting a Procedure or ProcType symbol')
11089 END
11090 END
11091 END UsesVarArgs ;
11092
11093
11094 (*
11095 PutUseOptArg - tell the symbol table that this procedure, Sym,
11096 uses an optarg.
11097 *)
11098
11099 PROCEDURE PutUseOptArg (Sym: CARDINAL; kind: ProcedureKind) ;
11100 VAR
11101 pSym: PtrToSymbol ;
11102 BEGIN
11103 AssertInRange(Sym) ;
11104 pSym := GetPsym(Sym) ;
11105 WITH pSym^ DO
11106 CASE SymbolType OF
11107
11108 ErrorSym: |
11109 ProcedureSym: Procedure.Decl[kind].HasOptArg := TRUE |
11110 ProcTypeSym : ProcType.HasOptArg := TRUE
11111
11112 ELSE
11113 InternalError ('expecting a Procedure or ProcType symbol')
11114 END
11115 END
11116 END PutUseOptArg ;
11117
11118
11119 (*
11120 UsesOptArg - returns TRUE if procedure, Sym, uses varargs.
11121 *)
11122
11123 PROCEDURE UsesOptArg (Sym: CARDINAL; kind: ProcedureKind) : BOOLEAN ;
11124 VAR
11125 pSym: PtrToSymbol ;
11126 BEGIN
11127 AssertInRange(Sym) ;
11128 pSym := GetPsym(Sym) ;
11129 WITH pSym^ DO
11130 CASE SymbolType OF
11131
11132 ErrorSym : RETURN FALSE |
11133 ProcedureSym: RETURN Procedure.Decl[kind].HasOptArg |
11134 ProcTypeSym : RETURN ProcType.HasOptArg
11135
11136 ELSE
11137 InternalError ('expecting a Procedure or ProcType symbol')
11138 END
11139 END
11140 END UsesOptArg ;
11141
11142
11143 (*
11144 UsesOptArgAny - returns TRUE if procedure Sym:kind uses an optional argument.
11145 *)
11146
11147 PROCEDURE UsesOptArgAny (Sym: CARDINAL) : BOOLEAN ;
11148 VAR
11149 pSym: PtrToSymbol ;
11150 BEGIN
11151 pSym := GetPsym(Sym) ;
11152 WITH pSym^ DO
11153 CASE SymbolType OF
11154
11155 ErrorSym : RETURN FALSE |
11156 ProcedureSym: RETURN IsProcedureAnyDefaultBoolean (Sym, FALSE, UsesOptArg) |
11157 ProcTypeSym : RETURN ProcType.HasOptArg
11158
11159 ELSE
11160 InternalError ('expecting a Procedure or ProcType symbol')
11161 END
11162 END
11163 END UsesOptArgAny ;
11164
11165
11166 (*
11167 PutOptArgInit - makes symbol, Sym, the initializer value to
11168 procedure, ProcSym.
11169 *)
11170
11171 PROCEDURE PutOptArgInit (ProcSym: CARDINAL; Sym: CARDINAL) ;
11172 VAR
11173 pSym: PtrToSymbol ;
11174 BEGIN
11175 AssertInRange(Sym) ;
11176 IF NOT IsError(ProcSym)
11177 THEN
11178 pSym := GetPsym(ProcSym) ;
11179 WITH pSym^ DO
11180 CASE SymbolType OF
11181
11182 ErrorSym : |
11183 ProcedureSym: Procedure.OptArgInit := Sym |
11184 ProcTypeSym : ProcType.OptArgInit := Sym
11185
11186 ELSE
11187 InternalError ('expecting a Procedure or ProcType symbol')
11188 END
11189 END
11190 END
11191 END PutOptArgInit ;
11192
11193
11194 (*
11195 GetOptArgInit - returns the initializer value to the optional parameter in
11196 procedure, ProcSym.
11197 *)
11198
11199 PROCEDURE GetOptArgInit (ProcSym: CARDINAL) : CARDINAL ;
11200 VAR
11201 pSym: PtrToSymbol ;
11202 BEGIN
11203 IF NOT IsError(ProcSym)
11204 THEN
11205 pSym := GetPsym(ProcSym) ;
11206 WITH pSym^ DO
11207 CASE SymbolType OF
11208
11209 ErrorSym : |
11210 ProcedureSym: RETURN( Procedure.OptArgInit ) |
11211 ProcTypeSym : RETURN( ProcType.OptArgInit )
11212
11213 ELSE
11214 InternalError ('expecting a Procedure or ProcType symbol')
11215 END
11216 END
11217 END ;
11218 RETURN( NulSym )
11219 END GetOptArgInit ;
11220
11221
11222 (*
11223 MakeParameterHeapVar - create a heap variable if sym is a pointer.
11224 *)
11225
11226 PROCEDURE MakeParameterHeapVar (tok: CARDINAL; type: CARDINAL; mode: ModeOfAddr) : CARDINAL ;
11227 VAR
11228 heapvar: CARDINAL ;
11229 BEGIN
11230 tok := CheckTok (tok, 'parameter heap var') ;
11231 heapvar := NulSym ;
11232 type := SkipType (type) ;
11233 IF IsPointer (type)
11234 THEN
11235 heapvar := MakeTemporary (tok, mode) ;
11236 PutVar (heapvar, type) ;
11237 PutVarHeap (heapvar, TRUE)
11238 END ;
11239 RETURN heapvar
11240 END MakeParameterHeapVar ;
11241
11242
11243 (*
11244 GetParameterHeapVar - return the heap variable associated with the
11245 parameter or NulSym.
11246 *)
11247
11248 PROCEDURE GetParameterHeapVar (ParSym: CARDINAL) : CARDINAL ;
11249 VAR
11250 pSym: PtrToSymbol ;
11251 BEGIN
11252 pSym := GetPsym (ParSym) ;
11253 WITH pSym^ DO
11254 CASE SymbolType OF
11255
11256 ParamSym : RETURN NulSym | (* Only VarParam has the pointer. *)
11257 VarParamSym: RETURN VarParam.HeapVar
11258
11259 ELSE
11260 InternalError ('expecting Param or VarParam symbol')
11261 END
11262 END
11263 END GetParameterHeapVar ;
11264
11265
11266 (*
11267 PutParameterHeapVar - creates a heap variable associated with parameter sym.
11268 *)
11269
11270 PROCEDURE PutParameterHeapVar (sym: CARDINAL) ;
11271 VAR
11272 pSym : PtrToSymbol ;
11273 BEGIN
11274 pSym := GetPsym (sym) ;
11275 WITH pSym^ DO
11276 CASE SymbolType OF
11277
11278 ParamSym : | (* Nothing to do for the non var parameter. *)
11279 VarParamSym: VarParam.HeapVar := MakeParameterHeapVar (GetDeclaredMod (sym),
11280 VarParam.Type, LeftValue)
11281
11282 ELSE
11283 InternalError ('Param or VarParam symbol expected')
11284 END
11285 END
11286 END PutParameterHeapVar ;
11287
11288
11289 (*
11290 PutProcedureParameterHeapVars - creates heap variables for parameter sym.
11291 *)
11292
11293 PROCEDURE PutProcedureParameterHeapVars (sym: CARDINAL) ;
11294 BEGIN
11295 Assert (IsProcedure (sym)) ;
11296 ForeachParamSymDo (sym, PutParameterHeapVar)
11297 END PutProcedureParameterHeapVars ;
11298
11299
11300 (*
11301 NoOfVariables - returns the number of variables in scope. The scope maybe
11302 a procedure, module or defimp scope.
11303 *)
11304
11305 PROCEDURE NoOfVariables (scope: CARDINAL) : CARDINAL ;
11306 VAR
11307 pSym: PtrToSymbol ;
11308 BEGIN
11309 IF IsProcedure (scope)
11310 THEN
11311 RETURN NoOfLocalVar (scope)
11312 ELSIF IsModule (scope)
11313 THEN
11314 pSym := GetPsym (scope) ;
11315 WITH pSym^ DO
11316 CASE SymbolType OF
11317
11318 ModuleSym: RETURN NoOfItemsInList (Module.ListOfVars)
11319
11320 ELSE
11321 InternalError ('expecting module symbol')
11322 END
11323 END
11324 ELSIF IsDefImp (scope)
11325 THEN
11326 pSym := GetPsym (scope) ;
11327 WITH pSym^ DO
11328 CASE SymbolType OF
11329
11330 DefImpSym: RETURN NoOfItemsInList (DefImp.ListOfVars)
11331
11332 ELSE
11333 InternalError ('expecting defimp symbol')
11334 END
11335 END
11336 ELSE
11337 InternalError ('expecting procedure, module or defimp symbol')
11338 END
11339 END NoOfVariables ;
11340
11341
11342 (*
11343 NoOfLocalVar - returns the number of local variables that exist in
11344 procedure Sym. Parameters are NOT included in the
11345 count.
11346 *)
11347
11348 PROCEDURE NoOfLocalVar (Sym: CARDINAL) : CARDINAL ;
11349 VAR
11350 pSym: PtrToSymbol ;
11351 n : CARDINAL ;
11352 BEGIN
11353 pSym := GetPsym(Sym) ;
11354 WITH pSym^ DO
11355 CASE SymbolType OF
11356
11357 ErrorSym : n := 0 |
11358 ProcedureSym: n := NoOfItemsInList(Procedure.ListOfVars)
11359
11360 ELSE
11361 InternalError ('expecting a Procedure symbol')
11362 END
11363 END ;
11364 (*
11365 Parameters are actually included in the list of local varaibles,
11366 therefore we must subtract the Parameter Number from local variable
11367 total.
11368 *)
11369 RETURN( n - NoOfParamAny (Sym) )
11370 END NoOfLocalVar ;
11371
11372
11373 (*
11374 IsParameterVar - returns true if parameter symbol Sym
11375 was declared as a VAR.
11376 *)
11377
11378 PROCEDURE IsParameterVar (Sym: CARDINAL) : BOOLEAN ;
11379 VAR
11380 pSym: PtrToSymbol ;
11381 BEGIN
11382 pSym := GetPsym(Sym) ;
11383 WITH pSym^ DO
11384 CASE SymbolType OF
11385
11386 ParamSym : RETURN( FALSE ) |
11387 VarParamSym: RETURN( TRUE )
11388
11389 ELSE
11390 InternalError ('expecting Param or VarParam symbol')
11391 END
11392 END
11393 END IsParameterVar ;
11394
11395
11396 (*
11397 IsParameterUnbounded - returns TRUE if parameter, Sym, is
11398 unbounded.
11399 *)
11400
11401 PROCEDURE IsParameterUnbounded (Sym: CARDINAL) : BOOLEAN ;
11402 VAR
11403 pSym: PtrToSymbol ;
11404 BEGIN
11405 pSym := GetPsym(Sym) ;
11406 WITH pSym^ DO
11407 CASE SymbolType OF
11408
11409 ParamSym : RETURN( Param.IsUnbounded ) |
11410 VarParamSym: RETURN( VarParam.IsUnbounded )
11411
11412 ELSE
11413 InternalError ('expecting Param or VarParam symbol')
11414 END
11415 END
11416 END IsParameterUnbounded ;
11417
11418
11419 (*
11420 IsUnboundedParam - Returns a conditional depending whether parameter
11421 ParamNo is an unbounded array procedure parameter.
11422 *)
11423
11424 PROCEDURE IsUnboundedParam (Sym: CARDINAL; kind: ProcedureKind;
11425 ParamNo: CARDINAL) : BOOLEAN ;
11426 VAR
11427 param: CARDINAL ;
11428 BEGIN
11429 param := GetNthParam (Sym, kind, ParamNo) ;
11430 RETURN IsParameterUnbounded (param)
11431 END IsUnboundedParam ;
11432
11433
11434 (*
11435 IsUnboundedParam - Returns a conditional depending whether parameter
11436 ParamNo is an unbounded array procedure parameter.
11437 *)
11438
11439 PROCEDURE IsUnboundedParamAny (Sym: CARDINAL; ParamNo: CARDINAL) : BOOLEAN ;
11440 VAR
11441 kind: ProcedureKind ;
11442 BEGIN
11443 FOR kind := MIN (ProcedureKind) TO MAX (ProcedureKind) DO
11444 IF GetProcedureParametersDefined (Sym, kind)
11445 THEN
11446 RETURN IsUnboundedParam (Sym, kind, ParamNo)
11447 END
11448 END ;
11449 InternalError ('no procedure kind exists')
11450 END IsUnboundedParamAny ;
11451
11452
11453 (*
11454 IsParameter - returns true if Sym is a parameter symbol.
11455 *)
11456
11457 PROCEDURE IsParameter (Sym: CARDINAL) : BOOLEAN ;
11458 VAR
11459 pSym: PtrToSymbol ;
11460 BEGIN
11461 pSym := GetPsym(Sym) ;
11462 WITH pSym^ DO
11463 CASE SymbolType OF
11464
11465 ParamSym,
11466 VarParamSym: RETURN( TRUE )
11467
11468 ELSE
11469 RETURN( FALSE )
11470 END
11471 END
11472 END IsParameter ;
11473
11474
11475 (*
11476 GetParameterShadowVar - returns the local variable associated with the
11477 parameter symbol, sym.
11478 *)
11479
11480 PROCEDURE GetParameterShadowVar (sym: CARDINAL) : CARDINAL ;
11481 VAR
11482 pSym: PtrToSymbol ;
11483 BEGIN
11484 pSym := GetPsym(sym) ;
11485 WITH pSym^ DO
11486 CASE SymbolType OF
11487
11488 ParamSym : RETURN( Param.ShadowVar ) |
11489 VarParamSym: RETURN( VarParam.ShadowVar )
11490
11491 ELSE
11492 InternalError ('expecting a ParamSym or VarParamSym')
11493 END
11494 END
11495 END GetParameterShadowVar ;
11496
11497
11498 (*
11499 IsProcedure - returns true if Sym is a procedure symbol.
11500 *)
11501
11502 PROCEDURE IsProcedure (Sym: CARDINAL) : BOOLEAN ;
11503 VAR
11504 pSym: PtrToSymbol ;
11505 BEGIN
11506 AssertInRange(Sym) ;
11507 pSym := GetPsym(Sym) ;
11508 RETURN( pSym^.SymbolType=ProcedureSym )
11509 END IsProcedure ;
11510
11511
11512 (*
11513 PutProcedureParametersDefined - the procedure symbol sym:kind
11514 parameters have been defined.
11515 *)
11516
11517 PROCEDURE PutProcedureParametersDefined (sym: CARDINAL; kind: ProcedureKind) ;
11518 VAR
11519 pSym: PtrToSymbol ;
11520 BEGIN
11521 AssertInRange (sym) ;
11522 pSym := GetPsym (sym) ;
11523 WITH pSym^ DO
11524 CASE SymbolType OF
11525
11526 ErrorSym : |
11527 ProcedureSym: Procedure.Decl[kind].ParamDefined := TRUE ;
11528 Procedure.BuildProcType := FALSE |
11529 ProcTypeSym :
11530
11531 ELSE
11532 InternalError ('expecting a Procedure symbol')
11533 END
11534 END
11535 END PutProcedureParametersDefined ;
11536
11537
11538 (*
11539 GetProcedureParametersDefined - returns true if procedure symbol sym:kind
11540 parameters are defined.
11541 *)
11542
11543 PROCEDURE GetProcedureParametersDefined (sym: CARDINAL; kind: ProcedureKind) : BOOLEAN ;
11544 VAR
11545 pSym: PtrToSymbol ;
11546 BEGIN
11547 AssertInRange (sym) ;
11548 pSym := GetPsym (sym) ;
11549 WITH pSym^ DO
11550 CASE SymbolType OF
11551
11552 ErrorSym : RETURN( FALSE ) |
11553 ProcedureSym: RETURN( Procedure.Decl[kind].ParamDefined ) |
11554 ProcTypeSym : RETURN( TRUE )
11555
11556 ELSE
11557 InternalError ('expecting a Procedure symbol')
11558 END
11559 END
11560 END GetProcedureParametersDefined ;
11561
11562
11563 (*
11564 PutProcedureDefined - the procedure symbol sym:kind is defined.
11565 *)
11566
11567 PROCEDURE PutProcedureDefined (sym: CARDINAL; kind: ProcedureKind) ;
11568 VAR
11569 pSym: PtrToSymbol ;
11570 BEGIN
11571 AssertInRange (sym) ;
11572 pSym := GetPsym (sym) ;
11573 WITH pSym^ DO
11574 CASE SymbolType OF
11575
11576 ErrorSym : |
11577 ProcedureSym: Procedure.Decl[kind].Defined := TRUE
11578
11579 ELSE
11580 InternalError ('expecting a Procedure symbol')
11581 END
11582 END
11583 END PutProcedureDefined ;
11584
11585
11586 (*
11587 GetProcedureDefined - returns true if procedure symbol sym:kind
11588 is defined.
11589 *)
11590
11591 PROCEDURE GetProcedureDefined (sym: CARDINAL; kind: ProcedureKind) : BOOLEAN ;
11592 VAR
11593 pSym: PtrToSymbol ;
11594 BEGIN
11595 AssertInRange (sym) ;
11596 pSym := GetPsym (sym) ;
11597 WITH pSym^ DO
11598 CASE SymbolType OF
11599
11600 ErrorSym : RETURN( FALSE ) |
11601 ProcedureSym: RETURN( Procedure.Decl[kind].Defined )
11602
11603 ELSE
11604 InternalError ('expecting a Procedure symbol')
11605 END
11606 END
11607 END GetProcedureDefined ;
11608
11609
11610 (*
11611 IsProcedureAnyBoolean - returns the boolean result from p
11612 for any of procedure kind which is defined.
11613 *)
11614
11615 PROCEDURE IsProcedureAnyBoolean (sym: CARDINAL; p: ProcAnyBoolean) : BOOLEAN ;
11616 VAR
11617 kind: ProcedureKind ;
11618 BEGIN
11619 FOR kind := MIN (ProcedureKind) TO MAX (ProcedureKind) DO
11620 IF GetProcedureDefined (sym, kind)
11621 THEN
11622 RETURN p (sym, kind)
11623 END
11624 END ;
11625 InternalError ('no procedure kind exists')
11626 END IsProcedureAnyBoolean ;
11627
11628
11629 (*
11630 IsProcedureAnyDefaultBoolean - returns the boolean result from p
11631 for any of procedure kind which is defined.
11632 *)
11633
11634 PROCEDURE IsProcedureAnyDefaultBoolean (sym: CARDINAL; default: BOOLEAN; p: ProcAnyBoolean) : BOOLEAN ;
11635 VAR
11636 kind: ProcedureKind ;
11637 BEGIN
11638 FOR kind := MIN (ProcedureKind) TO MAX (ProcedureKind) DO
11639 IF GetProcedureDefined (sym, kind)
11640 THEN
11641 RETURN p (sym, kind)
11642 END
11643 END ;
11644 RETURN default
11645 END IsProcedureAnyDefaultBoolean ;
11646
11647
11648 (*
11649 IsProcedureAnyNoReturn - return TRUE if any of the defined kinds
11650 of procedure sym is declared no return.
11651 *)
11652
11653 PROCEDURE IsProcedureAnyNoReturn (sym: CARDINAL) : BOOLEAN ;
11654 BEGIN
11655 RETURN IsProcedureAnyDefaultBoolean (sym, FALSE, IsProcedureNoReturn)
11656 END IsProcedureAnyNoReturn ;
11657
11658
11659 (*
11660 FillInUnknownFields -
11661 *)
11662
11663 PROCEDURE FillInUnknownFields (tok: CARDINAL; sym: CARDINAL; SymName: Name) ;
11664 VAR
11665 pSym: PtrToSymbol ;
11666 BEGIN
11667 pSym := GetPsym(sym) ;
11668 WITH pSym^ DO
11669 SymbolType := UndefinedSym ;
11670 WITH Undefined DO
11671 name := SymName ;
11672 oafamily := NulSym ;
11673 errorScope := GetCurrentErrorScope () ;
11674 InitWhereFirstUsedTok (tok, At)
11675 END
11676 END
11677 END FillInUnknownFields ;
11678
11679
11680 (*
11681 FillInPointerFields - given a new symbol, sym, make it a pointer symbol
11682 and initialize its fields.
11683 *)
11684
11685 PROCEDURE FillInPointerFields (Sym: CARDINAL; PointerName: Name;
11686 scope: CARDINAL; oaf: CARDINAL) ;
11687 VAR
11688 pSym: PtrToSymbol ;
11689 BEGIN
11690 IF NOT IsError(Sym)
11691 THEN
11692 pSym := GetPsym(Sym) ;
11693 WITH pSym^ DO
11694 SymbolType := PointerSym ;
11695 CASE SymbolType OF
11696
11697 PointerSym: Pointer.Type := NulSym ;
11698 Pointer.name := PointerName ;
11699 Pointer.oafamily := oaf ; (* The unbounded for this *)
11700 InitTree(Pointer.ConstLitTree) ; (* constants of this type *)
11701 Pointer.Scope := scope ; (* Which scope created it *)
11702 Pointer.Size := InitValue() ;
11703 Pointer.Align := NulSym ; (* Alignment of this type *)
11704
11705 ELSE
11706 InternalError ('expecting a Pointer symbol')
11707 END
11708 END
11709 END
11710 END FillInPointerFields ;
11711
11712
11713 (*
11714 MakePointer - returns a pointer symbol with PointerName.
11715 *)
11716
11717 PROCEDURE MakePointer (tok: CARDINAL; PointerName: Name) : CARDINAL ;
11718 VAR
11719 oaf, sym: CARDINAL ;
11720 BEGIN
11721 tok := CheckTok (tok, 'pointer') ;
11722 sym := HandleHiddenOrDeclare(tok, PointerName, oaf) ;
11723 FillInPointerFields(sym, PointerName, GetCurrentScope(), oaf) ;
11724 ForeachOAFamily(oaf, doFillInOAFamily) ;
11725 RETURN( sym )
11726 END MakePointer ;
11727
11728
11729 (*
11730 PutPointer - gives a pointer symbol a type, PointerType.
11731 *)
11732
11733 PROCEDURE PutPointer (Sym: CARDINAL; PointerType: CARDINAL) ;
11734 VAR
11735 pSym: PtrToSymbol ;
11736 BEGIN
11737 pSym := GetPsym(Sym) ;
11738 WITH pSym^ DO
11739 CASE SymbolType OF
11740
11741 ErrorSym : |
11742 PointerSym: Pointer.Type := PointerType
11743
11744 ELSE
11745 InternalError ('expecting a Pointer symbol')
11746 END
11747 END
11748 END PutPointer ;
11749
11750
11751 (*
11752 IsPointer - returns true is Sym is a pointer type symbol.
11753 *)
11754
11755 PROCEDURE IsPointer (Sym: CARDINAL) : BOOLEAN ;
11756 VAR
11757 pSym: PtrToSymbol ;
11758 BEGIN
11759 AssertInRange(Sym) ;
11760 pSym := GetPsym(Sym) ;
11761 RETURN( pSym^.SymbolType=PointerSym )
11762 END IsPointer ;
11763
11764
11765 (*
11766 IsRecord - returns true is Sym is a record type symbol.
11767 *)
11768
11769 PROCEDURE IsRecord (Sym: CARDINAL) : BOOLEAN ;
11770 VAR
11771 pSym: PtrToSymbol ;
11772 BEGIN
11773 AssertInRange(Sym) ;
11774 pSym := GetPsym(Sym) ;
11775 RETURN( pSym^.SymbolType=RecordSym )
11776 END IsRecord ;
11777
11778
11779 (*
11780 IsArray - returns true is Sym is an array type symbol.
11781 *)
11782
11783 PROCEDURE IsArray (Sym: CARDINAL) : BOOLEAN ;
11784 VAR
11785 pSym: PtrToSymbol ;
11786 BEGIN
11787 AssertInRange(Sym) ;
11788 pSym := GetPsym(Sym) ;
11789 RETURN( pSym^.SymbolType=ArraySym )
11790 END IsArray ;
11791
11792
11793 (*
11794 IsEnumeration - returns true if Sym is an enumeration symbol.
11795 *)
11796
11797 PROCEDURE IsEnumeration (Sym: CARDINAL) : BOOLEAN ;
11798 VAR
11799 pSym: PtrToSymbol ;
11800 BEGIN
11801 AssertInRange(Sym) ;
11802 pSym := GetPsym(Sym) ;
11803 RETURN( pSym^.SymbolType=EnumerationSym )
11804 END IsEnumeration ;
11805
11806
11807 (*
11808 IsUnbounded - returns true if Sym is an unbounded symbol.
11809 *)
11810
11811 PROCEDURE IsUnbounded (Sym: CARDINAL) : BOOLEAN ;
11812 VAR
11813 pSym: PtrToSymbol ;
11814 BEGIN
11815 AssertInRange(Sym) ;
11816 pSym := GetPsym(Sym) ;
11817 RETURN( pSym^.SymbolType=UnboundedSym )
11818 END IsUnbounded ;
11819
11820
11821 (*
11822 GetVarScope - returns the symbol which is the scope of variable Sym.
11823 ie a Module, DefImp or Procedure Symbol.
11824 *)
11825
11826 PROCEDURE GetVarScope (Sym: CARDINAL) : CARDINAL ;
11827 VAR
11828 pSym: PtrToSymbol ;
11829 BEGIN
11830 pSym := GetPsym(Sym) ;
11831 WITH pSym^ DO
11832 CASE SymbolType OF
11833
11834 ErrorSym: RETURN( NulSym ) |
11835 VarSym : RETURN( Var.Scope )
11836
11837 ELSE
11838 InternalError ('expecting a Var symbol')
11839 END
11840 END
11841 END GetVarScope ;
11842
11843
11844 (*
11845 NoOfElements - Returns the number of elements in array Sym,
11846 or the number of elements in an enumeration Sym or
11847 the number of interface symbols in an Interface list.
11848 *)
11849
11850 PROCEDURE NoOfElements (Sym: CARDINAL) : CARDINAL ;
11851 VAR
11852 pSym: PtrToSymbol ;
11853 n : CARDINAL ;
11854 BEGIN
11855 pSym := GetPsym(Sym) ;
11856 WITH pSym^ DO
11857 CASE SymbolType OF
11858
11859 ErrorSym : n := 0 |
11860 (*
11861 ArraySym ,
11862 UnboundedSym : n := 1 | (* Standard language limitation *)
11863 *)
11864 EnumerationSym: n := pSym^.Enumeration.NoOfElements |
11865 InterfaceSym : n := HighIndice(Interface.Parameters)
11866
11867 ELSE
11868 InternalError ('expecting an Array or UnBounded symbol')
11869 END
11870 END ;
11871 RETURN( n )
11872 END NoOfElements ;
11873
11874
11875 (*
11876 PutArraySubscript - places an index field into the array Sym. The
11877 index field is a subscript sym.
11878 *)
11879
11880 PROCEDURE PutArraySubscript (Sym: CARDINAL; SubscriptSymbol: CARDINAL) ;
11881 VAR
11882 pSym: PtrToSymbol ;
11883 BEGIN
11884 pSym := GetPsym(Sym) ;
11885 WITH pSym^ DO
11886 CASE SymbolType OF
11887
11888 ErrorSym: |
11889 ArraySym: Array.Subscript := SubscriptSymbol
11890
11891 ELSE
11892 InternalError ('expecting an Array symbol')
11893 END
11894 END
11895 END PutArraySubscript ;
11896
11897
11898 (*
11899 GetArraySubscript - returns the subscript symbol for array, Sym.
11900 *)
11901
11902 PROCEDURE GetArraySubscript (Sym: CARDINAL) : CARDINAL ;
11903 VAR
11904 pSym: PtrToSymbol ;
11905 BEGIN
11906 pSym := GetPsym(Sym) ;
11907 WITH pSym^ DO
11908 CASE SymbolType OF
11909
11910 ErrorSym: RETURN( NulSym ) |
11911 ArraySym: RETURN( Array.Subscript )
11912
11913 ELSE
11914 InternalError ('expecting an Array symbol')
11915 END
11916 END
11917 END GetArraySubscript ;
11918
11919
11920 (*
11921 MakeSubscript - makes a subscript Symbol.
11922 No name is required.
11923 *)
11924
11925 PROCEDURE MakeSubscript () : CARDINAL ;
11926 VAR
11927 pSym: PtrToSymbol ;
11928 Sym : CARDINAL ;
11929 BEGIN
11930 NewSym(Sym) ;
11931 pSym := GetPsym(Sym) ;
11932 WITH pSym^ DO
11933 SymbolType := SubscriptSym ;
11934 WITH Subscript DO
11935 Type := NulSym ; (* Index to a subrange symbol. *)
11936 Size := InitValue() ; (* Size of this indice in*Size *)
11937 Offset := InitValue() ; (* Offset at runtime of symbol *)
11938 (* Pseudo ie: Offset+Size*i *)
11939 (* 1..n. The array offset is *)
11940 (* the real memory offset. *)
11941 (* This offset allows the a[i] *)
11942 (* to be calculated without *)
11943 (* the need to perform *)
11944 (* subtractions when a[4..10] *)
11945 (* needs to be indexed. *)
11946 InitWhereDeclared(At) (* Declared here *)
11947 END
11948 END ;
11949 RETURN( Sym )
11950 END MakeSubscript ;
11951
11952
11953 (*
11954 PutSubscript - gives a subscript symbol a type, SimpleType.
11955 *)
11956
11957 PROCEDURE PutSubscript (Sym: CARDINAL; SimpleType: CARDINAL) ;
11958 VAR
11959 pSym: PtrToSymbol ;
11960 BEGIN
11961 pSym := GetPsym(Sym) ;
11962 WITH pSym^ DO
11963 CASE SymbolType OF
11964
11965 ErrorSym: |
11966 SubscriptSym: Subscript.Type := SimpleType ;
11967
11968 ELSE
11969 InternalError ('expecting a SubScript symbol')
11970 END
11971 END
11972 END PutSubscript ;
11973
11974
11975 (*
11976 MakeSet - makes a set Symbol with name, SetName.
11977 *)
11978
11979 PROCEDURE MakeSet (tok: CARDINAL; SetName: Name) : CARDINAL ;
11980 VAR
11981 pSym : PtrToSymbol ;
11982 oaf, sym: CARDINAL ;
11983 BEGIN
11984 tok := CheckTok (tok, 'set') ;
11985 sym := HandleHiddenOrDeclare(tok, SetName, oaf) ;
11986 IF NOT IsError(sym)
11987 THEN
11988 pSym := GetPsym(sym) ;
11989 WITH pSym^ DO
11990 SymbolType := SetSym ;
11991 WITH Set DO
11992 name := SetName ; (* The name of the set. *)
11993 Type := NulSym ; (* Index to a subrange symbol. *)
11994 Size := InitValue() ; (* Size of this set *)
11995 InitPacked(packedInfo) ; (* not packed and no *)
11996 (* equivalent (yet). *)
11997 ispacked := FALSE ; (* Not yet known to be packed. *)
11998 oafamily := oaf ; (* The unbounded sym for this *)
11999 Scope := GetCurrentScope() ; (* Which scope created it *)
12000 InitWhereDeclaredTok(tok, At) (* Declared here *)
12001 END
12002 END
12003 END ;
12004 ForeachOAFamily(oaf, doFillInOAFamily) ;
12005 RETURN( sym )
12006 END MakeSet ;
12007
12008
12009 (*
12010 PutSet - places SimpleType as the type for set, Sym.
12011 *)
12012
12013 PROCEDURE PutSet (Sym: CARDINAL; SimpleType: CARDINAL; packed: BOOLEAN) ;
12014 VAR
12015 pSym: PtrToSymbol ;
12016 BEGIN
12017 pSym := GetPsym(Sym) ;
12018 WITH pSym^ DO
12019 CASE SymbolType OF
12020
12021 ErrorSym: |
12022 SetSym: WITH Set DO
12023 Type := SimpleType ; (* Index to a subrange symbol *)
12024 (* or an enumeration type. *)
12025 ispacked := packed
12026 END
12027 ELSE
12028 InternalError ('expecting a Set symbol')
12029 END
12030 END
12031 END PutSet ;
12032
12033
12034 (*
12035 IsSet - returns TRUE if Sym is a set symbol.
12036 *)
12037
12038 PROCEDURE IsSet (Sym: CARDINAL) : BOOLEAN ;
12039 VAR
12040 pSym: PtrToSymbol ;
12041 BEGIN
12042 AssertInRange(Sym) ;
12043 pSym := GetPsym(Sym) ;
12044 RETURN( pSym^.SymbolType=SetSym )
12045 END IsSet ;
12046
12047
12048 (*
12049 IsSetPacked - returns TRUE if Sym is packed.
12050 *)
12051
12052 PROCEDURE IsSetPacked (Sym: CARDINAL) : BOOLEAN ;
12053 VAR
12054 pSym: PtrToSymbol ;
12055 BEGIN
12056 AssertInRange (Sym) ;
12057 pSym := GetPsym (Sym) ;
12058 RETURN (pSym^.SymbolType=SetSym) AND pSym^.Set.ispacked
12059 END IsSetPacked ;
12060
12061
12062 (*
12063 ForeachParameterDo -
12064 *)
12065
12066 PROCEDURE ForeachParameterDo (p: CheckProcedure) ;
12067 VAR
12068 l, h: CARDINAL ;
12069 BEGIN
12070 l := LowIndice(Symbols) ;
12071 h := HighIndice(Symbols) ;
12072 WHILE l<=h DO
12073 IF IsParameter(l)
12074 THEN
12075 p(l)
12076 END ;
12077 INC(l)
12078 END
12079 END ForeachParameterDo ;
12080
12081
12082 (*
12083 CheckUnbounded - checks to see if parameter, Sym, is now an unbounded parameter.
12084 *)
12085
12086 PROCEDURE CheckUnbounded (Sym: CARDINAL) ;
12087 VAR
12088 pSym: PtrToSymbol ;
12089 BEGIN
12090 AssertInRange(Sym) ;
12091 pSym := GetPsym(Sym) ;
12092 WITH pSym^ DO
12093 CASE SymbolType OF
12094
12095 ParamSym : IF IsUnbounded(Param.Type)
12096 THEN
12097 Param.IsUnbounded := TRUE
12098 END |
12099 VarParamSym: IF IsUnbounded(VarParam.Type)
12100 THEN
12101 VarParam.IsUnbounded := TRUE
12102 END
12103
12104 ELSE
12105 HALT
12106 END
12107 END
12108 END CheckUnbounded ;
12109
12110
12111 (*
12112 IsOAFamily - returns TRUE if, Sym, is an OAFamily symbol.
12113 *)
12114
12115 PROCEDURE IsOAFamily (Sym: CARDINAL) : BOOLEAN ;
12116 VAR
12117 pSym: PtrToSymbol ;
12118 BEGIN
12119 AssertInRange(Sym) ;
12120 pSym := GetPsym(Sym) ;
12121 RETURN( pSym^.SymbolType=OAFamilySym )
12122 END IsOAFamily ;
12123
12124
12125 (*
12126 MakeOAFamily - makes an OAFamily symbol based on SimpleType.
12127 It returns the OAFamily symbol. A new symbol
12128 is created if one does not already exist for
12129 SimpleType.
12130 *)
12131
12132 PROCEDURE MakeOAFamily (SimpleType: CARDINAL) : CARDINAL ;
12133 VAR
12134 pSym: PtrToSymbol ;
12135 sym : CARDINAL ;
12136 BEGIN
12137 sym := GetOAFamily(SimpleType) ;
12138 IF sym=NulSym
12139 THEN
12140 NewSym(sym) ;
12141 pSym := GetPsym(sym) ;
12142 WITH pSym^ DO
12143 SymbolType := OAFamilySym ;
12144 OAFamily.MaxDimensions := 0 ;
12145 OAFamily.SimpleType := SimpleType ;
12146 OAFamily.Dimensions := Indexing.InitIndex(1)
12147 END ;
12148 PutOAFamily(SimpleType, sym)
12149 END ;
12150 RETURN( sym )
12151 END MakeOAFamily ;
12152
12153
12154 (*
12155 GetOAFamily - returns the oafamily symbol associated with
12156 SimpleType.
12157 *)
12158
12159 PROCEDURE GetOAFamily (SimpleType: CARDINAL) : CARDINAL ;
12160 VAR
12161 pSym: PtrToSymbol ;
12162 BEGIN
12163 pSym := GetPsym(SimpleType) ;
12164 WITH pSym^ DO
12165 CASE SymbolType OF
12166
12167 ErrorSym : RETURN( NulSym ) |
12168 RecordSym : RETURN( Record.oafamily ) |
12169 SubrangeSym : RETURN( Subrange.oafamily ) |
12170 EnumerationSym: RETURN( Enumeration.oafamily ) |
12171 ArraySym : RETURN( Array.oafamily ) |
12172 ProcTypeSym : RETURN( ProcType.oafamily ) |
12173 TypeSym : RETURN( Type.oafamily ) |
12174 PointerSym : RETURN( Pointer.oafamily ) |
12175 SetSym : RETURN( Set.oafamily ) |
12176 UndefinedSym : RETURN( Undefined.oafamily )
12177
12178 ELSE
12179 RETURN( NulSym )
12180 END
12181 END
12182 END GetOAFamily ;
12183
12184
12185 (*
12186 PutOAFamily - places the, oaf, into, SimpleType, oafamily field.
12187 *)
12188
12189 PROCEDURE PutOAFamily (SimpleType: CARDINAL; oaf: CARDINAL) ;
12190 VAR
12191 pSym: PtrToSymbol ;
12192 BEGIN
12193 pSym := GetPsym(SimpleType) ;
12194 WITH pSym^ DO
12195 CASE SymbolType OF
12196
12197 ErrorSym : |
12198 RecordSym : Record.oafamily := oaf |
12199 SubrangeSym : Subrange.oafamily := oaf |
12200 EnumerationSym: Enumeration.oafamily := oaf |
12201 ArraySym : Array.oafamily := oaf |
12202 ProcTypeSym : ProcType.oafamily := oaf |
12203 TypeSym : Type.oafamily := oaf |
12204 PointerSym : Pointer.oafamily := oaf |
12205 SetSym : Set.oafamily := oaf |
12206 UndefinedSym : Undefined.oafamily := oaf
12207
12208 ELSE
12209 InternalError ('not expecting this SimpleType')
12210 END
12211 END
12212 END PutOAFamily ;
12213
12214
12215 (*
12216 ForeachOAFamily - call, p[oaf, ndim, symbol] for every unbounded symbol,
12217 sym, in the oaf.
12218 *)
12219
12220 PROCEDURE ForeachOAFamily (sym: CARDINAL; p: FamilyOperation) ;
12221 VAR
12222 pSym: PtrToSymbol ;
12223 h, i: CARDINAL ;
12224 pc : POINTER TO CARDINAL ;
12225 BEGIN
12226 IF sym#NulSym
12227 THEN
12228 pSym := GetPsym(sym) ;
12229 WITH pSym^ DO
12230 CASE SymbolType OF
12231
12232 OAFamilySym: h := Indexing.HighIndice(OAFamily.Dimensions) ;
12233 i := 1 ;
12234 WHILE i<=h DO
12235 pc := Indexing.GetIndice(OAFamily.Dimensions, i) ;
12236 IF pc#NIL
12237 THEN
12238 p(sym, i, pc^)
12239 END ;
12240 INC(i)
12241 END
12242
12243 ELSE
12244 InternalError ('expecting OAFamily symbol')
12245 END
12246 END
12247 END
12248 END ForeachOAFamily ;
12249
12250
12251 (*
12252 doFillInOAFamily -
12253 *)
12254
12255 PROCEDURE doFillInOAFamily (oaf: CARDINAL; i: CARDINAL; unbounded: CARDINAL) ;
12256 VAR
12257 SimpleType: CARDINAL ;
12258 BEGIN
12259 SimpleType := GetType(oaf) ;
12260 IF unbounded#NulSym
12261 THEN
12262 FillInUnboundedFields(GetTokenNo(), unbounded, SimpleType, i)
12263 END
12264 END doFillInOAFamily ;
12265
12266
12267 (*
12268 FillInUnboundedFields -
12269 *)
12270
12271 PROCEDURE FillInUnboundedFields (tok: CARDINAL;
12272 sym: CARDINAL; SimpleType: CARDINAL; ndim: CARDINAL) ;
12273 VAR
12274 pSym : PtrToSymbol ;
12275 Contents: CARDINAL ;
12276 i : CARDINAL ;
12277 BEGIN
12278 IF sym#NulSym
12279 THEN
12280 pSym := GetPsym(sym) ;
12281 WITH pSym^ DO
12282 SymbolType := UnboundedSym ;
12283 WITH Unbounded DO
12284 Type := SimpleType ; (* Index to a simple type. *)
12285 Size := InitValue() ; (* Size in bytes for this sym *)
12286 Scope := GetScope(SimpleType) ; (* Which scope will create it *)
12287 InitWhereDeclaredTok(tok, At) ; (* Declared here *)
12288 NewSym(RecordType) ;
12289 FillInRecordFields(tok, RecordType, NulName, GetScope(SimpleType), NulSym) ;
12290 NewSym(Contents) ;
12291 FillInPointerFields(Contents, NulName, GetScope(SimpleType), NulSym) ;
12292 PutPointer(Contents, SimpleType) ;
12293 (* create the contents field for the unbounded array. *)
12294 Assert (PutFieldRecord(RecordType,
12295 MakeKey(UnboundedAddressName),
12296 Contents, NulSym) # NulSym) ;
12297 (* create all the high fields for the unbounded array. *)
12298 i := 1 ;
12299 WHILE i<=ndim DO
12300 Assert (PutFieldRecord(RecordType,
12301 makekey(string(Mark(Sprintf1(Mark(InitString(UnboundedHighName)), i)))),
12302 Cardinal, NulSym) # NulSym) ;
12303 INC(i)
12304 END ;
12305 Dimensions := ndim
12306 END
12307 END ;
12308 ForeachParameterDo(CheckUnbounded)
12309 END
12310 END FillInUnboundedFields ;
12311
12312
12313 (*
12314 MakeUnbounded - makes an unbounded array Symbol.
12315 ndim is the number of dimensions required.
12316 No name is required.
12317 *)
12318
12319 PROCEDURE MakeUnbounded (tok: CARDINAL;
12320 SimpleType: CARDINAL; ndim: CARDINAL) : CARDINAL ;
12321 VAR
12322 sym, oaf: CARDINAL ;
12323 BEGIN
12324 tok := CheckTok (tok, 'unbounded') ;
12325 oaf := MakeOAFamily(SimpleType) ;
12326 sym := GetUnbounded(oaf, ndim) ;
12327 IF sym=NulSym
12328 THEN
12329 NewSym(sym) ;
12330 IF IsUnknown (SimpleType)
12331 THEN
12332 PutPartialUnbounded(sym, SimpleType, ndim)
12333 ELSE
12334 FillInUnboundedFields(tok, sym, SimpleType, ndim)
12335 END ;
12336 PutUnbounded(oaf, sym, ndim)
12337 END ;
12338 RETURN( sym )
12339 END MakeUnbounded ;
12340
12341
12342 (*
12343 GetUnbounded - returns the unbounded symbol associated with
12344 the OAFamily symbol, oaf, and the number of
12345 dimensions, ndim, of the open array.
12346 *)
12347
12348 PROCEDURE GetUnbounded (oaf: CARDINAL; ndim: CARDINAL) : CARDINAL ;
12349 VAR
12350 pSym: PtrToSymbol ;
12351 BEGIN
12352 pSym := GetPsym(oaf) ;
12353 WITH pSym^ DO
12354 CASE SymbolType OF
12355
12356 OAFamilySym: WITH OAFamily DO
12357 IF ndim>MaxDimensions
12358 THEN
12359 RETURN( NulSym )
12360 ELSE
12361 RETURN( GetFromIndex(Dimensions, ndim) )
12362 END
12363 END
12364
12365 ELSE
12366 InternalError ('expecting OAFamily symbol')
12367 END
12368 END
12369 END GetUnbounded ;
12370
12371
12372 (*
12373 PutUnbounded - associates the unbounded symbol, open, with
12374 SimpleType.
12375 *)
12376
12377 PROCEDURE PutUnbounded (oaf: CARDINAL; sym: CARDINAL; ndim: CARDINAL) ;
12378 VAR
12379 pSym: PtrToSymbol ;
12380 BEGIN
12381 pSym := GetPsym(oaf) ;
12382 WITH pSym^ DO
12383 CASE SymbolType OF
12384
12385 OAFamilySym: WITH OAFamily DO
12386 (* need to check to see if we need to add NulSym for all dimensions < ndim
12387 which have not been used. *)
12388 WHILE MaxDimensions<ndim DO
12389 INC(MaxDimensions) ;
12390 IF MaxDimensions<ndim
12391 THEN
12392 (* add NulSym to an unused dimension. *)
12393 PutIntoIndex(Dimensions, MaxDimensions, NulSym)
12394 END
12395 END ;
12396 (* and finally add the known sym. *)
12397 PutIntoIndex(Dimensions, ndim, sym)
12398 END
12399
12400 ELSE
12401 InternalError ('expecting OAFamily symbol')
12402 END
12403 END
12404 END PutUnbounded ;
12405
12406
12407 (*
12408 GetUnboundedRecordType - returns the record type used to
12409 implement the unbounded array.
12410 *)
12411
12412 PROCEDURE GetUnboundedRecordType (Sym: CARDINAL) : CARDINAL ;
12413 VAR
12414 pSym: PtrToSymbol ;
12415 BEGIN
12416 pSym := GetPsym(Sym) ;
12417 WITH pSym^ DO
12418 CASE SymbolType OF
12419
12420 UnboundedSym: RETURN( Unbounded.RecordType )
12421
12422 ELSE
12423 InternalError ('expecting an UnBounded symbol')
12424 END
12425 END
12426 END GetUnboundedRecordType ;
12427
12428
12429 (*
12430 GetUnboundedAddressOffset - returns the offset of the address field
12431 inside the record used to implement the
12432 unbounded type.
12433 *)
12434
12435 PROCEDURE GetUnboundedAddressOffset (sym: CARDINAL) : CARDINAL ;
12436 VAR
12437 field,
12438 rec : CARDINAL ;
12439 BEGIN
12440 rec := GetUnboundedRecordType(sym) ;
12441 IF rec=NulSym
12442 THEN
12443 InternalError ('expecting record type to be declared')
12444 ELSE
12445 field := GetLocalSym(rec, MakeKey(UnboundedAddressName)) ;
12446 IF field=NulSym
12447 THEN
12448 InternalError ('expecting address field to be present inside unbounded record')
12449 ELSE
12450 RETURN( field )
12451 END
12452 END
12453 END GetUnboundedAddressOffset ;
12454
12455
12456 (*
12457 GetUnboundedHighOffset - returns the offset of the high field
12458 inside the record used to implement the
12459 unbounded type.
12460 *)
12461
12462 PROCEDURE GetUnboundedHighOffset (sym: CARDINAL; ndim: CARDINAL) : CARDINAL ;
12463 VAR
12464 rec: CARDINAL ;
12465 BEGIN
12466 rec := GetUnboundedRecordType(sym) ;
12467 IF rec=NulSym
12468 THEN
12469 InternalError ('expecting record type to be declared')
12470 ELSE
12471 RETURN GetLocalSym(rec,
12472 makekey(string(Mark(Sprintf1(Mark(InitString(UnboundedHighName)),
12473 ndim)))))
12474 END
12475 END GetUnboundedHighOffset ;
12476
12477
12478 (*
12479 GetArrayDimension - returns the number of dimensions defined.
12480 *)
12481
12482 PROCEDURE GetArrayDimension (sym: CARDINAL) : CARDINAL ;
12483 VAR
12484 n: CARDINAL ;
12485 BEGIN
12486 n := 0 ;
12487 WHILE IsArray(sym) DO
12488 sym := SkipType(GetType(sym)) ;
12489 INC(n)
12490 END ;
12491 RETURN( n )
12492 END GetArrayDimension ;
12493
12494
12495 (*
12496 GetDimension - return the number of dimensions associated with
12497 this unbounded ARRAY parameter.
12498 *)
12499
12500 PROCEDURE GetDimension (sym: CARDINAL) : CARDINAL ;
12501 VAR
12502 pSym: PtrToSymbol ;
12503 BEGIN
12504 pSym := GetPsym(sym) ;
12505 WITH pSym^ DO
12506 CASE SymbolType OF
12507
12508 PartialUnboundedSym: RETURN( PartialUnbounded.NDim ) |
12509 UnboundedSym : RETURN( Unbounded.Dimensions ) |
12510 OAFamilySym : RETURN( OAFamily.MaxDimensions ) |
12511 ParamSym : IF Param.IsUnbounded
12512 THEN
12513 RETURN( GetDimension(GetType(sym)) )
12514 ELSE
12515 InternalError ('expecting unbounded paramater')
12516 END |
12517 VarParamSym : IF VarParam.IsUnbounded
12518 THEN
12519 RETURN( GetDimension(GetType(sym)) )
12520 ELSE
12521 InternalError ('expecting unbounded paramater')
12522 END |
12523 ArraySym : RETURN( GetArrayDimension(sym) ) |
12524 TypeSym : RETURN( GetDimension(GetType(sym)) ) |
12525 VarSym : RETURN( GetDimension(GetType(sym)) )
12526
12527 ELSE
12528 InternalError ('expecting PartialUnbounded')
12529 END
12530 END
12531 END GetDimension ;
12532
12533
12534 (*
12535 PutArray - places a type symbol into an arraysym.
12536 *)
12537
12538 PROCEDURE PutArray (arraysym, typesym: CARDINAL) ;
12539 VAR
12540 pSym: PtrToSymbol ;
12541 BEGIN
12542 pSym := GetPsym (arraysym) ;
12543 WITH pSym^ DO
12544 CASE SymbolType OF
12545
12546 ErrorSym: |
12547 ArraySym: WITH Array DO
12548 Type := typesym (* The ARRAY OF typesym. *)
12549 END
12550 ELSE
12551 InternalError ('expecting an Array symbol')
12552 END
12553 END
12554 END PutArray ;
12555
12556
12557 (*
12558 ResolveConstructorType - if, sym, has an unresolved constructor type
12559 then attempt to resolve it by examining the
12560 from, type.
12561 *)
12562
12563 PROCEDURE ResolveConstructorType (sym: CARDINAL;
12564 VAR type: CARDINAL;
12565 VAR from: CARDINAL;
12566 VAR unres: BOOLEAN) ;
12567 BEGIN
12568 IF unres
12569 THEN
12570 IF IsConstructor(from)
12571 THEN
12572 IF IsConstructorResolved(from)
12573 THEN
12574 unres := FALSE ;
12575 type := GetType(from) ;
12576 IF (type#NulSym) AND IsSet(SkipType(type))
12577 THEN
12578 PutConstSet(sym)
12579 END
12580 END
12581 ELSIF (from#NulSym) AND IsSet(SkipType(from))
12582 THEN
12583 unres := FALSE ;
12584 type := from ;
12585 PutConstSet(sym)
12586 ELSIF (from#NulSym) AND (IsRecord(SkipType(from)) OR IsArray(SkipType(from)))
12587 THEN
12588 unres := FALSE ;
12589 type := from
12590 END
12591 END
12592 END ResolveConstructorType ;
12593
12594
12595 (*
12596 IsConstructorResolved - returns TRUE if the constructor does not
12597 have an unresolved type.
12598 *)
12599
12600 PROCEDURE IsConstructorResolved (sym: CARDINAL) : BOOLEAN ;
12601 VAR
12602 pSym: PtrToSymbol ;
12603 BEGIN
12604 pSym := GetPsym(sym) ;
12605 WITH pSym^ DO
12606 CASE SymbolType OF
12607
12608 ConstVarSym: RETURN( NOT ConstVar.UnresFromType ) |
12609 ConstLitSym: RETURN( NOT ConstLit.UnresFromType )
12610
12611 ELSE
12612 InternalError ('expecting ConstVar or ConstLit symbol')
12613 END
12614 END
12615 END IsConstructorResolved ;
12616
12617
12618 (*
12619 CanResolveConstructor - returns TRUE if the type of the constructor,
12620 sym, is known.
12621 *)
12622
12623 PROCEDURE CanResolveConstructor (sym: CARDINAL) : BOOLEAN ;
12624 VAR
12625 pSym: PtrToSymbol ;
12626 BEGIN
12627 IF NOT IsConstructorResolved(sym)
12628 THEN
12629 pSym := GetPsym(sym) ;
12630 WITH pSym^ DO
12631 CASE SymbolType OF
12632
12633 ConstVarSym: WITH ConstVar DO
12634 ResolveConstructorType(sym, Type, FromType, UnresFromType)
12635 END |
12636 ConstLitSym: WITH ConstLit DO
12637 ResolveConstructorType(sym, Type, FromType, UnresFromType)
12638 END |
12639
12640 ELSE
12641 InternalError ('expecting ConstVar or ConstLit symbol')
12642 END
12643 END
12644 END ;
12645 RETURN( IsConstructorResolved(sym) )
12646 END CanResolveConstructor ;
12647
12648
12649 (*
12650 CheckAllConstructorsResolved - checks to see that the
12651 UnresolvedConstructorType list is
12652 empty and if it is not then it
12653 generates error messages.
12654 *)
12655
12656 PROCEDURE CheckAllConstructorsResolved ;
12657 VAR
12658 i, n, s: CARDINAL ;
12659 e : Error ;
12660 BEGIN
12661 n := NoOfItemsInList(UnresolvedConstructorType) ;
12662 IF n>0
12663 THEN
12664 FOR i := 1 TO n DO
12665 s := GetItemFromList(UnresolvedConstructorType, i) ;
12666 e := NewError(GetDeclaredMod(s)) ;
12667 ErrorFormat0(e, 'constructor has an unknown type')
12668 END ;
12669 FlushErrors
12670 END
12671 END CheckAllConstructorsResolved ;
12672
12673
12674 (*
12675 ResolveConstructorTypes - to be called at the end of pass three. Its
12676 purpose is to fix up all constructors whose
12677 types are unknown.
12678 *)
12679
12680 PROCEDURE ResolveConstructorTypes ;
12681 VAR
12682 finished: BOOLEAN ;
12683 i, n, s : CARDINAL ;
12684 BEGIN
12685 REPEAT
12686 n := NoOfItemsInList(UnresolvedConstructorType) ;
12687 finished := TRUE ;
12688 i := 1 ;
12689 WHILE i<=n DO
12690 s := GetItemFromList(UnresolvedConstructorType, i) ;
12691 Assert(IsConstructor(s)) ;
12692 IF CanResolveConstructor(s)
12693 THEN
12694 finished := FALSE ;
12695 RemoveItemFromList(UnresolvedConstructorType, s) ;
12696 i := n
12697 END ;
12698 INC(i)
12699 END
12700 UNTIL finished ;
12701 CheckAllConstructorsResolved
12702 END ResolveConstructorTypes ;
12703
12704
12705 (*
12706 SanityCheckParameters -
12707 *)
12708
12709 PROCEDURE SanityCheckParameters (sym: CARDINAL) ;
12710 VAR
12711 p : CARDINAL ;
12712 i, n: CARDINAL ;
12713 BEGIN
12714 i := 1 ;
12715 n := NoOfParamAny (sym) ;
12716 WHILE i <= n DO
12717 p := GetType (GetParam (sym, i)) ;
12718 IF IsConst (p)
12719 THEN
12720 MetaError3 ('the {%1N} formal parameter in procedure {%2Dad} should have a type rather than a constant {%3Dad}',
12721 i, sym, p)
12722 END ;
12723 INC (i)
12724 END
12725 END SanityCheckParameters ;
12726
12727
12728 (*
12729 SanityCheckArray - checks to see that an array has a correct subrange type.
12730 *)
12731
12732 PROCEDURE SanityCheckArray (sym: CARDINAL) ;
12733 VAR
12734 type : CARDINAL ;
12735 subscript: CARDINAL ;
12736 BEGIN
12737 IF IsArray(sym)
12738 THEN
12739 subscript := GetArraySubscript(sym) ;
12740 IF subscript#NulSym
12741 THEN
12742 type := SkipType(GetType(subscript)) ;
12743 IF IsAModula2Type(type)
12744 THEN
12745 (* ok all is good *)
12746 ELSE
12747 MetaError2('the array {%1Dad} must be declared with a simpletype in the [..] component rather than a {%2d}',
12748 sym, type)
12749 END
12750 END
12751 END
12752 END SanityCheckArray ;
12753
12754
12755 (*
12756 ForeachSymbolDo - foreach symbol, call, P(sym).
12757 *)
12758
12759 PROCEDURE ForeachSymbolDo (P: PerformOperation) ;
12760 VAR
12761 i, n: CARDINAL ;
12762 BEGIN
12763 i := Indexing.LowIndice(Symbols) ;
12764 n := Indexing.HighIndice(Symbols) ;
12765 WHILE i<=n DO
12766 P(i) ;
12767 INC(i)
12768 END
12769 END ForeachSymbolDo ;
12770
12771
12772 (*
12773 SanityCheckProcedure - check to see that procedure parameters do not use constants
12774 instead of types in their formal parameter section.
12775 *)
12776
12777 PROCEDURE SanityCheckProcedure (sym: CARDINAL) ;
12778 BEGIN
12779 SanityCheckParameters(sym)
12780 END SanityCheckProcedure ;
12781
12782
12783 (*
12784 SanityCheckModule -
12785 *)
12786
12787 PROCEDURE SanityCheckModule (sym: CARDINAL) ;
12788 BEGIN
12789 ForeachInnerModuleDo(sym, SanityCheckModule) ;
12790 ForeachProcedureDo(sym, SanityCheckProcedure) ;
12791 ForeachLocalSymDo(sym, SanityCheckArray)
12792 END SanityCheckModule ;
12793
12794
12795 (*
12796 SanityCheckConstants - must only be called once all constants, types, procedures
12797 have been declared. It checks to see that constants are
12798 not used as procedure parameter types.
12799 *)
12800
12801 PROCEDURE SanityCheckConstants ;
12802 BEGIN
12803 ForeachModuleDo(SanityCheckModule) ;
12804 ForeachSymbolDo(SanityCheckArray)
12805 END SanityCheckConstants ;
12806
12807
12808 (*
12809 AddNameTo - adds Name, n, to tree, s.
12810 *)
12811
12812 PROCEDURE AddNameTo (s: SymbolTree; o: CARDINAL) ;
12813 BEGIN
12814 IF GetSymKey(s, GetSymName(o))=NulKey
12815 THEN
12816 PutSymKey(s, GetSymName(o), o)
12817 END
12818 END AddNameTo ;
12819
12820
12821 (*
12822 AddNameToScope - adds a Name, n, to the list of objects declared at the
12823 current scope.
12824 *)
12825
12826 PROCEDURE AddNameToScope (n: Name) ;
12827 VAR
12828 pSym : PtrToSymbol ;
12829 scope: CARDINAL ;
12830 BEGIN
12831 scope := GetCurrentScope() ;
12832 pSym := GetPsym(scope) ;
12833 WITH pSym^ DO
12834 CASE SymbolType OF
12835
12836 ProcedureSym: AddNameTo(Procedure.NamedObjects, MakeObject(n)) |
12837 ModuleSym : AddNameTo(Module.NamedObjects, MakeObject(n)) |
12838 DefImpSym : AddNameTo(DefImp.NamedObjects, MakeObject(n))
12839
12840 ELSE
12841 InternalError ('expecting - DefImp')
12842 END
12843 END
12844 END AddNameToScope ;
12845
12846
12847 (*
12848 AddNameToImportList - adds a Name, n, to the import list of the current
12849 module.
12850 *)
12851
12852 PROCEDURE AddNameToImportList (n: Name) ;
12853 VAR
12854 pSym : PtrToSymbol ;
12855 scope: CARDINAL ;
12856 BEGIN
12857 scope := GetCurrentScope() ;
12858 pSym := GetPsym(scope) ;
12859 WITH pSym^ DO
12860 CASE SymbolType OF
12861
12862 ModuleSym: AddNameTo(Module.NamedImports, MakeObject(n)) |
12863 DefImpSym: AddNameTo(DefImp.NamedImports, MakeObject(n))
12864
12865 ELSE
12866 InternalError ('expecting - DefImp or Module symbol')
12867 END
12868 END
12869 END AddNameToImportList ;
12870
12871
12872 VAR
12873 ResolveModule: CARDINAL ;
12874
12875
12876 (*
12877 CollectSymbolFrom -
12878 *)
12879
12880 PROCEDURE CollectSymbolFrom (tok: CARDINAL; scope: CARDINAL; n: Name) : CARDINAL ;
12881 VAR
12882 n1 : Name ;
12883 sym: CARDINAL ;
12884 BEGIN
12885 n1 := GetSymName (scope) ;
12886 IF DebugUnknowns
12887 THEN
12888 printf2('declaring %a in %a', n, n1)
12889 END ;
12890 sym := CheckScopeForSym (scope, n) ;
12891 IF sym=NulSym
12892 THEN
12893 sym := FetchUnknownFrom (tok, scope, n)
12894 END ;
12895 IF DebugUnknowns
12896 THEN
12897 printf1(' symbol created (%d)\n', sym)
12898 END ;
12899 RETURN( sym )
12900 END CollectSymbolFrom ;
12901
12902
12903 (*
12904 CollectUnknown -
12905 *)
12906
12907 PROCEDURE CollectUnknown (tok: CARDINAL; sym: CARDINAL; n: Name) : CARDINAL ;
12908 VAR
12909 pSym: PtrToSymbol ;
12910 s : CARDINAL ;
12911 BEGIN
12912 s := NulSym ;
12913 IF IsModule (sym) OR IsDefImp (sym)
12914 THEN
12915 RETURN( CollectSymbolFrom (tok, sym, n) )
12916 ELSIF IsProcedure(sym)
12917 THEN
12918 s := CheckScopeForSym (sym, n) ;
12919 IF s=NulSym
12920 THEN
12921 pSym := GetPsym (sym) ;
12922 WITH pSym^ DO
12923 CASE SymbolType OF
12924
12925 ProcedureSym: IF GetSymKey (Procedure.NamedObjects, n) # NulKey
12926 THEN
12927 RETURN( CollectSymbolFrom (tok, sym, n) )
12928 END
12929
12930 ELSE
12931 InternalError ('expecting - Procedure symbol')
12932 END
12933 END ;
12934 s := CollectUnknown (tok, GetScope (sym), n)
12935 END
12936 END ;
12937 RETURN( s )
12938 END CollectUnknown ;
12939
12940
12941 (*
12942 ResolveImport -
12943 *)
12944
12945 PROCEDURE ResolveImport (o: WORD) ;
12946 VAR
12947 n1, n2: Name ;
12948 tok : CARDINAL ;
12949 sym : CARDINAL ;
12950 BEGIN
12951 IF DebugUnknowns
12952 THEN
12953 n1 := GetSymName(o) ;
12954 printf1('attempting to find out where %a was declared\n', n1) ;
12955 n1 := GetSymName(ResolveModule) ;
12956 n2 := GetSymName(GetScope(ResolveModule)) ;
12957 printf2('scope of module %a is %a\n', n1, n2)
12958 END ;
12959 tok := GetFirstUsed (o) ;
12960 sym := CollectUnknown (tok, GetScope(ResolveModule), GetSymName(o)) ;
12961 IF sym=NulSym
12962 THEN
12963 MetaError2('unknown symbol {%1Uad} found in import list of module {%2a}',
12964 o, ResolveModule)
12965 ELSE
12966 AddSymToModuleScope(ResolveModule, sym)
12967 END
12968 END ResolveImport ;
12969
12970
12971 (*
12972 ResolveRelativeImport -
12973 *)
12974
12975 PROCEDURE ResolveRelativeImport (sym: CARDINAL) ;
12976 VAR
12977 pSym: PtrToSymbol ;
12978 BEGIN
12979 IF IsModule(sym)
12980 THEN
12981 ResolveModule := sym ;
12982 pSym := GetPsym(sym) ;
12983 WITH pSym^ DO
12984 CASE SymbolType OF
12985
12986 ModuleSym: ForeachNodeDo(Module.NamedImports,
12987 ResolveImport)
12988
12989 ELSE
12990 InternalError ('expecting - Module symbol')
12991 END
12992 END
12993 END ;
12994 ForeachProcedureDo(sym, ResolveRelativeImport) ;
12995 ForeachInnerModuleDo(sym, ResolveRelativeImport)
12996 END ResolveRelativeImport ;
12997
12998
12999 (*
13000 ResolveImports - it examines the import list of all inner modules
13001 and resolves all relative imports.
13002 *)
13003
13004 PROCEDURE ResolveImports ;
13005 VAR
13006 scope: CARDINAL ;
13007 BEGIN
13008 scope := GetCurrentScope() ;
13009 IF DebugUnknowns
13010 THEN
13011 DisplayTrees(scope)
13012 END ;
13013 ForeachProcedureDo(scope, ResolveRelativeImport) ;
13014 ForeachInnerModuleDo(scope, ResolveRelativeImport)
13015 END ResolveImports ;
13016
13017
13018 (*
13019 GetScope - returns the declaration scope of the symbol.
13020 *)
13021
13022 PROCEDURE GetScope (Sym: CARDINAL) : CARDINAL ;
13023 VAR
13024 pSym: PtrToSymbol ;
13025 BEGIN
13026 pSym := GetPsym(Sym) ;
13027 WITH pSym^ DO
13028 CASE SymbolType OF
13029
13030 ErrorSym : RETURN( Error.Scope ) |
13031 DefImpSym : RETURN( NulSym ) |
13032 ModuleSym : RETURN( Module.Scope ) |
13033 VarSym : RETURN( Var.Scope ) |
13034 ProcedureSym : RETURN( Procedure.Scope ) |
13035 ProcTypeSym : RETURN( ProcType.Scope ) |
13036 RecordFieldSym : RETURN( RecordField.Scope ) |
13037 VarientSym : RETURN( Varient.Scope ) |
13038 VarientFieldSym : RETURN( VarientField.Scope ) |
13039 EnumerationSym : RETURN( Enumeration.Scope ) |
13040 EnumerationFieldSym: RETURN( EnumerationField.Scope ) |
13041 SubrangeSym : RETURN( Subrange.Scope ) |
13042 ArraySym : RETURN( Array.Scope ) |
13043 TypeSym : RETURN( Type.Scope ) |
13044 PointerSym : RETURN( Pointer.Scope ) |
13045 RecordSym : RETURN( Record.Scope ) |
13046 SetSym : RETURN( Set.Scope ) |
13047 UnboundedSym : RETURN( Unbounded.Scope ) |
13048 ConstLitSym : RETURN( ConstLit.Scope ) |
13049 ConstStringSym : RETURN( ConstString.Scope ) |
13050 ConstVarSym : RETURN( ConstVar.Scope ) |
13051 ParamSym : RETURN( Param.Scope ) |
13052 VarParamSym : RETURN( VarParam.Scope ) |
13053 UndefinedSym : RETURN( NulSym ) |
13054 PartialUnboundedSym: InternalError ('should not be requesting the scope of a PartialUnbounded symbol')
13055
13056 ELSE
13057 InternalError ('not implemented yet')
13058 END
13059 END
13060 END GetScope ;
13061
13062
13063 (*
13064 GetModuleScope - returns the module scope of symbol, sym.
13065 If sym was declared within a nested procedure
13066 then return the module which defines the
13067 procedure.
13068 *)
13069
13070 PROCEDURE GetModuleScope (sym: CARDINAL) : CARDINAL ;
13071 VAR
13072 mod: CARDINAL ;
13073 BEGIN
13074 mod := GetScope(sym) ;
13075 WHILE (mod#NulSym) AND (NOT IsDefImp(mod)) AND (NOT IsModule(mod)) DO
13076 mod := GetScope(mod)
13077 END ;
13078 RETURN( mod )
13079 END GetModuleScope ;
13080
13081
13082 (*
13083 GetProcedureScope - returns the innermost procedure (if any)
13084 in which the symbol, sym, resides.
13085 A module inside the procedure is skipped
13086 over.
13087 *)
13088
13089 PROCEDURE GetProcedureScope (sym: CARDINAL) : CARDINAL ;
13090 BEGIN
13091 WHILE (sym#NulSym) AND (NOT IsProcedure(sym)) DO
13092 sym := GetScope(sym)
13093 END ;
13094 IF (sym#NulSym) AND IsProcedure(sym)
13095 THEN
13096 RETURN( sym )
13097 ELSE
13098 RETURN( NulSym )
13099 END
13100 END GetProcedureScope ;
13101
13102
13103 (*
13104 IsModuleWithinProcedure - returns TRUE if module, sym, is
13105 inside a procedure.
13106 *)
13107
13108 PROCEDURE IsModuleWithinProcedure (sym: CARDINAL) : BOOLEAN ;
13109 BEGIN
13110 RETURN( GetProcedureScope (sym) # NulSym )
13111 END IsModuleWithinProcedure ;
13112
13113
13114 (*
13115 GetParent - returns the parent of symbol, Sym.
13116 *)
13117
13118 PROCEDURE GetParent (Sym: CARDINAL) : CARDINAL ;
13119 VAR
13120 pSym: PtrToSymbol ;
13121 BEGIN
13122 pSym := GetPsym(Sym) ;
13123 WITH pSym^ DO
13124 CASE SymbolType OF
13125
13126 ErrorSym : ErrorAbort0('') |
13127 VarientSym : RETURN( Varient.Parent ) |
13128 VarientFieldSym : RETURN( VarientField.Parent ) |
13129 RecordFieldSym : RETURN( RecordField.Parent ) |
13130 EnumerationFieldSym: RETURN( EnumerationField.Type )
13131
13132 ELSE
13133 InternalError ('not implemented yet')
13134 END
13135 END
13136 END GetParent ;
13137
13138
13139 (*
13140 IsRecordField - returns true if Sym is a record field.
13141 *)
13142
13143 PROCEDURE IsRecordField (Sym: CARDINAL) : BOOLEAN ;
13144 VAR
13145 pSym: PtrToSymbol ;
13146 BEGIN
13147 pSym := GetPsym(Sym) ;
13148 RETURN( pSym^.SymbolType=RecordFieldSym )
13149 END IsRecordField ;
13150
13151
13152 (*
13153 MakeProcType - returns a procedure type symbol with ProcTypeName.
13154 *)
13155
13156 PROCEDURE MakeProcType (tok: CARDINAL; ProcTypeName: Name) : CARDINAL ;
13157 VAR
13158 pSym : PtrToSymbol ;
13159 oaf, sym: CARDINAL ;
13160 BEGIN
13161 tok := CheckTok (tok, 'proctype') ;
13162 sym := HandleHiddenOrDeclare (tok, ProcTypeName, oaf) ;
13163 IF NOT IsError(sym)
13164 THEN
13165 pSym := GetPsym(sym) ;
13166 WITH pSym^ DO
13167 SymbolType := ProcTypeSym ;
13168 CASE SymbolType OF
13169
13170 ProcTypeSym: ProcType.ReturnType := NulSym ;
13171 ProcType.name := ProcTypeName ;
13172 InitList(ProcType.ListOfParam) ;
13173 ProcType.HasVarArgs := FALSE ; (* Does this proc type use ... ? *)
13174 ProcType.HasOptArg := FALSE ; (* Does this proc type use [ ] ? *)
13175 ProcType.OptArgInit := NulSym ; (* The optarg initial value. *)
13176 ProcType.ReturnOptional := FALSE ; (* Is the return value optional? *)
13177 ProcType.ReturnTypeTok := UnknownTokenNo ;
13178 ProcType.Scope := GetCurrentScope() ;
13179 (* scope of procedure. *)
13180 ProcType.Size := InitValue() ;
13181 ProcType.TotalParamSize := InitValue() ; (* size of all parameters *)
13182 ProcType.oafamily := oaf ; (* The oa family for this symbol *)
13183 InitWhereDeclaredTok(tok, ProcType.At) (* Declared here *)
13184
13185 ELSE
13186 InternalError ('expecting ProcType symbol')
13187 END
13188 END
13189 END ;
13190 ForeachOAFamily(oaf, doFillInOAFamily) ;
13191 RETURN( sym )
13192 END MakeProcType ;
13193
13194
13195 (*
13196 PutProcTypeParam - Places a Non VAR parameter ParamName with type
13197 ParamType into ProcType Sym.
13198 *)
13199
13200 PROCEDURE PutProcTypeParam (tok: CARDINAL;
13201 Sym: CARDINAL;
13202 ParamType: CARDINAL; isUnbounded: BOOLEAN) ;
13203 VAR
13204 pSym : PtrToSymbol ;
13205 ParSym: CARDINAL ;
13206 BEGIN
13207 NewSym(ParSym) ;
13208 pSym := GetPsym(ParSym) ;
13209 WITH pSym^ DO
13210 SymbolType := ParamSym ;
13211 WITH Param DO
13212 name := NulName ;
13213 Type := ParamType ;
13214 IsUnbounded := isUnbounded ;
13215 ShadowVar := NulSym ;
13216 FullTok := tok ;
13217 At := tok
13218 END
13219 END ;
13220 AddParameter (Sym, ProperProcedure, ParSym)
13221 END PutProcTypeParam ;
13222
13223
13224 (*
13225 PutProcTypeVarParam - Places a Non VAR parameter ParamName with type
13226 ParamType into ProcType Sym.
13227 *)
13228
13229 PROCEDURE PutProcTypeVarParam (tok: CARDINAL;
13230 Sym: CARDINAL;
13231 ParamType: CARDINAL; isUnbounded: BOOLEAN) ;
13232 VAR
13233 pSym : PtrToSymbol ;
13234 ParSym: CARDINAL ;
13235 BEGIN
13236 NewSym(ParSym) ;
13237 pSym := GetPsym(ParSym) ;
13238 WITH pSym^ DO
13239 SymbolType := VarParamSym ;
13240 WITH Param DO
13241 name := NulName ;
13242 Type := ParamType ;
13243 IsUnbounded := isUnbounded ;
13244 ShadowVar := NulSym ;
13245 FullTok := tok ;
13246 At := tok
13247 END
13248 END ;
13249 AddParameter (Sym, ProperProcedure, ParSym)
13250 END PutProcTypeVarParam ;
13251
13252
13253 (*
13254 GetProcedureProcType - returns the proctype matching procedure sym.
13255 *)
13256
13257 PROCEDURE GetProcedureProcType (sym: CARDINAL) : CARDINAL ;
13258 VAR
13259 pSym: PtrToSymbol ;
13260 BEGIN
13261 pSym := GetPsym(sym) ;
13262 WITH pSym^ DO
13263 CASE SymbolType OF
13264
13265 ProcedureSym: RETURN Procedure.ProcedureType
13266
13267 ELSE
13268 InternalError ('expecting Procedure symbol')
13269 END
13270 END
13271 END GetProcedureProcType ;
13272
13273
13274 (*
13275 PutProcedureReachable - Sets the procedure, Sym, to be reachable by the
13276 main Module.
13277 *)
13278
13279 PROCEDURE PutProcedureReachable (Sym: CARDINAL) ;
13280 VAR
13281 pSym: PtrToSymbol ;
13282 BEGIN
13283 pSym := GetPsym(Sym) ;
13284 WITH pSym^ DO
13285 CASE SymbolType OF
13286
13287 ErrorSym: |
13288 ProcedureSym: Procedure.Reachable := TRUE
13289
13290 ELSE
13291 InternalError ('expecting Procedure symbol')
13292 END
13293 END
13294 END PutProcedureReachable ;
13295
13296
13297 (*
13298 PutModuleStartQuad - Places QuadNumber into the Module symbol, Sym.
13299 QuadNumber is the start quad of Module,
13300 Sym.
13301 *)
13302
13303 PROCEDURE PutModuleStartQuad (Sym: CARDINAL; QuadNumber: CARDINAL) ;
13304 VAR
13305 pSym: PtrToSymbol ;
13306 BEGIN
13307 pSym := GetPsym(Sym) ;
13308 WITH pSym^ DO
13309 CASE SymbolType OF
13310
13311 ModuleSym: Module.StartQuad := QuadNumber |
13312 DefImpSym: DefImp.StartQuad := QuadNumber
13313
13314 ELSE
13315 InternalError ('expecting a Module or DefImp symbol')
13316 END
13317 END
13318 END PutModuleStartQuad ;
13319
13320
13321 (*
13322 PutModuleEndQuad - Places QuadNumber into the Module symbol, Sym.
13323 QuadNumber is the end quad of Module,
13324 Sym.
13325 *)
13326
13327 PROCEDURE PutModuleEndQuad (Sym: CARDINAL; QuadNumber: CARDINAL) ;
13328 VAR
13329 pSym: PtrToSymbol ;
13330 BEGIN
13331 pSym := GetPsym(Sym) ;
13332 WITH pSym^ DO
13333 CASE SymbolType OF
13334
13335 ModuleSym: Module.EndQuad := QuadNumber |
13336 DefImpSym: DefImp.EndQuad := QuadNumber
13337
13338 ELSE
13339 InternalError ('expecting a Module or DefImp symbol')
13340 END
13341 END
13342 END PutModuleEndQuad ;
13343
13344
13345 (*
13346 PutModuleFinallyStartQuad - Places QuadNumber into the Module symbol, Sym.
13347 QuadNumber is the finally start quad of
13348 Module, Sym.
13349 *)
13350
13351 PROCEDURE PutModuleFinallyStartQuad (Sym: CARDINAL; QuadNumber: CARDINAL) ;
13352 VAR
13353 pSym: PtrToSymbol ;
13354 BEGIN
13355 pSym := GetPsym(Sym) ;
13356 WITH pSym^ DO
13357 CASE SymbolType OF
13358
13359 ModuleSym: Module.StartFinishQuad := QuadNumber |
13360 DefImpSym: DefImp.StartFinishQuad := QuadNumber
13361
13362 ELSE
13363 InternalError ('expecting a Module or DefImp symbol')
13364 END
13365 END
13366 END PutModuleFinallyStartQuad ;
13367
13368
13369 (*
13370 PutModuleFinallyEndQuad - Places QuadNumber into the Module symbol, Sym.
13371 QuadNumber is the end quad of the finally block
13372 in Module, Sym.
13373 *)
13374
13375 PROCEDURE PutModuleFinallyEndQuad (Sym: CARDINAL; QuadNumber: CARDINAL) ;
13376 VAR
13377 pSym: PtrToSymbol ;
13378 BEGIN
13379 pSym := GetPsym(Sym) ;
13380 WITH pSym^ DO
13381 CASE SymbolType OF
13382
13383 ModuleSym: Module.EndFinishQuad := QuadNumber |
13384 DefImpSym: DefImp.EndFinishQuad := QuadNumber
13385
13386 ELSE
13387 InternalError ('expecting a Module or DefImp symbol')
13388 END
13389 END
13390 END PutModuleFinallyEndQuad ;
13391
13392
13393 (*
13394 GetModuleQuads - Returns, StartInit EndInit StartFinish EndFinish,
13395 Quads of a Module, Sym.
13396 Start and End represent the initialization code
13397 of the Module, Sym.
13398 *)
13399
13400 PROCEDURE GetModuleQuads (Sym: CARDINAL;
13401 VAR StartInit, EndInit,
13402 StartFinish, EndFinish: CARDINAL) ;
13403 VAR
13404 pSym: PtrToSymbol ;
13405 BEGIN
13406 pSym := GetPsym(Sym) ;
13407 WITH pSym^ DO
13408 CASE SymbolType OF
13409
13410 ModuleSym: WITH Module DO
13411 StartInit := StartQuad ;
13412 EndInit := EndQuad ;
13413 StartFinish := StartFinishQuad ;
13414 EndFinish := EndFinishQuad
13415 END |
13416 DefImpSym: WITH DefImp DO
13417 StartInit := StartQuad ;
13418 EndInit := EndQuad ;
13419 StartFinish := StartFinishQuad ;
13420 EndFinish := EndFinishQuad
13421 END
13422
13423 ELSE
13424 InternalError ('expecting a Module or DefImp symbol')
13425 END
13426 END
13427 END GetModuleQuads ;
13428
13429
13430 (*
13431 PutModuleFinallyFunction - Places Tree, finally, into the Module symbol, Sym.
13432 *)
13433
13434 PROCEDURE PutModuleFinallyFunction (Sym: CARDINAL; finally: tree) ;
13435 VAR
13436 pSym: PtrToSymbol ;
13437 BEGIN
13438 pSym := GetPsym(Sym) ;
13439 WITH pSym^ DO
13440 CASE SymbolType OF
13441
13442 ModuleSym: Module.FinallyFunction := finally |
13443 DefImpSym: DefImp.FinallyFunction := finally
13444
13445 ELSE
13446 InternalError ('expecting a Module or DefImp symbol')
13447 END
13448 END
13449 END PutModuleFinallyFunction ;
13450
13451
13452 (*
13453 GetModuleFinallyFunction - returns the finally tree from the Module symbol, Sym.
13454 *)
13455
13456 PROCEDURE GetModuleFinallyFunction (Sym: CARDINAL) : tree ;
13457 VAR
13458 pSym: PtrToSymbol ;
13459 BEGIN
13460 pSym := GetPsym(Sym) ;
13461 WITH pSym^ DO
13462 CASE SymbolType OF
13463
13464 ModuleSym: RETURN( Module.FinallyFunction) |
13465 DefImpSym: RETURN( DefImp.FinallyFunction)
13466
13467 ELSE
13468 InternalError ('expecting a Module or DefImp symbol')
13469 END
13470 END
13471 END GetModuleFinallyFunction ;
13472
13473
13474 (*
13475 PutProcedureScopeQuad - Places QuadNumber into the Procedure symbol, Sym.
13476 QuadNumber is the start quad of scope for procedure,
13477 Sym.
13478 *)
13479
13480 PROCEDURE PutProcedureScopeQuad (Sym: CARDINAL; QuadNumber: CARDINAL) ;
13481 VAR
13482 pSym: PtrToSymbol ;
13483 BEGIN
13484 pSym := GetPsym(Sym) ;
13485 WITH pSym^ DO
13486 CASE SymbolType OF
13487
13488 ProcedureSym: Procedure.ScopeQuad := QuadNumber
13489
13490 ELSE
13491 InternalError ('expecting a Procedure symbol')
13492 END
13493 END
13494 END PutProcedureScopeQuad ;
13495
13496
13497 (*
13498 PutProcedureStartQuad - Places QuadNumber into the Procedure symbol, Sym.
13499 QuadNumber is the start quad of procedure,
13500 Sym.
13501 *)
13502
13503 PROCEDURE PutProcedureStartQuad (Sym: CARDINAL; QuadNumber: CARDINAL) ;
13504 VAR
13505 pSym: PtrToSymbol ;
13506 BEGIN
13507 pSym := GetPsym(Sym) ;
13508 WITH pSym^ DO
13509 CASE SymbolType OF
13510
13511 ProcedureSym: Procedure.StartQuad := QuadNumber
13512
13513 ELSE
13514 InternalError ('expecting a Procedure symbol')
13515 END
13516 END
13517 END PutProcedureStartQuad ;
13518
13519
13520 (*
13521 PutProcedureEndQuad - Places QuadNumber into the Procedure symbol, Sym.
13522 QuadNumber is the end quad of procedure,
13523 Sym.
13524 *)
13525
13526 PROCEDURE PutProcedureEndQuad (Sym: CARDINAL; QuadNumber: CARDINAL) ;
13527 VAR
13528 pSym: PtrToSymbol ;
13529 BEGIN
13530 pSym := GetPsym(Sym) ;
13531 WITH pSym^ DO
13532 CASE SymbolType OF
13533
13534 ProcedureSym: Procedure.EndQuad := QuadNumber
13535
13536 ELSE
13537 InternalError ('expecting a Procedure symbol')
13538 END
13539 END
13540 END PutProcedureEndQuad ;
13541
13542
13543 (*
13544 GetProcedureQuads - Returns, Start and End, Quads of a procedure, Sym.
13545 *)
13546
13547 PROCEDURE GetProcedureQuads (Sym: CARDINAL; VAR scope, start, end: CARDINAL) ;
13548 VAR
13549 pSym: PtrToSymbol ;
13550 BEGIN
13551 pSym := GetPsym(Sym) ;
13552 WITH pSym^ DO
13553 CASE SymbolType OF
13554
13555 ProcedureSym: WITH Procedure DO
13556 scope := ScopeQuad ;
13557 start := StartQuad ;
13558 end := EndQuad
13559 END
13560
13561 ELSE
13562 InternalError ('expecting a Procedure symbol')
13563 END
13564 END
13565 END GetProcedureQuads ;
13566
13567
13568 (*
13569 GetReadQuads - assigns Start and End to the beginning and end of
13570 symbol, Sym, read history usage.
13571 *)
13572
13573 PROCEDURE GetReadQuads (Sym: CARDINAL; m: ModeOfAddr;
13574 VAR Start, End: CARDINAL) ;
13575 BEGIN
13576 GetReadLimitQuads(Sym, m, 0, 0, Start, End)
13577 END GetReadQuads ;
13578
13579
13580 (*
13581 GetWriteQuads - assigns Start and End to the beginning and end of
13582 symbol, Sym, usage.
13583 *)
13584
13585 PROCEDURE GetWriteQuads (Sym: CARDINAL; m: ModeOfAddr;
13586 VAR Start, End: CARDINAL) ;
13587 BEGIN
13588 GetWriteLimitQuads(Sym, m, 0, 0, Start, End)
13589 END GetWriteQuads ;
13590
13591
13592 (*
13593 PutProcedureBegin - assigns begin as the token number matching the
13594 procedure BEGIN.
13595 *)
13596
13597 PROCEDURE PutProcedureBegin (Sym: CARDINAL; begin: CARDINAL) ;
13598 VAR
13599 pSym: PtrToSymbol ;
13600 BEGIN
13601 pSym := GetPsym(Sym) ;
13602 WITH pSym^ DO
13603 CASE SymbolType OF
13604
13605 ProcedureSym: Procedure.Begin := begin
13606
13607 ELSE
13608 InternalError ('expecting a Procedure symbol')
13609 END
13610 END
13611 END PutProcedureBegin ;
13612
13613
13614 (*
13615 PutProcedureEnd - assigns end as the token number matching the
13616 procedure END.
13617 *)
13618
13619 PROCEDURE PutProcedureEnd (Sym: CARDINAL; end: CARDINAL) ;
13620 VAR
13621 pSym: PtrToSymbol ;
13622 BEGIN
13623 pSym := GetPsym(Sym) ;
13624 WITH pSym^ DO
13625 CASE SymbolType OF
13626
13627 ProcedureSym: Procedure.End := end
13628
13629 ELSE
13630 InternalError ('expecting a Procedure symbol')
13631 END
13632 END
13633 END PutProcedureEnd ;
13634
13635
13636 (*
13637 GetProcedureBeginEnd - assigns, begin, end, to the stored token values.
13638 *)
13639
13640 PROCEDURE GetProcedureBeginEnd (Sym: CARDINAL; VAR begin, end: CARDINAL) ;
13641 VAR
13642 pSym: PtrToSymbol ;
13643 BEGIN
13644 pSym := GetPsym(Sym) ;
13645 WITH pSym^ DO
13646 CASE SymbolType OF
13647
13648 ProcedureSym: begin := Procedure.Begin ;
13649 end := Procedure.End
13650
13651 ELSE
13652 InternalError ('expecting a Procedure symbol')
13653 END
13654 END
13655 END GetProcedureBeginEnd ;
13656
13657
13658 (*
13659 Max -
13660 *)
13661
13662 PROCEDURE Max (a, b: CARDINAL) : CARDINAL ;
13663 BEGIN
13664 IF a>b
13665 THEN
13666 RETURN( a )
13667 ELSE
13668 RETURN( b )
13669 END
13670 END Max ;
13671
13672
13673 (*
13674 Min -
13675 *)
13676
13677 PROCEDURE Min (a, b: CARDINAL) : CARDINAL ;
13678 BEGIN
13679 IF a<b
13680 THEN
13681 RETURN( a )
13682 ELSE
13683 RETURN( b )
13684 END
13685 END Min ;
13686
13687
13688 (*
13689 GetQuads - assigns Start and End to the beginning and end of
13690 symbol, Sym, usage.
13691 *)
13692
13693 PROCEDURE GetQuads (Sym: CARDINAL; m: ModeOfAddr; VAR Start, End: CARDINAL) ;
13694 VAR
13695 StartRead, EndRead,
13696 StartWrite, EndWrite: CARDINAL ;
13697 BEGIN
13698 GetReadQuads(Sym, m, StartRead, EndRead) ;
13699 GetWriteQuads(Sym, m, StartWrite, EndWrite) ;
13700 IF StartRead=0
13701 THEN
13702 Start := StartWrite
13703 ELSIF StartWrite=0
13704 THEN
13705 Start := StartRead
13706 ELSE
13707 Start := Min(StartRead, StartWrite)
13708 END ;
13709 IF EndRead=0
13710 THEN
13711 End := EndWrite
13712 ELSIF EndWrite=0
13713 THEN
13714 End := EndRead
13715 ELSE
13716 End := Max(EndRead, EndWrite)
13717 END
13718 END GetQuads ;
13719
13720
13721 (*
13722 PutReadQuad - places Quad into the list of symbol usage.
13723 *)
13724
13725 PROCEDURE PutReadQuad (Sym: CARDINAL; m: ModeOfAddr; Quad: CARDINAL) ;
13726 VAR
13727 pSym: PtrToSymbol ;
13728 BEGIN
13729 pSym := GetPsym(Sym) ;
13730 WITH pSym^ DO
13731 CASE SymbolType OF
13732
13733 VarSym: IncludeItemIntoList(Var.ReadUsageList[m], Quad)
13734
13735 ELSE
13736 InternalError ('expecting a Var symbol')
13737 END
13738 END
13739 END PutReadQuad ;
13740
13741
13742 (*
13743 RemoveReadQuad - places Quad into the list of symbol usage.
13744 *)
13745
13746 PROCEDURE RemoveReadQuad (Sym: CARDINAL; m: ModeOfAddr; Quad: CARDINAL) ;
13747 VAR
13748 pSym: PtrToSymbol ;
13749 BEGIN
13750 pSym := GetPsym(Sym) ;
13751 WITH pSym^ DO
13752 CASE SymbolType OF
13753
13754 VarSym: RemoveItemFromList(Var.ReadUsageList[m], Quad)
13755
13756 ELSE
13757 InternalError ('expecting a Var symbol')
13758 END
13759 END
13760 END RemoveReadQuad ;
13761
13762
13763 (*
13764 PutWriteQuad - places Quad into the list of symbol usage.
13765 *)
13766
13767 PROCEDURE PutWriteQuad (Sym: CARDINAL; m: ModeOfAddr; Quad: CARDINAL) ;
13768 VAR
13769 pSym: PtrToSymbol ;
13770 BEGIN
13771 pSym := GetPsym(Sym) ;
13772 WITH pSym^ DO
13773 CASE SymbolType OF
13774
13775 VarSym: IncludeItemIntoList(Var.WriteUsageList[m], Quad)
13776
13777 ELSE
13778 InternalError ('expecting a Var symbol')
13779 END
13780 END
13781 END PutWriteQuad ;
13782
13783
13784 (*
13785 RemoveWriteQuad - places Quad into the list of symbol usage.
13786 *)
13787
13788 PROCEDURE RemoveWriteQuad (Sym: CARDINAL; m: ModeOfAddr; Quad: CARDINAL) ;
13789 VAR
13790 pSym: PtrToSymbol ;
13791 BEGIN
13792 pSym := GetPsym(Sym) ;
13793 WITH pSym^ DO
13794 CASE SymbolType OF
13795
13796 VarSym: RemoveItemFromList(Var.WriteUsageList[m], Quad)
13797
13798 ELSE
13799 InternalError ('expecting a Var symbol')
13800 END
13801 END
13802 END RemoveWriteQuad ;
13803
13804
13805 (*
13806 DoFindLimits - assigns, Start, and, End, to the start and end
13807 limits contained in the list, l. It ensures that
13808 Start and End are within StartLimit..EndLimit.
13809 If StartLimit or EndLimit are 0 then Start is
13810 is set to the first value and End to the last.
13811 *)
13812
13813 PROCEDURE DoFindLimits (StartLimit, EndLimit: CARDINAL;
13814 VAR Start, End: CARDINAL; l: List) ;
13815 VAR
13816 i, j, n: CARDINAL ;
13817 BEGIN
13818 End := 0 ;
13819 Start := 0 ;
13820 i := 1 ;
13821 n := NoOfItemsInList(l) ;
13822 WHILE i<=n DO
13823 j := GetItemFromList(l, i) ;
13824 IF (j>End) AND (j>=StartLimit) AND ((j<=EndLimit) OR (EndLimit=0))
13825 THEN
13826 End := j
13827 END ;
13828 IF ((Start=0) OR (j<Start)) AND (j#0) AND (j>=StartLimit) AND
13829 ((j<=EndLimit) OR (EndLimit=0))
13830 THEN
13831 Start := j
13832 END ;
13833 INC(i)
13834 END
13835 END DoFindLimits ;
13836
13837
13838 (*
13839 GetReadLimitQuads - returns Start and End which have been assigned
13840 the start and end of when the symbol was read
13841 to within: StartLimit..EndLimit.
13842 *)
13843
13844 PROCEDURE GetReadLimitQuads (Sym: CARDINAL; m: ModeOfAddr;
13845 StartLimit, EndLimit: CARDINAL;
13846 VAR Start, End: CARDINAL) ;
13847 VAR
13848 pSym: PtrToSymbol ;
13849 BEGIN
13850 pSym := GetPsym(Sym) ;
13851 WITH pSym^ DO
13852 CASE SymbolType OF
13853
13854 VarSym: DoFindLimits(StartLimit, EndLimit, Start, End,
13855 Var.ReadUsageList[m])
13856
13857 ELSE
13858 InternalError ('expecting a Var symbol')
13859 END
13860 END
13861 END GetReadLimitQuads ;
13862
13863
13864 (*
13865 GetWriteLimitQuads - returns Start and End which have been assigned
13866 the start and end of when the symbol was written
13867 to within: StartLimit..EndLimit.
13868 *)
13869
13870 PROCEDURE GetWriteLimitQuads (Sym: CARDINAL; m: ModeOfAddr;
13871 StartLimit, EndLimit: CARDINAL;
13872 VAR Start, End: CARDINAL) ;
13873 VAR
13874 pSym: PtrToSymbol ;
13875 BEGIN
13876 pSym := GetPsym(Sym) ;
13877 WITH pSym^ DO
13878 CASE SymbolType OF
13879
13880 VarSym : DoFindLimits(StartLimit, EndLimit, Start, End,
13881 Var.WriteUsageList[m])
13882
13883 ELSE
13884 InternalError ('expecting a Var symbol')
13885 END
13886 END
13887 END GetWriteLimitQuads ;
13888
13889
13890 (*
13891 GetNthProcedure - Returns the Nth procedure in Module, Sym.
13892 *)
13893
13894 PROCEDURE GetNthProcedure (Sym: CARDINAL; n: CARDINAL) : CARDINAL ;
13895 VAR
13896 pSym: PtrToSymbol ;
13897 BEGIN
13898 pSym := GetPsym(Sym) ;
13899 WITH pSym^ DO
13900 CASE SymbolType OF
13901
13902 DefImpSym: RETURN( GetItemFromList(DefImp.ListOfProcs, n) ) |
13903 ModuleSym: RETURN( GetItemFromList(Module.ListOfProcs, n) )
13904
13905 ELSE
13906 InternalError ('expecting a DefImp or Module symbol')
13907 END
13908 END
13909 END GetNthProcedure ;
13910
13911
13912 (*
13913 GetDeclaredDefinition - returns the token where this symbol
13914 was declared in the definition module.
13915 *)
13916
13917 PROCEDURE GetDeclaredDefinition (Sym: CARDINAL) : CARDINAL ;
13918 VAR
13919 pSym: PtrToSymbol ;
13920 BEGIN
13921 pSym := GetPsym(Sym) ;
13922 WITH pSym^ DO
13923 CASE SymbolType OF
13924
13925 ErrorSym : RETURN( Error.At.DefDeclared ) |
13926 ObjectSym : RETURN( Object.At.DefDeclared ) |
13927 VarientSym : RETURN( Varient.At.DefDeclared ) |
13928 RecordSym : RETURN( Record.At.DefDeclared ) |
13929 SubrangeSym : RETURN( Subrange.At.DefDeclared ) |
13930 EnumerationSym : RETURN( Enumeration.At.DefDeclared ) |
13931 ArraySym : RETURN( Array.At.DefDeclared ) |
13932 SubscriptSym : RETURN( Subscript.At.DefDeclared ) |
13933 UnboundedSym : RETURN( Unbounded.At.DefDeclared ) |
13934 ProcedureSym : RETURN( Procedure.At.DefDeclared ) |
13935 ProcTypeSym : RETURN( ProcType.At.DefDeclared ) |
13936 ParamSym : RETURN( Param.At ) |
13937 VarParamSym : RETURN( VarParam.At ) |
13938 ConstStringSym : RETURN( ConstString.At.DefDeclared ) |
13939 ConstLitSym : RETURN( ConstLit.At.DefDeclared ) |
13940 ConstVarSym : RETURN( ConstVar.At.DefDeclared ) |
13941 VarSym : RETURN( Var.At.DefDeclared ) |
13942 TypeSym : RETURN( Type.At.DefDeclared ) |
13943 PointerSym : RETURN( Pointer.At.DefDeclared ) |
13944 RecordFieldSym : RETURN( RecordField.At.DefDeclared ) |
13945 VarientFieldSym : RETURN( VarientField.At.DefDeclared ) |
13946 EnumerationFieldSym: RETURN( EnumerationField.At.DefDeclared ) |
13947 SetSym : RETURN( Set.At.DefDeclared ) |
13948 DefImpSym : RETURN( DefImp.At.DefDeclared ) |
13949 ModuleSym : RETURN( Module.At.DefDeclared ) |
13950 UndefinedSym : RETURN( GetFirstUsed(Sym) ) |
13951 ImportSym : RETURN( Import.at.DefDeclared ) |
13952 ImportStatementSym : RETURN( ImportStatement.at.DefDeclared ) |
13953 PartialUnboundedSym: RETURN( GetDeclaredDefinition(PartialUnbounded.Type) )
13954
13955 ELSE
13956 InternalError ('not expecting this type of symbol')
13957 END
13958 END
13959 END GetDeclaredDefinition ;
13960
13961
13962 (*
13963 GetDeclaredModule - returns the token where this symbol was declared
13964 in an implementation or program module.
13965 *)
13966
13967 PROCEDURE GetDeclaredModule (Sym: CARDINAL) : CARDINAL ;
13968 VAR
13969 pSym: PtrToSymbol ;
13970 BEGIN
13971 pSym := GetPsym(Sym) ;
13972 WITH pSym^ DO
13973 CASE SymbolType OF
13974
13975 ErrorSym : RETURN( Error.At.ModDeclared ) |
13976 ObjectSym : RETURN( Object.At.ModDeclared ) |
13977 VarientSym : RETURN( Varient.At.ModDeclared ) |
13978 RecordSym : RETURN( Record.At.ModDeclared ) |
13979 SubrangeSym : RETURN( Subrange.At.ModDeclared ) |
13980 EnumerationSym : RETURN( Enumeration.At.ModDeclared ) |
13981 ArraySym : RETURN( Array.At.ModDeclared ) |
13982 SubscriptSym : RETURN( Subscript.At.ModDeclared ) |
13983 UnboundedSym : RETURN( Unbounded.At.ModDeclared ) |
13984 ProcedureSym : RETURN( Procedure.At.ModDeclared ) |
13985 ProcTypeSym : RETURN( ProcType.At.ModDeclared ) |
13986 ParamSym : RETURN( Param.At ) |
13987 VarParamSym : RETURN( VarParam.At ) |
13988 ConstStringSym : RETURN( ConstString.At.ModDeclared ) |
13989 ConstLitSym : RETURN( ConstLit.At.ModDeclared ) |
13990 ConstVarSym : RETURN( ConstVar.At.ModDeclared ) |
13991 VarSym : RETURN( Var.At.ModDeclared ) |
13992 TypeSym : RETURN( Type.At.ModDeclared ) |
13993 PointerSym : RETURN( Pointer.At.ModDeclared ) |
13994 RecordFieldSym : RETURN( RecordField.At.ModDeclared ) |
13995 VarientFieldSym : RETURN( VarientField.At.ModDeclared ) |
13996 EnumerationFieldSym: RETURN( EnumerationField.At.ModDeclared ) |
13997 SetSym : RETURN( Set.At.ModDeclared ) |
13998 DefImpSym : RETURN( DefImp.At.ModDeclared ) |
13999 ModuleSym : RETURN( Module.At.ModDeclared ) |
14000 UndefinedSym : RETURN( GetFirstUsed(Sym) ) |
14001 ImportSym : RETURN( Import.at.ModDeclared ) |
14002 ImportStatementSym : RETURN( ImportStatement.at.ModDeclared ) |
14003 PartialUnboundedSym: RETURN( GetDeclaredModule(PartialUnbounded.Type) )
14004
14005 ELSE
14006 InternalError ('not expecting this type of symbol')
14007 END
14008 END
14009 END GetDeclaredModule ;
14010
14011
14012 (*
14013 PutDeclaredDefinition - associates the current tokenno with
14014 the symbols declaration in the definition
14015 module.
14016 *)
14017
14018 PROCEDURE PutDeclaredDefinition (tok: CARDINAL; Sym: CARDINAL) ;
14019 VAR
14020 pSym: PtrToSymbol ;
14021 BEGIN
14022 pSym := GetPsym(Sym) ;
14023 WITH pSym^ DO
14024 CASE SymbolType OF
14025
14026 ErrorSym : Error.At.DefDeclared := tok |
14027 ObjectSym : Object.At.DefDeclared := tok |
14028 VarientSym : Varient.At.DefDeclared := tok |
14029 RecordSym : Record.At.DefDeclared := tok |
14030 SubrangeSym : Subrange.At.DefDeclared := tok |
14031 EnumerationSym : Enumeration.At.DefDeclared := tok |
14032 ArraySym : Array.At.DefDeclared := tok |
14033 SubscriptSym : Subscript.At.DefDeclared := tok |
14034 UnboundedSym : Unbounded.At.DefDeclared := tok |
14035 ProcedureSym : Procedure.At.DefDeclared := tok |
14036 ProcTypeSym : ProcType.At.DefDeclared := tok |
14037 ConstStringSym : ConstString.At.DefDeclared := tok |
14038 ConstLitSym : ConstLit.At.DefDeclared := tok |
14039 ConstVarSym : ConstVar.At.DefDeclared := tok |
14040 VarSym : Var.At.DefDeclared := tok |
14041 TypeSym : Type.At.DefDeclared := tok |
14042 PointerSym : Pointer.At.DefDeclared := tok |
14043 RecordFieldSym : RecordField.At.DefDeclared := tok |
14044 VarientFieldSym : VarientField.At.DefDeclared := tok |
14045 EnumerationFieldSym: EnumerationField.At.DefDeclared := tok |
14046 SetSym : Set.At.DefDeclared := tok |
14047 DefImpSym : DefImp.At.DefDeclared := tok |
14048 ModuleSym : Module.At.DefDeclared := tok |
14049 UndefinedSym : |
14050 PartialUnboundedSym: PutDeclaredDefinition(tok, PartialUnbounded.Type)
14051
14052 ELSE
14053 InternalError ('not expecting this type of symbol')
14054 END
14055 END
14056 END PutDeclaredDefinition ;
14057
14058
14059 (*
14060 PutDeclaredModule - returns the token where this symbol was declared
14061 in an implementation or program module.
14062 *)
14063
14064 PROCEDURE PutDeclaredModule (tok: CARDINAL; Sym: CARDINAL) ;
14065 VAR
14066 pSym: PtrToSymbol ;
14067 BEGIN
14068 pSym := GetPsym(Sym) ;
14069 WITH pSym^ DO
14070 CASE SymbolType OF
14071
14072 ErrorSym : Error.At.ModDeclared := tok |
14073 ObjectSym : Object.At.ModDeclared := tok |
14074 VarientSym : Varient.At.ModDeclared := tok |
14075 RecordSym : Record.At.ModDeclared := tok |
14076 SubrangeSym : Subrange.At.ModDeclared := tok |
14077 EnumerationSym : Enumeration.At.ModDeclared := tok |
14078 ArraySym : Array.At.ModDeclared := tok |
14079 SubscriptSym : Subscript.At.ModDeclared := tok |
14080 UnboundedSym : Unbounded.At.ModDeclared := tok |
14081 ProcedureSym : Procedure.At.ModDeclared := tok |
14082 ProcTypeSym : ProcType.At.ModDeclared := tok |
14083 ConstStringSym : ConstString.At.ModDeclared := tok |
14084 ConstLitSym : ConstLit.At.ModDeclared := tok |
14085 ConstVarSym : ConstVar.At.ModDeclared := tok |
14086 VarSym : Var.At.ModDeclared := tok |
14087 TypeSym : Type.At.ModDeclared := tok |
14088 PointerSym : Pointer.At.ModDeclared := tok |
14089 RecordFieldSym : RecordField.At.ModDeclared := tok |
14090 VarientFieldSym : VarientField.At.ModDeclared := tok |
14091 EnumerationFieldSym: EnumerationField.At.ModDeclared := tok |
14092 SetSym : Set.At.ModDeclared := tok |
14093 DefImpSym : DefImp.At.ModDeclared := tok |
14094 ModuleSym : Module.At.ModDeclared := tok |
14095 UndefinedSym : |
14096 PartialUnboundedSym: PutDeclaredModule(tok, PartialUnbounded.Type)
14097
14098 ELSE
14099 InternalError ('not expecting this type of symbol')
14100 END
14101 END
14102 END PutDeclaredModule ;
14103
14104
14105 (*
14106 PutDeclared - adds an entry to symbol, Sym, indicating that it
14107 was declared at, tok. This routine
14108 may be called twice, once for definition module
14109 partial declaration and once when parsing the
14110 implementation module.
14111 *)
14112
14113 PROCEDURE PutDeclared (tok: CARDINAL; Sym: CARDINAL) ;
14114 BEGIN
14115 IF CompilingDefinitionModule ()
14116 THEN
14117 PutDeclaredDefinition (tok, Sym)
14118 ELSE
14119 PutDeclaredModule (tok, Sym)
14120 END
14121 END PutDeclared ;
14122
14123
14124 (*
14125 GetDeclaredDef - returns the tokenno where the symbol was declared
14126 in the definition module. UnknownTokenNo is returned
14127 if no declaration occurred.
14128 *)
14129
14130 PROCEDURE GetDeclaredDef (Sym: CARDINAL) : CARDINAL ;
14131 BEGIN
14132 RETURN GetDeclaredDefinition (Sym)
14133 END GetDeclaredDef ;
14134
14135
14136 (*
14137 GetDeclaredMod - returns the tokenno where the symbol was declared.
14138 in the program or implementation module.
14139 UnknownTokenNo is returned if no declaration occurred.
14140 *)
14141
14142 PROCEDURE GetDeclaredMod (Sym: CARDINAL) : CARDINAL ;
14143 BEGIN
14144 RETURN GetDeclaredModule (Sym)
14145 END GetDeclaredMod ;
14146
14147
14148 (*
14149 GetDeclaredFor - returns the token where this forward procedure symbol
14150 was declared in the program or implementation module.
14151 UnknownTokenNo is returned if no declaration occurred.
14152 *)
14153
14154 PROCEDURE GetDeclaredFor (Sym: CARDINAL) : CARDINAL ;
14155 BEGIN
14156 IF IsProcedure (Sym)
14157 THEN
14158 RETURN GetProcedureDeclaredTok (Sym, ForwardProcedure)
14159 ELSE
14160 RETURN UnknownTokenNo
14161 END
14162 END GetDeclaredFor ;
14163
14164
14165 (*
14166 GetProcedureKind - returns the procedure kind given the declaration tok.
14167 The declaration tok must match the ident tok in the
14168 procedure name. It is only safe to call this
14169 procedure function during pass 2 onwards.
14170 *)
14171
14172 PROCEDURE GetProcedureKind (sym: CARDINAL; tok: CARDINAL) : ProcedureKind ;
14173 VAR
14174 kind: ProcedureKind ;
14175 pSym: PtrToSymbol ;
14176 BEGIN
14177 pSym := GetPsym (sym) ;
14178 WITH pSym^ DO
14179 CASE SymbolType OF
14180
14181 ProcedureSym: FOR kind := MIN (ProcedureKind) TO MAX (ProcedureKind) DO
14182 IF Procedure.Decl[kind].ProcedureTok = tok
14183 THEN
14184 RETURN kind
14185 END
14186 END |
14187 ProcTypeSym: RETURN ProperProcedure
14188
14189 ELSE
14190 InternalError ('expecting ProcedureSym symbol')
14191 END
14192 END ;
14193 InternalError ('ProcedureSym kind has not yet been declared')
14194 END GetProcedureKind ;
14195
14196
14197 (*
14198 GetProcedureDeclaredTok - return the token where the
14199 declaration of procedure sym:kind
14200 occurred.
14201 *)
14202
14203 PROCEDURE GetProcedureDeclaredTok (sym: CARDINAL; kind: ProcedureKind) : CARDINAL ;
14204 VAR
14205 pSym: PtrToSymbol ;
14206 BEGIN
14207 pSym := GetPsym (sym) ;
14208 WITH pSym^ DO
14209 CASE SymbolType OF
14210
14211 ProcedureSym: RETURN Procedure.Decl[kind].ProcedureTok
14212
14213 ELSE
14214 InternalError ('expecting procedure symbol')
14215 END
14216 END
14217 END GetProcedureDeclaredTok ;
14218
14219
14220 (*
14221 PutProcedureDeclaredTok - places the tok where the
14222 declaration of procedure sym:kind
14223 occurred.
14224 *)
14225
14226 PROCEDURE PutProcedureDeclaredTok (sym: CARDINAL; kind: ProcedureKind;
14227 tok: CARDINAL) ;
14228 VAR
14229 pSym: PtrToSymbol ;
14230 BEGIN
14231 pSym := GetPsym (sym) ;
14232 WITH pSym^ DO
14233 CASE SymbolType OF
14234
14235 ProcedureSym: Procedure.Decl[kind].ProcedureTok := tok
14236
14237 ELSE
14238 InternalError ('expecting procedure symbol')
14239 END
14240 END
14241 END PutProcedureDeclaredTok ;
14242
14243
14244 (*
14245 GetReturnTypeTok - return the token where the
14246 return type procedure sym:kind or proctype
14247 was defined.
14248 *)
14249
14250 PROCEDURE GetReturnTypeTok (sym: CARDINAL; kind: ProcedureKind) : CARDINAL ;
14251 VAR
14252 pSym: PtrToSymbol ;
14253 BEGIN
14254 pSym := GetPsym (sym) ;
14255 WITH pSym^ DO
14256 CASE SymbolType OF
14257
14258 ProcedureSym: RETURN Procedure.Decl[kind].ReturnTypeTok |
14259 ProcTypeSym : RETURN ProcType.ReturnTypeTok
14260
14261 ELSE
14262 InternalError ('expecting procedure symbol')
14263 END
14264 END
14265 END GetReturnTypeTok ;
14266
14267
14268 (*
14269 PutReturnTypeTok - places the tok where the
14270 return type of procedure sym:kind or proctype
14271 was defined.
14272 *)
14273
14274 PROCEDURE PutReturnTypeTok (sym: CARDINAL; kind: ProcedureKind;
14275 tok: CARDINAL) ;
14276 VAR
14277 pSym: PtrToSymbol ;
14278 BEGIN
14279 pSym := GetPsym (sym) ;
14280 WITH pSym^ DO
14281 CASE SymbolType OF
14282
14283 ProcedureSym: Procedure.Decl[kind].ReturnTypeTok := tok |
14284 ProcTypeSym : ProcType.ReturnTypeTok := tok
14285
14286 ELSE
14287 InternalError ('expecting procedure symbol')
14288 END
14289 END
14290 END PutReturnTypeTok ;
14291
14292
14293 (*
14294 GetProcedureKindDesc - return a string describing kind.
14295 *)
14296
14297 PROCEDURE GetProcedureKindDesc (kind: ProcedureKind) : String ;
14298 BEGIN
14299 IF kind = ProperProcedure
14300 THEN
14301 RETURN InitString ('proper procedure')
14302 ELSIF kind = ForwardProcedure
14303 THEN
14304 RETURN InitString ('forward procedure')
14305 ELSIF kind = DefProcedure
14306 THEN
14307 RETURN InitString ('definition procedure')
14308 END ;
14309 InternalError ('unknown kind value')
14310 END GetProcedureKindDesc ;
14311
14312
14313 (*
14314 GetFirstUsed - returns the token where this symbol was first used.
14315 *)
14316
14317 PROCEDURE GetFirstUsed (Sym: CARDINAL) : CARDINAL ;
14318 VAR
14319 pSym: PtrToSymbol ;
14320 BEGIN
14321 pSym := GetPsym (Sym) ;
14322 WITH pSym^ DO
14323 CASE SymbolType OF
14324
14325 ErrorSym : RETURN( Error.At.FirstUsed ) |
14326 ObjectSym : RETURN( Object.At.FirstUsed ) |
14327 UndefinedSym : RETURN( Undefined.At.FirstUsed ) |
14328 VarientSym : RETURN( Varient.At.FirstUsed ) |
14329 RecordSym : RETURN( Record.At.FirstUsed ) |
14330 SubrangeSym : RETURN( Subrange.At.FirstUsed ) |
14331 EnumerationSym : RETURN( Enumeration.At.FirstUsed ) |
14332 ArraySym : RETURN( Array.At.FirstUsed ) |
14333 SubscriptSym : RETURN( Subscript.At.FirstUsed ) |
14334 UnboundedSym : RETURN( Unbounded.At.FirstUsed ) |
14335 ProcedureSym : RETURN( Procedure.At.FirstUsed ) |
14336 ProcTypeSym : RETURN( ProcType.At.FirstUsed ) |
14337 (*
14338 ParamSym : RETURN( Param.At.FirstUsed ) |
14339 VarParamSym : RETURN( VarParam.At.FirstUsed ) |
14340 *)
14341 ConstStringSym : RETURN( ConstString.At.FirstUsed ) |
14342 ConstLitSym : RETURN( ConstLit.At.FirstUsed ) |
14343 ConstVarSym : RETURN( ConstVar.At.FirstUsed ) |
14344 VarSym : RETURN( Var.At.FirstUsed ) |
14345 TypeSym : RETURN( Type.At.FirstUsed ) |
14346 PointerSym : RETURN( Pointer.At.FirstUsed ) |
14347 RecordFieldSym : RETURN( RecordField.At.FirstUsed ) |
14348 VarientFieldSym : RETURN( VarientField.At.FirstUsed ) |
14349 EnumerationFieldSym: RETURN( EnumerationField.At.FirstUsed ) |
14350 SetSym : RETURN( Set.At.FirstUsed ) |
14351 DefImpSym : RETURN( DefImp.At.FirstUsed ) |
14352 ModuleSym : RETURN( Module.At.FirstUsed )
14353
14354 ELSE
14355 InternalError ('not expecting this type of symbol')
14356 END
14357 END
14358 END GetFirstUsed ;
14359
14360
14361 (*
14362 ForeachProcedureDo - for each procedure in module, Sym, do procedure, P.
14363 *)
14364
14365 PROCEDURE ForeachProcedureDo (Sym: CARDINAL; P: PerformOperation) ;
14366 VAR
14367 pSym: PtrToSymbol ;
14368 BEGIN
14369 pSym := GetPsym(Sym) ;
14370 WITH pSym^ DO
14371 CASE SymbolType OF
14372
14373 DefImpSym : ForeachItemInListDo( DefImp.ListOfProcs, P) |
14374 ModuleSym : ForeachItemInListDo( Module.ListOfProcs, P) |
14375 ProcedureSym: ForeachItemInListDo( Procedure.ListOfProcs, P)
14376
14377 ELSE
14378 InternalError ('expecting DefImp or Module symbol')
14379 END
14380 END
14381 END ForeachProcedureDo ;
14382
14383
14384 (*
14385 ForeachInnerModuleDo - for each inner module in module, Sym,
14386 do procedure, P.
14387 *)
14388
14389 PROCEDURE ForeachInnerModuleDo (Sym: CARDINAL; P: PerformOperation) ;
14390 VAR
14391 pSym: PtrToSymbol ;
14392 BEGIN
14393 pSym := GetPsym(Sym) ;
14394 WITH pSym^ DO
14395 CASE SymbolType OF
14396
14397 DefImpSym : ForeachItemInListDo( DefImp.ListOfModules, P) |
14398 ModuleSym : ForeachItemInListDo( Module.ListOfModules, P) |
14399 ProcedureSym: ForeachItemInListDo( Procedure.ListOfModules, P)
14400
14401 ELSE
14402 InternalError ('expecting DefImp or Module symbol')
14403 END
14404 END
14405 END ForeachInnerModuleDo ;
14406
14407
14408 (*
14409 ForeachModuleDo - for each module do procedure, P.
14410 *)
14411
14412 PROCEDURE ForeachModuleDo (P: PerformOperation) ;
14413 BEGIN
14414 ForeachNodeDo (ModuleTree, P)
14415 END ForeachModuleDo ;
14416
14417
14418 (*
14419 ForeachFieldEnumerationDo - for each field in enumeration, Sym,
14420 do procedure, P. Each call to P contains
14421 an enumeration field, the order is alphabetical.
14422 Use ForeachLocalSymDo for declaration order.
14423 *)
14424
14425 PROCEDURE ForeachFieldEnumerationDo (Sym: CARDINAL; P: PerformOperation) ;
14426 VAR
14427 pSym: PtrToSymbol ;
14428 BEGIN
14429 pSym := GetPsym(Sym) ;
14430 WITH pSym^ DO
14431 CASE SymbolType OF
14432
14433 EnumerationSym: ForeachNodeDo (Enumeration.LocalSymbols, P)
14434
14435 ELSE
14436 InternalError ('expecting Enumeration symbol')
14437 END
14438 END
14439 END ForeachFieldEnumerationDo ;
14440
14441
14442 (*
14443 IsProcedureReachable - Returns true if the procedure, Sym, is
14444 reachable from the main Module.
14445 *)
14446
14447 PROCEDURE IsProcedureReachable (Sym: CARDINAL) : BOOLEAN ;
14448 VAR
14449 pSym: PtrToSymbol ;
14450 BEGIN
14451 pSym := GetPsym(Sym) ;
14452 WITH pSym^ DO
14453 CASE SymbolType OF
14454
14455 ProcedureSym: RETURN( Procedure.Reachable )
14456
14457 ELSE
14458 InternalError ('expecting Procedure symbol')
14459 END
14460 END
14461 END IsProcedureReachable ;
14462
14463
14464 (*
14465 IsProcType - returns true if Sym is a ProcType Symbol.
14466 *)
14467
14468 PROCEDURE IsProcType (Sym: CARDINAL) : BOOLEAN ;
14469 VAR
14470 pSym: PtrToSymbol ;
14471 BEGIN
14472 pSym := GetPsym(Sym) ;
14473 RETURN( pSym^.SymbolType=ProcTypeSym )
14474 END IsProcType ;
14475
14476
14477 (*
14478 IsVar - returns true if Sym is a Var Symbol.
14479 *)
14480
14481 PROCEDURE IsVar (Sym: CARDINAL) : BOOLEAN ;
14482 VAR
14483 pSym: PtrToSymbol ;
14484 BEGIN
14485 pSym := GetPsym(Sym) ;
14486 RETURN( pSym^.SymbolType=VarSym )
14487 END IsVar ;
14488
14489
14490 (*
14491 DoIsConst - returns TRUE if Sym is defined as a constant
14492 or is an enumeration field or string.
14493 *)
14494
14495 PROCEDURE DoIsConst (Sym: CARDINAL) : BOOLEAN ;
14496 VAR
14497 pSym: PtrToSymbol ;
14498 BEGIN
14499 pSym := GetPsym(Sym) ;
14500 WITH pSym^ DO
14501 RETURN( (SymbolType=ConstVarSym) OR
14502 (SymbolType=ConstLitSym) OR
14503 (SymbolType=ConstStringSym) OR
14504 ((SymbolType=VarSym) AND (Var.AddrMode=ImmediateValue)) OR
14505 (SymbolType=EnumerationFieldSym)
14506 )
14507 END
14508 END DoIsConst ;
14509
14510
14511 (*
14512 IsConst - returns true if Sym contains a constant value.
14513 *)
14514
14515 PROCEDURE IsConst (Sym: CARDINAL) : BOOLEAN ;
14516 BEGIN
14517 IF IsConstructor(Sym)
14518 THEN
14519 RETURN( IsConstructorConstant(Sym) )
14520 ELSE
14521 RETURN( DoIsConst(Sym) )
14522 END
14523 END IsConst ;
14524
14525
14526 (*
14527 IsConstString - returns whether sym is a conststring of any variant.
14528 *)
14529
14530 PROCEDURE IsConstString (sym: CARDINAL) : BOOLEAN ;
14531 VAR
14532 pSym: PtrToSymbol ;
14533 BEGIN
14534 pSym := GetPsym (sym) ;
14535 WITH pSym^ DO
14536 RETURN SymbolType = ConstStringSym
14537 END
14538 END IsConstString ;
14539
14540
14541 (*
14542 IsConstLit - returns true if Sym is a literal constant.
14543 *)
14544
14545 PROCEDURE IsConstLit (Sym: CARDINAL) : BOOLEAN ;
14546 VAR
14547 pSym: PtrToSymbol ;
14548 BEGIN
14549 pSym := GetPsym(Sym) ;
14550 WITH pSym^ DO
14551 RETURN( SymbolType=ConstLitSym )
14552 END
14553 END IsConstLit ;
14554
14555
14556 (*
14557 IsDummy - returns true if Sym is a Dummy symbol.
14558 *)
14559
14560 PROCEDURE IsDummy (Sym: CARDINAL) : BOOLEAN ;
14561 VAR
14562 pSym: PtrToSymbol ;
14563 BEGIN
14564 pSym := GetPsym(Sym) ;
14565 RETURN( pSym^.SymbolType=DummySym )
14566 END IsDummy ;
14567
14568
14569 (*
14570 IsTemporary - returns true if Sym is a Temporary symbol.
14571 *)
14572
14573 PROCEDURE IsTemporary (Sym: CARDINAL) : BOOLEAN ;
14574 VAR
14575 pSym: PtrToSymbol ;
14576 BEGIN
14577 pSym := GetPsym(Sym) ;
14578 WITH pSym^ DO
14579 CASE SymbolType OF
14580
14581 VarSym : RETURN( Var.IsTemp ) |
14582 ConstVarSym: RETURN( ConstVar.IsTemp )
14583
14584 ELSE
14585 RETURN( FALSE )
14586 END
14587 END
14588 END IsTemporary ;
14589
14590
14591 (*
14592 IsVarAParam - returns true if Sym is a variable declared as a parameter.
14593 *)
14594
14595 PROCEDURE IsVarAParam (Sym: CARDINAL) : BOOLEAN ;
14596 VAR
14597 pSym: PtrToSymbol ;
14598 BEGIN
14599 pSym := GetPsym(Sym) ;
14600 WITH pSym^ DO
14601 CASE SymbolType OF
14602
14603 VarSym: RETURN( Var.IsParam )
14604
14605 ELSE
14606 RETURN( FALSE )
14607 END
14608 END
14609 END IsVarAParam ;
14610
14611
14612 (*
14613 IsSubscript - returns true if Sym is a subscript symbol.
14614 *)
14615
14616 PROCEDURE IsSubscript (Sym: CARDINAL) : BOOLEAN ;
14617 VAR
14618 pSym: PtrToSymbol ;
14619 BEGIN
14620 pSym := GetPsym(Sym) ;
14621 RETURN( pSym^.SymbolType=SubscriptSym )
14622 END IsSubscript ;
14623
14624
14625 (*
14626 IsSubrange - returns true if Sym is a subrange symbol.
14627 *)
14628
14629 PROCEDURE IsSubrange (Sym: CARDINAL) : BOOLEAN ;
14630 VAR
14631 pSym: PtrToSymbol ;
14632 BEGIN
14633 pSym := GetPsym(Sym) ;
14634 RETURN( pSym^.SymbolType=SubrangeSym )
14635 END IsSubrange ;
14636
14637
14638 (*
14639 IsProcedureVariable - returns true if a Sym is a variable and
14640 it was declared within a procedure.
14641 *)
14642
14643 PROCEDURE IsProcedureVariable (Sym: CARDINAL) : BOOLEAN ;
14644 BEGIN
14645 AssertInRange(Sym) ;
14646 RETURN( IsVar(Sym) AND IsProcedure(GetVarScope(Sym)) )
14647 END IsProcedureVariable ;
14648
14649
14650 (*
14651 IsProcedureNested - returns TRUE if procedure, Sym, was
14652 declared as a nested procedure.
14653 *)
14654
14655 PROCEDURE IsProcedureNested (Sym: CARDINAL) : BOOLEAN ;
14656 BEGIN
14657 RETURN( IsProcedure(Sym) AND (IsProcedure(GetScope(Sym))) )
14658 END IsProcedureNested ;
14659
14660
14661 (*
14662 IsAModula2Type - returns true if Sym, is a:
14663 IsType, IsPointer, IsRecord, IsEnumeration,
14664 IsSubrange, IsArray, IsUnbounded, IsProcType.
14665 NOTE that it different from IsType.
14666 *)
14667
14668 PROCEDURE IsAModula2Type (Sym: CARDINAL) : BOOLEAN ;
14669 BEGIN
14670 AssertInRange(Sym) ;
14671 RETURN(
14672 IsType(Sym) OR IsRecord(Sym) OR IsPointer(Sym) OR
14673 IsEnumeration(Sym) OR IsSubrange(Sym) OR IsArray(Sym) OR
14674 IsUnbounded(Sym) OR IsProcType(Sym) OR IsSet(Sym)
14675 )
14676 END IsAModula2Type ;
14677
14678
14679 (*
14680 IsGnuAsmVolatile - returns TRUE if a GnuAsm symbol was defined as VOLATILE.
14681 *)
14682
14683 PROCEDURE IsGnuAsmVolatile (Sym: CARDINAL) : BOOLEAN ;
14684 VAR
14685 pSym: PtrToSymbol ;
14686 BEGIN
14687 pSym := GetPsym(Sym) ;
14688 WITH pSym^ DO
14689 CASE SymbolType OF
14690
14691 GnuAsmSym: RETURN( GnuAsm.Volatile )
14692
14693 ELSE
14694 InternalError ('expecting GnuAsm symbol')
14695 END
14696 END
14697 END IsGnuAsmVolatile ;
14698
14699
14700 (*
14701 IsGnuAsmSimple - returns TRUE if a GnuAsm symbol is a simple kind.
14702 *)
14703
14704 PROCEDURE IsGnuAsmSimple (Sym: CARDINAL) : BOOLEAN ;
14705 VAR
14706 pSym: PtrToSymbol ;
14707 BEGIN
14708 pSym := GetPsym(Sym) ;
14709 WITH pSym^ DO
14710 CASE SymbolType OF
14711
14712 GnuAsmSym: RETURN( GnuAsm.Simple )
14713
14714 ELSE
14715 InternalError ('expecting GnuAsm symbol')
14716 END
14717 END
14718 END IsGnuAsmSimple ;
14719
14720
14721 (*
14722 IsGnuAsm - returns TRUE if Sym is a GnuAsm symbol.
14723 *)
14724
14725 PROCEDURE IsGnuAsm (Sym: CARDINAL) : BOOLEAN ;
14726 VAR
14727 pSym: PtrToSymbol ;
14728 BEGIN
14729 pSym := GetPsym(Sym) ;
14730 WITH pSym^ DO
14731 RETURN( SymbolType=GnuAsmSym )
14732 END
14733 END IsGnuAsm ;
14734
14735
14736 (*
14737 IsRegInterface - returns TRUE if Sym is a RegInterface symbol.
14738 *)
14739
14740 PROCEDURE IsRegInterface (Sym: CARDINAL) : BOOLEAN ;
14741 VAR
14742 pSym: PtrToSymbol ;
14743 BEGIN
14744 pSym := GetPsym(Sym) ;
14745 WITH pSym^ DO
14746 RETURN( SymbolType=InterfaceSym )
14747 END
14748 END IsRegInterface ;
14749
14750
14751 (*
14752 GetParam - returns the ParamNo parameter from procedure ProcSym
14753 *)
14754
14755 PROCEDURE GetParam (Sym: CARDINAL; ParamNo: CARDINAL) : CARDINAL ;
14756 BEGIN
14757 AssertInRange(Sym) ;
14758 IF ParamNo=0
14759 THEN
14760 (* Parameter Zero is the return argument for the Function *)
14761 RETURN(GetType(Sym))
14762 ELSE
14763 RETURN (GetNthParamAny (Sym, ParamNo))
14764 END
14765 END GetParam ;
14766
14767
14768 (*
14769 GetFromIndex - return a value from list, i, at position, n.
14770 *)
14771
14772 PROCEDURE GetFromIndex (i: Indexing.Index; n: CARDINAL) : CARDINAL ;
14773 VAR
14774 p: POINTER TO CARDINAL ;
14775 BEGIN
14776 p := Indexing.GetIndice(i, n) ;
14777 RETURN( p^ )
14778 END GetFromIndex ;
14779
14780
14781 (*
14782 PutIntoIndex - places value, v, into list, i, at position, n.
14783 *)
14784
14785 PROCEDURE PutIntoIndex (VAR i: Indexing.Index; n: CARDINAL; v: CARDINAL) ;
14786 VAR
14787 p: POINTER TO CARDINAL ;
14788 BEGIN
14789 NEW(p) ;
14790 p^ := v ;
14791 Indexing.PutIndice(i, n, p)
14792 END PutIntoIndex ;
14793
14794
14795 (*
14796 Make2Tuple - creates and returns a 2 tuple from, a, and, b.
14797 *)
14798
14799 PROCEDURE Make2Tuple (a, b: CARDINAL) : CARDINAL ;
14800 VAR
14801 pSym: PtrToSymbol ;
14802 Sym : CARDINAL ;
14803 BEGIN
14804 NewSym(Sym) ;
14805 pSym := GetPsym(Sym) ;
14806 WITH pSym^ DO
14807 SymbolType := TupleSym ;
14808 WITH Tuple DO
14809 nTuple := 2 ;
14810 list := Indexing.InitIndex(1) ;
14811 PutIntoIndex(list, 1, a) ;
14812 PutIntoIndex(list, 2, b) ;
14813 InitWhereDeclared(At) ;
14814 InitWhereFirstUsed(At)
14815 END
14816 END ;
14817 RETURN( Sym )
14818 END Make2Tuple ;
14819
14820
14821 (*
14822 IsSizeSolved - returns true if the size of Sym is solved.
14823 *)
14824
14825 PROCEDURE IsSizeSolved (Sym: CARDINAL) : BOOLEAN ;
14826 VAR
14827 pSym: PtrToSymbol ;
14828 BEGIN
14829 AssertInRange(Sym) ;
14830 pSym := GetPsym(Sym) ;
14831 WITH pSym^ DO
14832 CASE SymbolType OF
14833
14834 ProcedureSym : RETURN( IsSolved(Procedure.Size) ) |
14835 VarSym : RETURN( IsSolved(Var.Size) ) |
14836 TypeSym : RETURN( IsSolved(Type.Size) ) |
14837 SetSym : RETURN( IsSolved(Set.Size) ) |
14838 RecordSym : RETURN( IsSolved(Record.Size) ) |
14839 VarientSym : RETURN( IsSolved(Varient.Size) ) |
14840 EnumerationSym : RETURN( IsSolved(Enumeration.Size) ) |
14841 PointerSym : RETURN( IsSolved(Pointer.Size) ) |
14842 ArraySym : RETURN( IsSolved(Array.Size) ) |
14843 RecordFieldSym : RETURN( IsSolved(RecordField.Size) ) |
14844 VarientFieldSym : RETURN( IsSolved(VarientField.Size) ) |
14845 SubrangeSym : RETURN( IsSolved(Subrange.Size) ) |
14846 SubscriptSym : RETURN( IsSolved(Subscript.Size) ) |
14847 ProcTypeSym : RETURN( IsSolved(ProcType.Size) ) |
14848 UnboundedSym : RETURN( IsSolved(Unbounded.Size) )
14849
14850 ELSE
14851 InternalError ('not expecting this kind of symbol')
14852 END
14853 END
14854 END IsSizeSolved ;
14855
14856
14857 (*
14858 IsOffsetSolved - returns true if the Offset of Sym is solved.
14859 *)
14860
14861 PROCEDURE IsOffsetSolved (Sym: CARDINAL) : BOOLEAN ;
14862 VAR
14863 pSym: PtrToSymbol ;
14864 BEGIN
14865 AssertInRange(Sym) ;
14866 pSym := GetPsym(Sym) ;
14867 WITH pSym^ DO
14868 CASE SymbolType OF
14869
14870 VarSym : RETURN( IsSolved(Var.Offset) ) |
14871 RecordFieldSym : RETURN( IsSolved(RecordField.Offset) ) |
14872 VarientFieldSym : RETURN( IsSolved(VarientField.Offset) )
14873
14874 ELSE
14875 InternalError ('not expecting this kind of symbol')
14876 END
14877 END
14878 END IsOffsetSolved ;
14879
14880
14881 (*
14882 IsValueSolved - returns true if the value of Sym is solved.
14883 *)
14884
14885 PROCEDURE IsValueSolved (Sym: CARDINAL) : BOOLEAN ;
14886 VAR
14887 pSym: PtrToSymbol ;
14888 BEGIN
14889 AssertInRange(Sym) ;
14890 pSym := GetPsym(Sym) ;
14891 WITH pSym^ DO
14892 CASE SymbolType OF
14893
14894 ConstLitSym : RETURN( IsSolved(ConstLit.Value) ) |
14895 ConstVarSym : RETURN( IsSolved(ConstVar.Value) ) |
14896 EnumerationFieldSym : RETURN( IsSolved(EnumerationField.Value) ) |
14897 ConstStringSym : RETURN( TRUE )
14898
14899 ELSE
14900 InternalError ('not expecting this kind of symbol')
14901 END
14902 END
14903 END IsValueSolved ;
14904
14905
14906 (*
14907 IsConstructorConstant - returns TRUE if constructor, Sym, is
14908 defined by only constants.
14909 *)
14910
14911 PROCEDURE IsConstructorConstant (Sym: CARDINAL) : BOOLEAN ;
14912 VAR
14913 pSym: PtrToSymbol ;
14914 BEGIN
14915 IF IsConstructor(Sym) OR IsConstSet(Sym)
14916 THEN
14917 pSym := GetPsym(Sym) ;
14918 WITH pSym^ DO
14919 CASE SymbolType OF
14920
14921 ConstVarSym: RETURN( IsValueConst(ConstVar.Value) ) |
14922 ConstLitSym: RETURN( IsValueConst(ConstLit.Value) )
14923
14924 ELSE
14925 InternalError ('expecting Constructor')
14926 END
14927 END
14928 ELSE
14929 InternalError ('expecting Constructor')
14930 END
14931 END IsConstructorConstant ;
14932
14933
14934 (*
14935 IsComposite - returns TRUE if symbol, sym, is a composite
14936 type: ie an ARRAY or RECORD.
14937 *)
14938
14939 PROCEDURE IsComposite (sym: CARDINAL) : BOOLEAN ;
14940 BEGIN
14941 IF sym=NulSym
14942 THEN
14943 RETURN( FALSE )
14944 ELSE
14945 sym := SkipType(sym) ;
14946 RETURN( IsArray(sym) OR IsRecord(sym) )
14947 END
14948 END IsComposite ;
14949
14950
14951 (*
14952 IsSumOfParamSizeSolved - has the sum of parameters been solved yet?
14953 *)
14954
14955 PROCEDURE IsSumOfParamSizeSolved (Sym: CARDINAL) : BOOLEAN ;
14956 VAR
14957 pSym: PtrToSymbol ;
14958 BEGIN
14959 AssertInRange(Sym) ;
14960 pSym := GetPsym(Sym) ;
14961 WITH pSym^ DO
14962 CASE SymbolType OF
14963
14964 ProcedureSym: RETURN( IsSolved(Procedure.TotalParamSize) ) |
14965 ProcTypeSym : RETURN( IsSolved(ProcType.TotalParamSize) )
14966
14967 ELSE
14968 InternalError ('expecting Procedure or ProcType symbol')
14969 END
14970 END
14971 END IsSumOfParamSizeSolved ;
14972
14973
14974 (*
14975 PushSize - pushes the size of Sym.
14976 *)
14977
14978 PROCEDURE PushSize (Sym: CARDINAL) ;
14979 VAR
14980 pSym: PtrToSymbol ;
14981 BEGIN
14982 AssertInRange(Sym) ;
14983 pSym := GetPsym(Sym) ;
14984 WITH pSym^ DO
14985 CASE SymbolType OF
14986
14987 ProcedureSym : PushFrom(Procedure.Size) |
14988 VarSym : PushFrom(Var.Size) |
14989 TypeSym : PushFrom(Type.Size) |
14990 SetSym : PushFrom(Set.Size) |
14991 VarientSym : PushFrom(Varient.Size) |
14992 RecordSym : PushFrom(Record.Size) |
14993 EnumerationSym : PushFrom(Enumeration.Size) |
14994 PointerSym : PushFrom(Pointer.Size) |
14995 ArraySym : PushFrom(Array.Size) |
14996 RecordFieldSym : PushFrom(RecordField.Size) |
14997 VarientFieldSym : PushFrom(VarientField.Size) |
14998 SubrangeSym : PushFrom(Subrange.Size) |
14999 SubscriptSym : PushFrom(Subscript.Size) |
15000 ProcTypeSym : PushFrom(ProcType.Size) |
15001 UnboundedSym : PushFrom(Unbounded.Size)
15002
15003 ELSE
15004 InternalError ('not expecting this kind of symbol')
15005 END
15006 END
15007 END PushSize ;
15008
15009
15010 (*
15011 PopSize - pops the ALU stack into Size of Sym.
15012 *)
15013
15014 PROCEDURE PopSize (Sym: CARDINAL) ;
15015 VAR
15016 pSym: PtrToSymbol ;
15017 BEGIN
15018 AssertInRange(Sym) ;
15019 pSym := GetPsym(Sym) ;
15020 WITH pSym^ DO
15021 CASE SymbolType OF
15022
15023 ProcedureSym : PopInto(Procedure.Size) |
15024 VarSym : PopInto(Var.Size) |
15025 TypeSym : PopInto(Type.Size) |
15026 RecordSym : PopInto(Record.Size) |
15027 VarientSym : PopInto(Varient.Size) |
15028 EnumerationSym : PopInto(Enumeration.Size) |
15029 PointerSym : PopInto(Pointer.Size) |
15030 ArraySym : PopInto(Array.Size) |
15031 RecordFieldSym : PopInto(RecordField.Size) |
15032 VarientFieldSym : PopInto(VarientField.Size) |
15033 SubrangeSym : PopInto(Subrange.Size) |
15034 SubscriptSym : PopInto(Subscript.Size) |
15035 ProcTypeSym : PopInto(ProcType.Size) |
15036 UnboundedSym : PopInto(Unbounded.Size) |
15037 SetSym : PopInto(Set.Size)
15038
15039 ELSE
15040 InternalError ('not expecting this kind of symbol')
15041 END
15042 END
15043 END PopSize ;
15044
15045
15046 (*
15047 PushValue - pushes the Value of Sym onto the ALU stack.
15048 *)
15049
15050 PROCEDURE PushValue (Sym: CARDINAL) ;
15051 VAR
15052 pSym: PtrToSymbol ;
15053 BEGIN
15054 AssertInRange(Sym) ;
15055 pSym := GetPsym(Sym) ;
15056 WITH pSym^ DO
15057 CASE SymbolType OF
15058
15059 ConstLitSym : PushFrom(ConstLit.Value) |
15060 ConstVarSym : PushFrom(ConstVar.Value) |
15061 EnumerationFieldSym : PushFrom(EnumerationField.Value) |
15062 ConstStringSym : PushConstString(Sym)
15063
15064 ELSE
15065 InternalError ('not expecting this kind of symbol')
15066 END
15067 END
15068 END PushValue ;
15069
15070
15071 (*
15072 PushConstString - pushes the character string onto the ALU stack.
15073 It assumes that the character string is only
15074 one character long.
15075 *)
15076
15077 PROCEDURE PushConstString (Sym: CARDINAL) ;
15078 VAR
15079 pSym: PtrToSymbol ;
15080 a : ARRAY [0..10] OF CHAR ;
15081 BEGIN
15082 AssertInRange (Sym) ;
15083 pSym := GetPsym (Sym) ;
15084 WITH pSym^ DO
15085 CASE SymbolType OF
15086
15087 ConstStringSym: WITH ConstString DO
15088 IF Length = 0
15089 THEN
15090 PushChar (nul)
15091 ELSIF Length = 1
15092 THEN
15093 GetKey (Contents, a) ;
15094 PushChar (a[0])
15095 ELSE
15096 WriteFormat0 ('ConstString must be length 0 or 1')
15097 END
15098 END
15099
15100 ELSE
15101 InternalError ('expecting ConstString symbol')
15102 END
15103 END
15104 END PushConstString ;
15105
15106
15107 (*
15108 PushVarSize - pushes the size of a variable, Sym.
15109 The runtime size of Sym will depend upon its addressing mode,
15110 RightValue has size PushSize(GetType(Sym)) and
15111 LeftValue has size PushSize(Address) since it points to a
15112 variable.
15113 *)
15114
15115 PROCEDURE PushVarSize (Sym: CARDINAL) ;
15116 BEGIN
15117 AssertInRange(Sym) ;
15118 Assert(IsVar(Sym)) ;
15119 IF GetMode(Sym)=LeftValue
15120 THEN
15121 PushSize(Address)
15122 ELSE
15123 Assert(GetMode(Sym)=RightValue) ;
15124 PushSize(GetType(Sym))
15125 END
15126 END PushVarSize ;
15127
15128
15129 (*
15130 PopValue - pops the ALU stack into Value of Sym.
15131 *)
15132
15133 PROCEDURE PopValue (Sym: CARDINAL) ;
15134 VAR
15135 pSym: PtrToSymbol ;
15136 BEGIN
15137 AssertInRange(Sym) ;
15138 pSym := GetPsym(Sym) ;
15139 WITH pSym^ DO
15140 CASE SymbolType OF
15141
15142 ConstLitSym : PopInto(ConstLit.Value) |
15143 ConstVarSym : PopInto(ConstVar.Value) |
15144 EnumerationFieldSym : InternalError ('cannot pop into an enumeration field')
15145
15146 ELSE
15147 InternalError ('symbol type not expected')
15148 END
15149 END
15150 END PopValue ;
15151
15152
15153 (*
15154 PutAlignment - assigns the alignment constant associated with,
15155 type, with, align.
15156 *)
15157
15158 PROCEDURE PutAlignment (type: CARDINAL; align: CARDINAL) ;
15159 VAR
15160 pSym: PtrToSymbol ;
15161 BEGIN
15162 pSym := GetPsym(type) ;
15163 WITH pSym^ DO
15164 CASE SymbolType OF
15165
15166 RecordSym : Record.Align := align |
15167 RecordFieldSym: RecordField.Align := align |
15168 TypeSym : Type.Align := align |
15169 ArraySym : Array.Align := align |
15170 PointerSym : Pointer.Align := align |
15171 SubrangeSym : Subrange.Align := align
15172
15173 ELSE
15174 InternalError ('expecting record, field, pointer, type, subrange or an array symbol')
15175 END
15176 END
15177 END PutAlignment ;
15178
15179
15180 (*
15181 GetAlignment - returns the alignment constant associated with,
15182 type.
15183 *)
15184
15185 PROCEDURE GetAlignment (type: CARDINAL) : CARDINAL ;
15186 VAR
15187 pSym: PtrToSymbol ;
15188 BEGIN
15189 pSym := GetPsym(type) ;
15190 WITH pSym^ DO
15191 CASE SymbolType OF
15192
15193 RecordSym : RETURN( Record.Align ) |
15194 RecordFieldSym : RETURN( RecordField.Align ) |
15195 TypeSym : RETURN( Type.Align ) |
15196 ArraySym : RETURN( Array.Align ) |
15197 PointerSym : RETURN( Pointer.Align ) |
15198 VarientFieldSym: RETURN( GetAlignment(VarientField.Parent) ) |
15199 VarientSym : RETURN( GetAlignment(Varient.Parent) ) |
15200 SubrangeSym : RETURN( Subrange.Align )
15201
15202 ELSE
15203 InternalError ('expecting record, field, pointer, type, subrange or an array symbol')
15204 END
15205 END
15206 END GetAlignment ;
15207
15208
15209 (*
15210 PutDefaultRecordFieldAlignment - assigns, align, as the default alignment
15211 to record, sym.
15212 *)
15213
15214 PROCEDURE PutDefaultRecordFieldAlignment (sym: CARDINAL; align: CARDINAL) ;
15215 VAR
15216 pSym: PtrToSymbol ;
15217 BEGIN
15218 pSym := GetPsym(sym) ;
15219 WITH pSym^ DO
15220 CASE SymbolType OF
15221
15222 RecordSym: Record.DefaultAlign := align
15223
15224 ELSE
15225 InternalError ('expecting record symbol')
15226 END
15227 END
15228 END PutDefaultRecordFieldAlignment ;
15229
15230
15231 (*
15232 GetDefaultRecordFieldAlignment - assigns, align, as the default alignment
15233 to record, sym.
15234 *)
15235
15236 PROCEDURE GetDefaultRecordFieldAlignment (sym: CARDINAL) : CARDINAL ;
15237 VAR
15238 pSym: PtrToSymbol ;
15239 BEGIN
15240 pSym := GetPsym(sym) ;
15241 WITH pSym^ DO
15242 CASE SymbolType OF
15243
15244 RecordSym : RETURN( Record.DefaultAlign ) |
15245 VarientFieldSym: RETURN( GetDefaultRecordFieldAlignment(GetParent(sym)) ) |
15246 VarientSym : RETURN( GetDefaultRecordFieldAlignment(GetParent(sym)) )
15247
15248 ELSE
15249 InternalError ('expecting record symbol')
15250 END
15251 END
15252 END GetDefaultRecordFieldAlignment ;
15253
15254
15255 (*
15256 VarCheckReadInit - returns TRUE if sym has been initialized.
15257 *)
15258
15259 PROCEDURE VarCheckReadInit (sym: CARDINAL; mode: ModeOfAddr) : BOOLEAN ;
15260 VAR
15261 pSym: PtrToSymbol ;
15262 BEGIN
15263 IF IsVar (sym)
15264 THEN
15265 pSym := GetPsym (sym) ;
15266 WITH pSym^ DO
15267 CASE SymbolType OF
15268
15269 VarSym: RETURN GetInitialized (Var.InitState[mode])
15270
15271 ELSE
15272 END
15273 END
15274 END ;
15275 RETURN FALSE
15276 END VarCheckReadInit ;
15277
15278
15279 (*
15280 VarInitState - initializes the init state for variable sym.
15281 *)
15282
15283 PROCEDURE VarInitState (sym: CARDINAL) ;
15284 VAR
15285 pSym: PtrToSymbol ;
15286 BEGIN
15287 IF IsVar (sym)
15288 THEN
15289 pSym := GetPsym (sym) ;
15290 WITH pSym^ DO
15291 CASE SymbolType OF
15292
15293 VarSym: ConfigSymInit (Var.InitState[LeftValue], sym) ;
15294 ConfigSymInit (Var.InitState[RightValue], sym)
15295
15296 ELSE
15297 END
15298 END
15299 END
15300 END VarInitState ;
15301
15302
15303 (*
15304 PutVarInitialized - set sym as initialized.
15305 *)
15306
15307 PROCEDURE PutVarInitialized (sym: CARDINAL; mode: ModeOfAddr) ;
15308 VAR
15309 pSym: PtrToSymbol ;
15310 BEGIN
15311 IF IsVar (sym)
15312 THEN
15313 pSym := GetPsym (sym) ;
15314 WITH pSym^ DO
15315 CASE SymbolType OF
15316
15317 VarSym: WITH Var DO
15318 SetInitialized (InitState[mode])
15319 END
15320
15321 ELSE
15322 END
15323 END
15324 END
15325 END PutVarInitialized ;
15326
15327
15328 (*
15329 PutVarFieldInitialized - records that field has been initialized with
15330 variable sym. TRUE is returned if the field
15331 is detected and changed to initialized.
15332 *)
15333
15334 PROCEDURE PutVarFieldInitialized (sym: CARDINAL; mode: ModeOfAddr;
15335 fieldlist: List) : BOOLEAN ;
15336 VAR
15337 pSym: PtrToSymbol ;
15338 BEGIN
15339 IF IsVar (sym)
15340 THEN
15341 pSym := GetPsym (sym) ;
15342 WITH pSym^ DO
15343 CASE SymbolType OF
15344
15345 VarSym: WITH Var DO
15346 RETURN SetFieldInitialized (InitState[mode], fieldlist)
15347 END
15348
15349 ELSE
15350 END
15351 END
15352 END ;
15353 RETURN FALSE
15354 END PutVarFieldInitialized ;
15355
15356
15357 (*
15358 GetVarFieldInitialized - return TRUE if fieldlist has been initialized
15359 within variable sym.
15360 *)
15361
15362 PROCEDURE GetVarFieldInitialized (sym: CARDINAL; mode: ModeOfAddr;
15363 fieldlist: List) : BOOLEAN ;
15364 VAR
15365 pSym: PtrToSymbol ;
15366 BEGIN
15367 IF IsVar (sym)
15368 THEN
15369 pSym := GetPsym (sym) ;
15370 WITH pSym^ DO
15371 CASE SymbolType OF
15372
15373 VarSym: WITH Var DO
15374 RETURN GetFieldInitialized (InitState[mode], fieldlist)
15375 END
15376
15377 ELSE
15378 END
15379 END
15380 END ;
15381 RETURN FALSE
15382 END GetVarFieldInitialized ;
15383
15384
15385 (*
15386 PrintInitialized - display variable sym initialization state.
15387 *)
15388
15389 PROCEDURE PrintInitialized (sym: CARDINAL) ;
15390 VAR
15391 pSym: PtrToSymbol ;
15392 BEGIN
15393 IF IsVar (sym)
15394 THEN
15395 pSym := GetPsym (sym) ;
15396 WITH pSym^ DO
15397 CASE SymbolType OF
15398
15399 VarSym: printf0 ("LeftMode init: ") ;
15400 PrintSymInit (Var.InitState[LeftValue]) ;
15401 printf0 ("RightMode init: ") ;
15402 PrintSymInit (Var.InitState[RightValue])
15403
15404 ELSE
15405 END
15406 END
15407 END
15408 END PrintInitialized ;
15409
15410
15411 (*
15412 DumpSymbols - display all symbol numbers and their type.
15413 *)
15414
15415 (*
15416 PROCEDURE DumpSymbols ;
15417 VAR
15418 pSym: PtrToSymbol ;
15419 sym : CARDINAL ;
15420 BEGIN
15421 sym := 1 ;
15422 WHILE sym <= FinalSymbol () DO
15423 pSym := GetPsym(sym) ;
15424 printf ("%d ", sym) ;
15425 WITH pSym^ DO
15426 CASE SymbolType OF
15427
15428 RecordSym: printf ("RecordSym") |
15429 VarientSym: printf ("VarientSym") |
15430 DummySym: printf ("DummySym") |
15431 VarSym: printf ("VarSym") |
15432 EnumerationSym: printf ("EnumerationSym") |
15433 SubrangeSym: printf ("SubrangeSym") |
15434 ArraySym: printf ("ArraySym") |
15435 ConstStringSym: printf ("ConstStringSym") |
15436 ConstVarSym: printf ("ConstVarSym") |
15437 ConstLitSym: printf ("ConstLitSym") |
15438 VarParamSym: printf ("VarParamSym") |
15439 ParamSym: printf ("ParamSym") |
15440 PointerSym: printf ("PointerSym") |
15441 UndefinedSym: printf ("UndefinedSym") |
15442 TypeSym: printf ("TypeSym") |
15443 RecordFieldSym: printf ("RecordFieldSym") |
15444 VarientFieldSym: printf ("VarientFieldSym") |
15445 EnumerationFieldSym: printf ("EnumerationFieldSym") |
15446 DefImpSym: printf ("DefImpSym") |
15447 ModuleSym: printf ("ModuleSym") |
15448 SetSym: printf ("SetSym") |
15449 ProcedureSym: printf ("ProcedureSym") |
15450 ProcTypeSym: printf ("ProcTypeSym") |
15451 SubscriptSym: printf ("SubscriptSym") |
15452 UnboundedSym: printf ("UnboundedSym") |
15453 GnuAsmSym: printf ("GnuAsmSym") |
15454 InterfaceSym: printf ("InterfaceSym") |
15455 ObjectSym: printf ("ObjectSym") |
15456 PartialUnboundedSym: printf ("PartialUnboundedSym") |
15457 TupleSym: printf ("TupleSym") |
15458 OAFamilySym: printf ("OAFamilySym") |
15459 EquivSym: printf ("EquivSym") |
15460 ErrorSym: printf ("ErrorSym")
15461
15462 END
15463 END ;
15464 printf ("\n") ;
15465 INC (sym)
15466 END
15467 END DumpSymbols ;
15468 *)
15469
15470
15471 (*
15472 GetErrorScope - returns the error scope for a symbol.
15473 The error scope is the title scope which is used to
15474 announce the symbol in the GCC error message.
15475 *)
15476
15477 PROCEDURE GetErrorScope (sym: CARDINAL) : ErrorScope ;
15478 VAR
15479 pSym: PtrToSymbol ;
15480 BEGIN
15481 pSym := GetPsym (sym) ;
15482 WITH pSym^ DO
15483 CASE SymbolType OF
15484
15485 ProcedureSym: RETURN Procedure.errorScope |
15486 ModuleSym : RETURN Module.errorScope |
15487 DefImpSym : RETURN DefImp.errorScope |
15488 UndefinedSym: RETURN Undefined.errorScope
15489
15490 ELSE
15491 InternalError ('expecting procedure, module or defimp symbol')
15492 END
15493 END
15494 END GetErrorScope ;
15495
15496
15497 (*
15498 PutErrorScope - sets the error scope for a symbol.
15499 The error scope is the title scope which is used to
15500 announce the symbol in the GCC error message.
15501 *)
15502
15503 (*
15504 PROCEDURE PutErrorScope (sym: CARDINAL; errorScope: ErrorScope) ;
15505 VAR
15506 pSym: PtrToSymbol ;
15507 BEGIN
15508 pSym := GetPsym (type) ;
15509 WITH pSym^ DO
15510 CASE SymbolType OF
15511
15512 ProcedureSym: Procedure.errorScope := errorScope |
15513 ModuleSym : Module.errorScope := errorScope |
15514 DefImpSym : DefImp.errorScope := errorScope
15515
15516 ELSE
15517 InternalError ('expecting procedure, module or defimp symbol')
15518 END
15519 END
15520 END PutErrorScope ;
15521 *)
15522
15523
15524 (*
15525 IsLegal - returns TRUE if, sym, is a legal symbol.
15526 *)
15527
15528 PROCEDURE IsLegal (sym: CARDINAL) : BOOLEAN ;
15529 BEGIN
15530 RETURN sym < FreeSymbol
15531 END IsLegal ;
15532
15533
15534 BEGIN
15535 Init
15536 END SymbolTable.