Lines Matching +full:1 +full:g

14  * 1. Redistributions of source code must retain the above copyright
74 struct re_guts *g;
76 llvm_regmatch_t *pmatch; /* [nsub+1] (0 element unused) */
81 const char **lastpos; /* [nplus+1] */
99 #define BOL (OUT+1)
100 #define EOL (BOL+1)
134 matcher(struct re_guts *g, const char *string, size_t nmatch,
143 const sopno gf = g->firststate+1; /* +1 for OEND */
144 const sopno gl = g->laststate;
149 if (g->cflags&REG_NOSUB)
162 if (g->must != NULL) {
164 if (*dp == g->must[0] && stop - dp >= g->mlen &&
165 memcmp(dp, g->must, (size_t)g->mlen) == 0)
167 if (dp == stop) /* we didn't find g->must */
172 m->g = g;
195 if (nmatch == 0 && !g->backrefs)
208 if (nmatch == 1 && !g->backrefs)
213 m->pmatch = (llvm_regmatch_t *)malloc((m->g->nsub + 1) *
219 for (i = 1; i <= m->g->nsub; i++)
220 m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1;
221 if (!g->backrefs && !(m->eflags&REG_BACKR)) {
225 if (g->nplus > 0 && m->lastpos == NULL)
226 m->lastpos = (const char **)malloc((g->nplus+1) *
228 if (g->nplus > 0 && m->lastpos == NULL) {
240 assert(g->backrefs); /* must be back references doing it */
241 assert(g->nplus == 0 || m->lastpos != NULL);
246 endp = slow(m, m->coldp, endp-1, gf, gl);
251 for (i = 1; i <= m->g->nsub; i++) {
252 assert(m->pmatch[i].rm_so == -1);
253 assert(m->pmatch[i].rm_eo == -1);
267 start = m->coldp + 1; /* recycle starting later */
275 if (nmatch > 1) {
277 for (i = 1; i < nmatch; i++)
278 if (i <= m->g->nsub)
281 pmatch[i].rm_so = -1;
282 pmatch[i].rm_eo = -1;
295 * match. This can always conservatively return "stop - 1", but may return an
298 step_back(struct re_guts *g, const char *start, const char *stop, sopno startst,
303 const char *res = stop - 1;
310 if (OP(g->strip[startst]) != ORPAREN)
314 if (OP(g->strip[startst]) != OCHAR)
318 char ch = OPND(g->strip[startst]);
322 sopno nextst = startst + 1;
323 const char *next = res + 1;
324 if (nextst >= stopst || OP(g->strip[nextst]) != OCHAR || next >= stop ||
325 *next == (char)OPND(g->strip[nextst]))
357 switch (OP(m->g->strip[es])) {
360 es += OPND(m->g->strip[es]);
363 while (OP(m->g->strip[es]) != O_CH)
364 es += OPND(m->g->strip[es]);
370 switch (OP(m->g->strip[ss])) {
402 stp = step_back(m->g, sp, rest, es, stopst);
405 ssub = ss + 1;
406 esub = es - 1;
427 stp = step_back(m->g, sp, rest, es, stopst);
430 ssub = ss + 1;
431 esub = es - 1;
466 stp = rest - 1;
469 ssub = ss + 1;
470 esub = ss + OPND(m->g->strip[ss]) - 1;
471 assert(OP(m->g->strip[esub]) == OOR1);
476 assert(OP(m->g->strip[esub]) == OOR1);
478 assert(OP(m->g->strip[esub]) == OOR2);
479 ssub = esub + 1;
480 esub += OPND(m->g->strip[esub]);
481 if (OP(m->g->strip[esub]) == OOR2)
484 assert(OP(m->g->strip[esub]) == O_CH);
501 i = OPND(m->g->strip[ss]);
502 assert(0 < i && i <= m->g->nsub);
506 i = OPND(m->g->strip[ss]);
507 assert(0 < i && i <= m->g->nsub);
546 switch (OP(s = m->g->strip[ss])) {
557 cs = &m->g->sets[OPND(s)];
563 (sp < m->endp && *(sp-1) == '\n' &&
564 (m->g->cflags&REG_NEWLINE)) )
572 (m->g->cflags&REG_NEWLINE)) )
579 (sp < m->endp && *(sp-1) == '\n' &&
580 (m->g->cflags&REG_NEWLINE)) ||
582 !ISWORD(*(sp-1))) ) &&
591 (m->g->cflags&REG_NEWLINE)) ||
593 (sp > m->beginp && ISWORD(*(sp-1))) )
603 s = m->g->strip[ss];
607 } while (OP(s = m->g->strip[ss]) != O_CH);
611 hard = 1;
623 s = m->g->strip[ss];
627 assert(0 < i && i <= m->g->nsub);
628 if (m->pmatch[i].rm_eo == -1)
630 assert(m->pmatch[i].rm_so != -1);
640 while (m->g->strip[ss] != SOP(O_BACK, i))
642 return(backref(m, sp+len, stop, ss+1, stopst, lev, rec));
645 dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
648 return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev, rec));
652 assert(lev+1 <= m->g->nplus);
653 m->lastpos[lev+1] = sp;
654 return(backref(m, sp, stop, ss+1, stopst, lev+1, rec));
658 return(backref(m, sp, stop, ss+1, stopst, lev-1, rec));
661 dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev, rec);
663 return(backref(m, sp, stop, ss+1, stopst, lev-1, rec));
668 ssub = ss + 1;
669 esub = ss + OPND(s) - 1;
670 assert(OP(m->g->strip[esub]) == OOR1);
676 if (OP(m->g->strip[esub]) == O_CH)
679 assert(OP(m->g->strip[esub]) == OOR2);
680 ssub = esub + 1;
681 esub += OPND(m->g->strip[esub]);
682 if (OP(m->g->strip[esub]) == OOR2)
685 assert(OP(m->g->strip[esub]) == O_CH);
690 assert(0 < i && i <= m->g->nsub);
693 dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
701 assert(0 < i && i <= m->g->nsub);
704 dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
732 int c = (start == m->beginp) ? OUT : *(start-1);
740 st = step(m->g, startst, stopst, st, NOTHING, st);
754 if ( (lastc == '\n' && m->g->cflags&REG_NEWLINE) ||
757 i = m->g->nbol;
759 if ( (c == '\n' && m->g->cflags&REG_NEWLINE) ||
762 i += m->g->neol;
766 st = step(m->g, startst, stopst, st, flagch, st);
780 st = step(m->g, startst, stopst, st, flagch, st);
792 st = step(m->g, startst, stopst, tmp, c, st);
794 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
801 return(p+1);
817 sop s = m->g->strip[startst];
829 hard = 1;
839 int c = (p == m->beginp) ? OUT : *(p-1);
849 st = step(m->g, startst, stopst, st, NOTHING, st);
859 if ( (lastc == '\n' && m->g->cflags&REG_NEWLINE) ||
862 i = m->g->nbol;
864 if ( (c == '\n' && m->g->cflags&REG_NEWLINE) ||
867 i += m->g->neol;
871 st = step(m->g, startst, stopst, st, flagch, st);
885 st = step(m->g, startst, stopst, st, flagch, st);
899 st = step(m->g, startst, stopst, tmp, c, st);
901 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
913 step(struct re_guts *g,
928 s = g->strip[pc];
931 assert(pc == stop-1);
937 FWD(aft, bef, 1);
941 FWD(aft, bef, 1);
945 FWD(aft, bef, 1);
949 FWD(aft, bef, 1);
953 FWD(aft, bef, 1);
957 FWD(aft, bef, 1);
960 cs = &g->sets[OPND(s)];
962 FWD(aft, bef, 1);
966 FWD(aft, aft, 1);
969 FWD(aft, aft, 1);
972 FWD(aft, aft, 1);
977 pc -= OPND(s) + 1;
982 FWD(aft, aft, 1);
986 FWD(aft, aft, 1);
990 FWD(aft, aft, 1);
993 FWD(aft, aft, 1);
994 assert(OP(g->strip[pc+OPND(s)]) == OOR2);
999 for (look = 1;
1000 OP(s = g->strip[pc+look]) != O_CH;
1007 FWD(aft, aft, 1);
1008 if (OP(g->strip[pc+OPND(s)]) != O_CH) {
1009 assert(OP(g->strip[pc+OPND(s)]) == OOR2);
1014 FWD(aft, aft, 1);
1032 struct re_guts *g = m->g;
1034 int first = 1;
1042 for (i = 0; i < g->nstates; i++)