LCOV - code coverage report
Current view: top level - gcc/rust/hir/tree - rust-hir-path.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 62.0 % 229 142
Test Date: 2025-06-21 16:26:05 Functions: 60.0 % 45 27
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                 :             : #include "rust-hir-path.h"
      20                 :             : #include "optional.h"
      21                 :             : #include "rust-hir-bound.h"
      22                 :             : 
      23                 :             : namespace Rust {
      24                 :             : namespace HIR {
      25                 :             : 
      26                 :          63 : GenericArgsBinding::GenericArgsBinding (Identifier ident,
      27                 :             :                                         std::unique_ptr<Type> type_ptr,
      28                 :          63 :                                         location_t locus)
      29                 :          63 :   : identifier (std::move (ident)), type (std::move (type_ptr)), locus (locus)
      30                 :          63 : {}
      31                 :             : 
      32                 :         158 : GenericArgsBinding::GenericArgsBinding (GenericArgsBinding const &other)
      33                 :         158 :   : identifier (other.identifier), type (other.type->clone_type ()),
      34                 :         158 :     locus (other.locus)
      35                 :         158 : {}
      36                 :             : 
      37                 :             : GenericArgsBinding &
      38                 :           0 : GenericArgsBinding::operator= (GenericArgsBinding const &other)
      39                 :             : {
      40                 :           0 :   identifier = other.identifier;
      41                 :           0 :   type = other.type->clone_type ();
      42                 :           0 :   locus = other.locus;
      43                 :           0 :   return *this;
      44                 :             : }
      45                 :             : 
      46                 :          44 : ConstGenericArg::ConstGenericArg (std::unique_ptr<Expr> expression,
      47                 :          44 :                                   location_t locus)
      48                 :          44 :   : expression (std::move (expression)), locus (locus)
      49                 :          44 : {}
      50                 :             : 
      51                 :         122 : ConstGenericArg::ConstGenericArg (const ConstGenericArg &other)
      52                 :         122 :   : locus (other.locus)
      53                 :             : {
      54                 :         122 :   expression = other.expression->clone_expr ();
      55                 :         122 : }
      56                 :             : 
      57                 :             : ConstGenericArg
      58                 :           0 : ConstGenericArg::operator= (const ConstGenericArg &other)
      59                 :             : {
      60                 :           0 :   expression = other.expression->clone_expr ();
      61                 :           0 :   locus = other.locus;
      62                 :             : 
      63                 :           0 :   return *this;
      64                 :             : }
      65                 :             : 
      66                 :             : GenericArgs &
      67                 :         712 : GenericArgs::operator= (GenericArgs const &other)
      68                 :             : {
      69                 :         712 :   lifetime_args = other.lifetime_args;
      70                 :         712 :   binding_args = other.binding_args;
      71                 :         712 :   const_args = other.const_args;
      72                 :         712 :   locus = other.locus;
      73                 :             : 
      74                 :         712 :   type_args.clear ();
      75                 :         712 :   type_args.reserve (other.type_args.size ());
      76                 :        1433 :   for (const auto &e : other.type_args)
      77                 :         721 :     type_args.push_back (e->clone_type ());
      78                 :             : 
      79                 :         712 :   return *this;
      80                 :             : }
      81                 :             : 
      82                 :       57972 : GenericArgs::GenericArgs (std::vector<Lifetime> lifetime_args,
      83                 :             :                           std::vector<std::unique_ptr<Type> > type_args,
      84                 :             :                           std::vector<GenericArgsBinding> binding_args,
      85                 :             :                           std::vector<ConstGenericArg> const_args,
      86                 :       57972 :                           location_t locus)
      87                 :       57972 :   : lifetime_args (std::move (lifetime_args)),
      88                 :       57972 :     type_args (std::move (type_args)), binding_args (std::move (binding_args)),
      89                 :       57972 :     const_args (std::move (const_args)), locus (locus)
      90                 :       57972 : {}
      91                 :             : 
      92                 :       92586 : GenericArgs::GenericArgs (GenericArgs const &other)
      93                 :       92586 :   : lifetime_args (other.lifetime_args), binding_args (other.binding_args),
      94                 :       92586 :     const_args (other.const_args), locus (other.locus)
      95                 :             : {
      96                 :       92586 :   type_args.clear ();
      97                 :       92586 :   type_args.reserve (other.type_args.size ());
      98                 :             : 
      99                 :       96572 :   for (const auto &e : other.type_args)
     100                 :        3986 :     type_args.push_back (e->clone_type ());
     101                 :       92586 : }
     102                 :             : 
     103                 :             : bool
     104                 :        5357 : GenericArgs::is_empty () const
     105                 :             : {
     106                 :       10714 :   return lifetime_args.size () == 0 && type_args.size () == 0
     107                 :        5841 :          && binding_args.size () == 0;
     108                 :             : }
     109                 :             : 
     110                 :       45293 : PathExprSegment::PathExprSegment (Analysis::NodeMapping mappings,
     111                 :             :                                   PathIdentSegment segment_name,
     112                 :       45293 :                                   location_t locus, GenericArgs generic_args)
     113                 :       45293 :   : mappings (std::move (mappings)), segment_name (std::move (segment_name)),
     114                 :       45293 :     generic_args (std::move (generic_args)), locus (locus)
     115                 :       45293 : {}
     116                 :             : 
     117                 :       89564 : PathExprSegment::PathExprSegment (PathExprSegment const &other)
     118                 :       89564 :   : mappings (other.mappings), segment_name (other.segment_name),
     119                 :       89564 :     generic_args (other.generic_args), locus (other.locus)
     120                 :       89564 : {}
     121                 :             : 
     122                 :             : PathExprSegment &
     123                 :           0 : PathExprSegment::operator= (PathExprSegment const &other)
     124                 :             : {
     125                 :           0 :   mappings = other.mappings;
     126                 :           0 :   segment_name = other.segment_name;
     127                 :           0 :   generic_args = other.generic_args;
     128                 :           0 :   locus = other.locus;
     129                 :             : 
     130                 :           0 :   return *this;
     131                 :             : }
     132                 :             : 
     133                 :             : void
     134                 :       37695 : PathPattern::iterate_path_segments (std::function<bool (PathExprSegment &)> cb)
     135                 :             : {
     136                 :       37695 :   rust_assert (kind == Kind::Segmented);
     137                 :             : 
     138                 :       77701 :   for (auto it = segments.begin (); it != segments.end (); it++)
     139                 :             :     {
     140                 :       40713 :       if (!cb (*it))
     141                 :       37695 :         return;
     142                 :             :     }
     143                 :             : }
     144                 :             : 
     145                 :       37702 : PathInExpression::PathInExpression (Analysis::NodeMapping mappings,
     146                 :             :                                     std::vector<PathExprSegment> path_segments,
     147                 :             :                                     location_t locus,
     148                 :             :                                     bool has_opening_scope_resolution,
     149                 :       37702 :                                     std::vector<AST::Attribute> outer_attrs)
     150                 :             :   : PathPattern (std::move (path_segments)),
     151                 :             :     PathExpr (std::move (mappings), std::move (outer_attrs)),
     152                 :       37702 :     has_opening_scope_resolution (has_opening_scope_resolution), locus (locus)
     153                 :       37702 : {}
     154                 :             : 
     155                 :         106 : PathInExpression::PathInExpression (Analysis::NodeMapping mappings,
     156                 :             :                                     LangItem::Kind lang_item, location_t locus,
     157                 :             :                                     bool has_opening_scope_resolution,
     158                 :         106 :                                     std::vector<AST::Attribute> outer_attrs)
     159                 :             :   : PathPattern (lang_item),
     160                 :             :     PathExpr (std::move (mappings), std::move (outer_attrs)),
     161                 :         106 :     has_opening_scope_resolution (has_opening_scope_resolution), locus (locus)
     162                 :         106 : {}
     163                 :             : 
     164                 :             : bool
     165                 :           0 : PathInExpression::is_self () const
     166                 :             : 
     167                 :             : {
     168                 :           0 :   if (!is_single_segment ())
     169                 :             :     return false;
     170                 :             : 
     171                 :           0 :   return get_final_segment ().get_segment ().as_string ().compare ("self") == 0;
     172                 :             : }
     173                 :             : 
     174                 :       48143 : TypePathSegment::TypePathSegment (Analysis::NodeMapping mappings,
     175                 :             :                                   PathIdentSegment ident_segment,
     176                 :             :                                   bool has_separating_scope_resolution,
     177                 :       48143 :                                   location_t locus)
     178                 :       96286 :   : mappings (std::move (mappings)), ident_segment (std::move (ident_segment)),
     179                 :       48143 :     lang_item (tl::nullopt), locus (locus),
     180                 :       48143 :     has_separating_scope_resolution (has_separating_scope_resolution),
     181                 :       48143 :     type (SegmentType::REG)
     182                 :       48143 : {}
     183                 :             : 
     184                 :         140 : TypePathSegment::TypePathSegment (Analysis::NodeMapping mappings,
     185                 :         140 :                                   LangItem::Kind lang_item, location_t locus)
     186                 :         140 :   : mappings (std::move (mappings)), ident_segment (tl::nullopt),
     187                 :         140 :     lang_item (lang_item), locus (locus),
     188                 :         140 :     has_separating_scope_resolution (false), type (SegmentType::REG)
     189                 :         140 : {}
     190                 :             : 
     191                 :           0 : TypePathSegment::TypePathSegment (Analysis::NodeMapping mappings,
     192                 :             :                                   std::string segment_name,
     193                 :             :                                   bool has_separating_scope_resolution,
     194                 :           0 :                                   location_t locus)
     195                 :           0 :   : mappings (std::move (mappings)),
     196                 :           0 :     ident_segment (PathIdentSegment (std::move (segment_name))),
     197                 :           0 :     lang_item (tl::nullopt), locus (locus),
     198                 :           0 :     has_separating_scope_resolution (has_separating_scope_resolution),
     199                 :           0 :     type (SegmentType::REG)
     200                 :           0 : {}
     201                 :             : 
     202                 :        2215 : TypePathSegmentGeneric::TypePathSegmentGeneric (
     203                 :             :   Analysis::NodeMapping mappings, PathIdentSegment ident_segment,
     204                 :             :   bool has_separating_scope_resolution, GenericArgs generic_args,
     205                 :        2215 :   location_t locus)
     206                 :             :   : TypePathSegment (std::move (mappings), std::move (ident_segment),
     207                 :             :                      has_separating_scope_resolution, locus),
     208                 :        2215 :     generic_args (std::move (generic_args))
     209                 :        2215 : {}
     210                 :             : 
     211                 :           5 : TypePathSegmentGeneric::TypePathSegmentGeneric (Analysis::NodeMapping mappings,
     212                 :             :                                                 LangItem::Kind lang_item,
     213                 :             :                                                 GenericArgs generic_args,
     214                 :           5 :                                                 location_t locus)
     215                 :             :   : TypePathSegment (std::move (mappings), lang_item, locus),
     216                 :           5 :     generic_args (std::move (generic_args))
     217                 :           5 : {}
     218                 :             : 
     219                 :           0 : TypePathSegmentGeneric::TypePathSegmentGeneric (
     220                 :             :   Analysis::NodeMapping mappings, std::string segment_name,
     221                 :             :   bool has_separating_scope_resolution, std::vector<Lifetime> lifetime_args,
     222                 :             :   std::vector<std::unique_ptr<Type> > type_args,
     223                 :             :   std::vector<GenericArgsBinding> binding_args,
     224                 :           0 :   std::vector<ConstGenericArg> const_args, location_t locus)
     225                 :             :   : TypePathSegment (std::move (mappings), std::move (segment_name),
     226                 :             :                      has_separating_scope_resolution, locus),
     227                 :           0 :     generic_args (GenericArgs (std::move (lifetime_args), std::move (type_args),
     228                 :             :                                std::move (binding_args), std::move (const_args),
     229                 :           0 :                                locus))
     230                 :           0 : {}
     231                 :             : 
     232                 :          30 : TypePathFunction::TypePathFunction (std::vector<std::unique_ptr<Type> > inputs,
     233                 :          30 :                                     std::unique_ptr<Type> type)
     234                 :          30 :   : inputs (std::move (inputs)), return_type (std::move (type))
     235                 :          30 : {}
     236                 :             : 
     237                 :          30 : TypePathFunction::TypePathFunction (TypePathFunction const &other)
     238                 :             : {
     239                 :          30 :   return_type = other.has_return_type ()
     240                 :          30 :                   ? other.get_return_type ().clone_type ()
     241                 :          30 :                   : nullptr;
     242                 :             : 
     243                 :          30 :   inputs.reserve (other.inputs.size ());
     244                 :          64 :   for (const auto &e : other.inputs)
     245                 :          34 :     inputs.push_back (e->clone_type ());
     246                 :          30 : }
     247                 :             : 
     248                 :             : TypePathFunction &
     249                 :           0 : TypePathFunction::operator= (TypePathFunction const &other)
     250                 :             : {
     251                 :           0 :   return_type = other.has_return_type ()
     252                 :           0 :                   ? other.get_return_type ().clone_type ()
     253                 :           0 :                   : nullptr;
     254                 :             : 
     255                 :           0 :   inputs.reserve (other.inputs.size ());
     256                 :           0 :   for (const auto &e : other.inputs)
     257                 :           0 :     inputs.push_back (e->clone_type ());
     258                 :             : 
     259                 :           0 :   return *this;
     260                 :             : }
     261                 :             : 
     262                 :          30 : TypePathSegmentFunction::TypePathSegmentFunction (
     263                 :             :   Analysis::NodeMapping mappings, PathIdentSegment ident_segment,
     264                 :             :   bool has_separating_scope_resolution, TypePathFunction function_path,
     265                 :          30 :   location_t locus)
     266                 :             :   : TypePathSegment (std::move (mappings), std::move (ident_segment),
     267                 :             :                      has_separating_scope_resolution, locus),
     268                 :          30 :     function_path (std::move (function_path))
     269                 :          30 : {}
     270                 :             : 
     271                 :           0 : TypePathSegmentFunction::TypePathSegmentFunction (
     272                 :             :   Analysis::NodeMapping mappings, std::string segment_name,
     273                 :             :   bool has_separating_scope_resolution, TypePathFunction function_path,
     274                 :           0 :   location_t locus)
     275                 :             :   : TypePathSegment (std::move (mappings), std::move (segment_name),
     276                 :             :                      has_separating_scope_resolution, locus),
     277                 :           0 :     function_path (std::move (function_path))
     278                 :           0 : {}
     279                 :             : 
     280                 :       47332 : TypePath::TypePath (Analysis::NodeMapping mappings,
     281                 :             :                     std::vector<std::unique_ptr<TypePathSegment> > segments,
     282                 :       47332 :                     location_t locus, bool has_opening_scope_resolution)
     283                 :             :   : TypeNoBounds (mappings, locus),
     284                 :       47332 :     has_opening_scope_resolution (has_opening_scope_resolution),
     285                 :       47332 :     segments (std::move (segments))
     286                 :       47332 : {}
     287                 :             : 
     288                 :       13509 : TypePath::TypePath (TypePath const &other)
     289                 :       13509 :   : TypeNoBounds (other.mappings, other.locus),
     290                 :       13509 :     has_opening_scope_resolution (other.has_opening_scope_resolution)
     291                 :             : {
     292                 :       13509 :   segments.reserve (other.segments.size ());
     293                 :       26992 :   for (const auto &e : other.segments)
     294                 :       13483 :     segments.push_back (e->clone_type_path_segment ());
     295                 :       13509 : }
     296                 :             : 
     297                 :             : TypePath &
     298                 :           0 : TypePath::operator= (TypePath const &other)
     299                 :             : {
     300                 :           0 :   has_opening_scope_resolution = other.has_opening_scope_resolution;
     301                 :           0 :   locus = other.locus;
     302                 :           0 :   mappings = other.mappings;
     303                 :             : 
     304                 :           0 :   segments.reserve (other.segments.size ());
     305                 :           0 :   for (const auto &e : other.segments)
     306                 :           0 :     segments.push_back (e->clone_type_path_segment ());
     307                 :             : 
     308                 :           0 :   return *this;
     309                 :             : }
     310                 :             : 
     311                 :         407 : QualifiedPathType::QualifiedPathType (Analysis::NodeMapping mappings,
     312                 :             :                                       std::unique_ptr<Type> type,
     313                 :             :                                       std::unique_ptr<TypePath> trait,
     314                 :         407 :                                       location_t locus)
     315                 :         407 :   : type (std::move (type)), trait (std::move (trait)), locus (locus),
     316                 :         407 :     mappings (mappings)
     317                 :         407 : {}
     318                 :             : 
     319                 :         596 : QualifiedPathType::QualifiedPathType (QualifiedPathType const &other)
     320                 :         596 :   : type (other.type->clone_type ()),
     321                 :         596 :     trait (other.has_as_clause ()
     322                 :         596 :              ? std::unique_ptr<HIR::TypePath> (new HIR::TypePath (*other.trait))
     323                 :             :              : nullptr),
     324                 :         596 :     locus (other.locus), mappings (other.mappings)
     325                 :         596 : {}
     326                 :             : 
     327                 :             : QualifiedPathType &
     328                 :           0 : QualifiedPathType::operator= (QualifiedPathType const &other)
     329                 :             : {
     330                 :           0 :   type = other.type->clone_type ();
     331                 :           0 :   locus = other.locus;
     332                 :           0 :   mappings = other.mappings;
     333                 :           0 :   trait = other.has_as_clause ()
     334                 :           0 :             ? std::unique_ptr<HIR::TypePath> (new HIR::TypePath (*other.trait))
     335                 :           0 :             : nullptr;
     336                 :             : 
     337                 :           0 :   return *this;
     338                 :             : }
     339                 :             : 
     340                 :             : bool
     341                 :           0 : QualifiedPathType::trait_has_generic_args () const
     342                 :             : {
     343                 :           0 :   rust_assert (has_as_clause ());
     344                 :           0 :   bool is_generic_seg = trait->get_final_segment ().get_type ()
     345                 :           0 :                         == TypePathSegment::SegmentType::GENERIC;
     346                 :           0 :   if (!is_generic_seg)
     347                 :             :     return false;
     348                 :             : 
     349                 :           0 :   auto &seg
     350                 :           0 :     = static_cast<TypePathSegmentGeneric &> (trait->get_final_segment ());
     351                 :           0 :   return seg.has_generic_args ();
     352                 :             : }
     353                 :             : 
     354                 :             : GenericArgs &
     355                 :           0 : QualifiedPathType::get_trait_generic_args ()
     356                 :             : {
     357                 :           0 :   rust_assert (trait_has_generic_args ());
     358                 :           0 :   auto &seg
     359                 :           0 :     = static_cast<TypePathSegmentGeneric &> (trait->get_final_segment ());
     360                 :           0 :   return seg.get_generic_args ();
     361                 :             : }
     362                 :             : 
     363                 :         131 : QualifiedPathInExpression::QualifiedPathInExpression (
     364                 :             :   Analysis::NodeMapping mappings, QualifiedPathType qual_path_type,
     365                 :             :   std::vector<PathExprSegment> path_segments, location_t locus,
     366                 :         131 :   std::vector<AST::Attribute> outer_attrs)
     367                 :             :   : PathPattern (std::move (path_segments)),
     368                 :             :     PathExpr (std::move (mappings), std::move (outer_attrs)),
     369                 :         131 :     path_type (std::move (qual_path_type)), locus (locus)
     370                 :         131 : {}
     371                 :             : 
     372                 :           0 : QualifiedPathInExpression::QualifiedPathInExpression (
     373                 :             :   Analysis::NodeMapping mappings, QualifiedPathType qual_path_type,
     374                 :             :   LangItem::Kind lang_item, location_t locus,
     375                 :           0 :   std::vector<AST::Attribute> outer_attrs)
     376                 :             :   : PathPattern (lang_item),
     377                 :             :     PathExpr (std::move (mappings), std::move (outer_attrs)),
     378                 :           0 :     path_type (std::move (qual_path_type)), locus (locus)
     379                 :           0 : {}
     380                 :             : 
     381                 :         276 : QualifiedPathInType::QualifiedPathInType (
     382                 :             :   Analysis::NodeMapping mappings, QualifiedPathType qual_path_type,
     383                 :             :   std::unique_ptr<TypePathSegment> associated_segment,
     384                 :             :   std::vector<std::unique_ptr<TypePathSegment> > path_segments,
     385                 :         276 :   location_t locus)
     386                 :         276 :   : TypeNoBounds (mappings, locus), path_type (std::move (qual_path_type)),
     387                 :         276 :     associated_segment (std::move (associated_segment)),
     388                 :         276 :     segments (std::move (path_segments))
     389                 :         276 : {}
     390                 :             : 
     391                 :          59 : QualifiedPathInType::QualifiedPathInType (QualifiedPathInType const &other)
     392                 :          59 :   : TypeNoBounds (other.mappings, other.locus), path_type (other.path_type)
     393                 :             : {
     394                 :          59 :   auto seg = other.associated_segment->clone_type_path_segment_impl ();
     395                 :          59 :   associated_segment = std::unique_ptr<TypePathSegment> (seg);
     396                 :             : 
     397                 :          59 :   segments.reserve (other.segments.size ());
     398                 :          59 :   for (const auto &e : other.segments)
     399                 :           0 :     segments.push_back (e->clone_type_path_segment ());
     400                 :          59 : }
     401                 :             : 
     402                 :             : QualifiedPathInType &
     403                 :           0 : QualifiedPathInType::operator= (QualifiedPathInType const &other)
     404                 :             : {
     405                 :           0 :   auto seg = other.associated_segment->clone_type_path_segment_impl ();
     406                 :           0 :   associated_segment = std::unique_ptr<TypePathSegment> (seg);
     407                 :             : 
     408                 :           0 :   path_type = other.path_type;
     409                 :           0 :   locus = other.locus;
     410                 :           0 :   mappings = other.mappings;
     411                 :             : 
     412                 :           0 :   segments.reserve (other.segments.size ());
     413                 :           0 :   for (const auto &e : other.segments)
     414                 :           0 :     segments.push_back (e->clone_type_path_segment ());
     415                 :             : 
     416                 :           0 :   return *this;
     417                 :             : }
     418                 :             : 
     419                 :             : } // namespace HIR
     420                 :             : } // namespace Rust
        

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.