From 79af91f1248e69ba80b25d3127490b95dcea4298 Mon Sep 17 00:00:00 2001 From: Pherring04 Date: Mon, 10 Jun 2024 13:29:15 -0500 Subject: [PATCH] Updated convert_swig to fix several issues caused by SWIG 4 --- libexec/trick/convert_swig | 80 ++++++++++++++------------------------ 1 file changed, 29 insertions(+), 51 deletions(-) diff --git a/libexec/trick/convert_swig b/libexec/trick/convert_swig index ca58cad6..16a4a68c 100755 --- a/libexec/trick/convert_swig +++ b/libexec/trick/convert_swig @@ -590,19 +590,20 @@ sub process_class($$$$$) { my ($class_name) ; my $template_typedefs ; + ## Extract the class_name from the class_string $class_string =~ /^(?:class|struct)\s+ # keyword class or struct ([_A-Za-z]\w*) # class name \s*[\{\:]$ /sx or die "Internal error" ; $class_name = $1 ; - - my $class_content; - $class_content .= $class_string ; + my $my_class_contents = $class_string ; + #$$new_contents_ref .= "[[[".$class_string."]]]" ; if ( $class_string !~ /\{$/ ) { $$contents_ref =~ s/^(.*?\s*\{)//s ; - $class_content .= $1 ; + $my_class_contents .= $1 ; + #$$new_contents_ref .= $1 ; } ($extracted, $$contents_ref) = extract_bracketed( "{" . $$contents_ref , "{}") ; @@ -615,21 +616,10 @@ sub process_class($$$$$) { #print "*** extracted = $extracted ***\n" ; #print "*** contents = $$contents_ref ***\n" ; - my $save_namespace_content; - - if ( $curr_namespace ne "" ) { - my @split_namespaces = split "::", $curr_namespace; - my $sanitized_namespace = $split_namespaces[-1] ; - my @namespace_split = split /namespace\s*$sanitized_namespace/, $$new_contents_ref; - $save_namespace_content = 'namespace ' . $sanitized_namespace . $namespace_split[-1]; - $$new_contents_ref = join('namespace ' . $sanitized_namespace, @namespace_split[0 .. $#namespace_split-1]); - } # SWIG doesn't like "const static". Change it to "static const" $extracted =~ s/const\s+static/static const/g ; - my $isSwigExcludeBlock = 0; - # templated variables need to be declared with the SWIG %template directive. # This loop looks for any templated variables and creates the %template lines. while ( $extracted =~ s/^(.*?)(?:($template_var_def))//sx ) { @@ -638,17 +628,8 @@ sub process_class($$$$$) { if ( $non_var ne "" ) { #print "*** non_var = $non_var ***\n" ; - $class_content .= $non_var ; - my $ifndefSwig = $non_var; - if ($isSwigExcludeBlock == 0) { - if ($ifndefSwig =~ /(?:ifndef\s*SWIG|if\s*!\s*defined\s*\(\s*SWIG\s*\))/ ) { - $isSwigExcludeBlock = 1; - } - } else { - if ($ifndefSwig =~ /endif/ ) { - $isSwigExcludeBlock = 1; - } - } + $my_class_contents .= $non_var ; + #$$new_contents_ref .= $non_var ; } if ( $template_var_def_str ne "" ) { @@ -657,6 +638,8 @@ sub process_class($$$$$) { $template_var_def_str =~ /(.*?>)\s*([_A-Za-z]\w*).*?;/s ; my ($template_full_type) = $1 ; my ($var_name) = $2 ; + $my_class_contents .= $template_var_def_str ; + #$$new_contents_ref .= $template_var_def_str ; $template_full_type =~ /([_A-Za-z][:\w]*)\s* 0x040000\n\%pythoncode \%{\n __setattr__ = _swig_setattr_nondynamic_instance_variable(object.__setattr__)\n\%}\n#endif\n" ; - $class_content .= $extracted . ";\n" ; + $$new_contents_ref .= "\n#if SWIG_VERSION > 0x040000\n\%pythoncode \%{\n __setattr__ = _swig_setattr_nondynamic_instance_variable(object.__setattr__)\n\%}\n#endif\n" ; + $$new_contents_ref .= $extracted . ";\n" ; my $c_ = "$curr_namespace$class_name" ; $c_ =~ s/\:/_/g ; # Add a #define line that signals that this class has been processed by swig. Classes excluded in #if 0 blocks will # not have this #define defined. - $class_content .= "#define TRICK_SWIG_DEFINED_$c_" ; - if ( $save_namespace_content ne "" ) { - $$new_contents_ref .= $save_namespace_content; - } - $$new_contents_ref .= $class_content; + $$new_contents_ref .= "#define TRICK_SWIG_DEFINED_$c_" ; } ## ================================================================================