Skip to content

Commit

Permalink
Remove class AST::InherentImplItem
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* ast/rust-ast-full-decls.h
	(class InherentImplItem): Remove.
	* ast/rust-ast.h
	(class InherentImplItem): Remove.
	(class SingleASTNode):
	Store pointer to AssociatedItem instead of InherentImplItem.

	* ast/rust-ast.cc
	(SingleASTNode::SingleASTNode):
	Use clone_associated_item instead of clone_inherent_impl_item.
	(SingleASTNode::operator=): Likewise.

	* ast/rust-item.h
	(class InherentImpl):
	Use AssociatedItem rather than InherentImplItem.
	(class Function): Likewise.
	(class ConstantItem): Likewise.
	* ast/rust-macro.h
	(class MacroInvocation): Likewise.
	* expand/rust-expand-visitor.cc
	(ExpandVisitor::visit): Likewise.
	* parse/rust-parse-impl.h
	(Parser::parse_impl): Likewise.
	(Parser::parse_inherent_impl_item): Likewise.
	(Parser::parse_inherent_impl_function_or_method): Likewise.
	* parse/rust-parse.h
	(Parser::parse_inherent_impl_item): Likewise.
	(Parser::parse_inherent_impl_function_or_method): Likewise.

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 authored and P-E-P committed Nov 30, 2023
1 parent 0ddb160 commit 51f7bfc
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 38 deletions.
1 change: 0 additions & 1 deletion gcc/rust/ast/rust-ast-full-decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class GenericParam;
class LifetimeParam;
class ConstGenericParam;
class TraitItem;
class InherentImplItem;
class TraitImplItem;
struct Crate;
class PathExpr;
Expand Down
4 changes: 2 additions & 2 deletions gcc/rust/ast/rust-ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ SingleASTNode::SingleASTNode (SingleASTNode const &other)
break;

case IMPL:
impl_item = other.impl_item->clone_inherent_impl_item ();
impl_item = other.impl_item->clone_associated_item ();
break;

case TRAIT_IMPL:
Expand Down Expand Up @@ -104,7 +104,7 @@ SingleASTNode::operator= (SingleASTNode const &other)
break;

case IMPL:
impl_item = other.impl_item->clone_inherent_impl_item ();
impl_item = other.impl_item->clone_associated_item ();
break;

case TRAIT_IMPL:
Expand Down
22 changes: 3 additions & 19 deletions gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1687,22 +1687,6 @@ class TraitItem : virtual public AssociatedItem
location_t get_locus () const override { return locus; }
};

/* Abstract base class for items used within an inherent impl block (the impl
* name {} one) */
class InherentImplItem : virtual public AssociatedItem
{
protected:
// Clone function implementation as pure virtual method
virtual InherentImplItem *clone_associated_item_impl () const override = 0;

public:
// Unique pointer custom clone function
std::unique_ptr<InherentImplItem> clone_inherent_impl_item () const
{
return std::unique_ptr<InherentImplItem> (clone_associated_item_impl ());
}
};

// Abstract base class for items used in a trait impl
class TraitImplItem : virtual public AssociatedItem
{
Expand Down Expand Up @@ -1860,7 +1844,7 @@ class SingleASTNode : public Visitable
std::unique_ptr<Stmt> stmt;
std::unique_ptr<ExternalItem> external_item;
std::unique_ptr<TraitItem> trait_item;
std::unique_ptr<InherentImplItem> impl_item;
std::unique_ptr<AssociatedItem> impl_item;
std::unique_ptr<TraitImplItem> trait_impl_item;
std::unique_ptr<Type> type;

Expand All @@ -1885,7 +1869,7 @@ class SingleASTNode : public Visitable
: kind (TRAIT), trait_item (std::move (item))
{}

SingleASTNode (std::unique_ptr<InherentImplItem> item)
SingleASTNode (std::unique_ptr<AssociatedItem> item)
: kind (IMPL), impl_item (std::move (item))
{}

Expand Down Expand Up @@ -1959,7 +1943,7 @@ class SingleASTNode : public Visitable
return std::move (external_item);
}

