File: ParameterDeclaration.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 (85 lines) | stat: -rw-r--r-- 1,739 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
package CParse::ParameterDeclaration;

use 5.6.0;
use strict;
use warnings;

sub new
  {
    my $this = shift;
    my $class = ref($this) || $this;
    my $specifiers = shift;
    my $declarator = shift;
    my $self = {specifiers => $specifiers,
                declarator => $declarator,
               };
    bless $self, $class;
    return $self;
  }

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

sub dump_c
  {
    my $self = shift;

    my $str = join(' ', map {$_->dump_c} @{$self->{specifiers}});
    if (defined $self->{declarator})
      {
        $str .= " " if length $str;
        $str .= $self->{declarator}->dump_c;
      }

    return $str;
  }

sub get_type
  {
    my $self = shift;

    my $namespace = shift;

    my $storage_class;
    my @attributes;
    my @specifiers;

    foreach my $specifier (@{$self->{specifiers}})
      {
        if ($specifier->isa('CParse::StorageClass'))
          {
            if ($storage_class)
              {
                die "multiple storage class specifiers\n";
              }
            $storage_class = $specifier;
          }
        elsif ($specifier->isa('CParse::AttributeList'))
          {
            push @attributes, $specifier->attributes;
          }
        else
          {
            push @specifiers, $specifier;
          }
      }

    if ($storage_class and $storage_class->class ne 'register')
      {
        die "parameter declarations cannot have a storage class other than 'register'\n";
      }

    my $type = $self->{declarator}->get_decl_type($namespace, \@specifiers, \@attributes, 1);
    return $type;
  }

sub get_identifier
  {
    my $self = shift;
    return $self->{declarator}->get_identifier;
  }

1;