LCOV - code coverage report
Current view: top level - gcc/rust/backend - rust-compile-pattern.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 54.4 % 68 37
Test Date: 2024-04-13 14:00:49 Functions: 45.8 % 24 11
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

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