LCOV - code coverage report
Current view: top level - gcc/rust/resolve - rust-ast-resolve-type.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.4 % 83 80
Test Date: 2024-04-20 14:03:02 Functions: 92.3 % 13 12
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_TYPE_H
      20                 :             : #define RUST_AST_RESOLVE_TYPE_H
      21                 :             : 
      22                 :             : #include "rust-ast-resolve-base.h"
      23                 :             : #include "rust-ast-resolve-expr.h"
      24                 :             : 
      25                 :             : namespace Rust {
      26                 :             : namespace Resolver {
      27                 :             : 
      28                 :             : class ResolveRelativeTypePath
      29                 :             : {
      30                 :             : public:
      31                 :             :   static bool go (AST::TypePath &path, NodeId &resolved_node_id);
      32                 :             : };
      33                 :             : 
      34                 :         159 : class ResolveRelativeQualTypePath : public ResolverBase
      35                 :             : {
      36                 :             :   using ResolverBase::visit;
      37                 :             : 
      38                 :             : public:
      39                 :             :   static bool go (AST::QualifiedPathInType &path);
      40                 :             : 
      41                 :             :   void visit (AST::TypePathSegmentGeneric &seg) override;
      42                 :             : 
      43                 :             :   void visit (AST::TypePathSegment &seg) override;
      44                 :             : 
      45                 :             : protected:
      46                 :             :   bool resolve_qual_seg (AST::QualifiedPathType &seg);
      47                 :             : 
      48                 :             : private:
      49                 :             :   ResolveRelativeQualTypePath ();
      50                 :             : 
      51                 :             :   bool failure_flag;
      52                 :             : };
      53                 :             : 
      54                 :       42637 : class ResolveType : public ResolverBase
      55                 :             : {
      56                 :             :   using Rust::Resolver::ResolverBase::visit;
      57                 :             : 
      58                 :             : public:
      59                 :       42637 :   static NodeId go (AST::Type *type)
      60                 :             :   {
      61                 :       85274 :     ResolveType resolver;
      62                 :       42637 :     type->accept_vis (resolver);
      63                 :       42637 :     return resolver.resolved_node;
      64                 :       42637 :   }
      65                 :             : 
      66                 :          36 :   void visit (AST::BareFunctionType &fntype) override
      67                 :             :   {
      68                 :          69 :     for (auto &param : fntype.get_function_params ())
      69                 :          33 :       ResolveType::go (param.get_type ().get ());
      70                 :             : 
      71                 :          36 :     if (fntype.has_return_type ())
      72                 :          32 :       ResolveType::go (fntype.get_return_type ().get ());
      73                 :          36 :   }
      74                 :             : 
      75                 :         248 :   void visit (AST::TupleType &tuple) override
      76                 :             :   {
      77                 :         248 :     if (tuple.is_unit_type ())
      78                 :             :       {
      79                 :          57 :         resolved_node = resolver->get_unit_type_node_id ();
      80                 :          57 :         return;
      81                 :             :       }
      82                 :             : 
      83                 :         587 :     for (auto &elem : tuple.get_elems ())
      84                 :         396 :       ResolveType::go (elem.get ());
      85                 :             :   }
      86                 :             : 
      87                 :       34556 :   void visit (AST::TypePath &path) override
      88                 :             :   {
      89                 :       34556 :     ResolveRelativeTypePath::go (path, resolved_node);
      90                 :       34556 :   }
      91                 :             : 
      92                 :         159 :   void visit (AST::QualifiedPathInType &path) override
      93                 :             :   {
      94                 :         159 :     ResolveRelativeQualTypePath::go (path);
      95                 :         159 :   }
      96                 :             : 
      97                 :             :   void visit (AST::ArrayType &type) override;
      98                 :             : 
      99                 :             :   void visit (AST::ReferenceType &type) override;
     100                 :             : 
     101                 :             :   void visit (AST::InferredType &type) override;
     102                 :             : 
     103                 :             :   void visit (AST::NeverType &type) override;
     104                 :             : 
     105                 :             :   void visit (AST::RawPointerType &type) override;
     106                 :             : 
     107                 :             :   void visit (AST::TraitObjectTypeOneBound &type) override;
     108                 :             : 
     109                 :             :   void visit (AST::TraitObjectType &type) override;
     110                 :             : 
     111                 :             :   void visit (AST::SliceType &type) override;
     112                 :             : 
     113                 :             : private:
     114                 :       42637 :   ResolveType () : ResolverBase () {}
     115                 :             : };
     116                 :             : 
     117                 :         614 : class ResolveTypeBound : public ResolverBase
     118                 :             : {
     119                 :             :   using Rust::Resolver::ResolverBase::visit;
     120                 :             : 
     121                 :             : public:
     122                 :         614 :   static NodeId go (AST::TypeParamBound *type)
     123                 :             :   {
     124                 :        1228 :     ResolveTypeBound resolver;
     125                 :         614 :     type->accept_vis (resolver);
     126                 :         614 :     return resolver.resolved_node;
     127                 :         614 :   };
     128                 :             : 
     129                 :         602 :   void visit (AST::TraitBound &bound) override
     130                 :             :   {
     131                 :         602 :     resolved_node = ResolveType::go (&bound.get_type_path ());
     132                 :         602 :   }
     133                 :             : 
     134                 :             : private:
     135                 :         614 :   ResolveTypeBound () : ResolverBase () {}
     136                 :             : };
     137                 :             : 
     138                 :        5004 : class ResolveGenericParam : public ResolverBase
     139                 :             : {
     140                 :             :   using Rust::Resolver::ResolverBase::visit;
     141                 :             : 
     142                 :             : public:
     143                 :        5004 :   static NodeId go (AST::GenericParam *param, const CanonicalPath &prefix,
     144                 :             :                     const CanonicalPath &canonical_prefix)
     145                 :             :   {
     146                 :       10008 :     ResolveGenericParam resolver (prefix, canonical_prefix);
     147                 :        5004 :     param->accept_vis (resolver);
     148                 :        5004 :     return resolver.resolved_node;
     149                 :        5004 :   }
     150                 :             : 
     151                 :          28 :   void visit (AST::ConstGenericParam &param) override
     152                 :             :   {
     153                 :          28 :     ResolveType::go (param.get_type ().get ());
     154                 :             : 
     155                 :          28 :     if (param.has_default_value ())
     156                 :          16 :       ResolveExpr::go (param.get_default_value ().get_expression ().get (),
     157                 :             :                        prefix, canonical_prefix);
     158                 :             : 
     159                 :          28 :     ok = true;
     160                 :          28 :   }
     161                 :             : 
     162                 :        4851 :   void visit (AST::TypeParam &param) override
     163                 :             :   {
     164                 :             :     // if it has a type lets resolve it
     165                 :        4851 :     if (param.has_type ())
     166                 :         105 :       ResolveType::go (param.get_type ().get ());
     167                 :             : 
     168                 :        4851 :     if (param.has_type_param_bounds ())
     169                 :             :       {
     170                 :         502 :         for (auto &bound : param.get_type_param_bounds ())
     171                 :             :           {
     172                 :         252 :             ResolveTypeBound::go (bound.get ());
     173                 :             :           }
     174                 :             :       }
     175                 :             : 
     176                 :        4851 :     auto seg
     177                 :             :       = CanonicalPath::new_seg (param.get_node_id (),
     178                 :        4851 :                                 param.get_type_representation ().as_string ());
     179                 :        4851 :     resolver->get_type_scope ().insert (
     180                 :             :       seg, param.get_node_id (), param.get_locus (), false, Rib::ItemType::Type,
     181                 :        4851 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     182                 :           0 :         rust_error_at (param.get_locus (),
     183                 :             :                        "generic param redefined multiple times");
     184                 :           0 :         rust_error_at (locus, "was defined here");
     185                 :           0 :       });
     186                 :             : 
     187                 :        4851 :     mappings->insert_canonical_path (param.get_node_id (), seg);
     188                 :        4851 :   }
     189                 :             : 
     190                 :             : private:
     191                 :        5004 :   ResolveGenericParam (const CanonicalPath &prefix,
     192                 :             :                        const CanonicalPath &canonical_prefix)
     193                 :       10008 :     : ResolverBase (), ok (false), prefix (prefix),
     194                 :        5004 :       canonical_prefix (canonical_prefix)
     195                 :             :   {}
     196                 :             : 
     197                 :             :   bool ok;
     198                 :             :   const CanonicalPath &prefix;
     199                 :             :   const CanonicalPath &canonical_prefix;
     200                 :             : };
     201                 :             : 
     202                 :          80 : class ResolveWhereClause : public ResolverBase
     203                 :             : {
     204                 :             :   using Rust::Resolver::ResolverBase::visit;
     205                 :             : 
     206                 :             : public:
     207                 :          80 :   static void Resolve (AST::WhereClause &where_clause)
     208                 :             :   {
     209                 :         160 :     ResolveWhereClause r;
     210                 :         162 :     for (auto &clause : where_clause.get_items ())
     211                 :          82 :       clause->accept_vis (r);
     212                 :          80 :   }
     213                 :             : 
     214                 :          82 :   void visit (AST::TypeBoundWhereClauseItem &item) override
     215                 :             :   {
     216                 :          82 :     ResolveType::go (item.get_type ().get ());
     217                 :          82 :     if (item.has_type_param_bounds ())
     218                 :             :       {
     219                 :         164 :         for (auto &bound : item.get_type_param_bounds ())
     220                 :             :           {
     221                 :          82 :             ResolveTypeBound::go (bound.get ());
     222                 :             :           }
     223                 :             :       }
     224                 :          82 :   }
     225                 :             : 
     226                 :             : private:
     227                 :          80 :   ResolveWhereClause () : ResolverBase () {}
     228                 :             : };
     229                 :             : 
     230                 :        6506 : class ResolveTypeToCanonicalPath : public ResolverBase
     231                 :             : {
     232                 :             :   using Rust::Resolver::ResolverBase::visit;
     233                 :             : 
     234                 :             : public:
     235                 :             :   static bool go (AST::Type *type, CanonicalPath &result);
     236                 :             : 
     237                 :             :   void visit (AST::TypePath &path) override;
     238                 :             : 
     239                 :             :   void visit (AST::ReferenceType &type) override;
     240                 :             : 
     241                 :             :   void visit (AST::RawPointerType &type) override;
     242                 :             : 
     243                 :             :   void visit (AST::SliceType &type) override;
     244                 :             : 
     245                 :             :   void visit (AST::TraitObjectTypeOneBound &type) override;
     246                 :             : 
     247                 :             :   void visit (AST::TraitObjectType &type) override;
     248                 :             : 
     249                 :             : private:
     250                 :             :   ResolveTypeToCanonicalPath ();
     251                 :             : 
     252                 :             :   CanonicalPath result;
     253                 :             : };
     254                 :             : 
     255                 :        2521 : class ResolveGenericArgs : public ResolverBase
     256                 :             : {
     257                 :             :   using Rust::Resolver::ResolverBase::visit;
     258                 :             : 
     259                 :             : public:
     260                 :             :   static void go (AST::GenericArgs &generic_args);
     261                 :             :   static void go (AST::GenericArgs &generic_args, const CanonicalPath &prefix,
     262                 :             :                   const CanonicalPath &canonical_prefix);
     263                 :             : 
     264                 :             : private:
     265                 :        2521 :   ResolveGenericArgs (const CanonicalPath &prefix,
     266                 :             :                       const CanonicalPath &canonical_prefix)
     267                 :        2521 :     : ResolverBase (), prefix (prefix), canonical_prefix (canonical_prefix)
     268                 :             :   {}
     269                 :             : 
     270                 :             :   bool is_type_name (const CanonicalPath &path);
     271                 :             :   bool is_const_value_name (const CanonicalPath &path);
     272                 :             : 
     273                 :             :   /**
     274                 :             :    * Resolve a disambiguated generic arg
     275                 :             :    */
     276                 :             :   void disambiguate (AST::GenericArg &arg);
     277                 :             : 
     278                 :             :   /**
     279                 :             :    * Resolve a disambiguated generic arg
     280                 :             :    */
     281                 :             :   void resolve_disambiguated_generic (AST::GenericArg &arg);
     282                 :             : 
     283                 :             :   const CanonicalPath &prefix;
     284                 :             :   const CanonicalPath &canonical_prefix;
     285                 :             : };
     286                 :             : 
     287                 :             : } // namespace Resolver
     288                 :             : } // namespace Rust
     289                 :             : 
     290                 :             : #endif // RUST_AST_RESOLVE_TYPE_H
        

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.