LCOV - code coverage report
Current view: top level - /mnt/build/buildbot/bld/build-lcov/gcc/m2/gm2-compiler-boot - P3SymBuild.c (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.2 % 243 224
Test Date: 2026-10-17 16:30:31 Functions: 90.5 % 21 19
Legend: Lines:     hit not hit

            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       164816 : extern "C" void P3SymBuild_P3StartBuildDefModule (void)
     283              : {
     284       164816 :   unsigned int tok;
     285       164816 :   NameKey_Name name;
     286       164816 :   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       164816 :   M2Quads_PopTtok (&name, &tok);
     303       164816 :   ModuleSym = M2Batch_MakeDefinitionSource (tok, name);
     304       164816 :   SymbolTable_SetCurrentModule (ModuleSym);
     305       164816 :   SymbolTable_SetFileModule (ModuleSym);
     306       164816 :   SymbolTable_StartScope (ModuleSym);
     307       164816 :   M2Debug_Assert (SymbolTable_IsDefImp (ModuleSym));
     308       164816 :   M2Debug_Assert (M2Comp_CompilingDefinitionModule ());
     309       164816 :   M2StackSpell_Push (SymbolTable_GetBaseModule ());
     310       164816 :   M2StackSpell_Push (ModuleSym);
     311       164816 :   M2Quads_PushT (name);
     312       164816 :   M2Error_EnterDefinitionScope (name);
     313       164816 : }
     314              : 
     315       164816 : extern "C" void P3SymBuild_P3EndBuildDefModule (unsigned int tokno)
     316              : {
     317       164816 :   unsigned int NameStart;
     318       164816 :   unsigned int NameEnd;
     319              : 
     320              :   /* 
     321              :    EndBuildDefinitionModule - Destroys the definition module scope and
     322              :                               checks for correct name.
     323              : 
     324              :                               The Stack is expected:
     325              : 
     326              :                               Entry                 Exit
     327              : 
     328              :                        Ptr ->
     329              :                               +------------+        +-----------+
     330              :                               | NameEnd    |        |           |
     331              :                               |------------|        |-----------|
     332              :                               | NameStart  |        |           | <- Ptr
     333              :                               |------------|        |-----------|
     334              :   */
     335       164816 :   M2Debug_Assert (M2Comp_CompilingDefinitionModule ());
     336       164816 :   SymbolTable_CheckForUnknownInModule (tokno);
     337       164816 :   SymbolTable_EndScope ();
     338       164816 :   M2StackSpell_Pop ();
     339       164816 :   M2StackSpell_Pop ();
     340       164816 :   M2Quads_PopT (&NameEnd);
     341       164816 :   M2Quads_PopT (&NameStart);
     342       164816 :   if (NameStart != NameEnd)
     343              :     {
     344            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));
     345              :     }
     346       164816 :   M2Error_LeaveErrorScope ();
     347       164816 : }
     348              : 
     349        72644 : extern "C" void P3SymBuild_P3StartBuildImpModule (void)
     350              : {
     351        72644 :   unsigned int tok;
     352        72644 :   NameKey_Name name;
     353        72644 :   unsigned int ModuleSym;
     354              : 
     355              :   /* 
     356              :    StartBuildImplementationModule - Creates an implementation module and starts
     357              :                                     a new scope.
     358              : 
     359              :                                     The Stack is expected:
     360              : 
     361              :                                     Entry                 Exit
     362              : 
     363              :                              Ptr ->                                     <- Ptr
     364              :                                     +------------+        +-----------+
     365              :                                     | NameStart  |        | NameStart |
     366              :                                     |------------|        |-----------|
     367              : 
     368              :   */
     369        72644 :   M2Quads_PopTtok (&name, &tok);
     370        72644 :   ModuleSym = M2Batch_MakeImplementationSource (tok, name);
     371        72644 :   SymbolTable_SetCurrentModule (ModuleSym);
     372        72644 :   SymbolTable_SetFileModule (ModuleSym);
     373        72644 :   SymbolTable_StartScope (ModuleSym);
     374        72644 :   M2Debug_Assert (SymbolTable_IsDefImp (ModuleSym));
     375        72644 :   M2Debug_Assert (M2Comp_CompilingImplementationModule ());
     376        72644 :   M2Quads_PushT (name);
     377        72644 :   M2Error_EnterImplementationScope (name);
     378        72644 :   M2StackSpell_Push (SymbolTable_GetBaseModule ());
     379        72644 :   M2StackSpell_Push (ModuleSym);
     380        72644 : }
     381              : 
     382        72644 : extern "C" void P3SymBuild_P3EndBuildImpModule (unsigned int tokno)
     383              : {
     384        72644 :   NameKey_Name NameStart;
     385        72644 :   NameKey_Name NameEnd;
     386              : 
     387              :   /* 
     388              :    EndBuildImplementationModule - Destroys the implementation module scope and
     389              :                                   checks for correct name.
     390              : 
     391              :                                   The Stack is expected:
     392              : 
     393              :                                   Entry                 Exit
     394              : 
     395              :                            Ptr ->
     396              :                                   +------------+        +-----------+
     397              :                                   | NameEnd    |        |           |
     398              :                                   |------------|        |-----------|
     399              :                                   | NameStart  |        |           | <- Ptr
     400              :                                   |------------|        |-----------|
     401              :   */
     402        72644 :   M2Debug_Assert (M2Comp_CompilingImplementationModule ());
     403        72644 :   SymbolTable_CheckForUnknownInModule (tokno);
     404        72644 :   SymbolTable_EndScope ();
     405        72644 :   M2StackSpell_Pop ();
     406        72644 :   M2StackSpell_Pop ();
     407        72644 :   M2Quads_PopT (&NameEnd);
     408        72644 :   M2Quads_PopT (&NameStart);
     409        72644 :   if (NameStart != NameEnd)
     410              :     {
     411              :       /* we dont issue an error based around incorrect module names as this is done in P1 and P2.
     412              :          If we get here then something has gone wrong with our error recovery in P3, so we bail out.
     413              :   */
     414            0 :       M2Error_WriteFormat0 ((const char *) "too many errors in pass 3", 25);
     415            0 :       M2Error_FlushErrors ();
     416              :     }
     417        72644 :   M2Error_LeaveErrorScope ();
     418        72644 : }
     419              : 
     420        11729 : extern "C" void P3SymBuild_P3StartBuildProgModule (void)
     421              : {
     422        11729 :   unsigned int tok;
     423        11729 :   NameKey_Name name;
     424        11729 :   unsigned int ModuleSym;
     425              : 
     426              :   /* WriteString('StartBuildProgramModule') ; WriteLn ;  */
     427        11729 :   M2Quads_PopTtok (&name, &tok);
     428        11729 :   ModuleSym = M2Batch_MakeProgramSource (tok, name);
     429        11729 :   SymbolTable_SetCurrentModule (ModuleSym);
     430        11729 :   SymbolTable_SetFileModule (ModuleSym);
     431              :   /* WriteString('MODULE - ') ; WriteKey(GetSymName(ModuleSym)) ; WriteLn ;  */
     432        11729 :   SymbolTable_StartScope (ModuleSym);
     433        11729 :   M2Debug_Assert (M2Comp_CompilingProgramModule ());
     434        11729 :   M2Debug_Assert (! (SymbolTable_IsDefImp (ModuleSym)));
     435        11729 :   M2Quads_PushT (name);
     436        11729 :   M2Error_EnterProgramScope (name);
     437        11729 :   M2StackSpell_Push (SymbolTable_GetBaseModule ());
     438        11729 :   M2StackSpell_Push (ModuleSym);
     439        11729 : }
     440              : 
     441        11510 : extern "C" void P3SymBuild_P3EndBuildProgModule (unsigned int tokno)
     442              : {
     443        11510 :   NameKey_Name NameStart;
     444        11510 :   NameKey_Name NameEnd;
     445              : 
     446              :   /* 
     447              :    EndBuildProgramModule - Destroys the program module scope and
     448              :                            checks for correct name.
     449              : 
     450              :                            The Stack is expected:
     451              : 
     452              :                            Entry                 Exit
     453              : 
     454              :                     Ptr ->
     455              :                            +------------+        +-----------+
     456              :                            | NameEnd    |        |           |
     457              :                            |------------|        |-----------|
     458              :                            | NameStart  |        |           | <- Ptr
     459              :                            |------------|        |-----------|
     460              :   */
     461        11510 :   M2Debug_Assert (M2Comp_CompilingProgramModule ());
     462        11510 :   SymbolTable_CheckForUnknownInModule (tokno);
     463        11510 :   SymbolTable_EndScope ();
     464        11510 :   M2Quads_PopT (&NameEnd);
     465        11510 :   M2Quads_PopT (&NameStart);
     466        11510 :   if (NameStart != NameEnd)
     467              :     {
     468              :       /* we dont issue an error based around incorrect module names this would be done in P1 and P2.
     469              :          If we get here then something has gone wrong with our error recovery in P3, so we bail out.
     470              :   */
     471            0 :       M2Error_WriteFormat0 ((const char *) "too many errors in pass 3", 25);
     472            0 :       M2Error_FlushErrors ();
     473              :     }
     474        11510 :   M2Error_LeaveErrorScope ();
     475        11510 :   M2StackSpell_Pop ();
     476        11510 :   M2StackSpell_Pop ();
     477        11510 : }
     478              : 
     479              : 
     480              : /*
     481              :    CheckCanBeImported - checks to see that it is legal to import Sym from ModSym.
     482              : */
     483              : 
     484       705684 : extern "C" void P3SymBuild_CheckCanBeImported (unsigned int ModSym, unsigned int Sym)
     485              : {
     486       705684 :   if (SymbolTable_IsDefImp (ModSym))
     487              :     {
     488              :       /* avoid gcc warning by using compound statement even if not strictly necessary.  */
     489       705618 :       if (SymbolTable_IsExported (ModSym, Sym))
     490              :         {
     491              :           /* All done.  */
     492              :           return;
     493              :         }
     494              :       else
     495              :         {
     496           84 :           if (SymbolTable_IsImplicityExported (ModSym, Sym))
     497              :             {
     498              :               /* This is also legal.  */
     499              :               return;
     500              :             }
     501           24 :           else if ((SymbolTable_IsDefImp (Sym)) && (SymbolTable_IsIncludedByDefinition (ModSym, Sym)))
     502              :             {
     503              :               /* avoid dangling else.  */
     504              :               /* This is also legal (for a definition module).  */
     505              :               return;
     506              :             }
     507              :           /* Use spell checker for Unknown symbols.  */
     508           12 :           if (SymbolTable_IsUnknown (Sym))
     509              :             {
     510              :               /* Spellcheck.  */
     511           12 :               M2MetaError_MetaError2 ((const char *) "{%1Ua} is not exported from definition module {%2a} {%1&s}", 58, Sym, ModSym);
     512              :             }
     513              :           else
     514              :             {
     515            0 :               M2MetaError_MetaError2 ((const char *) "{%1Ua} is not exported from definition module {%2a}", 51, Sym, ModSym);
     516              :             }
     517              :         }
     518              :     }
     519              : }
     520              : 
     521              : 
     522              : /*
     523              :    StartBuildInnerModule - Creates an Inner module and starts
     524              :                            a new scope.
     525              : 
     526              :                            The Stack is expected:
     527              : 
     528              :                            Entry                 Exit
     529              : 
     530              :                     Ptr ->                                     <- Ptr
     531              :                            +------------+        +-----------+
     532              :                            | NameStart  |        | NameStart |
     533              :                            |------------|        |-----------|
     534              : 
     535              : */
     536              : 
     537          432 : extern "C" void P3SymBuild_StartBuildInnerModule (void)
     538              : {
     539          432 :   NameKey_Name name;
     540          432 :   unsigned int tok;
     541          432 :   unsigned int ModuleSym;
     542              : 
     543          432 :   M2Quads_PopTtok (&name, &tok);
     544          432 :   ModuleSym = SymbolTable_RequestSym (tok, name);
     545          432 :   M2Debug_Assert (SymbolTable_IsModule (ModuleSym));
     546          432 :   SymbolTable_StartScope (ModuleSym);
     547          432 :   M2Debug_Assert (! (SymbolTable_IsDefImp (ModuleSym)));
     548          432 :   SymbolTable_SetCurrentModule (ModuleSym);
     549          432 :   M2Quads_PushT (name);
     550          432 :   M2Error_EnterModuleScope (name);
     551          432 :   M2StackSpell_Push (SymbolTable_GetBaseModule ());
     552          432 :   M2StackSpell_Push (ModuleSym);
     553          432 : }
     554              : 
     555              : 
     556              : /*
     557              :    EndBuildInnerModule - Destroys the Inner module scope and
     558              :                          checks for correct name.
     559              : 
     560              :                          The Stack is expected:
     561              : 
     562              :                          Entry                 Exit
     563              : 
     564              :                   Ptr ->
     565              :                          +------------+        +-----------+
     566              :                          | NameEnd    |        |           |
     567              :                          |------------|        |-----------|
     568              :                          | NameStart  |        |           | <- Ptr
     569              :                          |------------|        |-----------|
     570              : */
     571              : 
     572          432 : extern "C" void P3SymBuild_EndBuildInnerModule (unsigned int tokno)
     573              : {
     574          432 :   NameKey_Name NameStart;
     575          432 :   NameKey_Name NameEnd;
     576              : 
     577          432 :   SymbolTable_CheckForUnknownInModule (tokno);
     578          432 :   SymbolTable_EndScope ();
     579          432 :   M2Quads_PopT (&NameEnd);
     580          432 :   M2Quads_PopT (&NameStart);
     581          432 :   if (NameStart != NameEnd)
     582              :     {
     583              :       /* we dont issue an error based around incorrect module names this would be done in P1 and P2.
     584              :          If we get here then something has gone wrong with our error recovery in P3, so we bail out.
     585              :   */
     586            0 :       M2Error_WriteFormat0 ((const char *) "too many errors in pass 3", 25);
     587            0 :       M2Error_FlushErrors ();
     588              :     }
     589          432 :   SymbolTable_SetCurrentModule (SymbolTable_GetModuleScope (SymbolTable_GetCurrentModule ()));
     590          432 :   M2Error_LeaveErrorScope ();
     591          432 :   M2StackSpell_Pop ();
     592          432 :   M2StackSpell_Pop ();
     593          432 : }
     594              : 
     595              : 
     596              : /*
     597              :    CheckImportListOuterModule - checks to see that all identifiers are
     598              :                                 exported from the definition module.
     599              : 
     600              :                                 The Stack is expected:
     601              : 
     602              :                                 Entry           OR    Entry
     603              : 
     604              :                          Ptr ->                Ptr ->
     605              :                                 +------------+        +-----------+
     606              :                                 | #          |        | #         |
     607              :                                 |------------|        |-----------|
     608              :                                 | Id1        |        | Id1       |
     609              :                                 |------------|        |-----------|
     610              :                                 .            .        .           .
     611              :                                 .            .        .           .
     612              :                                 .            .        .           .
     613              :                                 |------------|        |-----------|
     614              :                                 | Id#        |        | Id#       |
     615              :                                 |------------|        |-----------|
     616              :                                 | ImportTok  |        | Ident     |
     617              :                                 |------------|        |-----------|
     618              : 
     619              :                                 IMPORT Id1, .. Id# ;  FROM Ident IMPORT Id1 .. Id# ;
     620              : 
     621              : 
     622              :                                                       Error Condition
     623              :                                 Exit
     624              : 
     625              :                                 All above stack discarded
     626              : */
     627              : 
     628       123007 : extern "C" void P3SymBuild_CheckImportListOuterModule (void)
     629              : {
     630       123007 :   NameKey_Name n1;
     631       123007 :   NameKey_Name n2;
     632       123007 :   unsigned int tok;
     633       123007 :   unsigned int ModSym;
     634       123007 :   unsigned int i;
     635       123007 :   unsigned int n;
     636              : 
     637       123007 :   M2Quads_PopT (&n);  /* n   = # of the Ident List  */
     638       123007 :   if ((M2Quads_OperandT (n+1)) != M2Reserved_ImportTok)
     639              :     {
     640              :       /* Ident List contains list of objects  */
     641       123007 :       ModSym = M2Batch_LookupOuterModule (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
     642       123007 :       i = 1;
     643       413165 :       while (i <= n)
     644              :         {
     645       167151 :           tok = static_cast<unsigned int> (M2Quads_OperandTok (i));
     646       167151 :           if ((! (SymbolTable_IsExported (ModSym, SymbolTable_RequestSym (tok, M2Quads_OperandT (i))))) && (! (SymbolTable_IsImplicityExported (ModSym, SymbolTable_RequestSym (tok, M2Quads_OperandT (i))))))
     647              :             {
     648            0 :               n1 = static_cast<NameKey_Name> (M2Quads_OperandT (n+1));
     649            0 :               n2 = static_cast<NameKey_Name> (M2Quads_OperandT (i));
     650            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));
     651              :             }
     652       167151 :           i += 1;
     653              :         }
     654              :     }
     655       123007 :   M2Quads_PopN (n+1);  /* clear stack  */
     656       123007 : }
     657              : 
     658              : 
     659              : /*
     660              :    BuildProcedureHeading - Builds a procedure heading for the definition
     661              :                            module procedures.
     662              : 
     663              :                            Operation only performed if compiling a
     664              :                            definition module.
     665              : 
     666              :                            The Stack:
     667              : 
     668              :                            Entry                       Exit
     669              : 
     670              :                     Ptr ->
     671              :                            +------------+
     672              :                            | ProcSym    |
     673              :                            |------------|
     674              :                            | NameStart  |
     675              :                            |------------|
     676              :                                                        Empty
     677              : 
     678              : */
     679              : 
     680      3372453 : extern "C" void P3SymBuild_BuildProcedureHeading (void)
     681              : {
     682      3372453 :   unsigned int ProcSym;
     683      3372453 :   NameKey_Name NameStart;
     684              : 
     685      3372453 :   if (M2Comp_CompilingDefinitionModule ())
     686              :     {
     687      3331696 :       M2Quads_PopT (&ProcSym);
     688      3331696 :       M2Quads_PopT (&NameStart);
     689      3331696 :       SymbolTable_EndScope ();
     690      3331696 :       M2StackSpell_Pop ();
     691              :     }
     692      3372453 : }
     693              : 
     694              : 
     695              : /*
     696              :    StartBuildProcedure - Builds a Procedure.
     697              : 
     698              :                          The Stack:
     699              : 
     700              :                          Entry                 Exit
     701              : 
     702              :                                                               <- Ptr
     703              :                                                +------------+
     704              :                   Ptr ->                       | ProcSym    |
     705              :                          +------------+        |------------|
     706              :                          | Name       |        | Name       |
     707              :                          |------------|        |------------|
     708              : */
     709              : 
     710      5276401 : extern "C" void P3SymBuild_StartBuildProcedure (void)
     711              : {
     712      5276401 :   unsigned int tok;
     713      5276401 :   NameKey_Name name;
     714      5276401 :   unsigned int ProcSym;
     715              : 
     716      5276401 :   M2Quads_PopTtok (&name, &tok);
     717      5276401 :   M2Quads_PushTtok (name, tok);  /* Name saved for the EndBuildProcedure name check  */
     718      5276401 :   ProcSym = SymbolTable_RequestSym (tok, name);  /* Name saved for the EndBuildProcedure name check  */
     719      5276401 :   M2Debug_Assert (SymbolTable_IsProcedure (ProcSym));
     720      5276401 :   M2Quads_PushTtok (ProcSym, tok);
     721      5276401 :   SymbolTable_StartScope (ProcSym);
     722      5276401 :   M2Error_EnterProcedureScope (name);
     723      5276401 :   M2StackSpell_Push (ProcSym);
     724      5276401 : }
     725              : 
     726              : 
     727              : /*
     728              :    EndBuildProcedure - Ends building a Procedure.
     729              :                        It checks the start procedure name matches the end
     730              :                        procedure name.
     731              : 
     732              :                        The Stack:
     733              : 
     734              :                        (Procedure Not Defined in definition module)
     735              : 
     736              :                        Entry                 Exit
     737              : 
     738              :                 Ptr ->
     739              :                        +------------+
     740              :                        | NameEnd    |
     741              :                        |------------|
     742              :                        | ProcSym    |
     743              :                        |------------|
     744              :                        | NameStart  |
     745              :                        |------------|
     746              :                                              Empty
     747              : */
     748              : 
     749      1944637 : extern "C" void P3SymBuild_EndBuildProcedure (void)
     750              : {
     751      1944637 :   unsigned int ProcSym;
     752      1944637 :   NameKey_Name NameEnd;
     753      1944637 :   NameKey_Name NameStart;
     754              : 
     755      1944637 :   M2Quads_PopT (&NameEnd);
     756      1944637 :   M2Quads_PopT (&ProcSym);
     757      1944637 :   M2Quads_PopT (&NameStart);
     758      1944637 :   if (NameEnd != NameStart)
     759              :     {
     760              :       /* we dont issue an error based around incorrect module names this would be done in P1 and P2.
     761              :          If we get here then something has gone wrong with our error recovery in P3, so we bail out.
     762              :   */
     763            0 :       M2Error_WriteFormat0 ((const char *) "too many errors in pass 3", 25);
     764            0 :       M2Error_FlushErrors ();
     765              :     }
     766      1944637 :   SymbolTable_EndScope ();
     767      1944637 :   M2Error_LeaveErrorScope ();
     768      1944637 :   M2StackSpell_Pop ();
     769      1944637 : }
     770              : 
     771              : 
     772              : /*
     773              :    EndBuildForward -
     774              : */
     775              : 
     776           24 : extern "C" void P3SymBuild_EndBuildForward (void)
     777              : {
     778           24 :   M2Quads_PopN (2);
     779           24 :   SymbolTable_EndScope ();
     780           24 :   M2Error_LeaveErrorScope ();
     781           24 :   M2StackSpell_Pop ();
     782           24 : }
     783              : 
     784              : 
     785              : /*
     786              :    BuildSubrange - Builds a Subrange type Symbol.
     787              : 
     788              : 
     789              :                       Stack
     790              : 
     791              :                       Entry                 Exit
     792              : 
     793              :                Ptr ->
     794              :                       +------------+
     795              :                       | High       |
     796              :                       |------------|
     797              :                       | Low        |                       <- Ptr
     798              :                       |------------|
     799              : */
     800              : 
     801       104385 : extern "C" void P3SymBuild_BuildSubrange (void)
     802              : {
     803       104385 :   unsigned int Base;
     804       104385 :   unsigned int Type;
     805       104385 :   unsigned int Low;
     806       104385 :   unsigned int High;
     807              : 
     808       104385 :   M2Quads_PopT (&High);
     809       104385 :   M2Quads_PopT (&Low);
     810       104385 :   FifoQueue_GetSubrangeFromFifoQueue (&Type);  /* Collect subrange type from pass 2 and fill in  */
     811              :   /* bounds.  */
     812       104385 :   FifoQueue_GetSubrangeFromFifoQueue (&Base);  /* Get base of subrange (maybe NulSym)  */
     813              :   /* worked out later in M2GCCDeclare  */
     814       104385 :   SymbolTable_PutSubrange (Type, Low, High, Base);
     815       104385 : }
     816              : 
     817              : 
     818              : /*
     819              :    BuildNulName - Pushes a NulKey onto the top of the stack.
     820              :                   The Stack:
     821              : 
     822              : 
     823              :                   Entry                    Exit
     824              : 
     825              :                                                           <- Ptr
     826              :                   Empty                    +------------+
     827              :                                            | NulKey     |
     828              :                                            |------------|
     829              : */
     830              : 
     831            0 : extern "C" void P3SymBuild_BuildNulName (void)
     832              : {
     833            0 :   M2Quads_PushT (static_cast<unsigned int> (NameKey_NulName));
     834            0 : }
     835              : 
     836              : 
     837              : /*
     838              :    BuildConst - builds a constant.
     839              :                 Stack
     840              : 
     841              :                 Entry                 Exit
     842              : 
     843              :          Ptr ->                                      <- Ptr
     844              :                 +------------+        +------------+
     845              :                 | Name       |        | Sym        |
     846              :                 |------------+        |------------|
     847              : */
     848              : 
     849       299242 : extern "C" void P3SymBuild_BuildConst (void)
     850              : {
     851       299242 :   NameKey_Name name;
     852       299242 :   unsigned int tok;
     853       299242 :   unsigned int Sym;
     854              : 
     855       299242 :   M2Quads_PopTtok (&name, &tok);
     856       299242 :   Sym = SymbolTable_RequestSym (tok, name);
     857       299242 :   M2Quads_PushTtok (Sym, tok);
     858       299242 : }
     859              : 
     860              : 
     861              : /*
     862              :    BuildVarAtAddress - updates the symbol table entry of, variable sym, to be declared
     863              :                        at address, address.
     864              : 
     865              :                        Stack
     866              : 
     867              :                        Entry                 Exit
     868              : 
     869              :                 Ptr ->
     870              :                        +--------------+
     871              :                        | Expr | EType |                         <- Ptr
     872              :                        |--------------+        +--------------+
     873              :                        | name | SType |        | name | SType |
     874              :                        |--------------+        |--------------|
     875              : */
     876              : 
     877           54 : extern "C" void P3SymBuild_BuildVarAtAddress (void)
     878              : {
     879           54 :   unsigned int nametok;
     880           54 :   NameKey_Name name;
     881           54 :   unsigned int Sym;
     882           54 :   unsigned int SType;
     883           54 :   unsigned int Exp;
     884           54 :   unsigned int EType;
     885              : 
     886           54 :   M2Quads_PopTF (&Exp, &EType);
     887           54 :   M2Quads_PopTFtok (&name, &SType, &nametok);
     888           54 :   M2Quads_PushTF (name, SType);
     889           54 :   Sym = SymbolTable_RequestSym (nametok, name);
     890           54 :   if ((SymbolTable_GetMode (Sym)) == SymbolTable_LeftValue)
     891              :     {
     892           54 :       SymbolTable_PutVariableAtAddress (Sym, Exp);
     893              :     }
     894              :   else
     895              :     {
     896            0 :       M2Error_InternalError ((const char *) "expecting lvalue for this variable which is declared at an explicit address", 75);
     897              :     }
     898           54 : }
     899              : 
     900              : 
     901              : /*
     902              :    BuildOptArgInitializer - assigns the constant value symbol, const, to be the
     903              :                             initial value of the optional parameter should it be
     904              :                             absent.
     905              : 
     906              :                             Ptr ->
     907              :                                    +------------+
     908              :                                    | const      |
     909              :                                    |------------|                      <- Ptr
     910              : */
     911              : 
     912        15163 : extern "C" void P3SymBuild_BuildOptArgInitializer (void)
     913              : {
     914        15163 :   unsigned int tok;
     915        15163 :   unsigned int const_;
     916        15163 :   unsigned int ProcSym;
     917              : 
     918        15163 :   M2Quads_PopT (&const_);
     919        15163 :   M2Quads_PopTtok (&ProcSym, &tok);
     920        15163 :   M2Debug_Assert (SymbolTable_IsProcedure (ProcSym));
     921        15163 :   M2Quads_PushTtok (ProcSym, tok);
     922        15163 :   SymbolTable_PutOptArgInit (SymbolTable_GetCurrentScope (), const_);
     923        15163 : }
     924              : 
     925        15451 : extern "C" void _M2_P3SymBuild_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
     926              : {
     927        15451 : }
     928              : 
     929            0 : extern "C" void _M2_P3SymBuild_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
     930              : {
     931            0 : }
        

Generated by: LCOV version 2.5.0-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.