aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/tree/rust-hir-expr.h
diff options
context:
space:
mode:
authorJakub Dupak <dev@jakubdupak.com>2023-10-16 15:17:33 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 19:09:20 +0100
commita66df6197e84b6817d20c494bee7242bbfab0369 (patch)
tree6899716a2e0738ba47dea65a985ea00505f446e9 /gcc/rust/hir/tree/rust-hir-expr.h
parent3b1d27f78720bf4cf3857f31a4d26226e2581fb1 (diff)
downloadgcc-a66df6197e84b6817d20c494bee7242bbfab0369.zip
gcc-a66df6197e84b6817d20c494bee7242bbfab0369.tar.gz
gcc-a66df6197e84b6817d20c494bee7242bbfab0369.tar.bz2
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.
Diffstat (limited to 'gcc/rust/hir/tree/rust-hir-expr.h')
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h70
1 files changed, 37 insertions, 33 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 3bfadbf..6d26287 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
{