Branch data Line data Source code
1 : : /* do not edit automatically generated by mc from P1SymBuild. */
2 : : /* P1SymBuild.mod pass 1 symbol creation.
3 : :
4 : : Copyright (C) 2001-2025 Free Software Foundation, Inc.
5 : : Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 : :
7 : : This file is part of GNU Modula-2.
8 : :
9 : : GNU Modula-2 is free software; you can redistribute it and/or modify
10 : : it under the terms of the GNU General Public License as published by
11 : : the Free Software Foundation; either version 3, or (at your option)
12 : : any later version.
13 : :
14 : : GNU Modula-2 is distributed in the hope that it will be useful, but
15 : : WITHOUT ANY WARRANTY; without even the implied warranty of
16 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : : General Public License for more details.
18 : :
19 : : You should have received a copy of the GNU General Public License
20 : : along with GNU Modula-2; see the file COPYING3. If not see
21 : : <http://www.gnu.org/licenses/>. */
22 : :
23 : : #include "config.h"
24 : : #include "system.h"
25 : : #include "gcc-consolidation.h"
26 : :
27 : : #include <stdbool.h>
28 : : # if !defined (PROC_D)
29 : : # define PROC_D
30 : : typedef void (*PROC_t) (void);
31 : : typedef struct { PROC_t proc; } PROC;
32 : : # endif
33 : :
34 : : # if !defined (FALSE)
35 : : # define FALSE (1==0)
36 : : # endif
37 : :
38 : : #define _P1SymBuild_C
39 : :
40 : : #include "GP1SymBuild.h"
41 : : # include "GASCII.h"
42 : : # include "GNameKey.h"
43 : : # include "GM2Debug.h"
44 : : # include "GM2LexBuf.h"
45 : : # include "GM2MetaError.h"
46 : : # include "GDynamicStrings.h"
47 : : # include "GM2Printf.h"
48 : : # include "GM2Options.h"
49 : : # include "GM2Reserved.h"
50 : : # include "GFifoQueue.h"
51 : : # include "GP0SymBuild.h"
52 : : # include "Glibc.h"
53 : : # include "GSymbolTable.h"
54 : : # include "GM2Batch.h"
55 : : # include "GM2Quads.h"
56 : : # include "GM2Comp.h"
57 : :
58 : : # define Debugging false
59 : : static unsigned int importStatementCount;
60 : : extern "C" void P1SymBuild_P1StartBuildDefinitionModule (void);
61 : : extern "C" void P1SymBuild_P1EndBuildDefinitionModule (void);
62 : : extern "C" void P1SymBuild_P1StartBuildImplementationModule (void);
63 : : extern "C" void P1SymBuild_P1EndBuildImplementationModule (void);
64 : : extern "C" void P1SymBuild_P1StartBuildProgramModule (void);
65 : : extern "C" void P1SymBuild_P1EndBuildProgramModule (void);
66 : :
67 : : /*
68 : : StartBuildInnerModule - Creates an Inner module and starts
69 : : a new scope.
70 : :
71 : : The Stack is expected:
72 : :
73 : : Entry Exit
74 : :
75 : : Ptr -> <- Ptr
76 : : +------------+ +-----------+
77 : : | NameStart | | NameStart |
78 : : |------------| |-----------|
79 : :
80 : : */
81 : :
82 : : extern "C" void P1SymBuild_StartBuildInnerModule (void);
83 : :
84 : : /*
85 : : EndBuildInnerModule - Destroys the Inner module scope and
86 : : checks for correct name.
87 : :
88 : : The Stack is expected:
89 : :
90 : : Entry Exit
91 : :
92 : : Ptr ->
93 : : +------------+ +-----------+
94 : : | NameEnd | | |
95 : : |------------| |-----------|
96 : : | NameStart | | | <- Ptr
97 : : |------------| |-----------|
98 : : */
99 : :
100 : : extern "C" void P1SymBuild_EndBuildInnerModule (void);
101 : :
102 : : /*
103 : : BuildImportOuterModule - Builds imported identifiers into an outer module
104 : : from a definition module.
105 : :
106 : : The Stack is expected:
107 : :
108 : : Entry OR Entry
109 : :
110 : : Ptr -> Ptr ->
111 : : +------------+ +-----------+
112 : : | # | | # |
113 : : |------------| |-----------|
114 : : | Id1 | | Id1 |
115 : : |------------| |-----------|
116 : : . . . .
117 : : . . . .
118 : : . . . .
119 : : |------------| |-----------|
120 : : | Id# | | Id# |
121 : : |------------| |-----------|
122 : : | ImportTok | | Ident |
123 : : |------------| |-----------|
124 : :
125 : : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
126 : :
127 : :
128 : : Exit
129 : :
130 : : All above stack discarded
131 : : */
132 : :
133 : : extern "C" void P1SymBuild_BuildImportOuterModule (bool definition);
134 : :
135 : : /*
136 : : BuildExportOuterModule - Builds exported identifiers from an outer module
137 : : to the outside world of library modules.
138 : :
139 : : The Stack is expected:
140 : :
141 : : Entry OR Entry
142 : :
143 : : Ptr -> Ptr ->
144 : : +------------+ +--------------+
145 : : | # | | # |
146 : : |------------| |--------------|
147 : : | Id1 | | Id1 |
148 : : |------------| |--------------|
149 : : . . . .
150 : : . . . .
151 : : . . . .
152 : : |------------| |--------------|
153 : : | Id# | | Id# |
154 : : |------------| |--------------|
155 : : | ExportTok | | QualifiedTok |
156 : : |------------| |--------------|
157 : :
158 : : EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
159 : :
160 : : Error Condition
161 : :
162 : :
163 : : Exit
164 : :
165 : : All above stack discarded
166 : : */
167 : :
168 : : extern "C" void P1SymBuild_BuildExportOuterModule (void);
169 : :
170 : : /*
171 : : CheckExplicitExported - checks to see whether we are compiling
172 : : a definition module and whether the ident
173 : : is implicitly export qualified or unqualified.
174 : :
175 : :
176 : : The Stack is expected:
177 : :
178 : : Entry Exit
179 : :
180 : : Ptr -> Ptr ->
181 : : +------------+ +-----------+
182 : : | Identname | | Identname |
183 : : |------------| |-----------|
184 : :
185 : : */
186 : :
187 : : extern "C" void P1SymBuild_CheckExplicitExported (void);
188 : :
189 : : /*
190 : : BuildImportInnerModule - Builds imported identifiers into an inner module
191 : : from the last level of module.
192 : :
193 : : The Stack is expected:
194 : :
195 : : Entry OR Entry
196 : :
197 : : Ptr -> Ptr ->
198 : : +------------+ +-----------+
199 : : | # | | # |
200 : : |------------| |-----------|
201 : : | Id1 | | Id1 |
202 : : |------------| |-----------|
203 : : . . . .
204 : : . . . .
205 : : . . . .
206 : : |------------| |-----------|
207 : : | Id# | | Id# |
208 : : |------------| |-----------|
209 : : | ImportTok | | Ident |
210 : : |------------| |-----------|
211 : :
212 : : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
213 : :
214 : : Exit
215 : :
216 : : All above stack discarded
217 : : */
218 : :
219 : : extern "C" void P1SymBuild_BuildImportInnerModule (void);
220 : :
221 : : /*
222 : : BuildExportInnerModule - Builds exported identifiers from an inner module
223 : : to the next layer module.
224 : :
225 : : The Stack is expected:
226 : :
227 : : Entry OR Entry
228 : :
229 : : Ptr -> Ptr ->
230 : : +------------+ +--------------+
231 : : | # | | # |
232 : : |------------| |--------------|
233 : : | Id1 | | Id1 |
234 : : |------------| |--------------|
235 : : . . . .
236 : : . . . .
237 : : . . . .
238 : : |------------| |--------------|
239 : : | Id# | | Id# |
240 : : |------------| |--------------|
241 : : | ExportTok | | QualifiedTok |
242 : : |------------| |--------------|
243 : :
244 : : EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
245 : :
246 : :
247 : : Exit
248 : :
249 : :
250 : : All above stack discarded
251 : : */
252 : :
253 : : extern "C" void P1SymBuild_BuildExportInnerModule (void);
254 : :
255 : : /*
256 : : StartBuildEnumeration - Builds an Enumeration type Type.
257 : :
258 : :
259 : : Stack
260 : :
261 : : Entry Exit
262 : :
263 : : Ptr ->
264 : : +------------+
265 : : | # |
266 : : |------------|
267 : : | en 1 |
268 : : |------------|
269 : : | en 2 |
270 : : |------------|
271 : : . .
272 : : . .
273 : : . . <- Ptr
274 : : |------------| +------------+
275 : : | en # | | Type |
276 : : |------------| |------------|
277 : : | Name | | Name |
278 : : |------------| |------------|
279 : : */
280 : :
281 : : extern "C" void P1SymBuild_StartBuildEnumeration (void);
282 : :
283 : : /*
284 : : EndBuildEnumeration - completes the construction of the enumeration type.
285 : :
286 : :
287 : : Stack
288 : :
289 : : Entry Exit
290 : :
291 : : Ptr ->
292 : : +------------+
293 : : | Type | <- Ptr
294 : : |------------| +---------------+
295 : : | Name | | Type | Name |
296 : : |------------| |---------------|
297 : :
298 : : Empty
299 : : */
300 : :
301 : : extern "C" void P1SymBuild_EndBuildEnumeration (void);
302 : :
303 : : /*
304 : : BuildHiddenType - Builds a Hidden Type.
305 : :
306 : :
307 : : Stack
308 : :
309 : : Entry Exit
310 : :
311 : : Ptr ->
312 : : +------------+
313 : : | Name | <- Ptr
314 : : |------------| Empty
315 : : */
316 : :
317 : : extern "C" void P1SymBuild_BuildHiddenType (void);
318 : :
319 : : /*
320 : : StartBuildProcedure - Builds a Procedure.
321 : :
322 : : The Stack:
323 : :
324 : : Entry Exit
325 : :
326 : : Ptr -> <- Ptr
327 : : +------------+ +------------+
328 : : | Name | | ProcSym |
329 : : |------------| |------------|
330 : : | inlinetok | | |
331 : : | or | | |
332 : : | builtintok | | |
333 : : | or name or | | Name |
334 : : | NulTok | | |
335 : : |------------| |------------|
336 : : */
337 : :
338 : : extern "C" void P1SymBuild_StartBuildProcedure (void);
339 : :
340 : : /*
341 : : EndBuildProcedure - Ends building a Procedure.
342 : : It checks the start procedure name matches the end
343 : : procedure name.
344 : :
345 : : The Stack:
346 : :
347 : : (Procedure Not Defined in definition module)
348 : :
349 : : Entry Exit
350 : :
351 : : Ptr ->
352 : : +------------+
353 : : | NameEnd |
354 : : |------------|
355 : : | ProcSym |
356 : : |------------|
357 : : | NameStart |
358 : : |------------|
359 : : Empty
360 : : */
361 : :
362 : : extern "C" void P1SymBuild_EndBuildProcedure (void);
363 : :
364 : : /*
365 : : BuildProcedureHeading - Builds a procedure heading for the definition
366 : : module procedures.
367 : :
368 : : Operation only performed if compiling a
369 : : definition module.
370 : :
371 : : The Stack:
372 : :
373 : : Entry Exit
374 : :
375 : : Ptr ->
376 : : +------------+
377 : : | ProcSym |
378 : : |------------|
379 : : | NameStart |
380 : : |------------|
381 : : Empty
382 : :
383 : : */
384 : :
385 : : extern "C" void P1SymBuild_BuildProcedureHeading (void);
386 : :
387 : : /*
388 : : EndBuildForward - Ends building a forward procedure declaration.
389 : :
390 : : The Stack:
391 : :
392 : : (This procedure is not defined in definition module)
393 : :
394 : : Entry Exit
395 : :
396 : : Ptr ->
397 : : +------------+
398 : : | ProcSym |
399 : : |------------|
400 : : | NameStart |
401 : : |------------|
402 : : Empty
403 : : */
404 : :
405 : : extern "C" void P1SymBuild_EndBuildForward (unsigned int forwardPos);
406 : :
407 : : /*
408 : : BuildNulName - Pushes a NulName onto the top of the stack.
409 : : The Stack:
410 : :
411 : :
412 : : Entry Exit
413 : :
414 : : <- Ptr
415 : : Empty +------------+
416 : : | NulName |
417 : : |------------|
418 : : */
419 : :
420 : : extern "C" void P1SymBuild_BuildNulName (void);
421 : :
422 : : /*
423 : : BuildTypeEnd - Pops the type Type and Name.
424 : : The Stack:
425 : :
426 : :
427 : : Entry Exit
428 : :
429 : :
430 : : Ptr ->
431 : : +-------------+
432 : : | Type | Name | Empty
433 : : |-------------|
434 : : */
435 : :
436 : : extern "C" void P1SymBuild_BuildTypeEnd (void);
437 : :
438 : : /*
439 : : BuildImportStatement - create a new import statement in the current module.
440 : : It ignores local modules.
441 : :
442 : : The quadruple stack is not used.
443 : : */
444 : :
445 : : extern "C" void P1SymBuild_BuildImportStatement (unsigned int tok);
446 : :
447 : : /*
448 : : AddImportToImportStatement - the top of stack is expected to be a module name.
449 : : This is looked up from the module universe and
450 : : wrapped in an import symbol and placed into the
451 : : current import statement.
452 : :
453 : : The quadruple stack is unchanged.
454 : :
455 : : Entry Exit
456 : :
457 : :
458 : : Ptr -> <- Ptr
459 : : +---------------------+ +---------------------+
460 : : | ImportedModuleName | | ImportedModuleName |
461 : : |---------------------| |---------------------|
462 : : */
463 : :
464 : : extern "C" void P1SymBuild_AddImportToImportStatement (bool qualified);
465 : :
466 : 162871 : extern "C" void P1SymBuild_P1StartBuildDefinitionModule (void)
467 : : {
468 : 162871 : NameKey_Name name;
469 : 162871 : unsigned int language;
470 : 162871 : unsigned int ModuleSym;
471 : :
472 : : /*
473 : : StartBuildDefinitionModule - Creates a definition module and starts
474 : : a new scope.
475 : :
476 : : he Stack is expected:
477 : :
478 : : Entry Exit
479 : :
480 : : Ptr ->
481 : : +------------+
482 : : | NameStart | <- Ptr
483 : : |------------| +------------+
484 : : | NulName/"C"| | NameStart |
485 : : |------------| |------------|
486 : : */
487 : 162871 : importStatementCount = 0;
488 : 162871 : M2Quads_PopT (&name);
489 : : /* CheckFileName(name, 'definition') ; */
490 : 162871 : ModuleSym = M2Batch_MakeDefinitionSource (M2LexBuf_GetTokenNo (), name);
491 : 162871 : SymbolTable_PutDoesNotNeedExportList (ModuleSym);
492 : 162871 : SymbolTable_SetCurrentModule (ModuleSym);
493 : 162871 : SymbolTable_SetFileModule (ModuleSym);
494 : 162871 : SymbolTable_StartScope (ModuleSym);
495 : 162871 : M2Debug_Assert (SymbolTable_IsDefImp (ModuleSym));
496 : 162871 : M2Debug_Assert (M2Comp_CompilingDefinitionModule ());
497 : 162871 : M2Quads_PopT (&language);
498 : 162871 : if ((language != SymbolTable_NulSym) && (SymbolTable_IsConstString (language)))
499 : : {
500 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
501 : 13092 : if ((SymbolTable_GetSymName (language)) == (NameKey_MakeKey ((const char *) "C", 1)))
502 : : {
503 : 13092 : SymbolTable_PutDefinitionForC (ModuleSym);
504 : : }
505 : 0 : else if ((SymbolTable_GetSymName (language)) == NameKey_NulName)
506 : : {
507 : : /* avoid dangling else. */
508 : 0 : M2MetaError_MetaError0 ((const char *) "{%E}currently a non modula-2 definition module can only be declared as DEFINITION FOR {%k\"C\"}", 93);
509 : : }
510 : : else
511 : : {
512 : : /* avoid dangling else. */
513 : 0 : M2MetaError_MetaError1 ((const char *) "unknown definition module language {%1Ea}, currently a non modula-2 definition module can only be declared as DEFINITION FOR {%k\"C\"}", 132, language);
514 : : }
515 : : }
516 : 162871 : M2Quads_PushT (name);
517 : 162871 : P0SymBuild_EnterBlock (name);
518 : 162871 : }
519 : :
520 : 162871 : extern "C" void P1SymBuild_P1EndBuildDefinitionModule (void)
521 : : {
522 : 162871 : unsigned int start;
523 : 162871 : NameKey_Name NameStart;
524 : 162871 : NameKey_Name NameEnd;
525 : :
526 : : /*
527 : : EndBuildDefinitionModule - Destroys the definition module scope and
528 : : checks for correct name.
529 : :
530 : : The Stack is expected:
531 : :
532 : : Entry Exit
533 : :
534 : : Ptr ->
535 : : +------------+ +-----------+
536 : : | NameEnd | | |
537 : : |------------| |-----------|
538 : : | NameStart | | | <- Ptr
539 : : |------------| |-----------|
540 : : */
541 : 162871 : M2Debug_Assert (M2Comp_CompilingDefinitionModule ());
542 : 162871 : SymbolTable_EndScope ();
543 : 162871 : M2Quads_PopTtok (&NameStart, &start);
544 : 162871 : M2Quads_PopT (&NameEnd);
545 : 162871 : if (Debugging)
546 : : {
547 : : M2Printf_printf0 ((const char *) "pass 1: ", 8);
548 : : SymbolTable_DisplayTrees (SymbolTable_GetCurrentModule ());
549 : : }
550 : 162871 : if (NameStart != NameEnd)
551 : : {
552 : 0 : M2MetaError_MetaError1 ((const char *) "inconsistent definition module name {%1Wa}", 42, SymbolTable_MakeError (start, NameStart));
553 : : }
554 : 162871 : P0SymBuild_LeaveBlock ();
555 : 162871 : }
556 : :
557 : 71027 : extern "C" void P1SymBuild_P1StartBuildImplementationModule (void)
558 : : {
559 : 71027 : unsigned int tok;
560 : 71027 : NameKey_Name name;
561 : 71027 : unsigned int ModuleSym;
562 : :
563 : : /*
564 : : StartBuildImplementationModule - Creates an implementation module and starts
565 : : a new scope.
566 : :
567 : : The Stack is expected:
568 : :
569 : : Entry Exit
570 : :
571 : : Ptr -> <- Ptr
572 : : +------------+ +-----------+
573 : : | NameStart | | NameStart |
574 : : |------------| |-----------|
575 : :
576 : : */
577 : 71027 : importStatementCount = 0;
578 : 71027 : M2Quads_PopTtok (&name, &tok);
579 : : /* CheckFileName(name, 'implementation') ; */
580 : 71027 : ModuleSym = M2Batch_MakeImplementationSource (tok, name);
581 : 71027 : SymbolTable_SetCurrentModule (ModuleSym);
582 : 71027 : SymbolTable_SetFileModule (ModuleSym);
583 : 71027 : SymbolTable_StartScope (ModuleSym);
584 : 71027 : if (! (SymbolTable_IsDefImp (ModuleSym)))
585 : : {
586 : 0 : M2MetaError_MetaError1 ((const char *) "cannot find corresponding definition module for {%1Ea}", 54, ModuleSym);
587 : : }
588 : 71027 : M2Debug_Assert (M2Comp_CompilingImplementationModule ());
589 : 71027 : M2Quads_PushTtok (name, tok);
590 : 71027 : P0SymBuild_EnterBlock (name);
591 : 71027 : }
592 : :
593 : 71027 : extern "C" void P1SymBuild_P1EndBuildImplementationModule (void)
594 : : {
595 : 71027 : unsigned int start;
596 : 71027 : unsigned int end;
597 : 71027 : NameKey_Name NameStart;
598 : 71027 : NameKey_Name NameEnd;
599 : :
600 : : /*
601 : : EndBuildImplementationModule - Destroys the implementation module scope and
602 : : checks for correct name.
603 : :
604 : : The Stack is expected:
605 : :
606 : : Entry Exit
607 : :
608 : : Ptr ->
609 : : +------------+ +-----------+
610 : : | NameEnd | | |
611 : : |------------| |-----------|
612 : : | NameStart | | | <- Ptr
613 : : |------------| |-----------|
614 : : */
615 : 71027 : SymbolTable_ResolveImports ();
616 : 71027 : M2Debug_Assert (M2Comp_CompilingImplementationModule ());
617 : 71027 : SymbolTable_EndScope ();
618 : 71027 : M2Quads_PopTtok (&NameStart, &start);
619 : 71027 : M2Quads_PopTtok (&NameEnd, &end);
620 : 71027 : if (NameStart != NameEnd)
621 : : {
622 : 0 : M2MetaError_MetaErrorT1 (end, (const char *) "inconsistent implementation module name {%1Wa}", 46, SymbolTable_MakeError (start, NameStart));
623 : : }
624 : 71027 : P0SymBuild_LeaveBlock ();
625 : 71027 : }
626 : :
627 : 11744 : extern "C" void P1SymBuild_P1StartBuildProgramModule (void)
628 : : {
629 : 11744 : unsigned int tok;
630 : 11744 : NameKey_Name name;
631 : 11744 : unsigned int ModuleSym;
632 : :
633 : : /*
634 : : StartBuildProgramModule - Creates a program module and starts
635 : : a new scope.
636 : :
637 : : The Stack is expected:
638 : :
639 : : Entry Exit
640 : :
641 : : Ptr -> <- Ptr
642 : : +------------+ +-----------+
643 : : | NameStart | | NameStart |
644 : : |------------| |-----------|
645 : :
646 : : */
647 : 11744 : importStatementCount = 0;
648 : 11744 : M2Quads_PopTtok (&name, &tok);
649 : : /* CheckFileName(name, 'main') ; */
650 : 11744 : ModuleSym = M2Batch_MakeProgramSource (tok, name);
651 : 11744 : SymbolTable_SetCurrentModule (ModuleSym);
652 : 11744 : SymbolTable_SetFileModule (ModuleSym);
653 : 11744 : SymbolTable_StartScope (ModuleSym);
654 : 11744 : if ((! (M2Comp_CompilingProgramModule ())) || (SymbolTable_IsDefImp (ModuleSym)))
655 : : {
656 : 6 : M2MetaError_MetaErrorT1 (tok, (const char *) "module {%1Ea} has a corresponding DEFINITION MODULE but no IMPLEMENTATION keyword in the main module", 100, ModuleSym);
657 : : }
658 : 11744 : M2Quads_PushTtok (name, tok);
659 : 11744 : P0SymBuild_EnterBlock (name);
660 : 11744 : }
661 : :
662 : 11744 : extern "C" void P1SymBuild_P1EndBuildProgramModule (void)
663 : : {
664 : 11744 : unsigned int start;
665 : 11744 : unsigned int end;
666 : 11744 : NameKey_Name NameStart;
667 : 11744 : NameKey_Name NameEnd;
668 : :
669 : : /*
670 : : EndBuildProgramModule - Destroys the program module scope and
671 : : checks for correct name.
672 : :
673 : : The Stack is expected:
674 : :
675 : : Entry Exit
676 : :
677 : : Ptr ->
678 : : +------------+ +-----------+
679 : : | NameEnd | | |
680 : : |------------| |-----------|
681 : : | NameStart | | | <- Ptr
682 : : |------------| |-----------|
683 : : */
684 : 11744 : SymbolTable_ResolveImports ();
685 : 11744 : M2Debug_Assert (M2Comp_CompilingProgramModule ());
686 : 11738 : SymbolTable_EndScope ();
687 : 11738 : M2Quads_PopTtok (&NameStart, &start);
688 : 11738 : M2Quads_PopTtok (&NameEnd, &end);
689 : 11738 : if (Debugging)
690 : : {
691 : : M2Printf_printf0 ((const char *) "pass 1: ", 8);
692 : : SymbolTable_DisplayTrees (SymbolTable_GetCurrentModule ());
693 : : }
694 : 11738 : if (NameStart != NameEnd)
695 : : {
696 : 0 : M2MetaError_MetaErrorT1 (end, (const char *) "inconsistent program module name {%1Wa}", 39, SymbolTable_MakeError (start, NameStart));
697 : : }
698 : 11738 : P0SymBuild_LeaveBlock ();
699 : 11738 : }
700 : :
701 : :
702 : : /*
703 : : StartBuildInnerModule - Creates an Inner module and starts
704 : : a new scope.
705 : :
706 : : The Stack is expected:
707 : :
708 : : Entry Exit
709 : :
710 : : Ptr -> <- Ptr
711 : : +------------+ +-----------+
712 : : | NameStart | | NameStart |
713 : : |------------| |-----------|
714 : :
715 : : */
716 : :
717 : 428 : extern "C" void P1SymBuild_StartBuildInnerModule (void)
718 : : {
719 : 428 : unsigned int tok;
720 : 428 : NameKey_Name name;
721 : 428 : unsigned int ModuleSym;
722 : :
723 : 428 : M2Quads_PopTtok (&name, &tok);
724 : 428 : ModuleSym = SymbolTable_GetSym (name);
725 : 428 : M2Debug_Assert (ModuleSym != SymbolTable_NulSym);
726 : 428 : SymbolTable_StartScope (ModuleSym);
727 : 428 : M2Debug_Assert (! (SymbolTable_IsDefImp (ModuleSym)));
728 : 428 : M2Quads_PushTtok (name, tok);
729 : 428 : P0SymBuild_EnterBlock (name);
730 : 428 : }
731 : :
732 : :
733 : : /*
734 : : EndBuildInnerModule - Destroys the Inner module scope and
735 : : checks for correct name.
736 : :
737 : : The Stack is expected:
738 : :
739 : : Entry Exit
740 : :
741 : : Ptr ->
742 : : +------------+ +-----------+
743 : : | NameEnd | | |
744 : : |------------| |-----------|
745 : : | NameStart | | | <- Ptr
746 : : |------------| |-----------|
747 : : */
748 : :
749 : 428 : extern "C" void P1SymBuild_EndBuildInnerModule (void)
750 : : {
751 : 428 : unsigned int start;
752 : 428 : unsigned int end;
753 : 428 : NameKey_Name NameStart;
754 : 428 : NameKey_Name NameEnd;
755 : :
756 : 428 : SymbolTable_EndScope ();
757 : 428 : M2Quads_PopTtok (&NameStart, &start);
758 : 428 : M2Quads_PopTtok (&NameEnd, &end);
759 : 428 : if (NameStart != NameEnd)
760 : : {
761 : 0 : M2MetaError_MetaErrorT1 (end, (const char *) "inconsistent inner module name {%1Wa}", 37, SymbolTable_MakeError (start, NameStart));
762 : : }
763 : 428 : P0SymBuild_LeaveBlock ();
764 : 428 : }
765 : :
766 : :
767 : : /*
768 : : BuildImportOuterModule - Builds imported identifiers into an outer module
769 : : from a definition module.
770 : :
771 : : The Stack is expected:
772 : :
773 : : Entry OR Entry
774 : :
775 : : Ptr -> Ptr ->
776 : : +------------+ +-----------+
777 : : | # | | # |
778 : : |------------| |-----------|
779 : : | Id1 | | Id1 |
780 : : |------------| |-----------|
781 : : . . . .
782 : : . . . .
783 : : . . . .
784 : : |------------| |-----------|
785 : : | Id# | | Id# |
786 : : |------------| |-----------|
787 : : | ImportTok | | Ident |
788 : : |------------| |-----------|
789 : :
790 : : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
791 : :
792 : :
793 : : Exit
794 : :
795 : : All above stack discarded
796 : : */
797 : :
798 : 401308 : extern "C" void P1SymBuild_BuildImportOuterModule (bool definition)
799 : : {
800 : 401308 : unsigned int Sym;
801 : 401308 : unsigned int ModSym;
802 : 401308 : unsigned int i;
803 : 401308 : unsigned int n;
804 : :
805 : 401308 : M2Quads_PopT (&n); /* n = # of the Ident List */
806 : 401308 : if ((M2Quads_OperandT (n+1)) == M2Reserved_ImportTok)
807 : : {
808 : : /* Ident list contains Module Names */
809 : : i = 1;
810 : 113296 : while (i <= n)
811 : : {
812 : 64236 : ModSym = M2Batch_LookupModule (M2Quads_OperandTok ((n+1)-i), M2Quads_OperandT ((n+1)-i));
813 : 64236 : SymbolTable_PutImported (ModSym);
814 : 64236 : if (definition)
815 : : {
816 : 10013 : SymbolTable_PutIncludedByDefinition (ModSym);
817 : : }
818 : 64236 : i += 1;
819 : : }
820 : : }
821 : : else
822 : : {
823 : : /* Ident List contains list of objects */
824 : 352248 : ModSym = M2Batch_LookupModule (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
825 : 352248 : i = 1;
826 : 1553148 : while (i <= n)
827 : : {
828 : 848652 : Sym = SymbolTable_GetExported (M2Quads_OperandTok ((n+1)-i), ModSym, M2Quads_OperandT ((n+1)-i));
829 : 848652 : SymbolTable_PutImported (Sym);
830 : 848652 : i += 1;
831 : : }
832 : : }
833 : 401308 : M2Quads_PopN (n+1); /* clear stack */
834 : 401308 : }
835 : :
836 : :
837 : : /*
838 : : BuildExportOuterModule - Builds exported identifiers from an outer module
839 : : to the outside world of library modules.
840 : :
841 : : The Stack is expected:
842 : :
843 : : Entry OR Entry
844 : :
845 : : Ptr -> Ptr ->
846 : : +------------+ +--------------+
847 : : | # | | # |
848 : : |------------| |--------------|
849 : : | Id1 | | Id1 |
850 : : |------------| |--------------|
851 : : . . . .
852 : : . . . .
853 : : . . . .
854 : : |------------| |--------------|
855 : : | Id# | | Id# |
856 : : |------------| |--------------|
857 : : | ExportTok | | QualifiedTok |
858 : : |------------| |--------------|
859 : :
860 : : EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
861 : :
862 : : Error Condition
863 : :
864 : :
865 : : Exit
866 : :
867 : : All above stack discarded
868 : : */
869 : :
870 : 86044 : extern "C" void P1SymBuild_BuildExportOuterModule (void)
871 : : {
872 : 86044 : unsigned int i;
873 : 86044 : unsigned int n;
874 : :
875 : 86044 : M2Quads_PopT (&n); /* n = # of the Ident List */
876 : 86044 : if (((M2Quads_OperandT (n+1)) == M2Reserved_QualifiedTok) && (M2Comp_CompilingDefinitionModule ())) /* n = # of the Ident List */
877 : : {
878 : 74442 : SymbolTable_PutDoesNeedExportList (SymbolTable_GetCurrentModule ());
879 : : /* Ident List contains list of export qualified objects */
880 : 74442 : i = 1;
881 : 1699581 : while (i <= n)
882 : : {
883 : 1550697 : SymbolTable_PutExportQualified (M2Quads_OperandTok (i), M2Quads_OperandT (i));
884 : 1550697 : i += 1;
885 : : }
886 : : }
887 : 11602 : else if (((M2Quads_OperandT (n+1)) == M2Reserved_UnQualifiedTok) && (M2Comp_CompilingDefinitionModule ()))
888 : : {
889 : : /* avoid dangling else. */
890 : 11602 : SymbolTable_PutDoesNeedExportList (SymbolTable_GetCurrentModule ());
891 : : /* Ident List contains list of export unqualified objects */
892 : 11602 : i = 1;
893 : 838096 : while (i <= n)
894 : : {
895 : 814892 : SymbolTable_PutExportUnQualified (M2Quads_OperandTok (i), M2Quads_OperandT (i));
896 : 814892 : i += 1;
897 : : }
898 : : }
899 : 0 : else if (M2Comp_CompilingDefinitionModule ())
900 : : {
901 : : /* avoid dangling else. */
902 : 0 : M2MetaError_MetaError0 ((const char *) "the {%EkEXPORT} must be either {%kQUALIFIED} or {%kUNQUALIFIED} in a definition module", 86);
903 : : }
904 : : else
905 : : {
906 : : /* avoid dangling else. */
907 : 0 : M2MetaError_MetaError0 ((const char *) "{%E}only allowed inter module exports in a definition module", 60);
908 : : }
909 : 86044 : M2Quads_PopN (n+1); /* clear stack */
910 : 86044 : }
911 : :
912 : :
913 : : /*
914 : : CheckExplicitExported - checks to see whether we are compiling
915 : : a definition module and whether the ident
916 : : is implicitly export qualified or unqualified.
917 : :
918 : :
919 : : The Stack is expected:
920 : :
921 : : Entry Exit
922 : :
923 : : Ptr -> Ptr ->
924 : : +------------+ +-----------+
925 : : | Identname | | Identname |
926 : : |------------| |-----------|
927 : :
928 : : */
929 : :
930 : 7769522 : extern "C" void P1SymBuild_CheckExplicitExported (void)
931 : : {
932 : 7769522 : if ((M2Comp_CompilingDefinitionModule ()) && (SymbolTable_DoesNotNeedExportList (SymbolTable_GetCurrentModule ())))
933 : : {
934 : : /* printf1('exporting identifier %a
935 : : ', OperandT(1)) ; */
936 : 2151589 : SymbolTable_PutExportQualified (M2Quads_OperandTok (1), M2Quads_OperandT (1));
937 : : }
938 : 7769522 : }
939 : :
940 : :
941 : : /*
942 : : BuildImportInnerModule - Builds imported identifiers into an inner module
943 : : from the last level of module.
944 : :
945 : : The Stack is expected:
946 : :
947 : : Entry OR Entry
948 : :
949 : : Ptr -> Ptr ->
950 : : +------------+ +-----------+
951 : : | # | | # |
952 : : |------------| |-----------|
953 : : | Id1 | | Id1 |
954 : : |------------| |-----------|
955 : : . . . .
956 : : . . . .
957 : : . . . .
958 : : |------------| |-----------|
959 : : | Id# | | Id# |
960 : : |------------| |-----------|
961 : : | ImportTok | | Ident |
962 : : |------------| |-----------|
963 : :
964 : : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
965 : :
966 : : Exit
967 : :
968 : : All above stack discarded
969 : : */
970 : :
971 : 230 : extern "C" void P1SymBuild_BuildImportInnerModule (void)
972 : : {
973 : 230 : unsigned int Sym;
974 : 230 : unsigned int ModSym;
975 : 230 : unsigned int i;
976 : 230 : unsigned int n;
977 : :
978 : 230 : M2Quads_PopT (&n); /* n = # of the Ident List */
979 : 230 : if ((M2Quads_OperandT (n+1)) == M2Reserved_ImportTok)
980 : : {
981 : : /* Ident List contains list of objects */
982 : : i = 1;
983 : 334 : while (i <= n)
984 : : {
985 : 170 : SymbolTable_AddNameToImportList (M2Quads_OperandTok (i), M2Quads_OperandT (i));
986 : 170 : i += 1;
987 : : }
988 : : }
989 : : else
990 : : {
991 : : /* Ident List contains list of objects */
992 : 66 : ModSym = M2Batch_LookupOuterModule (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
993 : 66 : i = 1;
994 : 198 : while (i <= n)
995 : : {
996 : 66 : Sym = SymbolTable_GetExported (M2Quads_OperandTok ((n+1)-i), ModSym, M2Quads_OperandT ((n+1)-i));
997 : 66 : SymbolTable_PutImported (Sym);
998 : 66 : i += 1;
999 : : }
1000 : : }
1001 : 230 : M2Quads_PopN (n+1); /* clear stack */
1002 : 230 : }
1003 : :
1004 : :
1005 : : /*
1006 : : BuildExportInnerModule - Builds exported identifiers from an inner module
1007 : : to the next layer module.
1008 : :
1009 : : The Stack is expected:
1010 : :
1011 : : Entry OR Entry
1012 : :
1013 : : Ptr -> Ptr ->
1014 : : +------------+ +--------------+
1015 : : | # | | # |
1016 : : |------------| |--------------|
1017 : : | Id1 | | Id1 |
1018 : : |------------| |--------------|
1019 : : . . . .
1020 : : . . . .
1021 : : . . . .
1022 : : |------------| |--------------|
1023 : : | Id# | | Id# |
1024 : : |------------| |--------------|
1025 : : | ExportTok | | QualifiedTok |
1026 : : |------------| |--------------|
1027 : :
1028 : : EXPORT Id1, .. Id# ; EXPORT QUALIFIED Id1 .. Id# ;
1029 : :
1030 : :
1031 : : Exit
1032 : :
1033 : :
1034 : : All above stack discarded
1035 : : */
1036 : :
1037 : 282 : extern "C" void P1SymBuild_BuildExportInnerModule (void)
1038 : : {
1039 : 282 : unsigned int tok;
1040 : 282 : unsigned int PrevMod;
1041 : 282 : unsigned int Sym;
1042 : 282 : unsigned int i;
1043 : 282 : unsigned int n;
1044 : :
1045 : 282 : M2Quads_PopT (&n); /* n = # of the Ident List */
1046 : 282 : if ((M2Quads_OperandT (n+1)) == M2Reserved_ExportTok)
1047 : : {
1048 : : /* Ident List contains list of objects */
1049 : 282 : i = 1;
1050 : 282 : PrevMod = SymbolTable_GetScope (SymbolTable_GetCurrentScope ());
1051 : 870 : while (i <= n)
1052 : : {
1053 : 306 : tok = static_cast<unsigned int> (M2Quads_OperandTok (i));
1054 : 306 : if ((PrevMod != SymbolTable_NulSym) && ((SymbolTable_IsModule (PrevMod)) || (SymbolTable_IsDefImp (PrevMod))))
1055 : : {
1056 : 246 : Sym = SymbolTable_GetLocalSym (PrevMod, M2Quads_OperandT (i));
1057 : 246 : if (Sym == SymbolTable_NulSym)
1058 : : {
1059 : : /* avoid dangling else. */
1060 : 234 : Sym = SymbolTable_TryMoveUndeclaredSymToInnerModule (PrevMod, SymbolTable_GetCurrentScope (), M2Quads_OperandT (i));
1061 : 234 : if (Sym == SymbolTable_NulSym)
1062 : : {
1063 : 216 : Sym = SymbolTable_RequestSym (tok, M2Quads_OperandT (i));
1064 : 216 : SymbolTable_PutExported (Sym);
1065 : : }
1066 : : }
1067 : : else
1068 : : {
1069 : : /* use Sym which has already been created in outer scope */
1070 : 12 : SymbolTable_AddSymToModuleScope (SymbolTable_GetCurrentScope (), Sym);
1071 : : }
1072 : : }
1073 : : else
1074 : : {
1075 : 60 : Sym = SymbolTable_RequestSym (tok, M2Quads_OperandT (i));
1076 : 60 : SymbolTable_PutExported (Sym);
1077 : : }
1078 : 306 : i += 1;
1079 : : }
1080 : : }
1081 : : else
1082 : : {
1083 : 0 : M2MetaError_MetaError0 ((const char *) "{%EkQUALIFIED} not allowed in an inner module", 45);
1084 : : }
1085 : 282 : M2Quads_PopN (n+1); /* clear stack */
1086 : 282 : }
1087 : :
1088 : :
1089 : : /*
1090 : : StartBuildEnumeration - Builds an Enumeration type Type.
1091 : :
1092 : :
1093 : : Stack
1094 : :
1095 : : Entry Exit
1096 : :
1097 : : Ptr ->
1098 : : +------------+
1099 : : | # |
1100 : : |------------|
1101 : : | en 1 |
1102 : : |------------|
1103 : : | en 2 |
1104 : : |------------|
1105 : : . .
1106 : : . .
1107 : : . . <- Ptr
1108 : : |------------| +------------+
1109 : : | en # | | Type |
1110 : : |------------| |------------|
1111 : : | Name | | Name |
1112 : : |------------| |------------|
1113 : : */
1114 : :
1115 : 34138 : extern "C" void P1SymBuild_StartBuildEnumeration (void)
1116 : : {
1117 : 34138 : NameKey_Name name;
1118 : 34138 : unsigned int n;
1119 : 34138 : unsigned int i;
1120 : 34138 : unsigned int Type;
1121 : 34138 : unsigned int tokno;
1122 : :
1123 : 34138 : M2Quads_PopT (&n); /* No := # */
1124 : 34138 : name = static_cast<NameKey_Name> (M2Quads_OperandT (n+1)); /* No := # */
1125 : 34138 : tokno = static_cast<unsigned int> (M2Quads_OperandTok (n+1));
1126 : 34138 : Type = SymbolTable_MakeEnumeration (tokno, name);
1127 : 34138 : i = 1;
1128 : 531080 : while (i <= n)
1129 : : {
1130 : 462804 : SymbolTable_PutFieldEnumeration (M2Quads_OperandTok ((n-i)+1), Type, M2Quads_OperandT ((n-i)+1));
1131 : 462804 : i += 1;
1132 : : }
1133 : 34138 : FifoQueue_PutEnumerationIntoFifoQueue (Type); /* store enumeration away for pass 2 */
1134 : 34138 : M2Quads_PopN (n+1); /* store enumeration away for pass 2 */
1135 : 34138 : M2Quads_PushTtok (name, tokno);
1136 : 34138 : M2Quads_PushTtok (Type, tokno);
1137 : 34138 : }
1138 : :
1139 : :
1140 : : /*
1141 : : EndBuildEnumeration - completes the construction of the enumeration type.
1142 : :
1143 : :
1144 : : Stack
1145 : :
1146 : : Entry Exit
1147 : :
1148 : : Ptr ->
1149 : : +------------+
1150 : : | Type | <- Ptr
1151 : : |------------| +---------------+
1152 : : | Name | | Type | Name |
1153 : : |------------| |---------------|
1154 : :
1155 : : Empty
1156 : : */
1157 : :
1158 : 34138 : extern "C" void P1SymBuild_EndBuildEnumeration (void)
1159 : : {
1160 : 34138 : unsigned int tokno;
1161 : 34138 : unsigned int Sym;
1162 : 34138 : unsigned int Type;
1163 : 34138 : NameKey_Name n1;
1164 : 34138 : NameKey_Name n2;
1165 : 34138 : NameKey_Name name;
1166 : :
1167 : : /*
1168 : : Two cases
1169 : :
1170 : : - the type name the same as Name, or the name is nul. - do nothing.
1171 : : - when type with a name that is different to Name. In which case
1172 : : we create a new type.
1173 : : */
1174 : 34138 : M2Quads_PopTtok (&Type, &tokno);
1175 : 34138 : M2Quads_PopT (&name);
1176 : 34138 : if (Debugging)
1177 : : {
1178 : : n1 = SymbolTable_GetSymName (SymbolTable_GetCurrentModule ());
1179 : : M2Printf_printf2 ((const char *) "inside module %a declaring type name %a\\n", 41, (const unsigned char *) &n1, (sizeof (n1)-1), (const unsigned char *) &name, (sizeof (name)-1));
1180 : : if (! (SymbolTable_IsUnknown (Type)))
1181 : : {
1182 : : n1 = SymbolTable_GetSymName (SymbolTable_GetScope (Type));
1183 : : n2 = SymbolTable_GetSymName (Type);
1184 : : M2Printf_printf2 ((const char *) "type was created inside scope %a as name %a\\n", 45, (const unsigned char *) &n1, (sizeof (n1)-1), (const unsigned char *) &n2, (sizeof (n2)-1));
1185 : : }
1186 : : }
1187 : 34138 : if ((name == NameKey_NulName) || ((SymbolTable_GetSymName (Type)) == name))
1188 : : {
1189 : : /*
1190 : : Typically the declaration that causes this case is:
1191 : :
1192 : : VAR
1193 : : a: (blue, green, red) ;
1194 : : ^
1195 : : |
1196 : : +---- type has no name.
1197 : :
1198 : : in which case the constructed from StartBuildEnumeration is complete
1199 : : */
1200 : 34138 : M2Quads_PushTFtok (Type, name, tokno);
1201 : : }
1202 : : else
1203 : : {
1204 : : /* in this case we are seeing:
1205 : :
1206 : : TYPE
1207 : : name = (blue, green, red)
1208 : :
1209 : : so we construct the type name and define it to have the previously
1210 : : created enumeration type
1211 : : */
1212 : 0 : Sym = SymbolTable_MakeType (tokno, name);
1213 : 0 : SymbolTable_PutType (Sym, Type);
1214 : 0 : M2Quads_PushTFtok (Sym, name, tokno);
1215 : : }
1216 : 34138 : }
1217 : :
1218 : :
1219 : : /*
1220 : : BuildHiddenType - Builds a Hidden Type.
1221 : :
1222 : :
1223 : : Stack
1224 : :
1225 : : Entry Exit
1226 : :
1227 : : Ptr ->
1228 : : +------------+
1229 : : | Name | <- Ptr
1230 : : |------------| Empty
1231 : : */
1232 : :
1233 : 28771 : extern "C" void P1SymBuild_BuildHiddenType (void)
1234 : : {
1235 : 28771 : NameKey_Name name;
1236 : 28771 : unsigned int tokno;
1237 : :
1238 : 28771 : M2Quads_PopTtok (&name, &tokno);
1239 : : /* WriteKey(Name) ; WriteLn ; */
1240 : 28771 : M2Debug_Assert ((SymbolTable_MakeHiddenType (tokno, name)) != SymbolTable_NulSym);
1241 : 28771 : }
1242 : :
1243 : :
1244 : : /*
1245 : : StartBuildProcedure - Builds a Procedure.
1246 : :
1247 : : The Stack:
1248 : :
1249 : : Entry Exit
1250 : :
1251 : : Ptr -> <- Ptr
1252 : : +------------+ +------------+
1253 : : | Name | | ProcSym |
1254 : : |------------| |------------|
1255 : : | inlinetok | | |
1256 : : | or | | |
1257 : : | builtintok | | |
1258 : : | or name or | | Name |
1259 : : | NulTok | | |
1260 : : |------------| |------------|
1261 : : */
1262 : :
1263 : 5173064 : extern "C" void P1SymBuild_StartBuildProcedure (void)
1264 : : {
1265 : 5173064 : unsigned int tokno;
1266 : 5173064 : NameKey_Name builtin;
1267 : 5173064 : NameKey_Name name;
1268 : 5173064 : unsigned int ProcSym;
1269 : :
1270 : 5173064 : M2Quads_PopTtok (&name, &tokno);
1271 : 5173064 : M2Quads_PopT (&builtin); /* was this procedure defined as a builtin? */
1272 : 5173064 : M2Quads_PushTtok (name, tokno); /* Name saved for the EndBuildProcedure name check */
1273 : 5173064 : ProcSym = SymbolTable_RequestSym (tokno, name); /* Name saved for the EndBuildProcedure name check */
1274 : 5173064 : if (SymbolTable_IsUnknown (ProcSym))
1275 : : {
1276 : : /* A procedure may be created in a definition or implementation module, remember
1277 : : that an implementation module maybe compiled before the corresponding
1278 : : definition module.
1279 : :
1280 : : The procedure can also be created during a forward declaration.
1281 : : We record the forward declaration as the token of creation and adjust this
1282 : : later when we see the proper procedure declaration. Likwwise when the forward
1283 : : keyword is seen we assign the procedure forward token location. */
1284 : 3908415 : ProcSym = SymbolTable_MakeProcedure (tokno, name);
1285 : : }
1286 : 1264649 : else if (SymbolTable_IsProcedure (ProcSym))
1287 : : {
1288 : : /* avoid dangling else. */
1289 : : /* Declared in the other module or it could have been declared by a forward decl,
1290 : : we overwrite the declaration to tokno. The forward location is assigned in
1291 : : EndBuildForward. */
1292 : 1264649 : SymbolTable_PutDeclared (tokno, ProcSym);
1293 : : }
1294 : : else
1295 : : {
1296 : : /* avoid dangling else. */
1297 : 0 : M2MetaError_MetaError1 ((const char *) "expecting a procedure name and symbol {%1Ea} has been declared as a {%1dv}", 74, ProcSym);
1298 : 0 : M2Quads_PushT (ProcSym);
1299 : 0 : return;
1300 : : }
1301 : 5173064 : if (builtin != M2Reserved_NulTok)
1302 : : {
1303 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
1304 : 879692 : if (builtin == M2Reserved_BuiltinTok)
1305 : : {
1306 : 439620 : SymbolTable_PutProcedureBuiltin (ProcSym, name);
1307 : : }
1308 : 440072 : else if (builtin == M2Reserved_InlineTok)
1309 : : {
1310 : : /* avoid dangling else. */
1311 : 0 : SymbolTable_PutProcedureInline (ProcSym);
1312 : : }
1313 : : else
1314 : : {
1315 : : /* avoid dangling else. */
1316 : 440072 : SymbolTable_PutProcedureBuiltin (ProcSym, builtin);
1317 : : }
1318 : : }
1319 : 5173064 : M2Quads_PushTtok (ProcSym, tokno);
1320 : 5173064 : SymbolTable_StartScope (ProcSym);
1321 : 5173064 : if (M2Comp_CompilingDefinitionModule ())
1322 : : {
1323 : 3293050 : if (SymbolTable_GetProcedureDefined (ProcSym, SymbolTable_DefProcedure))
1324 : : {
1325 : 6 : M2MetaError_MetaErrorT1 (SymbolTable_GetProcedureDeclaredTok (ProcSym, SymbolTable_DefProcedure), (const char *) "first declaration of procedure {%1Ea} in the definition module", 62, ProcSym);
1326 : 6 : M2MetaError_MetaErrorT1 (tokno, (const char *) "duplicate declaration of procedure {%1Ea} in the definition module", 66, ProcSym);
1327 : : }
1328 : : else
1329 : : {
1330 : 3293044 : SymbolTable_PutProcedureDeclaredTok (ProcSym, SymbolTable_DefProcedure, tokno);
1331 : 3293044 : SymbolTable_PutProcedureDefined (ProcSym, SymbolTable_DefProcedure);
1332 : : }
1333 : : }
1334 : : else
1335 : : {
1336 : 1880014 : P0SymBuild_EnterBlock (name);
1337 : : }
1338 : : }
1339 : :
1340 : :
1341 : : /*
1342 : : EndBuildProcedure - Ends building a Procedure.
1343 : : It checks the start procedure name matches the end
1344 : : procedure name.
1345 : :
1346 : : The Stack:
1347 : :
1348 : : (Procedure Not Defined in definition module)
1349 : :
1350 : : Entry Exit
1351 : :
1352 : : Ptr ->
1353 : : +------------+
1354 : : | NameEnd |
1355 : : |------------|
1356 : : | ProcSym |
1357 : : |------------|
1358 : : | NameStart |
1359 : : |------------|
1360 : : Empty
1361 : : */
1362 : :
1363 : 1879954 : extern "C" void P1SymBuild_EndBuildProcedure (void)
1364 : : {
1365 : 1879954 : unsigned int tok;
1366 : 1879954 : unsigned int start;
1367 : 1879954 : unsigned int end;
1368 : 1879954 : unsigned int ProcSym;
1369 : 1879954 : NameKey_Name NameEnd;
1370 : 1879954 : NameKey_Name NameStart;
1371 : :
1372 : 1879954 : M2Quads_PopTtok (&NameEnd, &end);
1373 : 1879954 : M2Quads_PopTtok (&ProcSym, &tok);
1374 : 1879954 : M2Quads_PopTtok (&NameStart, &start);
1375 : 1879954 : if (NameEnd != NameStart)
1376 : : {
1377 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
1378 : 0 : if (end != M2LexBuf_UnknownTokenNo)
1379 : : {
1380 : 0 : M2MetaError_MetaErrorT1 (end, (const char *) "procedure name at end does not match name at beginning {%1EDa}", 62, ProcSym);
1381 : : }
1382 : 0 : else if (start != M2LexBuf_UnknownTokenNo)
1383 : : {
1384 : : /* avoid dangling else. */
1385 : 0 : M2MetaError_MetaErrorT2 (start, (const char *) "procedure name at end {%1EDa} does not match name at beginning {%2a}", 68, SymbolTable_MakeError (end, NameEnd), ProcSym);
1386 : : }
1387 : : else
1388 : : {
1389 : : /* avoid dangling else. */
1390 : 0 : M2MetaError_MetaError1 ((const char *) "procedure name at end does not match name at beginning {%1EDa}", 62, ProcSym);
1391 : : }
1392 : : }
1393 : 1879954 : SymbolTable_EndScope ();
1394 : 1879954 : if (SymbolTable_GetProcedureDefined (ProcSym, SymbolTable_ProperProcedure))
1395 : : {
1396 : 0 : M2MetaError_MetaErrorT1 (SymbolTable_GetProcedureDeclaredTok (ProcSym, SymbolTable_ProperProcedure), (const char *) "first proper declaration of procedure {%1Ea}", 44, ProcSym);
1397 : 0 : M2MetaError_MetaErrorT1 (tok, (const char *) "procedure {%1Ea} has already been declared", 42, ProcSym);
1398 : : }
1399 : : else
1400 : : {
1401 : 1879954 : SymbolTable_PutProcedureDeclaredTok (ProcSym, SymbolTable_ProperProcedure, tok);
1402 : 1879954 : SymbolTable_PutProcedureDefined (ProcSym, SymbolTable_ProperProcedure);
1403 : : }
1404 : 1879954 : M2Debug_Assert (! (M2Comp_CompilingDefinitionModule ()));
1405 : 1879954 : P0SymBuild_LeaveBlock ();
1406 : 1879954 : }
1407 : :
1408 : :
1409 : : /*
1410 : : BuildProcedureHeading - Builds a procedure heading for the definition
1411 : : module procedures.
1412 : :
1413 : : Operation only performed if compiling a
1414 : : definition module.
1415 : :
1416 : : The Stack:
1417 : :
1418 : : Entry Exit
1419 : :
1420 : : Ptr ->
1421 : : +------------+
1422 : : | ProcSym |
1423 : : |------------|
1424 : : | NameStart |
1425 : : |------------|
1426 : : Empty
1427 : :
1428 : : */
1429 : :
1430 : 5173064 : extern "C" void P1SymBuild_BuildProcedureHeading (void)
1431 : : {
1432 : 5173064 : unsigned int ProcSym;
1433 : 5173064 : NameKey_Name NameStart;
1434 : :
1435 : 5173064 : if (M2Comp_CompilingDefinitionModule ())
1436 : : {
1437 : 3293050 : M2Quads_PopT (&ProcSym);
1438 : 3293050 : M2Quads_PopT (&NameStart);
1439 : 3293050 : SymbolTable_EndScope ();
1440 : : }
1441 : 5173064 : }
1442 : :
1443 : :
1444 : : /*
1445 : : EndBuildForward - Ends building a forward procedure declaration.
1446 : :
1447 : : The Stack:
1448 : :
1449 : : (This procedure is not defined in definition module)
1450 : :
1451 : : Entry Exit
1452 : :
1453 : : Ptr ->
1454 : : +------------+
1455 : : | ProcSym |
1456 : : |------------|
1457 : : | NameStart |
1458 : : |------------|
1459 : : Empty
1460 : : */
1461 : :
1462 : 60 : extern "C" void P1SymBuild_EndBuildForward (unsigned int forwardPos)
1463 : : {
1464 : 60 : unsigned int ProcSym;
1465 : 60 : unsigned int tok;
1466 : :
1467 : 60 : ProcSym = static_cast<unsigned int> (M2Quads_OperandT (1));
1468 : 60 : tok = static_cast<unsigned int> (M2Quads_OperandTok (1));
1469 : 60 : if (! (M2Options_GetEnableForward ()))
1470 : : {
1471 : 0 : M2MetaError_MetaErrorT0 (forwardPos, (const char *) "forward declaration has not been enabled, use -fiso or -fenable-forward to enable forward procedure declarations", 112);
1472 : : }
1473 : 60 : if (SymbolTable_GetProcedureDefined (ProcSym, SymbolTable_ForwardProcedure))
1474 : : {
1475 : 6 : M2MetaError_MetaErrorT1 (SymbolTable_GetProcedureDeclaredTok (ProcSym, SymbolTable_ForwardProcedure), (const char *) "first forward declaration of {%1Ea}", 35, ProcSym);
1476 : 6 : M2MetaError_MetaErrorT1 (tok, (const char *) "forward declaration of procedure {%1Ea} has already occurred", 60, ProcSym);
1477 : : }
1478 : : else
1479 : : {
1480 : 54 : SymbolTable_PutProcedureDeclaredTok (ProcSym, SymbolTable_ForwardProcedure, tok);
1481 : 54 : SymbolTable_PutProcedureDefined (ProcSym, SymbolTable_ForwardProcedure);
1482 : : }
1483 : 60 : M2Quads_PopN (2);
1484 : 60 : SymbolTable_EndScope ();
1485 : 60 : M2Debug_Assert (! (M2Comp_CompilingDefinitionModule ()));
1486 : 60 : P0SymBuild_LeaveBlock ();
1487 : 60 : }
1488 : :
1489 : :
1490 : : /*
1491 : : BuildNulName - Pushes a NulName onto the top of the stack.
1492 : : The Stack:
1493 : :
1494 : :
1495 : : Entry Exit
1496 : :
1497 : : <- Ptr
1498 : : Empty +------------+
1499 : : | NulName |
1500 : : |------------|
1501 : : */
1502 : :
1503 : 1676970 : extern "C" void P1SymBuild_BuildNulName (void)
1504 : : {
1505 : 1676970 : M2Quads_PushT (static_cast<unsigned int> (NameKey_NulName));
1506 : 1676970 : }
1507 : :
1508 : :
1509 : : /*
1510 : : BuildTypeEnd - Pops the type Type and Name.
1511 : : The Stack:
1512 : :
1513 : :
1514 : : Entry Exit
1515 : :
1516 : :
1517 : : Ptr ->
1518 : : +-------------+
1519 : : | Type | Name | Empty
1520 : : |-------------|
1521 : : */
1522 : :
1523 : 0 : extern "C" void P1SymBuild_BuildTypeEnd (void)
1524 : : {
1525 : 0 : unsigned int Type;
1526 : 0 : NameKey_Name name;
1527 : :
1528 : 0 : M2Quads_PopTF (&Type, &name);
1529 : 0 : }
1530 : :
1531 : :
1532 : : /*
1533 : : BuildImportStatement - create a new import statement in the current module.
1534 : : It ignores local modules.
1535 : :
1536 : : The quadruple stack is not used.
1537 : : */
1538 : :
1539 : 401538 : extern "C" void P1SymBuild_BuildImportStatement (unsigned int tok)
1540 : : {
1541 : 401538 : unsigned int scope;
1542 : :
1543 : 401538 : scope = SymbolTable_GetCurrentScope ();
1544 : 401538 : if ((SymbolTable_IsDefImp (scope)) || ((SymbolTable_IsModule (scope)) && (! (SymbolTable_IsInnerModule (scope)))))
1545 : : {
1546 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
1547 : 401308 : if ((M2Comp_CompilingDefinitionModule ()) && (! (SymbolTable_IsDefImp (scope))))
1548 : : {
1549 : 0 : M2MetaError_MetaError1 ((const char *) "module scope should be a definition module rather than {%1EDa}", 62, scope);
1550 : : }
1551 : : else
1552 : : {
1553 : 401308 : importStatementCount += 1;
1554 : 401308 : SymbolTable_AppendModuleImportStatement (scope, SymbolTable_MakeImportStatement (tok, importStatementCount));
1555 : : }
1556 : : }
1557 : 401538 : }
1558 : :
1559 : :
1560 : : /*
1561 : : AddImportToImportStatement - the top of stack is expected to be a module name.
1562 : : This is looked up from the module universe and
1563 : : wrapped in an import symbol and placed into the
1564 : : current import statement.
1565 : :
1566 : : The quadruple stack is unchanged.
1567 : :
1568 : : Entry Exit
1569 : :
1570 : :
1571 : : Ptr -> <- Ptr
1572 : : +---------------------+ +---------------------+
1573 : : | ImportedModuleName | | ImportedModuleName |
1574 : : |---------------------| |---------------------|
1575 : : */
1576 : :
1577 : 416720 : extern "C" void P1SymBuild_AddImportToImportStatement (bool qualified)
1578 : : {
1579 : 416720 : unsigned int scope;
1580 : :
1581 : 416720 : scope = SymbolTable_GetCurrentScope ();
1582 : 416720 : if ((SymbolTable_IsDefImp (scope)) || ((SymbolTable_IsModule (scope)) && (! (SymbolTable_IsInnerModule (scope)))))
1583 : : {
1584 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
1585 : 416484 : if ((M2Comp_CompilingDefinitionModule ()) && (! (SymbolTable_IsDefImp (scope))))
1586 : : {
1587 : 0 : M2MetaError_MetaError1 ((const char *) "module scope should be a definition module rather than {%1EDa}", 62, scope);
1588 : : }
1589 : : else
1590 : : {
1591 : 416484 : SymbolTable_AppendModuleOnImportStatement (scope, SymbolTable_MakeImport (M2Quads_OperandTok (1), M2Batch_LookupModule (M2Quads_OperandTok (1), M2Quads_OperandT (1)), importStatementCount, qualified));
1592 : : }
1593 : : }
1594 : 416720 : }
1595 : :
1596 : 15229 : extern "C" void _M2_P1SymBuild_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
1597 : : {
1598 : 15229 : }
1599 : :
1600 : 0 : extern "C" void _M2_P1SymBuild_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
1601 : : {
1602 : 0 : }
|