38 #include <sys/types.h>
114 #define PEEK() (*p->next)
115 #define PEEK2() (*(p->next+1))
116 #define MORE() (p->next < p->end)
117 #define MORE2() (p->next+1 < p->end)
118 #define SEE(c) (MORE() && PEEK() == (c))
119 #define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b))
120 #define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0)
121 #define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
122 #define NEXT() (p->next++)
123 #define NEXT2() (p->next += 2)
124 #define NEXTn(n) (p->next += (n))
125 #define GETNEXT() (*p->next++)
126 #define SETERROR(e) seterr(p, (e))
127 #define REQUIRE(co, e) (void)((co) || SETERROR(e))
128 #define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e))
129 #define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e))
130 #define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e))
131 #define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
132 #define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
133 #define AHEAD(pos) dofwd(p, pos, HERE()-(pos))
134 #define ASTERN(sop, pos) EMIT(sop, HERE()-pos)
135 #define HERE() (p->slen)
136 #define THERE() (p->slen - 1)
137 #define THERETHERE() (p->slen - 2)
138 #define DROP(n) (p->slen -= (n))
140 #ifdef _POSIX2_RE_DUP_MAX
141 #define DUPMAX _POSIX2_RE_DUP_MAX
145 #define INFINITY (DUPMAX + 1)
148 static int never = 0;
161 struct parse *p = &pa;
165 # define GOODFLAGS(f) (f)
167 # define GOODFLAGS(f) ((f)&~REG_DUMP)
179 len =
strlen((
const char *)pattern);
186 p->
ssize = len/(size_t)2*(
size_t)3 + (size_t)1;
189 if (p->
strip == NULL) {
196 p->
next = (
char *)pattern;
200 for (i = 0; i <
NPAREN; i++) {
223 if (cflags®_EXTENDED)
225 else if (cflags®_NOSPEC)
268 while (
MORE() && (c =
PEEK()) !=
'|' && c != stop)
326 assert(p->
pend[subno] != 0);
331 #ifndef POSIX_MISTAKE
374 if (c >=
'1' && c <=
'9') {
380 backrefnum = c -
'0';
381 if (p->
pend[backrefnum] == 0) {
389 assert(backrefnum <= p->g->nsub);
391 assert(p->
pbegin[backrefnum] != 0);
415 if (!( c ==
'*' || c ==
'+' || c ==
'?' ||
452 repeat(p, pos, count, count2);
465 if (!( c ==
'*' || c ==
'+' || c ==
'?' ||
533 # define BACKSL (1<<CHAR_BIT)
567 assert(p->
pend[subno] != 0);
587 if (p->
pend[i] != 0) {
588 assert(i <= p->g->nsub);
590 assert(p->
pbegin[i] != 0);
613 }
else if (
EATTWO(
'\\',
'{')) {
623 repeat(p, pos, count, count2);
646 count = count*10 + (
GETNEXT() -
'0');
704 for (i = p->
g->
csetsize - 1; i >= 0; i--)
705 if (
CHIN(cs, i) && isalpha(i)) {
716 for (i = p->
g->
csetsize - 1; i >= 0; i--)
727 assert(cs->
multis == NULL);
729 if (
nch(p, cs) == 1) {
793 for (i = start; i <= finish; i++)
817 if (cp->
name == NULL) {
824 while ((c = *u++) !=
'\0')
898 return ((
uch)tolower(ch));
899 else if (islower(ch))
900 return ((
uch)toupper(ch));
913 char *oldnext = p->
next;
914 char *oldend = p->
end;
925 assert(p->
next == bracket+2);
955 char *oldnext = p->
next;
956 char *oldend = p->
end;
966 assert(p->
next == bracket+3);
983 # define REP(f, t) ((f)*8 + (t))
984 # define MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)
1001 repeat(p, start+1, 1, to);
1019 copy =
dupl(p, start+1, finish+1);
1020 assert(copy == finish+4);
1021 repeat(p, copy, 1, to-1);
1028 copy =
dupl(p, start, finish);
1029 repeat(p, copy, from-1, to-1);
1032 copy =
dupl(p, start, finish);
1033 repeat(p, copy, from-1, to);
1072 assert(nc % CHAR_BIT == 0);
1073 nbytes = nc / CHAR_BIT * css;
1085 for (i = 0; i < no; i++)
1094 cs = &p->
g->
sets[no];
1096 cs->
mask = 1 << ((no) % CHAR_BIT);
1123 for (i = 0; i < css; i++)
1148 for (cs2 = &p->
g->
sets[0]; cs2 < top; cs2++)
1149 if (cs2->
hash == h && cs2 != cs) {
1151 for (i = 0; i < css; i++)
1152 if (!!
CHIN(cs2, i) != !!
CHIN(cs, i))
1163 return((
int)(cs - p->
g->
sets));
1175 for (i = 0; i < css; i++)
1192 for (i = 0; i < css; i++)
1231 assert(cs->
multis == NULL);
1244 assert(cs->
multis == NULL);
1255 int ncols = (g->
ncsets+(CHAR_BIT-1)) / CHAR_BIT;
1256 unsigned uc = (
uch)c;
1258 for (i = 0, col = g->
setbits; i < ncols; i++, col += g->csetsize)
1272 int ncols = (g->
ncsets+(CHAR_BIT-1)) / CHAR_BIT;
1273 unsigned uc1 = (
uch)c1;
1274 unsigned uc2 = (
uch)c2;
1276 for (i = 0, col = g->
setbits; i < ncols; i++, col += g->csetsize)
1277 if (col[uc1] != col[uc2])
1297 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
1298 if (cats[c] == 0 &&
isinsets(g, c)) {
1301 for (c2 = c+1; c2 <= CHAR_MAX; c2++)
1302 if (cats[c2] == 0 &&
samesets(g, c, c2))
1316 sopno len = finish - start;
1318 assert(finish >= start);
1324 (
char *)(p->
strip + start), (
size_t)len*
sizeof(
sop));
1371 assert(
HERE() == sn+1);
1376 for (i = 1; i <
NPAREN; i++) {
1377 if (p->
pbegin[i] >= pos) {
1380 if (p->
pend[i] >= pos) {
1412 if (p->
ssize >= size)
1432 if (g->
strip == NULL) {
1464 scan = g->
strip + 1;
1470 newstart = scan - 1;
1492 if (newlen > g->
mlen) {
1506 if (g->
must == NULL) {
1512 for (i = g->
mlen; i > 0; i--) {
1513 while (
OP(s = *scan++) !=
OCHAR)
1515 assert(cp < g->must + g->
mlen);
1516 *cp++ = (char)
OPND(s);
1536 scan = g->
strip + 1;
1544 if (plusnest > maxnest)
static void nonnewline(struct parse *)
static void p_ere_exp(struct parse *)
static int p_simp_re(struct parse *, int)
static int firstch(struct parse *, cset *)
static struct cname cnames[]
static int samesets(struct re_guts *, int, int)
static int freezeset(struct parse *, cset *)
static void mccase(struct parse *, cset *)
static void p_b_term(struct parse *, cset *)
static void categorize(struct parse *, struct re_guts *)
static void findmust(struct parse *, struct re_guts *)
int llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags)
static int seterr(struct parse *, int)
void llvm_regfree(llvm_regex_t *)
static cset * allocset(struct parse *)
static void stripsnug(struct parse *, struct re_guts *)
static void dofwd(struct parse *, sopno, sop)
static void doemit(struct parse *, sop, size_t)
static void bothcases(struct parse *, int)
static int nch(struct parse *, cset *)
size_t llvm_strlcpy(char *dst, const char *src, size_t siz)
static void enlarge(struct parse *, sopno)
static void p_ere(struct parse *, int)
* if(!EatIfPresent(lltok::kw_thread_local)) return false
static void mcadd(struct parse *, cset *, const char *)
void *realloc(void *ptr, size_t size);
static void doinsert(struct parse *, sop, size_t, sopno)
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
static void p_b_cclass(struct parse *, cset *)
static void p_bracket(struct parse *)
static void freeset(struct parse *, cset *)
static char p_b_symbol(struct parse *)
static void ordinary(struct parse *, int)
size_t strlen(const char *s);
static void p_bre(struct parse *, int, int)
static int p_count(struct parse *)
static struct cclass cclasses[]
void *malloc(size_t size);
static char p_b_coll_elem(struct parse *, int)
static void p_b_eclass(struct parse *, cset *)
static char othercase(int)
static sopno dupl(struct parse *, sopno, sopno)
static void repeat(struct parse *, sopno, int, int)
static sopno pluscount(struct parse *, struct re_guts *)
static void p_str(struct parse *)
static int isinsets(struct re_guts *, int)
int strncmp(const char *s1, const char *s2, size_t n);
void *calloc(size_t count, size_t size);
static void mcinvert(struct parse *, cset *)