File Coverage

blib/lib/RPerl/Operation/Expression/Operator/Named/AbsoluteValue.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 32 32 100.0


line stmt bran cond sub pod time code
1             # [[[ DOCUMENTATION ]]]
2             # http://perldoc.perl.org/functions/abs.html
3             # SUPPORTED: abs VALUE
4             # NOT SUPPORTED: abs
5              
6             # [[[ HEADER ]]]
7             package RPerl::Operation::Expression::Operator::Named::AbsoluteValue;
8 5     5   35 use strict;
  5         13  
  5         150  
9 5     5   32 use warnings;
  5         14  
  5         126  
10 5     5   28 use RPerl::AfterSubclass;
  5         14  
  5         644  
11             our $VERSION = 0.003_100;
12              
13             # [[[ OO INHERITANCE ]]]
14 5     5   36 use parent qw(RPerl::Operation::Expression::Operator::Named);
  5         13  
  5         28  
15 5     5   335 use RPerl::Operation::Expression::Operator::Named;
  5         29  
  5         154  
16              
17             # [[[ CRITICS ]]]
18             ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
19             ## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils
20             ## no critic qw(ProhibitConstantPragma ProhibitMagicNumbers) # USER DEFAULT 3: allow constants
21              
22             # [[[ CONSTANTS ]]]
23 5     5   27 use constant NAME => my string $TYPED_NAME = 'abs';
  5         12  
  5         423  
24              
25             # DEV NOTE: with min & max args of 1, compile-time args length checking short-circuited first by Parse Phase 0 ERROR ECOPAPL03 'Useless use of FOO in void context'
26             # or ERROR ECOPARP00 'Unexpected Token: ,'; short-circuited second by ERROR ECOGEASRP13 on Operator_84 & OperatorVoid_122 multiple-argument productions below;
27             # can't figure out how to create test which gets past ECOPAPL03 & ECOPARP00 to trigger ECOGEASRP13
28 5     5   33 use constant ARGUMENTS_MIN => my integer $TYPED_ARGUMENTS_MIN = 1;
  5         15  
  5         235  
29 5     5   29 use constant ARGUMENTS_MAX => my integer $TYPED_ARGUMENTS_MAX = 1;
  5         11  
  5         2519  
