mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Rename value node fields
For the formerly-Value node types, rename the "val" field to a name specific to the node type, namely "ival", "fval", "sval", and "bsval". This makes some code clearer and catches mixups better. Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/8c1a2e37-c68d-703c-5a83-7a6077f4f997@enterprisedb.com
This commit is contained in:
parent
93415a3b5a
commit
c4cc2850f4
@ -58,7 +58,7 @@ defGetString(DefElem *def)
|
||||
case T_Integer:
|
||||
return psprintf("%ld", (long) intVal(def->arg));
|
||||
case T_Float:
|
||||
return castNode(Float, def->arg)->val;
|
||||
return castNode(Float, def->arg)->fval;
|
||||
case T_String:
|
||||
return strVal(def->arg);
|
||||
case T_TypeName:
|
||||
@ -201,7 +201,7 @@ defGetInt64(DefElem *def)
|
||||
* strings.
|
||||
*/
|
||||
return DatumGetInt64(DirectFunctionCall1(int8in,
|
||||
CStringGetDatum(castNode(Float, def->arg)->val)));
|
||||
CStringGetDatum(castNode(Float, def->arg)->fval)));
|
||||
default:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
|
@ -2745,16 +2745,16 @@ _copyA_Const(const A_Const *from)
|
||||
switch (nodeTag(&from->val))
|
||||
{
|
||||
case T_Integer:
|
||||
COPY_SCALAR_FIELD(val.ival.val);
|
||||
COPY_SCALAR_FIELD(val.ival.ival);
|
||||
break;
|
||||
case T_Float:
|
||||
COPY_STRING_FIELD(val.fval.val);
|
||||
COPY_STRING_FIELD(val.fval.fval);
|
||||
break;
|
||||
case T_String:
|
||||
COPY_STRING_FIELD(val.sval.val);
|
||||
COPY_STRING_FIELD(val.sval.sval);
|
||||
break;
|
||||
case T_BitString:
|
||||
COPY_STRING_FIELD(val.bsval.val);
|
||||
COPY_STRING_FIELD(val.bsval.bsval);
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "unrecognized node type: %d",
|
||||
@ -4934,7 +4934,7 @@ _copyInteger(const Integer *from)
|
||||
{
|
||||
Integer *newnode = makeNode(Integer);
|
||||
|
||||
COPY_SCALAR_FIELD(val);
|
||||
COPY_SCALAR_FIELD(ival);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@ -4944,7 +4944,7 @@ _copyFloat(const Float *from)
|
||||
{
|
||||
Float *newnode = makeNode(Float);
|
||||
|
||||
COPY_STRING_FIELD(val);
|
||||
COPY_STRING_FIELD(fval);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@ -4954,7 +4954,7 @@ _copyString(const String *from)
|
||||
{
|
||||
String *newnode = makeNode(String);
|
||||
|
||||
COPY_STRING_FIELD(val);
|
||||
COPY_STRING_FIELD(sval);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@ -4964,7 +4964,7 @@ _copyBitString(const BitString *from)
|
||||
{
|
||||
BitString *newnode = makeNode(BitString);
|
||||
|
||||
COPY_STRING_FIELD(val);
|
||||
COPY_STRING_FIELD(bsval);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
@ -3125,7 +3125,7 @@ _equalList(const List *a, const List *b)
|
||||
static bool
|
||||
_equalInteger(const Integer *a, const Integer *b)
|
||||
{
|
||||
COMPARE_SCALAR_FIELD(val);
|
||||
COMPARE_SCALAR_FIELD(ival);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -3133,7 +3133,7 @@ _equalInteger(const Integer *a, const Integer *b)
|
||||
static bool
|
||||
_equalFloat(const Float *a, const Float *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(val);
|
||||
COMPARE_STRING_FIELD(fval);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -3141,7 +3141,7 @@ _equalFloat(const Float *a, const Float *b)
|
||||
static bool
|
||||
_equalString(const String *a, const String *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(val);
|
||||
COMPARE_STRING_FIELD(sval);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -3149,7 +3149,7 @@ _equalString(const String *a, const String *b)
|
||||
static bool
|
||||
_equalBitString(const BitString *a, const BitString *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(val);
|
||||
COMPARE_STRING_FIELD(bsval);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -3421,7 +3421,7 @@ _outA_Expr(StringInfo str, const A_Expr *node)
|
||||
static void
|
||||
_outInteger(StringInfo str, const Integer *node)
|
||||
{
|
||||
appendStringInfo(str, "%d", node->val);
|
||||
appendStringInfo(str, "%d", node->ival);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -3431,7 +3431,7 @@ _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);
|
||||
appendStringInfoString(str, node->fval);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -3442,8 +3442,8 @@ _outString(StringInfo str, const String *node)
|
||||
* but we don't want it to do anything with an empty string.
|
||||
*/
|
||||
appendStringInfoChar(str, '"');
|
||||
if (node->val[0] != '\0')
|
||||
outToken(str, node->val);
|
||||
if (node->sval[0] != '\0')
|
||||
outToken(str, node->sval);
|
||||
appendStringInfoChar(str, '"');
|
||||
}
|
||||
|
||||
@ -3451,7 +3451,7 @@ static void
|
||||
_outBitString(StringInfo str, const BitString *node)
|
||||
{
|
||||
/* internal representation already has leading 'b' */
|
||||
appendStringInfoString(str, node->val);
|
||||
appendStringInfoString(str, node->bsval);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -24,7 +24,7 @@ makeInteger(int i)
|
||||
{
|
||||
Integer *v = makeNode(Integer);
|
||||
|
||||
v->val = i;
|
||||
v->ival = i;
|
||||
return v;
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ makeFloat(char *numericStr)
|
||||
{
|
||||
Float *v = makeNode(Float);
|
||||
|
||||
v->val = numericStr;
|
||||
v->fval = numericStr;
|
||||
return v;
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ makeString(char *str)
|
||||
{
|
||||
String *v = makeNode(String);
|
||||
|
||||
v->val = str;
|
||||
v->sval = str;
|
||||
return v;
|
||||
}
|
||||
|
||||
@ -66,6 +66,6 @@ makeBitString(char *str)
|
||||
{
|
||||
BitString *v = makeNode(BitString);
|
||||
|
||||
v->val = str;
|
||||
v->bsval = str;
|
||||
return v;
|
||||
}
|
||||
|
@ -1719,7 +1719,7 @@ zone_value:
|
||||
if ($3 != NIL)
|
||||
{
|
||||
A_Const *n = (A_Const *) linitial($3);
|
||||
if ((n->val.ival.val & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
|
||||
if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
|
||||
@ -16667,7 +16667,7 @@ makeStringConst(char *str, int location)
|
||||
A_Const *n = makeNode(A_Const);
|
||||
|
||||
n->val.sval.type = T_String;
|
||||
n->val.sval.val = str;
|
||||
n->val.sval.sval = str;
|
||||
n->location = location;
|
||||
|
||||
return (Node *)n;
|
||||
@ -16687,7 +16687,7 @@ makeIntConst(int val, int location)
|
||||
A_Const *n = makeNode(A_Const);
|
||||
|
||||
n->val.ival.type = T_Integer;
|
||||
n->val.ival.val = val;
|
||||
n->val.ival.ival = val;
|
||||
n->location = location;
|
||||
|
||||
return (Node *)n;
|
||||
@ -16699,7 +16699,7 @@ makeFloatConst(char *str, int location)
|
||||
A_Const *n = makeNode(A_Const);
|
||||
|
||||
n->val.fval.type = T_Float;
|
||||
n->val.fval.val = str;
|
||||
n->val.fval.fval = str;
|
||||
n->location = location;
|
||||
|
||||
return (Node *)n;
|
||||
@ -16711,7 +16711,7 @@ makeBitStringConst(char *str, int location)
|
||||
A_Const *n = makeNode(A_Const);
|
||||
|
||||
n->val.bsval.type = T_BitString;
|
||||
n->val.bsval.val = str;
|
||||
n->val.bsval.bsval = str;
|
||||
n->location = location;
|
||||
|
||||
return (Node *)n;
|
||||
@ -16736,16 +16736,16 @@ makeAConst(Node *v, int location)
|
||||
switch (v->type)
|
||||
{
|
||||
case T_Float:
|
||||
n = makeFloatConst(castNode(Float, v)->val, location);
|
||||
n = makeFloatConst(castNode(Float, v)->fval, location);
|
||||
break;
|
||||
|
||||
case T_Integer:
|
||||
n = makeIntConst(castNode(Integer, v)->val, location);
|
||||
n = makeIntConst(castNode(Integer, v)->ival, location);
|
||||
break;
|
||||
|
||||
case T_String:
|
||||
default:
|
||||
n = makeStringConst(castNode(String, v)->val, location);
|
||||
n = makeStringConst(castNode(String, v)->sval, location);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -17049,7 +17049,7 @@ doNegate(Node *n, int location)
|
||||
|
||||
if (IsA(&con->val, Integer))
|
||||
{
|
||||
con->val.ival.val = -con->val.ival.val;
|
||||
con->val.ival.ival = -con->val.ival.ival;
|
||||
return n;
|
||||
}
|
||||
if (IsA(&con->val, Float))
|
||||
@ -17065,14 +17065,14 @@ doNegate(Node *n, int location)
|
||||
static void
|
||||
doNegateFloat(Float *v)
|
||||
{
|
||||
char *oldval = v->val;
|
||||
char *oldval = v->fval;
|
||||
|
||||
if (*oldval == '+')
|
||||
oldval++;
|
||||
if (*oldval == '-')
|
||||
v->val = oldval+1; /* just strip the '-' */
|
||||
v->fval = oldval+1; /* just strip the '-' */
|
||||
else
|
||||
v->val = psprintf("-%s", oldval);
|
||||
v->fval = psprintf("-%s", oldval);
|
||||
}
|
||||
|
||||
static Node *
|
||||
|
@ -376,7 +376,7 @@ make_const(ParseState *pstate, A_Const *aconst)
|
||||
switch (nodeTag(&aconst->val))
|
||||
{
|
||||
case T_Integer:
|
||||
val = Int32GetDatum(aconst->val.ival.val);
|
||||
val = Int32GetDatum(intVal(&aconst->val));
|
||||
|
||||
typeid = INT4OID;
|
||||
typelen = sizeof(int32);
|
||||
@ -385,7 +385,7 @@ make_const(ParseState *pstate, A_Const *aconst)
|
||||
|
||||
case T_Float:
|
||||
/* could be an oversize integer as well as a float ... */
|
||||
if (scanint8(aconst->val.fval.val, true, &val64))
|
||||
if (scanint8(aconst->val.fval.fval, true, &val64))
|
||||
{
|
||||
/*
|
||||
* It might actually fit in int32. Probably only INT_MIN can
|
||||
@ -415,7 +415,7 @@ make_const(ParseState *pstate, A_Const *aconst)
|
||||
/* arrange to report location if numeric_in() fails */
|
||||
setup_parser_errposition_callback(&pcbstate, pstate, aconst->location);
|
||||
val = DirectFunctionCall3(numeric_in,
|
||||
CStringGetDatum(aconst->val.fval.val),
|
||||
CStringGetDatum(aconst->val.fval.fval),
|
||||
ObjectIdGetDatum(InvalidOid),
|
||||
Int32GetDatum(-1));
|
||||
cancel_parser_errposition_callback(&pcbstate);
|
||||
@ -432,7 +432,7 @@ make_const(ParseState *pstate, A_Const *aconst)
|
||||
* We assume here that UNKNOWN's internal representation is the
|
||||
* same as CSTRING
|
||||
*/
|
||||
val = CStringGetDatum(aconst->val.sval.val);
|
||||
val = CStringGetDatum(strVal(&aconst->val));
|
||||
|
||||
typeid = UNKNOWNOID; /* will be coerced later */
|
||||
typelen = -2; /* cstring-style varwidth type */
|
||||
@ -443,7 +443,7 @@ make_const(ParseState *pstate, A_Const *aconst)
|
||||
/* arrange to report location if bit_in() fails */
|
||||
setup_parser_errposition_callback(&pcbstate, pstate, aconst->location);
|
||||
val = DirectFunctionCall3(bit_in,
|
||||
CStringGetDatum(aconst->val.bsval.val),
|
||||
CStringGetDatum(aconst->val.bsval.bsval),
|
||||
ObjectIdGetDatum(InvalidOid),
|
||||
Int32GetDatum(-1));
|
||||
cancel_parser_errposition_callback(&pcbstate);
|
||||
|
@ -382,17 +382,17 @@ typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)
|
||||
|
||||
if (IsA(&ac->val, Integer))
|
||||
{
|
||||
cstr = psprintf("%ld", (long) ac->val.ival.val);
|
||||
cstr = psprintf("%ld", (long) intVal(&ac->val));
|
||||
}
|
||||
else if (IsA(&ac->val, Float))
|
||||
{
|
||||
/* we can just use the string representation directly. */
|
||||
cstr = ac->val.fval.val;
|
||||
cstr = ac->val.fval.fval;
|
||||
}
|
||||
else if (IsA(&ac->val, String))
|
||||
{
|
||||
/* we can just use the string representation directly. */
|
||||
cstr = ac->val.sval.val;
|
||||
cstr = strVal(&ac->val);
|
||||
}
|
||||
}
|
||||
else if (IsA(tm, ColumnRef))
|
||||
|
@ -603,7 +603,7 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
|
||||
qstring = quote_qualified_identifier(snamespace, sname);
|
||||
snamenode = makeNode(A_Const);
|
||||
snamenode->val.node.type = T_String;
|
||||
snamenode->val.sval.val = qstring;
|
||||
snamenode->val.sval.sval = qstring;
|
||||
snamenode->location = -1;
|
||||
castnode = makeNode(TypeCast);
|
||||
castnode->typeName = SystemTypeName("regclass");
|
||||
|
@ -324,7 +324,7 @@ oidparse(Node *node)
|
||||
* constants by the lexer. Accept these if they are valid OID
|
||||
* strings.
|
||||
*/
|
||||
return oidin_subr(castNode(Float, node)->val, NULL);
|
||||
return oidin_subr(castNode(Float, node)->fval, NULL);
|
||||
default:
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
|
||||
}
|
||||
|
@ -8332,7 +8332,7 @@ flatten_set_variable_args(const char *name, List *args)
|
||||
break;
|
||||
case T_Float:
|
||||
/* represented as a string, so just copy it */
|
||||
appendStringInfoString(&buf, castNode(Float, &con->val)->val);
|
||||
appendStringInfoString(&buf, castNode(Float, &con->val)->fval);
|
||||
break;
|
||||
case T_String:
|
||||
val = strVal(&con->val);
|
||||
|
@ -28,7 +28,7 @@
|
||||
typedef struct Integer
|
||||
{
|
||||
NodeTag type;
|
||||
int val;
|
||||
int ival;
|
||||
} Integer;
|
||||
|
||||
/*
|
||||
@ -45,24 +45,24 @@ typedef struct Integer
|
||||
typedef struct Float
|
||||
{
|
||||
NodeTag type;
|
||||
char *val;
|
||||
char *fval;
|
||||
} Float;
|
||||
|
||||
typedef struct String
|
||||
{
|
||||
NodeTag type;
|
||||
char *val;
|
||||
char *sval;
|
||||
} String;
|
||||
|
||||
typedef struct BitString
|
||||
{
|
||||
NodeTag type;
|
||||
char *val;
|
||||
char *bsval;
|
||||
} BitString;
|
||||
|
||||
#define intVal(v) (castNode(Integer, v)->val)
|
||||
#define floatVal(v) atof(castNode(Float, v)->val)
|
||||
#define strVal(v) (castNode(String, v)->val)
|
||||
#define intVal(v) (castNode(Integer, v)->ival)
|
||||
#define floatVal(v) atof(castNode(Float, v)->fval)
|
||||
#define strVal(v) (castNode(String, v)->sval)
|
||||
|
||||
extern Integer *makeInteger(int i);
|
||||
extern Float *makeFloat(char *numericStr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user