diff options
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 { |