diff options
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r-- | gcc/rust/ast/rust-item.h | 119 |
1 files changed, 42 insertions, 77 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index d075a57..323548a 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -177,6 +177,8 @@ public: virtual void accept_vis (ASTVisitor &vis) = 0; + virtual NodeId get_node_id () const = 0; + protected: // Clone function implementation as pure virtual method virtual WhereClauseItem *clone_where_clause_item_impl () const = 0; @@ -186,24 +188,31 @@ protected: class LifetimeWhereClauseItem : public WhereClauseItem { Lifetime lifetime; - - // LifetimeBounds lifetime_bounds; - std::vector<Lifetime> lifetime_bounds; // inlined lifetime bounds - + std::vector<Lifetime> lifetime_bounds; Location locus; + NodeId node_id; public: LifetimeWhereClauseItem (Lifetime lifetime, std::vector<Lifetime> lifetime_bounds, Location locus) : lifetime (std::move (lifetime)), - lifetime_bounds (std::move (lifetime_bounds)), locus (locus) + lifetime_bounds (std::move (lifetime_bounds)), locus (locus), + node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} std::string as_string () const override; void accept_vis (ASTVisitor &vis) override; + NodeId get_node_id () const override final { return node_id; } + + Lifetime &get_lifetime () { return lifetime; } + + std::vector<Lifetime> &get_lifetime_bounds () { return lifetime_bounds; } + + Location get_locus () const { return locus; } + protected: // Clone function implementation as (not pure) virtual method LifetimeWhereClauseItem *clone_where_clause_item_impl () const override @@ -215,18 +224,10 @@ protected: // A type bound where clause item class TypeBoundWhereClauseItem : public WhereClauseItem { - // bool has_for_lifetimes; - // LifetimeParams for_lifetimes; - std::vector<LifetimeParam> for_lifetimes; // inlined - + std::vector<LifetimeParam> for_lifetimes; std::unique_ptr<Type> bound_type; - - // bool has_type_param_bounds; - // TypeParamBounds type_param_bounds; - std::vector<std::unique_ptr<TypeParamBound>> - type_param_bounds; // inlined form - - // should this store location info? + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds; + NodeId node_id; public: // Returns whether the item has ForLifetimes @@ -240,7 +241,8 @@ public: std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds) : for_lifetimes (std::move (for_lifetimes)), bound_type (std::move (bound_type)), - type_param_bounds (std::move (type_param_bounds)) + type_param_bounds (std::move (type_param_bounds)), + node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} // Copy constructor requires clone @@ -248,6 +250,7 @@ public: : for_lifetimes (other.for_lifetimes), bound_type (other.bound_type->clone_type ()) { + node_id = other.node_id; type_param_bounds.reserve (other.type_param_bounds.size ()); for (const auto &e : other.type_param_bounds) type_param_bounds.push_back (e->clone_type_param_bound ()); @@ -256,9 +259,9 @@ public: // Overload assignment operator to clone TypeBoundWhereClauseItem &operator= (TypeBoundWhereClauseItem const &other) { + node_id = other.node_id; for_lifetimes = other.for_lifetimes; bound_type = other.bound_type->clone_type (); - type_param_bounds.reserve (other.type_param_bounds.size ()); for (const auto &e : other.type_param_bounds) type_param_bounds.push_back (e->clone_type_param_bound ()); @@ -275,7 +278,6 @@ public: void accept_vis (ASTVisitor &vis) override; - // TODO: is this better? Or is a "vis_block" better? std::unique_ptr<Type> &get_type () { rust_assert (bound_type != nullptr); @@ -287,12 +289,15 @@ public: { return type_param_bounds; } + const std::vector<std::unique_ptr<TypeParamBound>> & get_type_param_bounds () const { return type_param_bounds; } + NodeId get_node_id () const override final { return node_id; } + protected: // Clone function implementation as (not pure) virtual method TypeBoundWhereClauseItem *clone_where_clause_item_impl () const override @@ -306,17 +311,18 @@ struct WhereClause { private: std::vector<std::unique_ptr<WhereClauseItem>> where_clause_items; - - // should this store location info? + NodeId node_id; public: WhereClause (std::vector<std::unique_ptr<WhereClauseItem>> where_clause_items) - : where_clause_items (std::move (where_clause_items)) + : where_clause_items (std::move (where_clause_items)), + node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} // copy constructor with vector clone WhereClause (WhereClause const &other) { + node_id = other.node_id; where_clause_items.reserve (other.where_clause_items.size ()); for (const auto &e : other.where_clause_items) where_clause_items.push_back (e->clone_where_clause_item ()); @@ -325,6 +331,7 @@ public: // overloaded assignment operator with vector clone WhereClause &operator= (WhereClause const &other) { + node_id = other.node_id; where_clause_items.reserve (other.where_clause_items.size ()); for (const auto &e : other.where_clause_items) where_clause_items.push_back (e->clone_where_clause_item ()); @@ -347,6 +354,8 @@ public: std::string as_string () const; + NodeId get_node_id () const { return node_id; } + // TODO: this mutable getter seems kinda dodgy std::vector<std::unique_ptr<WhereClauseItem>> &get_items () { @@ -878,11 +887,7 @@ public: } // TODO: is this better? Or is a "vis_block" better? - WhereClause &get_where_clause () - { - rust_assert (has_where_clause ()); - return where_clause; - } + WhereClause &get_where_clause () { return where_clause; } Identifier get_method_name () const { return method_name; } @@ -1578,11 +1583,7 @@ public: Identifier get_function_name () const { return function_name; } // TODO: is this better? Or is a "vis_block" better? - WhereClause &get_where_clause () - { - rust_assert (has_where_clause ()); - return where_clause; - } + WhereClause &get_where_clause () { return where_clause; } // TODO: is this better? Or is a "vis_block" better? std::unique_ptr<Type> &get_return_type () @@ -1710,11 +1711,7 @@ public: } // TODO: is this better? Or is a "vis_block" better? - WhereClause &get_where_clause () - { - rust_assert (has_where_clause ()); - return where_clause; - } + WhereClause &get_where_clause () { return where_clause; } // TODO: is this better? Or is a "vis_block" better? std::unique_ptr<Type> &get_type_aliased () @@ -1780,11 +1777,7 @@ public: } // TODO: is this better? Or is a "vis_block" better? - WhereClause &get_where_clause () - { - rust_assert (has_where_clause ()); - return where_clause; - } + WhereClause &get_where_clause () { return where_clause; } Identifier get_identifier () const { return struct_name; } @@ -2401,11 +2394,7 @@ public: } // TODO: is this better? Or is a "vis_block" better? - WhereClause &get_where_clause () - { - rust_assert (has_where_clause ()); - return where_clause; - } + WhereClause &get_where_clause () { return where_clause; } protected: /* Use covariance to implement clone function as returning this object @@ -2511,11 +2500,7 @@ public: } // TODO: is this better? Or is a "vis_block" better? - WhereClause &get_where_clause () - { - rust_assert (has_where_clause ()); - return where_clause; - } + WhereClause &get_where_clause () { return where_clause; } Identifier get_identifier () const { return union_name; } @@ -2868,11 +2853,7 @@ public: } // TODO: is this better? Or is a "vis_block" better? - WhereClause &get_where_clause () - { - rust_assert (has_where_clause ()); - return where_clause; - } + WhereClause &get_where_clause () { return where_clause; } }; // Actual trait item function declaration within traits @@ -3095,11 +3076,7 @@ public: } // TODO: is this better? Or is a "vis_block" better? - WhereClause &get_where_clause () - { - rust_assert (has_where_clause ()); - return where_clause; - } + WhereClause &get_where_clause () { return where_clause; } SelfParam &get_self_param () { return self_param; } const SelfParam &get_self_param () const { return self_param; } @@ -3533,11 +3510,7 @@ public: return type_param_bounds; } - WhereClause &get_where_clause () - { - rust_assert (has_where_clause ()); - return where_clause; - } + WhereClause &get_where_clause () { return where_clause; } void insert_implict_self (std::unique_ptr<AST::GenericParam> &¶m) { @@ -3610,11 +3583,7 @@ public: } // TODO: is this better? Or is a "vis_block" better? - WhereClause &get_where_clause () - { - rust_assert (has_where_clause ()); - return where_clause; - } + WhereClause &get_where_clause () { return where_clause; } // TODO: is this better? Or is a "vis_block" better? std::unique_ptr<Type> &get_type () @@ -4261,11 +4230,7 @@ public: } // TODO: is this better? Or is a "vis_block" better? - WhereClause &get_where_clause () - { - rust_assert (has_where_clause ()); - return where_clause; - } + WhereClause &get_where_clause () { return where_clause; } // TODO: is this better? Or is a "vis_block" better? std::unique_ptr<Type> &get_return_type () |