/* want size of a char in bits, and max value in bounded quantifiers */ #ifndef _POSIX2_RE_DUP_MAX #define _POSIX2_RE_DUP_MAX 255/* normally from <limits.h> */ #endif
#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 */ /* Note: various places in the code know that WHITE is zero */
/* *Per-colordatastructureforthecompile-timecolormachinery * *If"sub"isnotNOSUBthenitisthenumberofthecolor'scurrent *subcolor,i.e.weareinprocessofdividingthiscolor(character *equivalenceclass)intotwocolors.Seesrc/backend/regex/READMEfor *discussionofsubcolors. * *Currently-unusedcolorshavetheFREECOLbitsetandarelinkedintoa *freelistusingtheir"sub"fields,butonlyiftheircolornumbersare *lessthancolormap.max.Anyarrayentriesbeyond"max"arejustgarbage.
*/ struct colordesc
{ int nschrs; /* number of simple chars of this color */ int nuchrs; /* number of upper map entries of this color */
color sub; /* open subcolor, if any; or free-chain ptr */ #define NOSUB COLORLESS /* value of "sub" when no open subcolor */ struct arc *arcs; /* chain of all arcs of this color */
chr firstchr; /* simple char first assigned to this color */ int flags; /* bitmask of the following flags: */ #define FREECOL 01/* currently free */ #define PSEUDO 02/* pseudocolor, no real chars */ #define COLMARK 04/* temporary marker used in some functions */
};
typedefstruct colormaprange
{
chr cmin; /* range represents cmin..cmax inclusive */
chr cmax; int rownum; /* row index in hicolormap array (>= 1) */
} colormaprange;
struct colormap
{ int magic; #define CMMAGIC 0x876 struct vars *v; /* for compile error reporting */
size_t ncds; /* allocated length of colordescs array */
size_t max; /* highest color number currently in use */
color free; /* beginning of free chain (if non-0) */ struct colordesc *cd; /* pointer to array of colordescs */ #define CDEND(cm) (&(cm)->cd[(cm)->max + 1])
/* mapping data for chrs <= MAX_SIMPLE_CHR: */
color *locolormap; /* simple array indexed by chr code */
/* mapping data for chrs > MAX_SIMPLE_CHR: */ int classbits[NUM_CCLASSES]; /* see comment above */ int numcmranges; /* number of colormapranges */
colormaprange *cmranges; /* ranges of high chrs */
color *hicolormap; /* 2-D array of color entries */ int maxarrayrows; /* number of array rows allocated */ int hiarrayrows; /* number of array rows in use */ int hiarraycols; /* number of array columns (2^N) */
/* If we need up to NINLINECDS, we store them here to save a malloc */ #define NINLINECDS ((size_t) 10) struct colordesc cdspace[NINLINECDS];
};
/* fetch color for chr; beware of multiple evaluation of c argument */ #define GETCOLOR(cm, c) \
((c) <= MAX_SIMPLE_CHR ? (cm)->locolormap[(c) - CHR_MIN] : pg_reg_getcolor(cm, c))
/* *Representationofasetofcharacters.chrs[]representsindividual *codepoints,ranges[]representsrangesintheformmin..maxinclusive. * *Ifthecvecrepresentsalocale-specificcharacterclass,eg[[:alpha:]], *thenthechrs[]andranges[]arrayscontainonlymembersofthatclass *uptoMAX_SIMPLE_CHR(inclusive).cclasscodeissettoregc_locale.c's *codefortheclass,ratherthanbeing-1asitisinanordinarycvec. * *Notethatincvecsgottenfromnewcvec()andintendedtobefreedby *freecvec(),botharraysofchrsareaftertheendofthestruct,not *separatelymalloc'd;sochrspaceandrangespaceareeffectivelyimmutable.
*/ struct cvec
{ int nchrs; /* number of chrs */ int chrspace; /* number of chrs allocated in chrs[] */
chr *chrs; /* pointer to vector of chrs */ int nranges; /* number of ranges (chr pairs) */ int rangespace; /* number of ranges allocated in ranges[] */
chr *ranges; /* pointer to vector of chr pairs */ int cclasscode; /* value of "enum classes", or -1 */
};
struct arc
{ int type; /* 0 if free, else an NFA arc type code */
color co; /* color the arc matches (possibly RAINBOW) */ struct state *from; /* where it's from */ struct state *to; /* where it's to */ struct arc *outchain; /* link in *from's outs chain or free chain */ struct arc *outchainRev; /* back-link in *from's outs chain */ #define freechain outchain /* we do not maintain "freechainRev" */ struct arc *inchain; /* link in *to's ins chain */ struct arc *inchainRev; /* back-link in *to's ins chain */ /* these fields are not used when co == RAINBOW: */ struct arc *colorchain; /* link in color's arc chain */ struct arc *colorchainRev; /* back-link in color's arc chain */
};
struct arcbatch
{ /* for bulk allocation of arcs */ struct arcbatch *next; /* chain link */
size_t narcs; /* number of arcs allocated in this arcbatch */ struct arc a[FLEXIBLE_ARRAY_MEMBER];
}; #define ARCBATCHSIZE(n) ((n) * sizeof(struct arc) + offsetof(struct arcbatch, a)) /* first batch will have FIRSTABSIZE arcs; then double it until MAXABSIZE */ #define FIRSTABSIZE 64 #define MAXABSIZE 1024
struct state
{ int no; /* state number, zero and up; or FREESTATE */ #define FREESTATE (-1) char flag; /* marks special states */ int nins; /* number of inarcs */ int nouts; /* number of outarcs */ struct arc *ins; /* chain of inarcs */ struct arc *outs; /* chain of outarcs */ struct state *tmp; /* temporary for traversal algorithms */ struct state *next; /* chain for traversing all live states */ /* the "next" field is also used to chain free states together */ struct state *prev; /* back-link in chain of all live states */
};
struct statebatch
{ /* for bulk allocation of states */ struct statebatch *next; /* chain link */
size_t nstates; /* number of states allocated in this batch */ struct state s[FLEXIBLE_ARRAY_MEMBER];
}; #define STATEBATCHSIZE(n) ((n) * sizeof(struct state) + offsetof(struct statebatch, s)) /* first batch will have FIRSTSBSIZE states; then double it until MAXSBSIZE */ #define FIRSTSBSIZE 32 #define MAXSBSIZE 1024
struct nfa
{ struct state *pre; /* pre-initial state */ struct state *init; /* initial state */ struct state *final; /* final state */ struct state *post; /* post-final state */ int nstates; /* for numbering states */ struct state *states; /* chain of live states */ struct state *slast; /* tail of the chain */ struct state *freestates; /* chain of free states */ struct arc *freearcs; /* chain of free arcs */ struct statebatch *lastsb; /* chain of statebatches */ struct arcbatch *lastab; /* chain of arcbatches */
size_t lastsbused; /* number of states consumed from *lastsb */
size_t lastabused; /* number of arcs consumed from *lastab */ struct colormap *cm; /* the color map */
color bos[2]; /* colors, if any, assigned to BOS and BOL */
color eos[2]; /* colors, if any, assigned to EOS and EOL */ int flags; /* flags to pass forward to cNFA */ int minmatchall; /* min number of chrs to match, if matchall */ int maxmatchall; /* max number of chrs to match, or DUPINF */ struct vars *v; /* simplifies compile error reporting */ struct nfa *parent; /* parent NFA, if any */
};
/* *definitionsforcompactedNFA * *ThemainspacesavingsinacompactedNFAisfrommakingthearcsassmall *aspossible.Westoreonlythetransitioncolorandnext-statenumberfor *eacharc.Thelistofoutarcsforeachstateisanarraybeginningat *cnfa.states[statenumber],andterminatedbyadummycarcstructwith *co==COLORLESS. * *Thenon-dummycarcstructsareoftwotypes:plainarcsandLACONarcs. *Plainarcsjuststorethetransitioncolornumberas"co".LACONarcs *storethelookaroundconstraintnumberpluscnfa.ncolorsas"co".LACON *arcscanbedistinguishedfromplainbytestingforco>=cnfa.ncolors. * *Notethatinaplainarc,"co"canbeRAINBOW;sincethat'snegative, *itdoesn'tbreaktheruleabouthowtorecognizeLACONarcs. * *Wehavespecialmarkingsfor"trivial"NFAsthatcanmatchanystring *(possiblywithlimitsonthenumberofcharacterstherein).Insucha *case,flags&MATCHALLisset(andHASLACONScan'tbeset).Thenthe *fieldsminmatchallandmaxmatchallgivetheminimumandmaximumnumbers *ofcharacterstomatch.Forexample,".*"producesminmatchall=0 *andmaxmatchall=DUPINF,while".+"producesminmatchall=1and *maxmatchall=DUPINF.
*/ struct carc
{
color co; /* COLORLESS is list terminator */ int to; /* next-state number */
};
struct cnfa
{ int nstates; /* number of states */ int ncolors; /* number of colors (max color in use + 1) */ int flags; /* bitmask of the following flags: */ #define HASLACONS 01/* uses lookaround constraints */ #define MATCHALL 02/* matches all strings of a range of lengths */ #define HASCANTMATCH 04/* contains CANTMATCH arcs */ /* Note: HASCANTMATCH appears in nfa structs' flags, but never in cnfas */ int pre; /* setup state number */ int post; /* teardown state number */
color bos[2]; /* colors, if any, assigned to BOS and BOL */
color eos[2]; /* colors, if any, assigned to EOS and EOL */ char *stflags; /* vector of per-state flags bytes */ #define CNFA_NOPROGRESS 01/* flag bit for a no-progress state */ struct carc **states; /* vector of pointers to outarc lists */ /* states[n] are pointers into a single malloc'd array of arcs */ struct carc *arcs; /* the area for the lists */ /* these fields are used only in a MATCHALL NFA (else they're -1): */ int minmatchall; /* min number of chrs to match */ int maxmatchall; /* max number of chrs to match, or DUPINF */
};
/* *subexpressiontree * *"op"isoneof: *'='plainregexwithoutinterestingsubstructure(implementedasDFA) *'b'back-reference(hasnosubstructureeither) *'('no-opcapturenode:capturesthematchofitssinglechild *'.'concatenation:matchesamatchforfirstchild,thensecondchild *'|'alternation:matchesamatchforanyofitschildren *'*'iteration:matchessomenumberofmatchesofitssinglechild * *Analternationnodecanhaveanynumberofchildren(butatleasttwo), *linkedthroughtheirsiblingfields. * *Aconcatenationnodemusthaveexactlytwochildren.Itmightbeuseful *tosupportmore,butthatwouldcomplicatetheexecutor.Notethatitis *thefirstchild'sgreedinessthatdeterminesthenode'spreferencefor *wheretosplitamatch. * *Note:whenabackrefisdirectlyquantified,westickthemin/maxcounts *intothebackrefratherthanplasteringaniterationnodeontop.Thisis *forefficiency:thereisnoneedtosearchforpossibledivisionpoints.
*/ struct subre
{ char op; /* see type codes above */ char flags; #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)) char latype; /* LATYPE code, if lookaround constraint */ int id; /* ID of subre (1..ntree-1) */ int capno; /* if capture node, subno to capture into */ int backno; /* if backref node, subno it refers to */ short min; /* min repetitions for iteration or backref */ short max; /* max repetitions for iteration or backref */ struct subre *child; /* first child, if any (also freelist chain) */ struct subre *sibling; /* next child of same parent, if any */ struct state *begin; /* outarcs from here... */ struct state *end; /* ...ending in inarcs here */ struct cnfa cnfa; /* compacted NFA, if any */ struct subre *chain; /* for bookkeeping and error cleanup */
};
/* *theinsidesofaregex_t,hiddenbehindavoid*
*/ struct guts
{ int magic; #define GUTSMAGIC 0xfed9 int cflags; /* copy of compile flags */ long info; /* copy of re_info */
size_t nsub; /* copy of re_nsub */ struct subre *tree; struct cnfa search; /* for fast preliminary search */ int ntree; /* number of subre's, plus one */ struct colormap cmap; int FUNCPTR(compare, (const chr *, const chr *, size_t)); struct subre *lacons; /* lookaround-constraint vector */ int nlacons; /* size of lacons[]; note that only slots
* numbered 1 .. nlacons-1 are used */
};
/* prototypes for functions that are exported from regcomp.c to regexec.c */ externvoid pg_set_regex_collation(Oid collation); extern color pg_reg_getcolor(struct colormap *cm, chr c);
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.17Bemerkung:
(vorverarbeitet am 2026-08-05)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.