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