Skip to content

Commit 0dbcc83

Browse files
PolygonalrCohenArthur
authored andcommitted
gccrs: Rename IdentifierPattern's to_bind to subpattern
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc: Rename to_bind to subpattern. * ast/rust-ast-visitor.cc: Ditto. * ast/rust-pattern.cc: Ditto. * ast/rust-pattern.h: Ditto. * backend/rust-compile-pattern.cc: Ditto. * expand/rust-cfg-strip.cc: Ditto. * hir/rust-ast-lower-pattern.cc: Ditto. * hir/rust-hir-dump.cc: Ditto. * hir/tree/rust-hir-pattern.h: Ditto. * hir/tree/rust-hir.cc: Ditto. * typecheck/rust-hir-type-check-pattern.cc: Ditto. Signed-off-by: Yap Zhi Heng <[email protected]>
1 parent 4e10607 commit 0dbcc83

11 files changed

+49
-46
lines changed

gcc/rust/ast/rust-ast-collector.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,7 @@ TokenCollector::visit (IdentifierPattern &pattern)
24822482
auto id = pattern.get_ident ().as_string ();
24832483
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
24842484

2485-
if (pattern.has_pattern_to_bind ())
2485+
if (pattern.has_subpattern ())
24862486
{
24872487
push (Rust::Token::make (PATTERN_BIND, UNDEF_LOCATION));
24882488
visit (pattern.get_pattern_to_bind ());

gcc/rust/ast/rust-ast-visitor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ DefaultASTVisitor::visit (AST::LiteralPattern &pattern)
11991199
void
12001200
DefaultASTVisitor::visit (AST::IdentifierPattern &pattern)
12011201
{
1202-
if (pattern.has_pattern_to_bind ())
1202+
if (pattern.has_subpattern ())
12031203
visit (pattern.get_pattern_to_bind ());
12041204
}
12051205

gcc/rust/ast/rust-pattern.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ IdentifierPattern::as_string () const
6565

6666
str += variable_ident.as_string ();
6767

68-
if (has_pattern_to_bind ())
69-
str += " @ " + to_bind->as_string ();
68+
if (has_subpattern ())
69+
str += " @ " + subpattern->as_string ();
7070

7171
return str;
7272
}

gcc/rust/ast/rust-pattern.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,30 @@ class IdentifierPattern : public Pattern
7474
bool is_mut;
7575

7676
// bool has_pattern;
77-
std::unique_ptr<Pattern> to_bind;
77+
std::unique_ptr<Pattern> subpattern;
7878
location_t locus;
7979
NodeId node_id;
8080

8181
public:
8282
std::string as_string () const override;
8383

8484
// Returns whether the IdentifierPattern has a pattern to bind.
85-
bool has_pattern_to_bind () const { return to_bind != nullptr; }
85+
bool has_subpattern () const { return subpattern != nullptr; }
8686

8787
// Constructor
8888
IdentifierPattern (Identifier ident, location_t locus, bool is_ref = false,
8989
bool is_mut = false,
90-
std::unique_ptr<Pattern> to_bind = nullptr)
90+
std::unique_ptr<Pattern> subpattern = nullptr)
9191
: Pattern (), variable_ident (std::move (ident)), is_ref (is_ref),
92-
is_mut (is_mut), to_bind (std::move (to_bind)), locus (locus),
92+
is_mut (is_mut), subpattern (std::move (subpattern)), locus (locus),
9393
node_id (Analysis::Mappings::get ().get_next_node_id ())
9494
{}
9595

9696
IdentifierPattern (NodeId node_id, Identifier ident, location_t locus,
9797
bool is_ref = false, bool is_mut = false,
98-
std::unique_ptr<Pattern> to_bind = nullptr)
98+
std::unique_ptr<Pattern> subpattern = nullptr)
9999
: Pattern (), variable_ident (std::move (ident)), is_ref (is_ref),
100-
is_mut (is_mut), to_bind (std::move (to_bind)), locus (locus),
100+
is_mut (is_mut), subpattern (std::move (subpattern)), locus (locus),
101101
node_id (node_id)
102102
{}
103103

