package ExtUtils::ParseXS;
-use strict 'subs';
-use strict 'refs';
+use strict;
use 5.006; # We use /??{}/ in regexes
use Cwd;
valid_proto_string
process_typemaps
make_targetable
+ map_type
);
-our (@ISA, @EXPORT_OK, $VERSION);
-@ISA = qw(Exporter);
-@EXPORT_OK = qw(process_file);
-$VERSION = '3';
+our @ISA = qw(Exporter);
+our @EXPORT_OK = qw(
+ process_file
+ report_error_count
+);
+our $VERSION = '3';
$VERSION = eval $VERSION if $VERSION =~ /_/;
-# use strict; # One of these days ...
-
our (
- $ProtoUsed, @InitFileCode, $FH, $proto_re, $Overload, $errors, $Fallback,
- $hiertype, $WantPrototypes, $WantVersionChk, $WantLineNumbers, $filepathname,
- $dir, $filename, %IncludedFiles, %input_expr, %output_expr,
- %type_kind, %proto_letter, $BLOCK_re, $lastline, $lastline_no, $Package,
- $Prefix, @line, %args_match, %defaults, %var_types, %arg_list, @proto_arg,
- $processing_arg_with_types, %argtype_seen, %in_out, %lengthof,
- $proto_in_this_xsub, $scope_in_this_xsub, $interface,
- $interface_macro, $interface_macro_set, $ProtoThisXSUB, $ScopeThisXSUB,
- @line_no, $ret_type, $func_name, $Full_func_name, $Packprefix, $Packid,
- %XsubAliases, %XsubAliasValues, %Interfaces, @Attributes, %outargs, $pname,
- $thisdone, $retvaldone, $deferred, $gotRETVAL, $condnum, $cond,
- $RETVAL_code, $printed_name, $func_args, @XSStack, $ALIAS,
+ # The scalars in the line below remain as 'our' variables because pulling
+ # them into $self led to build problems. In most cases, strings being
+ # 'eval'-ed contain the variables' names hard-coded.
+ $FH, $Package, $func_name, $Full_func_name, $Packid, $pname, $ALIAS,
+ @InitFileCode,
+ %IncludedFiles, %input_expr, %output_expr,
+ %type_kind, %proto_letter,
+ @line, %args_match, %defaults, %var_types, %arg_list, @proto_arg,
+ %argtype_seen, %in_out, %lengthof,
+ @line_no,
+ %XsubAliases, %XsubAliasValues, %Interfaces, @Attributes, %outargs,
+ @XSStack,
);
our ($DoSetMagic, $newXS, $proto, $Module_cname, $XsubAliases, $Interfaces, $var_num, );
+our $self = {};
+
sub process_file {
# Allow for $package->process_file(%hash) in the future
my ($pkg, %options) = @_ % 2 ? @_ : (__PACKAGE__, @_);
- $ProtoUsed = exists $options{prototypes};
+ $self->{ProtoUsed} = exists $options{prototypes};
# Set defaults.
my %args = (
my $cpp_next_tmp = 'XSubPPtmpAAAA';
@InitFileCode = @ExtUtils::ParseXS::Constants::InitFileCode;
$FH = $ExtUtils::ParseXS::Constants::FH;
- $proto_re = $ExtUtils::ParseXS::Constants::proto_re;
- $Overload = $ExtUtils::ParseXS::Constants::Overload;
- $errors = $ExtUtils::ParseXS::Constants::errors;
- $Fallback = $ExtUtils::ParseXS::Constants::Fallback;
+ $self->{Overload} = $ExtUtils::ParseXS::Constants::Overload;
+ $self->{errors} = $ExtUtils::ParseXS::Constants::errors;
+ $self->{Fallback} = $ExtUtils::ParseXS::Constants::Fallback;
# Most of the 1500 lines below uses these globals. We'll have to
# clean this up sometime, probably. For now, we just pull them out
# of %args. -Ken
- $hiertype = $args{hiertype};
- $WantPrototypes = $args{prototypes};
- $WantVersionChk = $args{versioncheck};
- $WantLineNumbers = $args{linenumbers};
+ $self->{hiertype} = $args{hiertype};
+ $self->{WantPrototypes} = $args{prototypes};
+ $self->{WantVersionChk} = $args{versioncheck};
+ $self->{WantLineNumbers} = $args{linenumbers};
for my $f ($args{filename}) {
die "Missing required parameter 'filename'" unless $f;
- $filepathname = $f;
- ($dir, $filename) = (dirname($f), basename($f));
- $filepathname =~ s/\\/\\\\/g;
+ $self->{filepathname} = $f;
+ ($self->{dir}, $self->{filename}) = (dirname($f), basename($f));
+ $self->{filepathname} =~ s/\\/\\\\/g;
$IncludedFiles{$f}++;
}
my $orig_cwd = cwd();
my $orig_fh = select();
- chdir($dir);
+ chdir($self->{dir});
my $pwd = cwd();
my $csuffix = $args{csuffix};
- if ($WantLineNumbers) {
+ if ($self->{WantLineNumbers}) {
my $cfile;
if ( $args{outfile} ) {
$cfile = $args{outfile};
my $END = "!End!\n\n"; # "impossible" keyword (multiple newline)
# Match an XS keyword
- $BLOCK_re = '\s*(' . join('|', qw(
- REQUIRE BOOT CASE PREINIT INPUT INIT CODE PPCODE
- OUTPUT CLEANUP ALIAS ATTRS PROTOTYPES PROTOTYPE
- VERSIONCHECK INCLUDE INCLUDE_COMMAND SCOPE INTERFACE
- INTERFACE_MACRO C_ARGS POSTCALL OVERLOAD FALLBACK
- )) . "|$END)\\s*:";
+ $self->{BLOCK_re} = '\s*(' .
+ join('|' => @ExtUtils::ParseXS::Constants::keywords) .
+ "|$END)\\s*:";
our ($C_group_rex, $C_arg);
# Group in C (no support for comments or literals)
print <<EOM;
/*
* This file was generated automatically by ExtUtils::ParseXS version $VERSION from the
- * contents of $filename. Do not edit this file, edit $filename instead.
+ * contents of $self->{filename}. Do not edit this file, edit $self->{filename} instead.
*
* ANY CHANGES MADE HERE WILL BE LOST!
*
EOM
- print("#line 1 \"$filepathname\"\n")
- if $WantLineNumbers;
+ print("#line 1 \"$self->{filepathname}\"\n")
+ if $self->{WantLineNumbers};
- # Open the input file (using basename'd $args{filename} due to chdir above)
- open($FH, $filename) or die "cannot open $filename: $!\n";
+ # Open the input file (using $self->{filename} which
+ # is a basename'd $args{filename} due to chdir above)
+ open($FH, $self->{filename}) or die "cannot open $self->{filename}: $!\n";
firstmodule:
while (<$FH>) {
# concatenated until 2 steps later, so we are safe.
# - Nicholas Clark
print("#if 0\n \"Skipped embedded POD.\"\n#endif\n");
- printf("#line %d \"$filepathname\"\n", $. + 1)
- if $WantLineNumbers;
+ printf("#line %d \"$self->{filepathname}\"\n", $. + 1)
+ if $self->{WantLineNumbers};
next firstmodule
}
# At this point $. is at end of file so die won't state the start
# of the problem, and as we haven't yet read any lines &death won't
# show the correct line in the message either.
- die ("Error: Unterminated pod in $filename, line $podstartline\n")
- unless $lastline;
+ die ("Error: Unterminated pod in $self->{filename}, line $podstartline\n")
+ unless $self->{lastline};
}
- last if ($Package, $Prefix) =
+ last if ($Package, $self->{Prefix}) =
/^MODULE\s*=\s*[\w:]+(?:\s+PACKAGE\s*=\s*([\w:]+))?(?:\s+PREFIX\s*=\s*(\S+))?\s*$/;
print $_;
exit 0; # Not a fatal error for the caller process
}
- print 'ExtUtils::ParseXS::CountLines'->end_marker, "\n" if $WantLineNumbers;
+ print 'ExtUtils::ParseXS::CountLines'->end_marker, "\n" if $self->{WantLineNumbers};
print <<"EOF";
#ifndef PERL_UNUSED_VAR
EOF
- print 'ExtUtils::ParseXS::CountLines'->end_marker, "\n" if $WantLineNumbers;
+ print 'ExtUtils::ParseXS::CountLines'->end_marker, "\n" if $self->{WantLineNumbers};
- $lastline = $_;
- $lastline_no = $.;
+ $self->{lastline} = $_;
+ $self->{lastline_no} = $.;
my (@BootCode, @outlist, $prepush_done, $xsreturn, $func_header, $orig_args, );
PARAGRAPH:
undef(%defaults);
undef(%arg_list);
undef(@proto_arg);
- undef($processing_arg_with_types);
+ undef($self->{processing_arg_with_types});
undef(%argtype_seen);
undef(@outlist);
undef(%in_out);
undef(%lengthof);
- undef($proto_in_this_xsub);
- undef($scope_in_this_xsub);
- undef($interface);
+ undef($self->{proto_in_this_xsub});
+ undef($self->{scope_in_this_xsub});
+ undef($self->{interface});
undef($prepush_done);
- $interface_macro = 'XSINTERFACE_FUNC';
- $interface_macro_set = 'XSINTERFACE_FUNC_SET';
- $ProtoThisXSUB = $WantPrototypes;
- $ScopeThisXSUB = 0;
+ $self->{interface_macro} = 'XSINTERFACE_FUNC';
+ $self->{interface_macro_set} = 'XSINTERFACE_FUNC_SET';
+ $self->{ProtoThisXSUB} = $self->{WantPrototypes};
+ $self->{ScopeThisXSUB} = 0;
$xsreturn = 0;
$_ = shift(@line);
if (check_keyword("BOOT")) {
&check_cpp;
- push (@BootCode, "#line $line_no[@line_no - @line] \"$filepathname\"")
- if $WantLineNumbers && $line[0] !~ /^\s*#\s*line\b/;
+ push (@BootCode, "#line $line_no[@line_no - @line] \"$self->{filepathname}\"")
+ if $self->{WantLineNumbers} && $line[0] !~ /^\s*#\s*line\b/;
push (@BootCode, @line, "");
next PARAGRAPH;
}
# extract return type, function name and arguments
- ($ret_type) = tidy_type($_);
- $RETVAL_no_return = 1 if $ret_type =~ s/^NO_OUTPUT\s+//;
+ ($self->{ret_type}) = tidy_type($_);
+ $RETVAL_no_return = 1 if $self->{ret_type} =~ s/^NO_OUTPUT\s+//;
# Allow one-line ANSI-like declaration
unshift @line, $2
if $args{argtypes}
- and $ret_type =~ s/^(.*?\w.*?)\s*\b(\w+\s*\(.*)/$1/s;
+ and $self->{ret_type} =~ s/^(.*?\w.*?)\s*\b(\w+\s*\(.*)/$1/s;
# a function definition needs at least 2 lines
- blurt ("Error: Function definition too short '$ret_type'"), next PARAGRAPH
+ blurt ("Error: Function definition too short '$self->{ret_type}'"), next PARAGRAPH
unless @line;
- $externC = 1 if $ret_type =~ s/^extern "C"\s+//;
- $static = 1 if $ret_type =~ s/^static\s+//;
+ $externC = 1 if $self->{ret_type} =~ s/^extern "C"\s+//;
+ $static = 1 if $self->{ret_type} =~ s/^static\s+//;
$func_header = shift(@line);
blurt ("Error: Cannot parse function definition from '$func_header'"), next PARAGRAPH
($class, $func_name, $orig_args) = ($1, $2, $3);
$class = "$4 $class" if $4;
- ($pname = $func_name) =~ s/^($Prefix)?/$Packprefix/;
+ ($pname = $func_name) =~ s/^($self->{Prefix})?/$self->{Packprefix}/;
my $clean_func_name;
- ($clean_func_name = $func_name) =~ s/^$Prefix//;
+ ($clean_func_name = $func_name) =~ s/^$self->{Prefix}//;
$Full_func_name = "${Packid}_$clean_func_name";
if ($Is_VMS) {
$Full_func_name = $SymSet->addsym($Full_func_name);
for (@func_args) {
s/^/&/ if $in_out{$_};
}
- $func_args = join(", ", @func_args);
+ $self->{func_args} = join(", ", @func_args);
@args_match{@args} = @args_num;
my $PPCODE = grep(/^\s*PPCODE\s*:/, @line);
# dXSI32;
EOF
print Q(<<"EOF") if $INTERFACE;
-# dXSFUNCTION($ret_type);
+# dXSFUNCTION($self->{ret_type});
EOF
if ($ellipsis) {
- $cond = ($min_args ? qq(items < $min_args) : 0);
+ $self->{cond} = ($min_args ? qq(items < $min_args) : 0);
}
elsif ($min_args == $num_args) {
- $cond = qq(items != $min_args);
+ $self->{cond} = qq(items != $min_args);
}
else {
- $cond = qq(items < $min_args || items > $num_args);
+ $self->{cond} = qq(items < $min_args || items > $num_args);
}
print Q(<<"EOF") if $args{except};
# *errbuf = '\0';
EOF
- if($cond) {
+ if($self->{cond}) {
print Q(<<"EOF");
-# if ($cond)
+# if ($self->{cond})
# croak_xs_usage(cv, "$report_args");
EOF
}
# Now do a block of some sort.
- $condnum = 0;
- $cond = ''; # last CASE: condidional
+ $self->{condnum} = 0;
+ $self->{cond} = ''; # last CASE: condidional
push(@line, "$END:");
push(@line_no, $line_no[-1]);
$_ = '';
EOF
# do initialization of input variables
- $thisdone = 0;
- $retvaldone = 0;
- $deferred = "";
+ $self->{thisdone} = 0;
+ $self->{retvaldone} = 0;
+ $self->{deferred} = "";
%arg_list = ();
- $gotRETVAL = 0;
+ $self->{gotRETVAL} = 0;
INPUT_handler();
process_keyword("INPUT|PREINIT|INTERFACE_MACRO|C_ARGS|ALIAS|ATTRS|PROTOTYPE|SCOPE|OVERLOAD");
- print Q(<<"EOF") if $ScopeThisXSUB;
+ print Q(<<"EOF") if $self->{ScopeThisXSUB};
# ENTER;
# [[
EOF
- if (!$thisdone && defined($class)) {
+ if (!$self->{thisdone} && defined($class)) {
if (defined($static) or $func_name eq 'new') {
print "\tchar *";
$var_types{"CLASS"} = "char *";
- &generate_init("char *", 1, "CLASS");
+ generate_init( {
+ type => "char *",
+ num => 1,
+ var => "CLASS",
+ printed_name => undef,
+ } );
}
else {
print "\t$class *";
$var_types{"THIS"} = "$class *";
- &generate_init("$class *", 1, "THIS");
+ generate_init( {
+ type => "$class *",
+ num => 1,
+ var => "THIS",
+ printed_name => undef,
+ } );
}
}
$_ = '';
}
else {
- if ($ret_type ne "void") {
- print "\t" . &map_type($ret_type, 'RETVAL') . ";\n"
- if !$retvaldone;
+ if ($self->{ret_type} ne "void") {
+ print "\t" . &map_type($self->{ret_type}, 'RETVAL', $self->{hiertype}) . ";\n"
+ if !$self->{retvaldone};
$args_match{"RETVAL"} = 0;
- $var_types{"RETVAL"} = $ret_type;
+ $var_types{"RETVAL"} = $self->{ret_type};
print "\tdXSTARG;\n"
- if $args{optimize} and $targetable{$type_kind{$ret_type}};
+ if $args{optimize} and $targetable{$type_kind{$self->{ret_type}}};
}
if (@fake_INPUT or @fake_INPUT_pre) {
unshift @line, @fake_INPUT_pre, @fake_INPUT, $_;
$_ = "";
- $processing_arg_with_types = 1;
+ $self->{processing_arg_with_types} = 1;
INPUT_handler();
}
- print $deferred;
+ print $self->{deferred};
process_keyword("INIT|ALIAS|ATTRS|PROTOTYPE|INTERFACE_MACRO|INTERFACE|C_ARGS|OVERLOAD");
if (check_keyword("PPCODE")) {
print_section();
death ("PPCODE must be last thing") if @line;
- print "\tLEAVE;\n" if $ScopeThisXSUB;
+ print "\tLEAVE;\n" if $self->{ScopeThisXSUB};
print "\tPUTBACK;\n\treturn;\n";
}
elsif (check_keyword("CODE")) {
}
else {
print "\n\t";
- if ($ret_type ne "void") {
+ if ($self->{ret_type} ne "void") {
print "RETVAL = ";
$wantRETVAL = 1;
}
}
$func_name =~ s/^\Q$args{'s'}//
if exists $args{'s'};
- $func_name = 'XSFUNCTION' if $interface;
- print "$func_name($func_args);\n";
+ $func_name = 'XSFUNCTION' if $self->{interface};
+ print "$func_name($self->{func_args});\n";
}
}
# do output variables
- $gotRETVAL = 0; # 1 if RETVAL seen in OUTPUT section;
- undef $RETVAL_code ; # code to set RETVAL (from OUTPUT section);
+ $self->{gotRETVAL} = 0; # 1 if RETVAL seen in OUTPUT section;
+ undef $self->{RETVAL_code} ; # code to set RETVAL (from OUTPUT section);
# $wantRETVAL set if 'RETVAL =' autogenerated
- ($wantRETVAL, $ret_type) = (0, 'void') if $RETVAL_no_return;
+ ($wantRETVAL, $self->{ret_type}) = (0, 'void') if $RETVAL_no_return;
undef %outargs;
process_keyword("POSTCALL|OUTPUT|ALIAS|ATTRS|PROTOTYPE|OVERLOAD");
- &generate_output($var_types{$_}, $args_match{$_}, $_, $DoSetMagic)
- for grep $in_out{$_} =~ /OUT$/, keys %in_out;
+ generate_output( {
+ type => $var_types{$_},
+ num => $args_match{$_},
+ var => $_,
+ do_setmagic => $DoSetMagic,
+ do_push => undef,
+ } ) for grep $in_out{$_} =~ /OUT$/, keys %in_out;
# all OUTPUT done, so now push the return value on the stack
- if ($gotRETVAL && $RETVAL_code) {
- print "\t$RETVAL_code\n";
+ if ($self->{gotRETVAL} && $self->{RETVAL_code}) {
+ print "\t$self->{RETVAL_code}\n";
}
- elsif ($gotRETVAL || $wantRETVAL) {
- my $t = $args{optimize} && $targetable{$type_kind{$ret_type}};
+ elsif ($self->{gotRETVAL} || $wantRETVAL) {
+ my $t = $args{optimize} && $targetable{$type_kind{$self->{ret_type}}};
+ # Although the '$var' declared in the next line is never explicitly
+ # used within this 'elsif' block, commenting it out leads to
+ # disaster, starting with the first 'eval qq' inside the 'elsif' block
+ # below.
+ # It appears that this is related to the fact that at this point the
+ # value of $t is a reference to an array whose [2] element includes
+ # '$var' as a substring:
+ # <i> <> <(IV)$var>
my $var = 'RETVAL';
- my $type = $ret_type;
+ my $type = $self->{ret_type};
# 0: type, 1: with_size, 2: how, 3: how_size
if ($t and not $t->[1] and $t->[0] eq 'p') {
}
else {
# RETVAL almost never needs SvSETMAGIC()
- &generate_output($ret_type, 0, 'RETVAL', 0);
+ generate_output( {
+ type => $self->{ret_type},
+ num => 0,
+ var => 'RETVAL',
+ do_setmagic => 0,
+ do_push => undef,
+ } );
}
}
- $xsreturn = 1 if $ret_type ne "void";
+ $xsreturn = 1 if $self->{ret_type} ne "void";
my $num = $xsreturn;
my $c = @outlist;
print "\tXSprePUSH;" if $c and not $prepush_done;
print "\tEXTEND(SP,$c);\n" if $c;
$xsreturn += $c;
- generate_output($var_types{$_}, $num++, $_, 0, 1) for @outlist;
+ generate_output( {
+ type => $var_types{$_},
+ num => $num++,
+ var => $_,
+ do_setmagic => 0,
+ do_push => 1,
+ } ) for @outlist;
# do cleanup
process_keyword("CLEANUP|ALIAS|ATTRS|PROTOTYPE|OVERLOAD");
- print Q(<<"EOF") if $ScopeThisXSUB;
+ print Q(<<"EOF") if $self->{ScopeThisXSUB};
# ]]
EOF
- print Q(<<"EOF") if $ScopeThisXSUB and not $PPCODE;
+ print Q(<<"EOF") if $self->{ScopeThisXSUB} and not $PPCODE;
# LEAVE;
EOF
EOF
if (check_keyword("CASE")) {
blurt ("Error: No `CASE:' at top of function")
- unless $condnum;
+ unless $self->{condnum};
$_ = "CASE: $_"; # Restore CASE: label
next;
}
last if $_ eq "$END:";
- death(/^$BLOCK_re/o ? "Misplaced `$1:'" : "Junk at end of function ($_)");
+ death(/^$self->{BLOCK_re}/o ? "Misplaced `$1:'" : "Junk at end of function ($_)");
}
print Q(<<"EOF") if $args{except};
$proto = "";
# Build the prototype string for the xsub
- if ($ProtoThisXSUB) {
+ if ($self->{ProtoThisXSUB}) {
$newXS = "newXSproto_portable";
- if ($ProtoThisXSUB eq 2) {
+ if ($self->{ProtoThisXSUB} eq 2) {
# User has specified empty prototype
}
- elsif ($ProtoThisXSUB eq 1) {
+ elsif ($self->{ProtoThisXSUB} eq 1) {
my $s = ';';
if ($min_args < $num_args) {
$s = '';
}
else {
# User has specified a prototype
- $proto = $ProtoThisXSUB;
+ $proto = $self->{ProtoThisXSUB};
}
$proto = qq{, "$proto"};
}
# apply_attrs_string("$Package", cv, "@Attributes", 0);
EOF
}
- elsif ($interface) {
+ elsif ($self->{interface}) {
while ( my ($yname, $value) = each %Interfaces) {
$yname = "$Package\::$yname" unless $yname =~ /::/;
push(@InitFileCode, Q(<<"EOF"));
# cv = ${newXS}(\"$yname\", XS_$Full_func_name, file$proto);
-# $interface_macro_set(cv,$value);
+# $self->{interface_macro_set}(cv,$value);
EOF
}
}
}
} # END 'PARAGRAPH' 'while' loop
- if ($Overload) { # make it findable with fetchmethod
+ if ($self->{Overload}) { # make it findable with fetchmethod
print Q(<<"EOF");
#XS(XS_${Packid}_nil); /* prototype to pass -Wmissing-prototypes */
#XS(XS_${Packid}_nil)
# PERL_UNUSED_VAR(items); /* -W */
EOF
- print Q(<<"EOF") if $WantVersionChk;
+ print Q(<<"EOF") if $self->{WantVersionChk};
# XS_VERSION_BOOTCHECK;
#
EOF
#
EOF
- print Q(<<"EOF") if ($Overload);
+ print Q(<<"EOF") if ($self->{Overload});
# /* register the overloading (type 'A') magic */
# PL_amagic_generation++;
# /* The magic for overload gets a GV* via gv_fetchmeth as */
# /* the "fallback" status. */
# sv_setsv(
# get_sv( "${Package}::()", TRUE ),
-# $Fallback
+# $self->{Fallback}
# );
EOF
#
EOF
- warn("Please specify prototyping behavior for $filename (see perlxs manual)\n")
- unless $ProtoUsed;
+ warn("Please specify prototyping behavior for $self->{filename} (see perlxs manual)\n")
+ unless $self->{ProtoUsed};
chdir($orig_cwd);
select($orig_fh);
return 1;
}
-sub errors { $errors }
+sub report_error_count { $self->{errors} }
# Input: ($_, @line) == unparsed input.
# Output: ($_, @line) == (rest of line, following lines).
# the "do" is required for right semantics
do { $_ = shift(@line) } while !/\S/ && @line;
- print("#line ", $line_no[@line_no - @line -1], " \"$filepathname\"\n")
- if $WantLineNumbers && !/^\s*#\s*line\b/ && !/^#if XSubPPtmp/;
- for (; defined($_) && !/^$BLOCK_re/o; $_ = shift(@line)) {
+ print("#line ", $line_no[@line_no - @line -1], " \"$self->{filepathname}\"\n")
+ if $self->{WantLineNumbers} && !/^\s*#\s*line\b/ && !/^#if XSubPPtmp/;
+ for (; defined($_) && !/^$self->{BLOCK_re}/o; $_ = shift(@line)) {
print "$_\n";
}
- print 'ExtUtils::ParseXS::CountLines'->end_marker, "\n" if $WantLineNumbers;
+ print 'ExtUtils::ParseXS::CountLines'->end_marker, "\n" if $self->{WantLineNumbers};
}
sub merge_section {
$_ = shift(@line);
}
- for (; defined($_) && !/^$BLOCK_re/o; $_ = shift(@line)) {
+ for (; defined($_) && !/^$self->{BLOCK_re}/o; $_ = shift(@line)) {
$in .= "$_\n";
}
chomp $in;
sub CASE_handler {
blurt ("Error: `CASE:' after unconditional `CASE:'")
- if $condnum && $cond eq '';
- $cond = $_;
- trim_whitespace($cond);
- print " ", ($condnum++ ? " else" : ""), ($cond ? " if ($cond)\n" : "\n");
+ if $self->{condnum} && $self->{cond} eq '';
+ $self->{cond} = $_;
+ trim_whitespace($self->{cond});
+ print " ", ($self->{condnum}++ ? " else" : ""), ($self->{cond} ? " if ($self->{cond})\n" : "\n");
$_ = '';
}
sub INPUT_handler {
- for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
+ for (; !/^$self->{BLOCK_re}/o; $_ = shift(@line)) {
last if /^\s*NOT_IMPLEMENTED_YET/;
next unless /\S/; # skip blank lines
if (s/^([^=]*)\blength\(\s*(\w+)\s*\)\s*$/$1 XSauto_length_of_$2=NO_INIT/x) {
print "\tSTRLEN\tSTRLEN_length_of_$2;\n";
$lengthof{$2} = undef;
- $deferred .= "\n\tXSauto_length_of_$2 = STRLEN_length_of_$2;\n";
+ $self->{deferred} .= "\n\tXSauto_length_of_$2 = STRLEN_length_of_$2;\n";
}
# check for optional initialisation code
# Check for duplicate definitions
blurt ("Error: duplicate definition of argument '$var_name' ignored"), next
if $arg_list{$var_name}++
- or defined $argtype_seen{$var_name} and not $processing_arg_with_types;
+ or defined $argtype_seen{$var_name} and not $self->{processing_arg_with_types};
- $thisdone |= $var_name eq "THIS";
- $retvaldone |= $var_name eq "RETVAL";
+ $self->{thisdone} |= $var_name eq "THIS";
+ $self->{retvaldone} |= $var_name eq "RETVAL";
$var_types{$var_name} = $var_type;
# XXXX This check is a safeguard against the unfinished conversion of
# generate_init(). When generate_init() is fixed,
# one can use 2-args map_type() unconditionally.
+ my $printed_name;
if ($var_type =~ / \( \s* \* \s* \) /x) {
# Function pointers are not yet supported with &output_init!
- print "\t" . &map_type($var_type, $var_name);
+ print "\t" . &map_type($var_type, $var_name, $self->{hiertype});
$printed_name = 1;
}
else {
- print "\t" . &map_type($var_type);
+ print "\t" . &map_type($var_type, undef, $self->{hiertype});
$printed_name = 0;
}
$var_num = $args_match{$var_name};
- $proto_arg[$var_num] = ProtoString($var_type)
- if $var_num;
- $func_args =~ s/\b($var_name)\b/&$1/ if $var_addr;
+ if ($var_num) {
+ $proto_arg[$var_num] = $proto_letter{$var_type} || "\$";
+ }
+ $self->{func_args} =~ s/\b($var_name)\b/&$1/ if $var_addr;
if ($var_init =~ /^[=;]\s*NO_INIT\s*;?\s*$/
or $in_out{$var_name} and $in_out{$var_name} =~ /^OUT/
and $var_init !~ /\S/) {
}
}
elsif ($var_init =~ /\S/) {
- &output_init($var_type, $var_num, $var_name, $var_init, $printed_name);
+ output_init( {
+ type => $var_type,
+ num => $var_num,
+ var => $var_name,
+ init => $var_init,
+ printed_name => $printed_name,
+ } );
}
elsif ($var_num) {
- # generate initialization code
- &generate_init($var_type, $var_num, $var_name, $printed_name);
+ generate_init( {
+ type => $var_type,
+ num => $var_num,
+ var => $var_name,
+ printed_name => $printed_name,
+ } );
}
else {
print ";\n";
}
sub OUTPUT_handler {
- for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
+ for (; !/^$self->{BLOCK_re}/o; $_ = shift(@line)) {
next unless /\S/;
if (/^\s*SETMAGIC\s*:\s*(ENABLE|DISABLE)\s*/) {
$DoSetMagic = ($1 eq "ENABLE" ? 1 : 0);
my ($outarg, $outcode) = /^\s*(\S+)\s*(.*?)\s*$/s;
blurt ("Error: duplicate OUTPUT argument '$outarg' ignored"), next
if $outargs{$outarg}++;
- if (!$gotRETVAL and $outarg eq 'RETVAL') {
+ if (!$self->{gotRETVAL} and $outarg eq 'RETVAL') {
# deal with RETVAL last
- $RETVAL_code = $outcode;
- $gotRETVAL = 1;
+ $self->{RETVAL_code} = $outcode;
+ $self->{gotRETVAL} = 1;
next;
}
blurt ("Error: OUTPUT $outarg not an argument"), next
print "\tSvSETMAGIC(ST(" , $var_num-1 , "));\n" if $DoSetMagic;
}
else {
- &generate_output($var_types{$outarg}, $var_num, $outarg, $DoSetMagic);
+ generate_output( {
+ type => $var_types{$outarg},
+ num => $var_num,
+ var => $outarg,
+ do_setmagic => $DoSetMagic,
+ do_push => undef,
+ } );
}
delete $in_out{$outarg} # No need to auto-OUTPUT
if exists $in_out{$outarg} and $in_out{$outarg} =~ /OUT$/;
my $in = merge_section();
trim_whitespace($in);
- $func_args = $in;
+ $self->{func_args} = $in;
}
sub INTERFACE_MACRO_handler() {
trim_whitespace($in);
if ($in =~ /\s/) { # two
- ($interface_macro, $interface_macro_set) = split ' ', $in;
+ ($self->{interface_macro}, $self->{interface_macro_set}) = split ' ', $in;
}
else {
- $interface_macro = $in;
- $interface_macro_set = 'UNKNOWN_CVT'; # catch later
+ $self->{interface_macro} = $in;
+ $self->{interface_macro_set} = 'UNKNOWN_CVT'; # catch later
}
- $interface = 1; # local
+ $self->{interface} = 1; # local
$Interfaces = 1; # global
}
foreach (split /[\s,]+/, $in) {
my $iface_name = $_;
- $iface_name =~ s/^$Prefix//;
+ $iface_name =~ s/^$self->{Prefix}//;
$Interfaces{$iface_name} = $_;
}
print Q(<<"EOF");
-# XSFUNCTION = $interface_macro($ret_type,cv,XSANY.any_dptr);
+# XSFUNCTION = $self->{interface_macro}($self->{ret_type},cv,XSANY.any_dptr);
EOF
- $interface = 1; # local
+ $self->{interface} = 1; # local
$Interfaces = 1; # global
}
my $orig_alias = $alias;
# check for optional package definition in the alias
- $alias = $Packprefix . $alias if $alias !~ /::/;
+ $alias = $self->{Packprefix} . $alias if $alias !~ /::/;
# check for duplicate alias name & duplicate value
Warn("Warning: Ignoring duplicate alias '$orig_alias'")
}
sub ATTRS_handler () {
- for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
+ for (; !/^$self->{BLOCK_re}/o; $_ = shift(@line)) {
next unless /\S/;
trim_whitespace($_);
push @Attributes, $_;
}
sub ALIAS_handler () {
- for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
+ for (; !/^$self->{BLOCK_re}/o; $_ = shift(@line)) {
next unless /\S/;
trim_whitespace($_);
GetAliases($_) if $_;
}
sub OVERLOAD_handler() {
- for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
+ for (; !/^$self->{BLOCK_re}/o; $_ = shift(@line)) {
next unless /\S/;
trim_whitespace($_);
while ( s/^\s*([\w:"\\)\+\-\*\/\%\<\>\.\&\|\^\!\~\{\}\=]+)\s*//) {
- $Overload = 1 unless $Overload;
+ $self->{Overload} = 1 unless $self->{Overload};
my $overload = "$Package\::(".$1;
push(@InitFileCode,
" (void)${newXS}(\"$overload\", XS_$Full_func_name, file$proto);\n");
# check for valid FALLBACK value
death ("Error: FALLBACK: TRUE/FALSE/UNDEF") unless exists $map{uc $_};
- $Fallback = $map{uc $_};
+ $self->{Fallback} = $map{uc $_};
}
death ("Error: VERSIONCHECK: ENABLE/DISABLE")
unless /^(ENABLE|DISABLE)/i;
- $WantVersionChk = 1 if $1 eq 'ENABLE';
- $WantVersionChk = 0 if $1 eq 'DISABLE';
+ $self->{WantVersionChk} = 1 if $1 eq 'ENABLE';
+ $self->{WantVersionChk} = 0 if $1 eq 'DISABLE';
}
my $specified;
death("Error: Only 1 PROTOTYPE definition allowed per xsub")
- if $proto_in_this_xsub++;
+ if $self->{proto_in_this_xsub}++;
- for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
+ for (; !/^$self->{BLOCK_re}/o; $_ = shift(@line)) {
next unless /\S/;
$specified = 1;
trim_whitespace($_);
if ($_ eq 'DISABLE') {
- $ProtoThisXSUB = 0;
+ $self->{ProtoThisXSUB} = 0;
}
elsif ($_ eq 'ENABLE') {
- $ProtoThisXSUB = 1;
+ $self->{ProtoThisXSUB} = 1;
}
else {
# remove any whitespace
s/\s+//g;
death("Error: Invalid prototype '$_'")
unless valid_proto_string($_);
- $ProtoThisXSUB = C_string($_);
+ $self->{ProtoThisXSUB} = C_string($_);
}
}
# If no prototype specified, then assume empty prototype ""
- $ProtoThisXSUB = 2 unless $specified;
+ $self->{ProtoThisXSUB} = 2 unless $specified;
- $ProtoUsed = 1;
+ $self->{ProtoUsed} = 1;
}
sub SCOPE_handler () {
death("Error: Only 1 SCOPE declaration allowed per xsub")
- if $scope_in_this_xsub++;
+ if $self->{scope_in_this_xsub}++;
trim_whitespace($_);
death ("Error: SCOPE: ENABLE/DISABLE")
unless /^(ENABLE|DISABLE)\b/i;
- $ScopeThisXSUB = ( uc($1) eq 'ENABLE' );
+ $self->{ScopeThisXSUB} = ( uc($1) eq 'ENABLE' );
}
sub PROTOTYPES_handler () {
death ("Error: PROTOTYPES: ENABLE/DISABLE")
unless /^(ENABLE|DISABLE)/i;
- $WantPrototypes = 1 if $1 eq 'ENABLE';
- $WantPrototypes = 0 if $1 eq 'DISABLE';
- $ProtoUsed = 1;
+ $self->{WantPrototypes} = 1 if $1 eq 'ENABLE';
+ $self->{WantPrototypes} = 0 if $1 eq 'DISABLE';
+ $self->{ProtoUsed} = 1;
+
}
sub PushXSStack {
+ my %args = @_;
# Save the current file context.
push(@XSStack, {
type => 'file',
- LastLine => $lastline,
- LastLineNo => $lastline_no,
+ LastLine => $self->{lastline},
+ LastLineNo => $self->{lastline_no},
Line => \@line,
LineNo => \@line_no,
- Filename => $filename,
- Filepathname => $filepathname,
+ Filename => $self->{filename},
+ Filepathname => $self->{filepathname},
Handle => $FH,
- IsPipe => scalar($filename =~ /\|\s*$/),
+ IsPipe => scalar($self->{filename} =~ /\|\s*$/),
%args,
});
print Q(<<"EOF");
#
-#/* INCLUDE: Including '$_' from '$filename' */
+#/* INCLUDE: Including '$_' from '$self->{filename}' */
#
EOF
- $filename = $_;
- $filepathname = File::Spec->catfile($dir, $filename);
+ $self->{filename} = $_;
+ $self->{filepathname} = File::Spec->catfile($self->{dir}, $self->{filename});
# Prime the pump by reading the first
# non-blank line
last unless /^\s*$/;
}
- $lastline = $_;
- $lastline_no = $.;
+ $self->{lastline} = $_;
+ $self->{lastline_no} = $.;
}
sub QuoteArgs {
print Q(<<"EOF");
#
-#/* INCLUDE_COMMAND: Including output of '$_' from '$filename' */
+#/* INCLUDE_COMMAND: Including output of '$_' from '$self->{filename}' */
#
EOF
- $filename = $_;
- $filepathname = $filename;
- $filepathname =~ s/\"/\\"/g;
+ $self->{filename} = $_;
+ $self->{filepathname} = $self->{filename};
+ $self->{filepathname} =~ s/\"/\\"/g;
# Prime the pump by reading the first
# non-blank line
last unless /^\s*$/;
}
- $lastline = $_;
- $lastline_no = $.;
+ $self->{lastline} = $_;
+ $self->{lastline_no} = $.;
}
sub PopFile() {
return 0 unless $XSStack[-1]{type} eq 'file';
my $data = pop @XSStack;
- my $ThisFile = $filename;
+ my $ThisFile = $self->{filename};
my $isPipe = $data->{IsPipe};
- --$IncludedFiles{$filename}
+ --$IncludedFiles{$self->{filename}}
unless $isPipe;
close $FH;
# $filename is the leafname, which for some reason isused for diagnostic
# messages, whereas $filepathname is the full pathname, and is used for
# #line directives.
- $filename = $data->{Filename};
- $filepathname = $data->{Filepathname};
- $lastline = $data->{LastLine};
- $lastline_no = $data->{LastLineNo};
+ $self->{filename} = $data->{Filename};
+ $self->{filepathname} = $data->{Filepathname};
+ $self->{lastline} = $data->{LastLine};
+ $self->{lastline_no} = $data->{LastLineNo};
@line = @{ $data->{Line} };
@line_no = @{ $data->{LineNo} };
if ($isPipe and $? ) {
- --$lastline_no;
- print STDERR "Error reading from pipe '$ThisFile': $! in $filename, line $lastline_no\n" ;
+ --$self->{lastline_no};
+ print STDERR "Error reading from pipe '$ThisFile': $! in $self->{filename}, line $self->{lastline_no}\n" ;
exit 1;
}
print Q(<<"EOF");
#
-#/* INCLUDE: Returning to '$filename' from '$ThisFile' */
+#/* INCLUDE: Returning to '$self->{filename}' from '$ThisFile' */
#
EOF
return 1;
}
-sub ProtoString ($) {
- my ($type) = @_;
-
- $proto_letter{$type} or "\$";
-}
-
sub check_cpp {
my @cpp = grep(/^\#\s*(?:if|e\w+)/, @line);
if (@cpp) {
sub fetch_para {
# parse paragraph
death ("Error: Unterminated `#if/#ifdef/#ifndef'")
- if !defined $lastline && $XSStack[-1]{type} eq 'if';
+ if !defined $self->{lastline} && $XSStack[-1]{type} eq 'if';
@line = ();
@line_no = ();
- return PopFile() if !defined $lastline;
+ return PopFile() if !defined $self->{lastline};
- if ($lastline =~
+ if ($self->{lastline} =~
/^MODULE\s*=\s*([\w:]+)(?:\s+PACKAGE\s*=\s*([\w:]+))?(?:\s+PREFIX\s*=\s*(\S+))?\s*$/) {
my $Module = $1;
$Package = defined($2) ? $2 : ''; # keep -w happy
- $Prefix = defined($3) ? $3 : ''; # keep -w happy
- $Prefix = quotemeta $Prefix;
+ $self->{Prefix} = defined($3) ? $3 : ''; # keep -w happy
+ $self->{Prefix} = quotemeta $self->{Prefix};
($Module_cname = $Module) =~ s/\W/_/g;
($Packid = $Package) =~ tr/:/_/;
- $Packprefix = $Package;
- $Packprefix .= "::" if $Packprefix ne "";
- $lastline = "";
+ $self->{Packprefix} = $Package;
+ $self->{Packprefix} .= "::" if $self->{Packprefix} ne "";
+ $self->{lastline} = "";
}
for (;;) {
# Skip embedded PODs
- while ($lastline =~ /^=/) {
- while ($lastline = <$FH>) {
- last if ($lastline =~ /^=cut\s*$/);
+ while ($self->{lastline} =~ /^=/) {
+ while ($self->{lastline} = <$FH>) {
+ last if ($self->{lastline} =~ /^=cut\s*$/);
}
- death ("Error: Unterminated pod") unless $lastline;
- $lastline = <$FH>;
- chomp $lastline;
- $lastline =~ s/^\s+$//;
+ death ("Error: Unterminated pod") unless $self->{lastline};
+ $self->{lastline} = <$FH>;
+ chomp $self->{lastline};
+ $self->{lastline} =~ s/^\s+$//;
}
- if ($lastline !~ /^\s*#/ ||
+ if ($self->{lastline} !~ /^\s*#/ ||
# CPP directives:
# ANSI: if ifdef ifndef elif else endif define undef
# line error pragma
# gcc: warning include_next
# obj-c: import
# others: ident (gcc notes that some cpps have this one)
- $lastline =~ /^#[ \t]*(?:(?:if|ifn?def|elif|else|endif|define|undef|pragma|error|warning|line\s+\d+|ident)\b|(?:include(?:_next)?|import)\s*["<].*[>"])/) {
- last if $lastline =~ /^\S/ && @line && $line[-1] eq "";
- push(@line, $lastline);
- push(@line_no, $lastline_no);
+ $self->{lastline} =~ /^#[ \t]*(?:(?:if|ifn?def|elif|else|endif|define|undef|pragma|error|warning|line\s+\d+|ident)\b|(?:include(?:_next)?|import)\s*["<].*[>"])/) {
+ last if $self->{lastline} =~ /^\S/ && @line && $line[-1] eq "";
+ push(@line, $self->{lastline});
+ push(@line_no, $self->{lastline_no});
}
# Read next line and continuation lines
- last unless defined($lastline = <$FH>);
- $lastline_no = $.;
+ last unless defined($self->{lastline} = <$FH>);
+ $self->{lastline_no} = $.;
my $tmp_line;
- $lastline .= $tmp_line
- while ($lastline =~ /\\$/ && defined($tmp_line = <$FH>));
+ $self->{lastline} .= $tmp_line
+ while ($self->{lastline} =~ /\\$/ && defined($tmp_line = <$FH>));
- chomp $lastline;
- $lastline =~ s/^\s+$//;
+ chomp $self->{lastline};
+ $self->{lastline} =~ s/^\s+$//;
}
pop(@line), pop(@line_no) while @line && $line[-1] eq "";
1;
}
sub output_init {
- local($type, $num, $var, $init, $printed_name) = @_;
- local($arg) = "ST(" . ($num - 1) . ")";
+ my $argsref = shift;
+ my ($type, $num, $var, $init, $printed_name) = (
+ $argsref->{type},
+ $argsref->{num},
+ $argsref->{var},
+ $argsref->{init},
+ $argsref->{printed_name}
+ );
+ my $arg = "ST(" . ($num - 1) . ")";
if ( $init =~ /^=/ ) {
if ($printed_name) {
}
else {
if ( $init =~ s/^\+// && $num ) {
- &generate_init($type, $num, $var, $printed_name);
+ generate_init( {
+ type => $type,
+ num => $num,
+ var => $var,
+ printed_name => $printed_name,
+ } );
}
elsif ($printed_name) {
print ";\n";
warn $@ if $@;
$init =~ s/^;//;
}
- $deferred .= eval qq/"\\n\\t$init\\n"/;
+ $self->{deferred} .= eval qq/"\\n\\t$init\\n"/;
warn $@ if $@;
}
}
-sub Warn {
- # work out the line number
- my $warn_line_number = $line_no[@line_no - @line -1];
-
- print STDERR "@_ in $filename, line $warn_line_number\n";
-}
-
-sub blurt {
- Warn @_;
- $errors++
-}
-
-sub death {
- Warn @_;
- exit 1;
-}
-
sub generate_init {
-# local($type, $num, $var) = @_;
-# local($arg) = "ST(" . ($num - 1) . ")";
- my ($type, $num, $var) = @_;
+ my $argsref = shift;
+ my ($type, $num, $var, $printed_name) = (
+ $argsref->{type},
+ $argsref->{num},
+ $argsref->{var},
+ $argsref->{printed_name},
+ );
my $arg = "ST(" . ($num - 1) . ")";
-# local($argoff) = $num - 1;
-# local($ntype);
-# local($tk);
my ($argoff, $ntype, $tk);
$argoff = $num - 1;
if defined $defaults{$var};
return;
}
- $type =~ tr/:/_/ unless $hiertype;
+ $type =~ tr/:/_/ unless $self->{hiertype};
blurt("Error: No INPUT definition for type '$type', typekind '$type_kind{$type}' found"), return
unless defined $input_expr{$tk};
my $expr = $input_expr{$tk};
$expr =~ s/DO_ARRAY_ELEM/$subexpr/;
}
if ($expr =~ m#/\*.*scope.*\*/#i) { # "scope" in C comments
- $ScopeThisXSUB = 1;
+ $self->{ScopeThisXSUB} = 1;
}
if (defined($defaults{$var})) {
$expr =~ s/(\t+)/$1 /g;
}
else {
eval qq/print "\\t$var;\\n"/;
- warn $@ if $@;
+ warn $@ if $@;
}
if ($defaults{$var} eq 'NO_INIT') {
- $deferred .= eval qq/"\\n\\tif (items >= $num) {\\n$expr;\\n\\t}\\n"/;
+ $self->{deferred} .= eval qq/"\\n\\tif (items >= $num) {\\n$expr;\\n\\t}\\n"/;
}
else {
- $deferred .= eval qq/"\\n\\tif (items < $num)\\n\\t $var = $defaults{$var};\\n\\telse {\\n$expr;\\n\\t}\\n"/;
+ $self->{deferred} .= eval qq/"\\n\\tif (items < $num)\\n\\t $var = $defaults{$var};\\n\\telse {\\n$expr;\\n\\t}\\n"/;
}
- warn $@ if $@;
+ warn $@ if $@;
}
- elsif ($ScopeThisXSUB or $expr !~ /^\s*\$var =/) {
+ elsif ($self->{ScopeThisXSUB} or $expr !~ /^\s*\$var =/) {
if ($printed_name) {
print ";\n";
}
else {
eval qq/print "\\t$var;\\n"/;
- warn $@ if $@;
+ warn $@ if $@;
}
- $deferred .= eval qq/"\\n$expr;\\n"/;
- warn $@ if $@;
+ $self->{deferred} .= eval qq/"\\n$expr;\\n"/;
+ warn $@ if $@;
}
else {
die "panic: do not know how to handle this branch for function pointers"
if $printed_name;
eval qq/print "$expr;\\n"/;
- warn $@ if $@;
+ warn $@ if $@;
}
}
sub generate_output {
-# local($type, $num, $var, $do_setmagic, $do_push) = @_;
-# local($arg) = "ST(" . ($num - ($num != 0)) . ")";
- my ($type, $num, $var, $do_setmagic, $do_push) = @_;
+ my $argsref = shift;
+ my ($type, $num, $var, $do_setmagic, $do_push) = (
+ $argsref->{type},
+ $argsref->{num},
+ $argsref->{var},
+ $argsref->{do_setmagic},
+ $argsref->{do_push}
+ );
my $arg = "ST(" . ($num - ($num != 0)) . ")";
-# local($argoff) = $num - 1;
-# local($ntype);
my $ntype;
$type = tidy_type($type);
my $expr = $output_expr{$type_kind{$type}};
if ($expr =~ /DO_ARRAY_ELEM/) {
blurt("Error: '$subtype' not in typemap"), return
- unless defined($type_kind{$subtype});
+ unless defined($type_kind{$subtype});
blurt("Error: No OUTPUT definition for type '$subtype', typekind '$type_kind{$subtype}' found"), return
- unless defined $output_expr{$type_kind{$subtype}};
+ unless defined $output_expr{$type_kind{$subtype}};
my $subexpr = $output_expr{$type_kind{$subtype}};
$subexpr =~ s/ntype/subtype/g;
$subexpr =~ s/\$arg/ST(ix_$var)/g;
$subexpr =~ s/\n\t/\n\t\t/g;
$expr =~ s/DO_ARRAY_ELEM\n/$subexpr/;
eval "print qq\a$expr\a";
- warn $@ if $@;
+ warn $@ if $@;
print "\t\tSvSETMAGIC(ST(ix_$var));\n" if $do_setmagic;
}
elsif ($var eq 'RETVAL') {
# We expect that $arg has refcnt 1, so we need to
# mortalize it.
eval "print qq\a$expr\a";
- warn $@ if $@;
+ warn $@ if $@;
print "\tsv_2mortal(ST($num));\n";
print "\tSvSETMAGIC(ST($num));\n" if $do_setmagic;
}
# We expect that $arg has refcnt >=1, so we need
# to mortalize it!
eval "print qq\a$expr\a";
- warn $@ if $@;
+ warn $@ if $@;
print "\tsv_2mortal(ST(0));\n";
print "\tSvSETMAGIC(ST(0));\n" if $do_setmagic;
}
# works too.
print "\tST(0) = sv_newmortal();\n";
eval "print qq\a$expr\a";
- warn $@ if $@;
+ warn $@ if $@;
# new mortals don't have set magic
}
}
print "\tPUSHs(sv_newmortal());\n";
$arg = "ST($num)";
eval "print qq\a$expr\a";
- warn $@ if $@;
+ warn $@ if $@;
print "\tSvSETMAGIC($arg);\n" if $do_setmagic;
}
elsif ($arg =~ /^ST\(\d+\)$/) {
eval "print qq\a$expr\a";
- warn $@ if $@;
+ warn $@ if $@;
print "\tSvSETMAGIC($arg);\n" if $do_setmagic;
}
}
}
-sub map_type {
- my($type, $varname) = @_;
+sub Warn {
+ # work out the line number
+ my $warn_line_number = $line_no[@line_no - @line -1];
- # C++ has :: in types too so skip this
- $type =~ tr/:/_/ unless $hiertype;
- $type =~ s/^array\(([^,]*),(.*)\).*/$1 */s;
- if ($varname) {
- if ($varname && $type =~ / \( \s* \* (?= \s* \) ) /xg) {
- (substr $type, pos $type, 0) = " $varname ";
- }
- else {
- $type .= "\t$varname";
- }
- }
- $type;
+ print STDERR "@_ in $self->{filename}, line $warn_line_number\n";
+}
+
+sub blurt {
+ Warn @_;
+ $self->{errors}++
+}
+
+sub death {
+ Warn @_;
+ exit 1;
}
1;