public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8061] gccrs: hir: Lower labelled block
@ 2024-01-16 18:15 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 18:15 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:a66df6197e84b6817d20c494bee7242bbfab0369
commit r14-8061-ga66df6197e84b6817d20c494bee7242bbfab0369
Author: Jakub Dupak <dev@jakubdupak.com>
Date: Mon Oct 16 15:17:33 2023 +0200
gccrs: hir: Lower labelled block
gcc/rust/ChangeLog:
* hir/rust-ast-lower.cc (ASTLoweringBlock::visit): Call loop lowering and add it to constr.
* hir/tree/rust-hir-expr.h (class LoopLabel): Move before BlockExpr and add to BlockExpr.
Diff:
---
gcc/rust/hir/rust-ast-lower.cc | 6 ++--
gcc/rust/hir/tree/rust-hir-expr.h | 70 +++++++++++++++++++++------------------
2 files changed, 41 insertions(+), 35 deletions(-)
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc
index 308a2ec83a4..d730f29b13a 100644
--- a/gcc/rust/hir/rust-ast-lower.cc
+++ b/gcc/rust/hir/rust-ast-lower.cc
@@ -95,6 +95,8 @@ ASTLowering::go ()
void
ASTLoweringBlock::visit (AST::BlockExpr &expr)
{
+ auto label = lower_loop_label (expr.get_label ());
+
std::vector<std::unique_ptr<HIR::Stmt>> block_stmts;
bool block_did_terminate = false;
@@ -143,8 +145,8 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr)
= new HIR::BlockExpr (mapping, std::move (block_stmts),
std::unique_ptr<HIR::ExprWithoutBlock> (tail_expr),
tail_reachable, expr.get_inner_attrs (),
- expr.get_outer_attrs (), expr.get_start_locus (),
- expr.get_end_locus ());
+ expr.get_outer_attrs (), label,
+ expr.get_start_locus (), expr.get_end_locus ());
terminated = block_did_terminate;
}
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 3bfadbf2dc0..6d26287dbe3 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -28,6 +28,34 @@
namespace Rust {
namespace HIR {
+// Loop label expression HIR node used with break and continue expressions
+// TODO: inline?
+class LoopLabel /*: public Node*/
+{
+ Lifetime label; // or type LIFETIME_OR_LABEL
+
+ location_t locus;
+
+ Analysis::NodeMapping mappings;
+
+public:
+ std::string as_string () const;
+
+ LoopLabel (Analysis::NodeMapping mapping, Lifetime loop_label,
+ location_t locus)
+ : label (std::move (loop_label)), locus (locus), mappings (mapping)
+ {}
+
+ // Returns whether the LoopLabel is in an error state.
+ bool is_error () const { return label.is_error (); }
+
+ location_t get_locus () const { return locus; }
+
+ Analysis::NodeMapping &get_mappings () { return mappings; }
+
+ Lifetime &get_lifetime () { return label; }
+};
+
// HIR node for an expression with an accompanying block - abstract
class ExprWithBlock : public Expr
{
@@ -2121,6 +2149,7 @@ public:
std::vector<std::unique_ptr<Stmt> > statements;
std::unique_ptr<Expr> expr;
bool tail_reachable;
+ LoopLabel label;
location_t start_locus;
location_t end_locus;
@@ -2140,19 +2169,19 @@ public:
std::vector<std::unique_ptr<Stmt> > block_statements,
std::unique_ptr<Expr> block_expr, bool tail_reachable,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- location_t start_locus, location_t end_locus)
+ LoopLabel label, location_t start_locus, location_t end_locus)
: ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
WithInnerAttrs (std::move (inner_attribs)),
statements (std::move (block_statements)), expr (std::move (block_expr)),
- tail_reachable (tail_reachable), start_locus (start_locus),
- end_locus (end_locus)
+ tail_reachable (tail_reachable), label (std::move (label)),
+ start_locus (start_locus), end_locus (end_locus)
{}
// Copy constructor with clone
BlockExpr (BlockExpr const &other)
: ExprWithBlock (other), /*statements(other.statements),*/
- WithInnerAttrs (other.inner_attrs), start_locus (other.start_locus),
- end_locus (other.end_locus)
+ WithInnerAttrs (other.inner_attrs), label (other.label),
+ start_locus (other.start_locus), end_locus (other.end_locus)
{
// guard to protect from null pointer dereference
if (other.expr != nullptr)
@@ -2211,6 +2240,9 @@ public:
return ExprType::Block;
}
+ bool has_label () const { return !label.is_error (); }
+ LoopLabel &get_label () { return label; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2835,34 +2867,6 @@ protected:
}
};
-// Loop label expression HIR node used with break and continue expressions
-// TODO: inline?
-class LoopLabel /*: public Node*/
-{
- Lifetime label; // or type LIFETIME_OR_LABEL
-
- location_t locus;
-
- Analysis::NodeMapping mappings;
-
-public:
- std::string as_string () const;
-
- LoopLabel (Analysis::NodeMapping mapping, Lifetime loop_label,
- location_t locus)
- : label (std::move (loop_label)), locus (locus), mappings (mapping)
- {}
-
- // Returns whether the LoopLabel is in an error state.
- bool is_error () const { return label.is_error (); }
-
- location_t get_locus () const { return locus; }
-
- Analysis::NodeMapping &get_mappings () { return mappings; }
-
- Lifetime &get_lifetime () { return label; }
-};
-
// Base loop expression HIR node - aka LoopExpr
class BaseLoopExpr : public ExprWithBlock
{
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-16 18:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 18:15 [gcc r14-8061] gccrs: hir: Lower labelled block Arthur Cohen
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).