LCOV - code coverage report
Current view: top level - gcc/m2/gm2-gcc - m2spellcheck.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.1 % 29 27
Test Date: 2025-11-22 14:42:49 Functions: 85.7 % 7 6
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* m2spellcheck.cc provides an interface to the GCC spell checker.
       2                 :             : 
       3                 :             : Copyright (C) 2025 Free Software Foundation, Inc.
       4                 :             : Contributed by Gaius Mulley <gaiusmod2@gmail.com>.
       5                 :             : 
       6                 :             : This file is part of GNU Modula-2.
       7                 :             : 
       8                 :             : GNU Modula-2 is free software; you can redistribute it and/or modify
       9                 :             : it under the terms of the GNU General Public License as published by
      10                 :             : the Free Software Foundation; either version 3, or (at your option)
      11                 :             : any later version.
      12                 :             : 
      13                 :             : GNU Modula-2 is distributed in the hope that it will be useful, but
      14                 :             : WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16                 :             : General Public License for more details.
      17                 :             : 
      18                 :             : You should have received a copy of the GNU General Public License
      19                 :             : along with GNU Modula-2; see the file COPYING3.  If not see
      20                 :             : <http://www.gnu.org/licenses/>.  */
      21                 :             : 
      22                 :             : #include "gcc-consolidation.h"
      23                 :             : 
      24                 :             : #include "../gm2-lang.h"
      25                 :             : #include "../m2-tree.h"
      26                 :             : 
      27                 :             : #define m2spellcheck_c
      28                 :             : #include "m2assert.h"
      29                 :             : #include "m2builtins.h"
      30                 :             : #include "m2convert.h"
      31                 :             : #include "m2decl.h"
      32                 :             : #include "m2expr.h"
      33                 :             : #include "m2spellcheck.h"
      34                 :             : 
      35                 :             : 
      36                 :             : /* Define the hidden type Candidates declared in the definition module.  */
      37                 :             : typedef auto_vec<const char *> candidates_array_vec_t;
      38                 :             : 
      39                 :             : typedef struct Candidates_t {
      40                 :             :   candidates_array_vec_t candidates_array;
      41                 :             :   struct Candidates_t *next;
      42                 :             : } Candidates;
      43                 :             : 
      44                 :             : 
      45                 :             : static Candidates *freeList = NULL;
      46                 :             : 
      47                 :             : 
      48                 :             : /* InitCandidates create an empty candidate array.  */
      49                 :             : 
      50                 :             : void *
      51                 :         212 : m2spellcheck_InitCandidates (void)
      52                 :             : {
      53                 :         212 :   Candidates *c = NULL;
      54                 :         212 :   if (freeList == NULL)
      55                 :         169 :     c = (Candidates *) xmalloc (sizeof (Candidates));
      56                 :             :   else
      57                 :             :     {
      58                 :          43 :       c = freeList;
      59                 :          43 :       freeList = freeList->next;
      60                 :             :     }
      61                 :         212 :   :: new (&c->candidates_array) auto_vec<const char *> ();
      62                 :         212 :   c->next = NULL;
      63                 :         212 :   return c;
      64                 :             : }
      65                 :             : 
      66                 :             : /* Push a string to the Candidates array.
      67                 :             :    The candidates array will contain the string name at the end.  */
      68                 :             : 
      69                 :             : static
      70                 :             : void
      71                 :        2857 : Push (Candidates *cand, const char *name)
      72                 :             : {
      73                 :           0 :   cand->candidates_array.safe_push (name);
      74                 :           0 : }
      75                 :             : 
      76                 :             : /* Push a string to the Candidates array.
      77                 :             :    The candidates array will contain str at the end.  */
      78                 :             : 
      79                 :             : void
      80                 :        2857 : m2spellcheck_Push (void *cand, const char *name)
      81                 :             : {
      82                 :        2857 :   Push (static_cast<Candidates *> (cand), name);
      83                 :        2857 : }
      84                 :             : 
      85                 :             : /* Return the Candidates structure to the freeList and deallocate
      86                 :             :    the auto_vec candidates_array.  */
      87                 :             : 
      88                 :             : static
      89                 :             : void
      90                 :         212 : KillCandidates (Candidates **cand)
      91                 :             : {
      92                 :         212 :   (*cand)->next = freeList;
      93                 :         212 :   (*cand)->candidates_array.~candidates_array_vec_t ();
      94                 :         212 :   freeList = *cand;
      95                 :         212 :   (*cand) = NULL;
      96                 :         212 : }
      97                 :             : 
      98                 :             : /* KillCandidates deallocates the candidates array and set (*cand) to NULL.
      99                 :             :    (*cand) is placed into the m2spellcheck module freeList.  */
     100                 :             : 
     101                 :             : void
     102                 :         212 : m2spellcheck_KillCandidates (void **cand)
     103                 :             : {
     104                 :         212 :   KillCandidates (reinterpret_cast<Candidates **> (cand));
     105                 :         212 : }
     106                 :             : 
     107                 :             : /* FindClosestCharStar return the closest match to name found within
     108                 :             :    the candidates_array.  NULL is returned if no close match is found.  */
     109                 :             : 
     110                 :             : const char*
     111                 :         212 : FindClosestCharStar (Candidates *cand, const char *name)
     112                 :             : {
     113                 :         212 :   return find_closest_string (name, &cand->candidates_array);
     114                 :             : }
     115                 :             : 
     116                 :             : const char*
     117                 :         212 : m2spellcheck_FindClosestCharStar (void *cand, const char *name)
     118                 :             : {
     119                 :         212 :   return FindClosestCharStar (static_cast<Candidates *> (cand),
     120                 :         212 :                               name);
     121                 :             : }
        

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.