Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,12 @@ class Item : public Stmt
ExternBlock,
};

// Returns whether the item is generated by a derive attribute.
bool is_derived () const { return derived; }

// Sets the item as derived.
void set_derived () { derived = true; }

virtual Kind get_item_kind () const = 0;

// Unique pointer custom clone function
Expand Down Expand Up @@ -1212,6 +1218,9 @@ class Item : public Stmt
* statement clone return item clone. Hopefully won't affect performance too
* much. */
Item *clone_stmt_impl () const final override { return clone_item_impl (); }

private:
bool derived = false;
};

// Item that supports visibility - abstract base class
Expand Down
3 changes: 2 additions & 1 deletion gcc/rust/hir/rust-ast-lower-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,8 @@ ASTLoweringBase::lower_extern_block (AST::ExternBlock &extern_block)
= new HIR::ExternBlock (mapping, abi, std::move (extern_items),
std::move (vis), extern_block.get_inner_attrs (),
extern_block.get_outer_attrs (),
extern_block.get_locus ());
extern_block.get_locus (),
extern_block.is_derived ());

mappings.insert_hir_extern_block (hir_extern_block);

Expand Down
9 changes: 5 additions & 4 deletions gcc/rust/hir/rust-ast-lower-enumitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class ASTLoweringEnumItem : public ASTLoweringBase
"visibility qualifier %qs not allowed on enum item",
item.get_visibility ().as_string ().c_str ());
translated = new HIR::EnumItem (mapping, item.get_identifier (),
item.get_outer_attrs (), item.get_locus ());
item.get_outer_attrs (), item.get_locus (),
item.is_derived ());
}

void visit (AST::EnumItemTuple &item) override
Expand Down Expand Up @@ -100,7 +101,7 @@ class ASTLoweringEnumItem : public ASTLoweringBase
translated
= new HIR::EnumItemTuple (mapping, item.get_identifier (),
std::move (fields), item.get_outer_attrs (),
item.get_locus ());
item.get_locus (), item.is_derived ());
}

void visit (AST::EnumItemStruct &item) override
Expand Down Expand Up @@ -141,7 +142,7 @@ class ASTLoweringEnumItem : public ASTLoweringBase
translated
= new HIR::EnumItemStruct (mapping, item.get_identifier (),
std::move (fields), item.get_outer_attrs (),
item.get_locus ());
item.get_locus (), item.is_derived ());
}

void visit (AST::EnumItemDiscriminant &item) override
Expand All @@ -161,7 +162,7 @@ class ASTLoweringEnumItem : public ASTLoweringBase
= new HIR::EnumItemDiscriminant (mapping, item.get_identifier (),
std::unique_ptr<HIR::Expr> (expr),
item.get_outer_attrs (),
item.get_locus ());
item.get_locus (), item.is_derived ());
}

private:
Expand Down
9 changes: 5 additions & 4 deletions gcc/rust/hir/rust-ast-lower-implitem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ASTLowerImplItem::visit (AST::TypeAlias &alias)
std::move (generic_params), std::move (where_clause),
std::unique_ptr<HIR::Type> (existing_type),
std::move (vis), alias.get_outer_attrs (),
alias.get_locus ());
alias.get_locus (), alias.is_derived ());

translated = type_alias;
item_cast = type_alias;
Expand All @@ -99,8 +99,8 @@ ASTLowerImplItem::visit (AST::ConstantItem &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 ());
constant.get_outer_attrs (), constant.get_locus (),
constant.is_derived ());

translated = translated_constant;
item_cast = translated_constant;
Expand Down Expand Up @@ -188,7 +188,8 @@ ASTLowerImplItem::visit (AST::Function &function)
std::move (function_params), std::move (return_type),
std::move (where_clause), std::move (function_body),
std::move (vis), function.get_outer_attrs (),
std::move (self_param), defaultness, locus);
std::move (self_param), defaultness, locus,
function.is_derived ());

if (fn->is_method ())
{
Expand Down
34 changes: 20 additions & 14 deletions gcc/rust/hir/rust-ast-lower-item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ASTLoweringItem::visit (AST::Module &module)

translated
= new HIR::Module (mapping, module.get_name (), module.get_locus (),
std::move (items), std::move (vis),
std::move (items), module.is_derived (), std::move (vis),
std::move (inner_attrs), std::move (outer_attrs));
mappings.insert_module (static_cast<Module *> (translated));
}
Expand Down Expand Up @@ -117,7 +117,7 @@ ASTLoweringItem::visit (AST::TypeAlias &alias)
std::move (generic_params), std::move (where_clause),
std::unique_ptr<HIR::Type> (existing_type),
std::move (vis), alias.get_outer_attrs (),
alias.get_locus ());
alias.get_locus (), alias.is_derived ());
}

