From d2f92e6a73338c986601a071b8641c051e700aba Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Fri, 5 Nov 2021 12:31:31 +0000 Subject: Add is_item helper to AST and HIR BlockExpr can contain Items and Stmts this allows us to differentiate between them on the Stmt level. --- gcc/rust/hir/tree/rust-hir-stmt.h | 6 ++++++ gcc/rust/hir/tree/rust-hir.h | 4 ++++ 2 files changed, 10 insertions(+) (limited to 'gcc/rust/hir') diff --git a/gcc/rust/hir/tree/rust-hir-stmt.h b/gcc/rust/hir/tree/rust-hir-stmt.h index cc61142..29e98fa 100644 --- a/gcc/rust/hir/tree/rust-hir-stmt.h +++ b/gcc/rust/hir/tree/rust-hir-stmt.h @@ -41,6 +41,8 @@ public: void accept_vis (HIRVisitor &vis) override; + bool is_item () const override final { return false; } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -119,6 +121,8 @@ public: HIR::Pattern *get_pattern () { return variables_pattern.get (); } + bool is_item () const override final { return false; } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -136,6 +140,8 @@ class ExprStmt : public Stmt public: Location get_locus () const override final { return locus; } + bool is_item () const override final { return false; } + protected: ExprStmt (Analysis::NodeMapping mappings, Location locus) : Stmt (std::move (mappings)), locus (locus) diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index d7977b4..d001eb1 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -104,6 +104,8 @@ public: const Analysis::NodeMapping &get_mappings () const { return mappings; } + virtual bool is_item () const = 0; + protected: Stmt (Analysis::NodeMapping mappings) : mappings (std::move (mappings)) {} @@ -140,6 +142,8 @@ public: AST::AttrVec &get_outer_attrs () { return outer_attrs; } const AST::AttrVec &get_outer_attrs () const { return outer_attrs; } + bool is_item () const override final { return true; } + protected: // Constructor Item (Analysis::NodeMapping mappings, -- cgit v1.1 From 17dc14cb4b0819532376a22b592b26dd6ffc364f Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Fri, 5 Nov 2021 12:32:44 +0000 Subject: Support forward declared items within blocks This changes the BlockExpr resolution to iterate Items first, then the Stmts. This could be handled in HIR by desugaring the BlockExpr by lowering the block into { ; ; } would also work. But the HIR lowering of blocks is a little messy right now and we need to clean up the unreachable lint. Fixes #531 --- gcc/rust/hir/tree/rust-hir-expr.h | 9 --------- 1 file changed, 9 deletions(-) (limited to 'gcc/rust/hir') diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index c472cab..575d1f6 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -2007,15 +2007,6 @@ public: void accept_vis (HIRVisitor &vis) override; - void iterate_stmts (std::function cb) - { - for (auto it = statements.begin (); it != statements.end (); it++) - { - if (!cb (it->get ())) - return; - } - } - bool is_final_stmt (Stmt *stmt) { return statements.back ().get () == stmt; } Location get_closing_locus () -- cgit v1.1