LCOV - code coverage report
Current view: top level - /mnt/build/buildbot/bld/build-lcov/gcc/m2/gm2-compiler-boot - FilterError.c (source / functions) Coverage Total Hit
Test: gcc.info Lines: 63.6 % 66 42
Test Date: 2026-08-29 16:23:03 Functions: 41.7 % 12 5
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* do not edit automatically generated by mc from FilterError.  */
       2              : /* FilterError.mod implements a filter for token and symbol.
       3              : 
       4              : Copyright (C) 2025-2026 Free Software Foundation, Inc.
       5              : Contributed by Gaius Mulley <gaiusmod2@gmail.com>.
       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 "GStorage.h"
      41              : #if defined(__cplusplus)
      42              : #   undef NULL
      43              : #   define NULL 0
      44              : #endif
      45              : #define _FilterError_C
      46              : 
      47              : #include "GFilterError.h"
      48              : #   include "GSYSTEM.h"
      49              : #   include "GStorage.h"
      50              : #   include "GBinDict.h"
      51              : #   include "GAssertion.h"
      52              : #   include "Glibc.h"
      53              : 
      54              : #   define Debugging false
      55              : typedef struct FilterError__T1_r FilterError__T1;
      56              : 
      57              : typedef FilterError__T1 *FilterError_Filter__opaque;
      58              : 
      59              : typedef unsigned int *FilterError_PtrToCardinal;
      60              : 
      61              : typedef bool *FilterError_PtrToBoolean;
      62              : 
      63              : struct FilterError__T1_r {
      64              :                            BinDict_Dictionary Sym2Dict;
      65              :                          };
      66              : 
      67              : 
      68              : /*
      69              :    Init - return a new empty Filter.
      70              : */
      71              : 
      72              : extern "C" FilterError_Filter FilterError_Init (void);
      73              : 
      74              : /*
      75              :    AddSymError - adds the pair sym token to the filter.
      76              : */
      77              : 
      78              : extern "C" void FilterError_AddSymError (FilterError_Filter filter, unsigned int sym, unsigned int token);
      79              : 
      80              : /*
      81              :    IsSymError - return TRUE if the pair sym token have been
      82              :                 entered in the filter.
      83              : */
      84              : 
      85              : extern "C" bool FilterError_IsSymError (FilterError_Filter filter, unsigned int sym, unsigned int token);
      86              : 
      87              : /*
      88              :    Kill - deletes the entire filter tree and all contents.
      89              : */
      90              : 
      91              : extern "C" void FilterError_Kill (FilterError_Filter *filter);
      92              : 
      93              : /*
      94              :    CompareCardinal - return an INTEGER representing the comparison
      95              :                      between left and right.
      96              :                      0 if left == right, -1 if left < right,
      97              :                     +1 if left > right.
      98              : */
      99              : 
     100              : static int CompareCardinal (FilterError_PtrToCardinal left, FilterError_PtrToCardinal right);
     101              : 
     102              : /*
     103              :    DeleteCardinal - deallocate the cardinal key.
     104              : */
     105              : 
     106              : static void DeleteCardinal (FilterError_PtrToCardinal card);
     107              : 
     108              : /*
     109              :    DeleteBoolean - deallocate the boolean value.
     110              : */
     111              : 
     112              : static void DeleteBoolean (FilterError_PtrToBoolean boolean);
     113              : 
     114              : /*
     115              :    DeleteTree - delete tree and all its contents.
     116              : */
     117              : 
     118              : static void DeleteTree (BinDict_Dictionary ErrorTree);
     119              : 
     120              : /*
     121              :    AddNewEntry - adds a new value to the sym token pair.
     122              : */
     123              : 
     124              : static void AddNewEntry (FilterError_Filter__opaque filter, unsigned int sym, unsigned int token, bool value);
     125              : 
     126              : /*
     127              :    PrintNode -
     128              : */
     129              : 
     130              : static void PrintNode (BinDict_Node node);
     131              : 
     132              : 
     133              : /*
     134              :    CompareCardinal - return an INTEGER representing the comparison
     135              :                      between left and right.
     136              :                      0 if left == right, -1 if left < right,
     137              :                     +1 if left > right.
     138              : */
     139              : 
     140          640 : static int CompareCardinal (FilterError_PtrToCardinal left, FilterError_PtrToCardinal right)
     141              : {
     142          640 :   if ((*left) == (*right))
     143              :     {
     144              :       return 0;
     145              :     }
     146          168 :   else if ((*left) < (*right))
     147              :     {
     148              :       /* avoid dangling else.  */
     149              :       return -1;
     150              :     }
     151              :   else
     152              :     {
     153              :       /* avoid dangling else.  */
     154           78 :       return 1;
     155              :     }
     156              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     157              :   __builtin_unreachable ();
     158              : }
     159              : 
     160              : 
     161              : /*
     162              :    DeleteCardinal - deallocate the cardinal key.
     163              : */
     164              : 
     165            0 : static void DeleteCardinal (FilterError_PtrToCardinal card)
     166              : {
     167            0 :   Storage_DEALLOCATE ((void **) &card, sizeof (unsigned int));
     168            0 : }
     169              : 
     170              : 
     171              : /*
     172              :    DeleteBoolean - deallocate the boolean value.
     173              : */
     174              : 
     175            0 : static void DeleteBoolean (FilterError_PtrToBoolean boolean)
     176              : {
     177            0 :   Storage_DEALLOCATE ((void **) &boolean, sizeof (bool));
     178            0 : }
     179              : 
     180              : 
     181              : /*
     182              :    DeleteTree - delete tree and all its contents.
     183              : */
     184              : 
     185            0 : static void DeleteTree (BinDict_Dictionary ErrorTree)
     186              : {
     187            0 :   BinDict_Kill (&ErrorTree);
     188            0 : }
     189              : 
     190              : 
     191              : /*
     192              :    AddNewEntry - adds a new value to the sym token pair.
     193              : */
     194              : 
     195          205 : static void AddNewEntry (FilterError_Filter__opaque filter, unsigned int sym, unsigned int token, bool value)
     196              : {
     197          205 :   BinDict_Dictionary TokenTree;
     198          205 :   FilterError_PtrToCardinal ptrToToken;
     199          205 :   FilterError_PtrToCardinal ptrToCard;
     200          205 :   FilterError_PtrToBoolean ptrToBool;
     201              : 
     202          205 :   TokenTree = static_cast<BinDict_Dictionary> (BinDict_Get (filter->Sym2Dict, &sym));
     203          205 :   if (TokenTree == NULL)
     204              :     {
     205          193 :       TokenTree = BinDict_Init ((BinDict_Compare) {(BinDict_Compare_t) CompareCardinal}, (BinDict_Delete) {(BinDict_Delete_t) DeleteCardinal}, (BinDict_Delete) {(BinDict_Delete_t) DeleteBoolean});
     206          193 :       Storage_ALLOCATE ((void **) &ptrToCard, sizeof (unsigned int));
     207          193 :       (*ptrToCard) = sym;
     208          193 :       BinDict_Insert (filter->Sym2Dict, reinterpret_cast <void *> (ptrToCard), reinterpret_cast <void *> (TokenTree));
     209          193 :       Assertion_Assert ((BinDict_Get (filter->Sym2Dict, reinterpret_cast <void *> (ptrToCard))) == TokenTree);
     210              :     }
     211          205 :   Storage_ALLOCATE ((void **) &ptrToBool, sizeof (bool));
     212          205 :   (*ptrToBool) = value;
     213          205 :   Storage_ALLOCATE ((void **) &ptrToToken, sizeof (unsigned int));
     214          205 :   (*ptrToToken) = token;
     215          205 :   if (Debugging)
     216              :     {
     217              :       libc_printf ((const char *) "adding sym %d: key = 0x%x, value = 0x%x  (%d, %d)\\n", 51, sym, ptrToToken, ptrToBool, (*ptrToToken), (*ptrToBool));
     218              :     }
     219          205 :   BinDict_Insert (TokenTree, reinterpret_cast <void *> (ptrToToken), reinterpret_cast <void *> (ptrToBool));
     220          205 :   Assertion_Assert ((BinDict_Get (TokenTree, reinterpret_cast <void *> (ptrToToken))) == ptrToBool);
     221          205 :   if (Debugging)
     222              :     {
     223              :       BinDict_PostOrder (TokenTree, (BinDict_VisitNode) {(BinDict_VisitNode_t) PrintNode});
     224              :     }
     225          205 : }
     226              : 
     227              : 
     228              : /*
     229              :    PrintNode -
     230              : */
     231              : 
     232            0 : static void PrintNode (BinDict_Node node)
     233              : {
     234            0 :   FilterError_PtrToCardinal ptrToCard;
     235            0 :   FilterError_PtrToBoolean ptrToBool;
     236              : 
     237            0 :   ptrToCard = static_cast<FilterError_PtrToCardinal> (BinDict_Key (node));
     238            0 :   ptrToBool = static_cast<FilterError_PtrToBoolean> (BinDict_Value (node));
     239            0 :   libc_printf ((const char *) "key = 0x%x, value = 0x%x  (%d, %d)\\n", 36, ptrToCard, ptrToBool, (*ptrToCard), (*ptrToBool));
     240            0 : }
     241              : 
     242              : 
     243              : /*
     244              :    Init - return a new empty Filter.
     245              : */
     246              : 
     247        16004 : extern "C" FilterError_Filter FilterError_Init (void)
     248              : {
     249        16004 :   FilterError_Filter__opaque filter;
     250              : 
     251        16004 :   Storage_ALLOCATE ((void **) &filter, sizeof (FilterError__T1));
     252        16004 :   filter->Sym2Dict = BinDict_Init ((BinDict_Compare) {(BinDict_Compare_t) CompareCardinal}, (BinDict_Delete) {(BinDict_Delete_t) DeleteCardinal}, (BinDict_Delete) {(BinDict_Delete_t) DeleteTree});
     253        16004 :   return static_cast<FilterError_Filter> (filter);
     254              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     255              :   __builtin_unreachable ();
     256              : }
     257              : 
     258              : 
     259              : /*
     260              :    AddSymError - adds the pair sym token to the filter.
     261              : */
     262              : 
     263          205 : extern "C" void FilterError_AddSymError (FilterError_Filter filter, unsigned int sym, unsigned int token)
     264              : {
     265          205 :   if (! (FilterError_IsSymError (filter, sym, token)))
     266              :     {
     267          205 :       AddNewEntry (static_cast<FilterError_Filter__opaque> (filter), sym, token, true);
     268              :     }
     269          205 : }
     270              : 
     271              : 
     272              : /*
     273              :    IsSymError - return TRUE if the pair sym token have been
     274              :                 entered in the filter.
     275              : */
     276              : 
     277          429 : extern "C" bool FilterError_IsSymError (FilterError_Filter filter, unsigned int sym, unsigned int token)
     278              : {
     279          429 :   FilterError_PtrToBoolean ptb;
     280          429 :   BinDict_Dictionary TokenTree;
     281              : 
     282          429 :   TokenTree = static_cast<BinDict_Dictionary> (BinDict_Get (static_cast<FilterError_Filter__opaque> (filter)->Sym2Dict, &sym));
     283              :   /* RETURN (TokenTree # NIL) ;  */
     284          429 :   if (TokenTree == NULL)
     285              :     {
     286              :       /* No symbol registered, therefore FALSE.  */
     287              :       return false;
     288              :     }
     289           43 :   ptb = static_cast<FilterError_PtrToBoolean> (BinDict_Get (TokenTree, &token));
     290           43 :   if (ptb == NULL)
     291              :     {
     292              :       /* The symbol was registered, but no entry for token, therefore FALSE.  */
     293              :       return false;
     294              :     }
     295              :   /* Found symbol and token so we return the result.  */
     296           19 :   return (*ptb);
     297              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     298              :   __builtin_unreachable ();
     299              : }
     300              : 
     301              : 
     302              : /*
     303              :    Kill - deletes the entire filter tree and all contents.
     304              : */
     305              : 
     306            0 : extern "C" void FilterError_Kill (FilterError_Filter *filter)
     307              : {
     308            0 :   BinDict_Kill (&static_cast<FilterError_Filter__opaque> ((*filter))->Sym2Dict);
     309            0 :   Storage_DEALLOCATE ((void **) &(*filter), sizeof (FilterError__T1));
     310            0 : }
     311              : 
     312            0 : extern "C" void _M2_FilterError_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
     313              : {
     314            0 : }
     315              : 
     316            0 : extern "C" void _M2_FilterError_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
     317              : {
     318            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.