void
Expand Down Expand Up @@ -172,7 +172,8 @@ ASTLoweringItem::visit (AST::TupleStruct &struct_decl)
std::move (generic_params),
std::move (where_clause), vis,
struct_decl.get_outer_attrs (),
struct_decl.get_locus ());
struct_decl.get_locus (),
struct_decl.is_derived ());
}

void
Expand Down Expand Up @@ -232,7 +233,8 @@ ASTLoweringItem::visit (AST::StructStruct &struct_decl)
std::move (generic_params),
std::move (where_clause), is_unit, vis,
struct_decl.get_outer_attrs (),
struct_decl.get_locus ());
struct_decl.get_locus (),
struct_decl.is_derived ());
}

void
Expand Down Expand Up @@ -275,7 +277,7 @@ ASTLoweringItem::visit (AST::Enum &enum_decl)
= new HIR::Enum (mapping, enum_decl.get_identifier (), vis,
std::move (generic_params), std::move (where_clause),
std::move (items), enum_decl.get_outer_attrs (),
enum_decl.get_locus ());
enum_decl.get_locus (), enum_decl.is_derived ());
translated = hir_enum;
for (auto &variant : hir_enum->get_variants ())
{
Expand Down Expand Up @@ -337,7 +339,7 @@ ASTLoweringItem::visit (AST::Union &union_decl)
= new HIR::Union (mapping, union_decl.get_identifier (), vis,
std::move (generic_params), std::move (where_clause),
std::move (variants), union_decl.get_outer_attrs (),
union_decl.get_locus ());
union_decl.get_locus (), union_decl.is_derived ());
}

void
Expand All @@ -358,7 +360,8 @@ ASTLoweringItem::visit (AST::StaticItem &var)
: Mutability::Imm,
std::unique_ptr<HIR::Type> (type),
std::unique_ptr<HIR::Expr> (expr), vis,
var.get_outer_attrs (), var.get_locus ());
var.get_outer_attrs (), var.get_locus (),
var.is_derived ());
}

void
Expand All @@ -376,11 +379,12 @@ ASTLoweringItem::visit (AST::ConstantItem &constant)
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 ());
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 (),
constant.is_derived ());
}

void
Expand Down Expand Up @@ -463,7 +467,8 @@ ASTLoweringItem::visit (AST::Function &function)
std::move (function_params), std::move (return_type),
std::move (where_clause), std::move (function_body),
std::move (vis), function.get_outer_attrs (),
tl::nullopt, defaultness, locus);
tl::nullopt, defaultness, locus,
function.is_derived ());

// add the mappings for the function params at the end
for (auto &param : fn->get_function_params ())
Expand Down Expand Up @@ -620,7 +625,8 @@ ASTLoweringItem::visit (AST::Trait &trait)
= new HIR::Trait (mapping, trait.get_identifier (), trait_unsafety,
std::move (generic_params), std::move (type_param_bounds),
where_clause, std::move (trait_items), vis,
trait.get_outer_attrs (), trait.get_locus ());
trait.get_outer_attrs (), trait.get_locus (),
trait.is_derived ());

if (trait.is_auto ())
mappings.insert_auto_trait (hir_trait);
Expand Down
79 changes: 48 additions & 31 deletions gcc/rust/hir/tree/rust-hir-item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ VisItem::VisItem (VisItem const &other)

