@@ -666,6 +666,80 @@ class AssignmentExpr : public OperatorExpr
666
666
}
667
667
};
668
668
669
+ class CompoundAssignmentExpr : public OperatorExpr
670
+ {
671
+ public:
672
+ using ExprType = ArithmeticOrLogicalOperator;
673
+
674
+ private:
675
+ // Note: overloading trait specified in comments
676
+ ExprType expr_type;
677
+ std::unique_ptr<Expr> right_expr;
678
+
679
+ public:
680
+ std::string as_string () const override ;
681
+
682
+ ExprType get_expr_type () const { return expr_type; }
683
+
684
+ // Use pointers in constructor to enable polymorphism
685
+ CompoundAssignmentExpr (Analysis::NodeMapping mappings,
686
+ std::unique_ptr<Expr> value_to_assign_to,
687
+ std::unique_ptr<Expr> value_to_assign,
688
+ ExprType expr_kind, Location locus)
689
+ : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
690
+ AST::AttrVec (), locus),
691
+ expr_type (expr_kind), right_expr (std::move (value_to_assign))
692
+ {}
693
+ // outer attributes not allowed
694
+
695
+ // Have clone in copy constructor
696
+ CompoundAssignmentExpr (CompoundAssignmentExpr const &other)
697
+ : OperatorExpr (other), expr_type (other.expr_type),
698
+ right_expr (other.right_expr->clone_expr ())
699
+ {}
700
+
701
+ // Overload assignment operator to clone
702
+ CompoundAssignmentExpr &operator = (CompoundAssignmentExpr const &other)
703
+ {
704
+ OperatorExpr::operator = (other);
705
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
706
+ right_expr = other.right_expr ->clone_expr ();
707
+ expr_type = other.expr_type ;
708
+ // outer_attrs = other.outer_attrs;
709
+
710
+ return *this ;
711
+ }
712
+
713
+ // move constructors
714
+ CompoundAssignmentExpr (CompoundAssignmentExpr &&other) = default;
715
+ CompoundAssignmentExpr &operator = (CompoundAssignmentExpr &&other) = default ;
716
+
717
+ void accept_vis (HIRVisitor &vis) override ;
718
+
719
+ std::unique_ptr<Expr> &get_left_expr ()
720
+ {
721
+ rust_assert (main_or_left_expr != nullptr );
722
+ return main_or_left_expr;
723
+ }
724
+
725
+ std::unique_ptr<Expr> &get_right_expr ()
726
+ {
727
+ rust_assert (right_expr != nullptr );
728
+ return right_expr;
729
+ }
730
+
731
+ void visit_lhs (HIRVisitor &vis) { main_or_left_expr->accept_vis (vis); }
732
+ void visit_rhs (HIRVisitor &vis) { right_expr->accept_vis (vis); }
733
+
734
+ protected:
735
+ /* Use covariance to implement clone function as returning this object rather
736
+ * than base */
737
+ CompoundAssignmentExpr *clone_expr_without_block_impl () const override
738
+ {
739
+ return new CompoundAssignmentExpr (*this );
740
+ }
741
+ };
742
+
669
743
// Expression in parentheses (i.e. like literally just any 3 + (2 * 6))
670
744
class GroupedExpr : public ExprWithoutBlock
671
745
{
0 commit comments