File Coverage

blib/lib/RPerl/CodeBlock/Subroutine/Method.pm
Criterion Covered Total %
statement 263 278 94.6
branch 18 28 64.2
condition 13 21 61.9
subroutine 61 62 98.3
pod n/a
total 355 389 91.2


line stmt bran cond sub pod time code
1             # [[[ HEADER ]]]
2             package RPerl::CodeBlock::Subroutine::Method;
3 7     7   39 use strict;
  7         15  
  7         160  
4 7     7   31 use warnings;
  7         13  
  7         132  
5 7     7   29 use RPerl::AfterSubclass;
  7         11  
  7         793  
6             our $VERSION = 0.008_000;
7              
8             # [[[ OO INHERITANCE ]]]
9 7     7   38 use parent qw(RPerl::CodeBlock::Subroutine);
  7         14  
  7         31  
10 7     7   388 use RPerl::CodeBlock::Subroutine;
  7         16  
  7         195  
11              
12             # [[[ CRITICS ]]]
13             ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
14             ## no critic qw(Capitalization ProhibitMultiplePackages ProhibitReusedNames) # SYSTEM DEFAULT 3: allow multiple & lower case package names
15              
16             # [[[ INCLUDES ]]]
17 7     7   3203 use Storable qw(dclone);
  7         16697  
  7         444  
18 7     7   54 use perlapinames_generated;
  7         13  
  7         7625  
19              
20             # [[[ OO PROPERTIES ]]]
21             our hashref $properties = {};
22              
23             # [[[ SUBROUTINES & OO METHODS ]]]
24              
25             sub ast_to_rperl__generate {
26 54     54   141 { my string_hashref::method $RETURN_TYPE };
  54         137  
27 54         157 ( my object $self, my string_hashref $modes) = @ARG;
28 54         242 my string_hashref $rperl_source_group = { PMC => q{} };
29 54         163 my string_hashref $rperl_source_subgroup;
30              
31             # RPerl::diag( 'in Method->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
32              
33             # unwrap Method_82 from SubroutineOrMethod_88
34 54 50       258 if ( ( ref $self ) eq 'SubroutineOrMethod_88' ) {
35 54         191 $self = $self->{children}->[0];
36             }
37              
38             # RPerl::diag( 'in Method->ast_to_rperl__generate(), have possibly-unwrapped $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
39              
40 54 50       248 if ( ( ref $self ) ne 'Method_82' ) {
41 0         0 die RPerl::Parser::rperl_rule__replace(
42             'ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Grammar rule ' . ( ref $self ) . ' found where Method_82 expected, dying' )
43             . "\n";
44             }
45              
46 54         229 my string $sub = $self->{children}->[0];
47 54         181 my string $name = $self->{children}->[1];
48 54         227 my string $left_brace = $self->{children}->[2];
49 54         213 my string $return_type_left_brace = $self->{children}->[3];
50 54         186 my string $return_type_my = $self->{children}->[4];
51 54         138 my string $return_type = $self->{children}->[5];
52 54         144 my string $return_type_var = $self->{children}->[6];
53 54         164 my string $return_type_right_brace = $self->{children}->[7];
54 54         225 my string $return_type_semicolon = $self->{children}->[8];
55 54         171 my object $arguments_optional = $self->{children}->[9];
56 54         116 my object $operations_star = $self->{children}->[10];
57 54         198 my string $right_brace = $self->{children}->[11];
58              
59 54 50       283 if ((substr $name, 0, 1) eq '_') {
60 0         0 die 'ERROR ECOGEASRP09, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: method name ' . ($name)
61             . ' must not start with underscore, dying' . "\n";
62             }
63              
64 54 100 100     920 if ((exists $perlapinames_generated::FUNCTIONS_DOCUMENTED->{$name}) or
      100        
      100        
65             (exists $perlapinames_generated::FUNCTIONS_UNDOCUMENTED->{$name}) or
66             (exists $perlapinames_generated::VARIABLES_DOCUMENTED->{$name}) or
67             (exists $perlapinames_generated::VARIABLES_UNDOCUMENTED->{$name})) {
68 4         85 die 'ERROR ECOGEASRP45, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Perl API name conflict, method name ' . q{'}
69             . $name . q{'}
70             . ' is the same as a protected function or variable name in the Perl API, please choose a different name, dying' . "\n";
71             }
72              
73             # CREATE SYMBOL TABLE ENTRY
74 50         181 $modes->{_symbol_table}->{_subroutine} = $name; # set current subroutine/method
75 50         395 $modes->{_symbol_table}->{$modes->{_symbol_table}->{_namespace}}->{_global}->{$name} = {isa => 'RPerl::CodeBlock::Subroutine::Method', type => $return_type}; # create individual symtab entry
76            
77             $rperl_source_group->{PMC} .=
78 50         371 $sub . q{ } . $name . q{ } . $left_brace . q{ } .
79             $return_type_left_brace . q{ } . $return_type_my . q{ } . $return_type . q{ } . $return_type_var . q{ } .
80             $return_type_right_brace . q{ } . $return_type_semicolon;
81              
82 50 100       227 if ( exists $arguments_optional->{children}->[0] ) {
83 39         1171 $rperl_source_subgroup = $arguments_optional->{children}->[0]->ast_to_rperl__generate($modes);
84 39         905 RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup );
85             }
86              
87 50         128 foreach my object $operation ( @{ $operations_star->{children} } ) {
  50         240  
88 112         2536 $rperl_source_subgroup = $operation->ast_to_rperl__generate($modes);
89 111         2302 RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup );
90             }
91              
92 49         199 $rperl_source_group->{PMC} .= $right_brace . "\n\n";
93 49         3463 return $rperl_source_group;
94             }
95              
96             sub ast_to_cpp__generate__CPPOPS_PERLTYPES {
97 0     0   0 { my string_hashref::method $RETURN_TYPE };
  0         0  
98 0         0 ( my object $self, my string_hashref $modes) = @ARG;
99 0         0 my string_hashref $cpp_source_group = { CPP => q{// <<< RP::CB::S::M __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>} . "\n" };
100              
101             #...
102 0         0 return $cpp_source_group;
103             }
104              
105             sub ast_to_cpp__generate_declaration__CPPOPS_CPPTYPES {
106 29     29   73 { my string_hashref::method $RETURN_TYPE };
  29         49  
107 29         103 ( my object $self, my string_hashref $modes) = @ARG;
108             # RPerl::diag( 'in Method->ast_to_cpp__generate_declaration__CPPOPS_CPPTYPES(), received $modes->{_symbol_table} = ' . "\n" . Dumper($modes->{_symbol_table}) . "\n");
109              
110 29         118 my string_hashref $cpp_source_group = { H => q{} };
111              
112             # RPerl::diag( 'in Method->ast_to_cpp__generate_declaration__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
113              
114             # unwrap Method_82 from SubroutineOrMethod_88
115 29 50       113 if ( ( ref $self ) eq 'SubroutineOrMethod_88' ) {
116 29         120 $self = $self->{children}->[0];
117             }
118              
119             # RPerl::diag( 'in Method->ast_to_cpp__generate_declaration__CPPOPS_CPPTYPES(), have possibly-unwrapped $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
120              
121 29 50       113 if ( ( ref $self ) ne 'Method_82' ) {
122 0         0 die RPerl::Parser::rperl_rule__replace(
123             'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule ' . ( ref $self ) . ' found where Method_82 expected, dying' )
124             . "\n";
125             }
126              
127 29         98 my string $name = $self->{children}->[1];
128 29         74 my string $return_type = $self->{children}->[5];
129 29         71 my object $arguments_optional = $self->{children}->[9];
130              
131 29         91 substr $return_type, -8, 8, ''; # strip trailing '::method'
132            
133             # RPerl::diag( 'in Method->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $name = ' . $name . "\n" );
134             # RPerl::diag( 'in Method->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $arguments_optional = ' . "\n" . RPerl::Parser::rperl_ast__dump($arguments_optional) . "\n" );
135              
136 29 50       107 if ((substr $name, 0, 1) eq '_') {
137 0         0 die 'ERROR ECOGEASCP09, CODE GENERATOR, ABSTRACT SYNTAX TO C++: method name ' . ($name)
138             . ' must not start with underscore, dying' . "\n";
139             }
140              
141 29 50 33     416 if ((exists $perlapinames_generated::FUNCTIONS_DOCUMENTED->{$name}) or
      33        
      33        
142             (exists $perlapinames_generated::FUNCTIONS_UNDOCUMENTED->{$name}) or
143             (exists $perlapinames_generated::VARIABLES_DOCUMENTED->{$name}) or
144             (exists $perlapinames_generated::VARIABLES_UNDOCUMENTED->{$name})) {
145 0         0 die 'ERROR ECOGEASCP45, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Perl API name conflict, method name ' . q{'}
146             . $name . q{'}
147             . ' is the same as a protected function or variable name in the Perl API, please choose a different name, dying' . "\n";
148             }
149              
150             # CREATE SYMBOL TABLE ENTRY
151 29         103 $modes->{_symbol_table}->{_subroutine} = $name; # set current subroutine/method
152 29         221 $modes->{_symbol_table}->{$modes->{_symbol_table}->{_namespace}}->{_global}->{$name} = {isa => 'RPerl::CodeBlock::Subroutine::Method', type => $return_type}; # create individual symtab entry
153              
154 29         745 $return_type = RPerl::Generator::type_convert_perl_to_cpp($return_type, 1); # $pointerify_classes = 1
155 29         113 $modes->{_symbol_table}->{$modes->{_symbol_table}->{_namespace}}->{_global}->{$name}->{type_cpp} = $return_type; # add converted C++ type to symtab entry
156              
157 29         110 $cpp_source_group->{H} .= q{ } . $return_type . q{ } . $name . '(';
158 29 100       106 if ( exists $arguments_optional->{children}->[0] ) {
159 28         74 my object $arguments = $arguments_optional->{children}->[0];
160 28         726 my string_hashref $cpp_source_subgroup = $arguments->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
161 28         91 $cpp_source_group->{H} .= $cpp_source_subgroup->{CPP};
162             }
163 29         72 $cpp_source_group->{H} .= ');';
164 29         449 return $cpp_source_group;
165             }
166              
167             sub ast_to_cpp__generate__CPPOPS_CPPTYPES {
168 29     29   66 { my string_hashref::method $RETURN_TYPE };
  29         52  
169 29         82 ( my object $self, my string $package_name_underscores, my string_hashref $modes) = @ARG;
170             # RPerl::diag( 'in Method->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $modes->{_symbol_table} = ' . "\n" . Dumper($modes->{_symbol_table}) . "\n");
171              
172 29         95 my string_hashref $cpp_source_group = { CPP => q{} };
173 29         70 my string_hashref $cpp_source_subgroup;
174              
175             # RPerl::diag( 'in Method->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
176              
177             # unwrap Method_82 from SubroutineOrMethod_88
178 29 50       121 if ( ( ref $self ) eq 'SubroutineOrMethod_88' ) {
179 29         84 $self = $self->{children}->[0];
180             }
181              
182             # RPerl::diag( 'in Method->ast_to_cpp__generate_declaration__CPPOPS_CPPTYPES(), have possibly-unwrapped $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
183              
184 29 50       103 if ( ( ref $self ) ne 'Method_82' ) {
185 0         0 die RPerl::Parser::rperl_rule__replace(
186             'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule ' . ( ref $self ) . ' found where Method_82 expected, dying' )
187             . "\n";
188             }
189              
190 29         91 my string $name = $self->{children}->[1];
191 29         72 my string $return_type = $self->{children}->[5];
192 29         69 my object $arguments_optional = $self->{children}->[9];
193 29         75 my object $operations_star = $self->{children}->[10];
194              
195 29         77 substr $return_type, -8, 8, ''; # strip trailing '::method'
196              
197 29         626 $return_type = RPerl::Generator::type_convert_perl_to_cpp($return_type, 1); # $pointerify_classes = 1
198 29         140 $cpp_source_group->{CPP} .= $return_type . q{ } . $package_name_underscores . '::' . $name . '(';
199              
200 29 100       81 if ( exists $arguments_optional->{children}->[0] ) {
201 28         618 $cpp_source_subgroup = $arguments_optional->{children}->[0]->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
202 28         705 RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup );
203             }
204              
205 29         61 $cpp_source_group->{CPP} .= ') {' . "\n";
206 29         107 my string $CPP_saved = $cpp_source_group->{CPP};
207 29         65 $cpp_source_group->{CPP} = q{};
208              
209 29         62 foreach my object $operation ( @{ $operations_star->{children} } ) {
  29         162  
210 77         1827 $cpp_source_subgroup = $operation->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
211 77         1741 RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup );
212             }
213              
214             # COMPILE-TIME OPTIMIZATION #02: declare all loop iterators at top of subroutine/method to avoid re-declarations in nested loops
215 29 50 33     105 if ((exists $modes->{_loop_iterators}) and (defined $modes->{_loop_iterators})) {
216 0         0 foreach my string $loop_iterator_symbol (sort keys %{$modes->{_loop_iterators}}) {
  0         0  
217 0         0 $CPP_saved .= $modes->{_loop_iterators}->{$loop_iterator_symbol} . q{ } . $loop_iterator_symbol . ';' . "\n";
218             }
219 0         0 delete $modes->{_loop_iterators};
220             }
221            
222 29         66 $CPP_saved .= $cpp_source_group->{CPP};
223 29         79 $cpp_source_group->{CPP} = $CPP_saved;
224              
225 29         83 $cpp_source_group->{CPP} .= '}';
226 29         654 return $cpp_source_group;
227             }
228              
229             # [[[ TYPES & SUBTYPES BELOW THIS LINE ]]]
230              
231             # a method is a subroutine belonging to a class or object
232             package # hide from PAUSE indexing
233             method;
234 7     7   59 use strict;
  7         16  
  7         223  
235 7     7   35 use warnings;
  7         14  
  7         309  
236 7     7   36 use parent qw(RPerl::CodeBlock::Subroutine::Method);
  7         14  
  7         43  
237              
238             # [[[ SCALAR & SCALAR REF METHODS ]]]
239              
240             # method with void return type
241             package # hide from PAUSE indexing
242             void::method;
243 7     7   729 use strict;
  7         17  
  7         113  
244 7     7   38 use warnings;
  7         16  
  7         267  
245 7     7   37 use parent -norequire, qw(method);
  7         13  
  7         29  
246              
247             # method with integer return type
248             package # hide from PAUSE indexing
249             integer::method;
250 7     7   331 use strict;
  7         15  
  7         111  
251 7     7   34 use warnings;
  7         13  
  7         221  
252 7     7   38 use parent -norequire, qw(method);
  7         13  
  7         33  
253              
254             # method with number return type
255             package # hide from PAUSE indexing
256             number::method;
257 7     7   342 use strict;
  7         18  
  7         126  
258 7     7   33 use warnings;
  7         13  
  7         184  
259 7     7   31 use parent -norequire, qw(method);
  7         13  
  7         30  
260              
261             # method with character return type
262             package # hide from PAUSE indexing
263             character::method;
264 7     7   282 use strict;
  7         15  
  7         121  
265 7     7   28 use warnings;
  7         14  
  7         157  
266 7     7   32 use parent -norequire, qw(method);
  7         19  
  7         28  
267              
268             # method with string return type
269             package # hide from PAUSE indexing
270             string::method;
271 7     7   306 use strict;
  7         13  
  7         445  
272 7     7   32 use warnings;
  7         14  
  7         255  
273 7     7   30 use parent -norequire, qw(method);
  7         13  
  7         27  
274              
275             # method with scalartype return type
276             package # hide from PAUSE indexing
277             scalartype::method;
278 7     7   338 use strict;
  7         13  
  7         113  
279 7     7   31 use warnings;
  7         17  
  7         203  
280 7     7   40 use parent -norequire, qw(method);
  7         14  
  7         29  
281              
282             # method with unknown return type
283             package # hide from PAUSE indexing
284             unknown::method;
285 7     7   315 use strict;
  7         15  
  7         140  
286 7     7   33 use warnings;
  7         14  
  7         192  
287 7     7   36 use parent -norequire, qw(method);
  7         15  
  7         36  
288              
289             # [[[ HASH METHODS ]]]
290              
291             package # hide from PAUSE indexing
292             integer_hashref::method;
293 7     7   329 use strict;
  7         17  
  7         176  
294 7     7   39 use warnings;
  7         14  
  7         190  
295 7     7   32 use parent -norequire, qw(method);
  7         13  
  7         24  
296              
297             package # hide from PAUSE indexing
298             number_hashref::method;
299 7     7   320 use strict;
  7         14  
  7         119  
300 7     7   29 use warnings;
  7         12  
  7         173  
301 7     7   36 use parent -norequire, qw(method);
  7         15  
  7         33  
302              
303             package # hide from PAUSE indexing
304             string_hashref::method;
305 7     7   254 use strict;
  7         18  
  7         135  
306 7     7   36 use warnings;
  7         13  
  7         197  
307 7     7   36 use parent -norequire, qw(method);
  7         17  
  7         29  
308              
309             package # hide from PAUSE indexing
310             object_hashref::method;
311 7     7   357 use strict;
  7         12  
  7         125  
312 7     7   31 use warnings;
  7         20  
  7         189  
313 7     7   33 use parent -norequire, qw(method);
  7         13  
  7         26  
314              
315             package # hide from PAUSE indexing
316             hashref_hashref::method;
317 7     7   309 use strict;
  7         13  
  7         108  
318 7     7   30 use warnings;
  7         14  
  7         163  
319 7     7   32 use parent -norequire, qw(method);
  7         13  
  7         25  
320              
321             # [[[ ARRAY METHODS ]]]
322              
323             package # hide from PAUSE indexing
324             integer_arrayref::method;
325 7     7   333 use strict;
  7         14  
  7         127  
326 7     7   33 use warnings;
  7         17  
  7         199  
327 7     7   32 use parent -norequire, qw(method);
  7         11  
  7         26  
328              
329             package # hide from PAUSE indexing
330             number_arrayref::method;
331 7     7   327 use strict;
  7         17  
  7         99  
332 7     7   24 use warnings;
  7         15  
  7         172  
333 7     7   31 use parent -norequire, qw(method);
  7         12  
  7         25  
334              
335             package # hide from PAUSE indexing
336             string_arrayref::method;
337 7     7   285 use strict;
  7         19  
  7         126  
338 7     7   35 use warnings;
  7         15  
  7         194  
339 7     7   35 use parent -norequire, qw(method);
  7         15  
  7         27  
340              
341             package # hide from PAUSE indexing
342             arrayref_arrayref::method;
343 7     7   300 use strict;
  7         18  
  7         131  
344 7     7   31 use warnings;
  7         13  
  7         197  
345 7     7   34 use parent -norequire, qw(method);
  7         12  
  7         25  
346              
347             1;