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.4 % 238 220
Test Date: 2025-11-22 14:42:49 Functions: 90.5 % 21 19
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

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

Generated by: LCOV version 2.1-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.