Module::Module (Analysis::NodeMapping mappings, Identifier module_name,
location_t locus, std::vector<std::unique_ptr<Item>> items,
Visibility visibility, AST::AttrVec inner_attrs,
AST::AttrVec outer_attrs)
: VisItem (std::move (mappings), std::move (visibility),
bool is_derived, Visibility visibility,
AST::AttrVec inner_attrs, AST::AttrVec outer_attrs)
: VisItem (std::move (mappings), is_derived, std::move (visibility),
std::move (outer_attrs)),
WithInnerAttrs (std::move (inner_attrs)), module_name (module_name),
locus (locus), items (std::move (items))
Expand Down Expand Up @@ -268,8 +268,9 @@ Function::Function (Analysis::NodeMapping mappings, Identifier function_name,
std::unique_ptr<Type> return_type, WhereClause where_clause,
std::unique_ptr<BlockExpr> function_body, Visibility vis,
AST::AttrVec outer_attrs, tl::optional<SelfParam> self,
Defaultness defaultness, location_t locus)
: VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
Defaultness defaultness, location_t locus, bool is_derived)
: VisItem (std::move (mappings), is_derived, std::move (vis),
std::move (outer_attrs)),
qualifiers (std::move (qualifiers)),
function_name (std::move (function_name)),
generic_params (std::move (generic_params)),
Expand Down Expand Up @@ -330,8 +331,10 @@ TypeAlias::TypeAlias (Analysis::NodeMapping mappings, Identifier new_type_name,
std::vector<std::unique_ptr<GenericParam>> generic_params,
WhereClause where_clause,
std::unique_ptr<Type> existing_type, Visibility vis,
AST::AttrVec outer_attrs, location_t locus)
: VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
AST::AttrVec outer_attrs, location_t locus,
bool is_derived)
: VisItem (std::move (mappings), is_derived, std::move (vis),
std::move (outer_attrs)),
new_type_name (std::move (new_type_name)),
generic_params (std::move (generic_params)),
where_clause (std::move (where_clause)),
Expand Down Expand Up @@ -420,44 +423,46 @@ TupleStruct::TupleStruct (
Identifier struct_name,
std::vector<std::unique_ptr<GenericParam>> generic_params,
WhereClause where_clause, Visibility vis, AST::AttrVec outer_attrs,
location_t locus)
location_t locus, bool is_derived)
: Struct (std::move (mappings), std::move (struct_name),
std::move (generic_params), std::move (where_clause),
std::move (vis), locus, std::move (outer_attrs)),
std::move (vis), locus, is_derived, std::move (outer_attrs)),
fields (std::move (fields))
{}

EnumItem::EnumItem (Analysis::NodeMapping mappings, Identifier variant_name,
AST::AttrVec outer_attrs, location_t locus)
: Item (std::move (mappings), std::move (outer_attrs)),
AST::AttrVec outer_attrs, location_t locus, bool is_derived)
: Item (std::move (mappings), is_derived, std::move (outer_attrs)),
variant_name (std::move (variant_name)), locus (locus)
{}

EnumItemTuple::EnumItemTuple (Analysis::NodeMapping mappings,
Identifier variant_name,
std::vector<TupleField> tuple_fields,
AST::AttrVec outer_attrs, location_t locus)
AST::AttrVec outer_attrs, location_t locus,
bool is_derived)
: EnumItem (std::move (mappings), std::move (variant_name),
std::move (outer_attrs), locus),
std::move (outer_attrs), locus, is_derived),
tuple_fields (std::move (tuple_fields))
{}

EnumItemStruct::EnumItemStruct (Analysis::NodeMapping mappings,
Identifier variant_name,
std::vector<StructField> struct_fields,
AST::AttrVec outer_attrs, location_t locus)
AST::AttrVec outer_attrs, location_t locus,
bool is_derived)
: EnumItem (std::move (mappings), std::move (variant_name),
std::move (outer_attrs), locus),
std::move (outer_attrs), locus, is_derived),
struct_fields (std::move (struct_fields))
{}

EnumItemDiscriminant::EnumItemDiscriminant (Analysis::NodeMapping mappings,
Identifier variant_name,
std::unique_ptr<Expr> expr,
AST::AttrVec outer_attrs,
location_t locus)
location_t locus, bool is_derived)
: EnumItem (std::move (mappings), std::move (variant_name),
std::move (outer_attrs), locus),
std::move (outer_attrs), locus, is_derived),
expression (std::move (expr))
{}

