blob: 10f4fd8a61bfca6be07f54e0cc26d75f6b28147b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
// Copyright (C) 2020-2023 Free Software Foundation, Inc.
// This file is part of GCC.
// GCC is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3, or (at your option) any later
// version.
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
// You should have received a copy of the GNU General Public License
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include "rust-ast-resolve-pattern.h"
#include "rust-ast-resolve-path.h"
#include "rust-ast-resolve-expr.h"
namespace Rust {
namespace Resolver {
void
PatternDeclaration::visit (AST::PathInExpression &pattern)
{
ResolvePath::go (&pattern);
}
void
PatternDeclaration::visit (AST::TupleStructPattern &pattern)
{
ResolvePath::go (&pattern.get_path ());
std::unique_ptr<AST::TupleStructItems> &items = pattern.get_items ();
switch (items->get_item_type ())
{
case AST::TupleStructItems::RANGE: {
// TODO
gcc_unreachable ();
}
break;
case AST::TupleStructItems::NO_RANGE: {
AST::TupleStructItemsNoRange &items_no_range
= static_cast<AST::TupleStructItemsNoRange &> (*items.get ());
for (auto &inner_pattern : items_no_range.get_patterns ())
{
PatternDeclaration::go (inner_pattern.get (), type);
}
}
break;
}
}
void
PatternDeclaration::visit (AST::StructPattern &pattern)
{
ResolvePath::go (&pattern.get_path ());
auto &struct_pattern_elems = pattern.get_struct_pattern_elems ();
for (auto &field : struct_pattern_elems.get_struct_pattern_fields ())
{
switch (field->get_item_type ())
{
case AST::StructPatternField::ItemType::TUPLE_PAT: {
// TODO
gcc_unreachable ();
}
break;
case AST::StructPatternField::ItemType::IDENT_PAT: {
// TODO
gcc_unreachable ();
}
break;
case AST::StructPatternField::ItemType::IDENT: {
AST::StructPatternFieldIdent &ident
= static_cast<AST::StructPatternFieldIdent &> (*field.get ());
resolver->get_name_scope ().insert (
CanonicalPath::new_seg (ident.get_node_id (),
ident.get_identifier ()),
ident.get_node_id (), ident.get_locus ());
}
break;
}
}
// TODO
rust_assert (!struct_pattern_elems.has_etc ());
}
void
PatternDeclaration::visit (AST::TuplePattern &pattern)
{
std::unique_ptr<AST::TuplePatternItems> &items = pattern.get_items ();
switch (items->get_pattern_type ())
{
case AST::TuplePatternItems::TuplePatternItemType::MULTIPLE: {
AST::TuplePatternItemsMultiple &ref
= *static_cast<AST::TuplePatternItemsMultiple *> (
pattern.get_items ().get ());
for (auto &p : ref.get_patterns ())
p->accept_vis (*this);
}
break;
case AST::TuplePatternItems::TuplePatternItemType::RANGED: {
AST::TuplePatternItemsRanged &ref
= *static_cast<AST::TuplePatternItemsRanged *> (
pattern.get_items ().get ());
for (auto &p : ref.get_lower_patterns ())
p->accept_vis (*this);
for (auto &p : ref.get_upper_patterns ())
p->accept_vis (*this);
}
break;
}
}
static void
resolve_range_pattern_bound (AST::RangePatternBound *bound)
{
switch (bound->get_bound_type ())
{
case AST::RangePatternBound::RangePatternBoundType::LITERAL:
// Nothing to resolve for a literal.
break;
case AST::RangePatternBound::RangePatternBoundType::PATH: {
AST::RangePatternBoundPath &ref
= *static_cast<AST::RangePatternBoundPath *> (bound);
ResolvePath::go (&ref.get_path ());
}
break;
case AST::RangePatternBound::RangePatternBoundType::QUALPATH: {
AST::RangePatternBoundQualPath &ref
= *static_cast<AST::RangePatternBoundQualPath *> (bound);
ResolvePath::go (&ref.get_qualified_path ());
}
break;
}
}
void
PatternDeclaration::visit (AST::RangePattern &pattern)
{
resolve_range_pattern_bound (pattern.get_upper_bound ().get ());
resolve_range_pattern_bound (pattern.get_lower_bound ().get ());
}
} // namespace Resolver
} // namespace Rust
|