Add parse location fields to NullTest and BooleanTest structs.

We did not need a location tag on NullTest or BooleanTest before, because
no error messages referred directly to their locations.  That's planned
to change though, so add these fields in a separate housekeeping commit.

Catversion bump because stored rules may change.
This commit is contained in:
Tom Lane 2015-02-22 14:40:27 -05:00
parent 6a75562ed1
commit c063da1769
14 changed files with 44 additions and 5 deletions

View File

@ -1693,6 +1693,7 @@ _copyNullTest(const NullTest *from)
COPY_NODE_FIELD(arg); COPY_NODE_FIELD(arg);
COPY_SCALAR_FIELD(nulltesttype); COPY_SCALAR_FIELD(nulltesttype);
COPY_SCALAR_FIELD(argisrow); COPY_SCALAR_FIELD(argisrow);
COPY_LOCATION_FIELD(location);
return newnode; return newnode;
} }
@ -1707,6 +1708,7 @@ _copyBooleanTest(const BooleanTest *from)
COPY_NODE_FIELD(arg); COPY_NODE_FIELD(arg);
COPY_SCALAR_FIELD(booltesttype); COPY_SCALAR_FIELD(booltesttype);
COPY_LOCATION_FIELD(location);
return newnode; return newnode;
} }

View File

@ -622,6 +622,7 @@ _equalNullTest(const NullTest *a, const NullTest *b)
COMPARE_NODE_FIELD(arg); COMPARE_NODE_FIELD(arg);
COMPARE_SCALAR_FIELD(nulltesttype); COMPARE_SCALAR_FIELD(nulltesttype);
COMPARE_SCALAR_FIELD(argisrow); COMPARE_SCALAR_FIELD(argisrow);
COMPARE_LOCATION_FIELD(location);
return true; return true;
} }
@ -631,6 +632,7 @@ _equalBooleanTest(const BooleanTest *a, const BooleanTest *b)
{ {
COMPARE_NODE_FIELD(arg); COMPARE_NODE_FIELD(arg);
COMPARE_SCALAR_FIELD(booltesttype); COMPARE_SCALAR_FIELD(booltesttype);
COMPARE_LOCATION_FIELD(location);
return true; return true;
} }

View File

@ -1346,12 +1346,22 @@ exprLocation(const Node *expr)
} }
break; break;
case T_NullTest: case T_NullTest:
/* just use argument's location */ {
loc = exprLocation((Node *) ((const NullTest *) expr)->arg); const NullTest *nexpr = (const NullTest *) expr;
/* Much as above */
loc = leftmostLoc(nexpr->location,
exprLocation((Node *) nexpr->arg));
}
break; break;
case T_BooleanTest: case T_BooleanTest:
/* just use argument's location */ {
loc = exprLocation((Node *) ((const BooleanTest *) expr)->arg); const BooleanTest *bexpr = (const BooleanTest *) expr;
/* Much as above */
loc = leftmostLoc(bexpr->location,
exprLocation((Node *) bexpr->arg));
}
break; break;
case T_CoerceToDomain: case T_CoerceToDomain:
{ {

View File

@ -1370,6 +1370,7 @@ _outNullTest(StringInfo str, const NullTest *node)
WRITE_NODE_FIELD(arg); WRITE_NODE_FIELD(arg);
WRITE_ENUM_FIELD(nulltesttype, NullTestType); WRITE_ENUM_FIELD(nulltesttype, NullTestType);
WRITE_BOOL_FIELD(argisrow); WRITE_BOOL_FIELD(argisrow);
WRITE_LOCATION_FIELD(location);
} }
static void static void
@ -1379,6 +1380,7 @@ _outBooleanTest(StringInfo str, const BooleanTest *node)
WRITE_NODE_FIELD(arg); WRITE_NODE_FIELD(arg);
WRITE_ENUM_FIELD(booltesttype, BoolTestType); WRITE_ENUM_FIELD(booltesttype, BoolTestType);
WRITE_LOCATION_FIELD(location);
} }
static void static void

