+ done = 0;
+
+ /* First strip off any qualifiers, if we have a function or method. */
+ while (!done)
+ switch (ret_comp->type)
+ {
+ case DEMANGLE_COMPONENT_CONST:
+ case DEMANGLE_COMPONENT_RESTRICT:
+ case DEMANGLE_COMPONENT_VOLATILE:
+ case DEMANGLE_COMPONENT_CONST_THIS:
+ case DEMANGLE_COMPONENT_RESTRICT_THIS:
+ case DEMANGLE_COMPONENT_VOLATILE_THIS:
+ case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
+ ret_comp = d_left (ret_comp);
+ break;
+ default:
+ done = 1;
+ break;
+ }
+
+ /* If what we have now is a function, discard the argument list. */
+ if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
+ ret_comp = d_left (ret_comp);
+
+ /* If what we have now is a template, strip off the template
+ arguments. The left subtree may be a qualified name. */
+ if (ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE)
+ ret_comp = d_left (ret_comp);
+
+ /* What we have now should be a name, possibly qualified. Additional
+ qualifiers could live in the left subtree or the right subtree. Find
+ the last piece. */
+ done = 0;
+ prev_comp = NULL;
+ cur_comp = ret_comp;
+ while (!done)
+ switch (cur_comp->type)
+ {
+ case DEMANGLE_COMPONENT_QUAL_NAME:
+ case DEMANGLE_COMPONENT_LOCAL_NAME:
+ prev_comp = cur_comp;
+ cur_comp = d_right (cur_comp);
+ break;
+ case DEMANGLE_COMPONENT_TEMPLATE:
+ case DEMANGLE_COMPONENT_NAME:
+ case DEMANGLE_COMPONENT_CTOR:
+ case DEMANGLE_COMPONENT_DTOR:
+ case DEMANGLE_COMPONENT_OPERATOR:
+ case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
+ done = 1;
+ break;
+ default:
+ done = 1;
+ cur_comp = NULL;
+ break;
+ }
+
+ ret = NULL;
+ if (cur_comp != NULL && prev_comp != NULL)