Mercurial > hg > GearsTemplate
diff src/parallel_execution/generate_stub.pl @ 259:195518ab62fc
fix type gathering pattern match in generate_stub.pl
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 28 Jan 2017 12:37:22 +0900 |
parents | 79bbe2c63fb0 |
children | 6b5444bbea8a |
line wrap: on
line diff
--- a/src/parallel_execution/generate_stub.pl Fri Jan 27 21:20:07 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Sat Jan 28 12:37:22 2017 +0900 @@ -32,7 +32,6 @@ } my %var; -my %type; my %code; my %dataGearVar; my %dataGear; @@ -46,11 +45,12 @@ open my $fd,"<",$filename or die("can't open $filename $!"); while (<$fd>) { if (! $inTypedef) { - if (/^typedef struct (\w+) {/) { + if (/^typedef struct (\w+)/) { $inTypedef = 1; $name = $1; $dataGear{$name} = $_; - $code{$name} = []; + $var{$name} = {}; + $code{$name} = {}; } elsif (/^(\w+)\* create(\w+)\(/) { if (defined $interface) { die "duplicate interface $interface\n"; @@ -65,18 +65,10 @@ } # gather type name and type $dataGear{$name} .= $_; - if (/(\w+);$/ and !/^} (\w+)/) { - my $tmp = $1 . "\n"; - if (/{/) { - $tmp = "{" . $'; - $tmp =~ s/;$//; - } - $var{$name} .= $tmp; - $tmp = $`; - $tmp =~ s/^\s*//; - $type{$name} .= $tmp . "\n"; + if (/^\s*(.*)\s+(\w+);$/ ) { + $var{$name}->{$2} = $1; } elsif (/\_\_code (\w+)\(/) { - push $code{$name}, $1; + $code{$name}->{$1} = 1; } if (/^}/) { $inTypedef = 0; @@ -96,18 +88,21 @@ my($codeGearName, $varName, $typeName, $typeField, $interface) = @_; push @{$dataGearVar{$codeGearName}},$varName; if ($typeField ne $varName) { - $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $typeName, $varName);\n"; - # print STDOUT "$codeGearName \t$typeName* $varName = ($typeName*)GearImpl(context, $typeName, $varName);\n"; + $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n"; } else { - for my $ivar ($var{$interface}) { + for my $ivar (keys %{$var{$interface}}) { if ($varName eq $ivar) { $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $interface)->$varName;\n"; - # print STDOUT "$codeGearName \t$typeName* $varName = Gearef(context, $interface)->$varName;\n"; + return; + } + } + for my $cName (keys %{$code{$interface}}) { + if ($varName eq $cName) { + $dataGearName{$codeGearName} .= "\tenum Code $varName = Gearef(context, $interface)->$varName;\n"; return; } } $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $typeName)->$typeField;\n"; - # print STDOUT "$codeGearName \t$typeName* $varName = Gearef(context, $typeName)->$typeField;\n"; } } @@ -128,6 +123,11 @@ $i++; } } + if ( $fn =~ m=(.*)/[^/]+$= ) { + if (! -d $1) { + mkdir $1; + } + } open my $fd,">",$fn or die("can't write $fn $!"); my $prevCodeGearName; @@ -158,7 +158,7 @@ } $prevCodeGearName = $codeGearName; $dataGearVar{$codeGearName} = []; - my $newArgs = ""; + my $newArgs = "struct Context *context,"; while($args) { if ($args =~ s/(^\s*,\s*)//) { $newArgs .= $1; @@ -177,6 +177,7 @@ my $typeField = lcfirst($typeName); &generateStubArgs($codeGearName, $varName, $typeName, $typeField, $interface); } + &generateStubArgs($codeGearName, $next, "Code", $next, $interface); } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { my $structType = $1; my $typeName = $2; @@ -203,12 +204,11 @@ my $args = $2; print $fd "${prev}goto meta(context, next);\n"; next; + } else { + s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new } - print $fd $_; - next; - } # gather type name and type - if (/^}/) { + } elsif (/^}/) { $inTypedef = 0; } print $fd $_;