Debian Codegraph @

gcc/m2/gm2-compiler/P1SymBuild.def

raw
1 (* P1SymBuild.def pass 1 symbol creation.
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 DEFINITION MODULE P1SymBuild ;
23
24 (*
25 Title : P1SymBuild
26 Author : Gaius Mulley
27 Date : 24/6/87
28 System : UNIX (GNU Modula-2)
29 Description: Builds symbol entities, types, constants, variables,
30 procedures, modules and scopes.
31 All procedures are only called during Pass 1.
32 *)
33
34
35 (*
36 StartBuildDefinitionModule - Creates a definition module and starts
37 a new scope.
38
39 The Stack is expected:
40
41 Entry Exit
42
43 Ptr ->
44 +------------+
45 | NameStart | <- Ptr
46 |------------| +------------+
47 | NulName/"C"| | NameStart |
48 |------------| |------------|
49 *)
50
51 PROCEDURE P1StartBuildDefinitionModule ;
52
53
54 (*
55 EndBuildDefinitionModule - Destroys the definition module scope and
56 checks for correct name.
57
58 The Stack is expected:
59
60 Entry Exit
61
62 Ptr ->
63 +------------+ +-----------+
64 | NameEnd | | |
65 |------------| |-----------|
66 | NameStart | | | <- Ptr
67 |------------| |-----------|
68 *)
69
70 PROCEDURE P1EndBuildDefinitionModule ;
71
72
73 (*
74 StartBuildImplementationModule - Creates an implementation module and starts
75 a new scope.
76
77 The Stack is expected:
78
79 Entry Exit
80
81 Ptr -> <- Ptr
82 +------------+ +-----------+
83 | NameStart | | NameStart |
84 |------------| |-----------|
85
86 *)
87
88 PROCEDURE P1StartBuildImplementationModule ;
89
90
91 (*
92 EndBuildImplementationModule - Destroys the implementation module scope and
93 checks for correct name.
94
95 The Stack is expected:
96
97 Entry Exit
98
99 Ptr ->
100 +------------+ +-----------+
101 | NameEnd | | |
102 |------------| |-----------|
103 | NameStart | | | <- Ptr
104 |------------| |-----------|
105 *)
106
107 PROCEDURE P1EndBuildImplementationModule ;
108
109
110 (*
111 StartBuildProgramModule - Creates a program module and starts
112 a new scope.
113
114 The Stack is expected:
115
116 Entry Exit
117
118 Ptr -> <- Ptr
119 +------------+ +-----------+
120 | NameStart | | NameStart |
121 |------------| |-----------|
122
123 *)
124
125 PROCEDURE P1StartBuildProgramModule ;
126
127
128 (*
129 EndBuildProgramModule - Destroys the program module scope and
130 checks for correct name.
131
132 The Stack is expected:
133
134 Entry Exit
135
136 Ptr ->
137 +------------+ +-----------+
138 | NameEnd | | |
139 |------------| |-----------|
140 | NameStart | | | <- Ptr
141 |------------| |-----------|
142 *)
143
144 PROCEDURE P1EndBuildProgramModule ;
145
146
147 (*
148 StartBuildInnerModule - Creates an Inner module and starts
149 a new scope.
150
151 The Stack is expected:
152
153 Entry Exit
154
155 Ptr -> <- Ptr
156 +------------+ +-----------+
157 | NameStart | | NameStart |
158 |------------| |-----------|
159
160 *)
161
162 PROCEDURE StartBuildInnerModule ;
163
164
165 (*
166 EndBuildInnermModule - Destroys the Inner module scope and
167 checks for correct name.
168
169 The Stack is expected:
170
171 Entry Exit
172
173 Ptr ->
174 +------------+ +-----------+
175 | NameEnd | | |
176 |------------| |-----------|
177 | NameStart | | | <- Ptr
178 |------------| |-----------|
179 *)
180
181 PROCEDURE EndBuildInnerModule ;
182
183
184 (*
185 BuildImportOuterModule - Builds imported identifiers into an outer module
186 from a definition module.
187
188 The Stack is expected:
189
190 Entry OR Entry
191
192 Ptr -> Ptr ->
193 +------------+ +-----------+
194 | # | | # |
195 |------------| |-----------|
196 | Id1 | | Id1 |
197 |------------| |-----------|
198 . . . .
199 . . . .
200 . . . .
201 |------------| |-----------|
202 | Id# | | Id# |
203 |------------| |-----------|
204 | ImportTok | | Ident |
205 |------------| |-----------|
206
207 IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
208
209
210 Error Condition
211 Exit
212
213 All above stack discarded
214 *)
215
216 PROCEDURE BuildImportOuterModule (definition: BOOLEAN) ;
217
218
219 (*
220 BuildExportOuterModule - Builds exported identifiers from an outer module
221 to the outside world of library modules.
222
223 The Stack is expected:
224
225 Entry OR Entry
226
227 Ptr -> Ptr ->
228 +------------+ +--------------+
229 | # | | # |
230 |------------| |--------------|
231 | Id1 | | Id1 |
232 |------------| |--------------|
233 . . . .
234 . . . .
235 . . . .
236 |------------| |--------------|
237 | Id# | | Id# |
238 |------------| |--------------|
239 | ExportTok | | QualifiedTok |
240 |------------| |--------------|
241
242 EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
243
244 Error Condition
245
246
247 Exit
248
249 All above stack discarded
250 *)
251
252 PROCEDURE BuildExportOuterModule ;
253
254
255 (*
256 CheckExplicitExported - checks to see whether we are compiling
257 a definition module and whether the ident
258 is implicitly export qualified or unqualified.
259
260
261 The Stack is expected:
262
263 Entry Exit
264
265 Ptr -> Ptr ->
266 +------------+ +-----------+
267 | Identname | | Identname |
268 |------------| |-----------|
269
270 *)
271
272 PROCEDURE CheckExplicitExported ;
273
274
275 (*
276 BuildImportInnerModule - Builds imported identifiers into an inner module
277 from the last level of module.
278
279 The Stack is expected:
280
281 Entry OR Entry
282
283 Ptr -> Ptr ->
284 +------------+ +-----------+
285 | # | | # |
286 |------------| |-----------|
287 | Id1 | | Id1 |
288 |------------| |-----------|
289 . . . .
290 . . . .
291 . . . .
292 |------------| |-----------|
293 | Id# | | Id# |
294 |------------| |-----------|
295 | ImportTok | | Ident |
296 |------------| |-----------|
297
298 IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
299
300
301 Error Condition
302 Exit
303
304 All above stack discarded
305 *)
306
307 PROCEDURE BuildImportInnerModule ;
308
309
310 (*
311 BuildExportInnerModule - Builds exported identifiers from an inner module
312 to the next layer module.
313
314 The Stack is expected:
315
316 Entry OR Entry
317
318 Ptr -> Ptr ->
319 +------------+ +--------------+
320 | # | | # |
321 |------------| |--------------|
322 | Id1 | | Id1 |
323 |------------| |--------------|
324 . . . .
325 . . . .
326 . . . .
327 |------------| |--------------|
328 | Id# | | Id# |
329 |------------| |--------------|
330 | ExportTok | | QualifiedTok |
331 |------------| |--------------|
332
333 EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
334
335
336 Exit
337
338 All above stack discarded
339 *)
340
341 PROCEDURE BuildExportInnerModule ;
342
343
344 (*
345 StartBuildEnumeration - Builds an Enumeration type Type.
346
347
348 Stack
349
350 Entry Exit
351
352 Ptr ->
353 +------------+
354 | # |
355 |------------|
356 | en 1 |
357 |------------|
358 | en 2 |
359 |------------|
360 . .
361 . .
362 . . <- Ptr
363 |------------| +------------+
364 | en # | | Type |
365 |------------| |------------|
366 | Name | | Name |
367 |------------| |------------|
368 *)
369
370 PROCEDURE StartBuildEnumeration ;
371
372
373 (*
374 EndBuildEnumeration - completes the construction of the enumeration type.
375
376
377 Stack
378
379 Entry Exit
380
381 Ptr ->
382 +------------+
383 | Type | <- Ptr
384 |------------| +---------------+
385 | Name | | Type | Name |
386 |------------| |---------------|
387
388 Empty
389 *)
390
391 PROCEDURE EndBuildEnumeration ;
392
393
394 (*
395 BuildHiddenType - Builds a Hidden Type.
396
397
398 Stack
399
400 Entry Exit
401
402 Ptr ->
403 +------------+
404 | Name | <- Ptr
405 |------------| Empty
406 *)
407
408 PROCEDURE BuildHiddenType ;
409
410
411 (*
412 StartBuildProcedure - Builds a Procedure.
413
414 The Stack:
415
416 Entry Exit
417
418 <- Ptr
419 +------------+
420 Ptr -> | ProcSym |
421 +------------+ |------------|
422 | Name | | Name |
423 |------------| |------------|
424 *)
425
426 PROCEDURE StartBuildProcedure ;
427
428
429 (*
430 EndBuildProcedure - Ends building a Procedure.
431 It checks the start procedure name matches the end
432 procedure name.
433
434 The Stack:
435
436
437 Entry Exit
438
439 Ptr ->
440 +------------+
441 | NameEnd |
442 |------------|
443 | ProcSym |
444 |------------|
445 | NameStart |
446 |------------|
447 Empty
448 *)
449
450 PROCEDURE EndBuildProcedure ;
451
452
453 (*
454 BuildProcedureHeading - Builds a procedure heading for the definition
455 module procedures.
456
457 Operation only performed if compiling a
458 definition module.
459
460 The Stack:
461
462 Entry Exit
463
464 Ptr ->
465 +------------+
466 | ProcSym | Empty
467 |------------|
468
469 *)
470
471 PROCEDURE BuildProcedureHeading ;
472
473
474 (*
475 EndBuildForward - Ends building a forward procedure declaration.
476
477 The Stack:
478
479 (This procedure is not defined in definition module)
480
481 Entry Exit
482
483 Ptr ->
484 +------------+
485 | ProcSym |
486 |------------|
487 | NameStart |
488 |------------|
489 Empty
490 *)
491
492 PROCEDURE EndBuildForward (forwardPos: CARDINAL) ;
493
494
495 (*
496 BuildNulName - Pushes a NulKey onto the top of the stack.
497 The Stack:
498
499
500 Entry Exit
501
502 <- Ptr
503 Empty +------------+
504 | NulKey |
505 |------------|
506 *)
507
508 PROCEDURE BuildNulName ;
509
510
511 (*
512 BuildTypeEnd - Pops the type Type and Name.
513 The Stack:
514
515
516 Entry Exit
517
518
519 Ptr ->
520 +-------------+
521 | Type | Name | Empty
522 |-------------|
523 *)
524
525 PROCEDURE BuildTypeEnd ;
526
527
528 (*
529 BuildImportStatement - create a new import statement in the current module.
530 It ignores local modules.
531
532 The quadruple stack is not used.
533 *)
534
535 PROCEDURE BuildImportStatement (tok: CARDINAL) ;
536
537
538 (*
539 AddImportToImportStatement - the top of stack is expected to be a module name.
540 This is looked up from the module universe and
541 wrapped in an import symbol and placed into the
542 current import statement.
543
544 The quadruple stack is unchanged.
545
546 Entry Exit
547
548
549 Ptr -> <- Ptr
550 +---------------------+ +---------------------+
551 | ImportedModuleName | | ImportedModuleName |
552 |---------------------| |---------------------|
553 *)
554
555 PROCEDURE AddImportToImportStatement (qualified: BOOLEAN) ;
556
557
558 END P1SymBuild.