std::unique_ptr<InherentImplItem> take_impl_item ()
std::unique_ptr<AssociatedItem> take_impl_item ()
{
rust_assert (!is_error ());
return std::move (impl_item);
Expand Down
18 changes: 10 additions & 8 deletions gcc/rust/ast/rust-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,9 @@ class UseDeclaration : public VisItem
class LetStmt;

// Rust function declaration AST node
class Function : public VisItem, public InherentImplItem, public TraitImplItem
class Function : public VisItem,
virtual public AssociatedItem,
public TraitImplItem
{
FunctionQualifiers qualifiers;
Identifier function_name;
Expand Down Expand Up @@ -2308,7 +2310,7 @@ class Union : public VisItem
/* "Constant item" AST node - used for constant, compile-time expressions
* within module scope (like constexpr) */
class ConstantItem : public VisItem,
public InherentImplItem,
virtual public AssociatedItem,
public TraitImplItem
{
// either has an identifier or "_" - maybe handle in identifier?
Expand Down Expand Up @@ -3408,7 +3410,7 @@ class Impl : public VisItem
class InherentImpl : public Impl
{
// bool has_impl_items;
std::vector<std::unique_ptr<InherentImplItem>> impl_items;
std::vector<std::unique_ptr<AssociatedItem>> impl_items;

public:
std::string as_string () const override;
Expand All @@ -3417,7 +3419,7 @@ class InherentImpl : public Impl
bool has_impl_items () const { return !impl_items.empty (); }

// Mega-constructor
InherentImpl (std::vector<std::unique_ptr<InherentImplItem>> impl_items,
InherentImpl (std::vector<std::unique_ptr<AssociatedItem>> impl_items,
std::vector<std::unique_ptr<GenericParam>> generic_params,
std::unique_ptr<Type> trait_type, WhereClause where_clause,
Visibility vis, std::vector<Attribute> inner_attrs,
Expand All @@ -3433,7 +3435,7 @@ class InherentImpl : public Impl
{
impl_items.reserve (other.impl_items.size ());
for (const auto &e : other.impl_items)
impl_items.push_back (e->clone_inherent_impl_item ());
impl_items.push_back (e->clone_associated_item ());
}

// Overloaded assignment operator with vector clone
Expand All @@ -3443,7 +3445,7 @@ class InherentImpl : public Impl

impl_items.reserve (other.impl_items.size ());
for (const auto &e : other.impl_items)
impl_items.push_back (e->clone_inherent_impl_item ());
impl_items.push_back (e->clone_associated_item ());

return *this;
}
Expand All @@ -3455,11 +3457,11 @@ class InherentImpl : public Impl
void accept_vis (ASTVisitor &vis) override;

// TODO: think of better way to do this
const std::vector<std::unique_ptr<InherentImplItem>> &get_impl_items () const
const std::vector<std::unique_ptr<AssociatedItem>> &get_impl_items () const
{
return impl_items;
}
std::vector<std::unique_ptr<InherentImplItem>> &get_impl_items ()
std::vector<std::unique_ptr<AssociatedItem>> &get_impl_items ()
{
return impl_items;
}
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/ast/rust-macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ class MacroInvocation : public TypeNoBounds,
public Item,
public TraitItem,
public TraitImplItem,
public InherentImplItem,
virtual public AssociatedItem,
public ExternalItem,
public ExprWithoutBlock
{
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/expand/rust-expand-visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ ExpandVisitor::visit (AST::InherentImpl &impl)
if (impl.has_where_clause ())
expand_where_clause (impl.get_where_clause ());

std::function<std::unique_ptr<AST::InherentImplItem> (AST::SingleASTNode)>
std::function<std::unique_ptr<AST::AssociatedItem> (AST::SingleASTNode)>
extractor = [] (AST::SingleASTNode node) { return node.take_impl_item (); };

expand_macro_children (MacroExpander::ContextType::IMPL,
Expand Down
8 changes: 4 additions & 4 deletions gcc/rust/parse/rust-parse-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5388,12 +5388,12 @@ Parser<ManagedTokenSource>::parse_impl (AST::Visibility vis,
AST::AttrVec inner_attrs = parse_inner_attributes ();

// parse inherent impl items
std::vector<std::unique_ptr<AST::InherentImplItem>> impl_items;
std::vector<std::unique_ptr<AST::AssociatedItem>> impl_items;

const_TokenPtr t = lexer.peek_token ();
while (t->get_id () != RIGHT_CURLY)
{
std::unique_ptr<AST::InherentImplItem> impl_item
std::unique_ptr<AST::AssociatedItem> impl_item
= parse_inherent_impl_item ();

if (impl_item == nullptr)
Expand Down Expand Up @@ -5512,7 +5512,7 @@ Parser<ManagedTokenSource>::parse_impl (AST::Visibility vis,

// Parses a single inherent impl item (item inside an inherent impl block).
template <typename ManagedTokenSource>
std::unique_ptr<AST::InherentImplItem>
std::unique_ptr<AST::AssociatedItem>
Parser<ManagedTokenSource>::parse_inherent_impl_item ()
{
// parse outer attributes (if they exist)
Expand Down Expand Up @@ -5629,7 +5629,7 @@ Parser<ManagedTokenSource>::parse_inherent_impl_item ()
// InherentImplItem is this specialisation of the template while TraitImplItem
// will be the other.
template <typename ManagedTokenSource>
std::unique_ptr<AST::InherentImplItem>
std::unique_ptr<AST::AssociatedItem>
Parser<ManagedTokenSource>::parse_inherent_impl_function_or_method (
AST::Visibility vis, AST::AttrVec outer_attrs)
{
Expand Down
4 changes: 2 additions & 2 deletions gcc/rust/parse/rust-parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ template <typename ManagedTokenSource> class Parser
std::unique_ptr<AST::Type> parse_type (bool save_errors = true);
std::unique_ptr<AST::ExternalItem> parse_external_item ();
std::unique_ptr<AST::TraitItem> parse_trait_item ();
std::unique_ptr<AST::InherentImplItem> parse_inherent_impl_item ();
std::unique_ptr<AST::AssociatedItem> parse_inherent_impl_item ();
std::unique_ptr<AST::TraitImplItem> parse_trait_impl_item ();
AST::PathInExpression parse_path_in_expression ();
std::vector<std::unique_ptr<AST::LifetimeParam>> parse_lifetime_params ();
Expand Down Expand Up @@ -348,7 +348,7 @@ template <typename ManagedTokenSource> class Parser

std::unique_ptr<AST::Impl> parse_impl (AST::Visibility vis,
AST::AttrVec outer_attrs);
std::unique_ptr<AST::InherentImplItem>
std::unique_ptr<AST::AssociatedItem>
parse_inherent_impl_function_or_method (AST::Visibility vis,
AST::AttrVec outer_attrs);
std::unique_ptr<AST::TraitImplItem>
Expand Down

0 comments on commit 51f7bfc

Please sign in to comment.