typedef of const structures not understood by SWIG

I kind of took the easy way out on this one, I remove any
structure definitions that matches the pattern
typedef const struct A {...} constA ; out of out of
convert_swig before they get to SWIG.

refs #169
This commit is contained in:
Alex Lin 2016-01-26 15:23:08 -06:00
parent a8c8c49f0d
commit 63f193441c

View File

@ -71,6 +71,10 @@ my $typedef_enum_def = qr/typedef\s+enum\s* # the words typedef e
[\w,\s\*]*\s*;) # enum name and ;
/sx ;
my $typedef_const_struct = qr/typedef\s+const\s+(?:struct|union)\s* # the words typedef const struct|union
(?:\s+[_A-Za-z]\w*)?\s* # optional name
{ # opening brace
/sx ;
my $typedef_struct = qr/typedef\s+(?:struct|union)\s* # the words typedef struct|union
(?:\s+[_A-Za-z]\w*)?\s* # optional name
{ # opening brace
@ -391,14 +395,16 @@ sub process_contents($$$$) {
my ( $contents_ref , $new_contents_ref , $curr_namespace , $class_names_ref ) = @_ ;
while ( $$contents_ref =~ s/^(.*?)(?:($typedef_struct)|
($typedef_const_struct)|
($template_def)|
($namespace_def)|
($class_def))//sx ) {
my ( $non_var ) = $1 ;
my ( $typedef_struct_string ) = $2 ;
my ( $template_string ) = $3 ;
my ( $namespace_string ) = $4 ;
my ( $class_string ) = $5 ;
my ( $typedef_const_struct_string ) = $3 ;
my ( $template_string ) = $4 ;
my ( $namespace_string ) = $5 ;
my ( $class_string ) = $6 ;
## Handle the case of: non_var
if ( $non_var ne "" ) {
@ -412,6 +418,12 @@ sub process_contents($$$$) {
process_typedef_struct($typedef_struct_string , $contents_ref, $new_contents_ref, $class_names_ref) ;
}
##
## Handle the case of: typedef_struct ==> typedef const (struct | union ) <name> '{' ...
##
if ( $typedef_const_struct_string ne "" ) {
process_typedef_const_struct($typedef_const_struct_string , $contents_ref) ;
}
##
## Handle the case of: template_def ==> template '<' <template-parameters> '>' class <class-name> ...
## This is required so that templated classes do not match the plain class definition.
##
@ -723,4 +735,25 @@ sub process_typedef_struct($$$$) {
}
## ================================================================================
## process_typedef_const_struct
##
## Synopsis
##
## Process a typedef const struct definition. SWIG doesn't like this construct.
## If we find one, we ignore the contents by finding the end of the definition
## and throwing it all out.
##
sub process_typedef_const_struct($$$$) {
my ($typedef_const_struct_string , $contents_ref ) = @_ ;
my $extracted ;
($extracted, $$contents_ref) = extract_bracketed( "{" . $$contents_ref , "{}") ;
$$contents_ref =~ s/^(\s*([\w,\s\*]+)?\s*;)//sx ;
}
__END__