From 0cbdbd17c6d33398ffe8fb1c7f2a778503764bc2 Mon Sep 17 00:00:00 2001
From: Daniel Farina <daniel@heroku.com>
Date: Wed, 29 Feb 2012 00:30:18 -0800
Subject: [PATCH] Straw man to show the effects of the change to const
 location

Signed-off-by: Daniel Farina <daniel@heroku.com>
---
 src/backend/nodes/copyfuncs.c     |    2 +-
 src/backend/nodes/makefuncs.c     |    2 +-
 src/backend/nodes/nodeFuncs.c     |    2 +-
 src/backend/nodes/outfuncs.c      |    2 +-
 src/backend/nodes/readfuncs.c     |    2 +-
 src/backend/parser/parse_coerce.c |   10 ++--------
 src/backend/parser/parse_expr.c   |    2 +-
 src/backend/parser/parse_node.c   |    4 ++--
 src/include/nodes/primnodes.h     |    2 +-
 9 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index c9133dd..078c645 100644
*** a/src/backend/nodes/copyfuncs.c
--- b/src/backend/nodes/copyfuncs.c
***************
*** 1086,1092 **** _copyConst(Const *from)
  
  	COPY_SCALAR_FIELD(constisnull);
  	COPY_SCALAR_FIELD(constbyval);
! 	COPY_LOCATION_FIELD(location);
  
  	return newnode;
  }
--- 1086,1092 ----
  
  	COPY_SCALAR_FIELD(constisnull);
  	COPY_SCALAR_FIELD(constbyval);
! 	COPY_LOCATION_FIELD(constlocation);
  
  	return newnode;
  }
*** a/src/backend/nodes/makefuncs.c
--- b/src/backend/nodes/makefuncs.c
***************
*** 287,293 **** makeConst(Oid consttype,
  	cnst->constvalue = constvalue;
  	cnst->constisnull = constisnull;
  	cnst->constbyval = constbyval;
! 	cnst->location = -1;		/* "unknown" */
  
  	return cnst;
  }
--- 287,293 ----
  	cnst->constvalue = constvalue;
  	cnst->constisnull = constisnull;
  	cnst->constbyval = constbyval;
! 	cnst->constlocation = -1;		/* "unknown" */
  
  	return cnst;
  }
*** a/src/backend/nodes/nodeFuncs.c
--- b/src/backend/nodes/nodeFuncs.c
***************
*** 1093,1099 **** exprLocation(Node *expr)
  			loc = ((Var *) expr)->location;
  			break;
  		case T_Const:
! 			loc = ((Const *) expr)->location;
  			break;
  		case T_Param:
  			loc = ((Param *) expr)->location;
--- 1093,1099 ----
  			loc = ((Var *) expr)->location;
  			break;
  		case T_Const:
! 			loc = ((Const *) expr)->constlocation;
  			break;
  		case T_Param:
  			loc = ((Param *) expr)->location;
*** a/src/backend/nodes/outfuncs.c
--- b/src/backend/nodes/outfuncs.c
***************
*** 921,927 **** _outConst(StringInfo str, Const *node)
  	WRITE_INT_FIELD(constlen);
  	WRITE_BOOL_FIELD(constbyval);
  	WRITE_BOOL_FIELD(constisnull);
! 	WRITE_LOCATION_FIELD(location);
  
  	appendStringInfo(str, " :constvalue ");
  	if (node->constisnull)
--- 921,927 ----
  	WRITE_INT_FIELD(constlen);
  	WRITE_BOOL_FIELD(constbyval);
  	WRITE_BOOL_FIELD(constisnull);
! 	WRITE_LOCATION_FIELD(constlocation);
  
  	appendStringInfo(str, " :constvalue ");
  	if (node->constisnull)
*** a/src/backend/nodes/readfuncs.c
--- b/src/backend/nodes/readfuncs.c
***************
*** 432,438 **** _readConst(void)
  	READ_INT_FIELD(constlen);
  	READ_BOOL_FIELD(constbyval);
  	READ_BOOL_FIELD(constisnull);
