public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Add missing NodeId to where clause items
@ 2022-06-08 11:44 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 11:44 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b0e9cea1ae57f895063189e2e3f8a9e664d4ca35

commit b0e9cea1ae57f895063189e2e3f8a9e664d4ca35
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Mon Oct 25 15:40:07 2021 +0100

    Add missing NodeId to where clause items

Diff:
---
 gcc/rust/ast/rust-item.h | 50 ++++++++++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index d075a57a1cd..a5d9a0ac869 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;
@@ -187,23 +189,29 @@ 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; }
+
 protected:
   // Clone function implementation as (not pure) virtual method
   LifetimeWhereClauseItem *clone_where_clause_item_impl () const override
@@ -215,18 +223,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 +240,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 +249,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 +258,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 +277,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 +288,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 +310,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 +330,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 +353,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 ()
   {


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 11:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 11:44 [gcc/devel/rust/master] Add missing NodeId to where clause items Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).