View File

@ -1044,6 +1044,7 @@ _readNullTest(void)
READ_NODE_FIELD(arg); READ_NODE_FIELD(arg);
READ_ENUM_FIELD(nulltesttype, NullTestType); READ_ENUM_FIELD(nulltesttype, NullTestType);
READ_BOOL_FIELD(argisrow); READ_BOOL_FIELD(argisrow);
READ_LOCATION_FIELD(location);
READ_DONE(); READ_DONE();
} }
@ -1058,6 +1059,7 @@ _readBooleanTest(void)
READ_NODE_FIELD(arg); READ_NODE_FIELD(arg);
READ_ENUM_FIELD(booltesttype, BoolTestType); READ_ENUM_FIELD(booltesttype, BoolTestType);
READ_LOCATION_FIELD(location);
READ_DONE(); READ_DONE();
} }

View File

@ -449,6 +449,7 @@ build_minmax_path(PlannerInfo *root, MinMaxAggInfo *mminfo,
ntest->arg = copyObject(mminfo->target); ntest->arg = copyObject(mminfo->target);
/* we checked it wasn't a rowtype in find_minmax_aggs_walker */ /* we checked it wasn't a rowtype in find_minmax_aggs_walker */
ntest->argisrow = false; ntest->argisrow = false;
ntest->location = -1;
/* User might have had that in WHERE already */ /* User might have had that in WHERE already */
if (!list_member((List *) parse->jointree->quals, ntest)) if (!list_member((List *) parse->jointree->quals, ntest))

View File

@ -212,6 +212,7 @@ negate_clause(Node *node)
newexpr->nulltesttype = (expr->nulltesttype == IS_NULL ? newexpr->nulltesttype = (expr->nulltesttype == IS_NULL ?
IS_NOT_NULL : IS_NULL); IS_NOT_NULL : IS_NULL);
newexpr->argisrow = expr->argisrow; newexpr->argisrow = expr->argisrow;
newexpr->location = expr->location;
return (Node *) newexpr; return (Node *) newexpr;
} }
} }
@ -247,6 +248,7 @@ negate_clause(Node *node)
(int) expr->booltesttype); (int) expr->booltesttype);
break; break;
} }
newexpr->location = expr->location;
return (Node *) newexpr; return (Node *) newexpr;
} }
break; break;

View File

@ -3305,6 +3305,7 @@ eval_const_expressions_mutator(Node *node,
newntest->arg = (Expr *) relem; newntest->arg = (Expr *) relem;
newntest->nulltesttype = ntest->nulltesttype; newntest->nulltesttype = ntest->nulltesttype;
newntest->argisrow = type_is_rowtype(exprType(relem)); newntest->argisrow = type_is_rowtype(exprType(relem));
newntest->location = ntest->location;
newargs = lappend(newargs, newntest); newargs = lappend(newargs, newntest);
} }
/* If all the inputs were constants, result is TRUE */ /* If all the inputs were constants, result is TRUE */
@ -3343,6 +3344,7 @@ eval_const_expressions_mutator(Node *node,
newntest->arg = (Expr *) arg; newntest->arg = (Expr *) arg;
newntest->nulltesttype = ntest->nulltesttype; newntest->nulltesttype = ntest->nulltesttype;
newntest->argisrow = ntest->argisrow; newntest->argisrow = ntest->argisrow;
newntest->location = ntest->location;
return (Node *) newntest; return (Node *) newntest;
} }
case T_BooleanTest: case T_BooleanTest:
@ -3395,6 +3397,7 @@ eval_const_expressions_mutator(Node *node,
newbtest = makeNode(BooleanTest); newbtest = makeNode(BooleanTest);
newbtest->arg = (Expr *) arg; newbtest->arg = (Expr *) arg;
newbtest->booltesttype = btest->booltesttype; newbtest->booltesttype = btest->booltesttype;
newbtest->location = btest->location;
return (Node *) newbtest; return (Node *) newbtest;
} }
case T_PlaceHolderVar: case T_PlaceHolderVar:

