diff options
author | Owen Avery <powerboat9.gamer@gmail.com> | 2023-03-15 23:30:19 -0400 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:34:08 +0100 |
commit | f2df348dcd5c7ef51e5a686a4d2473ae9bbb36bb (patch) | |
tree | b04421abddf75f0a0f5ebf5ece8b00c194c1a4ef /gcc/rust/ast/rust-expr.h | |
parent | 7d8de1ca4a78ec7bf9cdd7e5cbe9d11bd2546efe (diff) | |
download | gcc-f2df348dcd5c7ef51e5a686a4d2473ae9bbb36bb.zip gcc-f2df348dcd5c7ef51e5a686a4d2473ae9bbb36bb.tar.gz gcc-f2df348dcd5c7ef51e5a686a4d2473ae9bbb36bb.tar.bz2 |
gccrs: Unify AST::IfLetExprConseqIf{,Let} into AST::IfLetExprConseqElse
This simplifies the AST's representation of if-let-statements
to match the HIR.
gcc/rust/ChangeLog:
* ast/rust-expr.h
(class IfLetExprConseqElse): Make else_block ExprWithBlock.
(class IfLetExprConseqIf): Remove.
(class IfLetExprConseqIfLet): Remove.
* ast/rust-ast-full-decls.h
(class IfLetExprConseqIf): Remove.
(class IfLetExprConseqIfLet): Remove.
* ast/rust-ast.cc
(IfLetExprConseqElse::as_string): Adjust output.
(IfLetExprConseqIf::as_string): Remove.
(IfLetExprConseqIfLet::as_string): Remove.
(IfLetExprConseqIf::accept_vis): Remove.
(IfLetExprConseqIfLet::accept_vis): Remove.
* ast/rust-ast-visitor.h
(ASTVisitor::visit): Remove IfLetExprConseqIf{,Let} visitors.
* ast/rust-ast-dump.cc
(Dump::visit): Likewise.
* ast/rust-ast-dump.h:
(Dump::visit): Likewise.
* ast/rust-ast-tokenstream.cc
(TokenStream::visit): Likewise.
* ast/rust-ast-tokenstream.h
(TokenStream::visit): Likewise.
* util/rust-attributes.cc
(AttributeChecker::visit): Likewise.
* util/rust-attributes.h:
(AttributeChecker::visit): Likewise.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h
(EarlyNameResolver::visit): Likewise.
* resolve/rust-ast-resolve-base.h
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Likewise.
* checks/errors/rust-feature-gate.h
(FeatureGate::visit): Likewise.
* expand/rust-cfg-strip.cc
(CfgStrip::visit): Likewise.
* expand/rust-cfg-strip.h:
(CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h
(ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h:
(ASTLoweringBase::visit): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_if_let_expr): Replace IfLetExprConseqIf{,Let} with IfLetExprConseqElse.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc/rust/ast/rust-expr.h')
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 130 |
1 files changed, 6 insertions, 124 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index f91d9e9..abe6e03 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -3945,7 +3945,7 @@ protected: * end */ class IfLetExprConseqElse : public IfLetExpr { - std::unique_ptr<BlockExpr> else_block; + std::unique_ptr<ExprWithBlock> else_block; public: std::string as_string () const override; @@ -3953,8 +3953,8 @@ public: IfLetExprConseqElse ( std::vector<std::unique_ptr<Pattern> > match_arm_patterns, std::unique_ptr<Expr> value, std::unique_ptr<BlockExpr> if_block, - std::unique_ptr<BlockExpr> else_block, std::vector<Attribute> outer_attrs, - Location locus) + std::unique_ptr<ExprWithBlock> else_block, + std::vector<Attribute> outer_attrs, Location locus) : IfLetExpr (std::move (match_arm_patterns), std::move (value), std::move (if_block), std::move (outer_attrs), locus), else_block (std::move (else_block)) @@ -3963,7 +3963,7 @@ public: // copy constructor with clone IfLetExprConseqElse (IfLetExprConseqElse const &other) - : IfLetExpr (other), else_block (other.else_block->clone_block_expr ()) + : IfLetExpr (other), else_block (other.else_block->clone_expr_with_block ()) {} // overload assignment operator to clone @@ -3973,7 +3973,7 @@ public: // match_arm_patterns = other.match_arm_patterns; // value = other.value->clone_expr(); // if_block = other.if_block->clone_block_expr(); - else_block = other.else_block->clone_block_expr (); + else_block = other.else_block->clone_expr_with_block (); // outer_attrs = other.outer_attrs; return *this; @@ -3986,7 +3986,7 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr<BlockExpr> &get_else_block () + std::unique_ptr<ExprWithBlock> &get_else_block () { rust_assert (else_block != nullptr); return else_block; @@ -4001,124 +4001,6 @@ protected: } }; -/* AST node representing "if let" expression with an "else if" expression at the - * end */ -class IfLetExprConseqIf : public IfLetExpr -{ - std::unique_ptr<IfExpr> if_expr; - -public: - std::string as_string () const override; - - IfLetExprConseqIf (std::vector<std::unique_ptr<Pattern> > match_arm_patterns, - std::unique_ptr<Expr> value, - std::unique_ptr<BlockExpr> if_block, - std::unique_ptr<IfExpr> if_expr, - std::vector<Attribute> outer_attrs, Location locus) - : IfLetExpr (std::move (match_arm_patterns), std::move (value), - std::move (if_block), std::move (outer_attrs), locus), - if_expr (std::move (if_expr)) - {} - // again, outer attributes not allowed - - // copy constructor with clone - IfLetExprConseqIf (IfLetExprConseqIf const &other) - : IfLetExpr (other), if_expr (other.if_expr->clone_if_expr ()) - {} - - // overload assignment operator to clone - IfLetExprConseqIf &operator= (IfLetExprConseqIf const &other) - { - IfLetExpr::operator= (other); - // match_arm_patterns = other.match_arm_patterns; - // value = other.value->clone_expr(); - // if_block = other.if_block->clone_block_expr(); - if_expr = other.if_expr->clone_if_expr (); - - return *this; - } - - // move constructors - IfLetExprConseqIf (IfLetExprConseqIf &&other) = default; - IfLetExprConseqIf &operator= (IfLetExprConseqIf &&other) = default; - - void accept_vis (ASTVisitor &vis) override; - - // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr<IfExpr> &get_conseq_if_expr () - { - rust_assert (if_expr != nullptr); - return if_expr; - } - -protected: - /* Use covariance to implement clone function as returning this object rather - * than base */ - IfLetExprConseqIf *clone_if_let_expr_impl () const override - { - return new IfLetExprConseqIf (*this); - } -}; - -/* AST node representing "if let" expression with an "else if let" expression at - * the end */ -class IfLetExprConseqIfLet : public IfLetExpr -{ - std::unique_ptr<IfLetExpr> if_let_expr; - -public: - std::string as_string () const override; - - IfLetExprConseqIfLet ( - std::vector<std::unique_ptr<Pattern> > match_arm_patterns, - std::unique_ptr<Expr> value, std::unique_ptr<BlockExpr> if_block, - std::unique_ptr<IfLetExpr> if_let_expr, std::vector<Attribute> outer_attrs, - Location locus) - : IfLetExpr (std::move (match_arm_patterns), std::move (value), - std::move (if_block), std::move (outer_attrs), locus), - if_let_expr (std::move (if_let_expr)) - {} - // outer attributes not allowed - - // copy constructor with clone - IfLetExprConseqIfLet (IfLetExprConseqIfLet const &other) - : IfLetExpr (other), if_let_expr (other.if_let_expr->clone_if_let_expr ()) - {} - - // overload assignment operator to clone - IfLetExprConseqIfLet &operator= (IfLetExprConseqIfLet const &other) - { - IfLetExpr::operator= (other); - // match_arm_patterns = other.match_arm_patterns; - // value = other.value->clone_expr(); - // if_block = other.if_block->clone_block_expr(); - if_let_expr = other.if_let_expr->clone_if_let_expr (); - - return *this; - } - - // move constructors - IfLetExprConseqIfLet (IfLetExprConseqIfLet &&other) = default; - IfLetExprConseqIfLet &operator= (IfLetExprConseqIfLet &&other) = default; - - void accept_vis (ASTVisitor &vis) override; - - // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr<IfLetExpr> &get_conseq_if_let_expr () - { - rust_assert (if_let_expr != nullptr); - return if_let_expr; - } - -protected: - /* Use covariance to implement clone function as returning this object rather - * than base */ - IfLetExprConseqIfLet *clone_if_let_expr_impl () const override - { - return new IfLetExprConseqIfLet (*this); - } -}; - // Match arm expression struct MatchArm { |