From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 60936385C422; Tue, 16 Jan 2024 18:15:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 60936385C422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705428914; bh=iWF+NzehnhFlBn3Ux6iqOu7d9gxMdbdzVxH5rlNNgYk=; h=From:To:Subject:Date:From; b=RpaFHo5sIKwtiMVnpsIR0kbx4WImEelxqKbC7Wrz3Hka9T64RRxtpTBXVotwEda6b FGmVij4yolHh0kgwRFHKJGAB5dfnwwNj9cKKOZeGhykRI9GZw0J0msik5wUwbBq0fK fpar12oNe7yJMhQ8X/vZNvAIHDT317RH20GLttbs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8061] gccrs: hir: Lower labelled block X-Act-Checkin: gcc X-Git-Author: Jakub Dupak X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 3b1d27f78720bf4cf3857f31a4d26226e2581fb1 X-Git-Newrev: a66df6197e84b6817d20c494bee7242bbfab0369 Message-Id: <20240116181514.60936385C422@sourceware.org> Date: Tue, 16 Jan 2024 18:15:14 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a66df6197e84b6817d20c494bee7242bbfab0369 commit r14-8061-ga66df6197e84b6817d20c494bee7242bbfab0369 Author: Jakub Dupak 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> 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 (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 > statements; std::unique_ptr expr; bool tail_reachable; + LoopLabel label; location_t start_locus; location_t end_locus; @@ -2140,19 +2169,19 @@ public: std::vector > block_statements, std::unique_ptr 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 {