Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create base class AssociatedItem #2679

Merged
merged 1 commit into from
Oct 18, 2023
Merged
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
63 changes: 31 additions & 32 deletions gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1446,82 +1446,81 @@ class LifetimeParam : public GenericParam
}
};

class AssociatedItem : public Visitable
{
protected:
// Clone function implementation as pure virtual method
virtual AssociatedItem *clone_associated_item_impl () const = 0;

public:
virtual ~AssociatedItem () {}

std::unique_ptr<AssociatedItem> clone_associated_item () const
{
return std::unique_ptr<AssociatedItem> (clone_associated_item_impl ());
}

virtual std::string as_string () const = 0;

virtual void mark_for_strip () = 0;
virtual bool is_marked_for_strip () const = 0;

virtual location_t get_locus () const = 0;
};

// Item used in trait declarations - abstract base class
class TraitItem : public Visitable
class TraitItem : virtual public AssociatedItem
{
protected:
TraitItem (location_t locus)
: node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus)
{}

// Clone function implementation as pure virtual method
virtual TraitItem *clone_trait_item_impl () const = 0;
virtual TraitItem *clone_associated_item_impl () const override = 0;

NodeId node_id;
location_t locus;

public:
virtual ~TraitItem () {}

// Unique pointer custom clone function
std::unique_ptr<TraitItem> clone_trait_item () const
{
return std::unique_ptr<TraitItem> (clone_trait_item_impl ());
return std::unique_ptr<TraitItem> (clone_associated_item_impl ());
}

virtual std::string as_string () const = 0;

virtual void mark_for_strip () = 0;
virtual bool is_marked_for_strip () const = 0;

NodeId get_node_id () const { return node_id; }
location_t get_locus () const { return locus; }
};

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

public:
virtual ~InherentImplItem () {}

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

virtual std::string as_string () const = 0;

virtual void mark_for_strip () = 0;
virtual bool is_marked_for_strip () const = 0;

virtual location_t get_locus () const = 0;
};

// Abstract base class for items used in a trait impl
class TraitImplItem : public Visitable
class TraitImplItem : virtual public AssociatedItem
{
protected:
virtual TraitImplItem *clone_trait_impl_item_impl () const = 0;
virtual TraitImplItem *clone_associated_item_impl () const override = 0;

public:
virtual ~TraitImplItem (){};

// Unique pointer custom clone function
std::unique_ptr<TraitImplItem> clone_trait_impl_item () const
{
return std::unique_ptr<TraitImplItem> (clone_trait_impl_item_impl ());
return std::unique_ptr<TraitImplItem> (clone_associated_item_impl ());
}

virtual std::string as_string () const = 0;

virtual void mark_for_strip () = 0;
virtual bool is_marked_for_strip () const = 0;
};

// Abstract base class for an item used inside an extern block
Expand Down
37 changes: 8 additions & 29 deletions gcc/rust/ast/rust-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -923,14 +923,7 @@ class Method : public InherentImplItem, public TraitImplItem
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
Method *clone_inherent_impl_item_impl () const final override
{
return clone_method_impl ();
}

/* Use covariance to implement clone function as returning this object
* rather than base */
Method *clone_trait_impl_item_impl () const final override
Method *clone_associated_item_impl () const final override
{
return clone_method_impl ();
}
Expand Down Expand Up @@ -1703,14 +1696,7 @@ class Function : public VisItem, public InherentImplItem, public TraitImplItem

/* Use covariance to implement clone function as returning this object
* rather than base */
Function *clone_inherent_impl_item_impl () const override
{
return new Function (*this);
}

/* Use covariance to implement clone function as returning this object
* rather than base */
Function *clone_trait_impl_item_impl () const override
Function *clone_associated_item_impl () const override
{
return new Function (*this);
}
Expand Down Expand Up @@ -1834,7 +1820,7 @@ class TypeAlias : public VisItem, public TraitImplItem

/* Use covariance to implement clone function as returning this object
* rather than base */
TypeAlias *clone_trait_impl_item_impl () const override
TypeAlias *clone_associated_item_impl () const override
{
return new TypeAlias (*this);
}
Expand Down Expand Up @@ -2699,14 +2685,7 @@ class ConstantItem : public VisItem,

/* Use covariance to implement clone function as returning this object
* rather than base */
ConstantItem *clone_inherent_impl_item_impl () const override
{
return new ConstantItem (*this);
}

/* Use covariance to implement clone function as returning this object
* rather than base */
ConstantItem *clone_trait_impl_item_impl () const override
ConstantItem *clone_associated_item_impl () const override
{
return new ConstantItem (*this);
}
Expand Down Expand Up @@ -3016,7 +2995,7 @@ class TraitItemFunc : public TraitItem

protected:
// Clone function implementation as (not pure) virtual method
TraitItemFunc *clone_trait_item_impl () const override
TraitItemFunc *clone_associated_item_impl () const override
{
return new TraitItemFunc (*this);
}
Expand Down Expand Up @@ -3232,7 +3211,7 @@ class TraitItemMethod : public TraitItem

protected:
// Clone function implementation as (not pure) virtual method
TraitItemMethod *clone_trait_item_impl () const override
TraitItemMethod *clone_associated_item_impl () const override
{
return new TraitItemMethod (*this);
}
Expand Down Expand Up @@ -3337,7 +3316,7 @@ class TraitItemConst : public TraitItem

protected:
// Clone function implementation as (not pure) virtual method
TraitItemConst *clone_trait_item_impl () const override
TraitItemConst *clone_associated_item_impl () const override
{
return new TraitItemConst (*this);
}
Expand Down Expand Up @@ -3424,7 +3403,7 @@ class TraitItemType : public TraitItem

protected:
// Clone function implementation as (not pure) virtual method
TraitItemType *clone_trait_item_impl () const override
TraitItemType *clone_associated_item_impl () const override
{
return new TraitItemType (*this);
}
Expand Down
12 changes: 1 addition & 11 deletions gcc/rust/ast/rust-macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,20 +803,10 @@ class MacroInvocation : public TypeNoBounds,

bool is_item () const override { return !has_semicolon (); }

TraitItem *clone_trait_item_impl () const override
MacroInvocation *clone_associated_item_impl () const override
{
return clone_macro_invocation_impl ();
};

TraitImplItem *clone_trait_impl_item_impl () const override
{
return clone_macro_invocation_impl ();
};

InherentImplItem *clone_inherent_impl_item_impl () const override
{
return clone_macro_invocation_impl ();
}
};

// more generic meta item path-only form
Expand Down
Loading