From: Marc Poulhiès Date: Wed, 28 Jun 2023 20:11:50 +0000 (+0200) Subject: gccrs: minor HIR interface cleanup X-Git-Tag: basepoints/gcc-15~2410 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9499b41f40f182eb855c09f07883fe68d7042739;p=thirdparty%2Fgcc.git gccrs: minor HIR interface cleanup 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 --- diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index a783da1833c2..bbd72007f64f 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -835,7 +835,7 @@ protected: // Base array initialisation internal element representation thing (abstract) // aka ArrayElements -class ArrayElems +class ArrayElems : public FullVisitable { public: enum ArrayExprType @@ -1393,7 +1393,7 @@ public: /* Base HIR node for a single struct expression field (in struct instance * creation) - abstract */ -class StructExprField +class StructExprField : public FullVisitable { public: enum StructExprFieldKind @@ -2144,6 +2144,7 @@ protected: // A block HIR node class BlockExpr : public ExprWithBlock, public WithInnerAttrs { + // FIXME this should be private + get/set public: std::vector > statements; std::unique_ptr expr; diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index c719a7b03b87..eda2d43eee22 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -146,7 +146,7 @@ protected: /* "where" clause item base. Abstract - use LifetimeWhereClauseItem, * TypeBoundWhereClauseItem */ -class WhereClauseItem +class WhereClauseItem : public FullVisitable { public: enum ItemType @@ -803,7 +803,7 @@ protected: }; // The path-ish thing referred to in a use declaration - abstract base class -class UseTree +class UseTree : public FullVisitable { Location locus; @@ -820,8 +820,6 @@ public: 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; @@ -985,6 +983,12 @@ public: // 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; } @@ -1045,6 +1049,7 @@ public: Location get_locus () const override final { return locus; } ItemKind get_item_kind () const override { return ItemKind::UseDeclaration; } + std::unique_ptr &get_use_tree () { return use_tree; } void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRStmtVisitor &vis) override; void accept_vis (HIRVisItemVisitor &vis) override; @@ -1443,6 +1448,7 @@ protected: }; // A single field in a struct +// FIXME can't this be a TupleStruct + field_name? class StructField { public: @@ -1511,7 +1517,7 @@ public: 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; } }; @@ -1575,7 +1581,7 @@ protected: }; // A single field in a tuple -struct TupleField +class TupleField { private: // bool has_outer_attributes; @@ -1638,8 +1644,11 @@ public: 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 &get_field_type () { return field_type; } }; @@ -2236,7 +2245,7 @@ protected: }; // Function declaration in traits -struct TraitFunctionDecl +class TraitFunctionDecl { private: FunctionQualifiers qualifiers; @@ -2311,6 +2320,8 @@ public: // 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; } diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h index a76588f19956..692de3a7287f 100644 --- a/gcc/rust/hir/tree/rust-hir-pattern.h +++ b/gcc/rust/hir/tree/rust-hir-pattern.h @@ -781,7 +781,7 @@ protected: }; // Base abstract class for patterns used in TupleStructPattern -class TupleStructItems +class TupleStructItems : public FullVisitable { public: enum ItemType @@ -1014,7 +1014,7 @@ protected: }; // Base abstract class representing TuplePattern patterns -class TuplePatternItems +class TuplePatternItems : public FullVisitable { public: enum TuplePatternItemType @@ -1036,8 +1036,6 @@ public: virtual std::string as_string () const = 0; - virtual void accept_vis (HIRFullVisitor &vis) = 0; - virtual TuplePatternItemType get_pattern_type () const = 0; protected: