Commit 6eefd242 authored by Tom Lane's avatar Tom Lane

Remove typedef celt from the regex library, along with macro NOCELT.

The regex library used to have a notion of a "collating element" that was
distinct from a "character", but Henry Spencer never actually implemented
his planned support for multi-character collating elements, and the Tcl
crew ripped out most of the stubs for that years ago.  The only thing left
that distinguished the "celt" typedef from the "chr" typedef was that
"celt" was supposed to also be able to hold the not-a-character "NOCELT"
value.  However, NOCELT was not used anywhere after the MCCE stub removal
changes, which means there's no need for celt to be different from chr.
Removing the separate typedef simplifies matters and also removes a trap
for the unwary, in that celt is signed while chr may not be, so comparisons
could mean different things.  There's no bug there today because we
restrict CHR_MAX to be less than INT_MAX, but I think there may have been
such bugs before we did that, and there could be again if anyone ever
decides to fool with the range of chr.

This patch also removes assorted unnecessary casts to "chr" of values
that are already chrs.  Many of these seem to be leftover from days when
the code was compatible with pre-ANSI C.
parent 5285c5e8
...@@ -78,7 +78,7 @@ addchr(struct cvec * cv, /* character vector */ ...@@ -78,7 +78,7 @@ addchr(struct cvec * cv, /* character vector */
chr c) /* character to add */ chr c) /* character to add */
{ {
assert(cv->nchrs < cv->chrspace); assert(cv->nchrs < cv->chrspace);
cv->chrs[cv->nchrs++] = (chr) c; cv->chrs[cv->nchrs++] = c;
} }
/* /*
...@@ -90,8 +90,8 @@ addrange(struct cvec * cv, /* character vector */ ...@@ -90,8 +90,8 @@ addrange(struct cvec * cv, /* character vector */
chr to) /* last character of range */ chr to) /* last character of range */
{ {
assert(cv->nranges < cv->rangespace); assert(cv->nranges < cv->rangespace);
cv->ranges[cv->nranges * 2] = (chr) from; cv->ranges[cv->nranges * 2] = from;
cv->ranges[cv->nranges * 2 + 1] = (chr) to; cv->ranges[cv->nranges * 2 + 1] = to;
cv->nranges++; cv->nranges++;
} }
......
...@@ -870,7 +870,7 @@ lexescape(struct vars * v) ...@@ -870,7 +870,7 @@ lexescape(struct vars * v)
if (v->now == save || ((int) c > 0 && (int) c <= v->nsubexp)) if (v->now == save || ((int) c > 0 && (int) c <= v->nsubexp))
{ {
NOTE(REG_UBACKREF); NOTE(REG_UBACKREF);
RETV(BACKREF, (chr) c); RETV(BACKREF, c);
} }
/* oops, doesn't look like it's a backref after all... */ /* oops, doesn't look like it's a backref after all... */
v->now = save; v->now = save;
...@@ -986,10 +986,8 @@ lexdigits(struct vars * v, ...@@ -986,10 +986,8 @@ lexdigits(struct vars * v,
*/ */
static int /* 1 normal, 0 failure */ static int /* 1 normal, 0 failure */
brenext(struct vars * v, brenext(struct vars * v,
chr pc) chr c)
{ {
chr c = (chr) pc;
switch (c) switch (c)
{ {
case CHR('*'): case CHR('*'):
...@@ -1153,7 +1151,7 @@ chrnamed(struct vars * v, ...@@ -1153,7 +1151,7 @@ chrnamed(struct vars * v,
const chr *endp, /* just past end of name */ const chr *endp, /* just past end of name */
chr lastresort) /* what to return if name lookup fails */ chr lastresort) /* what to return if name lookup fails */
{ {
celt c; chr c;
int errsave; int errsave;
int e; int e;
struct cvec *cv; struct cvec *cv;
...@@ -1165,10 +1163,10 @@ chrnamed(struct vars * v, ...@@ -1165,10 +1163,10 @@ chrnamed(struct vars * v,
v->err = errsave; v->err = errsave;
if (e != 0) if (e != 0)
return (chr) lastresort; return lastresort;
cv = range(v, c, c, 0); cv = range(v, c, c, 0);
if (cv->nchrs == 0) if (cv->nchrs == 0)
return (chr) lastresort; return lastresort;
return cv->chrs[0]; return cv->chrs[0];
} }
...@@ -361,9 +361,9 @@ static const struct cname ...@@ -361,9 +361,9 @@ static const struct cname
/* /*
* element - map collating-element name to celt * element - map collating-element name to chr
*/ */
static celt static chr
element(struct vars * v, /* context */ element(struct vars * v, /* context */
const chr *startp, /* points to start of name */ const chr *startp, /* points to start of name */
const chr *endp) /* points just past end of name */ const chr *endp) /* points just past end of name */
...@@ -401,13 +401,13 @@ element(struct vars * v, /* context */ ...@@ -401,13 +401,13 @@ element(struct vars * v, /* context */
*/ */
static struct cvec * static struct cvec *
range(struct vars * v, /* context */ range(struct vars * v, /* context */
celt a, /* range start */ chr a, /* range start */
celt b, /* range end, might equal a */ chr b, /* range end, might equal a */
int cases) /* case-independent? */ int cases) /* case-independent? */
{ {
int nchrs; int nchrs;
struct cvec *cv; struct cvec *cv;
celt c, chr c,
cc; cc;
if (a != b && !before(a, b)) if (a != b && !before(a, b))
...@@ -444,7 +444,7 @@ range(struct vars * v, /* context */ ...@@ -444,7 +444,7 @@ range(struct vars * v, /* context */
for (c = a; c <= b; c++) for (c = a; c <= b; c++)
{ {
cc = pg_wc_tolower((chr) c); cc = pg_wc_tolower(c);
if (cc != c && if (cc != c &&
(before(cc, a) || before(b, cc))) (before(cc, a) || before(b, cc)))
{ {
...@@ -455,7 +455,7 @@ range(struct vars * v, /* context */ ...@@ -455,7 +455,7 @@ range(struct vars * v, /* context */
} }
addchr(cv, cc); addchr(cv, cc);
} }
cc = pg_wc_toupper((chr) c); cc = pg_wc_toupper(c);
if (cc != c && if (cc != c &&
(before(cc, a) || before(b, cc))) (before(cc, a) || before(b, cc)))
{ {
...@@ -477,10 +477,10 @@ range(struct vars * v, /* context */ ...@@ -477,10 +477,10 @@ range(struct vars * v, /* context */
} }
/* /*
* before - is celt x before celt y, for purposes of range legality? * before - is chr x before chr y, for purposes of range legality?
*/ */
static int /* predicate */ static int /* predicate */
before(celt x, celt y) before(chr x, chr y)
{ {
if (x < y) if (x < y)
return 1; return 1;
...@@ -493,7 +493,7 @@ before(celt x, celt y) ...@@ -493,7 +493,7 @@ before(celt x, celt y)
*/ */
static struct cvec * static struct cvec *
eclass(struct vars * v, /* context */ eclass(struct vars * v, /* context */
celt c, /* Collating element representing the chr c, /* Collating element representing the
* equivalence class. */ * equivalence class. */
int cases) /* all cases? */ int cases) /* all cases? */
{ {
...@@ -503,12 +503,12 @@ eclass(struct vars * v, /* context */ ...@@ -503,12 +503,12 @@ eclass(struct vars * v, /* context */
if ((v->cflags & REG_FAKE) && c == 'x') if ((v->cflags & REG_FAKE) && c == 'x')
{ {
cv = getcvec(v, 4, 0); cv = getcvec(v, 4, 0);
addchr(cv, (chr) 'x'); addchr(cv, CHR('x'));
addchr(cv, (chr) 'y'); addchr(cv, CHR('y'));
if (cases) if (cases)
{ {
addchr(cv, (chr) 'X'); addchr(cv, CHR('X'));
addchr(cv, (chr) 'Y'); addchr(cv, CHR('Y'));
} }
return cv; return cv;
} }
...@@ -518,7 +518,7 @@ eclass(struct vars * v, /* context */ ...@@ -518,7 +518,7 @@ eclass(struct vars * v, /* context */
return allcases(v, c); return allcases(v, c);
cv = getcvec(v, 1, 0); cv = getcvec(v, 1, 0);
assert(cv != NULL); assert(cv != NULL);
addchr(cv, (chr) c); addchr(cv, c);
return cv; return cv;
} }
...@@ -673,15 +673,14 @@ cclass(struct vars * v, /* context */ ...@@ -673,15 +673,14 @@ cclass(struct vars * v, /* context */
*/ */
static struct cvec * static struct cvec *
allcases(struct vars * v, /* context */ allcases(struct vars * v, /* context */
chr pc) /* character to get case equivs of */ chr c) /* character to get case equivs of */
{ {
struct cvec *cv; struct cvec *cv;
chr c = (chr) pc;
chr lc, chr lc,
uc; uc;
lc = pg_wc_tolower((chr) c); lc = pg_wc_tolower(c);
uc = pg_wc_toupper((chr) c); uc = pg_wc_toupper(c);
cv = getcvec(v, 2, 0); cv = getcvec(v, 2, 0);
addchr(cv, lc); addchr(cv, lc);
......
...@@ -210,10 +210,10 @@ static pg_wchar pg_wc_toupper(pg_wchar c); ...@@ -210,10 +210,10 @@ static pg_wchar pg_wc_toupper(pg_wchar c);
static pg_wchar pg_wc_tolower(pg_wchar c); static pg_wchar pg_wc_tolower(pg_wchar c);
/* === regc_locale.c === */ /* === regc_locale.c === */
static celt element(struct vars *, const chr *, const chr *); static chr element(struct vars *, const chr *, const chr *);
static struct cvec *range(struct vars *, celt, celt, int); static struct cvec *range(struct vars *, chr, chr, int);
static int before(celt, celt); static int before(chr, chr);
static struct cvec *eclass(struct vars *, celt, int); static struct cvec *eclass(struct vars *, chr, int);
static struct cvec *cclass(struct vars *, const chr *, const chr *, int); static struct cvec *cclass(struct vars *, const chr *, const chr *, int);
static struct cvec *allcases(struct vars *, chr); static struct cvec *allcases(struct vars *, chr);
static int cmp(const chr *, const chr *, size_t); static int cmp(const chr *, const chr *, size_t);
...@@ -1424,8 +1424,8 @@ brackpart(struct vars * v, ...@@ -1424,8 +1424,8 @@ brackpart(struct vars * v,
struct state * lp, struct state * lp,
struct state * rp) struct state * rp)
{ {
celt startc; chr startc;
celt endc; chr endc;
struct cvec *cv; struct cvec *cv;
const chr *startp; const chr *startp;
const chr *endp; const chr *endp;
......
...@@ -58,15 +58,13 @@ ...@@ -58,15 +58,13 @@
/* internal character type and related */ /* internal character type and related */
typedef pg_wchar chr; /* the type itself */ typedef pg_wchar chr; /* the type itself */
typedef unsigned uchr; /* unsigned type that will hold a chr */ typedef unsigned uchr; /* unsigned type that will hold a chr */
typedef int celt; /* type to hold chr, or NOCELT */
#define NOCELT (-1) /* celt value which is not valid chr */
#define CHR(c) ((unsigned char) (c)) /* turn char literal into chr literal */ #define CHR(c) ((unsigned char) (c)) /* turn char literal into chr literal */
#define DIGITVAL(c) ((c)-'0') /* turn chr digit into its value */ #define DIGITVAL(c) ((c)-'0') /* turn chr digit into its value */
#define CHRBITS 32 /* bits in a chr; must not use sizeof */ #define CHRBITS 32 /* bits in a chr; must not use sizeof */
#define CHR_MIN 0x00000000 /* smallest and largest chr; the value */ #define CHR_MIN 0x00000000 /* smallest and largest chr; the value */
#define CHR_MAX 0x7ffffffe /* CHR_MAX-CHR_MIN+1 must fit in an int, and #define CHR_MAX 0x7ffffffe /* CHR_MAX-CHR_MIN+1 must fit in an int, and
* CHR_MAX+1 must fit in both chr and celt */ * CHR_MAX+1 must fit in a chr variable */
/* /*
* Check if a chr value is in range. Ideally we'd just write this as * Check if a chr value is in range. Ideally we'd just write this as
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment