1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-11 10:01:57 +03:00

Remove Value node struct

The Value node struct is a weird construct.  It is its own node type,
but most of the time, it actually has a node type of Integer, Float,
String, or BitString.  As a consequence, the struct name and the node
type don't match most of the time, and so it has to be treated
specially a lot.  There doesn't seem to be any value in the special
construct.  There is very little code that wants to accept all Value
variants but nothing else (and even if it did, this doesn't provide
any convenient way to check it), and most code wants either just one
particular node type (usually String), or it accepts a broader set of
node types besides just Value.

This change removes the Value struct and node type and replaces them
by separate Integer, Float, String, and BitString node types that are
proper node types and structs of their own and behave mostly like
normal node types.

Also, this removes the T_Null node tag, which was previously also a
possible variant of Value but wasn't actually used outside of the
Value contained in A_Const.  Replace that by an isnull field in
A_Const.

Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/5ba6bc5b-3f95-04f2-2419-f8ddb4c046fb@enterprisedb.com
This commit is contained in:
Peter Eisentraut
2021-09-09 07:58:12 +02:00
parent cbdf75bf80
commit 639a86e36a
30 changed files with 371 additions and 335 deletions

View File

@ -3414,44 +3414,39 @@ _outA_Expr(StringInfo str, const A_Expr *node)
}
static void
_outValue(StringInfo str, const Value *node)
_outInteger(StringInfo str, const Integer *node)
{
switch (node->type)
{
case T_Integer:
appendStringInfo(str, "%d", node->val.ival);
break;
case T_Float:
appendStringInfo(str, "%d", node->val);
}
/*
* We assume the value is a valid numeric literal and so does not
* need quoting.
*/
appendStringInfoString(str, node->val.str);
break;
case T_String:
static void
_outFloat(StringInfo str, const Float *node)
{
/*
* We assume the value is a valid numeric literal and so does not
* need quoting.
*/
appendStringInfoString(str, node->val);
}
/*
* We use outToken to provide escaping of the string's content,
* but we don't want it to do anything with an empty string.
*/
appendStringInfoChar(str, '"');
if (node->val.str[0] != '\0')
outToken(str, node->val.str);
appendStringInfoChar(str, '"');
break;
case T_BitString:
/* internal representation already has leading 'b' */
appendStringInfoString(str, node->val.str);
break;
case T_Null:
/* this is seen only within A_Const, not in transformed trees */
appendStringInfoString(str, "NULL");
break;
default:
elog(ERROR, "unrecognized node type: %d", (int) node->type);
break;
}
static void
_outString(StringInfo str, const String *node)
{
/*
* We use outToken to provide escaping of the string's content,
* but we don't want it to do anything with an empty string.
*/
appendStringInfoChar(str, '"');
if (node->val[0] != '\0')
outToken(str, node->val);
appendStringInfoChar(str, '"');
}
static void
_outBitString(StringInfo str, const BitString *node)
{
/* internal representation already has leading 'b' */
appendStringInfoString(str, node->val);
}
static void
@ -3491,8 +3486,13 @@ _outA_Const(StringInfo str, const A_Const *node)
{
WRITE_NODE_TYPE("A_CONST");
appendStringInfoString(str, " :val ");
_outValue(str, &(node->val));
if (node->isnull)
appendStringInfoString(str, "NULL");
else
{
appendStringInfoString(str, " :val ");
outNode(str, &node->val);
}
WRITE_LOCATION_FIELD(location);
}
@ -3835,14 +3835,15 @@ outNode(StringInfo str, const void *obj)
appendStringInfoString(str, "<>");
else if (IsA(obj, List) || IsA(obj, IntList) || IsA(obj, OidList))
_outList(str, obj);
else if (IsA(obj, Integer) ||
IsA(obj, Float) ||
IsA(obj, String) ||
IsA(obj, BitString))
{
/* nodeRead does not want to see { } around these! */
_outValue(str, obj);
}
/* nodeRead does not want to see { } around these! */
else if (IsA(obj, Integer))
_outInteger(str, (Integer *) obj);
else if (IsA(obj, Float))
_outFloat(str, (Float *) obj);
else if (IsA(obj, String))
_outString(str, (String *) obj);
else if (IsA(obj, BitString))
_outBitString(str, (BitString *) obj);
else
{
appendStringInfoChar(str, '{');