LLVM  13.0.0git
Classes | Macros | Functions | Variables
regcomp.c File Reference
#include <sys/types.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include "regex_impl.h"
#include "regutils.h"
#include "regex2.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Compiler.h"
Include dependency graph for regcomp.c:

Go to the source code of this file.

Classes

struct  cclass
 
struct  cname
 
struct  parse
 

Macros

#define NPAREN   10 /* we need to remember () 1-9 for back refs */
 
#define PEEK()   (*p->next)
 
#define PEEK2()   (*(p->next+1))
 
#define MORE()   (p->next < p->end)
 
#define MORE2()   (p->next+1 < p->end)
 
#define SEE(c)   (MORE() && PEEK() == (c))
 
#define SEETWO(a, b)   (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b))
 
#define EAT(c)   ((SEE(c)) ? (NEXT(), 1) : 0)
 
#define EATTWO(a, b)   ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
 
#define NEXT()   (p->next++)
 
#define NEXT2()   (p->next += 2)
 
#define NEXTn(n)   (p->next += (n))
 
#define GETNEXT()   (*p->next++)
 
#define SETERROR(e)   seterr(p, (e))
 
#define REQUIRE(co, e)   (void)((co) || SETERROR(e))
 
#define MUSTSEE(c, e)   (REQUIRE(MORE() && PEEK() == (c), e))
 
#define MUSTEAT(c, e)   (REQUIRE(MORE() && GETNEXT() == (c), e))
 
#define MUSTNOTSEE(c, e)   (REQUIRE(!MORE() || PEEK() != (c), e))
 
#define EMIT(op, sopnd)   doemit(p, (sop)(op), (size_t)(sopnd))
 
#define INSERT(op, pos)   doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
 
#define AHEAD(pos)   dofwd(p, pos, HERE()-(pos))
 
#define ASTERN(sop, pos)   EMIT(sop, HERE()-pos)
 
#define HERE()   (p->slen)
 
#define THERE()   (p->slen - 1)
 
#define THERETHERE()   (p->slen - 2)
 
#define DROP(n)   (p->slen -= (n))
 
#define DUPMAX   255
 
#define INFINITY   (DUPMAX + 1)
 
#define never   0 /* some <assert.h>s have bugs too */
 
#define GOODFLAGS(f)   ((f)&~REG_DUMP)
 
#define BACKSL   (1<<CHAR_BIT)
 
#define N   2
 
#define INF   3
 
#define REP(f, t)   ((f)*8 + (t))
 
#define MAP(n)   (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)
 

Functions

static void p_ere (struct parse *, int)
 
static void p_ere_exp (struct parse *)
 
static void p_str (struct parse *)
 
static void p_bre (struct parse *, int, int)
 
static int p_simp_re (struct parse *, int)
 
static int p_count (struct parse *)
 
static void p_bracket (struct parse *)
 
static void p_b_term (struct parse *, cset *)
 
static void p_b_cclass (struct parse *, cset *)
 
static void p_b_eclass (struct parse *, cset *)
 
static char p_b_symbol (struct parse *)
 
static char p_b_coll_elem (struct parse *, int)
 
static char othercase (int)
 
static void bothcases (struct parse *, int)
 
static void ordinary (struct parse *, int)
 
static void nonnewline (struct parse *)
 
static void repeat (struct parse *, sopno, int, int)
 
static int seterr (struct parse *, int)
 
static csetallocset (struct parse *)
 
static void freeset (struct parse *, cset *)
 
static int freezeset (struct parse *, cset *)
 
static int firstch (struct parse *, cset *)
 
static int nch (struct parse *, cset *)
 
static void mcadd (struct parse *, cset *, const char *)
 
static void mcinvert (struct parse *, cset *)
 
static void mccase (struct parse *, cset *)
 
static int isinsets (struct re_guts *, int)
 
static int samesets (struct re_guts *, int, int)
 
static void categorize (struct parse *, struct re_guts *)
 
static sopno dupl (struct parse *, sopno, sopno)
 
static void doemit (struct parse *, sop, size_t)
 
static void doinsert (struct parse *, sop, size_t, sopno)
 
static void dofwd (struct parse *, sopno, sop)
 
static void enlarge (struct parse *, sopno)
 
static void stripsnug (struct parse *, struct re_guts *)
 
static void findmust (struct parse *, struct re_guts *)
 
static sopno pluscount (struct parse *, struct re_guts *)
 
int llvm_regcomp (llvm_regex_t *preg, const char *pattern, int cflags)
 

Variables

static struct cclass cclasses []
 
static struct cname cnames []
 
static char nuls [10]
 

Macro Definition Documentation

◆ AHEAD

#define AHEAD (   pos)    dofwd(p, pos, HERE()-(pos))

Definition at line 269 of file regcomp.c.

◆ ASTERN

#define ASTERN (   sop,
  pos 
)    EMIT(sop, HERE()-pos)

Definition at line 270 of file regcomp.c.

◆ BACKSL

#define BACKSL   (1<<CHAR_BIT)

◆ DROP

#define DROP (   n)    (p->slen -= (n))

Definition at line 274 of file regcomp.c.

◆ DUPMAX

#define DUPMAX   255

Definition at line 279 of file regcomp.c.

◆ EAT

#define EAT (   c)    ((SEE(c)) ? (NEXT(), 1) : 0)

Definition at line 256 of file regcomp.c.

◆ EATTWO

#define EATTWO (   a,
  b 
)    ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)

Definition at line 257 of file regcomp.c.

◆ EMIT

#define EMIT (   op,
  sopnd 
)    doemit(p, (sop)(op), (size_t)(sopnd))

Definition at line 267 of file regcomp.c.

◆ GETNEXT

#define GETNEXT ( )    (*p->next++)

Definition at line 261 of file regcomp.c.

◆ GOODFLAGS

#define GOODFLAGS (   f)    ((f)&~REG_DUMP)

◆ HERE

#define HERE ( )    (p->slen)

Definition at line 271 of file regcomp.c.

◆ INF

#define INF   3

◆ INFINITY

#define INFINITY   (DUPMAX + 1)

Definition at line 281 of file regcomp.c.

◆ INSERT

#define INSERT (   op,
  pos 
)    doinsert(p, (sop)(op), HERE()-(pos)+1, pos)

Definition at line 268 of file regcomp.c.

◆ MAP

#define MAP (   n)    (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)

◆ MORE

#define MORE ( )    (p->next < p->end)

Definition at line 252 of file regcomp.c.

◆ MORE2

#define MORE2 ( )    (p->next+1 < p->end)

Definition at line 253 of file regcomp.c.

◆ MUSTEAT

#define MUSTEAT (   c,
 
)    (REQUIRE(MORE() && GETNEXT() == (c), e))

Definition at line 265 of file regcomp.c.

◆ MUSTNOTSEE

#define MUSTNOTSEE (   c,
 
)    (REQUIRE(!MORE() || PEEK() != (c), e))

Definition at line 266 of file regcomp.c.

◆ MUSTSEE

#define MUSTSEE (   c,
 
)    (REQUIRE(MORE() && PEEK() == (c), e))

Definition at line 264 of file regcomp.c.

◆ N

#define N   2

◆ never

#define never   0 /* some <assert.h>s have bugs too */

Definition at line 286 of file regcomp.c.

◆ NEXT

#define NEXT ( )    (p->next++)

Definition at line 258 of file regcomp.c.

◆ NEXT2

#define NEXT2 ( )    (p->next += 2)

Definition at line 259 of file regcomp.c.

◆ NEXTn

#define NEXTn (   n)    (p->next += (n))

Definition at line 260 of file regcomp.c.

◆ NPAREN

#define NPAREN   10 /* we need to remember () 1-9 for back refs */

Definition at line 201 of file regcomp.c.

◆ PEEK

#define PEEK ( )    (*p->next)

Definition at line 250 of file regcomp.c.

◆ PEEK2

#define PEEK2 ( )    (*(p->next+1))

Definition at line 251 of file regcomp.c.

◆ REP

#define REP (   f,
  t 
)    ((f)*8 + (t))

◆ REQUIRE

#define REQUIRE (   co,
 
)    (void)((co) || SETERROR(e))

Definition at line 263 of file regcomp.c.

◆ SEE

#define SEE (   c)    (MORE() && PEEK() == (c))

Definition at line 254 of file regcomp.c.

◆ SEETWO

#define SEETWO (   a,
  b 
)    (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b))

Definition at line 255 of file regcomp.c.

◆ SETERROR

#define SETERROR (   e)    seterr(p, (e))

Definition at line 262 of file regcomp.c.

◆ THERE

#define THERE ( )    (p->slen - 1)

Definition at line 272 of file regcomp.c.

◆ THERETHERE

#define THERETHERE ( )    (p->slen - 2)

Definition at line 273 of file regcomp.c.

Function Documentation

◆ allocset()

static cset * allocset ( struct parse p)
static

Definition at line 1194 of file regcomp.c.

References assert(), cset::hash, i, if(), cset::mask, cset::multis, p, cset::ptr, REG_ESPACE, SETERROR, and cset::smultis.

Referenced by p_bracket().

◆ bothcases()

static void bothcases ( struct parse p,
int  ch 
)
static

Definition at line 1047 of file regcomp.c.

References assert(), othercase(), p, and p_bracket().

Referenced by ordinary().

◆ categorize()

static void categorize ( struct parse p,
struct re_guts g 
)
static

Definition at line 1424 of file regcomp.c.

References c, c2(), g, isinsets(), p, and samesets().

Referenced by llvm_regcomp().

◆ doemit()

static void doemit ( struct parse p,
sop  op,
size_t  opnd 
)
static

Definition at line 1475 of file regcomp.c.

References assert(), enlarge(), op, OPSHIFT, p, and SOP.

◆ dofwd()

static void dofwd ( struct parse p,
sopno  pos,
sop  value 
)
static

Definition at line 1532 of file regcomp.c.

References assert(), OP, OPSHIFT, and p.

◆ doinsert()

static void doinsert ( struct parse p,
sop  op,
size_t  opnd,
sopno  pos 
)
static

Definition at line 1497 of file regcomp.c.

References assert(), EMIT, HERE, i, NPAREN, op, p, and s.

◆ dupl()

static sopno dupl ( struct parse p,
sopno  start,
sopno  finish 
)
static

Definition at line 1449 of file regcomp.c.

References assert(), enlarge(), HERE, p, and ret().

Referenced by p_ere_exp(), p_simp_re(), and repeat().

◆ enlarge()

static void enlarge ( struct parse p,
sopno  size 
)
static

Definition at line 1546 of file regcomp.c.

References p, REG_ESPACE, SETERROR, size, and sp.

Referenced by doemit(), and dupl().

◆ findmust()

static void findmust ( struct parse p,
struct re_guts g 
)
static

Definition at line 1597 of file regcomp.c.

References assert(), g, i, LLVM_FALLTHROUGH, O_CH, O_QUEST, OCH_, OCHAR, OEND, OLPAREN, OOR2, OP, OPLUS_, OPND, OQUEST_, ORPAREN, p, REGEX_BAD, s, and scan().

Referenced by llvm_regcomp().

◆ firstch()

static int firstch ( struct parse p,
cset cs 
)
static

Definition at line 1308 of file regcomp.c.

References assert(), CHIN, for, i, never, and p.

Referenced by p_bracket().

◆ freeset()

static void freeset ( struct parse p,
cset cs 
)
static

Definition at line 1255 of file regcomp.c.

References CHsub, for, i, and p.

Referenced by freezeset(), and p_bracket().

◆ freezeset()

static int freezeset ( struct parse p,
cset cs 
)
static

Definition at line 1277 of file regcomp.c.

References CHIN, for, freeset(), h, cset::hash, i, and p.

Referenced by p_bracket().

◆ isinsets()

static int isinsets ( struct re_guts g,
int  c 
)
static

Definition at line 1389 of file regcomp.c.

References c, g, and i.

Referenced by categorize().

◆ llvm_regcomp()

int llvm_regcomp ( llvm_regex_t preg,
const char *  pattern,
int  cflags 
)

◆ mcadd()

static void mcadd ( struct parse p,
cset cs,
const char *  cp 
)
static

Definition at line 1340 of file regcomp.c.

References llvm_strlcpy(), cset::multis, REG_ESPACE, SETERROR, and cset::smultis.

◆ mccase()

static void mccase ( struct parse p,
cset cs 
)
static

Definition at line 1380 of file regcomp.c.

References assert(), and cset::multis.

Referenced by p_bracket().

◆ mcinvert()

static void mcinvert ( struct parse p,
cset cs 
)
static

Definition at line 1367 of file regcomp.c.

References assert(), and cset::multis.

Referenced by p_bracket().

◆ nch()

static int nch ( struct parse p,
cset cs 
)
static

Definition at line 1324 of file regcomp.c.

References CHIN, for, i, n, and p.

Referenced by p_bracket().

◆ nonnewline()

static void nonnewline ( struct parse p)
static

Definition at line 1089 of file regcomp.c.

References assert(), p, and p_bracket().

Referenced by p_ere_exp(), and p_simp_re().

◆ ordinary()

static void ordinary ( struct parse p,
int  ch 
)
static

Definition at line 1070 of file regcomp.c.

References bothcases(), EMIT, OCHAR, othercase(), p, and REG_ICASE.

Referenced by p_bracket(), p_ere_exp(), p_simp_re(), and p_str().

◆ othercase()

static char othercase ( int  ch)
static

Definition at line 1029 of file regcomp.c.

References assert().

Referenced by bothcases(), ordinary(), and p_bracket().

◆ p_b_cclass()

static void p_b_cclass ( struct parse p,
cset cs 
)
static

Definition at line 939 of file regcomp.c.

References c, cclasses, CHadd, cclass::chars, MCadd, MORE, cclass::multis, cclass::name, NEXT, p, PEEK, REG_ECTYPE, SETERROR, and sp.

Referenced by p_b_term().

◆ p_b_coll_elem()

static char p_b_coll_elem ( struct parse p,
int  endc 
)
static

Definition at line 1002 of file regcomp.c.

References cnames, cname::code, MORE, cname::name, NEXT, p, REG_EBRACK, REG_ECOLLATE, SEETWO, SETERROR, and sp.

Referenced by p_b_eclass(), and p_b_symbol().

◆ p_b_eclass()

static void p_b_eclass ( struct parse p,
cset cs 
)
static

Definition at line 972 of file regcomp.c.

References c, CHadd, p, and p_b_coll_elem().

Referenced by p_b_term().

◆ p_b_symbol()

static char p_b_symbol ( struct parse p)
static

Definition at line 984 of file regcomp.c.

References EATTWO, GETNEXT, MORE, p, p_b_coll_elem(), REG_EBRACK, REG_ECOLLATE, and REQUIRE.

Referenced by p_b_term().

◆ p_b_term()

static void p_b_term ( struct parse p,
cset cs 
)
static

◆ p_bracket()

static void p_bracket ( struct parse p)
static

◆ p_bre()

static void p_bre ( struct parse p,
int  end1,
int  end2 
)
static

Definition at line 629 of file regcomp.c.

References DROP, EAT, EMIT, HERE, MORE, OBOL, OEOL, p, p_simp_re(), REG_EMPTY, REQUIRE, SEETWO, USEBOL, and USEEOL.

Referenced by llvm_regcomp(), and p_simp_re().

◆ p_count()

static int p_count ( struct parse p)
static

Definition at line 776 of file regcomp.c.

References llvm::count(), DUPMAX, GETNEXT, MORE, PEEK, REG_BADBR, and REQUIRE.

Referenced by p_ere_exp(), and p_simp_re().

◆ p_ere()

static void p_ere ( struct parse p,
int  stop 
)
static

Definition at line 393 of file regcomp.c.

References AHEAD, assert(), ASTERN, c, EAT, EMIT, HERE, INSERT, MORE, O_CH, OCH_, OOR1, OOR2, p, p_ere_exp(), PEEK, REG_EMPTY, REQUIRE, SEE, and THERE.

Referenced by llvm_regcomp(), and p_ere_exp().

◆ p_ere_exp()

static void p_ere_exp ( struct parse p)
static

◆ p_simp_re()

static int p_simp_re ( struct parse p,
int  starordinary 
)
static

◆ p_str()

static void p_str ( struct parse p)
static

Definition at line 611 of file regcomp.c.

References GETNEXT, MORE, ordinary(), p, REG_EMPTY, and REQUIRE.

Referenced by llvm_regcomp().

◆ pluscount()

static sopno pluscount ( struct parse p,
struct re_guts g 
)
static

Definition at line 1675 of file regcomp.c.

References g, O_PLUS, OEND, OP, OPLUS_, p, REGEX_BAD, s, and scan().

Referenced by llvm_regcomp().

◆ repeat()

static void repeat ( struct parse p,
sopno  start,
int  from,
int  to 
)
static

Definition at line 1111 of file regcomp.c.

References AHEAD, assert(), ASTERN, copy, DROP, dupl(), EMIT, HERE, INF, INSERT, MAP, N, O_CH, O_PLUS, OCH_, OOR1, OOR2, OPLUS_, p, REG_ASSERT, REP, SETERROR, THERE, THERETHERE, and to.

Referenced by p_ere_exp(), and p_simp_re().

◆ samesets()

static int samesets ( struct re_guts g,
int  c1,
int  c2 
)
static

Definition at line 1406 of file regcomp.c.

References c2(), g, and i.

Referenced by categorize().

◆ seterr()

static int seterr ( struct parse p,
int  e 
)
static

Definition at line 1181 of file regcomp.c.

References llvm::numbers::e, nuls, and p.

◆ stripsnug()

static void stripsnug ( struct parse p,
struct re_guts g 
)
static

Definition at line 1571 of file regcomp.c.

References g, p, REG_ESPACE, and SETERROR.

Referenced by llvm_regcomp().

Variable Documentation

◆ cclasses

struct cclass cclasses[]
static
Initial value:
= {
{ "alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789", ""} ,
{ "alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
""} ,
{ "blank", " \t", ""} ,
{ "cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
\25\26\27\30\31\32\33\34\35\36\37\177", ""} ,
{ "digit", "0123456789", ""} ,
{ "graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
""} ,
{ "lower", "abcdefghijklmnopqrstuvwxyz",
""} ,
{ "print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ",
""} ,
{ "punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
""} ,
{ "space", "\t\n\v\f\r ", ""} ,
{ "upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
""} ,
{ "xdigit", "0123456789ABCDEFabcdef",
""} ,
{ NULL, 0, "" }
}

Referenced by p_b_cclass().

◆ cnames

struct cname cnames[]
static

Referenced by p_b_coll_elem().

◆ nuls

char nuls[10]
static

Definition at line 244 of file regcomp.c.

Referenced by seterr().