aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorM V V S Manoj Kumar <mvvsmanojkumar@gmail.com>2021-11-20 08:01:36 +0530
committerGitHub <noreply@github.com>2021-11-20 08:01:36 +0530
commit73a0903c156f86e1e59c30c542780fe2162438d4 (patch)
treed608a5ee3f316d63f259113ae7fed2da4149a6ce /gcc/rust/backend
parent9c4e3db7789dc32ae08a2302b13c2772f51d5bea (diff)
parentfece068309e8a3cbeb81539fba14e1c970740a94 (diff)
downloadgcc-73a0903c156f86e1e59c30c542780fe2162438d4.zip
gcc-73a0903c156f86e1e59c30c542780fe2162438d4.tar.gz
gcc-73a0903c156f86e1e59c30c542780fe2162438d4.tar.bz2
Merge branch 'Rust-GCC:master' into master
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-base.h18
-rw-r--r--gcc/rust/backend/rust-compile-block.h15
-rw-r--r--gcc/rust/backend/rust-compile-context.h191
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc393
-rw-r--r--gcc/rust/backend/rust-compile-expr.h197
-rw-r--r--gcc/rust/backend/rust-compile-extern.h12
-rw-r--r--gcc/rust/backend/rust-compile-fnparam.h16
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h71
-rw-r--r--gcc/rust/backend/rust-compile-intrinsic.cc4
-rw-r--r--gcc/rust/backend/rust-compile-intrinsic.h2
-rw-r--r--gcc/rust/backend/rust-compile-item.h37
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc8
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.h21
-rw-r--r--gcc/rust/backend/rust-compile-stmt.h14
-rw-r--r--gcc/rust/backend/rust-compile-struct-field-expr.h4
-rw-r--r--gcc/rust/backend/rust-compile-tyty.h16
-rw-r--r--gcc/rust/backend/rust-compile-var-decl.h9
-rw-r--r--gcc/rust/backend/rust-compile.cc324
18 files changed, 758 insertions, 594 deletions
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h
index 3184e27..af0ea40 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -193,23 +193,21 @@ protected:
Context *get_context () { return ctx; }
- void compile_function_body (Bfunction *fndecl,
+ void compile_function_body (tree fndecl,
std::unique_ptr<HIR::BlockExpr> &function_body,
bool has_return_type);
- bool compile_locals_for_block (Resolver::Rib &rib, Bfunction *fndecl,
+ bool compile_locals_for_block (Resolver::Rib &rib, tree fndecl,
std::vector<Bvariable *> &locals);
- Bexpression *coercion_site (Bexpression *compiled_ref, TyTy::BaseType *actual,
- TyTy::BaseType *expected, Location locus);
+ tree coercion_site (tree compiled_ref, TyTy::BaseType *actual,
+ TyTy::BaseType *expected, Location locus);
- Bexpression *coerce_to_dyn_object (Bexpression *compiled_ref,
- const TyTy::BaseType *actual,
- const TyTy::BaseType *expected,
- const TyTy::DynamicObjectType *ty,
- Location locus);
+ tree coerce_to_dyn_object (tree compiled_ref, const TyTy::BaseType *actual,
+ const TyTy::BaseType *expected,
+ const TyTy::DynamicObjectType *ty, Location locus);
- Bexpression *compute_address_for_trait_item (
+ tree compute_address_for_trait_item (
const Resolver::TraitItemReference *ref,
const TyTy::TypeBoundPredicate *predicate,
std::vector<std::pair<Resolver::TraitReference *, HIR::ImplBlock *>>
diff --git a/gcc/rust/backend/rust-compile-block.h b/gcc/rust/backend/rust-compile-block.h
index 6876e8a..af90671 100644
--- a/gcc/rust/backend/rust-compile-block.h
+++ b/gcc/rust/backend/rust-compile-block.h
@@ -30,7 +30,7 @@ class CompileBlock : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bblock *compile (HIR::BlockExpr *expr, Context *ctx, Bvariable *result)
+ static tree compile (HIR::BlockExpr *expr, Context *ctx, Bvariable *result)
{
CompileBlock compiler (ctx, result);
expr->accept_vis (compiler);
@@ -44,7 +44,7 @@ private:
: HIRCompileBase (ctx), translated (nullptr), result (result)
{}
- Bblock *translated;
+ tree translated;
Bvariable *result;
};
@@ -53,8 +53,7 @@ class CompileConditionalBlocks : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bstatement *compile (HIR::IfExpr *expr, Context *ctx,
- Bvariable *result)
+ static tree compile (HIR::IfExpr *expr, Context *ctx, Bvariable *result)
{
CompileConditionalBlocks resolver (ctx, result);
expr->accept_vis (resolver);
@@ -72,7 +71,7 @@ private:
: HIRCompileBase (ctx), translated (nullptr), result (result)
{}
- Bstatement *translated;
+ tree translated;
Bvariable *result;
};
@@ -81,8 +80,8 @@ class CompileExprWithBlock : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bstatement *compile (HIR::ExprWithBlock *expr, Context *ctx,
- Bvariable *result)
+ static tree compile (HIR::ExprWithBlock *expr, Context *ctx,
+ Bvariable *result)
{
CompileExprWithBlock resolver (ctx, result);
expr->accept_vis (resolver);
@@ -109,7 +108,7 @@ private:
: HIRCompileBase (ctx), translated (nullptr), result (result)
{}
- Bstatement *translated;
+ tree translated;
Bvariable *result;
};
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 396cb10..668e8ba 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -35,7 +35,7 @@ namespace Compile {
struct fncontext
{
- ::Bfunction *fndecl;
+ tree fndecl;
::Bvariable *ret_addr;
};
@@ -60,20 +60,20 @@ public:
ok = tyctx->lookup_type (ref, &lookup);
rust_assert (ok);
- Btype *compiled = TyTyCompile::compile (backend, lookup);
- compiled_type_map.insert (std::pair<HirId, Btype *> (ref, compiled));
+ tree compiled = TyTyCompile::compile (backend, lookup);
+ compiled_type_map.insert (std::pair<HirId, tree> (ref, compiled));
builtin_range.insert (ref);
}
}
- bool lookup_compiled_types (HirId id, ::Btype **type,
+ bool lookup_compiled_types (HirId id, tree *type,
const TyTy::BaseType *ref = nullptr)
{
if (ref != nullptr)
{
for (auto it = mono.begin (); it != mono.end (); it++)
{
- std::pair<HirId, ::Btype *> &val = it->second;
+ std::pair<HirId, tree> &val = it->second;
const TyTy::BaseType *r = it->first;
if (ref->is_equal (*r))
@@ -94,14 +94,14 @@ public:
return true;
}
- void insert_compiled_type (HirId id, ::Btype *type,
+ void insert_compiled_type (HirId id, tree type,
const TyTy::BaseType *ref = nullptr)
{
rust_assert (builtin_range.find (id) == builtin_range.end ());
- compiled_type_map.insert (std::pair<HirId, Btype *> (id, type));
+ compiled_type_map.insert (std::pair<HirId, tree> (id, type));
if (ref != nullptr)
{
- std::pair<HirId, ::Btype *> elem (id, type);
+ std::pair<HirId, tree> elem (id, type);
mono[ref] = std::move (elem);
}
}
@@ -112,13 +112,13 @@ public:
Analysis::Mappings *get_mappings () { return mappings; }
ConstFold::Context *get_const_ctx () { return const_ctx; }
- void push_block (Bblock *scope)
+ void push_block (tree scope)
{
scope_stack.push_back (scope);
statements.push_back ({});
}
- Bblock *pop_block ()
+ tree pop_block ()
{
auto block = scope_stack.back ();
scope_stack.pop_back ();
@@ -131,7 +131,7 @@ public:
return block;
}
- Bblock *peek_enclosing_scope ()
+ tree peek_enclosing_scope ()
{
if (scope_stack.size () == 0)
return nullptr;
@@ -139,12 +139,12 @@ public:
return scope_stack.back ();
}
- void add_statement_to_enclosing_scope (Bstatement *stmt)
+ void add_statement_to_enclosing_scope (tree stmt)
{
statements.at (statements.size () - 2).push_back (stmt);
}
- void add_statement (Bstatement *stmt) { statements.back ().push_back (stmt); }
+ void add_statement (tree stmt) { statements.back ().push_back (stmt); }
void insert_var_decl (HirId id, ::Bvariable *decl)
{
@@ -161,7 +161,7 @@ public:
return true;
}
- void insert_function_decl (const TyTy::FnType *ref, ::Bfunction *fn)
+ void insert_function_decl (const TyTy::FnType *ref, tree fn)
{
auto id = ref->get_ty_ref ();
auto dId = ref->get_id ();
@@ -176,8 +176,7 @@ public:
mono_fns[dId].push_back ({ref, fn});
}
- bool lookup_function_decl (HirId id, ::Bfunction **fn,
- DefId dId = UNKNOWN_DEFID,
+ bool lookup_function_decl (HirId id, tree *fn, DefId dId = UNKNOWN_DEFID,
const TyTy::BaseType *ref = nullptr)
{
// for for any monomorphized fns
@@ -192,7 +191,7 @@ public:
for (auto &e : mono_fns[dId])
{
const TyTy::BaseType *r = e.first;
- ::Bfunction *f = e.second;
+ tree f = e.second;
if (ref->is_equal (*r))
{
*fn = f;
@@ -210,12 +209,9 @@ public:
return true;
}
- void insert_const_decl (HirId id, ::Bexpression *expr)
- {
- compiled_consts[id] = expr;
- }
+ void insert_const_decl (HirId id, tree expr) { compiled_consts[id] = expr; }
- bool lookup_const_decl (HirId id, ::Bexpression **expr)
+ bool lookup_const_decl (HirId id, tree *expr)
{
auto it = compiled_consts.find (id);
if (it == compiled_consts.end ())
@@ -225,12 +221,9 @@ public:
return true;
}
- void insert_label_decl (HirId id, ::Blabel *label)
- {
- compiled_labels[id] = label;
- }
+ void insert_label_decl (HirId id, tree label) { compiled_labels[id] = label; }
- bool lookup_label_decl (HirId id, ::Blabel **label)
+ bool lookup_label_decl (HirId id, tree *label)
{
auto it = compiled_labels.find (id);
if (it == compiled_labels.end ())
@@ -240,17 +233,17 @@ public:
return true;
}
- void push_fn (::Bfunction *fn, ::Bvariable *ret_addr)
+ void push_fn (tree fn, ::Bvariable *ret_addr)
{
fn_stack.push_back (fncontext{fn, ret_addr});
}
void pop_fn () { fn_stack.pop_back (); }
fncontext peek_fn () { return fn_stack.back (); }
- void push_type (::Btype *t) { type_decls.push_back (t); }
+ void push_type (tree t) { type_decls.push_back (t); }
void push_var (::Bvariable *v) { var_decls.push_back (v); }
- void push_const (::Bexpression *c) { const_decls.push_back (c); }
- void push_function (::Bfunction *f) { func_decls.push_back (f); }
+ void push_const (tree c) { const_decls.push_back (c); }
+ void push_function (tree f) { func_decls.push_back (f); }
void write_to_backend ()
{
@@ -258,11 +251,11 @@ public:
var_decls);
}
- bool function_completed (Bfunction *fn)
+ bool function_completed (tree fn)
{
for (auto it = func_decls.begin (); it != func_decls.end (); it++)
{
- Bfunction *i = (*it);
+ tree i = (*it);
if (i == fn)
{
return true;
@@ -282,16 +275,16 @@ public:
return back;
}
- void push_loop_begin_label (Blabel *label)
+ void push_loop_begin_label (tree label)
{
loop_begin_labels.push_back (label);
}
- Blabel *peek_loop_begin_label () { return loop_begin_labels.back (); }
+ tree peek_loop_begin_label () { return loop_begin_labels.back (); }
- Blabel *pop_loop_begin_label ()
+ tree pop_loop_begin_label ()
{
- Blabel *pop = loop_begin_labels.back ();
+ tree pop = loop_begin_labels.back ();
loop_begin_labels.pop_back ();
return pop;
}
@@ -322,30 +315,30 @@ private:
// state
std::vector<fncontext> fn_stack;
std::map<HirId, ::Bvariable *> compiled_var_decls;
- std::map<HirId, ::Btype *> compiled_type_map;
- std::map<HirId, ::Bfunction *> compiled_fn_map;
- std::map<HirId, ::Bexpression *> compiled_consts;
- std::map<HirId, ::Blabel *> compiled_labels;
- std::vector<::std::vector<Bstatement *>> statements;
- std::vector<::Bblock *> scope_stack;
+ std::map<HirId, tree> compiled_type_map;
+ std::map<HirId, tree> compiled_fn_map;
+ std::map<HirId, tree> compiled_consts;
+ std::map<HirId, tree> compiled_labels;
+ std::vector<::std::vector<tree>> statements;
+ std::vector<tree> scope_stack;
std::vector<::Bvariable *> loop_value_stack;
- std::vector<::Blabel *> loop_begin_labels;
- std::map<const TyTy::BaseType *, std::pair<HirId, ::Btype *>> mono;
- std::map<DefId, std::vector<std::pair<const TyTy::BaseType *, ::Bfunction *>>>
+ std::vector<tree> loop_begin_labels;
+ std::map<const TyTy::BaseType *, std::pair<HirId, tree>> mono;
+ std::map<DefId, std::vector<std::pair<const TyTy::BaseType *, tree>>>
mono_fns;
// To GCC middle-end
- std::vector<::Btype *> type_decls;
+ std::vector<tree> type_decls;
std::vector<::Bvariable *> var_decls;
- std::vector<::Bexpression *> const_decls;
- std::vector<::Bfunction *> func_decls;
+ std::vector<tree> const_decls;
+ std::vector<tree> func_decls;
};
class TyTyResolveCompile : public TyTy::TyConstVisitor
{
public:
- static ::Btype *compile (Context *ctx, const TyTy::BaseType *ty,
- bool trait_object_mode = false)
+ static tree compile (Context *ctx, const TyTy::BaseType *ty,
+ bool trait_object_mode = false)
{
TyTyResolveCompile compiler (ctx, trait_object_mode);
ty->accept_vis (compiler);
@@ -375,16 +368,16 @@ public:
void visit (const TyTy::FnType &type) override
{
- Backend::Btyped_identifier receiver;
- std::vector<Backend::Btyped_identifier> parameters;
- std::vector<Backend::Btyped_identifier> results;
+ Backend::typed_identifier receiver;
+ std::vector<Backend::typed_identifier> parameters;
+ std::vector<Backend::typed_identifier> results;
if (!type.get_return_type ()->is_unit ())
{
auto hir_type = type.get_return_type ();
auto ret
= TyTyResolveCompile::compile (ctx, hir_type, trait_object_mode);
- results.push_back (Backend::Btyped_identifier (
+ results.push_back (Backend::typed_identifier (
"_", ret,
ctx->get_mappings ()->lookup_location (hir_type->get_ref ())));
}
@@ -395,7 +388,7 @@ public:
auto compiled_param_type
= TyTyResolveCompile::compile (ctx, param_tyty, trait_object_mode);
- auto compiled_param = Backend::Btyped_identifier (
+ auto compiled_param = Backend::typed_identifier (
param_pair.first->as_string (), compiled_param_type,
ctx->get_mappings ()->lookup_location (param_tyty->get_ref ()));
@@ -414,12 +407,12 @@ public:
void visit (const TyTy::FnPtr &type) override
{
- Btype *result_type
+ tree result_type
= TyTyResolveCompile::compile (ctx, type.get_return_type ());
- std::vector<Btype *> parameters;
+ std::vector<tree> parameters;
type.iterate_params ([&] (TyTy::BaseType *p) mutable -> bool {
- Btype *pty = TyTyResolveCompile::compile (ctx, p);
+ tree pty = TyTyResolveCompile::compile (ctx, p);
parameters.push_back (pty);
return true;
});
@@ -439,25 +432,25 @@ public:
rust_assert (type.number_of_variants () == 1);
TyTy::VariantDef &variant = *type.get_variants ().at (0);
- std::vector<Backend::Btyped_identifier> fields;
+ std::vector<Backend::typed_identifier> fields;
for (size_t i = 0; i < variant.num_fields (); i++)
{
const TyTy::StructFieldType *field = variant.get_field_at_index (i);
- Btype *compiled_field_ty
+ tree compiled_field_ty
= TyTyResolveCompile::compile (ctx, field->get_field_type ());
- Backend::Btyped_identifier f (field->get_name (), compiled_field_ty,
- ctx->get_mappings ()->lookup_location (
- type.get_ty_ref ()));
+ Backend::typed_identifier f (field->get_name (), compiled_field_ty,
+ ctx->get_mappings ()->lookup_location (
+ type.get_ty_ref ()));
fields.push_back (std::move (f));
}
- Btype *type_record;
+ tree type_record;
if (type.is_union ())
type_record = ctx->get_backend ()->union_type (fields);
else
type_record = ctx->get_backend ()->struct_type (fields);
- Btype *named_struct
+ tree named_struct
= ctx->get_backend ()->named_type (type.get_name (), type_record,
ctx->get_mappings ()->lookup_location (
type.get_ty_ref ()));
@@ -482,11 +475,11 @@ public:
return;
// create implicit struct
- std::vector<Backend::Btyped_identifier> fields;
+ std::vector<Backend::typed_identifier> fields;
for (size_t i = 0; i < type.num_fields (); i++)
{
TyTy::BaseType *field = type.get_field (i);
- Btype *compiled_field_ty = TyTyResolveCompile::compile (ctx, field);
+ tree compiled_field_ty = TyTyResolveCompile::compile (ctx, field);
// rustc uses the convention __N, where N is an integer, to
// name the fields of a tuple. We follow this as well,
@@ -494,15 +487,15 @@ public:
// this, rather than simply emitting the integer, is that this
// approach makes it simpler to use a C-only debugger, or
// GDB's C mode, when debugging Rust.
- Backend::Btyped_identifier f ("__" + std::to_string (i),
- compiled_field_ty,
- ctx->get_mappings ()->lookup_location (
- type.get_ty_ref ()));
+ Backend::typed_identifier f ("__" + std::to_string (i),
+ compiled_field_ty,
+ ctx->get_mappings ()->lookup_location (
+ type.get_ty_ref ()));
fields.push_back (std::move (f));
}
- Btype *struct_type_record = ctx->get_backend ()->struct_type (fields);
- Btype *named_struct
+ tree struct_type_record = ctx->get_backend ()->struct_type (fields);
+ tree named_struct
= ctx->get_backend ()->named_type (type.as_string (), struct_type_record,
ctx->get_mappings ()->lookup_location (
type.get_ty_ref ()));
@@ -514,7 +507,7 @@ public:
void visit (const TyTy::ArrayType &type) override
{
- Btype *element_type
+ tree element_type
= TyTyResolveCompile::compile (ctx, type.get_element_type ());
translated
= ctx->get_backend ()->array_type (element_type, type.get_capacity ());
@@ -522,7 +515,7 @@ public:
void visit (const TyTy::BoolType &type) override
{
- ::Btype *compiled_type = nullptr;
+ tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -530,7 +523,7 @@ public:
void visit (const TyTy::IntType &type) override
{
- ::Btype *compiled_type = nullptr;
+ tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -538,7 +531,7 @@ public:
void visit (const TyTy::UintType &type) override
{
- ::Btype *compiled_type = nullptr;
+ tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -546,7 +539,7 @@ public:
void visit (const TyTy::FloatType &type) override
{
- ::Btype *compiled_type = nullptr;
+ tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -554,7 +547,7 @@ public:
void visit (const TyTy::USizeType &type) override
{
- ::Btype *compiled_type = nullptr;
+ tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -562,7 +555,7 @@ public:
void visit (const TyTy::ISizeType &type) override
{
- ::Btype *compiled_type = nullptr;
+ tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -570,7 +563,7 @@ public:
void visit (const TyTy::CharType &type) override
{
- ::Btype *compiled_type = nullptr;
+ tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -578,7 +571,7 @@ public:
void visit (const TyTy::ReferenceType &type) override
{
- Btype *base_compiled_type
+ tree base_compiled_type
= TyTyResolveCompile::compile (ctx, type.get_base (), trait_object_mode);
if (type.is_mutable ())
{
@@ -593,7 +586,7 @@ public:
void visit (const TyTy::PointerType &type) override
{
- Btype *base_compiled_type
+ tree base_compiled_type
= TyTyResolveCompile::compile (ctx, type.get_base (), trait_object_mode);
if (type.is_mutable ())
{
@@ -608,7 +601,7 @@ public:
void visit (const TyTy::StrType &type) override
{
- ::Btype *compiled_type = nullptr;
+ tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -633,32 +626,32 @@ public:
// create implicit struct
auto items = type.get_object_items ();
- std::vector<Backend::Btyped_identifier> fields;
+ std::vector<Backend::typed_identifier> fields;
- Btype *uint = ctx->get_backend ()->integer_type (
+ tree uint = ctx->get_backend ()->integer_type (
true, ctx->get_backend ()->get_pointer_size ());
- Btype *uintptr_ty = ctx->get_backend ()->pointer_type (uint);
+ tree uintptr_ty = ctx->get_backend ()->pointer_type (uint);
- Backend::Btyped_identifier f ("__receiver_trait_obj_ptr", uintptr_ty,
- ctx->get_mappings ()->lookup_location (
- type.get_ty_ref ()));
+ Backend::typed_identifier f ("__receiver_trait_obj_ptr", uintptr_ty,
+ ctx->get_mappings ()->lookup_location (
+ type.get_ty_ref ()));
fields.push_back (std::move (f));
for (size_t i = 0; i < items.size (); i++)
{
// mrustc seems to make a vtable consisting of uintptr's
- Btype *uint = ctx->get_backend ()->integer_type (
+ tree uint = ctx->get_backend ()->integer_type (
true, ctx->get_backend ()->get_pointer_size ());
- Btype *uintptr_ty = ctx->get_backend ()->pointer_type (uint);
+ tree uintptr_ty = ctx->get_backend ()->pointer_type (uint);
- Backend::Btyped_identifier f ("__" + std::to_string (i), uintptr_ty,
- ctx->get_mappings ()->lookup_location (
- type.get_ty_ref ()));
+ Backend::typed_identifier f ("__" + std::to_string (i), uintptr_ty,
+ ctx->get_mappings ()->lookup_location (
+ type.get_ty_ref ()));
fields.push_back (std::move (f));
}
- Btype *type_record = ctx->get_backend ()->struct_type (fields);
- Btype *named_struct
+ tree type_record = ctx->get_backend ()->struct_type (fields);
+ tree named_struct
= ctx->get_backend ()->named_type (type.get_name (), type_record,
ctx->get_mappings ()->lookup_location (
type.get_ty_ref ()));
@@ -679,7 +672,7 @@ private:
Context *ctx;
bool trait_object_mode;
- ::Btype *translated;
+ tree translated;
size_t recursion_count;
static const size_t kDefaultRecusionLimit = 5;
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
new file mode 100644
index 0000000..fb01d8d
--- /dev/null
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -0,0 +1,393 @@
+// Copyright (C) 2020-2021 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-compile.h"
+#include "rust-compile-item.h"
+#include "rust-compile-expr.h"
+#include "rust-compile-struct-field-expr.h"
+#include "rust-hir-trait-resolve.h"
+#include "rust-hir-path-probe.h"
+#include "rust-hir-type-bounds.h"
+#include "rust-hir-dot-operator.h"
+
+namespace Rust {
+namespace Compile {
+
+void
+CompileExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
+{
+ auto op = expr.get_expr_type ();
+ auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx);
+ auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
+
+ // this might be an operator overload situation lets check
+ TyTy::FnType *fntype;
+ bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
+ expr.get_mappings ().get_hirid (), &fntype);
+ if (is_op_overload)
+ {
+ auto lang_item_type
+ = Analysis::RustLangItem::OperatorToLangItem (expr.get_expr_type ());
+ translated = resolve_operator_overload (lang_item_type, expr, lhs, rhs,
+ expr.get_lhs (), expr.get_rhs ());
+ return;
+ }
+
+ translated
+ = ctx->get_backend ()->arithmetic_or_logical_expression (op, lhs, rhs,
+ expr.get_locus ());
+}
+
+void
+CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
+{
+ fncontext fn = ctx->peek_fn ();
+
+ auto op = expr.get_expr_type ();
+ auto lhs = CompileExpr::Compile (expr.get_left_expr ().get (), ctx);
+ auto rhs = CompileExpr::Compile (expr.get_right_expr ().get (), ctx);
+
+ // this might be an operator overload situation lets check
+ TyTy::FnType *fntype;
+ bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
+ expr.get_mappings ().get_hirid (), &fntype);
+ if (is_op_overload)
+ {
+ auto lang_item_type
+ = Analysis::RustLangItem::CompoundAssignmentOperatorToLangItem (
+ expr.get_expr_type ());
+ auto compound_assignment
+ = resolve_operator_overload (lang_item_type, expr, lhs, rhs,
+ expr.get_left_expr ().get (),
+ expr.get_right_expr ().get ());
+ auto assignment
+ = ctx->get_backend ()->expression_statement (fn.fndecl,
+ compound_assignment);
+ ctx->add_statement (assignment);
+
+ return;
+ }
+
+ auto operator_expr
+ = ctx->get_backend ()->arithmetic_or_logical_expression (op, lhs, rhs,
+ expr.get_locus ());
+ tree assignment
+ = ctx->get_backend ()->assignment_statement (fn.fndecl, lhs, operator_expr,
+ expr.get_locus ());
+ ctx->add_statement (assignment);
+}
+
+void
+CompileExpr::visit (HIR::NegationExpr &expr)
+{
+ auto op = expr.get_expr_type ();
+ auto negated_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx);
+ auto location = expr.get_locus ();
+
+ // this might be an operator overload situation lets check
+ TyTy::FnType *fntype;
+ bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
+ expr.get_mappings ().get_hirid (), &fntype);
+ if (is_op_overload)
+ {
+ auto lang_item_type
+ = Analysis::RustLangItem::NegationOperatorToLangItem (op);
+ translated
+ = resolve_operator_overload (lang_item_type, expr, negated_expr,
+ nullptr, expr.get_expr ().get (), nullptr);
+ return;
+ }
+
+ translated
+ = ctx->get_backend ()->negation_expression (op, negated_expr, location);
+}
+
+tree
+CompileExpr::compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn,
+ TyTy::BaseType *receiver,
+ TyTy::FnType *fntype, tree receiver_ref,
+ std::vector<HIR::Expr *> &arguments,
+ Location expr_locus)
+{
+ size_t offs = 0;
+ const Resolver::TraitItemReference *ref = nullptr;
+ for (auto &bound : dyn->get_object_items ())
+ {
+ const Resolver::TraitItemReference *item = bound.first;
+ auto t = item->get_tyty ();
+ rust_assert (t->get_kind () == TyTy::TypeKind::FNDEF);
+ auto ft = static_cast<TyTy::FnType *> (t);
+
+ if (ft->get_id () == fntype->get_id ())
+ {
+ ref = item;
+ break;
+ }
+ offs++;
+ }
+
+ if (ref == nullptr)
+ return ctx->get_backend ()->error_expression ();
+
+ // get any indirection sorted out
+ if (receiver->get_kind () == TyTy::TypeKind::REF)
+ {
+ TyTy::ReferenceType *r = static_cast<TyTy::ReferenceType *> (receiver);
+ auto indirect_ty = r->get_base ();
+ tree indrect_compiled_tyty
+ = TyTyResolveCompile::compile (ctx, indirect_ty);
+
+ tree indirect
+ = ctx->get_backend ()->indirect_expression (indrect_compiled_tyty,
+ receiver_ref, true,
+ expr_locus);
+ receiver_ref = indirect;
+ }
+
+ // access the offs + 1 for the fnptr and offs=0 for the reciever obj
+ tree self_argument
+ = ctx->get_backend ()->struct_field_expression (receiver_ref, 0,
+ expr_locus);
+
+ // access the vtable for the fn
+ tree fn_vtable_access
+ = ctx->get_backend ()->struct_field_expression (receiver_ref, offs + 1,
+ expr_locus);
+
+ // cast it to the correct fntype
+ tree expected_fntype = TyTyResolveCompile::compile (ctx, fntype, true);
+ tree fn_convert_expr
+ = ctx->get_backend ()->convert_expression (expected_fntype,
+ fn_vtable_access, expr_locus);
+
+ fncontext fnctx = ctx->peek_fn ();
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
+ bool is_address_taken = false;
+ tree ret_var_stmt = NULL_TREE;
+ Bvariable *fn_convert_expr_tmp
+ = ctx->get_backend ()->temporary_variable (fnctx.fndecl, enclosing_scope,
+ expected_fntype, fn_convert_expr,
+ is_address_taken, expr_locus,
+ &ret_var_stmt);
+ ctx->add_statement (ret_var_stmt);
+
+ std::vector<tree> args;
+ args.push_back (self_argument);
+ for (auto &argument : arguments)
+ {
+ tree compiled_expr = CompileExpr::Compile (argument, ctx);
+ args.push_back (compiled_expr);
+ }
+
+ tree fn_expr
+ = ctx->get_backend ()->var_expression (fn_convert_expr_tmp, expr_locus);
+
+ return ctx->get_backend ()->call_expression (fnctx.fndecl, fn_expr, args,
+ nullptr, expr_locus);
+}
+
+tree
+CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref,
+ TyTy::BaseType *receiver,
+ HIR::PathIdentSegment &segment,
+ Analysis::NodeMapping expr_mappings,
+ Location expr_locus)
+{
+ // lookup compiled functions since it may have already been compiled
+ tree fn = NULL_TREE;
+ if (ctx->lookup_function_decl (fntype->get_ty_ref (), &fn))
+ {
+ return ctx->get_backend ()->function_code_expression (fn, expr_locus);
+ }
+
+ // Now we can try and resolve the address since this might be a forward
+ // declared function, generic function which has not be compiled yet or
+ // its an not yet trait bound function
+ HIR::ImplItem *resolved_item
+ = ctx->get_mappings ()->lookup_hir_implitem (expr_mappings.get_crate_num (),
+ ref, nullptr);
+ if (resolved_item != nullptr)
+ {
+ if (!fntype->has_subsititions_defined ())
+ return CompileInherentImplItem::Compile (receiver, resolved_item, ctx,
+ true);
+
+ return CompileInherentImplItem::Compile (receiver, resolved_item, ctx,
+ true, fntype);
+ }
+
+ // it might be resolved to a trait item
+ HIR::TraitItem *trait_item = ctx->get_mappings ()->lookup_hir_trait_item (
+ expr_mappings.get_crate_num (), ref);
+ HIR::Trait *trait = ctx->get_mappings ()->lookup_trait_item_mapping (
+ trait_item->get_mappings ().get_hirid ());
+
+ Resolver::TraitReference *trait_ref
+ = &Resolver::TraitReference::error_node ();
+ bool ok = ctx->get_tyctx ()->lookup_trait_reference (
+ trait->get_mappings ().get_defid (), &trait_ref);
+ rust_assert (ok);
+
+ // the type resolver can only resolve type bounds to their trait
+ // item so its up to us to figure out if this path should resolve
+ // to an trait-impl-block-item or if it can be defaulted to the
+ // trait-impl-item's definition
+
+ auto root = receiver->get_root ();
+ std::vector<Resolver::PathProbeCandidate> candidates
+ = Resolver::PathProbeType::Probe (root, segment, true, false, true);
+
+ if (candidates.size () == 0)
+ {
+ // this means we are defaulting back to the trait_item if
+ // possible
+ Resolver::TraitItemReference *trait_item_ref = nullptr;
+ bool ok = trait_ref->lookup_hir_trait_item (*trait_item, &trait_item_ref);
+ rust_assert (ok); // found
+ rust_assert (trait_item_ref->is_optional ()); // has definition
+
+ // FIXME Optional means it has a definition and an associated
+ // block which can be a default implementation, if it does not
+ // contain an implementation we should actually return
+ // error_mark_node
+
+ return CompileTraitItem::Compile (receiver,
+ trait_item_ref->get_hir_trait_item (),
+ ctx, fntype, true, expr_locus);
+ }
+ else
+ {
+ std::vector<Resolver::Adjustment> adjustments;
+ Resolver::PathProbeCandidate *candidate
+ = Resolver::MethodResolution::Select (candidates, root, adjustments);
+
+ // FIXME this will be a case to return error_mark_node, there is
+ // an error scenario where a Trait Foo has a method Bar, but this
+ // receiver does not implement this trait or has an incompatible
+ // implementation and we should just return error_mark_node
+ rust_assert (candidate != nullptr);
+ rust_assert (candidate->is_impl_candidate ());
+
+ HIR::ImplItem *impl_item = candidate->item.impl.impl_item;
+ if (!fntype->has_subsititions_defined ())
+ return CompileInherentImplItem::Compile (receiver, impl_item, ctx,
+ true);
+
+ return CompileInherentImplItem::Compile (receiver, impl_item, ctx, true,
+ fntype);
+ }
+}
+
+tree
+CompileExpr::resolve_operator_overload (
+ Analysis::RustLangItem::ItemType lang_item_type, HIR::OperatorExpr &expr,
+ tree lhs, tree rhs, HIR::Expr *lhs_expr, HIR::Expr *rhs_expr)
+{
+ TyTy::FnType *fntype;
+ bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
+ expr.get_mappings ().get_hirid (), &fntype);
+ rust_assert (is_op_overload);
+
+ // lookup the resolved name
+ NodeId resolved_node_id = UNKNOWN_NODEID;
+ bool ok = ctx->get_resolver ()->lookup_resolved_name (
+ expr.get_mappings ().get_nodeid (), &resolved_node_id);
+ rust_assert (ok);
+
+ // reverse lookup
+ HirId ref;
+ ok = ctx->get_mappings ()->lookup_node_to_hir (
+ expr.get_mappings ().get_crate_num (), resolved_node_id, &ref);
+ rust_assert (ok);
+
+ TyTy::BaseType *receiver = nullptr;
+ ok = ctx->get_tyctx ()->lookup_receiver (expr.get_mappings ().get_hirid (),
+ &receiver);
+ rust_assert (ok);
+
+ bool is_dyn_dispatch
+ = receiver->get_root ()->get_kind () == TyTy::TypeKind::DYNAMIC;
+ bool is_generic_receiver = receiver->get_kind () == TyTy::TypeKind::PARAM;
+ if (is_generic_receiver)
+ {
+ TyTy::ParamType *p = static_cast<TyTy::ParamType *> (receiver);
+ receiver = p->resolve ();
+ }
+
+ if (is_dyn_dispatch)
+ {
+ const TyTy::DynamicObjectType *dyn
+ = static_cast<const TyTy::DynamicObjectType *> (receiver->get_root ());
+
+ std::vector<HIR::Expr *> arguments;
+ if (rhs_expr != nullptr) // can be null for negation_expr (unary ones)
+ arguments.push_back (rhs_expr);
+
+ return compile_dyn_dispatch_call (dyn, receiver, fntype, lhs, arguments,
+ expr.get_locus ());
+ }
+
+ // lookup compiled functions since it may have already been compiled
+ HIR::PathIdentSegment segment_name (
+ Analysis::RustLangItem::ToString (lang_item_type));
+ tree fn_expr
+ = resolve_method_address (fntype, ref, receiver, segment_name,
+ expr.get_mappings (), expr.get_locus ());
+
+ // lookup the autoderef mappings
+ std::vector<Resolver::Adjustment> *adjustments = nullptr;
+ ok = ctx->get_tyctx ()->lookup_autoderef_mappings (
+ expr.get_mappings ().get_hirid (), &adjustments);
+ rust_assert (ok);
+
+ // FIXME refactor this out
+ tree self = lhs;
+ for (auto &adjustment : *adjustments)
+ {
+ switch (adjustment.get_type ())
+ {
+ case Resolver::Adjustment::AdjustmentType::IMM_REF:
+ case Resolver::Adjustment::AdjustmentType::MUT_REF:
+ self
+ = ctx->get_backend ()->address_expression (self,
+ lhs_expr->get_locus ());
+ break;
+
+ case Resolver::Adjustment::AdjustmentType::DEREF_REF:
+ tree expected_type
+ = TyTyResolveCompile::compile (ctx, adjustment.get_expected ());
+ self
+ = ctx->get_backend ()->indirect_expression (expected_type, self,
+ true, /* known_valid*/
+ lhs_expr->get_locus ());
+ break;
+ }
+ }
+
+ std::vector<tree> args;
+ args.push_back (self); // adjusted self
+ if (rhs != nullptr) // can be null for negation_expr (unary ones)
+ args.push_back (rhs);
+
+ auto fncontext = ctx->peek_fn ();
+ return ctx->get_backend ()->call_expression (fncontext.fndecl, fn_expr, args,
+ nullptr, expr.get_locus ());
+}
+
+} // namespace Compile
+} // namespace Rust
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index f43db50..2bf969b 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -33,7 +33,7 @@ class CompileExpr : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bexpression *Compile (HIR::Expr *expr, Context *ctx)
+ static tree Compile (HIR::Expr *expr, Context *ctx)
{
CompileExpr compiler (ctx);
expr->accept_vis (compiler);
@@ -45,7 +45,7 @@ public:
HIR::Expr *tuple_expr = expr.get_tuple_expr ().get ();
TupleIndex index = expr.get_tuple_index ();
- Bexpression *receiver_ref = CompileExpr::Compile (tuple_expr, ctx);
+ tree receiver_ref = CompileExpr::Compile (tuple_expr, ctx);
TyTy::BaseType *tuple_expr_ty = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
@@ -58,9 +58,9 @@ public:
TyTy::ReferenceType *r
= static_cast<TyTy::ReferenceType *> (tuple_expr_ty);
TyTy::BaseType *tuple_type = r->get_base ();
- Btype *tuple_tyty = TyTyResolveCompile::compile (ctx, tuple_type);
+ tree tuple_tyty = TyTyResolveCompile::compile (ctx, tuple_type);
- Bexpression *indirect
+ tree indirect
= ctx->get_backend ()->indirect_expression (tuple_tyty, receiver_ref,
true, expr.get_locus ());
receiver_ref = indirect;
@@ -88,11 +88,11 @@ public:
return;
}
- Btype *tuple_type = TyTyResolveCompile::compile (ctx, tyty);
+ tree tuple_type = TyTyResolveCompile::compile (ctx, tyty);
rust_assert (tuple_type != nullptr);
// this assumes all fields are in order from type resolution
- std::vector<Bexpression *> vals;
+ std::vector<tree> vals;
for (auto &elem : expr.get_tuple_elems ())
{
auto e = CompileExpr::Compile (elem.get (), ctx);
@@ -108,10 +108,10 @@ public:
{
auto fncontext = ctx->peek_fn ();
- std::vector<Bexpression *> retstmts;
+ std::vector<tree> retstmts;
if (expr.has_return_expr ())
{
- Bexpression *compiled_expr
+ tree compiled_expr
= CompileExpr::Compile (expr.return_expr.get (), ctx);
rust_assert (compiled_expr != nullptr);
@@ -204,7 +204,7 @@ public:
gcc_unreachable ();
}
- Bfunction *fn = nullptr;
+ tree fn = NULL_TREE;
Bvariable *var = nullptr;
if (ctx->lookup_const_decl (ref, &translated))
{
@@ -259,7 +259,7 @@ public:
return;
}
- Btype *type = TyTyResolveCompile::compile (ctx, tyty);
+ tree type = TyTyResolveCompile::compile (ctx, tyty);
translated
= ctx->get_backend ()->integer_constant_expression (type, ival);
}
@@ -285,7 +285,7 @@ public:
return;
}
- Btype *type = TyTyResolveCompile::compile (ctx, tyty);
+ tree type = TyTyResolveCompile::compile (ctx, tyty);
translated
= ctx->get_backend ()->float_constant_expression (type, fval);
}
@@ -330,21 +330,19 @@ public:
auto array_tyty = static_cast<TyTy::ArrayType *> (base_tyty);
std::string value_str = expr.get_literal ()->as_string ();
- std::vector<Bexpression *> vals;
+ std::vector<tree> vals;
std::vector<unsigned long> indexes;
for (size_t i = 0; i < value_str.size (); i++)
{
char b = value_str.at (i);
- Bexpression *bb
- = ctx->get_backend ()->char_constant_expression (b);
+ tree bb = ctx->get_backend ()->char_constant_expression (b);
vals.push_back (bb);
indexes.push_back (i);
}
- Btype *array_type = TyTyResolveCompile::compile (ctx, array_tyty);
- Bexpression *constructed
- = ctx->get_backend ()->array_constructor_expression (
- array_type, indexes, vals, expr.get_locus ());
+ tree array_type = TyTyResolveCompile::compile (ctx, array_tyty);
+ tree constructed = ctx->get_backend ()->array_constructor_expression (
+ array_type, indexes, vals, expr.get_locus ());
translated
= ctx->get_backend ()->address_expression (constructed,
@@ -381,17 +379,19 @@ public:
rvalue = coercion_site (rvalue, actual, expected, expr.get_locus ());
- Bstatement *assignment
+ tree assignment
= ctx->get_backend ()->assignment_statement (fn.fndecl, lvalue, rvalue,
expr.get_locus ());
ctx->add_statement (assignment);
}
+ void visit (HIR::CompoundAssignmentExpr &expr) override;
+
void visit (HIR::ArrayIndexExpr &expr) override
{
- Bexpression *array = CompileExpr::Compile (expr.get_array_expr (), ctx);
- Bexpression *index = CompileExpr::Compile (expr.get_index_expr (), ctx);
+ tree array = CompileExpr::Compile (expr.get_array_expr (), ctx);
+ tree index = CompileExpr::Compile (expr.get_index_expr (), ctx);
translated
= ctx->get_backend ()->array_index_expression (array, index,
expr.get_locus ());
@@ -412,7 +412,7 @@ public:
TyTy::ArrayType *array_tyty = static_cast<TyTy::ArrayType *> (tyty);
capacity_expr = array_tyty->get_capacity ();
- Btype *array_type = TyTyResolveCompile::compile (ctx, array_tyty);
+ tree array_type = TyTyResolveCompile::compile (ctx, array_tyty);
rust_assert (array_type != nullptr);
expr.get_internal_elements ()->accept_vis (*this);
@@ -430,14 +430,14 @@ public:
{
for (auto &elem : elems.get_values ())
{
- Bexpression *translated_expr = CompileExpr::Compile (elem.get (), ctx);
+ tree translated_expr = CompileExpr::Compile (elem.get (), ctx);
constructor.push_back (translated_expr);
}
}
void visit (HIR::ArrayElemsCopied &elems) override
{
- Bexpression *translated_expr
+ tree translated_expr
= CompileExpr::Compile (elems.get_elem_to_copy (), ctx);
size_t capacity;
@@ -448,17 +448,7 @@ public:
constructor.push_back (translated_expr);
}
- void visit (HIR::ArithmeticOrLogicalExpr &expr) override
- {
- auto op = expr.get_expr_type ();
- auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx);
- auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
- auto location = expr.get_locus ();
-
- translated
- = ctx->get_backend ()->arithmetic_or_logical_expression (op, lhs, rhs,
- location);
- }
+ void visit (HIR::ArithmeticOrLogicalExpr &expr) override;
void visit (HIR::ComparisonExpr &expr) override
{
@@ -482,15 +472,7 @@ public:
= ctx->get_backend ()->lazy_boolean_expression (op, lhs, rhs, location);
}
- void visit (HIR::NegationExpr &expr) override
- {
- auto op = expr.get_expr_type ();
- auto negated_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx);
- auto location = expr.get_locus ();
-
- translated
- = ctx->get_backend ()->negation_expression (op, negated_expr, location);
- }
+ void visit (HIR::NegationExpr &expr) override;
void visit (HIR::TypeCastExpr &expr) override
{
@@ -532,11 +514,11 @@ public:
if (needs_temp)
{
fncontext fnctx = ctx->peek_fn ();
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Btype *block_type = TyTyResolveCompile::compile (ctx, if_type);
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
+ tree block_type = TyTyResolveCompile::compile (ctx, if_type);
bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = nullptr;
tmp = ctx->get_backend ()->temporary_variable (
fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
expr.get_locus (), &ret_var_stmt);
@@ -569,11 +551,11 @@ public:
if (needs_temp)
{
fncontext fnctx = ctx->peek_fn ();
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Btype *block_type = TyTyResolveCompile::compile (ctx, if_type);
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
+ tree block_type = TyTyResolveCompile::compile (ctx, if_type);
bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = nullptr;
tmp = ctx->get_backend ()->temporary_variable (
fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
expr.get_locus (), &ret_var_stmt);
@@ -605,11 +587,11 @@ public:
if (needs_temp)
{
fncontext fnctx = ctx->peek_fn ();
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Btype *block_type = TyTyResolveCompile::compile (ctx, block_tyty);
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
+ tree block_type = TyTyResolveCompile::compile (ctx, block_tyty);
bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = nullptr;
tmp = ctx->get_backend ()->temporary_variable (
fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
expr.get_locus (), &ret_var_stmt);
@@ -656,15 +638,15 @@ public:
return;
}
- Btype *type = TyTyResolveCompile::compile (ctx, tyty);
+ tree type = TyTyResolveCompile::compile (ctx, tyty);
rust_assert (type != nullptr);
// 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;
+ std::vector<tree> vals;
for (auto &field : struct_expr.get_fields ())
{
- Bexpression *expr = CompileStructExprField::Compile (field.get (), ctx);
+ tree expr = CompileStructExprField::Compile (field.get (), ctx);
vals.push_back (expr);
}
@@ -681,7 +663,7 @@ public:
void visit (HIR::FieldAccessExpr &expr) override
{
- Bexpression *receiver_ref
+ tree receiver_ref
= CompileExpr::Compile (expr.get_receiver_expr ().get (), ctx);
// resolve the receiver back to ADT type
@@ -721,8 +703,8 @@ public:
&field_index);
rust_assert (ok);
- Btype *adt_tyty = TyTyResolveCompile::compile (ctx, adt);
- Bexpression *indirect
+ tree adt_tyty = TyTyResolveCompile::compile (ctx, adt);
+ tree indirect
= ctx->get_backend ()->indirect_expression (adt_tyty, receiver_ref,
true, expr.get_locus ());
receiver_ref = indirect;
@@ -758,11 +740,11 @@ public:
bool needs_temp = !block_tyty->is_unit ();
if (needs_temp)
{
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Btype *block_type = TyTyResolveCompile::compile (ctx, block_tyty);
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
+ tree block_type = TyTyResolveCompile::compile (ctx, block_tyty);
bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = NULL_TREE;
tmp = ctx->get_backend ()->temporary_variable (
fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
expr.get_locus (), &ret_var_stmt);
@@ -773,29 +755,29 @@ public:
if (expr.has_loop_label ())
{
HIR::LoopLabel &loop_label = expr.get_loop_label ();
- Blabel *label
+ tree label
= ctx->get_backend ()->label (fnctx.fndecl,
loop_label.get_lifetime ().get_name (),
loop_label.get_locus ());
- Bstatement *label_decl
+ tree label_decl
= ctx->get_backend ()->label_definition_statement (label);
ctx->add_statement (label_decl);
ctx->insert_label_decl (
loop_label.get_lifetime ().get_mappings ().get_hirid (), label);
}
- Blabel *loop_begin_label
+ tree loop_begin_label
= ctx->get_backend ()->label (fnctx.fndecl, "", expr.get_locus ());
- Bstatement *loop_begin_label_decl
+ tree loop_begin_label_decl
= ctx->get_backend ()->label_definition_statement (loop_begin_label);
ctx->add_statement (loop_begin_label_decl);
ctx->push_loop_begin_label (loop_begin_label);
- Bblock *code_block
+ tree code_block
= CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
- Bexpression *loop_expr
+ tree loop_expr
= ctx->get_backend ()->loop_expression (code_block, expr.get_locus ());
- Bstatement *loop_stmt
+ tree loop_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl, loop_expr);
ctx->add_statement (loop_stmt);
@@ -814,11 +796,11 @@ public:
if (expr.has_loop_label ())
{
HIR::LoopLabel &loop_label = expr.get_loop_label ();
- Blabel *label
+ tree label
= ctx->get_backend ()->label (fnctx.fndecl,
loop_label.get_lifetime ().get_name (),
loop_label.get_locus ());
- Bstatement *label_decl
+ tree label_decl
= ctx->get_backend ()->label_definition_statement (label);
ctx->add_statement (label_decl);
ctx->insert_label_decl (
@@ -829,39 +811,38 @@ public:
Location start_location = expr.get_loop_block ()->get_locus ();
Location end_location = expr.get_loop_block ()->get_locus (); // FIXME
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Bblock *loop_block
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
+ tree loop_block
= ctx->get_backend ()->block (fnctx.fndecl, enclosing_scope, locals,
start_location, end_location);
ctx->push_block (loop_block);
- Blabel *loop_begin_label
+ tree loop_begin_label
= ctx->get_backend ()->label (fnctx.fndecl, "", expr.get_locus ());
- Bstatement *loop_begin_label_decl
+ tree loop_begin_label_decl
= ctx->get_backend ()->label_definition_statement (loop_begin_label);
ctx->add_statement (loop_begin_label_decl);
ctx->push_loop_begin_label (loop_begin_label);
- Bexpression *condition
+ tree condition
= CompileExpr::Compile (expr.get_predicate_expr ().get (), ctx);
- Bexpression *exit_expr
+ tree exit_expr
= ctx->get_backend ()->exit_expression (condition, expr.get_locus ());
- Bstatement *break_stmt
+ tree break_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl, exit_expr);
ctx->add_statement (break_stmt);
- Bblock *code_block
+ tree code_block
= CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
- Bstatement *code_block_stmt
- = ctx->get_backend ()->block_statement (code_block);
+ tree code_block_stmt = ctx->get_backend ()->block_statement (code_block);
ctx->add_statement (code_block_stmt);
ctx->pop_loop_begin_label ();
ctx->pop_block ();
- Bexpression *loop_expr
+ tree loop_expr
= ctx->get_backend ()->loop_expression (loop_block, expr.get_locus ());
- Bstatement *loop_stmt
+ tree loop_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl, loop_expr);
ctx->add_statement (loop_stmt);
}
@@ -871,14 +852,14 @@ public:
fncontext fnctx = ctx->peek_fn ();
if (expr.has_break_expr ())
{
- Bexpression *compiled_expr
+ tree compiled_expr
= CompileExpr::Compile (expr.get_expr ().get (), ctx);
Bvariable *loop_result_holder = ctx->peek_loop_context ();
- Bexpression *result_reference = ctx->get_backend ()->var_expression (
+ tree result_reference = ctx->get_backend ()->var_expression (
loop_result_holder, expr.get_expr ()->get_locus ());
- Bstatement *assignment = ctx->get_backend ()->assignment_statement (
+ tree assignment = ctx->get_backend ()->assignment_statement (
fnctx.fndecl, result_reference, compiled_expr, expr.get_locus ());
ctx->add_statement (assignment);
}
@@ -906,7 +887,7 @@ public:
return;
}
- Blabel *label = nullptr;
+ tree label = NULL_TREE;
if (!ctx->lookup_label_decl (ref, &label))
{
rust_error_at (expr.get_label ().get_locus (),
@@ -914,16 +895,16 @@ public:
return;
}
- Bstatement *goto_label
+ tree goto_label
= ctx->get_backend ()->goto_statement (label, expr.get_locus ());
ctx->add_statement (goto_label);
}
else
{
- Bexpression *exit_expr = ctx->get_backend ()->exit_expression (
+ tree exit_expr = ctx->get_backend ()->exit_expression (
ctx->get_backend ()->boolean_constant_expression (true),
expr.get_locus ());
- Bstatement *break_stmt
+ tree break_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl, exit_expr);
ctx->add_statement (break_stmt);
}
@@ -931,7 +912,7 @@ public:
void visit (HIR::ContinueExpr &expr) override
{
- Blabel *label = ctx->peek_loop_begin_label ();
+ tree label = ctx->peek_loop_begin_label ();
if (expr.has_label ())
{
NodeId resolved_node_id = UNKNOWN_NODEID;
@@ -963,15 +944,14 @@ public:
}
}
- Bstatement *goto_label
+ tree goto_label
= ctx->get_backend ()->goto_statement (label, expr.get_locus ());
ctx->add_statement (goto_label);
}
void visit (HIR::BorrowExpr &expr) override
{
- Bexpression *main_expr
- = CompileExpr::Compile (expr.get_expr ().get (), ctx);
+ tree main_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx);
translated
= ctx->get_backend ()->address_expression (main_expr, expr.get_locus ());
@@ -979,8 +959,7 @@ public:
void visit (HIR::DereferenceExpr &expr) override
{
- Bexpression *main_expr
- = CompileExpr::Compile (expr.get_expr ().get (), ctx);
+ tree main_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx);
TyTy::BaseType *tyty = nullptr;
if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (),
@@ -991,7 +970,7 @@ public:
return;
}
- Btype *expected_type = TyTyResolveCompile::compile (ctx, tyty);
+ tree expected_type = TyTyResolveCompile::compile (ctx, tyty);
bool known_valid = true;
translated
= ctx->get_backend ()->indirect_expression (expected_type, main_expr,
@@ -999,14 +978,32 @@ public:
expr.get_locus ());
}
+protected:
+ tree compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn,
+ TyTy::BaseType *receiver,
+ TyTy::FnType *fntype, tree receiver_ref,
+ std::vector<HIR::Expr *> &arguments,
+ Location expr_locus);
+
+ tree resolve_method_address (TyTy::FnType *fntype, HirId ref,
+ TyTy::BaseType *receiver,
+ HIR::PathIdentSegment &segment,
+ Analysis::NodeMapping expr_mappings,
+ Location expr_locus);
+
+ tree
+ resolve_operator_overload (Analysis::RustLangItem::ItemType lang_item_type,
+ HIR::OperatorExpr &expr, tree lhs, tree rhs,
+ HIR::Expr *lhs_expr, HIR::Expr *rhs_expr);
+
private:
CompileExpr (Context *ctx)
: HIRCompileBase (ctx), translated (nullptr), capacity_expr (nullptr)
{}
- Bexpression *translated;
- Bexpression *capacity_expr;
- std::vector<Bexpression *> constructor;
+ tree translated;
+ tree capacity_expr;
+ std::vector<tree> constructor;
};
} // namespace Compile
diff --git a/gcc/rust/backend/rust-compile-extern.h b/gcc/rust/backend/rust-compile-extern.h
index 6e5a3fd..aa73509 100644
--- a/gcc/rust/backend/rust-compile-extern.h
+++ b/gcc/rust/backend/rust-compile-extern.h
@@ -55,7 +55,7 @@ public:
// FIXME this is assuming C ABI
std::string asm_name = name;
- Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
+ tree type = TyTyResolveCompile::compile (ctx, resolved_type);
bool is_external = true;
bool is_hidden = false;
bool in_unique_section = false;
@@ -99,14 +99,14 @@ public:
// items can be forward compiled which means we may not need to invoke this
// code. We might also have already compiled this generic function as well.
- Bfunction *lookup = nullptr;
+ tree lookup = NULL_TREE;
if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup,
fntype->get_id (), fntype))
{
// has this been added to the list then it must be finished
if (ctx->function_completed (lookup))
{
- Bfunction *dummy = nullptr;
+ tree dummy = NULL_TREE;
if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
ctx->insert_function_decl (fntype, lookup);
@@ -123,12 +123,12 @@ public:
if (fntype->get_abi () == ABI::INTRINSIC)
{
Intrinsics compile (ctx);
- Bfunction *fndecl = compile.compile (fntype);
+ tree fndecl = compile.compile (fntype);
ctx->insert_function_decl (fntype, fndecl);
return;
}
- ::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
+ tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
compiled_fn_type
= ctx->get_backend ()->specify_abi_attribute (compiled_fn_type,
fntype->get_abi ());
@@ -139,7 +139,7 @@ public:
std::string ir_symbol_name = function.get_item_name ();
std::string asm_name = function.get_item_name ();
- Bfunction *fndecl
+ tree fndecl
= ctx->get_backend ()->function (compiled_fn_type, ir_symbol_name,
asm_name, flags, function.get_locus ());
ctx->insert_function_decl (fntype, fndecl);
diff --git a/gcc/rust/backend/rust-compile-fnparam.h b/gcc/rust/backend/rust-compile-fnparam.h
index b246948..629f0f5 100644
--- a/gcc/rust/backend/rust-compile-fnparam.h
+++ b/gcc/rust/backend/rust-compile-fnparam.h
@@ -29,8 +29,8 @@ class CompileFnParam : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bvariable *compile (Context *ctx, Bfunction *fndecl,
- HIR::FunctionParam *param, Btype *decl_type,
+ static Bvariable *compile (Context *ctx, tree fndecl,
+ HIR::FunctionParam *param, tree decl_type,
Location locus)
{
CompileFnParam compiler (ctx, fndecl, decl_type, locus);
@@ -51,14 +51,13 @@ public:
}
private:
- CompileFnParam (Context *ctx, ::Bfunction *fndecl, ::Btype *decl_type,
- Location locus)
+ CompileFnParam (Context *ctx, tree fndecl, tree decl_type, Location locus)
: HIRCompileBase (ctx), fndecl (fndecl), decl_type (decl_type),
locus (locus), translated (nullptr)
{}
- ::Bfunction *fndecl;
- ::Btype *decl_type;
+ tree fndecl;
+ tree decl_type;
Location locus;
::Bvariable *translated;
};
@@ -66,9 +65,8 @@ private:
class CompileSelfParam : public HIRCompileBase
{
public:
- static Bvariable *compile (Context *ctx, Bfunction *fndecl,
- HIR::SelfParam &self, Btype *decl_type,
- Location locus)
+ static Bvariable *compile (Context *ctx, tree fndecl, HIR::SelfParam &self,
+ tree decl_type, Location locus)
{
bool is_immutable
= self.get_self_kind () == HIR::SelfParam::ImplicitSelfKind::IMM
diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h
index 05c7910..7b41226 100644
--- a/gcc/rust/backend/rust-compile-implitem.h
+++ b/gcc/rust/backend/rust-compile-implitem.h
@@ -34,11 +34,11 @@ class CompileInherentImplItem : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bexpression *Compile (const TyTy::BaseType *self, HIR::ImplItem *item,
- Context *ctx, bool compile_fns,
- TyTy::BaseType *concrete = nullptr,
- bool is_query_mode = false,
- Location ref_locus = Location ())
+ static tree Compile (const TyTy::BaseType *self, HIR::ImplItem *item,
+ Context *ctx, bool compile_fns,
+ TyTy::BaseType *concrete = nullptr,
+ bool is_query_mode = false,
+ Location ref_locus = Location ())
{
CompileInherentImplItem compiler (self, ctx, compile_fns, concrete,
ref_locus);
@@ -60,8 +60,8 @@ public:
&resolved_type);
rust_assert (ok);
- ::Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
- Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
+ tree type = TyTyResolveCompile::compile (ctx, resolved_type);
+ tree value = CompileExpr::Compile (constant.get_expr (), ctx);
const Resolver::CanonicalPath *canonical_path = nullptr;
ok = ctx->get_mappings ()->lookup_canonical_path (
@@ -70,7 +70,7 @@ public:
rust_assert (ok);
std::string ident = canonical_path->get ();
- Bexpression *const_expr = ctx->get_backend ()->named_constant_expression (
+ tree const_expr = ctx->get_backend ()->named_constant_expression (
type, constant.get_identifier (), value, constant.get_locus ());
ctx->push_const (const_expr);
@@ -110,14 +110,14 @@ public:
// items can be forward compiled which means we may not need to invoke this
// code. We might also have already compiled this generic function as well.
- Bfunction *lookup = nullptr;
+ tree lookup = NULL_TREE;
if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup,
fntype->get_id (), fntype))
{
// has this been added to the list then it must be finished
if (ctx->function_completed (lookup))
{
- Bfunction *dummy = nullptr;
+ tree dummy = NULL_TREE;
if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
{
ctx->insert_function_decl (fntype, lookup);
@@ -136,7 +136,7 @@ public:
}
// convert to the actual function type
- ::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
+ tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
unsigned int flags = 0;
@@ -156,7 +156,7 @@ public:
std::string asm_name
= ctx->mangle_impl_item (self, fntype, function.get_function_name ());
- Bfunction *fndecl
+ tree fndecl
= ctx->get_backend ()->function (compiled_fn_type, ir_symbol_name,
asm_name, flags, function.get_locus ());
ctx->insert_function_decl (fntype, fndecl);
@@ -178,7 +178,7 @@ public:
return;
}
- Btype *self_type = TyTyResolveCompile::compile (ctx, self_tyty_lookup);
+ tree self_type = TyTyResolveCompile::compile (ctx, self_tyty_lookup);
if (self_type == nullptr)
{
rust_error_at (function.get_self_param ().get_locus (),
@@ -262,12 +262,12 @@ public:
ok = compile_locals_for_block (*rib, fndecl, locals);
rust_assert (ok);
- Bblock *enclosing_scope = NULL;
+ tree enclosing_scope = NULL_TREE;
HIR::BlockExpr *function_body = function.get_definition ().get ();
Location start_location = function_body->get_locus ();
Location end_location = function_body->get_closing_locus ();
- Bblock *code_block
+ tree code_block
= ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
start_location, end_location);
ctx->push_block (code_block);
@@ -275,10 +275,10 @@ public:
Bvariable *return_address = nullptr;
if (function.has_function_return_type ())
{
- Btype *return_type = TyTyResolveCompile::compile (ctx, tyret);
+ tree return_type = TyTyResolveCompile::compile (ctx, tyret);
bool address_is_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = NULL_TREE;
return_address = ctx->get_backend ()->temporary_variable (
fndecl, code_block, return_type, NULL, address_is_taken,
@@ -319,7 +319,7 @@ private:
const TyTy::BaseType *self;
bool compile_fns;
TyTy::BaseType *concrete;
- Bexpression *reference;
+ tree reference;
Location ref_locus;
};
@@ -328,10 +328,10 @@ class CompileTraitItem : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bexpression *Compile (const TyTy::BaseType *self, HIR::TraitItem *item,
- Context *ctx, TyTy::BaseType *concrete,
- bool is_query_mode = false,
- Location ref_locus = Location ())
+ static tree Compile (const TyTy::BaseType *self, HIR::TraitItem *item,
+ Context *ctx, TyTy::BaseType *concrete,
+ bool is_query_mode = false,
+ Location ref_locus = Location ())
{
CompileTraitItem compiler (self, ctx, concrete, ref_locus);
item->accept_vis (compiler);
@@ -349,9 +349,8 @@ public:
rust_assert (concrete != nullptr);
TyTy::BaseType *resolved_type = concrete;
- ::Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
- Bexpression *value
- = CompileExpr::Compile (constant.get_expr ().get (), ctx);
+ tree type = TyTyResolveCompile::compile (ctx, resolved_type);
+ tree value = CompileExpr::Compile (constant.get_expr ().get (), ctx);
const Resolver::CanonicalPath *canonical_path = nullptr;
bool ok = ctx->get_mappings ()->lookup_canonical_path (
@@ -360,7 +359,7 @@ public:
rust_assert (ok);
std::string ident = canonical_path->get ();
- Bexpression *const_expr = ctx->get_backend ()->named_constant_expression (
+ tree const_expr = ctx->get_backend ()->named_constant_expression (
type, constant.get_name (), value, constant.get_locus ());
ctx->push_const (const_expr);
@@ -378,14 +377,14 @@ public:
// items can be forward compiled which means we may not need to invoke this
// code. We might also have already compiled this generic function as well.
- Bfunction *lookup = nullptr;
+ tree lookup = NULL_TREE;
if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup,
fntype->get_id (), fntype))
{
// has this been added to the list then it must be finished
if (ctx->function_completed (lookup))
{
- Bfunction *dummy = nullptr;
+ tree dummy = NULL_TREE;
if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
{
ctx->insert_function_decl (fntype, lookup);
@@ -404,7 +403,7 @@ public:
}
// convert to the actual function type
- ::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
+ tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
HIR::TraitFunctionDecl &function = func.get_decl ();
unsigned int flags = 0;
@@ -418,7 +417,7 @@ public:
std::string fn_identifier = canonical_path->get ();
std::string asm_name = ctx->mangle_item (fntype, *canonical_path);
- Bfunction *fndecl
+ tree fndecl
= ctx->get_backend ()->function (compiled_fn_type, fn_identifier,
asm_name, flags, func.get_locus ());
ctx->insert_function_decl (fntype, fndecl);
@@ -440,7 +439,7 @@ public:
return;
}
- Btype *self_type = TyTyResolveCompile::compile (ctx, self_tyty_lookup);
+ tree self_type = TyTyResolveCompile::compile (ctx, self_tyty_lookup);
if (self_type == nullptr)
{
rust_error_at (function.get_self ().get_locus (),
@@ -523,12 +522,12 @@ public:
ok = compile_locals_for_block (*rib, fndecl, locals);
rust_assert (ok);
- Bblock *enclosing_scope = NULL;
+ tree enclosing_scope = NULL_TREE;
HIR::BlockExpr *function_body = func.get_block_expr ().get ();
Location start_location = function_body->get_locus ();
Location end_location = function_body->get_closing_locus ();
- Bblock *code_block
+ tree code_block
= ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
start_location, end_location);
ctx->push_block (code_block);
@@ -536,10 +535,10 @@ public:
Bvariable *return_address = nullptr;
if (function.has_return_type ())
{
- Btype *return_type = TyTyResolveCompile::compile (ctx, tyret);
+ tree return_type = TyTyResolveCompile::compile (ctx, tyret);
bool address_is_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = NULL_TREE;
return_address = ctx->get_backend ()->temporary_variable (
fndecl, code_block, return_type, NULL, address_is_taken,
@@ -578,7 +577,7 @@ private:
const TyTy::BaseType *self;
TyTy::BaseType *concrete;
- Bexpression *reference;
+ tree reference;
Location ref_locus;
};
diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc
index 66d36e3..69626a9 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -21,7 +21,7 @@ namespace Compile {
Intrinsics::Intrinsics (Context *ctx) : ctx (ctx) {}
-Bfunction *
+tree
Intrinsics::compile (TyTy::FnType *fntype)
{
rust_assert (fntype->get_abi () == ABI::INTRINSIC);
@@ -77,7 +77,7 @@ Intrinsics::compile (TyTy::FnType *fntype)
// };
// Some(cx.get_intrinsic(&llvm_name))
- Bfunction *builtin = ctx->get_backend ()->lookup_builtin_by_rust_name (
+ tree builtin = ctx->get_backend ()->lookup_builtin_by_rust_name (
fntype->get_identifier ());
if (builtin != nullptr)
return builtin;
diff --git a/gcc/rust/backend/rust-compile-intrinsic.h b/gcc/rust/backend/rust-compile-intrinsic.h
index 25e298a..2d44baa 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.h
+++ b/gcc/rust/backend/rust-compile-intrinsic.h
@@ -27,7 +27,7 @@ class Intrinsics
public:
Intrinsics (Context *ctx);
- Bfunction *compile (TyTy::FnType *fntype);
+ tree compile (TyTy::FnType *fntype);
private:
Context *ctx;
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index 6691c2a..5af9ab3 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -37,11 +37,10 @@ protected:
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bexpression *compile (HIR::Item *item, Context *ctx,
- bool compile_fns = true,
- TyTy::BaseType *concrete = nullptr,
- bool is_query_mode = false,
- Location ref_locus = Location ())
+ static tree compile (HIR::Item *item, Context *ctx, bool compile_fns = true,
+ TyTy::BaseType *concrete = nullptr,
+ bool is_query_mode = false,
+ Location ref_locus = Location ())
{
CompileItem compiler (ctx, compile_fns, concrete, ref_locus);
item->accept_vis (compiler);
@@ -61,8 +60,8 @@ public:
&resolved_type);
rust_assert (ok);
- Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
- Bexpression *value = CompileExpr::Compile (var.get_expr (), ctx);
+ tree type = TyTyResolveCompile::compile (ctx, resolved_type);
+ tree value = CompileExpr::Compile (var.get_expr (), ctx);
const Resolver::CanonicalPath *canonical_path = nullptr;
ok = ctx->get_mappings ()->lookup_canonical_path (
@@ -97,8 +96,8 @@ public:
&resolved_type);
rust_assert (ok);
- ::Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
- Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
+ tree type = TyTyResolveCompile::compile (ctx, resolved_type);
+ tree value = CompileExpr::Compile (constant.get_expr (), ctx);
const Resolver::CanonicalPath *canonical_path = nullptr;
ok = ctx->get_mappings ()->lookup_canonical_path (
@@ -107,7 +106,7 @@ public:
rust_assert (ok);
std::string ident = canonical_path->get ();
- Bexpression *const_expr
+ tree const_expr
= ctx->get_backend ()->named_constant_expression (type, ident, value,
constant.get_locus ());
@@ -148,14 +147,14 @@ public:
// items can be forward compiled which means we may not need to invoke this
// code. We might also have already compiled this generic function as well.
- Bfunction *lookup = nullptr;
+ tree lookup = NULL_TREE;
if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup,
fntype->get_id (), fntype))
{
// has this been added to the list then it must be finished
if (ctx->function_completed (lookup))
{
- Bfunction *dummy = nullptr;
+ tree dummy = NULL_TREE;
if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
{
ctx->insert_function_decl (fntype, lookup);
@@ -174,7 +173,7 @@ public:
fntype->override_context ();
}
- ::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
+ tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
unsigned int flags = 0;
bool is_main_fn = function.get_function_name ().compare ("main") == 0;
@@ -202,7 +201,7 @@ public:
asm_name = ctx->mangle_item (fntype, *canonical_path);
}
- Bfunction *fndecl
+ tree fndecl
= ctx->get_backend ()->function (compiled_fn_type, ir_symbol_name,
asm_name, flags, function.get_locus ());
ctx->insert_function_decl (fntype, fndecl);
@@ -262,12 +261,12 @@ public:
ok = compile_locals_for_block (*rib, fndecl, locals);
rust_assert (ok);
- Bblock *enclosing_scope = NULL;
+ tree enclosing_scope = NULL_TREE;
HIR::BlockExpr *function_body = function.get_definition ().get ();
Location start_location = function_body->get_locus ();
Location end_location = function_body->get_closing_locus ();
- Bblock *code_block
+ tree code_block
= ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
start_location, end_location);
ctx->push_block (code_block);
@@ -275,10 +274,10 @@ public:
Bvariable *return_address = nullptr;
if (function.has_function_return_type ())
{
- Btype *return_type = TyTyResolveCompile::compile (ctx, tyret);
+ tree return_type = TyTyResolveCompile::compile (ctx, tyret);
bool address_is_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = NULL_TREE;
return_address = ctx->get_backend ()->temporary_variable (
fndecl, code_block, return_type, NULL, address_is_taken,
@@ -347,7 +346,7 @@ protected:
bool compile_fns;
TyTy::BaseType *concrete;
- Bexpression *reference;
+ tree reference;
Location ref_locus;
};
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index d571d4a..cb3f0df 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -40,7 +40,7 @@ ResolvePathRef::visit (HIR::PathInExpression &expr)
expr.get_mappings (), expr.get_locus (), false);
}
-Bexpression *
+tree
ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment,
const Analysis::NodeMapping &mappings,
Location expr_locus, bool is_qualified_path)
@@ -76,7 +76,7 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment,
}
// might be a constant
- Bexpression *constant_expr;
+ tree constant_expr;
if (ctx->lookup_const_decl (ref, &constant_expr))
return constant_expr;
@@ -92,7 +92,7 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment,
if (lookup->get_kind () == TyTy::TypeKind::FNDEF)
{
TyTy::FnType *fntype = static_cast<TyTy::FnType *> (lookup);
- Bfunction *fn = nullptr;
+ tree fn = NULL_TREE;
if (ctx->lookup_function_decl (fntype->get_ty_ref (), &fn))
{
return ctx->get_backend ()->function_code_expression (fn, expr_locus);
@@ -104,7 +104,7 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment,
is_qualified_path);
}
-Bexpression *
+tree
ResolvePathRef::query_compile (HirId ref, TyTy::BaseType *lookup,
const HIR::PathIdentSegment &final_segment,
const Analysis::NodeMapping &mappings,
diff --git a/gcc/rust/backend/rust-compile-resolve-path.h b/gcc/rust/backend/rust-compile-resolve-path.h
index ecb89b3..56f82d1 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.h
+++ b/gcc/rust/backend/rust-compile-resolve-path.h
@@ -30,15 +30,14 @@ class ResolvePathRef : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bexpression *Compile (HIR::QualifiedPathInExpression &expr,
- Context *ctx)
+ static tree Compile (HIR::QualifiedPathInExpression &expr, Context *ctx)
{
ResolvePathRef resolver (ctx);
expr.accept_vis (resolver);
return resolver.resolved;
}
- static Bexpression *Compile (HIR::PathInExpression &expr, Context *ctx)
+ static tree Compile (HIR::PathInExpression &expr, Context *ctx)
{
ResolvePathRef resolver (ctx);
expr.accept_vis (resolver);
@@ -54,16 +53,16 @@ private:
: HIRCompileBase (ctx), resolved (ctx->get_backend ()->error_expression ())
{}
- Bexpression *resolve (const HIR::PathIdentSegment &final_segment,
- const Analysis::NodeMapping &mappings, Location locus,
- bool is_qualified_path);
+ tree resolve (const HIR::PathIdentSegment &final_segment,
+ const Analysis::NodeMapping &mappings, Location locus,
+ bool is_qualified_path);
- Bexpression *query_compile (HirId ref, TyTy::BaseType *lookup,
- const HIR::PathIdentSegment &final_segment,
- const Analysis::NodeMapping &mappings,
- Location expr_locus, bool is_qualified_path);
+ tree query_compile (HirId ref, TyTy::BaseType *lookup,
+ const HIR::PathIdentSegment &final_segment,
+ const Analysis::NodeMapping &mappings,
+ Location expr_locus, bool is_qualified_path);
- Bexpression *resolved;
+ tree resolved;
};
} // namespace Compile
diff --git a/gcc/rust/backend/rust-compile-stmt.h b/gcc/rust/backend/rust-compile-stmt.h
index 754c5d2..f3ee69d 100644
--- a/gcc/rust/backend/rust-compile-stmt.h
+++ b/gcc/rust/backend/rust-compile-stmt.h
@@ -31,7 +31,7 @@ class CompileStmt : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bexpression *Compile (HIR::Stmt *stmt, Context *ctx)
+ static tree Compile (HIR::Stmt *stmt, Context *ctx)
{
CompileStmt compiler (ctx);
stmt->accept_vis (compiler);
@@ -56,8 +56,8 @@ public:
&resolved_type);
rust_assert (ok);
- ::Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
- Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
+ tree type = TyTyResolveCompile::compile (ctx, resolved_type);
+ tree value = CompileExpr::Compile (constant.get_expr (), ctx);
const Resolver::CanonicalPath *canonical_path = nullptr;
ok = ctx->get_mappings ()->lookup_canonical_path (
@@ -66,7 +66,7 @@ public:
rust_assert (ok);
std::string ident = canonical_path->get ();
- Bexpression *const_expr
+ tree const_expr
= ctx->get_backend ()->named_constant_expression (type, ident, value,
constant.get_locus ());
@@ -101,7 +101,7 @@ public:
return;
}
- Bexpression *init = CompileExpr::Compile (stmt.get_init_expr (), ctx);
+ tree init = CompileExpr::Compile (stmt.get_init_expr (), ctx);
// FIXME use error_mark_node, check that CompileExpr returns error_mark_node
// on failure and make this an assertion
if (init == nullptr)
@@ -118,7 +118,7 @@ public:
auto fnctx = ctx->peek_fn ();
if (ty->is_unit ())
{
- Bstatement *expr_stmt
+ tree expr_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl, init);
ctx->add_statement (expr_stmt);
}
@@ -132,7 +132,7 @@ public:
private:
CompileStmt (Context *ctx) : HIRCompileBase (ctx), translated (nullptr) {}
- Bexpression *translated;
+ tree translated;
};
} // namespace Compile
diff --git a/gcc/rust/backend/rust-compile-struct-field-expr.h b/gcc/rust/backend/rust-compile-struct-field-expr.h
index 553e870..6754e8c 100644
--- a/gcc/rust/backend/rust-compile-struct-field-expr.h
+++ b/gcc/rust/backend/rust-compile-struct-field-expr.h
@@ -30,7 +30,7 @@ class CompileStructExprField : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bexpression *Compile (HIR::StructExprField *field, Context *ctx)
+ static tree Compile (HIR::StructExprField *field, Context *ctx)
{
CompileStructExprField compiler (ctx);
field->accept_vis (compiler);
@@ -49,7 +49,7 @@ private:
: HIRCompileBase (ctx), translated (nullptr)
{}
- Bexpression *translated;
+ tree translated;
};
} // namespace Compile
diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h
index 180b971..04a3ecd 100644
--- a/gcc/rust/backend/rust-compile-tyty.h
+++ b/gcc/rust/backend/rust-compile-tyty.h
@@ -34,7 +34,7 @@ namespace Compile {
class TyTyCompile : public TyTy::TyVisitor
{
public:
- static ::Btype *compile (::Backend *backend, TyTy::BaseType *ty)
+ static tree compile (::Backend *backend, TyTy::BaseType *ty)
{
TyTyCompile compiler (backend);
ty->accept_vis (compiler);
@@ -72,15 +72,15 @@ public:
void visit (TyTy::FnType &type) override
{
- Backend::Btyped_identifier receiver;
- std::vector<Backend::Btyped_identifier> parameters;
- std::vector<Backend::Btyped_identifier> results;
+ Backend::typed_identifier receiver;
+ std::vector<Backend::typed_identifier> parameters;
+ std::vector<Backend::typed_identifier> results;
if (!type.get_return_type ()->is_unit ())
{
auto hir_type = type.get_return_type ();
auto ret = TyTyCompile::compile (backend, hir_type);
- results.push_back (Backend::Btyped_identifier (
+ results.push_back (Backend::typed_identifier (
"_", ret, mappings->lookup_location (hir_type->get_ref ())));
}
@@ -90,7 +90,7 @@ public:
auto param_tyty = params.second;
auto compiled_param_type = TyTyCompile::compile (backend, param_tyty);
- auto compiled_param = Backend::Btyped_identifier (
+ auto compiled_param = Backend::typed_identifier (
param_pattern->as_string (), compiled_param_type,
mappings->lookup_location (param_tyty->get_ref ()));
@@ -227,7 +227,7 @@ public:
void visit (TyTy::StrType &) override
{
- Btype *raw_str = backend->raw_str_type ();
+ tree raw_str = backend->raw_str_type ();
translated
= backend->named_type ("str", raw_str, Linemap::predeclared_location ());
}
@@ -248,7 +248,7 @@ private:
{}
::Backend *backend;
- ::Btype *translated;
+ tree translated;
Analysis::Mappings *mappings;
};
diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h
index 7a86e15..a964fa2 100644
--- a/gcc/rust/backend/rust-compile-var-decl.h
+++ b/gcc/rust/backend/rust-compile-var-decl.h
@@ -29,8 +29,7 @@ class CompileVarDecl : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static ::Bvariable *compile (::Bfunction *fndecl, HIR::Stmt *stmt,
- Context *ctx)
+ static ::Bvariable *compile (tree fndecl, HIR::Stmt *stmt, Context *ctx)
{
CompileVarDecl compiler (ctx, fndecl);
stmt->accept_vis (compiler);
@@ -64,13 +63,13 @@ public:
}
private:
- CompileVarDecl (Context *ctx, ::Bfunction *fndecl)
+ CompileVarDecl (Context *ctx, tree fndecl)
: HIRCompileBase (ctx), fndecl (fndecl), translated_type (nullptr),
translated (nullptr)
{}
- ::Bfunction *fndecl;
- ::Btype *translated_type;
+ tree fndecl;
+ tree translated_type;
Location locus;
::Bvariable *translated;
};
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index e9aca2c..579b323 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -72,7 +72,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
{
rust_assert (tyty->get_kind () == TyTy::TypeKind::ADT);
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (tyty);
- Btype *compiled_adt_type = TyTyResolveCompile::compile (ctx, tyty);
+ tree compiled_adt_type = TyTyResolveCompile::compile (ctx, tyty);
rust_assert (!adt->is_enum ());
rust_assert (adt->number_of_variants () == 1);
@@ -80,7 +80,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
// 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;
+ std::vector<tree> vals;
for (size_t i = 0; i < expr.get_arguments ().size (); i++)
{
auto &argument = expr.get_arguments ().at (i);
@@ -150,7 +150,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
required_num_args = fn->num_params ();
}
- std::vector<Bexpression *> args;
+ std::vector<tree> args;
for (size_t i = 0; i < expr.get_arguments ().size (); i++)
{
auto &argument = expr.get_arguments ().at (i);
@@ -195,7 +195,7 @@ void
CompileExpr::visit (HIR::MethodCallExpr &expr)
{
// method receiver
- Bexpression *self = CompileExpr::Compile (expr.get_receiver ().get (), ctx);
+ tree self = CompileExpr::Compile (expr.get_receiver ().get (), ctx);
// lookup the resolved name
NodeId resolved_node_id = UNKNOWN_NODEID;
@@ -242,220 +242,21 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
const TyTy::DynamicObjectType *dyn
= static_cast<const TyTy::DynamicObjectType *> (receiver->get_root ());
- size_t offs = 0;
- const Resolver::TraitItemReference *ref = nullptr;
- for (auto &bound : dyn->get_object_items ())
- {
- const Resolver::TraitItemReference *item = bound.first;
- auto t = item->get_tyty ();
- rust_assert (t->get_kind () == TyTy::TypeKind::FNDEF);
- auto ft = static_cast<TyTy::FnType *> (t);
-
- if (ft->get_id () == fntype->get_id ())
- {
- ref = item;
- break;
- }
- offs++;
- }
-
- if (ref == nullptr)
- {
- translated = ctx->get_backend ()->error_expression ();
- return;
- }
-
- // get any indirection sorted out
- auto receiver_ref = self;
- if (receiver->get_kind () == TyTy::TypeKind::REF)
- {
- TyTy::ReferenceType *r
- = static_cast<TyTy::ReferenceType *> (receiver);
- auto indirect_ty = r->get_base ();
- Btype *indrect_compiled_tyty
- = TyTyResolveCompile::compile (ctx, indirect_ty);
-
- Bexpression *indirect
- = ctx->get_backend ()->indirect_expression (indrect_compiled_tyty,
- receiver_ref, true,
- expr.get_locus ());
- receiver_ref = indirect;
- }
-
- // access the offs + 1 for the fnptr and offs=0 for the reciever obj
- Bexpression *self_argument
- = ctx->get_backend ()->struct_field_expression (receiver_ref, 0,
- expr.get_locus ());
-
- // access the vtable for the fn
- Bexpression *fn_vtable_access
- = ctx->get_backend ()->struct_field_expression (receiver_ref, offs + 1,
- expr.get_locus ());
-
- // cast it to the correct fntype
- Btype *expected_fntype = TyTyResolveCompile::compile (ctx, fntype, true);
- Bexpression *fn_convert_expr
- = ctx->get_backend ()->convert_expression (expected_fntype,
- fn_vtable_access,
- expr.get_locus ());
-
- fncontext fnctx = ctx->peek_fn ();
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
-
- Bvariable *fn_convert_expr_tmp = ctx->get_backend ()->temporary_variable (
- fnctx.fndecl, enclosing_scope, expected_fntype, fn_convert_expr,
- is_address_taken, expr.get_locus (), &ret_var_stmt);
- ctx->add_statement (ret_var_stmt);
-
- std::vector<Bexpression *> args;
- args.push_back (self_argument);
- for (auto &argument : expr.get_arguments ())
- {
- Bexpression *compiled_expr
- = CompileExpr::Compile (argument.get (), ctx);
- args.push_back (compiled_expr);
- }
-
- Bexpression *fn_expr
- = ctx->get_backend ()->var_expression (fn_convert_expr_tmp,
- expr.get_locus ());
+ std::vector<HIR::Expr *> arguments;
+ for (auto &arg : expr.get_arguments ())
+ arguments.push_back (arg.get ());
- translated
- = ctx->get_backend ()->call_expression (fnctx.fndecl, fn_expr, args,
- nullptr, expr.get_locus ());
+ translated = compile_dyn_dispatch_call (dyn, receiver, fntype, self,
+ arguments, expr.get_locus ());
return;
}
- // address of compiled function
- Bexpression *fn_expr = ctx->get_backend ()->error_expression ();
-
// lookup compiled functions since it may have already been compiled
- Bfunction *fn = nullptr;
- if (ctx->lookup_function_decl (fntype->get_ty_ref (), &fn))
- {
- fn_expr
- = ctx->get_backend ()->function_code_expression (fn, expr.get_locus ());
- }
- else
- {
- // Now we can try and resolve the address since this might be a forward
- // declared function, generic function which has not be compiled yet or
- // its an not yet trait bound function
- HIR::ImplItem *resolved_item = ctx->get_mappings ()->lookup_hir_implitem (
- expr.get_mappings ().get_crate_num (), ref, nullptr);
- if (resolved_item == nullptr)
- {
- // it might be resolved to a trait item
- HIR::TraitItem *trait_item
- = ctx->get_mappings ()->lookup_hir_trait_item (
- expr.get_mappings ().get_crate_num (), ref);
- HIR::Trait *trait = ctx->get_mappings ()->lookup_trait_item_mapping (
- trait_item->get_mappings ().get_hirid ());
-
- Resolver::TraitReference *trait_ref
- = &Resolver::TraitReference::error_node ();
- bool ok = ctx->get_tyctx ()->lookup_trait_reference (
- trait->get_mappings ().get_defid (), &trait_ref);
- rust_assert (ok);
-
- // the type resolver can only resolve type bounds to their trait
- // item so its up to us to figure out if this path should resolve
- // to an trait-impl-block-item or if it can be defaulted to the
- // trait-impl-item's definition
-
- auto root = receiver->get_root ();
- std::vector<Resolver::PathProbeCandidate> candidates
- = Resolver::PathProbeType::Probe (
- root, expr.get_method_name ().get_segment (), true, false, true);
-
- if (candidates.size () == 0)
- {
- // this means we are defaulting back to the trait_item if
- // possible
- Resolver::TraitItemReference *trait_item_ref = nullptr;
- bool ok = trait_ref->lookup_hir_trait_item (*trait_item,
- &trait_item_ref);
- rust_assert (ok); // found
- rust_assert (trait_item_ref->is_optional ()); // has definition
-
- // FIXME Optional means it has a definition and an associated
- // block which can be a default implementation, if it does not
- // contain an implementation we should actually return
- // error_mark_node
-
- TyTy::BaseType *self_type = nullptr;
- if (!ctx->get_tyctx ()->lookup_type (
- expr.get_receiver ()->get_mappings ().get_hirid (),
- &self_type))
- {
- rust_error_at (expr.get_locus (),
- "failed to resolve type for self param");
- return;
- }
-
- fn_expr = CompileTraitItem::Compile (
- self_type, trait_item_ref->get_hir_trait_item (), ctx, fntype,
- true, expr.get_locus ());
- }
- else
- {
- std::vector<Resolver::Adjustment> adjustments;
- Resolver::PathProbeCandidate *candidate
- = Resolver::MethodResolution::Select (candidates, root,
- adjustments);
-
- // FIXME this will be a case to return error_mark_node, there is
- // an error scenario where a Trait Foo has a method Bar, but this
- // receiver does not implement this trait or has an incompatible
- // implementation and we should just return error_mark_node
- rust_assert (candidate != nullptr);
- rust_assert (candidate->is_impl_candidate ());
-
- HIR::ImplItem *impl_item = candidate->item.impl.impl_item;
-
- TyTy::BaseType *self_type = nullptr;
- if (!ctx->get_tyctx ()->lookup_type (
- expr.get_receiver ()->get_mappings ().get_hirid (),
- &self_type))
- {
- rust_error_at (expr.get_locus (),
- "failed to resolve type for self param");
- return;
- }
-
- if (!fntype->has_subsititions_defined ())
- fn_expr
- = CompileInherentImplItem::Compile (self_type, impl_item, ctx,
- true);
- else
- fn_expr
- = CompileInherentImplItem::Compile (self_type, impl_item, ctx,
- true, fntype);
- }
- }
- else
- {
- TyTy::BaseType *self_type = nullptr;
- if (!ctx->get_tyctx ()->lookup_type (
- expr.get_receiver ()->get_mappings ().get_hirid (), &self_type))
- {
- rust_error_at (expr.get_locus (),
- "failed to resolve type for self param");
- return;
- }
-
- if (!fntype->has_subsititions_defined ())
- fn_expr
- = CompileInherentImplItem::Compile (self_type, resolved_item, ctx,
- true);
- else
- fn_expr
- = CompileInherentImplItem::Compile (self_type, resolved_item, ctx,
- true, fntype);
- }
- }
+ HIR::PathExprSegment method_name = expr.get_method_name ();
+ HIR::PathIdentSegment segment_name = method_name.get_segment ();
+ tree fn_expr
+ = resolve_method_address (fntype, ref, receiver, segment_name,
+ expr.get_mappings (), expr.get_locus ());
// lookup the autoderef mappings
std::vector<Resolver::Adjustment> *adjustments = nullptr;
@@ -474,7 +275,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
break;
case Resolver::Adjustment::AdjustmentType::DEREF_REF:
- Btype *expected_type
+ tree expected_type
= TyTyResolveCompile::compile (ctx, adjustment.get_expected ());
self = ctx->get_backend ()->indirect_expression (
expected_type, self, true, /* known_valid*/
@@ -483,7 +284,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
}
}
- std::vector<Bexpression *> args;
+ std::vector<tree> args;
args.push_back (self); // adjusted self
// normal args
@@ -521,7 +322,7 @@ void
CompileBlock::visit (HIR::BlockExpr &expr)
{
fncontext fnctx = ctx->peek_fn ();
- Bfunction *fndecl = fnctx.fndecl;
+ tree fndecl = fnctx.fndecl;
Location start_location = expr.get_locus ();
Location end_location = expr.get_closing_locus ();
auto body_mappings = expr.get_mappings ();
@@ -537,10 +338,9 @@ CompileBlock::visit (HIR::BlockExpr &expr)
bool ok = compile_locals_for_block (*rib, fndecl, locals);
rust_assert (ok);
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Bblock *new_block
- = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
- start_location, end_location);
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
+ tree new_block = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
+ start_location, end_location);
ctx->push_block (new_block);
for (auto &s : expr.get_statements ())
@@ -548,7 +348,7 @@ CompileBlock::visit (HIR::BlockExpr &expr)
auto compiled_expr = CompileStmt::Compile (s.get (), ctx);
if (compiled_expr != nullptr)
{
- Bstatement *compiled_stmt
+ tree compiled_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl,
compiled_expr);
ctx->add_statement (compiled_stmt);
@@ -559,23 +359,22 @@ CompileBlock::visit (HIR::BlockExpr &expr)
{
// the previous passes will ensure this is a valid return or
// a valid trailing expression
- Bexpression *compiled_expr = CompileExpr::Compile (expr.expr.get (), ctx);
+ tree compiled_expr = CompileExpr::Compile (expr.expr.get (), ctx);
if (compiled_expr != nullptr)
{
if (result == nullptr)
{
- Bstatement *final_stmt
+ tree final_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl,
compiled_expr);
ctx->add_statement (final_stmt);
}
else
{
- Bexpression *result_reference
- = ctx->get_backend ()->var_expression (
- result, expr.get_final_expr ()->get_locus ());
+ tree result_reference = ctx->get_backend ()->var_expression (
+ result, expr.get_final_expr ()->get_locus ());
- Bstatement *assignment
+ tree assignment
= ctx->get_backend ()->assignment_statement (fnctx.fndecl,
result_reference,
compiled_expr,
@@ -593,11 +392,9 @@ void
CompileConditionalBlocks::visit (HIR::IfExpr &expr)
{
fncontext fnctx = ctx->peek_fn ();
- Bfunction *fndecl = fnctx.fndecl;
- Bexpression *condition_expr
- = CompileExpr::Compile (expr.get_if_condition (), ctx);
- Bblock *then_block
- = CompileBlock::compile (expr.get_if_block (), ctx, result);
+ tree fndecl = fnctx.fndecl;
+ tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
+ tree then_block = CompileBlock::compile (expr.get_if_block (), ctx, result);
translated
= ctx->get_backend ()->if_statement (fndecl, condition_expr, then_block,
@@ -608,13 +405,10 @@ void
CompileConditionalBlocks::visit (HIR::IfExprConseqElse &expr)
{
fncontext fnctx = ctx->peek_fn ();
- Bfunction *fndecl = fnctx.fndecl;
- Bexpression *condition_expr
- = CompileExpr::Compile (expr.get_if_condition (), ctx);
- Bblock *then_block
- = CompileBlock::compile (expr.get_if_block (), ctx, result);
- Bblock *else_block
- = CompileBlock::compile (expr.get_else_block (), ctx, result);
+ tree fndecl = fnctx.fndecl;
+ tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
+ tree then_block = CompileBlock::compile (expr.get_if_block (), ctx, result);
+ tree else_block = CompileBlock::compile (expr.get_else_block (), ctx, result);
translated
= ctx->get_backend ()->if_statement (fndecl, condition_expr, then_block,
@@ -625,23 +419,20 @@ void
CompileConditionalBlocks::visit (HIR::IfExprConseqIf &expr)
{
fncontext fnctx = ctx->peek_fn ();
- Bfunction *fndecl = fnctx.fndecl;
- Bexpression *condition_expr
- = CompileExpr::Compile (expr.get_if_condition (), ctx);
- Bblock *then_block
- = CompileBlock::compile (expr.get_if_block (), ctx, result);
+ tree fndecl = fnctx.fndecl;
+ tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
+ tree then_block = CompileBlock::compile (expr.get_if_block (), ctx, result);
// else block
std::vector<Bvariable *> locals;
Location start_location = expr.get_conseq_if_expr ()->get_locus ();
Location end_location = expr.get_conseq_if_expr ()->get_locus (); // FIXME
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Bblock *else_block
- = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
- start_location, end_location);
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
+ tree else_block = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
+ start_location, end_location);
ctx->push_block (else_block);
- Bstatement *else_stmt_decl
+ tree else_stmt_decl
= CompileConditionalBlocks::compile (expr.get_conseq_if_expr (), ctx,
result);
ctx->add_statement (else_stmt_decl);
@@ -681,7 +472,7 @@ CompileStructExprField::visit (HIR::StructExprFieldIdentifier &field)
void
HIRCompileBase::compile_function_body (
- Bfunction *fndecl, std::unique_ptr<HIR::BlockExpr> &function_body,
+ tree fndecl, std::unique_ptr<HIR::BlockExpr> &function_body,
bool has_return_type)
{
for (auto &s : function_body->get_statements ())
@@ -689,7 +480,7 @@ HIRCompileBase::compile_function_body (
auto compiled_expr = CompileStmt::Compile (s.get (), ctx);
if (compiled_expr != nullptr)
{
- Bstatement *compiled_stmt
+ tree compiled_stmt
= ctx->get_backend ()->expression_statement (fndecl, compiled_expr);
ctx->add_statement (compiled_stmt);
}
@@ -699,14 +490,14 @@ HIRCompileBase::compile_function_body (
{
// the previous passes will ensure this is a valid return
// or a valid trailing expression
- Bexpression *compiled_expr
+ tree compiled_expr
= CompileExpr::Compile (function_body->expr.get (), ctx);
if (compiled_expr != nullptr)
{
if (has_return_type)
{
- std::vector<Bexpression *> retstmts;
+ std::vector<tree> retstmts;
retstmts.push_back (compiled_expr);
auto ret = ctx->get_backend ()->return_statement (
@@ -716,7 +507,7 @@ HIRCompileBase::compile_function_body (
}
else
{
- Bstatement *final_stmt
+ tree final_stmt
= ctx->get_backend ()->expression_statement (fndecl,
compiled_expr);
ctx->add_statement (final_stmt);
@@ -726,7 +517,7 @@ HIRCompileBase::compile_function_body (
}
bool
-HIRCompileBase::compile_locals_for_block (Resolver::Rib &rib, Bfunction *fndecl,
+HIRCompileBase::compile_locals_for_block (Resolver::Rib &rib, tree fndecl,
std::vector<Bvariable *> &locals)
{
rib.iterate_decls ([&] (NodeId n, Location) mutable -> bool {
@@ -760,10 +551,9 @@ HIRCompileBase::compile_locals_for_block (Resolver::Rib &rib, Bfunction *fndecl,
return true;
}
-Bexpression *
-HIRCompileBase::coercion_site (Bexpression *compiled_ref,
- TyTy::BaseType *actual, TyTy::BaseType *expected,
- Location locus)
+tree
+HIRCompileBase::coercion_site (tree compiled_ref, TyTy::BaseType *actual,
+ TyTy::BaseType *expected, Location locus)
{
auto root_actual_kind = actual->get_root ()->get_kind ();
auto root_expected_kind = expected->get_root ()->get_kind ();
@@ -779,14 +569,14 @@ HIRCompileBase::coercion_site (Bexpression *compiled_ref,
return compiled_ref;
}
-Bexpression *
-HIRCompileBase::coerce_to_dyn_object (Bexpression *compiled_ref,
+tree
+HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
const TyTy::BaseType *actual,
const TyTy::BaseType *expected,
const TyTy::DynamicObjectType *ty,
Location locus)
{
- Btype *dynamic_object = TyTyResolveCompile::compile (ctx, ty);
+ tree dynamic_object = TyTyResolveCompile::compile (ctx, ty);
//' this assumes ordering and current the structure is
// __trait_object_ptr
@@ -796,7 +586,7 @@ HIRCompileBase::coerce_to_dyn_object (Bexpression *compiled_ref,
std::vector<std::pair<Resolver::TraitReference *, HIR::ImplBlock *>>
probed_bounds_for_receiver = Resolver::TypeBoundsProbe::Probe (root);
- std::vector<Bexpression *> vals;
+ std::vector<tree> vals;
vals.push_back (compiled_ref);
for (auto &bound : ty->get_object_items ())
{
@@ -809,14 +599,14 @@ HIRCompileBase::coerce_to_dyn_object (Bexpression *compiled_ref,
vals.push_back (address);
}
- Bexpression *constructed_trait_object
+ tree constructed_trait_object
= ctx->get_backend ()->constructor_expression (dynamic_object, vals, -1,
locus);
fncontext fnctx = ctx->peek_fn ();
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = NULL_TREE;
Bvariable *dyn_tmp = ctx->get_backend ()->temporary_variable (
fnctx.fndecl, enclosing_scope, dynamic_object, constructed_trait_object,
@@ -858,7 +648,7 @@ HIRCompileBase::coerce_to_dyn_object (Bexpression *compiled_ref,
return resulting_dyn_object_ref;
}
-Bexpression *
+tree
HIRCompileBase::compute_address_for_trait_item (
const Resolver::TraitItemReference *ref,
const TyTy::TypeBoundPredicate *predicate,