mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Improve parser so that we can show an error cursor position for errors
during parse analysis, not only errors detected in the flex/bison stages. This is per my earlier proposal. This commit includes all the basic infrastructure, but locations are only tracked and reported for errors involving column references, function calls, and operators. More could be done later but this seems like a good set to start with. I've also moved the ReportSyntaxErrorPosition logic out of psql and into libpq, which should make it available to more people --- even within psql this is an improvement because warnings weren't handled by ReportSyntaxErrorPosition.
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.329 2006/03/05 15:58:27 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.330 2006/03/14 22:48:19 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1418,6 +1418,7 @@ _copyAExpr(A_Expr *from)
|
||||
COPY_NODE_FIELD(name);
|
||||
COPY_NODE_FIELD(lexpr);
|
||||
COPY_NODE_FIELD(rexpr);
|
||||
COPY_SCALAR_FIELD(location);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@ -1428,6 +1429,7 @@ _copyColumnRef(ColumnRef *from)
|
||||
ColumnRef *newnode = makeNode(ColumnRef);
|
||||
|
||||
COPY_NODE_FIELD(fields);
|
||||
COPY_SCALAR_FIELD(location);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@ -1482,6 +1484,7 @@ _copyFuncCall(FuncCall *from)
|
||||
COPY_NODE_FIELD(args);
|
||||
COPY_SCALAR_FIELD(agg_star);
|
||||
COPY_SCALAR_FIELD(agg_distinct);
|
||||
COPY_SCALAR_FIELD(location);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@ -1532,6 +1535,7 @@ _copyTypeName(TypeName *from)
|
||||
COPY_SCALAR_FIELD(pct_type);
|
||||
COPY_SCALAR_FIELD(typmod);
|
||||
COPY_NODE_FIELD(arrayBounds);
|
||||
COPY_SCALAR_FIELD(location);
|
||||
|
||||
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.265 2006/03/05 15:58:27 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.266 2006/03/14 22:48:19 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1540,6 +1540,7 @@ _equalAExpr(A_Expr *a, A_Expr *b)
|
||||
COMPARE_NODE_FIELD(name);
|
||||
COMPARE_NODE_FIELD(lexpr);
|
||||
COMPARE_NODE_FIELD(rexpr);
|
||||
COMPARE_SCALAR_FIELD(location);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1548,6 +1549,7 @@ static bool
|
||||
_equalColumnRef(ColumnRef *a, ColumnRef *b)
|
||||
{
|
||||
COMPARE_NODE_FIELD(fields);
|
||||
COMPARE_SCALAR_FIELD(location);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1577,6 +1579,7 @@ _equalFuncCall(FuncCall *a, FuncCall *b)
|
||||
COMPARE_NODE_FIELD(args);
|
||||
COMPARE_SCALAR_FIELD(agg_star);
|
||||
COMPARE_SCALAR_FIELD(agg_distinct);
|
||||
COMPARE_SCALAR_FIELD(location);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1619,6 +1622,7 @@ _equalTypeName(TypeName *a, TypeName *b)
|
||||
COMPARE_SCALAR_FIELD(pct_type);
|
||||
COMPARE_SCALAR_FIELD(typmod);
|
||||
COMPARE_NODE_FIELD(arrayBounds);
|
||||
COMPARE_SCALAR_FIELD(location);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.49 2006/03/05 15:58:27 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.50 2006/03/14 22:48:19 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -25,7 +25,8 @@
|
||||
* makes an A_Expr node
|
||||
*/
|
||||
A_Expr *
|
||||
makeA_Expr(A_Expr_Kind kind, List *name, Node *lexpr, Node *rexpr)
|
||||
makeA_Expr(A_Expr_Kind kind, List *name,
|
||||
Node *lexpr, Node *rexpr, int location)
|
||||
{
|
||||
A_Expr *a = makeNode(A_Expr);
|
||||
|
||||
@ -33,6 +34,7 @@ makeA_Expr(A_Expr_Kind kind, List *name, Node *lexpr, Node *rexpr)
|
||||
a->name = name;
|
||||
a->lexpr = lexpr;
|
||||
a->rexpr = rexpr;
|
||||
a->location = location;
|
||||
return a;
|
||||
}
|
||||
|
||||
@ -42,7 +44,7 @@ makeA_Expr(A_Expr_Kind kind, List *name, Node *lexpr, Node *rexpr)
|
||||
*/
|
||||
A_Expr *
|
||||
makeSimpleA_Expr(A_Expr_Kind kind, const char *name,
|
||||
Node *lexpr, Node *rexpr)
|
||||
Node *lexpr, Node *rexpr, int location)
|
||||
{
|
||||
A_Expr *a = makeNode(A_Expr);
|
||||
|
||||
@ -50,6 +52,7 @@ makeSimpleA_Expr(A_Expr_Kind kind, const char *name,
|
||||
a->name = list_make1(makeString((char *) name));
|
||||
a->lexpr = lexpr;
|
||||
a->rexpr = rexpr;
|
||||
a->location = location;
|
||||
return a;
|
||||
}
|
||||
|
||||
@ -253,6 +256,8 @@ makeRangeVar(char *schemaname, char *relname)
|
||||
/*
|
||||
* makeTypeName -
|
||||
* build a TypeName node for an unqualified name.
|
||||
*
|
||||
* typmod is defaulted, but can be changed later by caller.
|
||||
*/
|
||||
TypeName *
|
||||
makeTypeName(char *typnam)
|
||||
@ -261,6 +266,39 @@ makeTypeName(char *typnam)
|
||||
|
||||
n->names = list_make1(makeString(typnam));
|
||||
n->typmod = -1;
|
||||
n->location = -1;
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
* makeTypeNameFromNameList -
|
||||
* build a TypeName node for a String list representing a qualified name.
|
||||
*
|
||||
* typmod is defaulted, but can be changed later by caller.
|
||||
*/
|
||||
TypeName *
|
||||
makeTypeNameFromNameList(List *names)
|
||||
{
|
||||
TypeName *n = makeNode(TypeName);
|
||||
|
||||
n->names = names;
|
||||
n->typmod = -1;
|
||||
n->location = -1;
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
* makeTypeNameFromOid -
|
||||
* build a TypeName node to represent a type already known by OID.
|
||||
*/
|
||||
TypeName *
|
||||
makeTypeNameFromOid(Oid typeid, int32 typmod)
|
||||
{
|
||||
TypeName *n = makeNode(TypeName);
|
||||
|
||||
n->typeid = typeid;
|
||||
n->typmod = typmod;
|
||||
n->location = -1;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.269 2006/03/05 15:58:27 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.270 2006/03/14 22:48:19 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Every node type that can appear in stored rules' parsetrees *must*
|
||||
@ -1400,6 +1400,7 @@ _outFuncCall(StringInfo str, FuncCall *node)
|
||||
WRITE_NODE_FIELD(args);
|
||||
WRITE_BOOL_FIELD(agg_star);
|
||||
WRITE_BOOL_FIELD(agg_distinct);
|
||||
WRITE_INT_FIELD(location);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1449,6 +1450,7 @@ _outTypeName(StringInfo str, TypeName *node)
|
||||
WRITE_BOOL_FIELD(pct_type);
|
||||
WRITE_INT_FIELD(typmod);
|
||||
WRITE_NODE_FIELD(arrayBounds);
|
||||
/* location is deliberately not stored */
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1648,6 +1650,7 @@ _outAExpr(StringInfo str, A_Expr *node)
|
||||
|
||||
WRITE_NODE_FIELD(lexpr);
|
||||
WRITE_NODE_FIELD(rexpr);
|
||||
WRITE_INT_FIELD(location);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1687,6 +1690,7 @@ _outColumnRef(StringInfo str, ColumnRef *node)
|
||||
WRITE_NODE_TYPE("COLUMNREF");
|
||||
|
||||
WRITE_NODE_FIELD(fields);
|
||||
WRITE_INT_FIELD(location);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.185 2006/03/05 15:58:28 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.186 2006/03/14 22:48:19 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Path and Plan nodes do not have any readfuncs support, because we
|
||||
@ -893,6 +893,8 @@ _readTypeName(void)
|
||||
READ_BOOL_FIELD(pct_type);
|
||||
READ_INT_FIELD(typmod);
|
||||
READ_NODE_FIELD(arrayBounds);
|
||||
/* location is deliberately not stored */
|
||||
local_node->location = -1;
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
|
Reference in New Issue
Block a user