LCOV - code coverage report
Current view: top level - gcc/rust/hir/tree - rust-hir-pattern.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 66.0 % 315 208
Test Date: 2024-04-13 14:00:49 Functions: 65.1 % 86 56
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_PATTERN_H
      20                 :             : #define RUST_HIR_PATTERN_H
      21                 :             : 
      22                 :             : #include "rust-common.h"
      23                 :             : #include "rust-hir.h"
      24                 :             : 
      25                 :             : namespace Rust {
      26                 :             : namespace HIR {
      27                 :             : 
      28                 :             : // Literal pattern HIR node (comparing to a literal)
      29                 :             : class LiteralPattern : public Pattern
      30                 :             : {
      31                 :             :   Literal lit;
      32                 :             :   location_t locus;
      33                 :             :   Analysis::NodeMapping mappings;
      34                 :             : 
      35                 :             : public:
      36                 :             :   std::string as_string () const override;
      37                 :             : 
      38                 :             :   // Constructor for a literal pattern
      39                 :         141 :   LiteralPattern (Analysis::NodeMapping mappings, Literal lit, location_t locus)
      40                 :         141 :     : lit (std::move (lit)), locus (locus), mappings (mappings)
      41                 :         141 :   {}
      42                 :             : 
      43                 :             :   LiteralPattern (Analysis::NodeMapping mappings, std::string val,
      44                 :             :                   Literal::LitType type, location_t locus)
      45                 :             :     : lit (Literal (std::move (val), type, PrimitiveCoreType::CORETYPE_STR)),
      46                 :             :       locus (locus), mappings (mappings)
      47                 :             :   {}
      48                 :             : 
      49                 :         692 :   location_t get_locus () const override { return locus; }
      50                 :             : 
      51                 :             :   void accept_vis (HIRFullVisitor &vis) override;
      52                 :             :   void accept_vis (HIRPatternVisitor &vis) override;
      53                 :             : 
      54                 :         844 :   const Analysis::NodeMapping &get_mappings () const override final
      55                 :             :   {
      56                 :         844 :     return mappings;
      57                 :             :   }
      58                 :             : 
      59                 :           0 :   PatternType get_pattern_type () const override final
      60                 :             :   {
      61                 :           0 :     return PatternType::LITERAL;
      62                 :             :   }
      63                 :             : 
      64                 :         420 :   Literal &get_literal () { return lit; }
      65                 :             :   const Literal &get_literal () const { return lit; }
      66                 :             : 
      67                 :             : protected:
      68                 :             :   /* Use covariance to implement clone function as returning this object rather
      69                 :             :    * than base */
      70                 :         659 :   virtual LiteralPattern *clone_pattern_impl () const override
      71                 :             :   {
      72                 :         659 :     return new LiteralPattern (*this);
      73                 :             :   }
      74                 :             : };
      75                 :             : 
      76                 :             : // Identifier pattern HIR node (bind value matched to a variable)
      77                 :             : class IdentifierPattern : public Pattern
      78                 :             : {
      79                 :             :   Identifier variable_ident;
      80                 :             :   bool is_ref;
      81                 :             :   Mutability mut;
      82                 :             :   std::unique_ptr<Pattern> to_bind;
      83                 :             :   location_t locus;
      84                 :             :   Analysis::NodeMapping mappings;
      85                 :             : 
      86                 :             : public:
      87                 :             :   std::string as_string () const override;
      88                 :             : 
      89                 :             :   // Returns whether the IdentifierPattern has a pattern to bind.
      90                 :       45258 :   bool has_pattern_to_bind () const { return to_bind != nullptr; }
      91                 :             : 
      92                 :             :   // Constructor
      93                 :       22908 :   IdentifierPattern (Analysis::NodeMapping mappings, Identifier ident,
      94                 :             :                      location_t locus, bool is_ref = false,
      95                 :             :                      Mutability mut = Mutability::Imm,
      96                 :             :                      std::unique_ptr<Pattern> to_bind = nullptr)
      97                 :       45816 :     : variable_ident (std::move (ident)), is_ref (is_ref), mut (mut),
      98                 :       22908 :       to_bind (std::move (to_bind)), locus (locus), mappings (mappings)
      99                 :       22908 :   {}
     100                 :             : 
     101                 :             :   // Copy constructor with clone
     102                 :         625 :   IdentifierPattern (IdentifierPattern const &other)
     103                 :        1250 :     : variable_ident (other.variable_ident), is_ref (other.is_ref),
     104                 :         625 :       mut (other.mut), locus (other.locus), mappings (other.mappings)
     105                 :             :   {
     106                 :             :     // fix to get prevent null pointer dereference
     107                 :         625 :     if (other.to_bind != nullptr)
     108                 :           0 :       to_bind = other.to_bind->clone_pattern ();
     109                 :         625 :   }
     110                 :             : 
     111                 :             :   // Overload assignment operator to use clone
     112                 :             :   IdentifierPattern &operator= (IdentifierPattern const &other)
     113                 :             :   {
     114                 :             :     variable_ident = other.variable_ident;
     115                 :             :     is_ref = other.is_ref;
     116                 :             :     mut = other.mut;
     117                 :             :     locus = other.locus;
     118                 :             :     mappings = other.mappings;
     119                 :             : 
     120                 :             :     // fix to get prevent null pointer dereference
     121                 :             :     if (other.to_bind != nullptr)
     122                 :             :       to_bind = other.to_bind->clone_pattern ();
     123                 :             : 
     124                 :             :     return *this;
     125                 :             :   }
     126                 :             : 
     127                 :             :   // default move semantics
     128                 :             :   IdentifierPattern (IdentifierPattern &&other) = default;
     129                 :             :   IdentifierPattern &operator= (IdentifierPattern &&other) = default;
     130                 :             : 
     131                 :       25933 :   location_t get_locus () const override { return locus; }
     132                 :             : 
     133                 :       59182 :   bool is_mut () const { return mut == Mutability::Mut; }
     134                 :           0 :   bool get_is_ref () const { return is_ref; }
     135                 :           0 :   std::unique_ptr<Pattern> &get_to_bind () { return to_bind; }
     136                 :             : 
     137                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     138                 :             :   void accept_vis (HIRPatternVisitor &vis) override;
     139                 :             : 
     140                 :       96047 :   const Analysis::NodeMapping &get_mappings () const override final
     141                 :             :   {
     142                 :       96047 :     return mappings;
     143                 :             :   }
     144                 :             : 
     145                 :       13924 :   Identifier get_identifier () const { return variable_ident; }
     146                 :             : 
     147                 :           0 :   PatternType get_pattern_type () const override final
     148                 :             :   {
     149                 :           0 :     return PatternType::IDENTIFIER;
     150                 :             :   }
     151                 :             : 
     152                 :             : protected:
     153                 :             :   /* Use covariance to implement clone function as returning this object rather
     154                 :             :    * than base */
     155                 :         625 :   IdentifierPattern *clone_pattern_impl () const override
     156                 :             :   {
     157                 :         625 :     return new IdentifierPattern (*this);
     158                 :             :   }
     159                 :             : };
     160                 :             : 
     161                 :             : // HIR node for using the '_' wildcard "match any value" pattern
     162                 :         477 : class WildcardPattern : public Pattern
     163                 :             : {
     164                 :             :   location_t locus;
     165                 :             :   Analysis::NodeMapping mappings;
     166                 :             : 
     167                 :             : public:
     168                 :          79 :   std::string as_string () const override { return std::string (1, '_'); }
     169                 :             : 
     170                 :         212 :   WildcardPattern (Analysis::NodeMapping mappings, location_t locus)
     171                 :         212 :     : locus (locus), mappings (mappings)
     172                 :             :   {}
     173                 :             : 
     174                 :         374 :   location_t get_locus () const override { return locus; }
     175                 :             : 
     176                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     177                 :             :   void accept_vis (HIRPatternVisitor &vis) override;
     178                 :             : 
     179                 :        1250 :   const Analysis::NodeMapping &get_mappings () const override final
     180                 :             :   {
     181                 :        1250 :     return mappings;
     182                 :             :   }
     183                 :             : 
     184                 :           0 :   PatternType get_pattern_type () const override final
     185                 :             :   {
     186                 :           0 :     return PatternType::WILDCARD;
     187                 :             :   }
     188                 :             : 
     189                 :             : protected:
     190                 :             :   /* Use covariance to implement clone function as returning this object rather
     191                 :             :    * than base */
     192                 :         477 :   WildcardPattern *clone_pattern_impl () const override
     193                 :             :   {
     194                 :         477 :     return new WildcardPattern (*this);
     195                 :             :   }
     196                 :             : };
     197                 :             : 
     198                 :             : // Base range pattern bound (lower or upper limit) - abstract
     199                 :         168 : class RangePatternBound
     200                 :             : {
     201                 :             : public:
     202                 :             :   enum RangePatternBoundType
     203                 :             :   {
     204                 :             :     LITERAL,
     205                 :             :     PATH,
     206                 :             :     QUALPATH
     207                 :             :   };
     208                 :             : 
     209                 :             :   virtual ~RangePatternBound () {}
     210                 :             : 
     211                 :             :   // Unique pointer custom clone function
     212                 :         252 :   std::unique_ptr<RangePatternBound> clone_range_pattern_bound () const
     213                 :             :   {
     214                 :         126 :     return std::unique_ptr<RangePatternBound> (
     215                 :         126 :       clone_range_pattern_bound_impl ());
     216                 :             :   }
     217                 :             : 
     218                 :             :   virtual std::string as_string () const = 0;
     219                 :             : 
     220                 :             :   virtual void accept_vis (HIRFullVisitor &vis) = 0;
     221                 :             : 
     222                 :             :   virtual RangePatternBoundType get_bound_type () const = 0;
     223                 :             : 
     224                 :             : protected:
     225                 :             :   // pure virtual as RangePatternBound is abstract
     226                 :             :   virtual RangePatternBound *clone_range_pattern_bound_impl () const = 0;
     227                 :             : };
     228                 :             : 
     229                 :             : // Literal-based pattern bound
     230                 :             : class RangePatternBoundLiteral : public RangePatternBound
     231                 :             : {
     232                 :             :   Literal literal;
     233                 :             :   /* Can only be a char, byte, int, or float literal - same impl here as
     234                 :             :    * previously */
     235                 :             : 
     236                 :             :   // Minus prefixed to literal (if integer or floating-point)
     237                 :             :   bool has_minus;
     238                 :             : 
     239                 :             :   location_t locus;
     240                 :             : 
     241                 :             : public:
     242                 :             :   // Constructor
     243                 :          21 :   RangePatternBoundLiteral (Literal literal, location_t locus,
     244                 :             :                             bool has_minus = false)
     245                 :          21 :     : literal (literal), has_minus (has_minus), locus (locus)
     246                 :             :   {}
     247                 :             : 
     248                 :             :   std::string as_string () const override;
     249                 :             : 
     250                 :             :   location_t get_locus () const { return locus; }
     251                 :             : 
     252                 :          42 :   Literal get_literal () const { return literal; }
     253                 :           0 :   bool get_has_minus () const { return has_minus; }
     254                 :             : 
     255                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     256                 :             : 
     257                 :          42 :   RangePatternBoundType get_bound_type () const override
     258                 :             :   {
     259                 :          42 :     return RangePatternBoundType::LITERAL;
     260                 :             :   }
     261                 :             : 
     262                 :             : protected:
     263                 :             :   /* Use covariance to implement clone function as returning this object rather
     264                 :             :    * than base */
     265                 :         126 :   RangePatternBoundLiteral *clone_range_pattern_bound_impl () const override
     266                 :             :   {
     267                 :         126 :     return new RangePatternBoundLiteral (*this);
     268                 :             :   }
     269                 :             : };
     270                 :             : 
     271                 :             : // Path-based pattern bound
     272                 :         126 : class RangePatternBoundPath : public RangePatternBound
     273                 :             : {
     274                 :             :   PathInExpression path;
     275                 :             : 
     276                 :             :   /* TODO: should this be refactored so that PathInExpression is a subclass of
     277                 :             :    * RangePatternBound? */
     278                 :             : 
     279                 :             : public:
     280                 :          21 :   RangePatternBoundPath (PathInExpression path) : path (std::move (path)) {}
     281                 :             : 
     282                 :           0 :   std::string as_string () const override { return path.as_string (); }
     283                 :             : 
     284                 :             :   location_t get_locus () const { return path.get_locus (); }
     285                 :             : 
     286                 :          21 :   PathInExpression &get_path () { return path; }
     287                 :             :   const PathInExpression &get_path () const { return path; }
     288                 :             : 
     289                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     290                 :             : 
     291                 :          42 :   RangePatternBoundType get_bound_type () const override
     292                 :             :   {
     293                 :          42 :     return RangePatternBoundType::PATH;
     294                 :             :   }
     295                 :             : 
     296                 :             : protected:
     297                 :             :   /* Use covariance to implement clone function as returning this object rather
     298                 :             :    * than base */
     299                 :         126 :   RangePatternBoundPath *clone_range_pattern_bound_impl () const override
     300                 :             :   {
     301                 :         126 :     return new RangePatternBoundPath (*this);
     302                 :             :   }
     303                 :             : };
     304                 :             : 
     305                 :             : // Qualified path-based pattern bound
     306                 :           0 : class RangePatternBoundQualPath : public RangePatternBound
     307                 :             : {
     308                 :             :   QualifiedPathInExpression path;
     309                 :             : 
     310                 :             :   /* TODO: should this be refactored so that QualifiedPathInExpression is a
     311                 :             :    * subclass of RangePatternBound? */
     312                 :             : 
     313                 :             : public:
     314                 :           0 :   RangePatternBoundQualPath (QualifiedPathInExpression path)
     315                 :           0 :     : path (std::move (path))
     316                 :             :   {}
     317                 :             : 
     318                 :           0 :   std::string as_string () const override { return path.as_string (); }
     319                 :             : 
     320                 :             :   location_t get_locus () const { return path.get_locus (); }
     321                 :             : 
     322                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     323                 :             : 
     324                 :           0 :   QualifiedPathInExpression &get_qualified_path () { return path; }
     325                 :             :   const QualifiedPathInExpression &get_qualified_path () const { return path; }
     326                 :             : 
     327                 :           0 :   RangePatternBoundType get_bound_type () const override
     328                 :             :   {
     329                 :           0 :     return RangePatternBoundType::QUALPATH;
     330                 :             :   }
     331                 :             : 
     332                 :             : protected:
     333                 :             :   /* Use covariance to implement clone function as returning this object rather
     334                 :             :    * than base */
     335                 :           0 :   RangePatternBoundQualPath *clone_range_pattern_bound_impl () const override
     336                 :             :   {
     337                 :           0 :     return new RangePatternBoundQualPath (*this);
     338                 :             :   }
     339                 :             : };
     340                 :             : 
     341                 :             : // HIR node for matching within a certain range (range pattern)
     342                 :             : class RangePattern : public Pattern
     343                 :             : {
     344                 :             :   std::unique_ptr<RangePatternBound> lower;
     345                 :             :   std::unique_ptr<RangePatternBound> upper;
     346                 :             : 
     347                 :             :   bool has_ellipsis_syntax;
     348                 :             : 
     349                 :             :   /* location only stored to avoid a dereference - lower pattern should give
     350                 :             :    * correct location so maybe change in future */
     351                 :             :   location_t locus;
     352                 :             :   Analysis::NodeMapping mappings;
     353                 :             : 
     354                 :             : public:
     355                 :             :   std::string as_string () const override;
     356                 :             : 
     357                 :             :   // Constructor
     358                 :          21 :   RangePattern (Analysis::NodeMapping mappings,
     359                 :             :                 std::unique_ptr<RangePatternBound> lower,
     360                 :             :                 std::unique_ptr<RangePatternBound> upper, location_t locus,
     361                 :             :                 bool has_ellipsis_syntax = false)
     362                 :          21 :     : lower (std::move (lower)), upper (std::move (upper)),
     363                 :          21 :       has_ellipsis_syntax (has_ellipsis_syntax), locus (locus),
     364                 :          21 :       mappings (mappings)
     365                 :             :   {}
     366                 :             : 
     367                 :             :   // Copy constructor with clone
     368                 :         126 :   RangePattern (RangePattern const &other)
     369                 :         252 :     : lower (other.lower->clone_range_pattern_bound ()),
     370                 :         126 :       upper (other.upper->clone_range_pattern_bound ()),
     371                 :         126 :       has_ellipsis_syntax (other.has_ellipsis_syntax), locus (other.locus),
     372                 :         126 :       mappings (other.mappings)
     373                 :         126 :   {}
     374                 :             : 
     375                 :             :   // Overloaded assignment operator to clone
     376                 :             :   RangePattern &operator= (RangePattern const &other)
     377                 :             :   {
     378                 :             :     lower = other.lower->clone_range_pattern_bound ();
     379                 :             :     upper = other.upper->clone_range_pattern_bound ();
     380                 :             :     has_ellipsis_syntax = other.has_ellipsis_syntax;
     381                 :             :     locus = other.locus;
     382                 :             :     mappings = other.mappings;
     383                 :             : 
     384                 :             :     return *this;
     385                 :             :   }
     386                 :             : 
     387                 :             :   // default move semantics
     388                 :             :   RangePattern (RangePattern &&other) = default;
     389                 :             :   RangePattern &operator= (RangePattern &&other) = default;
     390                 :             : 
     391                 :         210 :   location_t get_locus () const override { return locus; }
     392                 :             : 
     393                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     394                 :             :   void accept_vis (HIRPatternVisitor &vis) override;
     395                 :             : 
     396                 :           0 :   bool get_has_ellipsis_syntax () { return has_ellipsis_syntax; };
     397                 :             : 
     398                 :         126 :   const Analysis::NodeMapping &get_mappings () const override final
     399                 :             :   {
     400                 :         126 :     return mappings;
     401                 :             :   }
     402                 :             : 
     403                 :           0 :   PatternType get_pattern_type () const override final
     404                 :             :   {
     405                 :           0 :     return PatternType::RANGE;
     406                 :             :   }
     407                 :             : 
     408                 :          42 :   std::unique_ptr<RangePatternBound> &get_lower_bound () { return lower; }
     409                 :             : 
     410                 :          42 :   std::unique_ptr<RangePatternBound> &get_upper_bound () { return upper; }
     411                 :             : 
     412                 :             : protected:
     413                 :             :   /* Use covariance to implement clone function as returning this object rather
     414                 :             :    * than base */
     415                 :         126 :   RangePattern *clone_pattern_impl () const override
     416                 :             :   {
     417                 :         126 :     return new RangePattern (*this);
     418                 :             :   }
     419                 :             : };
     420                 :             : 
     421                 :             : // HIR node for pattern based on dereferencing the pointers given
     422                 :             : class ReferencePattern : public Pattern
     423                 :             : {
     424                 :             :   Mutability mut;
     425                 :             :   std::unique_ptr<Pattern> pattern;
     426                 :             :   location_t locus;
     427                 :             :   Analysis::NodeMapping mappings;
     428                 :             : 
     429                 :             : public:
     430                 :             :   std::string as_string () const override;
     431                 :             : 
     432                 :          36 :   ReferencePattern (Analysis::NodeMapping mappings,
     433                 :             :                     std::unique_ptr<Pattern> pattern, Mutability reference_mut,
     434                 :             :                     location_t locus)
     435                 :          36 :     : mut (reference_mut), pattern (std::move (pattern)), locus (locus),
     436                 :          36 :       mappings (mappings)
     437                 :             :   {}
     438                 :             : 
     439                 :             :   // Copy constructor requires clone
     440                 :           2 :   ReferencePattern (ReferencePattern const &other)
     441                 :           4 :     : mut (other.mut), pattern (other.pattern->clone_pattern ()),
     442                 :           2 :       locus (other.locus), mappings (other.mappings)
     443                 :           2 :   {}
     444                 :             : 
     445                 :             :   // Overload assignment operator to clone
     446                 :             :   ReferencePattern &operator= (ReferencePattern const &other)
     447                 :             :   {
     448                 :             :     pattern = other.pattern->clone_pattern ();
     449                 :             :     mut = other.mut;
     450                 :             :     locus = other.locus;
     451                 :             :     mappings = other.mappings;
     452                 :             : 
     453                 :             :     return *this;
     454                 :             :   }
     455                 :             : 
     456                 :             :   // default move semantics
     457                 :             :   ReferencePattern (ReferencePattern &&other) = default;
     458                 :             :   ReferencePattern &operator= (ReferencePattern &&other) = default;
     459                 :             : 
     460                 :          67 :   bool is_mut () const { return mut == Mutability::Mut; }
     461                 :             : 
     462                 :           1 :   Mutability get_mutability () const { return mut; }
     463                 :             : 
     464                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     465                 :             :   void accept_vis (HIRPatternVisitor &vis) override;
     466                 :             : 
     467                 :         164 :   const Analysis::NodeMapping &get_mappings () const override final
     468                 :             :   {
     469                 :         164 :     return mappings;
     470                 :             :   }
     471                 :             : 
     472                 :          48 :   location_t get_locus () const override final { return locus; }
     473                 :             : 
     474                 :           0 :   PatternType get_pattern_type () const override final
     475                 :             :   {
     476                 :           0 :     return PatternType::REFERENCE;
     477                 :             :   }
     478                 :             : 
     479                 :          70 :   std::unique_ptr<Pattern> &get_referenced_pattern () { return pattern; }
     480                 :             : 
     481                 :             : protected:
     482                 :             :   /* Use covariance to implement clone function as returning this object rather
     483                 :             :    * than base */
     484                 :           2 :   ReferencePattern *clone_pattern_impl () const override
     485                 :             :   {
     486                 :           2 :     return new ReferencePattern (*this);
     487                 :             :   }
     488                 :             : };
     489                 :             : 
     490                 :             : // Base class for a single field in a struct pattern - abstract
     491                 :           0 : class StructPatternField
     492                 :             : {
     493                 :             :   AST::AttrVec outer_attrs;
     494                 :             :   location_t locus;
     495                 :             :   Analysis::NodeMapping mappings;
     496                 :             : 
     497                 :             : public:
     498                 :             :   enum ItemType
     499                 :             :   {
     500                 :             :     TUPLE_PAT,
     501                 :             :     IDENT_PAT,
     502                 :             :     IDENT
     503                 :             :   };
     504                 :             : 
     505                 :             :   virtual ~StructPatternField () {}
     506                 :             : 
     507                 :             :   // Unique pointer custom clone function
     508                 :         280 :   std::unique_ptr<StructPatternField> clone_struct_pattern_field () const
     509                 :             :   {
     510                 :         280 :     return std::unique_ptr<StructPatternField> (
     511                 :         280 :       clone_struct_pattern_field_impl ());
     512                 :             :   }
     513                 :             : 
     514                 :             :   virtual std::string as_string () const;
     515                 :             :   virtual void accept_vis (HIRFullVisitor &vis) = 0;
     516                 :             :   virtual ItemType get_item_type () const = 0;
     517                 :             : 
     518                 :         122 :   location_t get_locus () const { return locus; }
     519                 :         182 :   Analysis::NodeMapping get_mappings () const { return mappings; };
     520                 :           0 :   AST::AttrVec get_outer_attrs () { return outer_attrs; }
     521                 :             : 
     522                 :             : protected:
     523                 :          65 :   StructPatternField (Analysis::NodeMapping mappings,
     524                 :             :                       AST::AttrVec outer_attribs, location_t locus)
     525                 :          65 :     : outer_attrs (std::move (outer_attribs)), locus (locus),
     526                 :          65 :       mappings (mappings)
     527                 :             :   {}
     528                 :             : 
     529                 :             :   // Clone function implementation as pure virtual method
     530                 :             :   virtual StructPatternField *clone_struct_pattern_field_impl () const = 0;
     531                 :             : };
     532                 :             : 
     533                 :             : // Tuple pattern single field in a struct pattern
     534                 :             : class StructPatternFieldTuplePat : public StructPatternField
     535                 :             : {
     536                 :             :   TupleIndex index;
     537                 :             :   std::unique_ptr<Pattern> tuple_pattern;
     538                 :             : 
     539                 :             : public:
     540                 :           1 :   StructPatternFieldTuplePat (Analysis::NodeMapping mappings, TupleIndex index,
     541                 :             :                               std::unique_ptr<Pattern> tuple_pattern,
     542                 :             :                               AST::AttrVec outer_attribs, location_t locus)
     543                 :           1 :     : StructPatternField (mappings, std::move (outer_attribs), locus),
     544                 :           1 :       index (index), tuple_pattern (std::move (tuple_pattern))
     545                 :           1 :   {}
     546                 :             : 
     547                 :             :   // Copy constructor requires clone
     548                 :           0 :   StructPatternFieldTuplePat (StructPatternFieldTuplePat const &other)
     549                 :           0 :     : StructPatternField (other), index (other.index),
     550                 :           0 :       tuple_pattern (other.tuple_pattern->clone_pattern ())
     551                 :           0 :   {}
     552                 :             : 
     553                 :             :   // Overload assignment operator to perform clone
     554                 :             :   StructPatternFieldTuplePat &
     555                 :             :   operator= (StructPatternFieldTuplePat const &other)
     556                 :             :   {
     557                 :             :     StructPatternField::operator= (other);
     558                 :             :     tuple_pattern = other.tuple_pattern->clone_pattern ();
     559                 :             :     index = other.index;
     560                 :             :     // outer_attrs = other.outer_attrs;
     561                 :             : 
     562                 :             :     return *this;
     563                 :             :   }
     564                 :             : 
     565                 :             :   // default move semantics
     566                 :             :   StructPatternFieldTuplePat (StructPatternFieldTuplePat &&other) = default;
     567                 :             :   StructPatternFieldTuplePat &operator= (StructPatternFieldTuplePat &&other)
     568                 :             :     = default;
     569                 :             : 
     570                 :             :   std::string as_string () const override;
     571                 :             : 
     572                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     573                 :             : 
     574                 :           0 :   TupleIndex get_index () { return index; }
     575                 :           0 :   std::unique_ptr<Pattern> &get_tuple_pattern () { return tuple_pattern; }
     576                 :             : 
     577                 :           0 :   ItemType get_item_type () const override final { return ItemType::TUPLE_PAT; }
     578                 :             : 
     579                 :             : protected:
     580                 :             :   /* Use covariance to implement clone function as returning this object rather
     581                 :             :    * than base */
     582                 :           0 :   StructPatternFieldTuplePat *clone_struct_pattern_field_impl () const override
     583                 :             :   {
     584                 :           0 :     return new StructPatternFieldTuplePat (*this);
     585                 :             :   }
     586                 :             : };
     587                 :             : 
     588                 :             : // Identifier pattern single field in a struct pattern
     589                 :             : class StructPatternFieldIdentPat : public StructPatternField
     590                 :             : {
     591                 :             :   Identifier ident;
     592                 :             :   std::unique_ptr<Pattern> ident_pattern;
     593                 :             : 
     594                 :             : public:
     595                 :           1 :   StructPatternFieldIdentPat (Analysis::NodeMapping mappings, Identifier ident,
     596                 :             :                               std::unique_ptr<Pattern> ident_pattern,
     597                 :             :                               AST::AttrVec outer_attrs, location_t locus)
     598                 :           1 :     : StructPatternField (mappings, std::move (outer_attrs), locus),
     599                 :           1 :       ident (std::move (ident)), ident_pattern (std::move (ident_pattern))
     600                 :           1 :   {}
     601                 :             : 
     602                 :             :   // Copy constructor requires clone
     603                 :           0 :   StructPatternFieldIdentPat (StructPatternFieldIdentPat const &other)
     604                 :           0 :     : StructPatternField (other), ident (other.ident),
     605                 :           0 :       ident_pattern (other.ident_pattern->clone_pattern ())
     606                 :           0 :   {}
     607                 :             : 
     608                 :             :   // Overload assignment operator to clone
     609                 :             :   StructPatternFieldIdentPat &
     610                 :             :   operator= (StructPatternFieldIdentPat const &other)
     611                 :             :   {
     612                 :             :     StructPatternField::operator= (other);
     613                 :             :     ident = other.ident;
     614                 :             :     ident_pattern = other.ident_pattern->clone_pattern ();
     615                 :             :     // outer_attrs = other.outer_attrs;
     616                 :             : 
     617                 :             :     return *this;
     618                 :             :   }
     619                 :             : 
     620                 :             :   // default move semantics
     621                 :             :   StructPatternFieldIdentPat (StructPatternFieldIdentPat &&other) = default;
     622                 :             :   StructPatternFieldIdentPat &operator= (StructPatternFieldIdentPat &&other)
     623                 :             :     = default;
     624                 :             : 
     625                 :             :   std::string as_string () const override;
     626                 :             : 
     627                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     628                 :             : 
     629                 :           1 :   ItemType get_item_type () const override final { return ItemType::IDENT_PAT; }
     630                 :             : 
     631                 :           2 :   Identifier get_identifier () const { return ident; }
     632                 :             : 
     633                 :           1 :   std::unique_ptr<Pattern> &get_pattern () { return ident_pattern; }
     634                 :             : 
     635                 :             : protected:
     636                 :             :   /* Use covariance to implement clone function as returning this object rather
     637                 :             :    * than base */
     638                 :           0 :   StructPatternFieldIdentPat *clone_struct_pattern_field_impl () const override
     639                 :             :   {
     640                 :           0 :     return new StructPatternFieldIdentPat (*this);
     641                 :             :   }
     642                 :             : };
     643                 :             : 
     644                 :             : // Identifier only (with no pattern) single field in a struct pattern
     645                 :             : class StructPatternFieldIdent : public StructPatternField
     646                 :             : {
     647                 :             :   bool has_ref;
     648                 :             :   Mutability mut;
     649                 :             :   Identifier ident;
     650                 :             : 
     651                 :             : public:
     652                 :          63 :   StructPatternFieldIdent (Analysis::NodeMapping mappings, Identifier ident,
     653                 :             :                            bool is_ref, Mutability mut,
     654                 :             :                            AST::AttrVec outer_attrs, location_t locus)
     655                 :          63 :     : StructPatternField (mappings, std::move (outer_attrs), locus),
     656                 :          63 :       has_ref (is_ref), mut (mut), ident (std::move (ident))
     657                 :          63 :   {}
     658                 :             : 
     659                 :             :   std::string as_string () const override;
     660                 :             : 
     661                 :           0 :   bool is_mut () const { return mut == Mutability::Mut; }
     662                 :             : 
     663                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     664                 :             : 
     665                 :         174 :   ItemType get_item_type () const override final { return ItemType::IDENT; }
     666                 :           0 :   bool get_has_ref () const { return has_ref; }
     667                 :         180 :   Identifier get_identifier () const { return ident; };
     668                 :             : 
     669                 :             : protected:
     670                 :             :   /* Use covariance to implement clone function as returning this object rather
     671                 :             :    * than base */
     672                 :         280 :   StructPatternFieldIdent *clone_struct_pattern_field_impl () const override
     673                 :             :   {
     674                 :         280 :     return new StructPatternFieldIdent (*this);
     675                 :             :   }
     676                 :             : };
     677                 :             : 
     678                 :             : // Elements of a struct pattern
     679                 :          35 : class StructPatternElements
     680                 :             : {
     681                 :             :   std::vector<std::unique_ptr<StructPatternField>> fields;
     682                 :             : 
     683                 :             : public:
     684                 :             :   // Returns whether there are any struct pattern fields
     685                 :           0 :   bool has_struct_pattern_fields () const { return !fields.empty (); }
     686                 :             : 
     687                 :             :   /* Returns whether the struct pattern elements is entirely empty (no fields,
     688                 :             :    * no etc). */
     689                 :           0 :   bool is_empty () const { return !has_struct_pattern_fields (); }
     690                 :             : 
     691                 :             :   // Constructor for StructPatternElements with both (potentially)
     692                 :          35 :   StructPatternElements (
     693                 :             :     std::vector<std::unique_ptr<StructPatternField>> fields)
     694                 :          35 :     : fields (std::move (fields))
     695                 :             :   {}
     696                 :             : 
     697                 :             :   // Copy constructor with vector clone
     698                 :         140 :   StructPatternElements (StructPatternElements const &other)
     699                 :         140 :   {
     700                 :         140 :     fields.reserve (other.fields.size ());
     701                 :         420 :     for (const auto &e : other.fields)
     702                 :         280 :       fields.push_back (e->clone_struct_pattern_field ());
     703                 :         140 :   }
     704                 :             : 
     705                 :             :   // Overloaded assignment operator with vector clone
     706                 :             :   StructPatternElements &operator= (StructPatternElements const &other)
     707                 :             :   {
     708                 :             :     fields.clear ();
     709                 :             :     fields.reserve (other.fields.size ());
     710                 :             :     for (const auto &e : other.fields)
     711                 :             :       fields.push_back (e->clone_struct_pattern_field ());
     712                 :             : 
     713                 :             :     return *this;
     714                 :             :   }
     715                 :             : 
     716                 :             :   // move constructors
     717                 :          35 :   StructPatternElements (StructPatternElements &&other) = default;
     718                 :             :   StructPatternElements &operator= (StructPatternElements &&other) = default;
     719                 :             : 
     720                 :             :   // Creates an empty StructPatternElements
     721                 :             :   static StructPatternElements create_empty ()
     722                 :             :   {
     723                 :             :     return StructPatternElements (
     724                 :             :       std::vector<std::unique_ptr<StructPatternField>> ());
     725                 :             :   }
     726                 :             : 
     727                 :             :   std::string as_string () const;
     728                 :             : 
     729                 :             :   std::vector<std::unique_ptr<StructPatternField>> &get_struct_pattern_fields ()
     730                 :             :   {
     731                 :          89 :     return fields;
     732                 :             :   }
     733                 :             : };
     734                 :             : 
     735                 :             : // Struct pattern HIR node representation
     736                 :             : class StructPattern : public Pattern
     737                 :             : {
     738                 :             :   PathInExpression path;
     739                 :             :   StructPatternElements elems;
     740                 :             :   Analysis::NodeMapping mappings;
     741                 :             : 
     742                 :             : public:
     743                 :             :   std::string as_string () const override;
     744                 :             : 
     745                 :          35 :   StructPattern (Analysis::NodeMapping mappings, PathInExpression struct_path,
     746                 :             :                  StructPatternElements elems)
     747                 :          70 :     : path (std::move (struct_path)), elems (std::move (elems)),
     748                 :          35 :       mappings (mappings)
     749                 :          35 :   {}
     750                 :             : 
     751                 :           0 :   bool has_struct_pattern_elems () const { return !elems.is_empty (); }
     752                 :             : 
     753                 :          64 :   location_t get_locus () const override { return path.get_locus (); }
     754                 :             : 
     755                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     756                 :             :   void accept_vis (HIRPatternVisitor &vis) override;
     757                 :             : 
     758                 :         173 :   PathInExpression &get_path () { return path; }
     759                 :          89 :   StructPatternElements &get_struct_pattern_elems () { return elems; }
     760                 :             : 
     761                 :         139 :   const Analysis::NodeMapping &get_mappings () const override final
     762                 :             :   {
     763                 :         139 :     return mappings;
     764                 :             :   }
     765                 :             : 
     766                 :           0 :   PatternType get_pattern_type () const override final
     767                 :             :   {
     768                 :           0 :     return PatternType::STRUCT;
     769                 :             :   }
     770                 :             : 
     771                 :             : protected:
     772                 :             :   /* Use covariance to implement clone function as returning this object rather
     773                 :             :    * than base */
     774                 :         140 :   StructPattern *clone_pattern_impl () const override
     775                 :             :   {
     776                 :         140 :     return new StructPattern (*this);
     777                 :             :   }
     778                 :             : };
     779                 :             : 
     780                 :             : // Base abstract class for TupleStructItems and TuplePatternItems
     781                 :         478 : class TupleItems : public FullVisitable
     782                 :             : {
     783                 :             : public:
     784                 :             :   enum ItemType
     785                 :             :   {
     786                 :             :     MULTIPLE,
     787                 :             :     RANGED,
     788                 :             :   };
     789                 :             : 
     790                 :             :   virtual ~TupleItems () {}
     791                 :             : 
     792                 :             :   // TODO: should this store location data?
     793                 :             : 
     794                 :             :   // Unique pointer custom clone function
     795                 :             :   std::unique_ptr<TupleItems> clone_tuple_items () const
     796                 :             :   {
     797                 :             :     return std::unique_ptr<TupleItems> (clone_tuple_items_impl ());
     798                 :             :   }
     799                 :             : 
     800                 :             :   virtual ItemType get_item_type () const = 0;
     801                 :             : 
     802                 :             :   virtual std::string as_string () const = 0;
     803                 :             : 
     804                 :             : protected:
     805                 :             :   // pure virtual clone implementation
     806                 :             :   virtual TupleItems *clone_tuple_items_impl () const = 0;
     807                 :             : };
     808                 :             : 
     809                 :             : // Base abstract class for patterns used in TupleStructPattern
     810                 :         243 : class TupleStructItems : public TupleItems
     811                 :             : {
     812                 :             : public:
     813                 :             :   // Unique pointer custom clone function
     814                 :         137 :   std::unique_ptr<TupleStructItems> clone_tuple_struct_items () const
     815                 :             :   {
     816                 :         137 :     return std::unique_ptr<TupleStructItems> (clone_tuple_items_impl ());
     817                 :             :   }
     818                 :             : 
     819                 :             : protected:
     820                 :             :   // pure virtual clone implementation
     821                 :             :   virtual TupleStructItems *clone_tuple_items_impl () const override = 0;
     822                 :             : };
     823                 :             : 
     824                 :             : // Class for non-ranged tuple struct pattern patterns
     825                 :             : class TupleStructItemsNoRange : public TupleStructItems
     826                 :             : {
     827                 :             :   std::vector<std::unique_ptr<Pattern>> patterns;
     828                 :             : 
     829                 :             : public:
     830                 :         106 :   TupleStructItemsNoRange (std::vector<std::unique_ptr<Pattern>> patterns)
     831                 :         106 :     : patterns (std::move (patterns))
     832                 :             :   {}
     833                 :             : 
     834                 :             :   // Copy constructor with vector clone
     835                 :         137 :   TupleStructItemsNoRange (TupleStructItemsNoRange const &other)
     836                 :         137 :   {
     837                 :         137 :     patterns.reserve (other.patterns.size ());
     838                 :         274 :     for (const auto &e : other.patterns)
     839                 :         137 :       patterns.push_back (e->clone_pattern ());
     840                 :         137 :   }
     841                 :             : 
     842                 :             :   // Overloaded assignment operator with vector clone
     843                 :             :   TupleStructItemsNoRange &operator= (TupleStructItemsNoRange const &other)
     844                 :             :   {
     845                 :             :     patterns.clear ();
     846                 :             :     patterns.reserve (other.patterns.size ());
     847                 :             :     for (const auto &e : other.patterns)
     848                 :             :       patterns.push_back (e->clone_pattern ());
     849                 :             : 
     850                 :             :     return *this;
     851                 :             :   }
     852                 :             : 
     853                 :             :   // move constructors
     854                 :             :   TupleStructItemsNoRange (TupleStructItemsNoRange &&other) = default;
     855                 :             :   TupleStructItemsNoRange &operator= (TupleStructItemsNoRange &&other)
     856                 :             :     = default;
     857                 :             : 
     858                 :             :   std::string as_string () const override;
     859                 :             : 
     860                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     861                 :             : 
     862                 :         569 :   std::vector<std::unique_ptr<Pattern>> &get_patterns () { return patterns; }
     863                 :             :   const std::vector<std::unique_ptr<Pattern>> &get_patterns () const
     864                 :             :   {
     865                 :             :     return patterns;
     866                 :             :   }
     867                 :             : 
     868                 :         284 :   ItemType get_item_type () const override final { return ItemType::MULTIPLE; }
     869                 :             : 
     870                 :             : protected:
     871                 :             :   /* Use covariance to implement clone function as returning this object rather
     872                 :             :    * than base */
     873                 :         137 :   TupleStructItemsNoRange *clone_tuple_items_impl () const override
     874                 :             :   {
     875                 :         137 :     return new TupleStructItemsNoRange (*this);
     876                 :             :   }
     877                 :             : };
     878                 :             : 
     879                 :             : // Class for ranged tuple struct pattern patterns
     880                 :             : class TupleStructItemsRange : public TupleStructItems
     881                 :             : {
     882                 :             :   std::vector<std::unique_ptr<Pattern>> lower_patterns;
     883                 :             :   std::vector<std::unique_ptr<Pattern>> upper_patterns;
     884                 :             : 
     885                 :             : public:
     886                 :             :   TupleStructItemsRange (std::vector<std::unique_ptr<Pattern>> lower_patterns,
     887                 :             :                          std::vector<std::unique_ptr<Pattern>> upper_patterns)
     888                 :             :     : lower_patterns (std::move (lower_patterns)),
     889                 :             :       upper_patterns (std::move (upper_patterns))
     890                 :             :   {}
     891                 :             : 
     892                 :             :   // Copy constructor with vector clone
     893                 :           0 :   TupleStructItemsRange (TupleStructItemsRange const &other)
     894                 :           0 :   {
     895                 :           0 :     lower_patterns.reserve (other.lower_patterns.size ());
     896                 :           0 :     for (const auto &e : other.lower_patterns)
     897                 :           0 :       lower_patterns.push_back (e->clone_pattern ());
     898                 :             : 
     899                 :           0 :     upper_patterns.reserve (other.upper_patterns.size ());
     900                 :           0 :     for (const auto &e : other.upper_patterns)
     901                 :           0 :       upper_patterns.push_back (e->clone_pattern ());
     902                 :           0 :   }
     903                 :             : 
     904                 :             :   // Overloaded assignment operator to clone
     905                 :             :   TupleStructItemsRange &operator= (TupleStructItemsRange const &other)
     906                 :             :   {
     907                 :             :     lower_patterns.clear ();
     908                 :             :     lower_patterns.reserve (other.lower_patterns.size ());
     909                 :             :     for (const auto &e : other.lower_patterns)
     910                 :             :       lower_patterns.push_back (e->clone_pattern ());
     911                 :             : 
     912                 :             :     upper_patterns.clear ();
     913                 :             :     upper_patterns.reserve (other.upper_patterns.size ());
     914                 :             :     for (const auto &e : other.upper_patterns)
     915                 :             :       upper_patterns.push_back (e->clone_pattern ());
     916                 :             : 
     917                 :             :     return *this;
     918                 :             :   }
     919                 :             : 
     920                 :             :   // move constructors
     921                 :             :   TupleStructItemsRange (TupleStructItemsRange &&other) = default;
     922                 :             :   TupleStructItemsRange &operator= (TupleStructItemsRange &&other) = default;
     923                 :             : 
     924                 :             :   std::string as_string () const override;
     925                 :             : 
     926                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     927                 :             : 
     928                 :           0 :   std::vector<std::unique_ptr<Pattern>> &get_lower_patterns ()
     929                 :             :   {
     930                 :           0 :     return lower_patterns;
     931                 :             :   }
     932                 :             :   const std::vector<std::unique_ptr<Pattern>> &get_lower_patterns () const
     933                 :             :   {
     934                 :             :     return lower_patterns;
     935                 :             :   }
     936                 :             : 
     937                 :             :   // TODO: seems kinda dodgy. Think of better way.
     938                 :           0 :   std::vector<std::unique_ptr<Pattern>> &get_upper_patterns ()
     939                 :             :   {
     940                 :           0 :     return upper_patterns;
     941                 :             :   }
     942                 :             :   const std::vector<std::unique_ptr<Pattern>> &get_upper_patterns () const
     943                 :             :   {
     944                 :             :     return upper_patterns;
     945                 :             :   }
     946                 :             : 
     947                 :           0 :   ItemType get_item_type () const override final { return ItemType::RANGED; }
     948                 :             : 
     949                 :             : protected:
     950                 :             :   /* Use covariance to implement clone function as returning this object rather
     951                 :             :    * than base */
     952                 :           0 :   TupleStructItemsRange *clone_tuple_items_impl () const override
     953                 :             :   {
     954                 :           0 :     return new TupleStructItemsRange (*this);
     955                 :             :   }
     956                 :             : };
     957                 :             : 
     958                 :             : // HIR node representing a tuple struct pattern
     959                 :             : class TupleStructPattern : public Pattern
     960                 :             : {
     961                 :             :   PathInExpression path;
     962                 :             :   std::unique_ptr<TupleStructItems> items;
     963                 :             :   Analysis::NodeMapping mappings;
     964                 :             : 
     965                 :             :   /* TOOD: should this store location data? current accessor uses path location
     966                 :             :    * data */
     967                 :             : 
     968                 :             : public:
     969                 :             :   std::string as_string () const override;
     970                 :             : 
     971                 :         106 :   TupleStructPattern (Analysis::NodeMapping mappings,
     972                 :             :                       PathInExpression tuple_struct_path,
     973                 :             :                       std::unique_ptr<TupleStructItems> items)
     974                 :         212 :     : path (std::move (tuple_struct_path)), items (std::move (items)),
     975                 :         106 :       mappings (mappings)
     976                 :         106 :   {}
     977                 :             : 
     978                 :             :   // Copy constructor required to clone
     979                 :         137 :   TupleStructPattern (TupleStructPattern const &other)
     980                 :         137 :     : path (other.path), items (other.items->clone_tuple_struct_items ()),
     981                 :         137 :       mappings (other.mappings)
     982                 :         137 :   {}
     983                 :             : 
     984                 :             :   // Operator overload assignment operator to clone
     985                 :             :   TupleStructPattern &operator= (TupleStructPattern const &other)
     986                 :             :   {
     987                 :             :     path = other.path;
     988                 :             :     items = other.items->clone_tuple_struct_items ();
     989                 :             :     mappings = other.mappings;
     990                 :             : 
     991                 :             :     return *this;
     992                 :             :   }
     993                 :             : 
     994                 :             :   // move constructors
     995                 :             :   TupleStructPattern (TupleStructPattern &&other) = default;
     996                 :             :   TupleStructPattern &operator= (TupleStructPattern &&other) = default;
     997                 :             : 
     998                 :         184 :   location_t get_locus () const override { return path.get_locus (); }
     999                 :             : 
    1000                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1001                 :             :   void accept_vis (HIRPatternVisitor &vis) override;
    1002                 :             : 
    1003                 :         520 :   PathInExpression &get_path () { return path; }
    1004                 :             : 
    1005                 :         284 :   std::unique_ptr<TupleStructItems> &get_items () { return items; }
    1006                 :             : 
    1007                 :         431 :   const Analysis::NodeMapping &get_mappings () const override final
    1008                 :             :   {
    1009                 :         431 :     return mappings;
    1010                 :             :   }
    1011                 :             : 
    1012                 :           0 :   PatternType get_pattern_type () const override final
    1013                 :             :   {
    1014                 :           0 :     return PatternType::TUPLE_STRUCT;
    1015                 :             :   }
    1016                 :             : 
    1017                 :             : protected:
    1018                 :             :   /* Use covariance to implement clone function as returning this object rather
    1019                 :             :    * than base */
    1020                 :         137 :   TupleStructPattern *clone_pattern_impl () const override
    1021                 :             :   {
    1022                 :         137 :     return new TupleStructPattern (*this);
    1023                 :             :   }
    1024                 :             : };
    1025                 :             : 
    1026                 :             : // Base abstract class representing TuplePattern patterns
    1027                 :         235 : class TuplePatternItems : public TupleItems
    1028                 :             : {
    1029                 :             : public:
    1030                 :             :   // Unique pointer custom clone function
    1031                 :          88 :   std::unique_ptr<TuplePatternItems> clone_tuple_pattern_items () const
    1032                 :             :   {
    1033                 :          88 :     return std::unique_ptr<TuplePatternItems> (clone_tuple_items_impl ());
    1034                 :             :   }
    1035                 :             : 
    1036                 :             : protected:
    1037                 :             :   // pure virtual clone implementation
    1038                 :             :   virtual TuplePatternItems *clone_tuple_items_impl () const override = 0;
    1039                 :             : };
    1040                 :             : 
    1041                 :             : // Class representing TuplePattern patterns where there are multiple patterns
    1042                 :             : class TuplePatternItemsMultiple : public TuplePatternItems
    1043                 :             : {
    1044                 :             :   std::vector<std::unique_ptr<Pattern>> patterns;
    1045                 :             : 
    1046                 :             : public:
    1047                 :         147 :   TuplePatternItemsMultiple (std::vector<std::unique_ptr<Pattern>> patterns)
    1048                 :         147 :     : patterns (std::move (patterns))
    1049                 :             :   {}
    1050                 :             : 
    1051                 :             :   // Copy constructor with vector clone
    1052                 :          88 :   TuplePatternItemsMultiple (TuplePatternItemsMultiple const &other)
    1053                 :          88 :   {
    1054                 :          88 :     patterns.reserve (other.patterns.size ());
    1055                 :         264 :     for (const auto &e : other.patterns)
    1056                 :         176 :       patterns.push_back (e->clone_pattern ());
    1057                 :          88 :   }
    1058                 :             : 
    1059                 :             :   // Overloaded assignment operator to vector clone
    1060                 :             :   TuplePatternItemsMultiple &operator= (TuplePatternItemsMultiple const &other)
    1061                 :             :   {
    1062                 :             :     patterns.clear ();
    1063                 :             :     patterns.reserve (other.patterns.size ());
    1064                 :             :     for (const auto &e : other.patterns)
    1065                 :             :       patterns.push_back (e->clone_pattern ());
    1066                 :             : 
    1067                 :             :     return *this;
    1068                 :             :   }
    1069                 :             : 
    1070                 :             :   // move constructors
    1071                 :             :   TuplePatternItemsMultiple (TuplePatternItemsMultiple &&other) = default;
    1072                 :             :   TuplePatternItemsMultiple &operator= (TuplePatternItemsMultiple &&other)
    1073                 :             :     = default;
    1074                 :             : 
    1075                 :             :   std::string as_string () const override;
    1076                 :             : 
    1077                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1078                 :             : 
    1079                 :         405 :   ItemType get_item_type () const override { return ItemType::MULTIPLE; }
    1080                 :             : 
    1081                 :         404 :   std::vector<std::unique_ptr<Pattern>> &get_patterns () { return patterns; }
    1082                 :             :   const std::vector<std::unique_ptr<Pattern>> &get_patterns () const
    1083                 :             :   {
    1084                 :             :     return patterns;
    1085                 :             :   }
    1086                 :             : 
    1087                 :             : protected:
    1088                 :             :   /* Use covariance to implement clone function as returning this object rather
    1089                 :             :    * than base */
    1090                 :          88 :   TuplePatternItemsMultiple *clone_tuple_items_impl () const override
    1091                 :             :   {
    1092                 :          88 :     return new TuplePatternItemsMultiple (*this);
    1093                 :             :   }
    1094                 :             : };
    1095                 :             : 
    1096                 :             : // Class representing TuplePattern patterns where there are a range of patterns
    1097                 :             : class TuplePatternItemsRanged : public TuplePatternItems
    1098                 :             : {
    1099                 :             :   std::vector<std::unique_ptr<Pattern>> lower_patterns;
    1100                 :             :   std::vector<std::unique_ptr<Pattern>> upper_patterns;
    1101                 :             : 
    1102                 :             : public:
    1103                 :           0 :   TuplePatternItemsRanged (std::vector<std::unique_ptr<Pattern>> lower_patterns,
    1104                 :             :                            std::vector<std::unique_ptr<Pattern>> upper_patterns)
    1105                 :           0 :     : lower_patterns (std::move (lower_patterns)),
    1106                 :           0 :       upper_patterns (std::move (upper_patterns))
    1107                 :             :   {}
    1108                 :             : 
    1109                 :             :   // Copy constructor with vector clone
    1110                 :           0 :   TuplePatternItemsRanged (TuplePatternItemsRanged const &other)
    1111                 :           0 :   {
    1112                 :           0 :     lower_patterns.reserve (other.lower_patterns.size ());
    1113                 :           0 :     for (const auto &e : other.lower_patterns)
    1114                 :           0 :       lower_patterns.push_back (e->clone_pattern ());
    1115                 :             : 
    1116                 :           0 :     upper_patterns.reserve (other.upper_patterns.size ());
    1117                 :           0 :     for (const auto &e : other.upper_patterns)
    1118                 :           0 :       upper_patterns.push_back (e->clone_pattern ());
    1119                 :           0 :   }
    1120                 :             : 
    1121                 :             :   // Overloaded assignment operator to clone
    1122                 :             :   TuplePatternItemsRanged &operator= (TuplePatternItemsRanged const &other)
    1123                 :             :   {
    1124                 :             :     lower_patterns.clear ();
    1125                 :             :     lower_patterns.reserve (other.lower_patterns.size ());
    1126                 :             :     for (const auto &e : other.lower_patterns)
    1127                 :             :       lower_patterns.push_back (e->clone_pattern ());
    1128                 :             : 
    1129                 :             :     lower_patterns.clear ();
    1130                 :             :     upper_patterns.reserve (other.upper_patterns.size ());
    1131                 :             :     for (const auto &e : other.upper_patterns)
    1132                 :             :       upper_patterns.push_back (e->clone_pattern ());
    1133                 :             : 
    1134                 :             :     return *this;
    1135                 :             :   }
    1136                 :             : 
    1137                 :             :   // move constructors
    1138                 :             :   TuplePatternItemsRanged (TuplePatternItemsRanged &&other) = default;
    1139                 :             :   TuplePatternItemsRanged &operator= (TuplePatternItemsRanged &&other)
    1140                 :             :     = default;
    1141                 :             : 
    1142                 :             :   std::string as_string () const override;
    1143                 :             : 
    1144                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1145                 :             : 
    1146                 :           0 :   ItemType get_item_type () const override { return ItemType::RANGED; }
    1147                 :             : 
    1148                 :           0 :   std::vector<std::unique_ptr<Pattern>> &get_lower_patterns ()
    1149                 :             :   {
    1150                 :           0 :     return lower_patterns;
    1151                 :             :   }
    1152                 :             :   const std::vector<std::unique_ptr<Pattern>> &get_lower_patterns () const
    1153                 :             :   {
    1154                 :             :     return lower_patterns;
    1155                 :             :   }
    1156                 :             : 
    1157                 :           0 :   std::vector<std::unique_ptr<Pattern>> &get_upper_patterns ()
    1158                 :             :   {
    1159                 :           0 :     return upper_patterns;
    1160                 :             :   }
    1161                 :             :   const std::vector<std::unique_ptr<Pattern>> &get_upper_patterns () const
    1162                 :             :   {
    1163                 :             :     return upper_patterns;
    1164                 :             :   }
    1165                 :             : 
    1166                 :             : protected:
    1167                 :             :   /* Use covariance to implement clone function as returning this object rather
    1168                 :             :    * than base */
    1169                 :           0 :   TuplePatternItemsRanged *clone_tuple_items_impl () const override
    1170                 :             :   {
    1171                 :           0 :     return new TuplePatternItemsRanged (*this);
    1172                 :             :   }
    1173                 :             : };
    1174                 :             : 
    1175                 :             : // HIR node representing a tuple pattern
    1176                 :             : class TuplePattern : public Pattern
    1177                 :             : {
    1178                 :             :   std::unique_ptr<TuplePatternItems> items;
    1179                 :             :   location_t locus;
    1180                 :             :   Analysis::NodeMapping mappings;
    1181                 :             : 
    1182                 :             : public:
    1183                 :             :   std::string as_string () const override;
    1184                 :             : 
    1185                 :             :   // Returns true if the tuple pattern has items
    1186                 :         117 :   bool has_tuple_pattern_items () const { return items != nullptr; }
    1187                 :             : 
    1188                 :         147 :   TuplePattern (Analysis::NodeMapping mappings,
    1189                 :             :                 std::unique_ptr<TuplePatternItems> items, location_t locus)
    1190                 :         147 :     : items (std::move (items)), locus (locus), mappings (mappings)
    1191                 :             :   {}
    1192                 :             : 
    1193                 :             :   // Copy constructor requires clone
    1194                 :          88 :   TuplePattern (TuplePattern const &other)
    1195                 :         176 :     : items (other.items->clone_tuple_pattern_items ()), locus (other.locus),
    1196                 :          88 :       mappings (other.mappings)
    1197                 :          88 :   {}
    1198                 :             : 
    1199                 :             :   // Overload assignment operator to clone
    1200                 :             :   TuplePattern &operator= (TuplePattern const &other)
    1201                 :             :   {
    1202                 :             :     items = other.items->clone_tuple_pattern_items ();
    1203                 :             :     locus = other.locus;
    1204                 :             :     mappings = other.mappings;
    1205                 :             : 
    1206                 :             :     return *this;
    1207                 :             :   }
    1208                 :             : 
    1209                 :         548 :   location_t get_locus () const override { return locus; }
    1210                 :             : 
    1211                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1212                 :             :   void accept_vis (HIRPatternVisitor &vis) override;
    1213                 :             : 
    1214                 :         974 :   const Analysis::NodeMapping &get_mappings () const override final
    1215                 :             :   {
    1216                 :         974 :     return mappings;
    1217                 :             :   }
    1218                 :             : 
    1219                 :           0 :   PatternType get_pattern_type () const override final
    1220                 :             :   {
    1221                 :           0 :     return PatternType::TUPLE;
    1222                 :             :   }
    1223                 :             : 
    1224                 :         810 :   std::unique_ptr<TuplePatternItems> &get_items () { return items; }
    1225                 :             :   const std::unique_ptr<TuplePatternItems> &get_items () const { return items; }
    1226                 :             : 
    1227                 :             : protected:
    1228                 :             :   /* Use covariance to implement clone function as returning this object rather
    1229                 :             :    * than base */
    1230                 :          88 :   TuplePattern *clone_pattern_impl () const override
    1231                 :             :   {
    1232                 :          88 :     return new TuplePattern (*this);
    1233                 :             :   }
    1234                 :             : };
    1235                 :             : 
    1236                 :             : // HIR node representing patterns that can match slices and arrays
    1237                 :             : class SlicePattern : public Pattern
    1238                 :             : {
    1239                 :             :   std::vector<std::unique_ptr<Pattern>> items;
    1240                 :             :   location_t locus;
    1241                 :             :   Analysis::NodeMapping mappings;
    1242                 :             : 
    1243                 :             : public:
    1244                 :             :   std::string as_string () const override;
    1245                 :             : 
    1246                 :           0 :   SlicePattern (Analysis::NodeMapping mappings,
    1247                 :             :                 std::vector<std::unique_ptr<Pattern>> items, location_t locus)
    1248                 :           0 :     : items (std::move (items)), locus (locus), mappings (mappings)
    1249                 :           0 :   {}
    1250                 :             : 
    1251                 :             :   // Copy constructor with vector clone
    1252                 :           0 :   SlicePattern (SlicePattern const &other)
    1253                 :           0 :     : locus (other.locus), mappings (other.mappings)
    1254                 :             :   {
    1255                 :           0 :     items.reserve (other.items.size ());
    1256                 :           0 :     for (const auto &e : other.items)
    1257                 :           0 :       items.push_back (e->clone_pattern ());
    1258                 :           0 :   }
    1259                 :             : 
    1260                 :             :   // Overloaded assignment operator to vector clone
    1261                 :             :   SlicePattern &operator= (SlicePattern const &other)
    1262                 :             :   {
    1263                 :             :     locus = other.locus;
    1264                 :             :     mappings = other.mappings;
    1265                 :             : 
    1266                 :             :     items.clear ();
    1267                 :             :     items.reserve (other.items.size ());
    1268                 :             :     for (const auto &e : other.items)
    1269                 :             :       items.push_back (e->clone_pattern ());
    1270                 :             : 
    1271                 :             :     return *this;
    1272                 :             :   }
    1273                 :             : 
    1274                 :             :   // move constructors
    1275                 :             :   SlicePattern (SlicePattern &&other) = default;
    1276                 :             :   SlicePattern &operator= (SlicePattern &&other) = default;
    1277                 :             : 
    1278                 :           0 :   std::vector<std::unique_ptr<Pattern>> &get_items () { return items; }
    1279                 :             :   const std::vector<std::unique_ptr<Pattern>> &get_items () const
    1280                 :             :   {
    1281                 :             :     return items;
    1282                 :             :   }
    1283                 :             : 
    1284                 :           0 :   location_t get_locus () const override { return locus; }
    1285                 :             : 
    1286                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1287                 :             :   void accept_vis (HIRPatternVisitor &vis) override;
    1288                 :             : 
    1289                 :           0 :   const Analysis::NodeMapping &get_mappings () const override final
    1290                 :             :   {
    1291                 :           0 :     return mappings;
    1292                 :             :   }
    1293                 :             : 
    1294                 :           0 :   PatternType get_pattern_type () const override final
    1295                 :             :   {
    1296                 :           0 :     return PatternType::SLICE;
    1297                 :             :   }
    1298                 :             : 
    1299                 :             : protected:
    1300                 :             :   /* Use covariance to implement clone function as returning this object rather
    1301                 :             :    * than base */
    1302                 :           0 :   SlicePattern *clone_pattern_impl () const override
    1303                 :             :   {
    1304                 :           0 :     return new SlicePattern (*this);
    1305                 :             :   }
    1306                 :             : };
    1307                 :             : 
    1308                 :             : // HIR node for alternative patterns
    1309                 :             : class AltPattern : public Pattern
    1310                 :             : {
    1311                 :             :   std::vector<std::unique_ptr<Pattern>> alts;
    1312                 :             :   location_t locus;
    1313                 :             :   Analysis::NodeMapping mappings;
    1314                 :             : 
    1315                 :             : public:
    1316                 :             :   std::string as_string () const override;
    1317                 :             : 
    1318                 :           2 :   AltPattern (Analysis::NodeMapping mappings,
    1319                 :             :               std::vector<std::unique_ptr<Pattern>> alts, location_t locus)
    1320                 :           2 :     : alts (std::move (alts)), locus (locus), mappings (mappings)
    1321                 :           2 :   {}
    1322                 :             : 
    1323                 :             :   // Copy constructor with vector clone
    1324                 :           1 :   AltPattern (AltPattern const &other)
    1325                 :           1 :     : locus (other.locus), mappings (other.mappings)
    1326                 :             :   {
    1327                 :           1 :     alts.reserve (other.alts.size ());
    1328                 :           4 :     for (const auto &e : other.alts)
    1329                 :           3 :       alts.push_back (e->clone_pattern ());
    1330                 :           1 :   }
    1331                 :             : 
    1332                 :             :   // Overloaded assignment operator to vector clone
    1333                 :             :   AltPattern &operator= (AltPattern const &other)
    1334                 :             :   {
    1335                 :             :     locus = other.locus;
    1336                 :             :     mappings = other.mappings;
    1337                 :             : 
    1338                 :             :     alts.clear ();
    1339                 :             :     alts.reserve (other.alts.size ());
    1340                 :             :     for (const auto &e : other.alts)
    1341                 :             :       alts.push_back (e->clone_pattern ());
    1342                 :             : 
    1343                 :             :     return *this;
    1344                 :             :   }
    1345                 :             : 
    1346                 :             :   // move constructors
    1347                 :             :   AltPattern (AltPattern &&other) = default;
    1348                 :             :   AltPattern &operator= (AltPattern &&other) = default;
    1349                 :             : 
    1350                 :           2 :   std::vector<std::unique_ptr<Pattern>> &get_alts () { return alts; }
    1351                 :             :   const std::vector<std::unique_ptr<Pattern>> &get_alts () const
    1352                 :             :   {
    1353                 :             :     return alts;
    1354                 :             :   }
    1355                 :             : 
    1356                 :           6 :   location_t get_locus () const override { return locus; }
    1357                 :             : 
    1358                 :             :   void accept_vis (HIRFullVisitor &vis) override;
    1359                 :             :   void accept_vis (HIRPatternVisitor &vis) override;
    1360                 :             : 
    1361                 :          10 :   const Analysis::NodeMapping &get_mappings () const override final
    1362                 :             :   {
    1363                 :          10 :     return mappings;
    1364                 :             :   }
    1365                 :             : 
    1366                 :           0 :   PatternType get_pattern_type () const override final
    1367                 :             :   {
    1368                 :           0 :     return PatternType::ALT;
    1369                 :             :   }
    1370                 :             : 
    1371                 :             : protected:
    1372                 :             :   /* Use covariance to implement clone function as returning this object rather
    1373                 :             :    * than base */
    1374                 :           1 :   AltPattern *clone_pattern_impl () const override
    1375                 :             :   {
    1376                 :           1 :     return new AltPattern (*this);
    1377                 :             :   }
    1378                 :             : };
    1379                 :             : 
    1380                 :             : // Moved definition to rust-path.h
    1381                 :             : class PathPattern;
    1382                 :             : 
    1383                 :             : // Forward decls for paths (defined in rust-path.h)
    1384                 :             : class PathInExpression;
    1385                 :             : class QualifiedPathInExpression;
    1386                 :             : 
    1387                 :             : } // namespace HIR
    1388                 :             : } // namespace Rust
    1389                 :             : 
    1390                 :             : #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.