LCOV - code coverage report
Current view: top level - /mnt/build/buildbot/bld/build-lcov/gcc/m2/gm2-compiler-boot - M2Comp.c (source / functions) Coverage Total Hit
Test: gcc.info Lines: 58.5 % 598 350
Test Date: 2024-04-13 14:00:49 Functions: 59.5 % 37 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 M2Comp.  */
       2                 :             : /* M2Comp.mod continually calls the compiler for every source file.
       3                 :             : 
       4                 :             : Copyright (C) 2001-2024 Free Software Foundation, Inc.
       5                 :             : Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
       6                 :             : 
       7                 :             : This file is part of GNU Modula-2.
       8                 :             : 
       9                 :             : GNU Modula-2 is free software; you can redistribute it and/or modify
      10                 :             : it under the terms of the GNU General Public License as published by
      11                 :             : the Free Software Foundation; either version 3, or (at your option)
      12                 :             : any later version.
      13                 :             : 
      14                 :             : GNU Modula-2 is distributed in the hope that it will be useful, but
      15                 :             : WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17                 :             : General Public License for more details.
      18                 :             : 
      19                 :             : You should have received a copy of the GNU General Public License
      20                 :             : along with GNU Modula-2; see the file COPYING3.  If not see
      21                 :             : <http://www.gnu.org/licenses/>.  */
      22                 :             : 
      23                 :             : #include "config.h"
      24                 :             : #include "system.h"
      25                 :             : #include <stdbool.h>
      26                 :             : #   if !defined (PROC_D)
      27                 :             : #      define PROC_D
      28                 :             :        typedef void (*PROC_t) (void);
      29                 :             :        typedef struct { PROC_t proc; } PROC;
      30                 :             : #   endif
      31                 :             : 
      32                 :             : #   if !defined (TRUE)
      33                 :             : #      define TRUE (1==1)
      34                 :             : #   endif
      35                 :             : 
      36                 :             : #   if !defined (FALSE)
      37                 :             : #      define FALSE (1==0)
      38                 :             : #   endif
      39                 :             : 
      40                 :             : #   include "Gmcrts.h"
      41                 :             : #if defined(__cplusplus)
      42                 :             : #   undef NULL
      43                 :             : #   define NULL 0
      44                 :             : #endif
      45                 :             : #define _M2Comp_H
      46                 :             : #define _M2Comp_C
      47                 :             : 
      48                 :             : #   include "GM2Pass.h"
      49                 :             : #   include "GM2Reserved.h"
      50                 :             : #   include "GM2Search.h"
      51                 :             : #   include "GM2Code.h"
      52                 :             : #   include "GM2LexBuf.h"
      53                 :             : #   include "GM2FileName.h"
      54                 :             : #   include "GM2Preprocess.h"
      55                 :             : #   include "Glibc.h"
      56                 :             : #   include "GM2Error.h"
      57                 :             : #   include "GM2MetaError.h"
      58                 :             : #   include "GFormatStrings.h"
      59                 :             : #   include "GP0SymBuild.h"
      60                 :             : #   include "GM2Debug.h"
      61                 :             : #   include "Gm2flex.h"
      62                 :             : #   include "GP0SyntaxCheck.h"
      63                 :             : #   include "GP1Build.h"
      64                 :             : #   include "GP2Build.h"
      65                 :             : #   include "GPCBuild.h"
      66                 :             : #   include "GP3Build.h"
      67                 :             : #   include "GPHBuild.h"
      68                 :             : #   include "GPCSymBuild.h"
      69                 :             : #   include "GDynamicStrings.h"
      70                 :             : #   include "GM2Batch.h"
      71                 :             : #   include "GSymbolTable.h"
      72                 :             : #   include "GFIO.h"
      73                 :             : #   include "GSFIO.h"
      74                 :             : #   include "GNameKey.h"
      75                 :             : #   include "GM2Printf.h"
      76                 :             : #   include "GM2Quiet.h"
      77                 :             : #   include "GM2Options.h"
      78                 :             : #   include "GPathName.h"
      79                 :             : #   include "GLists.h"
      80                 :             : #   include "GIndexing.h"
      81                 :             : 
      82                 :             : #   define Debugging false
      83                 :             : static enum {M2Comp_None, M2Comp_Definition, M2Comp_Implementation, M2Comp_Program} ModuleType;
      84                 :             : static Indexing_Index DepContent;
      85                 :             : static DynamicStrings_String DepOutput;
      86                 :             : 
      87                 :             : /*
      88                 :             :    compile - compile the filename.
      89                 :             : */
      90                 :             : 
      91                 :             : extern "C" void M2Comp_compile (void * filename);
      92                 :             : 
      93                 :             : /*
      94                 :             :    CompilingDefinitionModule - returns true if the current module being
      95                 :             :                                compiled is a definition module.
      96                 :             : */
      97                 :             : 
      98                 :             : extern "C" bool M2Comp_CompilingDefinitionModule (void);
      99                 :             : 
     100                 :             : /*
     101                 :             :    CompilingImplementationModule - returns true if the current module being
     102                 :             :                                    compiled is an implementation module.
     103                 :             : */
     104                 :             : 
     105                 :             : extern "C" bool M2Comp_CompilingImplementationModule (void);
     106                 :             : 
     107                 :             : /*
     108                 :             :    CompilingProgramModule - returns true if the current module being
     109                 :             :                             compiled is a program module.
     110                 :             : */
     111                 :             : 
     112                 :             : extern "C" bool M2Comp_CompilingProgramModule (void);
     113                 :             : 
     114                 :             : /*
     115                 :             :    NeedToParseImplementation -
     116                 :             : */
     117                 :             : 
     118                 :             : static bool NeedToParseImplementation (unsigned int sym);
     119                 :             : 
     120                 :             : /*
     121                 :             :    GenerateDefDependency - generate a single dependency for the definition module
     122                 :             :                            providing that it can be found and is not blocked by -MM.
     123                 :             : */
     124                 :             : 
     125                 :             : static void GenerateDefDependency (unsigned int module);
     126                 :             : 
     127                 :             : /*
     128                 :             :    GenerateDependenciesFromImport - lookup the module associated with the import
     129                 :             :                                     and call GenerateDefDependency.
     130                 :             : */
     131                 :             : 
     132                 :             : static void GenerateDependenciesFromImport (unsigned int import);
     133                 :             : 
     134                 :             : /*
     135                 :             :    GenerateDependenciesFromList - iterative over the import lists and for
     136                 :             :                                   each module issue a dependency.
     137                 :             : */
     138                 :             : 
     139                 :             : static void GenerateDependenciesFromList (Lists_List dep);
     140                 :             : 
     141                 :             : /*
     142                 :             :    GenerateDependencies - generate a list of dependencies for the main module where
     143                 :             :                           the source code is found in sourcefile.
     144                 :             : */
     145                 :             : 
     146                 :             : static void GenerateDependencies (DynamicStrings_String sourcefile);
     147                 :             : 
     148                 :             : /*
     149                 :             :    Compile - compile file, s, using a 5 pass technique.
     150                 :             : */
     151                 :             : 
     152                 :             : static void Compile (DynamicStrings_String s);
     153                 :             : 
     154                 :             : /*
     155                 :             :    ExamineHeader - examines up until the ';', '[' or eof and determines if the source file
     156                 :             :                    is a program, implementation/definition module.
     157                 :             : */
     158                 :             : 
     159                 :             : static void ExamineHeader (void * *name, bool *isdefimp, bool *module);
     160                 :             : 
     161                 :             : /*
     162                 :             :    ExamineCompilationUnit - opens the source file to obtain the module name and kind of module.
     163                 :             : */
     164                 :             : 
     165                 :             : static unsigned int ExamineCompilationUnit (void);
     166                 :             : 
     167                 :             : /*
     168                 :             :    PeepInto - peeps into source, s, and initializes a definition/implementation or
     169                 :             :               program module accordingly.
     170                 :             : */
     171                 :             : 
     172                 :             : static void PeepInto (DynamicStrings_String s);
     173                 :             : 
     174                 :             : /*
     175                 :             :    qprintLibName - print the libname.
     176                 :             : */
     177                 :             : 
     178                 :             : static void qprintLibName (DynamicStrings_String LibName);
     179                 :             : 
     180                 :             : /*
     181                 :             :    CreateFileStem - create a stem using the template LibName_ModuleName.
     182                 :             : */
     183                 :             : 
     184                 :             : static DynamicStrings_String CreateFileStem (DynamicStrings_String SymName, DynamicStrings_String LibName);
     185                 :             : static DynamicStrings_String BaseName (DynamicStrings_String Path, bool CutExt);
     186                 :             : 
     187                 :             : /*
     188                 :             :    IsLibrary - return TRUE if line contains a library module.
     189                 :             : */
     190                 :             : 
     191                 :             : static bool IsLibrary (DynamicStrings_String line);
     192                 :             : 
     193                 :             : /*
     194                 :             :    IsUnique - return TRUE if line is unique in array content.
     195                 :             : */
     196                 :             : 
     197                 :             : static bool IsUnique (Indexing_Index content, DynamicStrings_String line);
     198                 :             : 
     199                 :             : /*
     200                 :             :    Append - append line to array content.
     201                 :             : */
     202                 :             : 
     203                 :             : static void Append (Indexing_Index content, DynamicStrings_String line);
     204                 :             : 
     205                 :             : /*
     206                 :             :    MergeDep - if line is unique in array content then append.
     207                 :             :               Check to see (and ignore) if line is a library module and -MM
     208                 :             :               is present.
     209                 :             : */
     210                 :             : 
     211                 :             : static void MergeDep (Indexing_Index content, DynamicStrings_String line);
     212                 :             : 
     213                 :             : /*
     214                 :             :    splitLine - split a line into words separated by spaces
     215                 :             :                and call MergeDep on each word.
     216                 :             : */
     217                 :             : 
     218                 :             : static void splitLine (Indexing_Index content, DynamicStrings_String line);
     219                 :             : 
     220                 :             : /*
     221                 :             :    MergeDeps - foreach dependency in ChildDep do
     222                 :             :                   add dependency to ChildDep if not already present.
     223                 :             :                ignore all ChildDep if -MM and libname # "".
     224                 :             : */
     225                 :             : 
     226                 :             : static void MergeDeps (Indexing_Index content, DynamicStrings_String ChildDep, DynamicStrings_String LibName);
     227                 :             : 
     228                 :             : /*
     229                 :             :    GetRuleTarget - return the rule target which is derived from the -MT arg
     230                 :             :                    or -o arg or filename.mod.
     231                 :             : */
     232                 :             : 
     233                 :             : static DynamicStrings_String GetRuleTarget (DynamicStrings_String filename);
     234                 :             : 
     235                 :             : /*
     236                 :             :    ReadDepContents - reads the contents of file dep into a dynamic array
     237                 :             :                      and return the array.  The file will be split into words
     238                 :             :                      and each word stored as an entry in the array.
     239                 :             : */
     240                 :             : 
     241                 :             : static Indexing_Index ReadDepContents (DynamicStrings_String filename, DynamicStrings_String dep);
     242                 :             : 
     243                 :             : /*
     244                 :             :    WriteDep - write the dependencies and target to file out.
     245                 :             : */
     246                 :             : 
     247                 :             : static void WriteDep (DynamicStrings_String dep, Indexing_Index contents, FIO_File out);
     248                 :             : 
     249                 :             : /*
     250                 :             :    WritePhonyDep - write the dependencies and target to file out.
     251                 :             : */
     252                 :             : 
     253                 :             : static void WritePhonyDep (DynamicStrings_String dep, Indexing_Index contents, FIO_File out);
     254                 :             : 
     255                 :             : /*
     256                 :             :    WriteDepContents - write the dynamic array to filename dep (or StdOut) if
     257                 :             :                       the GetMF file is NIL.
     258                 :             : */
     259                 :             : 
     260                 :             : static void WriteDepContents (DynamicStrings_String dep, Indexing_Index contents);
     261                 :             : 
     262                 :             : /*
     263                 :             :    CreateDepFilename - return a dependency filename associated with filename or use GetMF.
     264                 :             : */
     265                 :             : 
     266                 :             : static DynamicStrings_String CreateDepFilename (DynamicStrings_String filename);
     267                 :             : 
     268                 :             : /*
     269                 :             :    Pass0CheckDef -
     270                 :             : */
     271                 :             : 
     272                 :             : static bool Pass0CheckDef (unsigned int sym);
     273                 :             : 
     274                 :             : /*
     275                 :             :    Pass0CheckMod -
     276                 :             : */
     277                 :             : 
     278                 :             : static bool Pass0CheckMod (unsigned int sym, DynamicStrings_String PPSource);
     279                 :             : 
     280                 :             : /*
     281                 :             :    DoPass0 -
     282                 :             : */
     283                 :             : 
     284                 :             : static void DoPass0 (DynamicStrings_String filename);
     285                 :             : 
     286                 :             : /*
     287                 :             :    DoPass1 - parses the sources of all modules necessary to compile
     288                 :             :              the required module, Main.
     289                 :             : */
     290                 :             : 
     291                 :             : static void DoPass1 (void);
     292                 :             : 
     293                 :             : /*
     294                 :             :    DoPass2 - parses the sources of all modules necessary to compile
     295                 :             :              the required module, Main.
     296                 :             : */
     297                 :             : 
     298                 :             : static void DoPass2 (void);
     299                 :             : 
     300                 :             : /*
     301                 :             :    DoPassC - parses the sources of all modules necessary to compile
     302                 :             :              the required module, Main.
     303                 :             : */
     304                 :             : 
     305                 :             : static void DoPassC (void);
     306                 :             : 
     307                 :             : /*
     308                 :             :    DoPass3 - parses the sources of all modules necessary to compile
     309                 :             :              the required module, Main.
     310                 :             : */
     311                 :             : 
     312                 :             : static void DoPass3 (void);
     313                 :             : 
     314                 :             : 
     315                 :             : /*
     316                 :             :    NeedToParseImplementation -
     317                 :             : */
     318                 :             : 
     319                 :      104861 : static bool NeedToParseImplementation (unsigned int sym)
     320                 :             : {
     321                 :      104861 :   return ((((SymbolTable_IsDefImp (sym)) && (SymbolTable_IsHiddenTypeDeclared (sym))) && M2Options_ExtendedOpaque) || ((SymbolTable_IsDefImp (sym)) && (SymbolTable_IsBuiltinInModule (sym)))) || (M2Options_WholeProgram && (! (SymbolTable_IsDefinitionForC (sym))));
     322                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     323                 :             :   __builtin_unreachable ();
     324                 :             : }
     325                 :             : 
     326                 :             : 
     327                 :             : /*
     328                 :             :    GenerateDefDependency - generate a single dependency for the definition module
     329                 :             :                            providing that it can be found and is not blocked by -MM.
     330                 :             : */
     331                 :             : 
     332                 :           0 : static void GenerateDefDependency (unsigned int module)
     333                 :             : {
     334                 :           0 :   DynamicStrings_String stem;
     335                 :           0 :   DynamicStrings_String fullpath;
     336                 :           0 :   DynamicStrings_String named;
     337                 :             : 
     338                 :           0 :   stem = DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (SymbolTable_GetSymName (module)));
     339                 :           0 :   named = static_cast<DynamicStrings_String> (NULL);
     340                 :           0 :   if (M2Search_FindSourceDefFile (stem, &fullpath, &named))
     341                 :             :     {
     342                 :             :       /* avoid gcc warning by using compound statement even if not strictly necessary.  */
     343                 :           0 :       if ((DynamicStrings_EqualArray (named, (const char *) "", 0)) || (! (M2Options_GetMM ())))
     344                 :             :         {
     345                 :           0 :           MergeDep (DepContent, fullpath);
     346                 :             :         }
     347                 :             :       else
     348                 :             :         {
     349                 :           0 :           fullpath = DynamicStrings_KillString (fullpath);
     350                 :             :         }
     351                 :             :     }
     352                 :           0 :   stem = DynamicStrings_KillString (stem);
     353                 :           0 :   named = DynamicStrings_KillString (named);
     354                 :           0 : }
     355                 :             : 
     356                 :             : 
     357                 :             : /*
     358                 :             :    GenerateDependenciesFromImport - lookup the module associated with the import
     359                 :             :                                     and call GenerateDefDependency.
     360                 :             : */
     361                 :             : 
     362                 :           0 : static void GenerateDependenciesFromImport (unsigned int import)
     363                 :             : {
     364                 :           0 :   unsigned int module;
     365                 :             : 
     366                 :           0 :   M2Debug_Assert (SymbolTable_IsImport (import));
     367                 :           0 :   module = SymbolTable_GetImportModule (import);
     368                 :           0 :   GenerateDefDependency (module);
     369                 :           0 : }
     370                 :             : 
     371                 :             : 
     372                 :             : /*
     373                 :             :    GenerateDependenciesFromList - iterative over the import lists and for
     374                 :             :                                   each module issue a dependency.
     375                 :             : */
     376                 :             : 
     377                 :           0 : static void GenerateDependenciesFromList (Lists_List dep)
     378                 :             : {
     379                 :           0 :   Lists_List importList;
     380                 :           0 :   unsigned int import;
     381                 :           0 :   unsigned int i;
     382                 :           0 :   unsigned int n;
     383                 :           0 :   unsigned int j;
     384                 :           0 :   unsigned int m;
     385                 :             : 
     386                 :           0 :   n = Lists_NoOfItemsInList (dep);
     387                 :           0 :   i = 1;
     388                 :           0 :   while (i <= n)
     389                 :             :     {
     390                 :           0 :       import = static_cast<unsigned int> (Lists_GetItemFromList (dep, i));
     391                 :           0 :       if (SymbolTable_IsImportStatement (import))
     392                 :             :         {
     393                 :           0 :           importList = SymbolTable_GetImportStatementList (import);
     394                 :           0 :           j = 1;
     395                 :           0 :           m = Lists_NoOfItemsInList (importList);
     396                 :           0 :           while (j <= m)
     397                 :             :             {
     398                 :           0 :               import = static_cast<unsigned int> (Lists_GetItemFromList (importList, j));
     399                 :           0 :               GenerateDependenciesFromImport (import);
     400                 :           0 :               j += 1;
     401                 :             :             }
     402                 :             :         }
     403                 :             :       else
     404                 :             :         {
     405                 :           0 :           GenerateDependenciesFromImport (import);
     406                 :             :         }
     407                 :           0 :       i += 1;
     408                 :             :     }
     409                 :           0 : }
     410                 :             : 
     411                 :             : 
     412                 :             : /*
     413                 :             :    GenerateDependencies - generate a list of dependencies for the main module where
     414                 :             :                           the source code is found in sourcefile.
     415                 :             : */
     416                 :             : 
     417                 :           0 : static void GenerateDependencies (DynamicStrings_String sourcefile)
     418                 :             : {
     419                 :           0 :   if (SymbolTable_IsDefImp (SymbolTable_GetMainModule ()))
     420                 :             :     {
     421                 :           0 :       GenerateDependenciesFromList (SymbolTable_GetModuleDefImportStatementList (SymbolTable_GetMainModule ()));
     422                 :           0 :       GenerateDefDependency (SymbolTable_GetMainModule ());
     423                 :             :     }
     424                 :           0 :   GenerateDependenciesFromList (SymbolTable_GetModuleModImportStatementList (SymbolTable_GetMainModule ()));
     425                 :           0 :   WriteDepContents (DepOutput, DepContent);
     426                 :           0 : }
     427                 :             : 
     428                 :             : 
     429                 :             : /*
     430                 :             :    Compile - compile file, s, using a 5 pass technique.
     431                 :             : */
     432                 :             : 
     433                 :       12963 : static void Compile (DynamicStrings_String s)
     434                 :             : {
     435                 :       12963 :   DoPass0 (s);
     436                 :       12940 :   M2Error_FlushWarnings ();
     437                 :       12940 :   M2Error_FlushErrors ();
     438                 :       12916 :   M2LexBuf_ResetForNewPass ();
     439                 :       12916 :   M2Error_ResetErrorScope ();
     440                 :       12916 :   M2Quiet_qprintf0 ((const char *) "Pass 1: scopes, enumerated types, imports and exports\\n", 55);
     441                 :       12916 :   DoPass1 ();
     442                 :       12910 :   M2Error_FlushWarnings ();
     443                 :       12910 :   M2Error_FlushErrors ();
     444                 :       12904 :   if ((M2Options_GetM ()) || (M2Options_GetMM ()))
     445                 :             :     {
     446                 :           0 :       GenerateDependencies (s);
     447                 :             :     }
     448                 :       12904 :   if (! M2Options_PPonly)
     449                 :             :     {
     450                 :       12904 :       M2Quiet_qprintf0 ((const char *) "Pass 2: constants and types\\n", 29);
     451                 :       12904 :       M2LexBuf_ResetForNewPass ();
     452                 :       12904 :       M2Error_ResetErrorScope ();
     453                 :       12904 :       DoPass2 ();
     454                 :       12892 :       M2Error_FlushWarnings ();
     455                 :       12892 :       M2Error_FlushErrors ();
     456                 :       12868 :       M2Quiet_qprintf0 ((const char *) "Pass C: aggregate constants\\n", 29);
     457                 :       12868 :       M2LexBuf_ResetForNewPass ();
     458                 :       12868 :       M2Error_ResetErrorScope ();
     459                 :       12868 :       DoPassC ();
     460                 :       12850 :       M2Error_FlushWarnings ();
     461                 :       12850 :       M2Error_FlushErrors ();
     462                 :       12796 :       M2Quiet_qprintf0 ((const char *) "Pass 3: quadruple generation\\n", 30);
     463                 :       12796 :       M2LexBuf_ResetForNewPass ();
     464                 :       12796 :       M2Error_ResetErrorScope ();
     465                 :       12796 :       DoPass3 ();
     466                 :       12700 :       M2Error_FlushWarnings ();
     467                 :       12700 :       M2Error_FlushErrors ();
     468                 :       12454 :       M2Quiet_qprintf0 ((const char *) "Pass 4: gcc tree generation\\n", 29);
     469                 :       12454 :       M2Code_Code ();
     470                 :       12328 :       M2Error_FlushWarnings ();
     471                 :       12328 :       M2Error_FlushErrors ();
     472                 :             :     }
     473                 :       12143 : }
     474                 :             : 
     475                 :             : 
     476                 :             : /*
     477                 :             :    ExamineHeader - examines up until the ';', '[' or eof and determines if the source file
     478                 :             :                    is a program, implementation/definition module.
     479                 :             : */
     480                 :             : 
     481                 :       12962 : static void ExamineHeader (void * *name, bool *isdefimp, bool *module)
     482                 :             : {
     483                 :             :   /* Stop if we see one of eof ';' '['.  */
     484                 :       25918 :   while (((M2LexBuf_currenttoken != M2Reserved_eoftok) && (M2LexBuf_currenttoken != M2Reserved_semicolontok)) && (M2LexBuf_currenttoken != M2Reserved_lsbratok))
     485                 :             :     {
     486                 :       12956 :       if ((*name) == NULL)
     487                 :             :         {
     488                 :       12956 :           if ((M2LexBuf_currenttoken == M2Reserved_implementationtok) || (M2LexBuf_currenttoken == M2Reserved_definitiontok))
     489                 :             :             {
     490                 :        2548 :               (*isdefimp) = true;
     491                 :        2548 :               M2LexBuf_GetToken ();
     492                 :             :             }
     493                 :       12956 :           if (M2LexBuf_currenttoken == M2Reserved_moduletok)
     494                 :             :             {
     495                 :       12956 :               (*module) = true;
     496                 :       12956 :               M2LexBuf_GetToken ();
     497                 :       12956 :               if (M2LexBuf_currenttoken == M2Reserved_identtok)
     498                 :             :                 {
     499                 :       12956 :                   (*name) = M2LexBuf_currentstring;
     500                 :             :                 }
     501                 :             :             }
     502                 :             :         }
     503                 :       12956 :       M2LexBuf_GetToken ();
     504                 :             :     }
     505                 :       12962 : }
     506                 :             : 
     507                 :             : 
     508                 :             : /*
     509                 :             :    ExamineCompilationUnit - opens the source file to obtain the module name and kind of module.
     510                 :             : */
     511                 :             : 
     512                 :       12962 : static unsigned int ExamineCompilationUnit (void)
     513                 :             : {
     514                 :       12962 :   DynamicStrings_String Message;
     515                 :       12962 :   void * name;
     516                 :       12962 :   bool module;
     517                 :       12962 :   bool isdefimp;
     518                 :             : 
     519                 :       12962 :   name = NULL;
     520                 :       12962 :   isdefimp = false;  /* default to program module  */
     521                 :       12962 :   module = false;  /* Seen module keyword?  */
     522                 :       12962 :   ExamineHeader (&name, &isdefimp, &module);  /* Seen module keyword?  */
     523                 :       12962 :   if (name == NULL)
     524                 :             :     {
     525                 :           6 :       if (module)
     526                 :             :         {
     527                 :           0 :           Message = M2MetaError_MetaString0 (DynamicStrings_InitString ((const char *) "no {%kMODULE} keyword seen", 26));
     528                 :             :         }
     529                 :             :       else
     530                 :             :         {
     531                 :           6 :           Message = M2MetaError_MetaString0 (DynamicStrings_InitString ((const char *) "no module ident seen", 20));
     532                 :             :         }
     533                 :           6 :       m2flex_M2Error (DynamicStrings_string (Message));
     534                 :           6 :       libc_exit (1);
     535                 :             :     }
     536                 :             :   else
     537                 :             :     {
     538                 :             :       /* The token used is will be overwritten when P0 is underway.
     539                 :             :          At this point we are determining the module kind and the tokens
     540                 :             :          read will be discarded (see ReInitialize below).  */
     541                 :       12956 :       if (isdefimp)
     542                 :             :         {
     543                 :        2548 :           return M2Batch_MakeImplementationSource (M2LexBuf_BuiltinTokenNo, NameKey_makekey (name));
     544                 :             :         }
     545                 :             :       else
     546                 :             :         {
     547                 :       10408 :           return M2Batch_MakeProgramSource (M2LexBuf_BuiltinTokenNo, NameKey_makekey (name));
     548                 :             :         }
     549                 :             :     }
     550                 :             :   ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2Comp.def", 20, 1);
     551                 :             :   __builtin_unreachable ();
     552                 :             : }
     553                 :             : 
     554                 :             : 
     555                 :             : /*
     556                 :             :    PeepInto - peeps into source, s, and initializes a definition/implementation or
     557                 :             :               program module accordingly.
     558                 :             : */
     559                 :             : 
     560                 :       12963 : static void PeepInto (DynamicStrings_String s)
     561                 :             : {
     562                 :       12963 :   unsigned int mainModule;
     563                 :             : 
     564                 :       12963 :   if (M2LexBuf_OpenSource (s))
     565                 :             :     {
     566                 :       12962 :       mainModule = ExamineCompilationUnit ();
     567                 :       12956 :       if (mainModule != SymbolTable_NulSym)
     568                 :             :         {
     569                 :       12956 :           SymbolTable_SetMainModule (mainModule);
     570                 :             :         }
     571                 :       12956 :       M2LexBuf_CloseSource ();
     572                 :       12956 :       M2LexBuf_ReInitialize ();
     573                 :             :     }
     574                 :             :   else
     575                 :             :     {
     576                 :           1 :       M2Printf_fprintf1 (FIO_StdErr, (const char *) "failed to open %s\\n", 19, (const unsigned char *) &s, (sizeof (s)-1));
     577                 :           1 :       libc_exit (1);
     578                 :             :     }
     579                 :       12956 : }
     580                 :             : 
     581                 :             : 
     582                 :             : /*
     583                 :             :    qprintLibName - print the libname.
     584                 :             : */
     585                 :             : 
     586                 :      166843 : static void qprintLibName (DynamicStrings_String LibName)
     587                 :             : {
     588                 :      166843 :   if ((LibName != NULL) && (! (DynamicStrings_EqualArray (LibName, (const char *) "", 0))))
     589                 :             :     {
     590                 :      150792 :       M2Quiet_qprintf1 ((const char *) " [%s]", 5, (const unsigned char *) &LibName, (sizeof (LibName)-1));
     591                 :             :     }
     592                 :      166843 : }
     593                 :             : 
     594                 :             : 
     595                 :             : /*
     596                 :             :    CreateFileStem - create a stem using the template LibName_ModuleName.
     597                 :             : */
     598                 :             : 
     599                 :      153915 : static DynamicStrings_String CreateFileStem (DynamicStrings_String SymName, DynamicStrings_String LibName)
     600                 :             : {
     601                 :      153915 :   if ((DynamicStrings_Length (LibName)) > 0)
     602                 :             :     {
     603                 :      150204 :       return DynamicStrings_ConCat (DynamicStrings_Dup (LibName), DynamicStrings_ConCat (DynamicStrings_InitStringChar ('_'), SymName));
     604                 :             :     }
     605                 :             :   else
     606                 :             :     {
     607                 :             :       return SymName;
     608                 :             :     }
     609                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     610                 :             :   __builtin_unreachable ();
     611                 :             : }
     612                 :             : 
     613                 :           0 : static DynamicStrings_String BaseName (DynamicStrings_String Path, bool CutExt)
     614                 :             : {
     615                 :           0 :   int ext;
     616                 :           0 :   int basename;
     617                 :             : 
     618                 :             :   /* 
     619                 :             :    Return basename of path.  CutExt determines whether the .extension
     620                 :             :    should be removed.
     621                 :             :   */
     622                 :           0 :   basename = DynamicStrings_RIndex (Path, '/', 0);
     623                 :           0 :   if (basename == -1)
     624                 :             :     {
     625                 :             :       basename = 0;
     626                 :             :     }
     627                 :             :   else
     628                 :             :     {
     629                 :           0 :       basename = basename+1;
     630                 :             :     }
     631                 :           0 :   if (CutExt)
     632                 :             :     {
     633                 :             :       /* avoid dangling else.  */
     634                 :           0 :       ext = DynamicStrings_RIndex (Path, '.', 0);
     635                 :           0 :       if (ext == -1)
     636                 :             :         {
     637                 :           0 :           ext = 0;
     638                 :             :         }
     639                 :             :     }
     640                 :             :   else
     641                 :             :     {
     642                 :             :       ext = 0;
     643                 :             :     }
     644                 :           0 :   return DynamicStrings_Slice (Path, basename, ext);
     645                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     646                 :             :   __builtin_unreachable ();
     647                 :             : }
     648                 :             : 
     649                 :             : 
     650                 :             : /*
     651                 :             :    IsLibrary - return TRUE if line contains a library module.
     652                 :             : */
     653                 :             : 
     654                 :           0 : static bool IsLibrary (DynamicStrings_String line)
     655                 :             : {
     656                 :           0 :   DynamicStrings_String moduleName;
     657                 :           0 :   DynamicStrings_String libname;
     658                 :           0 :   DynamicStrings_String filename;
     659                 :           0 :   bool result;
     660                 :             : 
     661                 :           0 :   result = false;
     662                 :           0 :   moduleName = BaseName (line, true);
     663                 :           0 :   filename = static_cast<DynamicStrings_String> (NULL);
     664                 :           0 :   libname = static_cast<DynamicStrings_String> (NULL);
     665                 :           0 :   if (M2Search_FindSourceDefFile (moduleName, &filename, &libname))
     666                 :             :     {
     667                 :           0 :       moduleName = DynamicStrings_KillString (moduleName);
     668                 :           0 :       if ((DynamicStrings_Length (libname)) > 0)
     669                 :             :         {
     670                 :           0 :           moduleName = BaseName (line, false);
     671                 :           0 :           line = BaseName (line, false);
     672                 :           0 :           result = DynamicStrings_Equal (line, moduleName);
     673                 :           0 :           line = DynamicStrings_KillString (line);
     674                 :             :         }
     675                 :             :     }
     676                 :           0 :   libname = DynamicStrings_KillString (libname);
     677                 :           0 :   filename = DynamicStrings_KillString (filename);
     678                 :           0 :   moduleName = DynamicStrings_KillString (moduleName);
     679                 :           0 :   return result;
     680                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     681                 :             :   __builtin_unreachable ();
     682                 :             : }
     683                 :             : 
     684                 :             : 
     685                 :             : /*
     686                 :             :    IsUnique - return TRUE if line is unique in array content.
     687                 :             : */
     688                 :             : 
     689                 :           0 : static bool IsUnique (Indexing_Index content, DynamicStrings_String line)
     690                 :             : {
     691                 :           0 :   unsigned int high;
     692                 :           0 :   unsigned int i;
     693                 :             : 
     694                 :           0 :   high = Indexing_HighIndice (content);
     695                 :           0 :   i = 1;
     696                 :           0 :   while (i <= high)
     697                 :             :     {
     698                 :           0 :       if (DynamicStrings_Equal (line, static_cast<DynamicStrings_String> (Indexing_GetIndice (content, i))))
     699                 :             :         {
     700                 :             :           return false;
     701                 :             :         }
     702                 :           0 :       i += 1;
     703                 :             :     }
     704                 :             :   return true;
     705                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     706                 :             :   __builtin_unreachable ();
     707                 :             : }
     708                 :             : 
     709                 :             : 
     710                 :             : /*
     711                 :             :    Append - append line to array content.
     712                 :             : */
     713                 :             : 
     714                 :           0 : static void Append (Indexing_Index content, DynamicStrings_String line)
     715                 :             : {
     716                 :           0 :   unsigned int high;
     717                 :             : 
     718                 :           0 :   high = Indexing_HighIndice (content);
     719                 :           0 :   Indexing_PutIndice (content, high+1, reinterpret_cast<void *> (line));
     720                 :           0 : }
     721                 :             : 
     722                 :             : 
     723                 :             : /*
     724                 :             :    MergeDep - if line is unique in array content then append.
     725                 :             :               Check to see (and ignore) if line is a library module and -MM
     726                 :             :               is present.
     727                 :             : */
     728                 :             : 
     729                 :           0 : static void MergeDep (Indexing_Index content, DynamicStrings_String line)
     730                 :             : {
     731                 :           0 :   line = DynamicStrings_RemoveWhitePrefix (line);
     732                 :           0 :   if ((! (DynamicStrings_EqualArray (line, (const char *) "\\", 1))) && ((DynamicStrings_Length (line)) > 0))
     733                 :             :     {
     734                 :             :       /* Ignore if -MM and is a library module.  */
     735                 :           0 :       if (! ((M2Options_GetMM ()) && (IsLibrary (line))))
     736                 :             :         {
     737                 :           0 :           if (IsUnique (content, line))
     738                 :             :             {
     739                 :           0 :               Append (content, line);
     740                 :             :             }
     741                 :             :         }
     742                 :             :     }
     743                 :           0 : }
     744                 :             : 
     745                 :             : 
     746                 :             : /*
     747                 :             :    splitLine - split a line into words separated by spaces
     748                 :             :                and call MergeDep on each word.
     749                 :             : */
     750                 :             : 
     751                 :           0 : static void splitLine (Indexing_Index content, DynamicStrings_String line)
     752                 :             : {
     753                 :           0 :   DynamicStrings_String word;
     754                 :           0 :   int space;
     755                 :             : 
     756                 :           0 :   do {
     757                 :           0 :     line = DynamicStrings_RemoveWhitePrefix (line);
     758                 :           0 :     space = DynamicStrings_Index (line, ' ', 0);
     759                 :           0 :     if (space > 0)
     760                 :             :       {
     761                 :           0 :         word = DynamicStrings_Slice (line, 0, space);
     762                 :           0 :         word = DynamicStrings_RemoveWhitePrefix (word);
     763                 :           0 :         if ((DynamicStrings_Length (word)) > 0)
     764                 :             :           {
     765                 :           0 :             MergeDep (content, word);
     766                 :             :           }
     767                 :           0 :         line = DynamicStrings_Slice (line, space, 0);
     768                 :             :       }
     769                 :           0 :     else if (space < 0)
     770                 :             :       {
     771                 :             :         /* avoid dangling else.  */
     772                 :           0 :         MergeDep (content, line);
     773                 :             :       }
     774                 :           0 :   } while (! (space <= 0));
     775                 :           0 : }
     776                 :             : 
     777                 :             : 
     778                 :             : /*
     779                 :             :    MergeDeps - foreach dependency in ChildDep do
     780                 :             :                   add dependency to ChildDep if not already present.
     781                 :             :                ignore all ChildDep if -MM and libname # "".
     782                 :             : */
     783                 :             : 
     784                 :      153909 : static void MergeDeps (Indexing_Index content, DynamicStrings_String ChildDep, DynamicStrings_String LibName)
     785                 :             : {
     786                 :      153909 :   DynamicStrings_String line;
     787                 :      153909 :   FIO_File in;
     788                 :             : 
     789                 :      153909 :   if ((content != NULL) && (! ((M2Options_GetMM ()) && ((DynamicStrings_Length (LibName)) > 0))))
     790                 :             :     {
     791                 :           0 :       in = SFIO_OpenToRead (ChildDep);
     792                 :           0 :       if (FIO_IsNoError (in))
     793                 :             :         {
     794                 :           0 :           line = SFIO_ReadS (in);  /* Skip over first line containing the module object.  */
     795                 :           0 :           while (! (FIO_EOF (in)))  /* Skip over first line containing the module object.  */
     796                 :             :             {
     797                 :           0 :               line = SFIO_ReadS (in);
     798                 :           0 :               splitLine (content, line);
     799                 :             :             }
     800                 :             :         }
     801                 :           0 :       FIO_Close (in);
     802                 :             :     }
     803                 :      153909 : }
     804                 :             : 
     805                 :             : 
     806                 :             : /*
     807                 :             :    GetRuleTarget - return the rule target which is derived from the -MT arg
     808                 :             :                    or -o arg or filename.mod.
     809                 :             : */
     810                 :             : 
     811                 :           0 : static DynamicStrings_String GetRuleTarget (DynamicStrings_String filename)
     812                 :             : {
     813                 :           0 :   if ((M2Options_GetDepTarget ()) != NULL)
     814                 :             :     {
     815                 :           0 :       return DynamicStrings_InitStringCharStar (M2Options_GetDepTarget ());
     816                 :             :     }
     817                 :           0 :   else if ((M2Options_GetMF ()) != NULL)
     818                 :             :     {
     819                 :             :       /* avoid dangling else.  */
     820                 :           0 :       return DynamicStrings_InitStringCharStar (M2Options_GetMF ());
     821                 :             :     }
     822                 :             :   else
     823                 :             :     {
     824                 :             :       /* avoid dangling else.  */
     825                 :           0 :       return DynamicStrings_ConCat (BaseName (filename, true), DynamicStrings_InitString ((const char *) ".o", 2));
     826                 :             :     }
     827                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     828                 :             :   __builtin_unreachable ();
     829                 :             : }
     830                 :             : 
     831                 :             : 
     832                 :             : /*
     833                 :             :    ReadDepContents - reads the contents of file dep into a dynamic array
     834                 :             :                      and return the array.  The file will be split into words
     835                 :             :                      and each word stored as an entry in the array.
     836                 :             : */
     837                 :             : 
     838                 :       12963 : static Indexing_Index ReadDepContents (DynamicStrings_String filename, DynamicStrings_String dep)
     839                 :             : {
     840                 :       12963 :   Indexing_Index content;
     841                 :       12963 :   DynamicStrings_String line;
     842                 :       12963 :   FIO_File in;
     843                 :             : 
     844                 :       12963 :   content = static_cast<Indexing_Index> (NULL);
     845                 :       12963 :   if ((M2Options_GetM ()) || (M2Options_GetMM ()))
     846                 :             :     {
     847                 :           0 :       in = SFIO_OpenToRead (dep);
     848                 :             :       /* The file might not be created (if -MD or -MMD is used as these options
     849                 :             :          operate without preprocessing) in which case we create an dynamic
     850                 :             :          array with the source filename and target.  */
     851                 :           0 :       content = Indexing_InitIndex (1);
     852                 :           0 :       if (((M2Options_GetMD ()) || (M2Options_GetMMD ())) || (! (FIO_IsNoError (in))))
     853                 :             :         {
     854                 :             :           /* No preprocessing done therefore create first two lines using
     855                 :             :             target and source.  */
     856                 :           0 :           Indexing_PutIndice (content, 1, reinterpret_cast<void *> (DynamicStrings_ConCatChar (GetRuleTarget (filename), ':')));
     857                 :           0 :           Indexing_PutIndice (content, 2, reinterpret_cast<void *> (DynamicStrings_Dup (filename)));
     858                 :             :         }
     859                 :             :       else
     860                 :             :         {
     861                 :             :           /* Preprocessing (using cc1) has created one for us, so we read it.  */
     862                 :           0 :           while (! (FIO_EOF (in)))
     863                 :             :             {
     864                 :           0 :               line = SFIO_ReadS (in);
     865                 :           0 :               splitLine (content, line);
     866                 :             :             }
     867                 :             :         }
     868                 :           0 :       FIO_Close (in);
     869                 :             :     }
     870                 :       12963 :   return content;
     871                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     872                 :             :   __builtin_unreachable ();
     873                 :             : }
     874                 :             : 
     875                 :             : 
     876                 :             : /*
     877                 :             :    WriteDep - write the dependencies and target to file out.
     878                 :             : */
     879                 :             : 
     880                 :           0 : static void WriteDep (DynamicStrings_String dep, Indexing_Index contents, FIO_File out)
     881                 :             : {
     882                 :           0 :   unsigned int i;
     883                 :           0 :   unsigned int h;
     884                 :           0 :   DynamicStrings_String line;
     885                 :             : 
     886                 :           0 :   i = 1;
     887                 :           0 :   h = Indexing_HighIndice (contents);
     888                 :           0 :   while (i <= h)
     889                 :             :     {
     890                 :           0 :       line = static_cast<DynamicStrings_String> (Indexing_GetIndice (contents, i));
     891                 :           0 :       line = DynamicStrings_RemoveWhitePrefix (line);
     892                 :           0 :       if ((DynamicStrings_Length (line)) > 0)
     893                 :             :         {
     894                 :           0 :           if (i == 1)
     895                 :             :             {
     896                 :             :               /* avoid dangling else.  */
     897                 :             :               /* First line is always the target.  */
     898                 :           0 :               if ((M2Options_GetDepTarget ()) != NULL)
     899                 :             :                 {
     900                 :           0 :                   line = DynamicStrings_ConCatChar (DynamicStrings_InitStringCharStar (M2Options_GetDepTarget ()), ':');
     901                 :             :                 }
     902                 :             :             }
     903                 :           0 :           else if (i > 1)
     904                 :             :             {
     905                 :             :               /* avoid dangling else.  */
     906                 :           0 :               FIO_WriteChar (out, ' ');
     907                 :             :             }
     908                 :           0 :           line = SFIO_WriteS (out, line);
     909                 :           0 :           if (i < h)
     910                 :             :             {
     911                 :           0 :               FIO_WriteChar (out, ' ');
     912                 :           0 :               FIO_WriteChar (out, '\\');
     913                 :             :             }
     914                 :           0 :           FIO_WriteLine (out);
     915                 :             :         }
     916                 :           0 :       i += 1;
     917                 :             :     }
     918                 :           0 : }
     919                 :             : 
     920                 :             : 
     921                 :             : /*
     922                 :             :    WritePhonyDep - write the dependencies and target to file out.
     923                 :             : */
     924                 :             : 
     925                 :           0 : static void WritePhonyDep (DynamicStrings_String dep, Indexing_Index contents, FIO_File out)
     926                 :             : {
     927                 :           0 :   unsigned int i;
     928                 :           0 :   unsigned int h;
     929                 :           0 :   DynamicStrings_String line;
     930                 :             : 
     931                 :             :   /* The first line is always the target and the second line is always
     932                 :             :       the top level source file.  */
     933                 :           0 :   i = 3;
     934                 :           0 :   h = Indexing_HighIndice (contents);
     935                 :           0 :   while (i <= h)
     936                 :             :     {
     937                 :           0 :       line = static_cast<DynamicStrings_String> (Indexing_GetIndice (contents, i));
     938                 :           0 :       line = DynamicStrings_RemoveWhitePrefix (line);
     939                 :           0 :       if ((DynamicStrings_Length (line)) > 0)
     940                 :             :         {
     941                 :           0 :           line = SFIO_WriteS (out, line);
     942                 :           0 :           FIO_WriteChar (out, ':');
     943                 :           0 :           FIO_WriteLine (out);
     944                 :             :         }
     945                 :           0 :       i += 1;
     946                 :             :     }
     947                 :           0 : }
     948                 :             : 
     949                 :             : 
     950                 :             : /*
     951                 :             :    WriteDepContents - write the dynamic array to filename dep (or StdOut) if
     952                 :             :                       the GetMF file is NIL.
     953                 :             : */
     954                 :             : 
     955                 :           0 : static void WriteDepContents (DynamicStrings_String dep, Indexing_Index contents)
     956                 :             : {
     957                 :           0 :   FIO_File out;
     958                 :             : 
     959                 :           0 :   if ((contents != NULL) && ((M2Options_GetM ()) || (M2Options_GetMM ())))
     960                 :             :     {
     961                 :           0 :       if ((M2Options_GetMF ()) == NULL)
     962                 :             :         {
     963                 :           0 :           out = FIO_StdOut;
     964                 :           0 :           dep = M2Preprocess_OnExitDelete (dep);
     965                 :             :         }
     966                 :             :       else
     967                 :             :         {
     968                 :           0 :           out = SFIO_OpenToWrite (dep);
     969                 :             :         }
     970                 :           0 :       if (FIO_IsNoError (out))
     971                 :             :         {
     972                 :           0 :           WriteDep (dep, contents, out);
     973                 :           0 :           if (M2Options_GetMP ())
     974                 :             :             {
     975                 :           0 :               WritePhonyDep (dep, contents, out);
     976                 :             :             }
     977                 :             :         }
     978                 :           0 :       if ((M2Options_GetMF ()) == NULL)
     979                 :             :         {
     980                 :           0 :           FIO_FlushOutErr ();
     981                 :             :         }
     982                 :             :       else
     983                 :             :         {
     984                 :           0 :           FIO_Close (out);
     985                 :             :         }
     986                 :           0 :       contents = Indexing_KillIndex (contents);
     987                 :             :     }
     988                 :           0 : }
     989                 :             : 
     990                 :             : 
     991                 :             : /*
     992                 :             :    CreateDepFilename - return a dependency filename associated with filename or use GetMF.
     993                 :             : */
     994                 :             : 
     995                 :       12963 : static DynamicStrings_String CreateDepFilename (DynamicStrings_String filename)
     996                 :             : {
     997                 :       12963 :   DynamicStrings_String depfile;
     998                 :             : 
     999                 :       12963 :   if ((M2Options_GetMF ()) == NULL)
    1000                 :             :     {
    1001                 :       12963 :       depfile = M2Preprocess_MakeSaveTempsFileNameExt (filename, DynamicStrings_InitString ((const char *) ".d", 2));
    1002                 :       12963 :       return M2Preprocess_OnExitDelete (depfile);
    1003                 :             :     }
    1004                 :             :   else
    1005                 :             :     {
    1006                 :           0 :       return DynamicStrings_InitStringCharStar (M2Options_GetMF ());
    1007                 :             :     }
    1008                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
    1009                 :             :   __builtin_unreachable ();
    1010                 :             : }
    1011                 :             : 
    1012                 :             : 
    1013                 :             : /*
    1014                 :             :    Pass0CheckDef -
    1015                 :             : */
    1016                 :             : 
    1017                 :      117829 : static bool Pass0CheckDef (unsigned int sym)
    1018                 :             : {
    1019                 :      117829 :   DynamicStrings_String ChildDep;
    1020                 :      117829 :   DynamicStrings_String SymName;
    1021                 :      117829 :   DynamicStrings_String FileName;
    1022                 :      117829 :   DynamicStrings_String LibName;
    1023                 :             : 
    1024                 :      117829 :   LibName = static_cast<DynamicStrings_String> (NULL);
    1025                 :      117829 :   FileName = static_cast<DynamicStrings_String> (NULL);
    1026                 :      117829 :   SymName = DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (SymbolTable_GetSymName (sym)));
    1027                 :      117829 :   if (SymbolTable_IsDefImp (sym))
    1028                 :             :     {
    1029                 :      107421 :       if (M2Search_FindSourceDefFile (SymName, &FileName, &LibName))
    1030                 :             :         {
    1031                 :      107411 :           ModuleType = M2Comp_Definition;
    1032                 :      107411 :           ChildDep = M2Preprocess_MakeSaveTempsFileNameExt (CreateFileStem (SymName, LibName), DynamicStrings_InitString ((const char *) ".def.d", 6));
    1033                 :      107411 :           if (M2LexBuf_OpenSource (M2Batch_AssociateDefinition (M2Preprocess_PreprocessModule (FileName, false, true, ChildDep), sym)))
    1034                 :             :             {
    1035                 :      107411 :               if (! (P0SyntaxCheck_CompilationUnit ()))
    1036                 :             :                 {
    1037                 :           6 :                   M2Error_WriteFormat0 ((const char *) "compilation failed", 18);
    1038                 :           6 :                   M2LexBuf_CloseSource ();
    1039                 :           6 :                   SymName = DynamicStrings_KillString (SymName);
    1040                 :           6 :                   FileName = DynamicStrings_KillString (FileName);
    1041                 :           6 :                   LibName = DynamicStrings_KillString (LibName);
    1042                 :           6 :                   return false;
    1043                 :             :                 }
    1044                 :      107405 :               M2Quiet_qprintf2 ((const char *) "   Module %-20s : %s", 20, (const unsigned char *) &SymName, (sizeof (SymName)-1), (const unsigned char *) &FileName, (sizeof (FileName)-1));
    1045                 :      107405 :               qprintLibName (LibName);
    1046                 :      107405 :               SymbolTable_PutLibName (sym, NameKey_makekey (DynamicStrings_string (LibName)));
    1047                 :      107405 :               if (SymbolTable_IsDefinitionForC (sym))
    1048                 :             :                 {
    1049                 :        7388 :                   M2Quiet_qprintf0 ((const char *) " (for C)", 8);
    1050                 :             :                 }
    1051                 :      107405 :               if (SymbolTable_IsDefLink (sym))
    1052                 :             :                 {
    1053                 :       49656 :                   M2Quiet_qprintf0 ((const char *) " (linking)", 10);
    1054                 :             :                 }
    1055                 :      107405 :               M2Quiet_qprintf0 ((const char *) "\\n", 2);
    1056                 :      107405 :               M2LexBuf_CloseSource ();
    1057                 :      107405 :               MergeDeps (DepContent, ChildDep, LibName);
    1058                 :             :             }
    1059                 :             :           else
    1060                 :             :             {
    1061                 :             :               /* Unrecoverable error.  */
    1062                 :           0 :               M2MetaError_MetaErrorString1 (FormatStrings_Sprintf1 (DynamicStrings_InitString ((const char *) "file {%%1EUAF%s} containing module {%%1a} cannot be found", 57), (const unsigned char *) &FileName, (sizeof (FileName)-1)), sym);
    1063                 :             :             }
    1064                 :             :         }
    1065                 :             :       else
    1066                 :             :         {
    1067                 :             :           /* Unrecoverable error.  */
    1068                 :          10 :           M2MetaError_MetaError1 ((const char *) "the file containing the definition module {%1EMAa} cannot be found", 66, sym);
    1069                 :             :         }
    1070                 :      107405 :       ModuleType = M2Comp_Implementation;
    1071                 :             :     }
    1072                 :             :   else
    1073                 :             :     {
    1074                 :       10408 :       ModuleType = M2Comp_Program;
    1075                 :             :     }
    1076                 :      117813 :   SymName = DynamicStrings_KillString (SymName);
    1077                 :      117813 :   FileName = DynamicStrings_KillString (FileName);
    1078                 :      117813 :   LibName = DynamicStrings_KillString (LibName);
    1079                 :      117813 :   return true;
    1080                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
    1081                 :             :   __builtin_unreachable ();
    1082                 :             : }
    1083                 :             : 
    1084                 :             : 
    1085                 :             : /*
    1086                 :             :    Pass0CheckMod -
    1087                 :             : */
    1088                 :             : 
    1089                 :      117813 : static bool Pass0CheckMod (unsigned int sym, DynamicStrings_String PPSource)
    1090                 :             : {
    1091                 :      117813 :   unsigned int Main;
    1092                 :      117813 :   DynamicStrings_String ChildDep;
    1093                 :      117813 :   DynamicStrings_String SymName;
    1094                 :      117813 :   DynamicStrings_String FileName;
    1095                 :      117813 :   DynamicStrings_String LibName;
    1096                 :             : 
    1097                 :      117813 :   SymName = DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (SymbolTable_GetSymName (sym)));
    1098                 :      117813 :   FileName = static_cast<DynamicStrings_String> (NULL);
    1099                 :      117813 :   LibName = static_cast<DynamicStrings_String> (NULL);
    1100                 :      117813 :   Main = SymbolTable_GetMainModule ();
    1101                 :      117813 :   if ((Main == sym) || (NeedToParseImplementation (sym)))
    1102                 :             :     {
    1103                 :             :       /* avoid dangling else.  */
    1104                 :             :       /* Only need to read implementation module if hidden types are
    1105                 :             :          declared or it is the main module.  */
    1106                 :       15192 :       if (Main == sym)
    1107                 :             :         {
    1108                 :       12952 :           FileName = DynamicStrings_Dup (PPSource);
    1109                 :       12952 :           LibName = DynamicStrings_InitStringCharStar (M2Options_GetM2Prefix ());
    1110                 :       12952 :           SymbolTable_PutLibName (sym, NameKey_makekey (DynamicStrings_string (LibName)));
    1111                 :             :         }
    1112                 :             :       else
    1113                 :             :         {
    1114                 :        2240 :           if (M2Search_FindSourceModFile (SymName, &FileName, &LibName))
    1115                 :             :             {
    1116                 :        2144 :               ChildDep = M2Preprocess_MakeSaveTempsFileNameExt (CreateFileStem (SymName, LibName), DynamicStrings_InitString ((const char *) ".mod.d", 6));
    1117                 :        2144 :               FileName = M2Preprocess_PreprocessModule (FileName, false, true, ChildDep);
    1118                 :        2144 :               SymbolTable_PutLibName (sym, NameKey_makekey (DynamicStrings_string (LibName)));
    1119                 :        2144 :               MergeDeps (DepContent, ChildDep, LibName);
    1120                 :             :             }
    1121                 :             :           else
    1122                 :             :             {
    1123                 :          96 :               M2Quiet_qprintf1 ((const char *) "   Module %-20s : implementation source file not found\\n", 56, (const unsigned char *) &SymName, (sizeof (SymName)-1));
    1124                 :             :             }
    1125                 :             :         }
    1126                 :       15192 :       if (FileName != NULL)
    1127                 :             :         {
    1128                 :             :           /* avoid gcc warning by using compound statement even if not strictly necessary.  */
    1129                 :       15096 :           if (M2LexBuf_OpenSource (M2Batch_AssociateModule (DynamicStrings_Dup (FileName), sym)))
    1130                 :             :             {
    1131                 :       15096 :               if (! (P0SyntaxCheck_CompilationUnit ()))
    1132                 :             :                 {
    1133                 :          12 :                   M2Error_WriteFormat0 ((const char *) "compilation failed", 18);
    1134                 :          12 :                   M2LexBuf_CloseSource ();
    1135                 :          12 :                   SymName = DynamicStrings_KillString (SymName);
    1136                 :          12 :                   FileName = DynamicStrings_KillString (FileName);
    1137                 :          12 :                   LibName = DynamicStrings_KillString (LibName);
    1138                 :          12 :                   return false;
    1139                 :             :                 }
    1140                 :       15078 :               M2Quiet_qprintf2 ((const char *) "   Module %-20s : %s", 20, (const unsigned char *) &SymName, (sizeof (SymName)-1), (const unsigned char *) &FileName, (sizeof (FileName)-1));
    1141                 :       15078 :               qprintLibName (LibName);
    1142                 :       15078 :               if (SymbolTable_IsModLink (sym))
    1143                 :             :                 {
    1144                 :          36 :                   M2Quiet_qprintf0 ((const char *) " (linking)", 10);
    1145                 :             :                 }
    1146                 :       15078 :               M2Quiet_qprintf0 ((const char *) "\\n", 2);
    1147                 :       15078 :               M2LexBuf_CloseSource ();
    1148                 :             :             }
    1149                 :             :           else
    1150                 :             :             {
    1151                 :             :               /* It is quite legitimate to implement a module in C (and pretend it was a M2
    1152                 :             :                implementation) providing that it is not the main program module and the
    1153                 :             :                definition module does not declare a hidden type when -fextended-opaque
    1154                 :             :                is used.  */
    1155                 :           0 :               if ((! M2Options_WholeProgram || (sym == Main)) || (SymbolTable_IsHiddenTypeDeclared (sym)))
    1156                 :             :                 {
    1157                 :             :                   /* Unrecoverable error.  */
    1158                 :           0 :                   M2MetaError_MetaErrorString1 (FormatStrings_Sprintf1 (DynamicStrings_InitString ((const char *) "file {%%1EUAF%s} containing module {%%1a} cannot be found", 57), (const unsigned char *) &FileName, (sizeof (FileName)-1)), sym);
    1159                 :             :                 }
    1160                 :             :             }
    1161                 :             :         }
    1162                 :             :     }
    1163                 :      102621 :   else if (M2Options_GenModuleList)
    1164                 :             :     {
    1165                 :             :       /* avoid dangling else.  */
    1166                 :       58758 :       if ((SymbolTable_IsDefImp (sym)) && (! (SymbolTable_IsDefinitionForC (sym))))
    1167                 :             :         {
    1168                 :             :           /* The implementation module is only useful if -fgen-module-list= is
    1169                 :             :             used (to gather all dependencies).  Note that we do not insist
    1170                 :             :             upon finding the implementation module.  */
    1171                 :       54832 :           LibName = static_cast<DynamicStrings_String> (NULL);
    1172                 :       54832 :           if (M2Search_FindSourceModFile (SymName, &FileName, &LibName))
    1173                 :             :             {
    1174                 :       44360 :               SymbolTable_PutLibName (sym, NameKey_makekey (DynamicStrings_string (LibName)));
    1175                 :       44360 :               M2Quiet_qprintf2 ((const char *) "   Module %-20s : %s", 20, (const unsigned char *) &SymName, (sizeof (SymName)-1), (const unsigned char *) &FileName, (sizeof (FileName)-1));
    1176                 :       44360 :               qprintLibName (LibName);
    1177                 :       44360 :               M2Quiet_qprintf0 ((const char *) " (linking)\\n", 12);
    1178                 :       44360 :               ChildDep = M2Preprocess_MakeSaveTempsFileNameExt (CreateFileStem (SymName, LibName), DynamicStrings_InitString ((const char *) ".mod.d", 6));
    1179                 :       44360 :               if (M2LexBuf_OpenSource (M2Batch_AssociateModule (M2Preprocess_PreprocessModule (FileName, false, true, ChildDep), sym)))
    1180                 :             :                 {
    1181                 :       44360 :                   SymbolTable_PutModLink (sym, true);  /* This source is only used to determine link time info.  */
    1182                 :       44360 :                   if (! (P0SyntaxCheck_CompilationUnit ()))  /* This source is only used to determine link time info.  */
    1183                 :             :                     {
    1184                 :           0 :                       M2Error_WriteFormat0 ((const char *) "compilation failed", 18);
    1185                 :           0 :                       M2LexBuf_CloseSource ();
    1186                 :           0 :                       SymName = DynamicStrings_KillString (SymName);
    1187                 :           0 :                       FileName = DynamicStrings_KillString (FileName);
    1188                 :           0 :                       LibName = DynamicStrings_KillString (LibName);
    1189                 :           0 :                       return false;
    1190                 :             :                     }
    1191                 :       44360 :                   M2LexBuf_CloseSource ();
    1192                 :       44360 :                   MergeDeps (DepContent, ChildDep, LibName);
    1193                 :             :                 }
    1194                 :             :             }
    1195                 :             :         }
    1196                 :             :     }
    1197                 :      117795 :   SymName = DynamicStrings_KillString (SymName);
    1198                 :      117795 :   FileName = DynamicStrings_KillString (FileName);
    1199                 :      117795 :   LibName = DynamicStrings_KillString (LibName);
    1200                 :      117795 :   return true;
    1201                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
    1202                 :             :   __builtin_unreachable ();
    1203                 :             : }
    1204                 :             : 
    1205                 :             : 
    1206                 :             : /*
    1207                 :             :    DoPass0 -
    1208                 :             : */
    1209                 :             : 
    1210                 :       12963 : static void DoPass0 (DynamicStrings_String filename)
    1211                 :             : {
    1212                 :       12963 :   unsigned int sym;
    1213                 :       12963 :   unsigned int i;
    1214                 :       12963 :   DynamicStrings_String PPSource;
    1215                 :             : 
    1216                 :       12963 :   P0SymBuild_P0Init ();
    1217                 :       12963 :   M2Pass_SetPassToPass0 ();
    1218                 :             :   /* Maybe preprocess the main file.  */
    1219                 :       12963 :   DepOutput = CreateDepFilename (filename);
    1220                 :       12963 :   PPSource = M2Preprocess_PreprocessModule (filename, true, false, DepOutput);
    1221                 :       12963 :   DepContent = ReadDepContents (filename, DepOutput);
    1222                 :       12963 :   PeepInto (PPSource);
    1223                 :       12956 :   i = 1;
    1224                 :       12956 :   sym = M2Batch_GetModuleNo (i);
    1225                 :       12956 :   M2Quiet_qprintf1 ((const char *) "Compiling: %s\\n", 15, (const unsigned char *) &PPSource, (sizeof (PPSource)-1));
    1226                 :       12956 :   if (Debugging)
    1227                 :             :     {
    1228                 :             :       PathName_DumpPathName ((const char *) "DoPass0", 7);
    1229                 :             :     }
    1230                 :       12956 :   if (M2Options_Verbose)
    1231                 :             :     {
    1232                 :           0 :       M2Printf_fprintf1 (FIO_StdOut, (const char *) "Compiling: %s\\n", 15, (const unsigned char *) &PPSource, (sizeof (PPSource)-1));
    1233                 :             :     }
    1234                 :       12956 :   M2Quiet_qprintf0 ((const char *) "Pass 0: lexical analysis, parsing, modules and associated filenames\\n", 69);
    1235                 :      143707 :   while (sym != SymbolTable_NulSym)
    1236                 :             :     {
    1237                 :      117829 :       if (! (Pass0CheckDef (sym)))
    1238                 :             :         {
    1239                 :          18 :           return ;
    1240                 :             :         }
    1241                 :      117813 :       if (! (Pass0CheckMod (sym, PPSource)))
    1242                 :             :         {
    1243                 :             :           return ;
    1244                 :             :         }
    1245                 :      117795 :       i += 1;
    1246                 :      117795 :       sym = M2Batch_GetModuleNo (i);
    1247                 :             :     }
    1248                 :       12922 :   M2Pass_SetPassToNoPass ();
    1249                 :             : }
    1250                 :             : 
    1251                 :             : 
    1252                 :             : /*
    1253                 :             :    DoPass1 - parses the sources of all modules necessary to compile
    1254                 :             :              the required module, Main.
    1255                 :             : */
    1256                 :             : 
    1257                 :       12916 : static void DoPass1 (void)
    1258                 :             : {
    1259                 :       12916 :   NameKey_Name name;
    1260                 :       12916 :   unsigned int Sym;
    1261                 :       12916 :   unsigned int i;
    1262                 :       12916 :   DynamicStrings_String FileName;
    1263                 :             : 
    1264                 :       12916 :   P0SymBuild_P1Init ();
    1265                 :       12916 :   M2Pass_SetPassToPass1 ();
    1266                 :       12916 :   i = 1;
    1267                 :       12916 :   Sym = M2Batch_GetModuleNo (i);
    1268                 :      143423 :   while (Sym != SymbolTable_NulSym)
    1269                 :             :     {
    1270                 :      117597 :       FileName = M2Batch_GetDefinitionModuleFile (Sym);
    1271                 :      117597 :       if (FileName != NULL)
    1272                 :             :         {
    1273                 :      107213 :           if (Debugging)
    1274                 :             :             {
    1275                 :             :               name = SymbolTable_GetSymName (Sym);
    1276                 :             :               M2Quiet_qprintf1 ((const char *) "   Module %a\\n", 14, (const unsigned char *) &name, (sizeof (name)-1));
    1277                 :             :             }
    1278                 :      107213 :           if (M2LexBuf_OpenSource (FileName))
    1279                 :             :             {
    1280                 :      107213 :               ModuleType = M2Comp_Definition;
    1281                 :      107213 :               if (! (P1Build_CompilationUnit ()))
    1282                 :             :                 {
    1283                 :           0 :                   M2MetaError_MetaError0 ((const char *) "compilation failed", 18);
    1284                 :           0 :                   M2LexBuf_CloseSource ();
    1285                 :           0 :                   return ;
    1286                 :             :                 }
    1287                 :      107213 :               M2LexBuf_CloseSource ();
    1288                 :             :             }
    1289                 :             :           else
    1290                 :             :             {
    1291                 :           0 :               M2Printf_fprintf1 (FIO_StdErr, (const char *) "failed to open %s\\n", 19, (const unsigned char *) &FileName, (sizeof (FileName)-1));
    1292                 :           0 :               libc_exit (1);
    1293                 :             :             }
    1294                 :      107213 :           ModuleType = M2Comp_Implementation;
    1295                 :             :         }
    1296                 :             :       else
    1297                 :             :         {
    1298                 :       10384 :           ModuleType = M2Comp_Program;
    1299                 :             :         }
    1300                 :      117597 :       FileName = M2Batch_GetModuleFile (Sym);
    1301                 :      117597 :       if (FileName != NULL)
    1302                 :             :         {
    1303                 :       59378 :           if (Debugging)
    1304                 :             :             {
    1305                 :             :               name = SymbolTable_GetSymName (Sym);
    1306                 :             :               M2Quiet_qprintf1 ((const char *) "   Module %a\\n", 14, (const unsigned char *) &name, (sizeof (name)-1));
    1307                 :             :             }
    1308                 :       59378 :           if (M2LexBuf_OpenSource (FileName))
    1309                 :             :             {
    1310                 :       59378 :               if (! (P1Build_CompilationUnit ()))
    1311                 :             :                 {
    1312                 :           0 :                   M2MetaError_MetaError0 ((const char *) "compilation failed", 18);
    1313                 :           0 :                   M2LexBuf_CloseSource ();
    1314                 :           0 :                   return ;
    1315                 :             :                 }
    1316                 :       59372 :               M2LexBuf_CloseSource ();
    1317                 :             :             }
    1318                 :             :           else
    1319                 :             :             {
    1320                 :           0 :               M2Printf_fprintf1 (FIO_StdErr, (const char *) "failed to open %s\\n", 19, (const unsigned char *) &FileName, (sizeof (FileName)-1));
    1321                 :           0 :               libc_exit (1);
    1322                 :             :             }
    1323                 :             :         }
    1324                 :      117591 :       i += 1;
    1325                 :      117591 :       Sym = M2Batch_GetModuleNo (i);
    1326                 :             :     }
    1327                 :       12910 :   M2Pass_SetPassToNoPass ();
    1328                 :             : }
    1329                 :             : 
    1330                 :             : 
    1331                 :             : /*
    1332                 :             :    DoPass2 - parses the sources of all modules necessary to compile
    1333                 :             :              the required module, Main.
    1334                 :             : */
    1335                 :             : 
    1336                 :       12904 : static void DoPass2 (void)
    1337                 :             : {
    1338                 :       12904 :   NameKey_Name name;
    1339                 :       12904 :   unsigned int Sym;
    1340                 :       12904 :   unsigned int i;
    1341                 :       12904 :   DynamicStrings_String FileName;
    1342                 :             : 
    1343                 :       12904 :   M2Pass_SetPassToPass2 ();
    1344                 :       12904 :   i = 1;
    1345                 :       12904 :   Sym = M2Batch_GetModuleNo (i);
    1346                 :      143291 :   while (Sym != SymbolTable_NulSym)
    1347                 :             :     {
    1348                 :      117495 :       FileName = M2Batch_GetDefinitionModuleFile (Sym);
    1349                 :      117495 :       if (FileName != NULL)
    1350                 :             :         {
    1351                 :      107123 :           if (Debugging)
    1352                 :             :             {
    1353                 :             :               name = SymbolTable_GetSymName (Sym);
    1354                 :             :               M2Quiet_qprintf1 ((const char *) "   Module %a\\n", 14, (const unsigned char *) &name, (sizeof (name)-1));
    1355                 :             :             }
    1356                 :      107123 :           if (M2LexBuf_OpenSource (FileName))
    1357                 :             :             {
    1358                 :      107123 :               ModuleType = M2Comp_Definition;
    1359                 :      107123 :               if (! (P2Build_CompilationUnit ()))
    1360                 :             :                 {
    1361                 :           0 :                   M2MetaError_MetaError0 ((const char *) "compilation failed", 18);
    1362                 :           0 :                   M2LexBuf_CloseSource ();
    1363                 :           0 :                   return ;
    1364                 :             :                 }
    1365                 :      107123 :               M2LexBuf_CloseSource ();
    1366                 :             :             }
    1367                 :             :           else
    1368                 :             :             {
    1369                 :           0 :               M2Printf_fprintf1 (FIO_StdErr, (const char *) "failed to open %s\\n", 19, (const unsigned char *) &FileName, (sizeof (FileName)-1));
    1370                 :           0 :               libc_exit (1);
    1371                 :             :             }
    1372                 :      107123 :           ModuleType = M2Comp_Implementation;
    1373                 :             :         }
    1374                 :             :       else
    1375                 :             :         {
    1376                 :       10372 :           ModuleType = M2Comp_Program;
    1377                 :             :         }
    1378                 :      117495 :       FileName = M2Batch_GetModuleFile (Sym);
    1379                 :      117495 :       if (FileName != NULL)
    1380                 :             :         {
    1381                 :       59306 :           if (Debugging)
    1382                 :             :             {
    1383                 :             :               name = SymbolTable_GetSymName (Sym);
    1384                 :             :               M2Quiet_qprintf1 ((const char *) "   Module %a\\n", 14, (const unsigned char *) &name, (sizeof (name)-1));
    1385                 :             :             }
    1386                 :       59306 :           if (M2LexBuf_OpenSource (FileName))
    1387                 :             :             {
    1388                 :       59306 :               if (! (P2Build_CompilationUnit ()))
    1389                 :             :                 {
    1390                 :           0 :                   M2MetaError_MetaError0 ((const char *) "compilation failed", 18);
    1391                 :           0 :                   M2LexBuf_CloseSource ();
    1392                 :           0 :                   return ;
    1393                 :             :                 }
    1394                 :       59294 :               M2LexBuf_CloseSource ();
    1395                 :             :             }
    1396                 :             :           else
    1397                 :             :             {
    1398                 :           0 :               M2Printf_fprintf1 (FIO_StdErr, (const char *) "failed to open %s\\n", 19, (const unsigned char *) &FileName, (sizeof (FileName)-1));
    1399                 :           0 :               libc_exit (1);
    1400                 :             :             }
    1401                 :             :         }
    1402                 :      117483 :       i += 1;
    1403                 :      117483 :       Sym = M2Batch_GetModuleNo (i);
    1404                 :             :     }
    1405                 :       12892 :   M2Pass_SetPassToNoPass ();
    1406                 :             : }
    1407                 :             : 
    1408                 :             : 
    1409                 :             : /*
    1410                 :             :    DoPassC - parses the sources of all modules necessary to compile
    1411                 :             :              the required module, Main.
    1412                 :             : */
    1413                 :             : 
    1414                 :       12868 : static void DoPassC (void)
    1415                 :             : {
    1416                 :       12868 :   NameKey_Name name;
    1417                 :       12868 :   unsigned int Sym;
    1418                 :       12868 :   unsigned int i;
    1419                 :       12868 :   DynamicStrings_String FileName;
    1420                 :             : 
    1421                 :       12868 :   M2Pass_SetPassToPassC ();
    1422                 :       12868 :   i = 1;
    1423                 :       12868 :   Sym = M2Batch_GetModuleNo (i);
    1424                 :      143063 :   while (Sym != SymbolTable_NulSym)
    1425                 :             :     {
    1426                 :      117339 :       FileName = M2Batch_GetDefinitionModuleFile (Sym);
    1427                 :      117339 :       if (FileName != NULL)
    1428                 :             :         {
    1429                 :      106991 :           if (Debugging)
    1430                 :             :             {
    1431                 :             :               name = SymbolTable_GetSymName (Sym);
    1432                 :             :               M2Quiet_qprintf1 ((const char *) "   Module %a\\n", 14, (const unsigned char *) &name, (sizeof (name)-1));
    1433                 :             :             }
    1434                 :      106991 :           if (M2LexBuf_OpenSource (FileName))
    1435                 :             :             {
    1436                 :      106991 :               ModuleType = M2Comp_Definition;
    1437                 :      106991 :               if (! (PCBuild_CompilationUnit ()))
    1438                 :             :                 {
    1439                 :           0 :                   M2MetaError_MetaError0 ((const char *) "compilation failed", 18);
    1440                 :           0 :                   M2LexBuf_CloseSource ();
    1441                 :           0 :                   return ;
    1442                 :             :                 }
    1443                 :      106991 :               M2LexBuf_CloseSource ();
    1444                 :             :             }
    1445                 :             :           else
    1446                 :             :             {
    1447                 :           0 :               M2Printf_fprintf1 (FIO_StdErr, (const char *) "failed to open %s\\n", 19, (const unsigned char *) &FileName, (sizeof (FileName)-1));
    1448                 :           0 :               libc_exit (1);
    1449                 :             :             }
    1450                 :      106991 :           ModuleType = M2Comp_Implementation;
    1451                 :             :         }
    1452                 :             :       else
    1453                 :             :         {
    1454                 :       10348 :           ModuleType = M2Comp_Program;
    1455                 :             :         }
    1456                 :      117339 :       FileName = M2Batch_GetModuleFile (Sym);
    1457                 :      117339 :       if (FileName != NULL)
    1458                 :             :         {
    1459                 :       59270 :           if (Debugging)
    1460                 :             :             {
    1461                 :             :               name = SymbolTable_GetSymName (Sym);
    1462                 :             :               M2Quiet_qprintf1 ((const char *) "   Module %a\\n", 14, (const unsigned char *) &name, (sizeof (name)-1));
    1463                 :             :             }
    1464                 :       59270 :           if (M2LexBuf_OpenSource (FileName))
    1465                 :             :             {
    1466                 :       59270 :               if (! (PCBuild_CompilationUnit ()))
    1467                 :             :                 {
    1468                 :           0 :                   M2MetaError_MetaError0 ((const char *) "compilation failed", 18);
    1469                 :           0 :                   M2LexBuf_CloseSource ();
    1470                 :           0 :                   return ;
    1471                 :             :                 }
    1472                 :       59258 :               M2LexBuf_CloseSource ();
    1473                 :             :             }
    1474                 :             :           else
    1475                 :             :             {
    1476                 :           0 :               M2Printf_fprintf1 (FIO_StdErr, (const char *) "failed to open %s\\n", 19, (const unsigned char *) &FileName, (sizeof (FileName)-1));
    1477                 :           0 :               libc_exit (1);
    1478                 :             :             }
    1479                 :             :         }
    1480                 :      117327 :       i += 1;
    1481                 :      117327 :       Sym = M2Batch_GetModuleNo (i);
    1482                 :             :     }
    1483                 :       12856 :   PCSymBuild_ResolveConstTypes ();
    1484                 :       12856 :   SymbolTable_ResolveConstructorTypes ();
    1485                 :       12850 :   SymbolTable_SanityCheckConstants ();
    1486                 :       12850 :   M2Pass_SetPassToNoPass ();
    1487                 :             : }
    1488                 :             : 
    1489                 :             : 
    1490                 :             : /*
    1491                 :             :    DoPass3 - parses the sources of all modules necessary to compile
    1492                 :             :              the required module, Main.
    1493                 :             : */
    1494                 :             : 
    1495                 :       12796 : static void DoPass3 (void)
    1496                 :             : {
    1497                 :       12796 :   unsigned int Main;
    1498                 :       12796 :   unsigned int Sym;
    1499                 :       12796 :   unsigned int i;
    1500                 :       12796 :   DynamicStrings_String FileName;
    1501                 :             : 
    1502                 :       12796 :   M2Pass_SetPassToPass3 ();
    1503                 :       12796 :   Main = SymbolTable_GetMainModule ();
    1504                 :       12796 :   i = 1;
    1505                 :       12796 :   Sym = M2Batch_GetModuleNo (i);
    1506                 :      142439 :   while (Sym != SymbolTable_NulSym)
    1507                 :             :     {
    1508                 :      116943 :       FileName = M2Batch_GetDefinitionModuleFile (Sym);
    1509                 :      116943 :       if (FileName != NULL)
    1510                 :             :         {
    1511                 :      106649 :           if (M2LexBuf_OpenSource (FileName))
    1512                 :             :             {
    1513                 :      106649 :               ModuleType = M2Comp_Definition;
    1514                 :      106649 :               if (! (P3Build_CompilationUnit ()))
    1515                 :             :                 {
    1516                 :           0 :                   M2MetaError_MetaError0 ((const char *) "compilation failed", 18);
    1517                 :           0 :                   M2LexBuf_CloseSource ();
    1518                 :           0 :                   return ;
    1519                 :             :                 }
    1520                 :      106649 :               M2LexBuf_CloseSource ();
    1521                 :             :             }
    1522                 :             :           else
    1523                 :             :             {
    1524                 :           0 :               M2Printf_fprintf1 (FIO_StdErr, (const char *) "failed to open %s\\n", 19, (const unsigned char *) &FileName, (sizeof (FileName)-1));
    1525                 :           0 :               libc_exit (1);
    1526                 :             :             }
    1527                 :      106649 :           ModuleType = M2Comp_Implementation;
    1528                 :             :         }
    1529                 :             :       else
    1530                 :             :         {
    1531                 :       10294 :           ModuleType = M2Comp_Program;
    1532                 :             :         }
    1533                 :      116943 :       FileName = M2Batch_GetModuleFile (Sym);
    1534                 :      116943 :       if (FileName != NULL)
    1535                 :             :         {
    1536                 :             :           /* avoid gcc warning by using compound statement even if not strictly necessary.  */
    1537                 :       59198 :           if (M2LexBuf_OpenSource (FileName))
    1538                 :             :             {
    1539                 :       59198 :               if ((Main == Sym) || M2Options_WholeProgram)
    1540                 :             :                 {
    1541                 :             :                   /* avoid dangling else.  */
    1542                 :       13180 :                   if (! (P3Build_CompilationUnit ()))
    1543                 :             :                     {
    1544                 :           0 :                       M2MetaError_MetaError0 ((const char *) "compilation failed", 18);
    1545                 :           0 :                       M2LexBuf_CloseSource ();
    1546                 :           0 :                       return ;
    1547                 :             :                     }
    1548                 :             :                 }
    1549                 :             :               else
    1550                 :             :                 {
    1551                 :             :                   /* 
    1552                 :             :                   not the main module .mod therefore must be implementing
    1553                 :             :                   a hidden type - we dont want to generate any
    1554                 :             :                   StatementSequence quadrupes but we do want to build TYPEs
    1555                 :             :                   and ConstExpressions.
    1556                 :             :   */
    1557                 :       46018 :                   M2Pass_SetPassToNoPass ();
    1558                 :       46018 :                   M2Pass_SetPassToPassHidden ();
    1559                 :       46018 :                   if (! (PHBuild_CompilationUnit ()))
    1560                 :             :                     {
    1561                 :           0 :                       M2MetaError_MetaError0 ((const char *) "compilation failed", 18);
    1562                 :           0 :                       M2LexBuf_CloseSource ();
    1563                 :           0 :                       return ;
    1564                 :             :                     }
    1565                 :       46018 :                   M2Pass_SetPassToNoPass ();
    1566                 :       46018 :                   M2Pass_SetPassToPass3 ();
    1567                 :             :                 }
    1568                 :       59102 :               M2LexBuf_CloseSource ();
    1569                 :             :             }
    1570                 :             :           else
    1571                 :             :             {
    1572                 :           0 :               M2Printf_fprintf1 (FIO_StdErr, (const char *) "failed to open %s\\n", 19, (const unsigned char *) &FileName, (sizeof (FileName)-1));
    1573                 :           0 :               libc_exit (1);
    1574                 :             :             }
    1575                 :             :         }
    1576                 :      116847 :       i += 1;
    1577                 :      116847 :       Sym = M2Batch_GetModuleNo (i);
    1578                 :             :     }
    1579                 :       12700 :   M2Pass_SetPassToNoPass ();
    1580                 :             : }
    1581                 :             : 
    1582                 :             : 
    1583                 :             : /*
    1584                 :             :    compile - compile the filename.
    1585                 :             : */
    1586                 :             : 
    1587                 :       12963 : extern "C" void M2Comp_compile (void * filename)
    1588                 :             : {
    1589                 :       12963 :   DynamicStrings_String f;
    1590                 :             : 
    1591                 :       12963 :   f = DynamicStrings_InitStringCharStar (filename);
    1592                 :       12963 :   Compile (f);
    1593                 :       12143 :   f = DynamicStrings_KillString (f);
    1594                 :       12143 : }
    1595                 :             : 
    1596                 :             : 
    1597                 :             : /*
    1598                 :             :    CompilingDefinitionModule - returns true if the current module being
    1599                 :             :                                compiled is a definition module.
    1600                 :             : */
    1601                 :             : 
    1602                 :    89674677 : extern "C" bool M2Comp_CompilingDefinitionModule (void)
    1603                 :             : {
    1604                 :    89674677 :   return ModuleType == M2Comp_Definition;
    1605                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
    1606                 :             :   __builtin_unreachable ();
    1607                 :             : }
    1608                 :             : 
    1609                 :             : 
    1610                 :             : /*
    1611                 :             :    CompilingImplementationModule - returns true if the current module being
    1612                 :             :                                    compiled is an implementation module.
    1613                 :             : */
    1614                 :             : 
    1615                 :     4525321 : extern "C" bool M2Comp_CompilingImplementationModule (void)
    1616                 :             : {
    1617                 :     4525321 :   return ModuleType == M2Comp_Implementation;
    1618                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
    1619                 :             :   __builtin_unreachable ();
    1620                 :             : }
    1621                 :             : 
    1622                 :             : 
    1623                 :             : /*
    1624                 :             :    CompilingProgramModule - returns true if the current module being
    1625                 :             :                             compiled is a program module.
    1626                 :             : */
    1627                 :             : 
    1628                 :       92863 : extern "C" bool M2Comp_CompilingProgramModule (void)
    1629                 :             : {
    1630                 :       92863 :   return ModuleType == M2Comp_Program;
    1631                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
    1632                 :             :   __builtin_unreachable ();
    1633                 :             : }
    1634                 :             : 
    1635                 :       12963 : extern "C" void _M2_M2Comp_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
    1636                 :             : {
    1637                 :       12963 :   ModuleType = M2Comp_None;
    1638                 :       12963 :   DepContent = static_cast<Indexing_Index> (NULL);
    1639                 :       12963 :   DepOutput = static_cast<DynamicStrings_String> (NULL);
    1640                 :       12963 : }
    1641                 :             : 
    1642                 :           0 : extern "C" void _M2_M2Comp_fini (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
    1643                 :             : {
    1644                 :           0 : }
        

Generated by: LCOV version 2.1-beta

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