View File

@ -720,6 +720,7 @@ get_relation_constraints(PlannerInfo *root,
0); 0);
ntest->nulltesttype = IS_NOT_NULL; ntest->nulltesttype = IS_NOT_NULL;
ntest->argisrow = type_is_rowtype(att->atttypid); ntest->argisrow = type_is_rowtype(att->atttypid);
ntest->location = -1;
result = lappend(result, ntest); result = lappend(result, ntest);
} }
} }

View File

@ -11299,6 +11299,7 @@ a_expr: c_expr { $$ = $1; }
NullTest *n = makeNode(NullTest); NullTest *n = makeNode(NullTest);
n->arg = (Expr *) $1; n->arg = (Expr *) $1;
n->nulltesttype = IS_NULL; n->nulltesttype = IS_NULL;
n->location = @2;
$$ = (Node *)n; $$ = (Node *)n;
} }
| a_expr ISNULL | a_expr ISNULL
@ -11306,6 +11307,7 @@ a_expr: c_expr { $$ = $1; }
NullTest *n = makeNode(NullTest); NullTest *n = makeNode(NullTest);
n->arg = (Expr *) $1; n->arg = (Expr *) $1;
n->nulltesttype = IS_NULL; n->nulltesttype = IS_NULL;
n->location = @2;
$$ = (Node *)n; $$ = (Node *)n;
} }
| a_expr IS NOT NULL_P %prec IS | a_expr IS NOT NULL_P %prec IS
@ -11313,6 +11315,7 @@ a_expr: c_expr { $$ = $1; }
NullTest *n = makeNode(NullTest); NullTest *n = makeNode(NullTest);
n->arg = (Expr *) $1; n->arg = (Expr *) $1;
n->nulltesttype = IS_NOT_NULL; n->nulltesttype = IS_NOT_NULL;
n->location = @2;
$$ = (Node *)n; $$ = (Node *)n;
} }
| a_expr NOTNULL | a_expr NOTNULL
@ -11320,6 +11323,7 @@ a_expr: c_expr { $$ = $1; }
NullTest *n = makeNode(NullTest); NullTest *n = makeNode(NullTest);
n->arg = (Expr *) $1; n->arg = (Expr *) $1;
n->nulltesttype = IS_NOT_NULL; n->nulltesttype = IS_NOT_NULL;
n->location = @2;
$$ = (Node *)n; $$ = (Node *)n;
} }
| row OVERLAPS row | row OVERLAPS row
@ -11343,6 +11347,7 @@ a_expr: c_expr { $$ = $1; }
BooleanTest *b = makeNode(BooleanTest); BooleanTest *b = makeNode(BooleanTest);
b->arg = (Expr *) $1; b->arg = (Expr *) $1;
b->booltesttype = IS_TRUE; b->booltesttype = IS_TRUE;
b->location = @2;
$$ = (Node *)b; $$ = (Node *)b;
} }
| a_expr IS NOT TRUE_P %prec IS | a_expr IS NOT TRUE_P %prec IS
@ -11350,6 +11355,7 @@ a_expr: c_expr { $$ = $1; }
BooleanTest *b = makeNode(BooleanTest); BooleanTest *b = makeNode(BooleanTest);
b->arg = (Expr *) $1; b->arg = (Expr *) $1;
b->booltesttype = IS_NOT_TRUE; b->booltesttype = IS_NOT_TRUE;
b->location = @2;
$$ = (Node *)b; $$ = (Node *)b;
} }
| a_expr IS FALSE_P %prec IS | a_expr IS FALSE_P %prec IS
@ -11357,6 +11363,7 @@ a_expr: c_expr { $$ = $1; }
BooleanTest *b = makeNode(BooleanTest); BooleanTest *b = makeNode(BooleanTest);
b->arg = (Expr *) $1; b->arg = (Expr *) $1;
b->booltesttype = IS_FALSE; b->booltesttype = IS_FALSE;
b->location = @2;
$$ = (Node *)b; $$ = (Node *)b;
} }
| a_expr IS NOT FALSE_P %prec IS | a_expr IS NOT FALSE_P %prec IS
@ -11364,6 +11371,7 @@ a_expr: c_expr { $$ = $1; }
BooleanTest *b = makeNode(BooleanTest); BooleanTest *b = makeNode(BooleanTest);
b->arg = (Expr *) $1; b->arg = (Expr *) $1;
b->booltesttype = IS_NOT_FALSE; b->booltesttype = IS_NOT_FALSE;
b->location = @2;
$$ = (Node *)b; $$ = (Node *)b;
} }
| a_expr IS UNKNOWN %prec IS | a_expr IS UNKNOWN %prec IS
@ -11371,6 +11379,7 @@ a_expr: c_expr { $$ = $1; }
BooleanTest *b = makeNode(BooleanTest); BooleanTest *b = makeNode(BooleanTest);
b->arg = (Expr *) $1; b->arg = (Expr *) $1;
b->booltesttype = IS_UNKNOWN; b->booltesttype = IS_UNKNOWN;
b->location = @2;
$$ = (Node *)b; $$ = (Node *)b;
} }
| a_expr IS NOT UNKNOWN %prec IS | a_expr IS NOT UNKNOWN %prec IS
@ -11378,6 +11387,7 @@ a_expr: c_expr { $$ = $1; }
BooleanTest *b = makeNode(BooleanTest); BooleanTest *b = makeNode(BooleanTest);
b->arg = (Expr *) $1; b->arg = (Expr *) $1;
b->booltesttype = IS_NOT_UNKNOWN; b->booltesttype = IS_NOT_UNKNOWN;
b->location = @2;
$$ = (Node *)b; $$ = (Node *)b;
} }
| a_expr IS DISTINCT FROM a_expr %prec IS | a_expr IS DISTINCT FROM a_expr %prec IS

