Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bc2187e

Browse files
Consistently use named parameters in regex code.
Make regex code consistently use named parameters in function declarations. Also make sure that parameter names from each function's declaration match corresponding definition parameter names. This makes Henry Spencer's regex code follow Postgres coding standards. Author: Peter Geoghegan <pg@bowt.ie> Reviewed-By: David Rowley <dgrowleyml@gmail.com> Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com
1 parent 55b4966 commit bc2187e

File tree

5 files changed

+241
-184
lines changed

5 files changed

+241
-184
lines changed

src/backend/regex/regcomp.c

+193-149
Original file line numberDiff line numberDiff line change
@@ -38,158 +38,200 @@
3838
* forward declarations, up here so forward datatypes etc. are defined early
3939
*/
4040
/* === regcomp.c === */
41-
static void moresubs(struct vars *, int);
42-
static int freev(struct vars *, int);
43-
static void makesearch(struct vars *, struct nfa *);
44-
static struct subre *parse(struct vars *, int, int, struct state *, struct state *);
45-
static struct subre *parsebranch(struct vars *, int, int, struct state *, struct state *, int);
46-
static struct subre *parseqatom(struct vars *, int, int, struct state *, struct state *, struct subre *);
47-
static void nonword(struct vars *, int, struct state *, struct state *);
48-
static void word(struct vars *, int, struct state *, struct state *);
49-
static void charclass(struct vars *, enum char_classes,
50-
struct state *, struct state *);
51-
static void charclasscomplement(struct vars *, enum char_classes,
52-
struct state *, struct state *);
53-
static int scannum(struct vars *);
54-
static void repeat(struct vars *, struct state *, struct state *, int, int);
55-
static void bracket(struct vars *, struct state *, struct state *);
56-
static void cbracket(struct vars *, struct state *, struct state *);
57-
static void brackpart(struct vars *, struct state *, struct state *, bool *);
58-
static const chr *scanplain(struct vars *);
59-
static void onechr(struct vars *, chr, struct state *, struct state *);
60-
static void optimizebracket(struct vars *, struct state *, struct state *);
61-
static void wordchrs(struct vars *);
62-
static void processlacon(struct vars *, struct state *, struct state *, int,
63-
struct state *, struct state *);
64-
static struct subre *subre(struct vars *, int, int, struct state *, struct state *);
65-
static void freesubre(struct vars *, struct subre *);
66-
static void freesubreandsiblings(struct vars *, struct subre *);
67-
static void freesrnode(struct vars *, struct subre *);
68-
static void removecaptures(struct vars *, struct subre *);
69-
static int numst(struct subre *, int);
70-
static void markst(struct subre *);
71-
static void cleanst(struct vars *);
72-
static long nfatree(struct vars *, struct subre *, FILE *);
73-
static long nfanode(struct vars *, struct subre *, int, FILE *);
74-
static int newlacon(struct vars *, struct state *, struct state *, int);
75-
static void freelacons(struct subre *, int);
76-
static void rfree(regex_t *);
41+
static void moresubs(struct vars *v, int wanted);
42+
static int freev(struct vars *v, int err);
43+
static void makesearch(struct vars *v, struct nfa *nfa);
44+
static struct subre *parse(struct vars *v, int stopper, int type,
45+
struct state *init, struct state *final);
46+
static struct subre *parsebranch(struct vars *v, int stopper, int type,
47+
struct state *left, struct state *right,
48+
int partial);
49+
static struct subre *parseqatom(struct vars *v, int stopper, int type,
50+
struct state *lp, struct state *rp,
51+
struct subre *top);
52+
static void nonword(struct vars *v, int dir, struct state *lp,
53+
struct state *rp);
54+
static void word(struct vars *v, int dir, struct state *lp, struct state *rp);
55+
static void charclass(struct vars *v, enum char_classes cls, struct state *lp,
56+
struct state *rp);
57+
static void charclasscomplement(struct vars *v, enum char_classes cls,
58+
struct state *lp, struct state *rp);
59+
static int scannum(struct vars *v);
60+
static void repeat(struct vars *v, struct state *lp, struct state *rp,
61+
int m, int n);
62+
static void bracket(struct vars *v, struct state *lp, struct state *rp);
63+
static void cbracket(struct vars *v, struct state *lp, struct state *rp);
64+
static void brackpart(struct vars *v, struct state *lp, struct state *rp,
65+
bool *have_cclassc);
66+
static const chr *scanplain(struct vars *v);
67+
static void onechr(struct vars *v, chr c, struct state *lp, struct state *rp);
68+
static void optimizebracket(struct vars *v, struct state *lp, struct state *rp);
69+
static void wordchrs(struct vars *v);
70+
static void processlacon(struct vars *v, struct state *begin,
71+
struct state *end, int latype,
72+
struct state *lp, struct state *rp);
73+
static struct subre *subre(struct vars *v, int op, int flags,
74+
struct state *begin, struct state *end);
75+
static void freesubre(struct vars *v, struct subre *sr);
76+
static void freesubreandsiblings(struct vars *v, struct subre *sr);
77+
static void freesrnode(struct vars *v, struct subre *sr);
78+
static void removecaptures(struct vars *v, struct subre *t);
79+
static int numst(struct subre *t, int start);
80+
static void markst(struct subre *t);
81+
static void cleanst(struct vars *v);
82+
static long nfatree(struct vars *v, struct subre *t, FILE *f);
83+
static long nfanode(struct vars *v, struct subre *t,
84+
int converttosearch, FILE *f);
85+
static int newlacon(struct vars *v, struct state *begin, struct state *end,
86+
int latype);
87+
static void freelacons(struct subre *subs, int n);
88+
static void rfree(regex_t *re);
7789
static int rcancelrequested(void);
7890
static int rstacktoodeep(void);
7991

8092
#ifdef REG_DEBUG
81-
static void dump(regex_t *, FILE *);
82-
static void dumpst(struct subre *, FILE *, int);
83-
static void stdump(struct subre *, FILE *, int);
84-
static const char *stid(struct subre *, char *, size_t);
93+
static void dump(regex_t *re, FILE *f);
94+
static void dumpst(struct subre *t, FILE *f, int nfapresent);
95+
static void stdump(struct subre *t, FILE *f, int nfapresent);
96+
static const char *stid(struct subre *t, char *buf, size_t bufsize);
8597
#endif
8698
/* === regc_lex.c === */
87-
static void lexstart(struct vars *);
88-
static void prefixes(struct vars *);
89-
static int next(struct vars *);
90-
static int lexescape(struct vars *);
91-
static chr lexdigits(struct vars *, int, int, int);
92-
static int brenext(struct vars *, chr);
93-
static void skip(struct vars *);
99+
static void lexstart(struct vars *v);
100+
static void prefixes(struct vars *v);
101+
static int next(struct vars *v);
102+
static int lexescape(struct vars *v);
103+
static chr lexdigits(struct vars *v, int base, int minlen, int maxlen);
104+
static int brenext(struct vars *v, chr c);
105+
static void skip(struct vars *v);
94106
static chr newline(void);
95-
static chr chrnamed(struct vars *, const chr *, const chr *, chr);
107+
static chr chrnamed(struct vars *v, const chr *startp, const chr *endp,
108+
chr lastresort);
96109

97110
/* === regc_color.c === */
98-
static void initcm(struct vars *, struct colormap *);
99-
static void freecm(struct colormap *);
100-
static color maxcolor(struct colormap *);
101-
static color newcolor(struct colormap *);
102-
static void freecolor(struct colormap *, color);
103-
static color pseudocolor(struct colormap *);
104-
static color subcolor(struct colormap *, chr);
105-
static color subcolorhi(struct colormap *, color *);
106-
static color newsub(struct colormap *, color);
107-
static int newhicolorrow(struct colormap *, int);
108-
static void newhicolorcols(struct colormap *);
109-
static void subcolorcvec(struct vars *, struct cvec *, struct state *, struct state *);
110-
static void subcoloronechr(struct vars *, chr, struct state *, struct state *, color *);
111-
static void subcoloronerange(struct vars *, chr, chr, struct state *, struct state *, color *);
112-
static void subcoloronerow(struct vars *, int, struct state *, struct state *, color *);
113-
static void okcolors(struct nfa *, struct colormap *);
114-
static void colorchain(struct colormap *, struct arc *);
115-
static void uncolorchain(struct colormap *, struct arc *);
116-
static void rainbow(struct nfa *, struct colormap *, int, color, struct state *, struct state *);
117-
static void colorcomplement(struct nfa *, struct colormap *, int, struct state *, struct state *, struct state *);
111+
static void initcm(struct vars *v, struct colormap *cm);
112+
static void freecm(struct colormap *cm);
113+
static color maxcolor(struct colormap *cm);
114+
static color newcolor(struct colormap *cm);
115+
static void freecolor(struct colormap *cm, color co);
116+
static color pseudocolor(struct colormap *cm);
117+
static color subcolor(struct colormap *cm, chr c);
118+
static color subcolorhi(struct colormap *cm, color *pco);
119+
static color newsub(struct colormap *cm, color co);
120+
static int newhicolorrow(struct colormap *cm, int oldrow);
121+
static void newhicolorcols(struct colormap *cm);
122+
static void subcolorcvec(struct vars *v, struct cvec *cv, struct state *lp,
123+
struct state *rp);
124+
static void subcoloronechr(struct vars *v, chr ch, struct state *lp,
125+
struct state *rp, color *lastsubcolor);
126+
static void subcoloronerange(struct vars *v, chr from, chr to,
127+
struct state *lp, struct state *rp,
128+
color *lastsubcolor);
129+
static void subcoloronerow(struct vars *v, int rownum, struct state *lp,
130+
struct state *rp, color *lastsubcolor);
131+
static void okcolors(struct nfa *nfa, struct colormap *cm);
132+
static void colorchain(struct colormap *cm, struct arc *a);
133+
static void uncolorchain(struct colormap *cm, struct arc *a);
134+
static void rainbow(struct nfa *nfa, struct colormap *cm, int type, color but,
135+
struct state *from, struct state *to);
136+
static void colorcomplement(struct nfa *nfa, struct colormap *cm, int type,
137+
struct state *of, struct state *from,
138+
struct state *to);
118139

