1 (* P2SymBuild.def pass 2 symbol creation.
3 Copyright (C) 2001-2021 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
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)
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.
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/>. *)
22 DEFINITION MODULE P2SymBuild ;
28 LastEdit : Sat Dec 9 11:10:57 EST 1989
29 System : UNIX (GNU Modula-2)
30 Description: pass 2 symbol creation.
33 EXPORT QUALIFIED P2StartBuildDefModule,
35 P2StartBuildImplementationModule,
36 P2EndBuildImplementationModule,
37 P2StartBuildProgramModule,
38 P2EndBuildProgramModule,
39 StartBuildInnerModule,
41 BuildImportOuterModule,
42 BuildExportOuterModule,
43 BuildImportInnerModule,
44 BuildExportInnerModule,
48 BuildSubrange, BuildAligned,
49 BuildTypeAlignment, BuildVarAlignment,
50 P2BuildDefaultFieldAlignment, BuildPragmaConst,
52 StartBuildEnumeration,
54 StartBuildFormalParameters,
55 EndBuildFormalParameters,
56 BuildProcedureHeading,
72 StartBuildVarientFieldRecord,
73 EndBuildVarientFieldRecord,
76 StartBuildArray, BuildArrayComma,
88 SeenCType, SeenRType, SeenZType,
89 DetermineType, PushType, PopType,
96 StartBuildDefinitionModule - Creates a definition module and starts
99 The Stack is expected:
104 +------------+ +-----------+
105 | NameStart | | NameStart |
106 |------------| |-----------|
110 PROCEDURE P2StartBuildDefModule ;
114 EndBuildDefinitionModule - Destroys the definition module scope and
115 checks for correct name.
117 The Stack is expected:
122 +------------+ +-----------+
124 |------------| |-----------|
125 | NameStart | | | <- Ptr
126 |------------| |-----------|
129 PROCEDURE P2EndBuildDefModule ;
133 StartBuildImplementationModule - Creates an implementation module and starts
136 The Stack is expected:
141 +------------+ +-----------+
142 | NameStart | | NameStart |
143 |------------| |-----------|
147 PROCEDURE P2StartBuildImplementationModule ;
151 EndBuildImplementationModule - Destroys the implementation module scope and
152 checks for correct name.
154 The Stack is expected:
159 +------------+ +-----------+
161 |------------| |-----------|
162 | NameStart | | | <- Ptr
163 |------------| |-----------|
166 PROCEDURE P2EndBuildImplementationModule ;
170 StartBuildProgramModule - Creates a program module and starts
173 The Stack is expected:
178 +------------+ +-----------+
179 | NameStart | | NameStart |
180 |------------| |-----------|
184 PROCEDURE P2StartBuildProgramModule ;
188 EndBuildProgramModule - Destroys the program module scope and
189 checks for correct name.
191 The Stack is expected:
196 +------------+ +-----------+
198 |------------| |-----------|
199 | NameStart | | | <- Ptr
200 |------------| |-----------|
203 PROCEDURE P2EndBuildProgramModule ;
207 StartBuildInnerModule - Creates an Inner module and starts
210 The Stack is expected:
215 +------------+ +-----------+
216 | NameStart | | NameStart |
217 |------------| |-----------|
221 PROCEDURE StartBuildInnerModule ;
225 EndBuildInnerModule - Destroys the Inner module scope and
226 checks for correct name.
228 The Stack is expected:
233 +------------+ +-----------+
235 |------------| |-----------|
236 | NameStart | | | <- Ptr
237 |------------| |-----------|
240 PROCEDURE EndBuildInnerModule ;
244 BuildImportOuterModule - Builds imported identifiers into an outer module
245 from a definition module.
247 The Stack is expected:
252 +------------+ +-----------+
254 |------------| |-----------|
256 |------------| |-----------|
260 |------------| |-----------|
262 |------------| |-----------|
263 | ImportTok | | Ident |
264 |------------| |-----------|
266 IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
272 All above stack discarded
275 PROCEDURE BuildImportOuterModule ;
279 BuildExportOuterModule - Builds exported identifiers from an outer module
280 to the outside world of library modules.
282 The Stack is expected:
287 +------------+ +--------------+
289 |------------| |--------------|
291 |------------| |--------------|
295 |------------| |--------------|
297 |------------| |--------------|
298 | ExportTok | | QualifiedTok |
299 |------------| |--------------|
301 EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
308 All above stack discarded
311 PROCEDURE BuildExportOuterModule ;
315 BuildImportInnerModule - Builds imported identifiers into an inner module
316 from the last level of module.
318 The Stack is expected:
323 +------------+ +-----------+
325 |------------| |-----------|
327 |------------| |-----------|
331 |------------| |-----------|
333 |------------| |-----------|
334 | ImportTok | | Ident |
335 |------------| |-----------|
337 IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
343 All above stack discarded
346 PROCEDURE BuildImportInnerModule ;
350 BuildExportInnerModule - Builds exported identifiers from an inner module
351 to the next layer module.
353 The Stack is expected:
358 +------------+ +--------------+
360 |------------| |--------------|
362 |------------| |--------------|
366 |------------| |--------------|
368 |------------| |--------------|
369 | ExportTok | | QualifiedTok |
370 |------------| |--------------|
372 EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
377 All above stack discarded
380 PROCEDURE BuildExportInnerModule ;
384 BuildNumber - Converts a number into a symbol.
392 +------------+ +------------+
394 |------------+ |------------|
397 PROCEDURE BuildNumber ;
401 BuildString - Converts a string into a symbol.
409 +------------+ +------------+
411 |------------+ |------------|
414 PROCEDURE BuildString ;
418 BuildConst - builds a constant.
426 |------------+ <- Ptr
429 PROCEDURE BuildConst ;
433 StartBuildEnumeration - Builds an Enumeration type Type.
451 |------------| +------------+
453 |------------| |------------|
455 |------------| |------------|
458 PROCEDURE StartBuildEnumeration ;
462 BuildSubrange - Builds a Subrange type Symbol, the base type can also be
473 +------------+ |------------|
475 |------------| |------------|
478 PROCEDURE BuildSubrange (Base: CARDINAL) ;
482 BuildAligned - builds an alignment constant symbol which is placed onto
483 the stack. It expects the ident ALIGNED to be on the
492 +---------------+ +-----------------+
493 | bytealignment | | AlignmentConst |
494 +---------------+ |-----------------|
497 PROCEDURE BuildAligned ;
501 BuildVarAlignment - the AlignmentConst is either a temporary or NulSym.
502 A type may only have one alignment value and
503 error checking is performed.
512 | AlignmentConst | <- Ptr
513 |-----------------| +------------------+
514 | Type | | Type | TypeName |
515 |-----------------| |------------------|
518 PROCEDURE BuildVarAlignment ;
522 BuildTypeAlignment - the AlignmentConst is either a temporary or NulSym.
523 A type may only have one alignment value and
524 error checking is performed.
539 PROCEDURE BuildTypeAlignment ;
543 BuildDefaultFieldAlignment -
554 |-----------| +-----------+
555 | RecordSym | | RecordSym |
556 |-----------| |-----------|
558 |-----------| |-----------|
562 PROCEDURE P2BuildDefaultFieldAlignment ;
566 BuildPragmaConst - pushes a constant to the stack and stores it away into the
567 const fifo queue ready for pass 3.
570 PROCEDURE BuildPragmaConst ;
574 BuildVariable - Builds variables listed in an IdentList with a Type.
581 +------------+ +------------+
583 |------------| |------------|
585 |------------| |------------|
587 |------------| |------------|
589 |------------| |------------|
593 |------------| |------------|
594 | Ident # | | | <- Ptr
595 |------------| |------------|
600 PROCEDURE BuildVariable ;
604 BuildType - Builds a Type.
614 |------------| +---------------+
615 | Name | | Type | Name |
616 |------------| |---------------|
621 PROCEDURE BuildType ;
625 StartBuildFormalParameters - Initialises the quadruple stack for
638 PROCEDURE StartBuildFormalParameters ;
642 EndBuildFormalParameters - Resets the quadruple stack after building
652 |------------| +------------+
653 | ProcSym | | ProcSym |
654 |------------| |------------|
657 PROCEDURE EndBuildFormalParameters ;
661 BuildProcedureHeading - Builds a procedure heading for the definition
664 Operation only performed if compiling a
678 PROCEDURE BuildProcedureHeading ;
682 BuildFunction - Builds a procedures return type.
683 Procedure becomes a function.
692 |------------| +------------+
693 | ProcSym | | ProcSym |
694 |------------| |------------|
697 PROCEDURE BuildFunction ;
701 BuildOptFunction - Builds a procedures optional return type.
702 Procedure becomes a function and the user
703 can either call it as a function or a procedure.
712 |------------| +------------+
713 | ProcSym | | ProcSym |
714 |------------| |------------|
717 PROCEDURE BuildOptFunction ;
721 BuildFPSection - Builds a Formal Parameter in a procedure.
744 |------------| +------------+
745 | Var / Nul | | ParamTotal |
746 |------------| |------------|
747 | ProcSym | | ProcSym |
748 |------------| |------------|
751 PROCEDURE BuildFPSection ;
755 BuildVarArgs - indicates that the ProcSym takes varargs
758 +------------+ +------------+
759 | ParamTotal | | ParamTotal |
760 |------------| |------------|
761 | ProcSym | | ProcSym |
762 |------------| |------------|
766 PROCEDURE BuildVarArgs ;
770 BuildFormalVarArgs - indicates that the procedure type takes varargs.
772 +------------+ +------------+
773 | ProcSym | | ProcSym |
774 |------------| |------------|
778 PROCEDURE BuildFormalVarArgs ;
782 BuildOptArg - indicates that the ProcSym takes a single optarg
786 +------------+ +------------+
787 | ParamTotal | | ParamTotal |
788 |------------| |------------|
789 | ProcSym | | ProcSym |
790 |------------| |------------|
793 PROCEDURE BuildOptArg ;
797 StartBuildProcedure - Builds a Procedure.
806 +------------+ |------------|
808 |------------| |------------|
811 PROCEDURE StartBuildProcedure ;
815 EndBuildProcedure - Ends building a Procedure.
816 It checks the start procedure name matches the end
835 PROCEDURE EndBuildProcedure ;
839 BuildPointerType - builds a pointer type.
847 +------------+ +-------------+
848 | Type | | PointerType |
849 |------------| |-------------|
851 |------------| |-------------|
854 PROCEDURE BuildPointerType ;
858 BuildSetType - builds a set type.
866 +------------+ +-------------+
868 |------------| |-------------|
870 |------------| |-------------|
873 PROCEDURE BuildSetType (ispacked: BOOLEAN) ;
877 BuildRecord - Builds a record type.
886 +------------+ |-----------|
888 |------------| |-----------|
891 PROCEDURE BuildRecord ;
895 BuildFieldRecord - Builds a field into a record sym.
917 |-------------| +-------------+
918 | RecordSym | | RecordSym |
919 |-------------| |-------------|
920 | RecordName | | RecordName |
921 |-------------| |-------------|
924 PROCEDURE BuildFieldRecord ;
928 StartBuildVarient - Builds a varient symbol on top of a record sym.
937 Ptr -> | VarientSym |
938 +-------------+ |-------------|
939 | RecordSym | | RecordSym |
940 |-------------| |-------------|
941 | RecordName | | RecordName |
942 |-------------| |-------------|
945 PROCEDURE StartBuildVarient ;
949 EndBuildVarient - Removes the varient symbol from the stack.
957 | VarientSym | <- Ptr
958 |-------------| +-------------+
959 | RecordSym | | RecordSym |
960 |-------------| |-------------|
961 | RecordName | | RecordName |
962 |-------------| |-------------|
965 PROCEDURE EndBuildVarient ;
969 BuildVarientSelector - Builds a field into a record sym.
981 |-------------| +-------------+
982 | RecordSym | | RecordSym |
983 |-------------| |-------------|
986 PROCEDURE BuildVarientSelector ;
990 StartBuildVarientFieldRecord - Builds a varient field into a varient sym.
999 Ptr -> | VarientField|
1000 +-------------+ |-------------|
1001 | VarientSym | | RecordSym |
1002 |-------------| |-------------|
1005 PROCEDURE StartBuildVarientFieldRecord ;
1009 EndBuildVarientFieldRecord - Removes a varient field from the stack.
1018 | VarientField| <- Ptr
1019 |-------------| +-------------+
1020 | VarientSym | | VarientSym |
1021 |-------------| |-------------|
1024 PROCEDURE EndBuildVarientFieldRecord ;
1028 BuildNulName - Pushes a NulKey onto the top of the stack.
1035 Empty +------------+
1040 PROCEDURE BuildNulName ;
1044 BuildTypeEnd - Pops the type Type and Name.
1053 | Type | Name | Empty
1057 PROCEDURE BuildTypeEnd ;
1061 StartBuildArray - Builds an array type.
1070 +------------+ |-----------|
1072 |------------| |-----------|
1075 PROCEDURE StartBuildArray ;
1079 EndBuildArray - Builds an array type.
1088 |------------| +------------+
1089 | ArraySym | | ArraySym |
1090 |------------| |------------|
1092 |------------| |------------|
1095 PROCEDURE EndBuildArray ;
1099 BuildFieldArray - Builds a field into an array sym.
1108 | Type | Name | <- Ptr
1109 |-------------| +-------------+
1110 | ArraySym | | ArraySym |
1111 |-------------| |-------------|
1112 | ArrayName | | ArrayName |
1113 |-------------| |-------------|
1116 PROCEDURE BuildFieldArray ;
1120 BuildArrayComma - converts ARRAY [..], [..] OF into ARRAY [..] OF ARRAY [..]
1124 +-------------+ +-------------+
1125 | ArraySym1 | | ArraySym2 |
1126 |-------------| |-------------|
1127 | ArrayName | | ArrayName |
1128 |-------------| |-------------|
1131 PROCEDURE BuildArrayComma ;
1135 BuildProcedureType - builds a procedure type symbol.
1141 Ptr -> | ProcTypeSym |
1142 +-------------+ |-------------|
1144 |-------------| |-------------|
1147 PROCEDURE BuildProcedureType ;
1151 BuildFormalType - Builds a Formal Parameter in a procedure type.
1163 | Var / Nul | <- Ptr
1164 |------------| +--------------+
1165 | ProcTypeSym| | ProcTypeSym |
1166 |------------| |--------------|
1169 PROCEDURE BuildFormalType ;
1174 SeenUnknown - sets the operand type to unknown.
1177 PROCEDURE SeenUnknown ;
1181 SeenCast - sets the operand type to cast.
1184 PROCEDURE SeenCast (sym: CARDINAL) ;
1188 SeenSet - sets the operand type to set.
1195 SeenConstructor - sets the operand type to constructor.
1198 PROCEDURE SeenConstructor ;
1202 SeenArray - sets the operand type to array.
1205 PROCEDURE SeenArray ;
1209 SeenString - sets the operand type to string.
1212 PROCEDURE SeenString ;
1216 SeenBoolean - sets the operand type to a BOOLEAN.
1219 PROCEDURE SeenBoolean ;
1223 SeenZType - sets the operand type to a Z type.
1226 PROCEDURE SeenZType ;
1230 SeenRType - sets the operand type to a R type.
1233 PROCEDURE SeenRType ;
1237 SeenCType - sets the operand type to a C type.
1240 PROCEDURE SeenCType ;
1244 DetermineType - assigns the top of stack symbol with the type of
1245 constant expression, if known.
1248 PROCEDURE DetermineType ;
1252 PushType - pushes the current constant type.
1255 PROCEDURE PushType ;
1259 PopType - pops the stacked type.
1266 PushRememberConstant -
1269 PROCEDURE PushRememberConstant ;
1273 PopRememberConstant -
1276 PROCEDURE PopRememberConstant ;
1283 PROCEDURE RememberConstant (sym: CARDINAL) ;