@@ -107,8 +107,8 @@ class IdentifierPattern : public Pattern
107107
is_mut (other.is_mut), locus (other.locus), node_id (other.node_id)
108108
{
109109
// fix to get prevent null pointer dereference
110-
if (other.to_bind != nullptr)
111-
to_bind = other.to_bind->clone_pattern ();
110+
if (other.subpattern != nullptr)
111+
subpattern = other.subpattern->clone_pattern ();
112112
}
113113

114114
// Overload assignment operator to use clone
@@ -121,10 +121,10 @@ class IdentifierPattern : public Pattern
121121
node_id = other.node_id;
122122

123123
// fix to prevent null pointer dereference
124-
if (other.to_bind != nullptr)
125-
to_bind = other.to_bind->clone_pattern ();
124+
if (other.subpattern != nullptr)
125+
subpattern = other.subpattern->clone_pattern ();
126126
else
127-
to_bind = nullptr;
127+
subpattern = nullptr;
128128

129129
return *this;
130130
}
@@ -140,8 +140,8 @@ class IdentifierPattern : public Pattern
140140
// TODO: is this better? Or is a "vis_pattern" better?
141141
Pattern &get_pattern_to_bind ()
142142
{
143-
rust_assert (has_pattern_to_bind ());
144-
return *to_bind;
143+
rust_assert (has_subpattern ());
144+
return *subpattern;
145145
}
146146

147147
Identifier get_ident () const { return variable_ident; }

gcc/rust/backend/rust-compile-pattern.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,18 @@ CompilePatternCheckExpr::visit (HIR::TuplePattern &pattern)
434434
}
435435
}
436436

437-
void CompilePatternCheckExpr::visit (HIR::IdentifierPattern &pattern)
437+
void
438+
CompilePatternCheckExpr::visit (HIR::IdentifierPattern &pattern)
438439
{
439-
if (pattern.has_pattern_to_bind())
440-
{
441-
check_expr = CompilePatternCheckExpr::Compile (pattern.get_to_bind(), match_scrutinee_expr, ctx);
442-
} else
443-
{
444-
check_expr = boolean_true_node;
445-
}
440+
if (pattern.has_subpattern ())
441+
{
442+
check_expr = CompilePatternCheckExpr::Compile (pattern.get_subpattern (),
443+
match_scrutinee_expr, ctx);
444+
}
445+
else
446+
{
447+
check_expr = boolean_true_node;
448+
}
446449
}
447450

448451
// setup the bindings

gcc/rust/expand/rust-cfg-strip.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2262,7 +2262,7 @@ void
22622262
CfgStrip::visit (AST::IdentifierPattern &pattern)
22632263
{
22642264
// can only strip sub-patterns of the inner pattern to bind
2265-
if (!pattern.has_pattern_to_bind ())
2265+
if (!pattern.has_subpattern ())
22662266
return;
22672267

22682268
AST::DefaultASTVisitor::visit (pattern);

gcc/rust/hir/rust-ast-lower-pattern.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ ASTLoweringPattern::visit (AST::IdentifierPattern &pattern)
4949
mappings.get_next_hir_id (crate_num),
5050
UNKNOWN_LOCAL_DEFID);
5151

52-
std::unique_ptr<Pattern> to_bind;
53-
if (pattern.has_pattern_to_bind ())
52+
std::unique_ptr<Pattern> subpattern;
53+
if (pattern.has_subpattern ())
5454
{
55-
to_bind = std::unique_ptr<Pattern> (
55+
subpattern = std::unique_ptr<Pattern> (
5656
ASTLoweringPattern::translate (pattern.get_pattern_to_bind ()));
5757
}
5858
translated
5959
= new HIR::IdentifierPattern (mapping, pattern.get_ident (),
6060
pattern.get_locus (), pattern.get_is_ref (),
6161
pattern.get_is_mut () ? Mutability::Mut
6262
: Mutability::Imm,
63-
std::move (to_bind));
63+
std::move (subpattern));
6464
}
6565

6666
void

gcc/rust/hir/rust-hir-dump.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,10 +2115,10 @@ Dump::visit (IdentifierPattern &e)
21152115
put_field ("is_ref", std::to_string (e.get_is_ref ()));
21162116
put_field ("mut", std::to_string (e.is_mut ()));
21172117

