LCOV - code coverage report
Current view: top level - /mnt/build/buildbot/bld/build-lcov/gcc/m2/gm2-compiler-boot - P0SymBuild.c (source / functions) Coverage Total Hit
Test: gcc.info Lines: 77.5 % 329 255
Test Date: 2024-03-23 14:05:01 Functions: 75.9 % 29 22
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 P0SymBuild.  */
       2                 :             : /* P0SymBuild.mod pass 0 symbol creation.
       3                 :             : 
       4                 :             : Copyright (C) 2011-2024 Free Software Foundation, Inc.
       5                 :             : Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
       6                 :             : 
       7                 :             : This file is part of GNU Modula-2.
       8                 :             : 
       9                 :             : GNU Modula-2 is free software; you can redistribute it and/or modify
      10                 :             : it under the terms of the GNU General Public License as published by
      11                 :             : the Free Software Foundation; either version 3, or (at your option)
      12                 :             : any later version.
      13                 :             : 
      14                 :             : GNU Modula-2 is distributed in the hope that it will be useful, but
      15                 :             : WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17                 :             : General Public License for more details.
      18                 :             : 
      19                 :             : You should have received a copy of the GNU General Public License
      20                 :             : along with GNU Modula-2; see the file COPYING3.  If not see
      21                 :             : <http://www.gnu.org/licenses/>.  */
      22                 :             : 
      23                 :             : #include "config.h"
      24                 :             : #include "system.h"
      25                 :             : #include <stdbool.h>
      26                 :             : #   if !defined (PROC_D)
      27                 :             : #      define PROC_D
      28                 :             :        typedef void (*PROC_t) (void);
      29                 :             :        typedef struct { PROC_t proc; } PROC;
      30                 :             : #   endif
      31                 :             : 
      32                 :             : #   if !defined (FALSE)
      33                 :             : #      define FALSE (1==0)
      34                 :             : #   endif
      35                 :             : 
      36                 :             : #   include "GStorage.h"
      37                 :             : #if defined(__cplusplus)
      38                 :             : #   undef NULL
      39                 :             : #   define NULL 0
      40                 :             : #endif
      41                 :             : #define _P0SymBuild_H
      42                 :             : #define _P0SymBuild_C
      43                 :             : 
      44                 :             : #   include "GStorage.h"
      45                 :             : #   include "GM2Printf.h"
      46                 :             : #   include "GLists.h"
      47                 :             : #   include "GIndexing.h"
      48                 :             : #   include "GM2Batch.h"
      49                 :             : #   include "GSymbolTable.h"
      50                 :             : #   include "GNameKey.h"
      51                 :             : #   include "GM2Quads.h"
      52                 :             : #   include "GM2Reserved.h"
      53                 :             : #   include "GM2Debug.h"
      54                 :             : #   include "GM2MetaError.h"
      55                 :             : #   include "GM2LexBuf.h"
      56                 :             : #   include "GM2Error.h"
      57                 :             : #   include "GM2RTS.h"
      58                 :             : 
      59                 :             : #   define Debugging false
      60                 :             : typedef struct P0SymBuild__T1_r P0SymBuild__T1;
      61                 :             : 
      62                 :             : typedef P0SymBuild__T1 *P0SymBuild_BlockInfoPtr;
      63                 :             : 
      64                 :             : typedef struct P0SymBuild__T2_r P0SymBuild__T2;
      65                 :             : 
      66                 :             : typedef P0SymBuild__T2 *P0SymBuild_ModuleDesc;
      67                 :             : 
      68                 :             : typedef enum {P0SymBuild_module, P0SymBuild_program, P0SymBuild_defimp, P0SymBuild_inner, P0SymBuild_procedure, P0SymBuild_universe, P0SymBuild_unknown} P0SymBuild_Kind;
      69                 :             : 
      70                 :             : struct P0SymBuild__T1_r {
      71                 :             :                           NameKey_Name name;
      72                 :             :                           P0SymBuild_Kind kind;
      73                 :             :                           unsigned int sym;
      74                 :             :                           unsigned int level;
      75                 :             :                           unsigned int token;
      76                 :             :                           Lists_List LocalModules;
      77                 :             :                           Indexing_Index ImportedModules;
      78                 :             :                           P0SymBuild_BlockInfoPtr toPC;
      79                 :             :                           P0SymBuild_BlockInfoPtr toReturn;
      80                 :             :                           P0SymBuild_BlockInfoPtr toNext;
      81                 :             :                           P0SymBuild_BlockInfoPtr toUp;
      82                 :             :                           P0SymBuild_BlockInfoPtr toDown;
      83                 :             :                         };
      84                 :             : 
      85                 :             : struct P0SymBuild__T2_r {
      86                 :             :                           NameKey_Name name;
      87                 :             :                           unsigned int tok;
      88                 :             :                         };
      89                 :             : 
      90                 :             : static P0SymBuild_BlockInfoPtr headBP;
      91                 :             : static P0SymBuild_BlockInfoPtr curBP;
      92                 :             : static unsigned int Level;
      93                 :             : 
      94                 :             : /*
      95                 :             :    EndModule -
      96                 :             : */
      97                 :             : 
      98                 :             : extern "C" void P0SymBuild_EndModule (void);
      99                 :             : 
     100                 :             : /*
     101                 :             :    RegisterImports -
     102                 :             : */
     103                 :             : 
     104                 :             : extern "C" void P0SymBuild_RegisterImports (void);
     105                 :             : 
     106                 :             : /*
     107                 :             :    RegisterProgramModule - register the top of stack as a program module.
     108                 :             : */
     109                 :             : 
     110                 :             : extern "C" void P0SymBuild_RegisterProgramModule (void);
     111                 :             : 
     112                 :             : /*
     113                 :             :    RegisterImplementationModule - register the top of stack as an implementation module.
     114                 :             : */
     115                 :             : 
     116                 :             : extern "C" void P0SymBuild_RegisterImplementationModule (void);
     117                 :             : 
     118                 :             : /*
     119                 :             :    RegisterDefinitionModule - register the top of stack as a definition module.
     120                 :             : */
     121                 :             : 
     122                 :             : extern "C" void P0SymBuild_RegisterDefinitionModule (bool forC);
     123                 :             : 
     124                 :             : /*
     125                 :             :    RegisterInnerModule - register the top of stack as an inner module, this module name
     126                 :             :                          will be removed from the list of outstanding imports in the
     127                 :             :                          current module block.
     128                 :             : */
     129                 :             : 
     130                 :             : extern "C" void P0SymBuild_RegisterInnerModule (void);
     131                 :             : 
     132                 :             : /*
     133                 :             :    RegisterInnerImports -
     134                 :             : */
     135                 :             : 
     136                 :             : extern "C" void P0SymBuild_RegisterInnerImports (void);
     137                 :             : 
     138                 :             : /*
     139                 :             :    RegisterProcedure - register the top of stack as a procedure.
     140                 :             : */
     141                 :             : 
     142                 :             : extern "C" void P0SymBuild_RegisterProcedure (void);
     143                 :             : extern "C" void P0SymBuild_EndProcedure (void);
     144                 :             : 
     145                 :             : /*
     146                 :             :    P0Init -
     147                 :             : */
     148                 :             : 
     149                 :             : extern "C" void P0SymBuild_P0Init (void);
     150                 :             : 
     151                 :             : /*
     152                 :             :    P1Init -
     153                 :             : */
     154                 :             : 
     155                 :             : extern "C" void P0SymBuild_P1Init (void);
     156                 :             : 
     157                 :             : /*
     158                 :             :    EnterBlock -
     159                 :             : */
     160                 :             : 
     161                 :             : extern "C" void P0SymBuild_EnterBlock (NameKey_Name n);
     162                 :             : 
     163                 :             : /*
     164                 :             :    LeaveBlock -
     165                 :             : */
     166                 :             : 
     167                 :             : extern "C" void P0SymBuild_LeaveBlock (void);
     168                 :             : 
     169                 :             : /*
     170                 :             :    nSpaces -
     171                 :             : */
     172                 :             : 
     173                 :             : static void nSpaces (unsigned int n);
     174                 :             : 
     175                 :             : /*
     176                 :             :    DisplayB -
     177                 :             : */
     178                 :             : 
     179                 :             : static void DisplayB (P0SymBuild_BlockInfoPtr b);
     180                 :             : 
     181                 :             : /*
     182                 :             :    DisplayBlock -
     183                 :             : */
     184                 :             : 
     185                 :             : static void DisplayBlock (P0SymBuild_BlockInfoPtr b, unsigned int l);
     186                 :             : 
     187                 :             : /*
     188                 :             :    Display -
     189                 :             : */
     190                 :             : 
     191                 :             : static void Display (void);
     192                 :             : 
     193                 :             : /*
     194                 :             :    addDown - adds, b, to the down link of, a.
     195                 :             : */
     196                 :             : 
     197                 :             : static void addDown (P0SymBuild_BlockInfoPtr a, P0SymBuild_BlockInfoPtr b);
     198                 :             : 
     199                 :             : /*
     200                 :             :    GraftBlock - add a new block, b, into the tree in the correct order.
     201                 :             : */
     202                 :             : 
     203                 :             : static void GraftBlock (P0SymBuild_BlockInfoPtr b);
     204                 :             : 
     205                 :             : /*
     206                 :             :    BeginBlock - denotes the start of the next block.  We remember all imports and
     207                 :             :                 local modules and procedures created in this block.
     208                 :             : */
     209                 :             : 
     210                 :             : static void BeginBlock (NameKey_Name n, P0SymBuild_Kind k, unsigned int s, unsigned int tok);
     211                 :             : 
     212                 :             : /*
     213                 :             :    InitUniverse -
     214                 :             : */
     215                 :             : 
     216                 :             : static void InitUniverse (void);
     217                 :             : 
     218                 :             : /*
     219                 :             :    FlushImports -
     220                 :             : */
     221                 :             : 
     222                 :             : static void FlushImports (P0SymBuild_BlockInfoPtr b);
     223                 :             : 
     224                 :             : /*
     225                 :             :    EndBlock - shutdown the module and create definition symbols for all imported
     226                 :             :               modules.
     227                 :             : */
     228                 :             : 
     229                 :             : static void EndBlock (void);
     230                 :             : 
     231                 :             : /*
     232                 :             :    RegisterLocalModule - register, n, as a local module.
     233                 :             : */
     234                 :             : 
     235                 :             : static void RegisterLocalModule (NameKey_Name modname);
     236                 :             : 
     237                 :             : /*
     238                 :             :    RegisterImport - register, n, as a module imported from either a local scope or definition module.
     239                 :             : */
     240                 :             : 
     241                 :             : static void RegisterImport (unsigned int tok, NameKey_Name modname);
     242                 :             : 
     243                 :             : /*
     244                 :             :    DeclareModules - declare all inner modules seen at the current block level.
     245                 :             : */
     246                 :             : 
     247                 :             : static void DeclareModules (void);
     248                 :             : 
     249                 :             : /*
     250                 :             :    Move -
     251                 :             : */
     252                 :             : 
     253                 :             : static void Move (void);
     254                 :             : 
     255                 :             : 
     256                 :             : /*
     257                 :             :    nSpaces -
     258                 :             : */
     259                 :             : 
     260                 :           0 : static void nSpaces (unsigned int n)
     261                 :             : {
     262                 :           0 :   while (n > 0)
     263                 :             :     {
     264                 :           0 :       M2Printf_printf0 ((const char *) " ", 1);
     265                 :           0 :       n -= 1;
     266                 :             :     }
     267                 :           0 : }
     268                 :             : 
     269                 :             : 
     270                 :             : /*
     271                 :             :    DisplayB -
     272                 :             : */
     273                 :             : 
     274                 :           0 : static void DisplayB (P0SymBuild_BlockInfoPtr b)
     275                 :             : {
     276                 :           0 :   switch (b->kind)
     277                 :             :     {
     278                 :           0 :       case P0SymBuild_program:
     279                 :           0 :         M2Printf_printf1 ((const char *) "MODULE %a ;\\n", 13, (const unsigned char *) &b->name, (sizeof (b->name)-1));
     280                 :           0 :         break;
     281                 :             : 
     282                 :           0 :       case P0SymBuild_defimp:
     283                 :           0 :         M2Printf_printf1 ((const char *) "DEFIMP %a ;\\n", 13, (const unsigned char *) &b->name, (sizeof (b->name)-1));
     284                 :           0 :         break;
     285                 :             : 
     286                 :           0 :       case P0SymBuild_inner:
     287                 :           0 :         M2Printf_printf1 ((const char *) "INNER MODULE %a ;\\n", 19, (const unsigned char *) &b->name, (sizeof (b->name)-1));
     288                 :           0 :         break;
     289                 :             : 
     290                 :           0 :       case P0SymBuild_procedure:
     291                 :           0 :         M2Printf_printf1 ((const char *) "PROCEDURE %a ;\\n", 16, (const unsigned char *) &b->name, (sizeof (b->name)-1));
     292                 :           0 :         break;
     293                 :             : 
     294                 :             : 
     295                 :           0 :       default:
     296                 :           0 :         M2RTS_HALT (-1);
     297                 :             :         __builtin_unreachable ();
     298                 :           0 :         break;
     299                 :             :     }
     300                 :           0 : }
     301                 :             : 
     302                 :             : 
     303                 :             : /*
     304                 :             :    DisplayBlock -
     305                 :             : */
     306                 :             : 
     307                 :           0 : static void DisplayBlock (P0SymBuild_BlockInfoPtr b, unsigned int l)
     308                 :             : {
     309                 :           0 :   P0SymBuild_BlockInfoPtr a;
     310                 :             : 
     311                 :           0 :   nSpaces (l);
     312                 :           0 :   DisplayB (b);
     313                 :           0 :   a = b->toDown;
     314                 :           0 :   l += 3;
     315                 :           0 :   while (a != NULL)
     316                 :             :     {
     317                 :           0 :       DisplayBlock (a, l);
     318                 :           0 :       a = a->toNext;
     319                 :             :     }
     320                 :           0 :   l -= 3;
     321                 :           0 :   nSpaces (l);
     322                 :           0 :   M2Printf_printf1 ((const char *) "END %a\\n", 8, (const unsigned char *) &b->name, (sizeof (b->name)-1));
     323                 :           0 : }
     324                 :             : 
     325                 :             : 
     326                 :             : /*
     327                 :             :    Display -
     328                 :             : */
     329                 :             : 
     330                 :           0 : static void Display (void)
     331                 :             : {
     332                 :           0 :   P0SymBuild_BlockInfoPtr b;
     333                 :             : 
     334                 :           0 :   M2Printf_printf0 ((const char *) "Universe of Modula-2 modules\\n", 30);
     335                 :           0 :   if (headBP != NULL)
     336                 :             :     {
     337                 :           0 :       b = headBP->toDown;
     338                 :           0 :       while (b != NULL)
     339                 :             :         {
     340                 :           0 :           DisplayBlock (b, 0);
     341                 :           0 :           b = b->toNext;
     342                 :             :         }
     343                 :             :     }
     344                 :           0 : }
     345                 :             : 
     346                 :             : 
     347                 :             : /*
     348                 :             :    addDown - adds, b, to the down link of, a.
     349                 :             : */
     350                 :             : 
     351                 :     1069064 : static void addDown (P0SymBuild_BlockInfoPtr a, P0SymBuild_BlockInfoPtr b)
     352                 :             : {
     353                 :           0 :   if (a->toDown == NULL)
     354                 :             :     {
     355                 :       69126 :       a->toDown = b;
     356                 :             :     }
     357                 :             :   else
     358                 :             :     {
     359                 :             :       a = a->toDown;
     360                 :    19794164 :       while (a->toNext != NULL)
     361                 :             :         {
     362                 :             :           a = a->toNext;
     363                 :             :         }
     364                 :      999938 :       a->toNext = b;
     365                 :             :     }
     366                 :           0 : }
     367                 :             : 
     368                 :             : 
     369                 :             : /*
     370                 :             :    GraftBlock - add a new block, b, into the tree in the correct order.
     371                 :             : */
     372                 :             : 
     373                 :     1069064 : static void GraftBlock (P0SymBuild_BlockInfoPtr b)
     374                 :             : {
     375                 :     1069064 :   M2Debug_Assert (curBP != NULL);
     376                 :     1069064 :   M2Debug_Assert ( (Level-curBP->level) <= 1);
     377                 :     1069064 :   switch (Level-curBP->level)
     378                 :             :     {
     379                 :           0 :       case -1:
     380                 :           0 :         curBP = curBP->toUp;  /* returning up to the outer scope  */
     381                 :           0 :         M2Debug_Assert (curBP->toNext == NULL);
     382                 :           0 :         curBP->toNext = b;
     383                 :           0 :         break;
     384                 :             : 
     385                 :           0 :       case 0:
     386                 :           0 :         M2Debug_Assert (curBP->toNext == NULL);  /* add toNext  */
     387                 :           0 :         curBP->toNext = b;
     388                 :           0 :         b->toUp = curBP->toUp;
     389                 :           0 :         break;
     390                 :             : 
     391                 :     1069064 :       case 1:
     392                 :     1069064 :         b->toUp = curBP;  /* save return value  */
     393                 :     1069064 :         addDown (curBP, b);  /* save return value  */
     394                 :             :         break;
     395                 :             : 
     396                 :             : 
     397                 :           0 :       default:
     398                 :           0 :         M2RTS_HALT (-1);
     399                 :             :         __builtin_unreachable ();
     400                 :     1069064 :         break;
     401                 :             :     }
     402                 :     1069064 :   curBP = b;
     403                 :     1069064 : }
     404                 :             : 
     405                 :             : 
     406                 :             : /*
     407                 :             :    BeginBlock - denotes the start of the next block.  We remember all imports and
     408                 :             :                 local modules and procedures created in this block.
     409                 :             : */
     410                 :             : 
     411                 :     1069064 : static void BeginBlock (NameKey_Name n, P0SymBuild_Kind k, unsigned int s, unsigned int tok)
     412                 :             : {
     413                 :     1069064 :   P0SymBuild_BlockInfoPtr b;
     414                 :             : 
     415                 :     1069064 :   Storage_ALLOCATE ((void **) &b, sizeof (P0SymBuild__T1));
     416                 :     1069064 :   b->name = n;
     417                 :     1069064 :   b->kind = k;
     418                 :     1069064 :   b->sym = s;
     419                 :     1069064 :   Lists_InitList (&b->LocalModules);
     420                 :     1069064 :   b->ImportedModules = Indexing_InitIndex (1);
     421                 :     1069064 :   b->toPC = NULL;
     422                 :     1069064 :   b->toReturn = NULL;
     423                 :     1069064 :   b->toNext = NULL;
     424                 :     1069064 :   b->toDown = NULL;
     425                 :     1069064 :   b->toUp = NULL;
     426                 :     1069064 :   b->level = Level;
     427                 :     1069064 :   b->token = tok;
     428                 :     1069064 :   GraftBlock (b);
     429                 :     1069064 : }
     430                 :             : 
     431                 :             : 
     432                 :             : /*
     433                 :             :    InitUniverse -
     434                 :             : */
     435                 :             : 
     436                 :       16867 : static void InitUniverse (void)
     437                 :             : {
     438                 :       16867 :   Storage_ALLOCATE ((void **) &curBP, sizeof (P0SymBuild__T1));
     439                 :       16867 :   curBP->name = NameKey_NulName;
     440                 :       16867 :   curBP->kind = P0SymBuild_universe;
     441                 :       16867 :   curBP->sym = SymbolTable_NulSym;
     442                 :       16867 :   Lists_InitList (&curBP->LocalModules);
     443                 :       16867 :   curBP->ImportedModules = Indexing_InitIndex (1);
     444                 :       16867 :   curBP->toNext = NULL;
     445                 :       16867 :   curBP->toDown = NULL;
     446                 :       16867 :   curBP->toUp = curBP;
     447                 :       16867 :   curBP->level = Level;
     448                 :       16867 :   headBP = curBP;
     449                 :       16867 : }
     450                 :             : 
     451                 :             : 
     452                 :             : /*
     453                 :             :    FlushImports -
     454                 :             : */
     455                 :             : 
     456                 :     1257746 : static void FlushImports (P0SymBuild_BlockInfoPtr b)
     457                 :             : {
     458                 :     1257746 :   unsigned int i;
     459                 :     1257746 :   unsigned int n;
     460                 :     1257746 :   P0SymBuild_ModuleDesc desc;
     461                 :             : 
     462                 :     1257746 :   i = Indexing_LowIndice (b->ImportedModules);
     463                 :     1257746 :   n = Indexing_HighIndice (b->ImportedModules);
     464                 :     8257670 :   while (i <= n)
     465                 :             :     {
     466                 :     5742178 :       desc = static_cast<P0SymBuild_ModuleDesc> (Indexing_GetIndice (b->ImportedModules, i));
     467                 :     5742178 :       b->sym = M2Batch_MakeDefinitionSource (desc->tok, desc->name);
     468                 :     5742178 :       M2Debug_Assert (b->sym != SymbolTable_NulSym);
     469                 :     5742178 :       i += 1;
     470                 :             :     }
     471                 :     1257746 : }
     472                 :             : 
     473                 :             : 
     474                 :             : /*
     475                 :             :    EndBlock - shutdown the module and create definition symbols for all imported
     476                 :             :               modules.
     477                 :             : */
     478                 :             : 
     479                 :     1069064 : static void EndBlock (void)
     480                 :             : {
     481                 :     1069064 :   FlushImports (curBP);
     482                 :     1069064 :   curBP = curBP->toUp;
     483                 :     1069064 :   Level -= 1;
     484                 :     1069064 :   if (Level == 0)
     485                 :             :     {
     486                 :      188682 :       FlushImports (curBP);
     487                 :             :     }
     488                 :     1069064 : }
     489                 :             : 
     490                 :             : 
     491                 :             : /*
     492                 :             :    RegisterLocalModule - register, n, as a local module.
     493                 :             : */
     494                 :             : 
     495                 :         408 : static void RegisterLocalModule (NameKey_Name modname)
     496                 :             : {
     497                 :         408 :   unsigned int i;
     498                 :         408 :   unsigned int n;
     499                 :         408 :   P0SymBuild_ModuleDesc desc;
     500                 :             : 
     501                 :             :   /* printf1('seen local module %a
     502                 :             :   ', n) ;  */
     503                 :         408 :   Lists_IncludeItemIntoList (curBP->LocalModules, modname);
     504                 :         408 :   i = Indexing_LowIndice (curBP->ImportedModules);
     505                 :         408 :   n = Indexing_HighIndice (curBP->ImportedModules);
     506                 :         828 :   while (i <= n)
     507                 :             :     {
     508                 :          12 :       desc = static_cast<P0SymBuild_ModuleDesc> (Indexing_GetIndice (curBP->ImportedModules, i));
     509                 :          12 :       if (desc->name == modname)
     510                 :             :         {
     511                 :          12 :           Indexing_RemoveIndiceFromIndex (curBP->ImportedModules, reinterpret_cast<void *> (desc));
     512                 :          12 :           Storage_DEALLOCATE ((void **) &desc, sizeof (P0SymBuild__T2));
     513                 :             :           /* Continue checking in case a user imported the same module again.  */
     514                 :          12 :           n -= 1;
     515                 :             :         }
     516                 :             :       else
     517                 :             :         {
     518                 :           0 :           i += 1;
     519                 :             :         }
     520                 :             :     }
     521                 :         408 : }
     522                 :             : 
     523                 :             : 
     524                 :             : /*
     525                 :             :    RegisterImport - register, n, as a module imported from either a local scope or definition module.
     526                 :             : */
     527                 :             : 
     528                 :      283200 : static void RegisterImport (unsigned int tok, NameKey_Name modname)
     529                 :             : {
     530                 :      283200 :   P0SymBuild_BlockInfoPtr bp;
     531                 :      283200 :   P0SymBuild_ModuleDesc desc;
     532                 :             : 
     533                 :             :   /* printf1('register import from module %a
     534                 :             :   ', n) ;  */
     535                 :      283200 :   M2Debug_Assert (curBP != NULL);
     536                 :      283200 :   M2Debug_Assert (curBP->toUp != NULL);
     537                 :      283200 :   bp = curBP->toUp;  /* skip over current module  */
     538                 :      283200 :   if (! (Lists_IsItemInList (bp->LocalModules, modname)))  /* skip over current module  */
     539                 :             :     {
     540                 :      283176 :       Storage_ALLOCATE ((void **) &desc, sizeof (P0SymBuild__T2));
     541                 :      283176 :       desc->name = modname;
     542                 :      283176 :       desc->tok = tok;
     543                 :      283176 :       Indexing_IncludeIndiceIntoIndex (bp->ImportedModules, reinterpret_cast<void *> (desc));
     544                 :             :     }
     545                 :      283200 : }
     546                 :             : 
     547                 :             : 
     548                 :             : /*
     549                 :             :    DeclareModules - declare all inner modules seen at the current block level.
     550                 :             : */
     551                 :             : 
     552                 :     1068182 : static void DeclareModules (void)
     553                 :             : {
     554                 :     1068182 :   P0SymBuild_BlockInfoPtr b;
     555                 :     1068182 :   unsigned int s;
     556                 :             : 
     557                 :     1068182 :   b = curBP->toDown;
     558                 :     1947934 :   while (b != NULL)
     559                 :             :     {
     560                 :      879752 :       if (b->kind == P0SymBuild_inner)
     561                 :             :         {
     562                 :         408 :           if (Debugging)
     563                 :             :             {
     564                 :             :               M2Printf_printf1 ((const char *) "***  declaring inner module %a\\n", 32, (const unsigned char *) &b->name, (sizeof (b->name)-1));
     565                 :             :             }
     566                 :         408 :           s = SymbolTable_MakeInnerModule (curBP->token, b->name);
     567                 :         408 :           M2Debug_Assert (s != SymbolTable_NulSym);
     568                 :             :         }
     569                 :      879752 :       b = b->toNext;
     570                 :             :     }
     571                 :     1068182 : }
     572                 :             : 
     573                 :             : 
     574                 :             : /*
     575                 :             :    Move -
     576                 :             : */
     577                 :             : 
     578                 :     2136358 : static void Move (void)
     579                 :             : {
     580                 :     2136358 :   P0SymBuild_BlockInfoPtr b;
     581                 :             : 
     582                 :     2136358 :   if (Level == curBP->level)
     583                 :             :     {
     584                 :           0 :       b = curBP->toReturn;
     585                 :             :       /* moving to next  */
     586                 :           0 :       curBP = curBP->toNext;
     587                 :             :       /* remember our return  */
     588                 :           0 :       curBP->toReturn = b;
     589                 :             :     }
     590                 :             :   else
     591                 :             :     {
     592                 :     4272716 :       while (Level != curBP->level)
     593                 :             :         {
     594                 :     2136358 :           if (Level < curBP->level)
     595                 :             :             {
     596                 :             :               /* move up to the outer scope  */
     597                 :     1068176 :               b = curBP;
     598                 :     1068176 :               curBP = curBP->toReturn;
     599                 :     1068176 :               curBP->toPC = b->toNext;
     600                 :             :             }
     601                 :             :           else
     602                 :             :             {
     603                 :             :               /* remember where we came from  */
     604                 :     1068182 :               b = curBP;
     605                 :     1068182 :               if (curBP->toPC == NULL)
     606                 :             :                 {
     607                 :       52218 :                   M2Debug_Assert (curBP->toDown != NULL);
     608                 :       52218 :                   curBP->toPC = curBP->toDown;
     609                 :             :                 }
     610                 :     1068182 :               M2Debug_Assert (curBP->toPC != NULL);
     611                 :     1068182 :               curBP = curBP->toPC;
     612                 :     1068182 :               curBP->toReturn = b;
     613                 :             :             }
     614                 :             :         }
     615                 :             :     }
     616                 :     2136358 : }
     617                 :             : 
     618                 :             : 
     619                 :             : /*
     620                 :             :    EndModule -
     621                 :             : */
     622                 :             : 
     623                 :      189090 : extern "C" void P0SymBuild_EndModule (void)
     624                 :             : {
     625                 :      189090 :   NameKey_Name NameEnd;
     626                 :      189090 :   NameKey_Name NameStart;
     627                 :      189090 :   unsigned int end;
     628                 :      189090 :   unsigned int start;
     629                 :             : 
     630                 :      189090 :   M2Quads_PopTtok (&NameEnd, &end);
     631                 :      189090 :   M2Quads_PopTtok (&NameStart, &start);
     632                 :      189090 :   M2Debug_Assert (start != M2LexBuf_UnknownTokenNo);
     633                 :      189090 :   M2Debug_Assert (end != M2LexBuf_UnknownTokenNo);
     634                 :      189090 :   if (NameEnd != NameStart)
     635                 :             :     {
     636                 :             :       /* avoid gcc warning by using compound statement even if not strictly necessary.  */
     637                 :           6 :       if (NameEnd == NameKey_NulName)
     638                 :             :         {
     639                 :           0 :           M2MetaError_MetaErrorT1 (start, (const char *) "module name at beginning {%1Ea} does not match the name at end", 62, SymbolTable_MakeError (start, NameStart));
     640                 :           0 :           M2MetaError_MetaError1 ((const char *) "module name at end does not match the name at beginning {%1Ea}", 62, SymbolTable_MakeError (start, NameStart));
     641                 :             :         }
     642                 :             :       else
     643                 :             :         {
     644                 :           6 :           M2MetaError_MetaErrorT2 (start, (const char *) "module name at beginning {%1Ea} does not match the name at end {%2a}", 68, SymbolTable_MakeError (start, curBP->name), SymbolTable_MakeError (end, NameEnd));
     645                 :           6 :           M2MetaError_MetaErrorT2 (end, (const char *) "module name at end {%1Ea} does not match the name at beginning {%2Ea}", 69, SymbolTable_MakeError (end, NameEnd), SymbolTable_MakeError (start, curBP->name));
     646                 :             :         }
     647                 :             :     }
     648                 :      189090 :   EndBlock ();
     649                 :      189090 :   M2Error_LeaveErrorScope ();
     650                 :      189090 : }
     651                 :             : 
     652                 :             : 
     653                 :             : /*
     654                 :             :    RegisterImports -
     655                 :             : */
     656                 :             : 
     657                 :      275316 : extern "C" void P0SymBuild_RegisterImports (void)
     658                 :             : {
     659                 :      275316 :   unsigned int index;
     660                 :      275316 :   unsigned int i;
     661                 :      275316 :   unsigned int n;
     662                 :             : 
     663                 :      275316 :   M2Quads_PopT (&n);  /* n   = # of the Ident List  */
     664                 :      275316 :   if ((M2Quads_OperandT (n+1)) == M2Reserved_ImportTok)
     665                 :             :     {
     666                 :             :       /* Ident list contains Module Names  */
     667                 :             :       i = 1;
     668                 :       70730 :       while (i <= n)
     669                 :             :         {
     670                 :       39274 :           index = (n+1)-i;
     671                 :       39274 :           RegisterImport (M2Quads_OperandTok (index), M2Quads_OperandT (index));
     672                 :       39274 :           i += 1;
     673                 :             :         }
     674                 :             :     }
     675                 :             :   else
     676                 :             :     {
     677                 :             :       /* Ident List contains list of objects  */
     678                 :      243860 :       RegisterImport (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
     679                 :             :     }
     680                 :      275316 :   M2Quads_PopN (n+1);  /* clear stack  */
     681                 :      275316 : }
     682                 :             : 
     683                 :             : 
     684                 :             : /*
     685                 :             :    RegisterProgramModule - register the top of stack as a program module.
     686                 :             : */
     687                 :             : 
     688                 :       10240 : extern "C" void P0SymBuild_RegisterProgramModule (void)
     689                 :             : {
     690                 :       10240 :   NameKey_Name n;
     691                 :       10240 :   unsigned int sym;
     692                 :       10240 :   unsigned int tok;
     693                 :             : 
     694                 :       10240 :   M2Debug_Assert (Level == 0);
     695                 :       10240 :   Level += 1;
     696                 :       10240 :   M2Quads_PopTtok (&n, &tok);
     697                 :       10240 :   M2Quads_PushTtok (n, tok);
     698                 :       10240 :   sym = M2Batch_MakeProgramSource (tok, n);
     699                 :       10240 :   SymbolTable_SetCurrentModule (sym);
     700                 :       10240 :   SymbolTable_SetFileModule (sym);
     701                 :       10240 :   BeginBlock (n, P0SymBuild_program, sym, tok);
     702                 :       10240 :   M2Error_EnterProgramScope (n);
     703                 :       10240 : }
     704                 :             : 
     705                 :             : 
     706                 :             : /*
     707                 :             :    RegisterImplementationModule - register the top of stack as an implementation module.
     708                 :             : */
     709                 :             : 
     710                 :       52718 : extern "C" void P0SymBuild_RegisterImplementationModule (void)
     711                 :             : {
     712                 :       52718 :   NameKey_Name n;
     713                 :       52718 :   unsigned int sym;
     714                 :       52718 :   unsigned int tok;
     715                 :             : 
     716                 :       52718 :   M2Debug_Assert (Level == 0);
     717                 :       52718 :   Level += 1;
     718                 :       52718 :   M2Quads_PopTtok (&n, &tok);
     719                 :       52718 :   M2Quads_PushTtok (n, tok);
     720                 :       52718 :   sym = M2Batch_MakeImplementationSource (tok, n);
     721                 :       52718 :   SymbolTable_SetCurrentModule (sym);
     722                 :       52718 :   SymbolTable_SetFileModule (sym);
     723                 :       52718 :   BeginBlock (n, P0SymBuild_defimp, sym, tok);
     724                 :       52718 :   M2Error_EnterImplementationScope (n);
     725                 :       52718 : }
     726                 :             : 
     727                 :             : 
     728                 :             : /*
     729                 :             :    RegisterDefinitionModule - register the top of stack as a definition module.
     730                 :             : */
     731                 :             : 
     732                 :      125724 : extern "C" void P0SymBuild_RegisterDefinitionModule (bool forC)
     733                 :             : {
     734                 :      125724 :   NameKey_Name n;
     735                 :      125724 :   unsigned int sym;
     736                 :      125724 :   unsigned int tok;
     737                 :             : 
     738                 :      125724 :   M2Debug_Assert (Level == 0);
     739                 :      125724 :   Level += 1;
     740                 :      125724 :   M2Quads_PopTtok (&n, &tok);
     741                 :      125724 :   M2Quads_PushTtok (n, tok);
     742                 :      125724 :   sym = M2Batch_MakeDefinitionSource (tok, n);
     743                 :      125724 :   SymbolTable_SetCurrentModule (sym);
     744                 :      125724 :   SymbolTable_SetFileModule (sym);
     745                 :      125724 :   if (forC)
     746                 :             :     {
     747                 :        7646 :       SymbolTable_PutDefinitionForC (sym);
     748                 :             :     }
     749                 :      125724 :   BeginBlock (n, P0SymBuild_defimp, sym, tok);
     750                 :      125724 :   M2Error_EnterDefinitionScope (n);
     751                 :      125724 : }
     752                 :             : 
     753                 :             : 
     754                 :             : /*
     755                 :             :    RegisterInnerModule - register the top of stack as an inner module, this module name
     756                 :             :                          will be removed from the list of outstanding imports in the
     757                 :             :                          current module block.
     758                 :             : */
     759                 :             : 
     760                 :         408 : extern "C" void P0SymBuild_RegisterInnerModule (void)
     761                 :             : {
     762                 :         408 :   NameKey_Name n;
     763                 :         408 :   unsigned int tok;
     764                 :             : 
     765                 :         408 :   Level += 1;
     766                 :         408 :   M2Quads_PopTtok (&n, &tok);
     767                 :         408 :   M2Quads_PushTtok (n, tok);
     768                 :         408 :   RegisterLocalModule (n);
     769                 :         408 :   BeginBlock (n, P0SymBuild_inner, SymbolTable_NulSym, tok);
     770                 :         408 :   M2Error_EnterModuleScope (n);
     771                 :         408 : }
     772                 :             : 
     773                 :             : 
     774                 :             : /*
     775                 :             :    RegisterInnerImports -
     776                 :             : */
     777                 :             : 
     778                 :         210 : extern "C" void P0SymBuild_RegisterInnerImports (void)
     779                 :             : {
     780                 :         210 :   unsigned int n;
     781                 :             : 
     782                 :         210 :   M2Quads_PopT (&n);  /* n   = # of the Ident List  */
     783                 :         210 :   if ((M2Quads_OperandT (n+1)) == M2Reserved_ImportTok)
     784                 :             :     {}  /* empty.  */
     785                 :             :   else
     786                 :             :     {
     787                 :             :       /* Ident List contains list of objects, but we are importing directly from a module OperandT(n+1)  */
     788                 :          66 :       RegisterImport (M2Quads_OperandTok (n+1), M2Quads_OperandT (n+1));
     789                 :             :     }
     790                 :         210 :   M2Quads_PopN (n+1);  /* clear stack  */
     791                 :         210 : }
     792                 :             : 
     793                 :             : 
     794                 :             : /*
     795                 :             :    RegisterProcedure - register the top of stack as a procedure.
     796                 :             : */
     797                 :             : 
     798                 :      879974 : extern "C" void P0SymBuild_RegisterProcedure (void)
     799                 :             : {
     800                 :      879974 :   NameKey_Name n;
     801                 :      879974 :   unsigned int tok;
     802                 :             : 
     803                 :      879974 :   Level += 1;
     804                 :      879974 :   M2Quads_PopTtok (&n, &tok);
     805                 :      879974 :   M2Quads_PushTtok (n, tok);
     806                 :      879974 :   BeginBlock (n, P0SymBuild_procedure, SymbolTable_NulSym, tok);
     807                 :      879974 :   M2Error_EnterProcedureScope (n);
     808                 :      879974 : }
     809                 :             : 
     810                 :      879974 : extern "C" void P0SymBuild_EndProcedure (void)
     811                 :             : {
     812                 :      879974 :   NameKey_Name NameEnd;
     813                 :      879974 :   NameKey_Name NameStart;
     814                 :      879974 :   unsigned int end;
     815                 :      879974 :   unsigned int start;
     816                 :             : 
     817                 :             :   /* 
     818                 :             :    EndBuildProcedure - ends building a Procedure.
     819                 :             :   */
     820                 :      879974 :   M2Quads_PopTtok (&NameEnd, &end);
     821                 :      879974 :   M2Quads_PopTtok (&NameStart, &start);
     822                 :      879974 :   M2Debug_Assert (start != M2LexBuf_UnknownTokenNo);
     823                 :      879974 :   M2Debug_Assert (end != M2LexBuf_UnknownTokenNo);
     824                 :      879974 :   if (NameEnd != NameStart)
     825                 :             :     {
     826                 :             :       /* avoid gcc warning by using compound statement even if not strictly necessary.  */
     827                 :           0 :       if (NameEnd == NameKey_NulName)
     828                 :             :         {
     829                 :           0 :           M2MetaError_MetaErrorT1 (start, (const char *) "procedure name at beginning {%1Ea} does not match the name at end", 65, SymbolTable_MakeError (start, NameStart));
     830                 :           0 :           M2MetaError_MetaError1 ((const char *) "procedure name at end does not match the name at beginning {%1Ea}", 65, SymbolTable_MakeError (start, NameStart));
     831                 :             :         }
     832                 :             :       else
     833                 :             :         {
     834                 :           0 :           M2MetaError_MetaErrorT2 (start, (const char *) "procedure name at beginning {%1Ea} does not match the name at end {%2a}", 71, SymbolTable_MakeError (start, curBP->name), SymbolTable_MakeError (end, NameEnd));
     835                 :           0 :           M2MetaError_MetaErrorT2 (end, (const char *) "procedure name at end {%1Ea} does not match the name at beginning {%2Ea}", 72, SymbolTable_MakeError (end, NameEnd), SymbolTable_MakeError (start, curBP->name));
     836                 :             :         }
     837                 :             :     }
     838                 :      879974 :   EndBlock ();
     839                 :      879974 :   M2Error_LeaveErrorScope ();
     840                 :      879974 : }
     841                 :             : 
     842                 :             : 
     843                 :             : /*
     844                 :             :    P0Init -
     845                 :             : */
     846                 :             : 
     847                 :       16867 : extern "C" void P0SymBuild_P0Init (void)
     848                 :             : {
     849                 :       16867 :   headBP = NULL;
     850                 :       16867 :   curBP = NULL;
     851                 :       16867 :   Level = 0;
     852                 :       16867 :   InitUniverse ();
     853                 :       16867 : }
     854                 :             : 
     855                 :             : 
     856                 :             : /*
     857                 :             :    P1Init -
     858                 :             : */
     859                 :             : 
     860                 :       16826 : extern "C" void P0SymBuild_P1Init (void)
     861                 :             : {
     862                 :       16826 :   if (Debugging)
     863                 :             :     {
     864                 :             :       Display ();
     865                 :             :     }
     866                 :             :   /* curBP := headBP^.toDown ;  */
     867                 :       16826 :   curBP = headBP;
     868                 :       16826 :   M2Debug_Assert (curBP != NULL);
     869                 :       16826 :   curBP->toPC = curBP->toDown;
     870                 :       16826 :   curBP->toReturn = curBP;
     871                 :       16826 :   Level = 0;
     872                 :       16826 : }
     873                 :             : 
     874                 :             : 
     875                 :             : /*
     876                 :             :    EnterBlock -
     877                 :             : */
     878                 :             : 
     879                 :     1068182 : extern "C" void P0SymBuild_EnterBlock (NameKey_Name n)
     880                 :             : {
     881                 :     1068182 :   M2Debug_Assert (curBP != NULL);
     882                 :     1068182 :   Level += 1;
     883                 :     1068182 :   Move ();
     884                 :     1068182 :   if (Debugging)
     885                 :             :     {
     886                 :             :       nSpaces (Level*3);
     887                 :             :       if (n == curBP->name)
     888                 :             :         {
     889                 :             :           M2Printf_printf1 ((const char *) "block %a\\n", 10, (const unsigned char *) &n, (sizeof (n)-1));
     890                 :             :         }
     891                 :             :       else
     892                 :             :         {
     893                 :             :           M2Printf_printf2 ((const char *) "seen block %a but tree has recorded %a\\n", 40, (const unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) &curBP->name, (sizeof (curBP->name)-1));
     894                 :             :         }
     895                 :             :     }
     896                 :     2136364 :   M2Debug_Assert ((n == curBP->name) || (curBP->name == NameKey_NulName));
     897                 :     1068182 :   DeclareModules ();
     898                 :     1068182 : }
     899                 :             : 
     900                 :             : 
     901                 :             : /*
     902                 :             :    LeaveBlock -
     903                 :             : */
     904                 :             : 
     905                 :     1068176 : extern "C" void P0SymBuild_LeaveBlock (void)
     906                 :             : {
     907                 :     1068176 :   if (Debugging)
     908                 :             :     {
     909                 :             :       M2Printf_printf1 ((const char *) "leaving block %a ", 17, (const unsigned char *) &curBP->name, (sizeof (curBP->name)-1));
     910                 :             :     }
     911                 :     1068176 :   Level -= 1;
     912                 :     1068176 :   Move ();
     913                 :     1068176 : }
     914                 :             : 
     915                 :           0 : extern "C" void _M2_P0SymBuild_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
     916                 :             : {
     917                 :           0 : }
     918                 :             : 
     919                 :           0 : extern "C" void _M2_P0SymBuild_fini (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
     920                 :             : {
     921                 :           0 : }
        

Generated by: LCOV version 2.0-1

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.