+ struct pr_handle *info = (struct pr_handle *) p;
+ char *t;
+
+ t = pop_type (info);
+ if (t == NULL)
+ return FALSE;
+
+ if (! tg_fix_visibility (info, visibility))
+ return FALSE;
+
+ /* It happens, a bug? */
+ if (! name[0])
+ return TRUE;
+
+ fprintf (info->f, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
+ name, info->filename, t, info->stack->flavor, info->stack->type,
+ visibility_name (visibility));
+
+ return TRUE;
+}
+
+/* Finish a struct type. */
+
+static bfd_boolean
+tg_end_struct_type (void *p ATTRIBUTE_UNUSED)
+{
+ assert (((struct pr_handle *) p)->stack != NULL);
+
+ return TRUE;
+}
+
+/* Start a class type. */
+
+static bfd_boolean
+tg_start_class_type (void *p, const char *tag, unsigned int id,
+ bfd_boolean structp, unsigned int size,
+ bfd_boolean vptr, bfd_boolean ownvptr)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char *tv = NULL;
+ const char *name;
+ char idbuf[20];
+
+ info->indent += 2;
+
+ if (vptr && ! ownvptr)
+ {
+ tv = pop_type (info);
+ if (tv == NULL)
+ return FALSE;
+ }
+
+ if (tag != NULL)
+ name = tag;
+ else
+ {
+ sprintf (idbuf, "%%anon%u", id);
+ name = idbuf;
+ }
+
+ if (! push_type (info, name))
+ return FALSE;
+
+ info->stack->flavor = structp ? "class" : "union class";
+ info->stack->parents = NULL;
+ info->stack->num_parents = 0;
+
+ if (size != 0 || vptr || ownvptr || tag != NULL)
+ {
+ if (vptr)
+ {
+ if (! append_type (info, " vtable "))
+ return FALSE;
+ if (ownvptr)
+ {
+ if (! append_type (info, "self "))
+ return FALSE;
+ }
+ else
+ {
+ if (! append_type (info, tv)
+ || ! append_type (info, " "))
+ return FALSE;
+ }
+ }
+ }
+
+ info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
+
+ return TRUE;
+}
+
+/* Add a static member to a class. */
+
+static bfd_boolean
+tg_class_static_member (void *p, const char *name,
+ const char *physname ATTRIBUTE_UNUSED,
+ enum debug_visibility visibility)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char *t;
+ int len_var, len_class;
+ char *full_name;
+
+ len_var = strlen (name);
+ len_class = strlen (info->stack->next->type);
+ full_name = (char *) xmalloc (len_var + len_class + 3);
+ if (! full_name)
+ return FALSE;
+ sprintf (full_name, "%s::%s", info->stack->next->type, name);
+
+ if (! substitute_type (info, full_name))
+ {
+ free (full_name);
+ return FALSE;
+ }
+
+ if (! prepend_type (info, "static "))
+ {
+ free (full_name);
+ return FALSE;
+ }
+
+ t = pop_type (info);
+ if (t == NULL)
+ {
+ free (full_name);
+ return FALSE;
+ }
+
+ if (! tg_fix_visibility (info, visibility))
+ {
+ free (t);
+ free (full_name);
+ return FALSE;
+ }
+
+ fprintf (info->f, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
+ name, info->filename, t, info->stack->type,
+ visibility_name (visibility));
+ free (t);
+ free (full_name);
+
+ return TRUE;
+}
+
+/* Add a base class to a class. */
+
+static bfd_boolean
+tg_class_baseclass (void *p, bfd_vma bitpos ATTRIBUTE_UNUSED,
+ bfd_boolean is_virtual, enum debug_visibility visibility)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char *t;
+ const char *prefix;
+
+ assert (info->stack != NULL && info->stack->next != NULL);
+
+ t = pop_type (info);
+ if (t == NULL)
+ return FALSE;
+
+ if (CONST_STRNEQ (t, "class "))
+ t += sizeof "class " - 1;
+
+ /* Push it back on to take advantage of the prepend_type and
+ append_type routines. */
+ if (! push_type (info, t))
+ return FALSE;
+
+ if (is_virtual)
+ {
+ if (! prepend_type (info, "virtual "))
+ return FALSE;
+ }
+
+ switch (visibility)
+ {
+ case DEBUG_VISIBILITY_PUBLIC:
+ prefix = "public ";
+ break;
+ case DEBUG_VISIBILITY_PROTECTED:
+ prefix = "protected ";
+ break;
+ case DEBUG_VISIBILITY_PRIVATE:
+ prefix = "private ";
+ break;
+ default:
+ prefix = "/* unknown visibility */ ";
+ break;
+ }
+
+ if (! prepend_type (info, prefix))
+ return FALSE;
+
+ t = pop_type (info);
+ if (t == NULL)
+ return FALSE;
+
+ if (info->stack->num_parents && ! append_parent (info, ", "))
+ return FALSE;
+
+ if (! append_parent (info, t))
+ return FALSE;
+ info->stack->num_parents++;
+
+ free (t);
+
+ return TRUE;
+}
+
+/* Add a variant to a method. */
+
+static bfd_boolean
+tg_class_method_variant (void *p, const char *physname ATTRIBUTE_UNUSED,
+ enum debug_visibility visibility,
+ bfd_boolean constp, bfd_boolean volatilep,
+ bfd_vma voffset ATTRIBUTE_UNUSED,
+ bfd_boolean context)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char *method_type;
+ char *context_type;
+ char *method_name;
+
+ assert (info->stack != NULL);
+ assert (info->stack->next != NULL);
+
+ /* Put the const and volatile qualifiers on the type. */
+ if (volatilep)
+ {
+ if (! append_type (info, " volatile"))
+ return FALSE;
+ }
+ if (constp)
+ {
+ if (! append_type (info, " const"))
+ return FALSE;
+ }
+
+ method_name = strdup (context ? info->stack->next->next->method
+ : info->stack->next->method);
+
+ /* Stick the name of the method into its type. */
+ if (! substitute_type (info, method_name))
+ {
+ free (method_name);
+ return FALSE;
+ }
+
+ /* Get the type. */
+ method_type = pop_type (info);
+ if (method_type == NULL)
+ {
+ free (method_name);
+ return FALSE;
+ }
+
+ /* Pull off the context type if there is one. */
+ if (! context)
+ context_type = NULL;
+ else
+ {
+ context_type = pop_type (info);
+ if (context_type == NULL)
+ {
+ free (method_type);
+ free (method_name);
+ return FALSE;
+ }
+ }
+
+ /* Now the top of the stack is the class. */
+ if (! tg_fix_visibility (info, visibility))
+ {
+ free (method_type);
+ free (method_name);
+ free (context_type);
+ return FALSE;
+ }
+
+ fprintf (info->f, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
+ method_name, info->filename, method_type, info->stack->type);
+ free (method_type);
+ free (method_name);
+ free (context_type);
+
+ return TRUE;
+}
+
+/* Add a static variant to a method. */
+
+static bfd_boolean
+tg_class_static_method_variant (void *p,
+ const char *physname ATTRIBUTE_UNUSED,
+ enum debug_visibility visibility,
+ bfd_boolean constp, bfd_boolean volatilep)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char *method_type;
+ char *method_name;
+
+ assert (info->stack != NULL);
+ assert (info->stack->next != NULL);
+ assert (info->stack->next->method != NULL);
+
+ /* Put the const and volatile qualifiers on the type. */
+ if (volatilep)
+ {
+ if (! append_type (info, " volatile"))
+ return FALSE;
+ }
+ if (constp)
+ {
+ if (! append_type (info, " const"))
+ return FALSE;
+ }
+
+ /* Mark it as static. */
+ if (! prepend_type (info, "static "))
+ return FALSE;
+
+ method_name = strdup (info->stack->next->method);
+ /* Stick the name of the method into its type. */
+ if (! substitute_type (info, info->stack->next->method))
+ {
+ free (method_name);
+ return FALSE;
+ }
+
+ /* Get the type. */
+ method_type = pop_type (info);
+ if (method_type == NULL)
+ {
+ free (method_name);
+ return FALSE;
+ }
+
+ /* Now the top of the stack is the class. */
+ if (! tg_fix_visibility (info, visibility))
+ {
+ free (method_type);
+ free (method_name);
+ return FALSE;
+ }
+
+ fprintf (info->f, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
+ method_name, info->filename, method_type, info->stack->type,
+ visibility_name (visibility));
+ free (method_type);
+ free (method_name);
+
+ return TRUE;
+}
+
+/* Finish up a class. */
+
+static bfd_boolean
+tg_end_class_type (void *p)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+
+ fprintf (info->f, "%s\t%s\t0;\"\tkind:c\ttype:%s", info->stack->type,
+ info->filename, info->stack->flavor);
+ if (info->stack->num_parents)
+ {
+ fprintf (info->f, "\tinherits:%s", info->stack->parents);
+ free (info->stack->parents);
+ }
+ fputc ('\n', info->f);
+
+ return tg_end_struct_type (p);
+}
+
+/* Push a type on the stack using a tag name. */
+
+static bfd_boolean
+tg_tag_type (void *p, const char *name, unsigned int id,
+ enum debug_type_kind kind)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ const char *t, *tag;
+ char idbuf[20];
+
+ switch (kind)
+ {
+ case DEBUG_KIND_STRUCT:
+ t = "struct ";
+ break;
+ case DEBUG_KIND_UNION:
+ t = "union ";
+ break;
+ case DEBUG_KIND_ENUM:
+ t = "enum ";
+ break;
+ case DEBUG_KIND_CLASS:
+ t = "class ";
+ break;
+ case DEBUG_KIND_UNION_CLASS:
+ t = "union class ";
+ break;
+ default:
+ abort ();
+ return FALSE;
+ }
+
+ if (! push_type (info, t))
+ return FALSE;
+ if (name != NULL)
+ tag = name;
+ else
+ {
+ sprintf (idbuf, "%%anon%u", id);
+ tag = idbuf;
+ }
+
+ if (! append_type (info, tag))
+ return FALSE;
+
+ return TRUE;
+}
+
+/* Output a typedef. */
+
+static bfd_boolean
+tg_typdef (void *p, const char *name)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char *s;
+
+ s = pop_type (info);
+ if (s == NULL)
+ return FALSE;
+
+ fprintf (info->f, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name,
+ info->filename, s);
+
+ free (s);
+
+ return TRUE;
+}
+
+/* Output a tag. The tag should already be in the string on the
+ stack, so all we have to do here is print it out. */
+
+static bfd_boolean
+tg_tag (void *p ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char *t;
+
+ t = pop_type (info);
+ if (t == NULL)
+ return FALSE;
+ free (t);
+
+ return TRUE;
+}
+
+/* Output an integer constant. */
+
+static bfd_boolean
+tg_int_constant (void *p, const char *name, bfd_vma val)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char ab[22];
+
+ indent (info);
+ print_vma (val, ab, FALSE, FALSE);
+ fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
+ name, info->filename, ab);
+ return TRUE;
+}
+
+/* Output a floating point constant. */
+
+static bfd_boolean
+tg_float_constant (void *p, const char *name, double val)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+
+ indent (info);
+ fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
+ name, info->filename, val);
+ return TRUE;
+}
+
+/* Output a typed constant. */
+
+static bfd_boolean
+tg_typed_constant (void *p, const char *name, bfd_vma val)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char *t;
+ char ab[22];
+
+ t = pop_type (info);
+ if (t == NULL)
+ return FALSE;
+
+ indent (info);
+ print_vma (val, ab, FALSE, FALSE);
+ fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
+ name, info->filename, t, ab);
+
+ free (t);
+
+ return TRUE;
+}
+
+/* Output a variable. */
+
+static bfd_boolean
+tg_variable (void *p, const char *name, enum debug_var_kind kind,
+ bfd_vma val ATTRIBUTE_UNUSED)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char *t, *dname, *from_class;
+
+ t = pop_type (info);
+ if (t == NULL)
+ return FALSE;
+
+ dname = NULL;
+ if (info->demangler)
+ dname = info->demangler (info->abfd, name, demangle_flags);
+
+ from_class = NULL;
+ if (dname != NULL)
+ {
+ char *sep;
+ sep = strstr (dname, "::");
+ if (sep)
+ {
+ *sep = 0;
+ name = sep + 2;
+ from_class = dname;
+ }
+ else
+ /* Obscure types as vts and type_info nodes. */
+ name = dname;
+ }
+
+ fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:%s", name, info->filename, t);
+
+ switch (kind)
+ {
+ case DEBUG_STATIC:
+ case DEBUG_LOCAL_STATIC:
+ fprintf (info->f, "\tfile:");
+ break;
+ case DEBUG_REGISTER:
+ fprintf (info->f, "\tregister:");
+ break;
+ default:
+ break;
+ }
+
+ if (from_class)
+ fprintf (info->f, "\tclass:%s", from_class);
+
+ if (dname)
+ free (dname);
+
+ fprintf (info->f, "\n");
+
+ free (t);
+
+ return TRUE;
+}
+
+/* Start outputting a function. */
+
+static bfd_boolean
+tg_start_function (void *p, const char *name, bfd_boolean global)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char *dname;
+
+ if (! global)
+ info->stack->flavor = "static";
+ else
+ info->stack->flavor = NULL;
+
+ dname = NULL;
+ if (info->demangler)
+ dname = info->demangler (info->abfd, name, demangle_flags);
+
+ if (! substitute_type (info, dname ? dname : name))
+ return FALSE;
+
+ info->stack->method = NULL;
+ if (dname != NULL)
+ {
+ char *sep;
+ sep = strstr (dname, "::");
+ if (sep)
+ {
+ info->stack->method = dname;
+ *sep = 0;
+ name = sep + 2;
+ }
+ else
+ {
+ info->stack->method = "";
+ name = dname;
+ }
+ sep = strchr (name, '(');
+ if (sep)
+ *sep = 0;
+ /* Obscure functions as type_info function. */
+ }
+
+ info->stack->parents = strdup (name);
+
+ if (! info->stack->method && ! append_type (info, "("))
+ return FALSE;
+
+ info->parameter = 1;
+
+ return TRUE;
+}
+
+/* Output a function parameter. */
+
+static bfd_boolean
+tg_function_parameter (void *p, const char *name, enum debug_parm_kind kind,
+ bfd_vma val ATTRIBUTE_UNUSED)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char *t;
+
+ if (kind == DEBUG_PARM_REFERENCE
+ || kind == DEBUG_PARM_REF_REG)
+ {
+ if (! pr_reference_type (p))
+ return FALSE;
+ }
+
+ if (! substitute_type (info, name))
+ return FALSE;
+
+ t = pop_type (info);
+ if (t == NULL)
+ return FALSE;
+
+ if (! info->stack->method)
+ {
+ if (info->parameter != 1 && ! append_type (info, ", "))
+ return FALSE;
+
+ if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
+ if (! append_type (info, "register "))
+ return FALSE;
+
+ if (! append_type (info, t))
+ return FALSE;
+ }
+
+ free (t);
+
+ ++info->parameter;
+
+ return TRUE;
+}
+
+/* Start writing out a block. */
+
+static bfd_boolean
+tg_start_block (void *p, bfd_vma addr)
+{
+ struct pr_handle *info = (struct pr_handle *) p;
+ char ab[22], kind, *partof;
+ char *t;
+ bfd_boolean local;
+
+ if (info->parameter > 0)
+ {
+ info->parameter = 0;
+
+ /* Delayed name. */
+ fprintf (info->f, "%s\t%s\t", info->stack->parents, info->filename);
+ free (info->stack->parents);
+
+ print_vma (addr, ab, TRUE, TRUE);
+ translate_addresses (info->abfd, ab, info->f, info->syms);
+ local = info->stack->flavor != NULL;
+ if (info->stack->method && *info->stack->method)
+ {
+ kind = 'm';
+ partof = (char *) info->stack->method;
+ }
+ else
+ {
+ kind = 'f';
+ partof = NULL;
+ if (! info->stack->method && ! append_type (info, ")"))
+ return FALSE;
+ }
+ t = pop_type (info);
+ if (t == NULL)
+ return FALSE;
+ fprintf (info->f, ";\"\tkind:%c\ttype:%s", kind, t);
+ if (local)
+ fputs ("\tfile:", info->f);
+ if (partof)
+ {
+ fprintf (info->f, "\tclass:%s", partof);
+ free (partof);
+ }
+ fputc ('\n', info->f);
+ }
+
+ return TRUE;
+}
+
+/* Write out line number information. */
+
+static bfd_boolean
+tg_lineno (void *p ATTRIBUTE_UNUSED, const char *fname ATTRIBUTE_UNUSED,
+ unsigned long lineno ATTRIBUTE_UNUSED,
+ bfd_vma addr ATTRIBUTE_UNUSED)
+{
+ return TRUE;
+}
+
+/* Finish writing out a block. */
+
+static bfd_boolean
+tg_end_block (void *p ATTRIBUTE_UNUSED, bfd_vma addr ATTRIBUTE_UNUSED)
+{
+ return TRUE;
+}
+
+/* Convert the visibility value into a human readable name. */
+
+static const char *
+visibility_name (enum debug_visibility visibility)
+{
+ const char *s;
+
+ switch (visibility)
+ {
+ case DEBUG_VISIBILITY_PUBLIC:
+ s = "public";
+ break;
+ case DEBUG_VISIBILITY_PRIVATE:
+ s = "private";
+ break;
+ case DEBUG_VISIBILITY_PROTECTED:
+ s = "protected";
+ break;
+ case DEBUG_VISIBILITY_IGNORE:
+ s = "/* ignore */";
+ break;
+ default:
+ abort ();
+ return FALSE;
+ }
+ return s;