View File

@ -789,6 +789,7 @@ transformAExprOp(ParseState *pstate, A_Expr *a)
NullTest *n = makeNode(NullTest); NullTest *n = makeNode(NullTest);
n->nulltesttype = IS_NULL; n->nulltesttype = IS_NULL;
n->location = a->location;
if (exprIsNullConstant(lexpr)) if (exprIsNullConstant(lexpr))
n->arg = (Expr *) rexpr; n->arg = (Expr *) rexpr;

View File

@ -1023,6 +1023,7 @@ AddInvertedQual(Query *parsetree, Node *qual)
invqual = makeNode(BooleanTest); invqual = makeNode(BooleanTest);
invqual->arg = (Expr *) qual; invqual->arg = (Expr *) qual;
invqual->booltesttype = IS_NOT_TRUE; invqual->booltesttype = IS_NOT_TRUE;
invqual->location = -1;
AddQual(parsetree, (Node *) invqual); AddQual(parsetree, (Node *) invqual);
} }

View File

@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 201502191 #define CATALOG_VERSION_NO 201502221
#endif #endif

View File

@ -1050,6 +1050,7 @@ typedef struct NullTest
Expr *arg; /* input expression */ Expr *arg; /* input expression */
NullTestType nulltesttype; /* IS NULL, IS NOT NULL */ NullTestType nulltesttype; /* IS NULL, IS NOT NULL */
bool argisrow; /* T if input is of a composite type */ bool argisrow; /* T if input is of a composite type */
int location; /* token location, or -1 if unknown */
} NullTest; } NullTest;
/* /*
@ -1071,6 +1072,7 @@ typedef struct BooleanTest
Expr xpr; Expr xpr;
Expr *arg; /* input expression */ Expr *arg; /* input expression */
BoolTestType booltesttype; /* test type */ BoolTestType booltesttype; /* test type */
int location; /* token location, or -1 if unknown */
} BooleanTest; } BooleanTest;
/* /*