diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-02-18 08:14:30 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-18 08:14:30 +0000 |
commit | fbe22e87687c68357430e60361a8a124c81148cc (patch) | |
tree | 72b1cf54a3a6c8ed1584defaa2964e47b10428c9 /gcc/rust/ast/rust-path.h | |
parent | 9fb06d66cef70584e7aa2fa3a6ad22ef7def6b84 (diff) | |
parent | 0e15b89839170cb6c9115cfc57310af2170423a0 (diff) | |
download | gcc-fbe22e87687c68357430e60361a8a124c81148cc.zip gcc-fbe22e87687c68357430e60361a8a124c81148cc.tar.gz gcc-fbe22e87687c68357430e60361a8a124c81148cc.tar.bz2 |
Merge #940
940: Add more location info to AST structures r=CohenArthur a=CohenArthur
Two classes still remain locus-less: `TupleStructItems` and `TuplePatternItems` as I do not believe they are constructed at the moment.
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc/rust/ast/rust-path.h')
-rw-r--r-- | gcc/rust/ast/rust-path.h | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h index e062dc6..ed37f40 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 ()) @@ -539,11 +541,13 @@ private: // FIXME: think of better way to mark as invalid than taking up storage bool is_invalid; - // TODO: should this have location info? + Location locus; protected: // Constructor only used to create invalid type path functions. - TypePathFunction (bool is_invalid) : is_invalid (is_invalid) {} + TypePathFunction (bool is_invalid, Location locus) + : is_invalid (is_invalid), locus (locus) + {} public: // Returns whether the return type of the function has been specified. @@ -556,13 +560,16 @@ public: bool is_error () const { return is_invalid; } // Creates an error state function. - static TypePathFunction create_error () { return TypePathFunction (true); } + static TypePathFunction create_error () + { + return TypePathFunction (true, Location ()); + } // Constructor - TypePathFunction (std::vector<std::unique_ptr<Type> > inputs, + TypePathFunction (std::vector<std::unique_ptr<Type> > inputs, Location locus, std::unique_ptr<Type> type = nullptr) : inputs (std::move (inputs)), return_type (std::move (type)), - is_invalid (false) + is_invalid (false), locus (locus) {} // Copy constructor with clone |