public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] hir: Add mappings to ArrayElems
@ 2022-07-28 15:35 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-07-28 15:35 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2160d34c5ff8060723c4b71d31c3d195f51eaa06

commit 2160d34c5ff8060723c4b71d31c3d195f51eaa06
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Wed Jul 27 16:30:43 2022 +0200

    hir: Add mappings to ArrayElems

Diff:
---
 gcc/rust/hir/rust-ast-lower-expr.h | 18 ++++++++++++++++--
 gcc/rust/hir/tree/rust-hir-expr.h  | 20 ++++++++++++++------
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h
index 166a44b9096..b420a4d808d 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.h
+++ b/gcc/rust/hir/rust-ast-lower-expr.h
@@ -307,7 +307,14 @@ public:
 	elements.push_back (std::unique_ptr<HIR::Expr> (translated_elem));
       }
 
-    translated_array_elems = new HIR::ArrayElemsValues (std::move (elements));
+    auto crate_num = mappings->get_current_crate ();
+    Analysis::NodeMapping mapping (mappings->get_current_crate (),
+				   elems.get_node_id (),
+				   mappings->get_next_hir_id (crate_num),
+				   UNKNOWN_LOCAL_DEFID);
+
+    translated_array_elems
+      = new HIR::ArrayElemsValues (mapping, std::move (elements));
   }
 
   void visit (AST::ArrayElemsCopied &elems) override
@@ -317,8 +324,15 @@ public:
     HIR::Expr *num_copies
       = ASTLoweringExpr::translate (elems.get_num_copies ().get ());
 
+    auto crate_num = mappings->get_current_crate ();
+    Analysis::NodeMapping mapping (mappings->get_current_crate (),
+				   elems.get_node_id (),
+				   mappings->get_next_hir_id (crate_num),
+				   UNKNOWN_LOCAL_DEFID);
+
     translated_array_elems
-      = new HIR::ArrayElemsCopied (std::unique_ptr<HIR::Expr> (element),
+      = new HIR::ArrayElemsCopied (mapping,
+				   std::unique_ptr<HIR::Expr> (element),
 				   std::unique_ptr<HIR::Expr> (num_copies));
   }
 
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 327a9accfe1..d16ac92f6ca 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -849,6 +849,8 @@ public:
     COPIED,
   };
 
+  ArrayElems (Analysis::NodeMapping mappings) : mappings (mappings){};
+
   virtual ~ArrayElems () {}
 
   // Unique pointer custom clone ArrayElems function
@@ -863,9 +865,13 @@ public:
 
   virtual ArrayExprType get_array_expr_type () const = 0;
 
+  Analysis::NodeMapping &get_mappings () { return mappings; }
+
 protected:
   // pure virtual clone implementation
   virtual ArrayElems *clone_array_elems_impl () const = 0;
+
+  Analysis::NodeMapping mappings;
 };
 
 // Value array elements
@@ -876,12 +882,13 @@ class ArrayElemsValues : public ArrayElems
   // TODO: should this store location data?
 
 public:
-  ArrayElemsValues (std::vector<std::unique_ptr<Expr> > elems)
-    : values (std::move (elems))
+  ArrayElemsValues (Analysis::NodeMapping mappings,
+		    std::vector<std::unique_ptr<Expr> > elems)
+    : ArrayElems (mappings), values (std::move (elems))
   {}
 
   // copy constructor with vector clone
-  ArrayElemsValues (ArrayElemsValues const &other)
+  ArrayElemsValues (ArrayElemsValues const &other) : ArrayElems (other)
   {
     values.reserve (other.values.size ());
     for (const auto &e : other.values)
@@ -930,15 +937,16 @@ class ArrayElemsCopied : public ArrayElems
 
 public:
   // Constructor requires pointers for polymorphism
-  ArrayElemsCopied (std::unique_ptr<Expr> copied_elem,
+  ArrayElemsCopied (Analysis::NodeMapping mappings,
+		    std::unique_ptr<Expr> copied_elem,
 		    std::unique_ptr<Expr> copy_amount)
-    : elem_to_copy (std::move (copied_elem)),
+    : ArrayElems (mappings), elem_to_copy (std::move (copied_elem)),
       num_copies (std::move (copy_amount))
   {}
 
   // Copy constructor required due to unique_ptr - uses custom clone
   ArrayElemsCopied (ArrayElemsCopied const &other)
-    : elem_to_copy (other.elem_to_copy->clone_expr ()),
+    : ArrayElems (other), elem_to_copy (other.elem_to_copy->clone_expr ()),
       num_copies (other.num_copies->clone_expr ())
   {}


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

only message in thread, other threads:[~2022-07-28 15:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-28 15:35 [gcc/devel/rust/master] hir: Add mappings to ArrayElems 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).