PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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  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 MAX_COLOR   32767 /* max color (must fit in 'color' datatype) */
 
#define COLORLESS   (-1) /* impossible color */
 
#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 UNUSEDCOLOR(cd)   ((cd)->flags & FREECOL)
 
#define NUM_CCLASSES   13 /* must match data in regc_locale.c */
 
#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 ABSIZE   10
 
#define FREESTATE   (-1)
 
#define HASLACONS   01 /* uses lookaround constraints */
 
#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   (100000 * sizeof(struct state) + 100000 * sizeof(struct arcbatch))
 
#define LONGER   01 /* prefers longer match */
 
#define SHORTER   02 /* prefers shorter match */
 
#define MIXED   04 /* mixed preference below */
 
#define CAP   010 /* capturing parens below */
 
#define BACKR   020 /* back reference below */
 
#define INUSE   0100 /* in use in final tree */
 
#define NOPROP   03 /* bits which may not propagate up */
 
#define LMIX(f)   ((f)<<2) /* LONGER -> MIXED */
 
#define SMIX(f)   ((f)<<1) /* SHORTER -> MIXED */
 
#define UP(f)   (((f)&~NOPROP) | (LMIX(f) & SMIX(f) & MIXED))
 
#define MESSY(f)   ((f)&(MIXED|CAP|BACKR))
 
#define PREF(f)   ((f)&NOPROP)
 
#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
 

Functions

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

Macro Definition Documentation

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

Definition at line 82 of file regguts.h.

#define ABSIZE   10

Definition at line 294 of file regguts.h.

Referenced by allocarc().

#define BACKR   020 /* back reference below */

Definition at line 416 of file regguts.h.

Referenced by cdissect(), and parseqatom().

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

Definition at line 126 of file regguts.h.

Referenced by initialize(), and miss().

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

Definition at line 452 of file regguts.h.

Referenced by cdissect(), copyins(), copyouts(), mergeins(), miss(), moveins(), moveouts(), newarc(), newstate(), and range().

#define CAP   010 /* capturing parens below */

Definition at line 415 of file regguts.h.

Referenced by parseqatom().

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

Definition at line 215 of file regguts.h.

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

#define CMMAGIC   0x876

Definition at line 209 of file regguts.h.

Referenced by initcm().

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

Definition at line 365 of file regguts.h.

Referenced by compact(), and miss().

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

Definition at line 425 of file regguts.h.

Referenced by parseqatom().

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

Definition at line 58 of file regguts.h.

Referenced by next(), nfatree(), and pg_regcomp().

#define DUPINF   (DUPMAX+1)

Definition at line 94 of file regguts.h.

Referenced by cbrdissect(), citerdissect(), creviterdissect(), and parseqatom().

#define DUPMAX   _POSIX2_RE_DUP_MAX

Definition at line 93 of file regguts.h.

Referenced by scannum().

#define FDEBUG (   arglist)    {}

Definition at line 116 of file regguts.h.

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

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

Definition at line 284 of file regguts.h.

#define FREECOL   01 /* currently free */

Definition at line 163 of file regguts.h.

Referenced by freecolor().

#define FREESTATE   (-1)

Definition at line 301 of file regguts.h.

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

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

Definition at line 235 of file regguts.h.

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

#define GUTSMAGIC   0xfed9

Definition at line 465 of file regguts.h.

Referenced by pg_regcomp().

#define HASLACONS   01 /* uses lookaround constraints */

Definition at line 359 of file regguts.h.

Referenced by compact(), and miss().

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

Definition at line 417 of file regguts.h.

Referenced by cleanst(), and markst().

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

Definition at line 127 of file regguts.h.

Referenced by miss().

#define LATYPE_AHEAD_NEG   02 /* negative lookahead */

Definition at line 100 of file regguts.h.

Referenced by next(), and processlacon().

#define LATYPE_AHEAD_POS   03 /* positive lookahead */

Definition at line 99 of file regguts.h.

Referenced by next(), and processlacon().

#define LATYPE_BEHIND_NEG   00 /* negative lookbehind */

Definition at line 102 of file regguts.h.

Referenced by next(), and processlacon().

#define LATYPE_BEHIND_POS   01 /* positive lookbehind */

Definition at line 101 of file regguts.h.

Referenced by next(), and processlacon().

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

Definition at line 104 of file regguts.h.

Referenced by lacon(), and pg_regcomp().

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

Definition at line 103 of file regguts.h.

Referenced by lacon().

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

Definition at line 419 of file regguts.h.

#define LONGER   01 /* prefers longer match */

Definition at line 412 of file regguts.h.

Referenced by parse(), and parseqatom().

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

Definition at line 136 of file regguts.h.

Referenced by newcolor().

#define MDEBUG (   arglist)    {}
#define MESSY (   f)    ((f)&(MIXED|CAP|BACKR))

Definition at line 422 of file regguts.h.

Referenced by parse(), and parseqatom().

#define MIXED   04 /* mixed preference below */

Definition at line 414 of file regguts.h.

#define NINLINECDS   ((size_t) 10)

Definition at line 230 of file regguts.h.

Referenced by initcm().

#define NOPROP   03 /* bits which may not propagate up */

Definition at line 418 of file regguts.h.

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

Definition at line 159 of file regguts.h.

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

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

Definition at line 372 of file regguts.h.

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

#define NUM_CCLASSES   13 /* must match data in regc_locale.c */

Definition at line 197 of file regguts.h.

#define PREF (   f)    ((f)&NOPROP)

Definition at line 423 of file regguts.h.

Referenced by parseqatom().

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

Definition at line 424 of file regguts.h.

#define PSEUDO   02 /* pseudocolor, no real chars */
#define REG_MAX_COMPILE_SPACE   (100000 * sizeof(struct state) + 100000 * sizeof(struct arcbatch))

Definition at line 383 of file regguts.h.

Referenced by allocarc(), and newstate().

#define SHORTER   02 /* prefers shorter match */
#define SMIX (   f)    ((f)<<1) /* SHORTER -> MIXED */

Definition at line 420 of file regguts.h.

#define STACK_TOO_DEEP (   re)    ((*((struct fns *) (re)->re_fns)->stack_too_deep) ())
#define UBITS   (CHAR_BIT * sizeof(unsigned))

Definition at line 125 of file regguts.h.

Referenced by newdfa().

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

Definition at line 165 of file regguts.h.

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

#define UP (   f)    (((f)&~NOPROP) | (LMIX(f) & SMIX(f) & MIXED))

Definition at line 421 of file regguts.h.

Referenced by parse(), and parseqatom().

#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().

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

Definition at line 138 of file regguts.h.

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

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

Definition at line 371 of file regguts.h.

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

Typedef Documentation

typedef short color

Definition at line 134 of file regguts.h.

Function Documentation

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:37
color * hicolormap
Definition: regguts.h:224
int numcmranges
Definition: regguts.h:222
int hiarraycols
Definition: regguts.h:227
colormaprange * cmranges
Definition: regguts.h:223
static int cclass_column_index(struct colormap *cm, chr c)
Definition: regc_locale.c:672
#define MAX_SIMPLE_CHR
Definition: regcustom.h:97
void pg_set_regex_collation ( Oid  collation)

Definition at line 232 of file regc_pg_locale.c.

References C_COLLATION_OID, COLLPROVIDER_ICU, DEFAULT_COLLATION_OID, 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;
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 
266 #ifdef USE_ICU
269  else
270 #endif
271 #ifdef USE_WIDE_UPPER_LOWER
272  if (GetDatabaseEncoding() == PG_UTF8)
273  {
274  if (pg_regex_locale)
276  else
278  }
279  else
280 #endif /* USE_WIDE_UPPER_LOWER */
281  {
282  if (pg_regex_locale)
284  else
286  }
287 
288  pg_regex_collation = collation;
289  }
290 }
#define COLLPROVIDER_ICU
Definition: pg_collation.h:85
int errhint(const char *fmt,...)
Definition: elog.c:987
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:575
#define OidIsValid(objectId)
Definition: c.h:538
#define ERROR
Definition: elog.h:43
#define DEFAULT_COLLATION_OID
Definition: pg_collation.h:75
#define ereport(elevel, rest)
Definition: elog.h:122
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1265
int GetDatabaseEncoding(void)
Definition: mbutils.c:1015
#define C_COLLATION_OID
Definition: pg_collation.h:78
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1178