aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-06-05 13:42:40 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-06-05 16:40:19 +0100
commit69b3e488803f684d9d956223a7f410d219cced24 (patch)
tree3c68bc966995acfa8f566a35439a0939353386a4 /gcc
parentf1526062d9c16d3224d350967788dec9e4e2bbee (diff)
downloadgcc-69b3e488803f684d9d956223a7f410d219cced24.zip
gcc-69b3e488803f684d9d956223a7f410d219cced24.tar.gz
gcc-69b3e488803f684d9d956223a7f410d219cced24.tar.bz2
Add AST to HIR lowering for traits and trait impls.
This will change to desugar trait-impls to be just like a normal impl block later on. This will simplify things for method resolution. This is the initial building block so we can move forward and refactor as the trait resolution evolves. Addresses #395 #472
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-item.h7
-rw-r--r--gcc/rust/hir/rust-ast-lower-base.h2
-rw-r--r--gcc/rust/hir/rust-ast-lower-implitem.h218
-rw-r--r--gcc/rust/hir/rust-ast-lower-item.h143
-rw-r--r--gcc/rust/hir/rust-ast-lower.cc16
-rw-r--r--gcc/rust/hir/tree/rust-hir-full-test.cc2
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h61
-rw-r--r--gcc/rust/hir/tree/rust-hir.h4
8 files changed, 416 insertions, 37 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index a9da337..f9a5a6d 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -3422,6 +3422,8 @@ public:
Identifier get_identifier () const { return name; }
+ bool is_unsafe () const { return has_unsafe; }
+
// Mega-constructor
Trait (Identifier name, bool is_unsafe,
std::vector<std::unique_ptr<GenericParam> > generic_params,
@@ -3757,8 +3759,6 @@ public:
trait_path (std::move (trait_path)), impl_items (std::move (impl_items))
{}
- // TODO: constructors with less params
-
// Copy constructor with vector clone
TraitImpl (TraitImpl const &other)
: Impl (other), has_unsafe (other.has_unsafe),
@@ -3790,6 +3790,9 @@ public:
void accept_vis (ASTVisitor &vis) override;
+ bool is_unsafe () const { return has_unsafe; };
+ bool is_exclam () const { return has_exclam; }
+
// TODO: think of better way to do this
const std::vector<std::unique_ptr<TraitImplItem> > &get_impl_items () const
{
diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h
index 16143d2..a3baf50 100644
--- a/gcc/rust/hir/rust-ast-lower-base.h
+++ b/gcc/rust/hir/rust-ast-lower-base.h
@@ -293,6 +293,8 @@ protected:
HIR::GenericArgs lower_generic_args (AST::GenericArgs &args);
HIR::GenericArgsBinding lower_binding (AST::GenericArgsBinding &binding);
+
+ HIR::SelfParam lower_self (AST::SelfParam &self);
};
} // namespace HIR
diff --git a/gcc/rust/hir/rust-ast-lower-implitem.h b/gcc/rust/hir/rust-ast-lower-implitem.h
index 7b88408..f830918 100644
--- a/gcc/rust/hir/rust-ast-lower-implitem.h
+++ b/gcc/rust/hir/rust-ast-lower-implitem.h
@@ -43,19 +43,14 @@ public:
return resolver.translated;
}
- HIR::SelfParam lower_self (AST::SelfParam &self)
+ static HIR::TraitImplItem *translate (AST::TraitImplItem *item,
+ HirId parent_impl_id)
{
- HIR::Type *type = self.has_type ()
- ? ASTLoweringType::translate (self.get_type ().get ())
- : nullptr;
-
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, self.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (crate_num));
-
- return HIR::SelfParam (mapping, std::unique_ptr<HIR::Type> (type),
- self.get_is_mut (), self.get_locus ());
+ ASTLowerImplItem resolver (parent_impl_id);
+ item->accept_vis (resolver);
+ rust_assert (resolver.trait_impl_item != nullptr);
+ // can get a way with this for now since they have the same hierarchy
+ return resolver.trait_impl_item;
}
void visit (AST::ConstantItem &constant) override
@@ -70,11 +65,14 @@ public:
mappings->get_next_hir_id (crate_num),
mappings->get_next_localdef_id (crate_num));
- translated = new HIR::ConstantItem (mapping, constant.get_identifier (),
- vis, std::unique_ptr<HIR::Type> (type),
- std::unique_ptr<HIR::Expr> (expr),
- constant.get_outer_attrs (),
- constant.get_locus ());
+ auto translated_constant
+ = new HIR::ConstantItem (mapping, constant.get_identifier (), vis,
+ std::unique_ptr<HIR::Type> (type),
+ std::unique_ptr<HIR::Expr> (expr),
+ constant.get_outer_attrs (),
+ constant.get_locus ());
+ translated = translated_constant;
+ trait_impl_item = translated_constant;
mappings->insert_hir_implitem (mapping.get_crate_num (),
mapping.get_hirid (), parent_impl_id,
@@ -163,6 +161,7 @@ public:
}
translated = fn;
+ trait_impl_item = fn;
}
void visit (AST::Method &method) override
@@ -251,17 +250,200 @@ public:
}
translated = mth;
+ trait_impl_item = mth;
}
private:
ASTLowerImplItem (HirId parent_impl_id)
- : translated (nullptr), parent_impl_id (parent_impl_id)
+ : translated (nullptr), trait_impl_item (nullptr),
+ parent_impl_id (parent_impl_id)
{}
HIR::InherentImplItem *translated;
+ HIR::TraitImplItem *trait_impl_item;
HirId parent_impl_id;
};
+class ASTLowerTraitItem : public ASTLoweringBase
+{
+ using Rust::HIR::ASTLoweringBase::visit;
+
+public:
+ static HIR::TraitItem *translate (AST::TraitItem *item)
+ {
+ ASTLowerTraitItem resolver;
+ item->accept_vis (resolver);
+ rust_assert (resolver.translated != nullptr);
+ return resolver.translated;
+ }
+
+ void visit (AST::TraitItemFunc &func) override
+ {
+ AST::TraitFunctionDecl &ref = func.get_trait_function_decl ();
+
+ std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
+ HIR::WhereClause where_clause (std::move (where_clause_items));
+ HIR::FunctionQualifiers qualifiers (
+ HIR::FunctionQualifiers::AsyncConstStatus::NONE, false);
+
+ std::vector<std::unique_ptr<HIR::GenericParam> > generic_params;
+ if (ref.has_generics ())
+ {
+ generic_params = lower_generic_params (ref.get_generic_params ());
+ }
+
+ std::unique_ptr<HIR::Type> return_type
+ = ref.has_return_type () ? std::unique_ptr<HIR::Type> (
+ ASTLoweringType::translate (ref.get_return_type ().get ()))
+ : nullptr;
+
+ std::vector<HIR::FunctionParam> function_params;
+ for (auto &param : ref.get_function_params ())
+ {
+ auto translated_pattern = std::unique_ptr<HIR::Pattern> (
+ ASTLoweringPattern::translate (param.get_pattern ().get ()));
+ auto translated_type = std::unique_ptr<HIR::Type> (
+ ASTLoweringType::translate (param.get_type ().get ()));
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, param.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ UNKNOWN_LOCAL_DEFID);
+
+ auto hir_param
+ = HIR::FunctionParam (mapping, std::move (translated_pattern),
+ std::move (translated_type),
+ param.get_locus ());
+ function_params.push_back (hir_param);
+ }
+
+ HIR::TraitFunctionDecl decl (ref.get_identifier (), std::move (qualifiers),
+ std::move (generic_params),
+ std::move (function_params),
+ std::move (return_type),
+ std::move (where_clause));
+ HIR::Expr *block_expr
+ = func.has_definition ()
+ ? ASTLoweringExpr::translate (func.get_definition ().get ())
+ : nullptr;
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, func.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ UNKNOWN_LOCAL_DEFID);
+
+ translated
+ = new HIR::TraitItemFunc (mapping, std::move (decl),
+ std::unique_ptr<HIR::Expr> (block_expr),
+ func.get_outer_attrs (), func.get_locus ());
+ }
+
+ void visit (AST::TraitItemMethod &method) override
+ {
+ AST::TraitMethodDecl &ref = method.get_trait_method_decl ();
+
+ std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
+ HIR::WhereClause where_clause (std::move (where_clause_items));
+ HIR::FunctionQualifiers qualifiers (
+ HIR::FunctionQualifiers::AsyncConstStatus::NONE, false);
+
+ std::vector<std::unique_ptr<HIR::GenericParam> > generic_params;
+ if (ref.has_generics ())
+ {
+ generic_params = lower_generic_params (ref.get_generic_params ());
+ }
+
+ std::unique_ptr<HIR::Type> return_type
+ = ref.has_return_type () ? std::unique_ptr<HIR::Type> (
+ ASTLoweringType::translate (ref.get_return_type ().get ()))
+ : nullptr;
+
+ HIR::SelfParam self_param = lower_self (ref.get_self_param ());
+
+ std::vector<HIR::FunctionParam> function_params;
+ for (auto &param : ref.get_function_params ())
+ {
+ auto translated_pattern = std::unique_ptr<HIR::Pattern> (
+ ASTLoweringPattern::translate (param.get_pattern ().get ()));
+ auto translated_type = std::unique_ptr<HIR::Type> (
+ ASTLoweringType::translate (param.get_type ().get ()));
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, param.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ UNKNOWN_LOCAL_DEFID);
+
+ auto hir_param
+ = HIR::FunctionParam (mapping, std::move (translated_pattern),
+ std::move (translated_type),
+ param.get_locus ());
+ function_params.push_back (hir_param);
+ }
+
+ HIR::TraitMethodDecl decl (ref.get_identifier (), std::move (qualifiers),
+ std::move (generic_params),
+ std::move (self_param),
+ std::move (function_params),
+ std::move (return_type),
+ std::move (where_clause));
+ HIR::Expr *block_expr
+ = method.has_definition ()
+ ? ASTLoweringExpr::translate (method.get_definition ().get ())
+ : nullptr;
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, method.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ UNKNOWN_LOCAL_DEFID);
+
+ translated
+ = new HIR::TraitItemMethod (mapping, std::move (decl),
+ std::unique_ptr<HIR::Expr> (block_expr),
+ method.get_outer_attrs (),
+ method.get_locus ());
+ }
+
+ void visit (AST::TraitItemConst &constant) override
+ {
+ HIR::Type *type = ASTLoweringType::translate (constant.get_type ().get ());
+ HIR::Expr *expr
+ = constant.has_expression ()
+ ? ASTLoweringExpr::translate (constant.get_expr ().get ())
+ : nullptr;
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, constant.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ UNKNOWN_LOCAL_DEFID);
+
+ translated = new HIR::TraitItemConst (mapping, constant.get_identifier (),
+ std::unique_ptr<HIR::Type> (type),
+ std::unique_ptr<HIR::Expr> (expr),
+ constant.get_outer_attrs (),
+ constant.get_locus ());
+ }
+
+ void visit (AST::TraitItemType &type) override
+ {
+ std::vector<std::unique_ptr<HIR::TypeParamBound> > type_param_bounds;
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, type.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ UNKNOWN_LOCAL_DEFID);
+
+ translated
+ = new HIR::TraitItemType (mapping, type.get_identifier (),
+ std::move (type_param_bounds),
+ type.get_outer_attrs (), type.get_locus ());
+ }
+
+private:
+ ASTLowerTraitItem () : translated (nullptr) {}
+
+ HIR::TraitItem *translated;
+};
+
} // namespace HIR
} // namespace Rust
diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h
index 936aebb..206eeff 100644
--- a/gcc/rust/hir/rust-ast-lower-item.h
+++ b/gcc/rust/hir/rust-ast-lower-item.h
@@ -406,6 +406,149 @@ public:
}
}
+ void visit (AST::Trait &trait) override
+ {
+ std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
+
+ HIR::WhereClause where_clause (std::move (where_clause_items));
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+
+ std::vector<std::unique_ptr<HIR::GenericParam> > generic_params;
+ if (trait.has_generics ())
+ {
+ generic_params = lower_generic_params (trait.get_generic_params ());
+
+ for (auto &generic_param : generic_params)
+ {
+ switch (generic_param->get_kind ())
+ {
+ case HIR::GenericParam::GenericKind::TYPE: {
+ const HIR::TypeParam &t
+ = static_cast<const HIR::TypeParam &> (*generic_param);
+
+ if (t.has_type ())
+ {
+ // see https://github.com/rust-lang/rust/issues/36887
+ rust_error_at (
+ t.get_locus (),
+ "defaults for type parameters are not allowed here");
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ std::vector<std::unique_ptr<HIR::TypeParamBound> > type_param_bounds;
+
+ std::vector<std::unique_ptr<HIR::TraitItem> > trait_items;
+ for (auto &item : trait.get_trait_items ())
+ {
+ HIR::TraitItem *lowered = ASTLowerTraitItem::translate (item.get ());
+ trait_items.push_back (std::unique_ptr<HIR::TraitItem> (lowered));
+ }
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, trait.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (crate_num));
+
+ translated = new HIR::Trait (mapping, trait.get_identifier (),
+ trait.is_unsafe (), std::move (generic_params),
+ std::move (type_param_bounds), where_clause,
+ std::move (trait_items), vis,
+ trait.get_outer_attrs (), trait.get_locus ());
+
+ mappings->insert_defid_mapping (mapping.get_defid (), translated);
+ mappings->insert_hir_item (mapping.get_crate_num (), mapping.get_hirid (),
+ translated);
+ mappings->insert_location (crate_num, mapping.get_hirid (),
+ trait.get_locus ());
+ }
+
+ void visit (AST::TraitImpl &impl_block) override
+ {
+ std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
+ HIR::WhereClause where_clause (std::move (where_clause_items));
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+
+ std::vector<std::unique_ptr<HIR::GenericParam> > generic_params;
+ if (impl_block.has_generics ())
+ {
+ generic_params
+ = lower_generic_params (impl_block.get_generic_params ());
+
+ for (auto &generic_param : generic_params)
+ {
+ switch (generic_param->get_kind ())
+ {
+ case HIR::GenericParam::GenericKind::TYPE: {
+ const HIR::TypeParam &t
+ = static_cast<const HIR::TypeParam &> (*generic_param);
+
+ if (t.has_type ())
+ {
+ // see https://github.com/rust-lang/rust/issues/36887
+ rust_error_at (
+ t.get_locus (),
+ "defaults for type parameters are not allowed here");
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ HIR::Type *trait_type
+ = ASTLoweringType::translate (impl_block.get_type ().get ());
+ HIR::Type *trait = nullptr;
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, impl_block.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (crate_num));
+
+ std::vector<std::unique_ptr<HIR::TraitImplItem> > impl_items;
+ std::vector<HirId> impl_item_ids;
+ for (auto &impl_item : impl_block.get_impl_items ())
+ {
+ HIR::TraitImplItem *lowered
+ = ASTLowerImplItem::translate (impl_item.get (),
+ mapping.get_hirid ());
+ impl_items.push_back (std::unique_ptr<HIR::TraitImplItem> (lowered));
+ impl_item_ids.push_back (
+ lowered->get_trait_impl_mappings ().get_hirid ());
+ }
+
+ translated
+ = new HIR::TraitImpl (mapping, std::unique_ptr<HIR::Type> (trait),
+ impl_block.is_unsafe (), impl_block.is_exclam (),
+ std::move (impl_items), std::move (generic_params),
+ std::unique_ptr<HIR::Type> (trait_type),
+ where_clause, vis, impl_block.get_inner_attrs (),
+ impl_block.get_outer_attrs (),
+ impl_block.get_locus ());
+
+ mappings->insert_defid_mapping (mapping.get_defid (), translated);
+ mappings->insert_hir_item (mapping.get_crate_num (), mapping.get_hirid (),
+ translated);
+ mappings->insert_location (crate_num, mapping.get_hirid (),
+ impl_block.get_locus ());
+
+ for (auto &impl_item_id : impl_item_ids)
+ {
+ mappings->insert_impl_item_mapping (impl_item_id,
+ static_cast<HIR::InherentImpl *> (
+ translated));
+ }
+ }
+
private:
ASTLoweringItem () : translated (nullptr) {}
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc
index c8c506c..1abdd3c 100644
--- a/gcc/rust/hir/rust-ast-lower.cc
+++ b/gcc/rust/hir/rust-ast-lower.cc
@@ -347,5 +347,21 @@ ASTLoweringBase::lower_generic_args (AST::GenericArgs &args)
std::move (binding_args), args.get_locus ());
}
+HIR::SelfParam
+ASTLoweringBase::lower_self (AST::SelfParam &self)
+{
+ HIR::Type *type = self.has_type ()
+ ? ASTLoweringType::translate (self.get_type ().get ())
+ : nullptr;
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, self.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (crate_num));
+
+ return HIR::SelfParam (mapping, std::unique_ptr<HIR::Type> (type),
+ self.get_is_mut (), self.get_locus ());
+}
+
} // namespace HIR
} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc
index 8ccd6fa..63eb1bb 100644
--- a/gcc/rust/hir/tree/rust-hir-full-test.cc
+++ b/gcc/rust/hir/tree/rust-hir-full-test.cc
@@ -1170,7 +1170,7 @@ TraitImpl::as_string () const
str += "false";
}
- str += "\n TypePath (to trait): " + trait_path.as_string ();
+ str += "\n TypePath (to trait): " + trait_path->as_string ();
str += "\n Type (struct to impl on): " + trait_type->as_string ();
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index fa097e4..e466a35 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -700,6 +700,11 @@ public:
return get_mappings ();
};
+ Analysis::NodeMapping get_trait_impl_mappings () const override
+ {
+ return get_mappings ();
+ };
+
// Returns whether function has return type - if not, it is void.
bool has_function_return_type () const { return return_type != nullptr; }
@@ -748,6 +753,8 @@ public:
Location get_impl_locus () const final { return get_locus (); }
+ Location get_trait_impl_locus () const final { return get_locus (); }
+
std::unique_ptr<BlockExpr> &get_function_body () { return function_body; }
const std::unique_ptr<BlockExpr> &get_function_body () const
{
@@ -1370,6 +1377,8 @@ public:
Location get_impl_locus () const final { return get_locus (); }
+ Location get_trait_impl_locus () const final { return get_locus (); }
+
void accept_vis (HIRVisitor &vis) override;
Analysis::NodeMapping get_impl_mappings () const override
@@ -1377,6 +1386,11 @@ public:
return get_mappings ();
};
+ Analysis::NodeMapping get_trait_impl_mappings () const override
+ {
+ return get_mappings ();
+ };
+
std::vector<FunctionParam> &get_function_params () { return function_params; }
const std::vector<FunctionParam> &get_function_params () const
{
@@ -1518,6 +1532,8 @@ public:
Location get_locus () const { return locus; }
+ Location get_trait_impl_locus () const final { return get_locus (); }
+
void accept_vis (HIRVisitor &vis) override;
std::vector<std::unique_ptr<GenericParam> > &get_generic_params ()
@@ -1545,6 +1561,11 @@ public:
Identifier get_new_type_name () const { return new_type_name; }
+ Analysis::NodeMapping get_trait_impl_mappings () const override
+ {
+ return get_mappings ();
+ };
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -2271,6 +2292,8 @@ public:
Location get_impl_locus () const final { return get_locus (); }
+ Location get_trait_impl_locus () const final { return get_locus (); }
+
void accept_vis (HIRVisitor &vis) override;
Type *get_type () { return type.get (); }
@@ -2284,6 +2307,11 @@ public:
return get_mappings ();
};
+ Analysis::NodeMapping get_trait_impl_mappings () const override
+ {
+ return get_mappings ();
+ };
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -2478,7 +2506,7 @@ class TraitItemFunc : public TraitItem
{
AST::AttrVec outer_attrs;
TraitFunctionDecl decl;
- std::unique_ptr<BlockExpr> block_expr;
+ std::unique_ptr<Expr> block_expr;
Location locus;
public:
@@ -2486,8 +2514,8 @@ public:
bool has_definition () const { return block_expr != nullptr; }
TraitItemFunc (Analysis::NodeMapping mappings, TraitFunctionDecl decl,
- std::unique_ptr<BlockExpr> block_expr,
- AST::AttrVec outer_attrs, Location locus)
+ std::unique_ptr<Expr> block_expr, AST::AttrVec outer_attrs,
+ Location locus)
: TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
decl (std::move (decl)), block_expr (std::move (block_expr)),
locus (locus)
@@ -2499,7 +2527,7 @@ public:
decl (other.decl), locus (other.locus)
{
if (other.block_expr != nullptr)
- block_expr = other.block_expr->clone_block_expr ();
+ block_expr = other.block_expr->clone_expr ();
}
// Overloaded assignment operator to clone
@@ -2511,7 +2539,7 @@ public:
locus = other.locus;
mappings = other.mappings;
if (other.block_expr != nullptr)
- block_expr = other.block_expr->clone_block_expr ();
+ block_expr = other.block_expr->clone_expr ();
return *this;
}
@@ -2526,7 +2554,7 @@ public:
void accept_vis (HIRVisitor &vis) override;
- BlockExpr *get_block_expr () { return block_expr.get (); }
+ std::unique_ptr<Expr> &get_block_expr () { return block_expr; }
protected:
// Clone function implementation as (not pure) virtual method
@@ -2633,7 +2661,7 @@ class TraitItemMethod : public TraitItem
{
AST::AttrVec outer_attrs;
TraitMethodDecl decl;
- std::unique_ptr<BlockExpr> block_expr;
+ std::unique_ptr<Expr> block_expr;
Location locus;
public:
@@ -2641,8 +2669,8 @@ public:
bool has_definition () const { return block_expr != nullptr; }
TraitItemMethod (Analysis::NodeMapping mappings, TraitMethodDecl decl,
- std::unique_ptr<BlockExpr> block_expr,
- AST::AttrVec outer_attrs, Location locus)
+ std::unique_ptr<Expr> block_expr, AST::AttrVec outer_attrs,
+ Location locus)
: TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
decl (std::move (decl)), block_expr (std::move (block_expr)),
locus (locus)
@@ -2651,7 +2679,7 @@ public:
// Copy constructor with clone
TraitItemMethod (TraitItemMethod const &other)
: TraitItem (other.mappings), outer_attrs (other.outer_attrs),
- decl (other.decl), block_expr (other.block_expr->clone_block_expr ()),
+ decl (other.decl), block_expr (other.block_expr->clone_expr ()),
locus (other.locus)
{}
@@ -2661,7 +2689,7 @@ public:
TraitItem::operator= (other);
outer_attrs = other.outer_attrs;
decl = other.decl;
- block_expr = other.block_expr->clone_block_expr ();
+ block_expr = other.block_expr->clone_expr ();
locus = other.locus;
mappings = other.mappings;
@@ -2678,7 +2706,7 @@ public:
void accept_vis (HIRVisitor &vis) override;
- BlockExpr *get_block_expr () { return block_expr.get (); }
+ std::unique_ptr<Expr> &get_block_expr () { return block_expr; }
protected:
// Clone function implementation as (not pure) virtual method
@@ -3105,7 +3133,7 @@ class TraitImpl : public Impl
{
bool has_unsafe;
bool has_exclam;
- TypePath trait_path;
+ std::unique_ptr<Type> trait_path;
// bool has_impl_items;
std::vector<std::unique_ptr<TraitImplItem> > impl_items;
@@ -3117,7 +3145,7 @@ public:
bool has_impl_items () const { return !impl_items.empty (); }
// Mega-constructor
- TraitImpl (Analysis::NodeMapping mappings, TypePath trait_path,
+ TraitImpl (Analysis::NodeMapping mappings, std::unique_ptr<Type> trait_path,
bool is_unsafe, bool has_exclam,
std::vector<std::unique_ptr<TraitImplItem> > impl_items,
std::vector<std::unique_ptr<GenericParam> > generic_params,
@@ -3136,7 +3164,8 @@ public:
// Copy constructor with vector clone
TraitImpl (TraitImpl const &other)
: Impl (other), has_unsafe (other.has_unsafe),
- has_exclam (other.has_exclam), trait_path (other.trait_path)
+ has_exclam (other.has_exclam),
+ trait_path (other.trait_path->clone_type ())
{
impl_items.reserve (other.impl_items.size ());
for (const auto &e : other.impl_items)
@@ -3147,7 +3176,7 @@ public:
TraitImpl &operator= (TraitImpl const &other)
{
Impl::operator= (other);
- trait_path = other.trait_path;
+ trait_path = other.trait_path->clone_type ();
has_unsafe = other.has_unsafe;
has_exclam = other.has_exclam;
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index 1ac418c..0cc9d08 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -838,6 +838,10 @@ public:
virtual std::string as_string () const = 0;
virtual void accept_vis (HIRVisitor &vis) = 0;
+
+ virtual Analysis::NodeMapping get_trait_impl_mappings () const = 0;
+
+ virtual Location get_trait_impl_locus () const = 0;
};
// A crate HIR object - holds all the data for a single compilation unit