Skip to content

Commit c0cf5c3

Browse files
committed
Some minor further cleanup around A_Const. Don't attach a typecast in
makeFloatConst, and avoid "manual" construction of A_Const nodes in grammar productions, in favor of using makeXXXConst subroutines.
1 parent 77d3b98 commit c0cf5c3

File tree

4 files changed

+52
-81
lines changed

4 files changed

+52
-81
lines changed

src/backend/parser/gram.y

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.613 2008/04/29 14:59:16 alvherre Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.614 2008/04/29 20:44:49 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -95,6 +95,8 @@ static Node *makeStringConst(char *str);
9595
static Node *makeStringConstCast(char *str, TypeName *typename);
9696
static Node *makeIntConst(int val);
9797
static Node *makeFloatConst(char *str);
98+
static Node *makeBitStringConst(char *str);
99+
static Node *makeNullAConst(void);
98100
static Node *makeAConst(Value *v);
99101
static Node *makeBoolAConst(bool state);
100102
static FuncCall *makeOverlaps(List *largs, List *rargs, int location);
@@ -6395,9 +6397,7 @@ select_limit_value:
63956397
| ALL
63966398
{
63976399
/* LIMIT ALL is represented as a NULL constant */
6398-
A_Const *n = makeNode(A_Const);
6399-
n->val.type = T_Null;
6400-
$$ = (Node *)n;
6400+
$$ = makeNullAConst();
64016401
}
64026402
;
64036403

@@ -7409,11 +7409,9 @@ a_expr: c_expr { $$ = $1; }
74097409

74107410
| a_expr SIMILAR TO a_expr %prec SIMILAR
74117411
{
7412-
A_Const *c = makeNode(A_Const);
74137412
FuncCall *n = makeNode(FuncCall);
7414-
c->val.type = T_Null;
74157413
n->funcname = SystemFuncName("similar_escape");
7416-
n->args = list_make2($4, (Node *) c);
7414+
n->args = list_make2($4, makeNullAConst());
74177415
n->agg_star = FALSE;
74187416
n->agg_distinct = FALSE;
74197417
n->location = @2;
@@ -7431,11 +7429,9 @@ a_expr: c_expr { $$ = $1; }
74317429
}
74327430
| a_expr NOT SIMILAR TO a_expr %prec SIMILAR
74337431
{
7434-
A_Const *c = makeNode(A_Const);
74357432
FuncCall *n = makeNode(FuncCall);
7436-
c->val.type = T_Null;
74377433
n->funcname = SystemFuncName("similar_escape");
7438-
n->args = list_make2($5, (Node *) c);
7434+
n->args = list_make2($5, makeNullAConst());
74397435
n->agg_star = FALSE;
74407436
n->agg_distinct = FALSE;
74417437
n->location = @5;
@@ -8251,11 +8247,7 @@ func_expr: func_name '(' ')'
82518247
xml_root_version: VERSION_P a_expr
82528248
{ $$ = $2; }
82538249
| VERSION_P NO VALUE_P
8254-
{
8255-
A_Const *val = makeNode(A_Const);
8256-
val->val.type = T_Null;
8257-
$$ = (Node *) val;
8258-
}
8250+
{ $$ = makeNullAConst(); }
82598251
;
82608252

82618253
opt_xml_root_standalone: ',' STANDALONE_P YES_P
@@ -8409,10 +8401,7 @@ array_expr_list: array_expr { $$ = list_make1($1); }
84098401
extract_list:
84108402
extract_arg FROM a_expr
84118403
{
8412-
A_Const *n = makeNode(A_Const);
8413-
n->val.type = T_String;
8414-
n->val.val.str = $1;
8415-
$$ = list_make2((Node *) n, $3);
8404+
$$ = list_make2(makeStringConst($1), $3);
84168405
}
84178406
| /*EMPTY*/ { $$ = NIL; }
84188407
;
@@ -8496,10 +8485,7 @@ substr_list:
84968485
* which it is likely to do if the second argument
84978486
* is unknown or doesn't have an implicit cast to int4.
84988487
*/
8499-
A_Const *n = makeNode(A_Const);
8500-
n->val.type = T_Integer;
8501-
n->val.val.ival = 1;
8502-
$$ = list_make3($1, (Node *) n,
8488+
$$ = list_make3($1, makeIntConst(1),
85038489
makeTypeCast($2, SystemTypeName("int4")));
85048490
}
85058491
| expr_list
@@ -8811,31 +8797,19 @@ func_name: type_function_name
88118797
*/
88128798
AexprConst: Iconst
88138799
{
8814-
A_Const *n = makeNode(A_Const);
8815-
n->val.type = T_Integer;
8816-
n->val.val.ival = $1;
8817-
$$ = (Node *)n;
8800+
$$ = makeIntConst($1);
88188801
}
88198802
| FCONST
88208803
{
8821-
A_Const *n = makeNode(A_Const);
8822-
n->val.type = T_Float;
8823-
n->val.val.str = $1;
8824-
$$ = (Node *)n;
8804+
$$ = makeFloatConst($1);
88258805
}
88268806
| Sconst
88278807
{
8828-
A_Const *n = makeNode(A_Const);
8829-
n->val.type = T_String;
8830-
n->val.val.str = $1;
8831-
$$ = (Node *)n;
8808+
$$ = makeStringConst($1);
88328809
}
88338810
| BCONST
88348811
{
8835-
A_Const *n = makeNode(A_Const);
8836-
n->val.type = T_BitString;
8837-
n->val.val.str = $1;
8838-
$$ = (Node *)n;
8812+
$$ = makeBitStringConst($1);
88398813
}
88408814
| XCONST
88418815
{
@@ -8844,10 +8818,7 @@ AexprConst: Iconst
88448818
* a <general literal> shall not be a
88458819
* <bit string literal> or a <hex string literal>.
88468820
*/
8847-
A_Const *n = makeNode(A_Const);
8848-
n->val.type = T_BitString;
8849-
n->val.val.str = $1;
8850-
$$ = (Node *)n;
8821+
$$ = makeBitStringConst($1);
88518822
}
88528823
| func_name Sconst
88538824
{
@@ -8893,9 +8864,7 @@ AexprConst: Iconst
88938864
}
88948865
| NULL_P
88958866
{
8896-
A_Const *n = makeNode(A_Const);
8897-
n->val.type = T_Null;
8898-
$$ = (Node *)n;
8867+
$$ = makeNullAConst();
88998868
}
89008869
;
89018870

@@ -9482,7 +9451,28 @@ makeFloatConst(char *str)
94829451
n->val.type = T_Float;
94839452
n->val.val.str = str;
94849453

9485-
return makeTypeCast((Node *)n, SystemTypeName("float8"));
9454+
return (Node *)n;
9455+
}
9456+
9457+
static Node *
9458+
makeBitStringConst(char *str)
9459+
{
9460+
A_Const *n = makeNode(A_Const);
9461+
9462+
n->val.type = T_BitString;
9463+
n->val.val.str = str;
9464+
9465+
return (Node *)n;
9466+
}
9467+
9468+
static Node *
9469+
makeNullAConst(void)
9470+
{
9471+
A_Const *n = makeNode(A_Const);
9472+
9473+
n->val.type = T_Null;
9474+
9475+
return (Node *)n;
94869476
}
94879477

