aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorMarc Poulhiès <dkm@kataplop.net>2023-06-28 22:11:50 +0200
committerMarc Poulhiès <dkm@kataplop.net>2023-07-03 19:54:15 +0000
commit2f91d511200bf85558c9013b09a458c06edd1e02 (patch)
treecc2a5c3e5b653d7c155a1813dde5814de15b9f61 /gcc/rust
parent5d33b88c81ba07864c2bb03d80e75e7774a4c6d7 (diff)
downloadgcc-2f91d511200bf85558c9013b09a458c06edd1e02.zip
gcc-2f91d511200bf85558c9013b09a458c06edd1e02.tar.gz
gcc-2f91d511200bf85558c9013b09a458c06edd1e02.tar.bz2
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 <dkm@kataplop.net>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h5
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h25
-rw-r--r--gcc/rust/hir/tree/rust-hir-pattern.h6
3 files changed, 23 insertions, 13 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 844789a..3b66230 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<std::unique_ptr<Stmt> > statements;
std::unique_ptr<Expr> expr;
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 6339784..5b8d92c8 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<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; }
diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h
index 2633774..7dfae3f 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: