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] libproc_macro: Add remaining drop functions
Date: Tue,  2 May 2023 07:09:32 +0000 (GMT)	[thread overview]
Message-ID: <20230502070932.8C4903858284@sourceware.org> (raw)

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

commit dc89a98af04d11796c679b9927aaf8bb62c0cb75
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Wed Apr 12 17:58:27 2023 +0200

    libproc_macro: Add remaining drop functions
    
    Remaining structures from the rust bridge that missed a drop function
    now have one.
    
    ChangeLog:
    
            * libgrust/libproc_macro/group.cc (Group::drop): Add drop
            implementation.
            * libgrust/libproc_macro/group.h: Add drop prototype.
            * libgrust/libproc_macro/tokenstream.cc (TokenStream::drop): Add
            drop implementation.
            (TokenStream__drop): Change to a call to TokenStream::drop.
            * libgrust/libproc_macro/tokenstream.h: Add drop prototype.
            * libgrust/libproc_macro/tokentree.cc (TokenTree::drop): Add
            drop implementation.
            * libgrust/libproc_macro/tokentree.h: Add drop prototype.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 libgrust/libproc_macro/group.cc       |  6 ++++++
 libgrust/libproc_macro/group.h        |  2 ++
 libgrust/libproc_macro/tokenstream.cc | 17 +++++++++++++----
 libgrust/libproc_macro/tokenstream.h  |  2 ++
 libgrust/libproc_macro/tokentree.cc   | 19 +++++++++++++++++++
 libgrust/libproc_macro/tokentree.h    |  2 ++
 6 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/libgrust/libproc_macro/group.cc b/libgrust/libproc_macro/group.cc
index e6fdce5f84e..c5948ed03c7 100644
--- a/libgrust/libproc_macro/group.cc
+++ b/libgrust/libproc_macro/group.cc
@@ -30,4 +30,10 @@ Group::make_group (TokenStream::TokenStream stream, Delimiter delim)
   return {delim, stream};
 }
 
+void
+Group::drop (Group *g)
+{
+  TokenStream::TokenStream::drop (&g->stream);
+}
+
 } // namespace Group
diff --git a/libgrust/libproc_macro/group.h b/libgrust/libproc_macro/group.h
index 09a7add70e0..bf2a23ff3ec 100644
--- a/libgrust/libproc_macro/group.h
+++ b/libgrust/libproc_macro/group.h
@@ -42,6 +42,8 @@ struct Group
 
 public:
   static Group make_group (TokenStream::TokenStream stream, Delimiter delim);
+
+  static void drop (Group *g);
 };
 
 } // namespace Group
diff --git a/libgrust/libproc_macro/tokenstream.cc b/libgrust/libproc_macro/tokenstream.cc
index b8116c1735a..921cc22bf13 100644
--- a/libgrust/libproc_macro/tokenstream.cc
+++ b/libgrust/libproc_macro/tokenstream.cc
@@ -64,6 +64,18 @@ TokenStream::push (TokenTree::TokenTree tree)
   size++;
 }
 
+void
+TokenStream::drop (TokenStream *stream)
+{
+  for (std::uint64_t i = 0; i < stream->size; i++)
+    {
+      TokenTree::TokenTree::drop (&stream->data[i]);
+    }
+  delete[] stream->data;
+  stream->capacity = 0;
+  stream->size = 0;
+}
+
 extern "C" TokenStream
 TokenStream__new ()
 {
@@ -101,10 +113,7 @@ TokenStream__clone (const TokenStream *ts)
 extern "C" void
 TokenStream__drop (TokenStream *stream)
 {
-  // FIXME: Also drop stream components
-  delete[] stream->data;
-  stream->capacity = 0;
-  stream->size = 0;
+  TokenStream::drop (stream);
 }
 
 } // namespace TokenStream
diff --git a/libgrust/libproc_macro/tokenstream.h b/libgrust/libproc_macro/tokenstream.h
index 513553e1b2b..909e6f441b2 100644
--- a/libgrust/libproc_macro/tokenstream.h
+++ b/libgrust/libproc_macro/tokenstream.h
@@ -49,6 +49,8 @@ public:
   static TokenStream make_tokenstream (std::vector<TokenTree::TokenTree> vec);
   static TokenStream make_tokenstream (std::uint64_t capacity
 				       = DEFAULT_CAPACITY);
+
+  static void drop (TokenStream *stream);
 };
 
 extern "C" TokenStream
diff --git a/libgrust/libproc_macro/tokentree.cc b/libgrust/libproc_macro/tokentree.cc
index fd9d9815a89..924e50c6f3b 100644
--- a/libgrust/libproc_macro/tokentree.cc
+++ b/libgrust/libproc_macro/tokentree.cc
@@ -56,4 +56,23 @@ TokenTree::make_tokentree (Literal::Literal literal)
   return {LITERAL, payload};
 }
 
+void
+TokenTree::drop (TokenTree *tt)
+{
+  switch (tt->tag)
+    {
+    case GROUP:
+      Group::Group::drop (&tt->payload.group);
+      break;
+    case IDENT:
+      Ident::Ident::drop (&tt->payload.ident);
+      break;
+    case LITERAL:
+      Literal::Literal::drop (&tt->payload.literal);
+      break;
+    case PUNCT:
+      break;
+    }
+}
+
 } // namespace TokenTree
diff --git a/libgrust/libproc_macro/tokentree.h b/libgrust/libproc_macro/tokentree.h
index a982bfcc1ee..86fc5eb2688 100644
--- a/libgrust/libproc_macro/tokentree.h
+++ b/libgrust/libproc_macro/tokentree.h
@@ -56,6 +56,8 @@ public:
   static TokenTree make_tokentree (Ident::Ident ident);
   static TokenTree make_tokentree (Punct::Punct punct);
   static TokenTree make_tokentree (Literal::Literal literal);
+
+  static void drop (TokenTree *tt);
 };
 
 } // namespace TokenTree

                 reply	other threads:[~2023-05-02  7:09 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=20230502070932.8C4903858284@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).