Skip to content

Commit

Permalink
Create base class for TupleStructItems and TuplePatternItems
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* hir/tree/rust-hir-pattern.h
	(class TupleItems): New.
	(class TupleStructItems): Inherit from TupleItems.
	(class TuplePatternItems): Likewise.

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 committed Nov 3, 2023
1 parent 13cb697 commit cfa661e
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions gcc/rust/hir/tree/rust-hir-pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,8 @@ class StructPattern : public Pattern
}
};

// Base abstract class for patterns used in TupleStructPattern
class TupleStructItems : public FullVisitable
// Base abstract class for TupleStructItems and TuplePatternItems
class TupleItems : public FullVisitable
{
public:
enum ItemType
Expand All @@ -787,25 +787,38 @@ class TupleStructItems : public FullVisitable
RANGED,
};

virtual ~TupleStructItems () {}
virtual ~TupleItems () {}

// TODO: should this store location data?

// Unique pointer custom clone function
std::unique_ptr<TupleStructItems> clone_tuple_struct_items () const
std::unique_ptr<TupleItems> clone_tuple_items () const
{
return std::unique_ptr<TupleStructItems> (clone_tuple_items_impl ());
return std::unique_ptr<TupleItems> (clone_tuple_items_impl ());
}

virtual ItemType get_item_type () const = 0;

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

virtual void accept_vis (HIRFullVisitor &vis) = 0;
protected:
// pure virtual clone implementation
virtual TupleItems *clone_tuple_items_impl () const = 0;
};

virtual ItemType get_item_type () const = 0;
// Base abstract class for patterns used in TupleStructPattern
class TupleStructItems : public TupleItems
{
public:
// Unique pointer custom clone function
std::unique_ptr<TupleStructItems> clone_tuple_struct_items () const
{
return std::unique_ptr<TupleStructItems> (clone_tuple_items_impl ());
}

protected:
// pure virtual clone implementation
virtual TupleStructItems *clone_tuple_items_impl () const = 0;
virtual TupleStructItems *clone_tuple_items_impl () const override = 0;
};

// Class for non-ranged tuple struct pattern patterns
Expand Down Expand Up @@ -1011,32 +1024,18 @@ class TupleStructPattern : public Pattern
};

// Base abstract class representing TuplePattern patterns
class TuplePatternItems : public FullVisitable
class TuplePatternItems : public TupleItems
{
public:
enum ItemType
{
MULTIPLE,
RANGED,
};

virtual ~TuplePatternItems () {}

// TODO: should this store location data?

// Unique pointer custom clone function
std::unique_ptr<TuplePatternItems> clone_tuple_pattern_items () const
{
return std::unique_ptr<TuplePatternItems> (clone_tuple_items_impl ());
}

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

virtual ItemType get_item_type () const = 0;

protected:
// pure virtual clone implementation
virtual TuplePatternItems *clone_tuple_items_impl () const = 0;
virtual TuplePatternItems *clone_tuple_items_impl () const override = 0;
};

// Class representing TuplePattern patterns where there are multiple patterns
Expand Down

0 comments on commit cfa661e

Please sign in to comment.