changeset 280:21a5761e3e7a

mv_extraction_dg_compile_sources Context2Util
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 28 Jan 2020 15:20:34 +0900
parents 0a74a7bbe765
children 4d76280758db
files src/gearsTools/lib/Gears/Context.pm src/gearsTools/lib/Gears/Stub.pm src/gearsTools/lib/Gears/Util.pm
diffstat 3 files changed, 118 insertions(+), 113 deletions(-) [+]
line wrap: on
line diff
--- a/src/gearsTools/lib/Gears/Context.pm	Tue Jan 28 15:10:22 2020 +0900
+++ b/src/gearsTools/lib/Gears/Context.pm	Tue Jan 28 15:20:34 2020 +0900
@@ -26,117 +26,7 @@
 
 sub extraction_dg_compile_sources {
   my ($self, $compile_sources) = @_;
-  my %counter;
-  my %include_pool = ();
-  for my $cbc_file (@{$compile_sources}) {
-    open my $fh , '<', $cbc_file;
-    while (my $line = <$fh>) {
-        if ($line =~ m|//\s*:skip|) {
-         next;
-        }
-
-       if ($line =~ /#interface\s*"(.*)\.h"/) {
-          push(@{$counter{interfaces}->{$1}->{$cbc_file}},$.);
-          next;
-       }
-
-       if ($line =~ /^\/\/\s*data_gear\s*"(.*)\.(?:h|dg)?"/) {
-          push(@{$include_pool{$1}->{$cbc_file}},$.);
-          next;
-       }
-
-       if ($line =~ m|//\s*Skip:\s*generate_context|) {
-         $line = <$fh>;
-         next;
-       }
-
-
-       #if ($line =~ /^(\w+)(\*)+  *create(\w+)\(([^]]*)\)/) {
-       #   my $interface = $1;
-       #   my $implementation = $3;
-       #   $self->{data_gears_with_count}->{$interface}->{caller}->{$cbc_file}++;
-       #   $self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}++;
-       #   $counter{interfaces}->{$interface}++;
-       #   $counter{impl}->{$implementation}++;
-       #   next;
-       #}
-
-       if ($line =~ /Gearef\(context,\s*(\w+)\)/) {
-          my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
-          next;
-       }
-
-    #Element* element = &ALLOCATE(cbc_context, Element)->Element;
-       if ($line =~ /ALLOCATE\w*\((?:cbc_)?context,\s*(\w+)\)/) {
-          my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
-          next;
-       }
-
-       if ($line =~ /ALLOCATE_(?:PTR_)?ARRAY\((?:cbc_)?context,\s*(\w+),[\s\w]+\)/) {
-          my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
-          next;
-       }
-
-       if ($line =~ /new\s+(\w+?)\([\w\s]*\);/) {
-          my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
-          next;
-       }
-
-       if ($line =~ /ALLOCATE_DATA_GEAR\((\w+),\s*(\w+)\)/) {
-          my $implementation = $2;
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
-          next;
-       }
-
-       #TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
-       if ($line =~ /\((\w+)\*\)GearImpl\(context,\s*(\w+),\s*(\w+)\)/) {
-          my $interface = $2;
-          my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
-          push(@{$counter{interfaces}->{$interface}->{$cbc_file}},$.);
-          next;
-       }
-
-       if ($line =~ /^__code/) {
-         while ($line =~ /struct (\w+)\s*\*/g) {
-           next if $1 eq "Context";
-           next if (exists $counter{interfaces}->{$1});
-           push(@{$counter{impl}->{$1}->{$cbc_file}},$.);
-         }
-       }
-    }
-    close $fh;
-  }
-  use Data::Dumper;
-
-  for my $cg_name (keys %include_pool) {
-    my @tmp_cbc_file_names  = keys %{$include_pool{$cg_name}};
-    my $tmp_cbc_file_name  = shift @tmp_cbc_file_names;
-    if (exists $counter{interfaces}->{$cg_name}){
-      push(@{$counter{interfaces}->{$cg_name}->{$tmp_cbc_file_name}},$include_pool{$cg_name}->{$tmp_cbc_file_name});
-      delete $include_pool{$cg_name};
-      next;
-    }
-
-    if (exists $counter{impl}->{$cg_name}){
-      push(@{$counter{impl}->{$cg_name}->{$tmp_cbc_file_name}},$include_pool{$cg_name}->{$tmp_cbc_file_name});
-      delete $include_pool{$cg_name};
-      next;
-    }
-    push(@{$counter{interfaces}->{$cg_name}->{$tmp_cbc_file_name}},$include_pool{$cg_name}->{$tmp_cbc_file_name});
-    delete $include_pool{$cg_name};
-  }
-
-  $counter{interfaces}->{Meta}++;
-  $counter{interfaces}->{TaskManager}++;
-  print "-----------\n";
-  print Dumper \%counter;
-  print "-----------\n";
-  return \%counter;
+  return Gears::Util->extraction_dg_compile_sources($compile_sources);
 }
 
 sub set_data_gear_header_path {
--- a/src/gearsTools/lib/Gears/Stub.pm	Tue Jan 28 15:10:22 2020 +0900
+++ b/src/gearsTools/lib/Gears/Stub.pm	Tue Jan 28 15:20:34 2020 +0900
@@ -4,7 +4,6 @@
 use Carp qw/croak/;
 use File::Find;
 use Gears::Util;
-use Gears::Context;
 
 use DDP {deparse => 1};
 
@@ -22,7 +21,7 @@
 sub findInterfacewImpl {
   my $self     = shift;
   my $cbc_file = shift // $self->{file_name};
-  my $findInterfaces = Gears::Context->extraction_dg_compile_sources([$cbc_file]);
+  my $findInterfaces = Gears::Util->extraction_dg_compile_sources([$cbc_file]);
   p $findInterfaces;
 }
 
--- a/src/gearsTools/lib/Gears/Util.pm	Tue Jan 28 15:10:22 2020 +0900
+++ b/src/gearsTools/lib/Gears/Util.pm	Tue Jan 28 15:20:34 2020 +0900
@@ -164,5 +164,121 @@
   return $context;
 }
 
