changeset 705:cf82fc3512dd

fix collect local variables
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Aug 2020 08:54:17 +0900
parents d05e327cbc50
children ba423a2e0e8e
files src/parallel_execution/generate_stub.pl src/parallel_execution/lib/Gears/Context.pm src/parallel_execution/lib/Gears/Util.pm
diffstat 3 files changed, 33 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/generate_stub.pl	Sun Aug 23 06:53:13 2020 +0900
+++ b/src/parallel_execution/generate_stub.pl	Sun Aug 23 08:54:17 2020 +0900
@@ -8,7 +8,6 @@
 
 use FindBin;
 use lib "$FindBin::Bin/lib";
-use DDP {deparse => 1};
 
 use Gears::Interface;
 use Gears::Util;
@@ -158,12 +157,7 @@
                 next if ($interfaceHeader =~ /context.h/);
                 $interfaceHeader =~ m|(\w+)\.\w+$|; #remove filename extention
                 my $interfaceName = $1;
-                $call_interfaces{$filename}->{$interfaceName} = 1;
-                my $interface_path = $interfaceNameToHeaderPath->{$interfaceName};
-                if ($interface_path) {
-                    &getDataGear($interface_path);
-                    &getCodeGear($interface_path);
-                }
+                includeInterface(\%call_interfaces, $filename, $interfaceName, $interfaceNameToHeaderPath);
             } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
                 my $codeGearName = $1;
                 my $args = $2;
@@ -176,7 +170,7 @@
                   $codeGearInfo->{$codeGearName}->{arg}->{$vname} = $vname2type->{$vname};
                 }
                 $currentCodeGear = $codeGearName;
-            } elsif ((/^\s*(\w+)?\s*(\w+)(\*)\s+(\w+)\s+=/) && $currentCodeGear) { # collect local variables
+            } elsif ((/^\s*(union|struct|const|enum)?\s*(\w+)(\*)\s+(\w+)\s+=/) && $currentCodeGear) { # collect local variables
                 my $structType = $1;
                 my $interfaceName = $2;
                 my $instance = $4;
@@ -201,24 +195,15 @@
                     die "[ERROR] not found $instance type $.: $_\n";
                   }
                 }
-
-
                 unless (exists $call_interfaces{$filename}->{$typeName}) {
-                  warn "[WARN] forget #interface'$typeName'";
-                  $call_interfaces{$filename}->{$typeName} = 1;
-                  my $interface_path = $interfaceNameToHeaderPath->{$typeName};
-                  if ($interface_path) {
-                      &getDataGear($interface_path);
-                      &getCodeGear($interface_path);
-                  }
+                  warn "[AUTOINCLUDE] Forget #interface '$typeName'  declaration in $filename";
+                  includeInterface(\%call_interfaces, $filename, $typeName, $interfaceNameToHeaderPath);
                 }
 
                 my $res = findExistsOutputDataGear($typeName, $method);
                 if ($res) {
                   my @parsedArgs = split /,/ , $tmpArgs;
                   if (scalar(@parsedArgs) != 1) {
-                    p $tmpArgs;
-                    p @parsedArgs;
                     warn '[WARN] TBD';
                   }
                   #p $res;
@@ -267,6 +252,16 @@
 
 }
 
+sub includeInterface {
+    my ($call_interfaces, $filename, $interfaceName, $interfaceNameToHeaderPath) = @_;
+    $call_interfaces->{$filename}->{$interfaceName} = 1;
+    my $interface_path = $interfaceNameToHeaderPath->{$interfaceName};
+    if ($interface_path) {
+        getDataGear($interface_path);
+        getCodeGear($interface_path);
+    }
+}
+
 
 sub getCodeGear {
     my ($filename) = @_;
--- a/src/parallel_execution/lib/Gears/Context.pm	Sun Aug 23 06:53:13 2020 +0900
+++ b/src/parallel_execution/lib/Gears/Context.pm	Sun Aug 23 08:54:17 2020 +0900
@@ -227,7 +227,7 @@
 
 sub _select_output {
   my $self = shift;
-  print "$self->{output}\n";
+  #print "$self->{output}\n";
   if ($self->{output} eq  'stdout') {
     return *STDOUT;
   }
--- a/src/parallel_execution/lib/Gears/Util.pm	Sun Aug 23 06:53:13 2020 +0900
+++ b/src/parallel_execution/lib/Gears/Util.pm	Sun Aug 23 08:54:17 2020 +0900
@@ -58,6 +58,7 @@
 
 sub collect_codegears_from_all_cbc_sources {
   my ($class, $find_path) = @_;
+  $find_path //= ".";
 
   if ($cbc_files_analyzed_code_gear) {
     return $cbc_files_analyzed_code_gear;
@@ -81,6 +82,21 @@
   return $cbc_files_analyzed_code_gear;
 }
 
+
+sub searchFileContainsCodeGear {
+  my ($class, $codeGearName) = @_;
+  unless ($cbc_files_analyzed_code_gear) {
+    Gears::Util-> collect_codegears_from_all_cbc_sources();
+  }
+
+  my @res = grep { exists $cbc_files_analyzed_code_gear->{$_}->{$codeGearName} } keys %$cbc_files_analyzed_code_gear;
+
+  unless (@res) {
+    return undef;
+  }
+  return \@res;
+}
+
 sub parseCodeGearDeclarationArg {
     my ($clas, $args) = @_;
     my %tname2type;
@@ -100,4 +116,6 @@
 }
 
 
+
+
 1;