(root)/
gcc-13.2.0/
gcc/
rust/
backend/
rust-compile-pattern.h
       1  // Copyright (C) 2020-2023 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  
      21  namespace Rust {
      22  namespace Compile {
      23  
      24  class CompilePatternCaseLabelExpr : public HIRCompileBase,
      25  				    public HIR::HIRPatternVisitor
      26  {
      27  public:
      28    static tree Compile (HIR::Pattern *pattern, tree associated_case_label,
      29  		       Context *ctx)
      30    {
      31      CompilePatternCaseLabelExpr compiler (ctx, associated_case_label);
      32      pattern->accept_vis (compiler);
      33      return compiler.case_label_expr;
      34    }
      35  
      36    void visit (HIR::PathInExpression &pattern) override;
      37    void visit (HIR::StructPattern &pattern) override;
      38    void visit (HIR::TupleStructPattern &pattern) override;
      39    void visit (HIR::WildcardPattern &pattern) override;
      40    void visit (HIR::RangePattern &pattern) override;
      41  
      42    // Empty visit for unused Pattern HIR nodes.
      43    void visit (HIR::IdentifierPattern &) override {}
      44    void visit (HIR::LiteralPattern &) override;
      45    void visit (HIR::QualifiedPathInExpression &) override {}
      46    void visit (HIR::ReferencePattern &) override {}
      47    void visit (HIR::SlicePattern &) override {}
      48    void visit (HIR::TuplePattern &) override {}
      49  
      50    CompilePatternCaseLabelExpr (Context *ctx, tree associated_case_label)
      51      : HIRCompileBase (ctx), case_label_expr (error_mark_node),
      52        associated_case_label (associated_case_label)
      53    {}
      54  
      55    tree case_label_expr;
      56    tree associated_case_label;
      57  };
      58  
      59  class CompilePatternBindings : public HIRCompileBase,
      60  			       public HIR::HIRPatternVisitor
      61  {
      62  public:
      63    static void Compile (HIR::Pattern *pattern, tree match_scrutinee_expr,
      64  		       Context *ctx)
      65    {
      66      CompilePatternBindings compiler (ctx, match_scrutinee_expr);
      67      pattern->accept_vis (compiler);
      68    }
      69  
      70    void visit (HIR::StructPattern &pattern) override;
      71    void visit (HIR::TupleStructPattern &pattern) override;
      72  
      73    // Empty visit for unused Pattern HIR nodes.
      74    void visit (HIR::IdentifierPattern &) override {}
      75    void visit (HIR::LiteralPattern &) override {}
      76    void visit (HIR::PathInExpression &) override {}
      77    void visit (HIR::QualifiedPathInExpression &) override {}
      78    void visit (HIR::RangePattern &) override {}
      79    void visit (HIR::ReferencePattern &) override {}
      80    void visit (HIR::SlicePattern &) override {}
      81    void visit (HIR::TuplePattern &) override {}
      82    void visit (HIR::WildcardPattern &) override {}
      83  
      84  protected:
      85    CompilePatternBindings (Context *ctx, tree match_scrutinee_expr)
      86      : HIRCompileBase (ctx), match_scrutinee_expr (match_scrutinee_expr)
      87    {}
      88  
      89    tree match_scrutinee_expr;
      90  };
      91  
      92  class CompilePatternLet : public HIRCompileBase, public HIR::HIRPatternVisitor
      93  {
      94  public:
      95    static void Compile (HIR::Pattern *pattern, tree init_expr,
      96  		       TyTy::BaseType *ty, Location rval_locus, Context *ctx)
      97    {
      98      CompilePatternLet compiler (ctx, init_expr, ty, rval_locus);
      99      pattern->accept_vis (compiler);
     100    }
     101  
     102    void visit (HIR::IdentifierPattern &) override;
     103    void visit (HIR::WildcardPattern &) override;
     104    void visit (HIR::TuplePattern &) override;
     105  
     106    // check for unimplemented Pattern HIR nodes.
     107    void visit (HIR::LiteralPattern &pattern) override
     108    {
     109      rust_sorry_at (pattern.get_locus (),
     110  		   "literal pattern let statements not supported");
     111    }
     112  
     113    void visit (HIR::PathInExpression &pattern) override
     114    {
     115      rust_sorry_at (pattern.get_locus (),
     116  		   "path-in-expression pattern let statements not supported");
     117    }
     118  
     119    void visit (HIR::QualifiedPathInExpression &pattern) override
     120    {
     121      rust_sorry_at (
     122        pattern.get_locus (),
     123        "qualified-path-in-expression pattern let statements not supported");
     124    }
     125  
     126    void visit (HIR::RangePattern &pattern) override
     127    {
     128      rust_sorry_at (pattern.get_locus (),
     129  		   "range pattern let statements not supported");
     130    }
     131  
     132    void visit (HIR::ReferencePattern &pattern) override
     133    {
     134      rust_sorry_at (pattern.get_locus (),
     135  		   "reference pattern let statements not supported");
     136    }
     137  
     138    void visit (HIR::SlicePattern &pattern) override
     139    {
     140      rust_sorry_at (pattern.get_locus (),
     141  		   "slice pattern let statements not supported");
     142    }
     143  
     144    void visit (HIR::StructPattern &pattern) override
     145    {
     146      rust_sorry_at (pattern.get_locus (),
     147  		   "struct pattern let statements not supported");
     148    }
     149  
     150    void visit (HIR::TupleStructPattern &pattern) override
     151    {
     152      rust_sorry_at (pattern.get_locus (),
     153  		   "tuple-struct pattern let statements not supported");
     154    }
     155  
     156  protected:
     157    CompilePatternLet (Context *ctx, tree init_expr, TyTy::BaseType *ty,
     158  		     Location rval_locus)
     159      : HIRCompileBase (ctx), init_expr (init_expr), ty (ty),
     160        rval_locus (rval_locus)
     161    {}
     162  
     163    tree init_expr;
     164    TyTy::BaseType *ty;
     165    Location rval_locus;
     166  };
     167  
     168  } // namespace Compile
     169  } // namespace Rust