public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Remove gcc abstraction for expression statement
@ 2022-06-08 12:14 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:14 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:17d4a75971a0afec0a9a2bdd123779431105b850
commit 17d4a75971a0afec0a9a2bdd123779431105b850
Author: Philip Herron <philip.herron@embecosm.com>
Date: Thu Mar 3 09:13:53 2022 +0000
Remove gcc abstraction for expression statement
The gcc abstraction contained a method of turning expressions into
statements which used to contain their own types like Bstatement,
Bexpression this produced awkward interfaces which we no longer require.
This is part of a patch series to introduce the CPP front-end
convert_to_void to port over the support for the nodiscard attribute which
maps nicely over to Rust's must_use attribute.
Diff:
---
gcc/rust/backend/rust-compile-base.cc | 10 +++-------
gcc/rust/backend/rust-compile-expr.cc | 15 ++++++---------
gcc/rust/backend/rust-compile-expr.h | 30 ++++++++++--------------------
gcc/rust/backend/rust-compile-stmt.h | 5 ++---
gcc/rust/backend/rust-compile.cc | 13 +++----------
gcc/rust/rust-backend.h | 5 +----
gcc/rust/rust-gcc.cc | 21 ++++-----------------
7 files changed, 29 insertions(+), 70 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 33e4c267f12..3fc7360c5f7 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -262,9 +262,7 @@ HIRCompileBase::compile_function_body (Context *ctx, tree fndecl,
auto compiled_expr = CompileStmt::Compile (s.get (), ctx);
if (compiled_expr != nullptr)
{
- tree compiled_stmt
- = ctx->get_backend ()->expression_statement (fndecl, compiled_expr);
- ctx->add_statement (compiled_stmt);
+ ctx->add_statement (compiled_expr);
}
}
@@ -289,10 +287,8 @@ HIRCompileBase::compile_function_body (Context *ctx, tree fndecl,
}
else
{
- tree final_stmt
- = ctx->get_backend ()->expression_statement (fndecl,
- compiled_expr);
- ctx->add_statement (final_stmt);
+ // FIXME can this actually happen?
+ ctx->add_statement (compiled_expr);
}
}
}
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index bf47661f427..6d50c3fcf9f 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -63,8 +63,6 @@ CompileExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
void
CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
{
- fncontext fn = ctx->peek_fn ();
-
auto op = expr.get_expr_type ();
auto lhs = CompileExpr::Compile (expr.get_left_expr ().get (), ctx);
auto rhs = CompileExpr::Compile (expr.get_right_expr ().get (), ctx);
@@ -82,10 +80,7 @@ CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
= resolve_operator_overload (lang_item_type, expr, lhs, rhs,
expr.get_left_expr ().get (),
expr.get_right_expr ().get ());
- auto assignment
- = ctx->get_backend ()->expression_statement (fn.fndecl,
- compound_assignment);
- ctx->add_statement (assignment);
+ ctx->add_statement (compound_assignment);
return;
}
@@ -94,7 +89,7 @@ CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
= ctx->get_backend ()->arithmetic_or_logical_expression (op, lhs, rhs,
expr.get_locus ());
tree assignment
- = ctx->get_backend ()->assignment_statement (fn.fndecl, lhs, operator_expr,
+ = ctx->get_backend ()->assignment_statement (lhs, operator_expr,
expr.get_locus ());
ctx->add_statement (assignment);
}
@@ -304,8 +299,10 @@ CompileExpr::visit (HIR::MatchExpr &expr)
{
tree result_reference
= ctx->get_backend ()->var_expression (tmp, arm_locus);
- tree assignment = ctx->get_backend ()->assignment_statement (
- fnctx.fndecl, result_reference, kase_expr_tree, arm_locus);
+ tree assignment
+ = ctx->get_backend ()->assignment_statement (result_reference,
+ kase_expr_tree,
+ arm_locus);
ctx->add_statement (assignment);
}
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 3cc51d465cf..8aeb703aa03 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -169,7 +169,6 @@ public:
void visit (HIR::AssignmentExpr &expr) override
{
- fncontext fn = ctx->peek_fn ();
auto lvalue = CompileExpr::Compile (expr.get_lhs (), ctx);
auto rvalue = CompileExpr::Compile (expr.get_rhs (), ctx);
@@ -191,7 +190,7 @@ public:
expr.get_rhs ()->get_locus ());
tree assignment
- = ctx->get_backend ()->assignment_statement (fn.fndecl, lvalue, rvalue,
+ = ctx->get_backend ()->assignment_statement (lvalue, rvalue,
expr.get_locus ());
ctx->add_statement (assignment);
@@ -594,9 +593,7 @@ public:
= CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
tree loop_expr
= ctx->get_backend ()->loop_expression (code_block, expr.get_locus ());
- tree loop_stmt
- = ctx->get_backend ()->expression_statement (fnctx.fndecl, loop_expr);
- ctx->add_statement (loop_stmt);
+ ctx->add_statement (loop_expr);
if (tmp != NULL)
{
@@ -645,9 +642,7 @@ public:
= CompileExpr::Compile (expr.get_predicate_expr ().get (), ctx);
tree exit_expr
= ctx->get_backend ()->exit_expression (condition, expr.get_locus ());
- tree break_stmt
- = ctx->get_backend ()->expression_statement (fnctx.fndecl, exit_expr);
- ctx->add_statement (break_stmt);
+ ctx->add_statement (exit_expr);
tree code_block_stmt
= CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
@@ -659,14 +654,11 @@ public:
tree loop_expr
= ctx->get_backend ()->loop_expression (loop_block, expr.get_locus ());
- tree loop_stmt
- = ctx->get_backend ()->expression_statement (fnctx.fndecl, loop_expr);
- ctx->add_statement (loop_stmt);
+ ctx->add_statement (loop_expr);
}
void visit (HIR::BreakExpr &expr) override
{
- fncontext fnctx = ctx->peek_fn ();
if (expr.has_break_expr ())
{
tree compiled_expr
@@ -676,8 +668,10 @@ public:
tree result_reference = ctx->get_backend ()->var_expression (
loop_result_holder, expr.get_expr ()->get_locus ());
- tree assignment = ctx->get_backend ()->assignment_statement (
- fnctx.fndecl, result_reference, compiled_expr, expr.get_locus ());
+ tree assignment
+ = ctx->get_backend ()->assignment_statement (result_reference,
+ compiled_expr,
+ expr.get_locus ());
ctx->add_statement (assignment);
}
@@ -721,9 +715,7 @@ public:
tree exit_expr = ctx->get_backend ()->exit_expression (
ctx->get_backend ()->boolean_constant_expression (true),
expr.get_locus ());
- tree break_stmt
- = ctx->get_backend ()->expression_statement (fnctx.fndecl, exit_expr);
- ctx->add_statement (break_stmt);
+ ctx->add_statement (exit_expr);
}
}
@@ -761,9 +753,7 @@ public:
}
}
- tree goto_label
- = ctx->get_backend ()->goto_statement (label, expr.get_locus ());
- ctx->add_statement (goto_label);
+ translated = ctx->get_backend ()->goto_statement (label, expr.get_locus ());
}
void visit (HIR::BorrowExpr &expr) override;
diff --git a/gcc/rust/backend/rust-compile-stmt.h b/gcc/rust/backend/rust-compile-stmt.h
index 2dfb520980f..0f69fb0515a 100644
--- a/gcc/rust/backend/rust-compile-stmt.h
+++ b/gcc/rust/backend/rust-compile-stmt.h
@@ -90,9 +90,8 @@ public:
auto fnctx = ctx->peek_fn ();
if (ty->is_unit ())
{
- tree expr_stmt
- = ctx->get_backend ()->expression_statement (fnctx.fndecl, init);
- ctx->add_statement (expr_stmt);
+ // FIXME this feels wrong
+ ctx->add_statement (init);
}
else
{
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index fcbfc05a6c5..6aec0504a04 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -82,10 +82,7 @@ CompileBlock::visit (HIR::BlockExpr &expr)
auto compiled_expr = CompileStmt::Compile (s.get (), ctx);
if (compiled_expr != nullptr)
{
- tree compiled_stmt
- = ctx->get_backend ()->expression_statement (fnctx.fndecl,
- compiled_expr);
- ctx->add_statement (compiled_stmt);
+ ctx->add_statement (compiled_expr);
}
}
@@ -98,10 +95,7 @@ CompileBlock::visit (HIR::BlockExpr &expr)
{
if (result == nullptr)
{
- tree final_stmt
- = ctx->get_backend ()->expression_statement (fnctx.fndecl,
- compiled_expr);
- ctx->add_statement (final_stmt);
+ ctx->add_statement (compiled_expr);
}
else
{
@@ -109,8 +103,7 @@ CompileBlock::visit (HIR::BlockExpr &expr)
result, expr.get_final_expr ()->get_locus ());
tree assignment
- = ctx->get_backend ()->assignment_statement (fnctx.fndecl,
- result_reference,
+ = ctx->get_backend ()->assignment_statement (result_reference,
compiled_expr,
expr.get_locus ());
ctx->add_statement (assignment);
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index fe809c911e2..fca09b2bd68 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -292,16 +292,13 @@ public:
// Statements.
- // Create an expression statement within the specified function.
- virtual tree expression_statement (tree, tree) = 0;
-
// Create a variable initialization statement in the specified
// function. This initializes a local variable at the point in the
// program flow where it is declared.
virtual tree init_statement (tree, Bvariable *var, tree init) = 0;
// Create an assignment statement within the specified function.
- virtual tree assignment_statement (tree, tree lhs, tree rhs, Location) = 0;
+ virtual tree assignment_statement (tree lhs, tree rhs, Location) = 0;
// Create a return statement, passing the representation of the
// function and the list of values to return.
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 812fd55c61a..dfdfe8a5d26 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -249,11 +249,9 @@ public:
// Statements.
- tree expression_statement (tree, tree);
-
tree init_statement (tree, Bvariable *var, tree init);
- tree assignment_statement (tree, tree lhs, tree rhs, Location);
+ tree assignment_statement (tree lhs, tree rhs, Location);
tree return_statement (tree, const std::vector<tree> &, Location);
@@ -1837,14 +1835,6 @@ Gcc_backend::call_expression (tree, // containing fcn for call
return ret;
}
-// An expression as a statement.
-
-tree
-Gcc_backend::expression_statement (tree, tree expr)
-{
- return expr;
-}
-
// Variable initialization.
tree
@@ -1880,8 +1870,7 @@ Gcc_backend::init_statement (tree, Bvariable *var, tree init_tree)
// Assignment.
tree
-Gcc_backend::assignment_statement (tree bfn, tree lhs, tree rhs,
- Location location)
+Gcc_backend::assignment_statement (tree lhs, tree rhs, Location location)
{
if (lhs == error_mark_node || rhs == error_mark_node)
return error_mark_node;
@@ -1896,8 +1885,7 @@ Gcc_backend::assignment_statement (tree bfn, tree lhs, tree rhs,
|| int_size_in_bytes (TREE_TYPE (lhs)) == 0
|| TREE_TYPE (rhs) == void_type_node
|| int_size_in_bytes (TREE_TYPE (rhs)) == 0)
- return this->compound_statement (this->expression_statement (bfn, lhs),
- this->expression_statement (bfn, rhs));
+ return this->compound_statement (lhs, rhs);
rhs = this->convert_tree (TREE_TYPE (lhs), rhs, location);
@@ -2527,8 +2515,7 @@ Gcc_backend::temporary_variable (tree fndecl, tree bind_tree, tree type_tree,
if (init_tree != NULL_TREE
&& (this->type_size (type_tree) == 0
|| TREE_TYPE (init_tree) == void_type_node))
- *pstatement = this->compound_statement (
- this->expression_statement (fndecl, init_tree), *pstatement);
+ *pstatement = this->compound_statement (init_tree, *pstatement);
return new Bvariable (var);
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:14 [gcc/devel/rust/master] Remove gcc abstraction for expression statement Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).