Commit 6fff5c3b authored by Alvaro Herrera's avatar Alvaro Herrera

Remove typename from A_Const.

Brendan Jurd, minor editorialization by me.
parent 339570fd
......@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.392 2008/04/14 17:05:33 tgl Exp $
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.393 2008/04/29 14:59:16 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1639,8 +1639,6 @@ _copyAConst(A_Const *from)
break;
}
COPY_NODE_FIELD(typename);
return newnode;
}
......
......@@ -18,7 +18,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.321 2008/04/14 17:05:33 tgl Exp $
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.322 2008/04/29 14:59:16 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1693,7 +1693,6 @@ _equalAConst(A_Const *a, A_Const *b)
{
if (!equal(&a->val, &b->val)) /* hack for in-line Value field */
return false;
COMPARE_NODE_FIELD(typename);
return true;
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.325 2008/04/13 20:51:20 tgl Exp $
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.326 2008/04/29 14:59:16 alvherre Exp $
*
* NOTES
* Every node type that can appear in stored rules' parsetrees *must*
......@@ -1945,7 +1945,6 @@ _outAConst(StringInfo str, A_Const *node)
appendStringInfo(str, " :val ");
_outValue(str, &(node->val));
WRITE_NODE_FIELD(typename);
}
static void
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.227 2008/03/20 21:42:48 tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.228 2008/04/29 14:59:16 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -127,9 +127,6 @@ transformExpr(ParseState *pstate, Node *expr)
Value *val = &con->val;
result = (Node *) make_const(val);
if (con->typename != NULL)
result = typecast_expression(pstate, result,
con->typename);
break;
}
......@@ -649,8 +646,7 @@ exprIsNullConstant(Node *arg)
{
A_Const *con = (A_Const *) arg;
if (con->val.type == T_Null &&
con->typename == NULL)
if (con->val.type == T_Null)
return true;
}
return false;
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.159 2008/03/20 21:42:48 tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.160 2008/04/29 14:59:17 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1266,13 +1266,6 @@ FigureColnameInternal(Node *node, char **name)
return 2;
}
break;
case T_A_Const:
if (((A_Const *) node)->typename != NULL)
{
*name = strVal(llast(((A_Const *) node)->typename->names));
return 1;
}
break;
case T_TypeCast:
strength = FigureColnameInternal(((TypeCast *) node)->arg,
name);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.95 2008/04/11 22:54:23 tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.96 2008/04/29 14:59:17 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -289,20 +289,33 @@ typenameTypeMod(ParseState *pstate, const TypeName *typename, Type typ)
{
A_Const *ac = (A_Const *) tm;
/*
* The grammar hands back some integers with ::int4 attached, so
* allow a cast decoration if it's an Integer value, but not
* otherwise.
*/
if (IsA(&ac->val, Integer))
{
cstr = (char *) palloc(32);
snprintf(cstr, 32, "%ld", (long) ac->val.val.ival);
}
else if (ac->typename == NULL) /* no casts allowed */
{
/* otherwise we can just use the str field directly. */
else
/* we can just use the str field directly. */
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))
......
......@@ -19,7 +19,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.12 2008/04/24 20:46:49 tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.13 2008/04/29 14:59:17 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -308,6 +308,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
char *sname;
char *qstring;
A_Const *snamenode;
TypeCast *castnode;
FuncCall *funccallnode;
CreateSeqStmt *seqstmt;
AlterSeqStmt *altseqstmt;
......@@ -379,10 +380,12 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
snamenode = makeNode(A_Const);
snamenode->val.type = T_String;
snamenode->val.val.str = qstring;
snamenode->typename = SystemTypeName("regclass");
castnode = makeNode(TypeCast);
castnode->typename = SystemTypeName("regclass");
castnode->arg = (Node *) snamenode;
funccallnode = makeNode(FuncCall);
funccallnode->funcname = SystemFuncName("nextval");
funccallnode->args = list_make1(snamenode);
funccallnode->args = list_make1(castnode);
funccallnode->agg_star = false;
funccallnode->agg_distinct = false;
funccallnode->location = -1;
......
......@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.447 2008/04/18 01:42:17 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.448 2008/04/29 14:59:17 alvherre Exp $
*
*--------------------------------------------------------------------
*/
......@@ -5207,29 +5207,48 @@ flatten_set_variable_args(const char *name, List *args)
initStringInfo(&buf);
/*
* 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.
*/
foreach(l, args)
{
A_Const *arg = (A_Const *) lfirst(l);
Node *arg = (Node *) lfirst(l);
char *val;
TypeName *typename = NULL;
A_Const *con;
if (l != list_head(args))
appendStringInfo(&buf, ", ");
if (IsA(arg, TypeCast))
{
TypeCast *tc = (TypeCast *) arg;
arg = tc->arg;
typename = tc->typename;
}
if (!IsA(arg, A_Const))
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
switch (nodeTag(&arg->val))
con = (A_Const *) arg;
switch (nodeTag(&con->val))
{
case T_Integer:
appendStringInfo(&buf, "%ld", intVal(&arg->val));
appendStringInfo(&buf, "%ld", intVal(&con->val));
break;
case T_Float:
/* represented as a string, so just copy it */
appendStringInfoString(&buf, strVal(&arg->val));
appendStringInfoString(&buf, strVal(&con->val));
break;
case T_String:
val = strVal(&arg->val);
if (arg->typename != NULL)
/*
* Plain string literal or identifier. For quote mode,
* quote it if it's not a vanilla identifier.
*/
val = strVal(&con->val);
if (typename != NULL)
{
/*
* Must be a ConstInterval argument for TIME ZONE. Coerce
......@@ -5241,7 +5260,7 @@ flatten_set_variable_args(const char *name, List *args)
Datum interval;
char *intervalout;
typoid = typenameTypeId(NULL, arg->typename, &typmod);
typoid = typenameTypeId(NULL, typename, &typmod);
Assert(typoid == INTERVALOID);
interval =
......@@ -5254,13 +5273,12 @@ flatten_set_variable_args(const char *name, List *args)
DatumGetCString(DirectFunctionCall1(interval_out,
interval));
appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
/* don't leave this set */
typename = NULL;
}
else
{
/*
* Plain string literal or identifier. For quote mode,
* quote it if it's not a vanilla identifier.
*/
if (flags & GUC_LIST_QUOTE)
appendStringInfoString(&buf, quote_identifier(val));
else
......@@ -5269,7 +5287,7 @@ flatten_set_variable_args(const char *name, List *args)
break;
default:
elog(ERROR, "unrecognized node type: %d",
(int) nodeTag(&arg->val));
(int) nodeTag(&con->val));
break;
}
}
......
......@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.452 2008/04/29 13:00:22 alvherre Exp $
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.453 2008/04/29 14:59:17 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 200804291
#define CATALOG_VERSION_NO 200804292
#endif
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.362 2008/04/14 17:05:34 tgl Exp $
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.363 2008/04/29 14:59:17 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -234,17 +234,10 @@ typedef struct A_Const
{
NodeTag type;
Value val; /* the value (with the tag) */
TypeName *typename; /* typecast, or NULL if none */
} A_Const;
/*
* TypeCast - a CAST expression
*
* NOTE: for mostly historical reasons, A_Const parsenodes contain
* room for a TypeName, allowing a constant to be marked as being of a given
* type without a separate TypeCast node. Either representation will work,
* but the combined representation saves a bit of code in many
* productions in gram.y.
*/
typedef struct TypeCast
{
......
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