diff --git a/SWIG/Source/Modules/main.cxx b/SWIG/Source/Modules/main.cxx index be0577a3b..d1c2d3d03 100644 --- a/SWIG/Source/Modules/main.cxx +++ b/SWIG/Source/Modules/main.cxx @@ -85,14 +85,9 @@ static const char *usage2 = (const char*)"\ -version - Print SWIG version number\n\ -Wall - Enable all warning messages\n\ -Wallkw - Enable keyword warnings for all the supported languages\n\ - -Werror - Force to treat warnings as errors\n\ - -w - Suppress/add warning messages by code. \n\ - Use ',' as separator and the +/- signs as follows \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\ + -Werror - Treat warnings as errors\n\ + -w - Suppress/add warning messages eg -w401,+321 - see Warnings.html\n\ + -xmlout - Write XML version of the parse tree to after normal processing\n\ \n"; // Local variables @@ -100,6 +95,7 @@ static int freeze = 0; static String *lang_config = 0; static char *cpp_extension = (char *) "cxx"; static String *outdir = 0; +static String *xmlout = 0; // ----------------------------------------------------------------------------- // check_suffix(char *name) @@ -217,6 +213,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { int includecount = 0; int dump_tags = 0; int dump_tree = 0; + int dump_xml = 0; int browse = 0; int dump_typedef = 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) { dump_tree = 1; 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) { Swig_mark_arg(i); Swig_contract_mode_set(0); @@ -748,6 +757,9 @@ int SWIG_main(int argc, char *argv[], Language *l) { if (dump_tree) { Swig_print_tree(top); } + if (dump_xml) { + Swig_print_xml(top, xmlout); + } } if (tm_debug) Swig_typemap_debug(); if (memory_debug) DohMemoryDebug(); diff --git a/SWIG/Source/Modules/xml.cxx b/SWIG/Source/Modules/xml.cxx index 60a3e8982..0dd6033c8 100644 --- a/SWIG/Source/Modules/xml.cxx +++ b/SWIG/Source/Modules/xml.cxx @@ -112,7 +112,7 @@ public: } Printf( out, " \n" ); Xml_print_tree(n); - return SWIG_OK; + return SWIG_OK; } @@ -198,7 +198,8 @@ public: Replaceall( o, "<", "<" ); Replaceall( o, "\"", """ ); Replaceall( o, "\\", "\\\\" ); - Printf(out,"\n", ck, o, ++id, o ); + Replaceall( o, "\n", " " ); + Printf(out,"\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,"\n", ck, o, ++id, o ); + Printf(out,"\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, "\n", markup ); print_indent(0); - Printf( out, " />\n" ); + Printf( out, "\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, " \n" ); + xml.Xml_print_tree(obj); +} static Language * new_swig_xml() { return new XML(); diff --git a/SWIG/Source/Swig/swig.h b/SWIG/Source/Swig/swig.h index 0d4e79369..3834e8da9 100644 --- a/SWIG/Source/Swig/swig.h +++ b/SWIG/Source/Swig/swig.h @@ -359,6 +359,8 @@ extern void Swig_print_tags(File *obj, Node *root); extern void Swig_print_tree(Node *obj); extern void Swig_print_node(Node *obj); +extern void Swig_print_xml(Node *obj, String* filename); + /* -- Wrapper function Object */ typedef struct {