From: Nicholas Clark Date: Wed, 17 Mar 2010 13:33:48 +0000 (+0000) Subject: Generate PL_simple[] and PL_varies[] with regcomp.pl, rather than hard-coding. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f9ef50a71935a8e93b4030c12dcd1206ccab71ab;p=p5sagit%2Fp5-mst-13.2.git Generate PL_simple[] and PL_varies[] with regcomp.pl, rather than hard-coding. Add a new flags column to regcomp.sym, with V if the node type is in PL_varies, S if it is in PL_simple, and . if a placeholder is needed because subsequent optional columns are present. --- diff --git a/regcomp.h b/regcomp.h index a20d6e1..ad9a2cc 100644 --- a/regcomp.h +++ b/regcomp.h @@ -447,37 +447,6 @@ START_EXTERN_C #include "regnodes.h" #endif -/* The following have no fixed length. U8 so we can do strchr() on it. */ -#ifndef DOINIT -EXTCONST U8 PL_varies[]; -#else -EXTCONST U8 PL_varies[] = { - BRANCH, BACK, STAR, PLUS, CURLY, CURLYX, REF, REFF, REFFL, - WHILEM, CURLYM, CURLYN, BRANCHJ, IFTHEN, SUSPEND, CLUMP, - NREF, NREFF, NREFFL, - 0 -}; -#endif - -/* The following always have a length of 1. U8 we can do strchr() on it. */ -/* (Note that length 1 means "one character" under UTF8, not "one octet".) */ -#ifndef DOINIT -EXTCONST U8 PL_simple[]; -#else -EXTCONST U8 PL_simple[] = { - REG_ANY, SANY, CANY, - ANYOF, - ALNUM, ALNUML, - NALNUM, NALNUML, - SPACE, SPACEL, - NSPACE, NSPACEL, - DIGIT, NDIGIT, - VERTWS, NVERTWS, - HORIZWS, NHORIZWS, - 0 -}; -#endif - #ifndef PLUGGABLE_RE_EXTENSION #ifndef DOINIT EXTCONST regexp_engine PL_core_reg_engine; diff --git a/regcomp.pl b/regcomp.pl index 2fbe6c6..0c63b94 100644 --- a/regcomp.pl +++ b/regcomp.pl @@ -24,7 +24,7 @@ use warnings; open DESC, 'regcomp.sym'; my $ind = 0; -my (@name,@rest,@type,@code,@args,@longj); +my (@name,@rest,@type,@code,@args,@flags,@longj); my ($desc,$lastregop); while () { s/#.*$//; @@ -37,8 +37,8 @@ while () { unless ($lastregop) { $ind++; ($name[$ind], $desc, $rest[$ind]) = /^(\S+)\s+([^\t]+)\s*;\s*(.*)/; - ($type[$ind], $code[$ind], $args[$ind], $longj[$ind]) - = split /[,\s]\s*/, $desc, 4; + ($type[$ind], $code[$ind], $args[$ind], $flags[$ind], $longj[$ind]) + = split /[,\s]\s*/, $desc; } else { my ($type,@lists)=split /\s+/, $_; die "No list? $type" if !@lists; @@ -79,6 +79,29 @@ close DESC; die "Too many regexp/state opcodes! Maximum is 256, but there are $lastregop in file!" if $lastregop>256; +sub process_flags { + my ($flag, $varname, $comment) = @_; + $comment = '' unless defined $comment; + + $ind = 0; + my @selected; + while (++$ind <= $lastregop) { + push @selected, $name[$ind] if $flags[$ind] && $flags[$ind] eq $flag; + } + my $out_string = join ', ', @selected, 0; + $out_string =~ s/(.{1,70},) /$1\n /g; + return $comment . <<"EOP"; +#ifndef DOINIT +EXTCONST U8 PL_${varname}[]; +#else +EXTCONST U8 PL_${varname}[] = { + $out_string +}; +#endif /* DOINIT */ + +EOP +} + my $tmp_h = 'regnodes.h-new'; unlink $tmp_h if -f $tmp_h; @@ -236,6 +259,18 @@ print $out <