LCOV - code coverage report
Current view: top level - gcc/fortran - constructor.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 99.1 % 106 105
Test Date: 2024-04-20 14:03:02 Functions: 94.1 % 17 16
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Array and structure constructors
       2                 :             :    Copyright (C) 2009-2024 Free Software Foundation, Inc.
       3                 :             : 
       4                 :             : This file is part of GCC.
       5                 :             : 
       6                 :             : GCC is free software; you can redistribute it and/or modify it under
       7                 :             : the terms of the GNU General Public License as published by the Free
       8                 :             : Software Foundation; either version 3, or (at your option) any later
       9                 :             : version.
      10                 :             : 
      11                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14                 :             : for more details.
      15                 :             : 
      16                 :             : You should have received a copy of the GNU General Public License
      17                 :             : along with GCC; see the file COPYING3.  If not see
      18                 :             : <http://www.gnu.org/licenses/>.  */
      19                 :             : 
      20                 :             : #include "config.h"
      21                 :             : #include "system.h"
      22                 :             : #include "coretypes.h"
      23                 :             : #include "gfortran.h"
      24                 :             : #include "constructor.h"
      25                 :             : 
      26                 :             : 
      27                 :             : static void
      28                 :     2440902 : node_free (splay_tree_value value)
      29                 :             : {
      30                 :     2440902 :   gfc_constructor *c = (gfc_constructor*)value;
      31                 :             : 
      32                 :     2440902 :   if (c->expr)
      33                 :     2364781 :     gfc_free_expr (c->expr);
      34                 :             : 
      35                 :     2440902 :   if (c->iterator)
      36                 :        7142 :     gfc_free_iterator (c->iterator, 1);
      37                 :             : 
      38                 :     2440902 :   mpz_clear (c->offset);
      39                 :     2440902 :   mpz_clear (c->repeat);
      40                 :             : 
      41                 :     2440902 :   free (c);
      42                 :     2440902 : }
      43                 :             : 
      44                 :             : 
      45                 :             : static gfc_constructor *
      46                 :      629218 : node_copy (splay_tree_node node, void *base)
      47                 :             : {
      48                 :      629218 :   gfc_constructor *c, *src = (gfc_constructor*)node->value;
      49                 :             : 
      50                 :      629218 :   c = XCNEW (gfc_constructor);
      51                 :      629218 :   c->base = (gfc_constructor_base)base;
      52                 :      629218 :   c->expr = gfc_copy_expr (src->expr);
      53                 :      629218 :   c->iterator = gfc_copy_iterator (src->iterator);
      54                 :      629218 :   c->where = src->where;
      55                 :      629218 :   c->n.component = src->n.component;
      56                 :             : 
      57                 :      629218 :   mpz_init_set (c->offset, src->offset);
      58                 :      629218 :   mpz_init_set (c->repeat, src->repeat);
      59                 :             : 
      60                 :      629218 :   return c;
      61                 :             : }
      62                 :             : 
      63                 :             : 
      64                 :             : static int
      65                 :      629218 : node_copy_and_insert (splay_tree_node node, void *base)
      66                 :             : {
      67                 :      629218 :   int n = mpz_get_si (((gfc_constructor*)node->value)->offset);
      68                 :      629218 :   gfc_constructor_insert ((gfc_constructor_base*)base,
      69                 :             :                           node_copy (node, base), n);
      70                 :      629218 :   return 0;
      71                 :             : }
      72                 :             : 
      73                 :             : 
      74                 :             : gfc_constructor *
      75                 :     1838284 : gfc_constructor_get (void)
      76                 :             : {
      77                 :     1838284 :   gfc_constructor *c = XCNEW (gfc_constructor);
      78                 :     1838284 :   c->base = NULL;
      79                 :     1838284 :   c->expr = NULL;
      80                 :     1838284 :   c->iterator = NULL;
      81                 :             : 
      82                 :     1838284 :   mpz_init_set_si (c->offset, 0);
      83                 :     1838284 :   mpz_init_set_si (c->repeat, 1);
      84                 :             : 
      85                 :     1838284 :   return c;
      86                 :             : }
      87                 :             : 
      88                 :             : static gfc_constructor_base
      89                 :       86389 : gfc_constructor_get_base (void)
      90                 :             : {
      91                 :           0 :   return splay_tree_new (splay_tree_compare_ints, NULL, node_free);
      92                 :             : }
      93                 :             : 
      94                 :             : 
      95                 :             : gfc_constructor_base
      96                 :       87534 : gfc_constructor_copy (gfc_constructor_base base)
      97                 :             : {
      98                 :       87534 :   gfc_constructor_base new_base;
      99                 :             : 
     100                 :       87534 :   if (!base)
     101                 :             :     return NULL;
     102                 :             : 
     103                 :       86389 :   new_base = gfc_constructor_get_base ();
     104                 :       86389 :   splay_tree_foreach (base, node_copy_and_insert, &new_base);
     105                 :             : 
     106                 :       86389 :   return new_base;
     107                 :             : }
     108                 :             : 
     109                 :             : 
     110                 :             : void
     111                 :      350919 : gfc_constructor_free (gfc_constructor_base base)
     112                 :             : {
     113                 :      350919 :   if (base)
     114                 :      342272 :     splay_tree_delete (base);
     115                 :      350919 : }
     116                 :             : 
     117                 :             : 
     118                 :             : gfc_constructor *
     119                 :     1829802 : gfc_constructor_append (gfc_constructor_base *base, gfc_constructor *c)
     120                 :             : {
     121                 :     1829802 :   int offset = 0;
     122                 :     1829802 :   if (*base)
     123                 :     1565348 :     offset = (int)(splay_tree_max (*base)->key) + 1;
     124                 :             : 
     125                 :     1829802 :   return gfc_constructor_insert (base, c, offset);
     126                 :             : }
     127                 :             : 
     128                 :             : 
     129                 :             : gfc_constructor *
     130                 :     1634395 : gfc_constructor_append_expr (gfc_constructor_base *base,
     131                 :             :                              gfc_expr *e, locus *where)
     132                 :             : {
     133                 :     1634395 :   gfc_constructor *c = gfc_constructor_get ();
     134                 :     1634395 :   c->expr = e;
     135                 :     1634395 :   if (where)
     136                 :     1579934 :     c->where = *where;
     137                 :             : 
     138                 :     1634395 :   return gfc_constructor_append (base, c);
     139                 :             : }
     140                 :             : 
     141                 :             : 
     142                 :             : gfc_constructor *
     143                 :     2467501 : gfc_constructor_insert (gfc_constructor_base *base, gfc_constructor *c, int n)
     144                 :             : {
     145                 :     2467501 :   splay_tree_node node;
     146                 :             : 
     147                 :     2467501 :   if (*base == NULL)
     148                 :      265591 :     *base = splay_tree_new (splay_tree_compare_ints, NULL, node_free);
     149                 :             : 
     150                 :     2467501 :   c->base = *base;
     151                 :     2467501 :   mpz_set_si (c->offset, n);
     152                 :             : 
     153                 :     2467501 :   node = splay_tree_insert (*base, (splay_tree_key) n, (splay_tree_value) c);
     154                 :     2467501 :   gcc_assert (node);
     155                 :             : 
     156                 :     2467501 :   return (gfc_constructor*)node->value;
     157                 :             : }
     158                 :             : 
     159                 :             : 
     160                 :             : gfc_constructor *
     161                 :        8481 : gfc_constructor_insert_expr (gfc_constructor_base *base,
     162                 :             :                              gfc_expr *e, locus *where, int n)
     163                 :             : {
     164                 :        8481 :   gfc_constructor *c = gfc_constructor_get ();
     165                 :        8481 :   c->expr = e;
     166                 :        8481 :   if (where)
     167                 :        7957 :     c->where = *where;
     168                 :             : 
     169                 :        8481 :   return gfc_constructor_insert (base, c, n);
     170                 :             : }
     171                 :             : 
     172                 :             : 
     173                 :             : gfc_constructor *
     174                 :       87625 : gfc_constructor_lookup (gfc_constructor_base base, int offset)
     175                 :             : {
     176                 :       87625 :   gfc_constructor *c;
     177                 :       87625 :   splay_tree_node node;
     178                 :             : 
     179                 :       87625 :   if (!base)
     180                 :             :     return NULL;
     181                 :             : 
     182                 :       86566 :   node = splay_tree_lookup (base, (splay_tree_key) offset);
     183                 :       86566 :   if (node)
     184                 :       75700 :     return (gfc_constructor *) node->value;
     185                 :             : 
     186                 :             :   /* Check if the previous node has a repeat count big enough to
     187                 :             :      cover the offset looked for.  */
     188                 :       10866 :   node = splay_tree_predecessor (base, (splay_tree_key) offset);
     189                 :       10866 :   if (!node)
     190                 :             :     return NULL;
     191                 :             : 
     192                 :       10621 :   c = (gfc_constructor *) node->value;
     193                 :       10621 :   if (mpz_cmp_si (c->repeat, 1) > 0)
     194                 :             :     {
     195                 :          29 :       if (mpz_get_si (c->offset) + mpz_get_si (c->repeat) <= offset)
     196                 :       11916 :         c = NULL;
     197                 :             :     }
     198                 :             :   else
     199                 :             :     c = NULL;
     200                 :             : 
     201                 :             :   return c;
     202                 :             : }
     203                 :             : 
     204                 :             : 
     205                 :             : gfc_expr *
     206                 :       76589 : gfc_constructor_lookup_expr (gfc_constructor_base base, int offset)
     207                 :             : {
     208                 :       76589 :   gfc_constructor *c = gfc_constructor_lookup (base, offset);
     209                 :       76589 :   return c ? c->expr : NULL;
     210                 :             : }
     211                 :             : 
     212                 :             : 
     213                 :             : gfc_constructor *
     214                 :    12551603 : gfc_constructor_first (gfc_constructor_base base)
     215                 :             : {
     216                 :    12551603 :   if (base)
     217                 :             :     {
     218                 :    12527289 :       splay_tree_node node = splay_tree_min (base);
     219                 :    12527289 :       return node ? (gfc_constructor*) node->value : NULL;
     220                 :             :     }
     221                 :             :   else
     222                 :             :     return NULL;
     223                 :             : }
     224                 :             : 
     225                 :             : 
     226                 :             : gfc_constructor *
     227                 :    23913028 : gfc_constructor_next (gfc_constructor *ctor)
     228                 :             : {
     229                 :    23913028 :   if (ctor)
     230                 :             :     {
     231                 :    47825662 :       splay_tree_node node = splay_tree_successor (ctor->base,
     232                 :    23912831 :                                                    mpz_get_si (ctor->offset));
     233                 :    23912831 :       return node ? (gfc_constructor*) node->value : NULL;
     234                 :             :     }
     235                 :             :   else
     236                 :             :     return NULL;
     237                 :             : }
     238                 :             : 
     239                 :             : 
     240                 :             : void
     241                 :          10 : gfc_constructor_remove (gfc_constructor *ctor)
     242                 :             : {
     243                 :          10 :   if (ctor)
     244                 :          10 :     splay_tree_remove (ctor->base, mpz_get_si (ctor->offset));
     245                 :          10 : }
     246                 :             : 
     247                 :             : 
     248                 :             : gfc_constructor *
     249                 :         156 : gfc_constructor_lookup_next (gfc_constructor_base base, int offset)
     250                 :             : {
     251                 :         156 :   splay_tree_node node;
     252                 :             : 
     253                 :         156 :   if (!base)
     254                 :             :     return NULL;
     255                 :             : 
     256                 :          24 :   node = splay_tree_successor (base, (splay_tree_key) offset);
     257                 :          24 :   if (!node)
     258                 :             :     return NULL;
     259                 :             : 
     260                 :           4 :   return (gfc_constructor *) node->value;
     261                 :             : }
        

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.