{
dTHR;
char *posixcc = 0;
- I32 namedclass = -1;
+ I32 namedclass = OOB_NAMEDCLASS;
if (value == '[' && PL_regcomp_parse + 1 < PL_regxend &&
/* I smell either [: or [= or [. -- POSIX has been here, right? */
STATIC void
S_checkposixcc(pTHX)
{
- if (ckWARN(WARN_UNSAFE) && !SIZE_ONLY &&
+ if (!SIZE_ONLY && ckWARN(WARN_UNSAFE) &&
(*PL_regcomp_parse == ':' ||
*PL_regcomp_parse == '=' ||
*PL_regcomp_parse == '.')) {
S_regclass(pTHX)
{
dTHR;
- register char *opnd, *s;
register I32 value;
register I32 lastvalue = OOB_CHAR8;
register I32 range = 0;
I32 numlen;
I32 namedclass;
char *rangebegin;
+ bool need_class = 0;
- s = opnd = MASK(PL_regcode);
ret = reg_node(ANYOF);
- for (value = 0; value < ANYOF_SIZE; value++)
- REGC(0, s++);
+ if (SIZE_ONLY)
+ PL_regsize += ANYOF_SKIP;
+ else {
+ ret->flags = 0;
+ ANYOF_BITMAP_ZERO(ret);
+ PL_regcode += ANYOF_SKIP;
+ if (FOLD)
+ ANYOF_FLAGS(ret) |= ANYOF_FOLD;
+ if (LOC)
+ ANYOF_FLAGS(ret) |= ANYOF_LOCALE;
+ }
if (*PL_regcomp_parse == '^') { /* Complement of range. */
PL_regnaughty++;
PL_regcomp_parse++;
if (!SIZE_ONLY)
- ANYOF_FLAGS(opnd) |= ANYOF_INVERT;
- }
- if (!SIZE_ONLY) {
- PL_regcode += ANY_SKIP;
- if (FOLD)
- ANYOF_FLAGS(opnd) |= ANYOF_FOLD;
- if (LOC)
- ANYOF_FLAGS(opnd) |= ANYOF_LOCALE;
- }
- else {
- PL_regsize += ANY_SKIP;
+ ANYOF_FLAGS(ret) |= ANYOF_INVERT;
}
- checkposixcc();
+ if (!SIZE_ONLY && ckWARN(WARN_UNSAFE))
+ checkposixcc();
if (*PL_regcomp_parse == ']' || *PL_regcomp_parse == '-')
goto skipcond; /* allow 1st char to be ] or - */
}
}
if (namedclass > OOB_NAMEDCLASS) {
+ if (!need_class && !SIZE_ONLY)
+ ANYOF_CLASS_ZERO(ret);
+ need_class = 1;
if (range) { /* a-\d, a-[:digit:] */
if (!SIZE_ONLY) {
if (ckWARN(WARN_UNSAFE))
PL_regcomp_parse - rangebegin,
PL_regcomp_parse - rangebegin,
rangebegin);
- ANYOF_BITMAP_SET(opnd, lastvalue);
- ANYOF_BITMAP_SET(opnd, '-');
+ ANYOF_BITMAP_SET(ret, lastvalue);
+ ANYOF_BITMAP_SET(ret, '-');
}
range = 0; /* this is not a true range */
}
switch (namedclass) {
case ANYOF_ALNUM:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_ALNUM);
+ ANYOF_CLASS_SET(ret, ANYOF_ALNUM);
else {
for (value = 0; value < 256; value++)
if (isALNUM(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_NALNUM:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NALNUM);
+ ANYOF_CLASS_SET(ret, ANYOF_NALNUM);
else {
for (value = 0; value < 256; value++)
if (!isALNUM(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_SPACE:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_SPACE);
+ ANYOF_CLASS_SET(ret, ANYOF_SPACE);
else {
for (value = 0; value < 256; value++)
if (isSPACE(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_NSPACE:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NSPACE);
+ ANYOF_CLASS_SET(ret, ANYOF_NSPACE);
else {
for (value = 0; value < 256; value++)
if (!isSPACE(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_DIGIT:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_DIGIT);
+ ANYOF_CLASS_SET(ret, ANYOF_DIGIT);
else {
for (value = '0'; value <= '9'; value++)
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_NDIGIT:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NDIGIT);
+ ANYOF_CLASS_SET(ret, ANYOF_NDIGIT);
else {
for (value = 0; value < '0'; value++)
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
for (value = '9' + 1; value < 256; value++)
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_NALNUMC:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NALNUMC);
+ ANYOF_CLASS_SET(ret, ANYOF_NALNUMC);
else {
for (value = 0; value < 256; value++)
if (!isALNUMC(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_ALNUMC:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_ALNUMC);
+ ANYOF_CLASS_SET(ret, ANYOF_ALNUMC);
else {
for (value = 0; value < 256; value++)
if (isALNUMC(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_ALPHA:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_ALPHA);
+ ANYOF_CLASS_SET(ret, ANYOF_ALPHA);
else {
for (value = 0; value < 256; value++)
if (isALPHA(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_NALPHA:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NALPHA);
+ ANYOF_CLASS_SET(ret, ANYOF_NALPHA);
else {
for (value = 0; value < 256; value++)
if (!isALPHA(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_ASCII:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_ASCII);
+ ANYOF_CLASS_SET(ret, ANYOF_ASCII);
else {
for (value = 0; value < 128; value++)
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_NASCII:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NASCII);
+ ANYOF_CLASS_SET(ret, ANYOF_NASCII);
else {
for (value = 128; value < 256; value++)
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_CNTRL:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_CNTRL);
+ ANYOF_CLASS_SET(ret, ANYOF_CNTRL);
else {
for (value = 0; value < 256; value++)
if (isCNTRL(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
lastvalue = OOB_CHAR8;
break;
case ANYOF_NCNTRL:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NCNTRL);
+ ANYOF_CLASS_SET(ret, ANYOF_NCNTRL);
else {
for (value = 0; value < 256; value++)
if (!isCNTRL(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_GRAPH:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_GRAPH);
+ ANYOF_CLASS_SET(ret, ANYOF_GRAPH);
else {
for (value = 0; value < 256; value++)
if (isGRAPH(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_NGRAPH:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NGRAPH);
+ ANYOF_CLASS_SET(ret, ANYOF_NGRAPH);
else {
for (value = 0; value < 256; value++)
if (!isGRAPH(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_LOWER:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_LOWER);
+ ANYOF_CLASS_SET(ret, ANYOF_LOWER);
else {
for (value = 0; value < 256; value++)
if (isLOWER(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_NLOWER:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NLOWER);
+ ANYOF_CLASS_SET(ret, ANYOF_NLOWER);
else {
for (value = 0; value < 256; value++)
if (!isLOWER(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_PRINT:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_PRINT);
+ ANYOF_CLASS_SET(ret, ANYOF_PRINT);
else {
for (value = 0; value < 256; value++)
if (isPRINT(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_NPRINT:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NPRINT);
+ ANYOF_CLASS_SET(ret, ANYOF_NPRINT);
else {
for (value = 0; value < 256; value++)
if (!isPRINT(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_PUNCT:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_PUNCT);
+ ANYOF_CLASS_SET(ret, ANYOF_PUNCT);
else {
for (value = 0; value < 256; value++)
if (isPUNCT(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_NPUNCT:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NPUNCT);
+ ANYOF_CLASS_SET(ret, ANYOF_NPUNCT);
else {
for (value = 0; value < 256; value++)
if (!isPUNCT(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_UPPER:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_UPPER);
+ ANYOF_CLASS_SET(ret, ANYOF_UPPER);
else {
for (value = 0; value < 256; value++)
if (isUPPER(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_NUPPER:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NUPPER);
+ ANYOF_CLASS_SET(ret, ANYOF_NUPPER);
else {
for (value = 0; value < 256; value++)
if (!isUPPER(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_XDIGIT:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_XDIGIT);
+ ANYOF_CLASS_SET(ret, ANYOF_XDIGIT);
else {
for (value = 0; value < 256; value++)
if (isXDIGIT(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
case ANYOF_NXDIGIT:
if (LOC)
- ANYOF_CLASS_SET(opnd, ANYOF_NXDIGIT);
+ ANYOF_CLASS_SET(ret, ANYOF_NXDIGIT);
else {
for (value = 0; value < 256; value++)
if (!isXDIGIT(value))
- ANYOF_BITMAP_SET(opnd, value);
+ ANYOF_BITMAP_SET(ret, value);
}
break;
default:
break;
}
if (LOC)
- ANYOF_FLAGS(opnd) |= ANYOF_CLASS;
+ ANYOF_FLAGS(ret) |= ANYOF_CLASS;
continue;
}
}
PL_regcomp_parse - rangebegin,
rangebegin);
if (!SIZE_ONLY)
- ANYOF_BITMAP_SET(opnd, '-');
+ ANYOF_BITMAP_SET(ret, '-');
} else
range = 1;
continue; /* do it next time */
if (isLOWER(lastvalue)) {
for (i = lastvalue; i <= value; i++)
if (isLOWER(i))
- ANYOF_BITMAP_SET(opnd, i);
+ ANYOF_BITMAP_SET(ret, i);
} else {
for (i = lastvalue; i <= value; i++)
if (isUPPER(i))
- ANYOF_BITMAP_SET(opnd, i);
+ ANYOF_BITMAP_SET(ret, i);
}
}
else
#endif
for ( ; lastvalue <= value; lastvalue++)
- ANYOF_BITMAP_SET(opnd, lastvalue);
+ ANYOF_BITMAP_SET(ret, lastvalue);
}
range = 0;
}
+ if (need_class) {
+ if (SIZE_ONLY)
+ PL_regsize += ANYOF_CLASS_ADD_SKIP;
+ else
+ PL_regcode += ANYOF_CLASS_ADD_SKIP;
+ }
/* optimize case-insensitive simple patterns (e.g. /[a-z]/i) */
if (!SIZE_ONLY &&
- (ANYOF_FLAGS(opnd) & (ANYOF_FLAGS_ALL ^ ANYOF_INVERT)) == ANYOF_FOLD) {
+ (ANYOF_FLAGS(ret) & (ANYOF_FLAGS_ALL ^ ANYOF_INVERT)) == ANYOF_FOLD) {
for (value = 0; value < 256; ++value) {
- if (ANYOF_BITMAP_TEST(opnd, value)) {
+ if (ANYOF_BITMAP_TEST(ret, value)) {
I32 cf = PL_fold[value];
- ANYOF_BITMAP_SET(opnd, cf);
+ ANYOF_BITMAP_SET(ret, cf);
}
}
- ANYOF_FLAGS(opnd) &= ~ANYOF_FOLD;
+ ANYOF_FLAGS(ret) &= ~ANYOF_FOLD;
}
/* optimize inverted simple patterns (e.g. [^a-z]) */
- if (!SIZE_ONLY && (ANYOF_FLAGS(opnd) & ANYOF_FLAGS_ALL) == ANYOF_INVERT) {
+ if (!SIZE_ONLY && (ANYOF_FLAGS(ret) & ANYOF_FLAGS_ALL) == ANYOF_INVERT) {
for (value = 0; value < ANYOF_BITMAP_SIZE; ++value)
- opnd[ANYOF_BITMAP_OFFSET + value] ^= ANYOF_FLAGS_ALL;
- ANYOF_FLAGS(opnd) = 0;
+ ANYOF_BITMAP(ret)[value] ^= ANYOF_FLAGS_ALL;
+ ANYOF_FLAGS(ret) = 0;
}
return ret;
}
S_regclassutf8(pTHX)
{
dTHR;
- register char *opnd, *e;
+ register char *e;
register U32 value;
register U32 lastvalue = OOB_UTF8;
register I32 range = 0;
listsv = newSVpvn("# comment\n",10);
}
- checkposixcc();
+ if (!SIZE_ONLY && ckWARN(WARN_UNSAFE))
+ checkposixcc();
if (*PL_regcomp_parse == ']' || *PL_regcomp_parse == '-')
goto skipcond; /* allow 1st char to be ] or - */
}
else if (op == ANYOF) {
node = NEXTOPER(node);
- node += ANY_SKIP;
+ node += ANYOF_SKIP;
}
else if (PL_regkind[(U8)op] == EXACT) {
/* Literal string, where present. */
U16 arg2;
};
+#define ANYOF_BITMAP_SIZE 32 /* 256 b/(8 b/B) */
+#define ANYOF_CLASSBITMAP_SIZE 4
+
+struct regnode_charclass {
+ U8 flags;
+ U8 type;
+ U16 next_off;
+ char bitmap[ANYOF_BITMAP_SIZE];
+};
+
+struct regnode_charclass_class {
+ U8 flags;
+ U8 type;
+ U16 next_off;
+ char bitmap[ANYOF_BITMAP_SIZE];
+ char classflags[ANYOF_CLASSBITMAP_SIZE];
+};
+
/* XXX fix this description.
Impose a limit of REG_INFTY on various pattern matching operations
to limit stack growth and to avoid "infinite" recursions.
#define SIZE_ONLY (PL_regcode == &PL_regdummy)
-/* Flags for first parameter byte [0] of ANYOF */
+/* Flags for node->flags of ANYOF */
#define ANYOF_CLASS 0x08
#define ANYOF_INVERT 0x04
#define ANYOF_FOLD 0x02
#define ANYOF_LOCALE 0x01
-/* Character classes for bytes [1..4] of ANYOF */
+/* Character classes for node->classflags of ANYOF */
#define ANYOF_ALNUM 0 /* \w, utf8::IsWord, isALNUM() */
#define ANYOF_NALNUM 1
/* Utility macros for the bitmap and classes of ANYOF */
-#define ANYOF_OPND_SIZE 1
-#define ANYOF_CLASS_SIZE 4
-#define ANYOF_BITMAP_SIZE 32 /* 256 b/(8 b/B) */
-#define ANYOF_SIZE (ANYOF_OPND_SIZE+ANYOF_CLASS_SIZE+ANYOF_BITMAP_SIZE)
+#define ANYOF_SIZE (sizeof(struct regnode_charclass))
+#define ANYOF_CLASS_SIZE (sizeof(struct regnode_charclass_class))
-#define ANYOF_FLAGS(p) ((p)[0])
+#define ANYOF_FLAGS(p) ((p)->flags)
#define ANYOF_FLAGS_ALL 0xff
#define ANYOF_BIT(c) (1 << ((c) & 7))
-#define ANYOF_CLASS_OFFSET ANYOF_OPND_SIZE
-#define ANYOF_CLASS_BYTE(p, c) ((p)[ANYOF_CLASS_OFFSET + (((c) >> 3) & 3)])
+#define ANYOF_CLASS_BYTE(p, c) (((struct regnode_charclass_class*)(p))->classflags[((c) >> 3) & 3])
#define ANYOF_CLASS_SET(p, c) (ANYOF_CLASS_BYTE(p, c) |= ANYOF_BIT(c))
#define ANYOF_CLASS_CLEAR(p, c) (ANYOF_CLASS_BYTE(p, c) &= ~ANYOF_BIT(c))
#define ANYOF_CLASS_TEST(p, c) (ANYOF_CLASS_BYTE(p, c) & ANYOF_BIT(c))
-#define ANYOF_BITMAP_OFFSET (ANYOF_CLASS_OFFSET+ANYOF_CLASS_SIZE)
-#define ANYOF_BITMAP_BYTE(p, c) ((p)[ANYOF_BITMAP_OFFSET + (((c) >> 3) & 31)])
+#define ANYOF_CLASS_ZERO(ret) Zero(((struct regnode_charclass_class*)(ret))->classflags, ANYOF_CLASSBITMAP_SIZE, char)
+#define ANYOF_BITMAP_ZERO(ret) Zero(((struct regnode_charclass*)(ret))->bitmap, ANYOF_BITMAP_SIZE, char)
+
+#define ANYOF_BITMAP(p) (((struct regnode_charclass*)(p))->bitmap)
+#define ANYOF_BITMAP_BYTE(p, c) (ANYOF_BITMAP(p)[((c) >> 3) & 31])
#define ANYOF_BITMAP_SET(p, c) (ANYOF_BITMAP_BYTE(p, c) |= ANYOF_BIT(c))
#define ANYOF_BITMAP_CLEAR(p,c) (ANYOF_BITMAP_BYTE(p, c) &= ~ANYOF_BIT(c))
#define ANYOF_BITMAP_TEST(p, c) (ANYOF_BITMAP_BYTE(p, c) & ANYOF_BIT(c))
-#define ANY_SKIP ((ANYOF_SIZE - 1)/sizeof(regnode) + 1)
+#define ANYOF_SKIP ((ANYOF_SIZE - 1)/sizeof(regnode))
+#define ANYOF_CLASS_SKIP ((ANYOF_CLASS_SIZE - 1)/sizeof(regnode))
+#define ANYOF_CLASS_ADD_SKIP (ANYOF_CLASS_SKIP - ANYOF_SKIP)
/*
* Utility definitions.