2118-
if (e.has_pattern_to_bind ())
2119-
visit_field ("to_bind", e.get_to_bind ());
2118+
if (e.has_subpattern ())
2119+
visit_field ("subpattern", e.get_subpattern ());
21202120
else
2121-
put_field ("to_bind", "none");
2121+
put_field ("subpattern", "none");
21222122

21232123
end ("IdentifierPattern");
21242124
}

gcc/rust/hir/tree/rust-hir-pattern.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,23 @@ class IdentifierPattern : public Pattern
8080
Identifier variable_ident;
8181
bool is_ref;
8282
Mutability mut;
83-
std::unique_ptr<Pattern> to_bind;
83+
std::unique_ptr<Pattern> subpattern;
8484
location_t locus;
8585
Analysis::NodeMapping mappings;
8686

8787
public:
8888
std::string as_string () const override;
8989

9090
// Returns whether the IdentifierPattern has a pattern to bind.
91-
bool has_pattern_to_bind () const { return to_bind != nullptr; }
91+
bool has_subpattern () const { return subpattern != nullptr; }
9292

9393
// Constructor
9494
IdentifierPattern (Analysis::NodeMapping mappings, Identifier ident,
9595
location_t locus, bool is_ref = false,
9696
Mutability mut = Mutability::Imm,
97-
std::unique_ptr<Pattern> to_bind = nullptr)
97+
std::unique_ptr<Pattern> subpattern = nullptr)
9898
: variable_ident (std::move (ident)), is_ref (is_ref), mut (mut),
99-
to_bind (std::move (to_bind)), locus (locus), mappings (mappings)
99+
subpattern (std::move (subpattern)), locus (locus), mappings (mappings)
100100
{}
101101

102102
// Copy constructor with clone
@@ -105,8 +105,8 @@ class IdentifierPattern : public Pattern
105105
mut (other.mut), locus (other.locus), mappings (other.mappings)
106106
{
107107
// fix to get prevent null pointer dereference
108-
if (other.to_bind != nullptr)
109-
to_bind = other.to_bind->clone_pattern ();
108+
if (other.subpattern != nullptr)
109+
subpattern = other.subpattern->clone_pattern ();
110110
}
111111

112112
// Overload assignment operator to use clone
@@ -119,8 +119,8 @@ class IdentifierPattern : public Pattern
119119
mappings = other.mappings;
120120

121121
// fix to get prevent null pointer dereference
122-
if (other.to_bind != nullptr)
123-
to_bind = other.to_bind->clone_pattern ();
122+
if (other.subpattern != nullptr)
123+
subpattern = other.subpattern->clone_pattern ();
124124

125125
return *this;
126126
}
@@ -133,7 +133,7 @@ class IdentifierPattern : public Pattern
133133

134134
bool is_mut () const { return mut == Mutability::Mut; }
135135
bool get_is_ref () const { return is_ref; }
136-
Pattern &get_to_bind () { return *to_bind; }
136+
Pattern &get_subpattern () { return *subpattern; }
137137

138138
void accept_vis (HIRFullVisitor &vis) override;
139139
void accept_vis (HIRPatternVisitor &vis) override;

gcc/rust/hir/tree/rust-hir.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,9 +2608,9 @@ IdentifierPattern::as_string () const
26082608

26092609
str += variable_ident.as_string ();
26102610

2611-
if (has_pattern_to_bind ())
2611+
if (has_subpattern ())
26122612
{
2613-
str += " @ " + to_bind->as_string ();
2613+
str += " @ " + subpattern->as_string ();
26142614
}
26152615

26162616
return str;

gcc/rust/typecheck/rust-hir-type-check-pattern.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ TypeCheckPattern::visit (HIR::RangePattern &pattern)
546546
void
547547
TypeCheckPattern::visit (HIR::IdentifierPattern &pattern)
548548
{
549-
if (pattern.has_pattern_to_bind ())
549+
if (pattern.has_subpattern ())
550550
{
551-
TypeCheckPattern::Resolve (pattern.get_to_bind (), parent);
551+
TypeCheckPattern::Resolve (pattern.get_subpattern (), parent);
552552
}
553553

554554
if (!pattern.get_is_ref ())

0 commit comments

Comments
 (0)