119140
#ifdef REG_DEBUG
120-
static void dumpcolors(struct colormap *, FILE *);
121-
static void dumpchr(chr, FILE *);
141+
static void dumpcolors(struct colormap *cm, FILE *f);
142+
static void dumpchr(chr c, FILE *f);
122143
#endif
123144
/* === regc_nfa.c === */
124-
static struct nfa *newnfa(struct vars *, struct colormap *, struct nfa *);
125-
static void freenfa(struct nfa *);
126-
static struct state *newstate(struct nfa *);
127-
static struct state *newfstate(struct nfa *, int flag);
128-
static void dropstate(struct nfa *, struct state *);
129-
static void freestate(struct nfa *, struct state *);
130-
static void newarc(struct nfa *, int, color, struct state *, struct state *);
131-
static void createarc(struct nfa *, int, color, struct state *, struct state *);
132-
static struct arc *allocarc(struct nfa *);
133-
static void freearc(struct nfa *, struct arc *);
134-
static void changearcsource(struct arc *, struct state *);
135-
static void changearctarget(struct arc *, struct state *);
136-
static int hasnonemptyout(struct state *);
137-
static struct arc *findarc(struct state *, int, color);
138-
static void cparc(struct nfa *, struct arc *, struct state *, struct state *);
139-
static void sortins(struct nfa *, struct state *);
140-
static int sortins_cmp(const void *, const void *);
141-
static void sortouts(struct nfa *, struct state *);
142-
static int sortouts_cmp(const void *, const void *);
143-
static void moveins(struct nfa *, struct state *, struct state *);
144-
static void copyins(struct nfa *, struct state *, struct state *);
145-
static void mergeins(struct nfa *, struct state *, struct arc **, int);
146-
static void moveouts(struct nfa *, struct state *, struct state *);
147-
static void copyouts(struct nfa *, struct state *, struct state *);
148-
static void cloneouts(struct nfa *, struct state *, struct state *, struct state *, int);
149-
static void delsub(struct nfa *, struct state *, struct state *);
150-
static void deltraverse(struct nfa *, struct state *, struct state *);
151-
static void dupnfa(struct nfa *, struct state *, struct state *, struct state *, struct state *);
152-
static void duptraverse(struct nfa *, struct state *, struct state *);
153-
static void removeconstraints(struct nfa *, struct state *, struct state *);
154-
static void removetraverse(struct nfa *, struct state *);
155-
static void cleartraverse(struct nfa *, struct state *);
156-
static struct state *single_color_transition(struct state *, struct state *);
157-
static void specialcolors(struct nfa *);
158-
static long optimize(struct nfa *, FILE *);
159-
static void pullback(struct nfa *, FILE *);
160-
static int pull(struct nfa *, struct arc *, struct state **);
161-
static void pushfwd(struct nfa *, FILE *);
162-
static int push(struct nfa *, struct arc *, struct state **);
145+
static struct nfa *newnfa(struct vars *v, struct colormap *cm,
146+
struct nfa *parent);
147+
static void freenfa(struct nfa *nfa);
148+
static struct state *newstate(struct nfa *nfa);
149+
static struct state *newfstate(struct nfa *nfa, int flag);
150+
static void dropstate(struct nfa *nfa, struct state *s);
151+
static void freestate(struct nfa *nfa, struct state *s);
152+
static void newarc(struct nfa *nfa, int t, color co,
153+
struct state *from, struct state *to);
154+
static void createarc(struct nfa *nfa, int t, color co,
155+
struct state *from, struct state *to);
156+
static struct arc *allocarc(struct nfa *nfa);
157+
static void freearc(struct nfa *nfa, struct arc *victim);
158+
static void changearcsource(struct arc *a, struct state *newfrom);
159+
static void changearctarget(struct arc *a, struct state *newto);
160+
static int hasnonemptyout(struct state *s);
161+
static struct arc *findarc(struct state *s, int type, color co);
162+
static void cparc(struct nfa *nfa, struct arc *oa,
163+
struct state *from, struct state *to);
164+
static void sortins(struct nfa *nfa, struct state *s);
165+
static int sortins_cmp(const void *a, const void *b);
166+
static void sortouts(struct nfa *nfa, struct state *s);
167+
static int sortouts_cmp(const void *a, const void *b);
168+
static void moveins(struct nfa *nfa, struct state *oldState,
169+
struct state *newState);
170+
static void copyins(struct nfa *nfa, struct state *oldState,
171+
struct state *newState);
172+
static void mergeins(struct nfa *nfa, struct state *s,
173+
struct arc **arcarray, int arccount);
174+
static void moveouts(struct nfa *nfa, struct state *oldState,
175+
struct state *newState);
176+
static void copyouts(struct nfa *nfa, struct state *oldState,
177+
struct state *newState);
178+
static void cloneouts(struct nfa *nfa, struct state *old, struct state *from,
179+
struct state *to, int type);
180+
static void delsub(struct nfa *nfa, struct state *lp, struct state *rp);
181+
static void deltraverse(struct nfa *nfa, struct state *leftend,
182+
struct state *s);
183+
static void dupnfa(struct nfa *nfa, struct state *start, struct state *stop,
184+
struct state *from, struct state *to);
185+
static void duptraverse(struct nfa *nfa, struct state *s, struct state *stmp);
186+
static void removeconstraints(struct nfa *nfa, struct state *start, struct state *stop);
187+
static void removetraverse(struct nfa *nfa, struct state *s);
188+
static void cleartraverse(struct nfa *nfa, struct state *s);
189+
static struct state *single_color_transition(struct state *s1,
190+
struct state *s2);
191+
static void specialcolors(struct nfa *nfa);
192+
static long optimize(struct nfa *nfa, FILE *f);
193+
static void pullback(struct nfa *nfa, FILE *f);
194+
static int pull(struct nfa *nfa, struct arc *con,
195+
struct state **intermediates);
196+
static void pushfwd(struct nfa *nfa, FILE *f);
197+
static int push(struct nfa *nfa, struct arc *con,
198+
struct state **intermediates);
163199

