[GCC-XML]Emitting mangled names in gccxml

Paul Ross gccxml at paulross.demon.co.uk
Sun Oct 26 06:54:46 EST 2003


It strikes me that that it might be useful emit the mangled names in 
the gccxml output. It would extend the usefulness of gccxml as an ABI 
and BC tool. The other neat feature of this is that mangled names can 
act as XML IDs since the name mangling encoding conforms with the 
requirements of an XML name and, naturally enough, the mangled name 
is unique.

I got this working today (I think!) with the following:

Add the function (the diff for $Revision: 1.61 $ is in the postscript):

/* Print the XML attribute mangled="..." for the given node.  */
static void
xml_print_name_mangled_attribute (xml_dump_info_p xdi, tree n)
{
   if (DECL_NAME (n) && DECL_ASSEMBLER_NAME (n) && DECL_ASSEMBLER_NAME 
(n) != DECL_NAME (n)) {
     const char* name = xml_get_encoded_string (DECL_ASSEMBLER_NAME (n));
     fprintf (xdi->file, " mangled=\"%s\"", name);
   }
}

In xml_output_namespace_decl () add:
     xml_print_name_mangled_attribute (xdi, ns);

In xml_output_function_decl () add:
   xml_print_name_mangled_attribute (xdi, fd);

In xml_output_field_decl () add:
   xml_print_name_mangled_attribute (xdi, fd);

In xml_output_record_type () add:
   xml_print_name_mangled_attribute (xdi, TYPE_NAME(rt));

It seems to work but I am not really sure if I have covered everything.

Cheers,

Paul Ross

diff for xml.c $Revision: 1.61 $:

paul% diff -u xml.c xml_mangle.c
--- xml.c       Sun Oct  5 14:15:08 2003
+++ xml_mangle.c        Sun Oct 26 11:40:51 2003
@@ -492,6 +492,16 @@
    fprintf (xdi->file, " name=\"%s\"", name);
  }

+/* Print the XML attribute mangled="..." for the given node.  */
+static void
+xml_print_name_mangled_attribute (xml_dump_info_p xdi, tree n)
+{
+  if (DECL_NAME (n) && DECL_ASSEMBLER_NAME (n) && 
DECL_ASSEMBLER_NAME (n) != DECL_NAME (n)) {
+    const char* name = xml_get_encoded_string (DECL_ASSEMBLER_NAME (n));
+    fprintf (xdi->file, " mangled=\"%s\"", name);
+  }
+}
+
  /* Print the XML attribute type="..." for the given type.  If the type
     has cv-qualifiers, they are appended to the type's id as single
     characters (c=const, v=volatile, r=restrict).  */
@@ -502,9 +512,9 @@
    const char* ch_volatile = "";
    const char* ch_restrict = "";
    int id = xml_add_node (xdi, TYPE_MAIN_VARIANT(t), complete);
-  if (CP_TYPE_CONST_P (t)) { ch_const = "c"; }
-  if (CP_TYPE_VOLATILE_P (t)) { ch_volatile = "v"; }
-  if (CP_TYPE_RESTRICT_P (t)) { ch_restrict = "r"; }
+               if (CP_TYPE_CONST_P (t)) { ch_const = "c"; }
+               if (CP_TYPE_VOLATILE_P (t)) { ch_volatile = "v"; }
+               if (CP_TYPE_RESTRICT_P (t)) { ch_restrict = "r"; }
    fprintf (xdi->file, " type=\"_%d%s%s%s\"",
             id, ch_const, ch_volatile, ch_restrict);
  }
@@ -792,6 +802,7 @@
      fprintf (xdi->file, "  <Namespace");
      xml_print_id_attribute (xdi, dn);
      xml_print_name_attribute (xdi, DECL_NAME (ns));
+    xml_print_name_mangled_attribute (xdi, ns);
      xml_print_context_attribute (xdi, ns);
      xml_print_attributes_attribute (xdi, GCC_XML_DECL_ATTRIBUTES(ns), 0);

@@ -1007,6 +1018,7 @@
    fprintf (xdi->file, "  <%s", tag);
    xml_print_id_attribute (xdi, dn);
    xml_print_name_attribute (xdi, name);
+  xml_print_name_mangled_attribute (xdi, fd);

    if(do_returns)
      {
@@ -1095,6 +1107,7 @@
    fprintf (xdi->file, "  <Field");
    xml_print_id_attribute (xdi, dn);
    xml_print_name_attribute (xdi, DECL_NAME (fd));
+  xml_print_name_mangled_attribute (xdi, fd);
    xml_print_access_attribute (xdi, fd);
    /* TODO: handle bit field case.  */
    xml_print_type_attribute (xdi, TREE_TYPE (fd), dn->complete);
@@ -1124,6 +1137,7 @@
    fprintf (xdi->file, "  <%s", tag);
    xml_print_id_attribute (xdi, dn);
    xml_print_name_attribute (xdi, DECL_NAME (TYPE_NAME (rt)));
+  xml_print_name_mangled_attribute (xdi, TYPE_NAME(rt));
    xml_print_context_attribute (xdi, TYPE_NAME (rt));
    xml_print_access_attribute (xdi, TYPE_NAME (rt));
    xml_print_abstract_attribute (xdi, rt);




More information about the gccxml mailing list