Skip to content

Commit ef06769

Browse files
committed
path-id: Add location info on path identifier
1 parent 9e524a7 commit ef06769

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

gcc/rust/ast/rust-path.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ namespace AST {
3333
class PathIdentSegment
3434
{
3535
std::string segment_name;
36-
37-
// TODO: should this have location info stored?
36+
Location locus;
3837

3938
// only allow identifiers, "super", "self", "Self", "crate", or "$crate"
4039
public:
41-
PathIdentSegment (std::string segment_name)
42-
: segment_name (std::move (segment_name))
40+
PathIdentSegment (std::string segment_name, Location locus)
41+
: segment_name (std::move (segment_name)), locus (locus)
4342
{}
4443

4544
/* TODO: insert check in constructor for this? Or is this a semantic error
@@ -49,7 +48,10 @@ class PathIdentSegment
4948
* not entirely sure */
5049

5150
// Creates an error PathIdentSegment.
52-
static PathIdentSegment create_error () { return PathIdentSegment (""); }
51+
static PathIdentSegment create_error ()
52+
{
53+
return PathIdentSegment ("", Location ());
54+
}
5355

5456
// Returns whether PathIdentSegment is in an error state.
5557
bool is_error () const { return segment_name.empty (); }
@@ -221,7 +223,7 @@ class PathExprSegment
221223
bool has_generic_args () const { return generic_args.has_generic_args (); }
222224

223225
// Constructor for segment (from IdentSegment and GenericArgs)
224-
PathExprSegment (PathIdentSegment segment_name, Location locus = Location (),
226+
PathExprSegment (PathIdentSegment segment_name, Location locus,
225227
GenericArgs generic_args = GenericArgs::create_empty ())
226228
: segment_name (std::move (segment_name)),
227229
generic_args (std::move (generic_args)), locus (locus),
@@ -237,7 +239,7 @@ class PathExprSegment
237239
= std::vector<std::unique_ptr<Type> > (),
238240
std::vector<GenericArgsBinding> binding_args
239241
= std::vector<GenericArgsBinding> ())
240-
: segment_name (PathIdentSegment (std::move (segment_name))),
242+
: segment_name (PathIdentSegment (std::move (segment_name), locus)),
241243
generic_args (GenericArgs (std::move (lifetime_args),
242244
std::move (type_args),
243245
std::move (binding_args))),
@@ -250,7 +252,7 @@ class PathExprSegment
250252
// Creates an error-state path expression segment.
251253
static PathExprSegment create_error ()
252254
{
253-
return PathExprSegment (PathIdentSegment::create_error ());
255+
return PathExprSegment (PathIdentSegment::create_error (), Location ());
254256
}
255257

256258
std::string as_string () const;
@@ -440,7 +442,7 @@ class TypePathSegment
440442

441443
TypePathSegment (std::string segment_name,
442444
bool has_separating_scope_resolution, Location locus)
443-
: ident_segment (PathIdentSegment (std::move (segment_name))),
445+
: ident_segment (PathIdentSegment (std::move (segment_name), locus)),
444446
locus (locus),
445447
has_separating_scope_resolution (has_separating_scope_resolution),
446448
node_id (Analysis::Mappings::get ()->get_next_node_id ())

gcc/rust/parse/rust-parse-impl.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -706,29 +706,29 @@ Parser<ManagedTokenSource>::parse_path_ident_segment ()
706706
case IDENTIFIER:
707707
lexer.skip_token ();
708708

709-
return AST::PathIdentSegment (t->get_str ());
709+
return AST::PathIdentSegment (t->get_str (), t->get_locus ());
710710
case SUPER:
711711
lexer.skip_token ();
712712

713-
return AST::PathIdentSegment ("super");
713+
return AST::PathIdentSegment ("super", t->get_locus ());
714714
case SELF:
715715
lexer.skip_token ();
716716

717-
return AST::PathIdentSegment ("self");
717+
return AST::PathIdentSegment ("self", t->get_locus ());
718718
case SELF_ALIAS:
719719
lexer.skip_token ();
720720

721-
return AST::PathIdentSegment ("Self");
721+
return AST::PathIdentSegment ("Self", t->get_locus ());
722722
case CRATE:
723723
lexer.skip_token ();
724724

725-
return AST::PathIdentSegment ("crate");
725+
return AST::PathIdentSegment ("crate", t->get_locus ());
726726
case DOLLAR_SIGN:
727727
if (lexer.peek_token (1)->get_id () == CRATE)
728728
{
729729
lexer.skip_token (1);
730730

731-
return AST::PathIdentSegment ("$crate");
731+
return AST::PathIdentSegment ("$crate", t->get_locus ());
732732
}
733733
gcc_fallthrough ();
734734
default:
@@ -14613,8 +14613,10 @@ Parser<ManagedTokenSource>::parse_path_in_expression_pratt (const_TokenPtr tok)
1461314613

1461414614
AST::GenericArgs generic_args = parse_path_generic_args ();
1461514615

14616-
initial_segment = AST::PathExprSegment (initial_str, tok->get_locus (),
14617-
std::move (generic_args));
14616+
initial_segment
14617+
= AST::PathExprSegment (AST::PathIdentSegment (initial_str,
14618+
tok->get_locus ()),
14619+
tok->get_locus (), std::move (generic_args));
1461814620
}
1461914621
if (initial_segment.is_error ())
1462014622
{

gcc/rust/resolve/rust-ast-resolve.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define MKBUILTIN_TYPE(_X, _R, _TY) \
2727
do \
2828
{ \
29-
AST::PathIdentSegment seg (_X); \
29+
AST::PathIdentSegment seg (_X, Linemap::predeclared_location ()); \
3030
auto typePath = ::std::unique_ptr<AST::TypePathSegment> ( \
3131
new AST::TypePathSegment (::std::move (seg), false, \
3232
Linemap::predeclared_location ())); \

0 commit comments

Comments
 (0)