Branch data Line data Source code
1 : : /* do not edit automatically generated by mc from P3SymBuild. */
2 : : /* P3SymBuild.mod pass 3 symbol creation.
3 : :
4 : : Copyright (C) 2001-2026 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 : : #define _P3SymBuild_C
35 : :
36 : : #include "GP3SymBuild.h"
37 : : # include "GNameKey.h"
38 : : # include "GStrIO.h"
39 : : # include "GNumberIO.h"
40 : : # include "GM2Debug.h"
41 : : # include "GM2Error.h"
42 : : # include "GM2LexBuf.h"
43 : : # include "GSymbolTable.h"
44 : : # include "GM2Batch.h"
45 : : # include "GM2Quads.h"
46 : : # include "GM2Comp.h"
47 : : # include "GFifoQueue.h"
48 : : # include "GM2Reserved.h"
49 : : # include "GM2MetaError.h"
50 : : # include "GM2StackSpell.h"
51 : :
52 : : extern "C" void P3SymBuild_P3StartBuildDefModule (void);
53 : : extern "C" void P3SymBuild_P3EndBuildDefModule (unsigned int tokno);
54 : : extern "C" void P3SymBuild_P3StartBuildImpModule (void);
55 : : extern "C" void P3SymBuild_P3EndBuildImpModule (unsigned int tokno);
56 : : extern "C" void P3SymBuild_P3StartBuildProgModule (void);
57 : : extern "C" void P3SymBuild_P3EndBuildProgModule (unsigned int tokno);
58 : :
59 : : /*
60 : : CheckCanBeImported - checks to see that it is legal to import Sym from ModSym.
61 : : */
62 : :
63 : : extern "C" void P3SymBuild_CheckCanBeImported (unsigned int ModSym, unsigned int Sym);
64 : :
65 : : /*
66 : : StartBuildInnerModule - Creates an Inner module and starts
67 : : a new scope.
68 : :
69 : : The Stack is expected:
70 : :
71 : : Entry Exit
72 : :
73 : : Ptr -> <- Ptr
74 : : +------------+ +-----------+
75 : : | NameStart | | NameStart |
76 : : |------------| |-----------|
77 : :
78 : : */
79 : :
80 : : extern "C" void P3SymBuild_StartBuildInnerModule (void);
81 : :
82 : : /*
83 : : EndBuildInnerModule - Destroys the Inner module scope and
84 : : checks for correct name.
85 : :
86 : : The Stack is expected:
87 : :
88 : : Entry Exit
89 : :
90 : : Ptr ->
91 : : +------------+ +-----------+
92 : : | NameEnd | | |
93 : : |------------| |-----------|
94 : : | NameStart | | | <- Ptr
95 : : |------------| |-----------|
96 : : */
97 : :
98 : : extern "C" void P3SymBuild_EndBuildInnerModule (unsigned int tokno);
99 : :
100 : : /*
101 : : CheckImportListOuterModule - checks to see that all identifiers are
102 : : exported from the definition module.
103 : :
104 : : The Stack is expected:
105 : :
106 : : Entry OR Entry
107 : :
108 : : Ptr -> Ptr ->
109 : : +------------+ +-----------+
110 : : | # | | # |
111 : : |------------| |-----------|
112 : : | Id1 | | Id1 |
113 : : |------------| |-----------|
114 : : . . . .
115 : : . . . .
116 : : . . . .
117 : : |------------| |-----------|
118 : : | Id# | | Id# |
119 : : |------------| |-----------|
120 : : | ImportTok | | Ident |
121 : : |------------| |-----------|
122 : :
123 : : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
124 : :
125 : :
126 : : Error Condition
127 : : Exit
128 : :
129 : : All above stack discarded
130 : : */
131 : :
132 : : extern "C" void P3SymBuild_CheckImportListOuterModule (void);
133 : :
134 : : /*
135 : : BuildProcedureHeading - Builds a procedure heading for the definition
136 : : module procedures.
137 : :
138 : : Operation only performed if compiling a
139 : : definition module.
140 : :
141 : : The Stack:
142 : :
143 : : Entry Exit
144 : :
145 : : Ptr ->
146 : : +------------+
147 : : | ProcSym |
148 : : |------------|
149 : : | NameStart |
150 : : |------------|
151 : : Empty
152 : :
153 : : */
154 : :
155 : : extern "C" void P3SymBuild_BuildProcedureHeading (void);
156 : :
157 : : /*
158 : : StartBuildProcedure - Builds a Procedure.
159 : :
160 : : The Stack:
161 : :
162 : : Entry Exit
163 : :
164 : : <- Ptr
165 : : +------------+
166 : : Ptr -> | ProcSym |
167 : : +------------+ |------------|
168 : : | Name | | Name |
169 : : |------------| |------------|
170 : : */
171 : :
172 : : extern "C" void P3SymBuild_StartBuildProcedure (void);
173 : :
174 : : /*
175 : : EndBuildProcedure - Ends building a Procedure.
176 : : It checks the start procedure name matches the end
177 : : procedure name.
178 : :
179 : : The Stack:
180 : :
181 : : (Procedure Not Defined in definition module)
182 : :
183 : : Entry Exit
184 : :
185 : : Ptr ->
186 : : +------------+
187 : : | NameEnd |
188 : : |------------|
189 : : | ProcSym |
190 : : |------------|
191 : : | NameStart |
192 : : |------------|
193 : : Empty
194 : : */
195 : :
196 : : extern "C" void P3SymBuild_EndBuildProcedure (void);
197 : :
198 : : /*
199 : : EndBuildForward -
200 : : */
201 : :
202 : : extern "C" void P3SymBuild_EndBuildForward (void);
203 : :
204 : : /*
205 : : BuildSubrange - Builds a Subrange type Symbol.
206 : :
207 : :
208 : : Stack
209 : :
210 : : Entry Exit
211 : :
212 : : Ptr ->
213 : : +------------+
214 : : | High |
215 : : |------------|
216 : : | Low | <- Ptr
217 : : |------------|
218 : : */
219 : :
220 : : extern "C" void P3SymBuild_BuildSubrange (void);
221 : :
222 : : /*
223 : : BuildNulName - Pushes a NulKey onto the top of the stack.
224 : : The Stack:
225 : :
226 : :
227 : : Entry Exit
228 : :
229 : : <- Ptr
230 : : Empty +------------+
231 : : | NulKey |
232 : : |------------|
233 : : */
234 : :
235 : : extern "C" void P3SymBuild_BuildNulName (void);
236 : :
237 : : /*
238 : : BuildConst - builds a constant.
239 : : Stack
240 : :
241 : : Entry Exit
242 : :
243 : : Ptr -> <- Ptr
244 : : +------------+ +------------+
245 : : | Name | | Sym |
246 : : |------------+ |------------|
247 : : */
248 : :
249 : : extern "C" void P3SymBuild_BuildConst (void);
250 : :
251 : : /*
252 : : BuildVarAtAddress - updates the symbol table entry of, variable sym, to be declared
253 : : at address, address.
254 : :
255 : : Stack
256 : :
257 : : Entry Exit
258 : :
259 : : Ptr ->
260 : : +--------------+
261 : : | Expr | EType | <- Ptr
262 : : |--------------+ +--------------+
263 : : | name | SType | | name | SType |
264 : : |--------------+ |--------------|
265 : : */
266 : :
267 : : extern "C" void P3SymBuild_BuildVarAtAddress (void);
268 : :
269 : : /*
270 : : BuildOptArgInitializer - assigns the constant value symbol, const, to be the
271 : : initial value of the optional parameter should it be
272 : : absent.
273 : :
274 : : Ptr ->
275 : : +------------+
276 : : | const |
277 : : |------------| <- Ptr
278 : : */
279 : :
280 : : extern "C" void P3SymBuild_BuildOptArgInitializer (void);
281 : :
282 : 175323 : extern "C" void P3SymBuild_P3StartBuildDefModule (void)
283 : : {
284 : 175323 : unsigned int tok;
285 : 175323 : NameKey_Name name;
286 : 175323 : unsigned int ModuleSym;
287 : :
288 : : /*
289 : : StartBuildDefinitionModule - Creates a definition module and starts
290 : : a new scope.
291 : :
292 : : The Stack is expected:
293 : :
294 : : Entry Exit
295 : :
296 : : Ptr -> <- Ptr
297 : : +------------+ +-----------+
298 : : | NameStart | | NameStart |
299 : : |------------| |-----------|
300 : :
301 : : */
302 : 175323 : M2Quads_PopTtok (&name, &tok);
303 : 175323 : ModuleSym = M2Batch_MakeDefinitionSource (tok, name);
304 : 175323 : SymbolTable_SetCurrentModule (ModuleSym);
305 : 175323 : SymbolTable_SetFileModule (ModuleSym);
306 : 175323 : SymbolTable_StartScope (ModuleSym);
307 : 175323 : M2Debug_Assert (SymbolTable_IsDefImp (ModuleSym));
308 : 175323 : M2Debug_Assert (M2Comp_CompilingDefinitionModule ());
309 : 175323 : M2StackSpell_Push (ModuleSym);
310 : 175323 : M2Quads_PushT (name);
311 : 175323 : M2Error_EnterDefinitionScope (name);
312 : 175323 : }
313 : :
314 : 175323 : extern "C" void P3SymBuild_P3EndBuildDefModule (unsigned int tokno)
315 : : {
316 : 175323 : unsigned int NameStart;
317 : 175323 : unsigned int NameEnd;
318 : :
319 : : /*
320 : : EndBuildDefinitionModule - Destroys the definition module scope and
321 : : checks for correct name.
322 : :
323 : : The Stack is expected:
324 : :
325 : : Entry Exit
326 : :
327 : : Ptr ->
328 : : +------------+ +-----------+
329 : : | NameEnd | | |
330 : : |------------| |-----------|
331 : : | NameStart | | | <- Ptr
332 : : |------------| |-----------|
333 : : */
334 : 175323 : M2Debug_Assert (M2Comp_CompilingDefinitionModule ());
335 : 175323 : SymbolTable_CheckForUnknownInModule (tokno);
336 : 175323 : SymbolTable_EndScope ();
337 : 175323 : M2StackSpell_Pop ();
338 : 175323 : M2Quads_PopT (&NameEnd);
339 : 175323 : M2Quads_PopT (&NameStart);
340 : 175323 : if (NameStart != NameEnd)
341 : : {
342 : 0 : M2Error_WriteFormat2 ((const char *) "inconsistent definition module was named (%a) and concluded as (%a)", 67, (const unsigned char *) &NameStart, (sizeof (NameStart)-1), (const unsigned char *) &NameEnd, (sizeof (NameEnd)-1));
343 : : }
344 : 175323 : M2Error_LeaveErrorScope ();
345 : 175323 : }
346 : :
347 : 73383 : extern "C" void P3SymBuild_P3StartBuildImpModule (void)
348 : : {
349 : 73383 : unsigned int tok;
350 : 73383 : NameKey_Name name;
351 : 73383 : unsigned int ModuleSym;
352 : :
353 : : /*
354 : : StartBuildImplementationModule - Creates an implementation module and starts
355 : : a new scope.
356 : :
357 : : The Stack is expected:
358 : :
359 : : Entry Exit
360 : :
361 : : Ptr -> <- Ptr
362 : : +------------+ +-----------+
363 : : | NameStart | | NameStart |
364 : : |------------| |-----------|
365 : :
366 : : */
367 : 73383 : M2Quads_PopTtok (&name, &tok);
368 : 73383 : ModuleSym = M2Batch_MakeImplementationSource (tok, name);
369 : 73383 : SymbolTable_SetCurrentModule (ModuleSym);
370 : 73383 : SymbolTable_SetFileModule (ModuleSym);
371 : 73383 : SymbolTable_StartScope (ModuleSym);
372 : 73383 : M2Debug_Assert (SymbolTable_IsDefImp (ModuleSym));
373 : 73383 : M2Debug_Assert (M2Comp_CompilingImplementationModule ());
374 : 73383 : M2Quads_PushT (name);
375 : 73383 : M2Error_EnterImplementationScope (name);
376 : 73383 : M2StackSpell_Push (ModuleSym);
377 : 73383 : }
378 : :
379 : 73383 : extern "C" void P3SymBuild_P3EndBuildImpModule (unsigned int tokno)
380 : : {
381 : 73383 : NameKey_Name NameStart;
382 : 73383 : NameKey_Name NameEnd;
383 : :
384 : : /*
385 : : EndBuildImplementationModule - Destroys the implementation module scope and
386 : : checks for correct name.
387 : :
388 : : The Stack is expected:
389 : :
390 : : Entry Exit
391 : :
392 : : Ptr ->
393 : : +------------+ +-----------+
394 : : | NameEnd | | |
395 : : |------------| |-----------|
396 : : | NameStart | | | <- Ptr
397 : : |------------| |-----------|
398 : : */
399 : 73383 : M2Debug_Assert (M2Comp_CompilingImplementationModule ());
400 : 73383 : SymbolTable_CheckForUnknownInModule (tokno);
401 : 73383 : SymbolTable_EndScope ();
402 : 73383 : M2StackSpell_Pop ();
403 : 73383 : M2Quads_PopT (&NameEnd);
404 : 73383 : M2Quads_PopT (&NameStart);
405 : 73383 : if (NameStart != NameEnd)
406 : : {
407 : : /* we dont issue an error based around incorrect module names as this is done in P1 and P2.
408 : : If we get here then something has gone wrong with our error recovery in P3, so we bail out.
409 : : */
410 : 0 : M2Error_WriteFormat0 ((const char *) "too many errors in pass 3", 25);
411 : 0 : M2Error_FlushErrors ();
412 : : }
413 : 73383 : M2Error_LeaveErrorScope ();
414 : 73383 : }
415 : :
416 : 11592 : extern "C" void P3SymBuild_P3StartBuildProgModule (void)
417 : : {
418 : 11592 : unsigned int tok;
419 : 11592 : NameKey_Name name;
420 : 11592 : unsigned int ModuleSym;
421 : :
422 : : /* WriteString('StartBuildProgramModule') ; WriteLn ; */
423 : 11592 : M2Quads_PopTtok (&name, &tok);
424 : 11592 : ModuleSym = M2Batch_MakeProgramSource (tok, name);
425 : 11592 : SymbolTable_SetCurrentModule (ModuleSym);
426 : 11592 : SymbolTable_SetFileModule (ModuleSym);
427 : : /* WriteString('MODULE - ') ; WriteKey(GetSymName(ModuleSym)) ; WriteLn ; */
428 : 11592 : SymbolTable_StartScope (ModuleSym);
429 : 11592 : M2Debug_Assert (M2Comp_CompilingProgramModule ());
430 : 11592 : M2Debug_Assert (! (SymbolTable_IsDefImp (ModuleSym)));
431 : 11592 : M2Quads_PushT (name);
432 : 11592 : M2Error_EnterProgramScope (name);
433 : 11592 : M2StackSpell_Push (ModuleSym);
434 : 11592 : }
435 : :
436 : 11378 : extern "C" void P3SymBuild_P3EndBuildProgModule (unsigned int tokno)
437 : : {
438 : 11378 : NameKey_Name NameStart;
439 : 11378 : NameKey_Name NameEnd;
440 : :
441 : : /*
442 : : EndBuildProgramModule - Destroys the program module scope and
443 : : checks for correct name.
444 : :
445 : : The Stack is expected:
446 : :
447 : : Entry Exit
448 : :
449 : : Ptr ->
450 : : +------------+ +-----------+
451 : : | NameEnd | | |
452 : : |------------| |-----------|
453 : : | NameStart | | | <- Ptr
454 : : |------------| |-----------|
455 : : */
456 : 11378 : M2Debug_Assert (M2Comp_CompilingProgramModule ());
457 : 11378 : SymbolTable_CheckForUnknownInModule (tokno);
458 : 11378 : SymbolTable_EndScope ();
459 : 11378 : M2Quads_PopT (&NameEnd);
460 : 11378 : M2Quads_PopT (&NameStart);
461 : 11378 : if (NameStart != NameEnd)
462 : : {
463 : : /* we dont issue an error based around incorrect module names this would be done in P1 and P2.
464 : : If we get here then something has gone wrong with our error recovery in P3, so we bail out.
465 : : */
466 : 0 : M2Error_WriteFormat0 ((const char *) "too many errors in pass 3", 25);
467 : 0 : M2Error_FlushErrors ();
468 : : }
469 : 11378 : M2Error_LeaveErrorScope ();
470 : 11378 : M2StackSpell_Pop ();
471 : 11378 : }
472 : :
473 : :
474 : : /*
475 : : CheckCanBeImported - checks to see that it is legal to import Sym from ModSym.
476 : : */
477 : :
478 : 689528 : extern "C" void P3SymBuild_CheckCanBeImported (unsigned int ModSym, unsigned int Sym)
479 : : {
480 : 689528 : if (SymbolTable_IsDefImp (ModSym))
481 : : {
482 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
483 : 689462 : if (SymbolTable_IsExported (ModSym, Sym))
484 : : {
485 : : /* All done. */
486 : : return;
487 : : }
488 : : else
489 : : {
490 : 84 : if (SymbolTable_IsImplicityExported (ModSym, Sym))
491 : : {
492 : : /* This is also legal. */
493 : : return;
494 : : }
495 : 24 : else if ((SymbolTable_IsDefImp (Sym)) && (SymbolTable_IsIncludedByDefinition (ModSym, Sym)))
496 : : {
497 : : /* avoid dangling else. */
498 : : /* This is also legal (for a definition module). */
499 : : return;
500 : : }
501 : : /* Use spell checker for Unknown symbols. */
502 : 12 : if (SymbolTable_IsUnknown (Sym))
503 : : {
504 : : /* Spellcheck. */
505 : 12 : M2MetaError_MetaError2 ((const char *) "{%1Ua} is not exported from definition module {%2a} {%1&s}", 58, Sym, ModSym);
506 : : }
507 : : else
508 : : {
509 : 0 : M2MetaError_MetaError2 ((const char *) "{%1Ua} is not exported from definition module {%2a}", 51, Sym, ModSym);
510 : : }
511 : : }
512 : : }
513 : : }
514 : :
515 : :
516 : : /*
517 : : StartBuildInnerModule - Creates an Inner module and starts
518 : : a new scope.
519 : :
520 : : The Stack is expected:
521 : :
522 : : Entry Exit
523 : :
524 : : Ptr -> <- Ptr
525 : : +------------+ +-----------+
526 : : | NameStart | | NameStart |
527 : : |------------| |-----------|
528 : :
529 : : */
530 : :
531 : 420 : extern "C" void P3SymBuild_StartBuildInnerModule (void)
532 : : {
533 : 420 : NameKey_Name name;
534 : 420 : unsigned int tok;
535 : 420 : unsigned int ModuleSym;
536 : :
537 : 420 : M2Quads_PopTtok (&name, &tok);
538 : 420 : ModuleSym = SymbolTable_RequestSym (tok, name);
539 : 420 : M2Debug_Assert (SymbolTable_IsModule (ModuleSym));
540 : 420 : SymbolTable_StartScope (ModuleSym);
541 : 420 : M2Debug_Assert (! (SymbolTable_IsDefImp (ModuleSym)));
542 : 420 : SymbolTable_SetCurrentModule (ModuleSym);
543 : 420 : M2Quads_PushT (name);
544 : 420 : M2Error_EnterModuleScope (name);
545 : 420 : M2StackSpell_Push (ModuleSym);
546 : 420 : }
547 : :
548 : :
549 : : /*
550 : : EndBuildInnerModule - Destroys the Inner module scope and
551 : : checks for correct name.
552 : :
553 : : The Stack is expected:
554 : :
555 : : Entry Exit
556 : :
557 : : Ptr ->
558 : : +------------+ +-----------+
559 : : | NameEnd | | |
560 : : |------------| |-----------|
561 : : | NameStart | | | <- Ptr
562 : : |------------| |-----------|
563 : : */
564 : :
565 : 420 : extern "C" void P3SymBuild_EndBuildInnerModule (unsigned int tokno)
566 : : {
567 : 420 : NameKey_Name NameStart;
568 : 420 : NameKey_Name NameEnd;
569 : :
570 : 420 : SymbolTable_CheckForUnknownInModule (tokno);
571 : 420 : SymbolTable_EndScope ();
572 : 420 : M2Quads_PopT (&NameEnd);
573 : 420 : M2Quads_PopT (&NameStart);
574 : 420 : if (NameStart != NameEnd)
575 : : {
576 : : /* we dont issue an error based around incorrect module names this would be done in P1 and P2.
577 : : If we get here then something has gone wrong with our error recovery in P3, so we bail out.
578 : : */
579 : 0 : M2Error_WriteFormat0 ((const char *) "too many errors in pass 3", 25);
580 : 0 : M2Error_FlushErrors ();
581 : : }
582 : 420 : SymbolTable_SetCurrentModule (SymbolTable_GetModuleScope (SymbolTable_GetCurrentModule ()));
583 : 420 : M2Error_LeaveErrorScope ();
584 : 420 : M2StackSpell_Pop ();
585 : 420 : }
586 : :
587 : :
588 : : /*
589 : : CheckImportListOuterModule - checks to see that all identifiers are
590 : : exported from the definition module.
591 : :
592 : : The Stack is expected:
593 : :
594 : : Entry OR Entry
595 : :
596 : : Ptr -> Ptr ->
597 : : +------------+ +-----------+
598 : : | # | | # |
599 : : |------------| |-----------|
600 : : | Id1 | | Id1 |
601 : : |------------| |-----------|
602 : : . . . .
603 : : . . . .
604 : : . . . .
605 : : |------------| |-----------|
606 : : | Id# | | Id# |
607 : : |------------| |-----------|
608 : : | ImportTok | | Ident |
609 : : |------------| |-----------|
610 : :
611 : : IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ;
612 : :
613 : :
614 : : Error Condition
615 : : Exit
616 : :
617 : : All above stack discarded
618 : : */
619 : :
620 : 131467 : extern "C" void P3SymBuild_CheckImportListOuterModule (void)
621 : : {
622 : 131467 : NameKey_Name n1;
623 : 131467 : NameKey_Name n2;
624 : 131467 : unsigned int tok;
625 : 131467 : unsigned int ModSym;
626 : 131467 : unsigned int i;
627 : 131467 : unsigned int n;
628 : :
629 : 131467 : M2Quads_PopT (&n); /* n = # of the Ident List */
630 : 131467 : if ((M2Quads_OperandT (n+1)) != M2Reserved_ImportTok)
631 : : {
632 : : /* Ident List contains list of objects */
633 : 131467 : ModSym = M2Batch_LookupOuterModule (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
634 : 131467 : i = 1;
635 : 442115 : while (i <= n)
636 : : {
637 : 179181 : tok = static_cast<unsigned int> (M2Quads_OperandTok (i));
638 : 179181 : if ((! (SymbolTable_IsExported (ModSym, SymbolTable_RequestSym (tok, M2Quads_OperandT (i))))) && (! (SymbolTable_IsImplicityExported (ModSym, SymbolTable_RequestSym (tok, M2Quads_OperandT (i))))))
639 : : {
640 : 0 : n1 = static_cast<NameKey_Name> (M2Quads_OperandT (n+1));
641 : 0 : n2 = static_cast<NameKey_Name> (M2Quads_OperandT (i));
642 : 0 : M2Error_WriteFormat2 ((const char *) "symbol %a is not exported from definition or inner module %a", 60, (const unsigned char *) &n2, (sizeof (n2)-1), (const unsigned char *) &n1, (sizeof (n1)-1));
643 : : }
644 : 179181 : i += 1;
645 : : }
646 : : }
647 : 131467 : M2Quads_PopN (n+1); /* clear stack */
648 : 131467 : }
649 : :
650 : :
651 : : /*
652 : : BuildProcedureHeading - Builds a procedure heading for the definition
653 : : module procedures.
654 : :
655 : : Operation only performed if compiling a
656 : : definition module.
657 : :
658 : : The Stack:
659 : :
660 : : Entry Exit
661 : :
662 : : Ptr ->
663 : : +------------+
664 : : | ProcSym |
665 : : |------------|
666 : : | NameStart |
667 : : |------------|
668 : : Empty
669 : :
670 : : */
671 : :
672 : 3522686 : extern "C" void P3SymBuild_BuildProcedureHeading (void)
673 : : {
674 : 3522686 : unsigned int ProcSym;
675 : 3522686 : NameKey_Name NameStart;
676 : :
677 : 3522686 : if (M2Comp_CompilingDefinitionModule ())
678 : : {
679 : 3479761 : M2Quads_PopT (&ProcSym);
680 : 3479761 : M2Quads_PopT (&NameStart);
681 : 3479761 : SymbolTable_EndScope ();
682 : 3479761 : M2StackSpell_Pop ();
683 : : }
684 : 3522686 : }
685 : :
686 : :
687 : : /*
688 : : StartBuildProcedure - Builds a Procedure.
689 : :
690 : : The Stack:
691 : :
692 : : Entry Exit
693 : :
694 : : <- Ptr
695 : : +------------+
696 : : Ptr -> | ProcSym |
697 : : +------------+ |------------|
698 : : | Name | | Name |
699 : : |------------| |------------|
700 : : */
701 : :
702 : 5368274 : extern "C" void P3SymBuild_StartBuildProcedure (void)
703 : : {
704 : 5368274 : unsigned int tok;
705 : 5368274 : NameKey_Name name;
706 : 5368274 : unsigned int ProcSym;
707 : :
708 : 5368274 : M2Quads_PopTtok (&name, &tok);
709 : 5368274 : M2Quads_PushTtok (name, tok); /* Name saved for the EndBuildProcedure name check */
710 : 5368274 : ProcSym = SymbolTable_RequestSym (tok, name); /* Name saved for the EndBuildProcedure name check */
711 : 5368274 : M2Debug_Assert (SymbolTable_IsProcedure (ProcSym));
712 : 5368274 : M2Quads_PushTtok (ProcSym, tok);
713 : 5368274 : SymbolTable_StartScope (ProcSym);
714 : 5368274 : M2Error_EnterProcedureScope (name);
715 : 5368274 : M2StackSpell_Push (ProcSym);
716 : 5368274 : }
717 : :
718 : :
719 : : /*
720 : : EndBuildProcedure - Ends building a Procedure.
721 : : It checks the start procedure name matches the end
722 : : procedure name.
723 : :
724 : : The Stack:
725 : :
726 : : (Procedure Not Defined in definition module)
727 : :
728 : : Entry Exit
729 : :
730 : : Ptr ->
731 : : +------------+
732 : : | NameEnd |
733 : : |------------|
734 : : | ProcSym |
735 : : |------------|
736 : : | NameStart |
737 : : |------------|
738 : : Empty
739 : : */
740 : :
741 : 1888447 : extern "C" void P3SymBuild_EndBuildProcedure (void)
742 : : {
743 : 1888447 : unsigned int ProcSym;
744 : 1888447 : NameKey_Name NameEnd;
745 : 1888447 : NameKey_Name NameStart;
746 : :
747 : 1888447 : M2Quads_PopT (&NameEnd);
748 : 1888447 : M2Quads_PopT (&ProcSym);
749 : 1888447 : M2Quads_PopT (&NameStart);
750 : 1888447 : if (NameEnd != NameStart)
751 : : {
752 : : /* we dont issue an error based around incorrect module names this would be done in P1 and P2.
753 : : If we get here then something has gone wrong with our error recovery in P3, so we bail out.
754 : : */
755 : 0 : M2Error_WriteFormat0 ((const char *) "too many errors in pass 3", 25);
756 : 0 : M2Error_FlushErrors ();
757 : : }
758 : 1888447 : SymbolTable_EndScope ();
759 : 1888447 : M2Error_LeaveErrorScope ();
760 : 1888447 : M2StackSpell_Pop ();
761 : 1888447 : }
762 : :
763 : :
764 : : /*
765 : : EndBuildForward -
766 : : */
767 : :
768 : 24 : extern "C" void P3SymBuild_EndBuildForward (void)
769 : : {
770 : 24 : M2Quads_PopN (2);
771 : 24 : SymbolTable_EndScope ();
772 : 24 : M2Error_LeaveErrorScope ();
773 : 24 : M2StackSpell_Pop ();
774 : 24 : }
775 : :
776 : :
777 : : /*
778 : : BuildSubrange - Builds a Subrange type Symbol.
779 : :
780 : :
781 : : Stack
782 : :
783 : : Entry Exit
784 : :
785 : : Ptr ->
786 : : +------------+
787 : : | High |
788 : : |------------|
789 : : | Low | <- Ptr
790 : : |------------|
791 : : */
792 : :
793 : 103341 : extern "C" void P3SymBuild_BuildSubrange (void)
794 : : {
795 : 103341 : unsigned int Base;
796 : 103341 : unsigned int Type;
797 : 103341 : unsigned int Low;
798 : 103341 : unsigned int High;
799 : :
800 : 103341 : M2Quads_PopT (&High);
801 : 103341 : M2Quads_PopT (&Low);
802 : 103341 : FifoQueue_GetSubrangeFromFifoQueue (&Type); /* Collect subrange type from pass 2 and fill in */
803 : : /* bounds. */
804 : 103341 : FifoQueue_GetSubrangeFromFifoQueue (&Base); /* Get base of subrange (maybe NulSym) */
805 : : /* worked out later in M2GCCDeclare */
806 : 103341 : SymbolTable_PutSubrange (Type, Low, High, Base);
807 : 103341 : }
808 : :
809 : :
810 : : /*
811 : : BuildNulName - Pushes a NulKey onto the top of the stack.
812 : : The Stack:
813 : :
814 : :
815 : : Entry Exit
816 : :
817 : : <- Ptr
818 : : Empty +------------+
819 : : | NulKey |
820 : : |------------|
821 : : */
822 : :
823 : 0 : extern "C" void P3SymBuild_BuildNulName (void)
824 : : {
825 : 0 : M2Quads_PushT (static_cast<unsigned int> (NameKey_NulName));
826 : 0 : }
827 : :
828 : :
829 : : /*
830 : : BuildConst - builds a constant.
831 : : Stack
832 : :
833 : : Entry Exit
834 : :
835 : : Ptr -> <- Ptr
836 : : +------------+ +------------+
837 : : | Name | | Sym |
838 : : |------------+ |------------|
839 : : */
840 : :
841 : 307633 : extern "C" void P3SymBuild_BuildConst (void)
842 : : {
843 : 307633 : NameKey_Name name;
844 : 307633 : unsigned int tok;
845 : 307633 : unsigned int Sym;
846 : :
847 : 307633 : M2Quads_PopTtok (&name, &tok);
848 : 307633 : Sym = SymbolTable_RequestSym (tok, name);
849 : 307633 : M2Quads_PushTtok (Sym, tok);
850 : 307633 : }
851 : :
852 : :
853 : : /*
854 : : BuildVarAtAddress - updates the symbol table entry of, variable sym, to be declared
855 : : at address, address.
856 : :
857 : : Stack
858 : :
859 : : Entry Exit
860 : :
861 : : Ptr ->
862 : : +--------------+
863 : : | Expr | EType | <- Ptr
864 : : |--------------+ +--------------+
865 : : | name | SType | | name | SType |
866 : : |--------------+ |--------------|
867 : : */
868 : :
869 : 54 : extern "C" void P3SymBuild_BuildVarAtAddress (void)
870 : : {
871 : 54 : unsigned int nametok;
872 : 54 : NameKey_Name name;
873 : 54 : unsigned int Sym;
874 : 54 : unsigned int SType;
875 : 54 : unsigned int Exp;
876 : 54 : unsigned int EType;
877 : :
878 : 54 : M2Quads_PopTF (&Exp, &EType);
879 : 54 : M2Quads_PopTFtok (&name, &SType, &nametok);
880 : 54 : M2Quads_PushTF (name, SType);
881 : 54 : Sym = SymbolTable_RequestSym (nametok, name);
882 : 54 : if ((SymbolTable_GetMode (Sym)) == SymbolTable_LeftValue)
883 : : {
884 : 54 : SymbolTable_PutVariableAtAddress (Sym, Exp);
885 : : }
886 : : else
887 : : {
888 : 0 : M2Error_InternalError ((const char *) "expecting lvalue for this variable which is declared at an explicit address", 75);
889 : : }
890 : 54 : }
891 : :
892 : :
893 : : /*
894 : : BuildOptArgInitializer - assigns the constant value symbol, const, to be the
895 : : initial value of the optional parameter should it be
896 : : absent.
897 : :
898 : : Ptr ->
899 : : +------------+
900 : : | const |
901 : : |------------| <- Ptr
902 : : */
903 : :
904 : 17339 : extern "C" void P3SymBuild_BuildOptArgInitializer (void)
905 : : {
906 : 17339 : unsigned int tok;
907 : 17339 : unsigned int const_;
908 : 17339 : unsigned int ProcSym;
909 : :
910 : 17339 : M2Quads_PopT (&const_);
911 : 17339 : M2Quads_PopTtok (&ProcSym, &tok);
912 : 17339 : M2Debug_Assert (SymbolTable_IsProcedure (ProcSym));
913 : 17339 : M2Quads_PushTtok (ProcSym, tok);
914 : 17339 : SymbolTable_PutOptArgInit (SymbolTable_GetCurrentScope (), const_);
915 : 17339 : }
916 : :
917 : 17616 : extern "C" void _M2_P3SymBuild_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
918 : : {
919 : 17616 : }
920 : :
921 : 0 : extern "C" void _M2_P3SymBuild_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
922 : : {
923 : 0 : }
|