comparison src/gearsTools/lib/Gears/Context.pm @ 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 0ea4d14c54bd
children 4d76280758db
comparison
equal deleted inserted replaced
279:0a74a7bbe765 280:21a5761e3e7a
24 } 24 }
25 25
26 26
27 sub extraction_dg_compile_sources { 27 sub extraction_dg_compile_sources {
28 my ($self, $compile_sources) = @_; 28 my ($self, $compile_sources) = @_;
29 my %counter; 29 return Gears::Util->extraction_dg_compile_sources($compile_sources);
30 my %include_pool = ();
31 for my $cbc_file (@{$compile_sources}) {
32 open my $fh , '<', $cbc_file;
33 while (my $line = <$fh>) {
34 if ($line =~ m|//\s*:skip|) {
35 next;
36 }
37
38 if ($line =~ /#interface\s*"(.*)\.h"/) {
39 push(@{$counter{interfaces}->{$1}->{$cbc_file}},$.);
40 next;
41 }
42
43 if ($line =~ /^\/\/\s*data_gear\s*"(.*)\.(?:h|dg)?"/) {
44 push(@{$include_pool{$1}->{$cbc_file}},$.);
45 next;
46 }
47
48 if ($line =~ m|//\s*Skip:\s*generate_context|) {
49 $line = <$fh>;
50 next;
51 }
52
53
54 #if ($line =~ /^(\w+)(\*)+ *create(\w+)\(([^]]*)\)/) {
55 # my $interface = $1;
56 # my $implementation = $3;
57 # $self->{data_gears_with_count}->{$interface}->{caller}->{$cbc_file}++;
58 # $self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}++;
59 # $counter{interfaces}->{$interface}++;
60 # $counter{impl}->{$implementation}++;
61 # next;
62 #}
63
64 if ($line =~ /Gearef\(context,\s*(\w+)\)/) {
65 my $implementation = $1;
66 push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
67 next;
68 }
69
70 #Element* element = &ALLOCATE(cbc_context, Element)->Element;
71 if ($line =~ /ALLOCATE\w*\((?:cbc_)?context,\s*(\w+)\)/) {
72 my $implementation = $1;
73 push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
74 next;
75 }
76
77 if ($line =~ /ALLOCATE_(?:PTR_)?ARRAY\((?:cbc_)?context,\s*(\w+),[\s\w]+\)/) {
78 my $implementation = $1;
79 push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
80 next;
81 }
82
83 if ($line =~ /new\s+(\w+?)\([\w\s]*\);/) {
84 my $implementation = $1;
85 push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
86 next;
87 }
88
89 if ($line =~ /ALLOCATE_DATA_GEAR\((\w+),\s*(\w+)\)/) {
90 my $implementation = $2;
91 push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
92 next;
93 }
94
95 #TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
96 if ($line =~ /\((\w+)\*\)GearImpl\(context,\s*(\w+),\s*(\w+)\)/) {
97 my $interface = $2;
98 my $implementation = $1;
99 push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
100 push(@{$counter{interfaces}->{$interface}->{$cbc_file}},$.);
101 next;
102 }
103
104 if ($line =~ /^__code/) {
105 while ($line =~ /struct (\w+)\s*\*/g) {
106 next if $1 eq "Context";
107 next if (exists $counter{interfaces}->{$1});
108 push(@{$counter{impl}->{$1}->{$cbc_file}},$.);
109 }
110 }
111 }
112 close $fh;
113 }
114 use Data::Dumper;
115
116 for my $cg_name (keys %include_pool) {
117 my @tmp_cbc_file_names = keys %{$include_pool{$cg_name}};
118 my $tmp_cbc_file_name = shift @tmp_cbc_file_names;
119 if (exists $counter{interfaces}->{$cg_name}){
120 push(@{$counter{interfaces}->{$cg_name}->{$tmp_cbc_file_name}},$include_pool{$cg_name}->{$tmp_cbc_file_name});
121 delete $include_pool{$cg_name};
122 next;
123 }
124
125 if (exists $counter{impl}->{$cg_name}){
126 push(@{$counter{impl}->{$cg_name}->{$tmp_cbc_file_name}},$include_pool{$cg_name}->{$tmp_cbc_file_name});
127 delete $include_pool{$cg_name};
128 next;
129 }
130 push(@{$counter{interfaces}->{$cg_name}->{$tmp_cbc_file_name}},$include_pool{$cg_name}->{$tmp_cbc_file_name});
131 delete $include_pool{$cg_name};
132 }
133
134 $counter{interfaces}->{Meta}++;
135 $counter{interfaces}->{TaskManager}++;
136 print "-----------\n";
137 print Dumper \%counter;
138 print "-----------\n";
139 return \%counter;
140 } 30 }
141 31
142 sub set_data_gear_header_path { 32 sub set_data_gear_header_path {
143 my $self = shift; 33 my $self = shift;
144 my @data_gears_name; 34 my @data_gears_name;