LCOV - code coverage report
Current view: top level - gcc/rust/resolve - rust-ast-resolve-implitem.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 80.0 % 125 100
Test Date: 2024-03-23 14:05:01 Functions: 70.0 % 20 14
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2020-2024 Free Software Foundation, Inc.
       2                 :             : 
       3                 :             : // This file is part of GCC.
       4                 :             : 
       5                 :             : // GCC is free software; you can redistribute it and/or modify it under
       6                 :             : // the terms of the GNU General Public License as published by the Free
       7                 :             : // Software Foundation; either version 3, or (at your option) any later
       8                 :             : // version.
       9                 :             : 
      10                 :             : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11                 :             : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12                 :             : // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13                 :             : // for more details.
      14                 :             : 
      15                 :             : // You should have received a copy of the GNU General Public License
      16                 :             : // along with GCC; see the file COPYING3.  If not see
      17                 :             : // <http://www.gnu.org/licenses/>.
      18                 :             : 
      19                 :             : #ifndef RUST_AST_RESOLVE_IMPLITEM_H
      20                 :             : #define RUST_AST_RESOLVE_IMPLITEM_H
      21                 :             : 
      22                 :             : #include "rust-ast-resolve-base.h"
      23                 :             : #include "rust-ast-resolve-type.h"
      24                 :             : #include "rust-ast-full.h"
      25                 :             : 
      26                 :             : namespace Rust {
      27                 :             : namespace Resolver {
      28                 :             : 
      29                 :        4252 : class ResolveToplevelImplItem : public ResolverBase
      30                 :             : {
      31                 :             :   using Rust::Resolver::ResolverBase::visit;
      32                 :             : 
      33                 :             : public:
      34                 :        4252 :   static void go (AST::AssociatedItem *item, const CanonicalPath &prefix)
      35                 :             :   {
      36                 :        4252 :     if (item->is_marked_for_strip ())
      37                 :           0 :       return;
      38                 :             : 
      39                 :        4252 :     ResolveToplevelImplItem resolver (prefix);
      40                 :        4252 :     item->accept_vis (resolver);
      41                 :        4252 :   }
      42                 :             : 
      43                 :         733 :   void visit (AST::TypeAlias &type) override
      44                 :             :   {
      45                 :         733 :     auto decl = CanonicalPath::new_seg (type.get_node_id (),
      46                 :         733 :                                         type.get_new_type_name ().as_string ());
      47                 :         733 :     auto path = prefix.append (decl);
      48                 :             : 
      49                 :         733 :     resolver->get_type_scope ().insert (
      50                 :             :       path, type.get_node_id (), type.get_locus (), false, Rib::ItemType::Type,
      51                 :         733 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
      52                 :           0 :         rich_location r (line_table, type.get_locus ());
      53                 :           0 :         r.add_range (locus);
      54                 :           0 :         rust_error_at (r, "redefined multiple times");
      55                 :           0 :       });
      56                 :         733 :   }
      57                 :             : 
      58                 :          42 :   void visit (AST::ConstantItem &constant) override
      59                 :             :   {
      60                 :          42 :     auto decl = CanonicalPath::new_seg (constant.get_node_id (),
      61                 :          42 :                                         constant.get_identifier ());
      62                 :          42 :     auto path = prefix.append (decl);
      63                 :             : 
      64                 :          42 :     resolver->get_name_scope ().insert (
      65                 :             :       path, constant.get_node_id (), constant.get_locus (), false,
      66                 :             :       Rib::ItemType::Const,
      67                 :          42 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
      68                 :           1 :         rich_location r (line_table, constant.get_locus ());
      69                 :           1 :         r.add_range (locus);
      70                 :           1 :         rust_error_at (r, "redefined multiple times");
      71                 :           1 :       });
      72                 :          42 :   }
      73                 :             : 
      74                 :        3477 :   void visit (AST::Function &function) override
      75                 :             :   {
      76                 :        3477 :     auto decl
      77                 :             :       = CanonicalPath::new_seg (function.get_node_id (),
      78                 :        3477 :                                 function.get_function_name ().as_string ());
      79                 :        3477 :     auto path = prefix.append (decl);
      80                 :             : 
      81                 :        3477 :     resolver->get_name_scope ().insert (
      82                 :             :       path, function.get_node_id (), function.get_locus (), false,
      83                 :             :       Rib::ItemType::Function,
      84                 :        3477 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
      85                 :           2 :         rich_location r (line_table, function.get_locus ());
      86                 :           2 :         r.add_range (locus);
      87                 :           2 :         rust_error_at (r, "redefined multiple times");
      88                 :           2 :       });
      89                 :        3477 :   }
      90                 :             : 
      91                 :             : private:
      92                 :        4252 :   ResolveToplevelImplItem (const CanonicalPath &prefix)
      93                 :        4252 :     : ResolverBase (), prefix (prefix)
      94                 :             :   {
      95                 :        4252 :     rust_assert (!prefix.is_empty ());
      96                 :        4252 :   }
      97                 :             : 
      98                 :             :   const CanonicalPath &prefix;
      99                 :             : };
     100                 :             : 
     101                 :        1634 : class ResolveTopLevelTraitItems : public ResolverBase
     102                 :             : {
     103                 :             :   using Rust::Resolver::ResolverBase::visit;
     104                 :             : 
     105                 :             : public:
     106                 :        1634 :   static void go (AST::AssociatedItem *item, const CanonicalPath &prefix,
     107                 :             :                   const CanonicalPath &canonical_prefix)
     108                 :             :   {
     109                 :        3268 :     ResolveTopLevelTraitItems resolver (prefix, canonical_prefix);
     110                 :        3268 :     item->accept_vis (resolver);
     111                 :        1634 :   };
     112                 :             : 
     113                 :        1075 :   void visit (AST::Function &function) override
     114                 :             :   {
     115                 :        1075 :     auto decl
     116                 :             :       = CanonicalPath::new_seg (function.get_node_id (),
     117                 :        1075 :                                 function.get_function_name ().as_string ());
     118                 :        1075 :     auto path = prefix.append (decl);
     119                 :        1075 :     auto cpath = canonical_prefix.append (decl);
     120                 :             : 
     121                 :        1075 :     resolver->get_name_scope ().insert (
     122                 :             :       path, function.get_node_id (), function.get_locus (), false,
     123                 :             :       Rib::ItemType::Function,
     124                 :        1075 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     125                 :           0 :         rich_location r (line_table, function.get_locus ());
     126                 :           0 :         r.add_range (locus);
     127                 :           0 :         rust_error_at (r, "redefined multiple times");
     128                 :           0 :       });
     129                 :             : 
     130                 :        1075 :     mappings->insert_canonical_path (function.get_node_id (), cpath);
     131                 :        1075 :   }
     132                 :             : 
     133                 :          36 :   void visit (AST::TraitItemConst &constant) override
     134                 :             :   {
     135                 :          36 :     auto decl
     136                 :             :       = CanonicalPath::new_seg (constant.get_node_id (),
     137                 :          36 :                                 constant.get_identifier ().as_string ());
     138                 :          36 :     auto path = prefix.append (decl);
     139                 :          36 :     auto cpath = canonical_prefix.append (decl);
     140                 :             : 
     141                 :          36 :     resolver->get_name_scope ().insert (
     142                 :          36 :       path, constant.get_node_id (), constant.get_locus (), false,
     143                 :             :       Rib::ItemType::Const,
     144                 :          36 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     145                 :           0 :         rich_location r (line_table, constant.get_locus ());
     146                 :           0 :         r.add_range (locus);
     147                 :           0 :         rust_error_at (r, "redefined multiple times");
     148                 :           0 :       });
     149                 :             : 
     150                 :          36 :     mappings->insert_canonical_path (constant.get_node_id (), cpath);
     151                 :          36 :   }
     152                 :             : 
     153                 :         523 :   void visit (AST::TraitItemType &type) override
     154                 :             :   {
     155                 :         523 :     auto decl = CanonicalPath::new_seg (type.get_node_id (),
     156                 :         523 :                                         type.get_identifier ().as_string ());
     157                 :         523 :     auto path = prefix.append (decl);
     158                 :         523 :     auto cpath = canonical_prefix.append (decl);
     159                 :             : 
     160                 :         523 :     resolver->get_type_scope ().insert (
     161                 :         523 :       path, type.get_node_id (), type.get_locus (), false, Rib::ItemType::Type,
     162                 :         523 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     163                 :           0 :         rich_location r (line_table, type.get_locus ());
     164                 :           0 :         r.add_range (locus);
     165                 :           0 :         rust_error_at (r, "redefined multiple times");
     166                 :           0 :       });
     167                 :             : 
     168                 :         523 :     mappings->insert_canonical_path (type.get_node_id (), cpath);
     169                 :         523 :   }
     170                 :             : 
     171                 :             : private:
     172                 :        1634 :   ResolveTopLevelTraitItems (const CanonicalPath &prefix,
     173                 :             :                              const CanonicalPath &canonical_prefix)
     174                 :        1634 :     : ResolverBase (), prefix (prefix), canonical_prefix (canonical_prefix)
     175                 :             :   {}
     176                 :             : 
     177                 :             :   const CanonicalPath &prefix;
     178                 :             :   const CanonicalPath &canonical_prefix;
     179                 :             : };
     180                 :             : 
     181                 :        1858 : class ResolveToplevelExternItem : public ResolverBase
     182                 :             : {
     183                 :             :   using Rust::Resolver::ResolverBase::visit;
     184                 :             : 
     185                 :             : public:
     186                 :        1858 :   static void go (AST::ExternalItem *item, const CanonicalPath &prefix)
     187                 :             :   {
     188                 :        3716 :     ResolveToplevelExternItem resolver (prefix);
     189                 :        3716 :     item->accept_vis (resolver);
     190                 :        1858 :   };
     191                 :             : 
     192                 :        1856 :   void visit (AST::ExternalFunctionItem &function) override
     193                 :             :   {
     194                 :        1856 :     auto decl
     195                 :             :       = CanonicalPath::new_seg (function.get_node_id (),
     196                 :        1856 :                                 function.get_identifier ().as_string ());
     197                 :        1856 :     auto path = prefix.append (decl);
     198                 :             : 
     199                 :        1856 :     resolver->get_name_scope ().insert (
     200                 :             :       path, function.get_node_id (), function.get_locus (), false,
     201                 :             :       Rib::ItemType::Function,
     202                 :        1856 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     203                 :           0 :         rich_location r (line_table, function.get_locus ());
     204                 :           0 :         r.add_range (locus);
     205                 :           0 :         rust_error_at (r, "redefined multiple times");
     206                 :           0 :       });
     207                 :             : 
     208                 :        1856 :     NodeId current_module = resolver->peek_current_module_scope ();
     209                 :        1856 :     mappings->insert_module_child_item (current_module, decl);
     210                 :        1856 :   }
     211                 :             : 
     212                 :           1 :   void visit (AST::ExternalStaticItem &item) override
     213                 :             :   {
     214                 :           1 :     auto decl = CanonicalPath::new_seg (item.get_node_id (),
     215                 :           1 :                                         item.get_identifier ().as_string ());
     216                 :           1 :     auto path = prefix.append (decl);
     217                 :             : 
     218                 :           1 :     resolver->get_name_scope ().insert (
     219                 :             :       path, item.get_node_id (), item.get_locus (), false,
     220                 :             :       Rib::ItemType::Static,
     221                 :           1 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     222                 :           0 :         rich_location r (line_table, item.get_locus ());
     223                 :           0 :         r.add_range (locus);
     224                 :           0 :         rust_error_at (r, "redefined multiple times");
     225                 :           0 :       });
     226                 :             : 
     227                 :           1 :     NodeId current_module = resolver->peek_current_module_scope ();
     228                 :           1 :     mappings->insert_module_child_item (current_module, decl);
     229                 :           1 :   }
     230                 :             : 
     231                 :             : private:
     232                 :        1858 :   ResolveToplevelExternItem (const CanonicalPath &prefix)
     233                 :        1858 :     : ResolverBase (), prefix (prefix)
     234                 :             :   {}
     235                 :             : 
     236                 :             :   const CanonicalPath &prefix;
     237                 :             : };
     238                 :             : 
     239                 :             : } // namespace Resolver
     240                 :             : } // namespace Rust
     241                 :             : 
     242                 :             : #endif // RUST_AST_RESOLVE_IMPLITEM_H
        

Generated by: LCOV version 2.0-1

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.