aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-10-28 10:57:37 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-10-28 10:57:37 +0100
commit657a9735339f6e5b0723bc24f74ad55d78daae8e (patch)
tree9a459c90843a7b2ac8bb33517dd95756b991571b /gcc/rust/backend
parent161a690d21044f5211ad2b55ae6b06f91bbd9106 (diff)
downloadgcc-657a9735339f6e5b0723bc24f74ad55d78daae8e.zip
gcc-657a9735339f6e5b0723bc24f74ad55d78daae8e.tar.gz
gcc-657a9735339f6e5b0723bc24f74ad55d78daae8e.tar.bz2
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
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-stmt.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-stmt.h b/gcc/rust/backend/rust-compile-stmt.h
index 1a2f02c..21e5814 100644
--- a/gcc/rust/backend/rust-compile-stmt.h
+++ b/gcc/rust/backend/rust-compile-stmt.h
@@ -48,6 +48,33 @@ public:
translated = CompileExpr::Compile (stmt.get_expr (), ctx);
}
+ void visit (HIR::ConstantItem &constant) override
+ {
+ TyTy::BaseType *resolved_type = nullptr;
+ bool ok
+ = ctx->get_tyctx ()->lookup_type (constant.get_mappings ().get_hirid (),
+ &resolved_type);
+ rust_assert (ok);
+
+ ::Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
+ Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
+
+ const Resolver::CanonicalPath *canonical_path = nullptr;
+ rust_assert (ctx->get_mappings ()->lookup_canonical_path (
+ constant.get_mappings ().get_crate_num (),
+ constant.get_mappings ().get_nodeid (), &canonical_path));
+
+ std::string ident = canonical_path->get ();
+ Bexpression *const_expr
+ = ctx->get_backend ()->named_constant_expression (type, ident, value,
+ constant.get_locus ());
+
+ ctx->push_const (const_expr);
+ ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
+
+ translated = const_expr;
+ }
+
void visit (HIR::LetStmt &stmt) override
{
// nothing to do