mirror of
https://github.com/postgres/postgres.git
synced 2025-06-05 23:56:58 +03:00
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.
This commit is contained in:
parent
77d3b98c37
commit
c0cf5c37cd
@ -11,7 +11,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.613 2008/04/29 14:59:16 alvherre Exp $
|
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.614 2008/04/29 20:44:49 tgl Exp $
|
||||||
*
|
*
|
||||||
* HISTORY
|
* HISTORY
|
||||||
* AUTHOR DATE MAJOR EVENT
|
* AUTHOR DATE MAJOR EVENT
|
||||||
@ -95,6 +95,8 @@ static Node *makeStringConst(char *str);
|
|||||||
static Node *makeStringConstCast(char *str, TypeName *typename);
|
static Node *makeStringConstCast(char *str, TypeName *typename);
|
||||||
static Node *makeIntConst(int val);
|
static Node *makeIntConst(int val);
|
||||||
static Node *makeFloatConst(char *str);
|
static Node *makeFloatConst(char *str);
|
||||||
|
static Node *makeBitStringConst(char *str);
|
||||||
|
static Node *makeNullAConst(void);
|
||||||
static Node *makeAConst(Value *v);
|
static Node *makeAConst(Value *v);
|
||||||
static Node *makeBoolAConst(bool state);
|
static Node *makeBoolAConst(bool state);
|
||||||
static FuncCall *makeOverlaps(List *largs, List *rargs, int location);
|
static FuncCall *makeOverlaps(List *largs, List *rargs, int location);
|
||||||
@ -6395,9 +6397,7 @@ select_limit_value:
|
|||||||
| ALL
|
| ALL
|
||||||
{
|
{
|
||||||
/* LIMIT ALL is represented as a NULL constant */
|
/* LIMIT ALL is represented as a NULL constant */
|
||||||
A_Const *n = makeNode(A_Const);
|
$$ = makeNullAConst();
|
||||||
n->val.type = T_Null;
|
|
||||||
$$ = (Node *)n;
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -7409,11 +7409,9 @@ a_expr: c_expr { $$ = $1; }
|
|||||||
|
|
||||||
| a_expr SIMILAR TO a_expr %prec SIMILAR
|
| a_expr SIMILAR TO a_expr %prec SIMILAR
|
||||||
{
|
{
|
||||||
A_Const *c = makeNode(A_Const);
|
|
||||||
FuncCall *n = makeNode(FuncCall);
|
FuncCall *n = makeNode(FuncCall);
|
||||||
c->val.type = T_Null;
|
|
||||||
n->funcname = SystemFuncName("similar_escape");
|
n->funcname = SystemFuncName("similar_escape");
|
||||||
n->args = list_make2($4, (Node *) c);
|
n->args = list_make2($4, makeNullAConst());
|
||||||
n->agg_star = FALSE;
|
n->agg_star = FALSE;
|
||||||
n->agg_distinct = FALSE;
|
n->agg_distinct = FALSE;
|
||||||
n->location = @2;
|
n->location = @2;
|
||||||
@ -7431,11 +7429,9 @@ a_expr: c_expr { $$ = $1; }
|
|||||||
}
|
}
|
||||||
| a_expr NOT SIMILAR TO a_expr %prec SIMILAR
|
| a_expr NOT SIMILAR TO a_expr %prec SIMILAR
|
||||||
{
|
{
|
||||||
A_Const *c = makeNode(A_Const);
|
|
||||||
FuncCall *n = makeNode(FuncCall);
|
FuncCall *n = makeNode(FuncCall);
|
||||||
c->val.type = T_Null;
|
|
||||||
n->funcname = SystemFuncName("similar_escape");
|
n->funcname = SystemFuncName("similar_escape");
|
||||||
n->args = list_make2($5, (Node *) c);
|
n->args = list_make2($5, makeNullAConst());
|
||||||
n->agg_star = FALSE;
|
n->agg_star = FALSE;
|
||||||
n->agg_distinct = FALSE;
|
n->agg_distinct = FALSE;
|
||||||
n->location = @5;
|
n->location = @5;
|
||||||
@ -8251,11 +8247,7 @@ func_expr: func_name '(' ')'
|
|||||||
xml_root_version: VERSION_P a_expr
|
xml_root_version: VERSION_P a_expr
|
||||||
{ $$ = $2; }
|
{ $$ = $2; }
|
||||||
| VERSION_P NO VALUE_P
|
| VERSION_P NO VALUE_P
|
||||||
{
|
{ $$ = makeNullAConst(); }
|
||||||
A_Const *val = makeNode(A_Const);
|
|
||||||
val->val.type = T_Null;
|
|
||||||
$$ = (Node *) val;
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
opt_xml_root_standalone: ',' STANDALONE_P YES_P
|
opt_xml_root_standalone: ',' STANDALONE_P YES_P
|
||||||
@ -8409,10 +8401,7 @@ array_expr_list: array_expr { $$ = list_make1($1); }
|
|||||||
extract_list:
|
extract_list:
|
||||||
extract_arg FROM a_expr
|
extract_arg FROM a_expr
|
||||||
{
|
{
|
||||||
A_Const *n = makeNode(A_Const);
|
$$ = list_make2(makeStringConst($1), $3);
|
||||||
n->val.type = T_String;
|
|
||||||
n->val.val.str = $1;
|
|
||||||
$$ = list_make2((Node *) n, $3);
|
|
||||||
}
|
}
|
||||||
| /*EMPTY*/ { $$ = NIL; }
|
| /*EMPTY*/ { $$ = NIL; }
|
||||||
;
|
;
|
||||||
@ -8496,10 +8485,7 @@ substr_list:
|
|||||||
* which it is likely to do if the second argument
|
* which it is likely to do if the second argument
|
||||||
* is unknown or doesn't have an implicit cast to int4.
|
* is unknown or doesn't have an implicit cast to int4.
|
||||||
*/
|
*/
|
||||||
A_Const *n = makeNode(A_Const);
|
$$ = list_make3($1, makeIntConst(1),
|
||||||
n->val.type = T_Integer;
|
|
||||||
n->val.val.ival = 1;
|
|
||||||
$$ = list_make3($1, (Node *) n,
|
|
||||||
makeTypeCast($2, SystemTypeName("int4")));
|
makeTypeCast($2, SystemTypeName("int4")));
|
||||||
}
|
}
|
||||||
| expr_list
|
| expr_list
|
||||||
@ -8811,31 +8797,19 @@ func_name: type_function_name
|
|||||||
*/
|
*/
|
||||||
AexprConst: Iconst
|
AexprConst: Iconst
|
||||||
{
|
{
|
||||||
A_Const *n = makeNode(A_Const);
|
$$ = makeIntConst($1);
|
||||||
n->val.type = T_Integer;
|
|
||||||
n->val.val.ival = $1;
|
|
||||||
$$ = (Node *)n;
|
|
||||||
}
|
}
|
||||||
| FCONST
|
| FCONST
|
||||||
{
|
{
|
||||||
A_Const *n = makeNode(A_Const);
|
$$ = makeFloatConst($1);
|
||||||
n->val.type = T_Float;
|
|
||||||
n->val.val.str = $1;
|
|
||||||
$$ = (Node *)n;
|
|
||||||
}
|
}
|
||||||
| Sconst
|
| Sconst
|
||||||
{
|
{
|
||||||
A_Const *n = makeNode(A_Const);
|
$$ = makeStringConst($1);
|
||||||
n->val.type = T_String;
|
|
||||||
n->val.val.str = $1;
|
|
||||||
$$ = (Node *)n;
|
|
||||||
}
|
}
|
||||||
| BCONST
|
| BCONST
|
||||||
{
|
{
|
||||||
A_Const *n = makeNode(A_Const);
|
$$ = makeBitStringConst($1);
|
||||||
n->val.type = T_BitString;
|
|
||||||
n->val.val.str = $1;
|
|
||||||
$$ = (Node *)n;
|
|
||||||
}
|
}
|
||||||
| XCONST
|
| XCONST
|
||||||
{
|
{
|
||||||
@ -8844,10 +8818,7 @@ AexprConst: Iconst
|
|||||||
* a <general literal> shall not be a
|
* a <general literal> shall not be a
|
||||||
* <bit string literal> or a <hex string literal>.
|
* <bit string literal> or a <hex string literal>.
|
||||||
*/
|
*/
|
||||||
A_Const *n = makeNode(A_Const);
|
$$ = makeBitStringConst($1);
|
||||||
n->val.type = T_BitString;
|
|
||||||
n->val.val.str = $1;
|
|
||||||
$$ = (Node *)n;
|
|
||||||
}
|
}
|
||||||
| func_name Sconst
|
| func_name Sconst
|
||||||
{
|
{
|
||||||
@ -8893,9 +8864,7 @@ AexprConst: Iconst
|
|||||||
}
|
}
|
||||||
| NULL_P
|
| NULL_P
|
||||||
{
|
{
|
||||||
A_Const *n = makeNode(A_Const);
|
$$ = makeNullAConst();
|
||||||
n->val.type = T_Null;
|
|
||||||
$$ = (Node *)n;
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -9482,7 +9451,28 @@ makeFloatConst(char *str)
|
|||||||
n->val.type = T_Float;
|
n->val.type = T_Float;
|
||||||
n->val.val.str = str;
|
n->val.val.str = str;
|
||||||
|
|
||||||
return makeTypeCast((Node *)n, SystemTypeName("float8"));
|
return (Node *)n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Node *
|
||||||
|
makeBitStringConst(char *str)
|
||||||
|
{
|
||||||
|
A_Const *n = makeNode(A_Const);
|
||||||
|
|
||||||
|
n->val.type = T_BitString;
|
||||||
|
n->val.val.str = str;
|
||||||
|
|
||||||
|
return (Node *)n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Node *
|
||||||
|
makeNullAConst(void)
|
||||||
|
{
|
||||||
|
A_Const *n = makeNode(A_Const);
|
||||||
|
|
||||||
|
n->val.type = T_Null;
|
||||||
|
|
||||||
|
return (Node *)n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Node *
|
static Node *
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.96 2008/04/29 14:59:17 alvherre Exp $
|
* $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.97 2008/04/29 20:44:49 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -294,28 +294,11 @@ typenameTypeMod(ParseState *pstate, const TypeName *typename, Type typ)
|
|||||||
cstr = (char *) palloc(32);
|
cstr = (char *) palloc(32);
|
||||||
snprintf(cstr, 32, "%ld", (long) ac->val.val.ival);
|
snprintf(cstr, 32, "%ld", (long) ac->val.val.ival);
|
||||||
}
|
}
|
||||||
else
|
else if (IsA(&ac->val, Float) ||
|
||||||
|
IsA(&ac->val, String))
|
||||||
|
{
|
||||||
/* we can just use the str field directly. */
|
/* we can just use the str field directly. */
|
||||||
cstr = ac->val.val.str;
|
cstr = ac->val.val.str;
|
||||||
}
|
|
||||||
else if (IsA(tm, TypeCast))
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* The grammar hands back some integers with ::int4 attached, so
|
|
||||||
* allow a cast decoration if it's an Integer value, but not
|
|
||||||
* otherwise.
|
|
||||||
*/
|
|
||||||
TypeCast *tc = (TypeCast *) tm;
|
|
||||||
|
|
||||||
if (IsA(tc->arg, A_Const))
|
|
||||||
{
|
|
||||||
A_Const *ac = (A_Const *) tc->arg;
|
|
||||||
|
|
||||||
if (IsA(&ac->val, Integer))
|
|
||||||
{
|
|
||||||
cstr = (char *) palloc(32);
|
|
||||||
snprintf(cstr, 32, "%ld", (long) ac->val.val.ival);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IsA(tm, ColumnRef))
|
else if (IsA(tm, ColumnRef))
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.448 2008/04/29 14:59:17 alvherre Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.449 2008/04/29 20:44:49 tgl Exp $
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------
|
*--------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -5209,7 +5209,8 @@ flatten_set_variable_args(const char *name, List *args)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Each list member may be a plain A_Const node, or an A_Const within a
|
* Each list member may be a plain A_Const node, or an A_Const within a
|
||||||
* TypeCast, as produced by makeFloatConst() et al in gram.y.
|
* TypeCast; the latter case is supported only for ConstInterval
|
||||||
|
* arguments (for SET TIME ZONE).
|
||||||
*/
|
*/
|
||||||
foreach(l, args)
|
foreach(l, args)
|
||||||
{
|
{
|
||||||
@ -5231,8 +5232,8 @@ flatten_set_variable_args(const char *name, List *args)
|
|||||||
|
|
||||||
if (!IsA(arg, A_Const))
|
if (!IsA(arg, A_Const))
|
||||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
|
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
|
||||||
|
|
||||||
con = (A_Const *) arg;
|
con = (A_Const *) arg;
|
||||||
|
|
||||||
switch (nodeTag(&con->val))
|
switch (nodeTag(&con->val))
|
||||||
{
|
{
|
||||||
case T_Integer:
|
case T_Integer:
|
||||||
@ -5243,10 +5244,6 @@ flatten_set_variable_args(const char *name, List *args)
|
|||||||
appendStringInfoString(&buf, strVal(&con->val));
|
appendStringInfoString(&buf, strVal(&con->val));
|
||||||
break;
|
break;
|
||||||
case T_String:
|
case T_String:
|
||||||
/*
|
|
||||||
* Plain string literal or identifier. For quote mode,
|
|
||||||
* quote it if it's not a vanilla identifier.
|
|
||||||
*/
|
|
||||||
val = strVal(&con->val);
|
val = strVal(&con->val);
|
||||||
if (typename != NULL)
|
if (typename != NULL)
|
||||||
{
|
{
|
||||||
@ -5273,12 +5270,13 @@ flatten_set_variable_args(const char *name, List *args)
|
|||||||
DatumGetCString(DirectFunctionCall1(interval_out,
|
DatumGetCString(DirectFunctionCall1(interval_out,
|
||||||
interval));
|
interval));
|
||||||
appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
|
appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
|
||||||
|
|
||||||
/* don't leave this set */
|
|
||||||
typename = NULL;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Plain string literal or identifier. For quote mode,
|
||||||
|
* quote it if it's not a vanilla identifier.
|
||||||
|
*/
|
||||||
if (flags & GUC_LIST_QUOTE)
|
if (flags & GUC_LIST_QUOTE)
|
||||||
appendStringInfoString(&buf, quote_identifier(val));
|
appendStringInfoString(&buf, quote_identifier(val));
|
||||||
else
|
else
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.363 2008/04/29 14:59:17 alvherre Exp $
|
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.364 2008/04/29 20:44:49 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -228,12 +228,12 @@ typedef struct A_Expr
|
|||||||
} A_Expr;
|
} A_Expr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A_Const - a constant expression
|
* A_Const - a literal constant
|
||||||
*/
|
*/
|
||||||
typedef struct A_Const
|
typedef struct A_Const
|
||||||
{
|
{
|
||||||
NodeTag type;
|
NodeTag type;
|
||||||
Value val; /* the value (with the tag) */
|
Value val; /* value (includes type info, see value.h) */
|
||||||
} A_Const;
|
} A_Const;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user