changeset 941:78966e75194f

...
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Wed, 03 Feb 2021 23:14:48 +0900
parents f98fc785a397
children 604b0fd7f537
files src/parallel_execution/generate_context.pl src/parallel_execution/lib/Gears/Context.pm
diffstat 2 files changed, 83 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/generate_context.pl	Wed Feb 03 09:05:27 2021 +0900
+++ b/src/parallel_execution/generate_context.pl	Wed Feb 03 23:14:48 2021 +0900
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 #use DDP {deparse => 1};
-
+#
 #
 # generrate Gears OS context heaader and initializer from CbC sources
 #
@@ -105,11 +105,12 @@
 
   my @cbc_files = map { File::Spec->rel2abs($_) }  @ARGV;
   my $gears      = Gears::Context->new(
-                                       compile_sources => \@cbc_files,
-                                       find_root       => "$FindBin::Bin/../",
-                                       output          => $output,
-                                       project         => $opt_o,
-                                       template        => $project->{template});
+                                       compile_sources      => \@cbc_files,
+                                       find_root            => "$FindBin::Bin/../",
+                                       generate_script_path => $FindBin::Bin,
+                                       output               => $output,
+                                       project              => $opt_o,
+                                       template             => $project->{template});
 
   my $data_gears               = $gears->extraction_dg_compile_sources($gears->{compile_sources});
   my $data_gear_to_header_path = $gears->set_data_gear_header_path(keys %{$data_gears->{impl}},keys %{$data_gears->{interfaces}});
@@ -122,18 +123,28 @@
   my ($type_var, $type_ins) = check_use_generics($typed_variable, $generics, $gears->{generics_list});
 
   my $modify_list = convertGenerics($type_var, $type_ins);
-  my @mod;
 
-  if (%$modify_list) {
-    for my $ftype (qw/cbc header/) {
-      for my $fname (keys %{$modify_list->{$ftype}}) {
-        my $fileInfo = $modify_list->{$ftype}->{$fname};
-        for my $item (grep { $_->{before_impl} } @{$fileInfo}) {
-          print STDERR "@{$item->{before_impl}}\n";
+  my %tmp = map {
+    my %tmp;
+    my $interface = $tree->{$_};
+    if ($interface->{elem}) {
+      my $elem = $interface->{elem};
+      if ($elem->{typed_variable}) {
+        push(@{$tmp{$_}->{var}}, $elem->{typed_variable});
+      }
+    }
+
+    if ($interface->{impl}) {
+      for my $implName (keys %{$interface->{impl}}) {
+        my $elem = $interface->{impl}->{$implName};
+        if ($elem->{typed_variable}) {
+          push(@{$tmp{$implName}->{var}}, $elem->{typed_variable});
         }
       }
     }
-  }
+    %tmp;
+  } keys %$tree;
+
 
   $gears->tree2create_context_h($tree);
 }
--- a/src/parallel_execution/lib/Gears/Context.pm	Wed Feb 03 09:05:27 2021 +0900
+++ b/src/parallel_execution/lib/Gears/Context.pm	Wed Feb 03 23:14:48 2021 +0900
@@ -17,8 +17,10 @@
     data_gears_with_count => {},
     project               => $args{project},
     find_root             => $args{find_root} // ".",
+    generate_script_path  => $args{generate_script_path},
     output                => $args{output},
     template              => $args{template}  // "Gears::Template::Context",
+    interfaces            => Gears::Util->find_headers_from_path($args{find_root}),
     generics_list         => {}, #generics_list has two keys, defined_type or type_variable
                                  #type_variable is not defined specific type value
   };
@@ -40,18 +42,20 @@
   my %include_pool = ();
   for my $cbc_file (@{$compile_sources}) {
     open my $fh , '<', $cbc_file;
+    my $line_number = 0;
     while (my $line = <$fh>) {
-        if ($line =~ m|//\s*:skip|) {
-          next;
-        }
+       $line_number++;
+       if ($line =~ m|//\s*:skip|) {
+         next;
+       }
 
        if ($line =~ /#interface\s*"(.*)\.h"/) {
-          push(@{$counter{interfaces}->{$1}->{$cbc_file}},$.);
+          push(@{$counter{interfaces}->{$1}->{$cbc_file}},$line_number);
           next;
        }
 
        if ($line =~ /^\/\/\s*include\s*"(.*)\.(?:h|dg)?"/) {
-          push(@{$include_pool{$1}->{$cbc_file}},$.);
+          push(@{$include_pool{$1}->{$cbc_file}},$line_number);
           next;
        }
 
@@ -60,6 +64,40 @@
           next;
        }
 
+       while ($line =~ m|\s*(\w+)<([\w,]+)>\s*\*?\s*(\w+)|g) {
+         my $interface = $1;
+         my @generics_list = split /,/, $2;
+         my $vname = $3;
+         my @find_headers = grep { /$interface\.h$/ } @{$self->{interfaces}};
+         if (@find_headers != 1) { # !=1 case means exist multi header file
+                                  # we coolect current project header file
+            # find current project
+            @find_headers =  grep { /$self->{project}/ } @find_headers;
+         }
+         my $parsedHeader = Gears::Interface->parse($find_headers[0]);
+
+         if ($parsedHeader->{typed_variable_types}) {
+           for my $generics (@generics_list) {
+             unless ($parsedHeader->{typed_variable_types}->{$generics}) {
+               #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
+                      }
+                    );
+                }
+           }
+         }
+
+       }
 
        if ($line =~ /^\s*(\w+)(<(.*)>)\s*?\*\s*create(\w+)\(([<>,*\w\s]+)\)/) {
          #AtomicT<T>* createAtomicT(struct Context* context,T init) {
@@ -94,7 +132,7 @@
                         vname          => $tmpVarName,
                         typed_variable => $tmpGenerics,
                         caller         => $cbc_file,
-                        line_number    => $.
+                        line_number    => $line_number
                       }
                     );
                 } else {
@@ -107,7 +145,7 @@
                         vname        => $tmpVarName,
                         defined_type => $tmpGenerics,
                         caller       => $cbc_file,
-                        line_number  => $.
+                        line_number  => $line_number
                       }
                     );
                 }
