remove classnot from main switch
This commit is contained in:
30
pike.c
30
pike.c
@@ -79,7 +79,6 @@ enum /* rinst.opcode */
|
|||||||
CHAR = 1,
|
CHAR = 1,
|
||||||
ANY,
|
ANY,
|
||||||
CLASS,
|
CLASS,
|
||||||
CLASSNOT,
|
|
||||||
NAMEDCLASS,
|
NAMEDCLASS,
|
||||||
// Assert position
|
// Assert position
|
||||||
BOL,
|
BOL,
|
||||||
@@ -180,8 +179,8 @@ void decref(rsub *s)
|
|||||||
|
|
||||||
int re_classmatch(const int *pc, const char *sp)
|
int re_classmatch(const int *pc, const char *sp)
|
||||||
{
|
{
|
||||||
// pc points to "cnt" byte after opcode
|
// pc points to "classnot" byte after opcode
|
||||||
int is_positive = (pc[-1] == CLASS);
|
int is_positive = *pc++;
|
||||||
int cnt = *pc++, c;
|
int cnt = *pc++, c;
|
||||||
uc_code(c, sp)
|
uc_code(c, sp)
|
||||||
while (cnt--) {
|
while (cnt--) {
|
||||||
@@ -238,11 +237,10 @@ void re_dumpcode(rcode *prog)
|
|||||||
case ANY:
|
case ANY:
|
||||||
printf("any\n");
|
printf("any\n");
|
||||||
break;
|
break;
|
||||||
case CLASS:
|
case CLASS:;
|
||||||
case CLASSNOT:;
|
pc += 2;
|
||||||
int num = code[pc];
|
int num = code[pc - 1];
|
||||||
printf("class%s %d", (code[pc - 1] == CLASSNOT ? "not" : ""), num);
|
printf("class%s %d", (code[pc - 2] ? "" : "not"), num);
|
||||||
pc++;
|
|
||||||
while (num--) {
|
while (num--) {
|
||||||
printf(" 0x%02x-0x%02x", code[pc], code[pc + 1]);
|
printf(" 0x%02x-0x%02x", code[pc], code[pc + 1]);
|
||||||
pc += 2;
|
pc += 2;
|
||||||
@@ -306,12 +304,12 @@ static int _compilecode(const char **re_loc, rcode *prog, int sizecode)
|
|||||||
int cnt;
|
int cnt;
|
||||||
term = PC;
|
term = PC;
|
||||||
re++;
|
re++;
|
||||||
|
EMIT(PC++, CLASS);
|
||||||
if (*re == '^') {
|
if (*re == '^') {
|
||||||
EMIT(PC++, CLASSNOT);
|
EMIT(PC++, 0);
|
||||||
re++;
|
re++;
|
||||||
} else {
|
} else
|
||||||
EMIT(PC++, CLASS);
|
EMIT(PC++, 1);
|
||||||
}
|
|
||||||
PC++; // Skip "# of pairs" byte
|
PC++; // Skip "# of pairs" byte
|
||||||
prog->len++;
|
prog->len++;
|
||||||
for (cnt = 0; *re != ']'; cnt++) {
|
for (cnt = 0; *re != ']'; cnt++) {
|
||||||
@@ -329,7 +327,7 @@ static int _compilecode(const char **re_loc, rcode *prog, int sizecode)
|
|||||||
uc_code(c, re) EMIT(PC++, c);
|
uc_code(c, re) EMIT(PC++, c);
|
||||||
uc_len(c, re) re += c;
|
uc_len(c, re) re += c;
|
||||||
}
|
}
|
||||||
EMIT(term + 1, cnt);
|
EMIT(term + 2, cnt);
|
||||||
break;
|
break;
|
||||||
case '(':;
|
case '(':;
|
||||||
term = PC;
|
term = PC;
|
||||||
@@ -346,7 +344,6 @@ static int _compilecode(const char **re_loc, rcode *prog, int sizecode)
|
|||||||
return RE_UNSUPPORTED_SYNTAX;
|
return RE_UNSUPPORTED_SYNTAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (capture) {
|
if (capture) {
|
||||||
sub = ++prog->sub;
|
sub = ++prog->sub;
|
||||||
EMIT(PC++, SAVE);
|
EMIT(PC++, SAVE);
|
||||||
@@ -357,7 +354,6 @@ static int _compilecode(const char **re_loc, rcode *prog, int sizecode)
|
|||||||
*re_loc = re;
|
*re_loc = re;
|
||||||
if (res < 0) return res;
|
if (res < 0) return res;
|
||||||
if (*re != ')') return RE_SYNTAX_ERROR;
|
if (*re != ')') return RE_SYNTAX_ERROR;
|
||||||
|
|
||||||
if (capture) {
|
if (capture) {
|
||||||
EMIT(PC++, SAVE);
|
EMIT(PC++, SAVE);
|
||||||
EMIT(PC++, 2 * sub + 1);
|
EMIT(PC++, 2 * sub + 1);
|
||||||
@@ -396,7 +392,6 @@ static int _compilecode(const char **re_loc, rcode *prog, int sizecode)
|
|||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
switch (code[term]) {
|
switch (code[term]) {
|
||||||
case CLASS:
|
case CLASS:
|
||||||
case CLASSNOT:
|
|
||||||
case NAMEDCLASS:
|
case NAMEDCLASS:
|
||||||
case JMP:
|
case JMP:
|
||||||
case SPLIT:
|
case SPLIT:
|
||||||
@@ -638,12 +633,11 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
|||||||
addthread(prog->insts, plist, gen, nlist, pc, sub, s, sp+l);
|
addthread(prog->insts, plist, gen, nlist, pc, sub, s, sp+l);
|
||||||
break;
|
break;
|
||||||
case CLASS:
|
case CLASS:
|
||||||
case CLASSNOT:
|
|
||||||
if (!re_classmatch(pc, sp)) {
|
if (!re_classmatch(pc, sp)) {
|
||||||
decref(sub);
|
decref(sub);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pc += *pc * 2 + 1;
|
pc += *(pc+1) * 2 + 2;
|
||||||
goto addthread;
|
goto addthread;
|
||||||
case NAMEDCLASS:
|
case NAMEDCLASS:
|
||||||
if (!re_namedclassmatch(pc, sp)) {
|
if (!re_namedclassmatch(pc, sp)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user