+/* If FULL_NAME is the demangled name of a C++ function (including an
+ arg list, possibly including namespace/class qualifications),
+ return a new string containing only the function name (without the
+ arg list/class qualifications). Otherwise, return NULL. The
+ caller is responsible for freeing the memory in question. */
+
+char *
+cp_func_name (const char *full_name)
+{
+ char *ret;
+ struct demangle_component *ret_comp;
+ int done;
+
+ ret_comp = cp_demangled_name_to_comp (full_name, NULL);
+ if (!ret_comp)
+ return NULL;
+
+ ret_comp = unqualified_name_from_comp (ret_comp);
+
+ ret = NULL;
+ if (ret_comp != NULL)
+ ret = cp_comp_to_string (ret_comp, 10);
+
+ return ret;
+}
+
+/* DEMANGLED_NAME is the name of a function, including parameters and
+ (optionally) a return type. Return the name of the function without
+ parameters or return type, or NULL if we can not parse the name. */
+
+char *
+cp_remove_params (const char *demangled_name)
+{
+ int done = 0;
+ struct demangle_component *ret_comp;
+ char *ret = NULL;
+
+ if (demangled_name == NULL)
+ return NULL;
+
+ ret_comp = cp_demangled_name_to_comp (demangled_name, NULL);
+ if (ret_comp == NULL)
+ return NULL;
+
+ /* 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;
+ }
+
+ /* What we have now should be a function. Return its name. */
+ if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
+ ret = cp_comp_to_string (d_left (ret_comp), 10);
+
+ return ret;
+}
+