Mercurial > hg > Gears > Gears
changeset 869:0f58ffcf8ec3
move method
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 23 Jan 2021 15:27:14 +0900 |
parents | d98a83def544 |
children | 40437e1bd11b |
files | src/parallel_execution/generate_stub.pl |
diffstat | 1 files changed, 128 insertions(+), 115 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/generate_stub.pl Sat Jan 23 14:47:10 2021 +0900 +++ b/src/parallel_execution/generate_stub.pl Sat Jan 23 15:27:14 2021 +0900 @@ -882,122 +882,15 @@ debug_print("generateDataGear",__LINE__, $_) if $opt_debug; # handling goto statement # convert it to the meta call form with two arguments, that is context and enum Code - my $prev = $1; - my $next = $2; - my $method = $3; - my $tmpArgs = $4; - my $indent = get_indent_len($prev); - my $currentCodeGearInfo = $filename2EachCodeGearArgs{$filename}->{$codeGearName}; - #$tmpArgs =~ s/\(.*\)/\(\)/; - my @args = split(/,/,$tmpArgs); - if (! defined $dataGearVarType{$codeGearName}) { - print $fd $_ ; - next ; - } - my @types = @{$dataGearVarType{$codeGearName}}; - my $ntype; - my $ftype; - for my $v (@{$dataGearVar{$codeGearName}}) { - my $t = shift @types; - if ($v eq $next || $v eq "O_$next") { - $ntype = $t; - $ftype = lcfirst($ntype); - } - } - if (!defined $ntype) { - $ntype = $localVarType{$next}; - $ftype = lcfirst($ntype); - } - print $fd "${indent}Gearef(${context_name}, $ntype)->$ftype = (union Data*) $next;\n"; - # Put interface argument - my $prot = $code{$ntype}->{$method}; - my $i = 1; - my $nextType = $currentCodeGearInfo->{localVar}->{$next} // $currentCodeGearInfo->{arg}->{$next}; - # p $currentCodeGearInfo; - my $nextTypePath = $headerNameToInfo->{$nextType}->{path}; - my $parsedNextTypePath = Gears::Interface->detailed_parse($nextTypePath); - #p $parsedNextTypePath; - #print "method\n"; - #p $method; - unless (exists $parsedNextTypePath->{codeName}->{$method}) { - die "[ERROR] not found $next definition at $_ in $fn\n"; - } - my $nextMethodInfo = $parsedNextTypePath->{codeName}->{$method}; - my $nextMethodWantArgc = $nextMethodInfo->{argc}; - if ($nextMethodWantArgc != scalar(@args)) { - #use DDP {deparse => 1}; - # p $nextMethodWantArgc; - # p $nextMethodInfo; - # p @args; - #die "[EROR] invalid arg $_ you shoud impl $nextMethodInfo->{args}\n"; - } - - - for my $arg (@args) { - my $pType; - my $pName; - my $p = @$prot[$i]; - next if ($p eq $arg); - $p =~ s/^(.*)\s(\w+)//; - $pType = $1; - $pName = $2; - $arg =~ s/^(\s)*(\w+)/$2/; - if ($pType =~ s/\_\_code$//) { - if ($arg =~ /(\w+)\(.*\)/) { - print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $1;\n"; - } else { - my $hasGotoArgOrLocalVar = undef; - my $outputStubElem = $generateHaveOutputStub->{list}->{$codeGearName}; - - if ($implInterfaceInfo->{parsedInterfaceInfo}) { - if (exists_codegear_in_interface({codeGearName => $arg, parsedInfo => $implInterfaceInfo->{parsedInterfaceInfo}})) { - my $replaceCodeGear = "${arg}$implInterfaceInfo->{implementation}"; #${pop}SingleLinkedStack - $arg = $replaceCodeGear; - } - } - - if ($outputStubElem && !$stub{$outputStubElem->{createStubName}."_stub"}->{static}) { - my $pick_next = "$outputStubElem->{createStubName}_$outputStubElem->{counter}"; - print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = C_$pick_next;\n"; - $i++; - next; - } - - # find __code of argument or local variable - for my $localVarType (qw/arg localVar/) { - my $foundVarType = $currentCodeGearInfo->{$localVarType}->{$arg}; - if ($foundVarType && $foundVarType eq '__code') { - $hasGotoArgOrLocalVar = 1; - } - } - - # inteface case - - if ($arg =~ /->/) { - print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $arg;\n"; #Gearef->()->next = bar->baz; - $i++; - next; - } - - if ($hasGotoArgOrLocalVar) { - print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $arg;\n"; #Gearef->()->next = next; - $i++; - next; - } - - print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = C_$arg;\n"; - $i++; - next; - } - } elsif ($pType =~ /Data\**$/){ - print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = (union $pType) $arg;\n"; - } else { - print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $arg;\n"; - } - $i++; - } - print $fd "${prev}goto meta(${context_name}, $next->$method);\n"; + my $parsed = { + prev => $1, + next => $2, + method => $3, + tmpArgs => $4, + }; + #my ($line, $currentCodeGearName, $filename, $fd, $localVarType, $parsed, $filename2args) = @_; + generateInterfaceMeta($_, $codeGearName, $filename, $fd, $parsed, \%filename2EachCodeGearArgs, \%localVarType); next; } elsif(/^(.*)par goto (\w+)\((.*)\);/) { debug_print("generateDataGear",__LINE__, $_) if $opt_debug; @@ -1302,3 +1195,123 @@ my ($functionName, $lineNumber, $line) = @_; print "[$functionName] match $lineNumber : $line"; } + +sub generateInterfaceMeta { + my ($line, $currentCodeGearName, $filename, $fd, $parsed, $filename2args, $localVarType) = @_; + + my $prev = $parsed->{prev}; + my $next = $parsed->{next}; + my $method = $parsed->{method}; + my $tmpArgs = $parsed->{tmpArgs}; + + my $indent = get_indent_len($prev); + my $currentCodeGearInfo = $filename2args->{$filename}->{$currentCodeGearName}; + #$tmpArgs =~ s/\(.*\)/\(\)/; + my @args = split(/,/,$tmpArgs); + if (! defined $dataGearVarType{$currentCodeGearName}) { + print $fd $_ ; + return; + } + my @types = @{$dataGearVarType{$currentCodeGearName}}; + my $ntype; + my $ftype; + for my $v (@{$dataGearVar{$currentCodeGearName}}) { + my $t = shift @types; + if ($v eq $next || $v eq "O_$next") { + $ntype = $t; + $ftype = lcfirst($ntype); + } + } + if (!defined $ntype) { + $ntype = $localVarType->{$next}; + $ftype = lcfirst($ntype); + } + print $fd "${indent}Gearef(${context_name}, $ntype)->$ftype = (union Data*) $next;\n"; + # Put interface argument + my $prot = $code{$ntype}->{$method}; + my $i = 1; + my $nextType = $currentCodeGearInfo->{localVar}->{$next} // $currentCodeGearInfo->{arg}->{$next}; + my $nextTypePath = $headerNameToInfo->{$nextType}->{path}; + my $parsedNextTypePath = Gears::Interface->detailed_parse($nextTypePath); + + unless (exists $parsedNextTypePath->{codeName}->{$method}) { + die "[ERROR] not found $next definition at $_ in $filename\n"; + } + my $nextMethodInfo = $parsedNextTypePath->{codeName}->{$method}; + my $nextMethodWantArgc = $nextMethodInfo->{argc}; + + if ($nextMethodWantArgc != scalar(@args)) { + #use DDP {deparse => 1}; + # p $nextMethodWantArgc; + # p $nextMethodInfo; + # p @args; + #die "[EROR] invalid arg $_ you shoud impl $nextMethodInfo->{args}\n"; + } + + + for my $arg (@args) { + my $pType; + my $pName; + my $p = @$prot[$i]; + next if ($p eq $arg); + $p =~ s/^(.*)\s(\w+)//; + $pType = $1; + $pName = $2; + $arg =~ s/^(\s)*(\w+)/$2/; + if ($pType =~ s/\_\_code$//) { + if ($arg =~ /(\w+)\(.*\)/) { + print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $1;\n"; + } else { + my $hasGotoArgOrLocalVar = undef; + my $outputStubElem = $generateHaveOutputStub->{list}->{$currentCodeGearName}; + + if ($implInterfaceInfo->{parsedInterfaceInfo}) { + if (exists_codegear_in_interface({codeGearName => $arg, parsedInfo => $implInterfaceInfo->{parsedInterfaceInfo}})) { + my $replaceCodeGear = "${arg}$implInterfaceInfo->{implementation}"; #${pop}SingleLinkedStack + $arg = $replaceCodeGear; + } + } + + if ($outputStubElem && !$stub{$outputStubElem->{createStubName}."_stub"}->{static}) { + my $pick_next = "$outputStubElem->{createStubName}_$outputStubElem->{counter}"; + print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = C_$pick_next;\n"; + $i++; + next; + } + + # find __code of argument or local variable + for my $localVType (qw/arg localVar/) { + my $foundVarType = $currentCodeGearInfo->{$localVType}->{$arg}; + if ($foundVarType && $foundVarType eq '__code') { + $hasGotoArgOrLocalVar = 1; + } + } + + # inteface case + + if ($arg =~ /->/) { + print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $arg;\n"; #Gearef->()->next = bar->baz; + $i++; + next; + } + + if ($hasGotoArgOrLocalVar) { + print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $arg;\n"; #Gearef->()->next = next; + $i++; + next; + } + + print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = C_$arg;\n"; + $i++; + next; + } + } elsif ($pType =~ /Data\**$/){ + print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = (union $pType) $arg;\n"; + } else { + print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $arg;\n"; + } + $i++; + } + print $fd "${prev}goto meta(${context_name}, $next->$method);\n"; + return; +}