mirror of
https://gcc.gnu.org/git/gcc.git
synced 2026-02-22 20:01:22 -05:00
gccrs: Implement lowering ReferencePattern from AST to HIR
gcc/rust/ChangeLog: * ast/rust-pattern.h: (ReferencePattern::is_double_reference): Add method. (ReferencePattern::get_is_mut): Add method. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Add ReferencePattern visitor. * hir/rust-ast-lower-pattern.h: (ASTLoweringPattern::visit): Add ReferencePattern visitor. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
This commit is contained in:
@@ -469,6 +469,10 @@ public:
|
||||
return pattern;
|
||||
}
|
||||
|
||||
bool is_double_reference () const { return has_two_amps; }
|
||||
|
||||
bool get_is_mut () const { return is_mut; }
|
||||
|
||||
NodeId get_node_id () const { return node_id; }
|
||||
|
||||
NodeId get_pattern_node_id () const override final { return node_id; }
|
||||
|
||||
@@ -249,5 +249,34 @@ ASTLoweringPattern::visit (AST::GroupedPattern &pattern)
|
||||
pattern.get_pattern_in_parens ()->accept_vis (*this);
|
||||
}
|
||||
|
||||
void
|
||||
ASTLoweringPattern::visit (AST::ReferencePattern &pattern)
|
||||
{
|
||||
auto crate_num = mappings->get_current_crate ();
|
||||
Analysis::NodeMapping mapping (crate_num, pattern.get_node_id (),
|
||||
mappings->get_next_hir_id (crate_num),
|
||||
UNKNOWN_LOCAL_DEFID);
|
||||
|
||||
HIR::Pattern *inner
|
||||
= ASTLoweringPattern::translate (pattern.get_referenced_pattern ().get ());
|
||||
|
||||
translated
|
||||
= new HIR::ReferencePattern (mapping, std::unique_ptr<HIR::Pattern> (inner),
|
||||
pattern.get_is_mut () ? Mutability::Mut
|
||||
: Mutability::Imm,
|
||||
pattern.get_locus ());
|
||||
|
||||
if (pattern.is_double_reference ())
|
||||
{
|
||||
Analysis::NodeMapping mapping2 (crate_num, pattern.get_node_id (),
|
||||
mappings->get_next_hir_id (crate_num),
|
||||
UNKNOWN_LOCAL_DEFID);
|
||||
translated
|
||||
= new HIR::ReferencePattern (mapping2,
|
||||
std::unique_ptr<HIR::Pattern> (translated),
|
||||
Mutability::Imm, pattern.get_locus ());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace HIR
|
||||
} // namespace Rust
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
void visit (AST::LiteralPattern &pattern) override;
|
||||
void visit (AST::RangePattern &pattern) override;
|
||||
void visit (AST::GroupedPattern &pattern) override;
|
||||
void visit (AST::ReferencePattern &pattern) override;
|
||||
|
||||
private:
|
||||
ASTLoweringPattern ();
|
||||
|
||||
Reference in New Issue
Block a user