1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 // This file is part of GCC.
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
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
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/>.
19 #ifndef RUST_COMPILE_VAR_DECL
20 #define RUST_COMPILE_VAR_DECL
22 #include "rust-compile-base.h"
23 #include "rust-hir-visitor.h"
28 class CompileVarDecl
: public HIRCompileBase
, public HIR::HIRPatternVisitor
30 using HIR::HIRPatternVisitor::visit
;
33 static void compile (tree fndecl
, tree translated_type
, HIR::Pattern
*pattern
,
34 std::vector
<Bvariable
*> &locals
, Context
*ctx
)
36 CompileVarDecl
compiler (ctx
, fndecl
, translated_type
, locals
);
37 pattern
->accept_vis (compiler
);
40 void visit (HIR::IdentifierPattern
&pattern
) override
42 if (!pattern
.is_mut ())
43 translated_type
= ctx
->get_backend ()->immutable_type (translated_type
);
46 = ctx
->get_backend ()->local_variable (fndecl
, pattern
.get_identifier (),
47 translated_type
, NULL
/*decl_var*/,
48 pattern
.get_locus ());
50 HirId stmt_id
= pattern
.get_pattern_mappings ().get_hirid ();
51 ctx
->insert_var_decl (stmt_id
, var
);
53 locals
.push_back (var
);
56 // Empty visit for unused Pattern HIR nodes.
57 void visit (HIR::LiteralPattern
&) override
{}
58 void visit (HIR::PathInExpression
&) override
{}
59 void visit (HIR::QualifiedPathInExpression
&) override
{}
60 void visit (HIR::RangePattern
&) override
{}
61 void visit (HIR::ReferencePattern
&) override
{}
62 void visit (HIR::SlicePattern
&) override
{}
63 void visit (HIR::StructPattern
&) override
{}
64 void visit (HIR::TuplePattern
&) override
{}
65 void visit (HIR::TupleStructPattern
&) override
{}
66 void visit (HIR::WildcardPattern
&) override
{}
69 CompileVarDecl (Context
*ctx
, tree fndecl
, tree translated_type
,
70 std::vector
<Bvariable
*> &locals
)
71 : HIRCompileBase (ctx
), fndecl (fndecl
), translated_type (translated_type
),
78 std::vector
<Bvariable
*> &locals
;
81 } // namespace Compile
84 #endif // RUST_COMPILE_VAR_DECL