The attached patch (for perl5.7.2-ish xsubpp)
adds a -hiertype flag to xsubpp.
When flag is specified the tr/:/_/ on type names is supressed.

With the flag when mapping C++ code which uses namespace or just has
nested types you can write:

Foo::SubEntity
WriterDonor::SubEntityType(Foo::Entity entity)

and have it work without the  need for

#define Foo__SubEntity Foo::SubEntity

to "undo" the "helpful" translation.

patch2 does same for bleadperl xsubpp


--
Nick Ing-Simmons
http://www.ni-s.u-net.com/

--- /opt/tools/perl5.7.2/ExtUtils/xsubpp.ship   Wed Apr  3 07:41:46 2002
+++ /opt/tools/perl5.7.2/ExtUtils/xsubpp        Wed Apr  3 08:08:44 2002
@@ -34,6 +34,10 @@
 
 Adds ``extern "C"'' to the C code.
 
+=item B<-hiertype>
+
+Retains '::' in type names so that C++ hierachical types can be mapped.
+
 =item B<-except>
 
 Adds exception handling stubs to the C code.
@@ -100,7 +104,7 @@
 
 require 5.002;
 use Cwd;
-use vars '$cplusplus';
+use vars qw($cplusplus $hiertype);
 use vars '%v';
 
 use Config;
@@ -141,6 +145,7 @@
     $flag =~ s/^-// ;
     $spat = quotemeta shift,   next SWITCH     if $flag eq 's';
     $cplusplus = 1,    next SWITCH     if $flag eq 'C++';
+    $hiertype  = 1,    next SWITCH     if $flag eq 'hiertype';
     $WantPrototypes = 0, next SWITCH   if $flag eq 'noprototypes';
     $WantPrototypes = 1, next SWITCH   if $flag eq 'prototypes';
     $WantVersionChk = 0, next SWITCH   if $flag eq 'noversioncheck';
@@ -1621,7 +1626,7 @@
     ($subtype = $ntype) =~ s/(?:Array)?(?:Ptr)?$//;
     $tk = $type_kind{$type};
     $tk =~ s/OBJ$/REF/ if $func_name =~ /DESTROY$/;
-    $type =~ tr/:/_/;
+    $type =~ tr/:/_/ unless $hiertype;
     blurt("Error: No INPUT definition for type '$type', typekind '$type_kind{$type}' 
found"), return
         unless defined $input_expr{$tk} ;
     $expr = $input_expr{$tk};
@@ -1755,7 +1760,8 @@
 sub map_type {
     my($type, $varname) = @_;
 
-    $type =~ tr/:/_/;
+    # C++ has :: in types too so skip this
+    $type =~ tr/:/_/ unless $hiertype;
     $type =~ s/^array\(([^,]*),(.*)\).*/$1 */s;
     if ($varname) {
       if ($varname && $type =~ / \( \s* \* (?= \s* \) ) /xg) {
--- xsubpp.save Wed Apr  3 08:22:50 2002
+++ xsubpp      Wed Apr  3 08:24:19 2002
@@ -34,6 +34,10 @@
 
 Adds ``extern "C"'' to the C code.
 
+=item B<-hiertype>
+
+Retains '::' in type names so that C++ hierachical types can be mapped.
+
 =item B<-except>
 
 Adds exception handling stubs to the C code.
@@ -100,7 +104,7 @@
 
 require 5.002;
 use Cwd;
-use vars '$cplusplus';
+use vars qw($cplusplus $hiertype);
 use vars '%v';
 
 use Config;
@@ -142,6 +146,7 @@
     $flag =~ s/^-// ;
     $spat = quotemeta shift,   next SWITCH     if $flag eq 's';
     $cplusplus = 1,    next SWITCH     if $flag eq 'C++';
+    $hiertype  = 1,    next SWITCH     if $flag eq 'hiertype';
     $WantPrototypes = 0, next SWITCH   if $flag eq 'noprototypes';
     $WantPrototypes = 1, next SWITCH   if $flag eq 'prototypes';
     $WantVersionChk = 0, next SWITCH   if $flag eq 'noversioncheck';
@@ -1679,7 +1684,7 @@
        if defined $defaults{$var};
       return;
     }
-    $type =~ tr/:/_/;
+    $type =~ tr/:/_/ unless $hiertype;
     blurt("Error: No INPUT definition for type '$type', typekind '$type_kind{$type}' 
found"), return
         unless defined $input_expr{$tk} ;
     $expr = $input_expr{$tk};
@@ -1813,7 +1818,8 @@
 sub map_type {
     my($type, $varname) = @_;
 
-    $type =~ tr/:/_/;
+    # C++ has :: in types too so skip this
+    $type =~ tr/:/_/ unless $hiertype;
     $type =~ s/^array\(([^,]*),(.*)\).*/$1 */s;
     if ($varname) {
       if ($varname && $type =~ / \( \s* \* (?= \s* \) ) /xg) {

Reply via email to