llvm.org GIT mirror llvm / a485235
Merge 100438 from mainline. Push const through the regex engine. Fixes some of the warnings in PR6616. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_27@100450 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 10 years ago
2 changed file(s) with 51 addition(s) and 44 deletion(s). Raw diff Collapse all Expand all
7171 struct re_guts *g;
7272 int eflags;
7373 llvm_regmatch_t *pmatch; /* [nsub+1] (0 element unused) */
74 char *offp; /* offsets work from here */
75 char *beginp; /* start of string -- virtual NUL precedes */
76 char *endp; /* end of string -- virtual NUL here */
77 char *coldp; /* can be no match starting before here */
78 char **lastpos; /* [nplus+1] */
74 const char *offp; /* offsets work from here */
75 const char *beginp; /* start of string -- virtual NUL precedes */
76 const char *endp; /* end of string -- virtual NUL here */
77 const char *coldp; /* can be no match starting before here */
78 const char **lastpos; /* [nplus+1] */
7979 STATEVARS;
8080 states st; /* current states */
8181 states fresh; /* states for a fresh start */
8383 states empty; /* empty set of states */
8484 };
8585
86 static int matcher(struct re_guts *, char *, size_t, llvm_regmatch_t[], int);
87 static char *dissect(struct match *, char *, char *, sopno, sopno);
88 static char *backref(struct match *, char *, char *, sopno, sopno, sopno, int);
89 static char *fast(struct match *, char *, char *, sopno, sopno);
90 static char *slow(struct match *, char *, char *, sopno, sopno);
86 static int matcher(struct re_guts *, const char *, size_t,
87 llvm_regmatch_t[], int);
88 static const char *dissect(struct match *, const char *, const char *, sopno,
89 sopno);
90 static const char *backref(struct match *, const char *, const char *, sopno,
91 sopno, sopno, int);
92 static const char *fast(struct match *, const char *, const char *, sopno, sopno);
93 static const char *slow(struct match *, const char *, const char *, sopno, sopno);
9194 static states step(struct re_guts *, sopno, sopno, states, int, states);
9295 #define MAX_RECURSION 100
9396 #define BOL (OUT+1)
124127 - matcher - the actual matching engine
125128 */
126129 static int /* 0 success, REG_NOMATCH failure */
127 matcher(struct re_guts *g, char *string, size_t nmatch, llvm_regmatch_t pmatch[],
130 matcher(struct re_guts *g, const char *string, size_t nmatch,
131 llvm_regmatch_t pmatch[],
128132 int eflags)
129133 {
130 char *endp;
134 const char *endp;
131135 size_t i;
132136 struct match mv;
133137 struct match *m = &mv;
134 char *dp;
138 const char *dp;
135139 const sopno gf = g->firststate+1; /* +1 for OEND */
136140 const sopno gl = g->laststate;
137 char *start;
138 char *stop;
141 const char *start;
142 const char *stop;
139143
140144 /* simplify the situation where possible */
141145 if (g->cflags®_NOSUB)
215219 dp = dissect(m, m->coldp, endp, gf, gl);
216220 } else {
217221 if (g->nplus > 0 && m->lastpos == NULL)
218 m->lastpos = (char **)malloc((g->nplus+1) *
222 m->lastpos = (const char **)malloc((g->nplus+1) *
219223 sizeof(char *));
220224 if (g->nplus > 0 && m->lastpos == NULL) {
221225 free(m->pmatch);
286290 /*
287291 - dissect - figure out what matched what, no back references
288292 */
289 static char * /* == stop (success) always */
290 dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
293 static const char * /* == stop (success) always */
294 dissect(struct match *m, const char *start, const char *stop, sopno startst,
295 sopno stopst)
291296 {
292297 int i;
293298 sopno ss; /* start sop of current subRE */
294299 sopno es; /* end sop of current subRE */
295 char *sp; /* start of string matched by it */
296 char *stp; /* string matched by it cannot pass here */
297 char *rest; /* start of rest of string */
298 char *tail; /* string unmatched by rest of RE */
300 const char *sp; /* start of string matched by it */
301 const char *stp; /* string matched by it cannot pass here */
302 const char *rest; /* start of rest of string */
303 const char *tail; /* string unmatched by rest of RE */
299304 sopno ssub; /* start sop of subsubRE */
300305 sopno esub; /* end sop of subsubRE */
301 char *ssp; /* start of string matched by subsubRE */
302 char *sep; /* end of string matched by subsubRE */
303 char *oldssp; /* previous ssp */
306 const char *ssp; /* start of string matched by subsubRE */
307 const char *sep; /* end of string matched by subsubRE */
308 const char *oldssp; /* previous ssp */
304309
305310 AT("diss", start, stop, startst, stopst);
306311 sp = start;
359364 esub = es - 1;
360365 /* did innards match? */
361366 if (slow(m, sp, rest, ssub, esub) != NULL) {
362 char *dp = dissect(m, sp, rest, ssub, esub);
367 const char *dp = dissect(m, sp, rest, ssub, esub);
363368 (void)dp; /* avoid warning if assertions off */
364369 assert(dp == rest);
365370 } else /* no */
399404 assert(sep == rest); /* must exhaust substring */
400405 assert(slow(m, ssp, sep, ssub, esub) == rest);
401406 {
402 char *dp = dissect(m, ssp, sep, ssub, esub);
407 const char *dp = dissect(m, ssp, sep, ssub, esub);
403408 (void)dp; /* avoid warning if assertions off */
404409 assert(dp == sep);
405410 }
437442 assert(OP(m->g->strip[esub]) == O_CH);
438443 }
439444 {
440 char *dp = dissect(m, sp, rest, ssub, esub);
445 const char *dp = dissect(m, sp, rest, ssub, esub);
441446 (void)dp; /* avoid warning if assertions off */
442447 assert(dp == rest);
443448 }
473478 /*
474479 - backref - figure out what matched what, figuring in back references
475480 */
476 static char * /* == stop (success) or NULL (failure) */
477 backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst,
478 sopno lev, int rec) /* PLUS nesting level */
481 static const char * /* == stop (success) or NULL (failure) */
482 backref(struct match *m, const char *start, const char *stop, sopno startst,
483 sopno stopst, sopno lev, int rec) /* PLUS nesting level */
479484 {
480485 int i;
481486 sopno ss; /* start sop of current subRE */
482 char *sp; /* start of string matched by it */
487 const char *sp; /* start of string matched by it */
483488 sopno ssub; /* start sop of subsubRE */
484489 sopno esub; /* end sop of subsubRE */
485 char *ssp; /* start of string matched by subsubRE */
486 char *dp;
490 const char *ssp; /* start of string matched by subsubRE */
491 const char *dp;
487492 size_t len;
488493 int hard;
489494 sop s;
673678 /*
674679 - fast - step through the string at top speed
675680 */
676 static char * /* where tentative match ended, or NULL */
677 fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
681 static const char * /* where tentative match ended, or NULL */
682 fast(struct match *m, const char *start, const char *stop, sopno startst,
683 sopno stopst)
678684 {
679685 states st = m->st;
680686 states fresh = m->fresh;
681687 states tmp = m->tmp;
682 char *p = start;
688 const char *p = start;
683689 int c = (start == m->beginp) ? OUT : *(start-1);
684690 int lastc; /* previous c */
685691 int flagch;
686692 int i;
687 char *coldp; /* last p after which no match was underway */
693 const char *coldp; /* last p after which no match was underway */
688694
689695 CLEAR(st);
690696 SET1(st, startst);
757763 /*
758764 - slow - step through the string more deliberately
759765 */
760 static char * /* where it ended */
761 slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
766 static const char * /* where it ended */
767 slow(struct match *m, const char *start, const char *stop, sopno startst,
768 sopno stopst)
762769 {
763770 states st = m->st;
764771 states empty = m->empty;
765772 states tmp = m->tmp;
766 char *p = start;
773 const char *p = start;
767774 int c = (start == m->beginp) ? OUT : *(start-1);
768775 int lastc; /* previous c */
769776 int flagch;
770777 int i;
771 char *matchp; /* last p at which a match ended */
778 const char *matchp; /* last p at which a match ended */
772779
773780 AT("slow", start, stop, startst, stopst);
774781 CLEAR(st);
154154 eflags = GOODFLAGS(eflags);
155155
156156 if (g->nstates <= (long)(CHAR_BIT*sizeof(states1)) && !(eflags®_LARGE))
157 return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
157 return(smatcher(g, string, nmatch, pmatch, eflags));
158158 else
159 return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));
159 return(lmatcher(g, string, nmatch, pmatch, eflags));
160160 }