Skip to content

Commit ed1b4d7

Browse files
committed
lang-item: Remove unused NodeId from LangItemPath
gcc/rust/ChangeLog: * ast/rust-path.h: Adapt children of Path to fix some NodeId issues.
1 parent c0513af commit ed1b4d7

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

gcc/rust/ast/rust-path.h

+37-39
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,6 @@ class Path : public Pattern
599599
return Pattern::Kind::Path;
600600
}
601601

602-
location_t get_locus () const override { return locus; }
603-
NodeId get_node_id () const override { return node_id; }
604-
605602
std::unique_ptr<Path> clone_path ()
606603
{
607604
return std::unique_ptr<Path> (clone_path_impl ());
@@ -613,22 +610,19 @@ class Path : public Pattern
613610
}
614611

615612
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-
621613
virtual Path *clone_path_impl () const = 0;
622614
};
623615

624616
class RegularPath : public Path
625617
{
626618
std::vector<PathExprSegment> segments;
619+
NodeId node_id;
620+
location_t locus;
627621

628622
public:
629623
explicit RegularPath (std::vector<PathExprSegment> &&segments,
630624
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)
632626
{}
633627

634628
std::string as_string () const override;
@@ -657,17 +651,25 @@ class RegularPath : public Path
657651
return new RegularPath (std::vector<PathExprSegment> (segments), locus,
658652
node_id);
659653
}
654+
655+
NodeId get_node_id () const override { return node_id; }
656+
location_t get_locus () const override { return locus; }
660657
};
661658

662659
class LangItemPath : public Path
663660
{
664-
NodeId lang_item;
665-
666661
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+
{}
667668

668669
public:
669670
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)
671673
{}
672674

673675
Path::Kind get_path_kind () const override { return Path::Kind::LangItem; }
@@ -676,12 +678,15 @@ class LangItemPath : public Path
676678

677679
Path *clone_path_impl () const override
678680
{
679-
return new LangItemPath (kind, locus);
681+
return new LangItemPath (kind, node_id, locus);
680682
}
681683

682684
std::string as_string () const override;
683685

684686
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; }
685690
};
686691

687692
/* AST node representing a path-in-expression pattern (path that allows
@@ -739,11 +744,10 @@ class PathInExpression : public Pattern, public ExprWithoutBlock
739744
// Returns whether path in expression is in an error state.
740745
bool is_error () const
741746
{
742-
// FIXME: Cleanup
743747
if (path->get_path_kind () == Path::Kind::Regular)
744748
return !static_cast<RegularPath &> (*path).has_segments ();
745749

746-
return false;
750+
rust_unreachable ();
747751
}
748752

749753
/* Converts PathInExpression to SimplePath if possible (i.e. no generic
@@ -822,7 +826,7 @@ class PathInExpression : public Pattern, public ExprWithoutBlock
822826
if (path->get_path_kind () == Path::Kind::Regular)
823827
return static_cast<RegularPath &> (*path).get_segments ().size () == 1;
824828

825-
return false;
829+
rust_unreachable ();
826830
}
827831

828832
Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Path; }
@@ -1201,17 +1205,13 @@ class TypePathSegmentFunction : public TypePathSegment
12011205
}
12021206
};
12031207

1204-
// Path used inside types
12051208
class TypePath : public TypeNoBounds, public Path
12061209
{
12071210
bool has_opening_scope_resolution;
12081211
std::vector<std::unique_ptr<TypePathSegment> > segments;
1212+
location_t locus;
12091213

12101214
protected:
1211-
Kind get_path_kind () const override { return Kind::Type; }
1212-
1213-
Path *clone_path_impl () const override { return new TypePath (*this); }
1214-
12151215
/* Use covariance to implement clone function as returning this object
12161216
* rather than base */
12171217
TypePath *clone_type_no_bounds_impl () const override
@@ -1234,23 +1234,23 @@ class TypePath : public TypeNoBounds, public Path
12341234
static TypePath create_error ()
12351235
{
12361236
return TypePath (std::vector<std::unique_ptr<TypePathSegment> > (),
1237-
UNKNOWN_LOCATION);
1237+
UNDEF_LOCATION);
12381238
}
12391239

12401240
// Constructor
12411241
TypePath (std::vector<std::unique_ptr<TypePathSegment> > segments,
12421242
location_t locus, bool has_opening_scope_resolution = false)
12431243
: TypeNoBounds (),
1244-
Path (locus, Analysis::Mappings::get ().get_next_node_id ()),
12451244
has_opening_scope_resolution (has_opening_scope_resolution),
1246-
segments (std::move (segments))
1245+
segments (std::move (segments)), locus (locus)
12471246
{}
12481247

12491248
// Copy constructor with vector clone
12501249
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)
12531252
{
1253+
node_id = other.node_id;
12541254
segments.reserve (other.segments.size ());
12551255
for (const auto &e : other.segments)
12561256
segments.push_back (e->clone_type_path_segment ());
@@ -1259,7 +1259,9 @@ class TypePath : public TypeNoBounds, public Path
12591259
// Overloaded assignment operator with clone
12601260
TypePath &operator= (TypePath const &other)
12611261
{
1262+
node_id = other.node_id;
12621263
has_opening_scope_resolution = other.has_opening_scope_resolution;
1264+
locus = other.locus;
12631265

12641266
segments.reserve (other.segments.size ());
12651267
for (const auto &e : other.segments)
@@ -1281,6 +1283,12 @@ class TypePath : public TypeNoBounds, public Path
12811283
// Creates a trait bound with a clone of this type path as its only element.
12821284
TraitBound *to_trait_bound (bool in_parens) const override;
12831285

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+
12841292
void accept_vis (ASTVisitor &vis) override;
12851293

12861294
// TODO: this seems kinda dodgy
@@ -1294,20 +1302,10 @@ class TypePath : public TypeNoBounds, public Path
12941302
}
12951303

12961304
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.
13021305

1303-
void mark_for_strip () override { TypeNoBounds::mark_for_strip (); }
1306+
Path::Kind get_path_kind () const override { return Path::Kind::Type; }
13041307

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); }
13111309
};
13121310

13131311
struct QualifiedPathType
@@ -1496,7 +1494,7 @@ class QualifiedPathInExpression : public Pattern, public ExprWithoutBlock
14961494
if (path->get_path_kind () == Path::Kind::Regular)
14971495
return static_cast<RegularPath &> (*path).get_segments ().size () == 1;
14981496

1499-
return false;
1497+
rust_unreachable ();
15001498
}
15011499

15021500
protected:

0 commit comments

Comments
 (0)