diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-05-18 23:53:42 +0200 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2024-06-11 11:19:26 +0000 |
commit | 32ccdf41a087e1027e4ba26cbe71c39d9e44b4d3 (patch) | |
tree | 5ff8e51f174cf5ebbc0662581783e6bcbcdf81c0 /gcc/rust/ast/rust-expr.h | |
parent | 75049a3bfee8c3f888994bce3b741a805c631c2a (diff) | |
download | gcc-32ccdf41a087e1027e4ba26cbe71c39d9e44b4d3.zip gcc-32ccdf41a087e1027e4ba26cbe71c39d9e44b4d3.tar.gz gcc-32ccdf41a087e1027e4ba26cbe71c39d9e44b4d3.tar.bz2 |
Parse box expressions
Add support for old box expression syntax.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Add visit member
function for BoxExpr nodes.
* ast/rust-ast-collector.h: Add visit function prototype.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add visit member
function to default ast visitor.
* ast/rust-ast-visitor.h: Add visit function's prototype.
* ast/rust-ast.cc (BoxExpr::as_string): Add as_string function
implementation for BoxExpr.
(BoxExpr::accept_vis): Add accept_vis implementation to BoxExpr.
* ast/rust-expr.h (class BoxExpr): Add BoxExpr class to represent boxed
expressions.
* expand/rust-derive.h: Add BoxExpr visit function prototype.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add BoxExpr
visitor implementation.
* hir/rust-ast-lower-base.h: Add visit function's prototype.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Add BoxExpr
visitor implementation.
* hir/rust-ast-lower-expr.h: Add visit function's prototype.
* parse/rust-parse-impl.h (Parser::parse_box_expr): Add parse_box_expr
function's implementation.
* parse/rust-parse.h: Add parse_box_expr function's prototype.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add resolver
visit implementation.
* resolve/rust-ast-resolve-base.h: Add resolver's visit function
prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/ast/rust-expr.h')
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 015680b..c3b93d4 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -3310,6 +3310,79 @@ protected: } }; +class BoxExpr : public ExprWithoutBlock +{ + std::unique_ptr<Expr> expr; + std::vector<Attribute> outer_attrs; + location_t locus; + +public: + BoxExpr (std::unique_ptr<Expr> expr, std::vector<Attribute> outer_attrs, + location_t locus) + : expr (std::move (expr)), outer_attrs (outer_attrs), locus (locus) + {} + + // Copy constructor with clone + BoxExpr (BoxExpr const &other) + : ExprWithoutBlock (other), outer_attrs (other.outer_attrs), + locus (other.locus) + { + // guard to protect from null pointer dereference + if (other.expr != nullptr) + expr = other.expr->clone_expr (); + } + + BoxExpr &operator= (BoxExpr const &other) + { + ExprWithoutBlock::operator= (other); + locus = other.locus; + outer_attrs = other.outer_attrs; + + // guard to protect from null pointer dereference + if (other.expr != nullptr) + expr = other.expr->clone_expr (); + else + expr = nullptr; + + return *this; + } + + // move constructors + BoxExpr (BoxExpr &&other) = default; + BoxExpr &operator= (BoxExpr &&other) = default; + + location_t get_locus () const override final { return locus; } + + void accept_vis (ASTVisitor &vis) override; + + void mark_for_strip () override { expr = nullptr; } + bool is_marked_for_strip () const override { return expr == nullptr; } + + const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; } + std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; } + + void set_outer_attrs (std::vector<Attribute> new_attrs) override + { + outer_attrs = std::move (new_attrs); + } + + std::string as_string () const override; + + Expr &get_boxed_expr () + { + rust_assert (expr != nullptr); + return *expr; + } + +protected: + /* Use covariance to implement clone function as returning this object rather + * than base */ + BoxExpr *clone_expr_without_block_impl () const override + { + return new BoxExpr (*this); + } +}; + // Return expression AST node representation class ReturnExpr : public ExprWithoutBlock { |