| 1 | 8 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | package Inline::C::Parser::RegExp; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 7 | { | ||||||||||||||||||||||||||||
| 8 | 8 | extends => [qw(C)], | |||||||||||||||||||||||||||
| 9 | overrides => [qw(get_parser)], | ||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 8 | ▶ | sub get_parser { | ||||||||||||||||||||||||||
|
Subroutine
get_parser: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 8 | ▶ | Inline::C::_parser_test($_[0]->{CONFIG}{DIRECTORY}, "Inline::C::Parser::RegExp::get_parser called\n") if $_[0]->{CONFIG}{_TESTING}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | 8 | bless {}, 'Inline::C::Parser::RegExp' | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 8 | ▶ | sub code { | ||||||||||||||||||||||||||
|
Subroutine
code: called CC=17 SCAR=29.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 8 | my ($self,$code) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # These regular expressions were derived from Regexp::Common v0.01. | ||||||||||||||||||||||||||||
| 22 | 8 | my $RE_comment_C = q{(?:(?:\/\*)(?:(?:(?!\*\/)[\s\S])*)(?:\*\/))}; | |||||||||||||||||||||||||||
| 23 | 8 | my $RE_comment_Cpp = q{(?:\/\*(?:(?!\*\/)[\s\S])*\*\/|\/\/[^\n]*\n)}; | |||||||||||||||||||||||||||
| 24 | 8 | my $RE_quoted = ( | |||||||||||||||||||||||||||
| 25 | q{(?:(?:\")(?:[^\\\"]*(?:\\.[^\\\"]*)*)(?:\")} | ||||||||||||||||||||||||||||
| 26 | . q{|(?:\')(?:[^\\\']*(?:\\.[^\\\']*)*)(?:\'))} | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | 8 | our $RE_balanced_brackets; $RE_balanced_brackets = | |||||||||||||||||||||||||||
| 29 | 8 | qr'(?:[{]((?:(?>[^{}]+)|(??{$RE_balanced_brackets}))*)[}])'; | |||||||||||||||||||||||||||
| 30 | 8 | our $RE_balanced_parens; $RE_balanced_parens = | |||||||||||||||||||||||||||
| 31 | 8 | qr'(?:[(]((?:(?>[^()]+)|(??{$RE_balanced_parens}))*)[)])'; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # First, we crush out anything potentially confusing. | ||||||||||||||||||||||||||||
| 34 | # The order of these _does_ matter. | ||||||||||||||||||||||||||||
| 35 | 8 | $code =~ s/$RE_comment_C/ /go; | |||||||||||||||||||||||||||
| 36 | 8 | $code =~ s/$RE_comment_Cpp/ /go; | |||||||||||||||||||||||||||
| 37 | 8 | $code =~ s/^\#.*(\\\n.*)*//mgo; | |||||||||||||||||||||||||||
| 38 | #$code =~ s/$RE_quoted/\"\"/go; # Buggy, if included. | ||||||||||||||||||||||||||||
| 39 | 8 | $code =~ s/$RE_balanced_brackets/{ }/go; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 8 | $self->{_the_code_most_recently_parsed} = $code; # Simplifies debugging. | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 66 | ▶ | my $normalize_type = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | # Normalize a type for lookup in a typemap. | ||||||||||||||||||||||||||||
| 45 | 66 | my($type) = @_; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Remove "extern". | ||||||||||||||||||||||||||||
| 48 | # But keep "static", "inline", "typedef", etc, | ||||||||||||||||||||||||||||
| 49 | # to cause desirable typemap misses. | ||||||||||||||||||||||||||||
| 50 | 66 | $type =~ s/\bextern\b//g; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # Whitespace: only single spaces, none leading or trailing. | ||||||||||||||||||||||||||||
| 53 | 66 | $type =~ s/\s+/ /g; | |||||||||||||||||||||||||||
| 54 | 66 | $type =~ s/^\s//; $type =~ s/\s$//; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # Adjacent "derivative characters" are not separated by whitespace, | ||||||||||||||||||||||||||||
| 57 | # but _are_ separated from the adjoining text. | ||||||||||||||||||||||||||||
| 58 | # [ Is really only * (and not ()[]) needed??? ] | ||||||||||||||||||||||||||||
| 59 | 66 | $type =~ s/\*\s\*/\*\*/g; | |||||||||||||||||||||||||||
| 60 | 66 | $type =~ s/(?<=[^ \*])\*/ \*/g; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 66 | return $type; | |||||||||||||||||||||||||||
| 63 | 8 | }; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # The decision of what is an acceptable declaration was originally | ||||||||||||||||||||||||||||
| 66 | # derived from Inline::C::grammar.pm version 0.30 (Inline 0.43). | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 8 | my $re_plausible_place_to_begin_a_declaration = qr { | |||||||||||||||||||||||||||
| 69 | # The beginning of a line, possibly indented. | ||||||||||||||||||||||||||||
| 70 | # (Accepting indentation allows for C code to be aligned with | ||||||||||||||||||||||||||||
| 71 | # its surrounding perl, and for backwards compatibility with | ||||||||||||||||||||||||||||
| 72 | # Inline 0.43). | ||||||||||||||||||||||||||||
| 73 | (?m: ^ ) \s* | ||||||||||||||||||||||||||||
| 74 | }xo; | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # Instead of using \s , we don't tolerate blank lines. | ||||||||||||||||||||||||||||
| 77 | # This matches user expectation better than allowing arbitrary | ||||||||||||||||||||||||||||
| 78 | # vertical whitespace. | ||||||||||||||||||||||||||||
| 79 | 8 | my $sp = qr{[ \t]|\n(?![ \t]*\n)}; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 8 | my $re_type = qr{ | |||||||||||||||||||||||||||
| 82 | ( | ||||||||||||||||||||||||||||
| 83 | (?: \w+ $sp* )+? # words | ||||||||||||||||||||||||||||
| 84 | (?: \* $sp* )* # stars | ||||||||||||||||||||||||||||
| 85 | ) | ||||||||||||||||||||||||||||
| 86 | }xo; | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 8 | my $re_identifier = qr{ (\w+) $sp* }xo; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 8 | $code =~ s/\bconst\b//g; # Remove "const" qualifier - it's not wanted here. | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 8 | ▶ | while ($code =~ m{ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | $re_plausible_place_to_begin_a_declaration | ||||||||||||||||||||||||||||
| 94 | ( $re_type $re_identifier $RE_balanced_parens $sp* (\;|\{) ) | ||||||||||||||||||||||||||||
| 95 | }xgo | ||||||||||||||||||||||||||||
| 96 | ) { | ||||||||||||||||||||||||||||
| 97 | 34 | my ($type, $identifier, $args, $what) = ($2,$3,$4,$5); | |||||||||||||||||||||||||||
| 98 | 34 | ▶ | $args = "" if $args =~ /^\s+$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 34 | my $is_decl = $what eq ';'; | |||||||||||||||||||||||||||
| 101 | 34 | my $function = $identifier; | |||||||||||||||||||||||||||
| 102 | 34 | my $return_type = &$normalize_type($type); | |||||||||||||||||||||||||||
| 103 | 34 | my @arguments = split ',', $args; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 34 | ▶ | goto RESYNC if $is_decl && !$self->{data}{AUTOWRAP}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$is_decl and not $self->{"data"}{"AUTOWRAP"}
MC/DC0%0/2
$is_decl and not $self->{"data"}{"AUTOWRAP"}
$is_decl
not $self->{"data"}{"AUTOWRAP"}
Truth table33%1/3
A and not(B)
A= $is_declB= not $self->{"data"}{"AUTOWRAP"}
| |||||||||||||||||||||||||||||
| 106 | 34 | ▶ | goto RESYNC if $self->{data}{done}{$function}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | goto RESYNC if !defined | ||||||||||||||||||||||||||||
| 108 | 34 | ▶ | $self->{data}{typeconv}{valid_rtypes}{$return_type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 34 | my(@arg_names,@arg_types); | |||||||||||||||||||||||||||
| 111 | 34 | my $dummy_name = 'arg1'; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 34 | foreach my $arg (@arguments) { | |||||||||||||||||||||||||||
| 114 | 32 | my $arg_no_space = $arg; | |||||||||||||||||||||||||||
| 115 | 32 | $arg_no_space =~ s/\s//g; | |||||||||||||||||||||||||||
| 116 | # If $arg_no_space is 'void', there will be no identifier. | ||||||||||||||||||||||||||||
| 117 | 32 | ▶ | if (my($type, $identifier) = | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 118 | $arg =~ /^\s*$re_type(?:$re_identifier)?\s*$/o | ||||||||||||||||||||||||||||
| 119 | ) { | ||||||||||||||||||||||||||||
| 120 | 32 | my $arg_name = $identifier; | |||||||||||||||||||||||||||
| 121 | 32 | my $arg_type = &$normalize_type($type); | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 32 | ▶ | if ((!defined $arg_name) && ($arg_no_space ne 'void')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $arg_name and $arg_no_space ne "void"
MC/DC0%0/2
not defined $arg_name and $arg_no_space ne "void"
not defined $arg_name
$arg_no_space ne "void"
Truth table66%2/3
not(A) and B
A= not defined $arg_nameB= $arg_no_space ne "void"
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | goto RESYNC if !$is_decl; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | $arg_name = $dummy_name++; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | goto RESYNC if ((!defined | ||||||||||||||||||||||||||||
| 128 | 32 | ▶ | $self->{data}{typeconv}{valid_types}{$arg_type}) && ($arg_no_space ne 'void')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $self->{"data"}{"typeconv"}{"valid_types"}{$arg_type} and $arg_no_space ne "void"
MC/DC0%0/2
not defined $self->{"data"}{"typeconv"}{"valid_types"}{$arg_type} and $arg_no_space ne "void"
not defined $self->{"data"}{"typeconv"}{"valid_types"}{$arg_type}
$arg_no_space ne "void"
Truth table66%2/3
not(A) and B
A= not defined $self->{"data"}{"typeconv"}{"valid_types"}{$arg_type}B= $arg_no_space ne "void"
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # Push $arg_name onto @arg_names iff it's defined. Otherwise ($arg_no_space | ||||||||||||||||||||||||||||
| 131 | # was 'void'), push the empty string onto @arg_names (to avoid uninitialized | ||||||||||||||||||||||||||||
| 132 | # warnings emanating from C.pm). | ||||||||||||||||||||||||||||
| 133 | 32 | ▶ | defined($arg_name) ? push(@arg_names,$arg_name) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | : push(@arg_names, ''); | ||||||||||||||||||||||||||||
| 135 | 32 | ▶ | if ($arg_name) {push(@arg_types,$arg_type)} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 10 | else {push(@arg_types,'')} # $arg_no_space was 'void' - this push() avoids 'uninitialized' warnings from C.pm | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | elsif ($arg =~ /^\s*\.\.\.\s*$/) { | ||||||||||||||||||||||||||||
| 139 | 0 | push(@arg_names,'...'); | |||||||||||||||||||||||||||
| 140 | 0 | push(@arg_types,'...'); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | else { | ||||||||||||||||||||||||||||
| 143 | 0 | goto RESYNC; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # Commit. | ||||||||||||||||||||||||||||
| 148 | 34 | push @{$self->{data}{functions}}, $function; | |||||||||||||||||||||||||||
| 149 | 34 | $self->{data}{function}{$function}{return_type}= $return_type; | |||||||||||||||||||||||||||
| 150 | 34 | $self->{data}{function}{$function}{arg_names} = [@arg_names]; | |||||||||||||||||||||||||||
| 151 | 34 | $self->{data}{function}{$function}{arg_types} = [@arg_types]; | |||||||||||||||||||||||||||
| 152 | 34 | $self->{data}{done}{$function} = 1; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 34 | next; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | RESYNC: # Skip the rest of the current line, and continue. | |||||||||||||||||||||||||||
| 157 | $code =~ /\G[^\n]*\n/gc; | ||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 8 | return 1; # We never fail. | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 8 | 1; | |||||||||||||||||||||||||||