File: Pointer.pm

package info (click to toggle)
icheck 0.9.7-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,352 kB
  • sloc: perl: 12,152; makefile: 202; ansic: 100
file content (146 lines) | stat: -rw-r--r-- 2,943 bytes parent folder | download | duplicates (6)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package CType::Pointer;

use 5.6.0;
use strict;
use warnings;

use CType;
use CType::Fundamental;

no warnings 'recursion';

our @ISA = qw/CType::Fundamental::VoidPtr/;

sub new
  {
    my $this = shift;
    my $class = ref($this) || $this;
    my $type = shift;
    my $qualifiers = shift;
    my $attributes = shift;

    my $const = 0;
    my $restrict = 0;
    my $volatile = 0;

    foreach my $qualifier (@$qualifiers)
      {
        if ($qualifier->isa('CParse::TypeQualifier'))
          {
            if ($qualifier->name eq 'const')
              {
                $const = 1;
              }
            elsif ($qualifier->name eq 'volatile')
              {
                $volatile = 1;
              }
            elsif ($qualifier->name eq 'restrict')
              {
                $restrict = 1;
              }
            else
              {
                die "Internal error: unknown type qualifier " . $qualifier->name;
              }
          }
        else
          {
            die "Internal error: unknown type qualifier $qualifier";
          }
      }

    my $self = {type => $type,
                attributes => $attributes,
                const => $const,
                restrict => $restrict,
                volatile => $volatile,
               };
    bless $self, $class;

    $self->process_attributes($attributes);

    return $self;
  }

sub describe
  {
    my $self = shift;

    my $qualifiers = $self->describe_qualifiers;
    $qualifiers .= ' ' if $qualifiers;

    my $type = $self->{type}->describe;
    return $qualifiers . "pointer to " . $type;
  }

sub dump_c
  {
    my $self = shift;
    my $skip_cpp = shift;
    my $name = shift;

    my $qualifiers = $self->dump_c_qualifiers;

    my $str = '';
    $str .= '*';
    $str .= ' ' . $qualifiers if $qualifiers;
    $str .= ' ' . $name if $name;

    if ($self->{type}->capture_declarator)
      {
        unless ($self->{type}->isa('CType::Pointer'))
          {
            # Anything that captures, and isn't a pointer, needs to be
            # protected with parentheses
            $str = "($str)";
          }
        $str = $self->{type}->dump_c($skip_cpp, $str);
      }
    else
      {
        $str = $self->{type}->dump_c($skip_cpp) . ' ' . $str;
      }

    return $str;
  }

sub capture_declarator
  {
    return 1;
  }

sub _check_interface
  {
    my $self = shift;
    my $other = shift;

    return 'both' unless $other->isa('CType::Pointer');

    my @ret;

    push @ret, $self->check_sizes($other);
    push @ret, $self->check_qualifiers($other);
    push @ret, $self->{type}->check_interface($other->{type});

    return @ret;
  }

sub get_refs
  {
    my $self = shift;
    return $self->{type}->get_refs;
  }

sub layout
  {
    my $self = shift;
    my $accept_incomplete = shift;
    my $namespace = shift;

    $accept_incomplete = 1;

    $self->{type}->layout($accept_incomplete, $namespace);
  }

1;