aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-09-15 18:11:15 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-09-15 18:14:02 +0100
commitb3d5577b59cc3a6e216f9a0cb9517a4639f930ae (patch)
treee909674ca5dac049fede09a6bf003727a04906ce /gcc
parent57ebfd300bd6440880768e25edf876c158b78d4f (diff)
downloadgcc-b3d5577b59cc3a6e216f9a0cb9517a4639f930ae.zip
gcc-b3d5577b59cc3a6e216f9a0cb9517a4639f930ae.tar.gz
gcc-b3d5577b59cc3a6e216f9a0cb9517a4639f930ae.tar.bz2
Add HIR Lowering for TraitObjectTypeOneBound
This uses a little bit of a hack to get a plain old object for the TraitBound but we need to create an issue to refactor and remove the clone support for these types to be able to cleanup this work to use a simple std::unique_ptr. Addresses #197
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-type.h2
-rw-r--r--gcc/rust/hir/rust-ast-lower-type.h2
-rw-r--r--gcc/rust/hir/rust-ast-lower.cc23
-rw-r--r--gcc/rust/hir/tree/rust-hir-type.h17
4 files changed, 32 insertions, 12 deletions
diff --git a/gcc/rust/ast/rust-type.h b/gcc/rust/ast/rust-type.h
index fd69564..fd0fa53 100644
--- a/gcc/rust/ast/rust-type.h
+++ b/gcc/rust/ast/rust-type.h
@@ -367,6 +367,8 @@ public:
// TODO: check to ensure invariants are met?
return trait_bound;
}
+
+ bool is_dyn () const { return has_dyn; }
};
class TypePath; // definition moved to "rust-path.h"
diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h
index 464045a..611c844 100644
--- a/gcc/rust/hir/rust-ast-lower-type.h
+++ b/gcc/rust/hir/rust-ast-lower-type.h
@@ -289,6 +289,8 @@ public:
translated);
}
+ void visit (AST::TraitObjectTypeOneBound &type) override;
+
private:
ASTLoweringType () : ASTLoweringBase (), translated (nullptr) {}
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc
index 5c70b2c..ed0774c 100644
--- a/gcc/rust/hir/rust-ast-lower.cc
+++ b/gcc/rust/hir/rust-ast-lower.cc
@@ -515,6 +515,29 @@ ASTLowerQualifiedPathInType::visit (AST::QualifiedPathInType &path)
mappings->insert_hir_type (crate_num, hirid, translated);
}
+void
+ASTLoweringType::visit (AST::TraitObjectTypeOneBound &type)
+{
+ HIR::TypeParamBound *b
+ = ASTLoweringTypeBounds::translate (&type.get_trait_bound ());
+ rust_assert (b->get_bound_type () == HIR::TypeParamBound::TRAITBOUND);
+ HIR::TraitBound *bb = static_cast<HIR::TraitBound *> (b);
+ HIR::TraitBound bound (*bb);
+ delete bb;
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, type.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (crate_num));
+
+ translated
+ = new HIR::TraitObjectTypeOneBound (mapping, std::move (bound),
+ type.get_locus (), type.is_dyn ());
+
+ mappings->insert_hir_type (mapping.get_crate_num (), mapping.get_hirid (),
+ translated);
+}
+
// rust-ast-lower-base
HIR::Type *
diff --git a/gcc/rust/hir/tree/rust-hir-type.h b/gcc/rust/hir/tree/rust-hir-type.h
index cf33b9d..0428a7a 100644
--- a/gcc/rust/hir/tree/rust-hir-type.h
+++ b/gcc/rust/hir/tree/rust-hir-type.h
@@ -310,7 +310,6 @@ class TraitObjectTypeOneBound : public TypeNoBounds
{
bool has_dyn;
TraitBound trait_bound;
-
Location locus;
protected:
@@ -318,37 +317,31 @@ protected:
* than base */
TraitObjectTypeOneBound *clone_type_impl () const override
{
- return new TraitObjectTypeOneBound (*this);
+ return new TraitObjectTypeOneBound (mappings, trait_bound, locus, has_dyn);
}
/* Use covariance to implement clone function as returning this object rather
* than base */
TraitObjectTypeOneBound *clone_type_no_bounds_impl () const override
{
- return new TraitObjectTypeOneBound (*this);
+ return new TraitObjectTypeOneBound (mappings, trait_bound, locus, has_dyn);
}
public:
TraitObjectTypeOneBound (Analysis::NodeMapping mappings,
TraitBound trait_bound, Location locus,
- bool is_dyn_dispatch = false)
+ bool is_dyn_dispatch)
: TypeNoBounds (mappings), has_dyn (is_dyn_dispatch),
trait_bound (std::move (trait_bound)), locus (locus)
{}
std::string as_string () const override;
- // Creates a trait bound (clone of this one's trait bound) - HACK
- TraitBound *to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const override
- {
- /* NOTE: this assumes there is no dynamic dispatch specified- if there was,
- * this cloning would not be required as parsing is unambiguous. */
- return new HIR::TraitBound (trait_bound);
- }
-
Location get_locus () const { return locus; }
void accept_vis (HIRVisitor &vis) override;
+
+ TraitBound &get_trait_bound () { return trait_bound; }
};
class TypePath; // definition moved to "rust-path.h"