+/* Pop a type list element from the global type stack. */
+
+static std::vector<struct type *> *
+pop_typelist (void)
+{
+ gdb_assert (!type_stack.elements.empty ());
+ type_stack_elt elt = type_stack.elements.back ();
+ type_stack.elements.pop_back ();
+ return elt.typelist_val;
+}
+
+/* Pop a type_stack element from the global type stack. */
+
+static struct type_stack *
+pop_type_stack (void)
+{
+ gdb_assert (!type_stack.elements.empty ());
+ type_stack_elt elt = type_stack.elements.back ();
+ type_stack.elements.pop_back ();
+ return elt.stack_val;
+}
+
+/* Append the elements of the type stack FROM to the type stack TO.
+ Always returns TO. */
+
+struct type_stack *
+append_type_stack (struct type_stack *to, struct type_stack *from)
+{
+ to->elements.insert (to->elements.end (), from->elements.begin (),
+ from->elements.end ());
+ return to;
+}
+
+/* Push the type stack STACK as an element on the global type stack. */
+
+void
+push_type_stack (struct type_stack *stack)
+{
+ type_stack_elt elt;
+ elt.stack_val = stack;
+ type_stack.elements.push_back (elt);
+ push_type (tp_type_stack);
+}
+
+/* Copy the global type stack into a newly allocated type stack and
+ return it. The global stack is cleared. The returned type stack
+ must be freed with delete. */
+
+struct type_stack *
+get_type_stack (void)
+{
+ struct type_stack *result = new struct type_stack (std::move (type_stack));
+ type_stack.elements.clear ();
+ return result;
+}
+
+/* Push a function type with arguments onto the global type stack.
+ LIST holds the argument types. If the final item in LIST is NULL,
+ then the function will be varargs. */
+
+void
+push_typelist (std::vector<struct type *> *list)
+{
+ type_stack_elt elt;
+ elt.typelist_val = list;
+ type_stack.elements.push_back (elt);
+ push_type (tp_function_with_arguments);
+}
+
+/* Pop the type stack and return a type_instance_flags that
+ corresponds the const/volatile qualifiers on the stack. This is
+ called by the C++ parser when parsing methods types, and as such no
+ other kind of type in the type stack is expected. */
+
+type_instance_flags
+follow_type_instance_flags ()
+{
+ type_instance_flags flags = 0;
+
+ for (;;)
+ switch (pop_type ())
+ {
+ case tp_end:
+ return flags;
+ case tp_const:
+ flags |= TYPE_INSTANCE_FLAG_CONST;
+ break;
+ case tp_volatile:
+ flags |= TYPE_INSTANCE_FLAG_VOLATILE;
+ break;
+ default:
+ gdb_assert_not_reached ("unrecognized tp_ value in follow_types");
+ }
+}
+
+