From 657a9735339f6e5b0723bc24f74ad55d78daae8e Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 28 Oct 2021 10:57:37 +0100 Subject: Add support for constants within blocks BlockExpr's can contain constants these are Items which can exist within the BlockExpr Stmt list. Items like structs, functions and constants all inherit from Item so there is some duplication of code but we still do not support the forward declared Items within a stmt list so the duplication will need to be fixed as part of that bug. Fixes #711 --- gcc/rust/hir/rust-ast-lower-stmt.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'gcc/rust/hir') diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h b/gcc/rust/hir/rust-ast-lower-stmt.h index 50ccc9f..eab0922 100644 --- a/gcc/rust/hir/rust-ast-lower-stmt.h +++ b/gcc/rust/hir/rust-ast-lower-stmt.h @@ -83,6 +83,34 @@ public: mappings->insert_hir_stmt (crate_num, mapping.get_hirid (), translated); } + void visit (AST::ConstantItem &constant) override + { + HIR::Visibility vis = HIR::Visibility::create_public (); + + HIR::Type *type = ASTLoweringType::translate (constant.get_type ().get ()); + HIR::Expr *expr = ASTLoweringExpr::translate (constant.get_expr ().get ()); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, constant.get_node_id (), + mappings->get_next_hir_id (crate_num), + mappings->get_next_localdef_id (crate_num)); + + HIR::ConstantItem *constant_item + = new HIR::ConstantItem (mapping, constant.get_identifier (), vis, + std::unique_ptr (type), + std::unique_ptr (expr), + constant.get_outer_attrs (), + constant.get_locus ()); + translated = constant_item; + + mappings->insert_hir_item (mapping.get_crate_num (), mapping.get_hirid (), + constant_item); + mappings->insert_hir_stmt (mapping.get_crate_num (), mapping.get_hirid (), + constant_item); + mappings->insert_location (crate_num, mapping.get_hirid (), + constant.get_locus ()); + } + void visit (AST::LetStmt &stmt) override { HIR::Pattern *variables -- cgit v1.1