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: 79.3 % 334 265
Test Date: 2026-02-28 14:20:25 Functions: 80.0 % 30 24
Legend: Lines:     hit not hit

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

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