+sub extraction_dg_compile_sources {
+  my ($class, $compile_sources) = @_;
+  my %counter;
+  my %include_pool = ();
+  for my $cbc_file (@{$compile_sources}) {
+    open my $fh , '<', $cbc_file;
+    while (my $line = <$fh>) {
+        if ($line =~ m|//\s*:skip|) {
+         next;
+        }
+
+       if ($line =~ /#interface\s*"(.*)\.h"/) {
+          push(@{$counter{interfaces}->{$1}->{$cbc_file}},$.);
+          next;
+       }
+
+       if ($line =~ /^\/\/\s*data_gear\s*"(.*)\.(?:h|dg)?"/) {
+          push(@{$include_pool{$1}->{$cbc_file}},$.);
+          next;
+       }
+
+       if ($line =~ m|//\s*Skip:\s*generate_context|) {
+         $line = <$fh>;
+         next;
+       }
+
+
+       #if ($line =~ /^(\w+)(\*)+  *create(\w+)\(([^]]*)\)/) {
+       #   my $interface = $1;
+       #   my $implementation = $3;
+       #   $self->{data_gears_with_count}->{$interface}->{caller}->{$cbc_file}++;
+       #   $self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}++;
+       #   $counter{interfaces}->{$interface}++;
+       #   $counter{impl}->{$implementation}++;
+       #   next;
+       #}
+
+       if ($line =~ /Gearef\(context,\s*(\w+)\)/) {
+          my $implementation = $1;
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          next;
+       }
+
+    #Element* element = &ALLOCATE(cbc_context, Element)->Element;
+       if ($line =~ /ALLOCATE\w*\((?:cbc_)?context,\s*(\w+)\)/) {
+          my $implementation = $1;
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          next;
+       }
+
+       if ($line =~ /ALLOCATE_(?:PTR_)?ARRAY\((?:cbc_)?context,\s*(\w+),[\s\w]+\)/) {
+          my $implementation = $1;
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          next;
+       }
+
+       if ($line =~ /new\s+(\w+?)\([\w\s]*\);/) {
+          my $implementation = $1;
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          next;
+       }
+
+       if ($line =~ /ALLOCATE_DATA_GEAR\((\w+),\s*(\w+)\)/) {
+          my $implementation = $2;
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          next;
+       }
+
+       #TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
+       if ($line =~ /\((\w+)\*\)GearImpl\(context,\s*(\w+),\s*(\w+)\)/) {
+          my $interface = $2;
+          my $implementation = $1;
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          push(@{$counter{interfaces}->{$interface}->{$cbc_file}},$.);
+          next;
+       }
+
+       if ($line =~ /^__code/) {
+         while ($line =~ /struct (\w+)\s*\*/g) {
+           next if $1 eq "Context";
+           next if (exists $counter{interfaces}->{$1});
+           push(@{$counter{impl}->{$1}->{$cbc_file}},$.);
+         }
+       }
+    }
+    close $fh;
+  }
+  use Data::Dumper;
+
+  for my $cg_name (keys %include_pool) {
+    my @tmp_cbc_file_names  = keys %{$include_pool{$cg_name}};
+    my $tmp_cbc_file_name  = shift @tmp_cbc_file_names;
+    if (exists $counter{interfaces}->{$cg_name}){
+      push(@{$counter{interfaces}->{$cg_name}->{$tmp_cbc_file_name}},$include_pool{$cg_name}->{$tmp_cbc_file_name});
+      delete $include_pool{$cg_name};
+      next;
+    }
+
+    if (exists $counter{impl}->{$cg_name}){
+      push(@{$counter{impl}->{$cg_name}->{$tmp_cbc_file_name}},$include_pool{$cg_name}->{$tmp_cbc_file_name});
+      delete $include_pool{$cg_name};
+      next;
+    }
+    push(@{$counter{interfaces}->{$cg_name}->{$tmp_cbc_file_name}},$include_pool{$cg_name}->{$tmp_cbc_file_name});
+    delete $include_pool{$cg_name};
+  }
+
+  $counter{interfaces}->{Meta}++;
+  $counter{interfaces}->{TaskManager}++;
+  print "-----------\n";
+  print Dumper \%counter;
+  print "-----------\n";
+  return \%counter;
+}
+
+
 
 1;