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\
-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<list> - 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<list> - Suppress/add warning messages eg -w401,+321 - see Warnings.html\n\
-xmlout <file> - Write XML version of the parse tree to <file> 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();

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();

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_node(Node *obj);
extern void Swig_print_xml(Node *obj, String* filename);
/* -- Wrapper function Object */
typedef struct {