changeset 713:843a94916d8a

s/map/for/
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Fri, 28 Aug 2020 11:42:31 +0900
parents df34d44aceca
children d5bd1c640db0
files src/parallel_execution/generate_context.pl src/parallel_execution/lib/Gears/Context.pm src/parallel_execution/lib/Gears/Context/Template.pm src/parallel_execution/lib/Gears/Interface.pm
diffstat 4 files changed, 62 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/generate_context.pl	Tue Aug 25 19:46:57 2020 +0900
+++ b/src/parallel_execution/generate_context.pl	Fri Aug 28 11:42:31 2020 +0900
@@ -99,8 +99,7 @@
 
   my $output     = $opt_w ? "context.h" : "stdout";
 
-  my @cbc_files;
-  map { push(@cbc_files,File::Spec->rel2abs($_)); }  @ARGV;
+  my @cbc_files = map { File::Spec->rel2abs($_) }  @ARGV;
   my $gears      = Gears::Context->new(compile_sources => \@cbc_files, find_root => "$FindBin::Bin/../", output => $output, template => $project->{template});
   my $data_gears = $gears->extraction_dg_compile_sources($gears->{compile_sources});
   my $g          = $gears->set_data_gear_header_path(keys %{$data_gears->{impl}},keys %{$data_gears->{interfaces}});
--- a/src/parallel_execution/lib/Gears/Context.pm	Tue Aug 25 19:46:57 2020 +0900
+++ b/src/parallel_execution/lib/Gears/Context.pm	Fri Aug 28 11:42:31 2020 +0900
@@ -21,7 +21,9 @@
 
   if ($args{compile_sources}) {
     $self->{compile_sources} = $args{compile_sources};
-    map { Gears::Util->file_checking($_); } @{$self->{compile_sources}};
+    for my $file (@{$self->{compile_sources}}) {
+      Gears::Util->file_checking($file);
+    }
   }
 
   return bless $self, $class;
@@ -152,28 +154,40 @@
 sub _docking_header_name_to_path {
   my ($root_path, $data_gears_name) = @_;
   my %res;
-  map { $res{$_}++ } @$data_gears_name;
+
+  for my $dg (@{$data_gears_name}) {
+    $res{$dg}++;
+  }
 
   my $header_paths = Gears::Util->find_headers_from_path($root_path);
-  map {
-    if (/(\w+)\.(?:h|dg)$/) {
-        my $header_file = $1;
-        if (exists $res{$header_file}) {
-          if ($res{$header_file} =~ /^\d+$/){
-            $res{$header_file} = $_;
-          } elsif (($_ =~ /\.dg$/) && ($res{$header_file} =~ /\.h$/)) {
-            $res{$header_file} = $_;
-          }
-        }
+
+  for my $headerPATH (sort @$header_paths) {
+    if ($headerPATH !~ /(\w+)\.(?:h|dg)$/) {
+        next;
+    }
+
+    my $header = $1;
+
+    unless (exists $res{$header}) {
+        next;
     }
-  } sort @$header_paths;
+
+    if ($res{$header} =~ /^\d+$/) {
+      $res{$header} = $headerPATH;
+      next;
+    }
+
+    if (($headerPATH =~ /\.dg/) && ($res{$header} =~ /\.h$/)) {
+      $res{$header} = $headerPATH;
+    }
+  }
+
   return \%res;
 }
 
 sub set_data_gear_header_path {
   my $self = shift;
-  my @data_gears_name;
-  map { push (@data_gears_name,$_) if $_ ne "Context" } @_;
+  my @data_gears_name = grep { $_ ne "Context" } @_;
   return _docking_header_name_to_path($self->{find_root},\@data_gears_name);
 }
 
@@ -182,22 +196,14 @@
   my $new_dgs;
   for my $kind (keys %$dgs) {
     for my $dg_name (keys %{$dgs->{$kind}}) {
-      if ($dg2path->{$dg_name}) {
+      # If a header is not found, dg2path contains the number of times the header was used
+      if ($dg2path->{$dg_name} && $dg2path->{$dg_name} !~ /^\d+$/) {
         $new_dgs->{$kind}->{$dg_name} = $dg2path->{$dg_name};
       } else {
-        croak "failed trans header $dg_name\n";
+        carp "failed trans header $dg_name\n";
       }
     }
   }
-
-  for my $kind (keys %$dgs) {
-    map {
-      if ($new_dgs->{$kind}->{$_} =~ /^\d+$/) {
-        carp "failed: not found $_.(h|dg)\n";
-        delete $new_dgs->{$kind}->{$_};
-      }
-    } keys %{$new_dgs->{$kind}};
-  }
   return $new_dgs;
 }
 
@@ -283,18 +289,25 @@
   #print Dumper $dg2path;
   #print Dumper  $self;
 
-  map {  my $ir = Gears::Interface->parse($inters->{$_});   $dg_str{$_}->{elem} = $ir if $ir} keys %$inters;
+  for my $interface (keys %$inters) {
+    my $ir = Gears::Interface->parse($inters->{$interface});
+    if ($ir) {
+      $dg_str{$interface}->{elem} = $ir;
+    }
+  }
 
-  map {
-    my $res = Gears::Interface->parse($impls->{$_});
-    if ($res) {
-      if ($res->{isa}) {
-          $dg_str{$res->{isa}}->{impl}->{$_} = $res;
-      } else {
-          $dg_str{$_}->{elem} = $res;
-      }
+  for my $impl (keys %$impls) {
+    my $ir = Gears::Interface->parse($impls->{$impl});
+    unless ($ir) {
+      next;
     }
-  } keys %$impls;
+
+    if ($ir->{isa}) {
+      $dg_str{$ir->{isa}}->{impl}->{$impl} = $ir;
+    } else {
+      $dg_str{$impl}->{elem} = $ir;
+    }
+  }
 
   return \%dg_str;
 }
--- a/src/parallel_execution/lib/Gears/Context/Template.pm	Tue Aug 25 19:46:57 2020 +0900
+++ b/src/parallel_execution/lib/Gears/Context/Template.pm	Fri Aug 28 11:42:31 2020 +0900
@@ -157,7 +157,9 @@
 sub emit_include_header {
   my ($class, $out, $from_header_to_caller) = @_;
   for my $header (keys %{$from_header_to_caller}) {
-    map { print $out "// use $_\n" }  @{$from_header_to_caller->{$header}};
+    for my $caller (@{$from_header_to_caller->{$header}}) {
+      print $out "// use $caller\n";
+    }
     print $out "#include \"$header\"\n";
   }
 }
--- a/src/parallel_execution/lib/Gears/Interface.pm	Tue Aug 25 19:46:57 2020 +0900
+++ b/src/parallel_execution/lib/Gears/Interface.pm	Fri Aug 28 11:42:31 2020 +0900
@@ -115,8 +115,14 @@
 
   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}};
+
+  for my $dg (@{$ir->{content}}) {
+    if ($dg =~ /enum Code (\w+);/) {
+      push(@code_gears, $1);
+    } else {
+      push(@data_gears, $dg);
+    }
+  }
 
   open my $fh , '<', $file;
   my $i = 0;
@@ -143,6 +149,7 @@
       }
   }
 
+
   $ir->{codes} = \@code_gears;
   $ir->{data}  = \@data_gears;
   return $ir;