Expand All @@ -481,8 +486,9 @@ Enum::Enum (Analysis::NodeMapping mappings, Identifier enum_name,
std::vector<std::unique_ptr<GenericParam>> generic_params,
WhereClause where_clause,
std::vector<std::unique_ptr<EnumItem>> items,
AST::AttrVec outer_attrs, location_t locus)
: VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
AST::AttrVec outer_attrs, location_t locus, bool is_derived)
: VisItem (std::move (mappings), is_derived, std::move (vis),
std::move (outer_attrs)),
enum_name (std::move (enum_name)),
generic_params (std::move (generic_params)),
where_clause (std::move (where_clause)), items (std::move (items)),
Expand Down Expand Up @@ -525,8 +531,9 @@ Union::Union (Analysis::NodeMapping mappings, Identifier union_name,
Visibility vis,
std::vector<std::unique_ptr<GenericParam>> generic_params,
WhereClause where_clause, std::vector<StructField> variants,
AST::AttrVec outer_attrs, location_t locus)
: VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
AST::AttrVec outer_attrs, location_t locus, bool is_derived)
: VisItem (std::move (mappings), is_derived, std::move (vis),
std::move (outer_attrs)),
union_name (std::move (union_name)),
generic_params (std::move (generic_params)),
where_clause (std::move (where_clause)), variants (std::move (variants)),
Expand Down Expand Up @@ -562,8 +569,10 @@ Union::operator= (Union const &other)
ConstantItem::ConstantItem (Analysis::NodeMapping mappings, Identifier ident,
Visibility vis, std::unique_ptr<Type> type,
std::unique_ptr<Expr> const_expr,
AST::AttrVec outer_attrs, location_t locus)
: VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
AST::AttrVec outer_attrs, location_t locus,
bool is_derived)
: VisItem (std::move (mappings), is_derived, std::move (vis),
std::move (outer_attrs)),
identifier (std::move (ident)), type (std::move (type)),
const_expr (std::move (const_expr)), locus (locus)
{}
Expand All @@ -589,8 +598,10 @@ ConstantItem::operator= (ConstantItem const &other)
StaticItem::StaticItem (Analysis::NodeMapping mappings, Identifier name,
Mutability mut, std::unique_ptr<Type> type,
std::unique_ptr<Expr> expr, Visibility vis,
AST::AttrVec outer_attrs, location_t locus)
: VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
AST::AttrVec outer_attrs, location_t locus,
bool is_derived)
: VisItem (std::move (mappings), is_derived, std::move (vis),
std::move (outer_attrs)),
mut (mut), name (std::move (name)), type (std::move (type)),
expr (std::move (expr)), locus (locus)
{}
Expand Down Expand Up @@ -754,8 +765,10 @@ Trait::Trait (Analysis::NodeMapping mappings, Identifier name,
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
WhereClause where_clause,
std::vector<std::unique_ptr<TraitItem>> trait_items,
Visibility vis, AST::AttrVec outer_attrs, location_t locus)
: VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
Visibility vis, AST::AttrVec outer_attrs, location_t locus,
bool is_derived)
: VisItem (std::move (mappings), is_derived, std::move (vis),
std::move (outer_attrs)),
unsafety (unsafety), name (std::move (name)),
generic_params (std::move (generic_params)),
type_param_bounds (std::move (type_param_bounds)),
Expand Down Expand Up @@ -811,8 +824,10 @@ ImplBlock::ImplBlock (Analysis::NodeMapping mappings,
std::unique_ptr<TypePath> trait_ref,
WhereClause where_clause, BoundPolarity polarity,
Visibility vis, AST::AttrVec inner_attrs,
AST::AttrVec outer_attrs, location_t locus, bool unsafe)
: VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
AST::AttrVec outer_attrs, location_t locus, bool unsafe,
bool is_derived)
: VisItem (std::move (mappings), is_derived, std::move (vis),
std::move (outer_attrs)),
WithInnerAttrs (std::move (inner_attrs)),
generic_params (std::move (generic_params)),
impl_type (std::move (impl_type)), trait_ref (std::move (trait_ref)),
Expand Down Expand Up @@ -993,8 +1008,10 @@ ExternalTypeItem::ExternalTypeItem (ExternalTypeItem const &other)
ExternBlock::ExternBlock (
Analysis::NodeMapping mappings, ABI abi,
std::vector<std::unique_ptr<ExternalItem>> extern_items, Visibility vis,
AST::AttrVec inner_attrs, AST::AttrVec outer_attrs, location_t locus)
: VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
AST::AttrVec inner_attrs, AST::AttrVec outer_attrs, location_t locus,
bool is_derived)
: VisItem (std::move (mappings), is_derived, std::move (vis),
std::move (outer_attrs)),
WithInnerAttrs (std::move (inner_attrs)), abi (abi),
extern_items (std::move (extern_items)), locus (locus)
{}
Expand Down
Loading
Loading