PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
regexport.c File Reference
#include "regex/regguts.h"
#include "regex/regexport.h"
Include dependency graph for regexport.c:

Go to the source code of this file.

Functions

int pg_reg_getnumstates (const regex_t *regex)
 
int pg_reg_getinitialstate (const regex_t *regex)
 
int pg_reg_getfinalstate (const regex_t *regex)
 
static void traverse_lacons (struct cnfa *cnfa, int st, int *arcs_count, regex_arc_t *arcs, int arcs_len)
 
int pg_reg_getnumoutarcs (const regex_t *regex, int st)
 
void pg_reg_getoutarcs (const regex_t *regex, int st, regex_arc_t *arcs, int arcs_len)
 
int pg_reg_getnumcolors (const regex_t *regex)
 
int pg_reg_colorisbegin (const regex_t *regex, int co)
 
int pg_reg_colorisend (const regex_t *regex, int co)
 
int pg_reg_getnumcharacters (const regex_t *regex, int co)
 
void pg_reg_getcharacters (const regex_t *regex, int co, pg_wchar *chars, int chars_len)
 

Function Documentation

◆ pg_reg_colorisbegin()

int pg_reg_colorisbegin ( const regex_t regex,
int  co 
)

Definition at line 191 of file regexport.c.

192{
193 struct cnfa *cnfa;
194
195 assert(regex != NULL && regex->re_magic == REMAGIC);
196 cnfa = &((struct guts *) regex->re_guts)->search;
197
198 if (co == cnfa->bos[0] || co == cnfa->bos[1])
199 return true;
200 else
201 return false;
202}
#define assert(x)
Definition: regcustom.h:56
#define REMAGIC
Definition: regguts.h:101
Definition: regguts.h:407
color bos[2]
Definition: regguts.h:417
Definition: regguts.h:531

References assert, cnfa::bos, and REMAGIC.

Referenced by addKey().

◆ pg_reg_colorisend()

int pg_reg_colorisend ( const regex_t regex,
int  co 
)

Definition at line 208 of file regexport.c.

209{
210 struct cnfa *cnfa;
211
212 assert(regex != NULL && regex->re_magic == REMAGIC);
213 cnfa = &((struct guts *) regex->re_guts)->search;
214
215 if (co == cnfa->eos[0] || co == cnfa->eos[1])
216 return true;
217 else
218 return false;
219}
color eos[2]
Definition: regguts.h:418

References assert, cnfa::eos, and REMAGIC.

Referenced by addKey().

◆ pg_reg_getcharacters()

void pg_reg_getcharacters ( const regex_t regex,
int  co,
pg_wchar chars,
int  chars_len 
)

Definition at line 266 of file regexport.c.

268{
269 struct colormap *cm;
270 chr c;
271
272 assert(regex != NULL && regex->re_magic == REMAGIC);
273 cm = &((struct guts *) regex->re_guts)->cmap;
274
275 if (co <= 0 || co > cm->max || chars_len <= 0)
276 return;
277 if (cm->cd[co].flags & PSEUDO)
278 return;
279
280 /*
281 * We need only examine the low character map; there should not be any
282 * matching entries in the high map.
283 */
284 for (c = CHR_MIN; c <= MAX_SIMPLE_CHR; c++)
285 {
286 if (cm->locolormap[c - CHR_MIN] == co)
287 {
288 *chars++ = c;
289 if (--chars_len == 0)
290 break;
291 }
292 }
293}
char * c
#define MAX_SIMPLE_CHR
Definition: regcustom.h:87
pg_wchar chr
Definition: regcustom.h:59
#define CHR_MIN
Definition: regcustom.h:65
#define PSEUDO
Definition: regguts.h:186
int flags
Definition: regguts.h:184
color * locolormap
Definition: regguts.h:240
size_t max
Definition: regguts.h:234
struct colordesc * cd
Definition: regguts.h:236
static char chars[TZ_MAX_CHARS]
Definition: zic.c:401

References assert, colormap::cd, chars, CHR_MIN, colordesc::flags, colormap::locolormap, colormap::max, MAX_SIMPLE_CHR, PSEUDO, and REMAGIC.

Referenced by getColorInfo().

◆ pg_reg_getfinalstate()

int pg_reg_getfinalstate ( const regex_t regex)

Definition at line 64 of file regexport.c.

65{
66 struct cnfa *cnfa;
67
68 assert(regex != NULL && regex->re_magic == REMAGIC);
69 cnfa = &((struct guts *) regex->re_guts)->search;
70
71 return cnfa->post;
72}
int post
Definition: regguts.h:416

References assert, cnfa::post, and REMAGIC.

Referenced by addKey().

◆ pg_reg_getinitialstate()

int pg_reg_getinitialstate ( const regex_t regex)

Definition at line 50 of file regexport.c.

51{
52 struct cnfa *cnfa;
53
54 assert(regex != NULL && regex->re_magic == REMAGIC);
55 cnfa = &((struct guts *) regex->re_guts)->search;
56
57 return cnfa->pre;
58}
int pre
Definition: regguts.h:415

References assert, cnfa::pre, and REMAGIC.

Referenced by transformGraph().

◆ pg_reg_getnumcharacters()

int pg_reg_getnumcharacters ( const regex_t regex,
int  co 
)

Definition at line 230 of file regexport.c.

