public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Lorenzo Delana <ldelana@libero.it>
To: gcc@gcc.gnu.org
Cc: Matt Austern <austern@apple.com>
Subject: Re: -fdump-translation-unit-xml ( patch )
Date: Mon, 30 Sep 2002 23:57:00 -0000	[thread overview]
Message-ID: <200210010719.38272.ldelana@libero.it> (raw)
In-Reply-To: <BCF7F07C-D49F-11D6-A787-00039390D9E0@apple.com>

[-- Attachment #1: Type: text/plain, Size: 12250 bytes --]


Here is the patch to let a gcc switch `-fdump-translation-unit-xml' to dump 
the .tu file containing an xml like this produced:

~ $ ~/cc1plus -fdump-translation-unit-xml simple.cxx
 X::A<T>::A() virtual X::A<T>::~A() int X::A<T>::fn(int) int X::A<T>::fn(int, 
int)Opening simple.cxx for phase 1 suffix = .class
Opening simple.cxx for phase 0 suffix = .tu
Opened simple.cxx for phase 0

Execution times (seconds)
 varconst              :   0.02 (67%) usr   0.00 ( 0%) sys   0.02 (67%) wall
 TOTAL                 :   0.03             0.00             0.03
~ $ head -n 20 simple.cxx.tu
<?xml version='1.0'?>
<!DOCTYPE GXXTranslationUnit SYSTEM "GXXTranslationUnit.dtd">
<GXXTranslationUnit>

 <node index="1" codename="namespace_decl">
  <field type="_c_" name="name" value="2"/>
  <field type="_s_" name="srcp" value="&lt;internal&gt;:0"/>
  <field type="_c_" name="dcls" value="3"/>
 </node>

 <node index="2" codename="identifier_node">
  <field type="_s_" name="strg" value="::"/>
  <field type="_i_" name="lngt" value="2"/>
 </node>

 <node index="3" codename="namespace_decl">
  <field type="_c_" name="name" value="4"/>
  <field type="_c_" name="type" value="5"/>
  <field type="_s_" name="srcp" value="simple.cxx:2"/>
  <field type="_c_" name="chan" value="6"/>
~ $ tail simple.cxx.tu
  <field type="_s_" name="srcp" value="&lt;internal&gt;:0"/>
  <field type="_c_" name="chan" value="423"/>
 </node>

 <node index="846" codename="identifier_node">
  <field type="_s_" name="strg" value="__builtin_ptrdiff_t"/>
  <field type="_i_" name="lngt" value="19"/>
 </node>

</GXXTranslationUnit>

Notes:

a - admin questions:

 a1 - the patch sync'ed with CVS files: gcc/tree.h, gcc/tree-dump.c sync at 
the time Tue Oct  1 03:19 UTC 2002 ( so i recently )

 a2 - I build and tested this patch with my gcc-3.2 and works as demonstrated 
in the upper region of the email

 a3 - someone would apply this patch to gcc from CVS ( I cannot download 
entire cvs version, because my 5kmodem ), simply by copying files tree.h-diff 
and tree-dump.c-diff in the gcc/gcc dir and then patch < (diff-file) for each 
one. To test use `-fdump-translation-unit' and produce the TU that gcc 
produces before the patch, then `-fdump-translation-unit-xml' produces the TU 
with XML formatting.

 a4 - if <<... approved ...>>, someone could commit this thing?

g - general questions:
 
 g1 - the DTD: choosing a DTD is an hard thing, or choosing the right DTD is 
an hard thing... in any case I propose this, the resulting DTD from 
modification may be correct any if different, but consider that this DTD is 
very simple and inobtrusive respect the original TU format:

******************************************
*** FIRST ( implemented in patch ) DTD ***

<!ELEMENT GXXTranslationUnit (node*)>
<!ELEMENT node (field*)>
<!ATTLIST node index CDATA #REQUIRED
               codename CDATA #REQUIRED>

<!ELEMENT field EMPTY>
<!ATTLIST field type (_c_,_p_,_i_,_s_) #REQUIRED
                name CDATA #IMPLIED
                value CDATA #REQUIRED>

Example:
<?xml version='1.0'?>
<!DOCTYPE GXXTranslationUnit SYSTEM "GXXTranslationUnit.dtd">
<GXXTranslationUnit>

 <node index="1" codename="namespace_decl">
  <field type="_s_" name="name" value="2"/>
  <field type="_s_" name="srcp" value="&lt;internal&gt;:0"/>
  <field type="_s_" name="dcls" value="3"/>
 </node>

</GXXTranslationUnit>

 g1-2 - The `type' field of the `node' element is the only thing added to the 
TU informations that you can retrieve from the actual tu format... and this 
type serve to eliminate the ambiguities about the the type to convert the 
`value' field of the node ( that's a string ) to a correct type.

 Note: the "srcp" TU field ( source pos ) doesn't need a particular type, like 
as for "qual" TU field ( qualifier ) because they are strings... 

 NOTE: maybe possible reduce the DTD to this:
******************
*** SECOND DTD ***
<!ELEMENT GXXTranslationUnit (node*)>
<!ELEMENT node (child*,leaf*)>
<!ATTLIST node index CDATA #REQUIRED
               codename CDATA #REQUIRED>

<!ELEMENT child EMPTY>
<!ATTLIST child name CDATA #REQUIRED
                value CDATA #REQUIRED>

<!ELEMENT leaf EMPTY>
<!ATTLIST leaf name CDATA #IMPLIED
               value CDATA #REQUIRED>

Prev. example:

<?xml version='1.0'?>
<!DOCTYPE GXXTranslationUnit SYSTEM "GXXTranslationUnit.dtd">
<GXXTranslationUnit>

 <node index="1" codename="namespace_decl">
  <child name="name" value="2"/>
  <leaf name="srcp" value="&lt;internal&gt;:0"/>
  <child name="dcls" value="3"/>
 </node>

</GXXTranslationUnit>

This XML sample states only `child' and 'leaf' node fields... ( only two types 
)

 NOTE: at most ( of reduction ) the DTD may be:
*****************
*** THIRD DTD ***

<!ELEMENT GXXTranslationUnit (node*)>
<!ELEMENT node (child*,leaf*)>
<!ATTLIST node index CDATA #REQUIRED
               codename CDATA #REQUIRED>

<!ELEMENT field EMPTY>
<!ATTLIST field name CDATA #REQUIRED
                value CDATA #REQUIRED>

Prev. example:

<?xml version='1.0'?>
<!DOCTYPE GXXTranslationUnit SYSTEM "GXXTranslationUnit.dtd">
<GXXTranslationUnit>

 <node index="1" codename="namespace_decl">
  <field name="name" value="@2"/>
  <field name="srcp" value="&lt;internal&gt;:0"/>
  <field name="dcls" value="@3"/>
 </node>

</GXXTranslationUnit>

Note that in this last case, I must encode the type "child" with @ start 
symbol... but what happens if I would, for example, to encode a node, with a 
field that's supposed to be a string where the value starts with '@' ? 
AMBIGUITIES... as demonstrated by this actual TU dump sample ( where a simple 
.cxx file with a const string "@ciao" is preprocessed ):
@52     string_cst       type: @78     strg: @ciao    lngt: 6

So I suppose that the second DTD may be correct, but I implemented for the 
first DTD that reflect in some aspect the follow tree-dump.c routines:
- dump_index : CHILD
- dump_pointer : POINTER
- dump_int : INT
- dump_string : STRING


