File Coverage

blib/lib/rperltypessizes.pm
Criterion Covered Total %
statement 42 79 53.1
branch 11 50 22.0
condition 6 24 25.0
subroutine 10 15 66.6
pod 0 10 0.0
total 69 178 38.7


line stmt bran cond sub pod time code
1             # [[[ HEADER ]]]
2             ## no critic qw(Capitalization ProhibitMultiplePackages ProhibitReusedNames) # SYSTEM DEFAULT 3: allow multiple & lower case package names
3             package # hide from PAUSE indexing
4             rperltypessizes;
5 7     7   48 use strict;
  7         16  
  7         215  
6 7     7   42 use warnings;
  7         17  
  7         217  
7 7     7   40 use RPerl::Config;
  7         16  
  7         1199  
8             our $VERSION = 0.004_000;
9              
10             # [[[ CRITICS ]]]
11             ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
12             ## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils
13             ## no critic qw(ProhibitExcessComplexity) # SYSTEM SPECIAL 5: allow complex code inside subroutines, must be after line 1
14             ## no critic qw(ProhibitPostfixControls) # SYSTEM SPECIAL 6: PERL CRITIC FILED ISSUE #639, not postfix foreach or if
15             ## no critic qw(ProhibitDeepNests) # SYSTEM SPECIAL 7: allow deeply-nested code
16             ## no critic qw(RequireBriefOpen) # SYSTEM SPECIAL 10: allow complex processing with open filehandle
17             ## no critic qw(ProhibitCascadingIfElse) # SYSTEM SPECIAL 12: allow complex conditional logic
18              
19             # [[[ NON-RPERL MODULES ]]]
20 7     7   52 use Config;
  7         15  
  7         324  
21 7     7   40 use Carp qw(croak);
  7         14  
  7         6185  
