public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] hir: Add mappings to ArrayElems
Date: Thu, 28 Jul 2022 15:35:13 +0000 (GMT)	[thread overview]
Message-ID: <20220728153513.2FE803856DE3@sourceware.org> (raw)

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 ())
   {}


                 reply	other threads:[~2022-07-28 15:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220728153513.2FE803856DE3@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).