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