[----- hear this, please:

Finally: I ask someone that know ( I don't, exactly ) the AST of the GCC and 
future direction to get a feedback where is opinable to change this patch 
from first DTD to the second, or another one...

YEap, the question maybe if from a field name I can get the exact type of the 
value it states.

-----]

d - devel questions:

 d1 - the code is organized by static functions:
	* static void dump_xml_field PARAMS ((dump_info_p, xml_field_type, const 
char*, const char*, ...));
	* static void dump_xml_string PARAMS ((dump_info_p, const char*));

 d2 - and this ( c-source ) typedef
	* typedef enum {
	  xml_field_child_type,
	  xml_field_pointer_type,
	  xml_field_integer_type,
	  xml_field_string_type
	} xml_field_type;

  - with a macro:

	#define XML_FIELD_TYPE_GET_NAME(_t_)                    \
	(((_t_) == xml_field_child_type) ? "_c_" :              \
	 (((_t_) == xml_field_pointer_type) ? "_p_" :           \
	  (((_t_) == xml_field_integer_type) ? "_i_" :          \
	   (((_t_) == xml_field_string_type) ? "_s_" : NULL))))

  used in the dump rules...
  also this macro defines the root node name:
	#define XML_GXX_TU_DOCTYPE "GXXTranslationUnit"

 d3 - for each part where a dump on the stream is made there is a choose on 
the dump info flag and if XML mode ( TDF_XML ) is enabled nothing but xml is 
dumped out; for example follow code:

/* Print the node index.  */
  dump_index (di, index);
  /* And the type of node this is.  */
  if (dni->binfo_p)
    code_name = "binfo";
  else
    code_name = tree_code_name[(int) TREE_CODE (t)];
  fprintf (di->stream, "%-16s ", code_name);
  di->column = 25;

== changed to ==>

/* Determine the type of node this is */
  if (dni->binfo_p)
    code_name = "binfo";
  else
    code_name = tree_code_name[(int) TREE_CODE (t)];

  if (di->flags != TDF_XML)
    {
      /* Print the node index.  */
      dump_index (di, index);
      /* And the type of node this is.  */
      fprintf (di->stream, "%-16s ", code_name);
      di->column = 25;
    }
  else
    fprintf (di->stream, "\n <node index=\"%u\" codename=\"%s\">\n", index, 
code_name );

 d4 - the two functions dump_xml_{field,string} serves as dumper for an XML 
field, where the <node index="xxx" codename="yyy"> is opened and for dumping 
a string as xml string ( with & < > ' " changes to &amp; &lt; &gt; ... );
for example:

/* Print the index of the node.  */
  if (di->flags == TDF_XML)
    dump_xml_field (di, xml_field_child_type, field, "%u", index); // <==
  else
    {
      dump_maybe_newline (di);
      fprintf (di->stream, "%-4s: ", field);
      di->column += 6;
      dump_index (di, index);
    }

* di - dump info ( to get the stream output with out purpose )
* xml_field_child_type - I say to `dump_xml_field' that the type is, in the 
enumerative typedef of the type `xml_field_type', a "child" type; This is 
used to print out the "type" attribute of the "field" xml element.
* "%u", index - a printf like format to print what you want ( var arg )
 Note on `dump_xml_field' memory allocation: the "value" attribute of the 
field may contains some xml unescaped characters like for the string 
"<internal:0>" that must came "&lt;internal:0&gt;"; I don't use at this time 
the `dump_xml_string' because, I cannot use formatting needed for example 
when dump an `srcp' field ( "%s:%d", filename, lineno )... so xml_dump_field, 
supply the generation of the string to pass to `dump_xml_string' by using 
vsnprintf and to have a temp string buffer length enough an automatic memory 
reallocation mechanism is used, conform to glibc 2.0.6 and glibc>=2.1 ( 
eg.vsnprintf can return -1 or ( >0 = nr.char needed )... this tmpbuf string 
is a static char* and never freed but consuming only the max string lenght 
printed out +/- a chunk of bytes equal to a parameter static in the function 
itself called `tmpbuf_size_chunk' actually 25... To debug this tremendous 
behavior :)... simply add a printf here:

if ((vsnprintf_ret == -1) || (vsnprintf_ret > tmpbuf_size-1))
        {
          tmpbuf_size += tmpbuf_size_chunk;
	  printf( "EXPANDING tmpbuf to %d\n", tmpbuf_size );
          tmpbuf = (char*)xrealloc (tmpbuf, tmpbuf_size);
        }

and sets tmpbuf_size_chunk to 8, for example...

 d5 - the flag -fdump-translation-unit-xml are enabled by adding in 
gcc/tree-dump.c: `dump_options' array, an entry referring the TDF_XML 
constant added in the gcc/tree.h after TDF_SLIM to the next bit free ( 1L<<2)

 d6 - TODO: evenutally, but I don't see the need... let a phase with an .xml 
extension output instead to use .tu extension... Actually a .tu file is 
generated containing XML if -f..-xml is given.


On Monday 30 September 2002 18:09, Matt Austern wrote:
> On Saturday, September 28, 2002, at 11:01 AM, Lorenzo Delana wrote:
> > If you try to parse the result to `-fdump-translation-unit' you meet
> > some
> > problems specially for the question about where a string end, etc..
> > This problem was addressed in the past by someone in this list...
>
> Not a direct response, but this reminded me of something
> I'd been meaning to bring up before...
>
> -fdump-translation-unit is very useful, but I'd describe it more
> as human-parsable than as human-readable.  You can step
> through it by hand, but it's essentially impossible to use it to
> understand anything about tree structure at a glance.
>
> At Apple, we've developed an alternative tree dumper that's
> less useful for reading by machine, but much more human
> readable.  We've found our alternative tree dumper to be very
> useful for debugging.
>
> Is there any interest in an alternative tree dumper?  If so, we'd
> be very happy to talk some more about it, to show some
> examples of the tree dumps it produces, and to clean up the
> code for a patch.
>
> And just to state the obvious: we don't think of this as a
> replacement for -fdump-translation-unit.  We think of the two
> tree dumpers as complementary.
>
> 			--Matt

[-- Attachment #2: tree.h-diff --]
[-- Type: text/x-diff, Size: 426 bytes --]

--- /home/delana/gcc-20021001_0319/gcc/tree.h	2002-10-01 03:19:37.000000000 +0000
+++ tree.h	2002-10-01 05:40:16.000000000 +0000
@@ -3097,6 +3097,7 @@
    values, extend the DUMP_OPTIONS array in tree-dump.c */
 #define TDF_ADDRESS	(1 << 0)	/* dump node addresses */
 #define TDF_SLIM	(1 << 1)	/* don't go wild following links */
+#define TDF_XML (1 << 2)  /* dump in XML format */
 
 typedef struct dump_info *dump_info_p;
 

[-- Attachment #3: tree-dump.c-diff --]
[-- Type: text/x-diff, Size: 10875 bytes --]

--- /home/delana/gcc-20021001_0319/gcc/tree-dump.c	2002-10-01 03:19:37.000000000 +0000
+++ tree-dump.c	2002-10-01 06:29:44.000000000 +0000
@@ -35,6 +35,25 @@
 static void dump_maybe_newline PARAMS ((dump_info_p));
 static void dump_string_field PARAMS ((dump_info_p, const char *, const char *));
 
+#define XML_GXX_TU_DOCTYPE "GXXTranslationUnit"
+
+typedef enum {
+  xml_field_child_type,
+  xml_field_pointer_type,
+  xml_field_integer_type,
+  xml_field_string_type
+} xml_field_type;
+
+#define XML_FIELD_TYPE_GET_NAME(_t_)                    \
+(((_t_) == xml_field_child_type) ? "_c_" :              \
+ (((_t_) == xml_field_pointer_type) ? "_p_" :           \
+  (((_t_) == xml_field_integer_type) ? "_i_" :          \
+   (((_t_) == xml_field_string_type) ? "_s_" : NULL))))
+
+static void dump_xml_field PARAMS ((dump_info_p, xml_field_type, const char*,
+                                    const char*, ...));
+static void dump_xml_string PARAMS ((dump_info_p, const char*));
+
 /* Add T to the end of the queue of nodes to dump.  Returns the index
    assigned to T.  */
 
@@ -116,10 +135,15 @@
     index = queue (di, t, flags);
 
   /* Print the index of the node.  */
-  dump_maybe_newline (di);
-  fprintf (di->stream, "%-4s: ", field);
-  di->column += 6;
-  dump_index (di, index);
+  if (di->flags == TDF_XML)
+    dump_xml_field (di, xml_field_child_type, field, "%u", index);
+  else
+    {
+      dump_maybe_newline (di);
+      fprintf (di->stream, "%-4s: ", field);
+      di->column += 6;
+      dump_index (di, index);
+    }
 }
 
 /* Dump the type of T.  */
@@ -144,6 +168,7 @@
 dump_new_line (di)
      dump_info_p di;
 {
+  if (di->flags == TDF_XML) return;
   fprintf (di->stream, "\n%*s", SOL_COLUMN, "");
   di->column = SOL_COLUMN;
 }
@@ -156,6 +181,8 @@
 {
   int extra;
 
+  if (di->flags == TDF_XML) return;
+
   /* See if we need a new line.  */
   if (di->column > EOL_COLUMN)
     dump_new_line (di);
@@ -175,9 +202,14 @@
      const char *field;
      void *ptr;
 {
-  dump_maybe_newline (di);
-  fprintf (di->stream, "%-4s: %-8lx ", field, (long) ptr);
-  di->column += 15;
+  if (di->flags == TDF_XML)
+    dump_xml_field (di, xml_field_pointer_type, field, "%lx", (long)ptr);
+  else
+    {      
+      dump_maybe_newline (di);
+      fprintf (di->stream, "%-4s: %-8lx ", field, (long) ptr);
+      di->column += 15;
+    }
 }
 
 /* Dump integer I using FIELD to identify it.  */
@@ -188,9 +220,14 @@
      const char *field;
      int i;
 {
-  dump_maybe_newline (di);
-  fprintf (di->stream, "%-4s: %-7d ", field, i);
-  di->column += 14;
+  if (di->flags == TDF_XML)
+    dump_xml_field (di, xml_field_integer_type, field, "%d", i);
+  else
+    {      
+      dump_maybe_newline (di);
+      fprintf (di->stream, "%-4s: %-7d ", field, i);
+      di->column += 14;
+    }
 }
 
 /* Dump the string S.  */
@@ -200,12 +237,17 @@
      dump_info_p di;
      const char *string;
 {
-  dump_maybe_newline (di);
-  fprintf (di->stream, "%-13s ", string);
-  if (strlen (string) > 13)
-    di->column += strlen (string) + 1;
+  if (di->flags == TDF_XML)
+    dump_xml_field (di, xml_field_string_type, NULL, "%s", string);
   else
-    di->column += 14;
+    {
+      dump_maybe_newline (di);
+      fprintf (di->stream, "%-13s ", string);
+      if (strlen (string) > 13)
+        di->column += strlen (string) + 1;
+      else
+        di->column += 14;
+    }
 }
 
 /* Dump the string field S.  */
@@ -216,12 +258,110 @@
      const char *field;
      const char *string;
 {
-  dump_maybe_newline (di);
-  fprintf (di->stream, "%-4s: %-7s ", field, string);
-  if (strlen (string) > 7)
-    di->column += 6 + strlen (string) + 1;
+  if (di->flags == TDF_XML)
+    dump_xml_field (di, xml_field_string_type, field, "%s", string);
   else
-    di->column += 14;
+    {
+      dump_maybe_newline (di);
+      fprintf (di->stream, "%-4s: %-7s ", field, string);
+      if (strlen (string) > 7)
+        di->column += 6 + strlen (string) + 1;
+      else
+        di->column += 14;
+    }
+}
+
+/* Dump the given string in xml-escaped mode */
+
+static void
+dump_xml_string (di, str)
+     dump_info_p di;
+     const char* str;
+{
+  if (str == NULL) return;
+  while (*str)
+    {
+      switch (*str)
+        {
+        case '&':
+          fprintf (di->stream, "&amp;");
+          break;
+        case '\'':
+          fprintf (di->stream, "&apos;");
+          break;
+        case '>':
+          fprintf (di->stream, "&gt;");
+          break;
+        case '<':
+          fprintf (di->stream, "&lt;");
+          break;
+        case '"':
+          fprintf (di->stream, "&quot;");
+          break;
+        default:
+          fprintf (di->stream, "%c", *str);
+        }
+      str++;
+    }
+}
+
+/* Dump the given xml field and its attributes */
+
+static void
+dump_xml_field (di, type, name, value)
+     dump_info_p di;
+     xml_field_type type;
+     const char* name;
+     const char* value;
+{
+  static char* tmpbuf = NULL;
+  static int tmpbuf_size_chunk = 25;
+  static int tmpbuf_size = 0;
+  int vsnprintf_ret;
+
+  // dump the xml `field' element ( open mark )
+  fprintf (di->stream, "  <field ");
+
+  // dump the `type' attribute of the xml `field' element ( xml-unescaped )
+  fprintf (di->stream, "type=\"%s\" ", XML_FIELD_TYPE_GET_NAME (type));
+
+  // dump the `name' attribute of the xml `field' element ( xml-unescaped )
+  if (name) fprintf (di->stream, "name=\"%s\" ", name);
+
+  // allocate a minimal string buffer, if needed
+  if (tmpbuf==NULL)
+    {
+      tmpbuf_size += tmpbuf_size_chunk;
+      tmpbuf = (char*)xmalloc(tmpbuf_size);
+    }
+
+  // print in the string buffer, extending it if necessary, the
+  // `value' attribute of the xml `field' element ( xml-unescaped )
+  VA_OPEN (ap, value);
+  VA_FIXEDARG (ap, dump_info_p, di);
+  VA_FIXEDARG (ap, xml_field_type, type);
+  VA_FIXEDARG (ap, const char*, name);
+
+  while (1)
+    {
+      vsnprintf_ret = vsnprintf (tmpbuf, tmpbuf_size-1, value, ap);
+      if ((vsnprintf_ret == -1) || (vsnprintf_ret > tmpbuf_size-1))
+        {
+          tmpbuf_size += tmpbuf_size_chunk;
+          tmpbuf = (char*)xrealloc (tmpbuf, tmpbuf_size);
+        }
+      else break;
+    }
+
+  VA_CLOSE (ap);
+
+  // then dump the `value' field attribute as xml-escaped string
+  fprintf (di->stream, "value=\"");
+  dump_xml_string (di, tmpbuf);
+  fprintf (di->stream, "\"");
+
+  // dump the xml `field' element ( close mark )
+  fprintf (di->stream, "/>\n");
 }
 
 /* Dump the next node in the queue.  */
@@ -253,15 +393,22 @@
   dq->next = di->free_list;
   di->free_list = dq;
 
-  /* Print the node index.  */
-  dump_index (di, index);
-  /* And the type of node this is.  */
+  /* Determine the type of node this is */
   if (dni->binfo_p)
     code_name = "binfo";
   else
     code_name = tree_code_name[(int) TREE_CODE (t)];
-  fprintf (di->stream, "%-16s ", code_name);
-  di->column = 25;
+
+  if (di->flags != TDF_XML)
+    {
+      /* Print the node index.  */
+      dump_index (di, index);
+      /* And the type of node this is.  */
+      fprintf (di->stream, "%-16s ", code_name);
+      di->column = 25;
+    }
+  else    
+    fprintf (di->stream, "\n <node index=\"%u\" codename=\"%s\">\n", index, code_name );
 
   /* Figure out what kind of node this is.  */
   code = TREE_CODE (t);
@@ -334,10 +481,15 @@
 	    /* Skip the slash.  */
 	    ++filename;
 
-	  dump_maybe_newline (di);
-	  fprintf (di->stream, "srcp: %s:%-6d ", filename,
-		   DECL_SOURCE_LINE (t));
-	  di->column += 6 + strlen (filename) + 8;
+    if (di->flags != TDF_XML)
+      {
+        dump_maybe_newline (di);
+        fprintf (di->stream, "srcp: %s:%-6d ", filename,
+                 DECL_SOURCE_LINE (t));
+        di->column += 6 + strlen (filename) + 8;
+      }
+    else
+      dump_xml_field (di, xml_field_string_type, "srcp", "%s:%d", filename, DECL_SOURCE_LINE (t));
 	}
       /* And any declaration can be compiler-generated.  */
       if (DECL_ARTIFICIAL (t))
@@ -351,13 +503,21 @@
       int quals = (*lang_hooks.tree_dump.type_quals) (t);
 
       if (quals != TYPE_UNQUALIFIED)
-	{
-	  fprintf (di->stream, "qual: %c%c%c     ",
-		   (quals & TYPE_QUAL_CONST) ? 'c' : ' ',
-		   (quals & TYPE_QUAL_VOLATILE) ? 'v' : ' ',
-		   (quals & TYPE_QUAL_RESTRICT) ? 'r' : ' ');
-	  di->column += 14;
-	}
+        {
+          if (di->flags != TDF_XML)
+            {
+              fprintf (di->stream, "qual: %c%c%c     ",
+                       (quals & TYPE_QUAL_CONST) ? 'c' : ' ',
+                       (quals & TYPE_QUAL_VOLATILE) ? 'v' : ' ',
+                       (quals & TYPE_QUAL_RESTRICT) ? 'r' : ' ');
+              di->column += 14;
+            }
+          else
+            dump_xml_field (di, xml_field_string_type, "qual", "%c%c%c",
+                            (quals & TYPE_QUAL_CONST) ? 'c' : ' ',
+                            (quals & TYPE_QUAL_VOLATILE) ? 'v' : ' ',
+                            (quals & TYPE_QUAL_RESTRICT) ? 'r' : ' ');          
+        }
 
       /* All types have associated declarations.  */
       dump_child ("name", TYPE_NAME (t));
@@ -507,7 +667,10 @@
       break;
 
     case STRING_CST:
-      fprintf (di->stream, "strg: %-7s ", TREE_STRING_POINTER (t));
+      if (di->flags != TDF_XML)
+        fprintf (di->stream, "strg: %-7s ", TREE_STRING_POINTER (t));
+      else
+        dump_xml_field (di, xml_field_string_type, "strg", "%s", TREE_STRING_POINTER (t));
       dump_int (di, "lngt", TREE_STRING_LENGTH (t));
       break;
 
@@ -588,8 +751,11 @@
   if (dump_flag (di, TDF_ADDRESS, NULL))
     dump_pointer (di, "addr", (void *)t);
 
-  /* Terminate the line.  */
-  fprintf (di->stream, "\n");
+  /* Terminate the xml node / line.  */
+  if (di->flags == TDF_XML)
+    fprintf (di->stream, " </node>\n");
+  else       
+    fprintf (di->stream, "\n");    
 }
 
 /* Return nonzero if FLAG has been specified for the dump, and NODE
@@ -627,6 +793,14 @@
   di.nodes = splay_tree_new (splay_tree_compare_pointers, 0,
 			     (splay_tree_delete_value_fn) &free);
 
+  if ( di.flags == TDF_XML ) {
+    /* Dump XML header and root node ( open mark ) */
+    fprintf( stream, "<?xml version='1.0'?>\n" );
+    fprintf( stream, "<!DOCTYPE %s SYSTEM \"%s.dtd\">\n",
+             XML_GXX_TU_DOCTYPE, XML_GXX_TU_DOCTYPE );
+    fprintf( stream, "<%s>\n", XML_GXX_TU_DOCTYPE );
+  }
+
   /* Queue up the first node.  */
   queue (&di, t, DUMP_NONE);
 