231{
232 struct colormap *cm;
233
234 assert(regex != NULL && regex->re_magic == REMAGIC);
235 cm = &((struct guts *) regex->re_guts)->cmap;
236
237 if (co <= 0 || co > cm->max) /* <= 0 rejects WHITE and RAINBOW */
238 return -1;
239 if (cm->cd[co].flags & PSEUDO) /* also pseudocolors (BOS etc) */
240 return -1;
241
242 /*
243 * If the color appears anywhere in the high colormap, treat its number of
244 * members as uncertain. In principle we could determine all the specific
245 * chrs corresponding to each such entry, but it would be expensive
246 * (particularly if character class tests are required) and it doesn't
247 * seem worth it.
248 */
249 if (cm->cd[co].nuchrs != 0)
250 return -1;
251
252 /* OK, return the known number of member chrs */
253 return cm->cd[co].nschrs;
254}
int nuchrs
Definition: regguts.h:179
int nschrs
Definition: regguts.h:178

References assert, colormap::cd, colordesc::flags, colormap::max, colordesc::nschrs, colordesc::nuchrs, PSEUDO, and REMAGIC.

Referenced by getColorInfo().

◆ pg_reg_getnumcolors()

int pg_reg_getnumcolors ( const regex_t regex)

Definition at line 174 of file regexport.c.

175{
176 struct colormap *cm;
177
178 assert(regex != NULL && regex->re_magic == REMAGIC);
179 cm = &((struct guts *) regex->re_guts)->cmap;
180
181 return cm->max + 1;
182}

References assert, colormap::max, and REMAGIC.

Referenced by getColorInfo().

◆ pg_reg_getnumoutarcs()

int pg_reg_getnumoutarcs ( const regex_t regex,
int  st 
)

Definition at line 134 of file regexport.c.

135{
136 struct cnfa *cnfa;
137 int arcs_count;
138
139 assert(regex != NULL && regex->re_magic == REMAGIC);
140 cnfa = &((struct guts *) regex->re_guts)->search;
141
142 if (st < 0 || st >= cnfa->nstates)
143 return 0;
144 arcs_count = 0;
145 traverse_lacons(cnfa, st, &arcs_count, NULL, 0);
146 return arcs_count;
147}
static void traverse_lacons(struct cnfa *cnfa, int st, int *arcs_count, regex_arc_t *arcs, int arcs_len)
Definition: regexport.c:93
int nstates
Definition: regguts.h:408

References assert, cnfa::nstates, REMAGIC, and traverse_lacons().

Referenced by addArcs(), and addKey().

◆ pg_reg_getnumstates()

int pg_reg_getnumstates ( const regex_t regex)

Definition at line 36 of file regexport.c.

37{
38 struct cnfa *cnfa;
39
40 assert(regex != NULL && regex->re_magic == REMAGIC);
41 cnfa = &((struct guts *) regex->re_guts)->search;
42
43 return cnfa->nstates;
44}

References assert, cnfa::nstates, and REMAGIC.

◆ pg_reg_getoutarcs()

void pg_reg_getoutarcs ( const regex_t regex,
int  st,
regex_arc_t arcs,
int  arcs_len 
)

Definition at line 155 of file regexport.c.

157{
158 struct cnfa *cnfa;
159 int arcs_count;
160
161 assert(regex != NULL && regex->re_magic == REMAGIC);
162 cnfa = &((struct guts *) regex->re_guts)->search;
163
164 if (st < 0 || st >= cnfa->nstates || arcs_len <= 0)
165 return;
166 arcs_count = 0;
167 traverse_lacons(cnfa, st, &arcs_count, arcs, arcs_len);
168}

References assert, cnfa::nstates, REMAGIC, and traverse_lacons().

Referenced by addArcs(), and addKey().

◆ traverse_lacons()

static void traverse_lacons ( struct cnfa cnfa,
int  st,
int *  arcs_count,
regex_arc_t arcs,
int  arcs_len 
)
static

Definition at line 93 of file regexport.c.

96{
97 struct carc *ca;
98
99 /*
100 * Since this function recurses, it could theoretically be driven to stack
101 * overflow. In practice, this is mostly useful to backstop against a
102 * failure of the regex compiler to remove a loop of LACON arcs.
103 */
105
106 for (ca = cnfa->states[st]; ca->co != COLORLESS; ca++)
107 {
108 if (ca->co < cnfa->ncolors)
109 {
110 /* Ordinary arc, so count and possibly emit it */
111 int ndx = (*arcs_count)++;
112
113 if (ndx < arcs_len)
114 {
115 arcs[ndx].co = ca->co;
116 arcs[ndx].to = ca->to;
117 }
118 }
119 else
120 {
121 /* LACON arc --- assume it's satisfied and recurse... */
122 /* ... but first, assert it doesn't lead directly to post state */
123 Assert(ca->to != cnfa->post);
124
125 traverse_lacons(cnfa, ca->to, arcs_count, arcs, arcs_len);
126 }
127 }
128}
#define Assert(condition)
Definition: c.h:812
#define COLORLESS
Definition: regguts.h:158
void check_stack_depth(void)
Definition: stack_depth.c:95
Definition: regguts.h:401
int to
Definition: regguts.h:403
color co
Definition: regguts.h:402
struct carc ** states
Definition: regguts.h:421
int ncolors
Definition: regguts.h:409

References Assert, check_stack_depth(), regex_arc_t::co, carc::co, COLORLESS, cnfa::ncolors, cnfa::post, cnfa::states, regex_arc_t::to, carc::to, and traverse_lacons().

Referenced by pg_reg_getnumoutarcs(), pg_reg_getoutarcs(), and traverse_lacons().