diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-path.h | 20 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 18 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve.cc | 2 |
3 files changed, 22 insertions, 18 deletions
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h index e062dc6..cff3b09 100644 --- a/gcc/rust/ast/rust-path.h +++ b/gcc/rust/ast/rust-path.h @@ -33,13 +33,12 @@ namespace AST { class PathIdentSegment { std::string segment_name; - - // TODO: should this have location info stored? + Location locus; // only allow identifiers, "super", "self", "Self", "crate", or "$crate" public: - PathIdentSegment (std::string segment_name) - : segment_name (std::move (segment_name)) + PathIdentSegment (std::string segment_name, Location locus) + : segment_name (std::move (segment_name)), locus (locus) {} /* TODO: insert check in constructor for this? Or is this a semantic error @@ -49,7 +48,10 @@ public: * not entirely sure */ // Creates an error PathIdentSegment. - static PathIdentSegment create_error () { return PathIdentSegment (""); } + static PathIdentSegment create_error () + { + return PathIdentSegment ("", Location ()); + } // Returns whether PathIdentSegment is in an error state. bool is_error () const { return segment_name.empty (); } @@ -221,7 +223,7 @@ public: bool has_generic_args () const { return generic_args.has_generic_args (); } // Constructor for segment (from IdentSegment and GenericArgs) - PathExprSegment (PathIdentSegment segment_name, Location locus = Location (), + PathExprSegment (PathIdentSegment segment_name, Location locus, GenericArgs generic_args = GenericArgs::create_empty ()) : segment_name (std::move (segment_name)), generic_args (std::move (generic_args)), locus (locus), @@ -237,7 +239,7 @@ public: = std::vector<std::unique_ptr<Type> > (), std::vector<GenericArgsBinding> binding_args = std::vector<GenericArgsBinding> ()) - : segment_name (PathIdentSegment (std::move (segment_name))), + : segment_name (PathIdentSegment (std::move (segment_name), locus)), generic_args (GenericArgs (std::move (lifetime_args), std::move (type_args), std::move (binding_args))), @@ -250,7 +252,7 @@ public: // Creates an error-state path expression segment. static PathExprSegment create_error () { - return PathExprSegment (PathIdentSegment::create_error ()); + return PathExprSegment (PathIdentSegment::create_error (), Location ()); } std::string as_string () const; @@ -440,7 +442,7 @@ public: TypePathSegment (std::string segment_name, bool has_separating_scope_resolution, Location locus) - : ident_segment (PathIdentSegment (std::move (segment_name))), + : ident_segment (PathIdentSegment (std::move (segment_name), locus)), locus (locus), has_separating_scope_resolution (has_separating_scope_resolution), node_id (Analysis::Mappings::get ()->get_next_node_id ()) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 6498f3c..3ff1229 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -706,29 +706,29 @@ Parser<ManagedTokenSource>::parse_path_ident_segment () case IDENTIFIER: lexer.skip_token (); - return AST::PathIdentSegment (t->get_str ()); + return AST::PathIdentSegment (t->get_str (), t->get_locus ()); case SUPER: lexer.skip_token (); - return AST::PathIdentSegment ("super"); + return AST::PathIdentSegment ("super", t->get_locus ()); case SELF: lexer.skip_token (); - return AST::PathIdentSegment ("self"); + return AST::PathIdentSegment ("self", t->get_locus ()); case SELF_ALIAS: lexer.skip_token (); - return AST::PathIdentSegment ("Self"); + return AST::PathIdentSegment ("Self", t->get_locus ()); case CRATE: lexer.skip_token (); - return AST::PathIdentSegment ("crate"); + return AST::PathIdentSegment ("crate", t->get_locus ()); case DOLLAR_SIGN: if (lexer.peek_token (1)->get_id () == CRATE) { lexer.skip_token (1); - return AST::PathIdentSegment ("$crate"); + return AST::PathIdentSegment ("$crate", t->get_locus ()); } gcc_fallthrough (); default: @@ -14613,8 +14613,10 @@ Parser<ManagedTokenSource>::parse_path_in_expression_pratt (const_TokenPtr tok) AST::GenericArgs generic_args = parse_path_generic_args (); - initial_segment = AST::PathExprSegment (initial_str, tok->get_locus (), - std::move (generic_args)); + initial_segment + = AST::PathExprSegment (AST::PathIdentSegment (initial_str, + tok->get_locus ()), + tok->get_locus (), std::move (generic_args)); } if (initial_segment.is_error ()) { diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc index 5ac076a..3fb8b41 100644 --- a/gcc/rust/resolve/rust-ast-resolve.cc +++ b/gcc/rust/resolve/rust-ast-resolve.cc @@ -26,7 +26,7 @@ #define MKBUILTIN_TYPE(_X, _R, _TY) \ do \ { \ - AST::PathIdentSegment seg (_X); \ + AST::PathIdentSegment seg (_X, Linemap::predeclared_location ()); \ auto typePath = ::std::unique_ptr<AST::TypePathSegment> ( \ new AST::TypePathSegment (::std::move (seg), false, \ Linemap::predeclared_location ())); \ |