30              
31             # [[[ OO PROPERTIES ]]]
32             our hashref $properties = {};
33              
34             # [[[ OO METHODS & SUBROUTINES ]]]
35              
36             our string_hashref::method $ast_to_rperl__generate = sub {
37             ( my object $self, my object $operator_named, my string_hashref $modes) = @_;
38             my string_hashref $rperl_source_group = { PMC => q{} };
39              
40             # RPerl::diag( 'in Operator::Named::AbsoluteValue->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
41             # RPerl::diag( 'in Operator::Named::AbsoluteValue->ast_to_rperl__generate(), received $operator_named = ' . "\n" . RPerl::Parser::rperl_ast__dump($operator_named) . "\n" );
42              
43             my string $operator_named_class = ref $operator_named;
44             if ( $operator_named_class eq 'Operation_79' ) { # Operation -> OP01_NAMED_SCOLON
45             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASRP15, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: named operator '
46             . $operator_named->{children}->[0]
47             . ' requires exactly one argument, dying' )
48             . "\n";
49             }
50             elsif ( $operator_named_class eq 'Operator_83' ) { # Operator -> OP01_NAMED SubExpression
51             $rperl_source_group->{PMC} .= $operator_named->{children}->[0] . q{ };
52             my string_hashref $rperl_source_subgroup = $operator_named->{children}->[1]->ast_to_rperl__generate( $modes, $self );
53             RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup );
54             }
55             elsif ( $operator_named_class eq 'Operator_84' ) { # Operator -> LPAREN OP01_NAMED ListElement OP21_LIST_COMMA ListElements ')'
56             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASRP13a, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: named operator '
57             . $operator_named->{children}->[1]
58             . ' does not accept multiple arguments, dying' )
59             . "\n";
60             }
61             elsif ( $operator_named_class eq 'OperatorVoid_122' ) { # OperatorVoid -> OP01_NAMED ListElement OP21_LIST_COMMA ListElements ';'
62             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASRP13b, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: named operator '
63             . $operator_named->{children}->[0]
64             . ' does not accept multiple arguments, dying' )
65             . "\n";
66             }
67             else {
68             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: grammar rule '
69             . ($operator_named_class)
70             . ' found where Operation_79, Operator_83, Operator_84, or OperatorVoid_122 expected, dying' )
71             . "\n";
72             }
73              
74             return $rperl_source_group;
75             };
76              
77             our string_hashref::method $ast_to_cpp__generate__CPPOPS_PERLTYPES = sub {
78             ( my object $self, my string_hashref $modes) = @_;
79             my string_hashref $cpp_source_group = { CPP => q{// <<< RP::O::E::O::N::Abs __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>} . "\n" };
80              
81             #...
82             return $cpp_source_group;
83             };
84              
85             our string_hashref::method $ast_to_cpp__generate__CPPOPS_CPPTYPES = sub {
86             ( my object $self, my object $operator_named, my string_hashref $modes) = @_;
87             my string_hashref $cpp_source_group = { CPP => q{} };
88              
89             # RPerl::diag( 'in Operator::Named::AbsoluteValue->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
90             # RPerl::diag( 'in Operator::Named::AbsoluteValue->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $operator_named = ' . "\n" . RPerl::Parser::rperl_ast__dump($operator_named) . "\n" );
91              
92             my string $operator_named_class = ref $operator_named;
93             if ( $operator_named_class eq 'Operation_79' ) { # Operation -> OP01_NAMED_SCOLON
94             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP15, CODE GENERATOR, ABSTRACT SYNTAX TO C++: named operator '
95             . $operator_named->{children}->[0]
96             . ' requires exactly one argument, dying' )
97             . "\n";
98             }
99             elsif ( $operator_named_class eq 'Operator_83' ) { # Operator -> OP01_NAMED SubExpression
100             # DEV NOTE: math.h is added by default (see RPerl/Inline.pm)
101             # DEV NOTE, CORRELATION #rp110: C++ std::abs is the most versatile choice of C++ operator, and is equivalent to Perl abs
102             $cpp_source_group->{CPP} .= $operator_named->{children}->[0];
103             $cpp_source_group->{CPP} .= '('; # DEV NOTE: must wrap operand in extra parens to avoid error "cannot resolve overloaded function ‘abs’ based on conversion to type ..."
104             my string_hashref $cpp_source_subgroup = $operator_named->{children}->[1]->ast_to_cpp__generate__CPPOPS_CPPTYPES( $modes, $self );
105             RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup );
106             $cpp_source_group->{CPP} .= ')';
107             }
108             elsif ( $operator_named_class eq 'Operator_84' ) { # Operator -> LPAREN OP01_NAMED ListElement OP21_LIST_COMMA ListElements ')'
109             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP14a, CODE GENERATOR, ABSTRACT SYNTAX TO C++: named operator '
110             . $operator_named->{children}->[1]
111             . ' does not accept multiple arguments, dying' )
112             . "\n";
113             }
114             elsif ( $operator_named_class eq 'OperatorVoid_122' ) { # OperatorVoid -> OP01_NAMED ListElement OP21_LIST_COMMA ListElements ';'
115             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP14b, CODE GENERATOR, ABSTRACT SYNTAX TO C++: named operator '
116             . $operator_named->{children}->[0]
117             . ' does not accept multiple arguments, dying' )
118             . "\n";
119             }
120             else {
121             die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: grammar rule '
122             . ($operator_named_class)
123             . ' found where Operation_79, Operator_83, Operator_84, or OperatorVoid_122 expected, dying' )
124             . "\n";
125             }
126              
127             return $cpp_source_group;
128             };
129              
130             1; # end of class