! 	READ_LOCATION_FIELD(location);
  
  	token = pg_strtok(&length); /* skip :constvalue */
  	if (local_node->constisnull)
--- 432,438 ----
  	READ_INT_FIELD(constlen);
  	READ_BOOL_FIELD(constbyval);
  	READ_BOOL_FIELD(constisnull);
! 	READ_LOCATION_FIELD(constlocation);
  
  	token = pg_strtok(&length); /* skip :constvalue */
  	if (local_node->constisnull)
*** a/src/backend/parser/parse_coerce.c
--- b/src/backend/parser/parse_coerce.c
***************
*** 280,298 **** coerce_type(ParseState *pstate, Node *node,
  		newcon->constlen = typeLen(targetType);
  		newcon->constbyval = typeByVal(targetType);
  		newcon->constisnull = con->constisnull;
- 		/* Use the leftmost of the constant's and coercion's locations */
- 		if (location < 0)
- 			newcon->location = con->location;
- 		else if (con->location >= 0 && con->location < location)
- 			newcon->location = con->location;
- 		else
- 			newcon->location = location;
  
  		/*
  		 * Set up to point at the constant's text if the input routine throws
  		 * an error.
  		 */
! 		setup_parser_errposition_callback(&pcbstate, pstate, con->location);
  
  		/*
  		 * We assume here that UNKNOWN's internal representation is the same
--- 280,292 ----
  		newcon->constlen = typeLen(targetType);
  		newcon->constbyval = typeByVal(targetType);
  		newcon->constisnull = con->constisnull;
  
  		/*
  		 * Set up to point at the constant's text if the input routine throws
  		 * an error.
  		 */
! 		setup_parser_errposition_callback(&pcbstate, pstate,
! 										  con->constlocation);
  
  		/*
  		 * We assume here that UNKNOWN's internal representation is the same
*** a/src/backend/parser/parse_expr.c
--- b/src/backend/parser/parse_expr.c
***************
*** 1067,1073 **** transformAExprOf(ParseState *pstate, A_Expr *a)
  	result = (Const *) makeBoolConst(matched, false);
  
  	/* Make the result have the original input's parse location */
! 	result->location = exprLocation((Node *) a);
  
  	return (Node *) result;
  }
--- 1067,1073 ----
  	result = (Const *) makeBoolConst(matched, false);
  
  	/* Make the result have the original input's parse location */
! 	result->constlocation = exprLocation((Node *) a);
  
  	return (Node *) result;
  }
*** a/src/backend/parser/parse_node.c
--- b/src/backend/parser/parse_node.c
***************
*** 532,538 **** make_const(ParseState *pstate, Value *value, int location)
  							(Datum) 0,
  							true,
  							false);
! 			con->location = location;
  			return con;
  
  		default:
--- 532,538 ----
  							(Datum) 0,
  							true,
  							false);
! 			con->constlocation = location;
  			return con;
  
  		default:
***************
*** 547,553 **** make_const(ParseState *pstate, Value *value, int location)
  					val,
  					false,
  					typebyval);
! 	con->location = location;
  
  	return con;
  }
--- 547,553 ----
  					val,
  					false,
  					typebyval);
! 	con->constlocation = location;
  
  	return con;
  }
*** a/src/include/nodes/primnodes.h
--- b/src/include/nodes/primnodes.h
***************
*** 165,171 **** typedef struct Const
  								 * If true, then all the information is stored
  								 * in the Datum. If false, then the Datum
  								 * contains a pointer to the information. */
! 	int			location;		/* token location, or -1 if unknown */
  } Const;
  
  /* ----------------
--- 165,171 ----
  								 * If true, then all the information is stored
  								 * in the Datum. If false, then the Datum
  								 * contains a pointer to the information. */
! 	int			constlocation;		/* token location, or -1 if unknown */
  } Const;
  
  /* ----------------
