LCOV - code coverage report
Current view: top level - gcc/rust/hir/tree - rust-hir-item.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 56.6 % 790 447
Test Date: 2024-04-13 14:00:49 Functions: 53.7 % 175 94
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_HIR_ITEM_H
      20                 :             : #define RUST_HIR_ITEM_H
      21                 :             : 
      22                 :             : #include "rust-abi.h"
      23                 :             : #include "rust-ast-full-decls.h"
      24                 :             : #include "rust-common.h"
      25                 :             : #include "rust-hir-expr.h"
      26                 :             : #include "rust-hir.h"
      27                 :             : #include "rust-hir-path.h"
      28                 :             : 
      29                 :             : namespace Rust {
      30                 :             : namespace HIR {
      31                 :             : // forward decls
      32                 :             : class BlockExpr;
      33                 :             : class TypePath;
      34                 :             : 
      35                 :             : // A type generic parameter (as opposed to a lifetime generic parameter)
      36                 :             : class TypeParam : public GenericParam
      37                 :             : {
      38                 :             :   // bool has_outer_attribute;
      39                 :             :   // std::unique_ptr<Attribute> outer_attr;
      40                 :             :   AST::Attribute outer_attr;
      41                 :             : 
      42                 :             :   Identifier type_representation;
      43                 :             : 
      44                 :             :   // bool has_type_param_bounds;
      45                 :             :   // TypeParamBounds type_param_bounds;
      46                 :             :   std::vector<std::unique_ptr<TypeParamBound>>
      47                 :             :     type_param_bounds; // inlined form
      48                 :             : 
      49                 :             :   // bool has_type;
      50                 :             :   std::unique_ptr<Type> type;
      51                 :             : 
      52                 :             :   location_t locus;
      53                 :             : 
      54                 :             : public:
      55                 :             :   // Returns whether the type of the type param has been specified.
      56                 :       20236 :   bool has_type () const { return type != nullptr; }
      57                 :             : 
      58                 :             :   // Returns whether the type param has type param bounds.
      59                 :       16862 :   bool has_type_param_bounds () const { return !type_param_bounds.empty (); }
      60                 :             : 
      61                 :             :   // Returns whether the type param has an outer attribute.
      62                 :           0 :   bool has_outer_attribute () const { return !outer_attr.is_empty (); }
      63                 :           0 :   AST::Attribute &get_outer_attribute () { return outer_attr; }
      64                 :             : 
      65                 :        4839 :   TypeParam (Analysis::NodeMapping mappings, Identifier type_representation,
      66                 :             :              location_t locus = UNDEF_LOCATION,
      67                 :             :              std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds
      68                 :             :              = std::vector<std::unique_ptr<TypeParamBound>> (),
      69                 :             :              std::unique_ptr<Type> type = nullptr,
      70                 :             :              AST::Attribute outer_attr = AST::Attribute::create_empty ())
      71                 :        4839 :     : GenericParam (mappings), outer_attr (std::move (outer_attr)),
      72                 :        4839 :       type_representation (std::move (type_representation)),
      73                 :        4839 :       type_param_bounds (std::move (type_param_bounds)),
      74                 :        4839 :       type (std::move (type)), locus (locus)
      75                 :        4839 :   {}
      76                 :             : 
      77                 :             :   // Copy constructor uses clone
      78                 :           0 :   TypeParam (TypeParam const &other)
      79                 :           0 :     : GenericParam (other.mappings), outer_attr (other.outer_attr),
      80                 :           0 :       type_representation (other.type_representation), locus (other.locus)
      81                 :             :   {
      82                 :             :     // guard to prevent null pointer dereference
      83                 :           0 :     if (other.type != nullptr)
      84                 :           0 :       type = other.type->clone_type ();
      85                 :             : 
      86                 :           0 :     type_param_bounds.reserve (other.type_param_bounds.size ());
      87                 :           0 :     for (const auto &e : other.type_param_bounds)
      88                 :           0 :       type_param_bounds.push_back (e->clone_type_param_bound ());
      89                 :           0 :   }
      90                 :             : 
      91                 :             :   // Overloaded assignment operator to clone
      92                 :             :   TypeParam &operator= (TypeParam const &other)
      93                 :             :   {
      94                 :             :     type_representation = other.type_representation;
      95                 :             :     outer_attr = other.outer_attr;
      96                 :             :     locus = other.locus;
      97                 :             :     mappings = other.mappings;
      98                 :             : 
      99                 :             :     // guard to prevent null pointer dereference
     100                 :             :     if (other.type != nullptr)
     101                 :             :       type = other.type->clone_type ();
     102                 :             :     else
     103                 :             :       type = nullptr;
     104                 :             : 
     105                 :             :     type_param_bounds.reserve (other.type_param_bounds.size ());
     106                 :             :     for (const auto &e : other.type_param_bounds)
     107                 :             :       type_param_bounds.push_back (e->clone_type_param_bound ());
     108                 :             : 
     109                 :             :     return *this;
     110                 :             :   }
     111                 :             :   // move constructors
     112                 :             :   TypeParam (TypeParam &&other) = default;
     113                 :             :   TypeParam &operator= (TypeParam &&other) = default;
     114                 :             : 
     115                 :             :   std::string as_string () const override;
     116                 :             : 
     117                 :       19623 :   location_t get_locus () const override final { return locus; }
     118                 :             : 
     119                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     120                 :             : 
     121                 :       11148 :   Identifier get_type_representation () const { return type_representation; }
     122                 :             : 
     123                 :         102 :   std::unique_ptr<Type> &get_type () { return type; }
     124                 :             : 
     125                 :         243 :   Analysis::NodeMapping get_type_mappings () const
     126                 :             :   {
     127                 :         243 :     rust_assert (type != nullptr);
     128                 :         243 :     return type->get_mappings ();
     129                 :             :   }
     130                 :             : 
     131                 :           0 :   std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ()
     132                 :             :   {
     133                 :           0 :     return type_param_bounds;
     134                 :             :   }
     135                 :             : 
     136                 :             : protected:
     137                 :             :   // Clone function implementation as (not pure) virtual method
     138                 :           0 :   TypeParam *clone_generic_param_impl () const override
     139                 :             :   {
     140                 :           0 :     return new TypeParam (*this);
     141                 :             :   }
     142                 :             : };
     143                 :             : 
     144                 :             : /* "where" clause item base. Abstract - use LifetimeWhereClauseItem,
     145                 :             :  * TypeBoundWhereClauseItem */
     146                 :         147 : class WhereClauseItem : public FullVisitable
     147                 :             : {
     148                 :             : public:
     149                 :             :   enum ItemType
     150                 :             :   {
     151                 :             :     LIFETIME,
     152                 :             :     TYPE_BOUND,
     153                 :             :   };
     154                 :             : 
     155                 :             :   virtual ~WhereClauseItem () {}
     156                 :             : 
     157                 :             :   // Unique pointer custom clone function
     158                 :          66 :   std::unique_ptr<WhereClauseItem> clone_where_clause_item () const
     159                 :             :   {
     160                 :          66 :     return std::unique_ptr<WhereClauseItem> (clone_where_clause_item_impl ());
     161                 :             :   }
     162                 :             : 
     163                 :             :   virtual std::string as_string () const = 0;
     164                 :             : 
     165                 :             :   virtual void accept_vis (HIRFullVisitor &vis) = 0;
     166                 :             : 
     167                 :             :   virtual Analysis::NodeMapping get_mappings () const = 0;
     168                 :             : 
     169                 :             :   virtual ItemType get_item_type () const = 0;
     170                 :             : 
     171                 :             : protected:
     172                 :             :   // Clone function implementation as pure virtual method
     173                 :             :   virtual WhereClauseItem *clone_where_clause_item_impl () const = 0;
     174                 :             : };
     175                 :             : 
     176                 :             : // A lifetime where clause item
     177                 :             : class LifetimeWhereClauseItem : public WhereClauseItem
     178                 :             : {
     179                 :             :   Lifetime lifetime;
     180                 :             :   std::vector<Lifetime> lifetime_bounds;
     181                 :             :   location_t locus;
     182                 :             :   Analysis::NodeMapping mappings;
     183                 :             : 
     184                 :             : public:
     185                 :           0 :   LifetimeWhereClauseItem (Analysis::NodeMapping mappings, Lifetime lifetime,
     186                 :             :                            std::vector<Lifetime> lifetime_bounds,
     187                 :             :                            location_t locus)
     188                 :           0 :     : lifetime (std::move (lifetime)),
     189                 :           0 :       lifetime_bounds (std::move (lifetime_bounds)), locus (locus),
     190                 :           0 :       mappings (std::move (mappings))
     191                 :           0 :   {}
     192                 :             : 
     193                 :             :   std::string as_string () const override;
     194                 :             : 
     195                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     196                 :             : 
     197                 :           0 :   Lifetime &get_lifetime () { return lifetime; }
     198                 :             : 
     199                 :           0 :   std::vector<Lifetime> &get_lifetime_bounds () { return lifetime_bounds; }
     200                 :             : 
     201                 :           0 :   Analysis::NodeMapping get_mappings () const override final
     202                 :             :   {
     203                 :           0 :     return mappings;
     204                 :             :   };
     205                 :             : 
     206                 :           0 :   ItemType get_item_type () const override final
     207                 :             :   {
     208                 :           0 :     return WhereClauseItem::ItemType::LIFETIME;
     209                 :             :   }
     210                 :             : 
     211                 :             : protected:
     212                 :             :   // Clone function implementation as (not pure) virtual method
     213                 :           0 :   LifetimeWhereClauseItem *clone_where_clause_item_impl () const override
     214                 :             :   {
     215                 :           0 :     return new LifetimeWhereClauseItem (*this);
     216                 :             :   }
     217                 :             : };
     218                 :             : 
     219                 :             : // A type bound where clause item
     220                 :             : class TypeBoundWhereClauseItem : public WhereClauseItem
     221                 :             : {
     222                 :             :   std::vector<LifetimeParam> for_lifetimes;
     223                 :             :   std::unique_ptr<Type> bound_type;
     224                 :             :   std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds;
     225                 :             :   Analysis::NodeMapping mappings;
     226                 :             :   location_t locus;
     227                 :             : 
     228                 :             : public:
     229                 :             :   // Returns whether the item has ForLifetimes
     230                 :         436 :   bool has_for_lifetimes () const { return !for_lifetimes.empty (); }
     231                 :             : 
     232                 :             :   // Returns whether the item has type param bounds
     233                 :             :   bool has_type_param_bounds () const { return !type_param_bounds.empty (); }
     234                 :             : 
     235                 :          81 :   TypeBoundWhereClauseItem (
     236                 :             :     Analysis::NodeMapping mappings, std::vector<LifetimeParam> for_lifetimes,
     237                 :             :     std::unique_ptr<Type> bound_type,
     238                 :             :     std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
     239                 :             :     location_t locus)
     240                 :          81 :     : for_lifetimes (std::move (for_lifetimes)),
     241                 :          81 :       bound_type (std::move (bound_type)),
     242                 :          81 :       type_param_bounds (std::move (type_param_bounds)),
     243                 :          81 :       mappings (std::move (mappings)), locus (locus)
     244                 :             :   {}
     245                 :             : 
     246                 :             :   // Copy constructor requires clone
     247                 :          66 :   TypeBoundWhereClauseItem (TypeBoundWhereClauseItem const &other)
     248                 :          66 :     : for_lifetimes (other.for_lifetimes),
     249                 :          66 :       bound_type (other.bound_type->clone_type ()), mappings (other.mappings)
     250                 :             :   {
     251                 :          66 :     type_param_bounds.reserve (other.type_param_bounds.size ());
     252                 :         132 :     for (const auto &e : other.type_param_bounds)
     253                 :          66 :       type_param_bounds.push_back (e->clone_type_param_bound ());
     254                 :          66 :   }
     255                 :             : 
     256                 :             :   // Overload assignment operator to clone
     257                 :             :   TypeBoundWhereClauseItem &operator= (TypeBoundWhereClauseItem const &other)
     258                 :             :   {
     259                 :             :     mappings = other.mappings;
     260                 :             :     for_lifetimes = other.for_lifetimes;
     261                 :             :     bound_type = other.bound_type->clone_type ();
     262                 :             :     type_param_bounds.reserve (other.type_param_bounds.size ());
     263                 :             :     for (const auto &e : other.type_param_bounds)
     264                 :             :       type_param_bounds.push_back (e->clone_type_param_bound ());
     265                 :             : 
     266                 :             :     return *this;
     267                 :             :   }
     268                 :             : 
     269                 :             :   // move constructors
     270                 :             :   TypeBoundWhereClauseItem (TypeBoundWhereClauseItem &&other) = default;
     271                 :             :   TypeBoundWhereClauseItem &operator= (TypeBoundWhereClauseItem &&other)
     272                 :             :     = default;
     273                 :             : 
     274                 :             :   location_t get_locus () const { return locus; }
     275                 :             : 
     276                 :             :   std::string as_string () const override;
     277                 :             : 
     278                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     279                 :             : 
     280                 :           0 :   std::vector<LifetimeParam> &get_for_lifetimes () { return for_lifetimes; }
     281                 :             : 
     282                 :         436 :   std::unique_ptr<Type> &get_bound_type () { return bound_type; }
     283                 :             : 
     284                 :           0 :   std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ()
     285                 :             :   {
     286                 :         436 :     return type_param_bounds;
     287                 :             :   }
     288                 :             : 
     289                 :           0 :   Analysis::NodeMapping get_mappings () const override final
     290                 :             :   {
     291                 :           0 :     return mappings;
     292                 :             :   };
     293                 :             : 
     294                 :         436 :   ItemType get_item_type () const override final
     295                 :             :   {
     296                 :         436 :     return WhereClauseItem::ItemType::TYPE_BOUND;
     297                 :             :   }
     298                 :             : 
     299                 :             : protected:
     300                 :             :   // Clone function implementation as (not pure) virtual method
     301                 :          66 :   TypeBoundWhereClauseItem *clone_where_clause_item_impl () const override
     302                 :             :   {
     303                 :          66 :     return new TypeBoundWhereClauseItem (*this);
     304                 :             :   }
     305                 :             : };
     306                 :             : 
     307                 :             : // A where clause
     308                 :       41134 : struct WhereClause
     309                 :             : {
     310                 :             : private:
     311                 :             :   std::vector<std::unique_ptr<WhereClauseItem>> where_clause_items;
     312                 :             : 
     313                 :             :   // should this store location info?
     314                 :             : 
     315                 :             : public:
     316                 :       22415 :   WhereClause (std::vector<std::unique_ptr<WhereClauseItem>> where_clause_items)
     317                 :       22415 :     : where_clause_items (std::move (where_clause_items))
     318                 :             :   {}
     319                 :             : 
     320                 :             :   // copy constructor with vector clone
     321                 :        5083 :   WhereClause (WhereClause const &other)
     322                 :        5083 :   {
     323                 :        5083 :     where_clause_items.reserve (other.where_clause_items.size ());
     324                 :        5149 :     for (const auto &e : other.where_clause_items)
     325                 :          66 :       where_clause_items.push_back (e->clone_where_clause_item ());
     326                 :        5083 :   }
     327                 :             : 
     328                 :             :   // overloaded assignment operator with vector clone
     329                 :             :   WhereClause &operator= (WhereClause const &other)
     330                 :             :   {
     331                 :             :     where_clause_items.reserve (other.where_clause_items.size ());
     332                 :             :     for (const auto &e : other.where_clause_items)
     333                 :             :       where_clause_items.push_back (e->clone_where_clause_item ());
     334                 :             : 
     335                 :             :     return *this;
     336                 :             :   }
     337                 :             : 
     338                 :             :   // move constructors
     339                 :       21031 :   WhereClause (WhereClause &&other) = default;
     340                 :             :   WhereClause &operator= (WhereClause &&other) = default;
     341                 :             : 
     342                 :             :   // Creates a WhereClause with no items.
     343                 :             :   static WhereClause create_empty ()
     344                 :             :   {
     345                 :             :     return WhereClause (std::vector<std::unique_ptr<WhereClauseItem>> ());
     346                 :             :   }
     347                 :             : 
     348                 :             :   // Returns whether the WhereClause has no items.
     349                 :        6907 :   bool is_empty () const { return where_clause_items.empty (); }
     350                 :             : 
     351                 :             :   std::string as_string () const;
     352                 :             : 
     353                 :             :   std::vector<std::unique_ptr<WhereClauseItem>> &get_items ()
     354                 :             :   {
     355                 :       22817 :     return where_clause_items;
     356                 :             :   }
     357                 :             :   const std::vector<std::unique_ptr<WhereClauseItem>> &get_items () const
     358                 :             :   {
     359                 :             :     return where_clause_items;
     360                 :             :   }
     361                 :             : };
     362                 :             : 
     363                 :             : // A self parameter in a method
     364                 :             : struct SelfParam
     365                 :             : {
     366                 :             : public:
     367                 :             :   enum ImplicitSelfKind
     368                 :             :   {
     369                 :             :     IMM,     // self
     370                 :             :     MUT,     // mut self
     371                 :             :     IMM_REF, // &self
     372                 :             :     MUT_REF, // &mut self
     373                 :             :     NONE
     374                 :             :   };
     375                 :             : 
     376                 :             : private:
     377                 :             :   ImplicitSelfKind self_kind;
     378                 :             :   Lifetime lifetime;
     379                 :             :   std::unique_ptr<Type> type;
     380                 :             :   location_t locus;
     381                 :             :   Analysis::NodeMapping mappings;
     382                 :             : 
     383                 :        8549 :   SelfParam (Analysis::NodeMapping mappings, ImplicitSelfKind self_kind,
     384                 :             :              Lifetime lifetime, Type *type)
     385                 :        8549 :     : self_kind (self_kind), lifetime (std::move (lifetime)), type (type),
     386                 :        8549 :       mappings (mappings)
     387                 :             :   {}
     388                 :             : 
     389                 :             : public:
     390                 :             :   // Type-based self parameter (not ref, no lifetime)
     391                 :        1719 :   SelfParam (Analysis::NodeMapping mappings, std::unique_ptr<Type> type,
     392                 :             :              bool is_mut, location_t locus)
     393                 :        1719 :     : self_kind (is_mut ? ImplicitSelfKind::MUT : ImplicitSelfKind::IMM),
     394                 :        1719 :       lifetime (
     395                 :             :         Lifetime (mappings, AST::Lifetime::LifetimeType::NAMED, "", locus)),
     396                 :        1719 :       type (std::move (type)), locus (locus), mappings (mappings)
     397                 :        1719 :   {}
     398                 :             : 
     399                 :             :   // Lifetime-based self parameter (is ref, no type)
     400                 :        1754 :   SelfParam (Analysis::NodeMapping mappings, Lifetime lifetime, bool is_mut,
     401                 :             :              location_t locus)
     402                 :        1754 :     : self_kind (is_mut ? ImplicitSelfKind::MUT_REF
     403                 :             :                         : ImplicitSelfKind::IMM_REF),
     404                 :        1754 :       lifetime (std::move (lifetime)), locus (locus), mappings (mappings)
     405                 :             :   {}
     406                 :             : 
     407                 :             :   // Copy constructor requires clone
     408                 :           0 :   SelfParam (SelfParam const &other)
     409                 :           0 :     : self_kind (other.self_kind), lifetime (other.lifetime),
     410                 :           0 :       locus (other.locus), mappings (other.mappings)
     411                 :             :   {
     412                 :           0 :     if (other.type != nullptr)
     413                 :           0 :       type = other.type->clone_type ();
     414                 :           0 :   }
     415                 :             : 
     416                 :             :   // Overload assignment operator to use clone
     417                 :             :   SelfParam &operator= (SelfParam const &other)
     418                 :             :   {
     419                 :             :     if (other.type != nullptr)
     420                 :             :       type = other.type->clone_type ();
     421                 :             : 
     422                 :             :     self_kind = other.self_kind;
     423                 :             :     lifetime = other.lifetime;
     424                 :             :     locus = other.locus;
     425                 :             :     mappings = other.mappings;
     426                 :             : 
     427                 :             :     return *this;
     428                 :             :   }
     429                 :             : 
     430                 :             :   // move constructors
     431                 :       15761 :   SelfParam (SelfParam &&other) = default;
     432                 :        2653 :   SelfParam &operator= (SelfParam &&other) = default;
     433                 :             : 
     434                 :        8549 :   static SelfParam error ()
     435                 :             :   {
     436                 :        8549 :     return SelfParam (Analysis::NodeMapping::get_error (),
     437                 :        8549 :                       ImplicitSelfKind::NONE, Lifetime::error (), nullptr);
     438                 :             :   }
     439                 :             : 
     440                 :             :   // Returns whether the self-param has a type field.
     441                 :        7393 :   bool has_type () const { return type != nullptr; }
     442                 :             : 
     443                 :             :   // Returns whether the self-param has a valid lifetime.
     444                 :        3163 :   bool has_lifetime () const { return !lifetime.is_error (); }
     445                 :             : 
     446                 :        4405 :   const Lifetime &get_lifetime () const { return lifetime; }
     447                 :             : 
     448                 :             :   // Returns whether the self-param is in an error state.
     449                 :       70576 :   bool is_error () const { return self_kind == ImplicitSelfKind::NONE; }
     450                 :             : 
     451                 :             :   std::string as_string () const;
     452                 :             : 
     453                 :       12358 :   location_t get_locus () const { return locus; }
     454                 :             : 
     455                 :        9680 :   ImplicitSelfKind get_self_kind () const { return self_kind; }
     456                 :             : 
     457                 :           1 :   std::unique_ptr<Type> &get_type () { return type; }
     458                 :             : 
     459                 :       24505 :   Analysis::NodeMapping get_mappings () { return mappings; }
     460                 :             : 
     461                 :        2653 :   Mutability get_mut () const
     462                 :             :   {
     463                 :        2653 :     return (self_kind == ImplicitSelfKind::MUT
     464                 :        2653 :             || self_kind == ImplicitSelfKind::MUT_REF)
     465                 :        2653 :              ? Mutability::Mut
     466                 :             :              : Mutability::Imm;
     467                 :             :   }
     468                 :             : 
     469                 :        4740 :   bool is_mut () const
     470                 :             :   {
     471                 :        4740 :     return self_kind == ImplicitSelfKind::MUT
     472                 :        4740 :            || self_kind == ImplicitSelfKind::MUT_REF;
     473                 :             :   }
     474                 :             : 
     475                 :        7393 :   bool is_ref () const
     476                 :             :   {
     477                 :        7393 :     return self_kind == ImplicitSelfKind::IMM_REF
     478                 :        7393 :            || self_kind == ImplicitSelfKind::MUT_REF;
     479                 :             :   }
     480                 :             : };
     481                 :             : 
     482                 :             : // Qualifiers for function, i.e. const, unsafe, extern etc.
     483                 :             : struct FunctionQualifiers
     484                 :             : {
     485                 :             : private:
     486                 :             :   Async async_status;
     487                 :             :   Const const_status;
     488                 :             :   Unsafety unsafety;
     489                 :             :   bool has_extern;
     490                 :             :   ABI abi;
     491                 :             : 
     492                 :             : public:
     493                 :        9405 :   FunctionQualifiers (Async async_status, Const const_status, Unsafety unsafety,
     494                 :             :                       bool has_extern, ABI abi)
     495                 :        9405 :     : async_status (async_status), const_status (const_status),
     496                 :        9405 :       unsafety (unsafety), has_extern (has_extern), abi (abi)
     497                 :             :   {}
     498                 :             : 
     499                 :             :   std::string as_string () const;
     500                 :             : 
     501                 :             :   Const get_const_status () const { return const_status; }
     502                 :             : 
     503                 :       39824 :   bool is_const () const { return const_status == Const::Yes; }
     504                 :       10523 :   bool is_unsafe () const { return unsafety == Unsafety::Unsafe; }
     505                 :           0 :   bool is_async () const { return async_status == Async::Yes; }
     506                 :             : 
     507                 :        7968 :   ABI get_abi () const { return abi; }
     508                 :             : };
     509                 :             : 
     510                 :             : // A function parameter
     511                 :        3923 : struct FunctionParam
     512                 :             : {
     513                 :             :   std::unique_ptr<Pattern> param_name;
     514                 :             :   std::unique_ptr<Type> type;
     515                 :             :   location_t locus;
     516                 :             :   Analysis::NodeMapping mappings;
     517                 :             : 
     518                 :             : public:
     519                 :        3477 :   FunctionParam (Analysis::NodeMapping mappings,
     520                 :             :                  std::unique_ptr<Pattern> param_name,
     521                 :             :                  std::unique_ptr<Type> param_type, location_t locus)
     522                 :        3477 :     : param_name (std::move (param_name)), type (std::move (param_type)),
     523                 :        3477 :       locus (locus), mappings (mappings)
     524                 :             :   {}
     525                 :             : 
     526                 :             :   // Copy constructor uses clone
     527                 :         497 :   FunctionParam (FunctionParam const &other)
     528                 :         497 :     : param_name (other.param_name->clone_pattern ()),
     529                 :         497 :       type (other.type->clone_type ()), locus (other.locus),
     530                 :         497 :       mappings (other.mappings)
     531                 :         497 :   {}
     532                 :             : 
     533                 :             :   // Overload assignment operator to use clone
     534                 :             :   FunctionParam &operator= (FunctionParam const &other)
     535                 :             :   {
     536                 :             :     param_name = other.param_name->clone_pattern ();
     537                 :             :     type = other.type->clone_type ();
     538                 :             :     locus = other.locus;
     539                 :             :     mappings = other.mappings;
     540                 :             : 
     541                 :             :     return *this;
     542                 :             :   }
     543                 :             : 
     544                 :             :   // move constructors
     545                 :        3424 :   FunctionParam (FunctionParam &&other) = default;
     546                 :             :   FunctionParam &operator= (FunctionParam &&other) = default;
     547                 :             : 
     548                 :             :   std::string as_string () const;
     549                 :             : 
     550                 :        6409 :   location_t get_locus () const { return locus; }
     551                 :             : 
     552                 :       15730 :   std::unique_ptr<Pattern> &get_param_name () { return param_name; }
     553                 :             : 
     554                 :       10794 :   std::unique_ptr<Type> &get_type () { return type; }
     555                 :             : 
     556                 :        8410 :   const Analysis::NodeMapping &get_mappings () const { return mappings; }
     557                 :             : };
     558                 :             : 
     559                 :             : // Visibility of an item
     560                 :       90980 : struct Visibility
     561                 :             : {
     562                 :             : public:
     563                 :             :   enum VisType
     564                 :             :   {
     565                 :             :     PRIVATE,
     566                 :             :     PUBLIC,
     567                 :             :     RESTRICTED,
     568                 :             :     ERROR,
     569                 :             :   };
     570                 :             : 
     571                 :             : private:
     572                 :             :   VisType vis_type;
     573                 :             :   HIR::SimplePath path;
     574                 :             :   location_t locus;
     575                 :             : 
     576                 :             :   // should this store location info?
     577                 :             : 
     578                 :             : public:
     579                 :       26598 :   Visibility (VisType vis_type,
     580                 :             :               HIR::SimplePath path = HIR::SimplePath::create_empty (),
     581                 :             :               location_t locus = UNDEF_LOCATION)
     582                 :       26598 :     : vis_type (vis_type), path (std::move (path)), locus (locus)
     583                 :             :   {}
     584                 :             : 
     585                 :             :   // Returns whether visibility is in an error state.
     586                 :       12462 :   bool is_error () const { return vis_type == ERROR; }
     587                 :             : 
     588                 :             :   // Does the current visibility refer to a simple `pub <item>` entirely public
     589                 :       12183 :   bool is_public () const { return vis_type == PUBLIC; }
     590                 :             : 
     591                 :             :   // Is the current visibility public restricted to a certain path
     592                 :             :   bool is_restricted () const { return vis_type == RESTRICTED; }
     593                 :             : 
     594                 :             :   // Creates an error visibility.
     595                 :           0 :   static Visibility create_error ()
     596                 :             :   {
     597                 :           0 :     return Visibility (ERROR, HIR::SimplePath::create_empty ());
     598                 :             :   }
     599                 :             : 
     600                 :       33383 :   VisType get_vis_type () const { return vis_type; }
     601                 :             : 
     602                 :       12462 :   const HIR::SimplePath &get_path () const
     603                 :             :   {
     604                 :       12462 :     rust_assert (!is_error ());
     605                 :       12462 :     return path;
     606                 :             :   }
     607                 :             : 
     608                 :             :   std::string as_string () const;
     609                 :             : };
     610                 :             : 
     611                 :             : // Item that supports visibility - abstract base class
     612                 :             : class VisItem : public Item
     613                 :             : {
     614                 :             :   Visibility visibility;
     615                 :             : 
     616                 :             : protected:
     617                 :             :   // Visibility constructor
     618                 :       21769 :   VisItem (Analysis::NodeMapping mappings, Visibility visibility,
     619                 :             :            AST::AttrVec outer_attrs = AST::AttrVec ())
     620                 :       21769 :     : Item (std::move (mappings), std::move (outer_attrs)),
     621                 :       21769 :       visibility (std::move (visibility))
     622                 :       21769 :   {}
     623                 :             : 
     624                 :             :   // Visibility copy constructor
     625                 :           0 :   VisItem (VisItem const &other) : Item (other), visibility (other.visibility)
     626                 :           0 :   {}
     627                 :             : 
     628                 :             :   // Overload assignment operator to clone
     629                 :             :   VisItem &operator= (VisItem const &other)
     630                 :             :   {
     631                 :             :     Item::operator= (other);
     632                 :             :     visibility = other.visibility;
     633                 :             :     // outer_attrs = other.outer_attrs;
     634                 :             : 
     635                 :             :     return *this;
     636                 :             :   }
     637                 :             : 
     638                 :             :   // move constructors
     639                 :             :   VisItem (VisItem &&other) = default;
     640                 :             :   VisItem &operator= (VisItem &&other) = default;
     641                 :             : 
     642                 :             : public:
     643                 :             :   using HIR::Stmt::accept_vis;
     644                 :             : 
     645                 :       67170 :   BaseKind get_hir_kind () override final { return VIS_ITEM; }
     646                 :             : 
     647                 :             :   /* Does the item have some kind of public visibility (non-default
     648                 :             :    * visibility)? */
     649                 :           0 :   bool has_visibility () const { return !visibility.is_error (); }
     650                 :             : 
     651                 :             :   virtual void accept_vis (HIRVisItemVisitor &vis) = 0;
     652                 :             : 
     653                 :       24892 :   Visibility &get_visibility () { return visibility; }
     654                 :       23258 :   const Visibility &get_visibility () const { return visibility; }
     655                 :             : 
     656                 :             :   std::string as_string () const override;
     657                 :             : };
     658                 :             : 
     659                 :             : // Rust module item - abstract base class
     660                 :             : class Module : public VisItem, public WithInnerAttrs
     661                 :             : {
     662                 :             :   Identifier module_name;
     663                 :             :   location_t locus;
     664                 :             :   // bool has_items;
     665                 :             :   std::vector<std::unique_ptr<Item>> items;
     666                 :             : 
     667                 :             : public:
     668                 :             :   std::string as_string () const override;
     669                 :             : 
     670                 :             :   // Returns whether the module has items in its body.
     671                 :             :   bool has_items () const { return !items.empty (); }
     672                 :             : 
     673                 :             :   // Full constructor
     674                 :         432 :   Module (Analysis::NodeMapping mappings, Identifier module_name,
     675                 :             :           location_t locus, std::vector<std::unique_ptr<Item>> items,
     676                 :             :           Visibility visibility = Visibility::create_error (),
     677                 :             :           AST::AttrVec inner_attrs = AST::AttrVec (),
     678                 :             :           AST::AttrVec outer_attrs = AST::AttrVec ())
     679                 :         432 :     : VisItem (std::move (mappings), std::move (visibility),
     680                 :             :                std::move (outer_attrs)),
     681                 :         864 :       WithInnerAttrs (std::move (inner_attrs)), module_name (module_name),
     682                 :         432 :       locus (locus), items (std::move (items))
     683                 :         432 :   {}
     684                 :             : 
     685                 :             :   // Copy constructor with vector clone
     686                 :           0 :   Module (Module const &other)
     687                 :           0 :     : VisItem (other), WithInnerAttrs (other.inner_attrs), module_name ("")
     688                 :             :   {
     689                 :           0 :     items.reserve (other.items.size ());
     690                 :           0 :     for (const auto &e : other.items)
     691                 :           0 :       items.push_back (e->clone_item ());
     692                 :           0 :   }
     693                 :             : 
     694                 :             :   // Overloaded assignment operator with vector clone
     695                 :             :   Module &operator= (Module const &other)
     696                 :             :   {
     697                 :             :     VisItem::operator= (other);
     698                 :             :     inner_attrs = other.inner_attrs;
     699                 :             : 
     700                 :             :     items.reserve (other.items.size ());
     701                 :             :     for (const auto &e : other.items)
     702                 :             :       items.push_back (e->clone_item ());
     703                 :             : 
     704                 :             :     return *this;
     705                 :             :   }
     706                 :             : 
     707                 :             :   // move constructors
     708                 :             :   Module (Module &&other) = default;
     709                 :             :   Module &operator= (Module &&other) = default;
     710                 :             : 
     711                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     712                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
     713                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
     714                 :             : 
     715                 :           0 :   Identifier get_module_name () const { return module_name; }
     716                 :        4126 :   std::vector<std::unique_ptr<Item>> &get_items () { return items; };
     717                 :             : 
     718                 :             :   /* Override that runs the function recursively on all items contained within
     719                 :             :    * the module. */
     720                 :             :   void add_crate_name (std::vector<std::string> &names) const override;
     721                 :             : 
     722                 :        1289 :   location_t get_locus () const override final { return locus; }
     723                 :             : 
     724                 :           6 :   ItemKind get_item_kind () const override { return ItemKind::Module; }
     725                 :             : 
     726                 :             : protected:
     727                 :             :   /* Use covariance to implement clone function as returning this object
     728                 :             :    * rather than base */
     729                 :           0 :   Module *clone_item_impl () const override { return new Module (*this); }
     730                 :             : 
     731                 :             :   /* Use covariance to implement clone function as returning this object
     732                 :             :    * rather than base */
     733                 :             :   /*virtual Module* clone_statement_impl() const override {
     734                 :             :       return new Module(*this);
     735                 :             :   }*/
     736                 :             : };
     737                 :             : 
     738                 :             : // Rust extern crate declaration HIR node
     739                 :             : class ExternCrate : public VisItem
     740                 :             : {
     741                 :             :   // this is either an identifier or "self", with self parsed to string
     742                 :             :   std::string referenced_crate;
     743                 :             :   // bool has_as_clause;
     744                 :             :   // AsClause as_clause;
     745                 :             :   // this is either an identifier or "_", with _ parsed to string
     746                 :             :   std::string as_clause_name;
     747                 :             : 
     748                 :             :   location_t locus;
     749                 :             : 
     750                 :             :   /* e.g.
     751                 :             :       "extern crate foo as _"
     752                 :             :       "extern crate foo"
     753                 :             :       "extern crate std as cool_std"  */
     754                 :             : public:
     755                 :             :   std::string as_string () const override;
     756                 :             : 
     757                 :             :   // Returns whether extern crate declaration has an as clause.
     758                 :           0 :   bool has_as_clause () const { return !as_clause_name.empty (); }
     759                 :             : 
     760                 :             :   /* Returns whether extern crate declaration references the current crate
     761                 :             :    * (i.e. self). */
     762                 :             :   bool references_self () const { return referenced_crate == "self"; }
     763                 :             : 
     764                 :             :   // Constructor
     765                 :             :   ExternCrate (Analysis::NodeMapping mappings, std::string referenced_crate,
     766                 :             :                Visibility visibility, AST::AttrVec outer_attrs,
     767                 :             :                location_t locus, std::string as_clause_name = std::string ())
     768                 :             :     : VisItem (std::move (mappings), std::move (visibility),
     769                 :             :                std::move (outer_attrs)),
     770                 :             :       referenced_crate (std::move (referenced_crate)),
     771                 :             :       as_clause_name (std::move (as_clause_name)), locus (locus)
     772                 :             :   {}
     773                 :             : 
     774                 :           0 :   location_t get_locus () const override final { return locus; }
     775                 :             : 
     776                 :           0 :   ItemKind get_item_kind () const override { return ItemKind::ExternCrate; }
     777                 :           0 :   std::string get_referenced_crate () { return referenced_crate; }
     778                 :           0 :   std::string get_as_clause_name () { return as_clause_name; }
     779                 :             : 
     780                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     781                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
     782                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
     783                 :             : 
     784                 :             :   // Override that adds extern crate name in decl to passed list of names.
     785                 :           0 :   void add_crate_name (std::vector<std::string> &names) const override
     786                 :             :   {
     787                 :           0 :     names.push_back (referenced_crate);
     788                 :           0 :   }
     789                 :             : 
     790                 :             : protected:
     791                 :             :   /* Use covariance to implement clone function as returning this object
     792                 :             :    * rather than base */
     793                 :           0 :   ExternCrate *clone_item_impl () const override
     794                 :             :   {
     795                 :           0 :     return new ExternCrate (*this);
     796                 :             :   }
     797                 :             : 
     798                 :             :   /* Use covariance to implement clone function as returning this object
     799                 :             :    * rather than base */
     800                 :             :   /*virtual ExternCrate* clone_statement_impl() const override {
     801                 :             :       return new ExternCrate(*this);
     802                 :             :   }*/
     803                 :             : };
     804                 :             : 
     805                 :             : // The path-ish thing referred to in a use declaration - abstract base class
     806                 :           0 : class UseTree : public FullVisitable
     807                 :             : {
     808                 :             :   location_t locus;
     809                 :             : 
     810                 :             : public:
     811                 :             :   virtual ~UseTree () {}
     812                 :             : 
     813                 :             :   // Unique pointer custom clone function
     814                 :           0 :   std::unique_ptr<UseTree> clone_use_tree () const
     815                 :             :   {
     816                 :           0 :     return std::unique_ptr<UseTree> (clone_use_tree_impl ());
     817                 :             :   }
     818                 :             : 
     819                 :             :   virtual std::string as_string () const = 0;
     820                 :             : 
     821                 :             :   location_t get_locus () const { return locus; }
     822                 :             : 
     823                 :             : protected:
     824                 :             :   // Clone function implementation as pure virtual method
     825                 :             :   virtual UseTree *clone_use_tree_impl () const = 0;
     826                 :             : 
     827                 :             :   UseTree (location_t locus) : locus (locus) {}
     828                 :             : };
     829                 :             : 
     830                 :             : // Use tree with a glob (wildcard) operator
     831                 :             : class UseTreeGlob : public UseTree
     832                 :             : {
     833                 :             : public:
     834                 :             :   enum PathType
     835                 :             :   {
     836                 :             :     NO_PATH,
     837                 :             :     GLOBAL,
     838                 :             :     PATH_PREFIXED
     839                 :             :   };
     840                 :             : 
     841                 :             : private:
     842                 :             :   PathType glob_type;
     843                 :             :   AST::SimplePath path;
     844                 :             : 
     845                 :             : public:
     846                 :             :   UseTreeGlob (PathType glob_type, AST::SimplePath path, location_t locus)
     847                 :             :     : UseTree (locus), glob_type (glob_type), path (std::move (path))
     848                 :             :   {
     849                 :             :     if (this->glob_type != PATH_PREFIXED)
     850                 :             :       {
     851                 :             :         // compiler implementation error if there is a path with a
     852                 :             :         // non-path-prefixed use tree glob
     853                 :             :         gcc_assert (!has_path ());
     854                 :             :       }
     855                 :             :     // TODO: do path-prefixed paths also have to have a path? If so, have an
     856                 :             :     // assert for that too.
     857                 :             :   }
     858                 :             : 
     859                 :             :   /* Returns whether has path. Should be made redundant by PathType
     860                 :             :    * PATH_PREFIXED. */
     861                 :             :   bool has_path () const { return !path.is_empty (); }
     862                 :             : 
     863                 :           0 :   PathType get_glob_type () { return glob_type; }
     864                 :           0 :   AST::SimplePath get_path () { return path; };
     865                 :             : 
     866                 :             :   std::string as_string () const override;
     867                 :             : 
     868                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     869                 :             : 
     870                 :             :   /* TODO: find way to ensure only PATH_PREFIXED glob_type has path - factory
     871                 :             :    * methods? */
     872                 :             : protected:
     873                 :             :   /* Use covariance to implement clone function as returning this object
     874                 :             :    * rather than base */
     875                 :           0 :   UseTreeGlob *clone_use_tree_impl () const override
     876                 :             :   {
     877                 :           0 :     return new UseTreeGlob (*this);
     878                 :             :   }
     879                 :             : };
     880                 :             : 
     881                 :             : // Use tree with a list of paths with a common prefix
     882                 :             : class UseTreeList : public UseTree
     883                 :             : {
     884                 :             : public:
     885                 :             :   enum PathType
     886                 :             :   {
     887                 :             :     NO_PATH,
     888                 :             :     GLOBAL,
     889                 :             :     PATH_PREFIXED
     890                 :             :   };
     891                 :             : 
     892                 :             : private:
     893                 :             :   PathType path_type;
     894                 :             :   AST::SimplePath path;
     895                 :             : 
     896                 :             :   std::vector<std::unique_ptr<UseTree>> trees;
     897                 :             : 
     898                 :             : public:
     899                 :             :   UseTreeList (PathType path_type, AST::SimplePath path,
     900                 :             :                std::vector<std::unique_ptr<UseTree>> trees, location_t locus)
     901                 :             :     : UseTree (locus), path_type (path_type), path (std::move (path)),
     902                 :             :       trees (std::move (trees))
     903                 :             :   {
     904                 :             :     if (this->path_type != PATH_PREFIXED)
     905                 :             :       {
     906                 :             :         // compiler implementation error if there is a path with a
     907                 :             :         // non-path-prefixed use tree glob
     908                 :             :         gcc_assert (!has_path ());
     909                 :             :       }
     910                 :             :     // TODO: do path-prefixed paths also have to have a path? If so, have an
     911                 :             :     // assert for that too.
     912                 :             :   }
     913                 :             : 
     914                 :             :   // copy constructor with vector clone
     915                 :           0 :   UseTreeList (UseTreeList const &other)
     916                 :           0 :     : UseTree (other), path_type (other.path_type), path (other.path)
     917                 :             :   {
     918                 :           0 :     trees.reserve (other.trees.size ());
     919                 :           0 :     for (const auto &e : other.trees)
     920                 :           0 :       trees.push_back (e->clone_use_tree ());
     921                 :           0 :   }
     922                 :             : 
     923                 :             :   // overloaded assignment operator with vector clone
     924                 :             :   UseTreeList &operator= (UseTreeList const &other)
     925                 :             :   {
     926                 :             :     UseTree::operator= (other);
     927                 :             :     path_type = other.path_type;
     928                 :             :     path = other.path;
     929                 :             : 
     930                 :             :     trees.reserve (other.trees.size ());
     931                 :             :     for (const auto &e : other.trees)
     932                 :             :       trees.push_back (e->clone_use_tree ());
     933                 :             : 
     934                 :             :     return *this;
     935                 :             :   }
     936                 :             : 
     937                 :             :   // move constructors
     938                 :             :   UseTreeList (UseTreeList &&other) = default;
     939                 :             :   UseTreeList &operator= (UseTreeList &&other) = default;
     940                 :             : 
     941                 :             :   // Returns whether has path. Should be made redundant by path_type.
     942                 :             :   bool has_path () const { return !path.is_empty (); }
     943                 :             : 
     944                 :             :   // Returns whether has inner tree elements.
     945                 :           0 :   bool has_trees () const { return !trees.empty (); }
     946                 :             : 
     947                 :             :   std::string as_string () const override;
     948                 :             : 
     949                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     950                 :             : 
     951                 :           0 :   PathType get_path_type () { return path_type; }
     952                 :           0 :   AST::SimplePath get_path () { return path; }
     953                 :           0 :   std::vector<std::unique_ptr<UseTree>> &get_trees () { return trees; }
     954                 :             : 
     955                 :             :   // TODO: find way to ensure only PATH_PREFIXED path_type has path - factory
     956                 :             :   // methods?
     957                 :             : protected:
     958                 :             :   /* Use covariance to implement clone function as returning this object
     959                 :             :    * rather than base */
     960                 :           0 :   UseTreeList *clone_use_tree_impl () const override
     961                 :             :   {
     962                 :           0 :     return new UseTreeList (*this);
     963                 :             :   }
     964                 :             : };
     965                 :             : 
     966                 :             : // Use tree where it rebinds the module name as something else
     967                 :             : class UseTreeRebind : public UseTree
     968                 :             : {
     969                 :             : public:
     970                 :             :   enum NewBindType
     971                 :             :   {
     972                 :             :     NONE,
     973                 :             :     IDENTIFIER,
     974                 :             :     WILDCARD
     975                 :             :   };
     976                 :             : 
     977                 :             : private:
     978                 :             :   AST::SimplePath path;
     979                 :             : 
     980                 :             :   NewBindType bind_type;
     981                 :             :   Identifier identifier; // only if NewBindType is IDENTIFIER
     982                 :             : 
     983                 :             : public:
     984                 :             :   UseTreeRebind (NewBindType bind_type, AST::SimplePath path, location_t locus,
     985                 :             :                  Identifier identifier = std::string ())
     986                 :             :     : UseTree (locus), path (std::move (path)), bind_type (bind_type),
     987                 :             :       identifier (std::move (identifier))
     988                 :             :   {}
     989                 :             : 
     990                 :             :   // Returns whether has path (this should always be true).
     991                 :             :   bool has_path () const { return !path.is_empty (); }
     992                 :             : 
     993                 :           0 :   AST::SimplePath get_path () { return path; }
     994                 :             : 
     995                 :           0 :   Identifier get_identifier () const { return identifier; }
     996                 :             : 
     997                 :           0 :   NewBindType get_bind_type () const { return bind_type; }
     998                 :             : 
     999                 :             :   // Returns whether has identifier (or, rather, is allowed to).
    1000                 :             :   bool has_identifier () const { return bind_type == IDENTIFIER; }
    1001                 :             : 
    1002                 :             :   std::string as_string () const override;
    1003                 :             : 
    1004                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1005                 :             : 
    1006                 :             :   // TODO: find way to ensure only PATH_PREFIXED path_type has path - factory
    1007                 :             :   // methods?
    1008                 :             : protected:
    1009                 :             :   /* Use covariance to implement clone function as returning this object
    1010                 :             :    * rather than base */
    1011                 :           0 :   virtual UseTreeRebind *clone_use_tree_impl () const override
    1012                 :             :   {
    1013                 :           0 :     return new UseTreeRebind (*this);
    1014                 :             :   }
    1015                 :             : };
    1016                 :             : 
    1017                 :             : std::string enum_to_str (UseTreeRebind::NewBindType);
    1018                 :             : 
    1019                 :             : // Rust use declaration (i.e. for modules) HIR node
    1020                 :             : class UseDeclaration : public VisItem
    1021                 :             : {
    1022                 :             :   std::unique_ptr<UseTree> use_tree;
    1023                 :             :   location_t locus;
    1024                 :             : 
    1025                 :             : public:
    1026                 :             :   std::string as_string () const override;
    1027                 :             : 
    1028                 :             :   UseDeclaration (Analysis::NodeMapping mappings,
    1029                 :             :                   std::unique_ptr<UseTree> use_tree, Visibility visibility,
    1030                 :             :                   AST::AttrVec outer_attrs, location_t locus)
    1031                 :             :     : VisItem (std::move (mappings), std::move (visibility),
    1032                 :             :                std::move (outer_attrs)),
    1033                 :             :       use_tree (std::move (use_tree)), locus (locus)
    1034                 :             :   {}
    1035                 :             : 
    1036                 :             :   // Copy constructor with clone
    1037                 :           0 :   UseDeclaration (UseDeclaration const &other)
    1038                 :           0 :     : VisItem (other), use_tree (other.use_tree->clone_use_tree ()),
    1039                 :           0 :       locus (other.locus)
    1040                 :           0 :   {}
    1041                 :             : 
    1042                 :             :   // Overloaded assignment operator to clone
    1043                 :             :   UseDeclaration &operator= (UseDeclaration const &other)
    1044                 :             :   {
    1045                 :             :     VisItem::operator= (other);
    1046                 :             :     use_tree = other.use_tree->clone_use_tree ();
    1047                 :             :     // visibility = other.visibility->clone_visibility();
    1048                 :             :     // outer_attrs = other.outer_attrs;
    1049                 :             :     locus = other.locus;
    1050                 :             : 
    1051                 :             :     return *this;
    1052                 :             :   }
    1053                 :             : 
    1054                 :             :   // move constructors
    1055                 :             :   UseDeclaration (UseDeclaration &&other) = default;
    1056                 :             :   UseDeclaration &operator= (UseDeclaration &&other) = default;
    1057                 :             : 
    1058                 :           0 :   location_t get_locus () const override final { return locus; }
    1059                 :           0 :   ItemKind get_item_kind () const override { return ItemKind::UseDeclaration; }
    1060                 :             : 
    1061                 :           0 :   std::unique_ptr<UseTree> &get_use_tree () { return use_tree; }
    1062                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1063                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    1064                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
    1065                 :             : 
    1066                 :             : protected:
    1067                 :             :   /* Use covariance to implement clone function as returning this object
    1068                 :             :    * rather than base */
    1069                 :           0 :   UseDeclaration *clone_item_impl () const override
    1070                 :             :   {
    1071                 :           0 :     return new UseDeclaration (*this);
    1072                 :             :   }
    1073                 :             : 
    1074                 :             :   /* Use covariance to implement clone function as returning this object
    1075                 :             :    * rather than base */
    1076                 :             :   /*virtual UseDeclaration* clone_statement_impl() const override {
    1077                 :             :       return new UseDeclaration(*this);
    1078                 :             :   }*/
    1079                 :             : };
    1080                 :             : 
    1081                 :             : class LetStmt;
    1082                 :             : 
    1083                 :             : // Rust function declaration HIR node
    1084                 :             : class Function : public VisItem, public ImplItem
    1085                 :             : {
    1086                 :             :   FunctionQualifiers qualifiers;
    1087                 :             :   Identifier function_name;
    1088                 :             :   std::vector<std::unique_ptr<GenericParam>> generic_params;
    1089                 :             :   std::vector<FunctionParam> function_params;
    1090                 :             :   std::unique_ptr<Type> return_type;
    1091                 :             :   WhereClause where_clause;
    1092                 :             :   std::unique_ptr<BlockExpr> function_body;
    1093                 :             :   SelfParam self;
    1094                 :             :   location_t locus;
    1095                 :             : 
    1096                 :             : public:
    1097                 :             :   std::string as_string () const override;
    1098                 :             : 
    1099                 :             :   // Returns whether function has generic parameters.
    1100                 :        8857 :   bool has_generics () const { return !generic_params.empty (); }
    1101                 :             : 
    1102                 :             :   // Returns whether function has regular parameters.
    1103                 :           0 :   bool has_function_params () const { return !function_params.empty (); }
    1104                 :             : 
    1105                 :             :   // Returns whether function has return type - if not, it is void.
    1106                 :       16682 :   bool has_function_return_type () const { return return_type != nullptr; }
    1107                 :             : 
    1108                 :             :   // Returns whether function has a where clause.
    1109                 :           0 :   bool has_where_clause () const { return !where_clause.is_empty (); }
    1110                 :             : 
    1111                 :       45433 :   ImplItemType get_impl_item_type () const override final
    1112                 :             :   {
    1113                 :       45433 :     return ImplItem::ImplItemType::FUNCTION;
    1114                 :             :   }
    1115                 :             : 
    1116                 :        3992 :   ItemKind get_item_kind () const override { return ItemKind::Function; }
    1117                 :             : 
    1118                 :             :   // Mega-constructor with all possible fields
    1119                 :        8355 :   Function (Analysis::NodeMapping mappings, Identifier function_name,
    1120                 :             :             FunctionQualifiers qualifiers,
    1121                 :             :             std::vector<std::unique_ptr<GenericParam>> generic_params,
    1122                 :             :             std::vector<FunctionParam> function_params,
    1123                 :             :             std::unique_ptr<Type> return_type, WhereClause where_clause,
    1124                 :             :             std::unique_ptr<BlockExpr> function_body, Visibility vis,
    1125                 :             :             AST::AttrVec outer_attrs, SelfParam self, location_t locus)
    1126                 :        8355 :     : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
    1127                 :        8355 :       qualifiers (std::move (qualifiers)),
    1128                 :        8355 :       function_name (std::move (function_name)),
    1129                 :        8355 :       generic_params (std::move (generic_params)),
    1130                 :        8355 :       function_params (std::move (function_params)),
    1131                 :        8355 :       return_type (std::move (return_type)),
    1132                 :        8355 :       where_clause (std::move (where_clause)),
    1133                 :        8355 :       function_body (std::move (function_body)), self (std::move (self)),
    1134                 :        8355 :       locus (locus)
    1135                 :        8355 :   {}
    1136                 :             : 
    1137                 :             :   // Copy constructor with clone
    1138                 :           0 :   Function (Function const &other)
    1139                 :           0 :     : VisItem (other), qualifiers (other.qualifiers),
    1140                 :           0 :       function_name (other.function_name),
    1141                 :           0 :       function_params (other.function_params),
    1142                 :           0 :       where_clause (other.where_clause),
    1143                 :           0 :       function_body (other.function_body->clone_block_expr ()),
    1144                 :           0 :       self (other.self), locus (other.locus)
    1145                 :             :   {
    1146                 :             :     // guard to prevent null dereference (always required)
    1147                 :           0 :     if (other.return_type != nullptr)
    1148                 :           0 :       return_type = other.return_type->clone_type ();
    1149                 :             :     else
    1150                 :           0 :       return_type = nullptr;
    1151                 :             : 
    1152                 :           0 :     generic_params.reserve (other.generic_params.size ());
    1153                 :           0 :     for (const auto &e : other.generic_params)
    1154                 :           0 :       generic_params.push_back (e->clone_generic_param ());
    1155                 :           0 :   }
    1156                 :             : 
    1157                 :             :   // Overloaded assignment operator to clone
    1158                 :             :   Function &operator= (Function const &other)
    1159                 :             :   {
    1160                 :             :     VisItem::operator= (other);
    1161                 :             :     function_name = other.function_name;
    1162                 :             :     qualifiers = other.qualifiers;
    1163                 :             :     function_params = other.function_params;
    1164                 :             : 
    1165                 :             :     // guard to prevent null dereference (always required)
    1166                 :             :     if (other.return_type != nullptr)
    1167                 :             :       return_type = other.return_type->clone_type ();
    1168                 :             :     else
    1169                 :             :       return_type = nullptr;
    1170                 :             : 
    1171                 :             :     where_clause = other.where_clause;
    1172                 :             :     function_body = other.function_body->clone_block_expr ();
    1173                 :             :     locus = other.locus;
    1174                 :             :     self = other.self;
    1175                 :             : 
    1176                 :             :     generic_params.reserve (other.generic_params.size ());
    1177                 :             :     for (const auto &e : other.generic_params)
    1178                 :             :       generic_params.push_back (e->clone_generic_param ());
    1179                 :             : 
    1180                 :             :     return *this;
    1181                 :             :   }
    1182                 :             : 
    1183                 :             :   // move constructors
    1184                 :             :   Function (Function &&other) = default;
    1185                 :             :   Function &operator= (Function &&other) = default;
    1186                 :             : 
    1187                 :       46275 :   location_t get_locus () const override final { return locus; }
    1188                 :             : 
    1189                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1190                 :             :   void accept_vis (HIRImplVisitor &vis) override;
    1191                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    1192                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
    1193                 :             : 
    1194                 :       88328 :   Analysis::NodeMapping get_impl_mappings () const override
    1195                 :             :   {
    1196                 :       88328 :     return get_mappings ();
    1197                 :             :   };
    1198                 :             : 
    1199                 :       40908 :   std::vector<FunctionParam> &get_function_params () { return function_params; }
    1200                 :             :   const std::vector<FunctionParam> &get_function_params () const
    1201                 :             :   {
    1202                 :             :     return function_params;
    1203                 :             :   }
    1204                 :             : 
    1205                 :       13453 :   std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
    1206                 :             :   {
    1207                 :       13476 :     return generic_params;
    1208                 :             :   }
    1209                 :             :   const std::vector<std::unique_ptr<GenericParam>> &get_generic_params () const
    1210                 :             :   {
    1211                 :             :     return generic_params;
    1212                 :             :   }
    1213                 :             : 
    1214                 :             :   // TODO: is this better? Or is a "vis_block" better?
    1215                 :       65714 :   std::unique_ptr<BlockExpr> &get_definition () { return function_body; }
    1216                 :             : 
    1217                 :       34411 :   const FunctionQualifiers &get_qualifiers () const { return qualifiers; }
    1218                 :             : 
    1219                 :       61780 :   Identifier get_function_name () const { return function_name; }
    1220                 :             : 
    1221                 :             :   // TODO: is this better? Or is a "vis_block" better?
    1222                 :        8343 :   WhereClause &get_where_clause () { return where_clause; }
    1223                 :             : 
    1224                 :             :   bool has_return_type () const { return return_type != nullptr; }
    1225                 :             : 
    1226                 :             :   // TODO: is this better? Or is a "vis_block" better?
    1227                 :       16224 :   std::unique_ptr<Type> &get_return_type () { return return_type; }
    1228                 :             : 
    1229                 :       44162 :   bool is_method () const { return !self.is_error (); }
    1230                 :             : 
    1231                 :       13848 :   SelfParam &get_self_param () { return self; }
    1232                 :             : 
    1233                 :        1617 :   std::string get_impl_item_name () const override final
    1234                 :             :   {
    1235                 :        1617 :     return get_function_name ().as_string ();
    1236                 :             :   }
    1237                 :             : 
    1238                 :             : protected:
    1239                 :             :   /* Use covariance to implement clone function as returning this object
    1240                 :             :    * rather than base */
    1241                 :           0 :   Function *clone_item_impl () const override { return new Function (*this); }
    1242                 :             : 
    1243                 :             :   /* Use covariance to implement clone function as returning this object
    1244                 :             :    * rather than base */
    1245                 :           0 :   Function *clone_inherent_impl_item_impl () const override
    1246                 :             :   {
    1247                 :           0 :     return new Function (*this);
    1248                 :             :   }
    1249                 :             : };
    1250                 :             : 
    1251                 :             : // Rust type alias (i.e. typedef) HIR node
    1252                 :             : class TypeAlias : public VisItem, public ImplItem
    1253                 :             : {
    1254                 :             :   Identifier new_type_name;
    1255                 :             : 
    1256                 :             :   // bool has_generics;
    1257                 :             :   // Generics generic_params;
    1258                 :             :   std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined
    1259                 :             : 
    1260                 :             :   // bool has_where_clause;
    1261                 :             :   WhereClause where_clause;
    1262                 :             : 
    1263                 :             :   std::unique_ptr<Type> existing_type;
    1264                 :             : 
    1265                 :             :   location_t locus;
    1266                 :             : 
    1267                 :             : public:
    1268                 :             :   std::string as_string () const override;
    1269                 :             : 
    1270                 :             :   // Returns whether type alias has generic parameters.
    1271                 :         710 :   bool has_generics () const { return !generic_params.empty (); }
    1272                 :             : 
    1273                 :             :   // Returns whether type alias has a where clause.
    1274                 :           0 :   bool has_where_clause () const { return !where_clause.is_empty (); }
    1275                 :             : 
    1276                 :       12320 :   ImplItemType get_impl_item_type () const override final
    1277                 :             :   {
    1278                 :       12320 :     return ImplItem::ImplItemType::TYPE_ALIAS;
    1279                 :             :   }
    1280                 :             : 
    1281                 :             :   // Mega-constructor with all possible fields
    1282                 :         744 :   TypeAlias (Analysis::NodeMapping mappings, Identifier new_type_name,
    1283                 :             :              std::vector<std::unique_ptr<GenericParam>> generic_params,
    1284                 :             :              WhereClause where_clause, std::unique_ptr<Type> existing_type,
    1285                 :             :              Visibility vis, AST::AttrVec outer_attrs, location_t locus)
    1286                 :         744 :     : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
    1287                 :         744 :       new_type_name (std::move (new_type_name)),
    1288                 :         744 :       generic_params (std::move (generic_params)),
    1289                 :         744 :       where_clause (std::move (where_clause)),
    1290                 :         744 :       existing_type (std::move (existing_type)), locus (locus)
    1291                 :         744 :   {}
    1292                 :             : 
    1293                 :             :   // Copy constructor
    1294                 :           0 :   TypeAlias (TypeAlias const &other)
    1295                 :           0 :     : VisItem (other), new_type_name (other.new_type_name),
    1296                 :           0 :       where_clause (other.where_clause),
    1297                 :           0 :       existing_type (other.existing_type->clone_type ()), locus (other.locus)
    1298                 :             :   {
    1299                 :           0 :     generic_params.reserve (other.generic_params.size ());
    1300                 :           0 :     for (const auto &e : other.generic_params)
    1301                 :           0 :       generic_params.push_back (e->clone_generic_param ());
    1302                 :           0 :   }
    1303                 :             : 
    1304                 :             :   // Overloaded assignment operator to clone
    1305                 :             :   TypeAlias &operator= (TypeAlias const &other)
    1306                 :             :   {
    1307                 :             :     VisItem::operator= (other);
    1308                 :             :     new_type_name = other.new_type_name;
    1309                 :             :     where_clause = other.where_clause;
    1310                 :             :     existing_type = other.existing_type->clone_type ();
    1311                 :             :     locus = other.locus;
    1312                 :             : 
    1313                 :             :     generic_params.reserve (other.generic_params.size ());
    1314                 :             :     for (const auto &e : other.generic_params)
    1315                 :             :       generic_params.push_back (e->clone_generic_param ());
    1316                 :             : 
    1317                 :             :     return *this;
    1318                 :             :   }
    1319                 :             : 
    1320                 :             :   // move constructors
    1321                 :             :   TypeAlias (TypeAlias &&other) = default;
    1322                 :             :   TypeAlias &operator= (TypeAlias &&other) = default;
    1323                 :             : 
    1324                 :        2529 :   location_t get_locus () const override final { return locus; }
    1325                 :             : 
    1326                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1327                 :             :   void accept_vis (HIRImplVisitor &vis) override;
    1328                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    1329                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
    1330                 :             : 
    1331                 :         772 :   std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
    1332                 :             :   {
    1333                 :         772 :     return generic_params;
    1334                 :             :   }
    1335                 :             :   const std::vector<std::unique_ptr<GenericParam>> &get_generic_params () const
    1336                 :             :   {
    1337                 :             :     return generic_params;
    1338                 :             :   }
    1339                 :             : 
    1340                 :         743 :   WhereClause &get_where_clause () { return where_clause; }
    1341                 :             : 
    1342                 :         757 :   std::unique_ptr<Type> &get_type_aliased () { return existing_type; }
    1343                 :             : 
    1344                 :        5159 :   Identifier get_new_type_name () const { return new_type_name; }
    1345                 :             : 
    1346                 :           0 :   ItemKind get_item_kind () const override { return ItemKind::TypeAlias; }
    1347                 :             : 
    1348                 :       23297 :   Analysis::NodeMapping get_impl_mappings () const override
    1349                 :             :   {
    1350                 :       23297 :     return get_mappings ();
    1351                 :             :   };
    1352                 :             : 
    1353                 :        1296 :   std::string get_impl_item_name () const override final
    1354                 :             :   {
    1355                 :        1296 :     return get_new_type_name ().as_string ();
    1356                 :             :   }
    1357                 :             : 
    1358                 :             : protected:
    1359                 :             :   /* Use covariance to implement clone function as returning this object
    1360                 :             :    * rather than base */
    1361                 :           0 :   TypeAlias *clone_item_impl () const override { return new TypeAlias (*this); }
    1362                 :             : 
    1363                 :             :   /* Use covariance to implement clone function as returning this object
    1364                 :             :    * rather than base */
    1365                 :           0 :   TypeAlias *clone_inherent_impl_item_impl () const override
    1366                 :             :   {
    1367                 :           0 :     return new TypeAlias (*this);
    1368                 :             :   }
    1369                 :             : };
    1370                 :             : 
    1371                 :             : // Rust base struct declaration HIR node - abstract base class
    1372                 :             : class Struct : public VisItem
    1373                 :             : {
    1374                 :             : protected:
    1375                 :             :   // protected to enable access by derived classes - allows better as_string
    1376                 :             :   Identifier struct_name;
    1377                 :             : 
    1378                 :             :   // bool has_generics;
    1379                 :             :   // Generics generic_params;
    1380                 :             :   std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined
    1381                 :             : 
    1382                 :             :   // bool has_where_clause;
    1383                 :             :   WhereClause where_clause;
    1384                 :             : 
    1385                 :             :   location_t locus;
    1386                 :             : 
    1387                 :             : public:
    1388                 :        3723 :   Identifier get_identifier () const { return struct_name; }
    1389                 :             : 
    1390                 :             :   // Returns whether struct has generic parameters.
    1391                 :        1667 :   bool has_generics () const { return !generic_params.empty (); }
    1392                 :             : 
    1393                 :             :   // Returns whether struct has a where clause.
    1394                 :           0 :   bool has_where_clause () const { return !where_clause.is_empty (); }
    1395                 :             : 
    1396                 :        8690 :   location_t get_locus () const override final { return locus; }
    1397                 :           2 :   ItemKind get_item_kind () const override { return ItemKind::Struct; }
    1398                 :             : 
    1399                 :        2958 :   std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
    1400                 :             :   {
    1401                 :        2958 :     return generic_params;
    1402                 :             :   }
    1403                 :             : 
    1404                 :        1667 :   WhereClause &get_where_clause () { return where_clause; }
    1405                 :             : 
    1406                 :             : protected:
    1407                 :        1671 :   Struct (Analysis::NodeMapping mappings, Identifier struct_name,
    1408                 :             :           std::vector<std::unique_ptr<GenericParam>> generic_params,
    1409                 :             :           WhereClause where_clause, Visibility vis, location_t locus,
    1410                 :             :           AST::AttrVec outer_attrs = AST::AttrVec ())
    1411                 :        1671 :     : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
    1412                 :        3342 :       struct_name (std::move (struct_name)),
    1413                 :        1671 :       generic_params (std::move (generic_params)),
    1414                 :        1671 :       where_clause (std::move (where_clause)), locus (locus)
    1415                 :        1671 :   {}
    1416                 :             : 
    1417                 :             :   // Copy constructor with vector clone
    1418                 :           0 :   Struct (Struct const &other)
    1419                 :           0 :     : VisItem (other), struct_name (other.struct_name),
    1420                 :           0 :       where_clause (other.where_clause), locus (other.locus)
    1421                 :             :   {
    1422                 :           0 :     generic_params.reserve (other.generic_params.size ());
    1423                 :           0 :     for (const auto &e : other.generic_params)
    1424                 :           0 :       generic_params.push_back (e->clone_generic_param ());
    1425                 :           0 :   }
    1426                 :             : 
    1427                 :             :   // Overloaded assignment operator with vector clone
    1428                 :             :   Struct &operator= (Struct const &other)
    1429                 :             :   {
    1430                 :             :     VisItem::operator= (other);
    1431                 :             :     struct_name = other.struct_name;
    1432                 :             :     where_clause = other.where_clause;
    1433                 :             :     locus = other.locus;
    1434                 :             : 
    1435                 :             :     generic_params.reserve (other.generic_params.size ());
    1436                 :             :     for (const auto &e : other.generic_params)
    1437                 :             :       generic_params.push_back (e->clone_generic_param ());
    1438                 :             : 
    1439                 :             :     return *this;
    1440                 :             :   }
    1441                 :             : 
    1442                 :             :   // move constructors
    1443                 :             :   Struct (Struct &&other) = default;
    1444                 :             :   Struct &operator= (Struct &&other) = default;
    1445                 :             : };
    1446                 :             : 
    1447                 :             : // A single field in a struct
    1448                 :             : // FIXME can't this be a TupleStruct + field_name?
    1449                 :             : class StructField
    1450                 :             : {
    1451                 :             : public:
    1452                 :             :   // bool has_outer_attributes;
    1453                 :             :   AST::AttrVec outer_attrs;
    1454                 :             : 
    1455                 :             :   // bool has_visibility;
    1456                 :             :   Visibility visibility;
    1457                 :             : 
    1458                 :             :   Identifier field_name;
    1459                 :             :   std::unique_ptr<Type> field_type;
    1460                 :             : 
    1461                 :             :   Analysis::NodeMapping mappings;
    1462                 :             : 
    1463                 :             :   location_t locus;
    1464                 :             : 
    1465                 :             :   // Returns whether struct field has any outer attributes.
    1466                 :             :   bool has_outer_attributes () const { return !outer_attrs.empty (); }
    1467                 :             : 
    1468                 :             :   // Returns whether struct field has a non-private (non-default) visibility.
    1469                 :           0 :   bool has_visibility () const { return !visibility.is_error (); }
    1470                 :             : 
    1471                 :        1661 :   StructField (Analysis::NodeMapping mappings, Identifier field_name,
    1472                 :             :                std::unique_ptr<Type> field_type, Visibility vis,
    1473                 :             :                location_t locus, AST::AttrVec outer_attrs = AST::AttrVec ())
    1474                 :        1661 :     : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
    1475                 :        1661 :       field_name (std::move (field_name)), field_type (std::move (field_type)),
    1476                 :        1661 :       mappings (mappings), locus (locus)
    1477                 :        1661 :   {}
    1478                 :             : 
    1479                 :             :   // Copy constructor
    1480                 :           0 :   StructField (StructField const &other)
    1481                 :           0 :     : outer_attrs (other.outer_attrs), visibility (other.visibility),
    1482                 :           0 :       field_name (other.field_name),
    1483                 :           0 :       field_type (other.field_type->clone_type ()), mappings (other.mappings)
    1484                 :           0 :   {}
    1485                 :             : 
    1486                 :        2772 :   ~StructField () = default;
    1487                 :             : 
    1488                 :             :   // Overloaded assignment operator to clone
    1489                 :             :   StructField &operator= (StructField const &other)
    1490                 :             :   {
    1491                 :             :     field_name = other.field_name;
    1492                 :             :     field_type = other.field_type->clone_type ();
    1493                 :             :     visibility = other.visibility;
    1494                 :             :     outer_attrs = other.outer_attrs;
    1495                 :             :     mappings = other.mappings;
    1496                 :             : 
    1497                 :             :     return *this;
    1498                 :             :   }
    1499                 :             : 
    1500                 :             :   // move constructors
    1501                 :        2749 :   StructField (StructField &&other) = default;
    1502                 :             :   StructField &operator= (StructField &&other) = default;
    1503                 :             : 
    1504                 :             :   std::string as_string () const;
    1505                 :             : 
    1506                 :        5625 :   Identifier get_field_name () const { return field_name; }
    1507                 :             : 
    1508                 :        1798 :   std::unique_ptr<Type> &get_field_type () { return field_type; }
    1509                 :             : 
    1510                 :        4349 :   Analysis::NodeMapping get_mappings () const { return mappings; }
    1511                 :             : 
    1512                 :        1967 :   location_t get_locus () { return locus; }
    1513                 :           0 :   AST::AttrVec &get_outer_attrs () { return outer_attrs; }
    1514                 :         650 :   Visibility &get_visibility () { return visibility; }
    1515                 :             : };
    1516                 :             : 
    1517                 :             : // Rust struct declaration with true struct type HIR node
    1518                 :             : class StructStruct : public Struct
    1519                 :             : {
    1520                 :             : public:
    1521                 :             :   std::vector<StructField> fields;
    1522                 :             :   bool is_unit;
    1523                 :             : 
    1524                 :             :   std::string as_string () const override;
    1525                 :             : 
    1526                 :             :   // Mega-constructor with all possible fields
    1527                 :         915 :   StructStruct (Analysis::NodeMapping mappings, std::vector<StructField> fields,
    1528                 :             :                 Identifier struct_name,
    1529                 :             :                 std::vector<std::unique_ptr<GenericParam>> generic_params,
    1530                 :             :                 WhereClause where_clause, bool is_unit, Visibility vis,
    1531                 :             :                 AST::AttrVec outer_attrs, location_t locus)
    1532                 :         915 :     : Struct (std::move (mappings), std::move (struct_name),
    1533                 :             :               std::move (generic_params), std::move (where_clause),
    1534                 :             :               std::move (vis), locus, std::move (outer_attrs)),
    1535                 :         915 :       fields (std::move (fields)), is_unit (is_unit)
    1536                 :         915 :   {}
    1537                 :             : 
    1538                 :             :   // Unit struct constructor
    1539                 :             :   StructStruct (Analysis::NodeMapping mappings, Identifier struct_name,
    1540                 :             :                 std::vector<std::unique_ptr<GenericParam>> generic_params,
    1541                 :             :                 WhereClause where_clause, Visibility vis,
    1542                 :             :                 AST::AttrVec outer_attrs, location_t locus)
    1543                 :             :     : Struct (std::move (mappings), std::move (struct_name),
    1544                 :             :               std::move (generic_params), std::move (where_clause),
    1545                 :             :               std::move (vis), locus, std::move (outer_attrs)),
    1546                 :             :       is_unit (true)
    1547                 :             :   {}
    1548                 :             :   // TODO: can a unit struct have generic fields? assuming yes for now.
    1549                 :             : 
    1550                 :             :   /* Returns whether the struct is a unit struct - struct defined without
    1551                 :             :    * fields. This is important because it also means an implicit constant of its
    1552                 :             :    * type is defined. */
    1553                 :           0 :   bool is_unit_struct () const { return is_unit; }
    1554                 :             : 
    1555                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1556                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    1557                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
    1558                 :             : 
    1559                 :        1686 :   std::vector<StructField> &get_fields () { return fields; }
    1560                 :             : 
    1561                 :             : protected:
    1562                 :             :   /* Use covariance to implement clone function as returning this object
    1563                 :             :    * rather than base */
    1564                 :           0 :   StructStruct *clone_item_impl () const override
    1565                 :             :   {
    1566                 :           0 :     return new StructStruct (*this);
    1567                 :             :   }
    1568                 :             : 
    1569                 :             :   /* Use covariance to implement clone function as returning this object
    1570                 :             :    * rather than base */
    1571                 :             :   /*virtual StructStruct* clone_statement_impl() const override {
    1572                 :             :       return new StructStruct(*this);
    1573                 :             :   }*/
    1574                 :             : };
    1575                 :             : 
    1576                 :             : // A single field in a tuple
    1577                 :             : class TupleField
    1578                 :             : {
    1579                 :             : private:
    1580                 :             :   // bool has_outer_attributes;
    1581                 :             :   AST::AttrVec outer_attrs;
    1582                 :             : 
    1583                 :             :   // bool has_visibility;
    1584                 :             :   Visibility visibility;
    1585                 :             : 
    1586                 :             :   std::unique_ptr<Type> field_type;
    1587                 :             : 
    1588                 :             :   location_t locus;
    1589                 :             : 
    1590                 :             :   Analysis::NodeMapping mappings;
    1591                 :             : 
    1592                 :             : public:
    1593                 :             :   // Returns whether tuple field has outer attributes.
    1594                 :             :   bool has_outer_attributes () const { return !outer_attrs.empty (); }
    1595                 :             : 
    1596                 :             :   /* Returns whether tuple field has a non-default visibility (i.e. a public
    1597                 :             :    * one) */
    1598                 :           0 :   bool has_visibility () const { return !visibility.is_error (); }
    1599                 :             : 
    1600                 :             :   // Complete constructor
    1601                 :        1453 :   TupleField (Analysis::NodeMapping mapping, std::unique_ptr<Type> field_type,
    1602                 :             :               Visibility vis, location_t locus,
    1603                 :             :               AST::AttrVec outer_attrs = AST::AttrVec ())
    1604                 :        1453 :     : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
    1605                 :        1453 :       field_type (std::move (field_type)), locus (locus), mappings (mapping)
    1606                 :        1453 :   {}
    1607                 :             : 
    1608                 :             :   // Copy constructor with clone
    1609                 :           0 :   TupleField (TupleField const &other)
    1610                 :           0 :     : outer_attrs (other.outer_attrs), visibility (other.visibility),
    1611                 :           0 :       field_type (other.field_type->clone_type ()), locus (other.locus),
    1612                 :           0 :       mappings (other.mappings)
    1613                 :           0 :   {}
    1614                 :             : 
    1615                 :        2093 :   ~TupleField () = default;
    1616                 :             : 
    1617                 :             :   // Overloaded assignment operator to clone
    1618                 :             :   TupleField &operator= (TupleField const &other)
    1619                 :             :   {
    1620                 :             :     field_type = other.field_type->clone_type ();
    1621                 :             :     visibility = other.visibility;
    1622                 :             :     outer_attrs = other.outer_attrs;
    1623                 :             :     locus = other.locus;
    1624                 :             :     mappings = other.mappings;
    1625                 :             : 
    1626                 :             :     return *this;
    1627                 :             :   }
    1628                 :             : 
    1629                 :             :   // move constructors
    1630                 :        2083 :   TupleField (TupleField &&other) = default;
    1631                 :             :   TupleField &operator= (TupleField &&other) = default;
    1632                 :             : 
    1633                 :             :   // Returns whether tuple field is in an error state.
    1634                 :             :   bool is_error () const { return field_type == nullptr; }
    1635                 :             : 
    1636                 :             :   std::string as_string () const;
    1637                 :             : 
    1638                 :        3050 :   Analysis::NodeMapping get_mappings () const { return mappings; }
    1639                 :             : 
    1640                 :           0 :   Visibility &get_visibility () { return visibility; }
    1641                 :             : 
    1642                 :        1442 :   location_t get_locus () const { return locus; }
    1643                 :             : 
    1644                 :           0 :   AST::AttrVec &get_outer_attrs () { return outer_attrs; }
    1645                 :        1442 :   std::unique_ptr<HIR::Type> &get_field_type () { return field_type; }
    1646                 :             : };
    1647                 :             : 
    1648                 :             : // Rust tuple declared using struct keyword HIR node
    1649                 :             : class TupleStruct : public Struct
    1650                 :             : {
    1651                 :             :   std::vector<TupleField> fields;
    1652                 :             : 
    1653                 :             : public:
    1654                 :             :   std::string as_string () const override;
    1655                 :             : 
    1656                 :             :   // Mega-constructor with all possible fields
    1657                 :         756 :   TupleStruct (Analysis::NodeMapping mappings, std::vector<TupleField> fields,
    1658                 :             :                Identifier struct_name,
    1659                 :             :                std::vector<std::unique_ptr<GenericParam>> generic_params,
    1660                 :             :                WhereClause where_clause, Visibility vis,
    1661                 :             :                AST::AttrVec outer_attrs, location_t locus)
    1662                 :         756 :     : Struct (std::move (mappings), std::move (struct_name),
    1663                 :             :               std::move (generic_params), std::move (where_clause),
    1664                 :             :               std::move (vis), locus, std::move (outer_attrs)),
    1665                 :         756 :       fields (std::move (fields))
    1666                 :         756 :   {}
    1667                 :             : 
    1668                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1669                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    1670                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
    1671                 :             : 
    1672                 :         754 :   std::vector<TupleField> &get_fields () { return fields; }
    1673                 :             :   const std::vector<TupleField> &get_fields () const { return fields; }
    1674                 :             : 
    1675                 :             : protected:
    1676                 :             :   /* Use covariance to implement clone function as returning this object
    1677                 :             :    * rather than base */
    1678                 :           0 :   TupleStruct *clone_item_impl () const override
    1679                 :             :   {
    1680                 :           0 :     return new TupleStruct (*this);
    1681                 :             :   }
    1682                 :             : 
    1683                 :             :   /* Use covariance to implement clone function as returning this object
    1684                 :             :    * rather than base */
    1685                 :             :   /*virtual TupleStruct* clone_statement_impl() const override {
    1686                 :             :       return new TupleStruct(*this);
    1687                 :             :   }*/
    1688                 :             : };
    1689                 :             : 
    1690                 :             : /* An item used in an "enum" tagged union - not abstract: base represents a
    1691                 :             :    name-only enum. Syntactically EnumItem's can have a Visibility. But not
    1692                 :             :    Semantically. So check there is no Visibility when lowering and make this
    1693                 :             :    an Item, not an VisItem.  */
    1694                 :             : class EnumItem : public Item
    1695                 :             : {
    1696                 :             :   Identifier variant_name;
    1697                 :             :   location_t locus;
    1698                 :             : 
    1699                 :             : public:
    1700                 :          29 :   virtual ~EnumItem () {}
    1701                 :             : 
    1702                 :             :   enum EnumItemKind
    1703                 :             :   {
    1704                 :             :     Named,
    1705                 :             :     Tuple,
    1706                 :             :     Struct,
    1707                 :             :     Discriminant,
    1708                 :             :   };
    1709                 :             : 
    1710                 :         422 :   EnumItem (Analysis::NodeMapping mappings, Identifier variant_name,
    1711                 :             :             AST::AttrVec outer_attrs, location_t locus)
    1712                 :         422 :     : Item (std::move (mappings), std::move (outer_attrs)),
    1713                 :         422 :       variant_name (std::move (variant_name)), locus (locus)
    1714                 :         422 :   {}
    1715                 :             : 
    1716                 :             :   // Unique pointer custom clone function
    1717                 :           0 :   std::unique_ptr<EnumItem> clone_enum_item () const
    1718                 :             :   {
    1719                 :           0 :     return std::unique_ptr<EnumItem> (clone_item_impl ());
    1720                 :             :   }
    1721                 :             : 
    1722                 :             :   virtual std::string as_string () const override;
    1723                 :         361 :   virtual EnumItemKind get_enum_item_kind () const { return Named; };
    1724                 :             : 
    1725                 :             :   // not pure virtual as not abstract
    1726                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1727                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    1728                 :             :   // void accept_vis (HIRVisItemVisitor &vis) override;
    1729                 :             : 
    1730                 :        1878 :   location_t get_locus () const override { return locus; }
    1731                 :             : 
    1732                 :         401 :   Identifier get_identifier () const { return variant_name; }
    1733                 :             : 
    1734                 :           0 :   ItemKind get_item_kind () const override { return ItemKind::EnumItem; }
    1735                 :             : 
    1736                 :             : protected:
    1737                 :           0 :   EnumItem *clone_item_impl () const override { return new EnumItem (*this); }
    1738                 :             : };
    1739                 :             : 
    1740                 :             : // A tuple item used in an "enum" tagged union
    1741                 :             : class EnumItemTuple : public EnumItem
    1742                 :             : {
    1743                 :             :   // bool has_tuple_fields;
    1744                 :             :   std::vector<TupleField> tuple_fields;
    1745                 :             : 
    1746                 :             : public:
    1747                 :             :   // Returns whether tuple enum item has tuple fields.
    1748                 :           0 :   bool has_tuple_fields () const { return !tuple_fields.empty (); }
    1749                 :             : 
    1750                 :         338 :   EnumItemKind get_enum_item_kind () const override
    1751                 :             :   {
    1752                 :         338 :     return EnumItemKind::Tuple;
    1753                 :             :   }
    1754                 :             : 
    1755                 :         176 :   EnumItemTuple (Analysis::NodeMapping mappings, Identifier variant_name,
    1756                 :             :                  std::vector<TupleField> tuple_fields, AST::AttrVec outer_attrs,
    1757                 :             :                  location_t locus)
    1758                 :         176 :     : EnumItem (std::move (mappings), std::move (variant_name),
    1759                 :             :                 std::move (outer_attrs), locus),
    1760                 :         176 :       tuple_fields (std::move (tuple_fields))
    1761                 :         176 :   {}
    1762                 :             : 
    1763                 :             :   std::string as_string () const override;
    1764                 :             : 
    1765                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1766                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    1767                 :             : 
    1768                 :         338 :   std::vector<TupleField> &get_tuple_fields () { return tuple_fields; }
    1769                 :             : 
    1770                 :             : protected:
    1771                 :             :   // Clone function implementation as (not pure) virtual method
    1772                 :           0 :   EnumItemTuple *clone_item_impl () const override
    1773                 :             :   {
    1774                 :           0 :     return new EnumItemTuple (*this);
    1775                 :             :   }
    1776                 :             : };
    1777                 :             : 
    1778                 :             : // A struct item used in an "enum" tagged union
    1779                 :             : class EnumItemStruct : public EnumItem
    1780                 :             : {
    1781                 :             :   // bool has_struct_fields;
    1782                 :             :   std::vector<StructField> struct_fields;
    1783                 :             : 
    1784                 :             : public:
    1785                 :             :   // Returns whether struct enum item has struct fields.
    1786                 :           0 :   bool has_struct_fields () const { return !struct_fields.empty (); }
    1787                 :             : 
    1788                 :          77 :   EnumItemKind get_enum_item_kind () const override
    1789                 :             :   {
    1790                 :          77 :     return EnumItemKind::Struct;
    1791                 :             :   }
    1792                 :             : 
    1793                 :          46 :   EnumItemStruct (Analysis::NodeMapping mappings, Identifier variant_name,
    1794                 :             :                   std::vector<StructField> struct_fields,
    1795                 :             :                   AST::AttrVec outer_attrs, location_t locus)
    1796                 :          46 :     : EnumItem (std::move (mappings), std::move (variant_name),
    1797                 :             :                 std::move (outer_attrs), locus),
    1798                 :          46 :       struct_fields (std::move (struct_fields))
    1799                 :          46 :   {}
    1800                 :             : 
    1801                 :             :   std::string as_string () const override;
    1802                 :             : 
    1803                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1804                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    1805                 :             : 
    1806                 :          77 :   std::vector<StructField> &get_struct_fields () { return struct_fields; }
    1807                 :             : 
    1808                 :             : protected:
    1809                 :             :   // Clone function implementation as (not pure) virtual method
    1810                 :           0 :   EnumItemStruct *clone_item_impl () const override
    1811                 :             :   {
    1812                 :           0 :     return new EnumItemStruct (*this);
    1813                 :             :   }
    1814                 :             : };
    1815                 :             : 
    1816                 :             : // A discriminant (numbered enum) item used in an "enum" tagged union
    1817                 :             : class EnumItemDiscriminant : public EnumItem
    1818                 :             : {
    1819                 :             :   std::unique_ptr<Expr> expression;
    1820                 :             : 
    1821                 :             : public:
    1822                 :           5 :   EnumItemDiscriminant (Analysis::NodeMapping mappings, Identifier variant_name,
    1823                 :             :                         std::unique_ptr<Expr> expr, AST::AttrVec outer_attrs,
    1824                 :             :                         location_t locus)
    1825                 :           5 :     : EnumItem (std::move (mappings), std::move (variant_name),
    1826                 :             :                 std::move (outer_attrs), locus),
    1827                 :           5 :       expression (std::move (expr))
    1828                 :           5 :   {}
    1829                 :             : 
    1830                 :             :   // Copy constructor with clone
    1831                 :           0 :   EnumItemDiscriminant (EnumItemDiscriminant const &other)
    1832                 :           0 :     : EnumItem (other), expression (other.expression->clone_expr ())
    1833                 :           0 :   {}
    1834                 :             : 
    1835                 :             :   // Overloaded assignment operator to clone
    1836                 :             :   EnumItemDiscriminant &operator= (EnumItemDiscriminant const &other)
    1837                 :             :   {
    1838                 :             :     EnumItem::operator= (other);
    1839                 :             :     expression = other.expression->clone_expr ();
    1840                 :             :     // variant_name = other.variant_name;
    1841                 :             :     // outer_attrs = other.outer_attrs;
    1842                 :             : 
    1843                 :             :     return *this;
    1844                 :             :   }
    1845                 :             : 
    1846                 :             :   // move constructors
    1847                 :             :   EnumItemDiscriminant (EnumItemDiscriminant &&other) = default;
    1848                 :             :   EnumItemDiscriminant &operator= (EnumItemDiscriminant &&other) = default;
    1849                 :             : 
    1850                 :           2 :   EnumItemKind get_enum_item_kind () const override
    1851                 :             :   {
    1852                 :           2 :     return EnumItemKind::Discriminant;
    1853                 :             :   }
    1854                 :             : 
    1855                 :             :   std::string as_string () const override;
    1856                 :             : 
    1857                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1858                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    1859                 :             : 
    1860                 :           2 :   std::unique_ptr<Expr> &get_discriminant_expression () { return expression; }
    1861                 :             : 
    1862                 :             : protected:
    1863                 :             :   // Clone function implementation as (not pure) virtual method
    1864                 :           0 :   EnumItemDiscriminant *clone_item_impl () const override
    1865                 :             :   {
    1866                 :           0 :     return new EnumItemDiscriminant (*this);
    1867                 :             :   }
    1868                 :             : };
    1869                 :             : 
    1870                 :             : // HIR node for Rust "enum" - tagged union
    1871                 :             : class Enum : public VisItem
    1872                 :             : {
    1873                 :             :   Identifier enum_name;
    1874                 :             : 
    1875                 :             :   // bool has_generics;
    1876                 :             :   // Generics generic_params;
    1877                 :             :   std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined
    1878                 :             : 
    1879                 :             :   // bool has_where_clause;
    1880                 :             :   WhereClause where_clause;
    1881                 :             : 
    1882                 :             :   std::vector<std::unique_ptr<EnumItem>> items;
    1883                 :             : 
    1884                 :             :   location_t locus;
    1885                 :             : 
    1886                 :             : public:
    1887                 :             :   std::string as_string () const override;
    1888                 :             : 
    1889                 :             :   // Returns whether "enum" has generic parameters.
    1890                 :         163 :   bool has_generics () const { return !generic_params.empty (); }
    1891                 :             : 
    1892                 :             :   // Returns whether "enum" has a where clause.
    1893                 :           0 :   bool has_where_clause () const { return !where_clause.is_empty (); }
    1894                 :             : 
    1895                 :             :   /* Returns whether enum is a "zero-variant" (no possible variant) enum,
    1896                 :             :    * which cannot be instantiated. */
    1897                 :             :   bool is_zero_variant () const { return items.empty (); }
    1898                 :             : 
    1899                 :             :   // Mega-constructor
    1900                 :         169 :   Enum (Analysis::NodeMapping mappings, Identifier enum_name, Visibility vis,
    1901                 :             :         std::vector<std::unique_ptr<GenericParam>> generic_params,
    1902                 :             :         WhereClause where_clause, std::vector<std::unique_ptr<EnumItem>> items,
    1903                 :             :         AST::AttrVec outer_attrs, location_t locus)
    1904                 :         169 :     : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
    1905                 :         338 :       enum_name (std::move (enum_name)),
    1906                 :         169 :       generic_params (std::move (generic_params)),
    1907                 :         169 :       where_clause (std::move (where_clause)), items (std::move (items)),
    1908                 :         169 :       locus (locus)
    1909                 :         169 :   {}
    1910                 :             : 
    1911                 :             :   // TODO: constructor with less arguments
    1912                 :             : 
    1913                 :             :   // Copy constructor with vector clone
    1914                 :           0 :   Enum (Enum const &other)
    1915                 :           0 :     : VisItem (other), enum_name (other.enum_name),
    1916                 :           0 :       where_clause (other.where_clause), locus (other.locus)
    1917                 :             :   {
    1918                 :           0 :     generic_params.reserve (other.generic_params.size ());
    1919                 :           0 :     for (const auto &e : other.generic_params)
    1920                 :           0 :       generic_params.push_back (e->clone_generic_param ());
    1921                 :             : 
    1922                 :           0 :     items.reserve (other.items.size ());
    1923                 :           0 :     for (const auto &e : other.items)
    1924                 :           0 :       items.push_back (e->clone_enum_item ());
    1925                 :           0 :   }
    1926                 :             : 
    1927                 :             :   // Overloaded assignment operator with vector clone
    1928                 :             :   Enum &operator= (Enum const &other)
    1929                 :             :   {
    1930                 :             :     VisItem::operator= (other);
    1931                 :             :     enum_name = other.enum_name;
    1932                 :             :     where_clause = other.where_clause;
    1933                 :             :     locus = other.locus;
    1934                 :             : 
    1935                 :             :     generic_params.reserve (other.generic_params.size ());
    1936                 :             :     for (const auto &e : other.generic_params)
    1937                 :             :       generic_params.push_back (e->clone_generic_param ());
    1938                 :             : 
    1939                 :             :     items.reserve (other.items.size ());
    1940                 :             :     for (const auto &e : other.items)
    1941                 :             :       items.push_back (e->clone_enum_item ());
    1942                 :             : 
    1943                 :             :     return *this;
    1944                 :             :   }
    1945                 :             : 
    1946                 :             :   // Move constructors
    1947                 :             :   Enum (Enum &&other) = default;
    1948                 :             :   Enum &operator= (Enum &&other) = default;
    1949                 :             : 
    1950                 :         662 :   location_t get_locus () const override final { return locus; }
    1951                 :             : 
    1952                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1953                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    1954                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
    1955                 :             : 
    1956                 :         163 :   Identifier get_identifier () const { return enum_name; }
    1957                 :           0 :   ItemKind get_item_kind () const override { return ItemKind::Enum; }
    1958                 :             : 
    1959                 :         392 :   std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
    1960                 :             :   {
    1961                 :         392 :     return generic_params;
    1962                 :             :   }
    1963                 :             : 
    1964                 :             :   const std::vector<std::unique_ptr<EnumItem>> &get_variants () const
    1965                 :             :   {
    1966                 :             :     return items;
    1967                 :             :   }
    1968                 :             : 
    1969                 :         642 :   std::vector<std::unique_ptr<EnumItem>> &get_variants () { return items; }
    1970                 :           0 :   WhereClause &get_where_clause () { return where_clause; }
    1971                 :             : 
    1972                 :             : protected:
    1973                 :             :   /* Use covariance to implement clone function as returning this object
    1974                 :             :    * rather than base */
    1975                 :           0 :   Enum *clone_item_impl () const override { return new Enum (*this); }
    1976                 :             : 
    1977                 :             :   /* Use covariance to implement clone function as returning this object
    1978                 :             :    * rather than base */
    1979                 :             :   /*virtual Enum* clone_statement_impl() const override {
    1980                 :             :       return new Enum(*this);
    1981                 :             :   }*/
    1982                 :             : };
    1983                 :             : 
    1984                 :             : // Rust untagged union used for C compat HIR node
    1985                 :             : class Union : public VisItem
    1986                 :             : {
    1987                 :             :   Identifier union_name;
    1988                 :             : 
    1989                 :             :   // bool has_generics;
    1990                 :             :   // Generics generic_params;
    1991                 :             :   std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined
    1992                 :             : 
    1993                 :             :   // bool has_where_clause;
    1994                 :             :   WhereClause where_clause;
    1995                 :             : 
    1996                 :             :   std::vector<StructField> variants;
    1997                 :             : 
    1998                 :             :   location_t locus;
    1999                 :             : 
    2000                 :             : public:
    2001                 :             :   std::string as_string () const override;
    2002                 :             : 
    2003                 :             :   // Returns whether union has generic params.
    2004                 :          90 :   bool has_generics () const { return !generic_params.empty (); }
    2005                 :             : 
    2006                 :             :   // Returns whether union has where clause.
    2007                 :           0 :   bool has_where_clause () const { return !where_clause.is_empty (); }
    2008                 :             : 
    2009                 :          92 :   Union (Analysis::NodeMapping mappings, Identifier union_name, Visibility vis,
    2010                 :             :          std::vector<std::unique_ptr<GenericParam>> generic_params,
    2011                 :             :          WhereClause where_clause, std::vector<StructField> variants,
    2012                 :             :          AST::AttrVec outer_attrs, location_t locus)
    2013                 :          92 :     : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
    2014                 :         184 :       union_name (std::move (union_name)),
    2015                 :          92 :       generic_params (std::move (generic_params)),
    2016                 :          92 :       where_clause (std::move (where_clause)), variants (std::move (variants)),
    2017                 :          92 :       locus (locus)
    2018                 :          92 :   {}
    2019                 :             : 
    2020                 :             :   // copy constructor with vector clone
    2021                 :           0 :   Union (Union const &other)
    2022                 :           0 :     : VisItem (other), union_name (other.union_name),
    2023                 :           0 :       where_clause (other.where_clause), variants (other.variants),
    2024                 :           0 :       locus (other.locus)
    2025                 :             :   {
    2026                 :           0 :     generic_params.reserve (other.generic_params.size ());
    2027                 :           0 :     for (const auto &e : other.generic_params)
    2028                 :           0 :       generic_params.push_back (e->clone_generic_param ());
    2029                 :           0 :   }
    2030                 :             : 
    2031                 :             :   // overloaded assignment operator with vector clone
    2032                 :             :   Union &operator= (Union const &other)
    2033                 :             :   {
    2034                 :             :     VisItem::operator= (other);
    2035                 :             :     union_name = other.union_name;
    2036                 :             :     where_clause = other.where_clause;
    2037                 :             :     variants = other.variants;
    2038                 :             :     locus = other.locus;
    2039                 :             : 
    2040                 :             :     generic_params.reserve (other.generic_params.size ());
    2041                 :             :     for (const auto &e : other.generic_params)
    2042                 :             :       generic_params.push_back (e->clone_generic_param ());
    2043                 :             : 
    2044                 :             :     return *this;
    2045                 :             :   }
    2046                 :             : 
    2047                 :             :   // move constructors
    2048                 :             :   Union (Union &&other) = default;
    2049                 :             :   Union &operator= (Union &&other) = default;
    2050                 :             : 
    2051                 :         243 :   std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
    2052                 :             :   {
    2053                 :         243 :     return generic_params;
    2054                 :             :   }
    2055                 :             : 
    2056                 :         180 :   Identifier get_identifier () const { return union_name; }
    2057                 :             : 
    2058                 :         366 :   location_t get_locus () const override final { return locus; }
    2059                 :             : 
    2060                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    2061                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    2062                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
    2063                 :             : 
    2064                 :          90 :   std::vector<StructField> &get_variants () { return variants; }
    2065                 :             : 
    2066                 :          90 :   WhereClause &get_where_clause () { return where_clause; }
    2067                 :             : 
    2068                 :           0 :   ItemKind get_item_kind () const override { return ItemKind::Union; }
    2069                 :             : 
    2070                 :             : protected:
    2071                 :             :   /* Use covariance to implement clone function as returning this object
    2072                 :             :    * rather than base */
    2073                 :           0 :   Union *clone_item_impl () const override { return new Union (*this); }
    2074                 :             : };
    2075                 :             : 
    2076                 :             : class ConstantItem : public VisItem, public ImplItem
    2077                 :             : {
    2078                 :             :   Identifier identifier;
    2079                 :             :   std::unique_ptr<Type> type;
    2080                 :             :   std::unique_ptr<Expr> const_expr;
    2081                 :             :   location_t locus;
    2082                 :             : 
    2083                 :             : public:
    2084                 :             :   std::string as_string () const override;
    2085                 :             : 
    2086                 :         462 :   ConstantItem (Analysis::NodeMapping mappings, Identifier ident,
    2087                 :             :                 Visibility vis, std::unique_ptr<Type> type,
    2088                 :             :                 std::unique_ptr<Expr> const_expr, AST::AttrVec outer_attrs,
    2089                 :             :                 location_t locus)
    2090                 :         462 :     : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
    2091                 :         462 :       identifier (std::move (ident)), type (std::move (type)),
    2092                 :         462 :       const_expr (std::move (const_expr)), locus (locus)
    2093                 :         462 :   {}
    2094                 :             : 
    2095                 :           0 :   ConstantItem (ConstantItem const &other)
    2096                 :           0 :     : VisItem (other), identifier (other.identifier),
    2097                 :           0 :       type (other.type->clone_type ()),
    2098                 :           0 :       const_expr (other.const_expr->clone_expr ()), locus (other.locus)
    2099                 :           0 :   {}
    2100                 :             : 
    2101                 :             :   // Overload assignment operator to clone
    2102                 :             :   ConstantItem &operator= (ConstantItem const &other)
    2103                 :             :   {
    2104                 :             :     VisItem::operator= (other);
    2105                 :             :     identifier = other.identifier;
    2106                 :             :     type = other.type->clone_type ();
    2107                 :             :     const_expr = other.const_expr->clone_expr ();
    2108                 :             :     locus = other.locus;
    2109                 :             : 
    2110                 :             :     return *this;
    2111                 :             :   }
    2112                 :             : 
    2113                 :             :   // move constructors
    2114                 :             :   ConstantItem (ConstantItem &&other) = default;
    2115                 :             :   ConstantItem &operator= (ConstantItem &&other) = default;
    2116                 :             : 
    2117                 :             :   // Returns whether constant item is an "unnamed" (wildcard underscore used
    2118                 :             :   // as identifier) constant.
    2119                 :             :   bool is_unnamed () const
    2120                 :             :   {
    2121                 :             :     return identifier.as_string () == std::string ("_");
    2122                 :             :   }
    2123                 :             : 
    2124                 :        2281 :   location_t get_locus () const override final { return locus; }
    2125                 :             : 
    2126                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    2127                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    2128                 :             :   void accept_vis (HIRImplVisitor &vis) override;
    2129                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
    2130                 :             : 
    2131                 :         924 :   std::unique_ptr<Type> &get_type () { return type; }
    2132                 :             : 
    2133                 :        2272 :   std::unique_ptr<Expr> &get_expr () { return const_expr; }
    2134                 :             : 
    2135                 :         141 :   Identifier get_identifier () const { return identifier; }
    2136                 :             : 
    2137                 :         435 :   Analysis::NodeMapping get_impl_mappings () const override
    2138                 :             :   {
    2139                 :         435 :     return get_mappings ();
    2140                 :             :   };
    2141                 :             : 
    2142                 :          95 :   ImplItemType get_impl_item_type () const override final
    2143                 :             :   {
    2144                 :          95 :     return ImplItem::ImplItemType::CONSTANT;
    2145                 :             :   }
    2146                 :             : 
    2147                 :         517 :   ItemKind get_item_kind () const override { return ItemKind::Constant; }
    2148                 :             : 
    2149                 :          30 :   std::string get_impl_item_name () const override final
    2150                 :             :   {
    2151                 :          30 :     return get_identifier ().as_string ();
    2152                 :             :   }
    2153                 :             : 
    2154                 :             : protected:
    2155                 :             :   /* Use covariance to implement clone function as returning this object
    2156                 :             :    * rather than base */
    2157                 :           0 :   ConstantItem *clone_item_impl () const override
    2158                 :             :   {
    2159                 :           0 :     return new ConstantItem (*this);
    2160                 :             :   }
    2161                 :             : 
    2162                 :             :   /* Use covariance to implement clone function as returning this object
    2163                 :             :    * rather than base */
    2164                 :           0 :   ConstantItem *clone_inherent_impl_item_impl () const override
    2165                 :             :   {
    2166                 :           0 :     return new ConstantItem (*this);
    2167                 :             :   }
    2168                 :             : };
    2169                 :             : 
    2170                 :             : /* Static item HIR node - items within module scope with fixed storage
    2171                 :             :  * duration? */
    2172                 :             : class StaticItem : public VisItem
    2173                 :             : {
    2174                 :             :   Mutability mut;
    2175                 :             :   Identifier name;
    2176                 :             :   std::unique_ptr<Type> type;
    2177                 :             :   std::unique_ptr<Expr> expr;
    2178                 :             :   location_t locus;
    2179                 :             : 
    2180                 :             : public:
    2181                 :             :   std::string as_string () const override;
    2182                 :             : 
    2183                 :          41 :   StaticItem (Analysis::NodeMapping mappings, Identifier name, Mutability mut,
    2184                 :             :               std::unique_ptr<Type> type, std::unique_ptr<Expr> expr,
    2185                 :             :               Visibility vis, AST::AttrVec outer_attrs, location_t locus)
    2186                 :          41 :     : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
    2187                 :          82 :       mut (mut), name (std::move (name)), type (std::move (type)),
    2188                 :          41 :       expr (std::move (expr)), locus (locus)
    2189                 :          41 :   {}
    2190                 :             : 
    2191                 :             :   // Copy constructor with clone
    2192                 :           0 :   StaticItem (StaticItem const &other)
    2193                 :           0 :     : VisItem (other), mut (other.mut), name (other.name),
    2194                 :           0 :       type (other.type->clone_type ()), expr (other.expr->clone_expr ()),
    2195                 :           0 :       locus (other.locus)
    2196                 :           0 :   {}
    2197                 :             : 
    2198                 :             :   // Overloaded assignment operator to clone
    2199                 :             :   StaticItem &operator= (StaticItem const &other)
    2200                 :             :   {
    2201                 :             :     VisItem::operator= (other);
    2202                 :             :     name = other.name;
    2203                 :             :     mut = other.mut;
    2204                 :             :     type = other.type->clone_type ();
    2205                 :             :     expr = other.expr->clone_expr ();
    2206                 :             :     locus = other.locus;
    2207                 :             : 
    2208                 :             :     return *this;
    2209                 :             :   }
    2210                 :             : 
    2211                 :             :   // move constructors
    2212                 :             :   StaticItem (StaticItem &&other) = default;
    2213                 :             :   StaticItem &operator= (StaticItem &&other) = default;
    2214                 :             : 
    2215                 :         245 :   location_t get_locus () const override final { return locus; }
    2216                 :             : 
    2217                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    2218                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    2219                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
    2220                 :             : 
    2221                 :           0 :   Identifier get_identifier () const { return name; }
    2222                 :             : 
    2223                 :             :   Mutability get_mut () const { return mut; }
    2224                 :             : 
    2225                 :          18 :   bool is_mut () const { return mut == Mutability::Mut; }
    2226                 :             : 
    2227                 :         198 :   std::unique_ptr<Expr> &get_expr () { return expr; }
    2228                 :             : 
    2229                 :          80 :   std::unique_ptr<Type> &get_type () { return type; }
    2230                 :             : 
    2231                 :          18 :   ItemKind get_item_kind () const override { return ItemKind::Static; }
    2232                 :             : 
    2233                 :             : protected:
    2234                 :           0 :   StaticItem *clone_item_impl () const override
    2235                 :             :   {
    2236                 :           0 :     return new StaticItem (*this);
    2237                 :             :   }
    2238                 :             : };
    2239                 :             : 
    2240                 :             : // Function declaration in traits
    2241                 :             : class TraitFunctionDecl
    2242                 :             : {
    2243                 :             : private:
    2244                 :             :   FunctionQualifiers qualifiers;
    2245                 :             :   Identifier function_name;
    2246                 :             :   std::vector<std::unique_ptr<GenericParam>> generic_params;
    2247                 :             :   std::vector<FunctionParam> function_params;
    2248                 :             :   std::unique_ptr<Type> return_type;
    2249                 :             :   WhereClause where_clause;
    2250                 :             :   SelfParam self;
    2251                 :             : 
    2252                 :             : public:
    2253                 :             :   // Mega-constructor
    2254                 :        1014 :   TraitFunctionDecl (Identifier function_name, FunctionQualifiers qualifiers,
    2255                 :             :                      std::vector<std::unique_ptr<GenericParam>> generic_params,
    2256                 :             :                      SelfParam self, std::vector<FunctionParam> function_params,
    2257                 :             :                      std::unique_ptr<Type> return_type,
    2258                 :             :                      WhereClause where_clause)
    2259                 :        1014 :     : qualifiers (std::move (qualifiers)),
    2260                 :        1014 :       function_name (std::move (function_name)),
    2261                 :        1014 :       generic_params (std::move (generic_params)),
    2262                 :        1014 :       function_params (std::move (function_params)),
    2263                 :        1014 :       return_type (std::move (return_type)),
    2264                 :        1014 :       where_clause (std::move (where_clause)), self (std::move (self))
    2265                 :        1014 :   {}
    2266                 :             : 
    2267                 :             :   // Copy constructor with clone
    2268                 :           0 :   TraitFunctionDecl (TraitFunctionDecl const &other)
    2269                 :           0 :     : qualifiers (other.qualifiers), function_name (other.function_name),
    2270                 :           0 :       function_params (other.function_params),
    2271                 :           0 :       return_type (other.return_type->clone_type ()),
    2272                 :           0 :       where_clause (other.where_clause), self (other.self)
    2273                 :             :   {
    2274                 :           0 :     generic_params.reserve (other.generic_params.size ());
    2275                 :           0 :     for (const auto &e : other.generic_params)
    2276                 :           0 :       generic_params.push_back (e->clone_generic_param ());
    2277                 :           0 :   }
    2278                 :             : 
    2279                 :        2028 :   ~TraitFunctionDecl () = default;
    2280                 :             : 
    2281                 :             :   // Overloaded assignment operator with clone
    2282                 :             :   TraitFunctionDecl &operator= (TraitFunctionDecl const &other)
    2283                 :             :   {
    2284                 :             :     function_name = other.function_name;
    2285                 :             :     qualifiers = other.qualifiers;
    2286                 :             :     function_params = other.function_params;
    2287                 :             :     return_type = other.return_type->clone_type ();
    2288                 :             :     where_clause = other.where_clause;
    2289                 :             :     self = other.self;
    2290                 :             : 
    2291                 :             :     generic_params.reserve (other.generic_params.size ());
    2292                 :             :     for (const auto &e : other.generic_params)
    2293                 :             :       generic_params.push_back (e->clone_generic_param ());
    2294                 :             : 
    2295                 :             :     return *this;
    2296                 :             :   }
    2297                 :             : 
    2298                 :             :   // move constructors
    2299                 :        2028 :   TraitFunctionDecl (TraitFunctionDecl &&other) = default;
    2300                 :             :   TraitFunctionDecl &operator= (TraitFunctionDecl &&other) = default;
    2301                 :             : 
    2302                 :             :   std::string as_string () const;
    2303                 :             : 
    2304                 :             :   // Returns whether function decl has generic parameters.
    2305                 :        5318 :   bool has_generics () const { return !generic_params.empty (); }
    2306                 :             : 
    2307                 :             :   // Returns whether function decl has regular parameters.
    2308                 :           0 :   bool has_params () const { return !function_params.empty (); }
    2309                 :             : 
    2310                 :             :   // Returns whether function has return type (otherwise is void).
    2311                 :        5483 :   bool has_return_type () const { return return_type != nullptr; }
    2312                 :             : 
    2313                 :             :   // Returns whether function has a where clause.
    2314                 :        5318 :   bool has_where_clause () const { return !where_clause.is_empty (); }
    2315                 :             : 
    2316                 :           0 :   WhereClause &get_where_clause () { return where_clause; }
    2317                 :             : 
    2318                 :       12808 :   bool is_method () const { return !self.is_error (); }
    2319                 :             : 
    2320                 :        4863 :   SelfParam &get_self () { return self; }
    2321                 :             : 
    2322                 :        7238 :   Identifier get_function_name () const { return function_name; }
    2323                 :             : 
    2324                 :           0 :   std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
    2325                 :             :   {
    2326                 :           0 :     return generic_params;
    2327                 :             :   }
    2328                 :             : 
    2329                 :        9599 :   std::unique_ptr<Type> &get_return_type () { return return_type; }
    2330                 :             : 
    2331                 :        6455 :   std::vector<FunctionParam> &get_function_params () { return function_params; }
    2332                 :             : 
    2333                 :         123 :   const FunctionQualifiers &get_qualifiers () const { return qualifiers; }
    2334                 :             : };
    2335                 :             : 
    2336                 :             : // Actual trait item function declaration within traits
    2337                 :             : class TraitItemFunc : public TraitItem
    2338                 :             : {
    2339                 :             :   AST::AttrVec outer_attrs;
    2340                 :             :   TraitFunctionDecl decl;
    2341                 :             :   std::unique_ptr<BlockExpr> block_expr;
    2342                 :             :   location_t locus;
    2343                 :             : 
    2344                 :             : public:
    2345                 :             :   // Returns whether function has a definition or is just a declaration.
    2346                 :           0 :   bool has_definition () const { return block_expr != nullptr; }
    2347                 :             : 
    2348                 :        1014 :   TraitItemFunc (Analysis::NodeMapping mappings, TraitFunctionDecl decl,
    2349                 :             :                  std::unique_ptr<BlockExpr> block_expr,
    2350                 :             :                  AST::AttrVec outer_attrs, location_t locus)
    2351                 :        1014 :     : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
    2352                 :        1014 :       decl (std::move (decl)), block_expr (std::move (block_expr)),
    2353                 :        1014 :       locus (locus)
    2354                 :        1014 :   {}
    2355                 :             : 
    2356                 :             :   // Copy constructor with clone
    2357                 :           0 :   TraitItemFunc (TraitItemFunc const &other)
    2358                 :           0 :     : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
    2359                 :           0 :       decl (other.decl), locus (other.locus)
    2360                 :             :   {
    2361                 :           0 :     if (other.block_expr != nullptr)
    2362                 :           0 :       block_expr = other.block_expr->clone_block_expr ();
    2363                 :           0 :   }
    2364                 :             : 
    2365                 :             :   // Overloaded assignment operator to clone
    2366                 :             :   TraitItemFunc &operator= (TraitItemFunc const &other)
    2367                 :             :   {
    2368                 :             :     TraitItem::operator= (other);
    2369                 :             :     outer_attrs = other.outer_attrs;
    2370                 :             :     decl = other.decl;
    2371                 :             :     locus = other.locus;
    2372                 :             :     mappings = other.mappings;
    2373                 :             :     if (other.block_expr != nullptr)
    2374                 :             :       block_expr = other.block_expr->clone_block_expr ();
    2375                 :             : 
    2376                 :             :     return *this;
    2377                 :             :   }
    2378                 :             : 
    2379                 :             :   // move constructors
    2380                 :             :   TraitItemFunc (TraitItemFunc &&other) = default;
    2381                 :             :   TraitItemFunc &operator= (TraitItemFunc &&other) = default;
    2382                 :             : 
    2383                 :             :   std::string as_string () const override;
    2384                 :             : 
    2385                 :        9125 :   location_t get_locus () const { return locus; }
    2386                 :             : 
    2387                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    2388                 :             :   void accept_vis (HIRTraitItemVisitor &vis) override;
    2389                 :             : 
    2390                 :        9129 :   TraitFunctionDecl &get_decl () { return decl; }
    2391                 :             : 
    2392                 :         676 :   const TraitFunctionDecl &get_decl () const { return decl; }
    2393                 :             : 
    2394                 :        3096 :   bool has_block_defined () const { return block_expr != nullptr; }
    2395                 :             : 
    2396                 :         614 :   std::unique_ptr<BlockExpr> &get_block_expr () { return block_expr; }
    2397                 :             : 
    2398                 :         392 :   const std::string trait_identifier () const override final
    2399                 :             :   {
    2400                 :         392 :     return decl.get_function_name ().as_string ();
    2401                 :             :   }
    2402                 :             : 
    2403                 :        1496 :   TraitItemKind get_item_kind () const override final
    2404                 :             :   {
    2405                 :        1496 :     return TraitItemKind::FUNC;
    2406                 :             :   }
    2407                 :             : 
    2408                 :         123 :   AST::AttrVec &get_outer_attrs () override final { return outer_attrs; }
    2409                 :        2736 :   const AST::AttrVec &get_outer_attrs () const override final
    2410                 :             :   {
    2411                 :        2736 :     return outer_attrs;
    2412                 :             :   }
    2413                 :             : 
    2414                 :        2028 :   location_t get_trait_locus () const override { return get_locus (); }
    2415                 :             : 
    2416                 :             : protected:
    2417                 :             :   // Clone function implementation as (not pure) virtual method
    2418                 :           0 :   TraitItemFunc *clone_trait_item_impl () const override
    2419                 :             :   {
    2420                 :           0 :     return new TraitItemFunc (*this);
    2421                 :             :   }
    2422                 :             : };
    2423                 :             : 
    2424                 :             : // Constant item within traits
    2425                 :             : class TraitItemConst : public TraitItem
    2426                 :             : {
    2427                 :             :   AST::AttrVec outer_attrs;
    2428                 :             :   Identifier name;
    2429                 :             :   std::unique_ptr<Type> type;
    2430                 :             :   std::unique_ptr<Expr> expr;
    2431                 :             :   location_t locus;
    2432                 :             : 
    2433                 :             : public:
    2434                 :             :   // Whether the constant item has an associated expression.
    2435                 :           0 :   bool has_expression () const { return expr != nullptr; }
    2436                 :             : 
    2437                 :          34 :   TraitItemConst (Analysis::NodeMapping mappings, Identifier name,
    2438                 :             :                   std::unique_ptr<Type> type, std::unique_ptr<Expr> expr,
    2439                 :             :                   AST::AttrVec outer_attrs, location_t locus)
    2440                 :          34 :     : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
    2441                 :          34 :       name (std::move (name)), type (std::move (type)), expr (std::move (expr)),
    2442                 :          34 :       locus (locus)
    2443                 :          34 :   {}
    2444                 :             : 
    2445                 :             :   // Copy constructor with clones
    2446                 :           0 :   TraitItemConst (TraitItemConst const &other)
    2447                 :           0 :     : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
    2448                 :           0 :       name (other.name), type (other.type->clone_type ()),
    2449                 :           0 :       expr (other.expr->clone_expr ()), locus (other.locus)
    2450                 :           0 :   {}
    2451                 :             : 
    2452                 :             :   // Overloaded assignment operator to clone
    2453                 :             :   TraitItemConst &operator= (TraitItemConst const &other)
    2454                 :             :   {
    2455                 :             :     TraitItem::operator= (other);
    2456                 :             :     outer_attrs = other.outer_attrs;
    2457                 :             :     name = other.name;
    2458                 :             :     type = other.type->clone_type ();
    2459                 :             :     expr = other.expr->clone_expr ();
    2460                 :             :     locus = other.locus;
    2461                 :             :     mappings = other.mappings;
    2462                 :             : 
    2463                 :             :     return *this;
    2464                 :             :   }
    2465                 :             : 
    2466                 :             :   // move constructors
    2467                 :             :   TraitItemConst (TraitItemConst &&other) = default;
    2468                 :             :   TraitItemConst &operator= (TraitItemConst &&other) = default;
    2469                 :             : 
    2470                 :             :   std::string as_string () const override;
    2471                 :             : 
    2472                 :         109 :   location_t get_locus () const { return locus; }
    2473                 :             : 
    2474                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    2475                 :             :   void accept_vis (HIRTraitItemVisitor &vis) override;
    2476                 :             : 
    2477                 :          34 :   Identifier get_name () const { return name; }
    2478                 :             : 
    2479                 :         121 :   bool has_expr () const { return expr != nullptr; }
    2480                 :             : 
    2481                 :          29 :   std::unique_ptr<Type> &get_type () { return type; }
    2482                 :             : 
    2483                 :          21 :   std::unique_ptr<Expr> &get_expr () { return expr; }
    2484                 :             : 
    2485                 :           0 :   const std::string trait_identifier () const override final
    2486                 :             :   {
    2487                 :           0 :     return name.as_string ();
    2488                 :             :   }
    2489                 :             : 
    2490                 :           0 :   TraitItemKind get_item_kind () const override final
    2491                 :             :   {
    2492                 :           0 :     return TraitItemKind::CONST;
    2493                 :             :   }
    2494                 :             : 
    2495                 :           0 :   AST::AttrVec &get_outer_attrs () override final { return outer_attrs; }
    2496                 :          63 :   const AST::AttrVec &get_outer_attrs () const override final
    2497                 :             :   {
    2498                 :          63 :     return outer_attrs;
    2499                 :             :   }
    2500                 :             : 
    2501                 :          68 :   location_t get_trait_locus () const override { return get_locus (); }
    2502                 :             : 
    2503                 :             : protected:
    2504                 :             :   // Clone function implementation as (not pure) virtual method
    2505                 :           0 :   TraitItemConst *clone_trait_item_impl () const override
    2506                 :             :   {
    2507                 :           0 :     return new TraitItemConst (*this);
    2508                 :             :   }
    2509                 :             : };
    2510                 :             : 
    2511                 :             : // Type items within traits
    2512                 :             : class TraitItemType : public TraitItem
    2513                 :             : {
    2514                 :             :   AST::AttrVec outer_attrs;
    2515                 :             : 
    2516                 :             :   Identifier name;
    2517                 :             :   std::vector<std::unique_ptr<TypeParamBound>>
    2518                 :             :     type_param_bounds; // inlined form
    2519                 :             :   location_t locus;
    2520                 :             : 
    2521                 :             : public:
    2522                 :             :   // Returns whether trait item type has type param bounds.
    2523                 :           0 :   bool has_type_param_bounds () const { return !type_param_bounds.empty (); }
    2524                 :             : 
    2525                 :         474 :   TraitItemType (Analysis::NodeMapping mappings, Identifier name,
    2526                 :             :                  std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
    2527                 :             :                  AST::AttrVec outer_attrs, location_t locus)
    2528                 :         474 :     : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
    2529                 :         474 :       name (std::move (name)),
    2530                 :         474 :       type_param_bounds (std::move (type_param_bounds)), locus (locus)
    2531                 :         474 :   {}
    2532                 :             : 
    2533                 :             :   // Copy constructor with vector clone
    2534                 :           0 :   TraitItemType (TraitItemType const &other)
    2535                 :           0 :     : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
    2536                 :           0 :       name (other.name), locus (other.locus)
    2537                 :             :   {
    2538                 :           0 :     type_param_bounds.reserve (other.type_param_bounds.size ());
    2539                 :           0 :     for (const auto &e : other.type_param_bounds)
    2540                 :           0 :       type_param_bounds.push_back (e->clone_type_param_bound ());
    2541                 :           0 :   }
    2542                 :             : 
    2543                 :             :   // Overloaded assignment operator with vector clone
    2544                 :             :   TraitItemType &operator= (TraitItemType const &other)
    2545                 :             :   {
    2546                 :             :     TraitItem::operator= (other);
    2547                 :             :     outer_attrs = other.outer_attrs;
    2548                 :             :     name = other.name;
    2549                 :             :     locus = other.locus;
    2550                 :             :     mappings = other.mappings;
    2551                 :             : 
    2552                 :             :     type_param_bounds.reserve (other.type_param_bounds.size ());
    2553                 :             :     for (const auto &e : other.type_param_bounds)
    2554                 :             :       type_param_bounds.push_back (e->clone_type_param_bound ());
    2555                 :             : 
    2556                 :             :     return *this;
    2557                 :             :   }
    2558                 :             : 
    2559                 :             :   // default move constructors
    2560                 :             :   TraitItemType (TraitItemType &&other) = default;
    2561                 :             :   TraitItemType &operator= (TraitItemType &&other) = default;
    2562                 :             : 
    2563                 :             :   std::string as_string () const override;
    2564                 :             : 
    2565                 :        1421 :   location_t get_locus () const { return locus; }
    2566                 :             : 
    2567                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    2568                 :             :   void accept_vis (HIRTraitItemVisitor &vis) override;
    2569                 :             : 
    2570                 :         946 :   Identifier get_name () const { return name; }
    2571                 :             : 
    2572                 :           0 :   std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ()
    2573                 :             :   {
    2574                 :           0 :     return type_param_bounds;
    2575                 :             :   }
    2576                 :             : 
    2577                 :         106 :   const std::string trait_identifier () const override final
    2578                 :             :   {
    2579                 :         106 :     return name.as_string ();
    2580                 :             :   }
    2581                 :             : 
    2582                 :          89 :   TraitItemKind get_item_kind () const override final
    2583                 :             :   {
    2584                 :          89 :     return TraitItemKind::TYPE;
    2585                 :             :   }
    2586                 :             : 
    2587                 :           0 :   AST::AttrVec &get_outer_attrs () override final { return outer_attrs; }
    2588                 :        1184 :   const AST::AttrVec &get_outer_attrs () const override final
    2589                 :             :   {
    2590                 :        1184 :     return outer_attrs;
    2591                 :             :   }
    2592                 :             : 
    2593                 :         948 :   location_t get_trait_locus () const override { return get_locus (); }
    2594                 :             : 
    2595                 :             : protected:
    2596                 :             :   // Clone function implementation as (not pure) virtual method
    2597                 :           0 :   TraitItemType *clone_trait_item_impl () const override
    2598                 :             :   {
    2599                 :           0 :     return new TraitItemType (*this);
    2600                 :             :   }
    2601                 :             : };
    2602                 :             : 
    2603                 :             : // Rust trait item declaration HIR node
    2604                 :             : class Trait : public VisItem
    2605                 :             : {
    2606                 :             :   Unsafety unsafety;
    2607                 :             :   Identifier name;
    2608                 :             :   std::vector<std::unique_ptr<GenericParam>> generic_params;
    2609                 :             :   std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds;
    2610                 :             :   WhereClause where_clause;
    2611                 :             :   std::vector<std::unique_ptr<TraitItem>> trait_items;
    2612                 :             :   location_t locus;
    2613                 :             : 
    2614                 :             : public:
    2615                 :             :   std::string as_string () const override;
    2616                 :             : 
    2617                 :             :   // Returns whether trait has generic parameters.
    2618                 :             :   bool has_generics () const { return !generic_params.empty (); }
    2619                 :             : 
    2620                 :             :   // Returns whether trait has type parameter bounds.
    2621                 :        2080 :   bool has_type_param_bounds () const { return !type_param_bounds.empty (); }
    2622                 :             : 
    2623                 :             :   // Returns whether trait has where clause.
    2624                 :           0 :   bool has_where_clause () const { return !where_clause.is_empty (); }
    2625                 :             : 
    2626                 :             :   // Returns whether trait has trait items.
    2627                 :           0 :   bool has_trait_items () const { return !trait_items.empty (); }
    2628                 :             : 
    2629                 :           0 :   std::vector<std::unique_ptr<TraitItem>> &get_trait_items ()
    2630                 :             :   {
    2631                 :        8076 :     return trait_items;
    2632                 :             :   }
    2633                 :             : 
    2634                 :           0 :   WhereClause &get_where_clause () { return where_clause; }
    2635                 :             : 
    2636                 :        6493 :   Identifier get_name () const { return name; }
    2637                 :           0 :   bool is_unsafe () const { return unsafety == Unsafety::Unsafe; }
    2638                 :             : 
    2639                 :             :   // Mega-constructor
    2640                 :        2079 :   Trait (Analysis::NodeMapping mappings, Identifier name, Unsafety unsafety,
    2641                 :             :          std::vector<std::unique_ptr<GenericParam>> generic_params,
    2642                 :             :          std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
    2643                 :             :          WhereClause where_clause,
    2644                 :             :          std::vector<std::unique_ptr<TraitItem>> trait_items, Visibility vis,
    2645                 :             :          AST::AttrVec outer_attrs, location_t locus)
    2646                 :        2079 :     : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
    2647                 :        4158 :       unsafety (unsafety), name (std::move (name)),
    2648                 :        2079 :       generic_params (std::move (generic_params)),
    2649                 :        2079 :       type_param_bounds (std::move (type_param_bounds)),
    2650                 :        2079 :       where_clause (std::move (where_clause)),
    2651                 :        2079 :       trait_items (std::move (trait_items)), locus (locus)
    2652                 :        2079 :   {}
    2653                 :             : 
    2654                 :             :   // Copy constructor with vector clone
    2655                 :           0 :   Trait (Trait const &other)
    2656                 :           0 :     : VisItem (other), unsafety (other.unsafety), name (other.name),
    2657                 :           0 :       where_clause (other.where_clause), locus (other.locus)
    2658                 :             :   {
    2659                 :           0 :     generic_params.reserve (other.generic_params.size ());
    2660                 :           0 :     for (const auto &e : other.generic_params)
    2661                 :           0 :       generic_params.push_back (e->clone_generic_param ());
    2662                 :             : 
    2663                 :           0 :     type_param_bounds.reserve (other.type_param_bounds.size ());
    2664                 :           0 :     for (const auto &e : other.type_param_bounds)
    2665                 :           0 :       type_param_bounds.push_back (e->clone_type_param_bound ());
    2666                 :             : 
    2667                 :           0 :     trait_items.reserve (other.trait_items.size ());
    2668                 :           0 :     for (const auto &e : other.trait_items)
    2669                 :           0 :       trait_items.push_back (e->clone_trait_item ());
    2670                 :           0 :   }
    2671                 :             : 
    2672                 :             :   // Overloaded assignment operator with vector clone
    2673                 :             :   Trait &operator= (Trait const &other)
    2674                 :             :   {
    2675                 :             :     VisItem::operator= (other);
    2676                 :             :     name = other.name;
    2677                 :             :     unsafety = other.unsafety;
    2678                 :             :     where_clause = other.where_clause;
    2679                 :             :     locus = other.locus;
    2680                 :             : 
    2681                 :             :     generic_params.reserve (other.generic_params.size ());
    2682                 :             :     for (const auto &e : other.generic_params)
    2683                 :             :       generic_params.push_back (e->clone_generic_param ());
    2684                 :             : 
    2685                 :             :     type_param_bounds.reserve (other.type_param_bounds.size ());
    2686                 :             :     for (const auto &e : other.type_param_bounds)
    2687                 :             :       type_param_bounds.push_back (e->clone_type_param_bound ());
    2688                 :             : 
    2689                 :             :     trait_items.reserve (other.trait_items.size ());
    2690                 :             :     for (const auto &e : other.trait_items)
    2691                 :             :       trait_items.push_back (e->clone_trait_item ());
    2692                 :             : 
    2693                 :             :     return *this;
    2694                 :             :   }
    2695                 :             : 
    2696                 :             :   // default move constructors
    2697                 :             :   Trait (Trait &&other) = default;
    2698                 :             :   Trait &operator= (Trait &&other) = default;
    2699                 :             : 
    2700                 :       12677 :   location_t get_locus () const override final { return locus; }
    2701                 :             : 
    2702                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    2703                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    2704                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
    2705                 :             : 
    2706                 :        4003 :   std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
    2707                 :             :   {
    2708                 :        6084 :     return generic_params;
    2709                 :             :   }
    2710                 :             : 
    2711                 :             :   const std::vector<std::unique_ptr<GenericParam>> &get_generic_params () const
    2712                 :             :   {
    2713                 :             :     return generic_params;
    2714                 :             :   }
    2715                 :             : 
    2716                 :           0 :   std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ()
    2717                 :             :   {
    2718                 :           0 :     return type_param_bounds;
    2719                 :             :   }
    2720                 :             : 
    2721                 :             :   const std::vector<std::unique_ptr<TypeParamBound>> &
    2722                 :             :   get_type_param_bounds () const
    2723                 :             :   {
    2724                 :             :     return type_param_bounds;
    2725                 :             :   }
    2726                 :             : 
    2727                 :       81942 :   ItemKind get_item_kind () const override { return ItemKind::Trait; }
    2728                 :             : 
    2729                 :             : protected:
    2730                 :             :   /* Use covariance to implement clone function as returning this object
    2731                 :             :    * rather than base */
    2732                 :           0 :   Trait *clone_item_impl () const override { return new Trait (*this); }
    2733                 :             : };
    2734                 :             : 
    2735                 :             : class ImplBlock : public VisItem, public WithInnerAttrs
    2736                 :             : {
    2737                 :             :   std::vector<std::unique_ptr<GenericParam>> generic_params;
    2738                 :             :   std::unique_ptr<Type> impl_type;
    2739                 :             :   std::unique_ptr<TypePath> trait_ref;
    2740                 :             :   WhereClause where_clause;
    2741                 :             :   BoundPolarity polarity;
    2742                 :             :   location_t locus;
    2743                 :             :   std::vector<std::unique_ptr<ImplItem>> impl_items;
    2744                 :             : 
    2745                 :             : public:
    2746                 :        6700 :   ImplBlock (Analysis::NodeMapping mappings,
    2747                 :             :              std::vector<std::unique_ptr<ImplItem>> impl_items,
    2748                 :             :              std::vector<std::unique_ptr<GenericParam>> generic_params,
    2749                 :             :              std::unique_ptr<Type> impl_type,
    2750                 :             :              std::unique_ptr<TypePath> trait_ref, WhereClause where_clause,
    2751                 :             :              BoundPolarity polarity, Visibility vis, AST::AttrVec inner_attrs,
    2752                 :             :              AST::AttrVec outer_attrs, location_t locus)
    2753                 :        6700 :     : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
    2754                 :             :       WithInnerAttrs (std::move (inner_attrs)),
    2755                 :        6700 :       generic_params (std::move (generic_params)),
    2756                 :        6700 :       impl_type (std::move (impl_type)), trait_ref (std::move (trait_ref)),
    2757                 :        6700 :       where_clause (std::move (where_clause)), polarity (polarity),
    2758                 :        6700 :       locus (locus), impl_items (std::move (impl_items))
    2759                 :        6700 :   {}
    2760                 :             : 
    2761                 :           0 :   ImplBlock (ImplBlock const &other)
    2762                 :           0 :     : VisItem (other), WithInnerAttrs (other.inner_attrs),
    2763                 :           0 :       impl_type (other.impl_type->clone_type ()),
    2764                 :           0 :       where_clause (other.where_clause), polarity (other.polarity),
    2765                 :           0 :       locus (other.locus)
    2766                 :             :   {
    2767                 :           0 :     generic_params.reserve (other.generic_params.size ());
    2768                 :           0 :     for (const auto &e : other.generic_params)
    2769                 :           0 :       generic_params.push_back (e->clone_generic_param ());
    2770                 :             : 
    2771                 :           0 :     impl_items.reserve (other.impl_items.size ());
    2772                 :           0 :     for (const auto &e : other.impl_items)
    2773                 :           0 :       impl_items.push_back (e->clone_inherent_impl_item ());
    2774                 :           0 :   }
    2775                 :             : 
    2776                 :             :   ImplBlock &operator= (ImplBlock const &other)
    2777                 :             :   {
    2778                 :             :     VisItem::operator= (other);
    2779                 :             :     impl_type = other.impl_type->clone_type ();
    2780                 :             :     where_clause = other.where_clause;
    2781                 :             :     polarity = other.polarity;
    2782                 :             :     inner_attrs = other.inner_attrs;
    2783                 :             :     locus = other.locus;
    2784                 :             : 
    2785                 :             :     generic_params.reserve (other.generic_params.size ());
    2786                 :             :     for (const auto &e : other.generic_params)
    2787                 :             :       generic_params.push_back (e->clone_generic_param ());
    2788                 :             : 
    2789                 :             :     impl_items.reserve (other.impl_items.size ());
    2790                 :             :     for (const auto &e : other.impl_items)
    2791                 :             :       impl_items.push_back (e->clone_inherent_impl_item ());
    2792                 :             : 
    2793                 :             :     return *this;
    2794                 :             :   }
    2795                 :             : 
    2796                 :             :   ImplBlock (ImplBlock &&other) = default;
    2797                 :             :   ImplBlock &operator= (ImplBlock &&other) = default;
    2798                 :             : 
    2799                 :             :   std::string as_string () const override;
    2800                 :             : 
    2801                 :             :   // Returns whether inherent impl block has inherent impl items.
    2802                 :        2745 :   bool has_impl_items () const { return !impl_items.empty (); }
    2803                 :             : 
    2804                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    2805                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    2806                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
    2807                 :             : 
    2808                 :           0 :   std::vector<std::unique_ptr<ImplItem>> &get_impl_items ()
    2809                 :             :   {
    2810                 :       44050 :     return impl_items;
    2811                 :             :   };
    2812                 :             : 
    2813                 :             :   const std::vector<std::unique_ptr<ImplItem>> &get_impl_items () const
    2814                 :             :   {
    2815                 :        7068 :     return impl_items;
    2816                 :             :   };
    2817                 :             : 
    2818                 :             :   // Returns whether impl has generic parameters.
    2819                 :       11974 :   bool has_generics () const { return !generic_params.empty (); }
    2820                 :             : 
    2821                 :             :   // Returns whether impl has where clause.
    2822                 :           0 :   bool has_where_clause () const { return !where_clause.is_empty (); }
    2823                 :             : 
    2824                 :             :   // Returns the polarity of the impl.
    2825                 :             :   BoundPolarity get_polarity () const { return polarity; }
    2826                 :             : 
    2827                 :        8986 :   location_t get_locus () const override final { return locus; }
    2828                 :             : 
    2829                 :      221909 :   std::unique_ptr<Type> &get_type () { return impl_type; };
    2830                 :             : 
    2831                 :       10399 :   std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
    2832                 :             :   {
    2833                 :       11425 :     return generic_params;
    2834                 :             :   }
    2835                 :             : 
    2836                 :      288942 :   bool has_trait_ref () const { return trait_ref != nullptr; }
    2837                 :             : 
    2838                 :       59798 :   std::unique_ptr<TypePath> &get_trait_ref () { return trait_ref; }
    2839                 :             : 
    2840                 :       11974 :   WhereClause &get_where_clause () { return where_clause; }
    2841                 :             : 
    2842                 :           0 :   ItemKind get_item_kind () const override { return ItemKind::Impl; }
    2843                 :             : 
    2844                 :             : protected:
    2845                 :           0 :   ImplBlock *clone_item_impl () const override { return new ImplBlock (*this); }
    2846                 :             : };
    2847                 :             : 
    2848                 :             : // Abstract base class for an item used inside an extern block
    2849                 :             : class ExternalItem : public Node
    2850                 :             : {
    2851                 :             :   Analysis::NodeMapping mappings;
    2852                 :             :   AST::AttrVec outer_attrs;
    2853                 :             :   Visibility visibility;
    2854                 :             :   Identifier item_name;
    2855                 :             :   location_t locus;
    2856                 :             : 
    2857                 :             : public:
    2858                 :             :   enum class ExternKind
    2859                 :             :   {
    2860                 :             :     Static,
    2861                 :             :     Function,
    2862                 :             :   };
    2863                 :             : 
    2864                 :           1 :   virtual ~ExternalItem () {}
    2865                 :             : 
    2866                 :           0 :   BaseKind get_hir_kind () override final { return EXTERNAL; }
    2867                 :             : 
    2868                 :             :   virtual ExternKind get_extern_kind () = 0;
    2869                 :             : 
    2870                 :             :   // Returns whether item has outer attributes.
    2871                 :             :   bool has_outer_attrs () const { return !outer_attrs.empty (); }
    2872                 :             : 
    2873                 :             :   // Returns whether item has non-default visibility.
    2874                 :           0 :   bool has_visibility () const { return !visibility.is_error (); }
    2875                 :             : 
    2876                 :             :   // Unique pointer custom clone function
    2877                 :           0 :   std::unique_ptr<ExternalItem> clone_external_item () const
    2878                 :             :   {
    2879                 :           0 :     return std::unique_ptr<ExternalItem> (clone_external_item_impl ());
    2880                 :             :   }
    2881                 :             : 
    2882                 :             :   virtual std::string as_string () const;
    2883                 :             : 
    2884                 :        3937 :   location_t get_locus () const { return locus; }
    2885                 :             : 
    2886                 :             :   virtual void accept_vis (HIRFullVisitor &vis) = 0;
    2887                 :             :   virtual void accept_vis (HIRExternalItemVisitor &vis) = 0;
    2888                 :             : 
    2889                 :           0 :   Visibility &get_visibility () { return visibility; }
    2890                 :       13562 :   Analysis::NodeMapping get_mappings () const { return mappings; }
    2891                 :             : 
    2892                 :        4703 :   Identifier get_item_name () const { return item_name; }
    2893                 :             : 
    2894                 :         302 :   AST::AttrVec &get_outer_attrs () { return outer_attrs; }
    2895                 :             : 
    2896                 :             : protected:
    2897                 :        1592 :   ExternalItem (Analysis::NodeMapping mappings, Identifier item_name,
    2898                 :             :                 Visibility vis, AST::AttrVec outer_attrs, location_t locus)
    2899                 :        1592 :     : mappings (mappings), outer_attrs (std::move (outer_attrs)),
    2900                 :        1592 :       visibility (std::move (vis)), item_name (std::move (item_name)),
    2901                 :        1592 :       locus (locus)
    2902                 :        1592 :   {}
    2903                 :             : 
    2904                 :             :   // Copy constructor
    2905                 :           0 :   ExternalItem (ExternalItem const &other)
    2906                 :           0 :     : mappings (other.mappings), outer_attrs (other.outer_attrs),
    2907                 :           0 :       visibility (other.visibility), item_name (other.item_name),
    2908                 :           0 :       locus (other.locus)
    2909                 :           0 :   {}
    2910                 :             : 
    2911                 :             :   // Overloaded assignment operator to clone
    2912                 :             :   ExternalItem &operator= (ExternalItem const &other)
    2913                 :             :   {
    2914                 :             :     mappings = other.mappings;
    2915                 :             :     item_name = other.item_name;
    2916                 :             :     visibility = other.visibility;
    2917                 :             :     outer_attrs = other.outer_attrs;
    2918                 :             :     locus = other.locus;
    2919                 :             : 
    2920                 :             :     return *this;
    2921                 :             :   }
    2922                 :             : 
    2923                 :             :   // move constructors
    2924                 :             :   ExternalItem (ExternalItem &&other) = default;
    2925                 :             :   ExternalItem &operator= (ExternalItem &&other) = default;
    2926                 :             : 
    2927                 :             :   // Clone function implementation as pure virtual method
    2928                 :             :   virtual ExternalItem *clone_external_item_impl () const = 0;
    2929                 :             : };
    2930                 :             : 
    2931                 :             : // A static item used in an extern block
    2932                 :             : class ExternalStaticItem : public ExternalItem
    2933                 :             : {
    2934                 :             :   Mutability mut;
    2935                 :             :   std::unique_ptr<Type> item_type;
    2936                 :             : 
    2937                 :             : public:
    2938                 :           1 :   ExternalStaticItem (Analysis::NodeMapping mappings, Identifier item_name,
    2939                 :             :                       std::unique_ptr<Type> item_type, Mutability mut,
    2940                 :             :                       Visibility vis, AST::AttrVec outer_attrs,
    2941                 :             :                       location_t locus)
    2942                 :           1 :     : ExternalItem (std::move (mappings), std::move (item_name),
    2943                 :             :                     std::move (vis), std::move (outer_attrs), locus),
    2944                 :           1 :       mut (mut), item_type (std::move (item_type))
    2945                 :           1 :   {}
    2946                 :             : 
    2947                 :             :   // Copy constructor
    2948                 :           0 :   ExternalStaticItem (ExternalStaticItem const &other)
    2949                 :           0 :     : ExternalItem (other), mut (other.mut),
    2950                 :           0 :       item_type (other.item_type->clone_type ())
    2951                 :           0 :   {}
    2952                 :             : 
    2953                 :             :   // Overloaded assignment operator to clone
    2954                 :             :   ExternalStaticItem &operator= (ExternalStaticItem const &other)
    2955                 :             :   {
    2956                 :             :     ExternalItem::operator= (other);
    2957                 :             :     item_type = other.item_type->clone_type ();
    2958                 :             :     mut = other.mut;
    2959                 :             : 
    2960                 :             :     return *this;
    2961                 :             :   }
    2962                 :             : 
    2963                 :             :   // move constructors
    2964                 :             :   ExternalStaticItem (ExternalStaticItem &&other) = default;
    2965                 :             :   ExternalStaticItem &operator= (ExternalStaticItem &&other) = default;
    2966                 :             : 
    2967                 :             :   std::string as_string () const override;
    2968                 :             : 
    2969                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    2970                 :             :   void accept_vis (HIRExternalItemVisitor &vis) override;
    2971                 :             : 
    2972                 :           0 :   bool is_mut () const { return mut == Mutability::Mut; }
    2973                 :             : 
    2974                 :             :   Mutability get_mut () { return mut; }
    2975                 :             : 
    2976                 :           1 :   std::unique_ptr<Type> &get_item_type () { return item_type; }
    2977                 :             : 
    2978                 :           1 :   ExternKind get_extern_kind () override { return ExternKind::Static; }
    2979                 :             : 
    2980                 :             : protected:
    2981                 :             :   /* Use covariance to implement clone function as returning this object
    2982                 :             :    * rather than base */
    2983                 :           0 :   ExternalStaticItem *clone_external_item_impl () const override
    2984                 :             :   {
    2985                 :           0 :     return new ExternalStaticItem (*this);
    2986                 :             :   }
    2987                 :             : };
    2988                 :             : 
    2989                 :             : // A named function parameter used in external functions
    2990                 :             : struct NamedFunctionParam
    2991                 :             : {
    2992                 :             : private:
    2993                 :             :   Identifier name;
    2994                 :             :   std::unique_ptr<Type> param_type;
    2995                 :             :   Analysis::NodeMapping mappings;
    2996                 :             : 
    2997                 :             : public:
    2998                 :             :   bool has_name () const { return name.as_string () != "_"; }
    2999                 :             : 
    3000                 :        1935 :   NamedFunctionParam (Analysis::NodeMapping mappings, Identifier name,
    3001                 :             :                       std::unique_ptr<Type> param_type)
    3002                 :        1935 :     : name (std::move (name)), param_type (std::move (param_type)),
    3003                 :        1935 :       mappings (std::move (mappings))
    3004                 :             :   {}
    3005                 :             : 
    3006                 :             :   // Copy constructor
    3007                 :           0 :   NamedFunctionParam (NamedFunctionParam const &other)
    3008                 :           0 :     : name (other.name), param_type (other.param_type->clone_type ()),
    3009                 :           0 :       mappings (other.mappings)
    3010                 :           0 :   {}
    3011                 :             : 
    3012                 :        2454 :   ~NamedFunctionParam () = default;
    3013                 :             : 
    3014                 :             :   // Overloaded assignment operator to clone
    3015                 :             :   NamedFunctionParam &operator= (NamedFunctionParam const &other)
    3016                 :             :   {
    3017                 :             :     mappings = other.mappings;
    3018                 :             :     name = other.name;
    3019                 :             :     param_type = other.param_type->clone_type ();
    3020                 :             :     // has_name = other.has_name;
    3021                 :             : 
    3022                 :             :     return *this;
    3023                 :             :   }
    3024                 :             : 
    3025                 :             :   // move constructors
    3026                 :        2453 :   NamedFunctionParam (NamedFunctionParam &&other) = default;
    3027                 :             :   NamedFunctionParam &operator= (NamedFunctionParam &&other) = default;
    3028                 :             : 
    3029                 :             :   std::string as_string () const;
    3030                 :             : 
    3031                 :        1933 :   Identifier get_param_name () const { return name; }
    3032                 :             : 
    3033                 :        1933 :   std::unique_ptr<Type> &get_type () { return param_type; }
    3034                 :             : 
    3035                 :        1933 :   Analysis::NodeMapping get_mappings () const { return mappings; }
    3036                 :             : };
    3037                 :             : 
    3038                 :             : // A function item used in an extern block
    3039                 :             : class ExternalFunctionItem : public ExternalItem
    3040                 :             : {
    3041                 :             :   // bool has_generics;
    3042                 :             :   // Generics generic_params;
    3043                 :             :   std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined
    3044                 :             : 
    3045                 :             :   // bool has_return_type;
    3046                 :             :   // FunctionReturnType return_type;
    3047                 :             :   std::unique_ptr<Type> return_type; // inlined
    3048                 :             : 
    3049                 :             :   // bool has_where_clause;
    3050                 :             :   WhereClause where_clause;
    3051                 :             : 
    3052                 :             :   std::vector<NamedFunctionParam> function_params;
    3053                 :             :   bool has_variadics;
    3054                 :             : 
    3055                 :             : public:
    3056                 :             :   // Returns whether item has generic parameters.
    3057                 :        1590 :   bool has_generics () const { return !generic_params.empty (); }
    3058                 :             : 
    3059                 :             :   // Returns whether item has a return type (otherwise void).
    3060                 :        1589 :   bool has_return_type () const { return return_type != nullptr; }
    3061                 :             : 
    3062                 :             :   // Returns whether item has a where clause.
    3063                 :        1589 :   bool has_where_clause () const { return !where_clause.is_empty (); }
    3064                 :             : 
    3065                 :             :   WARN_UNUSED_RESULT const WhereClause &get_where_clause () const
    3066                 :             :   {
    3067                 :             :     return where_clause;
    3068                 :             :   }
    3069                 :             : 
    3070                 :        1591 :   ExternalFunctionItem (
    3071                 :             :     Analysis::NodeMapping mappings, Identifier item_name,
    3072                 :             :     std::vector<std::unique_ptr<GenericParam>> generic_params,
    3073                 :             :     std::unique_ptr<Type> return_type, WhereClause where_clause,
    3074                 :             :     std::vector<NamedFunctionParam> function_params, bool has_variadics,
    3075                 :             :     Visibility vis, AST::AttrVec outer_attrs, location_t locus)
    3076                 :        1591 :     : ExternalItem (std::move (mappings), std::move (item_name),
    3077                 :             :                     std::move (vis), std::move (outer_attrs), locus),
    3078                 :        1591 :       generic_params (std::move (generic_params)),
    3079                 :        1591 :       return_type (std::move (return_type)),
    3080                 :        1591 :       where_clause (std::move (where_clause)),
    3081                 :        1591 :       function_params (std::move (function_params)),
    3082                 :        1591 :       has_variadics (has_variadics)
    3083                 :        1591 :   {}
    3084                 :             : 
    3085                 :             :   // Copy constructor with clone
    3086                 :           0 :   ExternalFunctionItem (ExternalFunctionItem const &other)
    3087                 :           0 :     : ExternalItem (other), return_type (other.return_type->clone_type ()),
    3088                 :           0 :       where_clause (other.where_clause),
    3089                 :           0 :       function_params (other.function_params),
    3090                 :           0 :       has_variadics (other.has_variadics)
    3091                 :             :   {
    3092                 :           0 :     generic_params.reserve (other.generic_params.size ());
    3093                 :           0 :     for (const auto &e : other.generic_params)
    3094                 :           0 :       generic_params.push_back (e->clone_generic_param ());
    3095                 :           0 :   }
    3096                 :             : 
    3097                 :             :   // Overloaded assignment operator with clone
    3098                 :             :   ExternalFunctionItem &operator= (ExternalFunctionItem const &other)
    3099                 :             :   {
    3100                 :             :     ExternalItem::operator= (other);
    3101                 :             :     return_type = other.return_type->clone_type ();
    3102                 :             :     where_clause = other.where_clause;
    3103                 :             :     function_params = other.function_params;
    3104                 :             :     has_variadics = other.has_variadics;
    3105                 :             : 
    3106                 :             :     generic_params.reserve (other.generic_params.size ());
    3107                 :             :     for (const auto &e : other.generic_params)
    3108                 :             :       generic_params.push_back (e->clone_generic_param ());
    3109                 :             : 
    3110                 :             :     return *this;
    3111                 :             :   }
    3112                 :             : 
    3113                 :             :   // move constructors
    3114                 :             :   ExternalFunctionItem (ExternalFunctionItem &&other) = default;
    3115                 :             :   ExternalFunctionItem &operator= (ExternalFunctionItem &&other) = default;
    3116                 :             : 
    3117                 :             :   std::string as_string () const override;
    3118                 :             : 
    3119                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    3120                 :             :   void accept_vis (HIRExternalItemVisitor &vis) override;
    3121                 :             : 
    3122                 :           0 :   std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
    3123                 :             :   {
    3124                 :           0 :     return generic_params;
    3125                 :             :   }
    3126                 :             : 
    3127                 :        1496 :   std::unique_ptr<Type> &get_return_type () { return return_type; }
    3128                 :             : 
    3129                 :             :   std::vector<NamedFunctionParam> &get_function_params ()
    3130                 :             :   {
    3131                 :        1589 :     return function_params;
    3132                 :             :   }
    3133                 :             : 
    3134                 :        1589 :   bool is_variadic () const { return has_variadics; }
    3135                 :             : 
    3136                 :         326 :   ExternKind get_extern_kind () override { return ExternKind::Function; }
    3137                 :             : 
    3138                 :             : protected:
    3139                 :             :   /* Use covariance to implement clone function as returning this object
    3140                 :             :    * rather than base */
    3141                 :           0 :   ExternalFunctionItem *clone_external_item_impl () const override
    3142                 :             :   {
    3143                 :           0 :     return new ExternalFunctionItem (*this);
    3144                 :             :   }
    3145                 :             : };
    3146                 :             : 
    3147                 :             : // An extern block HIR node
    3148                 :             : class ExternBlock : public VisItem, public WithInnerAttrs
    3149                 :             : {
    3150                 :             :   ABI abi;
    3151                 :             :   std::vector<std::unique_ptr<ExternalItem>> extern_items;
    3152                 :             :   location_t locus;
    3153                 :             : 
    3154                 :             : public:
    3155                 :             :   std::string as_string () const override;
    3156                 :             : 
    3157                 :             :   // Returns whether extern block has extern items.
    3158                 :           0 :   bool has_extern_items () const { return !extern_items.empty (); }
    3159                 :             : 
    3160                 :        2313 :   ABI get_abi () const { return abi; }
    3161                 :             : 
    3162                 :        1024 :   ExternBlock (Analysis::NodeMapping mappings, ABI abi,
    3163                 :             :                std::vector<std::unique_ptr<ExternalItem>> extern_items,
    3164                 :             :                Visibility vis, AST::AttrVec inner_attrs,
    3165                 :             :                AST::AttrVec outer_attrs, location_t locus)
    3166                 :        1024 :     : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
    3167                 :        1024 :       WithInnerAttrs (std::move (inner_attrs)), abi (abi),
    3168                 :        1024 :       extern_items (std::move (extern_items)), locus (locus)
    3169                 :        1024 :   {}
    3170                 :             : 
    3171                 :             :   // Copy constructor with vector clone
    3172                 :           0 :   ExternBlock (ExternBlock const &other)
    3173                 :           0 :     : VisItem (other), WithInnerAttrs (other.inner_attrs), abi (other.abi),
    3174                 :           0 :       locus (other.locus)
    3175                 :             :   {
    3176                 :           0 :     extern_items.reserve (other.extern_items.size ());
    3177                 :           0 :     for (const auto &e : other.extern_items)
    3178                 :           0 :       extern_items.push_back (e->clone_external_item ());
    3179                 :           0 :   }
    3180                 :             : 
    3181                 :             :   // Overloaded assignment operator with vector clone
    3182                 :             :   ExternBlock &operator= (ExternBlock const &other)
    3183                 :             :   {
    3184                 :             :     VisItem::operator= (other);
    3185                 :             :     abi = other.abi;
    3186                 :             :     inner_attrs = other.inner_attrs;
    3187                 :             :     locus = other.locus;
    3188                 :             : 
    3189                 :             :     extern_items.reserve (other.extern_items.size ());
    3190                 :             :     for (const auto &e : other.extern_items)
    3191                 :             :       extern_items.push_back (e->clone_external_item ());
    3192                 :             : 
    3193                 :             :     return *this;
    3194                 :             :   }
    3195                 :             : 
    3196                 :             :   // move constructors
    3197                 :             :   ExternBlock (ExternBlock &&other) = default;
    3198                 :             :   ExternBlock &operator= (ExternBlock &&other) = default;
    3199                 :             : 
    3200                 :        3045 :   location_t get_locus () const override final { return locus; }
    3201                 :             : 
    3202                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    3203                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
    3204                 :             :   void accept_vis (HIRVisItemVisitor &vis) override;
    3205                 :             : 
    3206                 :           0 :   std::vector<std::unique_ptr<ExternalItem>> &get_extern_items ()
    3207                 :             :   {
    3208                 :        4048 :     return extern_items;
    3209                 :             :   }
    3210                 :             : 
    3211                 :           0 :   ItemKind get_item_kind () const override { return ItemKind::ExternBlock; }
    3212                 :             : 
    3213                 :             : protected:
    3214                 :             :   /* Use covariance to implement clone function as returning this object
    3215                 :             :    * rather than base */
    3216                 :           0 :   ExternBlock *clone_item_impl () const override
    3217                 :             :   {
    3218                 :           0 :     return new ExternBlock (*this);
    3219                 :             :   }
    3220                 :             : 
    3221                 :             :   /* Use covariance to implement clone function as returning this object
    3222                 :             :    * rather than base */
    3223                 :             :   /*virtual ExternBlock* clone_statement_impl() const override {
    3224                 :             :       return new ExternBlock(*this);
    3225                 :             :   }*/
    3226                 :             : };
    3227                 :             : 
    3228                 :             : } // namespace HIR
    3229                 :             : } // namespace Rust
    3230                 :             : 
    3231                 :             : #endif
        

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.