diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-02-06 22:20:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-06 22:20:09 +0000 |
commit | 5c36d24c659d18b634629a56d547ae208b914394 (patch) | |
tree | b018d9d93f8bcf074246ebe625d9212a190eeeff /gcc/rust/ast/rust-expr.h | |
parent | 05cfe8f9fdc363ff7db4cba2decaf22e44057c3f (diff) | |
parent | b92a9b80faa4b6daeca3e94db8bcdebdeec0b859 (diff) | |
download | gcc-5c36d24c659d18b634629a56d547ae208b914394.zip gcc-5c36d24c659d18b634629a56d547ae208b914394.tar.gz gcc-5c36d24c659d18b634629a56d547ae208b914394.tar.bz2 |
Merge #888
888: Added location data to Match Arm and removed unused code r=philberty a=mvvsmk
Fixes #863
- Added location data to Match arm in gcc/rust/ast/rust-expr.h and gcc/rust/hir/tree/rust-hir-expr.h
- Updated the respective constructors and copy constructors
- Updated location info for match arm in code generation in gcc/rust/backend/eust-compile-expr.cc
- Removed unused code in the above rust-expr.h and rust-gir-expr.h files as mentioned in the issue by `@philberty.`
- Comment removed form rust-expr.h
- Changed partameterized constructor and static function in
rust-hir-expr.h
- Changed line 697 to pass expr.get_locus() in rust-ast-lower
- Changed parameterised constructor in rust-expr.h
- Changed line 8563 in rust-parse-impl.h to pass location data.
Note :
- I also added a public member funtion for the class MatchArm
`Location get_locus ( ) const { return locus; }`
Do me know if I missed anything or could improve on something.
Signed-off-by : M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
Co-authored-by: @mvvsmk <mvvsmanojkumar@gmail.com>
Diffstat (limited to 'gcc/rust/ast/rust-expr.h')
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 130 |
1 files changed, 8 insertions, 122 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index a2ce1d8..3f3ed5c 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -4225,7 +4225,7 @@ private: // inlined from MatchArmGuard std::unique_ptr<Expr> guard_expr; - // TODO: should this store location data? + Location locus; public: // Returns whether the MatchArm has a match arm guard expression @@ -4233,11 +4233,11 @@ public: // Constructor for match arm with a guard expression MatchArm (std::vector<std::unique_ptr<Pattern> > match_arm_patterns, - std::unique_ptr<Expr> guard_expr = nullptr, + Location locus, std::unique_ptr<Expr> guard_expr = nullptr, std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) : outer_attrs (std::move (outer_attrs)), match_arm_patterns (std::move (match_arm_patterns)), - guard_expr (std::move (guard_expr)) + guard_expr (std::move (guard_expr)), locus (locus) {} // Copy constructor with clone @@ -4250,6 +4250,8 @@ public: match_arm_patterns.reserve (other.match_arm_patterns.size ()); for (const auto &e : other.match_arm_patterns) match_arm_patterns.push_back (e->clone_pattern ()); + + locus = other.locus; } ~MatchArm () = default; @@ -4281,7 +4283,8 @@ public: // Creates a match arm in an error state. static MatchArm create_error () { - return MatchArm (std::vector<std::unique_ptr<Pattern> > ()); + Location locus = Location (); + return MatchArm (std::vector<std::unique_ptr<Pattern> > (), locus); } std::string as_string () const; @@ -4305,36 +4308,9 @@ public: { return match_arm_patterns; } -}; - -/* -// Base "match case" for a match expression - abstract -class MatchCase -{ - MatchArm arm; - -protected: - MatchCase (MatchArm arm) : arm (std::move (arm)) {} - - // Should not require copy constructor or assignment operator overloading - // Clone function implementation as pure virtual method - virtual MatchCase *clone_match_case_impl () const = 0; - -public: - virtual ~MatchCase () {} - - // Unique pointer custom clone function - std::unique_ptr<MatchCase> clone_match_case () const - { - return std::unique_ptr<MatchCase> (clone_match_case_impl ()); - } - - virtual std::string as_string () const; - - virtual void accept_vis (ASTVisitor &vis) = 0; + Location get_locus () const { return locus; } }; -*/ /* A "match case" - a correlated match arm and resulting expression. Not * abstract. */ @@ -4391,96 +4367,6 @@ public: NodeId get_node_id () const { return node_id; } }; -#if 0 -// Block expression match case -class MatchCaseBlockExpr : public MatchCase -{ - std::unique_ptr<BlockExpr> block_expr; - - // TODO: should this store location data? - -public: - MatchCaseBlockExpr (MatchArm arm, std::unique_ptr<BlockExpr> block_expr) - : MatchCase (std::move (arm)), block_expr (std::move (block_expr)) - {} - - // Copy constructor requires clone - MatchCaseBlockExpr (MatchCaseBlockExpr const &other) - : MatchCase (other), block_expr (other.block_expr->clone_block_expr ()) - {} - - // Overload assignment operator to have clone - MatchCaseBlockExpr &operator= (MatchCaseBlockExpr const &other) - { - MatchCase::operator= (other); - block_expr = other.block_expr->clone_block_expr (); - // arm = other.arm; - - return *this; - } - - // move constructors - MatchCaseBlockExpr (MatchCaseBlockExpr &&other) = default; - MatchCaseBlockExpr &operator= (MatchCaseBlockExpr &&other) = default; - - std::string as_string () const override; - - void accept_vis (ASTVisitor &vis) override; - -protected: - /* Use covariance to implement clone function as returning this object rather - * than base */ - MatchCaseBlockExpr *clone_match_case_impl () const override - { - return new MatchCaseBlockExpr (*this); - } -}; - -// Expression (except block expression) match case -class MatchCaseExpr : public MatchCase -{ - std::unique_ptr<Expr> expr; - - // TODO: should this store location data? - -public: - MatchCaseExpr (MatchArm arm, std::unique_ptr<Expr> expr) - : MatchCase (std::move (arm)), expr (std::move (expr)) - {} - - // Copy constructor requires clone - MatchCaseExpr (MatchCaseExpr const &other) - : MatchCase (other), expr (other.expr->clone_expr ()) - {} - - // Overload assignment operator to have clone - MatchCaseExpr &operator= (MatchCaseExpr const &other) - { - MatchCase::operator= (other); - expr = other.expr->clone_expr (); - // arm = other.arm; - - return *this; - } - - // move constructors - MatchCaseExpr (MatchCaseExpr &&other) = default; - MatchCaseExpr &operator= (MatchCaseExpr &&other) = default; - - std::string as_string () const override; - - void accept_vis (ASTVisitor &vis) override; - -protected: - /* Use covariance to implement clone function as returning this object rather - * than base */ - MatchCaseExpr *clone_match_case_impl () const override - { - return new MatchCaseExpr (*this); - } -}; -#endif - // Match expression AST node class MatchExpr : public ExprWithBlock { |