From: David du Colombier <0intro@gmail.com> Date: Sat, 8 Jun 2013 19:30:00 +0000 (+0200) Subject: replace u1 and u2 by r and l X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=782d1677a378230879a51db3b57783487a99289e;p=proto%2Flibregexp.git replace u1 and u2 by r and l --- diff --git a/regcomp.c b/regcomp.c index 36b6eb3..d7cd766 100644 --- a/regcomp.c +++ b/regcomp.c @@ -64,8 +64,8 @@ static Reinst* newinst(int t) { freep->type = t; - freep->u2.left = 0; - freep->u1.right = 0; + freep->l.left = 0; + freep->r.right = 0; return freep++; } @@ -79,9 +79,9 @@ operand(int t) i = newinst(t); if(t == CCLASS || t == NCCLASS) - i->u1.cp = yyclassp; + i->r.cp = yyclassp; if(t == RUNE) - i->u1.r = yyrune; + i->r.r = yyrune; pushand(i, i); lastwasand = TRUE; @@ -183,51 +183,51 @@ evaluntil(int pri) case LBRA: /* must have been RBRA */ op1 = popand('('); inst2 = newinst(RBRA); - inst2->u1.subid = *subidp; - op1->last->u2.next = inst2; + inst2->r.subid = *subidp; + op1->last->l.next = inst2; inst1 = newinst(LBRA); - inst1->u1.subid = *subidp; - inst1->u2.next = op1->first; + inst1->r.subid = *subidp; + inst1->l.next = op1->first; pushand(inst1, inst2); return; case OR: op2 = popand('|'); op1 = popand('|'); inst2 = newinst(NOP); - op2->last->u2.next = inst2; - op1->last->u2.next = inst2; + op2->last->l.next = inst2; + op1->last->l.next = inst2; inst1 = newinst(OR); - inst1->u1.right = op1->first; - inst1->u2.left = op2->first; + inst1->r.right = op1->first; + inst1->l.left = op2->first; pushand(inst1, inst2); break; case CAT: op2 = popand(0); op1 = popand(0); - op1->last->u2.next = op2->first; + op1->last->l.next = op2->first; pushand(op1->first, op2->last); break; case STAR: op2 = popand('*'); inst1 = newinst(OR); - op2->last->u2.next = inst1; - inst1->u1.right = op2->first; + op2->last->l.next = inst1; + inst1->r.right = op2->first; pushand(inst1, inst1); break; case PLUS: op2 = popand('+'); inst1 = newinst(OR); - op2->last->u2.next = inst1; - inst1->u1.right = op2->first; + op2->last->l.next = inst1; + inst1->r.right = op2->first; pushand(op2->first, inst1); break; case QUEST: op2 = popand('?'); inst1 = newinst(OR); inst2 = newinst(NOP); - inst1->u2.left = inst2; - inst1->u1.right = op2->first; - op2->last->u2.next = inst2; + inst1->l.left = inst2; + inst1->r.right = op2->first; + op2->last->l.next = inst2; pushand(inst1, inst2); break; } @@ -247,10 +247,10 @@ optimize(Reprog *pp) * get rid of NOOP chains */ for(inst=pp->firstinst; inst->type!=END; inst++){ - target = inst->u2.next; + target = inst->l.next; while(target->type == NOP) - target = target->u2.next; - inst->u2.next = target; + target = target->l.next; + inst->l.next = target; } /* @@ -270,16 +270,16 @@ optimize(Reprog *pp) case STAR: case PLUS: case QUEST: - inst->u1.right = (void*)((char*)inst->u1.right + diff); + inst->r.right = (void*)((char*)inst->r.right + diff); break; case CCLASS: case NCCLASS: - inst->u1.right = (void*)((char*)inst->u1.right + diff); - cl = inst->u1.cp; + inst->r.right = (void*)((char*)inst->r.right + diff); + cl = inst->r.cp; cl->end = (void*)((char*)cl->end + diff); break; } - inst->u2.left = (void*)((char*)inst->u2.left + diff); + inst->l.left = (void*)((char*)inst->l.left + diff); } npp->startinst = (void*)((char*)npp->startinst + diff); return npp; @@ -308,14 +308,14 @@ dump(Reprog *pp) l = pp->firstinst; do{ printf("%d:\t0%o\t%d\t%d", (int)(l-pp->firstinst), l->type, - (int)(l->u2.left-pp->firstinst), (int)(l->u1.right-pp->firstinst)); + (int)(l->l.left-pp->firstinst), (int)(l->r.right-pp->firstinst)); if(l->type == RUNE) - printf("\t%C\n", l->u1.r); + printf("\t%C\n", l->r.r); else if(l->type == CCLASS || l->type == NCCLASS){ printf("\t["); if(l->type == NCCLASS) printf("^"); - for(p = l->u1.cp->spans; p < l->u1.cp->end; p += 2) + for(p = l->r.cp->spans; p < l->r.cp->end; p += 2) if(p[0] == p[1]) printf("%C", p[0]); else diff --git a/regexec.c b/regexec.c index fa6accc..e2dadb8 100644 --- a/regexec.c +++ b/regexec.c @@ -81,27 +81,27 @@ regexec1(Reprog *progp, /* program to run */ /* Execute machine until current list is empty */ for(tlp=tl; tlp->inst; tlp++){ /* assignment = */ - for(inst = tlp->inst; ; inst = inst->u2.next){ + for(inst = tlp->inst; ; inst = inst->l.next){ switch(inst->type){ case RUNE: /* regular character */ - if(inst->u1.r == r){ - if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle) + if(inst->r.r == r){ + if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle) return -1; } break; case LBRA: - tlp->se.m[inst->u1.subid].s.sp = s; + tlp->se.m[inst->r.subid].s.sp = s; continue; case RBRA: - tlp->se.m[inst->u1.subid].e.ep = s; + tlp->se.m[inst->r.subid].e.ep = s; continue; case ANY: if(r != '\n') - if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle) + if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle) return -1; break; case ANYNL: - if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle) + if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle) return -1; break; case BOL: @@ -113,26 +113,26 @@ regexec1(Reprog *progp, /* program to run */ continue; break; case CCLASS: - ep = inst->u1.cp->end; - for(rp = inst->u1.cp->spans; rp < ep; rp += 2) + ep = inst->r.cp->end; + for(rp = inst->r.cp->spans; rp < ep; rp += 2) if(r >= rp[0] && r <= rp[1]){ - if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle) + if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle) return -1; break; } break; case NCCLASS: - ep = inst->u1.cp->end; - for(rp = inst->u1.cp->spans; rp < ep; rp += 2) + ep = inst->r.cp->end; + for(rp = inst->r.cp->spans; rp < ep; rp += 2) if(r >= rp[0] && r <= rp[1]) break; if(rp == ep) - if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle) + if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle) return -1; break; case OR: /* evaluate right choice later */ - if(_renewthread(tlp, inst->u1.right, ms, &tlp->se) == tle) + if(_renewthread(tlp, inst->r.right, ms, &tlp->se) == tle) return -1; /* efficiency: advance and re-evaluate */ continue; @@ -208,9 +208,9 @@ regexec(Reprog *progp, /* program to run */ } j.starttype = 0; j.startchar = 0; - if(progp->startinst->type == RUNE && progp->startinst->u1.r < Runeself) { + if(progp->startinst->type == RUNE && progp->startinst->r.r < Runeself) { j.starttype = RUNE; - j.startchar = progp->startinst->u1.r; + j.startchar = progp->startinst->r.r; } if(progp->startinst->type == BOL) j.starttype = BOL; diff --git a/regexp9.h b/regexp9.h index e78cb7d..b85cebb 100644 --- a/regexp9.h +++ b/regexp9.h @@ -44,16 +44,16 @@ struct Reclass{ */ struct Reinst{ int type; - union { + union { Reclass *cp; /* class pointer */ Rune r; /* character */ int subid; /* sub-expression id for RBRA and LBRA */ Reinst *right; /* right child of OR */ - }u1; + }r; union { /* regexp relies on these two being in the same union */ Reinst *left; /* left child of OR */ Reinst *next; /* next instruction for CAT & LBRA */ - }u2; + }l; }; /* diff --git a/rregexec.c b/rregexec.c index e273cba..a63d0b4 100644 --- a/rregexec.c +++ b/rregexec.c @@ -74,26 +74,26 @@ rregexec1(Reprog *progp, /* program to run */ /* Execute machine until current list is empty */ for(tlp=tl; tlp->inst; tlp++){ - for(inst=tlp->inst; ; inst = inst->u2.next){ + for(inst=tlp->inst; ; inst = inst->l.next){ switch(inst->type){ case RUNE: /* regular character */ - if(inst->u1.r == r) - if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle) + if(inst->r.r == r) + if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle) return -1; break; case LBRA: - tlp->se.m[inst->u1.subid].s.rsp = s; + tlp->se.m[inst->r.subid].s.rsp = s; continue; case RBRA: - tlp->se.m[inst->u1.subid].e.rep = s; + tlp->se.m[inst->r.subid].e.rep = s; continue; case ANY: if(r != '\n') - if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle) + if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle) return -1; break; case ANYNL: - if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle) + if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle) return -1; break; case BOL: @@ -105,26 +105,26 @@ rregexec1(Reprog *progp, /* program to run */ continue; break; case CCLASS: - ep = inst->u1.cp->end; - for(rp = inst->u1.cp->spans; rp < ep; rp += 2) + ep = inst->r.cp->end; + for(rp = inst->r.cp->spans; rp < ep; rp += 2) if(r >= rp[0] && r <= rp[1]){ - if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle) + if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle) return -1; break; } break; case NCCLASS: - ep = inst->u1.cp->end; - for(rp = inst->u1.cp->spans; rp < ep; rp += 2) + ep = inst->r.cp->end; + for(rp = inst->r.cp->spans; rp < ep; rp += 2) if(r >= rp[0] && r <= rp[1]) break; if(rp == ep) - if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle) + if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle) return -1; break; case OR: /* evaluate right choice later */ - if(_renewthread(tlp, inst->u1.right, ms, &tlp->se) == tle) + if(_renewthread(tlp, inst->r.right, ms, &tlp->se) == tle) return -1; /* efficiency: advance and re-evaluate */ continue; @@ -188,9 +188,9 @@ rregexec(Reprog *progp, /* program to run */ } j.starttype = 0; j.startchar = 0; - if(progp->startinst->type == RUNE && progp->startinst->u1.r < Runeself) { + if(progp->startinst->type == RUNE && progp->startinst->r.r < Runeself) { j.starttype = RUNE; - j.startchar = progp->startinst->u1.r; + j.startchar = progp->startinst->r.r; } if(progp->startinst->type == BOL) j.starttype = BOL;