@@ -599,9 +599,6 @@ class Path : public Pattern
599
599
return Pattern::Kind::Path;
600
600
}
601
601
602
- location_t get_locus () const override { return locus; }
603
- NodeId get_node_id () const override { return node_id; }
604
-
605
602
std::unique_ptr<Path> clone_path ()
606
603
{
607
604
return std::unique_ptr<Path> (clone_path_impl ());
@@ -613,22 +610,19 @@ class Path : public Pattern
613
610
}
614
611
615
612
protected:
616
- location_t locus;
617
- NodeId node_id;
618
-
619
- Path (location_t locus, NodeId node_id) : locus (locus), node_id (node_id) {}
620
-
621
613
virtual Path *clone_path_impl () const = 0;
622
614
};
623
615
624
616
class RegularPath : public Path
625
617
{
626
618
std::vector<PathExprSegment> segments;
619
+ NodeId node_id;
620
+ location_t locus;
627
621
628
622
public:
629
623
explicit RegularPath (std::vector<PathExprSegment> &&segments,
630
624
location_t locus, NodeId node_id)
631
- : Path (locus, node_id), segments (std::move (segments))
625
+ : segments (std::move (segments)), node_id (node_id), locus (locus )
632
626
{}
633
627
634
628
std::string as_string () const override ;
@@ -657,17 +651,25 @@ class RegularPath : public Path
657
651
return new RegularPath (std::vector<PathExprSegment> (segments), locus,
658
652
node_id);
659
653
}
654
+
655
+ NodeId get_node_id () const override { return node_id; }
656
+ location_t get_locus () const override { return locus; }
660
657
};
661
658
662
659
class LangItemPath : public Path
663
660
{
664
- NodeId lang_item;
665
-
666
661
LangItem::Kind kind;
662
+ NodeId node_id;
663
+ location_t locus;
664
+
665
+ LangItemPath (LangItem::Kind kind, NodeId node_id, location_t locus)
666
+ : kind (kind), node_id (node_id), locus (locus)
667
+ {}
667
668
668
669
public:
669
670
explicit LangItemPath (LangItem::Kind kind, location_t locus)
670
- : Path (locus, Analysis::Mappings::get ().get_next_node_id ()), kind (kind)
671
+ : kind (kind), node_id (Analysis::Mappings::get ().get_next_node_id ()),
672
+ locus (locus)
671
673
{}
672
674
673
675
Path::Kind get_path_kind () const override { return Path::Kind::LangItem; }
@@ -676,12 +678,15 @@ class LangItemPath : public Path
676
678
677
679
Path *clone_path_impl () const override
678
680
{
679
- return new LangItemPath (kind, locus);
681
+ return new LangItemPath (kind, node_id, locus);
680
682
}
681
683
682
684
std::string as_string () const override ;
683
685
684
686
LangItem::Kind get_lang_item_kind () { return kind; }
687
+
688
+ NodeId get_node_id () const override { return node_id; }
689
+ location_t get_locus () const override { return locus; }
685
690
};
686
691
687
692
/* AST node representing a path-in-expression pattern (path that allows
@@ -739,11 +744,10 @@ class PathInExpression : public Pattern, public ExprWithoutBlock
739
744
// Returns whether path in expression is in an error state.
740
745
bool is_error () const
741
746
{
742
- // FIXME: Cleanup
743
747
if (path->get_path_kind () == Path::Kind::Regular)
744
748
return !static_cast <RegularPath &> (*path).has_segments ();
745
749
746
- return false ;
750
+ rust_unreachable () ;
747
751
}
748
752
749
753
/* Converts PathInExpression to SimplePath if possible (i.e. no generic
@@ -822,7 +826,7 @@ class PathInExpression : public Pattern, public ExprWithoutBlock
822
826
if (path->get_path_kind () == Path::Kind::Regular)
823
827
return static_cast <RegularPath &> (*path).get_segments ().size () == 1 ;
824
828
825
- return false ;
829
+ rust_unreachable () ;
826
830
}
827
831
828
832
Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Path; }
@@ -1201,17 +1205,13 @@ class TypePathSegmentFunction : public TypePathSegment
1201
1205
}
1202
1206
};
1203
1207
1204
- // Path used inside types
1205
1208
class TypePath : public TypeNoBounds , public Path
1206
1209
{
1207
1210
bool has_opening_scope_resolution;
1208
1211
std::vector<std::unique_ptr<TypePathSegment> > segments;
1212
+ location_t locus;
1209
1213
1210
1214
protected:
1211
- Kind get_path_kind () const override { return Kind::Type; }
1212
-
1213
- Path *clone_path_impl () const override { return new TypePath (*this ); }
1214
-
1215
1215
/* Use covariance to implement clone function as returning this object
1216
1216
* rather than base */
1217
1217
TypePath *clone_type_no_bounds_impl () const override
@@ -1234,23 +1234,23 @@ class TypePath : public TypeNoBounds, public Path
1234
1234
static TypePath create_error ()
1235
1235
{
1236
1236
return TypePath (std::vector<std::unique_ptr<TypePathSegment> > (),
1237
- UNKNOWN_LOCATION );
1237
+ UNDEF_LOCATION );
1238
1238
}
1239
1239
1240
1240
// Constructor
1241
1241
TypePath (std::vector<std::unique_ptr<TypePathSegment> > segments,
1242
1242
location_t locus, bool has_opening_scope_resolution = false )
1243
1243
: TypeNoBounds (),
1244
- Path (locus, Analysis::Mappings::get ().get_next_node_id ()),
1245
1244
has_opening_scope_resolution (has_opening_scope_resolution),
1246
- segments (std::move (segments))
1245
+ segments (std::move (segments)), locus (locus)
1247
1246
{}
1248
1247
1249
1248
// Copy constructor with vector clone
1250
1249
TypePath (TypePath const &other)
1251
- : Path (other.locus, other.Path::get_node_id () ),
1252
- has_opening_scope_resolution (other.has_opening_scope_resolution )
1250
+ : has_opening_scope_resolution (other.has_opening_scope_resolution ),
1251
+ locus (other.locus )
1253
1252
{
1253
+ node_id = other.node_id ;
1254
1254
segments.reserve (other.segments .size ());
1255
1255
for (const auto &e : other.segments )
1256
1256
segments.push_back (e->clone_type_path_segment ());
@@ -1259,7 +1259,9 @@ class TypePath : public TypeNoBounds, public Path
1259
1259
// Overloaded assignment operator with clone
1260
1260
TypePath &operator = (TypePath const &other)
1261
1261
{
1262
+ node_id = other.node_id ;
1262
1263
has_opening_scope_resolution = other.has_opening_scope_resolution ;
1264
+ locus = other.locus ;
1263
1265
1264
1266
segments.reserve (other.segments .size ());
1265
1267
for (const auto &e : other.segments )
@@ -1281,6 +1283,12 @@ class TypePath : public TypeNoBounds, public Path
1281
1283
// Creates a trait bound with a clone of this type path as its only element.
1282
1284
TraitBound *to_trait_bound (bool in_parens) const override ;
1283
1285
1286
+ location_t get_locus () const override final { return locus; }
1287
+ NodeId get_node_id () const override final { return node_id; }
1288
+
1289
+ void mark_for_strip () override {}
1290
+ bool is_marked_for_strip () const override { return false ; }
1291
+
1284
1292
void accept_vis (ASTVisitor &vis) override ;
1285
1293
1286
1294
// TODO: this seems kinda dodgy
@@ -1294,20 +1302,10 @@ class TypePath : public TypeNoBounds, public Path
1294
1302
}
1295
1303
1296
1304
size_t get_num_segments () const { return segments.size (); }
1297
- location_t get_locus () const override { return Path::get_locus (); }
1298
-
1299
- // TypePath is both a Type and a Path, which is really annoying for a few
1300
- // methods. We need to override them and manually call either of them, which
1301
- // sucks. Oh well.
1302
1305
1303
- void mark_for_strip () override { TypeNoBounds::mark_for_strip () ; }
1306
+ Path::Kind get_path_kind () const override { return Path::Kind::Type ; }
1304
1307
1305
- bool is_marked_for_strip () const override
1306
- {
1307
- return TypeNoBounds::is_marked_for_strip ();
1308
- }
1309
-
1310
- NodeId get_node_id () const override { return TypeNoBounds::get_node_id (); }
1308
+ Path *clone_path_impl () const override { return new TypePath (*this ); }
1311
1309
};
1312
1310
1313
1311
struct QualifiedPathType
@@ -1496,7 +1494,7 @@ class QualifiedPathInExpression : public Pattern, public ExprWithoutBlock
1496
1494
if (path->get_path_kind () == Path::Kind::Regular)
1497
1495
return static_cast <RegularPath &> (*path).get_segments ().size () == 1 ;
1498
1496
1499
- return false ;
1497
+ rust_unreachable () ;
1500
1498
}
1501
1499
1502
1500
protected:
0 commit comments