@@ -634,6 +808,10 @@
   while (di.queue)
     dequeue_and_dump (&di);
 
+  if ( di.flags == TDF_XML )
+    /* Dump the xml root node ( close mark ) */
+    fprintf( stream, "\n</%s>\n", XML_GXX_TU_DOCTYPE );  
+
   /* Now, clean up.  */
   for (dq = di.free_list; dq; dq = next_dq)
     {
@@ -676,6 +854,7 @@
 {
   {"address", TDF_ADDRESS},
   {"slim", TDF_SLIM},
+  {"xml", TDF_XML},
   {"all", ~0},
   {NULL, 0}
 };

      parent reply	other threads:[~2002-10-01  5:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-28  9:40 -fdump-translation-unit-xml Lorenzo Delana
2002-09-30 11:14 ` -fdump-translation-unit-xml Matt Austern
2002-09-30 11:18   ` -fdump-translation-unit-xml Zack Weinberg
2002-09-30 11:25   ` -fdump-translation-unit-xml Gabriel Dos Reis
2002-09-30 12:23   ` -fdump-translation-unit-xml Pop Sébastian
2002-09-30 12:26     ` -fdump-translation-unit-xml Mike Stump
2002-09-30 12:27       ` -fdump-translation-unit-xml Pop Sébastian
2002-09-30 12:41         ` -fdump-translation-unit-xml Phil Edwards
2002-09-30 13:06           ` -fdump-translation-unit-xml Pop Sébastian
2002-09-30 13:20           ` -fdump-translation-unit-xml Daniel Berlin
2002-09-30 13:26             ` -fdump-translation-unit-xml David Carlton
2002-09-30 13:59         ` -fdump-translation-unit-xml Matt Austern
2002-09-30 23:57   ` Lorenzo Delana [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200210010719.38272.ldelana@libero.it \
    --to=ldelana@libero.it \
    --cc=austern@apple.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).