XML patch from Robin Dunn adds -dump_xml and -xmlout <file> for generating XML of post processed parse tree

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6037 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2004-07-12 19:53:23 +00:00
commit a03dad3a41
3 changed files with 55 additions and 13 deletions

View file

@ -112,7 +112,7 @@ public:
}
Printf( out, "<?xml version=\"1.0\" ?> \n" );
Xml_print_tree(n);
return SWIG_OK;
return SWIG_OK;
}
@ -198,7 +198,8 @@ public:
Replaceall( o, "<", "&lt;" );
Replaceall( o, "\"", "&quot;" );
Replaceall( o, "\\", "\\\\" );
Printf(out,"<attribute name=\"%s\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o );
Replaceall( o, "\n", "&#10;" );
Printf(out,"<attribute name=\"%s\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o );
Delete(o);
Delete(ck);
}
@ -207,7 +208,7 @@ public:
o = Getattr(obj,k);
String *ck = NewString(k);
Replaceall( ck, ":", "_" );
Printf(out,"<attribute name=\"%s\" value=\"%x\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o );
Printf(out,"<attribute name=\"%s\" value=\"%x\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o );
Delete(ck);
}
}
@ -319,9 +320,8 @@ public:
print_indent(0);
Printf( out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n.item );
Xml_print_attributes( n.item );
Printf( out, "</%ssitem >\n", markup );
print_indent(0);
Printf( out, " />\n" );
Printf( out, "</%ssitem >\n", markup );
n = Next(n);
}
indent_level -= 4;
@ -331,6 +331,34 @@ public:
};
/* -----------------------------------------------------------------------------
* Swig_print_xml
*
* Dump an XML version of the parse tree. This is different from using the -xml
* language module normally as it allows the real language module to process the
* tree first, possibly stuffing in new attributes, so the XML that is output ends
* up being a post-processing version of the tree.
* ----------------------------------------------------------------------------- */
void Swig_print_xml(DOH *obj, String* filename)
{
XML xml;
xmllite = 1;
if (! filename) {
out = stdout;
}
else {
out = NewFile(filename, "w");
if (!out) {
Printf(stderr,"*** Can't open '%s'\n", filename);
SWIG_exit(EXIT_FAILURE);
}
}
Printf( out, "<?xml version=\"1.0\" ?> \n" );
xml.Xml_print_tree(obj);
}
static Language * new_swig_xml() {
return new XML();