diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-10-20 16:21:37 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-10-22 10:13:06 +0100 |
commit | a1b0df02414eb323dac53dc07702861a9d4b63b6 (patch) | |
tree | 9ab8a073a48489d04d51e1c9ee2c9c2ae0f7fee8 /gcc | |
parent | 5f19fb535c95f2afef30f8eb976907d5f0986041 (diff) | |
download | gcc-a1b0df02414eb323dac53dc07702861a9d4b63b6.zip gcc-a1b0df02414eb323dac53dc07702861a9d4b63b6.tar.gz gcc-a1b0df02414eb323dac53dc07702861a9d4b63b6.tar.bz2 |
Constify BaseType::get_root since this should not change ownership
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/backend/rust-compile-base.h | 8 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-implitem.h | 9 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile.cc | 19 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-dot-operator.h | 9 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 7 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 8 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.h | 2 |
7 files changed, 33 insertions, 29 deletions
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h index 4a81061..d741598 100644 --- a/gcc/rust/backend/rust-compile-base.h +++ b/gcc/rust/backend/rust-compile-base.h @@ -205,14 +205,14 @@ protected: TyTy::BaseType *expected, Location locus); Bexpression *coerce_to_dyn_object (Bexpression *compiled_ref, - TyTy::BaseType *actual, - TyTy::BaseType *expected, - TyTy::DynamicObjectType *ty, + const TyTy::BaseType *actual, + const TyTy::BaseType *expected, + const TyTy::DynamicObjectType *ty, Location locus); Bexpression * compute_address_for_trait_item (const Resolver::TraitItemReference *ref, - TyTy::BaseType *receiver); + const TyTy::BaseType *receiver); }; } // namespace Compile diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h index 1d3ad02..ace5e4c 100644 --- a/gcc/rust/backend/rust-compile-implitem.h +++ b/gcc/rust/backend/rust-compile-implitem.h @@ -34,7 +34,7 @@ class CompileInherentImplItem : public HIRCompileBase using Rust::Compile::HIRCompileBase::visit; public: - static Bexpression *Compile (TyTy::BaseType *self, HIR::ImplItem *item, + static Bexpression *Compile (const TyTy::BaseType *self, HIR::ImplItem *item, Context *ctx, bool compile_fns, TyTy::BaseType *concrete = nullptr, bool is_query_mode = false, @@ -309,14 +309,15 @@ public: } private: - CompileInherentImplItem (TyTy::BaseType *self, Context *ctx, bool compile_fns, - TyTy::BaseType *concrete, Location ref_locus) + CompileInherentImplItem (const TyTy::BaseType *self, Context *ctx, + bool compile_fns, TyTy::BaseType *concrete, + Location ref_locus) : HIRCompileBase (ctx), self (self), compile_fns (compile_fns), concrete (concrete), reference (ctx->get_backend ()->error_expression ()), ref_locus (ref_locus) {} - TyTy::BaseType *self; + const TyTy::BaseType *self; bool compile_fns; TyTy::BaseType *concrete; Bexpression *reference; diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 23a035f..56d3e40 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -234,8 +234,8 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) if (is_dyn_dispatch) { - TyTy::DynamicObjectType *dyn - = static_cast<TyTy::DynamicObjectType *> (receiver->get_root ()); + const TyTy::DynamicObjectType *dyn + = static_cast<const TyTy::DynamicObjectType *> (receiver->get_root ()); size_t offs = 0; const Resolver::TraitItemReference *ref = nullptr; @@ -763,8 +763,8 @@ HIRCompileBase::coercion_site (Bexpression *compiled_ref, if (root_expected_kind == TyTy::TypeKind::DYNAMIC && root_actual_kind != TyTy::TypeKind::DYNAMIC) { - TyTy::DynamicObjectType *dyn - = static_cast<TyTy::DynamicObjectType *> (expected->get_root ()); + const TyTy::DynamicObjectType *dyn + = static_cast<const TyTy::DynamicObjectType *> (expected->get_root ()); return coerce_to_dyn_object (compiled_ref, actual, expected, dyn, locus); } @@ -773,9 +773,9 @@ HIRCompileBase::coercion_site (Bexpression *compiled_ref, Bexpression * HIRCompileBase::coerce_to_dyn_object (Bexpression *compiled_ref, - TyTy::BaseType *actual, - TyTy::BaseType *expected, - TyTy::DynamicObjectType *ty, + const TyTy::BaseType *actual, + const TyTy::BaseType *expected, + const TyTy::DynamicObjectType *ty, Location locus) { Btype *dynamic_object = TyTyResolveCompile::compile (ctx, ty); @@ -814,7 +814,7 @@ HIRCompileBase::coerce_to_dyn_object (Bexpression *compiled_ref, std::vector<Resolver::Adjustment> adjustments; while (e->get_kind () == TyTy::TypeKind::REF) { - auto r = static_cast<TyTy::ReferenceType *> (e); + auto r = static_cast<const TyTy::ReferenceType *> (e); e = r->get_base (); if (r->is_mutable ()) @@ -845,7 +845,8 @@ HIRCompileBase::coerce_to_dyn_object (Bexpression *compiled_ref, Bexpression * HIRCompileBase::compute_address_for_trait_item ( - const Resolver::TraitItemReference *trait_item_ref, TyTy::BaseType *receiver) + const Resolver::TraitItemReference *trait_item_ref, + const TyTy::BaseType *receiver) { TyTy::BaseType *item_type = trait_item_ref->get_tyty (); rust_assert (item_type->get_kind () == TyTy::TypeKind::FNDEF); diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.h b/gcc/rust/typecheck/rust-hir-dot-operator.h index 279e67f..9c0cc43 100644 --- a/gcc/rust/typecheck/rust-hir-dot-operator.h +++ b/gcc/rust/typecheck/rust-hir-dot-operator.h @@ -35,10 +35,10 @@ class MethodResolution { public: static PathProbeCandidate * - Select (std::vector<PathProbeCandidate> &candidates, TyTy::BaseType *receiver, - std::vector<Adjustment> &adjustments) + Select (std::vector<PathProbeCandidate> &candidates, + const TyTy::BaseType *receiver, std::vector<Adjustment> &adjustments) { - TyTy::BaseType *r = receiver; + const TyTy::BaseType *r = receiver; while (true) { PathProbeCandidate *c = nullptr; @@ -80,7 +80,8 @@ public: // FIXME this needs to use deref trait and fall back to unsized to // remove array syntax - TyTy::ReferenceType *rr = static_cast<TyTy::ReferenceType *> (r); + const TyTy::ReferenceType *rr + = static_cast<const TyTy::ReferenceType *> (r); r = rr->get_base (); adjustments.push_back ( Adjustment (Adjustment::AdjustmentType::DEREF_REF, r)); diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index b386763..83fafa6 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -219,7 +219,7 @@ public: // in order to probe of the correct type paths we need the root type, which // strips any references - TyTy::BaseType *root = receiver_tyty->get_root (); + const TyTy::BaseType *root = receiver_tyty->get_root (); // https://doc.rust-lang.org/reference/expressions/method-call-expr.html // method resolution is complex in rust once we start handling generics and @@ -297,7 +297,7 @@ public: if (root->get_kind () == TyTy::TypeKind::ADT) { - TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (root); + const TyTy::ADTType *adt = static_cast<const TyTy::ADTType *> (root); if (adt->has_substitutions () && fn->needs_substitution ()) { // consider the case where we have: @@ -322,7 +322,8 @@ public: auto s = fn->get_self_type ()->get_root (); rust_assert (s->can_eq (adt, false)); rust_assert (s->get_kind () == TyTy::TypeKind::ADT); - TyTy::ADTType *self_adt = static_cast<TyTy::ADTType *> (s); + const TyTy::ADTType *self_adt + = static_cast<const TyTy::ADTType *> (s); // we need to grab the Self substitutions as the inherit type // parameters for this diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 22255d9..969360e 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -114,13 +114,13 @@ BaseType::inherit_bounds ( } } -BaseType * -BaseType::get_root () +const BaseType * +BaseType::get_root () const { - BaseType *root = this; + const BaseType *root = this; while (root->get_kind () == TyTy::REF) { - ReferenceType *r = static_cast<ReferenceType *> (root); + const ReferenceType *r = static_cast<const ReferenceType *> (root); root = r->get_base (); } return root; diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 0e74d49..f726069 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -337,7 +337,7 @@ public: debug_str ().c_str ()); } - BaseType *get_root (); + const BaseType *get_root () const; protected: BaseType (HirId ref, HirId ty_ref, TypeKind kind, |