Remaining structures from the rust bridge that missed a drop function
now have one.
libgrust/ChangeLog:
* libproc_macro/group.cc (Group::drop): Add drop
implementation.
* libproc_macro/group.h: Add drop prototype.
* libproc_macro/tokenstream.cc (TokenStream::drop): Add
drop implementation.
(TokenStream__drop): Change to a call to TokenStream::drop.
* libproc_macro/tokenstream.h: Add drop prototype.
* libproc_macro/tokentree.cc (TokenTree::drop): Add
drop implementation.
* libproc_macro/tokentree.h: Add drop prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
return {delim, stream};
}
+void
+Group::drop (Group *g)
+{
+ TokenStream::TokenStream::drop (&g->stream);
+}
+
} // namespace Group
public:
static Group make_group (TokenStream::TokenStream stream, Delimiter delim);
+
+ static void drop (Group *g);
};
} // namespace Group
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 ()
{
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
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
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
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