LCOV - code coverage report
Current view: top level - gcc/rust/backend - rust-compile-pattern.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 53.2 % 62 33
Test Date: 2025-09-20 13:40:47 Functions: 45.0 % 20 9
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2020-2025 Free Software Foundation, Inc.
       2                 :             : 
       3                 :             : // This file is part of GCC.
       4                 :             : 
       5                 :             : // GCC is free software; you can redistribute it and/or modify it under
       6                 :             : // the terms of the GNU General Public License as published by the Free
       7                 :             : // Software Foundation; either version 3, or (at your option) any later
       8                 :             : // version.
       9                 :             : 
      10                 :             : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11                 :             : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12                 :             : // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13                 :             : // for more details.
      14                 :             : 
      15                 :             : // You should have received a copy of the GNU General Public License
      16                 :             : // along with GCC; see the file COPYING3.  If not see
      17                 :             : // <http://www.gnu.org/licenses/>.
      18                 :             : 
      19                 :             : #include "rust-compile-base.h"
      20                 :             : #include "rust-hir-pattern.h"
      21                 :             : #include "rust-hir-visitor.h"
      22                 :             : #include "rust-tyty.h"
      23                 :             : 
      24                 :             : namespace Rust {
      25                 :             : namespace Compile {
      26                 :             : 
      27                 :        3149 : class CompilePatternCheckExpr : public HIRCompileBase,
      28                 :             :                                 public HIR::HIRPatternVisitor
      29                 :             : {
      30                 :             : public:
      31                 :        3149 :   static tree Compile (HIR::Pattern &pattern, tree match_scrutinee_expr,
      32                 :             :                        Context *ctx)
      33                 :             :   {
      34                 :        3149 :     CompilePatternCheckExpr compiler (ctx, match_scrutinee_expr);
      35                 :        3149 :     pattern.accept_vis (compiler);
      36                 :        3149 :     rust_assert (compiler.check_expr);
      37                 :        3149 :     return compiler.check_expr;
      38                 :        3149 :   }
      39                 :             : 
      40                 :             :   void visit (HIR::PathInExpression &pattern) override;
      41                 :             :   void visit (HIR::LiteralPattern &) override;
      42                 :             :   void visit (HIR::RangePattern &pattern) override;
      43                 :             :   void visit (HIR::ReferencePattern &) override;
      44                 :             :   void visit (HIR::AltPattern &) override;
      45                 :             :   void visit (HIR::StructPattern &) override;
      46                 :             :   void visit (HIR::TupleStructPattern &) override;
      47                 :             :   void visit (HIR::TuplePattern &) override;
      48                 :             :   void visit (HIR::IdentifierPattern &) override;
      49                 :             :   void visit (HIR::SlicePattern &) override;
      50                 :             : 
      51                 :             :   // Always succeeds
      52                 :         414 :   void visit (HIR::WildcardPattern &) override
      53                 :             :   {
      54                 :         414 :     check_expr = boolean_true_node;
      55                 :         414 :   }
      56                 :             : 
      57                 :             :   // Empty visit for unused Pattern HIR nodes.
      58                 :           0 :   void visit (HIR::QualifiedPathInExpression &) override {}
      59                 :             : 
      60                 :        3149 :   CompilePatternCheckExpr (Context *ctx, tree match_scrutinee_expr)
      61                 :        3149 :     : HIRCompileBase (ctx), match_scrutinee_expr (match_scrutinee_expr),
      62                 :        3149 :       check_expr (NULL_TREE)
      63                 :             :   {}
      64                 :             : 
      65                 :             :   tree match_scrutinee_expr;
      66                 :             :   tree check_expr;
      67                 :             : };
      68                 :             : 
      69                 :        3325 : class CompilePatternBindings : public HIRCompileBase,
      70                 :             :                                public HIR::HIRPatternVisitor
      71                 :             : {
      72                 :             : public:
      73                 :        3325 :   static void Compile (HIR::Pattern &pattern, tree match_scrutinee_expr,
      74                 :             :                        Context *ctx)
      75                 :             :   {
      76                 :        3325 :     CompilePatternBindings compiler (ctx, match_scrutinee_expr);
      77                 :        3325 :     pattern.accept_vis (compiler);
      78                 :        3325 :   }
      79                 :             : 
      80                 :             :   tree make_struct_access (TyTy::ADTType *adt, TyTy::VariantDef *variant,
      81                 :             :                            const Identifier &ident, int variant_index);
      82                 :             : 
      83                 :             :   void handle_struct_pattern_ident (HIR::StructPatternField &pat,
      84                 :             :                                     TyTy::ADTType *adt,
      85                 :             :                                     TyTy::VariantDef *variant,
      86                 :             :                                     int variant_index);
      87                 :             :   void handle_struct_pattern_ident_pat (HIR::StructPatternField &pat,
      88                 :             :                                         TyTy::ADTType *adt,
      89                 :             :                                         TyTy::VariantDef *variant,
      90                 :             :                                         int variant_index);
      91                 :             :   void handle_struct_pattern_tuple_pat (HIR::StructPatternField &pat);
      92                 :             : 
      93                 :             :   void visit (HIR::StructPattern &pattern) override;
      94                 :             :   void visit (HIR::TupleStructPattern &pattern) override;
      95                 :             :   void visit (HIR::ReferencePattern &pattern) override;
      96                 :             :   void visit (HIR::IdentifierPattern &) override;
      97                 :             :   void visit (HIR::TuplePattern &pattern) override;
      98                 :             :   void visit (HIR::SlicePattern &) override;
      99                 :             : 
     100                 :             :   // Empty visit for unused Pattern HIR nodes.
     101                 :          43 :   void visit (HIR::AltPattern &) override {}
     102                 :         269 :   void visit (HIR::LiteralPattern &) override {}
     103                 :         675 :   void visit (HIR::PathInExpression &) override {}
     104                 :           0 :   void visit (HIR::QualifiedPathInExpression &) override {}
     105                 :          21 :   void visit (HIR::RangePattern &) override {}
     106                 :         415 :   void visit (HIR::WildcardPattern &) override {}
     107                 :             : 
     108                 :             : protected:
     109                 :        3325 :   CompilePatternBindings (Context *ctx, tree match_scrutinee_expr)
     110                 :        3325 :     : HIRCompileBase (ctx), match_scrutinee_expr (match_scrutinee_expr)
     111                 :             :   {}
     112                 :             : 
     113                 :             :   tree match_scrutinee_expr;
     114                 :             : };
     115                 :             : 
     116                 :       11331 : class CompilePatternLet : public HIRCompileBase, public HIR::HIRPatternVisitor
     117                 :             : {
     118                 :             : public:
     119                 :       11331 :   static void Compile (HIR::Pattern *pattern, tree init_expr,
     120                 :             :                        TyTy::BaseType *ty, location_t rval_locus, Context *ctx)
     121                 :             :   {
     122                 :       11331 :     CompilePatternLet compiler (ctx, init_expr, ty, rval_locus);
     123                 :       11331 :     pattern->accept_vis (compiler);
     124                 :       11331 :   }
     125                 :             : 
     126                 :             :   void visit (HIR::IdentifierPattern &) override;
     127                 :             :   void visit (HIR::WildcardPattern &) override;
     128                 :             :   void visit (HIR::TuplePattern &) override;
     129                 :             : 
     130                 :             :   // check for unimplemented Pattern HIR nodes.
     131                 :           0 :   void visit (HIR::AltPattern &pattern) override
     132                 :             :   {
     133                 :           0 :     rust_sorry_at (pattern.get_locus (),
     134                 :             :                    "alternate pattern let statements not supported");
     135                 :           0 :   }
     136                 :             : 
     137                 :           0 :   void visit (HIR::LiteralPattern &pattern) override
     138                 :             :   {
     139                 :           0 :     rust_sorry_at (pattern.get_locus (),
     140                 :             :                    "literal pattern let statements not supported");
     141                 :           0 :   }
     142                 :             : 
     143                 :           0 :   void visit (HIR::PathInExpression &pattern) override
     144                 :             :   {
     145                 :           0 :     rust_sorry_at (pattern.get_locus (),
     146                 :             :                    "path-in-expression pattern let statements not supported");
     147                 :           0 :   }
     148                 :             : 
     149                 :           0 :   void visit (HIR::QualifiedPathInExpression &pattern) override
     150                 :             :   {
     151                 :           0 :     rust_sorry_at (
     152                 :             :       pattern.get_locus (),
     153                 :             :       "qualified-path-in-expression pattern let statements not supported");
     154                 :           0 :   }
     155                 :             : 
     156                 :           0 :   void visit (HIR::RangePattern &pattern) override
     157                 :             :   {
     158                 :           0 :     rust_sorry_at (pattern.get_locus (),
     159                 :             :                    "range pattern let statements not supported");
     160                 :           0 :   }
     161                 :             : 
     162                 :           0 :   void visit (HIR::ReferencePattern &pattern) override
     163                 :             :   {
     164                 :           0 :     rust_sorry_at (pattern.get_locus (),
     165                 :             :                    "reference pattern let statements not supported");
     166                 :           0 :   }
     167                 :             : 
     168                 :           0 :   void visit (HIR::SlicePattern &pattern) override
     169                 :             :   {
     170                 :           0 :     rust_sorry_at (pattern.get_locus (),
     171                 :             :                    "slice pattern let statements not supported");
     172                 :           0 :   }
     173                 :             : 
     174                 :           0 :   void visit (HIR::StructPattern &pattern) override
     175                 :             :   {
     176                 :           0 :     rust_sorry_at (pattern.get_locus (),
     177                 :             :                    "struct pattern let statements not supported");
     178                 :           0 :   }
     179                 :             : 
     180                 :           0 :   void visit (HIR::TupleStructPattern &pattern) override
     181                 :             :   {
     182                 :           0 :     rust_sorry_at (pattern.get_locus (),
     183                 :             :                    "tuple-struct pattern let statements not supported");
     184                 :           0 :   }
     185                 :             : 
     186                 :             : protected:
     187                 :       11331 :   CompilePatternLet (Context *ctx, tree init_expr, TyTy::BaseType *ty,
     188                 :             :                      location_t rval_locus)
     189                 :       11331 :     : HIRCompileBase (ctx), init_expr (init_expr), ty (ty),
     190                 :       11331 :       rval_locus (rval_locus)
     191                 :             :   {}
     192                 :             : 
     193                 :             :   tree init_expr;
     194                 :             :   TyTy::BaseType *ty;
     195                 :             :   location_t rval_locus;
     196                 :             : };
     197                 :             : 
     198                 :             : } // namespace Compile
     199                 :             : } // namespace Rust
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.