From 5f25f457eca1e04e577aae8e60fe640bb32d36fc Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Mon, 17 Oct 2022 17:18:30 +0100 Subject: Add hir lowering of closure expressions In the AST we have ClosureExprInner and ClosureExprInnerTyped the first is the closure expression of the form: let closure_inferred = |i| i + 1; The second is of the form: let closure_annotated = |i: i32| -> i32 { i + 1 }; Both of these can be seguared into a single HIR::ClosureExpr with an optional return type and parameter types. Addresses #195 --- gcc/rust/ast/rust-expr.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index c764f9c..c58fae5 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -2134,8 +2134,6 @@ struct ClosureParam private: std::vector outer_attrs; std::unique_ptr pattern; - - // bool has_type_given; std::unique_ptr type; Location locus; @@ -2202,19 +2200,19 @@ public: const std::vector &get_outer_attrs () const { return outer_attrs; } std::vector &get_outer_attrs () { return outer_attrs; } - // TODO: is this better? Or is a "vis_block" better? std::unique_ptr &get_pattern () { rust_assert (pattern != nullptr); return pattern; } - // TODO: is this better? Or is a "vis_block" better? std::unique_ptr &get_type () { rust_assert (has_type_given ()); return type; } + + Location get_locus () const { return locus; } }; // Base closure definition expression AST node - abstract @@ -2248,6 +2246,8 @@ public: { outer_attrs = std::move (new_attrs); } + + bool get_has_move () const { return has_move; } }; // Represents a non-type-specified closure expression AST node @@ -2307,7 +2307,6 @@ public: return closure_inner == nullptr; } - // TODO: is this better? Or is a "vis_block" better? std::unique_ptr &get_definition_expr () { rust_assert (closure_inner != nullptr); -- cgit v1.1 From d396692534019f1e80b821c9e483164f302679bf Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 20 Oct 2022 17:59:27 +0100 Subject: Add missing hir lowering to function type-path segments --- gcc/rust/ast/rust-path.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h index 80ff960..4643054 100644 --- a/gcc/rust/ast/rust-path.h +++ b/gcc/rust/ast/rust-path.h @@ -898,6 +898,8 @@ public: rust_assert (has_return_type ()); return return_type; } + + Location get_locus () const { return locus; } }; // Segment used in type path with a function argument -- cgit v1.1