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
parent a56015224b
commit a03dad3a41
3 changed files with 55 additions and 13 deletions

View File

@ -85,14 +85,9 @@ static const char *usage2 = (const char*)"\
-version - Print SWIG version number\n\ -version - Print SWIG version number\n\
-Wall - Enable all warning messages\n\ -Wall - Enable all warning messages\n\
-Wallkw - Enable keyword warnings for all the supported languages\n\ -Wallkw - Enable keyword warnings for all the supported languages\n\
-Werror - Force to treat warnings as errors\n\ -Werror - Treat warnings as errors\n\
-w<list> - Suppress/add warning messages by code. \n\ -w<list> - Suppress/add warning messages eg -w401,+321 - see Warnings.html\n\
Use ',' as separator and the +/- signs as follows \n\ -xmlout <file> - Write XML version of the parse tree to <file> after normal processing\n\
\n\
-w+321,401,-402 \n\
\n\
where code 321(+) is added, and 401(no sign) and 402(-) \n\
are suppressed. See documentation for code meanings.\n\
\n"; \n";
// Local variables // Local variables
@ -100,6 +95,7 @@ static int freeze = 0;
static String *lang_config = 0; static String *lang_config = 0;
static char *cpp_extension = (char *) "cxx"; static char *cpp_extension = (char *) "cxx";
static String *outdir = 0; static String *outdir = 0;
static String *xmlout = 0;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// check_suffix(char *name) // check_suffix(char *name)
@ -217,6 +213,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
int includecount = 0; int includecount = 0;
int dump_tags = 0; int dump_tags = 0;
int dump_tree = 0; int dump_tree = 0;
int dump_xml = 0;
int browse = 0; int browse = 0;
int dump_typedef = 0; int dump_typedef = 0;
int dump_classes = 0; int dump_classes = 0;
@ -496,6 +493,18 @@ int SWIG_main(int argc, char *argv[], Language *l) {
} else if (strcmp(argv[i],"-dump_tree") == 0) { } else if (strcmp(argv[i],"-dump_tree") == 0) {
dump_tree = 1; dump_tree = 1;
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i],"-dump_xml") == 0) {
dump_xml = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-xmlout") == 0) {
dump_xml = 1;
Swig_mark_arg(i);
if (argv[i+1]) {
xmlout = NewString(argv[i+1]);
Swig_mark_arg(i+1);
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i],"-nocontract") == 0) { } else if (strcmp(argv[i],"-nocontract") == 0) {
Swig_mark_arg(i); Swig_mark_arg(i);
Swig_contract_mode_set(0); Swig_contract_mode_set(0);
@ -748,6 +757,9 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (dump_tree) { if (dump_tree) {
Swig_print_tree(top); Swig_print_tree(top);
} }
if (dump_xml) {
Swig_print_xml(top, xmlout);
}
} }
if (tm_debug) Swig_typemap_debug(); if (tm_debug) Swig_typemap_debug();
if (memory_debug) DohMemoryDebug(); if (memory_debug) DohMemoryDebug();

View File

@ -198,6 +198,7 @@ public:
Replaceall( o, "<", "&lt;" ); Replaceall( o, "<", "&lt;" );
Replaceall( o, "\"", "&quot;" ); Replaceall( o, "\"", "&quot;" );
Replaceall( o, "\\", "\\\\" ); Replaceall( o, "\\", "\\\\" );
Replaceall( o, "\n", "&#10;" );
Printf(out,"<attribute name=\"%s\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o ); Printf(out,"<attribute name=\"%s\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o );
Delete(o); Delete(o);
Delete(ck); Delete(ck);
@ -319,9 +320,8 @@ public:
print_indent(0); print_indent(0);
Printf( out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n.item ); Printf( out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n.item );
Xml_print_attributes( n.item ); Xml_print_attributes( n.item );
Printf( out, "</%ssitem >\n", markup );
print_indent(0); print_indent(0);
Printf( out, " />\n" ); Printf( out, "</%ssitem >\n", markup );
n = Next(n); n = Next(n);
} }
indent_level -= 4; 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() { static Language * new_swig_xml() {
return new XML(); return new XML();

View File

@ -359,6 +359,8 @@ extern void Swig_print_tags(File *obj, Node *root);
extern void Swig_print_tree(Node *obj); extern void Swig_print_tree(Node *obj);
extern void Swig_print_node(Node *obj); extern void Swig_print_node(Node *obj);
extern void Swig_print_xml(Node *obj, String* filename);
/* -- Wrapper function Object */ /* -- Wrapper function Object */
typedef struct { typedef struct {