Skip to content

Commit

Permalink
gccrs: minor HIR interface cleanup
Browse files Browse the repository at this point in the history
Minor changes in HIR interface: add missing getters, make some classes
inherit from FullVisitable.

gcc/rust/ChangeLog:

	* hir/tree/rust-hir-expr.h (class ArrayElems): Inherit from FullVisitable.
	(class StructExprField): Likewise.
	* hir/tree/rust-hir-item.h (class WhereClauseItem): Likewise.
	(class UseTree): Likewise.
	(UseTreeRebind::get_path, UseTreeRebind::get_identifier)
	(UseTreeRebind::get_bind_type): New.
	(UseDeclaration::get_use_tree): New.
	(struct TraitFunctionDecl): Change struct to ...
	(class TraitFunctionDecl): ... class.
	(TraitFunctionDecl::get_where_clause): New.
	(StructField::get_outer_attrs): New.
	(struct TupleField): Change struct to ...
	(class TupleField): ... class.
	(TupleField::get_visibility, TupleField::get_outer_attrs): New.
	* hir/tree/rust-hir-pattern.h (class TupleStructItems): Inherit
	from FullVisitable.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
  • Loading branch information
dkm committed Jul 3, 2023
1 parent 5d33b88 commit 2f91d51
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
5 changes: 3 additions & 2 deletions gcc/rust/hir/tree/rust-hir-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ class GroupedExpr : public ExprWithoutBlock, public WithInnerAttrs

// Base array initialisation internal element representation thing (abstract)
// aka ArrayElements
class ArrayElems
class ArrayElems : public FullVisitable
{
public:
enum ArrayExprType
Expand Down Expand Up @@ -1393,7 +1393,7 @@ struct StructBase

/* Base HIR node for a single struct expression field (in struct instance
* creation) - abstract */
class StructExprField
class StructExprField : public FullVisitable
{
public:
enum StructExprFieldKind
Expand Down Expand Up @@ -2144,6 +2144,7 @@ class ClosureExpr : public ExprWithoutBlock
// A block HIR node
class BlockExpr : public ExprWithBlock, public WithInnerAttrs
{
// FIXME this should be private + get/set
public:
std::vector<std::unique_ptr<Stmt> > statements;
std::unique_ptr<Expr> expr;
Expand Down
25 changes: 18 additions & 7 deletions gcc/rust/hir/tree/rust-hir-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class TypeParam : public GenericParam

/* "where" clause item base. Abstract - use LifetimeWhereClauseItem,
* TypeBoundWhereClauseItem */
class WhereClauseItem
class WhereClauseItem : public FullVisitable
{
public:
enum ItemType
Expand Down Expand Up @@ -803,7 +803,7 @@ class ExternCrate : public VisItem
};

// The path-ish thing referred to in a use declaration - abstract base class
class UseTree
class UseTree : public FullVisitable
{
Location locus;

Expand All @@ -820,8 +820,6 @@ class UseTree

Location get_locus () const { return locus; }

virtual void accept_vis (HIRFullVisitor &vis) = 0;

protected:
// Clone function implementation as pure virtual method
virtual UseTree *clone_use_tree_impl () const = 0;
Expand Down Expand Up @@ -985,6 +983,12 @@ class UseTreeRebind : public UseTree
// Returns whether has path (this should always be true).
bool has_path () const { return !path.is_empty (); }

AST::SimplePath get_path () { return path; }

Identifier get_identifier () const { return identifier; }

NewBindType get_bind_type () const { return bind_type; }

// Returns whether has identifier (or, rather, is allowed to).
bool has_identifier () const { return bind_type == IDENTIFIER; }

Expand Down Expand Up @@ -1045,6 +1049,7 @@ class UseDeclaration : public VisItem
Location get_locus () const override final { return locus; }
ItemKind get_item_kind () const override { return ItemKind::UseDeclaration; }

std::unique_ptr<UseTree> &get_use_tree () { return use_tree; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRStmtVisitor &vis) override;
void accept_vis (HIRVisItemVisitor &vis) override;
Expand Down Expand Up @@ -1443,6 +1448,7 @@ class Struct : public VisItem
};

// A single field in a struct
// FIXME can't this be a TupleStruct + field_name?
class StructField
{
public:
Expand Down Expand Up @@ -1511,7 +1517,7 @@ class StructField
Analysis::NodeMapping get_mappings () const { return mappings; }

Location get_locus () { return locus; }

AST::AttrVec &get_outer_attrs () { return outer_attrs; }
Visibility &get_visibility () { return visibility; }
};

Expand Down Expand Up @@ -1575,7 +1581,7 @@ class StructStruct : public Struct
};

// A single field in a tuple
struct TupleField
class TupleField
{
private:
// bool has_outer_attributes;
Expand Down Expand Up @@ -1638,8 +1644,11 @@ struct TupleField

Analysis::NodeMapping get_mappings () const { return mappings; }

Visibility &get_visibility () { return visibility; }

Location get_locus () const { return locus; }

AST::AttrVec &get_outer_attrs () { return outer_attrs; }
std::unique_ptr<HIR::Type> &get_field_type () { return field_type; }
};

Expand Down Expand Up @@ -2236,7 +2245,7 @@ class StaticItem : public VisItem
};

// Function declaration in traits
struct TraitFunctionDecl
class TraitFunctionDecl
{
private:
FunctionQualifiers qualifiers;
Expand Down Expand Up @@ -2311,6 +2320,8 @@ struct TraitFunctionDecl
// Returns whether function has a where clause.
bool has_where_clause () const { return !where_clause.is_empty (); }

WhereClause &get_where_clause () { return where_clause; }

bool is_method () const { return !self.is_error (); }

SelfParam &get_self () { return self; }
Expand Down
6 changes: 2 additions & 4 deletions gcc/rust/hir/tree/rust-hir-pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ class StructPattern : public Pattern
};

// Base abstract class for patterns used in TupleStructPattern
class TupleStructItems
class TupleStructItems : public FullVisitable
{
public:
enum ItemType
Expand Down Expand Up @@ -1014,7 +1014,7 @@ class TupleStructPattern : public Pattern
};

// Base abstract class representing TuplePattern patterns
class TuplePatternItems
class TuplePatternItems : public FullVisitable
{
public:
enum TuplePatternItemType
Expand All @@ -1036,8 +1036,6 @@ class TuplePatternItems

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

virtual void accept_vis (HIRFullVisitor &vis) = 0;

virtual TuplePatternItemType get_pattern_type () const = 0;

protected:
Expand Down

0 comments on commit 2f91d51

Please sign in to comment.