changeset 670:f8b98e469256

use warnings at generate_stub.pl
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Wed, 19 Aug 2020 08:59:07 +0900
parents e8800c60811a
children dbefe3a266ec
files src/parallel_execution/generate_stub.pl
diffstat 1 files changed, 48 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/generate_stub.pl	Wed Aug 19 08:05:53 2020 +0900
+++ b/src/parallel_execution/generate_stub.pl	Wed Aug 19 08:59:07 2020 +0900
@@ -1,8 +1,9 @@
 #!/usr/bin/perl
 
 use strict;
+use warnings;
 use Getopt::Long;
-use File::Path qw(make_path);
+use File::Path qw/make_path/;
 use File::Basename qw/basename dirname/;
 use File::Spec qw/rel2abs/;
 
@@ -169,14 +170,14 @@
         if (/^\s*(.*)\s+(\w+);$/ ) {
             my $ttype = $1;
             my $tname = $2;
-            if ($ttype =~ /^(union|struct|const|enu,)?\s*(\w+)/) {
-                if ($1 ne 'const') {
-                    $ttype = $2;
+            if ($ttype =~ /^(union|struct|const|enum)\s*(\w+)/) {
+                my $structType = $1;
+                my $vname = $2;
+                if ($structType ne 'const') {
+                    $ttype = $vname;
                 } else {
-                    my $vname = $2;
-                    my $ttype = $1;
-                    if ($ttype =~ /(const|enum)/) {
-                      $ttype = "$1 $vname";
+                    if ($structType =~ /(const|enum)/) {
+                      $ttype = "$structType $vname";
                     }
                 }
             }
@@ -193,7 +194,7 @@
               my $tname = $3;
 
               $ttype =~ s/(Impl|Isa|Type)/Data/;
-              if ($const_type =~ /(const|enum)/) {
+              if ($const_type && ($const_type =~ /(const|enum)/)) {
                 $ttype = "$1 $ttype";
               }
               $var{$name}->{$tname} = $ttype;
@@ -236,7 +237,7 @@
                         my $ptrType = $3;
                         my $varName = $4;
                         my $typeField = lcfirst($typeName);
-                        if ($structType =~ /const/) {
+                        if ($structType && ($structType =~ /const/)) {
                             $typeName = "$structType $typeName";
                         }
                         push(@{$code{$name}->{$method}},"$typeName$ptrType $varName");
@@ -308,35 +309,40 @@
     }
     push @{$dataGearVar{$codeGearName}}, $varname1;
     push @{$dataGearVarType{$codeGearName}}, $typeName;
-    if ($typeName eq $implementation) {
+    if ($implementation && ($implementation eq $typeName)) {
         # get implementation
         $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl($context_name, $interface, $varName);\n";
         return 1;
     }
+
+
     # interface var
-    for my $ivar (keys %{$var{$interface}}) {
-        #  input data gear field
-        if ($varName eq $ivar) {
-            if ($typeName eq $var{$interface}->{$ivar}) {
-                if ($output) {
-                    $dataGearName{$codeGearName} .= "\t$typeName$ptrType* O_$varName = &Gearef($context_name, $interface)->$varName;\n";
-                    $outputVar{$codeGearName} .= "\t$typeName$ptrType $varName  __attribute__((unused))  = *O_$varName;\n";
-                    return 1;
-                }
-                $dataGearName{$codeGearName} .= "\t$typeName$ptrType $varName = Gearef($context_name, $interface)->$varName;\n";
-                return 1;
-            }
-        }
+    if ($interface) {
+      for my $ivar (keys %{$var{$interface}}) {
+          #  input data gear field
+          if ($varName eq $ivar) {
+              if ($typeName eq $var{$interface}->{$ivar}) {
+                  if ($output) {
+                      $dataGearName{$codeGearName} .= "\t$typeName$ptrType* O_$varName = &Gearef($context_name, $interface)->$varName;\n";
+                      $outputVar{$codeGearName} .= "\t$typeName$ptrType $varName  __attribute__((unused))  = *O_$varName;\n";
+                      return 1;
+                  }
+                  $dataGearName{$codeGearName} .= "\t$typeName$ptrType $varName = Gearef($context_name, $interface)->$varName;\n";
+                  return 1;
+              }
+          }
+      }
+
+      # interface continuation
+      for my $cName (keys %{$code{$interface}}) {
+          if ($varName eq $cName) {
+              # continuation field
+              $dataGearName{$codeGearName} .= "\tenum Code $varName = Gearef($context_name, $interface)->$varName;\n";
+              return 1;
+          }
+      }
     }
 
-    # interface continuation
-    for my $cName (keys %{$code{$interface}}) {
-        if ($varName eq $cName) {
-            # continuation field
-            $dataGearName{$codeGearName} .= "\tenum Code $varName = Gearef($context_name, $interface)->$varName;\n";
-            return 1;
-        }
-    }
     # par goto  var
     for my $var (keys %{$codeGear{$codeGearName}->{"var"}}) {
         #  input data gear field
@@ -363,9 +369,10 @@
         }
     }
 
+
     # par goto continuation
     # global or local variable case
-    if ($typeName eq "Code") {
+    if (($typeName eq "Code") && $interface) {
         $dataGearName{$codeGearName} .= "\tenum $typeName$ptrType $varName = Gearef(${context_name}, $interface)->$varName;\n";
         return 1;
     }
@@ -419,7 +426,7 @@
                 next unless ($interfaceHeader =~ /context.h/);
             } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
                 $inCode = 1;
-                %localVarType = {};
+                %localVarType = ();
                 $codeGearName = $1;
                 my $args = $2;
                 my $tail = $3;
@@ -492,7 +499,7 @@
                         my $ptrType = $3;
                         my $varName = $4;
                         $newArgs .= $&;    # assuming no duplicate
-                        if ($structType =~ /(const|enum)/) {
+                        if ($structType && ($structType =~ /(const|enum)/)) {
                             $typeName = "$structType $typeName";
                         }
                         my $typeField = lcfirst($typeName);
@@ -519,7 +526,7 @@
                 }
                 next;
             } elsif (! $inCode) {
-                s/new\s+(\w+)\(\)/\&ALLOCATE(${context_name}, \1)->\1/g;   # replacing new
+                s/new\s+(\w+)\(\)/\&ALLOCATE(${context_name}, $1)->$1/g;   # replacing new
                 print $fd $_;
                 next;
             } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) {
@@ -626,10 +633,10 @@
                     print $fd "${prev}GET_META($dataGear)->wait = createSynchronizedQueue(${context_name});\n";
                 }
                 for my $i (0..$inputCount-1) {
-                    print $fd "${prev}${context_name}\->task->data[${context_name}\->task->idg+$i] = (union Data*)@dataGears[$i];\n";
+                    print $fd "${prev}${context_name}\->task->data[${context_name}\->task->idg+$i] = (union Data*)$dataGears[$i];\n";
                 }
                 for my $i (0..$outputCount-1) {
-                    print $fd "${prev}${context_name}\->task->data[${context_name}\->task->odg+$i] = (union Data*)@dataGears[$inputCount+$i];\n";
+                    print $fd "${prev}${context_name}\->task->data[${context_name}\->task->odg+$i] = (union Data*)$dataGears[$inputCount+$i];\n";
                 }
                 my $putTask = << "EOFEOF";
                 ${prev}element = &ALLOCATE(${context_name}, Element)->Element;
@@ -656,7 +663,7 @@
                     # continuation arguments
                     $v = 1  if ( $n eq $next);
                 }
-                if ($v || defined $code{$interface}->{$next}) {
+                if ($v || ($interface && defined $code{$interface}->{$next})) {
                     # write continuation's arguments into the interface arguments
                     # we may need a commit for a shared DataGear
                     for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) {
@@ -690,11 +697,11 @@
                 my $type    = $2;
                 my $varName = $3;
                 $localVarType{$varName} = $type;
-                s/new\s+(\w+)\(\)/\&ALLOCATE(${context_name}, \1)->\1/g;   # replacing new
+                s/new\s+(\w+)\(\)/\&ALLOCATE(${context_name}, $1)->$1/g;   # replacing new
             } elsif(/^}/) {
                 $hasParGoto = 0;
             } else {
-                s/new\s+(\w+)\(\)/\&ALLOCATE(${context_name}, \1)->\1/g;   # replacing new
+                s/new\s+(\w+)\(\)/\&ALLOCATE(${context_name}, $1)->$1/g;   # replacing new
             }
             # gather type name and type
         } elsif ($inMain) {