File Coverage

blib/lib/RPerl/Operation/Statement/OperatorVoid/Print.pm
Criterion Covered Total %
statement 66 88 75.0
branch 12 30 40.0
condition 5 14 35.7
subroutine 7 8 87.5
pod n/a
total 90 140 64.2


line stmt bran cond sub pod time code
1             # [[[ HEADER ]]]
2             package RPerl::Operation::Statement::OperatorVoid::Print;
3 4     4   23 use strict;
  4         9  
  4         107  
4 4     4   44 use warnings;
  4         9  
  4         92  
5 4     4   20 use RPerl::AfterSubclass;
  4         8  
  4         516  
6             our $VERSION = 0.004_000;
7              
8             # [[[ OO INHERITANCE ]]]
9 4     4   24 use parent qw(RPerl::Operation::Statement::OperatorVoid);
  4         10  
  4         20  
10 4     4   199 use RPerl::Operation::Statement::OperatorVoid;
  4         10  
  4         2692  
11              
12             # [[[ CRITICS ]]]
13             ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
14             ## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils
15              
16             # [[[ OO PROPERTIES ]]]
17             our hashref $properties = {};
18              
19             # [[[ SUBROUTINES & OO METHODS ]]]
20              
21             sub ast_to_rperl__generate {
22 938     938   1836 { my string_hashref::method $RETURN_TYPE };
  938         1729  
23 938         2528 ( my object $self, my string_hashref $modes) = @ARG;
24 938         3291 my string_hashref $rperl_source_group = { PMC => q{} };
25 938         1737 my string_hashref $rperl_source_subgroup;
26              
27             # RPerl::diag( 'in OperatorVoid::Print->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
28              
29 938         2298 my string $self_class = ref $self;
30 938 100       3199 if ( $self_class eq 'OperatorVoid_129' ) { # OperatorVoid -> OP01_PRINT OPTIONAL-31 ListElements ';'
    50          
31 931         2849 my string $print = $self->{children}->[0];
32 931         1837 my object $stdout_stderr_optional = $self->{children}->[1];
33 931         1820 my object $list_elements = $self->{children}->[2];
34 931         2380 my string $semicolon = $self->{children}->[3];
35              
36             # RPerl::diag( 'in OperatorVoid::Print->ast_to_rperl__generate(), have $stdout_stderr_optional = ' . "\n" . RPerl::Parser::rperl_ast__dump($stdout_stderr_optional) . "\n" );
37              
38 931         2994 $rperl_source_group->{PMC} .= $print . q{ };
39              
40 931 100       3896 if ( exists $stdout_stderr_optional->{children}->[0] ) {
41 20 50 66     112 if ( ( $stdout_stderr_optional->{children}->[0]->{attr} ne '{*STDOUT}' ) and ( $stdout_stderr_optional->{children}->[0]->{attr} ne '{*STDERR}' ) ) {
42             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASRP28, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: output stream '
43             . $stdout_stderr_optional->{children}->[0]->{attr}
44 0         0 . ' found where {*STDOUT} or {*STDERR} expected, dying' )
45             . "\n";
46             }
47              
48             # DEV NOTE: STDOUT & STDERR are generated below, they are only grammar tokens, not grammar rules, so they do not get their own classes, the following do not exist:
49             # RPerl::InputOutput::Stderr & RPerl::InputOutput::Stdout
50 20         72 $rperl_source_group->{PMC} .= $stdout_stderr_optional->{children}->[0]->{attr} . q{ };
51             }
52              
53 931         19713 $rperl_source_subgroup = $list_elements->ast_to_rperl__generate($modes);
54 931         19684 RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup );
55 931         3362 $rperl_source_group->{PMC} .= $semicolon . "\n";
56             }
57             elsif ( $self_class eq 'OperatorVoid_130' ) { # OperatorVoid -> OP01_PRINT FHREF_SYMBOL_BRACES ListElements ';'
58 7         30 my string $print = $self->{children}->[0];
59 7         16 my string $fhref_symbol_braces = $self->{children}->[1];
60 7         14 my object $list_elements = $self->{children}->[2];
61 7         11 my string $semicolon = $self->{children}->[3];
62              
63 7         18 $rperl_source_group->{PMC} .= $print . q{ } . $fhref_symbol_braces . q{ };
64 7         125 $rperl_source_subgroup = $list_elements->ast_to_rperl__generate($modes);
65 7         131 RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup );
66 7         20 $rperl_source_group->{PMC} .= $semicolon . "\n";
67             }
68             else {
69 0         0 die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Grammar rule '
70             . $self_class
71             . ' found where OperatorVoid_129 or OperatorVoid_130 expected, dying' )
72             . "\n";
73             }
74 938         5833 return $rperl_source_group;
75             }
76              
77             sub ast_to_cpp__generate__CPPOPS_PERLTYPES {
78 0     0   0 { my string_hashref::method $RETURN_TYPE };
  0         0  
79 0         0 ( my object $self, my string_hashref $modes) = @ARG;
80 0         0 my string_hashref $cpp_source_group = { CPP => q{// <<< RP::O::S::OV::P __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>} . "\n" };
81              
82             #...
83 0         0 return $cpp_source_group;
84             }
85              
86             sub ast_to_cpp__generate__CPPOPS_CPPTYPES {
87 64     64   126 { my string_hashref::method $RETURN_TYPE };
  64         120  
88 64         461 ( my object $self, my string_hashref $modes) = @ARG;
89 64         204 my string_hashref $cpp_source_group = { CPP => q{} };
90 64         124 my string_hashref $cpp_source_subgroup;
91              
92             # RPerl::diag( 'in OperatorVoid::Print->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
93              
94             # NEED FIX PARALLEL: temporarily disabled print operators while inside parallel loop to avoid pluto polycc error
95 64 50       217 if ($modes->{_inside_parallel_loop}) {
96 0         0 return $cpp_source_group;
97             }
98              
99 64         149 my string $self_class = ref $self;
100 64 50       171 if ( $self_class eq 'OperatorVoid_129' ) { # OperatorVoid -> OP01_PRINT OPTIONAL-31 ListElements ';'
    0          
101 64         153 my object $stdout_stderr_optional = $self->{children}->[1];
102 64         124 my object $list_elements = $self->{children}->[2];
103 64         156 my string $semicolon = $self->{children}->[3];
104              
105             # RPerl::diag( 'in OperatorVoid::Print->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $stdout_stderr_optional = ' . "\n" . RPerl::Parser::rperl_ast__dump($stdout_stderr_optional) . "\n" );
106             # RPerl::diag( 'in OperatorVoid::Print->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $list_elements = ' . "\n" . RPerl::Parser::rperl_ast__dump($list_elements) . "\n" );
107              
108 64 50       157 if ( exists $stdout_stderr_optional->{children}->[0] ) {
109 0 0       0 if ( $stdout_stderr_optional->{children}->[0]->{attr} eq '{*STDOUT}' ) {
    0          
110             # DEV NOTE, CORRELATION #rp100: C++ cout w/ double-less-than << input list separators is equivalent to Perl print w/ comma separators
111             # $cpp_source_group->{CPP} .= 'cout << ';
112 0         0 $cpp_source_group->{CPP} .= 'print ';
113             }
114             elsif ( $stdout_stderr_optional->{children}->[0]->{attr} eq '{*STDERR}' ) {
115             # DEV NOTE, CORRELATION #rp101: C++ cerr w/ double-less-than << input list separators is equivalent to Perl print {*STDERR} w/ comma separators
116             # $cpp_source_group->{CPP} .= 'cerr << ';
117 0         0 $cpp_source_group->{CPP} .= 'prerr ';
118             }
119             else {
120             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP28, CODE GENERATOR, ABSTRACT SYNTAX TO C++: output stream '
121             . $stdout_stderr_optional->{children}->[0]->{attr}
122 0         0 . ' found where {*STDOUT} or {*STDERR} expected, dying' )
123             . "\n";
124             }
125             }
126             else {
127             # $cpp_source_group->{CPP} .= 'cout << ';
128 64         163 $cpp_source_group->{CPP} .= 'print ';
129             }
130              
131             # DEV NOTE: always use endl instead of "\n" for cout, because Perl immediately flushes buffers on STDOUT newline characters
132             # http://perl.plover.com/FAQs/Buffering.html
133             # When a filehandle is attached to the terminal, as STDOUT is here, it is in line buffered mode by default.
134             # A filehandle in line buffered mode has two special properties: It's flushed automatically whenever you print a newline character to it,
135             # and it's flushed automatically whenever you read from the terminal.
136              
137             # save to stack of saved flags, when needed
138 64 50 33     220 if ((exists $modes->{_inside_print_operator}) and (defined $modes->{_inside_print_operator})) {
139 0 0 0     0 if ((not exists $modes->{_inside_print_operator_saved}) or (not defined $modes->{_inside_print_operator_saved})) {
140 0         0 $modes->{_inside_print_operator_saved} = [];
141             }
142 0         0 push @{$modes->{_inside_print_operator_saved}}, $modes->{_inside_print_operator};
  0         0  
143             }
144 64         170 $modes->{_inside_print_operator} = 1;
145              
146 64         1417 $cpp_source_subgroup = $list_elements->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
147 64         1343 RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup );
148             # replace closing "\n" with endl
149 64 100       226 if ((substr $cpp_source_group->{CPP}, -4, 4) eq q{"\n"}) {
150             # if (0) {
151 63         164 substr $cpp_source_group->{CPP}, -4, 4, q{};
152 63         123 $cpp_source_group->{CPP} .= 'endl';
153             }
154 64         147 $cpp_source_group->{CPP} .= $semicolon . "\n";
155              
156             # restore from stack of saved flags, when needed
157 64         138 delete $modes->{_inside_print_operator};
158 64 0 33     237 if ((exists $modes->{_inside_print_operator_saved}) and (defined $modes->{_inside_print_operator_saved}) and (scalar $modes->{_inside_print_operator_saved})) {
      50        
159 0         0 $modes->{_inside_print_operator} = pop @{$modes->{_inside_print_operator_saved}};
  0         0  
160 0 0       0 if (not scalar $modes->{_inside_print_operator_saved}) { delete $modes->{_inside_print_operator_saved}; }
  0         0  
161             }
162             }
163             elsif ( $self_class eq 'OperatorVoid_130' ) { # OperatorVoid -> OP01_PRINT FHREF_SYMBOL_BRACES ListElements ';'
164 0         0 $cpp_source_group->{CPP} .= '// <<< RP::O::S::OV::P __DUMMY_SOURCE_CODE CPPOPS_CPPTYPES >>>' . "\n";
165             }
166             else {
167 0         0 die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule '
168             . $self_class
169             . ' found where OperatorVoid_129 or OperatorVoid_130 expected, dying' )
170             . "\n";
171             }
172              
173             # RPerl::diag( 'in OperatorVoid::Print->ast_to_cpp__generate__CPPOPS_CPPTYPES(), about to return $cpp_source_group = ' . "\n" . RPerl::Parser::rperl_ast__dump($cpp_source_group) . "\n" );
174 64         368 return $cpp_source_group;
175             }
176              
177             1; # end of class