Mercurial > hg > GearsTemplate
changeset 583:ba529ff3f068
fix trans_impl.pl
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 28 Nov 2019 16:33:01 +0900 |
parents | 2a97d22c2a76 |
children | 823503ada47f |
files | src/parallel_execution/lib/Gears/Util.pm src/parallel_execution/trans_impl.pl |
diffstat | 2 files changed, 41 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/lib/Gears/Util.pm Wed Nov 27 18:44:00 2019 +0900 +++ b/src/parallel_execution/lib/Gears/Util.pm Thu Nov 28 16:33:01 2019 +0900 @@ -63,7 +63,7 @@ next; } next if ($line =~ /^\s+$/); - next if ($line =~ m[^//]); + next if ($line =~ m[^\s*//]); next if ($line =~ m[^\}\s*$ir->{name};]); if ($line =~ m|__code (\w+)\(([()\.\*\s\w,_]+)\)|) { @@ -76,6 +76,32 @@ return $ir; } +sub parse_with_rewrite { + my ($class, $file) = @_; + my $ir = _parse_base($file); + + my @data_gears; + my @code_gears; + map { push (@data_gears, $_) unless ($_ =~ /enum Code/);} @{$ir->{content}}; + map { push (@code_gears, $1) if ($_ =~ /enum Code (\w+);/);} @{$ir->{content}}; + + open my $fh , '<', $file; + my $i = 0; + while (($i < scalar @code_gears) && (my $line = <$fh>)) { + my $cg = $code_gears[$i]; + if ($line =~ m|__code $cg\(([()\.\*\s\w,_]+)\)|) { + $code_gears[$i] = { + name => $cg, + args => $1, + }; + $i++; + } + } + $ir->{codes} = \@code_gears; + $ir->{data} = \@data_gears; + return $ir; +} + sub file_checking { my ($class, $file_name) = @_; unless (-f $file_name) { @@ -116,7 +142,7 @@ my $find_path = shift // "."; my @files; - find( { wanted => sub { push @files, $_ if /\.h/ }, no_chdir => 1 }, $find_path); + find( { wanted => sub { push @files, $_ if /\.(?:h|dg)/ }, no_chdir => 1 }, $find_path); return \@files; } @@ -136,6 +162,10 @@ } } + unless (defined $content_space) { + $content_space = ""; + } + for my $c (@{$h2context->{content}}) { $c =~ s/$content_space//; $context .= "${space}${space}$c"; @@ -144,4 +174,5 @@ return $context; } + 1;
--- a/src/parallel_execution/trans_impl.pl Wed Nov 27 18:44:00 2019 +0900 +++ b/src/parallel_execution/trans_impl.pl Thu Nov 28 16:33:01 2019 +0900 @@ -12,10 +12,10 @@ getopts("w" => \%opt); my $impl_file = shift or die 'require impl file'; -my $impl_ir = Gears::Util->parse_code_verbose($impl_file); +my $impl_ir = Gears::Util->parse_with_rewrite($impl_file); my $interface_file = Gears::Util->find_header($impl_ir->{isa},"$FindBin::Bin"); -my $inter_ir = Gears::Util->parse_code_verbose($interface_file); +my $inter_ir = Gears::Util->parse_with_rewrite($interface_file); my $output_file = $impl_file; @@ -73,11 +73,11 @@ for my $datum (@impl_data) { if ($datum =~ /\w+ \w+\* (\w+)/) { - print $out " ${impl_inter}->$1 = NULL;\n"; + print $out " ${instance_impl}->$1 = NULL;\n"; next; } if ($datum =~ /\w+ \w+ (\w+)/) { - print $out " ${impl_inter}->$1 = 0;\n"; + print $out " ${instance_impl}->$1 = 0;\n"; } } @@ -92,7 +92,7 @@ } for my $code (@{$inter_ir->{codes}}) { - my $code_gear = $code->[0]; + my $code_gear = $code->{name}; print $out " ${instance_inter}->$code_gear = C_$code_gear$impl_ir->{name};\n" } @@ -115,8 +115,8 @@ my $data_gear_types = {}; for my $code_ir (@{$inter_ir->{codes}}) { - my $data_gears = $code_ir->[1]; - $data_gears =~ s/Impl/$impl/g; + my $data_gears = $code_ir->{args}; + $data_gears =~ s/Impl/struct $impl/g; while ($data_gears =~ /Type\*\s*(\w+),/g) { my $target = $1; if (exists $data_gear_types->{$target}){ @@ -132,7 +132,7 @@ } } - print $out "__code $code_ir->[0]$impl("; + print $out "__code $code_ir->{name}$impl("; print $out "$data_gears) {\n\n"; #__code next(...), __code whenEmpty(...)