/usr/share/icheck/perl5/CType/Structural.pm is in icheck 0.9.7-6.3+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | package CType::Structural;
# Common functions for all structural types
use 5.6.0;
use strict;
use warnings;
use CType::Fundamental qw/compare_ord/;
sub alignment_exprs
{
my $self = shift;
return @{$self->{alignment_exprs}};
}
sub compute_alignment
{
my $self = shift;
my $alignment = 1;
foreach my $a ($self->alignment_exprs)
{
my $n = $a->compute;
if (not defined $alignment or $alignment < $n)
{
$alignment = $n;
}
}
return $alignment;
}
sub add_alignment
{
my $self = shift;
my $new = shift;
my @alignment;
# We special-case the handling of explicit integer alignment
if ($new->isa('CExpr::Integer'))
{
foreach my $a ($self->alignment_exprs)
{
if ($a->isa('CExpr::Integer'))
{
# Integer values are compared numerically
if ($new->compute > $a->compute)
{
# Discard the current value in favour of the new one
next;
}
else
{
# Discard the new value in favour of the current one
return;
}
}
else
{
# Integer values ignore non-integer ones
push @alignment, $a;
}
}
unshift @alignment, $new;
$self->{alignment_exprs} = \@alignment;
return;
}
foreach my $a ($self->alignment_exprs)
{
if ($new->isa('CExpr::Integer') and $a->isa('CExpr::Integer'))
{
# Integer values are compared numerically
if ($new->compute > $a->compute)
{
# Discard the current value in favour of the new one
next;
}
else
{
# Discard the new value in favour of the current one
return;
}
}
my $c = compare_ord($a, $new);
if (defined $c and ($c == 1 or $c == 0))
{
# There is already an alignment listed which is ordinally
# greater or equal, so we don't need to add this one
return;
}
if (defined $c and ($c == -1))
{
# This alignment is ordinally greater than one which is
# currently listed, so we dump the current one in favour
# of this one
next;
}
push @alignment, $a;
}
push @alignment, $new;
$self->{alignment_exprs} = \@alignment;
}
1;
|