File Coverage

blib/lib/RPerl/Operation/Statement/Conditional.pm
Criterion Covered Total %
statement 56 107 52.3
branch 4 12 33.3
condition n/a
subroutine 5 7 71.4
pod n/a
total 65 126 51.5


line stmt bran cond sub pod time code
1             # [[[ HEADER ]]]
2             package RPerl::Operation::Statement::Conditional;
3 4     4   23 use strict;
  4         9  
  4         96  
4 4     4   19 use warnings;
  4         8  
  4         80  
5 4     4   17 use RPerl::AfterSubclass;
  4         7  
  4         466  
6             our $VERSION = 0.002_100;
7              
8             # [[[ OO INHERITANCE ]]]
9 4     4   25 use parent qw(RPerl::Operation::Statement);
  4         6  
  4         20  
10              
11             # [[[ CRITICS ]]]
12             ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
13             ## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils
14              
15             # [[[ OO PROPERTIES ]]]
16             our hashref $properties = {};
17              
18             # [[[ SUBROUTINES & OO METHODS ]]]
19              
20             sub ast_to_rperl__generate {
21 48     48   169 { my string_hashref::method $RETURN_TYPE };
  48         112  
22 48         171 ( my object $self, my string_hashref $modes) = @ARG;
23 48         180 my string_hashref $rperl_source_group = { PMC => q{} };
24              
25             # RPerl::diag( 'in Conditional->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
26              
27 48         147 my string $self_class = ref $self;
28              
29             # unwrap Conditional_177 from Statement_166
30 48 50       239 if ( $self_class eq 'Statement_166' ) { # Statement -> Conditional
31 48         226 $self = $self->{children}->[0];
32 48         158 $self_class = ref $self;
33             }
34              
35             # RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have possibly-unwrapped $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
36              
37             # Conditional -> 'if' LPAREN SubExpression ')' CodeBlock STAR-38 OPTIONAL-40
38 48 50       198 if ( $self_class eq 'Conditional_177' ) {
39 48         192 my string $if = $self->{children}->[0];
40 48         174 my string $left_paren = $self->{children}->[1];
41 48         128 my object $subexpression = $self->{children}->[2];
42 48         146 my string $right_paren = $self->{children}->[3];
43 48         138 my object $codeblock = $self->{children}->[4];
44 48         140 my object $elsif_star = $self->{children}->[5];
45 48         125 my object $else_optional = $self->{children}->[6];
46              
47             # RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have $if = ' . $if . "\n" );
48             # RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have $left_paren = ' . $left_paren . "\n" );
49             # RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have ( ref $subexpression ) = ' . ( ref $subexpression ) . "\n" );
50             # RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have $right_paren = ' . $right_paren . "\n" );
51             # RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have ( ref $codeblock ) = ' . ( ref $codeblock ) . "\n" );
52             # RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have ( ref $elsif_star ) = ' . ( ref $elsif_star ) . "\n" );
53             # RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have $elsif_star = ' . "\n" . RPerl::Parser::rperl_ast__dump($elsif_star) . "\n" );
54             # RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have ( ref $else_optional ) = ' . ( ref $else_optional ) . "\n" );
55              
56 48         202 $rperl_source_group->{PMC} .= $if . q{ } . $left_paren . q{ };
57 48         1102 my object $rperl_source_subgroup
58             = $subexpression->ast_to_rperl__generate($modes);
59 48         1235 RPerl::Generator::source_group_append( $rperl_source_group,
60             $rperl_source_subgroup );
61 48         205 $rperl_source_group->{PMC} .= q{ } . $right_paren . q{ };
62 48         1157 $rperl_source_subgroup = $codeblock->ast_to_rperl__generate($modes);
63 48         1190 RPerl::Generator::source_group_append( $rperl_source_group,
64             $rperl_source_subgroup );
65              
66             # ('elsif' LPAREN SubExpression ')' CodeBlock)*
67             # NEED FIX: destructive to AST!!!
68 48         263 while ( exists $elsif_star->{children}->[0] ) {
69              
70             # DEV NOTE: 'elsif' and ')' are automatically dropped by EYAPP, presumably because they are hard-coded strings inside EYAPP parenthesis, possibly EYAPP bug?
71             # my object $elsif = shift @{ $elsif_star->{children} };
72 12         62 my string $elsif = 'elsif';
73 12         28 my string $elsif_left_paren = shift @{ $elsif_star->{children} };
  12         42  
74             my object $elsif_subexpression
75 12         23 = shift @{ $elsif_star->{children} };
  12         31  
76              
77             # my object $elsif_right_paren = shift @{ $elsif_star->{children} };
78 12         24 my string $elsif_right_paren = ')';
79 12         24 my object $elsif_codeblock = shift @{ $elsif_star->{children} };
  12         30  
80              
81             # RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have $elsif = ' . "\n" . RPerl::Parser::rperl_ast__dump($elsif) . "\n" );
82             # RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have $elsif_left_paren = ' . "\n" . RPerl::Parser::rperl_ast__dump($elsif_left_paren) . "\n" );
83              
84             $rperl_source_group->{PMC}
85 12         53 .= $elsif . q{ } . $elsif_left_paren->{attr} . q{ };
86 12         305 $rperl_source_subgroup
87             = $elsif_subexpression->ast_to_rperl__generate($modes);
88 12         268 RPerl::Generator::source_group_append( $rperl_source_group,
89             $rperl_source_subgroup );
90 12         33 $rperl_source_group->{PMC} .= q{ } . $elsif_right_paren . q{ };
91 12         232 $rperl_source_subgroup
92             = $elsif_codeblock->ast_to_rperl__generate($modes);
93 12         243 RPerl::Generator::source_group_append( $rperl_source_group,
94             $rperl_source_subgroup );
95             }
96              
97             # ('else' CodeBlock)?
98 48 100       326 if ( exists $else_optional->{children}->[0] ) {
99              
100             # my string $else = $else_optional->{children}->[0];
101 5         16 my string $else = 'else';
102 5         14 my object $else_codeblock = $else_optional->{children}->[0];
103              
104 5         16 $rperl_source_group->{PMC} .= $else . q{ };
105 5         108 $rperl_source_subgroup
106             = $else_codeblock->ast_to_rperl__generate($modes);
107 5         119 RPerl::Generator::source_group_append( $rperl_source_group,
108             $rperl_source_subgroup );
109             }
110             }
111             else {
112 0         0 die RPerl::Parser::rperl_rule__replace(
113             'ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Grammar rule '
114             . $self_class
115             . ' found where Conditional_177 expected, dying' )
116             . "\n";
117             }
118 48         346 return $rperl_source_group;
119             }
120              
121             sub ast_to_cpp__generate__CPPOPS_PERLTYPES {
122 0     0     { my string_hashref::method $RETURN_TYPE };
  0            
123 0           ( my object $self, my string_hashref $modes) = @ARG;
124 0           my string_hashref $cpp_source_group
125             = {
126             CPP => q{// <<< RP::O::S::C __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>}
127             . "\n"
128             };
129              
130             #...
131 0           return $cpp_source_group;
132             }
133              
134             sub ast_to_cpp__generate__CPPOPS_CPPTYPES {
135 0     0     { my string_hashref::method $RETURN_TYPE };
  0            
136 0           ( my object $self, my string_hashref $modes) = @ARG;
137 0           my string_hashref $cpp_source_group = { CPP => q{} };
138              
139             # RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
140              
141 0           my string $self_class = ref $self;
142              
143             # unwrap Conditional_177 from Statement_166
144 0 0         if ( $self_class eq 'Statement_166' ) { # Statement -> Conditional
145 0           $self = $self->{children}->[0];
146 0           $self_class = ref $self;
147             }
148              
149             # RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have possibly-unwrapped $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
150              
151             # Conditional -> 'if' LPAREN SubExpression ')' CodeBlock STAR-38 OPTIONAL-40
152 0 0         if ( $self_class eq 'Conditional_177' ) {
153 0           my string $if = $self->{children}->[0];
154 0           my string $left_paren = $self->{children}->[1];
155 0           my object $subexpression = $self->{children}->[2];
156 0           my string $right_paren = $self->{children}->[3];
157 0           my object $codeblock = $self->{children}->[4];
158 0           my object $elsif_star = $self->{children}->[5];
159 0           my object $else_optional = $self->{children}->[6];
160              
161             # RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $if = ' . $if . "\n" );
162             # RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $left_paren = ' . $left_paren . "\n" );
163             # RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have ( ref $subexpression ) = ' . ( ref $subexpression ) . "\n" );
164             # RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $right_paren = ' . $right_paren . "\n" );
165             # RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have ( ref $codeblock ) = ' . ( ref $codeblock ) . "\n" );
166             # RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have ( ref $elsif_star ) = ' . ( ref $elsif_star ) . "\n" );
167             # RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $elsif_star = ' . "\n" . RPerl::Parser::rperl_ast__dump($elsif_star) . "\n" );
168             # RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have ( ref $else_optional ) = ' . ( ref $else_optional ) . "\n" );
169              
170 0           $cpp_source_group->{CPP} .= $if . q{ } . $left_paren . q{ };
171 0           my object $cpp_source_subgroup
172             = $subexpression->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
173 0           RPerl::Generator::source_group_append( $cpp_source_group,
174             $cpp_source_subgroup );
175 0           $cpp_source_group->{CPP} .= q{ } . $right_paren . q{ };
176 0           $cpp_source_subgroup = $codeblock->ast_to_cpp__generate__CPPOPS_CPPTYPES(undef, $modes); # undef $loop_label
177 0           RPerl::Generator::source_group_append( $cpp_source_group,
178             $cpp_source_subgroup );
179              
180             # ('elsif' LPAREN SubExpression ')' CodeBlock)*
181             # NEED FIX: destructive to AST!!!
182 0           while ( exists $elsif_star->{children}->[0] ) {
183              
184             # DEV NOTE: 'elsif' and ')' are automatically dropped by EYAPP, presumably because they are hard-coded strings inside EYAPP parenthesis, possibly EYAPP bug?
185             # my object $elsif = shift @{ $elsif_star->{children} };
186 0           my string $elsif = 'else if';
187 0           my string $elsif_left_paren = shift @{ $elsif_star->{children} };
  0            
188             my object $elsif_subexpression
189 0           = shift @{ $elsif_star->{children} };
  0            
190              
191             # my object $elsif_right_paren = shift @{ $elsif_star->{children} };
192 0           my string $elsif_right_paren = ')';
193 0           my object $elsif_codeblock = shift @{ $elsif_star->{children} };
  0            
194              
195             # RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $elsif = ' . "\n" . RPerl::Parser::rperl_ast__dump($elsif) . "\n" );
196             # RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $elsif_left_paren = ' . "\n" . RPerl::Parser::rperl_ast__dump($elsif_left_paren) . "\n" );
197              
198             $cpp_source_group->{CPP}
199 0           .= $elsif . q{ } . $elsif_left_paren->{attr} . q{ };
200 0           $cpp_source_subgroup
201             = $elsif_subexpression->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
202 0           RPerl::Generator::source_group_append( $cpp_source_group,
203             $cpp_source_subgroup );
204 0           $cpp_source_group->{CPP} .= q{ } . $elsif_right_paren . q{ };
205 0           $cpp_source_subgroup
206             = $elsif_codeblock->ast_to_cpp__generate__CPPOPS_CPPTYPES(undef, $modes); # undef $loop_label
207 0           RPerl::Generator::source_group_append( $cpp_source_group,
208             $cpp_source_subgroup );
209             }
210              
211             # ('else' CodeBlock)?
212 0 0         if ( exists $else_optional->{children}->[0] ) {
213              
214             # my string $else = $else_optional->{children}->[0];
215 0           my string $else = 'else';
216 0           my object $else_codeblock = $else_optional->{children}->[0];
217              
218 0           $cpp_source_group->{CPP} .= $else . q{ };
219 0           $cpp_source_subgroup
220             = $else_codeblock->ast_to_cpp__generate__CPPOPS_CPPTYPES(undef, $modes); # undef $loop_label
221 0           RPerl::Generator::source_group_append( $cpp_source_group,
222             $cpp_source_subgroup );
223             }
224             }
225             else {
226 0           die RPerl::Parser::rperl_rule__replace(
227             'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule '
228             . $self_class
229             . ' found where Conditional_177 expected, dying' )
230             . "\n";
231             }
232 0           return $cpp_source_group;
233             }
234              
235             1; # end of class