/usr/share/perl5/Inline/C/Parser/RegExp.pm is in libinline-c-perl 0.76-1.
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 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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | use strict; use warnings;
package Inline::C::Parser::RegExp;
use Carp;
sub register {
{
extends => [qw(C)],
overrides => [qw(get_parser)],
}
}
sub get_parser {
Inline::C::_parser_test($_[0]->{CONFIG}{DIRECTORY}, "Inline::C::Parser::RegExp::get_parser called\n") if $_[0]->{CONFIG}{_TESTING};
bless {}, 'Inline::C::Parser::RegExp'
}
sub code {
my ($self,$code) = @_;
# These regular expressions were derived from Regexp::Common v0.01.
my $RE_comment_C = q{(?:(?:\/\*)(?:(?:(?!\*\/)[\s\S])*)(?:\*\/))};
my $RE_comment_Cpp = q{(?:\/\*(?:(?!\*\/)[\s\S])*\*\/|\/\/[^\n]*\n)};
my $RE_quoted = (
q{(?:(?:\")(?:[^\\\"]*(?:\\.[^\\\"]*)*)(?:\")}
. q{|(?:\')(?:[^\\\']*(?:\\.[^\\\']*)*)(?:\'))}
);
our $RE_balanced_brackets; $RE_balanced_brackets =
qr'(?:[{]((?:(?>[^{}]+)|(??{$RE_balanced_brackets}))*)[}])';
our $RE_balanced_parens; $RE_balanced_parens =
qr'(?:[(]((?:(?>[^()]+)|(??{$RE_balanced_parens}))*)[)])';
# First, we crush out anything potentially confusing.
# The order of these _does_ matter.
$code =~ s/$RE_comment_C/ /go;
$code =~ s/$RE_comment_Cpp/ /go;
$code =~ s/^\#.*(\\\n.*)*//mgo;
#$code =~ s/$RE_quoted/\"\"/go; # Buggy, if included.
$code =~ s/$RE_balanced_brackets/{ }/go;
$self->{_the_code_most_recently_parsed} = $code; # Simplifies debugging.
my $normalize_type = sub {
# Normalize a type for lookup in a typemap.
my($type) = @_;
# Remove "extern".
# But keep "static", "inline", "typedef", etc,
# to cause desirable typemap misses.
$type =~ s/\bextern\b//g;
# Whitespace: only single spaces, none leading or trailing.
$type =~ s/\s+/ /g;
$type =~ s/^\s//; $type =~ s/\s$//;
# Adjacent "derivative characters" are not separated by whitespace,
# but _are_ separated from the adjoining text.
# [ Is really only * (and not ()[]) needed??? ]
$type =~ s/\*\s\*/\*\*/g;
$type =~ s/(?<=[^ \*])\*/ \*/g;
return $type;
};
# The decision of what is an acceptable declaration was originally
# derived from Inline::C::grammar.pm version 0.30 (Inline 0.43).
my $re_plausible_place_to_begin_a_declaration = qr {
# The beginning of a line, possibly indented.
# (Accepting indentation allows for C code to be aligned with
# its surrounding perl, and for backwards compatibility with
# Inline 0.43).
(?m: ^ ) \s*
}xo;
# Instead of using \s , we don't tolerate blank lines.
# This matches user expectation better than allowing arbitrary
# vertical whitespace.
my $sp = qr{[ \t]|\n(?![ \t]*\n)};
my $re_type = qr{
(
(?: \w+ $sp* )+? # words
(?: \* $sp* )* # stars
)
}xo;
my $re_identifier = qr{ (\w+) $sp* }xo;
$code =~ s/\bconst\b//g; # Remove "const" qualifier - it's not wanted here.
while ($code =~ m{
$re_plausible_place_to_begin_a_declaration
( $re_type $re_identifier $RE_balanced_parens $sp* (\;|\{) )
}xgo
) {
my ($type, $identifier, $args, $what) = ($2,$3,$4,$5);
$args = "" if $args =~ /^\s+$/;
my $is_decl = $what eq ';';
my $function = $identifier;
my $return_type = &$normalize_type($type);
my @arguments = split ',', $args;
goto RESYNC if $is_decl && !$self->{data}{AUTOWRAP};
goto RESYNC if $self->{data}{done}{$function};
goto RESYNC if !defined
$self->{data}{typeconv}{valid_rtypes}{$return_type};
my(@arg_names,@arg_types);
my $dummy_name = 'arg1';
foreach my $arg (@arguments) {
my $arg_no_space = $arg;
$arg_no_space =~ s/\s//g;
# If $arg_no_space is 'void', there will be no identifier.
if (my($type, $identifier) =
$arg =~ /^\s*$re_type(?:$re_identifier)?\s*$/o
) {
my $arg_name = $identifier;
my $arg_type = &$normalize_type($type);
if ((!defined $arg_name) && ($arg_no_space ne 'void')) {
goto RESYNC if !$is_decl;
$arg_name = $dummy_name++;
}
goto RESYNC if ((!defined
$self->{data}{typeconv}{valid_types}{$arg_type}) && ($arg_no_space ne 'void'));
# Push $arg_name onto @arg_names iff it's defined. Otherwise ($arg_no_space
# was 'void'), push the empty string onto @arg_names (to avoid uninitialized
# warnings emanating from C.pm).
defined($arg_name) ? push(@arg_names,$arg_name)
: push(@arg_names, '');
if ($arg_name) {push(@arg_types,$arg_type)}
else {push(@arg_types,'')} # $arg_no_space was 'void' - this push() avoids 'uninitialized' warnings from C.pm
}
elsif ($arg =~ /^\s*\.\.\.\s*$/) {
push(@arg_names,'...');
push(@arg_types,'...');
}
else {
goto RESYNC;
}
}
# Commit.
push @{$self->{data}{functions}}, $function;
$self->{data}{function}{$function}{return_type}= $return_type;
$self->{data}{function}{$function}{arg_names} = [@arg_names];
$self->{data}{function}{$function}{arg_types} = [@arg_types];
$self->{data}{done}{$function} = 1;
next;
RESYNC: # Skip the rest of the current line, and continue.
$code =~ /\G[^\n]*\n/gc;
}
return 1; # We never fail.
}
1;
|