aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Faust <david.faust@oracle.com>2021-11-15 11:29:10 -0800
committerDavid Faust <david.faust@oracle.com>2021-11-16 13:02:11 -0800
commit7a751f354a91a8459b877c60a5e5d78203aeb3ce (patch)
tree6905b25bbe6a6e9042ee93992e752987ed22dc15 /gcc
parent97c98deec7d4c698d7b8ee8a4e56888d5d85b8bd (diff)
downloadgcc-7a751f354a91a8459b877c60a5e5d78203aeb3ce.zip
gcc-7a751f354a91a8459b877c60a5e5d78203aeb3ce.tar.gz
gcc-7a751f354a91a8459b877c60a5e5d78203aeb3ce.tar.bz2
Replace Btype use with GCC tree
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-context.h102
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc6
-rw-r--r--gcc/rust/backend/rust-compile-expr.h26
-rw-r--r--gcc/rust/backend/rust-compile-extern.h4
-rw-r--r--gcc/rust/backend/rust-compile-fnparam.h8
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h16
-rw-r--r--gcc/rust/backend/rust-compile-item.h8
-rw-r--r--gcc/rust/backend/rust-compile-stmt.h2
-rw-r--r--gcc/rust/backend/rust-compile-tyty.h16
-rw-r--r--gcc/rust/backend/rust-compile-var-decl.h2
-rw-r--r--gcc/rust/backend/rust-compile.cc6
-rw-r--r--gcc/rust/rust-backend.h151
-rw-r--r--gcc/rust/rust-gcc.cc426
-rw-r--r--gcc/rust/typecheck/rust-hir-const-fold.cc8
-rw-r--r--gcc/rust/typecheck/rust-hir-const-fold.h18
15 files changed, 376 insertions, 423 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 396cb10..82c02f8 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -60,20 +60,20 @@ public:
ok = tyctx->lookup_type (ref, &lookup);
rust_assert (ok);
- Btype *compiled = TyTyCompile::compile (backend, lookup);
- compiled_type_map.insert (std::pair<HirId, Btype *> (ref, compiled));
+ tree compiled = TyTyCompile::compile (backend, lookup);
+ compiled_type_map.insert (std::pair<HirId, tree > (ref, compiled));
builtin_range.insert (ref);
}
}
- bool lookup_compiled_types (HirId id, ::Btype **type,
+ bool lookup_compiled_types (HirId id, ::tree *type,
const TyTy::BaseType *ref = nullptr)
{
if (ref != nullptr)
{
for (auto it = mono.begin (); it != mono.end (); it++)
{
- std::pair<HirId, ::Btype *> &val = it->second;
+ std::pair<HirId, ::tree > &val = it->second;
const TyTy::BaseType *r = it->first;
if (ref->is_equal (*r))
@@ -94,14 +94,14 @@ public:
return true;
}
- void insert_compiled_type (HirId id, ::Btype *type,
+ void insert_compiled_type (HirId id, ::tree type,
const TyTy::BaseType *ref = nullptr)
{
rust_assert (builtin_range.find (id) == builtin_range.end ());
- compiled_type_map.insert (std::pair<HirId, Btype *> (id, type));
+ compiled_type_map.insert (std::pair<HirId, tree > (id, type));
if (ref != nullptr)
{
- std::pair<HirId, ::Btype *> elem (id, type);
+ std::pair<HirId, ::tree > elem (id, type);
mono[ref] = std::move (elem);
}
}
@@ -247,7 +247,7 @@ public:
void pop_fn () { fn_stack.pop_back (); }
fncontext peek_fn () { return fn_stack.back (); }
- void push_type (::Btype *t) { type_decls.push_back (t); }
+ void push_type (::tree t) { type_decls.push_back (t); }
void push_var (::Bvariable *v) { var_decls.push_back (v); }
void push_const (::Bexpression *c) { const_decls.push_back (c); }
void push_function (::Bfunction *f) { func_decls.push_back (f); }
@@ -322,7 +322,7 @@ private:
// state
std::vector<fncontext> fn_stack;
std::map<HirId, ::Bvariable *> compiled_var_decls;
- std::map<HirId, ::Btype *> 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, ::Blabel *> compiled_labels;
@@ -330,12 +330,12 @@ private:
std::vector<::Bblock *> scope_stack;
std::vector<::Bvariable *> loop_value_stack;
std::vector<::Blabel *> loop_begin_labels;
- std::map<const TyTy::BaseType *, std::pair<HirId, ::Btype *>> mono;
+ std::map<const TyTy::BaseType *, std::pair<HirId, ::tree >> mono;
std::map<DefId, std::vector<std::pair<const TyTy::BaseType *, ::Bfunction *>>>
mono_fns;
// To GCC middle-end
- std::vector<::Btype *> type_decls;
+ std::vector<tree> type_decls;
std::vector<::Bvariable *> var_decls;
std::vector<::Bexpression *> const_decls;
std::vector<::Bfunction *> func_decls;
@@ -344,7 +344,7 @@ private:
class TyTyResolveCompile : public TyTy::TyConstVisitor
{
public:
- static ::Btype *compile (Context *ctx, const TyTy::BaseType *ty,
+ static tree compile (Context *ctx, const TyTy::BaseType *ty,
bool trait_object_mode = false)
{
TyTyResolveCompile compiler (ctx, trait_object_mode);
@@ -375,16 +375,16 @@ public:
void visit (const TyTy::FnType &type) override
{
- Backend::Btyped_identifier receiver;
- std::vector<Backend::Btyped_identifier> parameters;
- std::vector<Backend::Btyped_identifier> results;
+ Backend::typed_identifier receiver;
+ std::vector<Backend::typed_identifier> parameters;
+ std::vector<Backend::typed_identifier> results;
if (!type.get_return_type ()->is_unit ())
{
auto hir_type = type.get_return_type ();
auto ret
= TyTyResolveCompile::compile (ctx, hir_type, trait_object_mode);
- results.push_back (Backend::Btyped_identifier (
+ results.push_back (Backend::typed_identifier (
"_", ret,
ctx->get_mappings ()->lookup_location (hir_type->get_ref ())));
}
@@ -395,7 +395,7 @@ public:
auto compiled_param_type
= TyTyResolveCompile::compile (ctx, param_tyty, trait_object_mode);
- auto compiled_param = Backend::Btyped_identifier (
+ auto compiled_param = Backend::typed_identifier (
param_pair.first->as_string (), compiled_param_type,
ctx->get_mappings ()->lookup_location (param_tyty->get_ref ()));
@@ -414,12 +414,12 @@ public:
void visit (const TyTy::FnPtr &type) override
{
- Btype *result_type
+ tree result_type
= TyTyResolveCompile::compile (ctx, type.get_return_type ());
- std::vector<Btype *> parameters;
+ std::vector<tree > parameters;
type.iterate_params ([&] (TyTy::BaseType *p) mutable -> bool {
- Btype *pty = TyTyResolveCompile::compile (ctx, p);
+ tree pty = TyTyResolveCompile::compile (ctx, p);
parameters.push_back (pty);
return true;
});
@@ -439,25 +439,25 @@ public:
rust_assert (type.number_of_variants () == 1);
TyTy::VariantDef &variant = *type.get_variants ().at (0);
- std::vector<Backend::Btyped_identifier> fields;
+ std::vector<Backend::typed_identifier> fields;
for (size_t i = 0; i < variant.num_fields (); i++)
{
const TyTy::StructFieldType *field = variant.get_field_at_index (i);
- Btype *compiled_field_ty
+ tree compiled_field_ty
= TyTyResolveCompile::compile (ctx, field->get_field_type ());
- Backend::Btyped_identifier f (field->get_name (), compiled_field_ty,
+ Backend::typed_identifier f (field->get_name (), compiled_field_ty,
ctx->get_mappings ()->lookup_location (
type.get_ty_ref ()));
fields.push_back (std::move (f));
}
- Btype *type_record;
+ tree type_record;
if (type.is_union ())
type_record = ctx->get_backend ()->union_type (fields);
else
type_record = ctx->get_backend ()->struct_type (fields);
- Btype *named_struct
+ tree named_struct
= ctx->get_backend ()->named_type (type.get_name (), type_record,
ctx->get_mappings ()->lookup_location (
type.get_ty_ref ()));
@@ -482,11 +482,11 @@ public:
return;
// create implicit struct
- std::vector<Backend::Btyped_identifier> fields;
+ std::vector<Backend::typed_identifier> fields;
for (size_t i = 0; i < type.num_fields (); i++)
{
TyTy::BaseType *field = type.get_field (i);
- Btype *compiled_field_ty = TyTyResolveCompile::compile (ctx, field);
+ tree compiled_field_ty = TyTyResolveCompile::compile (ctx, field);
// rustc uses the convention __N, where N is an integer, to
// name the fields of a tuple. We follow this as well,
@@ -494,15 +494,15 @@ public:
// this, rather than simply emitting the integer, is that this
// approach makes it simpler to use a C-only debugger, or
// GDB's C mode, when debugging Rust.
- Backend::Btyped_identifier f ("__" + std::to_string (i),
+ Backend::typed_identifier f ("__" + std::to_string (i),
compiled_field_ty,
ctx->get_mappings ()->lookup_location (
type.get_ty_ref ()));
fields.push_back (std::move (f));
}
- Btype *struct_type_record = ctx->get_backend ()->struct_type (fields);
- Btype *named_struct
+ tree struct_type_record = ctx->get_backend ()->struct_type (fields);
+ tree named_struct
= ctx->get_backend ()->named_type (type.as_string (), struct_type_record,
ctx->get_mappings ()->lookup_location (
type.get_ty_ref ()));
@@ -514,7 +514,7 @@ public:
void visit (const TyTy::ArrayType &type) override
{
- Btype *element_type
+ tree element_type
= TyTyResolveCompile::compile (ctx, type.get_element_type ());
translated
= ctx->get_backend ()->array_type (element_type, type.get_capacity ());
@@ -522,7 +522,7 @@ public:
void visit (const TyTy::BoolType &type) override
{
- ::Btype *compiled_type = nullptr;
+ ::tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -530,7 +530,7 @@ public:
void visit (const TyTy::IntType &type) override
{
- ::Btype *compiled_type = nullptr;
+ ::tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -538,7 +538,7 @@ public:
void visit (const TyTy::UintType &type) override
{
- ::Btype *compiled_type = nullptr;
+ ::tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -546,7 +546,7 @@ public:
void visit (const TyTy::FloatType &type) override
{
- ::Btype *compiled_type = nullptr;
+ ::tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -554,7 +554,7 @@ public:
void visit (const TyTy::USizeType &type) override
{
- ::Btype *compiled_type = nullptr;
+ ::tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -562,7 +562,7 @@ public:
void visit (const TyTy::ISizeType &type) override
{
- ::Btype *compiled_type = nullptr;
+ ::tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -570,7 +570,7 @@ public:
void visit (const TyTy::CharType &type) override
{
- ::Btype *compiled_type = nullptr;
+ ::tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -578,7 +578,7 @@ public:
void visit (const TyTy::ReferenceType &type) override
{
- Btype *base_compiled_type
+ tree base_compiled_type
= TyTyResolveCompile::compile (ctx, type.get_base (), trait_object_mode);
if (type.is_mutable ())
{
@@ -593,7 +593,7 @@ public:
void visit (const TyTy::PointerType &type) override
{
- Btype *base_compiled_type
+ tree base_compiled_type
= TyTyResolveCompile::compile (ctx, type.get_base (), trait_object_mode);
if (type.is_mutable ())
{
@@ -608,7 +608,7 @@ public:
void visit (const TyTy::StrType &type) override
{
- ::Btype *compiled_type = nullptr;
+ ::tree compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
rust_assert (ok);
translated = compiled_type;
@@ -633,13 +633,13 @@ public:
// create implicit struct
auto items = type.get_object_items ();
- std::vector<Backend::Btyped_identifier> fields;
+ std::vector<Backend::typed_identifier> fields;
- Btype *uint = ctx->get_backend ()->integer_type (
+ tree uint = ctx->get_backend ()->integer_type (
true, ctx->get_backend ()->get_pointer_size ());
- Btype *uintptr_ty = ctx->get_backend ()->pointer_type (uint);
+ tree uintptr_ty = ctx->get_backend ()->pointer_type (uint);
- Backend::Btyped_identifier f ("__receiver_trait_obj_ptr", uintptr_ty,
+ Backend::typed_identifier f ("__receiver_trait_obj_ptr", uintptr_ty,
ctx->get_mappings ()->lookup_location (
type.get_ty_ref ()));
fields.push_back (std::move (f));
@@ -647,18 +647,18 @@ public:
for (size_t i = 0; i < items.size (); i++)
{
// mrustc seems to make a vtable consisting of uintptr's
- Btype *uint = ctx->get_backend ()->integer_type (
+ tree uint = ctx->get_backend ()->integer_type (
true, ctx->get_backend ()->get_pointer_size ());
- Btype *uintptr_ty = ctx->get_backend ()->pointer_type (uint);
+ tree uintptr_ty = ctx->get_backend ()->pointer_type (uint);
- Backend::Btyped_identifier f ("__" + std::to_string (i), uintptr_ty,
+ Backend::typed_identifier f ("__" + std::to_string (i), uintptr_ty,
ctx->get_mappings ()->lookup_location (
type.get_ty_ref ()));
fields.push_back (std::move (f));
}
- Btype *type_record = ctx->get_backend ()->struct_type (fields);
- Btype *named_struct
+ tree type_record = ctx->get_backend ()->struct_type (fields);
+ tree named_struct
= ctx->get_backend ()->named_type (type.get_name (), type_record,
ctx->get_mappings ()->lookup_location (
type.get_ty_ref ()));
@@ -679,7 +679,7 @@ private:
Context *ctx;
bool trait_object_mode;
- ::Btype *translated;
+ ::tree translated;
size_t recursion_count;
static const size_t kDefaultRecusionLimit = 5;
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 594cfff..0279ef9 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -150,7 +150,7 @@ CompileExpr::compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn,
{
TyTy::ReferenceType *r = static_cast<TyTy::ReferenceType *> (receiver);
auto indirect_ty = r->get_base ();
- Btype *indrect_compiled_tyty
+ tree indrect_compiled_tyty
= TyTyResolveCompile::compile (ctx, indirect_ty);
Bexpression *indirect
@@ -171,7 +171,7 @@ CompileExpr::compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn,
expr_locus);
// cast it to the correct fntype
- Btype *expected_fntype = TyTyResolveCompile::compile (ctx, fntype, true);
+ tree expected_fntype = TyTyResolveCompile::compile (ctx, fntype, true);
Bexpression *fn_convert_expr
= ctx->get_backend ()->convert_expression (expected_fntype,
fn_vtable_access, expr_locus);
@@ -370,7 +370,7 @@ CompileExpr::resolve_operator_overload (
break;
case Resolver::Adjustment::AdjustmentType::DEREF_REF:
- Btype *expected_type
+ tree expected_type
= TyTyResolveCompile::compile (ctx, adjustment.get_expected ());
self
= ctx->get_backend ()->indirect_expression (expected_type, self,
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index b4079f7..d2f79ec 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -58,7 +58,7 @@ public:
TyTy::ReferenceType *r
= static_cast<TyTy::ReferenceType *> (tuple_expr_ty);
TyTy::BaseType *tuple_type = r->get_base ();
- Btype *tuple_tyty = TyTyResolveCompile::compile (ctx, tuple_type);
+ tree tuple_tyty = TyTyResolveCompile::compile (ctx, tuple_type);
Bexpression *indirect
= ctx->get_backend ()->indirect_expression (tuple_tyty, receiver_ref,
@@ -88,7 +88,7 @@ public:
return;
}
- Btype *tuple_type = TyTyResolveCompile::compile (ctx, tyty);
+ tree tuple_type = TyTyResolveCompile::compile (ctx, tyty);
rust_assert (tuple_type != nullptr);
// this assumes all fields are in order from type resolution
@@ -259,7 +259,7 @@ public:
return;
}
- Btype *type = TyTyResolveCompile::compile (ctx, tyty);
+ tree type = TyTyResolveCompile::compile (ctx, tyty);
translated
= ctx->get_backend ()->integer_constant_expression (type, ival);
}
@@ -285,7 +285,7 @@ public:
return;
}
- Btype *type = TyTyResolveCompile::compile (ctx, tyty);
+ tree type = TyTyResolveCompile::compile (ctx, tyty);
translated
= ctx->get_backend ()->float_constant_expression (type, fval);
}
@@ -341,7 +341,7 @@ public:
indexes.push_back (i);
}
- Btype *array_type = TyTyResolveCompile::compile (ctx, array_tyty);
+ tree array_type = TyTyResolveCompile::compile (ctx, array_tyty);
Bexpression *constructed
= ctx->get_backend ()->array_constructor_expression (
array_type, indexes, vals, expr.get_locus ());
@@ -414,7 +414,7 @@ public:
TyTy::ArrayType *array_tyty = static_cast<TyTy::ArrayType *> (tyty);
capacity_expr = array_tyty->get_capacity ();
- Btype *array_type = TyTyResolveCompile::compile (ctx, array_tyty);
+ tree array_type = TyTyResolveCompile::compile (ctx, array_tyty);
rust_assert (array_type != nullptr);
expr.get_internal_elements ()->accept_vis (*this);
@@ -517,7 +517,7 @@ public:
{
fncontext fnctx = ctx->peek_fn ();
Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Btype *block_type = TyTyResolveCompile::compile (ctx, if_type);
+ tree block_type = TyTyResolveCompile::compile (ctx, if_type);
bool is_address_taken = false;
Bstatement *ret_var_stmt = nullptr;
@@ -554,7 +554,7 @@ public:
{
fncontext fnctx = ctx->peek_fn ();
Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Btype *block_type = TyTyResolveCompile::compile (ctx, if_type);
+ tree block_type = TyTyResolveCompile::compile (ctx, if_type);
bool is_address_taken = false;
Bstatement *ret_var_stmt = nullptr;
@@ -590,7 +590,7 @@ public:
{
fncontext fnctx = ctx->peek_fn ();
Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Btype *block_type = TyTyResolveCompile::compile (ctx, block_tyty);
+ tree block_type = TyTyResolveCompile::compile (ctx, block_tyty);
bool is_address_taken = false;
Bstatement *ret_var_stmt = nullptr;
@@ -640,7 +640,7 @@ public:
return;
}
- Btype *type = TyTyResolveCompile::compile (ctx, tyty);
+ tree type = TyTyResolveCompile::compile (ctx, tyty);
rust_assert (type != nullptr);
// this assumes all fields are in order from type resolution and if a base
@@ -705,7 +705,7 @@ public:
&field_index);
rust_assert (ok);
- Btype *adt_tyty = TyTyResolveCompile::compile (ctx, adt);
+ tree adt_tyty = TyTyResolveCompile::compile (ctx, adt);
Bexpression *indirect
= ctx->get_backend ()->indirect_expression (adt_tyty, receiver_ref,
true, expr.get_locus ());
@@ -743,7 +743,7 @@ public:
if (needs_temp)
{
Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Btype *block_type = TyTyResolveCompile::compile (ctx, block_tyty);
+ tree block_type = TyTyResolveCompile::compile (ctx, block_tyty);
bool is_address_taken = false;
Bstatement *ret_var_stmt = nullptr;
@@ -975,7 +975,7 @@ public:
return;
}
- Btype *expected_type = TyTyResolveCompile::compile (ctx, tyty);
+ tree expected_type = TyTyResolveCompile::compile (ctx, tyty);
bool known_valid = true;
translated
= ctx->get_backend ()->indirect_expression (expected_type, main_expr,
diff --git a/gcc/rust/backend/rust-compile-extern.h b/gcc/rust/backend/rust-compile-extern.h
index 6e5a3fd..2d3d251 100644
--- a/gcc/rust/backend/rust-compile-extern.h
+++ b/gcc/rust/backend/rust-compile-extern.h
@@ -55,7 +55,7 @@ public:
// FIXME this is assuming C ABI
std::string asm_name = name;
- Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
+ tree type = TyTyResolveCompile::compile (ctx, resolved_type);
bool is_external = true;
bool is_hidden = false;
bool in_unique_section = false;
@@ -128,7 +128,7 @@ public:
return;
}
- ::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
+ tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
compiled_fn_type
= ctx->get_backend ()->specify_abi_attribute (compiled_fn_type,
fntype->get_abi ());
diff --git a/gcc/rust/backend/rust-compile-fnparam.h b/gcc/rust/backend/rust-compile-fnparam.h
index b246948..903f839 100644
--- a/gcc/rust/backend/rust-compile-fnparam.h
+++ b/gcc/rust/backend/rust-compile-fnparam.h
@@ -30,7 +30,7 @@ class CompileFnParam : public HIRCompileBase
public:
static Bvariable *compile (Context *ctx, Bfunction *fndecl,
- HIR::FunctionParam *param, Btype *decl_type,
+ HIR::FunctionParam *param, tree decl_type,
Location locus)
{
CompileFnParam compiler (ctx, fndecl, decl_type, locus);
@@ -51,14 +51,14 @@ public:
}
private:
- CompileFnParam (Context *ctx, ::Bfunction *fndecl, ::Btype *decl_type,
+ CompileFnParam (Context *ctx, ::Bfunction *fndecl, tree decl_type,
Location locus)
: HIRCompileBase (ctx), fndecl (fndecl), decl_type (decl_type),
locus (locus), translated (nullptr)
{}
::Bfunction *fndecl;
- ::Btype *decl_type;
+ tree decl_type;
Location locus;
::Bvariable *translated;
};
@@ -67,7 +67,7 @@ class CompileSelfParam : public HIRCompileBase
{
public:
static Bvariable *compile (Context *ctx, Bfunction *fndecl,
- HIR::SelfParam &self, Btype *decl_type,
+ HIR::SelfParam &self, tree decl_type,
Location locus)
{
bool is_immutable
diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h
index 05c7910..51a691f 100644
--- a/gcc/rust/backend/rust-compile-implitem.h
+++ b/gcc/rust/backend/rust-compile-implitem.h
@@ -60,7 +60,7 @@ public:
&resolved_type);
rust_assert (ok);
- ::Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
+ tree type = TyTyResolveCompile::compile (ctx, resolved_type);
Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
const Resolver::CanonicalPath *canonical_path = nullptr;
@@ -136,7 +136,7 @@ public:
}
// convert to the actual function type
- ::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
+ tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
unsigned int flags = 0;
@@ -178,7 +178,7 @@ public:
return;
}
- Btype *self_type = TyTyResolveCompile::compile (ctx, self_tyty_lookup);
+ tree self_type = TyTyResolveCompile::compile (ctx, self_tyty_lookup);
if (self_type == nullptr)
{
rust_error_at (function.get_self_param ().get_locus (),
@@ -275,7 +275,7 @@ public:
Bvariable *return_address = nullptr;
if (function.has_function_return_type ())
{
- Btype *return_type = TyTyResolveCompile::compile (ctx, tyret);
+ tree return_type = TyTyResolveCompile::compile (ctx, tyret);
bool address_is_taken = false;
Bstatement *ret_var_stmt = nullptr;
@@ -349,7 +349,7 @@ public:
rust_assert (concrete != nullptr);
TyTy::BaseType *resolved_type = concrete;
- ::Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
+ tree type = TyTyResolveCompile::compile (ctx, resolved_type);
Bexpression *value
= CompileExpr::Compile (constant.get_expr ().get (), ctx);
@@ -404,7 +404,7 @@ public:
}
// convert to the actual function type
- ::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
+ tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
HIR::TraitFunctionDecl &function = func.get_decl ();
unsigned int flags = 0;
@@ -440,7 +440,7 @@ public:
return;
}
- Btype *self_type = TyTyResolveCompile::compile (ctx, self_tyty_lookup);
+ tree self_type = TyTyResolveCompile::compile (ctx, self_tyty_lookup);
if (self_type == nullptr)
{
rust_error_at (function.get_self ().get_locus (),
@@ -536,7 +536,7 @@ public:
Bvariable *return_address = nullptr;
if (function.has_return_type ())
{
- Btype *return_type = TyTyResolveCompile::compile (ctx, tyret);
+ tree return_type = TyTyResolveCompile::compile (ctx, tyret);
bool address_is_taken = false;
Bstatement *ret_var_stmt = nullptr;
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index 6691c2a..87c577c 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -61,7 +61,7 @@ public:
&resolved_type);
rust_assert (ok);
- Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
+ tree type = TyTyResolveCompile::compile (ctx, resolved_type);
Bexpression *value = CompileExpr::Compile (var.get_expr (), ctx);
const Resolver::CanonicalPath *canonical_path = nullptr;
@@ -97,7 +97,7 @@ public:
&resolved_type);
rust_assert (ok);
- ::Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
+ tree type = TyTyResolveCompile::compile (ctx, resolved_type);
Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
const Resolver::CanonicalPath *canonical_path = nullptr;
@@ -174,7 +174,7 @@ public:
fntype->override_context ();
}
- ::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
+ tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
unsigned int flags = 0;
bool is_main_fn = function.get_function_name ().compare ("main") == 0;
@@ -275,7 +275,7 @@ public:
Bvariable *return_address = nullptr;
if (function.has_function_return_type ())
{
- Btype *return_type = TyTyResolveCompile::compile (ctx, tyret);
+ tree return_type = TyTyResolveCompile::compile (ctx, tyret);
bool address_is_taken = false;
Bstatement *ret_var_stmt = nullptr;
diff --git a/gcc/rust/backend/rust-compile-stmt.h b/gcc/rust/backend/rust-compile-stmt.h
index 754c5d2..80566f6 100644
--- a/gcc/rust/backend/rust-compile-stmt.h
+++ b/gcc/rust/backend/rust-compile-stmt.h
@@ -56,7 +56,7 @@ public:
&resolved_type);
rust_assert (ok);
- ::Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
+ tree type = TyTyResolveCompile::compile (ctx, resolved_type);
Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
const Resolver::CanonicalPath *canonical_path = nullptr;
diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h
index 180b971..04a3ecd 100644
--- a/gcc/rust/backend/rust-compile-tyty.h
+++ b/gcc/rust/backend/rust-compile-tyty.h
@@ -34,7 +34,7 @@ namespace Compile {
class TyTyCompile : public TyTy::TyVisitor
{
public:
- static ::Btype *compile (::Backend *backend, TyTy::BaseType *ty)
+ static tree compile (::Backend *backend, TyTy::BaseType *ty)
{
TyTyCompile compiler (backend);
ty->accept_vis (compiler);
@@ -72,15 +72,15 @@ public:
void visit (TyTy::FnType &type) override
{
- Backend::Btyped_identifier receiver;
- std::vector<Backend::Btyped_identifier> parameters;
- std::vector<Backend::Btyped_identifier> results;
+ Backend::typed_identifier receiver;
+ std::vector<Backend::typed_identifier> parameters;
+ std::vector<Backend::typed_identifier> results;
if (!type.get_return_type ()->is_unit ())
{
auto hir_type = type.get_return_type ();
auto ret = TyTyCompile::compile (backend, hir_type);
- results.push_back (Backend::Btyped_identifier (
+ results.push_back (Backend::typed_identifier (
"_", ret, mappings->lookup_location (hir_type->get_ref ())));
}
@@ -90,7 +90,7 @@ public:
auto param_tyty = params.second;
auto compiled_param_type = TyTyCompile::compile (backend, param_tyty);
- auto compiled_param = Backend::Btyped_identifier (
+ auto compiled_param = Backend::typed_identifier (
param_pattern->as_string (), compiled_param_type,
mappings->lookup_location (param_tyty->get_ref ()));
@@ -227,7 +227,7 @@ public:
void visit (TyTy::StrType &) override
{
- Btype *raw_str = backend->raw_str_type ();
+ tree raw_str = backend->raw_str_type ();
translated
= backend->named_type ("str", raw_str, Linemap::predeclared_location ());
}
@@ -248,7 +248,7 @@ private:
{}
::Backend *backend;
- ::Btype *translated;
+ tree translated;
Analysis::Mappings *mappings;
};
diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h
index 7a86e15..deabd7d 100644
--- a/gcc/rust/backend/rust-compile-var-decl.h
+++ b/gcc/rust/backend/rust-compile-var-decl.h
@@ -70,7 +70,7 @@ private:
{}
::Bfunction *fndecl;
- ::Btype *translated_type;
+ tree translated_type;
Location locus;
::Bvariable *translated;
};
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index e53993a..cb736f3 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -72,7 +72,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
{
rust_assert (tyty->get_kind () == TyTy::TypeKind::ADT);
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (tyty);
- Btype *compiled_adt_type = TyTyResolveCompile::compile (ctx, tyty);
+ tree compiled_adt_type = TyTyResolveCompile::compile (ctx, tyty);
rust_assert (!adt->is_enum ());
rust_assert (adt->number_of_variants () == 1);
@@ -275,7 +275,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
break;
case Resolver::Adjustment::AdjustmentType::DEREF_REF:
- Btype *expected_type
+ tree expected_type
= TyTyResolveCompile::compile (ctx, adjustment.get_expected ());
self = ctx->get_backend ()->indirect_expression (
expected_type, self, true, /* known_valid*/
@@ -587,7 +587,7 @@ HIRCompileBase::coerce_to_dyn_object (Bexpression *compiled_ref,
const TyTy::DynamicObjectType *ty,
Location locus)
{
- Btype *dynamic_object = TyTyResolveCompile::compile (ctx, ty);
+ tree dynamic_object = TyTyResolveCompile::compile (ctx, ty);
//' this assumes ordering and current the structure is
// __trait_object_ptr
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index 340284f..3bdd0c6 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -29,6 +29,8 @@
#include "operator.h"
#include "rust-abi.h"
+#include "tree.h"
+
extern bool
saw_errors (void);
@@ -39,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 representation of a type.
-class Btype;
-
// The backend represention of an expression.
class Bexpression;
@@ -70,24 +69,24 @@ public:
// Name/type/location. Used for function parameters, struct fields,
// interface methods.
- struct Btyped_identifier
+ struct typed_identifier
{
std::string name;
- Btype *btype;
+ tree type;
Location location;
- Btyped_identifier ()
- : name (), btype (NULL), location (Linemap::unknown_location ())
+ typed_identifier ()
+ : name (), type (NULL_TREE), location (Linemap::unknown_location ())
{}
- Btyped_identifier (const std::string &a_name, Btype *a_btype,
+ typed_identifier (const std::string &a_name, tree a_type,
Location a_location)
- : name (a_name), btype (a_btype), location (a_location)
+ : name (a_name), type (a_type), location (a_location)
{}
};
// debug
- virtual void debug (Btype *) = 0;
+ virtual void debug (tree) = 0;
virtual void debug (Bexpression *) = 0;
virtual void debug (Bstatement *) = 0;
virtual void debug (Bfunction *) = 0;
@@ -147,50 +146,50 @@ public:
// Produce an error type. Actually the backend could probably just
// crash if this is called.
- virtual Btype *error_type () = 0;
+ virtual tree error_type () = 0;
// Get a void type. This is used in (at least) two ways: 1) as the
// return type of a function with no result parameters; 2)
// unsafe.Pointer is represented as *void.
- virtual Btype *void_type () = 0;
+ virtual tree void_type () = 0;
// get unit-type
- virtual Btype *unit_type () = 0;
+ virtual tree unit_type () = 0;
// Get the unnamed boolean type.
- virtual Btype *bool_type () = 0;
+ virtual tree bool_type () = 0;
// Get the char type
- virtual Btype *char_type () = 0;
+ virtual tree char_type () = 0;
// Get the wchar type
- virtual Btype *wchar_type () = 0;
+ virtual tree wchar_type () = 0;
// Get the Host pointer size in bits
virtual int get_pointer_size () = 0;
// Get the raw str type const char*
- virtual Btype *raw_str_type () = 0;
+ virtual tree raw_str_type () = 0;
// Get an unnamed integer type with the given signedness and number
// of bits.
- virtual Btype *integer_type (bool is_unsigned, int bits) = 0;
+ virtual tree integer_type (bool is_unsigned, int bits) = 0;
// Get an unnamed floating point type with the given number of bits
// (32 or 64).
- virtual Btype *float_type (int bits) = 0;
+ virtual tree float_type (int bits) = 0;
// Get an unnamed complex type with the given number of bits (64 or 128).
- virtual Btype *complex_type (int bits) = 0;
+ virtual tree complex_type (int bits) = 0;
// Get a pointer type.
- virtual Btype *pointer_type (Btype *to_type) = 0;
+ virtual tree pointer_type (tree to_type) = 0;
// Get a reference type.
- virtual Btype *reference_type (Btype *to_type) = 0;
+ virtual tree reference_type (tree to_type) = 0;
// make type immutable
- virtual Btype *immutable_type (Btype *base) = 0;
+ virtual tree immutable_type (tree base) = 0;
// Get a function type. The receiver, parameter, and results are
// generated from the types in the Function_type. The Function_type
@@ -201,62 +200,62 @@ public:
// one result, RESULT_STRUCT is a struct type to hold the results,
// and RESULTS may be ignored; if there are zero or one results,
// RESULT_STRUCT is NULL.
- virtual Btype *
- function_type (const Btyped_identifier &receiver,
- const std::vector<Btyped_identifier> &parameters,
- const std::vector<Btyped_identifier> &results,
- Btype *result_struct, Location location)
+ virtual tree
+ function_type (const typed_identifier &receiver,
+ const std::vector<typed_identifier> &parameters,
+ const std::vector<typed_identifier> &results,
+ tree result_struct, Location location)
= 0;
- virtual Btype *
- function_type_varadic (const Btyped_identifier &receiver,
- const std::vector<Btyped_identifier> &parameters,
- const std::vector<Btyped_identifier> &results,
- Btype *result_struct, Location location)
+ virtual tree
+ function_type_varadic (const typed_identifier &receiver,
+ const std::vector<typed_identifier> &parameters,
+ const std::vector<typed_identifier> &results,
+ tree result_struct, Location location)
= 0;
- virtual Btype *function_ptr_type (Btype *result,
- const std::vector<Btype *> &praameters,
- Location location)
+ virtual tree function_ptr_type (tree result,
+ const std::vector<tree> &praameters,
+ Location location)
= 0;
// Get a struct type.
- virtual Btype *struct_type (const std::vector<Btyped_identifier> &fields) = 0;
+ virtual tree struct_type (const std::vector<typed_identifier> &fields) = 0;
// Get a union type.
- virtual Btype *union_type (const std::vector<Btyped_identifier> &fields) = 0;
+ virtual tree union_type (const std::vector<typed_identifier> &fields) = 0;
// Get an array type.
- virtual Btype *array_type (Btype *element_type, Bexpression *length) = 0;
+ virtual tree array_type (tree element_type, Bexpression *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
// created via placeholder_pointer_type, placeholder_struct_type, or
// placeholder_array_type.. (It may be called for a pointer,
// struct, or array type in a case like "type P *byte; type Q P".)
- virtual Btype *named_type (const std::string &name, Btype *, Location) = 0;
+ virtual tree named_type (const std::string &name, tree, Location) = 0;
// Return the size of a type.
- virtual int64_t type_size (Btype *) = 0;
+ virtual int64_t type_size (tree) = 0;
// Return the alignment of a type.
- virtual int64_t type_alignment (Btype *) = 0;
+ virtual int64_t type_alignment (tree) = 0;
// Return the alignment of a struct field of this type. This is
// normally the same as type_alignment, but not always.
- virtual int64_t type_field_alignment (Btype *) = 0;
+ virtual int64_t type_field_alignment (tree) = 0;
// Return the offset of field INDEX in a struct type. INDEX is the
// entry in the FIELDS std::vector parameter of struct_type or
// set_placeholder_struct_type.
- virtual int64_t type_field_offset (Btype *, size_t index) = 0;
+ virtual int64_t type_field_offset (tree, size_t index) = 0;
// Expressions.
// 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 (Btype *) = 0;
+ virtual Bexpression *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
@@ -278,27 +277,25 @@ public:
// (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 (Btype *btype, Bexpression *expr,
+ virtual Bexpression *indirect_expression (tree btype, Bexpression *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 (Btype *btype,
+ virtual Bexpression *named_constant_expression (tree btype,
const std::string &name,
Bexpression *val, Location)
= 0;
// Return an expression for the multi-precision integer VAL in BTYPE.
- virtual Bexpression *integer_constant_expression (Btype *btype, mpz_t val)
- = 0;
+ virtual Bexpression *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 (Btype *btype, mpfr_t val) = 0;
+ virtual Bexpression *float_constant_expression (tree btype, mpfr_t val) = 0;
// Return an expression for the complex value VAL in BTYPE.
- virtual Bexpression *complex_constant_expression (Btype *btype, mpc_t val)
- = 0;
+ virtual Bexpression *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;
@@ -326,7 +323,7 @@ public:
= 0;
// Return an expression that converts EXPR to TYPE.
- virtual Bexpression *convert_expression (Btype *type, Bexpression *expr,
+ virtual Bexpression *convert_expression (tree type, Bexpression *expr,
Location)
= 0;
@@ -350,10 +347,10 @@ public:
// 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, Btype *btype,
- Bexpression *condition, Bexpression *then_expr,
- Bexpression *else_expr, Location)
+ virtual Bexpression *conditional_expression (Bfunction *function, tree btype,
+ Bexpression *condition,
+ Bexpression *then_expr,
+ Bexpression *else_expr, Location)
= 0;
// Return an expression for the negation operation OP EXPR.
@@ -388,7 +385,7 @@ public:
// backend representation a of struct. VALS must be in the same order as the
// corresponding fields in BTYPE.
virtual Bexpression *
- constructor_expression (Btype *btype, const std::vector<Bexpression *> &vals,
+ constructor_expression (tree btype, const std::vector<Bexpression *> &vals,
int, Location)
= 0;
@@ -396,7 +393,7 @@ public:
// 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 (
- Btype *btype, const std::vector<unsigned long> &indexes,
+ tree btype, const std::vector<unsigned long> &indexes,
const std::vector<Bexpression *> &vals, Location)
= 0;
@@ -535,7 +532,7 @@ public:
// permit the linker to garbage collect the variable if it is not
// referenced. LOCATION is where the variable was defined.
virtual Bvariable *global_variable (const std::string &name,
- const std::string &asm_name, Btype *btype,
+ const std::string &asm_name, tree btype,
bool is_external, bool is_hidden,
bool in_unique_section, Location location)
= 0;
@@ -561,7 +558,7 @@ public:
// LOCATION is where the variable is defined. For each local variable
// the frontend will call init_statement to set the initial value.
virtual Bvariable *
- local_variable (Bfunction *function, const std::string &name, Btype *type,
+ local_variable (Bfunction *function, const std::string &name, tree type,
Bvariable *decl_var, bool is_address_taken, Location location)
= 0;
@@ -569,14 +566,14 @@ public:
// a result parameter (result parameters are treated as local
// variables). The arguments are as for local_variable.
virtual Bvariable *
- parameter_variable (Bfunction *function, const std::string &name, Btype *type,
+ parameter_variable (Bfunction *function, const std::string &name, tree type,
bool is_address_taken, Location location)
= 0;
// Create a static chain parameter. This is the closure parameter.
virtual Bvariable *static_chain_variable (Bfunction *function,
- const std::string &name,
- Btype *type, Location location)
+ const std::string &name, tree type,
+ Location location)
= 0;
// Create a temporary variable. A temporary variable has no name,
@@ -591,7 +588,7 @@ public:
// 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 *, Btype *, Bexpression *init,
+ temporary_variable (Bfunction *, Bblock *, tree, Bexpression *init,
bool address_is_taken, Location location,
Bstatement **pstatement)
= 0;
@@ -622,10 +619,10 @@ public:
// the zero value. IS_HIDDEN and IS_COMMON will never both be true.
//
// If ALIGNMENT is not zero, it is the desired alignment of the variable.
- virtual Bvariable *
- implicit_variable (const std::string &name, const std::string &asm_name,
- Btype *type, bool is_hidden, bool is_constant,
- bool is_common, int64_t alignment)
+ virtual Bvariable *implicit_variable (const std::string &name,
+ const std::string &asm_name, tree type,
+ bool is_hidden, bool is_constant,
+ bool is_common, int64_t alignment)
= 0;
// Set the initial value of a variable created by implicit_variable.
@@ -639,7 +636,7 @@ public:
// If IS_COMMON is true, INIT will be NULL, and the
// variable should be initialized to all zeros.
virtual void implicit_variable_set_init (Bvariable *, const std::string &name,
- Btype *type, bool is_hidden,
+ tree type, bool is_hidden,
bool is_constant, bool is_common,
Bexpression *init)
= 0;
@@ -651,7 +648,7 @@ public:
// variable in C.
virtual Bvariable *implicit_variable_reference (const std::string &name,
const std::string &asm_name,
- Btype *type)
+ tree type)
= 0;
// Create a named immutable initialized data structure. This is
@@ -684,7 +681,7 @@ public:
// immutable_struct_set_init.
virtual Bvariable *
immutable_struct (const std::string &name, const std::string &asm_name,
- bool is_hidden, bool is_common, Btype *type, Location)
+ bool is_hidden, bool is_common, tree type, Location)
= 0;
// Set the initial value of a variable created by immutable_struct.
@@ -696,7 +693,7 @@ public:
// immutable_struct.
virtual void immutable_struct_set_init (Bvariable *, const std::string &name,
bool is_hidden, bool is_common,
- Btype *type, Location,
+ tree type, Location,
Bexpression *initializer)
= 0;
@@ -707,7 +704,7 @@ public:
// corresponds to an extern const global variable in C.
virtual Bvariable *immutable_struct_reference (const std::string &name,
const std::string &asm_name,
- Btype *type, Location)
+ tree type, Location)
= 0;
// Labels.
@@ -774,12 +771,12 @@ public:
// string, is the name that should be used in the symbol table; this
// will be non-empty if a magic extern comment is used. FLAGS is
// bit flags described above.
- virtual Bfunction *function (Btype *fntype, const std::string &name,
+ virtual Bfunction *function (tree fntype, const std::string &name,
const std::string &asm_name, unsigned int flags,
Location)
= 0;
- virtual Btype *specify_abi_attribute (Btype *type, Rust::ABI abi) = 0;
+ virtual tree specify_abi_attribute (tree type, Rust::ABI abi) = 0;
// Create a statement that runs all deferred calls for FUNCTION. This should
// be a statement that looks like this in C++:
@@ -814,7 +811,7 @@ public:
// Write the definitions for all TYPE_DECLS, CONSTANT_DECLS,
// FUNCTION_DECLS, and VARIABLE_DECLS declared globally.
virtual void
- write_global_definitions (const std::vector<Btype *> &type_decls,
+ write_global_definitions (const std::vector<tree> &type_decls,
const std::vector<Bexpression *> &constant_decls,
const std::vector<Bfunction *> &function_decls,
const std::vector<Bvariable *> &variable_decls)
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 65fc1f3..a205d65 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -69,11 +69,6 @@ private:
};
// In gcc, types, expressions, and statements are all trees.
-class Btype : public Gcc_tree
-{
-public:
- Btype (tree t) : Gcc_tree (t) {}
-};
class Bexpression : public Gcc_tree
{
@@ -159,7 +154,7 @@ class Gcc_backend : public Backend
public:
Gcc_backend ();
- void debug (Btype *t) { debug_tree (t->get_tree ()); };
+ 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 ()); };
@@ -168,13 +163,13 @@ public:
void debug (Blabel *t) { debug_tree (t->get_tree ()); };
// Types.
- Btype *error_type () { return this->make_type (error_mark_node); }
+ tree error_type () { return error_mark_node; }
- Btype *void_type () { return this->make_type (void_type_node); }
+ tree void_type () { return void_type_node; }
- Btype *unit_type ()
+ tree unit_type ()
{
- static Btype *unit_type;
+ static tree unit_type;
if (unit_type == nullptr)
{
auto unit_type_node = integer_type (true, 0);
@@ -185,9 +180,9 @@ public:
return unit_type;
}
- Btype *bool_type () { return this->make_type (boolean_type_node); }
+ tree bool_type () { return boolean_type_node; }
- Btype *char_type () { return this->make_type (char_type_node); }
+ tree char_type () { return char_type_node; }
bool const_size_cast (Bexpression *expr, size_t *result)
{
@@ -221,72 +216,71 @@ public:
bool const_values_equal (Bexpression *a, Bexpression *b)
{
- return operand_equal_p (a->get_tree (), b->get_tree (),
- OEP_ONLY_CONST | OEP_PURE_SAME);
+ return operand_equal_p (a->get_tree (), b->get_tree (), OEP_ONLY_CONST | OEP_PURE_SAME);
// printf ("comparing!\n");
// debug_tree (a->get_tree ());
// debug_tree (b->get_tree ());
// printf ("ok = %s\n", ok ? "true" : "false");
}
- Btype *wchar_type ()
+ tree wchar_type ()
{
tree wchar = make_unsigned_type (32);
TYPE_STRING_FLAG (wchar) = 1;
- return this->make_type (wchar);
+ return wchar;
}
int get_pointer_size ();
- Btype *raw_str_type ();
+ tree raw_str_type ();
- Btype *integer_type (bool, int);
+ tree integer_type (bool, int);
- Btype *float_type (int);
+ tree float_type (int);
- Btype *complex_type (int);
+ tree complex_type (int);
- Btype *pointer_type (Btype *);
+ tree pointer_type (tree);
- Btype *reference_type (Btype *);
+ tree reference_type (tree);
- Btype *immutable_type (Btype *);
+ tree immutable_type (tree);
- Btype *specify_abi_attribute (Btype *, Rust::ABI);
+ tree specify_abi_attribute (tree, Rust::ABI);
- Btype *insert_type_attribute (Btype *, const std::string &);
+ tree insert_type_attribute (tree, const std::string &);
- Btype *function_type (const Btyped_identifier &,
- const std::vector<Btyped_identifier> &,
- const std::vector<Btyped_identifier> &, Btype *,
+ tree function_type (const typed_identifier &,
+ const std::vector<typed_identifier> &,
+ const std::vector<typed_identifier> &, tree,
const Location);
- Btype *function_type_varadic (const Btyped_identifier &,
- const std::vector<Btyped_identifier> &,
- const std::vector<Btyped_identifier> &, Btype *,
+ tree function_type_varadic (const typed_identifier &,
+ const std::vector<typed_identifier> &,
+ const std::vector<typed_identifier> &, tree,
const Location);
- Btype *function_ptr_type (Btype *, const std::vector<Btype *> &, Location);
+ tree function_ptr_type (tree, const std::vector<tree> &, Location);
- Btype *struct_type (const std::vector<Btyped_identifier> &);
+ tree struct_type (const std::vector<typed_identifier> &);
- Btype *union_type (const std::vector<Btyped_identifier> &);
+ tree union_type (const std::vector<typed_identifier> &);
- Btype *array_type (Btype *, Bexpression *);
+ tree array_type (tree, Bexpression *);
- Btype *named_type (const std::string &, Btype *, Location);
+ tree named_type (const std::string &, tree, Location);
- int64_t type_size (Btype *);
+ int64_t type_size (tree);
- int64_t type_alignment (Btype *);
+ int64_t type_alignment (tree);
- int64_t type_field_alignment (Btype *);
+ int64_t type_field_alignment (tree);
- int64_t type_field_offset (Btype *, size_t index);
+ int64_t type_field_offset (tree, size_t index);
// Expressions.
- Bexpression *zero_expression (Btype *);
+ Bexpression *zero_expression (tree);
Bexpression *error_expression ()
{
@@ -310,17 +304,17 @@ public:
Bexpression *var_expression (Bvariable *var, Location);
- Bexpression *indirect_expression (Btype *, Bexpression *expr,
+ Bexpression *indirect_expression (tree, Bexpression *expr,
bool known_valid, Location);
- Bexpression *named_constant_expression (Btype *btype, const std::string &name,
+ Bexpression *named_constant_expression (tree type, const std::string &name,
Bexpression *val, Location);
- Bexpression *integer_constant_expression (Btype *btype, mpz_t val);
+ Bexpression *integer_constant_expression (tree type, mpz_t val);
- Bexpression *float_constant_expression (Btype *btype, mpfr_t val);
+ Bexpression *float_constant_expression (tree type, mpfr_t val);
- Bexpression *complex_constant_expression (Btype *btype, mpc_t val);
+ Bexpression *complex_constant_expression (tree type, mpc_t val);
Bexpression *string_constant_expression (const std::string &val);
@@ -337,7 +331,7 @@ public:
Bexpression *complex_expression (Bexpression *breal, Bexpression *bimag,
Location);
- Bexpression *convert_expression (Btype *type, Bexpression *expr, Location);
+ Bexpression *convert_expression (tree type, Bexpression *expr, Location);
Bexpression *function_code_expression (Bfunction *, Location);
@@ -347,7 +341,7 @@ public:
Bexpression *compound_expression (Bstatement *, Bexpression *, Location);
- Bexpression *conditional_expression (Bfunction *, Btype *, Bexpression *,
+ Bexpression *conditional_expression (Bfunction *, tree, Bexpression *,
Bexpression *, Bexpression *, Location);
Bexpression *negation_expression (NegationOperator op, Bexpression *expr,
@@ -364,11 +358,11 @@ public:
Bexpression *left, Bexpression *right,
Location);
- Bexpression *constructor_expression (Btype *,
+ Bexpression *constructor_expression (tree,
const std::vector<Bexpression *> &, int,
Location);
- Bexpression *array_constructor_expression (Btype *,
+ Bexpression *array_constructor_expression (tree,
const std::vector<unsigned long> &,
const std::vector<Bexpression *> &,
Location);
@@ -434,41 +428,41 @@ public:
Bvariable *error_variable () { return new Bvariable (error_mark_node); }
Bvariable *global_variable (const std::string &var_name,
- const std::string &asm_name, Btype *btype,
+ const std::string &asm_name, tree type,
bool is_external, bool is_hidden,
bool in_unique_section, Location location);
void global_variable_set_init (Bvariable *, Bexpression *);
- Bvariable *local_variable (Bfunction *, const std::string &, Btype *,
+ Bvariable *local_variable (Bfunction *, const std::string &, tree,
Bvariable *, bool, Location);
- Bvariable *parameter_variable (Bfunction *, const std::string &, Btype *,
+ Bvariable *parameter_variable (Bfunction *, const std::string &, tree,
bool, Location);
- Bvariable *static_chain_variable (Bfunction *, const std::string &, Btype *,
+ Bvariable *static_chain_variable (Bfunction *, const std::string &, tree,
Location);
- Bvariable *temporary_variable (Bfunction *, Bblock *, Btype *, Bexpression *,
+ Bvariable *temporary_variable (Bfunction *, Bblock *, tree, Bexpression *,
bool, Location, Bstatement **);
Bvariable *implicit_variable (const std::string &, const std::string &,
- Btype *, bool, bool, bool, int64_t);
+ tree, bool, bool, bool, int64_t);
- void implicit_variable_set_init (Bvariable *, const std::string &, Btype *,
+ void implicit_variable_set_init (Bvariable *, const std::string &, tree,
bool, bool, bool, Bexpression *);
Bvariable *implicit_variable_reference (const std::string &,
- const std::string &, Btype *);
+ const std::string &, tree);
Bvariable *immutable_struct (const std::string &, const std::string &, bool,
- bool, Btype *, Location);
+ bool, tree, Location);
void immutable_struct_set_init (Bvariable *, const std::string &, bool, bool,
- Btype *, Location, Bexpression *);
+ tree, Location, Bexpression *);
Bvariable *immutable_struct_reference (const std::string &,
- const std::string &, Btype *,
+ const std::string &, tree,
Location);
// Labels.
@@ -485,7 +479,7 @@ public:
Bfunction *error_function () { return this->make_function (error_mark_node); }
- Bfunction *function (Btype *fntype, const std::string &name,
+ Bfunction *function (tree fntype, const std::string &name,
const std::string &asm_name, unsigned int flags,
Location);
@@ -502,7 +496,7 @@ public:
Bfunction *lookup_builtin_by_rust_name (const std::string &);
- void write_global_definitions (const std::vector<Btype *> &,
+ void write_global_definitions (const std::vector<tree> &,
const std::vector<Bexpression *> &,
const std::vector<Bfunction *> &,
const std::vector<Bvariable *> &);
@@ -516,14 +510,11 @@ private:
// Make a Bstatement from a tree.
Bstatement *make_statement (tree t) { return new Bstatement (t); }
- // Make a Btype from a tree.
- Btype *make_type (tree t) { return new Btype (t); }
-
Bfunction *make_function (tree t) { return new Bfunction (t); }
- Btype *fill_in_fields (Btype *, const std::vector<Btyped_identifier> &);
+ tree fill_in_fields (tree, const std::vector<typed_identifier> &);
- Btype *fill_in_array (Btype *, Btype *, Bexpression *);
+ tree fill_in_array (tree, tree, Bexpression *);
tree non_zero_size_type (tree);
@@ -791,15 +782,15 @@ Gcc_backend::get_pointer_size ()
return POINTER_SIZE;
}
-Btype *
+tree
Gcc_backend::raw_str_type ()
{
tree char_ptr = build_pointer_type (char_type_node);
tree const_char_type = build_qualified_type (char_ptr, TYPE_QUAL_CONST);
- return this->make_type (const_char_type);
+ return const_char_type;
}
-Btype *
+tree
Gcc_backend::integer_type (bool is_unsigned, int bits)
{
tree type;
@@ -829,12 +820,12 @@ Gcc_backend::integer_type (bool is_unsigned, int bits)
else
type = make_signed_type (bits);
}
- return this->make_type (type);
+ return type;
}
// Get an unnamed float type.
-Btype *
+tree
Gcc_backend::float_type (int bits)
{
tree type;
@@ -850,12 +841,12 @@ Gcc_backend::float_type (int bits)
TYPE_PRECISION (type) = bits;
layout_type (type);
}
- return this->make_type (type);
+ return type;
}
// Get an unnamed complex type.
-Btype *
+tree
Gcc_backend::complex_type (int bits)
{
tree type;
@@ -872,49 +863,46 @@ Gcc_backend::complex_type (int bits)
layout_type (type);
type = build_complex_type (type);
}
- return this->make_type (type);
+ return type;
}
// Get a pointer type.
-Btype *
-Gcc_backend::pointer_type (Btype *to_type)
+tree
+Gcc_backend::pointer_type (tree to_type)
{
- tree to_type_tree = to_type->get_tree ();
- if (to_type_tree == error_mark_node)
+ if (to_type == error_mark_node)
return this->error_type ();
- tree type = build_pointer_type (to_type_tree);
- return this->make_type (type);
+ tree type = build_pointer_type (to_type);
+ return type;
}
// Get a reference type.
-Btype *
-Gcc_backend::reference_type (Btype *to_type)
+tree
+Gcc_backend::reference_type (tree to_type)
{
- tree to_type_tree = to_type->get_tree ();
- if (to_type_tree == error_mark_node)
+ if (to_type == error_mark_node)
return this->error_type ();
- tree type = build_reference_type (to_type_tree);
- return this->make_type (type);
+ tree type = build_reference_type (to_type);
+ return type;
}
// Get immutable type
-Btype *
-Gcc_backend::immutable_type (Btype *base)
+tree
+Gcc_backend::immutable_type (tree base)
{
- tree type_tree = base->get_tree ();
- if (type_tree == error_mark_node)
+ if (base == error_mark_node)
return this->error_type ();
- tree constified = build_qualified_type (type_tree, TYPE_QUAL_CONST);
- return this->make_type (constified);
+ tree constified = build_qualified_type (base, TYPE_QUAL_CONST);
+ return constified;
}
// ABI
-Btype *
-Gcc_backend::specify_abi_attribute (Btype *type, Rust::ABI abi)
+tree
+Gcc_backend::specify_abi_attribute (tree type, Rust::ABI abi)
{
std::string abi_string;
switch (abi)
@@ -940,46 +928,46 @@ Gcc_backend::specify_abi_attribute (Btype *type, Rust::ABI abi)
return insert_type_attribute (type, abi_string);
}
-Btype *
-Gcc_backend::insert_type_attribute (Btype *type, const std::string &attrname)
+tree
+Gcc_backend::insert_type_attribute (tree type, const std::string &attrname)
{
tree ident = get_identifier (attrname.c_str ());
tree attribs = NULL_TREE;
- tree old_attrs = TYPE_ATTRIBUTES (type->get_tree ());
+ tree old_attrs = TYPE_ATTRIBUTES (type);
if (old_attrs)
attribs = merge_type_attributes (old_attrs,
tree_cons (ident, NULL_TREE, NULL_TREE));
else
attribs = tree_cons (ident, NULL_TREE, NULL_TREE);
- tree res = build_type_attribute_variant (type->get_tree (), attribs);
- return this->make_type (res);
+ tree res = build_type_attribute_variant (type, attribs);
+ return res;
}
// Make a function type.
-Btype *
-Gcc_backend::function_type (const Btyped_identifier &receiver,
- const std::vector<Btyped_identifier> &parameters,
- const std::vector<Btyped_identifier> &results,
- Btype *result_struct, Location)
+tree
+Gcc_backend::function_type (const typed_identifier &receiver,
+ const std::vector<typed_identifier> &parameters,
+ const std::vector<typed_identifier> &results,
+ tree result_struct, Location)
{
tree args = NULL_TREE;
tree *pp = &args;
- if (receiver.btype != NULL)
+ if (receiver.type != NULL_TREE)
{
- tree t = receiver.btype->get_tree ();
+ tree t = receiver.type;
if (t == error_mark_node)
return this->error_type ();
*pp = tree_cons (NULL_TREE, t, NULL_TREE);
pp = &TREE_CHAIN (*pp);
}
- for (std::vector<Btyped_identifier>::const_iterator p = parameters.begin ();
+ for (std::vector<typed_identifier>::const_iterator p = parameters.begin ();
p != parameters.end (); ++p)
{
- tree t = p->btype->get_tree ();
+ tree t = p->type;
if (t == error_mark_node)
return this->error_type ();
*pp = tree_cons (NULL_TREE, t, NULL_TREE);
@@ -994,11 +982,11 @@ Gcc_backend::function_type (const Btyped_identifier &receiver,
if (results.empty ())
result = void_type_node;
else if (results.size () == 1)
- result = results.front ().btype->get_tree ();
+ result = results.front ().type;
else
{
gcc_assert (result_struct != NULL);
- result = result_struct->get_tree ();
+ result = result_struct;
}
if (result == error_mark_node)
return this->error_type ();
@@ -1015,32 +1003,32 @@ Gcc_backend::function_type (const Btyped_identifier &receiver,
if (fntype == error_mark_node)
return this->error_type ();
- return this->make_type (build_pointer_type (fntype));
+ return build_pointer_type (fntype);
}
-Btype *
+tree
Gcc_backend::function_type_varadic (
- const Btyped_identifier &receiver,
- const std::vector<Btyped_identifier> &parameters,
- const std::vector<Btyped_identifier> &results, Btype *result_struct, Location)
+ const typed_identifier &receiver,
+ const std::vector<typed_identifier> &parameters,
+ const std::vector<typed_identifier> &results, tree result_struct, Location)
{
- size_t n = parameters.size () + (receiver.btype != NULL ? 1 : 0);
+ size_t n = parameters.size () + (receiver.type != NULL_TREE ? 1 : 0);
tree *args = XALLOCAVEC (tree, n);
size_t offs = 0;
- if (receiver.btype != NULL)
+ if (receiver.type != NULL_TREE)
{
- tree t = receiver.btype->get_tree ();
+ tree t = receiver.type;
if (t == error_mark_node)
return this->error_type ();
args[offs++] = t;
}
- for (std::vector<Btyped_identifier>::const_iterator p = parameters.begin ();
+ for (std::vector<typed_identifier>::const_iterator p = parameters.begin ();
p != parameters.end (); ++p)
{
- tree t = p->btype->get_tree ();
+ tree t = p->type;
if (t == error_mark_node)
return this->error_type ();
args[offs++] = t;
@@ -1050,11 +1038,11 @@ Gcc_backend::function_type_varadic (
if (results.empty ())
result = void_type_node;
else if (results.size () == 1)
- result = results.front ().btype->get_tree ();
+ result = results.front ().type;
else
{
- gcc_assert (result_struct != NULL);
- result = result_struct->get_tree ();
+ gcc_assert (result_struct != NULL_TREE);
+ result = result_struct;
}
if (result == error_mark_node)
return this->error_type ();
@@ -1071,12 +1059,12 @@ Gcc_backend::function_type_varadic (
if (fntype == error_mark_node)
return this->error_type ();
- return this->make_type (build_pointer_type (fntype));
+ return build_pointer_type (fntype);
}
-Btype *
-Gcc_backend::function_ptr_type (Btype *result_type,
- const std::vector<Btype *> &parameters,
+tree
+Gcc_backend::function_ptr_type (tree result_type,
+ const std::vector<tree> &parameters,
Location /* locus */)
{
tree args = NULL_TREE;
@@ -1084,17 +1072,16 @@ Gcc_backend::function_ptr_type (Btype *result_type,
for (auto &param : parameters)
{
- tree t = param->get_tree ();
- if (t == error_mark_node)
+ if (param == error_mark_node)
return this->error_type ();
- *pp = tree_cons (NULL_TREE, t, NULL_TREE);
+ *pp = tree_cons (NULL_TREE, param, NULL_TREE);
pp = &TREE_CHAIN (*pp);
}
*pp = void_list_node;
- tree result = result_type->get_tree ();
+ tree result = result_type;
if (result != void_type_node && int_size_in_bytes (result) == 0)
result = void_type_node;
@@ -1102,82 +1089,77 @@ Gcc_backend::function_ptr_type (Btype *result_type,
if (fntype == error_mark_node)
return this->error_type ();
- return this->make_type (build_pointer_type (fntype));
+ return build_pointer_type (fntype);
}
// Make a struct type.
-Btype *
-Gcc_backend::struct_type (const std::vector<Btyped_identifier> &fields)
+tree
+Gcc_backend::struct_type (const std::vector<typed_identifier> &fields)
{
- return this->fill_in_fields (this->make_type (make_node (RECORD_TYPE)),
- fields);
+ return this->fill_in_fields (make_node (RECORD_TYPE), fields);
}
// Make a union type.
-Btype *
-Gcc_backend::union_type (const std::vector<Btyped_identifier> &fields)
+tree
+Gcc_backend::union_type (const std::vector<typed_identifier> &fields)
{
- return this->fill_in_fields (this->make_type (make_node (UNION_TYPE)),
- fields);
+ return this->fill_in_fields (make_node (UNION_TYPE), fields);
}
// Fill in the fields of a struct or union type.
-Btype *
-Gcc_backend::fill_in_fields (Btype *fill,
- const std::vector<Btyped_identifier> &fields)
+tree
+Gcc_backend::fill_in_fields (tree fill,
+ const std::vector<typed_identifier> &fields)
{
- tree fill_tree = fill->get_tree ();
tree field_trees = NULL_TREE;
tree *pp = &field_trees;
- for (std::vector<Btyped_identifier>::const_iterator p = fields.begin ();
+ for (std::vector<typed_identifier>::const_iterator p = fields.begin ();
p != fields.end (); ++p)
{
tree name_tree = get_identifier_from_string (p->name);
- tree type_tree = p->btype->get_tree ();
+ tree type_tree = p->type;
if (type_tree == error_mark_node)
return this->error_type ();
tree field = build_decl (p->location.gcc_location (), FIELD_DECL,
name_tree, type_tree);
- DECL_CONTEXT (field) = fill_tree;
+ DECL_CONTEXT (field) = fill;
*pp = field;
pp = &DECL_CHAIN (field);
}
- TYPE_FIELDS (fill_tree) = field_trees;
- layout_type (fill_tree);
+ TYPE_FIELDS (fill) = field_trees;
+ layout_type (fill);
// Because Rust permits converting between named struct types and
// equivalent struct types, for which we use VIEW_CONVERT_EXPR, and
// because we don't try to maintain TYPE_CANONICAL for struct types,
// we need to tell the middle-end to use structural equality.
- SET_TYPE_STRUCTURAL_EQUALITY (fill_tree);
+ SET_TYPE_STRUCTURAL_EQUALITY (fill);
return fill;
}
// Make an array type.
-Btype *
-Gcc_backend::array_type (Btype *element_btype, Bexpression *length)
+tree
+Gcc_backend::array_type (tree element_type, Bexpression *length)
{
- return this->fill_in_array (this->make_type (make_node (ARRAY_TYPE)),
- element_btype, length);
+ return this->fill_in_array (make_node (ARRAY_TYPE), element_type, length);
}
// Fill in an array type.
-Btype *
-Gcc_backend::fill_in_array (Btype *fill, Btype *element_type,
+tree
+Gcc_backend::fill_in_array (tree fill, tree element_type,
Bexpression *length)
{
- tree element_type_tree = element_type->get_tree ();
tree length_tree = length->get_tree ();
- if (element_type_tree == error_mark_node || length_tree == error_mark_node)
+ if (element_type == error_mark_node || length_tree == error_mark_node)
return this->error_type ();
- gcc_assert (TYPE_SIZE (element_type_tree) != NULL_TREE);
+ gcc_assert (TYPE_SIZE (element_type) != NULL_TREE);
length_tree = fold_convert (sizetype, length_tree);
@@ -1186,18 +1168,17 @@ Gcc_backend::fill_in_array (Btype *fill, Btype *element_type,
tree index_type_tree = build_index_type (
fold_build2 (MINUS_EXPR, sizetype, length_tree, size_one_node));
- tree fill_tree = fill->get_tree ();
- TREE_TYPE (fill_tree) = element_type_tree;
- TYPE_DOMAIN (fill_tree) = index_type_tree;
- TYPE_ADDR_SPACE (fill_tree) = TYPE_ADDR_SPACE (element_type_tree);
- layout_type (fill_tree);
+ TREE_TYPE (fill) = element_type;
+ TYPE_DOMAIN (fill) = index_type_tree;
+ TYPE_ADDR_SPACE (fill) = TYPE_ADDR_SPACE (element_type);
+ layout_type (fill);
- if (TYPE_STRUCTURAL_EQUALITY_P (element_type_tree))
- SET_TYPE_STRUCTURAL_EQUALITY (fill_tree);
- else if (TYPE_CANONICAL (element_type_tree) != element_type_tree
+ if (TYPE_STRUCTURAL_EQUALITY_P (element_type))
+ SET_TYPE_STRUCTURAL_EQUALITY (fill);
+ else if (TYPE_CANONICAL (element_type) != element_type
|| TYPE_CANONICAL (index_type_tree) != index_type_tree)
- TYPE_CANONICAL (fill_tree)
- = build_array_type (TYPE_CANONICAL (element_type_tree),
+ TYPE_CANONICAL (fill)
+ = build_array_type (TYPE_CANONICAL (element_type),
TYPE_CANONICAL (index_type_tree));
return fill;
@@ -1205,11 +1186,9 @@ Gcc_backend::fill_in_array (Btype *fill, Btype *element_type,
// Return a named version of a type.
-Btype *
-Gcc_backend::named_type (const std::string &name, Btype *btype,
- Location location)
+tree
+Gcc_backend::named_type (const std::string &name, tree type, Location location)
{
- tree type = btype->get_tree ();
if (type == error_mark_node)
return this->error_type ();
@@ -1225,7 +1204,7 @@ Gcc_backend::named_type (const std::string &name, Btype *btype,
tree decl = build_decl (BUILTINS_LOCATION, TYPE_DECL,
get_identifier_from_string (name), type);
TYPE_NAME (type) = decl;
- return this->make_type (type);
+ return type;
}
tree copy = build_variant_type_copy (type);
@@ -1233,15 +1212,14 @@ Gcc_backend::named_type (const std::string &name, Btype *btype,
get_identifier_from_string (name), copy);
DECL_ORIGINAL_TYPE (decl) = type;
TYPE_NAME (copy) = decl;
- return this->make_type (copy);
+ return copy;
}
// Return the size of a type.
int64_t
-Gcc_backend::type_size (Btype *btype)
+Gcc_backend::type_size (tree t)
{
- tree t = btype->get_tree ();
if (t == error_mark_node)
return 1;
if (t == void_type_node)
@@ -1258,9 +1236,8 @@ Gcc_backend::type_size (Btype *btype)
// Return the alignment of a type.
int64_t
-Gcc_backend::type_alignment (Btype *btype)
+Gcc_backend::type_alignment (tree t)
{
- tree t = btype->get_tree ();
if (t == error_mark_node)
return 1;
return TYPE_ALIGN_UNIT (t);
@@ -1269,9 +1246,8 @@ Gcc_backend::type_alignment (Btype *btype)
// Return the alignment of a struct field of type BTYPE.
int64_t
-Gcc_backend::type_field_alignment (Btype *btype)
+Gcc_backend::type_field_alignment (tree t)
{
- tree t = btype->get_tree ();
if (t == error_mark_node)
return 1;
return rust_field_alignment (t);
@@ -1280,9 +1256,8 @@ Gcc_backend::type_field_alignment (Btype *btype)
// Return the offset of a field in a struct.
int64_t
-Gcc_backend::type_field_offset (Btype *btype, size_t index)
+Gcc_backend::type_field_offset (tree struct_tree, size_t index)
{
- tree struct_tree = btype->get_tree ();
if (struct_tree == error_mark_node)
return 0;
gcc_assert (TREE_CODE (struct_tree) == RECORD_TYPE);
@@ -1301,9 +1276,8 @@ Gcc_backend::type_field_offset (Btype *btype, size_t index)
// Return the zero value for a type.
Bexpression *
-Gcc_backend::zero_expression (Btype *btype)
+Gcc_backend::zero_expression (tree t)
{
- tree t = btype->get_tree ();
tree ret;
if (t == error_mark_node)
ret = error_mark_node;
@@ -1326,11 +1300,10 @@ Gcc_backend::var_expression (Bvariable *var, Location location)
// An expression that indirectly references an expression.
Bexpression *
-Gcc_backend::indirect_expression (Btype *btype, Bexpression *expr,
+Gcc_backend::indirect_expression (tree type_tree, Bexpression *expr,
bool known_valid, Location location)
{
tree expr_tree = expr->get_tree ();
- tree type_tree = btype->get_tree ();
if (expr_tree == error_mark_node || type_tree == error_mark_node)
return this->error_expression ();
@@ -1351,10 +1324,9 @@ Gcc_backend::indirect_expression (Btype *btype, Bexpression *expr,
// constant value VAL in BTYPE.
Bexpression *
-Gcc_backend::named_constant_expression (Btype *btype, const std::string &name,
+Gcc_backend::named_constant_expression (tree type_tree, const std::string &name,
Bexpression *val, Location location)
{
- tree type_tree = btype->get_tree ();
tree const_val = val->get_tree ();
if (type_tree == error_mark_node || const_val == error_mark_node)
return this->error_expression ();
@@ -1373,9 +1345,8 @@ Gcc_backend::named_constant_expression (Btype *btype, const std::string &name,
// Return a typed value as a constant integer.
Bexpression *
-Gcc_backend::integer_constant_expression (Btype *btype, mpz_t val)
+Gcc_backend::integer_constant_expression (tree t, mpz_t val)
{
- tree t = btype->get_tree ();
if (t == error_mark_node)
return this->error_expression ();
@@ -1386,9 +1357,8 @@ Gcc_backend::integer_constant_expression (Btype *btype, mpz_t val)
// Return a typed value as a constant floating-point number.
Bexpression *
-Gcc_backend::float_constant_expression (Btype *btype, mpfr_t val)
+Gcc_backend::float_constant_expression (tree t, mpfr_t val)
{
- tree t = btype->get_tree ();
tree ret;
if (t == error_mark_node)
return this->error_expression ();
@@ -1404,9 +1374,8 @@ Gcc_backend::float_constant_expression (Btype *btype, mpfr_t val)
// Return a typed real and imaginary value as a constant complex number.
Bexpression *
-Gcc_backend::complex_constant_expression (Btype *btype, mpc_t val)
+Gcc_backend::complex_constant_expression (tree t, mpc_t val)
{
- tree t = btype->get_tree ();
tree ret;
if (t == error_mark_node)
return this->error_expression ();
@@ -1444,14 +1413,14 @@ Gcc_backend::string_constant_expression (const std::string &val)
Bexpression *
Gcc_backend::wchar_constant_expression (wchar_t c)
{
- tree ret = build_int_cst (this->wchar_type ()->get_tree (), c);
+ tree ret = build_int_cst (this->wchar_type (), c);
return this->make_expression (ret);
}
Bexpression *
Gcc_backend::char_constant_expression (char c)
{
- tree ret = build_int_cst (this->char_type ()->get_tree (), c);
+ tree ret = build_int_cst (this->char_type (), c);
return this->make_expression (ret);
}
@@ -1516,17 +1485,16 @@ Gcc_backend::complex_expression (Bexpression *breal, Bexpression *bimag,
// An expression that converts an expression to a different type.
Bexpression *
-Gcc_backend::convert_expression (Btype *type, Bexpression *expr,
+Gcc_backend::convert_expression (tree type_tree, Bexpression *expr,
Location location)
{
- tree type_tree = type->get_tree ();
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 ();
tree ret;
- if (this->type_size (type) == 0 || TREE_TYPE (expr_tree) == void_type_node)
+ if (this->type_size (type_tree) == 0 || TREE_TYPE (expr_tree) == void_type_node)
{
// Do not convert zero-sized types.
ret = expr_tree;
@@ -1628,12 +1596,11 @@ Gcc_backend::compound_expression (Bstatement *bstat, Bexpression *bexpr,
// ELSE_EXPR otherwise.
Bexpression *
-Gcc_backend::conditional_expression (Bfunction *, Btype *btype,
+Gcc_backend::conditional_expression (Bfunction *, tree type_tree,
Bexpression *condition,
Bexpression *then_expr,
Bexpression *else_expr, Location location)
{
- tree type_tree = btype == NULL ? void_type_node : btype->get_tree ();
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 ();
@@ -1876,11 +1843,10 @@ Gcc_backend::lazy_boolean_expression (LazyBooleanOperator op, Bexpression *left,
// Return an expression that constructs BTYPE with VALS.
Bexpression *
-Gcc_backend::constructor_expression (Btype *btype,
+Gcc_backend::constructor_expression (tree type_tree,
const std::vector<Bexpression *> &vals,
int union_index, Location location)
{
- tree type_tree = btype->get_tree ();
if (type_tree == error_mark_node)
return this->error_expression ();
@@ -1965,10 +1931,9 @@ Gcc_backend::constructor_expression (Btype *btype,
Bexpression *
Gcc_backend::array_constructor_expression (
- Btype *array_btype, const std::vector<unsigned long> &indexes,
+ tree type_tree, const std::vector<unsigned long> &indexes,
const std::vector<Bexpression *> &vals, Location location)
{
- tree type_tree = array_btype->get_tree ();
if (type_tree == error_mark_node)
return this->error_expression ();
@@ -2674,11 +2639,10 @@ Gcc_backend::convert_tree (tree type_tree, tree expr_tree, Location location)
Bvariable *
Gcc_backend::global_variable (const std::string &var_name,
- const std::string &asm_name, Btype *btype,
+ const std::string &asm_name, tree type_tree,
bool is_external, bool is_hidden,
bool in_unique_section, Location location)
{
- tree type_tree = btype->get_tree ();
if (type_tree == error_mark_node)
return this->error_variable ();
@@ -2742,10 +2706,9 @@ Gcc_backend::global_variable_set_init (Bvariable *var, Bexpression *expr)
Bvariable *
Gcc_backend::local_variable (Bfunction *function, const std::string &name,
- Btype *btype, Bvariable *decl_var,
+ tree type_tree, Bvariable *decl_var,
bool is_address_taken, Location location)
{
- tree type_tree = btype->get_tree ();
if (type_tree == error_mark_node)
return this->error_variable ();
tree decl = build_decl (location.gcc_location (), VAR_DECL,
@@ -2767,10 +2730,9 @@ Gcc_backend::local_variable (Bfunction *function, const std::string &name,
Bvariable *
Gcc_backend::parameter_variable (Bfunction *function, const std::string &name,
- Btype *btype, bool is_address_taken,
+ tree type_tree, bool is_address_taken,
Location location)
{
- tree type_tree = btype->get_tree ();
if (type_tree == error_mark_node)
return this->error_variable ();
tree decl = build_decl (location.gcc_location (), PARM_DECL,
@@ -2788,10 +2750,9 @@ Gcc_backend::parameter_variable (Bfunction *function, const std::string &name,
Bvariable *
Gcc_backend::static_chain_variable (Bfunction *function,
- const std::string &name, Btype *btype,
+ const std::string &name, tree type_tree,
Location location)
{
- tree type_tree = btype->get_tree ();
if (type_tree == error_mark_node)
return this->error_variable ();
tree decl = build_decl (location.gcc_location (), PARM_DECL,
@@ -2823,13 +2784,12 @@ Gcc_backend::static_chain_variable (Bfunction *function,
Bvariable *
Gcc_backend::temporary_variable (Bfunction *function, Bblock *bblock,
- Btype *btype, Bexpression *binit,
+ tree type_tree, Bexpression *binit,
bool is_address_taken, Location location,
Bstatement **pstatement)
{
gcc_assert (function != NULL);
tree decl = function->get_tree ();
- tree type_tree = btype->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)
@@ -2870,7 +2830,7 @@ Gcc_backend::temporary_variable (Bfunction *function, Bblock *bblock,
BIND_EXPR_VARS (bind_tree) = BLOCK_VARS (block_tree);
}
- if (this->type_size (btype) != 0 && init_tree != NULL_TREE
+ if (this->type_size (type_tree) != 0 && init_tree != NULL_TREE
&& TREE_TYPE (init_tree) != void_type_node)
DECL_INITIAL (var) = this->convert_tree (type_tree, init_tree, location);
@@ -2883,7 +2843,7 @@ Gcc_backend::temporary_variable (Bfunction *function, Bblock *bblock,
// For a zero sized type, don't initialize VAR with BINIT, but still
// evaluate BINIT for its side effects.
if (init_tree != NULL_TREE
- && (this->type_size (btype) == 0
+ && (this->type_size (type_tree) == 0
|| TREE_TYPE (init_tree) == void_type_node))
*pstatement
= this->compound_statement (this->expression_statement (function, binit),
@@ -2897,11 +2857,10 @@ Gcc_backend::temporary_variable (Bfunction *function, Bblock *bblock,
Bvariable *
Gcc_backend::implicit_variable (const std::string &name,
- const std::string &asm_name, Btype *type,
+ const std::string &asm_name, tree type_tree,
bool is_hidden, bool is_constant,
bool is_common, int64_t alignment)
{
- tree type_tree = type->get_tree ();
if (type_tree == error_mark_node)
return this->error_variable ();
@@ -2952,7 +2911,7 @@ Gcc_backend::implicit_variable (const std::string &name,
void
Gcc_backend::implicit_variable_set_init (Bvariable *var, const std::string &,
- Btype *, bool, bool, bool is_common,
+ tree, bool, bool, bool is_common,
Bexpression *init)
{
tree decl = var->get_decl ();
@@ -2984,9 +2943,8 @@ Gcc_backend::implicit_variable_set_init (Bvariable *var, const std::string &,
Bvariable *
Gcc_backend::implicit_variable_reference (const std::string &name,
const std::string &asm_name,
- Btype *btype)
+ tree type_tree)
{
- tree type_tree = btype->get_tree ();
if (type_tree == error_mark_node)
return this->error_variable ();
@@ -3007,9 +2965,9 @@ Gcc_backend::implicit_variable_reference (const std::string &name,
Bvariable *
Gcc_backend::immutable_struct (const std::string &name,
const std::string &asm_name, bool is_hidden,
- bool is_common, Btype *btype, Location location)
+ bool is_common, tree type_tree,
+ Location location)
{
- tree type_tree = btype->get_tree ();
if (type_tree == error_mark_node)
return this->error_variable ();
gcc_assert (TREE_CODE (type_tree) == RECORD_TYPE);
@@ -3053,7 +3011,7 @@ Gcc_backend::immutable_struct (const std::string &name,
void
Gcc_backend::immutable_struct_set_init (Bvariable *var, const std::string &,
- bool, bool is_common, Btype *, Location,
+ bool, bool is_common, tree, Location,
Bexpression *initializer)
{
tree decl = var->get_decl ();
@@ -3084,9 +3042,8 @@ Gcc_backend::immutable_struct_set_init (Bvariable *var, const std::string &,
Bvariable *
Gcc_backend::immutable_struct_reference (const std::string &name,
const std::string &asm_name,
- Btype *btype, Location location)
+ tree type_tree, Location location)
{
- tree type_tree = btype->get_tree ();
if (type_tree == error_mark_node)
return this->error_variable ();
gcc_assert (TREE_CODE (type_tree) == RECORD_TYPE);
@@ -3173,11 +3130,10 @@ Gcc_backend::label_address (Blabel *label, Location location)
// Declare or define a new function.
Bfunction *
-Gcc_backend::function (Btype *fntype, const std::string &name,
+Gcc_backend::function (tree functype, const std::string &name,
const std::string &asm_name, unsigned int flags,
Location location)
{
- tree functype = fntype->get_tree ();
if (functype != error_mark_node)
{
gcc_assert (FUNCTION_POINTER_TYPE_P (functype));
@@ -3330,7 +3286,7 @@ Gcc_backend::lookup_builtin_by_rust_name (const std::string &name)
void
Gcc_backend::write_global_definitions (
- const std::vector<Btype *> &type_decls,
+ const std::vector<tree> &type_decls,
const std::vector<Bexpression *> &constant_decls,
const std::vector<Bfunction *> &function_decls,
const std::vector<Bvariable *> &variable_decls)
@@ -3354,10 +3310,10 @@ Gcc_backend::write_global_definitions (
}
}
- for (std::vector<Btype *>::const_iterator p = type_decls.begin ();
+ for (std::vector<tree>::const_iterator p = type_decls.begin ();
p != type_decls.end (); ++p)
{
- tree type_tree = (*p)->get_tree ();
+ tree type_tree = (*p);
if (type_tree != error_mark_node && IS_TYPE_OR_DECL_P (type_tree))
{
defs[i] = TYPE_NAME (type_tree);
diff --git a/gcc/rust/typecheck/rust-hir-const-fold.cc b/gcc/rust/typecheck/rust-hir-const-fold.cc
index a2dd03f..d68879c 100644
--- a/gcc/rust/typecheck/rust-hir-const-fold.cc
+++ b/gcc/rust/typecheck/rust-hir-const-fold.cc
@@ -85,7 +85,7 @@ ConstFoldArrayElems::visit (HIR::ArrayElemsValues &elems)
return;
}
- Btype *btype = ConstFoldType::fold (tyty, ctx->get_backend ());
+ tree type = ConstFoldType::fold (tyty, ctx->get_backend ());
for (auto &value : elems.get_values ())
{
@@ -94,7 +94,7 @@ ConstFoldArrayElems::visit (HIR::ArrayElemsValues &elems)
}
folded
- = ctx->get_backend ()->array_constructor_expression (btype, indices, values,
+ = ctx->get_backend ()->array_constructor_expression (type, indices, values,
expr.get_locus ());
}
@@ -112,7 +112,7 @@ ConstFoldArrayElems::visit (HIR::ArrayElemsCopied &elems)
return;
}
- Btype *btype = ConstFoldType::fold (tyty, ctx->get_backend ());
+ tree type = ConstFoldType::fold (tyty, ctx->get_backend ());
Bexpression *elem = ConstFoldExpr::fold (elems.get_elem_to_copy ());
// num copies expr was already folded in rust-hir-type-check-expr; lookup the
@@ -132,7 +132,7 @@ ConstFoldArrayElems::visit (HIR::ArrayElemsCopied &elems)
}
folded
- = ctx->get_backend ()->array_constructor_expression (btype, indices, values,
+ = ctx->get_backend ()->array_constructor_expression (type, indices, values,
expr.get_locus ());
}
diff --git a/gcc/rust/typecheck/rust-hir-const-fold.h b/gcc/rust/typecheck/rust-hir-const-fold.h
index b3a53eb..a45a7f2 100644
--- a/gcc/rust/typecheck/rust-hir-const-fold.h
+++ b/gcc/rust/typecheck/rust-hir-const-fold.h
@@ -28,7 +28,7 @@ namespace ConstFold {
class ConstFoldType : public TyTy::TyVisitor
{
public:
- static Btype *fold (TyTy::BaseType *type, ::Backend *backend)
+ static tree fold (TyTy::BaseType *type, ::Backend *backend)
{
ConstFoldType folder (backend);
type->accept_vis (folder);
@@ -43,13 +43,13 @@ public:
void visit (TyTy::ArrayType &type) override
{
- Btype *element_ty = ConstFoldType::fold (type.get_element_type (), backend);
+ tree element_ty = ConstFoldType::fold (type.get_element_type (), backend);
translated = backend->array_type (element_ty, type.get_capacity ());
}
void visit (TyTy::ReferenceType &type) override
{
- Btype *base_compiled_type = ConstFoldType::fold (type.get_base (), backend);
+ tree base_compiled_type = ConstFoldType::fold (type.get_base (), backend);
if (type.is_mutable ())
{
translated = backend->reference_type (base_compiled_type);
@@ -63,7 +63,7 @@ public:
void visit (TyTy::PointerType &type) override
{
- Btype *base_compiled_type = ConstFoldType::fold (type.get_base (), backend);
+ tree base_compiled_type = ConstFoldType::fold (type.get_base (), backend);
if (type.is_mutable ())
{
translated = backend->pointer_type (base_compiled_type);
@@ -212,7 +212,7 @@ public:
void visit (TyTy::StrType &) override
{
- Btype *raw_str = backend->raw_str_type ();
+ tree raw_str = backend->raw_str_type ();
translated
= backend->named_type ("str", raw_str, Linemap::predeclared_location ());
}
@@ -229,7 +229,7 @@ private:
{}
::Backend *backend;
- ::Btype *translated;
+ ::tree translated;
};
class ConstFoldItem : public ConstFoldBase
@@ -369,7 +369,7 @@ public:
return;
}
- Btype *type = ConstFoldType::fold (tyty, ctx->get_backend ());
+ tree type = ConstFoldType::fold (tyty, ctx->get_backend ());
folded
= ctx->get_backend ()->integer_constant_expression (type, ival);
}
@@ -400,7 +400,7 @@ public:
return;
}
- Btype *type = ConstFoldType::fold (tyty, ctx->get_backend ());
+ tree type = ConstFoldType::fold (tyty, ctx->get_backend ());
folded = ctx->get_backend ()->float_constant_expression (type, fval);
}
return;
@@ -480,7 +480,7 @@ public:
return;
}
- Btype *expected_type = ConstFoldType::fold (tyty, ctx->get_backend ());
+ tree expected_type = ConstFoldType::fold (tyty, ctx->get_backend ());
bool known_valid = true;
folded = ctx->get_backend ()->indirect_expression (expected_type, main_expr,
known_valid,