94889478
static Node *

src/backend/parser/parse_type.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.96 2008/04/29 14:59:17 alvherre Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.97 2008/04/29 20:44:49 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -294,28 +294,11 @@ typenameTypeMod(ParseState *pstate, const TypeName *typename, Type typ)
294294
cstr = (char *) palloc(32);
295295
snprintf(cstr, 32, "%ld", (long) ac->val.val.ival);
296296
}
297-
else
297+
else if (IsA(&ac->val, Float) ||
298+
IsA(&ac->val, String))
299+
{
298300
/* we can just use the str field directly. */
299301
cstr = ac->val.val.str;
300-
}
301-
else if (IsA(tm, TypeCast))
302-
{
303-
/*
304-
* The grammar hands back some integers with ::int4 attached, so
305-
* allow a cast decoration if it's an Integer value, but not
306-
* otherwise.
307-
*/
308-
TypeCast *tc = (TypeCast *) tm;
309-
310-
if (IsA(tc->arg, A_Const))
311-
{
312-
A_Const *ac = (A_Const *) tc->arg;
313-
314-
if (IsA(&ac->val, Integer))
315-
{
316-
cstr = (char *) palloc(32);
317-
snprintf(cstr, 32, "%ld", (long) ac->val.val.ival);
318-
}
319302
}
320303
}
321304
else if (IsA(tm, ColumnRef))

src/backend/utils/misc/guc.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.448 2008/04/29 14:59:17 alvherre Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.449 2008/04/29 20:44:49 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -5209,7 +5209,8 @@ flatten_set_variable_args(const char *name, List *args)
52095209

52105210
/*
52115211
* Each list member may be a plain A_Const node, or an A_Const within a
5212-
* TypeCast, as produced by makeFloatConst() et al in gram.y.
5212+
* TypeCast; the latter case is supported only for ConstInterval
5213+
* arguments (for SET TIME ZONE).
52135214
*/
52145215
foreach(l, args)
52155216
{
@@ -5231,8 +5232,8 @@ flatten_set_variable_args(const char *name, List *args)
52315232

52325233
if (!IsA(arg, A_Const))
52335234
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
5234-
52355235
con = (A_Const *) arg;
5236+
52365237
switch (nodeTag(&con->val))
52375238
{
52385239
case T_Integer:
@@ -5243,10 +5244,6 @@ flatten_set_variable_args(const char *name, List *args)
52435244
appendStringInfoString(&buf, strVal(&con->val));
52445245
break;
52455246
case T_String:
5246-
/*
5247-
* Plain string literal or identifier. For quote mode,
5248-
* quote it if it's not a vanilla identifier.
5249-
*/
52505247
val = strVal(&con->val);
52515248
if (typename != NULL)
52525249
{
@@ -5273,12 +5270,13 @@ flatten_set_variable_args(const char *name, List *args)
52735270
DatumGetCString(DirectFunctionCall1(interval_out,
52745271
interval));
52755272
appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
5276-
5277-
/* don't leave this set */
5278-
typename = NULL;
52795273
}
52805274
else
52815275
{
5276+
/*
5277+
* Plain string literal or identifier. For quote mode,
5278+
* quote it if it's not a vanilla identifier.
5279+
*/
52825280
if (flags & GUC_LIST_QUOTE)
52835281
appendStringInfoString(&buf, quote_identifier(val));
52845282
else

src/include/nodes/parsenodes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.363 2008/04/29 14:59:17 alvherre Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.364 2008/04/29 20:44:49 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -228,12 +228,12 @@ typedef struct A_Expr
228228
} A_Expr;
229229

230230
/*
231-
* A_Const - a constant expression
231+
* A_Const - a literal constant
232232
*/
233233
typedef struct A_Const
234234
{
235235
NodeTag type;
236-
Value val; /* the value (with the tag) */
236+
Value val; /* value (includes type info, see value.h) */
237237
} A_Const;
238238

239239
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy