From 32ccdf41a087e1027e4ba26cbe71c39d9e44b4d3 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Sat, 18 May 2024 23:53:42 +0200 Subject: 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 --- gcc/rust/hir/rust-ast-lower-base.cc | 5 +++++ gcc/rust/hir/rust-ast-lower-base.h | 1 + gcc/rust/hir/rust-ast-lower-expr.cc | 8 ++++++++ gcc/rust/hir/rust-ast-lower-expr.h | 1 + 4 files changed, 15 insertions(+) (limited to 'gcc/rust/hir') diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index 66cff8f..fc37b50 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -213,6 +213,11 @@ ASTLoweringBase::visit (AST::RangeFromToInclExpr &) void ASTLoweringBase::visit (AST::RangeToInclExpr &) {} + +void +ASTLoweringBase::visit (AST::BoxExpr &) +{} + void ASTLoweringBase::visit (AST::ReturnExpr &) {} diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index cacd8c1..d477739 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -137,6 +137,7 @@ public: virtual void visit (AST::RangeFullExpr &expr); virtual void visit (AST::RangeFromToInclExpr &expr); virtual void visit (AST::RangeToInclExpr &expr); + virtual void visit (AST::BoxExpr &expr); virtual void visit (AST::ReturnExpr &expr); virtual void visit (AST::UnsafeBlockExpr &expr); virtual void visit (AST::LoopExpr &expr); diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc index 35d542b..3b462ee 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.cc +++ b/gcc/rust/hir/rust-ast-lower-expr.cc @@ -24,6 +24,7 @@ #include "rust-ast-lower-type.h" #include "rust-ast.h" #include "rust-diagnostics.h" +#include "rust-system.h" namespace Rust { namespace HIR { @@ -142,6 +143,13 @@ ASTLoweringExpr::visit (AST::QualifiedPathInExpression &expr) } void +ASTLoweringExpr::visit (AST::BoxExpr &expr) +{ + // Not implemented + rust_unreachable (); +} + +void ASTLoweringExpr::visit (AST::ReturnExpr &expr) { terminated = true; diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h index ab3ae0a..e145259 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.h +++ b/gcc/rust/hir/rust-ast-lower-expr.h @@ -85,6 +85,7 @@ public: void visit (AST::UnsafeBlockExpr &expr) override; void visit (AST::PathInExpression &expr) override; void visit (AST::QualifiedPathInExpression &expr) override; + void visit (AST::BoxExpr &expr) override; void visit (AST::ReturnExpr &expr) override; void visit (AST::CallExpr &expr) override; void visit (AST::MethodCallExpr &expr) override; -- cgit v1.1