aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2020-12-30 22:13:41 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-01-06 10:01:17 +0000
commit36ebe9a0380694c8517536eb37c7134f1323a30b (patch)
tree06901ff25aa5ea093184e0713bd0363735408959 /gcc/rust/ast
parent467141184aa274126ff7e2a41d08bb621b7a3fdf (diff)
downloadgcc-36ebe9a0380694c8517536eb37c7134f1323a30b.zip
gcc-36ebe9a0380694c8517536eb37c7134f1323a30b.tar.gz
gcc-36ebe9a0380694c8517536eb37c7134f1323a30b.tar.bz2
This brings structs back in post HIR changes. It supports structs
where no base struct is referenced and the constructor is in order.
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r--gcc/rust/ast/rust-expr.h21
-rw-r--r--gcc/rust/ast/rust-item.h15
2 files changed, 34 insertions, 2 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index cc87498..584e210 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -1571,9 +1571,16 @@ public:
virtual Location get_locus_slow () const = 0;
+ NodeId get_node_id () const { return node_id; }
+
protected:
// pure virtual clone implementation
virtual StructExprField *clone_struct_expr_field_impl () const = 0;
+
+ StructExprField () : node_id (Analysis::Mappings::get ()->get_next_node_id ())
+ {}
+
+ NodeId node_id;
};
// Identifier-only variant of StructExprField AST node
@@ -1584,7 +1591,8 @@ class StructExprFieldIdentifier : public StructExprField
public:
StructExprFieldIdentifier (Identifier field_identifier, Location locus)
- : field_name (std::move (field_identifier)), locus (locus)
+ : StructExprField (), field_name (std::move (field_identifier)),
+ locus (locus)
{}
std::string as_string () const override { return field_name; }
@@ -1611,7 +1619,7 @@ class StructExprFieldWithVal : public StructExprField
protected:
StructExprFieldWithVal (std::unique_ptr<Expr> field_value)
- : value (std::move (field_value))
+ : StructExprField (), value (std::move (field_value))
{}
// Copy constructor requires clone
@@ -1769,6 +1777,15 @@ public:
return fields;
}
+ void iterate (std::function<bool (StructExprField *)> cb)
+ {
+ for (auto &field : fields)
+ {
+ if (!cb (field.get ()))
+ return;
+ }
+ }
+
StructBase &get_struct_base () { return struct_base; }
const StructBase &get_struct_base () const { return struct_base; }
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 1088842..9bd8de4 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -1746,6 +1746,8 @@ public:
return where_clause;
}
+ Identifier get_identifier () const { return struct_name; }
+
protected:
Struct (Identifier struct_name,
std::vector<std::unique_ptr<GenericParam> > generic_params,
@@ -1802,6 +1804,8 @@ private:
// should this store location info?
+ NodeId node_id;
+
public:
// Returns whether struct field has any outer attributes.
bool has_outer_attributes () const { return !outer_attrs.empty (); }
@@ -1877,6 +1881,8 @@ public:
}
Visibility get_visibility () const { return visibility; }
+
+ NodeId get_node_id () const { return node_id; }
};
// Rust struct declaration with true struct type AST node
@@ -1922,6 +1928,15 @@ public:
std::vector<StructField> &get_fields () { return fields; }
const std::vector<StructField> &get_fields () const { return fields; }
+ void iterate (std::function<bool (StructField &)> cb)
+ {
+ for (auto &field : fields)
+ {
+ if (!cb (field))
+ return;
+ }
+ }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */