diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-01-18 14:51:36 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-20 09:59:22 +0000 |
commit | 9a942d6fbd0cc087cbc801ce4681a498e59dce2c (patch) | |
tree | 5198e76f054e741f5ba9793e111bfd63be88e80d /gcc/rust/ast/rust-item.h | |
parent | 89631998d2ffda0c0c05066c148c6fc19398da5c (diff) | |
download | gcc-9a942d6fbd0cc087cbc801ce4681a498e59dce2c.zip gcc-9a942d6fbd0cc087cbc801ce4681a498e59dce2c.tar.gz gcc-9a942d6fbd0cc087cbc801ce4681a498e59dce2c.tar.bz2 |
Add in TupleStruct support
This adds in tuple struct support with name and type resolution. The
arguments and number of arguments are validated against. Test cases
added for those errors too.
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 */ |