changeset 942:604b0fd7f537

generics
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Thu, 04 Feb 2021 00:37:39 +0900
parents 78966e75194f
children 7eb9d23da279
files src/parallel_execution/examples/DPP/main.cbc src/parallel_execution/generate_context.pl src/parallel_execution/lib/Gears/Context.pm
diffstat 3 files changed, 69 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/examples/DPP/main.cbc	Wed Feb 03 23:14:48 2021 +0900
+++ b/src/parallel_execution/examples/DPP/main.cbc	Thu Feb 04 00:37:39 2021 +0900
@@ -40,11 +40,11 @@
 
 
 __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
-    AtomicT<int>* fork0 = createAtomicTImpl(contex,-1); // model checking : fork0
-    AtomicT<int>* fork1 = createAtomicTImpl(contex,-1); // model checking : fork1
-    AtomicT<int>* fork2 = createAtomicTImpl(contex,-1); // model checking : fork2
-    AtomicT<int>* fork3 = createAtomicTImpl(contex,-1); // model checking : fork3
-    AtomicT<int>* fork4 = createAtomicTImpl(contex,-1); // model checking : fork4
+    AtomicT<int>* fork0 = createAtomicTImpl<int>(contex,-1); // model checking : fork0
+    AtomicT<int>* fork1 = createAtomicTImpl<int>(contex,-1); // model checking : fork1
+    AtomicT<int>* fork2 = createAtomicTImpl<int>(contex,-1); // model checking : fork2
+    AtomicT<int>* fork3 = createAtomicTImpl<int>(contex,-1); // model checking : fork3
+    AtomicT<int>* fork4 = createAtomicTImpl<int>(contex,-1); // model checking : fork4
 
     Phils* phils0 = createPhilsImpl(context,0,fork0,fork1); // model checking : phils0
     Phils* phils1 = createPhilsImpl(context,1,fork1,fork2); // model checking : phils1
--- a/src/parallel_execution/generate_context.pl	Wed Feb 03 23:14:48 2021 +0900
+++ b/src/parallel_execution/generate_context.pl	Thu Feb 04 00:37:39 2021 +0900
@@ -530,7 +530,7 @@
 
 
         my @types = keys %{{ map { $_->{in_type_name} => 1 } @{$file_each_instances->{$file}} }};
