@@ -3700,6 +3700,82 @@ class ReturnExpr : public ExprWithoutBlock
3700
3700
}
3701
3701
};
3702
3702
3703
+ // Try expression AST node representation
3704
+ class TryExpr : public ExprWithBlock
3705
+ {
3706
+ std::vector<Attribute> outer_attrs;
3707
+ std::unique_ptr<BlockExpr> block_expr;
3708
+ location_t locus;
3709
+
3710
+ // TODO: find another way to store this to save memory?
3711
+ bool marked_for_strip = false ;
3712
+
3713
+ public:
3714
+ std::string as_string () const override ;
3715
+
3716
+ // Constructor for ReturnExpr.
3717
+ TryExpr (std::unique_ptr<BlockExpr> block_expr,
3718
+ std::vector<Attribute> outer_attribs, location_t locus)
3719
+ : outer_attrs (std::move (outer_attribs)),
3720
+ block_expr (std::move (block_expr)), locus (locus)
3721
+ {
3722
+ rust_assert (this ->block_expr );
3723
+ }
3724
+
3725
+ // Copy constructor with clone
3726
+ TryExpr (TryExpr const &other)
3727
+ : ExprWithBlock (other), outer_attrs (other.outer_attrs),
3728
+ block_expr (other.block_expr->clone_block_expr ()), locus (other.locus),
3729
+ marked_for_strip (other.marked_for_strip)
3730
+ {}
3731
+
3732
+ // Overloaded assignment operator to clone return_expr pointer
3733
+ TryExpr &operator = (TryExpr const &other)
3734
+ {
3735
+ ExprWithBlock::operator = (other);
3736
+ locus = other.locus ;
3737
+ marked_for_strip = other.marked_for_strip ;
3738
+ outer_attrs = other.outer_attrs ;
3739
+
3740
+ block_expr = other.block_expr ->clone_block_expr ();
3741
+
3742
+ return *this ;
3743
+ }
3744
+
3745
+ // move constructors
3746
+ TryExpr (TryExpr &&other) = default;
3747
+ TryExpr &operator = (TryExpr &&other) = default ;
3748
+
3749
+ location_t get_locus () const override final { return locus; }
3750
+
3751
+ void accept_vis (ASTVisitor &vis) override ;
3752
+
3753
+ // Can't think of any invalid invariants, so store boolean.
3754
+ void mark_for_strip () override { marked_for_strip = true ; }
3755
+ bool is_marked_for_strip () const override { return marked_for_strip; }
3756
+
3757
+ // TODO: is this better? Or is a "vis_block" better?
3758
+ BlockExpr &get_block_expr () { return *block_expr; }
3759
+
3760
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
3761
+ std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }
3762
+
3763
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override
3764
+ {
3765
+ outer_attrs = std::move (new_attrs);
3766
+ }
3767
+
3768
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Return; }
3769
+
3770
+ protected:
3771
+ /* Use covariance to implement clone function as returning this object rather
3772
+ * than base */
3773
+ TryExpr *clone_expr_with_block_impl () const override
3774
+ {
3775
+ return new TryExpr (*this );
3776
+ }
3777
+ };
3778
+
3703
3779
// Forward decl - defined in rust-macro.h
3704
3780
class MacroInvocation ;
3705
3781
0 commit comments