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 9     9   54 use strict;
  9         19  
  9         216  
6 9     9   43 use warnings;
  9         17  
  9         183  
7 9     9   40 use RPerl::Config;
  9         22  
  9         1139  
8             our $VERSION = 0.003_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 9     9   65 use Config;
  9         22  
  9         346  
21 9     9   47 use Carp qw(croak);
  9         18  
  9         7432  
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 18926035 type_integer_errorcheck();
52             # return (string_to_integer($Config{ivsize}) * 8); # return answer in bits, not bytes
53 2         14 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 52     52 0 203 type_integer_errorcheck();
63 52         214 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 52 50 0     186 if ($ivtype eq 'long') {
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
68 52         306 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 0         0 return ' -D__TYPE__INTEGER__LONG_LONG';
72             }
73             elsif ($ivtype eq '__int8') {
74 0         0 return ' -D__TYPE__INTEGER____INT8';
75             }
76             elsif ($ivtype eq '__int16') {
77 0         0 return ' -D__TYPE__INTEGER____INT16';
78             }
79             elsif ($ivtype eq '__int32') {
80 0         0 return ' -D__TYPE__INTEGER____INT32';
81             }
82             elsif ($ivtype eq '__int64') {
83 0         0 return ' -D__TYPE__INTEGER____INT64';
84             }
85             elsif ($ivtype eq '__int128') {
86 0         0 return ' -D__TYPE__INTEGER____INT128';
87             }
88             elsif ($ivtype eq 'int8_t') {
89 0         0 return ' -D__TYPE__INTEGER__INT8_T';
90             }
91             elsif ($ivtype eq 'int16_t') {
92 0         0 return ' -D__TYPE__INTEGER__INT16_T';
93             }
94             elsif ($ivtype eq 'int32_t') {
95 0         0 return ' -D__TYPE__INTEGER__INT32_T';
96             }
97             elsif ($ivtype eq 'int64_t') {
98 0         0 return ' -D__TYPE__INTEGER__INT64_T';
99             }
100             elsif ($ivtype eq 'int128_t') {
101 0         0 return ' -D__TYPE__INTEGER__INT128_T';
102             }
103             }
104              
105             sub type_integer_errorcheck {
106             # NEED ANSWER: should we be checking $Config{use64bitint}, $Config{use64bitall}, $Config{i64size}, $Config{i64type}???
107 54 50 33 54 0 1842 if ((not exists $Config{ivsize}) or (not defined $Config{ivsize})) {
108 0         0 croak 'ERROR ERPTYREI00: Non-existent or undefined Perl config value $Config{ivsize}, croaking';
109             }
110 54         324 my string $ivsize = $Config{ivsize};
111              
112 54 50 33     1214 if ((not exists $Config{ivtype}) or (not defined $Config{ivtype})) {
113 0         0 croak 'ERROR ERPTYREI01: Non-existent or undefined Perl config value $Config{ivtype}, croaking';
114             }
115 54         273 my string $ivtype = $Config{ivtype};
116              
117 54 50       242 if (exists $ALTERNATE_TYPES_TO_PERLISH_TYPES->{$ivtype}) {
118 0         0 $ivtype = $ALTERNATE_TYPES_TO_PERLISH_TYPES->{$ivtype};
119             }
120              
121 54         161 my string $ivtypesize_key = $ivtype . 'size';
122            
123 54 50 33     1190 if ((not exists $Config{$ivtypesize_key}) or (not defined $Config{$ivtypesize_key})) {
124 0         0 croak 'ERROR ERPTYREI02: Non-existent or undefined Perl config value $Config{' . $ivtypesize_key . '}, croaking';
125             }
126 54         283 my string $ivtypesize = $Config{$ivtypesize_key};
127              
128 54 50       227 if ($ivsize ne $ivtypesize) {
129 0         0 croak 'ERROR ERPTYREI03: Mis-matching Perl config values, $Config{ivsize} = ' . $ivsize . ', $Config{' . $ivtypesize_key . '} = ' . $ivtypesize . ', croaking';
130             }
131             }
132              
133             sub type_integer_bitsize_dump {
134 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)) {
135 0         0 print q($Config{) . $o . q(} = ) . $Config{$o} . "\n";
136             }
137             }
138              
139             sub type_number_bitsize {
140 0     0 0 0 type_number_errorcheck();
141             # return (string_to_integer($Config{nvsize}) * 8); # return answer in bits, not bytes
142 0         0 return ($Config{nvsize} * 8); # return answer in bits, not bytes
143             }
144              
145             sub type_number_native {
146 0     0 0 0 type_number_errorcheck();
147 0         0 return $Config{nvtype};
148             }
149              
150             sub type_number_native_ccflag {
151 52     52 0 205 type_number_errorcheck();
152 52 50       248 if ($Config{nvtype} eq 'double') {
    0          
153 52         294 return ' -D__TYPE__NUMBER__DOUBLE';
154             }
155             elsif ($Config{nvtype} eq 'longdbl') {
156 0         0 return ' -D__TYPE__NUMBER__LONG__DOUBLE';
157             }
158             }
159              
160             sub type_number_errorcheck {
161             # NEED ANSWER: should we be checking $Config{use64bitall}???
162 52 50 33 52 0 1232 if ((not exists $Config{nvsize}) or (not defined $Config{nvsize})) {
163 0         0 croak 'ERROR ERPTYREN00: Non-existent or undefined Perl config value $Config{nvsize}, croaking';
164             }
165 52         253 my string $nvsize = $Config{nvsize};
166              
167 52 50 33     1226 if ((not exists $Config{nvtype}) or (not defined $Config{nvtype})) {
168 0         0 croak 'ERROR ERPTYREN01: Non-existent or undefined Perl config value $Config{nvtype}, croaking';
169             }
170              
171 52         250 my string $nvtype = $Config{nvtype};
172              
173             # DEV NOTE: I decided to programmatically approach the 'long double' issue in case 'longdouble' and 'longdbl' are both valid,
174             # instead of hard-coding one or the other in $ALTERNATE_TYPES_TO_PERLISH_TYPES;
175             # if nvtype contains whitespace, remove it: 'long double' becomes 'longdouble'
176 52         211 $nvtype =~ s/\s//gxms;
177              
178 52         144 my string $nvtypesize_key = $nvtype . 'size';
179              
180 52 50 33     1036 if ((not exists $Config{$nvtypesize_key}) or (not defined $Config{$nvtypesize_key})) {
181             # try with 'dbl' instead of 'double'
182 0 0       0 if ($nvtype =~ m/double/gxms) {
183 0         0 $nvtype =~ s/double/dbl/gxms;
184 0         0 my string $nvtypesize_key_long = $nvtypesize_key;
185 0         0 $nvtypesize_key = $nvtype . 'size';
186 0 0 0     0 if ((not exists $Config{$nvtypesize_key}) or (not defined $Config{$nvtypesize_key})) {
187 0         0 croak 'ERROR ERPTYREN02: Non-existent or undefined Perl config values $Config{' . $nvtypesize_key_long . '} and $Config{' . $nvtypesize_key . '}, croaking';
188             }
189             }
190             else {
191 0         0 croak 'ERROR ERPTYREN03: Non-existent or undefined Perl config value $Config{' . $nvtypesize_key . '}, croaking';
192             }
193             }
194 52         263 my string $nvtypesize = $Config{$nvtypesize_key};
195              
196 52 50       226 if ($nvsize ne $nvtypesize) {
197 0           croak 'ERROR ERPTYREN04: Mis-matching Perl config values, $Config{nvsize} = ' . $nvsize . ', $Config{' . $nvtypesize_key . '} = ' . $nvtypesize . ', croaking';
198             }
199             }
200              
201             sub type_number_bitsize_dump {
202 0     0 0   foreach my $o (qw(nvsize nvtype use64bitall doublesize longdblsize d_longdbl)) {
203 0           print q($Config{) . $o . q(} = ) . $Config{$o} . "\n";
204             }
205             }
206              
207             1; # end of package