LCOV - code coverage report
Current view: top level - /mnt/build/buildbot/bld/build-lcov/gcc/m2/gm2-compiler-boot - M2Search.c (source / functions) Coverage Total Hit
Test: gcc.info Lines: 83.3 % 36 30
Test Date: 2026-02-28 14:20:25 Functions: 87.5 % 8 7
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* do not edit automatically generated by mc from M2Search.  */
       2              : /* M2Search.mod provides a mechanism to search selected directories.
       3              : 
       4              : Copyright (C) 2001-2026 Free Software Foundation, Inc.
       5              : Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
       6              : 
       7              : This file is part of GNU Modula-2.
       8              : 
       9              : GNU Modula-2 is free software; you can redistribute it and/or modify
      10              : it under the terms of the GNU General Public License as published by
      11              : the Free Software Foundation; either version 3, or (at your option)
      12              : any later version.
      13              : 
      14              : GNU Modula-2 is distributed in the hope that it will be useful, but
      15              : WITHOUT ANY WARRANTY; without even the implied warranty of
      16              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17              : General Public License for more details.
      18              : 
      19              : You should have received a copy of the GNU General Public License
      20              : along with GNU Modula-2; see the file COPYING3.  If not see
      21              : <http://www.gnu.org/licenses/>.  */
      22              : 
      23              : #include "config.h"
      24              : #include "system.h"
      25              : #include <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              : #if defined(__cplusplus)
      41              : #   undef NULL
      42              : #   define NULL 0
      43              : #endif
      44              : #define _M2Search_C
      45              : 
      46              : #include "GM2Search.h"
      47              : #   include "GM2FileName.h"
      48              : #   include "GAssertion.h"
      49              : #   include "GPathName.h"
      50              : #   include "GDynamicStrings.h"
      51              : 
      52              : #   define GarbageDebugging false
      53              : #   define DefaultDefExt ".def"
      54              : #   define DefaultModExt ".mod"
      55              : static DynamicStrings_String Def;
      56              : static DynamicStrings_String Mod;
      57              : 
      58              : /*
      59              :    FindSourceFile - attempts to locate the source file FileName.
      60              :                     If a file is found then TRUE is returned otherwise
      61              :                     FALSE is returned.
      62              :                     The parameter FullPath is set indicating the
      63              :                     absolute location of source FileName.
      64              :                     FullPath will be totally overwritten and should
      65              :                     not be initialized by InitString before this function
      66              :                     is called.
      67              :                     FullPath is set to NIL if this function returns FALSE.
      68              :                     FindSourceFile sets FullPath to a new string if successful.
      69              :                     The string FileName is not altered.
      70              : */
      71              : 
      72              : extern "C" bool M2Search_FindSourceFile (DynamicStrings_String FileName, DynamicStrings_String *FullPath, DynamicStrings_String *named);
      73              : 
      74              : /*
      75              :    FindSourceDefFile - attempts to find the definition module for
      76              :                        a module, Stem. If successful it returns
      77              :                        the full path and returns TRUE. If unsuccessful
      78              :                        then FALSE is returned and FullPath is set to NIL.
      79              : */
      80              : 
      81              : extern "C" bool M2Search_FindSourceDefFile (DynamicStrings_String Stem, DynamicStrings_String *FullPath, DynamicStrings_String *named);
      82              : 
      83              : /*
      84              :    FindSourceModFile - attempts to find the implementation module for
      85              :                        a module, Stem. If successful it returns
      86              :                        the full path and returns TRUE. If unsuccessful
      87              :                        then FALSE is returned and FullPath is set to NIL.
      88              : */
      89              : 
      90              : extern "C" bool M2Search_FindSourceModFile (DynamicStrings_String Stem, DynamicStrings_String *FullPath, DynamicStrings_String *named);
      91              : 
      92              : /*
      93              :    SetDefExtension - sets the default extension for definition modules to, ext.
      94              :                      The string, ext, should be deallocated by the caller at
      95              :                      an appropriate time.
      96              : */
      97              : 
      98              : extern "C" void M2Search_SetDefExtension (DynamicStrings_String ext);
      99              : 
     100              : /*
     101              :    SetModExtension - sets the default extension for implementation and program
     102              :                      modules to, ext. The string, ext, should be deallocated
     103              :                      by the caller at an appropriate time.
     104              : */
     105              : 
     106              : extern "C" void M2Search_SetModExtension (DynamicStrings_String ext);
     107              : 
     108              : /*
     109              :    Init - initializes the def and mod default string names to NIL.
     110              : */
     111              : 
     112              : static void Init (void);
     113              : 
     114              : 
     115              : /*
     116              :    Init - initializes the def and mod default string names to NIL.
     117              : */
     118              : 
     119        14952 : static void Init (void)
     120              : {
     121        14952 :   Def = static_cast<DynamicStrings_String> (NULL);
     122        14952 :   Mod = static_cast<DynamicStrings_String> (NULL);
     123            0 : }
     124              : 
     125              : 
     126              : /*
     127              :    FindSourceFile - attempts to locate the source file FileName.
     128              :                     If a file is found then TRUE is returned otherwise
     129              :                     FALSE is returned.
     130              :                     The parameter FullPath is set indicating the
     131              :                     absolute location of source FileName.
     132              :                     FullPath will be totally overwritten and should
     133              :                     not be initialized by InitString before this function
     134              :                     is called.
     135              :                     FullPath is set to NIL if this function returns FALSE.
     136              :                     FindSourceFile sets FullPath to a new string if successful.
     137              :                     The string FileName is not altered.
     138              : */
     139              : 
     140       249313 : extern "C" bool M2Search_FindSourceFile (DynamicStrings_String FileName, DynamicStrings_String *FullPath, DynamicStrings_String *named)
     141              : {
     142       249313 :   (*FullPath) = PathName_FindNamedPathFile (FileName, named);
     143       249313 :   return (*FullPath) != NULL;
     144              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     145              :   __builtin_unreachable ();
     146              : }
     147              : 
     148              : 
     149              : /*
     150              :    FindSourceDefFile - attempts to find the definition module for
     151              :                        a module, Stem. If successful it returns
     152              :                        the full path and returns TRUE. If unsuccessful
     153              :                        then FALSE is returned and FullPath is set to NIL.
     154              : */
     155              : 
     156       162119 : extern "C" bool M2Search_FindSourceDefFile (DynamicStrings_String Stem, DynamicStrings_String *FullPath, DynamicStrings_String *named)
     157              : {
     158       162119 :   DynamicStrings_String f;
     159              : 
     160       162119 :   if (Def != NULL)
     161              :     {
     162           36 :       f = M2FileName_CalculateFileName (Stem, Def);
     163           36 :       if (M2Search_FindSourceFile (f, FullPath, named))
     164              :         {
     165              :           return true;
     166              :         }
     167           30 :       f = DynamicStrings_KillString (f);
     168              :     }
     169              :   /* Try the GNU Modula-2 default extension.  */
     170       162113 :   f = M2FileName_CalculateFileName (Stem, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ".def", 4)));
     171       162113 :   return M2Search_FindSourceFile (f, FullPath, named);
     172              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     173              :   __builtin_unreachable ();
     174              : }
     175              : 
     176              : 
     177              : /*
     178              :    FindSourceModFile - attempts to find the implementation module for
     179              :                        a module, Stem. If successful it returns
     180              :                        the full path and returns TRUE. If unsuccessful
     181              :                        then FALSE is returned and FullPath is set to NIL.
     182              : */
     183              : 
     184        87164 : extern "C" bool M2Search_FindSourceModFile (DynamicStrings_String Stem, DynamicStrings_String *FullPath, DynamicStrings_String *named)
     185              : {
     186        87164 :   DynamicStrings_String f;
     187              : 
     188        87164 :   if (Mod != NULL)
     189              :     {
     190            0 :       f = M2FileName_CalculateFileName (Stem, Mod);
     191            0 :       if (M2Search_FindSourceFile (f, FullPath, named))
     192              :         {
     193              :           return true;
     194              :         }
     195            0 :       f = DynamicStrings_KillString (f);
     196              :     }
     197              :   /* Try the GNU Modula-2 default extension.  */
     198        87164 :   f = M2FileName_CalculateFileName (Stem, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ".mod", 4)));
     199        87164 :   return M2Search_FindSourceFile (f, FullPath, named);
     200              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     201              :   __builtin_unreachable ();
     202              : }
     203              : 
     204              : 
     205              : /*
     206              :    SetDefExtension - sets the default extension for definition modules to, ext.
     207              :                      The string, ext, should be deallocated by the caller at
     208              :                      an appropriate time.
     209              : */
     210              : 
     211            6 : extern "C" void M2Search_SetDefExtension (DynamicStrings_String ext)
     212              : {
     213            6 :   Def = DynamicStrings_KillString (Def);
     214            6 :   Def = DynamicStrings_Dup (ext);
     215            6 : }
     216              : 
     217              : 
     218              : /*
     219              :    SetModExtension - sets the default extension for implementation and program
     220              :                      modules to, ext. The string, ext, should be deallocated
     221              :                      by the caller at an appropriate time.
     222              : */
     223              : 
     224            6 : extern "C" void M2Search_SetModExtension (DynamicStrings_String ext)
     225              : {
     226            6 :   Mod = DynamicStrings_KillString (Mod);
     227            6 :   Mod = DynamicStrings_Dup (ext);
     228            6 : }
     229              : 
     230        14952 : extern "C" void _M2_M2Search_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
     231              : {
     232        14952 :   Init ();
     233        14952 : }
     234              : 
     235            0 : extern "C" void _M2_M2Search_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
     236              : {
     237            0 : }
        

Generated by: LCOV version 2.4-beta

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