@@ -500,9 +500,9 @@ my %DeclaredVarH=(); # list of my varibles in the current subroute
500500 if ( $ValClass [$k ]=~/ [sah]/ ){
501501 check_ref($CurSubName , $k ); # SNOOPYJC
502502 if ($ValClass [$k ] eq ' s' && $ValPerl [$k ] eq ' $_' && $k +1 <= $#ValClass &&
503- ($ValClass [$k +1] eq ' =' ||
504- ($ValClass [$k +1] eq ' ~' && $ValClass [$k +2] eq ' f' && $ValPerl [$k +2] =~ / ^(?:re|tr)$ / )) # issue ddts
505- ) {
503+ ($ValClass [$k +1] eq ' =' ||
504+ ($ValClass [$k +1] eq ' ~' && $ValClass [$k +2] eq ' f' && $ValPerl [$k +2] =~ / ^(?:re|tr)$ / )) # issue ddts
505+ ) {
506506 # issue s84 $SubAttributes{$CurSubName}{modifies_arglist} = 1; # SNOOPYJC: This sub mods it's args
507507 $SubAttributes {&Perlscan::cur_sub()}{modifies_arglist } = 1; # SNOOPYJC: This sub mods it's args, issue s84
508508 }
@@ -533,30 +533,30 @@ my %DeclaredVarH=(); # list of my varibles in the current subroute
533533 } elsif ($ValClass [$k ] eq ' f' && ($ValPerl [$k ] eq ' re' && $ValPy [$k ] =~ / \b $DEFAULT_VAR \b / ) ||
534534 ($ValPerl [$k ] eq ' tr' && ($k == 0 || $ValClass [$k -1] ne ' ~' ))) { # issue s8: sets the $DEFAULT_VAR
535535
536- my $t = merge_types($DEFAULT_VAR , $CurSubName , ' S' ); # issue s104
536+ my $t = merge_types($DEFAULT_VAR , $CurSubName , ' S' ); # issue s104
537537 $VarType {$DEFAULT_VAR }{$CurSubName } = $t ; # issue s8, issue s104
538538 $VarSubMap {$DEFAULT_VAR }{$CurSubName }=' +' ; # issue s103
539539 $NeedsInitializing {$CurSubName }{$DEFAULT_VAR } = $t if (!exists $initialized {$CurSubName }{$DEFAULT_VAR }); # issue s8, issue s104
540- } elsif ($ValClass [$k ] eq ' f' && arg_type($ValPerl [$k ], $ValPy [$k ], 0, 0) eq ' H' && $#ValClass > $k ) { # issue s101: handle file handles across subs
541- my $h = $k +1;
542- $h ++ if ($ValClass [$h ] eq ' (' );
543- if ($ValClass [$h ] eq ' i' && index ($ValPy [$h ],' .' ) < 0) { # Do this for bareword file handles, but not STDxx
544- $VarSubMap {$ValPy [$h ]}{$CurSubName }=' +' ;
545- }
540+ } elsif ($ValClass [$k ] eq ' f' && arg_type($ValPerl [$k ], $ValPy [$k ], 0, 0) eq ' H' && $#ValClass > $k ) { # issue s101: handle file handles across subs
541+ my $h = $k +1;
542+ $h ++ if ($ValClass [$h ] eq ' (' );
543+ if ($ValClass [$h ] eq ' i' && index ($ValPy [$h ],' .' ) < 0) { # Do this for bareword file handles, but not STDxx
544+ $VarSubMap {$ValPy [$h ]}{$CurSubName }=' +' ;
545+ }
546546 } elsif ($ValClass [$k ] eq ' f' &&
547- ((($ValPerl [$k ] eq ' chomp' || $ValPerl [$k ] eq ' chop' || $ValPerl [$k ] eq ' eval' || $ValPerl [$k ] eq ' split' ||
548- $ValPerl [$k ] eq ' defined' || $ValPerl [$k ] eq ' mkdir' || $ValPerl [$k ] eq ' ord' || $ValPerl [$k ] eq ' chr' ||
549- $ValPerl [$k ] eq ' quotemeta' || $ValPerl [$k ] eq ' oct' || $ValPerl [$k ] eq ' hex' || $ValPerl [$k ] eq ' require' ||
550- $ValPerl [$k ] eq ' stat' || $ValPerl [$k ] eq ' lstat' || $ValPerl [$k ] eq ' reverse' ) && $#ValClass == $k || end_of_function($k ) == $k ) ||
551- ($ValPerl [$k ] eq ' split' && $#ValClass == $k +1) ||
552- (($ValPerl [$k ] eq ' print' || $ValPerl [$k ] eq ' printf' ) && ($#ValClass == $k || ($#ValClass == $k +1 && $ValClass [$k +1] eq ' i' ))))) { # issue s103
553- my $t = ' S' ; # issue s104
554- $t = ' m' if $ValPerl [$k ] eq ' defined' ; # issue s104
547+ ((($ValPerl [$k ] eq ' chomp' || $ValPerl [$k ] eq ' chop' || $ValPerl [$k ] eq ' eval' || $ValPerl [$k ] eq ' split' ||
548+ $ValPerl [$k ] eq ' defined' || $ValPerl [$k ] eq ' mkdir' || $ValPerl [$k ] eq ' ord' || $ValPerl [$k ] eq ' chr' ||
549+ $ValPerl [$k ] eq ' quotemeta' || $ValPerl [$k ] eq ' oct' || $ValPerl [$k ] eq ' hex' || $ValPerl [$k ] eq ' require' ||
550+ $ValPerl [$k ] eq ' stat' || $ValPerl [$k ] eq ' lstat' || $ValPerl [$k ] eq ' reverse' ) && $#ValClass == $k || end_of_function($k ) == $k ) ||
551+ ($ValPerl [$k ] eq ' split' && $#ValClass == $k +1) ||
552+ (($ValPerl [$k ] eq ' print' || $ValPerl [$k ] eq ' printf' ) && ($#ValClass == $k || ($#ValClass == $k +1 && $ValClass [$k +1] eq ' i' ))))) { # issue s103
553+ my $t = ' S' ; # issue s104
554+ $t = ' m' if $ValPerl [$k ] eq ' defined' ; # issue s104
555555 $t = merge_types($DEFAULT_VAR , $CurSubName , $t ); # issue s104
556556 $VarType {$DEFAULT_VAR }{$CurSubName } = $t ; # issue s104
557- $VarSubMap {$DEFAULT_VAR }{$CurSubName }=' +' ; # issue s103
558- $NeedsInitializing {$CurSubName }{$DEFAULT_VAR } = $t if (!exists $initialized {$CurSubName }{$DEFAULT_VAR }); # issue s103, issue s104
559- }
557+ $VarSubMap {$DEFAULT_VAR }{$CurSubName }=' +' ; # issue s103
558+ $NeedsInitializing {$CurSubName }{$DEFAULT_VAR } = $t if (!exists $initialized {$CurSubName }{$DEFAULT_VAR }); # issue s103, issue s104
559+ }
560560
561561 } # for
562562 if (scalar (@ValClass ) > 0 && $ValClass [0] eq ' k' && $ValPerl [0] eq ' return' ) { # SNOOPYJC: return statement
@@ -901,9 +901,9 @@ my %DeclaredVarH=(); # list of my varibles in the current subroute
901901 my $vn = substr ($varname , $dx +1);
902902 my $ig = ' _init_global' ;
903903 $ig = " $PERLLIB .init_global" if ($: :import_perllib);
904- if (exists $Packages {$packname }) { # Only init if the named package is defined here
904+ if (exists $Packages {$packname }) { # Only init if the named package is defined here
905905 $InitVar {$subname } .= " \n $varname = $ig ('$packname ', '$vn ', " .init_val($NeedsInitializing {$subname }{$varname }) . ' )' ;
906- }
906+ }
907907 }
908908 }
909909 }
@@ -968,6 +968,11 @@ sub check_ref # SNOOPYJC: Check references to variables so we can type
968968 say STDERR " check_ref($CurSub , $name ) at $k " ;
969969 }
970970
971+ if (exists $Perlscan::sub_varclasses {$CurSub }{$ValPerl [$k ]} && $Perlscan::sub_varclasses {$CurSub }{$ValPerl [$k ]} eq ' local' ) { # issue s144
972+ # issue s144: 'local' variables aren't really local
973+ $CurSub = ' __main__'
974+ }
975+
971976 # Record if we are modifying the loop counter
972977 if ($ValPy [0] ne ' for' && $class eq ' s' &&
973978 (($k != 0 && $ValClass [$k -1] eq ' ^' ) || ($k +1 <= $#ValClass && ($ValClass [$k +1] eq ' =' || $ValClass [$k +1] eq ' ^' )))) {
@@ -1078,11 +1083,11 @@ sub check_ref # SNOOPYJC: Check references to variables so we can type
10781083 } else {
10791084 $type = ' u' ;
10801085 }
1081- if ($ValClass [$k ] eq ' a' ) { # issue s95
1082- $type = ' a' ; # issue s95
1083- } elsif ($ValClass [$k ] eq ' h' ) { # issue s95
1084- $type = ' h' ; # issue s95
1085- }
1086+ if ($ValClass [$k ] eq ' a' ) { # issue s95
1087+ $type = ' a' ; # issue s95
1088+ } elsif ($ValClass [$k ] eq ' h' ) { # issue s95
1089+ $type = ' h' ; # issue s95
1090+ }
10861091 $initialized {$CurSub }{$name } = $type unless (&Perlscan::in_conditional($k ));
10871092 }
10881093 }
@@ -1147,27 +1152,46 @@ sub check_ref # SNOOPYJC: Check references to variables so we can type
11471152 } elsif (index (' )x*/%+-.HI>&|0r?:,Ao"' , $ValClass [$p ]) >= 0) {
11481153 return ; # Just a reference to the array
11491154 }
1155+ } elsif ($k -1 >= 0 && $ValClass [$k -1] eq ' f' && ($ValPerl [$k -1] eq ' chop' || $ValPerl [$k -1] eq ' chomp' )) { # issue s148
1156+ $VarType {$name }{$CurSub } = merge_types($name , $CurSub , " $type of S" );
1157+ } elsif ($k -2 >= 0 && $ValClass [$k -1] eq ' (' && $ValClass [$k -2] eq ' f' && ($ValPerl [$k -2] eq ' chop' || $ValPerl [$k -2] eq ' chomp' )) { # issue s148
1158+ $VarType {$name }{$CurSub } = merge_types($name , $CurSub , " $type of S" );
11501159 } else {
11511160 return ; # Just a reference to the array
11521161 }
1153- # issue s98 if(defined $rhs_type) {
1154- # issue s98 $VarType{$name}{$CurSub} = merge_types($name, $CurSub, "$type of $rhs_type");
1155- # issue s98 } else {
1156- $VarType {$name }{$CurSub } = merge_types($name , $CurSub , " $type of m" );
1162+ # issue s98 if(defined $rhs_type) {
1163+ # issue s98 $VarType{$name}{$CurSub} = merge_types($name, $CurSub, "$type of $rhs_type");
1164+ # issue s98 } else {
1165+ $VarType {$name }{$CurSub } = merge_types($name , $CurSub , " $type of m" );
11571166 # issue s98 }
1167+ } elsif ($class eq ' s' && $k -1 >= 0 && $ValClass [$k -1] eq ' f' && ($ValPerl [$k -1] eq ' chop' || $ValPerl [$k -1] eq ' chomp' )) { # issue s148
1168+ $VarType {$name }{$CurSub } = merge_types($name , $CurSub , ' S' );
1169+ } elsif ($class eq ' s' && $k -2 >= 0 && $ValClass [$k -1] eq ' (' && $ValClass [$k -2] eq ' f' && ($ValPerl [$k -2] eq ' chop' || $ValPerl [$k -2] eq ' chomp' )) { # issue s148
1170+ $VarType {$name }{$CurSub } = merge_types($name , $CurSub , ' S' );
11581171 } elsif ($class eq ' a' || $class eq ' h' ) { # e.g. if(@arr) or if(%hash) or push @arr, ...
11591172 $type = $class ;
11601173 if ($k -1 >= 0 && $ValClass [$k -1] eq ' f' && ($ValPerl [$k -1] eq ' push' || $ValPerl [$k -1] eq ' unshift' ) && $k +2 <= $#ValClass ) {
11611174 $type = expr_type($k +2, $#ValClass , $CurSub );
11621175 $type = " $class of $type " ;
11631176 $VarType {$name }{$CurSub } = merge_types($name , $CurSub , $type );
1177+ } elsif ($k -2 >= 0 && $ValClass [$k -1] eq ' (' && $ValClass [$k -2] eq ' f' && ($ValPerl [$k -2] eq ' push' || $ValPerl [$k -2] eq ' unshift' ) && $k +2 <= $#ValClass ) {
1178+ my $match = matching_br($k -1);
1179+ $type = expr_type($k +2, $match -1, $CurSub );
1180+ $type = " $class of $type " ;
1181+ $VarType {$name }{$CurSub } = merge_types($name , $CurSub , $type );
1182+ } elsif ($k -1 >= 0 && $ValClass [$k -1] eq ' f' && ($ValPerl [$k -1] eq ' chop' || $ValPerl [$k -1] eq ' chomp' )) { # issue s148
1183+ $type = " $class of S" ;
1184+ $VarType {$name }{$CurSub } = merge_types($name , $CurSub , $type );
1185+ } elsif ($k -2 >= 0 && $ValClass [$k -1] eq ' (' && $ValClass [$k -2] eq ' f' && ($ValPerl [$k -2] eq ' chop' || $ValPerl [$k -2] eq ' chomp' )) { # issue s148
1186+ $type = " $class of S" ;
1187+ $VarType {$name }{$CurSub } = merge_types($name , $CurSub , $type );
11641188 # issue s93 } elsif(substr($ValPy[$k],0,4) eq 'len(') {
11651189 } elsif ($name =~ / ^\( len\( (.*)\) -1\) $ / ) { # issue s93: $#myArray
11661190 $NeedsInitializing {$CurSub }{$1 } = ' a' if (!exists $initialized {$CurSub }{$1 }); # issue s93
1167- $type = ' I' ; # issue s93
1191+ $type = ' I' ; # issue s93
11681192 } elsif ($name =~ / ^len\( (.*)\) $ / ) { # issue s93: scalar(@myArray)
11691193 $NeedsInitializing {$CurSub }{$1 } = ' a' if (!exists $initialized {$CurSub }{$1 }); # issue s93
1170- $type = ' I' ; # issue s93
1194+ $type = ' I' ; # issue s93
11711195 } # issue s93
11721196 # issue s93 $type = 'I';
11731197 # issue s93 }
0 commit comments