-        my @impls = keys %{{ map { $_->{impl} => 1 } @{$file_each_instances->{$file}} }};
+        my @impls = keys %{{ map { $_->{impl} => 1 } grep { exists $_->{impl} } @{$file_each_instances->{$file}} }};
 
 
         if ( (scalar(@types) != 1) && (scalar(@types) != scalar(@impls))) {
@@ -543,6 +543,7 @@
         my @rep_types;
 
         for my $t ($type, $impl) {
+          next unless ($t);
           if (exists $typed_variables->{$t}) {
             push(@rep_types, grep { ($_ ne '_caller' ) && ( $_ ne '_interface' )  } keys %{$typed_variables->{$t}});
           }
@@ -561,40 +562,51 @@
 
         $replaceType =~ s/$type/${type}_$defType/;
         my $repimpl = 0;
-        if (defined $typed_variables->{$impl}) {
-          $replaceImpls =~ s/$type/${type}_$defType/;
-          $targetImpl   =~ s/$type/${type}_$defType/;
-          $replaceImpls =~ s/$/_$defType/;
-          $repimpl = 1;
+        if ($impl) {
+          if (defined $typed_variables->{$impl}) {
+            $replaceImpls =~ s/$type/${type}_$defType/;
+            $targetImpl   =~ s/$type/${type}_$defType/;
+            $replaceImpls =~ s/$/_$defType/;
+            $repimpl = 1;
+          }
         }
 
         if ($file =~ /\.h$/) {
           print STDERR "[info] $file is header\n";
           unless (grep { $_ eq $replaceType } map { $_->{before} } @{$modifyList->{header}->{$file}}) {
             push(@{$modifyList->{header}->{$file}}, { before => [$type], after => [$replaceType]});
+            my $implName = $file_each_instances->{$file}->[0]->{impl};
+            unless ($implName) {
+              print STDERR "[error] not implemented thsi case\n";
+            }
+            push(@{$modifyList->{replace}->{$implName}}, { before => [$type], after => [$replaceType]});
           }
           next;
         }
 
-        if ($impl eq $replaceImpls) { #not impl
-          push(@{$modifyList->{cbc}->{$file}},{before => [$type], after => [$replaceType]});
-        } else { #impl
-          #push(@{$modifyList->{cbc}->{$file}},{before => [$type, $impl], after => [$replaceType, $replaceImpls]});
-          push(@{$modifyList->{cbc}->{$file}},
-                {
-                  before      => [$type], after      => [$replaceType],
-                  before_impl => [$impl], after_impl => [$replaceImpls]
-                }
-              );
+        if ($impl) {
+          if ($impl eq $replaceImpls) { #not impl
+            push(@{$modifyList->{cbc}->{$file}},{before => [$type], after => [$replaceType]});
+          } else { #impl
+            #push(@{$modifyList->{cbc}->{$file}},{before => [$type, $impl], after => [$replaceType, $replaceImpls]});
+            push(@{$modifyList->{cbc}->{$file}},
+                  {
+                    before      => [$type], after      => [$replaceType],
+                    before_impl => [$impl], after_impl => [$replaceImpls]
+                  }
+                );
+            push(@{$modifyList->{replace}->{$type}}, { before => [$type], after => [$replaceType]});
+            push(@{$modifyList->{replace}->{$impl}}, { before => [$impl], after => [$replaceImpls]});
+          }
         }
 
         my @cbc_cont;
 
         open my $fh, '<', $file;
         while (my $line = <$fh> ){
-          $line =~ s/$type(<.*>)?/$replaceType/g;
+          $line =~ s/$type(<.*?>)?/$replaceType/g;
           if ($repimpl) {
-            $line =~ s/${targetImpl}(<.*>)?/$replaceImpls/g;
+            $line =~ s/${targetImpl}(<.*?>)?/$replaceImpls/g;
           }
           $line =~ s/${type_v}([\s\*])/$defType$1/;
           push(@cbc_cont, $line);
@@ -606,12 +618,12 @@
     }
   }
 
-  #for my $type (keys %$typed_variables) {
-  #   my @cfiles = grep { /\.c$/ } keys  %{$typed_variables->{$type}->{_caller}};
-  #   for my $file (@cfiles) {
-  #     p $type;
-  #   }
-  # }
+  for my $type (keys %$typed_variables) {
+     my @cfiles = grep { /\.c$/ } keys  %{$typed_variables->{$type}->{_caller}};
+     for my $file (@cfiles) {
+       push(@{$modifyList->{replaceFiles}->{$file}}, $type);
+     }
+   }
 
   #for my $file (keys %$file2cont) {
   #  open my $fh, '>', $file;
@@ -620,6 +632,7 @@
   #  }
   #  close $fh;
   #}
+  #p $modifyList;
   return $modifyList;
 }
 
--- a/src/parallel_execution/lib/Gears/Context.pm	Wed Feb 03 23:14:48 2021 +0900
+++ b/src/parallel_execution/lib/Gears/Context.pm	Thu Feb 04 00:37:39 2021 +0900
@@ -78,25 +78,36 @@
 
          if ($parsedHeader->{typed_variable_types}) {
            for my $generics (@generics_list) {
-             unless ($parsedHeader->{typed_variable_types}->{$generics}) {
+             if ($parsedHeader->{typed_variable_types}->{$generics}) {
+                push(
+                  @{$self->{generics_list}->{typed_variable}},
+                  {
+                    interface      => $interface,
+                    impl           => undef,
+                    type           => $interface,
+                    vname          => $vname,
+                    typed_variable => $generics,
+                    caller         => $cbc_file,
+                    line_number    => $line_number
+                  }
+                );
+              } else {
                #this case is defined type
-             } else {
-                    push(
-                      @{$self->{generics_list}->{typed_variable}},
-                      {
-                        interface      => $interface,
-                        impl           => undef,
-                        type           => $interface,
-                        vname          => $vname,
-                        typed_variable => $generics,
-                        caller         => $cbc_file,
-                        line_number    => $line_number
-                      }
-                    );
-                }
+                push(
+                  @{$self->{generics_list}->{defined_type}},
+                  {
+                    interface    => $interface,
+                    impl         => undef,
+                    type         => $interface,
+                    vname        => $vname,
+                    defined_type => $generics,
+                    caller       => $cbc_file,
+                    line_number  => $line_number
+                  }
+                );
+              }
            }
          }
-
        }
 
        if ($line =~ /^\s*(\w+)(<(.*)>)\s*?\*\s*create(\w+)\(([<>,*\w\s]+)\)/) {