diff options
Diffstat (limited to 'gcc/rust/ast/rust-item.h')
-rw-r--r-- | gcc/rust/ast/rust-item.h | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 6ebb2e9..a1b505d 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1817,13 +1817,14 @@ public: Visibility vis, std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)), - field_name (std::move (field_name)), field_type (std::move (field_type)) + field_name (std::move (field_name)), field_type (std::move (field_type)), + node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} // Copy constructor StructField (StructField const &other) : outer_attrs (other.outer_attrs), visibility (other.visibility), - field_name (other.field_name) + field_name (other.field_name), node_id (other.node_id) { // guard to prevent null dereference if (other.field_type != nullptr) @@ -1838,6 +1839,7 @@ public: field_name = other.field_name; visibility = other.visibility; outer_attrs = other.outer_attrs; + node_id = other.node_id; // guard to prevent null dereference if (other.field_type != nullptr) @@ -1959,6 +1961,7 @@ private: std::unique_ptr<Type> field_type; // should this store location info? + NodeId node_id; public: // Returns whether tuple field has outer attributes. @@ -1972,12 +1975,14 @@ public: TupleField (std::unique_ptr<Type> field_type, Visibility vis, std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)), - field_type (std::move (field_type)) + field_type (std::move (field_type)), + node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} // Copy constructor with clone TupleField (TupleField const &other) - : outer_attrs (other.outer_attrs), visibility (other.visibility) + : outer_attrs (other.outer_attrs), visibility (other.visibility), + node_id (other.node_id) { // guard to prevent null dereference (only required if error) if (other.field_type != nullptr) @@ -1991,6 +1996,7 @@ public: { visibility = other.visibility; outer_attrs = other.outer_attrs; + node_id = other.node_id; // guard to prevent null dereference (only required if error) if (other.field_type != nullptr) @@ -2016,6 +2022,8 @@ public: std::string as_string () const; + NodeId get_node_id () const { return node_id; }; + // TODO: this mutable getter seems really dodgy. Think up better way. std::vector<Attribute> &get_outer_attrs () { return outer_attrs; } const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; } @@ -2053,6 +2061,15 @@ public: std::vector<TupleField> &get_fields () { return fields; } const std::vector<TupleField> &get_fields () const { return fields; } + void iterate (std::function<bool (TupleField &)> cb) + { + for (auto &field : fields) + { + if (!cb (field)) + return; + } + } + protected: /* Use covariance to implement clone function as returning this object * rather than base */ |