line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Const::Introspect::C::Constant; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
238241
|
use 5.020; |
|
2
|
|
|
|
|
16
|
|
4
|
2
|
|
|
2
|
|
554
|
use Moo; |
|
2
|
|
|
|
|
11661
|
|
|
2
|
|
|
|
|
16
|
|
5
|
2
|
|
|
2
|
|
1872
|
use experimental qw( signatures ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
17
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Class representing a C/C++ constant |
8
|
|
|
|
|
|
|
our $VERSION = '0.01'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has c => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
required => 1, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has name => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
required => 1, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has raw_value => ( |
24
|
|
|
|
|
|
|
is => 'ro', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has value => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
lazy => 1, |
31
|
|
|
|
|
|
|
default => sub ($self) { |
32
|
|
|
|
|
|
|
my $type = $self->type; |
33
|
|
|
|
|
|
|
$type eq 'other' |
34
|
|
|
|
|
|
|
? undef |
35
|
|
|
|
|
|
|
: do { |
36
|
|
|
|
|
|
|
local $@ = ''; |
37
|
|
|
|
|
|
|
my $value = eval { $self->c->compute_expression_value($type, $self->name) }; |
38
|
|
|
|
|
|
|
# TODO: diagnostic on `fail` |
39
|
|
|
|
|
|
|
$@ ? undef : $value; |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has type => ( |
46
|
|
|
|
|
|
|
is => 'ro', |
47
|
|
|
|
|
|
|
isa => sub { |
48
|
|
|
|
|
|
|
die "type should be one of: string, int, long, pointer, float, double or other" |
49
|
|
|
|
|
|
|
unless $_[0] =~ /^(string|int|long|pointer|float|double|other)$/; |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
lazy => 1, |
52
|
|
|
|
|
|
|
default => sub ($self) { |
53
|
|
|
|
|
|
|
local $@ = ''; |
54
|
|
|
|
|
|
|
my $type = eval { $self->c->compute_expression_type($self->name) }; |
55
|
|
|
|
|
|
|
# TODO: diagnostic on `other` |
56
|
|
|
|
|
|
|
$@ ? 'other' : $type; |
57
|
|
|
|
|
|
|
}, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
2
|
|
1156
|
no Moo; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |