aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Faust <david.faust@oracle.com>2021-11-15 11:17:26 -0800
committerDavid Faust <david.faust@oracle.com>2021-11-16 13:04:58 -0800
commitb52a68d2d8676ea378f0fbb6726639cc80402542 (patch)
treefa70c52eb6f879864fa76908a2cf670b50d88e48
parent7a751f354a91a8459b877c60a5e5d78203aeb3ce (diff)
downloadgcc-b52a68d2d8676ea378f0fbb6726639cc80402542.zip
gcc-b52a68d2d8676ea378f0fbb6726639cc80402542.tar.gz
gcc-b52a68d2d8676ea378f0fbb6726639cc80402542.tar.bz2
Replace Bexpression with GCC tree
-rw-r--r--gcc/rust/backend/rust-compile-base.h14
-rw-r--r--gcc/rust/backend/rust-compile-context.h15
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc31
-rw-r--r--gcc/rust/backend/rust-compile-expr.h96
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h31
-rw-r--r--gcc/rust/backend/rust-compile-item.h17
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc6
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.h21
-rw-r--r--gcc/rust/backend/rust-compile-stmt.h10
-rw-r--r--gcc/rust/backend/rust-compile-struct-field-expr.h4
-rw-r--r--gcc/rust/backend/rust-compile.cc47
-rw-r--r--gcc/rust/rust-backend.h173
-rw-r--r--gcc/rust/rust-gcc.cc528
-rw-r--r--gcc/rust/typecheck/rust-hir-const-fold-ctx.h6
-rw-r--r--gcc/rust/typecheck/rust-hir-const-fold.cc12
-rw-r--r--gcc/rust/typecheck/rust-hir-const-fold.h20
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.h7
-rw-r--r--gcc/rust/typecheck/rust-tyty.h8
18 files changed, 455 insertions, 591 deletions
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h
index 3184e27..5650451 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -200,16 +200,14 @@ protected:
bool compile_locals_for_block (Resolver::Rib &rib, Bfunction *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-context.h b/gcc/rust/backend/rust-compile-context.h
index 82c02f8..35ea012 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -210,12 +210,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 ())
@@ -249,7 +246,7 @@ public:
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_const (::tree c) { const_decls.push_back (c); }
void push_function (::Bfunction *f) { func_decls.push_back (f); }
void write_to_backend ()
@@ -322,9 +319,9 @@ private:
// state
std::vector<fncontext> fn_stack;
std::map<HirId, ::Bvariable *> compiled_var_decls;
- std::map<HirId, ::tree > compiled_type_map;
+ std::map<HirId, tree> compiled_type_map;
std::map<HirId, ::Bfunction *> compiled_fn_map;
- std::map<HirId, ::Bexpression *> compiled_consts;
+ std::map<HirId, tree> compiled_consts;
std::map<HirId, ::Blabel *> compiled_labels;
std::vector<::std::vector<Bstatement *>> statements;
std::vector<::Bblock *> scope_stack;
@@ -337,7 +334,7 @@ private:
// To GCC middle-end
std::vector<tree> type_decls;
std::vector<::Bvariable *> var_decls;
- std::vector<::Bexpression *> const_decls;
+ std::vector<tree> const_decls;
std::vector<::Bfunction *> func_decls;
};
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 0279ef9..d475ec4 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -117,11 +117,10 @@ CompileExpr::visit (HIR::NegationExpr &expr)
= ctx->get_backend ()->negation_expression (op, negated_expr, location);
}
-Bexpression *
+tree
CompileExpr::compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn,
TyTy::BaseType *receiver,
- TyTy::FnType *fntype,
- Bexpression *receiver_ref,
+ TyTy::FnType *fntype, tree receiver_ref,
std::vector<HIR::Expr *> &arguments,
Location expr_locus)
{
@@ -153,7 +152,7 @@ CompileExpr::compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn,
tree indrect_compiled_tyty
= TyTyResolveCompile::compile (ctx, indirect_ty);
- Bexpression *indirect
+ tree indirect
= ctx->get_backend ()->indirect_expression (indrect_compiled_tyty,
receiver_ref, true,
expr_locus);
@@ -161,18 +160,18 @@ CompileExpr::compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn,
}
// access the offs + 1 for the fnptr and offs=0 for the reciever obj
- Bexpression *self_argument
+ tree self_argument
= ctx->get_backend ()->struct_field_expression (receiver_ref, 0,
expr_locus);
// access the vtable for the fn
- Bexpression *fn_vtable_access
+ 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);
- Bexpression *fn_convert_expr
+ tree fn_convert_expr
= ctx->get_backend ()->convert_expression (expected_fntype,
fn_vtable_access, expr_locus);
@@ -187,22 +186,22 @@ CompileExpr::compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn,
&ret_var_stmt);
ctx->add_statement (ret_var_stmt);
- std::vector<Bexpression *> args;
+ std::vector<tree> args;
args.push_back (self_argument);
for (auto &argument : arguments)
{
- Bexpression *compiled_expr = CompileExpr::Compile (argument, ctx);
+ tree compiled_expr = CompileExpr::Compile (argument, ctx);
args.push_back (compiled_expr);
}
- Bexpression *fn_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);
}
-Bexpression *
+tree
CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref,
TyTy::BaseType *receiver,
HIR::PathIdentSegment &segment,
@@ -294,10 +293,10 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref,
}
}
-Bexpression *
+tree
CompileExpr::resolve_operator_overload (
Analysis::RustLangItem::ItemType lang_item_type, HIR::OperatorExpr &expr,
- Bexpression *lhs, Bexpression *rhs, HIR::Expr *lhs_expr, HIR::Expr *rhs_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 (
@@ -346,7 +345,7 @@ CompileExpr::resolve_operator_overload (
// lookup compiled functions since it may have already been compiled
HIR::PathIdentSegment segment_name (
Analysis::RustLangItem::ToString (lang_item_type));
- Bexpression *fn_expr
+ tree fn_expr
= resolve_method_address (fntype, ref, receiver, segment_name,
expr.get_mappings (), expr.get_locus ());
@@ -357,7 +356,7 @@ CompileExpr::resolve_operator_overload (
rust_assert (ok);
// FIXME refactor this out
- Bexpression *self = lhs;
+ tree self = lhs;
for (auto &adjustment : *adjustments)
{
switch (adjustment.get_type ())
@@ -380,7 +379,7 @@ CompileExpr::resolve_operator_overload (
}
}
- std::vector<Bexpression *> args;
+ 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);
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index d2f79ec..2f6395c 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 (
@@ -60,7 +60,7 @@ public:
TyTy::BaseType *tuple_type = r->get_base ();
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;
@@ -92,7 +92,7 @@ public:
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);
@@ -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);
}
tree array_type = TyTyResolveCompile::compile (ctx, array_tyty);
- Bexpression *constructed
- = ctx->get_backend ()->array_constructor_expression (
- array_type, indexes, vals, expr.get_locus ());
+ tree constructed = ctx->get_backend ()->array_constructor_expression (
+ array_type, indexes, vals, expr.get_locus ());
translated
= ctx->get_backend ()->address_expression (constructed,
@@ -392,8 +390,8 @@ public:
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 ());
@@ -432,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;
@@ -645,10 +643,10 @@ public:
// 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);
}
@@ -665,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
@@ -706,7 +704,7 @@ public:
rust_assert (ok);
tree adt_tyty = TyTyResolveCompile::compile (ctx, adt);
- Bexpression *indirect
+ tree indirect
= ctx->get_backend ()->indirect_expression (adt_tyty, receiver_ref,
true, expr.get_locus ());
receiver_ref = indirect;
@@ -777,7 +775,7 @@ public:
Bblock *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
= ctx->get_backend ()->expression_statement (fnctx.fndecl, loop_expr);
@@ -826,9 +824,9 @@ public:
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
= ctx->get_backend ()->expression_statement (fnctx.fndecl, exit_expr);
@@ -843,7 +841,7 @@ public:
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
= ctx->get_backend ()->expression_statement (fnctx.fndecl, loop_expr);
@@ -855,11 +853,11 @@ 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 (
@@ -904,7 +902,7 @@ public:
}
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
@@ -954,8 +952,7 @@ public:
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 ());
@@ -963,8 +960,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 (),
@@ -984,33 +980,31 @@ public:
}
protected:
- Bexpression *compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn,
- TyTy::BaseType *receiver,
- TyTy::FnType *fntype,
- Bexpression *receiver_ref,
- std::vector<HIR::Expr *> &arguments,
- Location expr_locus);
-
- Bexpression *resolve_method_address (TyTy::FnType *fntype, HirId ref,
- TyTy::BaseType *receiver,
- HIR::PathIdentSegment &segment,
- Analysis::NodeMapping expr_mappings,
- Location expr_locus);
-
- Bexpression *
+ 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, Bexpression *lhs,
- Bexpression *rhs, HIR::Expr *lhs_expr,
- HIR::Expr *rhs_expr);
+ 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-implitem.h b/gcc/rust/backend/rust-compile-implitem.h
index 51a691f..65f3d2c 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);
@@ -61,7 +61,7 @@ public:
rust_assert (ok);
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
- Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
+ 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);
@@ -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);
@@ -350,8 +350,7 @@ public:
TyTy::BaseType *resolved_type = concrete;
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
- Bexpression *value
- = CompileExpr::Compile (constant.get_expr ().get (), ctx);
+ 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);
@@ -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-item.h b/gcc/rust/backend/rust-compile-item.h
index 87c577c..95de611 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);
@@ -62,7 +61,7 @@ public:
rust_assert (ok);
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
- Bexpression *value = CompileExpr::Compile (var.get_expr (), ctx);
+ tree value = CompileExpr::Compile (var.get_expr (), ctx);
const Resolver::CanonicalPath *canonical_path = nullptr;
ok = ctx->get_mappings ()->lookup_canonical_path (
@@ -98,7 +97,7 @@ public:
rust_assert (ok);
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
- Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
+ 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 ());
@@ -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..81ffad8 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;
@@ -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 80566f6..604d9a5 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);
@@ -57,7 +57,7 @@ public:
rust_assert (ok);
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
- Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
+ 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)
@@ -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.cc b/gcc/rust/backend/rust-compile.cc
index cb736f3..3531930 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -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;
@@ -254,7 +254,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
// lookup compiled functions since it may have already been compiled
HIR::PathExprSegment method_name = expr.get_method_name ();
HIR::PathIdentSegment segment_name = method_name.get_segment ();
- Bexpression *fn_expr
+ tree fn_expr
= resolve_method_address (fntype, ref, receiver, segment_name,
expr.get_mappings (), expr.get_locus ());
@@ -284,7 +284,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
}
}
- std::vector<Bexpression *> args;
+ std::vector<tree> args;
args.push_back (self); // adjusted self
// normal args
@@ -360,7 +360,7 @@ 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)
@@ -372,9 +372,8 @@ CompileBlock::visit (HIR::BlockExpr &expr)
}
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
= ctx->get_backend ()->assignment_statement (fnctx.fndecl,
@@ -395,8 +394,7 @@ CompileConditionalBlocks::visit (HIR::IfExpr &expr)
{
fncontext fnctx = ctx->peek_fn ();
Bfunction *fndecl = fnctx.fndecl;
- Bexpression *condition_expr
- = CompileExpr::Compile (expr.get_if_condition (), ctx);
+ tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
Bblock *then_block
= CompileBlock::compile (expr.get_if_block (), ctx, result);
@@ -410,8 +408,7 @@ CompileConditionalBlocks::visit (HIR::IfExprConseqElse &expr)
{
fncontext fnctx = ctx->peek_fn ();
Bfunction *fndecl = fnctx.fndecl;
- Bexpression *condition_expr
- = CompileExpr::Compile (expr.get_if_condition (), ctx);
+ tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
Bblock *then_block
= CompileBlock::compile (expr.get_if_block (), ctx, result);
Bblock *else_block
@@ -427,8 +424,7 @@ CompileConditionalBlocks::visit (HIR::IfExprConseqIf &expr)
{
fncontext fnctx = ctx->peek_fn ();
Bfunction *fndecl = fnctx.fndecl;
- Bexpression *condition_expr
- = CompileExpr::Compile (expr.get_if_condition (), ctx);
+ tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
Bblock *then_block
= CompileBlock::compile (expr.get_if_block (), ctx, result);
@@ -500,14 +496,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 (
@@ -561,10 +557,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 ();
@@ -580,8 +575,8 @@ 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,
@@ -597,7 +592,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 ())
{
@@ -610,7 +605,7 @@ 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);
@@ -659,7 +654,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,
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index 3bdd0c6..49b9eea 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -41,9 +41,6 @@ saw_errors (void);
// frontend, and passed back to the backend. The types must be
// defined by the backend using these names.
-// The backend represention of an expression.
-class Bexpression;
-
// The backend representation of a statement.
class Bstatement;
@@ -87,7 +84,6 @@ public:
// debug
virtual void debug (tree) = 0;
- virtual void debug (Bexpression *) = 0;
virtual void debug (Bstatement *) = 0;
virtual void debug (Bfunction *) = 0;
virtual void debug (Bblock *) = 0;
@@ -95,9 +91,9 @@ public:
virtual void debug (Blabel *) = 0;
// const folder helpers
- virtual bool const_size_cast (Bexpression *, size_t *) = 0;
- virtual std::string const_size_val_to_string (Bexpression *) = 0;
- virtual bool const_values_equal (Bexpression *, Bexpression *) = 0;
+ virtual bool const_size_cast (tree, size_t *) = 0;
+ virtual std::string const_size_val_to_string (tree) = 0;
+ virtual bool const_values_equal (tree, tree) = 0;
static Rust::ABI get_abi_from_string (const std::string &abi, Location locus)
{
@@ -226,7 +222,7 @@ public:
virtual tree union_type (const std::vector<typed_identifier> &fields) = 0;
// Get an array type.
- virtual tree array_type (tree element_type, Bexpression *length) = 0;
+ virtual tree array_type (tree element_type, tree length) = 0;
// Return a named version of a type. The location is the location
// of the type definition. This will not be called for a type
@@ -255,165 +251,148 @@ public:
// Return an expression for a zero value of the given type. This is
// used for cases such as local variable initialization and
// converting nil to other types.
- virtual Bexpression *zero_expression (tree) = 0;
+ virtual tree zero_expression (tree) = 0;
// Create an error expression. This is used for cases which should
// not occur in a correct program, in order to keep the compilation
// going without crashing.
- virtual Bexpression *error_expression () = 0;
+ virtual tree error_expression () = 0;
// return whether this is error_mark_node
- virtual bool is_error_expression (Bexpression *) = 0;
+ virtual bool is_error_expression (tree) = 0;
// Create a nil pointer expression.
- virtual Bexpression *nil_pointer_expression () = 0;
+ virtual tree nil_pointer_expression () = 0;
- virtual Bexpression *unit_expression () = 0;
+ virtual tree unit_expression () = 0;
// Create a reference to a variable.
- virtual Bexpression *var_expression (Bvariable *var, Location) = 0;
+ virtual tree var_expression (Bvariable *var, Location) = 0;
// Create an expression that indirects through the pointer expression EXPR
// (i.e., return the expression for *EXPR). KNOWN_VALID is true if the pointer
// is known to point to a valid memory location. BTYPE is the expected type
// of the indirected EXPR.
- virtual Bexpression *indirect_expression (tree btype, Bexpression *expr,
- bool known_valid, Location)
+ virtual tree indirect_expression (tree btype, tree expr, bool known_valid,
+ Location)
= 0;
// Return an expression that declares a constant named NAME with the
// constant value VAL in BTYPE.
- virtual Bexpression *named_constant_expression (tree btype,
- const std::string &name,
- Bexpression *val, Location)
+ virtual tree named_constant_expression (tree btype, const std::string &name,
+ tree val, Location)
= 0;
// Return an expression for the multi-precision integer VAL in BTYPE.
- virtual Bexpression *integer_constant_expression (tree btype, mpz_t val) = 0;
+ virtual tree integer_constant_expression (tree btype, mpz_t val) = 0;
// Return an expression for the floating point value VAL in BTYPE.
- virtual Bexpression *float_constant_expression (tree btype, mpfr_t val) = 0;
+ virtual tree float_constant_expression (tree btype, mpfr_t val) = 0;
// Return an expression for the complex value VAL in BTYPE.
- virtual Bexpression *complex_constant_expression (tree btype, mpc_t val) = 0;
+ virtual tree complex_constant_expression (tree btype, mpc_t val) = 0;
// Return an expression for the string value VAL.
- virtual Bexpression *string_constant_expression (const std::string &val) = 0;
+ virtual tree string_constant_expression (const std::string &val) = 0;
// Get a char literal
- virtual Bexpression *char_constant_expression (char c) = 0;
+ virtual tree char_constant_expression (char c) = 0;
// Get a char literal
- virtual Bexpression *wchar_constant_expression (wchar_t c) = 0;
+ virtual tree wchar_constant_expression (wchar_t c) = 0;
// Return an expression for the boolean value VAL.
- virtual Bexpression *boolean_constant_expression (bool val) = 0;
+ virtual tree boolean_constant_expression (bool val) = 0;
// Return an expression for the real part of BCOMPLEX.
- virtual Bexpression *real_part_expression (Bexpression *bcomplex, Location)
- = 0;
+ virtual tree real_part_expression (tree bcomplex, Location) = 0;
// Return an expression for the imaginary part of BCOMPLEX.
- virtual Bexpression *imag_part_expression (Bexpression *bcomplex, Location)
- = 0;
+ virtual tree imag_part_expression (tree bcomplex, Location) = 0;
// Return an expression for the complex number (BREAL, BIMAG).
- virtual Bexpression *complex_expression (Bexpression *breal,
- Bexpression *bimag, Location)
- = 0;
+ virtual tree complex_expression (tree breal, tree bimag, Location) = 0;
// Return an expression that converts EXPR to TYPE.
- virtual Bexpression *convert_expression (tree type, Bexpression *expr,
- Location)
- = 0;
+ virtual tree convert_expression (tree type, tree expr, Location) = 0;
// Create an expression for the address of a function. This is used to
// get the address of the code for a function.
- virtual Bexpression *function_code_expression (Bfunction *, Location) = 0;
+ virtual tree function_code_expression (Bfunction *, Location) = 0;
// Create an expression that takes the address of an expression.
- virtual Bexpression *address_expression (Bexpression *, Location) = 0;
+ virtual tree address_expression (tree, Location) = 0;
// Return an expression for the field at INDEX in BSTRUCT.
- virtual Bexpression *struct_field_expression (Bexpression *bstruct,
- size_t index, Location)
+ virtual tree struct_field_expression (tree bstruct, size_t index, Location)
= 0;
// Create an expression that executes BSTAT before BEXPR.
- virtual Bexpression *compound_expression (Bstatement *bstat,
- Bexpression *bexpr, Location)
+ virtual tree compound_expression (Bstatement *bstat, tree bexpr, Location)
= 0;
// Return an expression that executes THEN_EXPR if CONDITION is true, or
// ELSE_EXPR otherwise and returns the result as type BTYPE, within the
// specified function FUNCTION. ELSE_EXPR may be NULL. BTYPE may be NULL.
- virtual Bexpression *conditional_expression (Bfunction *function, tree btype,
- Bexpression *condition,
- Bexpression *then_expr,
- Bexpression *else_expr, Location)
+ virtual tree conditional_expression (Bfunction *function, tree btype,
+ tree condition, tree then_expr,
+ tree else_expr, Location)
= 0;
// Return an expression for the negation operation OP EXPR.
// Supported values of OP are enumerated in NegationOperator.
- virtual Bexpression *negation_expression (NegationOperator op,
- Bexpression *expr, Location)
+ virtual tree negation_expression (NegationOperator op, tree expr, Location)
= 0;
// Return an expression for the operation LEFT OP RIGHT.
// Supported values of OP are enumerated in ArithmeticOrLogicalOperator.
- virtual Bexpression *
- arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op,
- Bexpression *left, Bexpression *right,
- Location)
+ virtual tree arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op,
+ tree left, tree right,
+ Location)
= 0;
// Return an expression for the operation LEFT OP RIGHT.
// Supported values of OP are enumerated in ComparisonOperator.
- virtual Bexpression *comparison_expression (ComparisonOperator op,
- Bexpression *left,
- Bexpression *right, Location)
+ virtual tree comparison_expression (ComparisonOperator op, tree left,
+ tree right, Location)
= 0;
// Return an expression for the operation LEFT OP RIGHT.
// Supported values of OP are enumerated in LazyBooleanOperator.
- virtual Bexpression *lazy_boolean_expression (LazyBooleanOperator op,
- Bexpression *left,
- Bexpression *right, Location)
+ virtual tree lazy_boolean_expression (LazyBooleanOperator op, tree left,
+ tree right, Location)
= 0;
// Return an expression that constructs BTYPE with VALS. BTYPE must be the
// backend representation a of struct. VALS must be in the same order as the
// corresponding fields in BTYPE.
- virtual Bexpression *
- constructor_expression (tree btype, const std::vector<Bexpression *> &vals,
- int, Location)
+ virtual tree constructor_expression (tree btype,
+ const std::vector<tree> &vals, int,
+ Location)
= 0;
// Return an expression that constructs an array of BTYPE with INDEXES and
// VALS. INDEXES and VALS must have the same amount of elements. Each index
// in INDEXES must be in the same order as the corresponding value in VALS.
- virtual Bexpression *array_constructor_expression (
- tree btype, const std::vector<unsigned long> &indexes,
- const std::vector<Bexpression *> &vals, Location)
+ virtual tree
+ array_constructor_expression (tree btype,
+ const std::vector<unsigned long> &indexes,
+ const std::vector<tree> &vals, Location)
= 0;
// Return an expression for the address of BASE[INDEX].
// BASE has a pointer type. This is used for slice indexing.
- virtual Bexpression *pointer_offset_expression (Bexpression *base,
- Bexpression *index, Location)
- = 0;
+ virtual tree pointer_offset_expression (tree base, tree index, Location) = 0;
// Return an expression for ARRAY[INDEX] as an l-value. ARRAY is a valid
// fixed-length array, not a slice.
- virtual Bexpression *array_index_expression (Bexpression *array,
- Bexpression *index, Location)
- = 0;
+ virtual tree array_index_expression (tree array, tree index, Location) = 0;
// Create an expression for a call to FN with ARGS, taking place within
// caller CALLER.
- virtual Bexpression *call_expression (Bfunction *caller, Bexpression *fn,
- const std::vector<Bexpression *> &args,
- Bexpression *static_chain, Location)
+ virtual tree call_expression (Bfunction *caller, tree fn,
+ const std::vector<tree> &args,
+ tree static_chain, Location)
= 0;
// Statements.
@@ -424,37 +403,36 @@ public:
virtual Bstatement *error_statement () = 0;
// Create an expression statement within the specified function.
- virtual Bstatement *expression_statement (Bfunction *, Bexpression *) = 0;
+ virtual Bstatement *expression_statement (Bfunction *, tree) = 0;
// Create a variable initialization statement in the specified
// function. This initializes a local variable at the point in the
// program flow where it is declared.
- virtual Bstatement *init_statement (Bfunction *, Bvariable *var,
- Bexpression *init)
+ virtual Bstatement *init_statement (Bfunction *, Bvariable *var, tree init)
= 0;
// Create an assignment statement within the specified function.
- virtual Bstatement *assignment_statement (Bfunction *, Bexpression *lhs,
- Bexpression *rhs, Location)
+ virtual Bstatement *assignment_statement (Bfunction *, tree lhs, tree rhs,
+ Location)
= 0;
// Create a return statement, passing the representation of the
// function and the list of values to return.
- virtual Bstatement *
- return_statement (Bfunction *, const std::vector<Bexpression *> &, Location)
+ virtual Bstatement *return_statement (Bfunction *, const std::vector<tree> &,
+ Location)
= 0;
// Create an if statement within a function. ELSE_BLOCK may be NULL.
- virtual Bstatement *if_statement (Bfunction *, Bexpression *condition,
+ virtual Bstatement *if_statement (Bfunction *, tree condition,
Bblock *then_block, Bblock *else_block,
Location)
= 0;
// infinite loop expressions
- virtual Bexpression *loop_expression (Bblock *body, Location) = 0;
+ virtual tree loop_expression (Bblock *body, Location) = 0;
// exit expressions
- virtual Bexpression *exit_expression (Bexpression *condition, Location) = 0;
+ virtual tree exit_expression (tree condition, Location) = 0;
// Create a switch statement where the case values are constants.
// CASES and STATEMENTS must have the same number of entries. If
@@ -464,8 +442,8 @@ public:
// STATEMENTS[i + 1]. CASES[i] is empty for the default clause,
// which need not be last. FUNCTION is the current function.
virtual Bstatement *
- switch_statement (Bfunction *function, Bexpression *value,
- const std::vector<std::vector<Bexpression *> > &cases,
+ switch_statement (Bfunction *function, tree value,
+ const std::vector<std::vector<tree> > &cases,
const std::vector<Bstatement *> &statements, Location)
= 0;
@@ -543,7 +521,7 @@ public:
// global_variable_set_init to set the initial value. If this is
// not called, the backend should initialize a global variable to 0.
// The init function may then assign a value to it.
- virtual void global_variable_set_init (Bvariable *, Bexpression *) = 0;
+ virtual void global_variable_set_init (Bvariable *, tree) = 0;
// Create a local variable. The frontend will create the local
// variables first, and then create the block which contains them.
@@ -587,10 +565,10 @@ public:
// variable, and may not be very useful. This function should
// return a variable which can be referenced later and should set
// *PSTATEMENT to a statement which initializes the variable.
- virtual Bvariable *
- temporary_variable (Bfunction *, Bblock *, tree, Bexpression *init,
- bool address_is_taken, Location location,
- Bstatement **pstatement)
+ virtual Bvariable *temporary_variable (Bfunction *, Bblock *, tree, tree init,
+ bool address_is_taken,
+ Location location,
+ Bstatement **pstatement)
= 0;
// Create an implicit variable that is compiler-defined. This is
@@ -638,7 +616,7 @@ public:
virtual void implicit_variable_set_init (Bvariable *, const std::string &name,
tree type, bool is_hidden,
bool is_constant, bool is_common,
- Bexpression *init)
+ tree init)
= 0;
// Create a reference to a named implicit variable defined in some
@@ -693,8 +671,7 @@ public:
// immutable_struct.
virtual void immutable_struct_set_init (Bvariable *, const std::string &name,
bool is_hidden, bool is_common,
- tree type, Location,
- Bexpression *initializer)
+ tree type, Location, tree initializer)
= 0;
// Create a reference to a named immutable initialized data
@@ -725,7 +702,7 @@ public:
// Create an expression for the address of a label. This is used to
// get the return address of a deferred function which may call
// recover.
- virtual Bexpression *label_address (Blabel *, Location) = 0;
+ virtual tree label_address (Blabel *, Location) = 0;
// Functions.
@@ -782,9 +759,9 @@ public:
// be a statement that looks like this in C++:
// finish:
// try { DEFER_RETURN; } catch { CHECK_DEFER; goto finish; }
- virtual Bstatement *
- function_defer_statement (Bfunction *function, Bexpression *undefer,
- Bexpression *check_defer, Location)
+ virtual Bstatement *function_defer_statement (Bfunction *function,
+ tree undefer, tree check_defer,
+ Location)
= 0;
// Record PARAM_VARS as the variables to use for the parameters of FUNCTION.
@@ -812,7 +789,7 @@ public:
// FUNCTION_DECLS, and VARIABLE_DECLS declared globally.
virtual void
write_global_definitions (const std::vector<tree> &type_decls,
- const std::vector<Bexpression *> &constant_decls,
+ const std::vector<tree> &constant_decls,
const std::vector<Bfunction *> &function_decls,
const std::vector<Bvariable *> &variable_decls)
= 0;
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index a205d65..ef7b0b7 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -70,12 +70,6 @@ private:
// In gcc, types, expressions, and statements are all trees.
-class Bexpression : public Gcc_tree
-{
-public:
- Bexpression (tree t) : Gcc_tree (t) {}
-};
-
class Bstatement : public Gcc_tree
{
public:
@@ -155,7 +149,6 @@ public:
Gcc_backend ();
void debug (tree t) { debug_tree (t); };
- void debug (Bexpression *t) { debug_tree (t->get_tree ()); };
void debug (Bstatement *t) { debug_tree (t->get_tree ()); };
void debug (Bfunction *t) { debug_tree (t->get_tree ()); };
void debug (Bblock *t) { debug_tree (t->get_tree ()); };
@@ -184,14 +177,14 @@ public:
tree char_type () { return char_type_node; }
- bool const_size_cast (Bexpression *expr, size_t *result)
+ bool const_size_cast (tree expr, size_t *result)
{
- rust_assert (TREE_CONSTANT (expr->get_tree ()));
+ rust_assert (TREE_CONSTANT (expr));
unsigned char buf[sizeof (size_t) + 1];
memset (buf, 0, sizeof (buf));
- int ret = native_encode_expr (expr->get_tree (), buf, sizeof (buf), 0);
+ int ret = native_encode_expr (expr, buf, sizeof (buf), 0);
if (ret <= 0)
return false;
@@ -200,23 +193,23 @@ public:
return true;
}
- std::string const_size_val_to_string (Bexpression *expr)
+ std::string const_size_val_to_string (tree expr)
{
- rust_assert (TREE_CONSTANT (expr->get_tree ()));
+ rust_assert (TREE_CONSTANT (expr));
unsigned char buf[sizeof (size_t) + 1];
memset (buf, 0, sizeof (buf));
- int ret = native_encode_expr (expr->get_tree (), buf, sizeof (buf), 0);
+ int ret = native_encode_expr (expr, buf, sizeof (buf), 0);
rust_assert (ret > 0);
size_t *ptr = (size_t *) buf;
return std::to_string (*ptr);
}
- bool const_values_equal (Bexpression *a, Bexpression *b)
+ bool const_values_equal (tree a, tree b)
{
- return operand_equal_p (a->get_tree (), b->get_tree (), OEP_ONLY_CONST | OEP_PURE_SAME);
+ return operand_equal_p (a, b, OEP_ONLY_CONST | OEP_PURE_SAME);
// printf ("comparing!\n");
// debug_tree (a->get_tree ());
// debug_tree (b->get_tree ());
@@ -266,7 +259,7 @@ public:
tree union_type (const std::vector<typed_identifier> &);
- tree array_type (tree, Bexpression *);
+ tree array_type (tree, tree);
tree named_type (const std::string &, tree, Location);
@@ -280,102 +273,78 @@ public:
// Expressions.
- Bexpression *zero_expression (tree);
+ tree zero_expression (tree);
- Bexpression *error_expression ()
- {
- return this->make_expression (error_mark_node);
- }
+ tree error_expression () { return error_mark_node; }
- bool is_error_expression (Bexpression *expr)
- {
- return expr->get_tree () == error_mark_node;
- }
+ bool is_error_expression (tree expr) { return expr == error_mark_node; }
- Bexpression *nil_pointer_expression ()
- {
- return this->make_expression (null_pointer_node);
- }
+ tree nil_pointer_expression () { return null_pointer_node; }
- Bexpression *unit_expression ()
- {
- return this->make_expression (integer_zero_node);
- }
+ tree unit_expression () { return integer_zero_node; }
- Bexpression *var_expression (Bvariable *var, Location);
+ tree var_expression (Bvariable *var, Location);
- Bexpression *indirect_expression (tree, Bexpression *expr,
- bool known_valid, Location);
+ tree indirect_expression (tree, tree expr, bool known_valid, Location);
- Bexpression *named_constant_expression (tree type, const std::string &name,
- Bexpression *val, Location);
+ tree named_constant_expression (tree type, const std::string &name, tree val,
+ Location);
- Bexpression *integer_constant_expression (tree type, mpz_t val);
+ tree integer_constant_expression (tree type, mpz_t val);
- Bexpression *float_constant_expression (tree type, mpfr_t val);
+ tree float_constant_expression (tree type, mpfr_t val);
- Bexpression *complex_constant_expression (tree type, mpc_t val);
+ tree complex_constant_expression (tree type, mpc_t val);
- Bexpression *string_constant_expression (const std::string &val);
+ tree string_constant_expression (const std::string &val);
- Bexpression *wchar_constant_expression (wchar_t c);
+ tree wchar_constant_expression (wchar_t c);
- Bexpression *char_constant_expression (char c);
+ tree char_constant_expression (char c);
- Bexpression *boolean_constant_expression (bool val);
+ tree boolean_constant_expression (bool val);
- Bexpression *real_part_expression (Bexpression *bcomplex, Location);
+ tree real_part_expression (tree bcomplex, Location);
- Bexpression *imag_part_expression (Bexpression *bcomplex, Location);
+ tree imag_part_expression (tree bcomplex, Location);
- Bexpression *complex_expression (Bexpression *breal, Bexpression *bimag,
- Location);
+ tree complex_expression (tree breal, tree bimag, Location);
- Bexpression *convert_expression (tree type, Bexpression *expr, Location);
+ tree convert_expression (tree type, tree expr, Location);
- Bexpression *function_code_expression (Bfunction *, Location);
+ tree function_code_expression (Bfunction *, Location);
- Bexpression *address_expression (Bexpression *, Location);
+ tree address_expression (tree, Location);
- Bexpression *struct_field_expression (Bexpression *, size_t, Location);
+ tree struct_field_expression (tree, size_t, Location);
- Bexpression *compound_expression (Bstatement *, Bexpression *, Location);
+ tree compound_expression (Bstatement *, tree, Location);
- Bexpression *conditional_expression (Bfunction *, tree, Bexpression *,
- Bexpression *, Bexpression *, Location);
+ tree conditional_expression (Bfunction *, tree, tree, tree, tree, Location);
- Bexpression *negation_expression (NegationOperator op, Bexpression *expr,
- Location);
+ tree negation_expression (NegationOperator op, tree expr, Location);
- Bexpression *arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op,
- Bexpression *left,
- Bexpression *right, Location);
+ tree arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op,
+ tree left, tree right, Location);
- Bexpression *comparison_expression (ComparisonOperator op, Bexpression *left,
- Bexpression *right, Location);
+ tree comparison_expression (ComparisonOperator op, tree left, tree right,
+ Location);
- Bexpression *lazy_boolean_expression (LazyBooleanOperator op,
- Bexpression *left, Bexpression *right,
- Location);
+ tree lazy_boolean_expression (LazyBooleanOperator op, tree left, tree right,
+ Location);
- Bexpression *constructor_expression (tree,
- const std::vector<Bexpression *> &, int,
- Location);
+ tree constructor_expression (tree, const std::vector<tree> &, int, Location);
- Bexpression *array_constructor_expression (tree,
- const std::vector<unsigned long> &,
- const std::vector<Bexpression *> &,
- Location);
+ tree array_constructor_expression (tree, const std::vector<unsigned long> &,
+ const std::vector<tree> &, Location);
- Bexpression *pointer_offset_expression (Bexpression *base,
- Bexpression *offset, Location);
+ tree pointer_offset_expression (tree base, tree offset, Location);
- Bexpression *array_index_expression (Bexpression *array, Bexpression *index,
- Location);
+ tree array_index_expression (tree array, tree index, Location);
- Bexpression *call_expression (Bfunction *caller, Bexpression *fn,
- const std::vector<Bexpression *> &args,
- Bexpression *static_chain, Location);
+ tree call_expression (Bfunction *caller, tree fn,
+ const std::vector<tree> &args, tree static_chain,
+ Location);
// Statements.
@@ -384,23 +353,22 @@ public:
return this->make_statement (error_mark_node);
}
- Bstatement *expression_statement (Bfunction *, Bexpression *);
+ Bstatement *expression_statement (Bfunction *, tree);
- Bstatement *init_statement (Bfunction *, Bvariable *var, Bexpression *init);
+ Bstatement *init_statement (Bfunction *, Bvariable *var, tree init);
- Bstatement *assignment_statement (Bfunction *, Bexpression *lhs,
- Bexpression *rhs, Location);
+ Bstatement *assignment_statement (Bfunction *, tree lhs, tree rhs, Location);
- Bstatement *return_statement (Bfunction *, const std::vector<Bexpression *> &,
+ Bstatement *return_statement (Bfunction *, const std::vector<tree> &,
Location);
- Bstatement *if_statement (Bfunction *, Bexpression *condition,
- Bblock *then_block, Bblock *else_block, Location);
+ Bstatement *if_statement (Bfunction *, tree condition, Bblock *then_block,
+ Bblock *else_block, Location);
- Bstatement *
- switch_statement (Bfunction *function, Bexpression *value,
- const std::vector<std::vector<Bexpression *> > &cases,
- const std::vector<Bstatement *> &statements, Location);
+ Bstatement *switch_statement (Bfunction *function, tree value,
+ const std::vector<std::vector<tree>> &cases,
+ const std::vector<Bstatement *> &statements,
+ Location);
Bstatement *compound_statement (Bstatement *, Bstatement *);
@@ -410,9 +378,9 @@ public:
Bstatement *except_stmt,
Bstatement *finally_stmt, Location);
- Bexpression *loop_expression (Bblock *body, Location);
+ tree loop_expression (Bblock *body, Location);
- Bexpression *exit_expression (Bexpression *condition, Location);
+ tree exit_expression (tree condition, Location);
// Blocks.
@@ -432,7 +400,7 @@ public:
bool is_external, bool is_hidden,
bool in_unique_section, Location location);
- void global_variable_set_init (Bvariable *, Bexpression *);
+ void global_variable_set_init (Bvariable *, tree);
Bvariable *local_variable (Bfunction *, const std::string &, tree,
Bvariable *, bool, Location);
@@ -443,14 +411,14 @@ public:
Bvariable *static_chain_variable (Bfunction *, const std::string &, tree,
Location);
- Bvariable *temporary_variable (Bfunction *, Bblock *, tree, Bexpression *,
- bool, Location, Bstatement **);
+ Bvariable *temporary_variable (Bfunction *, Bblock *, tree, tree, bool,
+ Location, Bstatement **);
Bvariable *implicit_variable (const std::string &, const std::string &,
tree, bool, bool, bool, int64_t);
- void implicit_variable_set_init (Bvariable *, const std::string &, tree,
- bool, bool, bool, Bexpression *);
+ void implicit_variable_set_init (Bvariable *, const std::string &, tree, bool,
+ bool, bool, tree);
Bvariable *implicit_variable_reference (const std::string &,
const std::string &, tree);
@@ -459,7 +427,7 @@ public:
bool, tree, Location);
void immutable_struct_set_init (Bvariable *, const std::string &, bool, bool,
- tree, Location, Bexpression *);
+ tree, Location, tree);
Bvariable *immutable_struct_reference (const std::string &,
const std::string &, tree,
@@ -473,7 +441,7 @@ public:
Bstatement *goto_statement (Blabel *, Location);
- Bexpression *label_address (Blabel *, Location);
+ tree label_address (Blabel *, Location);
// Functions.
@@ -483,9 +451,8 @@ public:
const std::string &asm_name, unsigned int flags,
Location);
- Bstatement *function_defer_statement (Bfunction *function,
- Bexpression *undefer,
- Bexpression *defer, Location);
+ Bstatement *function_defer_statement (Bfunction *function, tree undefer,
+ tree defer, Location);
bool function_set_parameters (Bfunction *function,
const std::vector<Bvariable *> &);
@@ -497,15 +464,13 @@ public:
Bfunction *lookup_builtin_by_rust_name (const std::string &);
void write_global_definitions (const std::vector<tree> &,
- const std::vector<Bexpression *> &,
+ const std::vector<tree> &,
const std::vector<Bfunction *> &,
const std::vector<Bvariable *> &);
void write_export_data (const char *bytes, unsigned int size);
private:
- // Make a Bexpression from a tree.
- Bexpression *make_expression (tree t) { return new Bexpression (t); }
// Make a Bstatement from a tree.
Bstatement *make_statement (tree t) { return new Bstatement (t); }
@@ -514,7 +479,7 @@ private:
tree fill_in_fields (tree, const std::vector<typed_identifier> &);
- tree fill_in_array (tree, tree, Bexpression *);
+ tree fill_in_array (tree, tree, tree);
tree non_zero_size_type (tree);
@@ -1144,7 +1109,7 @@ Gcc_backend::fill_in_fields (tree fill,
// Make an array type.
tree
-Gcc_backend::array_type (tree element_type, Bexpression *length)
+Gcc_backend::array_type (tree element_type, tree length)
{
return this->fill_in_array (make_node (ARRAY_TYPE), element_type, length);
}
@@ -1152,10 +1117,8 @@ Gcc_backend::array_type (tree element_type, Bexpression *length)
// Fill in an array type.
tree
-Gcc_backend::fill_in_array (tree fill, tree element_type,
- Bexpression *length)
+Gcc_backend::fill_in_array (tree fill, tree element_type, tree length_tree)
{
- tree length_tree = length->get_tree ();
if (element_type == error_mark_node || length_tree == error_mark_node)
return this->error_type ();
@@ -1275,7 +1238,7 @@ Gcc_backend::type_field_offset (tree struct_tree, size_t index)
// Return the zero value for a type.
-Bexpression *
+tree
Gcc_backend::zero_expression (tree t)
{
tree ret;
@@ -1283,27 +1246,26 @@ Gcc_backend::zero_expression (tree t)
ret = error_mark_node;
else
ret = build_zero_cst (t);
- return this->make_expression (ret);
+ return ret;
}
// An expression that references a variable.
-Bexpression *
+tree
Gcc_backend::var_expression (Bvariable *var, Location location)
{
tree ret = var->get_tree (location);
if (ret == error_mark_node)
return this->error_expression ();
- return this->make_expression (ret);
+ return ret;
}
// An expression that indirectly references an expression.
-Bexpression *
-Gcc_backend::indirect_expression (tree type_tree, Bexpression *expr,
+tree
+Gcc_backend::indirect_expression (tree type_tree, tree expr_tree,
bool known_valid, Location location)
{
- tree expr_tree = expr->get_tree ();
if (expr_tree == error_mark_node || type_tree == error_mark_node)
return this->error_expression ();
@@ -1317,17 +1279,16 @@ Gcc_backend::indirect_expression (tree type_tree, Bexpression *expr,
tree ret = build_fold_indirect_ref_loc (location.gcc_location (), expr_tree);
if (known_valid)
TREE_THIS_NOTRAP (ret) = 1;
- return this->make_expression (ret);
+ return ret;
}
// Return an expression that declares a constant named NAME with the
// constant value VAL in BTYPE.
-Bexpression *
+tree
Gcc_backend::named_constant_expression (tree type_tree, const std::string &name,
- Bexpression *val, Location location)
+ tree const_val, Location location)
{
- tree const_val = val->get_tree ();
if (type_tree == error_mark_node || const_val == error_mark_node)
return this->error_expression ();
@@ -1339,24 +1300,24 @@ Gcc_backend::named_constant_expression (tree type_tree, const std::string &name,
TREE_READONLY (decl) = 1;
rust_preserve_from_gc (decl);
- return this->make_expression (decl);
+ return decl;
}
// Return a typed value as a constant integer.
-Bexpression *
+tree
Gcc_backend::integer_constant_expression (tree t, mpz_t val)
{
if (t == error_mark_node)
return this->error_expression ();
tree ret = double_int_to_tree (t, mpz_get_double_int (t, val, true));
- return this->make_expression (ret);
+ return ret;
}
// Return a typed value as a constant floating-point number.
-Bexpression *
+tree
Gcc_backend::float_constant_expression (tree t, mpfr_t val)
{
tree ret;
@@ -1368,12 +1329,12 @@ Gcc_backend::float_constant_expression (tree t, mpfr_t val)
REAL_VALUE_TYPE r2;
real_convert (&r2, TYPE_MODE (t), &r1);
ret = build_real (t, r2);
- return this->make_expression (ret);
+ return ret;
}
// Return a typed real and imaginary value as a constant complex number.
-Bexpression *
+tree
Gcc_backend::complex_constant_expression (tree t, mpc_t val)
{
tree ret;
@@ -1392,12 +1353,12 @@ Gcc_backend::complex_constant_expression (tree t, mpc_t val)
ret = build_complex (t, build_real (TREE_TYPE (t), r2),
build_real (TREE_TYPE (t), r4));
- return this->make_expression (ret);
+ return ret;
}
// Make a constant string expression.
-Bexpression *
+tree
Gcc_backend::string_constant_expression (const std::string &val)
{
tree index_type = build_index_type (size_int (val.length ()));
@@ -1407,70 +1368,63 @@ Gcc_backend::string_constant_expression (const std::string &val)
tree string_val = build_string (val.length (), val.data ());
TREE_TYPE (string_val) = string_type;
- return this->make_expression (string_val);
+ return string_val;
}
-Bexpression *
+tree
Gcc_backend::wchar_constant_expression (wchar_t c)
{
- tree ret = build_int_cst (this->wchar_type (), c);
- return this->make_expression (ret);
+ return build_int_cst (this->wchar_type (), c);
}
-Bexpression *
+tree
Gcc_backend::char_constant_expression (char c)
{
- tree ret = build_int_cst (this->char_type (), c);
- return this->make_expression (ret);
+ return build_int_cst (this->char_type (), c);
}
// Make a constant boolean expression.
-Bexpression *
+tree
Gcc_backend::boolean_constant_expression (bool val)
{
- tree bool_cst = val ? boolean_true_node : boolean_false_node;
- return this->make_expression (bool_cst);
+ return val ? boolean_true_node : boolean_false_node;
}
// Return the real part of a complex expression.
-Bexpression *
-Gcc_backend::real_part_expression (Bexpression *bcomplex, Location location)
+tree
+Gcc_backend::real_part_expression (tree complex_tree, Location location)
{
- tree complex_tree = bcomplex->get_tree ();
if (complex_tree == error_mark_node)
return this->error_expression ();
gcc_assert (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (complex_tree)));
tree ret
= fold_build1_loc (location.gcc_location (), REALPART_EXPR,
TREE_TYPE (TREE_TYPE (complex_tree)), complex_tree);
- return this->make_expression (ret);
+ return ret;
}
// Return the imaginary part of a complex expression.
-Bexpression *
-Gcc_backend::imag_part_expression (Bexpression *bcomplex, Location location)
+tree
+Gcc_backend::imag_part_expression (tree complex_tree, Location location)
{
- tree complex_tree = bcomplex->get_tree ();
if (complex_tree == error_mark_node)
return this->error_expression ();
gcc_assert (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (complex_tree)));
tree ret
= fold_build1_loc (location.gcc_location (), IMAGPART_EXPR,
TREE_TYPE (TREE_TYPE (complex_tree)), complex_tree);
- return this->make_expression (ret);
+ return ret;
}
// Make a complex expression given its real and imaginary parts.
-Bexpression *
-Gcc_backend::complex_expression (Bexpression *breal, Bexpression *bimag,
+tree
+Gcc_backend::complex_expression (tree real_tree, tree imag_tree,
Location location)
{
- tree real_tree = breal->get_tree ();
- tree imag_tree = bimag->get_tree ();
if (real_tree == error_mark_node || imag_tree == error_mark_node)
return this->error_expression ();
gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (real_tree))
@@ -1479,16 +1433,15 @@ Gcc_backend::complex_expression (Bexpression *breal, Bexpression *bimag,
tree ret = fold_build2_loc (location.gcc_location (), COMPLEX_EXPR,
build_complex_type (TREE_TYPE (real_tree)),
real_tree, imag_tree);
- return this->make_expression (ret);
+ return ret;
}
// An expression that converts an expression to a different type.
-Bexpression *
-Gcc_backend::convert_expression (tree type_tree, Bexpression *expr,
+tree
+Gcc_backend::convert_expression (tree type_tree, tree expr_tree,
Location location)
{
- tree expr_tree = expr->get_tree ();
if (type_tree == error_mark_node || expr_tree == error_mark_node
|| TREE_TYPE (expr_tree) == error_mark_node)
return this->error_expression ();
@@ -1515,12 +1468,12 @@ Gcc_backend::convert_expression (tree type_tree, Bexpression *expr,
else
ret = fold_convert_loc (location.gcc_location (), type_tree, expr_tree);
- return this->make_expression (ret);
+ return ret;
}
// Get the address of a function.
-Bexpression *
+tree
Gcc_backend::function_code_expression (Bfunction *bfunc, Location location)
{
tree func = bfunc->get_tree ();
@@ -1528,29 +1481,26 @@ Gcc_backend::function_code_expression (Bfunction *bfunc, Location location)
return this->error_expression ();
tree ret = build_fold_addr_expr_loc (location.gcc_location (), func);
- return this->make_expression (ret);
+ return ret;
}
// Get the address of an expression.
-Bexpression *
-Gcc_backend::address_expression (Bexpression *bexpr, Location location)
+tree
+Gcc_backend::address_expression (tree expr, Location location)
{
- tree expr = bexpr->get_tree ();
if (expr == error_mark_node)
return this->error_expression ();
- tree ret = build_fold_addr_expr_loc (location.gcc_location (), expr);
- return this->make_expression (ret);
+ return build_fold_addr_expr_loc (location.gcc_location (), expr);
}
// Return an expression for the field at INDEX in BSTRUCT.
-Bexpression *
-Gcc_backend::struct_field_expression (Bexpression *bstruct, size_t index,
+tree
+Gcc_backend::struct_field_expression (tree struct_tree, size_t index,
Location location)
{
- tree struct_tree = bstruct->get_tree ();
if (struct_tree == error_mark_node
|| TREE_TYPE (struct_tree) == error_mark_node)
return this->error_expression ();
@@ -1574,42 +1524,37 @@ Gcc_backend::struct_field_expression (Bexpression *bstruct, size_t index,
TREE_TYPE (field), struct_tree, field, NULL_TREE);
if (TREE_CONSTANT (struct_tree))
TREE_CONSTANT (ret) = 1;
- return this->make_expression (ret);
+ return ret;
}
// Return an expression that executes BSTAT before BEXPR.
-Bexpression *
-Gcc_backend::compound_expression (Bstatement *bstat, Bexpression *bexpr,
+tree
+Gcc_backend::compound_expression (Bstatement *bstat, tree expr,
Location location)
{
tree stat = bstat->get_tree ();
- tree expr = bexpr->get_tree ();
if (stat == error_mark_node || expr == error_mark_node)
return this->error_expression ();
tree ret = fold_build2_loc (location.gcc_location (), COMPOUND_EXPR,
TREE_TYPE (expr), stat, expr);
- return this->make_expression (ret);
+ return ret;
}
// Return an expression that executes THEN_EXPR if CONDITION is true, or
// ELSE_EXPR otherwise.
-Bexpression *
+tree
Gcc_backend::conditional_expression (Bfunction *, tree type_tree,
- Bexpression *condition,
- Bexpression *then_expr,
- Bexpression *else_expr, Location location)
-{
- tree cond_tree = condition->get_tree ();
- tree then_tree = then_expr->get_tree ();
- tree else_tree = else_expr == NULL ? NULL_TREE : else_expr->get_tree ();
- if (type_tree == error_mark_node || cond_tree == error_mark_node
- || then_tree == error_mark_node || else_tree == error_mark_node)
+ tree cond_expr, tree then_expr,
+ tree else_expr, Location location)
+{
+ if (type_tree == error_mark_node || cond_expr == error_mark_node
+ || then_expr == error_mark_node || else_expr == error_mark_node)
return this->error_expression ();
tree ret = build3_loc (location.gcc_location (), COND_EXPR, type_tree,
- cond_tree, then_tree, else_tree);
- return this->make_expression (ret);
+ cond_expr, then_expr, else_expr);
+ return ret;
}
/* Helper function that converts rust operators to equivalent GCC tree_code.
@@ -1711,13 +1656,12 @@ is_floating_point (tree t)
}
// Return an expression for the negation operation OP EXPR.
-Bexpression *
-Gcc_backend::negation_expression (NegationOperator op, Bexpression *expr,
+tree
+Gcc_backend::negation_expression (NegationOperator op, tree expr_tree,
Location location)
{
/* Check if the expression is an error, in which case we return an error
expression. */
- auto expr_tree = expr->get_tree ();
if (expr_tree == error_mark_node || TREE_TYPE (expr_tree) == error_mark_node)
return this->error_expression ();
@@ -1746,20 +1690,17 @@ Gcc_backend::negation_expression (NegationOperator op, Bexpression *expr,
tree_type, expr_tree);
if (floating_point && extended_type != NULL_TREE)
new_tree = convert (original_type, expr_tree);
- return this->make_expression (new_tree);
+ return new_tree;
}
// Return an expression for the arithmetic or logical operation LEFT OP RIGHT.
-Bexpression *
+tree
Gcc_backend::arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op,
- Bexpression *left,
- Bexpression *right,
+ tree left_tree, tree right_tree,
Location location)
{
/* Check if either expression is an error, in which case we return an error
expression. */
- auto left_tree = left->get_tree ();
- auto right_tree = right->get_tree ();
if (left_tree == error_mark_node || right_tree == error_mark_node)
return this->error_expression ();
@@ -1792,18 +1733,16 @@ Gcc_backend::arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op,
tree_type, left_tree, right_tree);
if (floating_point && extended_type != NULL_TREE)
new_tree = convert (original_type, new_tree);
- return this->make_expression (new_tree);
+ return new_tree;
}
// Return an expression for the comparison operation LEFT OP RIGHT.
-Bexpression *
-Gcc_backend::comparison_expression (ComparisonOperator op, Bexpression *left,
- Bexpression *right, Location location)
+tree
+Gcc_backend::comparison_expression (ComparisonOperator op, tree left_tree,
+ tree right_tree, Location location)
{
/* Check if either expression is an error, in which case we return an error
expression. */
- auto left_tree = left->get_tree ();
- auto right_tree = right->get_tree ();
if (left_tree == error_mark_node || right_tree == error_mark_node)
return this->error_expression ();
@@ -1814,18 +1753,16 @@ Gcc_backend::comparison_expression (ComparisonOperator op, Bexpression *left,
/* Construct a new tree and build an expression from it. */
auto new_tree = fold_build2_loc (location.gcc_location (), tree_code,
tree_type, left_tree, right_tree);
- return this->make_expression (new_tree);
+ return new_tree;
}
// Return an expression for the lazy boolean operation LEFT OP RIGHT.
-Bexpression *
-Gcc_backend::lazy_boolean_expression (LazyBooleanOperator op, Bexpression *left,
- Bexpression *right, Location location)
+tree
+Gcc_backend::lazy_boolean_expression (LazyBooleanOperator op, tree left_tree,
+ tree right_tree, Location location)
{
/* Check if either expression is an error, in which case we return an error
expression. */
- auto left_tree = left->get_tree ();
- auto right_tree = right->get_tree ();
if (left_tree == error_mark_node || right_tree == error_mark_node)
return this->error_expression ();
@@ -1837,14 +1774,14 @@ Gcc_backend::lazy_boolean_expression (LazyBooleanOperator op, Bexpression *left,
/* Construct a new tree and build an expression from it. */
auto new_tree = fold_build2_loc (location.gcc_location (), tree_code,
tree_type, left_tree, right_tree);
- return this->make_expression (new_tree);
+ return new_tree;
}
// Return an expression that constructs BTYPE with VALS.
-Bexpression *
+tree
Gcc_backend::constructor_expression (tree type_tree,
- const std::vector<Bexpression *> &vals,
+ const std::vector<tree> &vals,
int union_index, Location location)
{
if (type_tree == error_mark_node)
@@ -1859,7 +1796,7 @@ Gcc_backend::constructor_expression (tree type_tree,
if (union_index != -1)
{
gcc_assert (TREE_CODE (type_tree) == UNION_TYPE);
- tree val = vals.front ()->get_tree ();
+ tree val = vals.front ();
for (int i = 0; i < union_index; i++)
{
gcc_assert (field != NULL_TREE);
@@ -1891,11 +1828,11 @@ Gcc_backend::constructor_expression (tree type_tree,
else
{
gcc_assert (TREE_CODE (type_tree) == RECORD_TYPE);
- for (std::vector<Bexpression *>::const_iterator p = vals.begin ();
+ for (std::vector<tree>::const_iterator p = vals.begin ();
p != vals.end (); ++p, field = DECL_CHAIN (field))
{
gcc_assert (field != NULL_TREE);
- tree val = (*p)->get_tree ();
+ tree val = (*p);
if (TREE_TYPE (field) == error_mark_node || val == error_mark_node
|| TREE_TYPE (val) == error_mark_node)
return this->error_expression ();
@@ -1926,13 +1863,13 @@ Gcc_backend::constructor_expression (tree type_tree,
if (sink != NULL_TREE)
ret = fold_build2_loc (location.gcc_location (), COMPOUND_EXPR, type_tree,
sink, ret);
- return this->make_expression (ret);
+ return ret;
}
-Bexpression *
+tree
Gcc_backend::array_constructor_expression (
tree type_tree, const std::vector<unsigned long> &indexes,
- const std::vector<Bexpression *> &vals, Location location)
+ const std::vector<tree> &vals, Location location)
{
if (type_tree == error_mark_node)
return this->error_expression ();
@@ -1949,7 +1886,7 @@ Gcc_backend::array_constructor_expression (
for (size_t i = 0; i < vals.size (); ++i)
{
tree index = size_int (indexes[i]);
- tree val = (vals[i])->get_tree ();
+ tree val = vals[i];
if (index == error_mark_node || val == error_mark_node)
return this->error_expression ();
@@ -1979,17 +1916,15 @@ Gcc_backend::array_constructor_expression (
if (sink != NULL_TREE)
ret = fold_build2_loc (location.gcc_location (), COMPOUND_EXPR, type_tree,
sink, ret);
- return this->make_expression (ret);
+ return ret;
}
// Return an expression for the address of BASE[INDEX].
-Bexpression *
-Gcc_backend::pointer_offset_expression (Bexpression *base, Bexpression *index,
+tree
+Gcc_backend::pointer_offset_expression (tree base_tree, tree index_tree,
Location location)
{
- tree base_tree = base->get_tree ();
- tree index_tree = index->get_tree ();
tree element_type_tree = TREE_TYPE (TREE_TYPE (base_tree));
if (base_tree == error_mark_node || TREE_TYPE (base_tree) == error_mark_node
|| index_tree == error_mark_node || element_type_tree == error_mark_node)
@@ -2002,17 +1937,15 @@ Gcc_backend::pointer_offset_expression (Bexpression *base, Bexpression *index,
index_tree, element_size);
tree ptr = fold_build2_loc (location.gcc_location (), POINTER_PLUS_EXPR,
TREE_TYPE (base_tree), base_tree, offset);
- return this->make_expression (ptr);
+ return ptr;
}
// Return an expression representing ARRAY[INDEX]
-Bexpression *
-Gcc_backend::array_index_expression (Bexpression *array, Bexpression *index,
+tree
+Gcc_backend::array_index_expression (tree array_tree, tree index_tree,
Location location)
{
- tree array_tree = array->get_tree ();
- tree index_tree = index->get_tree ();
if (array_tree == error_mark_node || TREE_TYPE (array_tree) == error_mark_node
|| index_tree == error_mark_node)
return this->error_expression ();
@@ -2029,17 +1962,15 @@ Gcc_backend::array_index_expression (Bexpression *array, Bexpression *index,
ret = fold_build2_loc (location.gcc_location (), COMPOUND_EXPR,
void_type_node, array_tree, index_tree);
- return this->make_expression (ret);
+ return ret;
}
// Create an expression for a call to FN_EXPR with FN_ARGS.
-Bexpression *
+tree
Gcc_backend::call_expression (Bfunction *, // containing fcn for call
- Bexpression *fn_expr,
- const std::vector<Bexpression *> &fn_args,
- Bexpression *chain_expr, Location location)
+ tree fn, const std::vector<tree> &fn_args,
+ tree chain_expr, Location location)
{
- tree fn = fn_expr->get_tree ();
if (fn == error_mark_node || TREE_TYPE (fn) == error_mark_node)
return this->error_expression ();
@@ -2050,7 +1981,7 @@ Gcc_backend::call_expression (Bfunction *, // containing fcn for call
tree *args = nargs == 0 ? NULL : new tree[nargs];
for (size_t i = 0; i < nargs; ++i)
{
- args[i] = fn_args.at (i)->get_tree ();
+ args[i] = fn_args.at (i);
if (args[i] == error_mark_node)
return this->error_expression ();
}
@@ -2096,7 +2027,7 @@ Gcc_backend::call_expression (Bfunction *, // containing fcn for call
fn, nargs, args);
if (chain_expr)
- CALL_EXPR_STATIC_CHAIN (ret) = chain_expr->get_tree ();
+ CALL_EXPR_STATIC_CHAIN (ret) = chain_expr;
if (excess_type != NULL_TREE)
{
@@ -2106,24 +2037,23 @@ Gcc_backend::call_expression (Bfunction *, // containing fcn for call
}
delete[] args;
- return this->make_expression (ret);
+ return ret;
}
// An expression as a statement.
Bstatement *
-Gcc_backend::expression_statement (Bfunction *, Bexpression *expr)
+Gcc_backend::expression_statement (Bfunction *, tree expr)
{
- return this->make_statement (expr->get_tree ());
+ return this->make_statement (expr);
}
// Variable initialization.
Bstatement *
-Gcc_backend::init_statement (Bfunction *, Bvariable *var, Bexpression *init)
+Gcc_backend::init_statement (Bfunction *, Bvariable *var, tree init_tree)
{
tree var_tree = var->get_decl ();
- tree init_tree = init->get_tree ();
if (var_tree == error_mark_node || init_tree == error_mark_node)
return this->error_statement ();
gcc_assert (TREE_CODE (var_tree) == VAR_DECL);
@@ -2153,12 +2083,10 @@ Gcc_backend::init_statement (Bfunction *, Bvariable *var, Bexpression *init)
// Assignment.
Bstatement *
-Gcc_backend::assignment_statement (Bfunction *bfn, Bexpression *lhs,
- Bexpression *rhs, Location location)
+Gcc_backend::assignment_statement (Bfunction *bfn, tree lhs, tree rhs,
+ Location location)
{
- tree lhs_tree = lhs->get_tree ();
- tree rhs_tree = rhs->get_tree ();
- if (lhs_tree == error_mark_node || rhs_tree == error_mark_node)
+ if (lhs == error_mark_node || rhs == error_mark_node)
return this->error_statement ();
// To avoid problems with GNU ld, we don't make zero-sized
@@ -2167,26 +2095,25 @@ Gcc_backend::assignment_statement (Bfunction *bfn, Bexpression *lhs,
// expression; avoid crashes here by avoiding assignments of
// zero-sized expressions. Such assignments don't really mean
// anything anyhow.
- if (TREE_TYPE (lhs_tree) == void_type_node
- || int_size_in_bytes (TREE_TYPE (lhs_tree)) == 0
- || TREE_TYPE (rhs_tree) == void_type_node
- || int_size_in_bytes (TREE_TYPE (rhs_tree)) == 0)
+ if (TREE_TYPE (lhs) == void_type_node
+ || int_size_in_bytes (TREE_TYPE (lhs)) == 0
+ || TREE_TYPE (rhs) == void_type_node
+ || int_size_in_bytes (TREE_TYPE (rhs)) == 0)
return this->compound_statement (this->expression_statement (bfn, lhs),
this->expression_statement (bfn, rhs));
- rhs_tree = this->convert_tree (TREE_TYPE (lhs_tree), rhs_tree, location);
+ rhs = this->convert_tree (TREE_TYPE (lhs), rhs, location);
return this->make_statement (fold_build2_loc (location.gcc_location (),
MODIFY_EXPR, void_type_node,
- lhs_tree, rhs_tree));
+ lhs, rhs));
}
// Return.
Bstatement *
Gcc_backend::return_statement (Bfunction *bfunction,
- const std::vector<Bexpression *> &vals,
- Location location)
+ const std::vector<tree> &vals, Location location)
{
tree fntree = bfunction->get_tree ();
if (fntree == error_mark_node)
@@ -2202,10 +2129,10 @@ Gcc_backend::return_statement (Bfunction *bfunction,
if (res_type == void_type_node || int_size_in_bytes (res_type) == 0)
{
tree stmt_list = NULL_TREE;
- for (std::vector<Bexpression *>::const_iterator p = vals.begin ();
+ for (std::vector<tree>::const_iterator p = vals.begin ();
p != vals.end (); p++)
{
- tree val = (*p)->get_tree ();
+ tree val = (*p);
if (val == error_mark_node)
return this->error_statement ();
append_to_statement_list (val, &stmt_list);
@@ -2222,12 +2149,11 @@ Gcc_backend::return_statement (Bfunction *bfunction,
void_type_node, NULL_TREE);
else if (vals.size () == 1)
{
- tree val = vals.front ()->get_tree ();
+ tree val = vals.front ();
if (val == error_mark_node)
return this->error_statement ();
- tree set
- = fold_build2_loc (location.gcc_location (), MODIFY_EXPR,
- void_type_node, result, vals.front ()->get_tree ());
+ tree set = fold_build2_loc (location.gcc_location (), MODIFY_EXPR,
+ void_type_node, result, vals.front ());
ret = fold_build1_loc (location.gcc_location (), RETURN_EXPR,
void_type_node, set);
}
@@ -2248,18 +2174,18 @@ Gcc_backend::return_statement (Bfunction *bfunction,
pop_cfun ();
tree field = TYPE_FIELDS (rettype);
- for (std::vector<Bexpression *>::const_iterator p = vals.begin ();
+ for (std::vector<tree>::const_iterator p = vals.begin ();
p != vals.end (); p++, field = DECL_CHAIN (field))
{
gcc_assert (field != NULL_TREE);
tree ref
= fold_build3_loc (location.gcc_location (), COMPONENT_REF,
TREE_TYPE (field), rettmp, field, NULL_TREE);
- tree val = (*p)->get_tree ();
+ tree val = (*p);
if (val == error_mark_node)
return this->error_statement ();
tree set = fold_build2_loc (location.gcc_location (), MODIFY_EXPR,
- void_type_node, ref, (*p)->get_tree ());
+ void_type_node, ref, (*p));
append_to_statement_list (set, &stmt_list);
}
gcc_assert (field == NULL_TREE);
@@ -2308,11 +2234,9 @@ Gcc_backend::exception_handler_statement (Bstatement *bstat,
// If.
Bstatement *
-Gcc_backend::if_statement (Bfunction *, Bexpression *condition,
- Bblock *then_block, Bblock *else_block,
- Location location)
+Gcc_backend::if_statement (Bfunction *, tree cond_tree, Bblock *then_block,
+ Bblock *else_block, Location location)
{
- tree cond_tree = condition->get_tree ();
tree then_tree = then_block->get_tree ();
tree else_tree = else_block == NULL ? NULL_TREE : else_block->get_tree ();
if (cond_tree == error_mark_node || then_tree == error_mark_node
@@ -2325,30 +2249,27 @@ Gcc_backend::if_statement (Bfunction *, Bexpression *condition,
// Loops
-Bexpression *
+tree
Gcc_backend::loop_expression (Bblock *body, Location locus)
{
- tree loop_expr_tree = fold_build1_loc (locus.gcc_location (), LOOP_EXPR,
- void_type_node, body->get_tree ());
- return this->make_expression (loop_expr_tree);
+ return fold_build1_loc (locus.gcc_location (), LOOP_EXPR, void_type_node,
+ body->get_tree ());
}
-Bexpression *
-Gcc_backend::exit_expression (Bexpression *condition, Location locus)
+tree
+Gcc_backend::exit_expression (tree cond_tree, Location locus)
{
- tree cond_tree = condition->get_tree ();
- tree exit_expr_tree = fold_build1_loc (locus.gcc_location (), EXIT_EXPR,
- void_type_node, cond_tree);
- return this->make_expression (exit_expr_tree);
+ return fold_build1_loc (locus.gcc_location (), EXIT_EXPR, void_type_node,
+ cond_tree);
}
// Switch.
Bstatement *
-Gcc_backend::switch_statement (
- Bfunction *function, Bexpression *value,
- const std::vector<std::vector<Bexpression *> > &cases,
- const std::vector<Bstatement *> &statements, Location switch_location)
+Gcc_backend::switch_statement (Bfunction *function, tree value,
+ const std::vector<std::vector<tree>> &cases,
+ const std::vector<Bstatement *> &statements,
+ Location switch_location)
{
gcc_assert (cases.size () == statements.size ());
@@ -2359,7 +2280,7 @@ Gcc_backend::switch_statement (
push_cfun (DECL_STRUCT_FUNCTION (decl));
tree stmt_list = NULL_TREE;
- std::vector<std::vector<Bexpression *> >::const_iterator pc = cases.begin ();
+ std::vector<std::vector<tree>>::const_iterator pc = cases.begin ();
for (std::vector<Bstatement *>::const_iterator ps = statements.begin ();
ps != statements.end (); ++ps, ++pc)
{
@@ -2373,15 +2294,15 @@ Gcc_backend::switch_statement (
}
else
{
- for (std::vector<Bexpression *>::const_iterator pcv = pc->begin ();
+ for (std::vector<tree>::const_iterator pcv = pc->begin ();
pcv != pc->end (); ++pcv)
{
- tree t = (*pcv)->get_tree ();
+ tree t = (*pcv);
if (t == error_mark_node)
return this->error_statement ();
location_t loc = EXPR_LOCATION (t);
tree label = create_artificial_label (loc);
- tree c = build_case_label ((*pcv)->get_tree (), NULL_TREE, label);
+ tree c = build_case_label ((*pcv), NULL_TREE, label);
append_to_statement_list (c, &stmt_list);
}
}
@@ -2396,7 +2317,7 @@ Gcc_backend::switch_statement (
}
pop_cfun ();
- tree tv = value->get_tree ();
+ tree tv = value;
if (tv == error_mark_node)
return this->error_statement ();
tree t = build2_loc (switch_location.gcc_location (), SWITCH_EXPR, NULL_TREE,
@@ -2680,9 +2601,8 @@ Gcc_backend::global_variable (const std::string &var_name,
// Set the initial value of a global variable.
void
-Gcc_backend::global_variable_set_init (Bvariable *var, Bexpression *expr)
+Gcc_backend::global_variable_set_init (Bvariable *var, tree expr_tree)
{
- tree expr_tree = expr->get_tree ();
if (expr_tree == error_mark_node)
return;
gcc_assert (TREE_CONSTANT (expr_tree));
@@ -2784,13 +2704,12 @@ Gcc_backend::static_chain_variable (Bfunction *function,
Bvariable *
Gcc_backend::temporary_variable (Bfunction *function, Bblock *bblock,
- tree type_tree, Bexpression *binit,
+ tree type_tree, tree init_tree,
bool is_address_taken, Location location,
Bstatement **pstatement)
{
gcc_assert (function != NULL);
tree decl = function->get_tree ();
- tree init_tree = binit == NULL ? NULL_TREE : binit->get_tree ();
if (type_tree == error_mark_node || init_tree == error_mark_node
|| decl == error_mark_node)
{
@@ -2845,9 +2764,8 @@ Gcc_backend::temporary_variable (Bfunction *function, Bblock *bblock,
if (init_tree != NULL_TREE
&& (this->type_size (type_tree) == 0
|| TREE_TYPE (init_tree) == void_type_node))
- *pstatement
- = this->compound_statement (this->expression_statement (function, binit),
- *pstatement);
+ *pstatement = this->compound_statement (
+ this->expression_statement (function, init_tree), *pstatement);
return new Bvariable (var);
}
@@ -2912,14 +2830,9 @@ Gcc_backend::implicit_variable (const std::string &name,
void
Gcc_backend::implicit_variable_set_init (Bvariable *var, const std::string &,
tree, bool, bool, bool is_common,
- Bexpression *init)
+ tree init_tree)
{
tree decl = var->get_decl ();
- tree init_tree;
- if (init == NULL)
- init_tree = NULL_TREE;
- else
- init_tree = init->get_tree ();
if (decl == error_mark_node || init_tree == error_mark_node)
return;
@@ -3012,10 +2925,9 @@ Gcc_backend::immutable_struct (const std::string &name,
void
Gcc_backend::immutable_struct_set_init (Bvariable *var, const std::string &,
bool, bool is_common, tree, Location,
- Bexpression *initializer)
+ tree init_tree)
{
tree decl = var->get_decl ();
- tree init_tree = initializer->get_tree ();
if (decl == error_mark_node || init_tree == error_mark_node)
return;
@@ -3114,7 +3026,7 @@ Gcc_backend::goto_statement (Blabel *label, Location location)
// Get the address of a label.
-Bexpression *
+tree
Gcc_backend::label_address (Blabel *label, Location location)
{
tree lab = label->get_tree ();
@@ -3124,7 +3036,7 @@ Gcc_backend::label_address (Blabel *label, Location location)
= fold_convert_loc (location.gcc_location (), ptr_type_node,
build_fold_addr_expr_loc (location.gcc_location (),
lab));
- return this->make_expression (ret);
+ return ret;
}
// Declare or define a new function.
@@ -3186,12 +3098,9 @@ Gcc_backend::function (tree functype, const std::string &name,
// try { UNDEFER; } catch { CHECK_DEFER; goto finish; }
Bstatement *
-Gcc_backend::function_defer_statement (Bfunction *function,
- Bexpression *undefer, Bexpression *defer,
- Location location)
+Gcc_backend::function_defer_statement (Bfunction *function, tree undefer_tree,
+ tree defer_tree, Location location)
{
- tree undefer_tree = undefer->get_tree ();
- tree defer_tree = defer->get_tree ();
tree fntree = function->get_tree ();
if (undefer_tree == error_mark_node || defer_tree == error_mark_node
@@ -3286,8 +3195,7 @@ Gcc_backend::lookup_builtin_by_rust_name (const std::string &name)
void
Gcc_backend::write_global_definitions (
- const std::vector<tree> &type_decls,
- const std::vector<Bexpression *> &constant_decls,
+ const std::vector<tree> &type_decls, const std::vector<tree> &constant_decls,
const std::vector<Bfunction *> &function_decls,
const std::vector<Bvariable *> &variable_decls)
{
@@ -3322,12 +3230,12 @@ Gcc_backend::write_global_definitions (
++i;
}
}
- for (std::vector<Bexpression *>::const_iterator p = constant_decls.begin ();
+ for (std::vector<tree>::const_iterator p = constant_decls.begin ();
p != constant_decls.end (); ++p)
{
- if ((*p)->get_tree () != error_mark_node)
+ if ((*p) != error_mark_node)
{
- defs[i] = (*p)->get_tree ();
+ defs[i] = (*p);
rust_preserve_from_gc (defs[i]);
++i;
}
diff --git a/gcc/rust/typecheck/rust-hir-const-fold-ctx.h b/gcc/rust/typecheck/rust-hir-const-fold-ctx.h
index d330ac8..a3f5a16 100644
--- a/gcc/rust/typecheck/rust-hir-const-fold-ctx.h
+++ b/gcc/rust/typecheck/rust-hir-const-fold-ctx.h
@@ -36,15 +36,15 @@ public:
::Backend *get_backend () { return backend; }
- bool lookup_const (HirId id, Bexpression **expr);
+ bool lookup_const (HirId id, tree *expr);
- void insert_const (HirId, Bexpression *expr);
+ void insert_const (HirId, tree expr);
private:
Context (::Backend *backend);
::Backend *backend;
- std::map<HirId, Bexpression *> ctx;
+ std::map<HirId, tree> ctx;
};
} // namespace ConstFold
diff --git a/gcc/rust/typecheck/rust-hir-const-fold.cc b/gcc/rust/typecheck/rust-hir-const-fold.cc
index d68879c..6acedd1 100644
--- a/gcc/rust/typecheck/rust-hir-const-fold.cc
+++ b/gcc/rust/typecheck/rust-hir-const-fold.cc
@@ -41,7 +41,7 @@ Context::get ()
}
bool
-Context::lookup_const (HirId id, Bexpression **expr)
+Context::lookup_const (HirId id, tree *expr)
{
auto it = ctx.find (id);
if (it == ctx.end ())
@@ -52,7 +52,7 @@ Context::lookup_const (HirId id, Bexpression **expr)
}
void
-Context::insert_const (HirId id, Bexpression *expr)
+Context::insert_const (HirId id, tree expr)
{
rust_assert (ctx.find (id) == ctx.end ());
ctx[id] = expr;
@@ -75,7 +75,7 @@ ConstFoldArrayElems::visit (HIR::ArrayElemsValues &elems)
{
unsigned long index = 0;
std::vector<unsigned long> indices;
- std::vector<Bexpression *> values;
+ std::vector<tree> values;
TyTy::BaseType *tyty = nullptr;
if (!tyctx->lookup_type (expr.get_mappings ().get_hirid (), &tyty))
@@ -102,7 +102,7 @@ void
ConstFoldArrayElems::visit (HIR::ArrayElemsCopied &elems)
{
std::vector<unsigned long> indices;
- std::vector<Bexpression *> values;
+ std::vector<tree> values;
TyTy::BaseType *tyty = nullptr;
if (!tyctx->lookup_type (expr.get_mappings ().get_hirid (), &tyty))
@@ -113,11 +113,11 @@ ConstFoldArrayElems::visit (HIR::ArrayElemsCopied &elems)
}
tree type = ConstFoldType::fold (tyty, ctx->get_backend ());
- Bexpression *elem = ConstFoldExpr::fold (elems.get_elem_to_copy ());
+ tree elem = ConstFoldExpr::fold (elems.get_elem_to_copy ());
// num copies expr was already folded in rust-hir-type-check-expr; lookup the
// earlier result
- Bexpression *num_copies_expr = ctx->get_backend ()->error_expression ();
+ tree num_copies_expr = ctx->get_backend ()->error_expression ();
ctx->lookup_const (elems.get_num_copies_expr ()->get_mappings ().get_hirid (),
&num_copies_expr);
diff --git a/gcc/rust/typecheck/rust-hir-const-fold.h b/gcc/rust/typecheck/rust-hir-const-fold.h
index a45a7f2..c965e25 100644
--- a/gcc/rust/typecheck/rust-hir-const-fold.h
+++ b/gcc/rust/typecheck/rust-hir-const-fold.h
@@ -237,7 +237,7 @@ class ConstFoldItem : public ConstFoldBase
using ConstFoldBase::visit;
public:
- static Bexpression *fold (HIR::Item &item)
+ static tree fold (HIR::Item &item)
{
ConstFoldItem folder;
item.accept_vis (folder);
@@ -258,7 +258,7 @@ private:
: ConstFoldBase (), folded (ctx->get_backend ()->error_expression ())
{}
- Bexpression *folded;
+ tree folded;
};
class ConstFoldArrayElems : public ConstFoldBase
@@ -266,7 +266,7 @@ class ConstFoldArrayElems : public ConstFoldBase
using ConstFoldBase::visit;
public:
- static Bexpression *fold (HIR::ArrayExpr &expr)
+ static tree fold (HIR::ArrayExpr &expr)
{
ConstFoldArrayElems folder (expr);
HIR::ArrayElems *elems = expr.get_internal_elements ();
@@ -283,7 +283,7 @@ private:
expr (expr)
{}
- Bexpression *folded;
+ tree folded;
HIR::ArrayExpr &expr;
};
@@ -292,7 +292,7 @@ class ConstFoldExpr : public ConstFoldBase
using ConstFoldBase::visit;
public:
- static Bexpression *fold (HIR::Expr *expr)
+ static tree fold (HIR::Expr *expr)
{
ConstFoldExpr folder;
expr->accept_vis (folder);
@@ -453,8 +453,8 @@ public:
void visit (HIR::ArrayIndexExpr &expr) override
{
- Bexpression *array = ConstFoldExpr::fold (expr.get_array_expr ());
- Bexpression *index = ConstFoldExpr::fold (expr.get_index_expr ());
+ tree array = ConstFoldExpr::fold (expr.get_array_expr ());
+ tree index = ConstFoldExpr::fold (expr.get_index_expr ());
folded = ctx->get_backend ()->array_index_expression (array, index,
expr.get_locus ());
@@ -462,7 +462,7 @@ public:
void visit (HIR::BorrowExpr &expr) override
{
- Bexpression *main_expr = ConstFoldExpr::fold (expr.get_expr ().get ());
+ tree main_expr = ConstFoldExpr::fold (expr.get_expr ().get ());
folded
= ctx->get_backend ()->address_expression (main_expr, expr.get_locus ());
@@ -470,7 +470,7 @@ public:
void visit (HIR::DereferenceExpr &expr) override
{
- Bexpression *main_expr = ConstFoldExpr::fold (expr.get_expr ().get ());
+ tree main_expr = ConstFoldExpr::fold (expr.get_expr ().get ());
TyTy::BaseType *tyty = nullptr;
if (!tyctx->lookup_type (expr.get_mappings ().get_hirid (), &tyty))
@@ -497,7 +497,7 @@ private:
: ConstFoldBase (), folded (ctx->get_backend ()->error_expression ())
{}
- Bexpression *folded;
+ tree folded;
};
} // namespace ConstFold
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index 99696ae..daef15b 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -687,7 +687,7 @@ public:
UNKNOWN_LOCAL_DEFID);
/* Capacity is the size of the string (number of chars).
- It is a constant, but for fold it to get a Bexpression. */
+ It is a constant, but for fold it to get a tree. */
std::string capacity_str
= std::to_string (expr.get_literal ()->as_string ().size ());
HIR::LiteralExpr literal_capacity (capacity_mapping, capacity_str,
@@ -700,8 +700,7 @@ public:
new TyTy::USizeType (
capacity_mapping.get_hirid ()));
- Bexpression *capacity
- = ConstFold::ConstFoldExpr::fold (&literal_capacity);
+ tree capacity = ConstFold::ConstFoldExpr::fold (&literal_capacity);
Analysis::NodeMapping array_mapping (crate_num, UNKNOWN_NODEID,
mappings->get_next_hir_id (
@@ -1491,7 +1490,7 @@ private:
/* The return value of visit(ArrayElemsValues&) and visit(ArrayElemsCopied&)
Stores the type of array elements, if `expr` is ArrayExpr. */
TyTy::BaseType *infered_array_elems;
- Bexpression *folded_array_capacity;
+ tree folded_array_capacity;
Location root_array_expr_locus;
bool inside_loop;
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 4472eee..915aad9 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -1588,13 +1588,13 @@ private:
class ArrayType : public BaseType
{
public:
- ArrayType (HirId ref, Bexpression *capacity, TyVar base,
+ ArrayType (HirId ref, tree capacity, TyVar base,
std::set<HirId> refs = std::set<HirId> ())
: BaseType (ref, ref, TypeKind::ARRAY, refs), capacity (capacity),
element_type (base)
{}
- ArrayType (HirId ref, HirId ty_ref, Bexpression *capacity, TyVar base,
+ ArrayType (HirId ref, HirId ty_ref, tree capacity, TyVar base,
std::set<HirId> refs = std::set<HirId> ())
: BaseType (ref, ty_ref, TypeKind::ARRAY, refs), capacity (capacity),
element_type (base)
@@ -1615,7 +1615,7 @@ public:
bool is_equal (const BaseType &other) const override;
- Bexpression *get_capacity () const { return capacity; }
+ tree get_capacity () const { return capacity; }
std::string capacity_string () const;
BaseType *get_element_type () const;
@@ -1628,7 +1628,7 @@ public:
}
private:
- Bexpression *capacity;
+ tree capacity;
TyVar element_type;
};