PostgreSQL Source Code  git master
regguts.h File Reference
#include "regcustom.h"
Include dependency graph for regguts.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  colordesc
 
struct  colormaprange
 
struct  colormap
 
struct  cvec
 
struct  arc
 
struct  arcbatch
 
struct  state
 
struct  statebatch
 
struct  nfa
 
struct  carc
 
struct  cnfa
 
struct  subre
 
struct  fns
 
struct  guts
 

Macros

#define DISCARD   void /* for throwing values away */
 
#define VS(x)   ((void *)(x)) /* cast something to generic ptr */
 
#define _POSIX2_RE_DUP_MAX   255 /* normally from <limits.h> */
 
#define NOTREACHED   0
 
#define DUPMAX   _POSIX2_RE_DUP_MAX
 
#define DUPINF   (DUPMAX+1)
 
#define REMAGIC   0xfed7 /* magic number for main struct */
 
#define LATYPE_AHEAD_POS   03 /* positive lookahead */
 
#define LATYPE_AHEAD_NEG   02 /* negative lookahead */
 
#define LATYPE_BEHIND_POS   01 /* positive lookbehind */
 
#define LATYPE_BEHIND_NEG   00 /* negative lookbehind */
 
#define LATYPE_IS_POS(la)   ((la) & 01)
 
#define LATYPE_IS_AHEAD(la)   ((la) & 02)
 
#define FDEBUG(arglist)   {}
 
#define MDEBUG(arglist)   {}
 
#define UBITS   (CHAR_BIT * sizeof(unsigned))
 
#define BSET(uv, sn)   ((uv)[(sn)/UBITS] |= (unsigned)1 << ((sn)%UBITS))
 
#define ISBSET(uv, sn)   ((uv)[(sn)/UBITS] & ((unsigned)1 << ((sn)%UBITS)))
 
#define NUM_CCLASSES   14
 
#define MAX_COLOR   32767 /* max color (must fit in 'color' datatype) */
 
#define COLORLESS   (-1) /* impossible color */
 
#define RAINBOW   (-2) /* represents all colors except pseudocolors */
 
#define WHITE   0 /* default color, parent of all others */
 
#define NOSUB   COLORLESS /* value of "sub" when no open subcolor */
 
#define FREECOL   01 /* currently free */
 
#define PSEUDO   02 /* pseudocolor, no real chars */
 
#define COLMARK   04 /* temporary marker used in some functions */
 
#define UNUSEDCOLOR(cd)   ((cd)->flags & FREECOL)
 
#define CMMAGIC   0x876
 
#define CDEND(cm)   (&(cm)->cd[(cm)->max + 1])
 
#define NINLINECDS   ((size_t) 10)
 
#define GETCOLOR(cm, c)   ((c) <= MAX_SIMPLE_CHR ? (cm)->locolormap[(c) - CHR_MIN] : pg_reg_getcolor(cm, c))
 
#define freechain   outchain /* we do not maintain "freechainRev" */
 
#define ARCBATCHSIZE(n)   ((n) * sizeof(struct arc) + offsetof(struct arcbatch, a))
 
#define FIRSTABSIZE   64
 
#define MAXABSIZE   1024
 
#define FREESTATE   (-1)
 
#define STATEBATCHSIZE(n)   ((n) * sizeof(struct state) + offsetof(struct statebatch, s))
 
#define FIRSTSBSIZE   32
 
#define MAXSBSIZE   1024
 
#define HASLACONS   01 /* uses lookaround constraints */
 
#define MATCHALL   02 /* matches all strings of a range of lengths */
 
#define CNFA_NOPROGRESS   01 /* flag bit for a no-progress state */
 
#define ZAPCNFA(cnfa)   ((cnfa).nstates = 0)
 
#define NULLCNFA(cnfa)   ((cnfa).nstates == 0)
 
#define REG_MAX_COMPILE_SPACE   (500000 * (sizeof(struct state) + 4 * sizeof(struct arc)))
 
#define LONGER   01 /* prefers longer match */
 
#define SHORTER   02 /* prefers shorter match */
 
#define MIXED   04 /* mixed preference below */
 
#define CAP   010 /* capturing parens here or below */
 
#define BACKR   020 /* back reference here or below */
 
#define BRUSE   040 /* is referenced by a back reference */
 
#define INUSE   0100 /* in use in final tree */
 
#define UPPROP   (MIXED|CAP|BACKR) /* flags which should propagate up */
 
#define LMIX(f)   ((f)<<2) /* LONGER -> MIXED */
 
#define SMIX(f)   ((f)<<1) /* SHORTER -> MIXED */
 
