1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-29 22:49:41 +03:00

Replace LookupFuncNameTypeNames() with LookupFuncWithArgs()

The old function took function name and function argument list as
separate arguments.  Now that all function signatures are passed around
as ObjectWithArgs structs, this is no longer necessary and can be
replaced by a function that takes ObjectWithArgs directly.  Similarly
for aggregates and operators.

Reviewed-by: Jim Nasby <Jim.Nasby@BlueTreble.com>
Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
This commit is contained in:
Peter Eisentraut
2016-12-28 12:00:00 -05:00
parent 8b6d6cf853
commit 2ca64c6f71
13 changed files with 68 additions and 116 deletions

View File

@@ -5778,9 +5778,11 @@ opclass_item:
OPERATOR Iconst any_operator opclass_purpose opt_recheck
{
CreateOpClassItem *n = makeNode(CreateOpClassItem);
ObjectWithArgs *owa = makeNode(ObjectWithArgs);
owa->objname = $3;
owa->objargs = NIL;
n->itemtype = OPCLASS_ITEM_OPERATOR;
n->name = $3;
n->args = NIL;
n->name = owa;
n->number = $2;
n->order_family = $4;
$$ = (Node *) n;
@@ -5790,8 +5792,7 @@ opclass_item:
{
CreateOpClassItem *n = makeNode(CreateOpClassItem);
n->itemtype = OPCLASS_ITEM_OPERATOR;
n->name = $3->objname;
n->args = $3->objargs;
n->name = $3;
n->number = $2;
n->order_family = $4;
$$ = (Node *) n;
@@ -5800,8 +5801,7 @@ opclass_item:
{
CreateOpClassItem *n = makeNode(CreateOpClassItem);
n->itemtype = OPCLASS_ITEM_FUNCTION;
n->name = $3->objname;
n->args = $3->objargs;
n->name = $3;
n->number = $2;
$$ = (Node *) n;
}
@@ -5809,8 +5809,7 @@ opclass_item:
{
CreateOpClassItem *n = makeNode(CreateOpClassItem);
n->itemtype = OPCLASS_ITEM_FUNCTION;
n->name = $6->objname;
n->args = $6->objargs;
n->name = $6;
n->number = $2;
n->class_args = $4;
$$ = (Node *) n;
@@ -8789,8 +8788,7 @@ AlterOperatorStmt:
ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
{
AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
n->opername = $3->objname;
n->operargs = $3->objargs;
n->opername = $3;
n->options = $6;
$$ = (Node *)n;
}

View File

@@ -1932,19 +1932,19 @@ LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool noError)
}
/*
* LookupFuncNameTypeNames
* LookupFuncWithArgs
* Like LookupFuncName, but the argument types are specified by a
* list of TypeName nodes.
* ObjectWithArgs node.
*/
Oid
LookupFuncNameTypeNames(List *funcname, List *argtypes, bool noError)
LookupFuncWithArgs(ObjectWithArgs *func, bool noError)
{
Oid argoids[FUNC_MAX_ARGS];
int argcount;
int i;
ListCell *args_item;
argcount = list_length(argtypes);
argcount = list_length(func->objargs);
if (argcount > FUNC_MAX_ARGS)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
@@ -1953,7 +1953,7 @@ LookupFuncNameTypeNames(List *funcname, List *argtypes, bool noError)
FUNC_MAX_ARGS,
FUNC_MAX_ARGS)));
args_item = list_head(argtypes);
args_item = list_head(func->objargs);
for (i = 0; i < argcount; i++)
{
TypeName *t = (TypeName *) lfirst(args_item);
@@ -1962,19 +1962,19 @@ LookupFuncNameTypeNames(List *funcname, List *argtypes, bool noError)
args_item = lnext(args_item);
}
return LookupFuncName(funcname, argcount, argoids, noError);
return LookupFuncName(func->objname, argcount, argoids, noError);
}
/*
* LookupAggNameTypeNames
* Find an aggregate function given a name and list of TypeName nodes.
* LookupAggWithArgs
* Find an aggregate function from a given ObjectWithArgs node.
*
* This is almost like LookupFuncNameTypeNames, but the error messages refer
* This is almost like LookupFuncWithArgs, but the error messages refer
* to aggregates rather than plain functions, and we verify that the found
* function really is an aggregate.
*/
Oid
LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
LookupAggWithArgs(ObjectWithArgs *agg, bool noError)
{
Oid argoids[FUNC_MAX_ARGS];
int argcount;
@@ -1984,7 +1984,7 @@ LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
HeapTuple ftup;
Form_pg_proc pform;
argcount = list_length(argtypes);
argcount = list_length(agg->objargs);
if (argcount > FUNC_MAX_ARGS)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
@@ -1994,7 +1994,7 @@ LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
FUNC_MAX_ARGS)));
i = 0;
foreach(lc, argtypes)
foreach(lc, agg->objargs)
{
TypeName *t = (TypeName *) lfirst(lc);
@@ -2002,7 +2002,7 @@ LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
i++;
}
oid = LookupFuncName(aggname, argcount, argoids, true);
oid = LookupFuncName(agg->objname, argcount, argoids, true);
if (!OidIsValid(oid))
{
@@ -2012,12 +2012,12 @@ LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("aggregate %s(*) does not exist",
NameListToString(aggname))));
NameListToString(agg->objname))));
else
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("aggregate %s does not exist",
func_signature_string(aggname, argcount,
func_signature_string(agg->objname, argcount,
NIL, argoids))));
}
@@ -2036,7 +2036,7 @@ LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("function %s is not an aggregate",
func_signature_string(aggname, argcount,
func_signature_string(agg->objname, argcount,
NIL, argoids))));
}

View File

@@ -132,32 +132,34 @@ LookupOperName(ParseState *pstate, List *opername, Oid oprleft, Oid oprright,
}
/*
* LookupOperNameTypeNames
* LookupOperWithArgs
* Like LookupOperName, but the argument types are specified by
* TypeName nodes.
*
* Pass oprleft = NULL for a prefix op, oprright = NULL for a postfix op.
* a ObjectWithArg node.
*/
Oid
LookupOperNameTypeNames(ParseState *pstate, List *opername,
TypeName *oprleft, TypeName *oprright,
bool noError, int location)
LookupOperWithArgs(ObjectWithArgs *oper, bool noError)
{
TypeName *oprleft,
*oprright;
Oid leftoid,
rightoid;
Assert(list_length(oper->objargs) == 2);
oprleft = linitial(oper->objargs);
oprright = lsecond(oper->objargs);
if (oprleft == NULL)
leftoid = InvalidOid;
else
leftoid = LookupTypeNameOid(pstate, oprleft, noError);
leftoid = LookupTypeNameOid(NULL, oprleft, noError);
if (oprright == NULL)
rightoid = InvalidOid;
else
rightoid = LookupTypeNameOid(pstate, oprright, noError);
rightoid = LookupTypeNameOid(NULL, oprright, noError);
return LookupOperName(pstate, opername, leftoid, rightoid,
noError, location);
return LookupOperName(NULL, oper->objname, leftoid, rightoid,
noError, -1);
}
/*