Skip to content

Commit ded7e5a

Browse files
committed
Add binding layer for nested bindings.
gcc/rust/ChangeLog: * resolve/rust-name-resolution-context.h (class BindingContext): Use BindingLayer instead. (class BindingLayer): Add new class to group bindings from the same top level binding pattern. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
1 parent d12bf05 commit ded7e5a

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

gcc/rust/resolve/rust-name-resolution-context.h

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,10 @@ enum class BindingSource
177177
Param
178178
};
179179

180-
class BindingContext
180+
class BindingLayer
181181
{
182-
// FIXME: Use std::vector<std::vector<Binding>> to handle nested patterns
183-
std::vector<Binding> bindings;
184-
185182
BindingSource source;
183+
std::vector<Binding> bindings;
186184

187185
bool bind_test (Identifier ident, Binding::Kind kind)
188186
{
@@ -197,6 +195,12 @@ class BindingContext
197195
}
198196

199197
public:
198+
void push (Binding::Kind kind) { bindings.push_back (Binding (kind)); }
199+
200+
BindingLayer (BindingSource source) : source (source)
201+
{
202+
push (Binding::Kind::Product);
203+
}
200204
bool and_binded (Identifier ident)
201205
{
202206
return bind_test (ident, Binding::Kind::Product);
@@ -209,21 +213,6 @@ class BindingContext
209213

210214
void insert_ident (Identifier ident) { bindings.back ().set.insert (ident); }
211215

212-
void push (Binding::Kind kind) { bindings.push_back (Binding (kind)); }
213-
214-
void new_binding (BindingSource source)
215-
{
216-
rust_assert (bindings.size () == 0);
217-
this->source = source;
218-
push (Binding::Kind::Product);
219-
}
220-
221-
void clear ()
222-
{
223-
rust_assert (bindings.size () == 1);
224-
bindings.clear ();
225-
}
226-
227216
void merge ()
228217
{
229218
auto last_binding = bindings.back ();
@@ -237,6 +226,37 @@ class BindingContext
237226
BindingSource get_source () const { return source; }
238227
};
239228

229+
class BindingContext
230+
{
231+
std::vector<BindingLayer> bindings;
232+
233+
public:
234+
bool and_binded (Identifier ident)
235+
{
236+
return bindings.back ().and_binded (ident);
237+
}
238+
239+
bool or_binded (Identifier ident)
240+
{
241+
return bindings.back ().or_binded (ident);
242+
}
243+
244+
void merge () { bindings.back ().merge (); }
245+
246+
void push (Binding::Kind kind) { bindings.back ().push (kind); }
247+
248+
void insert_ident (Identifier ident)
249+
{
250+
bindings.back ().insert_ident (ident);
251+
}
252+
253+
void new_binding (BindingSource source) { bindings.emplace_back (source); }
254+
255+
void clear () { bindings.pop_back (); }
256+
257+
BindingSource get_source () const { return bindings.back ().get_source (); }
258+
};
259+
240260
// Now our resolver, which keeps track of all the `ForeverStack`s we could want
241261
class NameResolutionContext
242262
{

0 commit comments

Comments
 (0)