From b92a9b80faa4b6daeca3e94db8bcdebdeec0b859 Mon Sep 17 00:00:00 2001 From: "@mvvsmk" Date: Thu, 3 Feb 2022 07:27:20 +0530 Subject: Upated parameterised constuctor of MatchArm to take location data Addresses issue #863 1)comment removed form rust-expr.h 2)changed partameterized constructor and static function in rust-hir-expr.h 3)changed line 697 to pass expr.get_locus() in rust-ast-lower 4)changed parameterised constructor in rust-expr.h 5)changed line 8563 in rust-parse-impl.h to pass location data. Signed-off-by : M V V S Manoj Kumar --- gcc/rust/ast/rust-expr.h | 9 ++++----- gcc/rust/hir/rust-ast-lower-expr.h | 2 +- gcc/rust/hir/tree/rust-hir-expr.h | 8 ++++---- gcc/rust/parse/rust-parse-impl.h | 5 +++-- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 2f46fee..3f3ed5c 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -4225,7 +4225,6 @@ private: // inlined from MatchArmGuard std::unique_ptr guard_expr; - // TODO: should this store location data? Location locus; public: @@ -4234,9 +4233,8 @@ public: // Constructor for match arm with a guard expression MatchArm (std::vector > match_arm_patterns, - std::unique_ptr guard_expr = nullptr, - std::vector outer_attrs = std::vector (), - Location locus = Location ()) + Location locus, std::unique_ptr guard_expr = nullptr, + std::vector outer_attrs = std::vector ()) : outer_attrs (std::move (outer_attrs)), match_arm_patterns (std::move (match_arm_patterns)), guard_expr (std::move (guard_expr)), locus (locus) @@ -4285,7 +4283,8 @@ public: // Creates a match arm in an error state. static MatchArm create_error () { - return MatchArm (std::vector > ()); + Location locus = Location (); + return MatchArm (std::vector > (), locus); } std::string as_string () const; diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h index 8cd4fb5..1aa21bd 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.h +++ b/gcc/rust/hir/rust-ast-lower-expr.h @@ -693,7 +693,7 @@ public: match_arm_patterns.push_back (std::unique_ptr (ptrn)); } - HIR::MatchArm arm (std::move (match_arm_patterns), + HIR::MatchArm arm (std::move (match_arm_patterns), expr.get_locus (), std::unique_ptr (kase_guard_expr), match_case.get_arm ().get_outer_attrs ()); diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 89b9f64..3267d01 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -3721,9 +3721,8 @@ public: // Constructor for match arm with a guard expression MatchArm (std::vector > match_arm_patterns, - std::unique_ptr guard_expr = nullptr, - AST::AttrVec outer_attrs = AST::AttrVec (), - Location locus = Location ()) + Location locus, std::unique_ptr guard_expr = nullptr, + AST::AttrVec outer_attrs = AST::AttrVec ()) : outer_attrs (std::move (outer_attrs)), match_arm_patterns (std::move (match_arm_patterns)), guard_expr (std::move (guard_expr)), locus (locus) @@ -3770,7 +3769,8 @@ public: // Creates a match arm in an error state. static MatchArm create_error () { - return MatchArm (std::vector > ()); + Location locus = Location (); + return MatchArm (std::vector > (), locus); } std::string as_string () const; diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 0e39e48..6d393b0 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -8560,8 +8560,9 @@ Parser::parse_match_arm () // DEBUG rust_debug ("successfully parsed match arm"); - return AST::MatchArm (std::move (match_arm_patterns), std::move (guard_expr), - std::move (outer_attrs)); + return AST::MatchArm (std::move (match_arm_patterns), + lexer.peek_token ()->get_locus (), + std::move (guard_expr), std::move (outer_attrs)); } /* Parses the patterns used in a match arm. End token id is the id of the token -- cgit v1.1