#define UP(f)   (((f)&UPPROP) | (LMIX(f) & SMIX(f) & MIXED))
 
#define MESSY(f)   ((f)&(MIXED|CAP|BACKR))
 
#define PREF(f)   ((f)&(LONGER|SHORTER))
 
#define PREF2(f1, f2)   ((PREF(f1) != 0) ? PREF(f1) : PREF(f2))
 
#define COMBINE(f1, f2)   (UP((f1)|(f2)) | PREF2(f1, f2))
 
#define CANCEL_REQUESTED(re)   ((*((struct fns *) (re)->re_fns)->cancel_requested) ())
 
#define STACK_TOO_DEEP(re)   ((*((struct fns *) (re)->re_fns)->stack_too_deep) ())
 
#define GUTSMAGIC   0xfed9
 

Typedefs

typedef short color
 
typedef struct colormaprange colormaprange
 

Enumerations

enum  char_classes {
  CC_ALNUM, CC_ALPHA, CC_ASCII, CC_BLANK,
  CC_CNTRL, CC_DIGIT, CC_GRAPH, CC_LOWER,
  CC_PRINT, CC_PUNCT, CC_SPACE, CC_UPPER,
  CC_XDIGIT, CC_WORD
}
 

Functions

void pg_set_regex_collation (Oid collation)
 
color pg_reg_getcolor (struct colormap *cm, chr c)
 

Macro Definition Documentation

◆ _POSIX2_RE_DUP_MAX

#define _POSIX2_RE_DUP_MAX   255 /* normally from <limits.h> */

Definition at line 82 of file regguts.h.

◆ ARCBATCHSIZE

#define ARCBATCHSIZE (   n)    ((n) * sizeof(struct arc) + offsetof(struct arcbatch, a))

Definition at line 312 of file regguts.h.

Referenced by allocarc(), and freenfa().

◆ BACKR

#define BACKR   020 /* back reference here or below */

Definition at line 479 of file regguts.h.

Referenced by cdissect(), parseqatom(), removecaptures(), and rstacktoodeep().

◆ BRUSE

#define BRUSE   040 /* is referenced by a back reference */

Definition at line 480 of file regguts.h.

Referenced by parseqatom(), removecaptures(), and rstacktoodeep().

◆ BSET

#define BSET (   uv,
  sn 
)    ((uv)[(sn)/UBITS] |= (unsigned)1 << ((sn)%UBITS))

Definition at line 126 of file regguts.h.

Referenced by initialize(), and miss().

◆ CANCEL_REQUESTED

#define CANCEL_REQUESTED (   re)    ((*((struct fns *) (re)->re_fns)->cancel_requested) ())

◆ CAP

#define CAP   010 /* capturing parens here or below */

Definition at line 478 of file regguts.h.

Referenced by parseqatom(), removecaptures(), and rstacktoodeep().

◆ CDEND

#define CDEND (   cm)    (&(cm)->cd[(cm)->max + 1])

Definition at line 232 of file regguts.h.

Referenced by colorcomplement(), okcolors(), optimizebracket(), and rainbow().

◆ CMMAGIC

#define CMMAGIC   0x876

Definition at line 226 of file regguts.h.

Referenced by initcm().

◆ CNFA_NOPROGRESS

#define CNFA_NOPROGRESS   01 /* flag bit for a no-progress state */

Definition at line 413 of file regguts.h.

Referenced by compact(), dumpnfa(), and miss().

◆ COLMARK

#define COLMARK   04 /* temporary marker used in some functions */

Definition at line 182 of file regguts.h.

Referenced by colorcomplement(), and optimizebracket().

◆ COLORLESS

◆ COMBINE

#define COMBINE (   f1,
  f2 
)    (UP((f1)|(f2)) | PREF2(f1, f2))

Definition at line 489 of file regguts.h.

Referenced by parseqatom().

◆ DISCARD

#define DISCARD   void /* for throwing values away */

Definition at line 58 of file regguts.h.

Referenced by nfatree(), and pg_regcomp().

◆ DUPINF

◆ DUPMAX

#define DUPMAX   _POSIX2_RE_DUP_MAX

Definition at line 93 of file regguts.h.

Referenced by scannum().

◆ FDEBUG

#define FDEBUG (   arglist)    {}

Definition at line 116 of file regguts.h.

Referenced by getvacant(), lacon(), longest(), matchuntil(), miss(), pickss(), and shortest().

◆ FIRSTABSIZE

#define FIRSTABSIZE   64

Definition at line 314 of file regguts.h.

Referenced by allocarc().

◆ FIRSTSBSIZE

#define FIRSTSBSIZE   32

Definition at line 340 of file regguts.h.

Referenced by newstate().

◆ freechain

#define freechain   outchain /* we do not maintain "freechainRev" */

Definition at line 298 of file regguts.h.

◆ FREECOL

#define FREECOL   01 /* currently free */

Definition at line 180 of file regguts.h.

Referenced by freecolor().

◆ FREESTATE

#define FREESTATE   (-1)

Definition at line 320 of file regguts.h.

Referenced by delsub(), deltraverse(), and freestate().

◆ GETCOLOR

#define GETCOLOR (   cm,
  c 
)    ((c) <= MAX_SIMPLE_CHR ? (cm)->locolormap[(c) - CHR_MIN] : pg_reg_getcolor(cm, c))

Definition at line 252 of file regguts.h.

Referenced by colorcomplement(), findprefix(), longest(), matchuntil(), and shortest().

◆ GUTSMAGIC

#define GUTSMAGIC   0xfed9

Definition at line 530 of file regguts.h.

Referenced by pg_regcomp(), and rstacktoodeep().

◆ HASLACONS

#define HASLACONS   01 /* uses lookaround constraints */

Definition at line 406 of file regguts.h.

Referenced by compact(), dumpnfa(), and miss().

◆ INUSE

#define INUSE   0100 /* in use in final tree */

Definition at line 481 of file regguts.h.

Referenced by cleanst(), markst(), and rstacktoodeep().

◆ ISBSET

#define ISBSET (   uv,
  sn 
)    ((uv)[(sn)/UBITS] & ((unsigned)1 << ((sn)%UBITS)))

Definition at line 127 of file regguts.h.

Referenced by miss().

◆ LATYPE_AHEAD_NEG

#define LATYPE_AHEAD_NEG   02 /* negative lookahead */

Definition at line 100 of file regguts.h.

Referenced by next(), processlacon(), and rstacktoodeep().

◆ LATYPE_AHEAD_POS

#define LATYPE_AHEAD_POS   03 /* positive lookahead */

Definition at line 99 of file regguts.h.

Referenced by next(), processlacon(), and rstacktoodeep().

◆ LATYPE_BEHIND_NEG

#define LATYPE_BEHIND_NEG   00 /* negative lookbehind */

Definition at line 102 of file regguts.h.

Referenced by next(), processlacon(), and rstacktoodeep().

◆ LATYPE_BEHIND_POS

#define LATYPE_BEHIND_POS   01 /* positive lookbehind */

Definition at line 101 of file regguts.h.

Referenced by next(), processlacon(), and rstacktoodeep().

◆ LATYPE_IS_AHEAD

#define LATYPE_IS_AHEAD (   la)    ((la) & 02)

Definition at line 104 of file regguts.h.

Referenced by lacon(), and pg_regcomp().

◆ LATYPE_IS_POS

#define LATYPE_IS_POS (   la)    ((la) & 01)

Definition at line 103 of file regguts.h.

Referenced by lacon().

◆ LMIX

#define LMIX (   f)    ((f)<<2) /* LONGER -> MIXED */

Definition at line 483 of file regguts.h.

◆ LONGER

#define LONGER   01 /* prefers longer match */

Definition at line 475 of file regguts.h.

Referenced by parse(), parseqatom(), and rstacktoodeep().

◆ MATCHALL

#define MATCHALL   02 /* matches all strings of a range of lengths */

Definition at line 407 of file regguts.h.

Referenced by checkmatchall(), dumpnfa(), longest(), makesearch(), matchuntil(), pg_regprefix(), and shortest().

◆ MAX_COLOR

#define MAX_COLOR   32767 /* max color (must fit in 'color' datatype) */

Definition at line 152 of file regguts.h.

Referenced by newcolor().

◆ MAXABSIZE

#define MAXABSIZE   1024

Definition at line 315 of file regguts.h.

Referenced by allocarc().

◆ MAXSBSIZE

#define MAXSBSIZE   1024

Definition at line 341 of file regguts.h.

Referenced by newstate().

◆ MDEBUG

#define MDEBUG (   arglist)    {}

◆ MESSY

#define MESSY (   f)    ((f)&(MIXED|CAP|BACKR))

Definition at line 486 of file regguts.h.

Referenced by parse(), and parseqatom().

◆ MIXED

#define MIXED   04 /* mixed preference below */

Definition at line 477 of file regguts.h.

Referenced by parseqatom(), removecaptures(), and rstacktoodeep().

◆ NINLINECDS

#define NINLINECDS   ((size_t) 10)

Definition at line 247 of file regguts.h.

Referenced by initcm().

◆ NOSUB

#define NOSUB   COLORLESS /* value of "sub" when no open subcolor */

Definition at line 176 of file regguts.h.

Referenced by freecolor(), initcm(), newcolor(), newsub(), okcolors(), and pseudocolor().

◆ NOTREACHED

#define NOTREACHED   0

◆ NULLCNFA

#define NULLCNFA (   cnfa)    ((cnfa).nstates == 0)

Definition at line 431 of file regguts.h.

Referenced by freecnfa(), freelacons(), freesrnode(), rfree(), and rstacktoodeep().

◆ NUM_CCLASSES

#define NUM_CCLASSES   14

Definition at line 139 of file regguts.h.

Referenced by bracket().

◆ PREF

#define PREF (   f)    ((f)&(LONGER|SHORTER))

Definition at line 487 of file regguts.h.

Referenced by parseqatom().

◆ PREF2

#define PREF2 (   f1,
  f2 
)    ((PREF(f1) != 0) ? PREF(f1) : PREF(f2))

Definition at line 488 of file regguts.h.

◆ PSEUDO

◆ RAINBOW

#define RAINBOW   (-2) /* represents all colors except pseudocolors */

◆ REG_MAX_COMPILE_SPACE

#define REG_MAX_COMPILE_SPACE   (500000 * (sizeof(struct state) + 4 * sizeof(struct arc)))

Definition at line 444 of file regguts.h.

Referenced by allocarc(), and newstate().

◆ REMAGIC

◆ SHORTER

#define SHORTER   02 /* prefers shorter match */

◆ SMIX

#define SMIX (   f)    ((f)<<1) /* SHORTER -> MIXED */

Definition at line 484 of file regguts.h.

◆ STACK_TOO_DEEP

#define STACK_TOO_DEEP (   re)    ((*((struct fns *) (re)->re_fns)->stack_too_deep) ())

◆ STATEBATCHSIZE

#define STATEBATCHSIZE (   n)    ((n) * sizeof(struct state) + offsetof(struct statebatch, s))

Definition at line 338 of file regguts.h.

Referenced by freenfa(), and newstate().

◆ UBITS

#define UBITS   (CHAR_BIT * sizeof(unsigned))

Definition at line 125 of file regguts.h.

Referenced by newdfa().

◆ UNUSEDCOLOR

#define UNUSEDCOLOR (   cd)    ((cd)->flags & FREECOL)

Definition at line 185 of file regguts.h.

Referenced by colorcomplement(), freecolor(), newcolor(), okcolors(), optimizebracket(), and rainbow().

◆ UP

#define UP (   f)    (((f)&UPPROP) | (LMIX(f) & SMIX(f) & MIXED))

Definition at line 485 of file regguts.h.

Referenced by parse(), and parseqatom().

◆ UPPROP

#define UPPROP   (MIXED|CAP|BACKR) /* flags which should propagate up */

Definition at line 482 of file regguts.h.

◆ VS

#define VS (   x)    ((void *)(x)) /* cast something to generic ptr */

Definition at line 61 of file regguts.h.

Referenced by cmp(), moresubs(), newcolor(), pg_regcomp(), and pg_regexec().

◆ WHITE

#define WHITE   0 /* default color, parent of all others */

Definition at line 155 of file regguts.h.

Referenced by freecolor(), initcm(), and pickss().

◆ ZAPCNFA

#define ZAPCNFA (   cnfa)    ((cnfa).nstates = 0)

Definition at line 429 of file regguts.h.

Referenced by freecnfa(), newlacon(), pg_regcomp(), and subre().

Typedef Documentation

◆ color

typedef short color

Definition at line 150 of file regguts.h.

◆ colormaprange

typedef struct colormaprange colormaprange

Enumeration Type Documentation

◆ char_classes

Enumerator
CC_ALNUM 
CC_ALPHA 
CC_ASCII 
CC_BLANK 
CC_CNTRL 
CC_DIGIT 
CC_GRAPH 
CC_LOWER 
CC_PRINT 
CC_PUNCT 
CC_SPACE 
CC_UPPER 
CC_XDIGIT 
CC_WORD 

Definition at line 133 of file regguts.h.

Function Documentation

◆ pg_reg_getcolor()

color pg_reg_getcolor ( struct colormap cm,
chr  c 
)

Definition at line 120 of file regc_color.c.

References assert, cclass_column_index(), colormap::cmranges, colormap::hiarraycols, colormap::hicolormap, MAX_SIMPLE_CHR, colormap::numcmranges, and colormaprange::rownum.

121 {
122  int rownum,
123  colnum,
124  low,
125  high;
126 
127  /* Should not be used for chrs in the locolormap */
129 
130  /*
131  * Find which row it's in. The colormapranges are in order, so we can use
132  * binary search.
133  */
134  rownum = 0; /* if no match, use array row zero */
135  low = 0;
136  high = cm->numcmranges;
137  while (low < high)
138  {
139  int middle = low + (high - low) / 2;
140  const colormaprange *cmr = &cm->cmranges[middle];
141 
142  if (c < cmr->cmin)
143  high = middle;
144  else if (c > cmr->cmax)
145  low = middle + 1;
146  else
147  {
148  rownum = cmr->rownum; /* found a match */
149  break;
150  }
151  }
152 
153  /*
154  * Find which column it's in --- this is all locale-dependent.
155  */
156  if (cm->hiarraycols > 1)
157  {
158  colnum = cclass_column_index(cm, c);
159  return cm->hicolormap[rownum * cm->hiarraycols + colnum];
160  }
161  else
162  {
163  /* fast path if no relevant cclasses */
164  return cm->hicolormap[rownum];
165  }
166 }
char * c
#define assert(TEST)
Definition: imath.c:73
color * hicolormap
Definition: regguts.h:241
int numcmranges
Definition: regguts.h:239
int hiarraycols
Definition: regguts.h:244
colormaprange * cmranges
Definition: regguts.h:240
static int cclass_column_index(struct colormap *cm, chr c)
Definition: regc_locale.c:675
#define MAX_SIMPLE_CHR
Definition: regcustom.h:95

◆ pg_set_regex_collation()

void pg_set_regex_collation ( Oid  collation)

Definition at line 232 of file regc_pg_locale.c.

References pg_locale_struct::deterministic, ereport, errcode(), errhint(), errmsg(), ERROR, GetDatabaseEncoding(), lc_ctype_is_c(), OidIsValid, pg_newlocale_from_collation(), pg_regex_collation, PG_REGEX_LOCALE_1BYTE, PG_REGEX_LOCALE_1BYTE_L, PG_REGEX_LOCALE_C, PG_REGEX_LOCALE_ICU, PG_REGEX_LOCALE_WIDE, PG_REGEX_LOCALE_WIDE_L, pg_regex_strategy, PG_UTF8, and pg_locale_struct::provider.

Referenced by pg_regcomp(), pg_regexec(), and pg_regprefix().

233 {
234  if (lc_ctype_is_c(collation))
235  {
236  /* C/POSIX collations use this path regardless of database encoding */
238  pg_regex_locale = 0;
239  pg_regex_collation = C_COLLATION_OID;
240  }
241  else
242  {
243  if (collation == DEFAULT_COLLATION_OID)
244  pg_regex_locale = 0;
245  else if (OidIsValid(collation))
246  {
247  /*
248  * NB: pg_newlocale_from_collation will fail if not HAVE_LOCALE_T;
249  * the case of pg_regex_locale != 0 but not HAVE_LOCALE_T does not
250  * have to be considered below.
251  */
253  }
254  else
255  {
256  /*
257  * This typically means that the parser could not resolve a
258  * conflict of implicit collations, so report it that way.
259  */
260  ereport(ERROR,
261  (errcode(ERRCODE_INDETERMINATE_COLLATION),
262  errmsg("could not determine which collation to use for regular expression"),
263  errhint("Use the COLLATE clause to set the collation explicitly.")));
264  }
265 
267  ereport(ERROR,
268  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
269  errmsg("nondeterministic collations are not supported for regular expressions")));
270 
271 #ifdef USE_ICU
272  if (pg_regex_locale && pg_regex_locale->provider == COLLPROVIDER_ICU)
274  else
275 #endif
276  if (GetDatabaseEncoding() == PG_UTF8)
277  {
278  if (pg_regex_locale)
280  else
282  }
283  else
284  {
285  if (pg_regex_locale)
287  else
289  }
290 
291  pg_regex_collation = collation;
292  }
293 }
int errhint(const char *fmt,...)
Definition: elog.c:1156
static pg_locale_t pg_regex_locale
static Oid pg_regex_collation
static PG_Locale_Strategy pg_regex_strategy
int errcode(int sqlerrcode)
Definition: elog.c:698
#define OidIsValid(objectId)
Definition: c.h:710
#define ERROR
Definition: elog.h:46
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1468
int GetDatabaseEncoding(void)
Definition: mbutils.c:1210
bool deterministic
Definition: pg_locale.h:85
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1371