diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-01-15 11:20:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-15 11:20:18 +0000 |
commit | b02824c6a798a78657568e7d831bd10529d63e37 (patch) | |
tree | 83fd67a961ce521c6350e9c47bcbe3aa94965751 /gcc/rust/hir | |
parent | b21caeb3af4313016afeb94a91956e8fc4c2656d (diff) | |
parent | 7d456b882a8f72b6fb3bdb0e71367811770b4413 (diff) | |
download | gcc-b02824c6a798a78657568e7d831bd10529d63e37.zip gcc-b02824c6a798a78657568e7d831bd10529d63e37.tar.gz gcc-b02824c6a798a78657568e7d831bd10529d63e37.tar.bz2 |
Merge #874
874: Track end locus of BlockExpr r=philberty a=dafaust
Capture the closing locus of a block during parsing, and remove the old
hack to get the final statement locus within the block now that it is
properly tracked.
Fixes #864
Co-authored-by: David Faust <david.faust@oracle.com>
Diffstat (limited to 'gcc/rust/hir')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower.cc | 3 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 28 |
2 files changed, 16 insertions, 15 deletions
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index 326412b..d6f5cf2 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -101,7 +101,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_locus ()); + expr.get_outer_attrs (), 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 1d7d528..7a93323 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -2069,7 +2069,8 @@ public: std::vector<std::unique_ptr<Stmt> > statements; std::unique_ptr<Expr> expr; bool tail_reachable; - Location locus; + Location start_locus; + Location end_locus; std::string as_string () const override; @@ -2085,17 +2086,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 locus) + Location start_locus, Location end_locus) : ExprWithBlock (std::move (mappings), std::move (outer_attribs)), inner_attrs (std::move (inner_attribs)), statements (std::move (block_statements)), expr (std::move (block_expr)), - tail_reachable (tail_reachable), locus (locus) + tail_reachable (tail_reachable), start_locus (start_locus), + end_locus (end_locus) {} // Copy constructor with clone BlockExpr (BlockExpr const &other) : ExprWithBlock (other), /*statements(other.statements),*/ - inner_attrs (other.inner_attrs), locus (other.locus) + inner_attrs (other.inner_attrs), start_locus (other.start_locus), + end_locus (other.end_locus) { // guard to protect from null pointer dereference if (other.expr != nullptr) @@ -2113,7 +2116,8 @@ public: // statements = other.statements; expr = other.expr->clone_expr (); inner_attrs = other.inner_attrs; - locus = other.locus; + start_locus = other.end_locus; + end_locus = other.end_locus; // outer_attrs = other.outer_attrs; statements.reserve (other.statements.size ()); @@ -2133,19 +2137,15 @@ public: return std::unique_ptr<BlockExpr> (clone_block_expr_impl ()); } - Location get_locus () const override final { return locus; } + Location get_locus () const override final { return start_locus; } - void accept_vis (HIRFullVisitor &vis) override; + Location get_start_locus () const { return start_locus; } - bool is_final_stmt (Stmt *stmt) { return statements.back ().get () == stmt; } + Location get_end_locus () const { return end_locus; } - Location get_closing_locus () - { - if (statements.size () == 0) - return get_locus (); + void accept_vis (HIRFullVisitor &vis) override; - return statements[statements.size () - 1]->get_locus (); - } + bool is_final_stmt (Stmt *stmt) { return statements.back ().get () == stmt; } std::unique_ptr<Expr> &get_final_expr () { return expr; } |