aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/tree
diff options
context:
space:
mode:
authorOwen Avery <powerboat9.gamer@gmail.com>2023-03-15 16:35:47 -0400
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:21:12 +0100
commit265d8555fe3ad38755e64a6b9880521c7f3a3cc7 (patch)
treefff5e9683b2eb2b4da0fb2d23a5448980145dfc8 /gcc/rust/hir/tree
parentf821a019e624555397b539e864cc145057922a63 (diff)
downloadgcc-265d8555fe3ad38755e64a6b9880521c7f3a3cc7.zip
gcc-265d8555fe3ad38755e64a6b9880521c7f3a3cc7.tar.gz
gcc-265d8555fe3ad38755e64a6b9880521c7f3a3cc7.tar.bz2
gccrs: 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/tree')
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h146
-rw-r--r--gcc/rust/hir/tree/rust-hir-full-decls.h2
-rw-r--r--gcc/rust/hir/tree/rust-hir-visitor.h6
-rw-r--r--gcc/rust/hir/tree/rust-hir.cc46
4 files changed, 6 insertions, 194 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 1ed97ef..b93040a 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 32c5c43..64ffe5f 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 f516f05..e597983 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 926712c..96ec5a2 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);