22              
23             # [[[ PRE-DECLARED TYPES ]]]
24             package # hide from PAUSE indexing
25             string;
26             package # hide from PAUSE indexing
27             string_hashref;
28              
29             # return to primary package namespace
30             package # hide from PAUSE indexing
31             rperltypessizes;
32              
33             # DEV NOTE, CORRELATION #rp001: keep track of all these hard-coded "semi-dynamic" integer data types
34             our string_hashref $ALTERNATE_TYPES_TO_PERLISH_TYPES = {
35             '__int8' => 'i8',
36             '__int16' => 'i16',
37             '__int32' => 'i32',
38             '__int64' => 'i64',
39             '__int128' => 'i128',
40             'int8_t' => 'i8',
41             'int16_t' => 'i16',
42             'int32_t' => 'i32',
43             'int64_t' => 'i64',
44             'int128_t' => 'i128',
45             # 'long long' => 'i64', # NEED ANSWER: is it more correct to map to 'longlong' instead of 'i64', as done below?
46             'long long' => 'longlong', # DEV NOTE: on Windows OS, real type "long long" is not shortened to "longlong" as in Linux
47             };
48              
49             # [[[ C++ TYPE SIZE REPORTING ]]]
50             sub type_integer_bitsize {
51 2     2 0 43749493 type_integer_errorcheck();
52             # return (string_to_integer($Config{ivsize}) * 8); # return answer in bits, not bytes
53 2         11 return ($Config{ivsize} * 8); # return answer in bits, not bytes
54             }
55              
56             sub type_integer_native {
57 0     0 0 0 type_integer_errorcheck();
58 0         0 return $Config{ivtype};
59             }
60              
61             sub type_integer_native_ccflag {
62 36     36 0 138 type_integer_errorcheck();
63 36         152 my string $ivtype = $Config{ivtype};
64              
65             # NEED ANSWER: is there some better way to support all the different types, rather than all this hard-coding?
66             # DEV NOTE, CORRELATION #rp001: keep track of all these hard-coded integer data types
67 36 50 0     126 if ($ivtype eq 'long') {
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
68 36         194 return ' -D__TYPE__INTEGER__LONG';
69             }
70             elsif (($ivtype eq 'longlong') or ($ivtype eq 'long long')) { # DEV NOTE: match both Linux'ish 'longlong' & Windows'ish 'long long'; 'long long' is the real type
71             # DEV NOTE, CORRELATION #rp041: GMP does not support 'long long' or 'long double', will cause t/07_type_gmp.t to fail
72             # return ' -D__TYPE__INTEGER__LONG_LONG';
73 0         0 return ' -D__TYPE__INTEGER__LONG';
74             }
75             elsif ($ivtype eq '__int8') {
76 0         0 return ' -D__TYPE__INTEGER____INT8';
77             }
78             elsif ($ivtype eq '__int16') {
79 0         0 return ' -D__TYPE__INTEGER____INT16';
80             }
81             elsif ($ivtype eq '__int32') {
82 0         0 return ' -D__TYPE__INTEGER____INT32';
83             }
84             elsif ($ivtype eq '__int64') {
85 0         0 return ' -D__TYPE__INTEGER____INT64';
86             }
87             elsif ($ivtype eq '__int128') {
88 0         0 return ' -D__TYPE__INTEGER____INT128';
89             }
90             elsif ($ivtype eq 'int8_t') {
91 0         0 return ' -D__TYPE__INTEGER__INT8_T';
92             }
93             elsif ($ivtype eq 'int16_t') {
94 0         0 return ' -D__TYPE__INTEGER__INT16_T';
95             }
96             elsif ($ivtype eq 'int32_t') {
97 0         0 return ' -D__TYPE__INTEGER__INT32_T';
98             }
99             elsif ($ivtype eq 'int64_t') {
100 0         0 return ' -D__TYPE__INTEGER__INT64_T';
101             }
102             elsif ($ivtype eq 'int128_t') {
103 0         0 return ' -D__TYPE__INTEGER__INT128_T';
104             }
105             }
106              
107             sub type_integer_errorcheck {
108             # NEED ANSWER: should we be checking $Config{use64bitint}, $Config{use64bitall}, $Config{i64size}, $Config{i64type}???
109 38 50 33 38 0 1298 if ((not exists $Config{ivsize}) or (not defined $Config{ivsize})) {
110 0         0 croak 'ERROR ERPTYREI00: Non-existent or undefined Perl config value $Config{ivsize}, croaking';
111             }
112 38         260 my string $ivsize = $Config{ivsize};
113              
114 38 50 33     849 if ((not exists $Config{ivtype}) or (not defined $Config{ivtype})) {
115 0         0 croak 'ERROR ERPTYREI01: Non-existent or undefined Perl config value $Config{ivtype}, croaking';
116             }
117 38         228 my string $ivtype = $Config{ivtype};
118              
119 38 50       148 if (exists $ALTERNATE_TYPES_TO_PERLISH_TYPES->{$ivtype}) {
120 0         0 $ivtype = $ALTERNATE_TYPES_TO_PERLISH_TYPES->{$ivtype};
121             }
122              
123 38         103 my string $ivtypesize_key = $ivtype . 'size';
124            
125 38 50 33     784 if ((not exists $Config{$ivtypesize_key}) or (not defined $Config{$ivtypesize_key})) {
126 0         0 croak 'ERROR ERPTYREI02: Non-existent or undefined Perl config value $Config{' . $ivtypesize_key . '}, croaking';
127             }
128 38         195 my string $ivtypesize = $Config{$ivtypesize_key};
129              
130 38 50       150 if ($ivsize ne $ivtypesize) {
131 0         0 croak 'ERROR ERPTYREI03: Mis-matching Perl config values, $Config{ivsize} = ' . $ivsize . ', $Config{' . $ivtypesize_key . '} = ' . $ivtypesize . ', croaking';
132             }
133             }
134              
135             sub type_integer_bitsize_dump {
136 0     0 0 0 foreach my $o (qw(ivsize ivtype use64bitint use64bitall intsize longsize longlongsize d_longlong i8size i8type i16size i16type i32size i32type i64size i64type)) {
137 0         0 print q($Config{) . $o . q(} = ) . $Config{$o} . "\n";
138             }
139             }
140              
141             sub type_number_bitsize {
142 0     0 0 0 type_number_errorcheck();
143             # return (string_to_integer($Config{nvsize}) * 8); # return answer in bits, not bytes
144 0         0 return ($Config{nvsize} * 8); # return answer in bits, not bytes
145             }
146              
147             sub type_number_native {
148 0     0 0 0 type_number_errorcheck();
149 0         0 return $Config{nvtype};
150             }
151              
152             sub type_number_native_ccflag {
153 36     36 0 118 type_number_errorcheck();
154 36 50       178 if ($Config{nvtype} eq 'double') {
    0          
155 36         209 return ' -D__TYPE__NUMBER__DOUBLE';
156             }
157             elsif ($Config{nvtype} eq 'longdbl') {
158             # DEV NOTE, CORRELATION #rp041: GMP does not support 'long long' or 'long double', will cause t/07_type_gmp.t to fail
159             # return ' -D__TYPE__NUMBER__LONG__DOUBLE';
160 0         0 return ' -D__TYPE__NUMBER__DOUBLE';
161             }
162             }
163              
164             sub type_number_errorcheck {
165             # NEED ANSWER: should we be checking $Config{use64bitall}???
166 36 50 33 36 0 784 if ((not exists $Config{nvsize}) or (not defined $Config{nvsize})) {
167 0         0 croak 'ERROR ERPTYREN00: Non-existent or undefined Perl config value $Config{nvsize}, croaking';
168             }
169 36         211 my string $nvsize = $Config{nvsize};
170              
171 36 50 33     823 if ((not exists $Config{nvtype}) or (not defined $Config{nvtype})) {
172 0         0 croak 'ERROR ERPTYREN01: Non-existent or undefined Perl config value $Config{nvtype}, croaking';
173             }
174              
175 36         178 my string $nvtype = $Config{nvtype};
176              
177             # DEV NOTE: I decided to programmatically approach the 'long double' issue in case 'longdouble' and 'longdbl' are both valid,
178             # instead of hard-coding one or the other in $ALTERNATE_TYPES_TO_PERLISH_TYPES;
179             # if nvtype contains whitespace, remove it: 'long double' becomes 'longdouble'
180 36         140 $nvtype =~ s/\s//gxms;
181              
182 36         104 my string $nvtypesize_key = $nvtype . 'size';
183              
184 36 50 33     623 if ((not exists $Config{$nvtypesize_key}) or (not defined $Config{$nvtypesize_key})) {
185             # try with 'dbl' instead of 'double'
186 0 0       0 if ($nvtype =~ m/double/gxms) {
187 0         0 $nvtype =~ s/double/dbl/gxms;
188 0         0 my string $nvtypesize_key_long = $nvtypesize_key;
189 0         0 $nvtypesize_key = $nvtype . 'size';
190 0 0 0     0 if ((not exists $Config{$nvtypesize_key}) or (not defined $Config{$nvtypesize_key})) {
191 0         0 croak 'ERROR ERPTYREN02: Non-existent or undefined Perl config values $Config{' . $nvtypesize_key_long . '} and $Config{' . $nvtypesize_key . '}, croaking';
192             }
193             }
194             else {
195 0         0 croak 'ERROR ERPTYREN03: Non-existent or undefined Perl config value $Config{' . $nvtypesize_key . '}, croaking';
196             }
197             }
198 36         184 my string $nvtypesize = $Config{$nvtypesize_key};
199              
200 36 50       158 if ($nvsize ne $nvtypesize) {
201 0           croak 'ERROR ERPTYREN04: Mis-matching Perl config values, $Config{nvsize} = ' . $nvsize . ', $Config{' . $nvtypesize_key . '} = ' . $nvtypesize . ', croaking';
202             }
203             }
204              
205             sub type_number_bitsize_dump {
206 0     0 0   foreach my $o (qw(nvsize nvtype use64bitall doublesize longdblsize d_longdbl)) {
207 0           print q($Config{) . $o . q(} = ) . $Config{$o} . "\n";
208             }
209             }
210              
211             1; # end of package