aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast
diff options
context:
space:
mode:
authorOwen Avery <powerboat9.gamer@gmail.com>2023-03-15 23:05:07 -0400
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:28:46 +0100
commitd88234af9ffa2f51e498dc518ccab8b1c293a148 (patch)
tree30eb657d2ad209077f4317b305d5c5b26f9720dd /gcc/rust/ast
parent5444ed27a8139d5d584859321a88cadaafdb1cb0 (diff)
downloadgcc-d88234af9ffa2f51e498dc518ccab8b1c293a148.zip
gcc-d88234af9ffa2f51e498dc518ccab8b1c293a148.tar.gz
gcc-d88234af9ffa2f51e498dc518ccab8b1c293a148.tar.bz2
gccrs: Unify AST::IfExprConseqIf{,Let} into AST::IfExprConseqElse
This simplifies the AST's representation of if-statements to match the HIR. gcc/rust/ChangeLog: * ast/rust-expr.h (class IfExprConseqElse): Make else_block ExprWithBlock. (class IfExprConseqIf): Remove. (class IfExprConseqIfLet): Remove. * ast/rust-ast-full-decls.h (class IfExprConseqIf): Remove. (class IfExprConseqIfLet): Remove. * ast/rust-ast.cc (IfExprConseqElse::as_string): Adjust output. (IfExprConseqIf::as_string): Remove. (IfExprConseqIfLet::as_string): Remove. (IfExprConseqIf::accept_vis): Remove. (IfExprConseqIfLet::accept_vis): Remove. * ast/rust-ast-visitor.h (ASTVisitor::visit): Remove IfExprConseqIf{,Let} visitors. * ast/rust-ast-tokenstream.cc (TokenStream::visit): Likewise. * ast/rust-ast-tokenstream.h (TokenStream::visit): Likewise. * ast/rust-ast-dump.cc (Dump::visit): Likewise. * ast/rust-ast-dump.h (Dump::visit): Likewise. * checks/errors/rust-feature-gate.h (FeatureGate::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. * resolve/rust-ast-resolve-expr.h (ResolveExpr::visit): Remove IfExprConseqIf visitor. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Remove IfExprConseqIf{,Let} visitors. * 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. * hir/rust-ast-lower-block.h (ASTLoweringIfBlock::visit): Remove IfExprConseqIf visitor. (ASTLoweringExprWithBlock::visit): Likewise. * hir/rust-ast-lower.cc (ASTLoweringIfBlock::visit): Remove IfExprConseqIf visitor, adjust IfExprConseqElse lowering. * hir/rust-ast-lower-expr.h (ASTLoweringExpr::visit): Remove IfExprConseqIf visitor. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * parse/rust-parse-impl.h (Parser::parse_if_expr): Replace IfExprConseqIf{,Let} with IfExprConseqElse. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r--gcc/rust/ast/rust-ast-dump.cc16
-rw-r--r--gcc/rust/ast/rust-ast-dump.h2
-rw-r--r--gcc/rust/ast/rust-ast-full-decls.h2
-rw-r--r--gcc/rust/ast/rust-ast-tokenstream.cc19
-rw-r--r--gcc/rust/ast/rust-ast-tokenstream.h2
-rw-r--r--gcc/rust/ast/rust-ast-visitor.h2
-rw-r--r--gcc/rust/ast/rust-ast.cc34
-rw-r--r--gcc/rust/ast/rust-expr.h127
8 files changed, 6 insertions, 198 deletions
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index d25a2a4..12cbfac 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -937,22 +937,6 @@ Dump::visit (IfExprConseqElse &expr)
}
void
-Dump::visit (IfExprConseqIf &expr)
-{
- stream << "if ";
- visit (expr.get_condition_expr ());
- stream << " ";
- visit (expr.get_if_block ());
- stream << indentation << "else ";
- // The "if" part of the "else if" is printed by the next visitor
- visit (expr.get_conseq_if_expr ());
-}
-
-void
-Dump::visit (IfExprConseqIfLet &)
-{}
-
-void
Dump::visit (IfLetExpr &)
{}
diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
index 26f7208..a48d4761 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -184,8 +184,6 @@ private:
void visit (ForLoopExpr &expr);
void visit (IfExpr &expr);
void visit (IfExprConseqElse &expr);
- void visit (IfExprConseqIf &expr);
- void visit (IfExprConseqIfLet &expr);
void visit (IfLetExpr &expr);
void visit (IfLetExprConseqElse &expr);
void visit (IfLetExprConseqIf &expr);
diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h
index b3f71c0..94691f9 100644
--- a/gcc/rust/ast/rust-ast-full-decls.h
+++ b/gcc/rust/ast/rust-ast-full-decls.h
@@ -135,9 +135,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/ast/rust-ast-tokenstream.cc b/gcc/rust/ast/rust-ast-tokenstream.cc
index d4e23bf..8c54141 100644
--- a/gcc/rust/ast/rust-ast-tokenstream.cc
+++ b/gcc/rust/ast/rust-ast-tokenstream.cc
@@ -1428,25 +1428,6 @@ TokenStream::visit (IfExprConseqElse &expr)
}
void
-TokenStream::visit (IfExprConseqIf &expr)
-{
- visit (static_cast<IfExpr &> (expr));
- indentation ();
- tokens.push_back (Rust::Token::make (ELSE, expr.get_locus ()));
- // The "if" part of the "else if" is printed by the next visitor
- visit (expr.get_conseq_if_expr ());
-}
-
-void
-TokenStream::visit (IfExprConseqIfLet &expr)
-{
- visit (static_cast<IfExpr &> (expr));
- indentation ();
- tokens.push_back (Rust::Token::make (ELSE, expr.get_locus ()));
- visit (expr.get_conseq_if_let_expr ());
-}
-
-void
TokenStream::visit (IfLetExpr &expr)
{
tokens.push_back (Rust::Token::make (IF, expr.get_locus ()));
diff --git a/gcc/rust/ast/rust-ast-tokenstream.h b/gcc/rust/ast/rust-ast-tokenstream.h
index 8ce25e1..83fdece 100644
--- a/gcc/rust/ast/rust-ast-tokenstream.h
+++ b/gcc/rust/ast/rust-ast-tokenstream.h
@@ -198,8 +198,6 @@ private:
void visit (ForLoopExpr &expr);
void visit (IfExpr &expr);
void visit (IfExprConseqElse &expr);
- void visit (IfExprConseqIf &expr);
- void visit (IfExprConseqIfLet &expr);
void visit (IfLetExpr &expr);
void visit (IfLetExprConseqElse &expr);
void visit (IfLetExprConseqIf &expr);
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index 6990d61..621f09e 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -115,8 +115,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/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index feb60eb..dbbeda3 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -1638,27 +1638,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;
}
@@ -4576,18 +4556,6 @@ IfExprConseqElse::accept_vis (ASTVisitor &vis)
}
void
-IfExprConseqIf::accept_vis (ASTVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
-IfExprConseqIfLet::accept_vis (ASTVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
IfLetExpr::accept_vis (ASTVisitor &vis)
{
vis.visit (*this);
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index bcf5ab3..f91d9e9 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -3753,14 +3753,14 @@ protected:
// If expression with an ending "else" expression AST 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;
IfExprConseqElse (std::unique_ptr<Expr> condition,
std::unique_ptr<BlockExpr> if_block,
- std::unique_ptr<BlockExpr> else_block,
+ std::unique_ptr<ExprWithBlock> else_block,
std::vector<Attribute> outer_attrs, Location locus)
: IfExpr (std::move (condition), std::move (if_block),
std::move (outer_attrs), locus),
@@ -3770,7 +3770,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
@@ -3779,7 +3779,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;
}
@@ -3793,7 +3793,7 @@ public:
void vis_else_block (ASTVisitor &vis) { else_block->accept_vis (vis); }
// 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;
@@ -3808,67 +3808,6 @@ protected:
}
};
-// If expression with an ending "else if" expression AST node
-class IfExprConseqIf : public IfExpr
-{
- std::unique_ptr<IfExpr> conseq_if_expr;
-
-public:
- std::string as_string () const override;
-
- IfExprConseqIf (std::unique_ptr<Expr> condition,
- std::unique_ptr<BlockExpr> if_block,
- std::unique_ptr<IfExpr> conseq_if_expr,
- std::vector<Attribute> outer_attrs, Location locus)
- : IfExpr (std::move (condition), std::move (if_block),
- std::move (outer_attrs), 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 (ASTVisitor &vis) override;
-
- void vis_conseq_if_expr (ASTVisitor &vis)
- {
- conseq_if_expr->accept_vis (vis);
- }
-
- // TODO: is this better? Or is a "vis_block" better?
- std::unique_ptr<IfExpr> &get_conseq_if_expr ()
- {
- rust_assert (conseq_if_expr != nullptr);
- return conseq_if_expr;
- }
-
-protected:
- /* 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 AST node with no else
class IfLetExpr : public ExprWithBlock
{
@@ -4002,62 +3941,6 @@ protected:
}
};
-// If expression with an ending "else if let" expression AST node
-class IfExprConseqIfLet : public IfExpr
-{
- std::unique_ptr<IfLetExpr> if_let_expr;
-
-public:
- std::string as_string () const override;
-
- IfExprConseqIfLet (std::unique_ptr<Expr> condition,
- std::unique_ptr<BlockExpr> if_block,
- std::unique_ptr<IfLetExpr> conseq_if_let_expr,
- std::vector<Attribute> outer_attrs, Location locus)
- : IfExpr (std::move (condition), std::move (if_block),
- std::move (outer_attrs), 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 (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 */
- IfExprConseqIfLet *clone_if_expr_impl () const override
- {
- return new IfExprConseqIfLet (*this);
- }
-};
-
/* AST node representing "if let" expression with an "else" expression at the
* end */
class IfLetExprConseqElse : public IfLetExpr