+/* Obstack for data temporarily allocated during parsing. Points to
+ the obstack in the rust_parser, or to a temporary obstack during
+ unit testing. */
+
+static auto_obstack *work_obstack;
+
+/* An instance of this is created before parsing, and destroyed when
+ parsing is finished. */
+
+struct rust_parser
+{
+ rust_parser (struct parser_state *state)
+ : rust_ast (nullptr),
+ pstate (state)
+ {
+ gdb_assert (current_parser == nullptr);
+ current_parser = this;
+ work_obstack = &obstack;
+ }
+
+ ~rust_parser ()
+ {
+ /* Clean up the globals we set. */
+ current_parser = nullptr;
+ work_obstack = nullptr;
+ }
+
+ /* Create a new rust_set_vector. The storage for the new vector is
+ managed by this class. */
+ rust_set_vector *new_set_vector ()
+ {
+ rust_set_vector *result = new rust_set_vector;
+ set_vectors.push_back (std::unique_ptr<rust_set_vector> (result));
+ return result;
+ }
+
+ /* Create a new rust_ops_vector. The storage for the new vector is
+ managed by this class. */
+ rust_op_vector *new_op_vector ()
+ {
+ rust_op_vector *result = new rust_op_vector;
+ op_vectors.push_back (std::unique_ptr<rust_op_vector> (result));
+ return result;
+ }
+
+ /* Return the parser's language. */
+ const struct language_defn *language () const
+ {
+ return parse_language (pstate);
+ }
+
+ /* Return the parser's gdbarch. */
+ struct gdbarch *arch () const
+ {
+ return parse_gdbarch (pstate);
+ }
+
+ /* A pointer to this is installed globally. */
+ auto_obstack obstack;
+
+ /* Result of parsing. Points into obstack. */
+ const struct rust_op *rust_ast;
+
+ /* This keeps track of the various vectors we allocate. */
+ std::vector<std::unique_ptr<rust_set_vector>> set_vectors;
+ std::vector<std::unique_ptr<rust_op_vector>> op_vectors;
+
+ /* The parser state gdb gave us. */
+ struct parser_state *pstate;
+};