164200
#define INCOMPATIBLE 1 /* destroys arc */
165201
#define SATISFIED 2 /* constraint satisfied */
166202
#define COMPATIBLE 3 /* compatible but not satisfied yet */
167203
#define REPLACEARC 4 /* replace arc's color with constraint color */
168204
static int combine(struct nfa *nfa, struct arc *con, struct arc *a);
169-
static void fixempties(struct nfa *, FILE *);
170-
static struct state *emptyreachable(struct nfa *, struct state *,
171-
struct state *, struct arc **);
172-
static int isconstraintarc(struct arc *);
173-
static int hasconstraintout(struct state *);
174-
static void fixconstraintloops(struct nfa *, FILE *);
175-
static int findconstraintloop(struct nfa *, struct state *);
176-
static void breakconstraintloop(struct nfa *, struct state *);
177-
static void clonesuccessorstates(struct nfa *, struct state *, struct state *,
178-
struct state *, struct arc *,
179-
char *, char *, int);
180-
static void cleanup(struct nfa *);
181-
static void markreachable(struct nfa *, struct state *, struct state *, struct state *);
182-
static void markcanreach(struct nfa *, struct state *, struct state *, struct state *);
183-
static long analyze(struct nfa *);
184-
static void checkmatchall(struct nfa *);
185-
static bool checkmatchall_recurse(struct nfa *, struct state *, bool **);
186-
static bool check_out_colors_match(struct state *, color, color);
187-
static bool check_in_colors_match(struct state *, color, color);
188-
static void compact(struct nfa *, struct cnfa *);
189-
static void carcsort(struct carc *, size_t);
190-
static int carc_cmp(const void *, const void *);
191-
static void freecnfa(struct cnfa *);
192-
static void dumpnfa(struct nfa *, FILE *);
205+
static void fixempties(struct nfa *nfa, FILE *f);
206+
static struct state *emptyreachable(struct nfa *nfa, struct state *s,
207+
struct state *lastfound,
208+
struct arc **inarcsorig);
209+
static int isconstraintarc(struct arc *a);
210+
static int hasconstraintout(struct state *s);
211+
static void fixconstraintloops(struct nfa *nfa, FILE *f);
212+
static int findconstraintloop(struct nfa *nfa, struct state *s);
213+
static void breakconstraintloop(struct nfa *nfa, struct state *sinitial);
214+
static void clonesuccessorstates(struct nfa *nfa, struct state *ssource,
215+
struct state *sclone,
216+
struct state *spredecessor,
217+
struct arc *refarc, char *curdonemap,
218+
char *outerdonemap, int nstates);
219+
static void cleanup(struct nfa *nfa);
220+
static void markreachable(struct nfa *nfa, struct state *s,
221+
struct state *okay, struct state *mark);
222+
static void markcanreach(struct nfa *nfa, struct state *s, struct state *okay,
223+
struct state *mark);
224+
static long analyze(struct nfa *nfa);
225+
static void checkmatchall(struct nfa *nfa);
226+
static bool checkmatchall_recurse(struct nfa *nfa, struct state *s,
227+
bool **haspaths);
228+
static bool check_out_colors_match(struct state *s, color co1, color co2);
229+
static bool check_in_colors_match(struct state *s, color co1, color co2);
230+
static void compact(struct nfa *nfa, struct cnfa *cnfa);
231+
static void carcsort(struct carc *first, size_t n);
232+
static int carc_cmp(const void *a, const void *b);
233+
static void freecnfa(struct cnfa *cnfa);
234+
static void dumpnfa(struct nfa *nfa, FILE *f);
193235

