aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2020-12-30 22:13:41 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-01-06 10:01:17 +0000
commit36ebe9a0380694c8517536eb37c7134f1323a30b (patch)
tree06901ff25aa5ea093184e0713bd0363735408959 /gcc/rust/backend/rust-compile-expr.h
parent467141184aa274126ff7e2a41d08bb621b7a3fdf (diff)
downloadgcc-36ebe9a0380694c8517536eb37c7134f1323a30b.zip
gcc-36ebe9a0380694c8517536eb37c7134f1323a30b.tar.gz
gcc-36ebe9a0380694c8517536eb37c7134f1323a30b.tar.bz2
This brings structs back in post HIR changes. It supports structs
where no base struct is referenced and the constructor is in order.
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 871b4ba..7b01e0e 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -23,6 +23,7 @@
#include "rust-compile-tyty.h"
#include "rust-compile-resolve-path.h"
#include "rust-compile-block.h"
+#include "rust-compile-struct-field-expr.h"
namespace Rust {
namespace Compile {
@@ -56,7 +57,7 @@ public:
void visit (HIR::CallExpr &expr)
{
- Bexpression *fn = ResolvePath::Compile (expr.get_fnexpr (), ctx);
+ Bexpression *fn = ResolvePathRef::Compile (expr.get_fnexpr (), ctx);
rust_assert (fn != nullptr);
std::vector<Bexpression *> args;
@@ -355,6 +356,25 @@ public:
ctx->add_statement (block_stmt);
}
+ void visit (HIR::StructExprStructFields &struct_expr)
+ {
+ Btype *type
+ = ResolvePathType::Compile (&struct_expr.get_struct_name (), ctx);
+
+ // this assumes all fields are in order from type resolution and if a base
+ // struct was specified those fields are filed via accesors
+ std::vector<Bexpression *> vals;
+ struct_expr.iterate ([&] (HIR::StructExprField *field) mutable -> bool {
+ Bexpression *expr = CompileStructExprField::Compile (field, ctx);
+ vals.push_back (expr);
+ return true;
+ });
+
+ translated
+ = ctx->get_backend ()->constructor_expression (type, vals,
+ struct_expr.get_locus ());
+ }
+
private:
CompileExpr (Context *ctx) : HIRCompileBase (ctx), translated (nullptr) {}