File Coverage

blib/lib/RPerl/Operation/Expression/Operator/NamedUnary/Scalar.pm
Criterion Covered Total %
statement 30 30 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod n/a
total 40 40 100.0


line stmt bran cond sub pod time code
1             # [[[ DOCUMENTATION ]]]
2             # http://perldoc.perl.org/functions/scalar.html
3             # SUPPORTED: scalar EXPR
4              
5             # [[[ HEADER ]]]
6             package RPerl::Operation::Expression::Operator::NamedUnary::Scalar;
7 5     5   31 use strict;
  5         17  
  5         131  
8 5     5   28 use warnings;
  5         11  
  5         112  
9 5     5   25 use RPerl::AfterSubclass;
  5         12  
  5         655  
10             our $VERSION = 0.003_100;
11              
12             # [[[ OO INHERITANCE ]]]
13 5     5   35 use parent qw(RPerl::Operation::Expression::Operator::NamedUnary);
  5         10  
  5         31  
14 5     5   305 use RPerl::Operation::Expression::Operator::NamedUnary;
  5         18  
  5         147  
15              
16             # [[[ CRITICS ]]]
17             ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
18             ## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils
19              
20             # [[[ CONSTANTS ]]]
21 5     5   31 use constant NAME => my string $TYPED_NAME = 'scalar';
  5         14  
  5         287  
22 5     5   34 use constant NAME_CPPOPS_PERLTYPES => my string $TYPED_NAME_CPPOPS_PERLTYPES = 'DUMMY_OP_SCALAR';
  5         13  
  5         297  
23 5     5   34 use constant NAME_CPPOPS_CPPTYPES => my string $TYPED_NAME_CPPOPS_CPPTYPES = 'size';
  5         12  
  5         329  
24 5     5   39 use constant ARGUMENTS_MIN => my integer $TYPED_ARGUMENTS_MIN = 1;
  5         14  
  5         281  
25 5     5   35 use constant ARGUMENTS_MAX => my integer $TYPED_ARGUMENTS_MAX = 1;
  5         12  
  5         3819  
26              
27             # [[[ OO PROPERTIES ]]]
28             our hashref $properties = {};
29              
30             # [[[ SUBROUTINES & OO METHODS ]]]
31              
32             our string_hashref::method $ast_to_rperl__generate = sub {
33             ( my object $self, my object $operator_named, my string_hashref $modes) = @_;
34             my string_hashref $rperl_source_group = { PMC => q{} };
35              
36             # RPerl::diag( 'in Operator::NamedUnary::Scalar->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
37             # RPerl::diag( 'in Operator::NamedUnary::Scalar->ast_to_rperl__generate(), received $operator_named = ' . "\n" . RPerl::Parser::rperl_ast__dump($operator_named) . "\n" );
38              
39             my string $operator_named_class = ref $operator_named;
40             if ( $operator_named_class eq 'Operation_80' ) { # Operation -> OP10_NAMED_UNARY_SCOLON
41             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASRP16, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Named operator '
42             . q{'} . $operator_named->{children}->[0] . q{'}
43             . ' requires exactly one argument, dying' )
44             . "\n";
45             }
46             elsif ( $operator_named_class eq 'Operator_99' ) { # Operator -> OP10_NAMED_UNARY SubExpression
47             $rperl_source_group->{PMC} .= $operator_named->{children}->[0] . q{ };
48             my string_hashref $rperl_source_subgroup = $operator_named->{children}->[1]->ast_to_rperl__generate( $modes, $self );
49             RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup );
50             }
51             elsif ( $operator_named_class eq 'Operator_100' ) { # Operator -> OP10_NAMED_UNARY
52             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASRP16, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Named operator '
53             . q{'} . $operator_named->{children}->[0] . q{'}
54             . ' requires exactly one argument, dying' )
55             . "\n";
56             }
57             else {
58             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Grammar rule '
59             . ($operator_named_class)
60             . ' found where Operation_80, Operator_99, or Operator_100 expected, dying' )
61             . "\n";
62             }
63              
64             return $rperl_source_group;
65             };
66              
67             our string_hashref::method $ast_to_cpp__generate__CPPOPS_PERLTYPES = sub {
68             ( my object $self, my string_hashref $modes) = @_;
69             my string_hashref $cpp_source_group = { CPP => q{// <<< RP::O::E::O::NU::Sca __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>} . "\n" };
70              
71             #...
72             return $cpp_source_group;
73             };
74              
75             our string_hashref::method $ast_to_cpp__generate__CPPOPS_CPPTYPES = sub {
76             ( my object $self, my object $operator_named, my string_hashref $modes) = @_;
77             my string_hashref $cpp_source_group = { CPP => q{} };
78              
79             # RPerl::diag( 'in NamedUnary::Scalar->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
80             # RPerl::diag( 'in NamedUnary::Scalar->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $operator_named = ' . "\n" . RPerl::Parser::rperl_ast__dump($operator_named) . "\n" );
81              
82             my string $operator_named_class = ref $operator_named;
83             if ( $operator_named_class eq 'Operation_80' ) { # Operation -> OP10_NAMED_UNARY_SCOLON
84             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP16, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Named operator '
85             . q{'} . $operator_named->{children}->[0] . q{'}
86             . ' requires exactly one argument, dying' )
87             . "\n";
88             }
89             elsif ( $operator_named_class eq 'Operator_99' ) { # Operator -> OP10_NAMED_UNARY SubExpression
90             # must have ArrayDereference as only argument
91             my object $subexpression = $operator_named->{children}->[1];
92             my string $subexpression_class = ref $subexpression;
93             if ( ( $subexpression_class ne 'SubExpression_140' )
94             and ( $subexpression_class ne 'ArrayDereference_200' )
95             and ( $subexpression_class ne 'ArrayDereference_201' ) )
96             {
97             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP70, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Named operator '
98             . q{'} . $operator_named->{children}->[0] . q{'}
99             . ' requires ArrayDereference argument, received '
100             . $subexpression_class
101             . ' instead, dying' )
102             . "\n";
103             }
104              
105             # unwrap ArrayDereference_200 and ArrayDereference_201 from SubExpression_140
106             if ( $subexpression_class eq 'SubExpression_140' ) { # SubExpression -> ArrayDereference
107             $subexpression = $subexpression->{children}->[0];
108             }
109              
110             $subexpression_class = ref $subexpression;
111             my string_hashref $cpp_source_subgroup;
112             if ( $subexpression_class eq 'ArrayDereference_200' ) { # ArrayDereference -> '@{' Variable '}'
113             $cpp_source_subgroup = $subexpression->{children}->[1]->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
114             RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup );
115             }
116             elsif ( $subexpression_class eq 'ArrayDereference_201' ) { # ArrayDereference -> '@{' OPTIONAL-47 ArrayReference '}'
117             my object $type_inner_optional = $subexpression->{children}->[1];
118             my object $array_reference = $subexpression->{children}->[2];
119              
120             if ( exists $type_inner_optional->{children}->[0] ) {
121             $cpp_source_group->{CPP} .= '((';
122             $cpp_source_subgroup = $type_inner_optional->{children}->[0]->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
123              
124             # RPerl::diag( 'in NamedUnary::Scalar->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $cpp_source_subgroup = ' . "\n" . RPerl::Parser::rperl_ast__dump($cpp_source_subgroup) . "\n" );
125             RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup );
126             $cpp_source_group->{CPP} .= ') ';
127             $cpp_source_subgroup = $array_reference->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
128             RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup );
129             $cpp_source_group->{CPP} .= ')';
130             }
131              
132             # DEV NOTE: I think we don't have to die here in CPPOPS_PERLTYPES mode???
133             # DEV NOTE, CORRELATION #rp031: NEED ANSWER: are array dereferences allowed in CPPOPS or not???
134             else {
135             die RPerl::Parser::rperl_rule__replace(
136             'ERROR ECOGEASCP13, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Array dereference of array reference must provide data type for array reference in CPPOPS_CPPTYPES mode, but no data type provided, dying'
137             ) . "\n";
138             }
139             }
140             else {
141             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule '
142             . $subexpression_class
143             . ' found where ArrayDereference_200 or ArrayDereference_201 expected, dying' )
144             . "\n";
145             }
146              
147             $cpp_source_group->{CPP} .= '.' . NAME_CPPOPS_CPPTYPES() . '()';
148             }
149             elsif ( $operator_named_class eq 'Operator_100' ) { # Operator -> OP10_NAMED_UNARY
150             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP16, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Named operator '
151             . $operator_named->{children}->[0]
152             . ' requires exactly one argument, dying' )
153             . "\n";
154             }
155             else {
156             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule '
157             . ($operator_named_class)
158             . ' found where Operation_80, Operator_99, or Operator_100 expected, dying' )
159             . "\n";
160             }
161              
162             return $cpp_source_group;
163             };
164              
165             1; # end of class