You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ja...@apache.org on 2001/07/09 19:32:35 UTC
cvs commit: xml-xerces/perl postSource.pl
jasons 01/07/09 10:32:34
Modified: perl postSource.pl
Log:
* postSource.pl (Repository):
Added generic exception handling mechanism
modified exception handling to support overloaded methods
began to modularize with methods substitute_line(), fix_method(),
skip_to_closing_brace()
Revision Changes Path
1.5 +293 -26 xml-xerces/perl/postSource.pl
Index: postSource.pl
===================================================================
RCS file: /home/cvs/xml-xerces/perl/postSource.pl,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- postSource.pl 2001/06/14 05:33:29 1.4
+++ postSource.pl 2001/07/09 17:32:29 1.5
@@ -1,6 +1,7 @@
#!/usr/bin/perl
+use strict;
-%operator_symbols = (
+my %operator_symbols = (
'addition' => '+',
'addition_assignment' => '+=',
'subtraction' => '-',
@@ -43,29 +44,114 @@
open(TEMP, ">$temp_file")
or die "Couldn't open $temp_file for writing";
-while(<FILE>) {
- # SWIG only knows about the non PL_ version of these variables.
- s/\bsv_undef\b/PL_sv_undef/g if /\bsv_undef\b/;
- s/\bsv_yes\b/PL_sv_yes/g if /\bsv_yes\b/;
- s/\bna\b/PL_na/g if /\bna\b/;
+#
+# Set up the regexp for matching methods that need to hand DOM_DOMException's
+#
+my @dom_methods = qw(DOMParser::parse
+ DOM_CharacterData::appendData
+ DOM_CharacterData::deleteData
+ DOM_CharacterData::getData
+ DOM_CharacterData::insertData
+ DOM_CharacterData::replaceData
+ DOM_CharacterData::substringData
+ DOM_DOMImplementation::createDocument
+ DOM_DOMImplementation::createDocumentType
+ DOM_Element::removeAttribute
+ DOM_Element::removeAttributeNS
+ DOM_Element::removeAttributeNode
+ DOM_Element::setAttribute
+ DOM_Element::setAttributeNS
+ DOM_Element::setAttributeNode
+ DOM_Element::setAttributeNodeNS
+ DOM_NamedNodeMap::removeNamedItem
+ DOM_NamedNodeMap::removeNamedItemNS
+ DOM_NamedNodeMap::setNamedItem
+ DOM_NamedNodeMap::setNamedItemNS
+ DOM_Node::appendChild
+ DOM_Node::getNodeValue
+ DOM_Node::insertBefore
+ DOM_Node::removeChild
+ DOM_Node::replaceChild
+ DOM_Node::setPrefix
+ DOM_NodeIterator::nextNode
+ DOM_NodeIterator::previousNode
+ DOM_ProcessingInstruction::getData
+ DOM_Text::splitText
+ DTDHandler::notationDecl
+ DTDHandler::unparsedEntityDecl
+ DOM_DOMImplementation::createDocument
+ );
+my $dom_methods = join '|',
+ map {s/::/_/; "_wrap_$_(?:__overload__\\d)?"} @dom_methods;
+
+my $domexception_regexp = qr/XS\(($dom_methods)\)/;
+
+
+# now for the methods that only raise XMLExceptions
+my @xml_methods = qw(new::LocalFileInputSource
+ SAX2XMLReader::parse
+ );
+my $xml_methods = join '|',
+ map {s/::/_/; "_wrap_$_"} @xml_methods;
+
+my $xmlexception_regexp = qr/XS\(($xml_methods)\)/;
+
+# now for the methods that only raise SAXExceptions
+my @sax_methods = qw(SAX2XMLReader::setProperty
+ SAX2XMLReader::setFeature
+ SAX2XMLReader::getProperty
+ SAX2XMLReader::getFeature
+ );
+my $sax_methods = join '|',
+ map {s/::/_/; "_wrap_$_"} @sax_methods;
+
+my $saxexception_regexp = qr/XS\(($sax_methods)\)/;
+
+
+FILE: while(<FILE>) {
+
+ substitute_line($_);
+
+ # SWIG screws up the enumerations, so we make them ints in the
+ # header file and have to explicitly cast them by hand
+ if (/XS\(_wrap_DOM_DOMException_code_set/) {
+ fix_method(\*FILE,
+ \*TEMP,
+ 'arg0->code',
+ " arg0->code = (DOM_DOMException::ExceptionCode)arg1;\n"
+ );
+ next FILE;
+ }
- for $key (keys %operator_symbols) {
- s/\b$key\b/ operator$operator_symbols{$key} /
+ if (/XS\(_wrap_IDOM_DOMException_code_set/) {
+ fix_method(\*FILE,
+ \*TEMP,
+ 'arg0->code',
+ " arg0->code = (IDOM_DOMException::ExceptionCode)arg1;\n"
+ );
+ next FILE;
}
- # force SWIG 1.1p5 to make the namespace XML::Xerces
- s/swig_setiv\("(?!XML::Xercesc::)/swig_setiv("XML::Xercesc::/;
- s/SWIG_GetPtr(.*?)"(?!XML::Xerces::)(\w+)"/SWIG_GetPtr$1"XML::Xerces::$2"/;
- s/SWIG_RegisterMapping\("(?!XML::Xerces::)(\w+)","(?!XML::Xerces::)(\w+)",Swig/SWIG_RegisterMapping\("XML::Xerces::$1","XML::Xerces::$2",Swig/;
- s/sv_setref_pv\(ST\(argvi\+\+\),"(?!XML::Xerces::)/sv_setref_pv(ST(argvi++),"XML::Xerces::/;
- s/boot_Xerces/boot_XML__Xerces/g;
+ if (/XS\(_wrap_DOM_RangeException_code_set/) {
+ fix_method(\*FILE,
+ \*TEMP,
+ 'arg0->code',
+ " arg0->code = (DOM_RangeException::RangeExceptionCode)arg1;\n"
+ );
+ next FILE;
+ }
- # force SWIG to handle overloaded functions
- s/(result\s+=.*)__overload__\d+/$1/;
+ if (/XS\(_wrap_IDOM_RangeException_code_set/) {
+ fix_method(\*FILE,
+ \*TEMP,
+ 'arg0->code',
+ " arg0->code = (IDOM_RangeException::RangeExceptionCode)arg1;\n"
+ );
+ next FILE;
+ }
# fix the PerlExceptionHandler::setExceptionHandler method
if (/XS\(_wrap_PerlExceptionHandler_setExceptionHandler/) {
-# if (0) {
print TEMP;
skip_to_closing_brace(\*FILE);
@@ -86,18 +172,51 @@
XSRETURN(argvi);
}
EOT
- next;
+ next FILE;
}
- # Creating InputSource's can raise XMLExceptions
- if (/new .*InputSource\(/) {
+ if (/XS\(_wrap_DOM_Attr_DOM_Attr__constructor__1/) {
+ print TEMP;
+
+ skip_to_closing_brace(\*FILE);
print TEMP <<"EOT";
+ DOM_Attr *arg0 ;
+ int argvi = 0;
+ DOM_Attr *result ;
+ dXSARGS;
+
+ if ((items < 1) || (items > 1))
+ croak("Usage: DOM_Attr_DOM_Attr__constructor__1(self);");
+ if (SWIG_ConvertPtr(ST(0),(void **) &arg0,SWIGTYPE_p_DOM_Attr) < 0) {
+ croak("Type error in argument 1 of DOM_Attr_DOM_Attr__constructor__1. Expected %s", SWIGTYPE_p_DOM_Attr->name);
+ XSRETURN(1);
+ }
+ result = new DOM_Attr((DOM_Attr const &)*arg0);
+ ST(argvi) = sv_newmortal();
+ SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE_p_DOM_Attr);
+ XSRETURN(argvi);
+}
+EOT
+ next FILE;
+ }
+
+ # Creating LocalFileInputSource's can raise XMLExceptions
+ if (/$xmlexception_regexp/) {
+ print TEMP;
+ TEMP: while (<FILE>) {
+ substitute_line($_);
+ if (/arg0->|result\s+=/) {
+ # $brace tracks an irritating SWIG bug, that stuffs two lines together...
+ my $brace = s/;\{/;/;
+ print TEMP <<"EOT";
try {
$_
}
catch (const XMLException& e)
{
- PerlExceptionHandler::catchException(e);
+ PerlExceptionHandler* handler;
+ handler = PerlExceptionHandler::getInstance();
+ handler->catchXMLException(e);
}
catch (...)
{
@@ -106,7 +225,96 @@
exit(4);
}
EOT
- next;
+ print TEMP ' {' if $brace;
+ skip_to_closing_brace(\*FILE, \*TEMP, 1);
+ next FILE;
+ } else {
+ print TEMP;
+ next TEMP;
+ }
+ }
+ }
+
+ # DOMParser::Parse has two possible exceptions
+ if (/$domexception_regexp/) {
+ print TEMP;
+ TEMP: while (<FILE>) {
+ substitute_line($_);
+ if (/arg0->|result\s+=/) {
+ # $brace tracks an irritating SWIG bug, that stuffs two lines together...
+ my $brace = s/;\{/;/;
+ print TEMP <<"EOT";
+ try {
+$_
+ }
+ catch (const XMLException& e)
+ {
+ PerlExceptionHandler* handler;
+ handler = PerlExceptionHandler::getInstance();
+ handler->catchXMLException(e);
+ }
+ catch (const DOM_DOMException& toCatch)
+ {
+ PerlExceptionHandler* handler;
+ handler = PerlExceptionHandler::getInstance();
+ handler->catchDOMException(toCatch);
+ }
+ catch (...)
+ {
+ cerr << "Handling Unknown exception" << endl;
+ XMLPlatformUtils::Terminate();
+ exit(4);
+ }
+EOT
+ print TEMP ' {' if $brace;
+ skip_to_closing_brace(\*FILE, \*TEMP, 1);
+ next FILE;
+ } else {
+ print TEMP;
+ next TEMP;
+ }
+ }
+ }
+
+ # SAXParser::Parse has two possible exceptions
+ if (/$saxexception_regexp/) {
+ print TEMP;
+ TEMP: while (<FILE>) {
+ substitute_line($_);
+ if (/arg0->|result\s+=/) {
+ # $brace tracks an irritating SWIG bug, that stuffs two lines together...
+ my $brace = s/;\{/;/;
+ print TEMP <<"EOT";
+ try {
+$_
+ }
+ catch (const SAXNotSupportedException& e)
+ {
+ PerlExceptionHandler* handler;
+ handler = PerlExceptionHandler::getInstance();
+ handler->catchSAXNotSupportedException(e);
+ }
+ catch (const SAXNotRecognizedException& e)
+ {
+ PerlExceptionHandler* handler;
+ handler = PerlExceptionHandler::getInstance();
+ handler->catchSAXNotRecognizedException(e);
+ }
+ catch (...)
+ {
+ cerr << "Handling Unknown exception" << endl;
+ XMLPlatformUtils::Terminate();
+ exit(4);
+ }
+EOT
+ print TEMP ' {' if $brace;
+ skip_to_closing_brace(\*FILE, \*TEMP, 1);
+ next FILE;
+ } else {
+ print TEMP;
+ next TEMP;
+ }
+ }
}
# we need to move the new SWIG_TypeCheck() *after* the perl
@@ -182,14 +390,73 @@
sub skip_to_closing_brace {
- my $fh = shift;
+ my ($in_fh,$out_fh,$print) = @_;
+ $print = 0 unless defined $print;
my $braces = 1;
- while ($braces && ! eof($fh)) {
- $_ = <$fh>;
+ while ($braces && ! eof($in_fh)) {
+ $_ = <$in_fh>;
$braces-- if /\}/;
$braces++ if /\{/;
+ if ($print) {
+ substitute_line($_);
+ print TEMP;
+ }
}
if ($braces) {
- print STDERR "skip_closing_brace exited with positive brace count";
+ print STDERR "skip_to_closing_brace exited with positive brace count";
}
}
+
+sub fix_method {
+ my ($in_fh,$out_fh,$match,$subst) = @_;
+ my $braces = 1;
+ print TEMP;
+ while ($braces && ! eof($in_fh)) {
+ $_ = <$in_fh>;
+ $braces-- if /\}/;
+ $braces++ if /\{/;
+ substitute_line($_);
+ if (/$match/) {
+ s/^.*\n/$subst\n/;
+ }
+ print TEMP;
+ }
+ if ($braces) {
+ print STDERR "fix_method exited with positive brace count";
+ }
+}
+
+sub substitute_line {
+ $_ = shift;
+
+ # SWIG only knows about the non PL_ version of these variables.
+ s/\bsv_undef\b/PL_sv_undef/g if /\bsv_undef\b/;
+ s/\bsv_yes\b/PL_sv_yes/g if /\bsv_yes\b/;
+ s/\bna\b/PL_na/g if /\bna\b/;
+
+ # SWIG sometimes begins typemaps right at the end of lines
+ # this messes up the exception handling transforms
+# s/;\{/;\n \{/;
+
+ for my $key (keys %operator_symbols) {
+ s/\b$key\b/ operator$operator_symbols{$key} /
+ }
+
+ # force SWIG 1.1p5 to make the namespace XML::Xerces
+ s/swig_setiv\("(?!XML::Xercesc::)/swig_setiv("XML::Xercesc::/;
+ s/SWIG_GetPtr(.*?)"(?!XML::Xerces::)(\w+)"/SWIG_GetPtr$1"XML::Xerces::$2"/;
+ s/SWIG_RegisterMapping\("(?!XML::Xerces::)(\w+)","(?!XML::Xerces::)(\w+)",Swig/SWIG_RegisterMapping\("XML::Xerces::$1","XML::Xerces::$2",Swig/;
+ s/sv_setref_pv\(ST\(argvi\+\+\),"(?!XML::Xerces::)/sv_setref_pv(ST(argvi++),"XML::Xerces::/;
+ s/boot_Xerces/boot_XML__Xerces/g;
+
+ # force SWIG to handle overloaded functions
+ s/(result\s+=.*)__overload__\d+/$1/;
+
+ # this works for methods with no return value, e.g. Parser::parse()
+ s/(arg0->.*)__overload__\d+/$1/;
+
+ # force SWIG to handle overloaded functions
+ s/(result\s+=)\s+.*arg0->(.*)__constructor__\d+/$1 new $2/;
+
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org