194236
#ifdef REG_DEBUG
195237
static void dumpstate(struct state *, FILE *);
@@ -199,12 +241,12 @@ static void dumpcnfa(struct cnfa *, FILE *);
199241
static void dumpcstate(int, struct cnfa *, FILE *);
200242
#endif
201243
/* === regc_cvec.c === */
202-
static struct cvec *newcvec(int, int);
203-
static struct cvec *clearcvec(struct cvec *);
204-
static void addchr(struct cvec *, chr);
205-
static void addrange(struct cvec *, chr, chr);
206-
static struct cvec *getcvec(struct vars *, int, int);
207-
static void freecvec(struct cvec *);
244+
static struct cvec *newcvec(int nchrs, int nranges);
245+
static struct cvec *clearcvec(struct cvec *cv);
246+
static void addchr(struct cvec *cv, chr c);
247+
static void addrange(struct cvec *cv, chr from, chr to);
248+
static struct cvec *getcvec(struct vars *v, int nchrs, int nranges);
249+
static void freecvec(struct cvec *cv);
208250

209251
/* === regc_pg_locale.c === */
210252
static int pg_wc_isdigit(pg_wchar c);
@@ -221,16 +263,18 @@ static pg_wchar pg_wc_toupper(pg_wchar c);
221263
static pg_wchar pg_wc_tolower(pg_wchar c);
222264

223265
/* === regc_locale.c === */
224-
static chr element(struct vars *, const chr *, const chr *);
225-
static struct cvec *range(struct vars *, chr, chr, int);
226-
static int before(chr, chr);
227-
static struct cvec *eclass(struct vars *, chr, int);
228-
static enum char_classes lookupcclass(struct vars *, const chr *, const chr *);
229-
static struct cvec *cclasscvec(struct vars *, enum char_classes, int);
230-
static int cclass_column_index(struct colormap *, chr);
231-
static struct cvec *allcases(struct vars *, chr);
232-
static int cmp(const chr *, const chr *, size_t);
233-
static int casecmp(const chr *, const chr *, size_t);
266+
static chr element(struct vars *v, const chr *startp, const chr *endp);
267+
static struct cvec *range(struct vars *v, chr a, chr b, int cases);
268+
static int before(chr x, chr y);
269+
static struct cvec *eclass(struct vars *v, chr c, int cases);
270+
static enum char_classes lookupcclass(struct vars *v, const chr *startp,
271+
const chr *endp);
272+
static struct cvec *cclasscvec(struct vars *v, enum char_classes cclasscode,
273+
int cases);
274+
static int cclass_column_index(struct colormap *cm, chr c);
275+
static struct cvec *allcases(struct vars *v, chr c);
276+
static int cmp(const chr *x, const chr *y, size_t len);
277+
static int casecmp(const chr *x, const chr *y, size_t len);
234278

235279

236280
/* internal variables, bundled for easy passing around */

0 commit comments

Comments
 (0)