delta += (minnext + deltanext) * maxcount - minnext * mincount;
/* Try powerful optimization CURLYX => CURLYN. */
-#ifdef REGALIGN_STRUCT
if ( OP(oscan) == CURLYX && data
&& data->flags & SF_IN_PAR
&& !(data->flags & SF_HAS_EVAL)
NEXT_OFF(nxt+ 1) = 0; /* just for consistancy. */
#endif
}
-#endif
nogo:
/* Try optimization CURLYX => CURLYM. */
if ( OP(oscan) == CURLYX && data
-#ifdef REGALIGN_STRUCT
&& !(data->flags & SF_HAS_PAR)
-#else
- && !(data->flags & (SF_HAS_PAR|SF_IN_PAR))
-#endif
&& !(data->flags & SF_HAS_EVAL)
&& !deltanext ) {
/* XXXX How to optimize if data == 0? */
&& (OP(nxt2) != WHILEM))
nxt = nxt2;
OP(nxt2) = SUCCEED; /* Whas WHILEM */
-#ifdef REGALIGN_STRUCT
/* Need to optimize away parenths. */
if (data->flags & SF_IN_PAR) {
/* Set the parenth number. */
study_chunk(&nxt1, &deltanext, nxt, NULL, 0);
} else
oscan->flags = 0;
-#endif
}
if (data && fl & (SF_HAS_PAR|SF_IN_PAR))
pars++;
if (data && (fl & SF_HAS_EVAL))
data->flags |= SF_HAS_EVAL;
optimize_curly_tail:
-#ifdef REGALIGN
if (OP(oscan) != CURLYX) {
while (regkind[(U8)OP(next = regnext(oscan))] == NOTHING
&& NEXT_OFF(next))
NEXT_OFF(oscan) += NEXT_OFF(next);
}
-#endif
continue;
default: /* REF only? */
if (flags & SCF_DO_SUBSTR) {
} else if (OP(scan) == OPEN) {
pars++;
} else if (OP(scan) == CLOSE && ARG(scan) == is_par) {
-#ifdef REGALIGN_STRUCT
next = regnext(scan);
if ( next && (OP(next) != WHILEM) && next < last)
-#endif
is_par = 0; /* Disable optimization */
} else if (OP(scan) == EVAL) {
if (data)
/* Small enough for pointer-storage convention?
If extralen==0, this means that we will not need long jumps. */
-#ifndef REGALIGN_STRUCT
- if (regsize >= 0x10000L && extralen)
- FAIL("regexp too big");
-#else
if (regsize >= 0x10000L && extralen)
regsize += extralen;
else
extralen = 0;
-#endif
/* Allocate space and initialize. */
Newc(1001, r, sizeof(regexp) + (unsigned)regsize * sizeof(regnode),
ret = NULL; /* For look-ahead/behind. */
switch (paren) {
case '<':
-#ifndef REGALIGN_STRUCT
- FAIL("lookbehind non-implemented without REGALIGN_STRUCT");
-#endif
regseen |= REG_SEEN_LOOKBEHIND;
if (*regcomp_parse == '!')
paren = ',';
if (paren == '>')
node = SUSPEND, flag = 0;
reginsert(node,ret);
-#ifdef REGALIGN_STRUCT
ret->flags = flag;
-#endif
regtail(ret, reg_node(TAIL));
}
}
if (SIZE_ONLY)
extralen += 3;
}
-#ifdef REGALIGN_STRUCT
ret->flags = 0;
-#endif
if (min > 0)
*flagp = (WORST|HASWIDTH);
if (op == '*' && (flags&SIMPLE)) {
reginsert(STAR, ret);
-#ifdef REGALIGN_STRUCT
ret->flags = 0;
-#endif
regnaughty += 4;
}
else if (op == '*') {
goto do_curly;
} else if (op == '+' && (flags&SIMPLE)) {
reginsert(PLUS, ret);
-#ifdef REGALIGN_STRUCT
ret->flags = 0;
-#endif
regnaughty += 3;
}
else if (op == '+') {
if (*regcomp_parse == '?') {
nextchar();
reginsert(MINMOD, ret);
-#ifdef REGALIGN
regtail(ret, ret + NODE_STEP_REGNODE);
-#else
- regtail(ret, ret + 3);
-#endif
}
if (ISMULT2(regcomp_parse))
FAIL("nested *?+ in regexp");
*OPERAND(ret) = len;
regc('\0', s++);
if (SIZE_ONLY) {
-#ifdef REGALIGN_STRUCT
regsize += (len + 2 + sizeof(regnode) - 1) / sizeof(regnode);
-#endif
} else {
regcode += (len + 2 + sizeof(regnode) - 1) / sizeof(regnode);
}
ret = regcode;
if (SIZE_ONLY) {
SIZE_ALIGN(regsize);
-#ifdef REGALIGN_STRUCT
regsize += 1;
-#else
- regsize += 3;
-#endif
return(ret);
}
ret = regcode;
if (SIZE_ONLY) {
SIZE_ALIGN(regsize);
-#ifdef REGALIGN
regsize += 2;
-#else
- regsize += 5;
-#endif
return(ret);
}
src = NEXTOPER(place);
FILL_ADVANCE_NODE(place, op);
Zero(src, offset, regnode);
-#if defined(REGALIGN) && !defined(REGALIGN_STRUCT)
- src[offset + 1] = '\177';
-#endif
}
/*
scan = temp;
}
-#ifdef REGALIGN
-# ifdef REGALIGN_STRUCT
if (reg_off_by_arg[OP(scan)]) {
ARG_SET(scan, val - scan);
} else {
NEXT_OFF(scan) = val - scan;
}
-# else
- offset = val - scan;
-# ifndef lint
- *(short*)(scan+1) = offset;
-# endif
-#endif
-#else
- if (OP(scan) == BACK)
- offset = scan - val;
- else
- offset = val - scan;
- *(scan+1) = (offset>>8)&0377;
- *(scan+2) = offset&0377;
-#endif
}
/*
sv_catpvf(sv, "CURLY {%d,%d}", ARG1(o), ARG2(o));
break;
case CURLYM:
-#ifdef REGALIGN_STRUCT
sv_catpvf(sv, "CURLYM[%d] {%d,%d}", o->flags, ARG1(o), ARG2(o));
-#else
- sv_catpvf(sv, "CURLYM {%d,%d}", ARG1(o), ARG2(o));
-#endif
break;
case CURLYN:
-#ifdef REGALIGN_STRUCT
sv_catpvf(sv, "CURLYN[%d] {%d,%d}", o->flags, ARG1(o), ARG2(o));
-#else
- sv_catpvf(sv, "CURLYN {%d,%d}", ARG1(o), ARG2(o));
-#endif
break;
case CURLYX:
sv_catpvf(sv, "CURLYX {%d,%d}", ARG1(o), ARG2(o));
p = "GPOS";
break;
case UNLESSM:
-#ifdef REGALIGN_STRUCT
sv_catpvf(sv, "UNLESSM[-%d]", o->flags);
-#else
- p = "UNLESSM";
-#endif
break;
case IFMATCH:
-#ifdef REGALIGN_STRUCT
sv_catpvf(sv, "IFMATCH[-%d]", o->flags);
-#else
- p = "IFMATCH";
-#endif
break;
case SUCCEED:
p = "SUCCEED";
if (offset == 0)
return(NULL);
-#ifdef REGALIGN
return(p+offset);
-#else
- if (OP(p) == BACK)
- return(p-offset);
- else
- return(p+offset);
-#endif
}
STATIC void
* For instance, /[a-z].foo/ has a regmust of 'foo' and a regback of 2.]
*/
-/* #ifndef gould */
-/* #ifndef cray */
-/* #ifndef eta10 */
-#define REGALIGN
-/* #endif */
-/* #endif */
-/* #endif */
-
-#ifdef REGALIGN
-# define REGALIGN_STRUCT
-#endif
-
/*
* Structure for regexp "program". This is essentially a linear encoding
* of a nondeterministic finite-state machine (aka syntax charts or
#define REFF 46 /* num Match already matched string, folded */
#define REFFL 47 /* num Match already matched string, folded in loc. */
#define EVAL 48 /* evl Execute some Perl code. */
-#define LONGJMP 49 /* off Jump far away, requires REGALIGN_STRUCT. */
-#define BRANCHJ 50 /* off BRANCH with long offset, requires REGALIGN_STRUCT. */
+#define LONGJMP 49 /* off Jump far away. */
+#define BRANCHJ 50 /* off BRANCH with long offset. */
#define IFTHEN 51 /* off Switch, should be preceeded by switcher . */
#define GROUPP 52 /* num Whether the group matched. */
#define LOGICAL 53 /* no Next opcode should set the flag only. */
* Using two bytes for the "next" pointer is vast overkill for most things,
* but allows patterns to get big without disasters.
*
- * [If REGALIGN is defined, the "next" pointer is always aligned on an even
+ * [The "next" pointer is always aligned on an even
* boundary, and reads the offset directly as a short. Also, there is no
* special test to reverse the sign of BACK pointers since the offset is
* stored negative.]
*/
-#ifdef REGALIGN_STRUCT
-
struct regnode_string {
U8 flags;
U8 type;
U16 arg2;
};
-#endif
-
/* 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 REG_INFTY I16_MAX
#endif
-#ifdef REGALIGN
-# define ARG_VALUE(arg) (arg)
-# define ARG__SET(arg,val) ((arg) = (val))
-#else
-# define ARG_VALUE(arg) (((*((char*)&arg)&0377)<<8) + (*(((char*)&arg)+1)&0377))
-# define ARG__SET(arg,val) (((char*)&arg)[0] = (val) >> 8; ((char*)&arg)[1] = (val) & 0377;)
-#endif
+#define ARG_VALUE(arg) (arg)
+#define ARG__SET(arg,val) ((arg) = (val))
#define ARG(p) ARG_VALUE(ARG_LOC(p))
#define ARG1(p) ARG_VALUE(ARG1_LOC(p))
#define ARG2_SET(p, val) ARG__SET(ARG2_LOC(p), (val))
#ifndef lint
-# ifdef REGALIGN
-# ifdef REGALIGN_STRUCT
-# define NEXT_OFF(p) ((p)->next_off)
-# define NODE_ALIGN(node)
-# define NODE_ALIGN_FILL(node) ((node)->flags = 0xde) /* deadbeef */
-# else
-# define NEXT_OFF(p) (*(short*)(p+1))
-# define NODE_ALIGN(node) ((!((long)node & 1)) ? node++ : 0)
-# define NODE_ALIGN_FILL(node) ((!((long)node & 1)) ? *node++ = 127 : 0)
-# endif
-# else
-# define NEXT_OFF(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))
-# define NODE_ALIGN(node)
-# define NODE_ALIGN_FILL(node)
-# endif
+# define NEXT_OFF(p) ((p)->next_off)
+# define NODE_ALIGN(node)
+# define NODE_ALIGN_FILL(node) ((node)->flags = 0xde) /* deadbeef */
#else /* lint */
# define NEXT_OFF(p) 0
-# define NODE_ALIGN(node)
-# define NODE_ALIGN_FILL(node)
+# define NODE_ALIGN(node)
+# define NODE_ALIGN_FILL(node)
#endif /* lint */
#define SIZE_ALIGN NODE_ALIGN
-#ifdef REGALIGN_STRUCT
-# define OP(p) ((p)->type)
-# define OPERAND(p) (((struct regnode_string *)p)->string)
-# define NODE_ALIGN(node)
-# define ARG_LOC(p) (((struct regnode_1 *)p)->arg1)
-# define ARG1_LOC(p) (((struct regnode_2 *)p)->arg1)
-# define ARG2_LOC(p) (((struct regnode_2 *)p)->arg2)
-# define NODE_STEP_REGNODE 1 /* sizeof(regnode)/sizeof(regnode) */
-# define EXTRA_STEP_2ARGS EXTRA_SIZE(struct regnode_2)
-#else
-# define OP(p) (*(p))
-# define OPERAND(p) ((p) + 3)
-# define ARG_LOC(p) (*(unsigned short*)(p+3))
-# define ARG1_LOC(p) (*(unsigned short*)(p+3))
-# define ARG2_LOC(p) (*(unsigned short*)(p+5))
-typedef char* regnode;
-# define NODE_STEP_REGNODE NODE_STEP_B
-# define EXTRA_STEP_2ARGS 4
-#endif
-
-#ifdef REGALIGN
-# define NODE_STEP_B 4
-#else
-# define NODE_STEP_B 3
-#endif
+#define OP(p) ((p)->type)
+#define OPERAND(p) (((struct regnode_string *)p)->string)
+#define NODE_ALIGN(node)
+#define ARG_LOC(p) (((struct regnode_1 *)p)->arg1)
+#define ARG1_LOC(p) (((struct regnode_2 *)p)->arg1)
+#define ARG2_LOC(p) (((struct regnode_2 *)p)->arg2)
+#define NODE_STEP_REGNODE 1 /* sizeof(regnode)/sizeof(regnode) */
+#define EXTRA_STEP_2ARGS EXTRA_SIZE(struct regnode_2)
+
+#define NODE_STEP_B 4
#define NEXTOPER(p) ((p) + NODE_STEP_REGNODE)
#define PREVOPER(p) ((p) - NODE_STEP_REGNODE)
-#ifdef REGALIGN_STRUCT
-# define FILL_ADVANCE_NODE(ptr, op) STMT_START { \
+#define FILL_ADVANCE_NODE(ptr, op) STMT_START { \
(ptr)->type = op; (ptr)->next_off = 0; (ptr)++; } STMT_END
-# define FILL_ADVANCE_NODE_ARG(ptr, op, arg) STMT_START { \
+#define FILL_ADVANCE_NODE_ARG(ptr, op, arg) STMT_START { \
ARG_SET(ptr, arg); FILL_ADVANCE_NODE(ptr, op); (ptr) += 1; } STMT_END
-#else
-# define FILL_ADVANCE_NODE(ptr, op) STMT_START { \
- *(ptr)++ = op; *(ptr)++ = '\0'; *(ptr)++ = '\0'; } STMT_END
-# define FILL_ADVANCE_NODE_ARG(ptr, op, arg) STMT_START { \
- ARG_SET(ptr, arg); FILL_ADVANCE_NODE(ptr, op); (ptr) += 2; } STMT_END
-#endif
#define MAGIC 0234
#define ANYOF_CLEAR(p,c) (ANYOF_BYTE(p,c) &= ~ANYOF_BIT(c))
#define ANYOF_TEST(p,c) (ANYOF_BYTE(p,c) & ANYOF_BIT(c))
-#ifdef REGALIGN_STRUCT
#define ANY_SKIP ((33 - 1)/sizeof(regnode) + 1)
-#else
-#define ANY_SKIP 32 /* overwrite the first byte of
- * the next guy. */
-#endif
/*
* Utility definitions.
#ifdef REG_COMP_C
const static U8 regarglen[] = {
-# ifdef REGALIGN_STRUCT
0,0,0,0,0,0,0,0,0,0,
/*CURLY*/ EXTRA_SIZE(struct regnode_2),
/*CURLYX*/ EXTRA_SIZE(struct regnode_2),
/*LOGICAL*/ 0,
/*SUSPEND*/ EXTRA_SIZE(struct regnode_1),
/*RENUM*/ EXTRA_SIZE(struct regnode_1), 0,
-# else
- 0,0,0,0,0,0,0,0,0,0,
- /*CURLY*/ 4, /*CURLYX*/ 4,
- 0,0,0,0,0,0,0,0,0,0,0,0,
- /*REF*/ 2, /*OPEN*/ 2, /*CLOSE*/ 2,
- 0,0, /*IFMATCH*/ 2, /*UNLESSM*/ 2,
- 0,0,0,0,0,0,0,0,0,0,0,0,/*CURLYM*/ 4,/*CURLYN*/ 4,
- 0, /*REFF*/ 2, /*REFFL*/ 2, /*EVAL*/ 2, /*LONGJMP*/ 2, /*BRANCHJ*/ 2,
- /*IFTHEN*/ 2, /*GROUPP*/ 2, /*LOGICAL*/ 0, /*RENUM*/ 2, /*RENUM*/ 2, 0,
-# endif
};
const static char reg_off_by_arg[] = {