Use bit instead of node for regex SSC
authorKarl Williamson <public@khwilliamson.com>
Mon, 13 Jan 2014 06:39:43 +0000 (23:39 -0700)
committerKarl Williamson <public@khwilliamson.com>
Wed, 22 Jan 2014 18:45:56 +0000 (11:45 -0700)
commit710680787cad21825395c0224606ac1535624c52
treec4f06a3bbc9eaa17894e69081b84b73c4baea6f0
parentbeab9ebe349dffa8fc22a2912b83f62d2365e594
Use bit instead of node for regex SSC

The flag bits in regular expression ANYOF nodes are perennially in short
supply.  However there are still plenty of regex nodes possible.  So one
solution to needing to pass more information is to create a node that
encapsulates what is needed.  That is what commit
9aa1e39f96ac28f6ce5d814d9a1eccf1464aba4a did to tell regexec.c that a
particular ANYOF node is for the synthetic start class (SSC).  However
this solution introduces other issues.  If you have to express two
things, then you need a regnode for A, a regnode for B, a regnode for
both A and B, and another regnode for both not A nor B;  With three
things, you need 8 regnodes to express all possible combinations.  This
becomes unwieldy to write code for.  The number of combinations goes way
down if some of them are mutually exclusive.  At the time of that
commit, I thought that a SSC need not ever warn if matching against an
above-Unicode code point.  I was wrong, and that has been corrected
earlier in the 5.19 series.

But it finally came to me how to tell regexec that an ANYOF node is
for the SSC without taking up a flag bit and without requiring a regnode
type.  The 'next_off' field in a regnode tells the engine the offeset in
the regex program to the node it's supposed to go to after processing
this one.  Since the SSC stands alone, its 'next_off' field is unused,
and we can put anything we want in it.  That, however, is not true of
other ANYOF regnodes.  But it turns out that there are certain values
that will never be legitimate in the 'next_off' field in these, and so
this commit uses one of those to signal that this ANYOF field is an SSC.
regnodes come in various sizes, and the offset is in terms of how many
of the smallest ones are there to the next node to look at.  Since ANYOF
nodes are large, the offset is always > 1, and so this commit uses 1 to
indicate an SSC.
pod/perldebguts.pod
regcomp.c
regcomp.h
regcomp.sym
regexec.c
regnodes.h