@@ -115,8 +153,8 @@
             }
           }
 
-          push(@{$counter{interfaces}->{$interface}->{$cbc_file}},$.);
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          push(@{$counter{interfaces}->{$interface}->{$cbc_file}},$line_number);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$line_number);
           if ($generics) {
             #"AtomicT<T>* createAtomicTImpl(struct Context* context,T init) {
             push(
@@ -128,7 +166,7 @@
                         vname          => $interface,  #==> define val?
                         typed_variable => $generics, #T
                         caller         => $cbc_file,
-                        line_number    => $.
+                        line_number    => $line_number
                       }
                   );
           }
@@ -151,7 +189,7 @@
            $impl = $1;
          }
 
-          push(@{$counter{interfaces}->{$interface}->{$cbc_file}},$.);
+          push(@{$counter{interfaces}->{$interface}->{$cbc_file}},$line_number);
           push(@{$self->{generics_list}->{defined_type}},
             {
               interface    => $interface,
@@ -160,7 +198,7 @@
               vname        => $interface,
               defined_type => $generics,
               caller       => $cbc_file,
-              line_number  => $.
+              line_number  => $line_number
             }
           );
        }
@@ -168,7 +206,7 @@
 
        if ($line =~ /Gearef\(context,\s*(\w+)\)/) {
           my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$line_number);
           next;
        }
 
@@ -177,25 +215,25 @@
     #Element* element = &ALLOCATE(cbc_context, Element)->Element;
        if ($line =~ /ALLOCATE\w*\((?:cbc_)?context,\s*(\w+)\)/) {
           my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$line_number);
           next;
        }
 
        if ($line =~ /ALLOCATE_(?:PTR_)?ARRAY\((?:cbc_)?context,\s*(\w+),[\s\w]+\)/) {
           my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$line_number);
           next;
        }
 
        if ($line =~ /new\s+(\w+?)\([\w\s]*\);/) {
           my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$line_number);
           next;
        }
 
        if ($line =~ /ALLOCATE_DATA_GEAR\((\w+),\s*(\w+)\)/) {
           my $implementation = $2;
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$line_number);
           next;
        }
 
@@ -203,8 +241,8 @@
        if ($line =~ /\((\w+)\*\)GearImpl\(context,\s*(\w+),\s*(\w+)\)/) {
           my $implementation = $1;
           my $interface      = $2;
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
-          push(@{$counter{interfaces}->{$interface}->{$cbc_file}},$.);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$line_number);
+          push(@{$counter{interfaces}->{$interface}->{$cbc_file}},$line_number);
           next;
        }
 
@@ -212,7 +250,7 @@
          while ($line =~ /struct (\w+)\s*\*/g) {
            next if $1 eq "Context";
            next if (exists $counter{interfaces}->{$1});
-           push(@{$counter{impl}->{$1}->{$cbc_file}},$.);
+           push(@{$counter{impl}->{$1}->{$cbc_file}},$line_number);
          }
        }
     }