@@ -177,6 +177,8 @@ class WhereClauseItem
177
177
178
178
virtual void accept_vis (ASTVisitor &vis) = 0;
179
179
180
+ virtual NodeId get_node_id () const = 0;
181
+
180
182
protected:
181
183
// Clone function implementation as pure virtual method
182
184
virtual WhereClauseItem *clone_where_clause_item_impl () const = 0;
@@ -186,24 +188,31 @@ class WhereClauseItem
186
188
class LifetimeWhereClauseItem : public WhereClauseItem
187
189
{
188
190
Lifetime lifetime;
189
-
190
- // LifetimeBounds lifetime_bounds;
191
- std::vector<Lifetime> lifetime_bounds; // inlined lifetime bounds
192
-
191
+ std::vector<Lifetime> lifetime_bounds;
193
192
Location locus;
193
+ NodeId node_id;
194
194
195
195
public:
196
196
LifetimeWhereClauseItem (Lifetime lifetime,
197
197
std::vector<Lifetime> lifetime_bounds,
198
198
Location locus)
199
199
: lifetime (std::move (lifetime)),
200
- lifetime_bounds (std::move (lifetime_bounds)), locus (locus)
200
+ lifetime_bounds (std::move (lifetime_bounds)), locus (locus),
201
+ node_id (Analysis::Mappings::get ()->get_next_node_id ())
201
202
{}
202
203
203
204
std::string as_string () const override ;
204
205
205
206
void accept_vis (ASTVisitor &vis) override ;
206
207
208
+ NodeId get_node_id () const override final { return node_id; }
209
+
210
+ Lifetime &get_lifetime () { return lifetime; }
211
+
212
+ std::vector<Lifetime> &get_lifetime_bounds () { return lifetime_bounds; }
213
+
214
+ Location get_locus () const { return locus; }
215
+
207
216
protected:
208
217
// Clone function implementation as (not pure) virtual method
209
218
LifetimeWhereClauseItem *clone_where_clause_item_impl () const override
@@ -215,18 +224,10 @@ class LifetimeWhereClauseItem : public WhereClauseItem
215
224
// A type bound where clause item
216
225
class TypeBoundWhereClauseItem : public WhereClauseItem
217
226
{
218
- // bool has_for_lifetimes;
219
- // LifetimeParams for_lifetimes;
220
- std::vector<LifetimeParam> for_lifetimes; // inlined
221
-
227
+ std::vector<LifetimeParam> for_lifetimes;
222
228
std::unique_ptr<Type> bound_type;
223
-
224
- // bool has_type_param_bounds;
225
- // TypeParamBounds type_param_bounds;
226
- std::vector<std::unique_ptr<TypeParamBound>>
227
- type_param_bounds; // inlined form
228
-
229
- // should this store location info?
229
+ std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds;
230
+ NodeId node_id;
230
231
231
232
public:
232
233
// Returns whether the item has ForLifetimes
@@ -240,14 +241,16 @@ class TypeBoundWhereClauseItem : public WhereClauseItem
240
241
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds)
241
242
: for_lifetimes (std::move (for_lifetimes)),
242
243
bound_type (std::move (bound_type)),
243
- type_param_bounds (std::move (type_param_bounds))
244
+ type_param_bounds (std::move (type_param_bounds)),
245
+ node_id (Analysis::Mappings::get ()->get_next_node_id ())
244
246
{}
245
247
246
248
// Copy constructor requires clone
247
249
TypeBoundWhereClauseItem (TypeBoundWhereClauseItem const &other)
248
250
: for_lifetimes (other.for_lifetimes),
249
251
bound_type (other.bound_type->clone_type ())
250
252
{
253
+ node_id = other.node_id ;
251
254
type_param_bounds.reserve (other.type_param_bounds .size ());
252
255
for (const auto &e : other.type_param_bounds )
253
256
type_param_bounds.push_back (e->clone_type_param_bound ());
@@ -256,9 +259,9 @@ class TypeBoundWhereClauseItem : public WhereClauseItem
256
259
// Overload assignment operator to clone
257
260
TypeBoundWhereClauseItem &operator = (TypeBoundWhereClauseItem const &other)
258
261
{
262
+ node_id = other.node_id ;
259
263
for_lifetimes = other.for_lifetimes ;
260
264
bound_type = other.bound_type ->clone_type ();
261
-
262
265
type_param_bounds.reserve (other.type_param_bounds .size ());
263
266
for (const auto &e : other.type_param_bounds )
264
267
type_param_bounds.push_back (e->clone_type_param_bound ());
@@ -275,7 +278,6 @@ class TypeBoundWhereClauseItem : public WhereClauseItem
275
278
276
279
void accept_vis (ASTVisitor &vis) override ;
277
280
278
- // TODO: is this better? Or is a "vis_block" better?
279
281
std::unique_ptr<Type> &get_type ()
280
282
{
281
283
rust_assert (bound_type != nullptr );
@@ -287,12 +289,15 @@ class TypeBoundWhereClauseItem : public WhereClauseItem
287
289
{
288
290
return type_param_bounds;
289
291
}
292
+
290
293
const std::vector<std::unique_ptr<TypeParamBound>> &
291
294
get_type_param_bounds () const
292
295
{
293
296
return type_param_bounds;
294
297
}
295
298
299
+ NodeId get_node_id () const override final { return node_id; }
300
+
296
301
protected:
297
302
// Clone function implementation as (not pure) virtual method
298
303
TypeBoundWhereClauseItem *clone_where_clause_item_impl () const override
@@ -306,17 +311,18 @@ struct WhereClause
306
311
{
307
312
private:
308
313
std::vector<std::unique_ptr<WhereClauseItem>> where_clause_items;
309
-
310
- // should this store location info?
314
+ NodeId node_id;
311
315
312
316
public:
313
317
WhereClause (std::vector<std::unique_ptr<WhereClauseItem>> where_clause_items)
314
- : where_clause_items (std::move (where_clause_items))
318
+ : where_clause_items (std::move (where_clause_items)),
319
+ node_id (Analysis::Mappings::get ()->get_next_node_id ())
315
320
{}
316
321
317
322
// copy constructor with vector clone
318
323
WhereClause (WhereClause const &other)
319
324
{
325
+ node_id = other.node_id ;
320
326
where_clause_items.reserve (other.where_clause_items .size ());
321
327
for (const auto &e : other.where_clause_items )
322
328
where_clause_items.push_back (e->clone_where_clause_item ());
@@ -325,6 +331,7 @@ struct WhereClause
325
331
// overloaded assignment operator with vector clone
326
332
WhereClause &operator = (WhereClause const &other)
327
333
{
334
+ node_id = other.node_id ;
328
335
where_clause_items.reserve (other.where_clause_items .size ());
329
336
for (const auto &e : other.where_clause_items )
330
337
where_clause_items.push_back (e->clone_where_clause_item ());
@@ -347,6 +354,8 @@ struct WhereClause
347
354
348
355
std::string as_string () const ;
349
356
357
+ NodeId get_node_id () const { return node_id; }
358
+
350
359
// TODO: this mutable getter seems kinda dodgy
351
360
std::vector<std::unique_ptr<WhereClauseItem>> &get_items ()
352
361
{
@@ -878,11 +887,7 @@ class Method : public InherentImplItem, public TraitImplItem
878
887
}
879
888
880
889
// TODO: is this better? Or is a "vis_block" better?
881
- WhereClause &get_where_clause ()
882
- {
883
- rust_assert (has_where_clause ());
884
- return where_clause;
885
- }
890
+ WhereClause &get_where_clause () { return where_clause; }
886
891
887
892
Identifier get_method_name () const { return method_name; }
888
893
@@ -1578,11 +1583,7 @@ class Function : public VisItem, public InherentImplItem, public TraitImplItem
1578
1583
Identifier get_function_name () const { return function_name; }
1579
1584
1580
1585
// TODO: is this better? Or is a "vis_block" better?
1581
- WhereClause &get_where_clause ()
1582
- {
1583
- rust_assert (has_where_clause ());
1584
- return where_clause;
1585
- }
1586
+ WhereClause &get_where_clause () { return where_clause; }
1586
1587
1587
1588
// TODO: is this better? Or is a "vis_block" better?
1588
1589
std::unique_ptr<Type> &get_return_type ()
@@ -1710,11 +1711,7 @@ class TypeAlias : public VisItem, public TraitImplItem
1710
1711
}
1711
1712
1712
1713
// TODO: is this better? Or is a "vis_block" better?
1713
- WhereClause &get_where_clause ()
1714
- {
1715
- rust_assert (has_where_clause ());
1716
- return where_clause;
1717
- }
1714
+ WhereClause &get_where_clause () { return where_clause; }
1718
1715
1719
1716
// TODO: is this better? Or is a "vis_block" better?
1720
1717
std::unique_ptr<Type> &get_type_aliased ()
@@ -1780,11 +1777,7 @@ class Struct : public VisItem
1780
1777
}
1781
1778
1782
1779
// TODO: is this better? Or is a "vis_block" better?
1783
- WhereClause &get_where_clause ()
1784
- {
1785
- rust_assert (has_where_clause ());
1786
- return where_clause;
1787
- }
1780
+ WhereClause &get_where_clause () { return where_clause; }
1788
1781
1789
1782
Identifier get_identifier () const { return struct_name; }
1790
1783
@@ -2401,11 +2394,7 @@ class Enum : public VisItem
2401
2394
}
2402
2395
2403
2396
// TODO: is this better? Or is a "vis_block" better?
2404
- WhereClause &get_where_clause ()
2405
- {
2406
- rust_assert (has_where_clause ());
2407
- return where_clause;
2408
- }
2397
+ WhereClause &get_where_clause () { return where_clause; }
2409
2398
2410
2399
protected:
2411
2400
/* Use covariance to implement clone function as returning this object
@@ -2511,11 +2500,7 @@ class Union : public VisItem
2511
2500
}
2512
2501
2513
2502
// TODO: is this better? Or is a "vis_block" better?
2514
- WhereClause &get_where_clause ()
2515
- {
2516
- rust_assert (has_where_clause ());
2517
- return where_clause;
2518
- }
2503
+ WhereClause &get_where_clause () { return where_clause; }
2519
2504
2520
2505
Identifier get_identifier () const { return union_name; }
2521
2506
@@ -2868,11 +2853,7 @@ struct TraitFunctionDecl
2868
2853
}
2869
2854
2870
2855
// TODO: is this better? Or is a "vis_block" better?
2871
- WhereClause &get_where_clause ()
2872
- {
2873
- rust_assert (has_where_clause ());
2874
- return where_clause;
2875
- }
2856
+ WhereClause &get_where_clause () { return where_clause; }
2876
2857
};
2877
2858
2878
2859
// Actual trait item function declaration within traits
@@ -3095,11 +3076,7 @@ struct TraitMethodDecl
3095
3076
}
3096
3077
3097
3078
// TODO: is this better? Or is a "vis_block" better?
3098
- WhereClause &get_where_clause ()
3099
- {
3100
- rust_assert (has_where_clause ());
3101
- return where_clause;
3102
- }
3079
+ WhereClause &get_where_clause () { return where_clause; }
3103
3080
3104
3081
SelfParam &get_self_param () { return self_param; }
3105
3082
const SelfParam &get_self_param () const { return self_param; }
@@ -3533,11 +3510,7 @@ class Trait : public VisItem
3533
3510
return type_param_bounds;
3534
3511
}
3535
3512
3536
- WhereClause &get_where_clause ()
3537
- {
3538
- rust_assert (has_where_clause ());
3539
- return where_clause;
3540
- }
3513
+ WhereClause &get_where_clause () { return where_clause; }
3541
3514
3542
3515
void insert_implict_self (std::unique_ptr<AST::GenericParam> &¶m)
3543
3516
{
@@ -3610,11 +3583,7 @@ class Impl : public VisItem
3610
3583
}
3611
3584
3612
3585
// TODO: is this better? Or is a "vis_block" better?
3613
- WhereClause &get_where_clause ()
3614
- {
3615
- rust_assert (has_where_clause ());
3616
- return where_clause;
3617
- }
3586
+ WhereClause &get_where_clause () { return where_clause; }
3618
3587
3619
3588
// TODO: is this better? Or is a "vis_block" better?
3620
3589
std::unique_ptr<Type> &get_type ()
@@ -4261,11 +4230,7 @@ class ExternalFunctionItem : public ExternalItem
4261
4230
}
4262
4231
4263
4232
// TODO: is this better? Or is a "vis_block" better?
4264
- WhereClause &get_where_clause ()
4265
- {
4266
- rust_assert (has_where_clause ());
4267
- return where_clause;
4268
- }
4233
+ WhereClause &get_where_clause () { return where_clause; }
4269
4234
4270
4235
// TODO: is this better? Or is a "vis_block" better?
4271
4236
std::unique_ptr<Type> &get_return_type ()
0 commit comments