]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: minor HIR interface cleanup
authorMarc Poulhiès <dkm@kataplop.net>
Wed, 28 Jun 2023 20:11:50 +0000 (22:11 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:49:31 +0000 (18:49 +0100)
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>
gcc/rust/hir/tree/rust-hir-expr.h
gcc/rust/hir/tree/rust-hir-item.h
gcc/rust/hir/tree/rust-hir-pattern.h

index a783da1833c27d3c04adb50bc499b5043b55c322..bbd72007f64f62208c73e06df028bd37dcb19612 100644 (file)
@@ -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<std::unique_ptr<Stmt> > statements;
   std::unique_ptr<Expr> expr;
index c719a7b03b8758fef3087f75e8e20f2bedff3cbd..eda2d43eee22fe8636f48d5d035e7d5f405468ad 100644 (file)
@@ -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<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;
@@ -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<HIR::Type> &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; }
index a76588f199562c51a26f75341b8ccea81bebf7fa..692de3a7287f5bed5d8ac26d4ed31735bb4828bb 100644 (file)
@@ -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: