File: AST.pm

package info (click to toggle)
libinline-c-perl 0.82-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 656 kB
  • sloc: perl: 2,197; makefile: 10; ansic: 6
file content (50 lines) | stat: -rw-r--r-- 1,024 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
use strict; use warnings;
package Inline::C::Parser::Pegex::AST;
use Pegex::Base;

extends 'Pegex::Tree';

has data => {};

sub initial {
    my ($self) = @_;
    my $data = {
        functions => [],
        function => {},
        done => {},
    };
    $self->data($data);
}

sub final {
    my ($self, $got) = @_;
    return $self->{data};
}

sub got_function_definition {
    my ($self, $ast) = @_;
    my ($rtype, $name, $args) = @$ast;
    my ($rname, $rstars) = @$rtype;
    my $data = $self->data;
    my $def = $data->{function}{$name} = {};
    push @{$data->{functions}}, $name;
    $def->{return_type} = $rname . ($rstars ? " $rstars" : '');
    $def->{arg_names} = [];
    $def->{arg_types} = [];
    for my $arg (@$args) {
        my ($type, $stars, $name) = @$arg;
        push @{$def->{arg_names}}, $name;
        push @{$def->{arg_types}}, $type . ($stars ? " $stars" : '');
    }
    $data->{done}{$name} = 1;
    return;
}


sub got_arg {
    my ($self, $ast) = @_;
    pop @$ast;
    return $ast;
}

1;