Skip to content

Commit b74044f

Browse files
Merge #1164
1164: Add `NodeId`s to `SimplePath{Segment}`s r=CohenArthur a=CohenArthur This is a necessary first step which addresses #1158 I am working on the visibility resolver and simple-path name resolver in parallel and will need those changes. I'm not sure if the `has_path` method is necessary since we will have `HIR::Visibilities` in the visibility resolver, which will be desugared. Maybe I am doing this wrong and we should be working on `AST::Visibilities` instead? Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2 parents 2b1cb4b + d0c7549 commit b74044f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

gcc/rust/ast/rust-ast.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,14 @@ class SimplePathSegment : public PathSegment
325325
{
326326
std::string segment_name;
327327
Location locus;
328+
NodeId node_id;
328329

329330
// only allow identifiers, "super", "self", "crate", or "$crate"
330331
public:
331332
// TODO: put checks in constructor to enforce this rule?
332333
SimplePathSegment (std::string segment_name, Location locus = Location ())
333-
: segment_name (std::move (segment_name)), locus (locus)
334+
: segment_name (std::move (segment_name)), locus (locus),
335+
node_id (Analysis::Mappings::get ()->get_next_node_id ())
334336
{}
335337

336338
/* Returns whether simple path segment is in an invalid state (currently, if
@@ -346,6 +348,7 @@ class SimplePathSegment : public PathSegment
346348
std::string as_string () const override;
347349

348350
Location get_locus () const { return locus; }
351+
NodeId get_node_id () const { return node_id; }
349352

350353
// TODO: visitor pattern?
351354
};
@@ -356,14 +359,16 @@ class SimplePath
356359
bool has_opening_scope_resolution;
357360
std::vector<SimplePathSegment> segments;
358361
Location locus;
362+
NodeId node_id;
359363

360364
public:
361365
// Constructor
362366
SimplePath (std::vector<SimplePathSegment> path_segments,
363367
bool has_opening_scope_resolution = false,
364368
Location locus = Location ())
365369
: has_opening_scope_resolution (has_opening_scope_resolution),
366-
segments (std::move (path_segments)), locus (locus)
370+
segments (std::move (path_segments)), locus (locus),
371+
node_id (Analysis::Mappings::get ()->get_next_node_id ())
367372
{}
368373

369374
// Creates an empty SimplePath.
@@ -378,6 +383,7 @@ class SimplePath
378383
std::string as_string () const;
379384

380385
Location get_locus () const { return locus; }
386+
NodeId get_node_id () const { return node_id; }
381387

382388
// does this need visitor if not polymorphic? probably not
383389

gcc/rust/ast/rust-item.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,9 @@ struct Visibility
640640
return vis_type == PUB_IN_PATH && in_path.is_empty ();
641641
}
642642

643+
// Returns whether a visibility has a path
644+
bool has_path () const { return !(is_error ()) && vis_type == PUB_IN_PATH; }
645+
643646
// Returns whether visibility is public or not.
644647
bool is_public () const { return vis_type != PRIV && !is_error (); }
645648

0 commit comments

Comments
 (0)