diff options
author | Owen Avery <powerboat9.gamer@gmail.com> | 2023-03-15 16:35:47 -0400 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-03-17 16:31:54 +0000 |
commit | 3d4b1871910e4d7b4ef171f3fdeab5ec0e78a167 (patch) | |
tree | 8f81adecf100bc4f6a4b9e5091c943b907eea0f1 /gcc/rust/hir | |
parent | dd4038083ef08ce8e8456261389d4b26f5dd7ace (diff) | |
download | gcc-3d4b1871910e4d7b4ef171f3fdeab5ec0e78a167.zip gcc-3d4b1871910e4d7b4ef171f3fdeab5ec0e78a167.tar.gz gcc-3d4b1871910e4d7b4ef171f3fdeab5ec0e78a167.tar.bz2 |
Unify HIR::IfExprConseqIf{,Let} into HIR::IfExprConseqElse
This should simplify 'if' expression handling to match
future simplifications to 'if let' expression handling.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc
(TypeCheckExpr::visit): Remove IfExprConseqIf visitor.
* typecheck/rust-hir-type-check-expr.h
(TypeCheckExpr::visit): Remove IfExprConseqIf{,Let} visitor.
* backend/rust-compile-block.cc
(CompileConditionalBlocks::visit): Remove IfExprConseqIf visitor.
* backend/rust-compile-block.h
(CompileConditionalBlocks::visit): Remove IfExprConseqIf{,Let} visitors.
(CompileExprWithBlock::visit):
Remove IfExprConseqIf{,Let} visitors, implement BlockExpr visitor.
* backend/rust-compile-expr.cc
(CompileExpr::visit): Remove IfExprConseqIf visitor.
* backend/rust-compile-expr.h
(CompileExpr::visit): Remove IfExprConseqIf{,Let} visitors.
* checks/lints/rust-lint-marklive.h
(MarkLive::visit): Remove IfExprConseqIf visitor.
* checks/errors/rust-const-checker.cc
(ConstChecker::visit): Remove IfExprConseqIf{,Let} visitors.
* checks/errors/rust-const-checker.h
(ConstChecker::visit): Remove IfExprConseqIf{,Let} visitors.
* checks/errors/rust-unsafe-checker.cc
(UnsafeChecker::visit): Remove IfExprConseqIf{,Let} visitors.
* checks/errors/rust-unsafe-checker.h
(UnsafeChecker::visit): Remove IfExprConseqIf{,Let} visitors.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::visit): Remove IfExprConseqIf{,Let} visitors.
* checks/errors/privacy/rust-privacy-reporter.h
(PrivacyReporter::visit): Remove IfExprConseqIf{,Let} visitors.
* hir/tree/rust-hir-expr.h
(class IfExprConseqElse): Make else_block ExprWithBlock.
(class IfExprConseqIf): Remove.
(class IfExprConseqIfLet): Remove.
* hir/tree/rust-hir-full-decls.h
(class IfExprConseqIf): Remove.
(class IfExprConseqIfLet): Remove.
* hir/tree/rust-hir.cc
(IfExprConseqElse::as_string): Adjust output.
(IfExprConseqIf::as_string): Remove.
(IfExprConseqIfLet::as_string): Remove.
(IfExprConseqIf::accept_vis): Remove.
(IfExprConseqIfLet::accept_vis): Remove.
* hir/tree/rust-hir-visitor.h
(HIRFullVisitor::visit): Remove IfExprConseqIf{,Let} visitors.
(HIRFullVisitorBase::visit): Remove IfExprConseqIf{,Let} visitors.
(HIRExpressionVisitor::visit): Remove IfExprConseqIf{,Let} visitors.
* hir/rust-hir-dump.cc
(Dump::visit): Remove IfExprConseqIf{,Let} visitors.
* hir/rust-hir-dump.h
(Dump::visit): Remove IfExprConseqIf{,Let} visitors.
* hir/rust-ast-lower.cc
(ASTLoweringIfBlock::visit): Replace HIR::IfExprConseqIf with HIR::IfExprConseqElse.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc/rust/hir')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower.cc | 9 | ||||
-rw-r--r-- | gcc/rust/hir/rust-hir-dump.cc | 6 | ||||
-rw-r--r-- | gcc/rust/hir/rust-hir-dump.h | 2 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 146 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-full-decls.h | 2 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-visitor.h | 6 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir.cc | 46 |
7 files changed, 10 insertions, 207 deletions
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index 2e25be7..36dd1a9 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -221,11 +221,10 @@ ASTLoweringIfBlock::visit (AST::IfExprConseqIf &expr) mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); - translated - = new HIR::IfExprConseqIf (mapping, std::unique_ptr<HIR::Expr> (condition), - std::unique_ptr<HIR::BlockExpr> (block), - std::unique_ptr<HIR::IfExpr> (conseq_if_expr), - expr.get_locus ()); + translated = new HIR::IfExprConseqElse ( + mapping, std::unique_ptr<HIR::Expr> (condition), + std::unique_ptr<HIR::BlockExpr> (block), + std::unique_ptr<HIR::ExprWithBlock> (conseq_if_expr), expr.get_locus ()); } void diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index a7aa16a..f823e86 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -309,12 +309,6 @@ void Dump::visit (IfExprConseqElse &) {} void -Dump::visit (IfExprConseqIf &) -{} -void -Dump::visit (IfExprConseqIfLet &) -{} -void Dump::visit (IfLetExpr &) {} void diff --git a/gcc/rust/hir/rust-hir-dump.h b/gcc/rust/hir/rust-hir-dump.h index 145a6a1..7aefb9e 100644 --- a/gcc/rust/hir/rust-hir-dump.h +++ b/gcc/rust/hir/rust-hir-dump.h @@ -96,8 +96,6 @@ private: virtual void visit (ForLoopExpr &) override; virtual void visit (IfExpr &) override; virtual void visit (IfExprConseqElse &) override; - virtual void visit (IfExprConseqIf &) override; - virtual void visit (IfExprConseqIfLet &) override; virtual void visit (IfLetExpr &) override; virtual void visit (IfLetExprConseqElse &) override; virtual void visit (IfLetExprConseqIf &) override; diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index bf10351..9b54b24 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -3276,7 +3276,7 @@ protected: // If expression with an ending "else" expression HIR node (trailing) class IfExprConseqElse : public IfExpr { - std::unique_ptr<BlockExpr> else_block; + std::unique_ptr<ExprWithBlock> else_block; public: std::string as_string () const override; @@ -3284,7 +3284,7 @@ public: IfExprConseqElse (Analysis::NodeMapping mappings, std::unique_ptr<Expr> condition, std::unique_ptr<BlockExpr> if_block, - std::unique_ptr<BlockExpr> else_block, Location locus) + std::unique_ptr<ExprWithBlock> else_block, Location locus) : IfExpr (std::move (mappings), std::move (condition), std::move (if_block), locus), else_block (std::move (else_block)) @@ -3293,7 +3293,7 @@ public: // Copy constructor with clone IfExprConseqElse (IfExprConseqElse const &other) - : IfExpr (other), else_block (other.else_block->clone_block_expr ()) + : IfExpr (other), else_block (other.else_block->clone_expr_with_block ()) {} // Overloaded assignment operator with cloning @@ -3302,7 +3302,7 @@ public: IfExpr::operator= (other); // condition = other.condition->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 (); return *this; } @@ -3316,7 +3316,7 @@ public: void vis_else_block (HIRFullVisitor &vis) { else_block->accept_vis (vis); } - BlockExpr *get_else_block () { return else_block.get (); } + ExprWithBlock *get_else_block () { return else_block.get (); } protected: /* Use covariance to implement clone function as returning this object rather @@ -3341,77 +3341,6 @@ protected: } }; -// If expression with an ending "else if" expression HIR node -class IfExprConseqIf : public IfExpr -{ - std::unique_ptr<IfExpr> conseq_if_expr; - -public: - std::string as_string () const override; - - IfExprConseqIf (Analysis::NodeMapping mappings, - std::unique_ptr<Expr> condition, - std::unique_ptr<BlockExpr> if_block, - std::unique_ptr<IfExpr> conseq_if_expr, Location locus) - : IfExpr (std::move (mappings), std::move (condition), std::move (if_block), - locus), - conseq_if_expr (std::move (conseq_if_expr)) - {} - // outer attributes not allowed - - // Copy constructor with clone - IfExprConseqIf (IfExprConseqIf const &other) - : IfExpr (other), conseq_if_expr (other.conseq_if_expr->clone_if_expr ()) - {} - - // Overloaded assignment operator to use clone - IfExprConseqIf &operator= (IfExprConseqIf const &other) - { - IfExpr::operator= (other); - // condition = other.condition->clone_expr(); - // if_block = other.if_block->clone_block_expr(); - conseq_if_expr = other.conseq_if_expr->clone_if_expr (); - - return *this; - } - - // move constructors - IfExprConseqIf (IfExprConseqIf &&other) = default; - IfExprConseqIf &operator= (IfExprConseqIf &&other) = default; - - void accept_vis (HIRFullVisitor &vis) override; - void accept_vis (HIRExpressionVisitor &vis) override; - - void vis_conseq_if_expr (HIRFullVisitor &vis) - { - conseq_if_expr->accept_vis (vis); - } - - IfExpr *get_conseq_if_expr () { return conseq_if_expr.get (); } - -protected: - /* Use covariance to implement clone function as returning this object rather - * than base */ - IfExprConseqIf *clone_expr_impl () const override - { - return new IfExprConseqIf (*this); - } - - /* Use covariance to implement clone function as returning this object rather - * than base */ - IfExprConseqIf *clone_expr_with_block_impl () const override - { - return new IfExprConseqIf (*this); - } - - /* Use covariance to implement clone function as returning this object rather - * than base */ - IfExprConseqIf *clone_if_expr_impl () const override - { - return new IfExprConseqIf (*this); - } -}; - // Basic "if let" expression HIR node with no else class IfLetExpr : public ExprWithBlock { @@ -3515,71 +3444,6 @@ protected: } }; -// If expression with an ending "else if let" expression HIR node -class IfExprConseqIfLet : public IfExpr -{ - std::unique_ptr<IfLetExpr> if_let_expr; - -public: - std::string as_string () const override; - - IfExprConseqIfLet (Analysis::NodeMapping mappings, - std::unique_ptr<Expr> condition, - std::unique_ptr<BlockExpr> if_block, - std::unique_ptr<IfLetExpr> conseq_if_let_expr, - Location locus) - : IfExpr (std::move (mappings), std::move (condition), std::move (if_block), - locus), - if_let_expr (std::move (conseq_if_let_expr)) - {} - // outer attributes not allowed - - // Copy constructor with clone - IfExprConseqIfLet (IfExprConseqIfLet const &other) - : IfExpr (other), if_let_expr (other.if_let_expr->clone_if_let_expr ()) - {} - - // Overloaded assignment operator to use clone - IfExprConseqIfLet &operator= (IfExprConseqIfLet const &other) - { - IfExpr::operator= (other); - // condition = other.condition->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 - IfExprConseqIfLet (IfExprConseqIfLet &&other) = default; - IfExprConseqIfLet &operator= (IfExprConseqIfLet &&other) = default; - - void accept_vis (HIRFullVisitor &vis) override; - void accept_vis (HIRExpressionVisitor &vis) override; - -protected: - /* Use covariance to implement clone function as returning this object rather - * than base */ - IfExprConseqIfLet *clone_expr_impl () const override - { - return new IfExprConseqIfLet (*this); - } - - /* Use covariance to implement clone function as returning this object rather - * than base */ - IfExprConseqIfLet *clone_expr_with_block_impl () const override - { - return new IfExprConseqIfLet (*this); - } - - /* Use covariance to implement clone function as returning this object rather - * than base */ - IfExprConseqIfLet *clone_if_expr_impl () const override - { - return new IfExprConseqIfLet (*this); - } -}; - /* HIR node representing "if let" expression with an "else" expression at the * end */ class IfLetExprConseqElse : public IfLetExpr diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h index 5e35666..058e620 100644 --- a/gcc/rust/hir/tree/rust-hir-full-decls.h +++ b/gcc/rust/hir/tree/rust-hir-full-decls.h @@ -117,9 +117,7 @@ class WhileLetLoopExpr; class ForLoopExpr; class IfExpr; class IfExprConseqElse; -class IfExprConseqIf; class IfLetExpr; -class IfExprConseqIfLet; class IfLetExprConseqElse; class IfLetExprConseqIf; class IfLetExprConseqIfLet; diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h b/gcc/rust/hir/tree/rust-hir-visitor.h index 037aa01..494365e 100644 --- a/gcc/rust/hir/tree/rust-hir-visitor.h +++ b/gcc/rust/hir/tree/rust-hir-visitor.h @@ -81,8 +81,6 @@ public: virtual void visit (ForLoopExpr &expr) = 0; virtual void visit (IfExpr &expr) = 0; virtual void visit (IfExprConseqElse &expr) = 0; - virtual void visit (IfExprConseqIf &expr) = 0; - virtual void visit (IfExprConseqIfLet &expr) = 0; virtual void visit (IfLetExpr &expr) = 0; virtual void visit (IfLetExprConseqElse &expr) = 0; virtual void visit (IfLetExprConseqIf &expr) = 0; @@ -224,8 +222,6 @@ public: virtual void visit (ForLoopExpr &) override {} virtual void visit (IfExpr &) override {} virtual void visit (IfExprConseqElse &) override {} - virtual void visit (IfExprConseqIf &) override {} - virtual void visit (IfExprConseqIfLet &) override {} virtual void visit (IfLetExpr &) override {} virtual void visit (IfLetExprConseqElse &) override {} virtual void visit (IfLetExprConseqIf &) override {} @@ -460,8 +456,6 @@ public: virtual void visit (ForLoopExpr &expr) = 0; virtual void visit (IfExpr &expr) = 0; virtual void visit (IfExprConseqElse &expr) = 0; - virtual void visit (IfExprConseqIf &expr) = 0; - virtual void visit (IfExprConseqIfLet &expr) = 0; virtual void visit (IfLetExpr &expr) = 0; virtual void visit (IfLetExprConseqElse &expr) = 0; virtual void visit (IfLetExprConseqIf &expr) = 0; diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc index 1c168db..c0532d8 100644 --- a/gcc/rust/hir/tree/rust-hir.cc +++ b/gcc/rust/hir/tree/rust-hir.cc @@ -1525,27 +1525,7 @@ IfExprConseqElse::as_string () const { std::string str = IfExpr::as_string (); - str += "\n Else block expr: " + else_block->as_string (); - - return str; -} - -std::string -IfExprConseqIf::as_string () const -{ - std::string str = IfExpr::as_string (); - - str += "\n Else if expr: \n " + conseq_if_expr->as_string (); - - return str; -} - -std::string -IfExprConseqIfLet::as_string () const -{ - std::string str = IfExpr::as_string (); - - str += "\n Else if let expr: \n " + if_let_expr->as_string (); + str += "\n Else expr: " + else_block->as_string (); return str; } @@ -4138,18 +4118,6 @@ IfExprConseqElse::accept_vis (HIRFullVisitor &vis) } void -IfExprConseqIf::accept_vis (HIRFullVisitor &vis) -{ - vis.visit (*this); -} - -void -IfExprConseqIfLet::accept_vis (HIRFullVisitor &vis) -{ - vis.visit (*this); -} - -void IfLetExpr::accept_vis (HIRFullVisitor &vis) { vis.visit (*this); @@ -4948,18 +4916,6 @@ IfLetExpr::accept_vis (HIRExpressionVisitor &vis) } void -IfExprConseqIfLet::accept_vis (HIRExpressionVisitor &vis) -{ - vis.visit (*this); -} - -void -IfExprConseqIf::accept_vis (HIRExpressionVisitor &vis) -{ - vis.visit (*this); -} - -void IfExprConseqElse::accept_vis (HIRExpressionVisitor &vis) { vis.visit (*this); |