Add const qualifiers to node inspection functions

Thomas Munro
pull/1/head
Peter Eisentraut 14 years ago
parent 0d0ec527af
commit d5f23af6bf
  1. 518
      src/backend/nodes/copyfuncs.c
  2. 364
      src/backend/nodes/equalfuncs.c
  3. 74
      src/backend/nodes/list.c
  4. 306
      src/backend/nodes/nodeFuncs.c
  5. 440
      src/backend/nodes/outfuncs.c
  6. 34
      src/backend/nodes/print.c
  7. 8
      src/backend/optimizer/util/clauses.c
  8. 12
      src/include/nodes/nodeFuncs.h
  9. 8
      src/include/nodes/nodes.h
  10. 44
      src/include/nodes/pg_list.h
  11. 14
      src/include/nodes/print.h
  12. 4
      src/include/optimizer/clauses.h

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -31,7 +31,7 @@
* Check that the specified List is valid (so far as we can tell). * Check that the specified List is valid (so far as we can tell).
*/ */
static void static void
check_list_invariants(List *list) check_list_invariants(const List *list)
{ {
if (list == NIL) if (list == NIL)
return; return;
@ -383,7 +383,7 @@ list_truncate(List *list, int new_size)
* failure if there is no such cell. * failure if there is no such cell.
*/ */
static ListCell * static ListCell *
list_nth_cell(List *list, int n) list_nth_cell(const List *list, int n)
{ {
ListCell *match; ListCell *match;
@ -407,7 +407,7 @@ list_nth_cell(List *list, int n)
* specified list. (List elements begin at 0.) * specified list. (List elements begin at 0.)
*/ */
void * void *
list_nth(List *list, int n) list_nth(const List *list, int n)
{ {
Assert(IsPointerList(list)); Assert(IsPointerList(list));
return lfirst(list_nth_cell(list, n)); return lfirst(list_nth_cell(list, n));
@ -418,7 +418,7 @@ list_nth(List *list, int n)
* specified list. * specified list.
*/ */
int int
list_nth_int(List *list, int n) list_nth_int(const List *list, int n)
{ {
Assert(IsIntegerList(list)); Assert(IsIntegerList(list));
return lfirst_int(list_nth_cell(list, n)); return lfirst_int(list_nth_cell(list, n));
@ -429,7 +429,7 @@ list_nth_int(List *list, int n)
* list. * list.
*/ */
Oid Oid
list_nth_oid(List *list, int n) list_nth_oid(const List *list, int n)
{ {
Assert(IsOidList(list)); Assert(IsOidList(list));
return lfirst_oid(list_nth_cell(list, n)); return lfirst_oid(list_nth_cell(list, n));
@ -441,9 +441,9 @@ list_nth_oid(List *list, int n)
* Node as 'datum'. * Node as 'datum'.
*/ */
bool bool
list_member(List *list, void *datum) list_member(const List *list, const void *datum)
{ {
ListCell *cell; const ListCell *cell;
Assert(IsPointerList(list)); Assert(IsPointerList(list));
check_list_invariants(list); check_list_invariants(list);
@ -462,9 +462,9 @@ list_member(List *list, void *datum)
* determined by using simple pointer comparison. * determined by using simple pointer comparison.
*/ */
bool bool
list_member_ptr(List *list, void *datum) list_member_ptr(const List *list, const void *datum)
{ {
ListCell *cell; const ListCell *cell;
Assert(IsPointerList(list)); Assert(IsPointerList(list));
check_list_invariants(list); check_list_invariants(list);
@ -482,9 +482,9 @@ list_member_ptr(List *list, void *datum)
* Return true iff the integer 'datum' is a member of the list. * Return true iff the integer 'datum' is a member of the list.
*/ */
bool bool
list_member_int(List *list, int datum) list_member_int(const List *list, int datum)
{ {
ListCell *cell; const ListCell *cell;
Assert(IsIntegerList(list)); Assert(IsIntegerList(list));
check_list_invariants(list); check_list_invariants(list);
@ -502,9 +502,9 @@ list_member_int(List *list, int datum)
* Return true iff the OID 'datum' is a member of the list. * Return true iff the OID 'datum' is a member of the list.
*/ */
bool bool
list_member_oid(List *list, Oid datum) list_member_oid(const List *list, Oid datum)
{ {
ListCell *cell; const ListCell *cell;
Assert(IsOidList(list)); Assert(IsOidList(list));
check_list_invariants(list); check_list_invariants(list);
@ -694,10 +694,10 @@ list_delete_first(List *list)
* performance bottleneck. * performance bottleneck.
*/ */
List * List *
list_union(List *list1, List *list2) list_union(const List *list1, const List *list2)
{ {
List *result; List *result;
ListCell *cell; const ListCell *cell;
Assert(IsPointerList(list1)); Assert(IsPointerList(list1));
Assert(IsPointerList(list2)); Assert(IsPointerList(list2));
@ -718,10 +718,10 @@ list_union(List *list1, List *list2)
* pointer comparison. * pointer comparison.
*/ */
List * List *
list_union_ptr(List *list1, List *list2) list_union_ptr(const List *list1, const List *list2)
{ {
List *result; List *result;
ListCell *cell; const ListCell *cell;
Assert(IsPointerList(list1)); Assert(IsPointerList(list1));
Assert(IsPointerList(list2)); Assert(IsPointerList(list2));
@ -741,10 +741,10 @@ list_union_ptr(List *list1, List *list2)
* This variant of list_union() operates upon lists of integers. * This variant of list_union() operates upon lists of integers.
*/ */
List * List *
list_union_int(List *list1, List *list2) list_union_int(const List *list1, const List *list2)
{ {
List *result; List *result;
ListCell *cell; const ListCell *cell;
Assert(IsIntegerList(list1)); Assert(IsIntegerList(list1));
Assert(IsIntegerList(list2)); Assert(IsIntegerList(list2));
@ -764,10 +764,10 @@ list_union_int(List *list1, List *list2)
* This variant of list_union() operates upon lists of OIDs. * This variant of list_union() operates upon lists of OIDs.
*/ */
List * List *
list_union_oid(List *list1, List *list2) list_union_oid(const List *list1, const List *list2)
{ {
List *result; List *result;
ListCell *cell; const ListCell *cell;
Assert(IsOidList(list1)); Assert(IsOidList(list1));
Assert(IsOidList(list2)); Assert(IsOidList(list2));
@ -797,10 +797,10 @@ list_union_oid(List *list1, List *list2)
* to in the result. * to in the result.
*/ */
List * List *
list_intersection(List *list1, List *list2) list_intersection(const List *list1, const List *list2)
{ {
List *result; List *result;
ListCell *cell; const ListCell *cell;
if (list1 == NIL || list2 == NIL) if (list1 == NIL || list2 == NIL)
return NIL; return NIL;
@ -829,9 +829,9 @@ list_intersection(List *list1, List *list2)
* membership via equal() * membership via equal()
*/ */
List * List *
list_difference(List *list1, List *list2) list_difference(const List *list1, const List *list2)
{ {
ListCell *cell; const ListCell *cell;
List *result = NIL; List *result = NIL;
Assert(IsPointerList(list1)); Assert(IsPointerList(list1));
@ -855,9 +855,9 @@ list_difference(List *list1, List *list2)
* simple pointer equality. * simple pointer equality.
*/ */
List * List *
list_difference_ptr(List *list1, List *list2) list_difference_ptr(const List *list1, const List *list2)
{ {
ListCell *cell; const ListCell *cell;
List *result = NIL; List *result = NIL;
Assert(IsPointerList(list1)); Assert(IsPointerList(list1));
@ -880,9 +880,9 @@ list_difference_ptr(List *list1, List *list2)
* This variant of list_difference() operates upon lists of integers. * This variant of list_difference() operates upon lists of integers.
*/ */
List * List *
list_difference_int(List *list1, List *list2) list_difference_int(const List *list1, const List *list2)
{ {
ListCell *cell; const ListCell *cell;
List *result = NIL; List *result = NIL;
Assert(IsIntegerList(list1)); Assert(IsIntegerList(list1));
@ -905,9 +905,9 @@ list_difference_int(List *list1, List *list2)
* This variant of list_difference() operates upon lists of OIDs. * This variant of list_difference() operates upon lists of OIDs.
*/ */
List * List *
list_difference_oid(List *list1, List *list2) list_difference_oid(const List *list1, const List *list2)
{ {
ListCell *cell; const ListCell *cell;
List *result = NIL; List *result = NIL;
Assert(IsOidList(list1)); Assert(IsOidList(list1));
@ -1131,7 +1131,7 @@ list_free_deep(List *list)
* Return a shallow copy of the specified list. * Return a shallow copy of the specified list.
*/ */
List * List *
list_copy(List *oldlist) list_copy(const List *oldlist)
{ {
List *newlist; List *newlist;
ListCell *newlist_prev; ListCell *newlist_prev;
@ -1174,7 +1174,7 @@ list_copy(List *oldlist)
* Return a shallow copy of the specified list, without the first N elements. * Return a shallow copy of the specified list, without the first N elements.
*/ */
List * List *
list_copy_tail(List *oldlist, int nskip) list_copy_tail(const List *oldlist, int nskip)
{ {
List *newlist; List *newlist;
ListCell *newlist_prev; ListCell *newlist_prev;
@ -1230,7 +1230,7 @@ list_copy_tail(List *oldlist, int nskip)
#ifndef USE_INLINE #ifndef USE_INLINE
ListCell * ListCell *
list_head(List *l) list_head(const List *l)
{ {
return l ? l->head : NULL; return l ? l->head : NULL;
} }
@ -1242,7 +1242,7 @@ list_tail(List *l)
} }
int int
list_length(List *l) list_length(const List *l)
{ {
return l ? l->length : 0; return l ? l->length : 0;
} }
@ -1264,10 +1264,10 @@ list_length(List *l)
* list_length() macro in order to avoid the overhead of a function * list_length() macro in order to avoid the overhead of a function
* call. * call.
*/ */
int length(List *list); int length(const List *list);
int int
length(List *list) length(const List *list)
{ {
return list_length(list); return list_length(list);
} }

@ -32,7 +32,7 @@ static int leftmostLoc(int loc1, int loc2);
* returns the Oid of the type of the expression's result. * returns the Oid of the type of the expression's result.
*/ */
Oid Oid
exprType(Node *expr) exprType(const Node *expr)
{ {
Oid type; Oid type;
@ -42,23 +42,23 @@ exprType(Node *expr)
switch (nodeTag(expr)) switch (nodeTag(expr))
{ {
case T_Var: case T_Var:
type = ((Var *) expr)->vartype; type = ((const Var *) expr)->vartype;
break; break;
case T_Const: case T_Const:
type = ((Const *) expr)->consttype; type = ((const Const *) expr)->consttype;
break; break;
case T_Param: case T_Param:
type = ((Param *) expr)->paramtype; type = ((const Param *) expr)->paramtype;
break; break;
case T_Aggref: case T_Aggref:
type = ((Aggref *) expr)->aggtype; type = ((const Aggref *) expr)->aggtype;
break; break;
case T_WindowFunc: case T_WindowFunc:
type = ((WindowFunc *) expr)->wintype; type = ((const WindowFunc *) expr)->wintype;
break; break;
case T_ArrayRef: case T_ArrayRef:
{ {
ArrayRef *arrayref = (ArrayRef *) expr; const ArrayRef *arrayref = (const ArrayRef *) expr;
/* slice and/or store operations yield the array type */ /* slice and/or store operations yield the array type */
if (arrayref->reflowerindexpr || arrayref->refassgnexpr) if (arrayref->reflowerindexpr || arrayref->refassgnexpr)
@ -68,19 +68,19 @@ exprType(Node *expr)
} }
break; break;
case T_FuncExpr: case T_FuncExpr:
type = ((FuncExpr *) expr)->funcresulttype; type = ((const FuncExpr *) expr)->funcresulttype;
break; break;
case T_NamedArgExpr: case T_NamedArgExpr:
type = exprType((Node *) ((NamedArgExpr *) expr)->arg); type = exprType((Node *) ((const NamedArgExpr *) expr)->arg);
break; break;
case T_OpExpr: case T_OpExpr:
type = ((OpExpr *) expr)->opresulttype; type = ((const OpExpr *) expr)->opresulttype;
break; break;
case T_DistinctExpr: case T_DistinctExpr:
type = ((DistinctExpr *) expr)->opresulttype; type = ((const DistinctExpr *) expr)->opresulttype;
break; break;
case T_NullIfExpr: case T_NullIfExpr:
type = ((NullIfExpr *) expr)->opresulttype; type = ((const NullIfExpr *) expr)->opresulttype;
break; break;
case T_ScalarArrayOpExpr: case T_ScalarArrayOpExpr:
type = BOOLOID; type = BOOLOID;
@ -90,7 +90,7 @@ exprType(Node *expr)
break; break;
case T_SubLink: case T_SubLink:
{ {
SubLink *sublink = (SubLink *) expr; const SubLink *sublink = (const SubLink *) expr;
if (sublink->subLinkType == EXPR_SUBLINK || if (sublink->subLinkType == EXPR_SUBLINK ||
sublink->subLinkType == ARRAY_SUBLINK) sublink->subLinkType == ARRAY_SUBLINK)
@ -124,7 +124,7 @@ exprType(Node *expr)
break; break;
case T_SubPlan: case T_SubPlan:
{ {
SubPlan *subplan = (SubPlan *) expr; const SubPlan *subplan = (const SubPlan *) expr;
if (subplan->subLinkType == EXPR_SUBLINK || if (subplan->subLinkType == EXPR_SUBLINK ||
subplan->subLinkType == ARRAY_SUBLINK) subplan->subLinkType == ARRAY_SUBLINK)
@ -150,58 +150,58 @@ exprType(Node *expr)
break; break;
case T_AlternativeSubPlan: case T_AlternativeSubPlan:
{ {
AlternativeSubPlan *asplan = (AlternativeSubPlan *) expr; const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
/* subplans should all return the same thing */ /* subplans should all return the same thing */
type = exprType((Node *) linitial(asplan->subplans)); type = exprType((Node *) linitial(asplan->subplans));
} }
break; break;
case T_FieldSelect: case T_FieldSelect:
type = ((FieldSelect *) expr)->resulttype; type = ((const FieldSelect *) expr)->resulttype;
break; break;
case T_FieldStore: case T_FieldStore:
type = ((FieldStore *) expr)->resulttype; type = ((const FieldStore *) expr)->resulttype;
break; break;
case T_RelabelType: case T_RelabelType:
type = ((RelabelType *) expr)->resulttype; type = ((const RelabelType *) expr)->resulttype;
break; break;
case T_CoerceViaIO: case T_CoerceViaIO:
type = ((CoerceViaIO *) expr)->resulttype; type = ((const CoerceViaIO *) expr)->resulttype;
break; break;
case T_ArrayCoerceExpr: case T_ArrayCoerceExpr:
type = ((ArrayCoerceExpr *) expr)->resulttype; type = ((const ArrayCoerceExpr *) expr)->resulttype;
break; break;
case T_ConvertRowtypeExpr: case T_ConvertRowtypeExpr:
type = ((ConvertRowtypeExpr *) expr)->resulttype; type = ((const ConvertRowtypeExpr *) expr)->resulttype;
break; break;
case T_CollateExpr: case T_CollateExpr:
type = exprType((Node *) ((CollateExpr *) expr)->arg); type = exprType((Node *) ((const CollateExpr *) expr)->arg);
break; break;
case T_CaseExpr: case T_CaseExpr:
type = ((CaseExpr *) expr)->casetype; type = ((const CaseExpr *) expr)->casetype;
break; break;
case T_CaseTestExpr: case T_CaseTestExpr:
type = ((CaseTestExpr *) expr)->typeId; type = ((const CaseTestExpr *) expr)->typeId;
break; break;
case T_ArrayExpr: case T_ArrayExpr:
type = ((ArrayExpr *) expr)->array_typeid; type = ((const ArrayExpr *) expr)->array_typeid;
break; break;
case T_RowExpr: case T_RowExpr:
type = ((RowExpr *) expr)->row_typeid; type = ((const RowExpr *) expr)->row_typeid;
break; break;
case T_RowCompareExpr: case T_RowCompareExpr:
type = BOOLOID; type = BOOLOID;
break; break;
case T_CoalesceExpr: case T_CoalesceExpr:
type = ((CoalesceExpr *) expr)->coalescetype; type = ((const CoalesceExpr *) expr)->coalescetype;
break; break;
case T_MinMaxExpr: case T_MinMaxExpr:
type = ((MinMaxExpr *) expr)->minmaxtype; type = ((const MinMaxExpr *) expr)->minmaxtype;
break; break;
case T_XmlExpr: case T_XmlExpr:
if (((XmlExpr *) expr)->op == IS_DOCUMENT) if (((const XmlExpr *) expr)->op == IS_DOCUMENT)
type = BOOLOID; type = BOOLOID;
else if (((XmlExpr *) expr)->op == IS_XMLSERIALIZE) else if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
type = TEXTOID; type = TEXTOID;
else else
type = XMLOID; type = XMLOID;
@ -213,19 +213,19 @@ exprType(Node *expr)
type = BOOLOID; type = BOOLOID;
break; break;
case T_CoerceToDomain: case T_CoerceToDomain:
type = ((CoerceToDomain *) expr)->resulttype; type = ((const CoerceToDomain *) expr)->resulttype;
break; break;
case T_CoerceToDomainValue: case T_CoerceToDomainValue:
type = ((CoerceToDomainValue *) expr)->typeId; type = ((const CoerceToDomainValue *) expr)->typeId;
break; break;
case T_SetToDefault: case T_SetToDefault:
type = ((SetToDefault *) expr)->typeId; type = ((const SetToDefault *) expr)->typeId;
break; break;
case T_CurrentOfExpr: case T_CurrentOfExpr:
type = BOOLOID; type = BOOLOID;
break; break;
case T_PlaceHolderVar: case T_PlaceHolderVar:
type = exprType((Node *) ((PlaceHolderVar *) expr)->phexpr); type = exprType((Node *) ((const PlaceHolderVar *) expr)->phexpr);
break; break;
default: default:
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr)); elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
@ -241,7 +241,7 @@ exprType(Node *expr)
* if it can be determined. In many cases, it can't and we return -1. * if it can be determined. In many cases, it can't and we return -1.
*/ */
int32 int32
exprTypmod(Node *expr) exprTypmod(const Node *expr)
{ {
if (!expr) if (!expr)
return -1; return -1;
@ -249,14 +249,14 @@ exprTypmod(Node *expr)
switch (nodeTag(expr)) switch (nodeTag(expr))
{ {
case T_Var: case T_Var:
return ((Var *) expr)->vartypmod; return ((const Var *) expr)->vartypmod;
case T_Const: case T_Const:
return ((Const *) expr)->consttypmod; return ((const Const *) expr)->consttypmod;
case T_Param: case T_Param:
return ((Param *) expr)->paramtypmod; return ((const Param *) expr)->paramtypmod;
case T_ArrayRef: case T_ArrayRef:
/* typmod is the same for array or element */ /* typmod is the same for array or element */
return ((ArrayRef *) expr)->reftypmod; return ((const ArrayRef *) expr)->reftypmod;
case T_FuncExpr: case T_FuncExpr:
{ {
int32 coercedTypmod; int32 coercedTypmod;
@ -267,21 +267,21 @@ exprTypmod(Node *expr)
} }
break; break;
case T_NamedArgExpr: case T_NamedArgExpr:
return exprTypmod((Node *) ((NamedArgExpr *) expr)->arg); return exprTypmod((Node *) ((const NamedArgExpr *) expr)->arg);
case T_NullIfExpr: case T_NullIfExpr:
{ {
/* /*
* Result is either first argument or NULL, so we can report * Result is either first argument or NULL, so we can report
* first argument's typmod if known. * first argument's typmod if known.
*/ */
NullIfExpr *nexpr = (NullIfExpr *) expr; const NullIfExpr *nexpr = (const NullIfExpr *) expr;
return exprTypmod((Node *) linitial(nexpr->args)); return exprTypmod((Node *) linitial(nexpr->args));
} }
break; break;
case T_SubLink: case T_SubLink:
{ {
SubLink *sublink = (SubLink *) expr; const SubLink *sublink = (const SubLink *) expr;
if (sublink->subLinkType == EXPR_SUBLINK || if (sublink->subLinkType == EXPR_SUBLINK ||
sublink->subLinkType == ARRAY_SUBLINK) sublink->subLinkType == ARRAY_SUBLINK)
@ -302,7 +302,7 @@ exprTypmod(Node *expr)
break; break;
case T_SubPlan: case T_SubPlan:
{ {
SubPlan *subplan = (SubPlan *) expr; const SubPlan *subplan = (const SubPlan *) expr;
if (subplan->subLinkType == EXPR_SUBLINK || if (subplan->subLinkType == EXPR_SUBLINK ||
subplan->subLinkType == ARRAY_SUBLINK) subplan->subLinkType == ARRAY_SUBLINK)
@ -320,27 +320,27 @@ exprTypmod(Node *expr)
break; break;
case T_AlternativeSubPlan: case T_AlternativeSubPlan:
{ {
AlternativeSubPlan *asplan = (AlternativeSubPlan *) expr; const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
/* subplans should all return the same thing */ /* subplans should all return the same thing */
return exprTypmod((Node *) linitial(asplan->subplans)); return exprTypmod((Node *) linitial(asplan->subplans));
} }
break; break;
case T_FieldSelect: case T_FieldSelect:
return ((FieldSelect *) expr)->resulttypmod; return ((const FieldSelect *) expr)->resulttypmod;
case T_RelabelType: case T_RelabelType:
return ((RelabelType *) expr)->resulttypmod; return ((const RelabelType *) expr)->resulttypmod;
case T_ArrayCoerceExpr: case T_ArrayCoerceExpr:
return ((ArrayCoerceExpr *) expr)->resulttypmod; return ((const ArrayCoerceExpr *) expr)->resulttypmod;
case T_CollateExpr: case T_CollateExpr:
return exprTypmod((Node *) ((CollateExpr *) expr)->arg); return exprTypmod((Node *) ((const CollateExpr *) expr)->arg);
case T_CaseExpr: case T_CaseExpr:
{ {
/* /*
* If all the alternatives agree on type/typmod, return that * If all the alternatives agree on type/typmod, return that
* typmod, else use -1 * typmod, else use -1
*/ */
CaseExpr *cexpr = (CaseExpr *) expr; const CaseExpr *cexpr = (const CaseExpr *) expr;
Oid casetype = cexpr->casetype; Oid casetype = cexpr->casetype;
int32 typmod; int32 typmod;
ListCell *arg; ListCell *arg;
@ -366,14 +366,14 @@ exprTypmod(Node *expr)
} }
break; break;
case T_CaseTestExpr: case T_CaseTestExpr:
return ((CaseTestExpr *) expr)->typeMod; return ((const CaseTestExpr *) expr)->typeMod;
case T_ArrayExpr: case T_ArrayExpr:
{ {
/* /*
* If all the elements agree on type/typmod, return that * If all the elements agree on type/typmod, return that
* typmod, else use -1 * typmod, else use -1
*/ */
ArrayExpr *arrayexpr = (ArrayExpr *) expr; const ArrayExpr *arrayexpr = (const ArrayExpr *) expr;
Oid commontype; Oid commontype;
int32 typmod; int32 typmod;
ListCell *elem; ListCell *elem;
@ -405,7 +405,7 @@ exprTypmod(Node *expr)
* If all the alternatives agree on type/typmod, return that * If all the alternatives agree on type/typmod, return that
* typmod, else use -1 * typmod, else use -1
*/ */
CoalesceExpr *cexpr = (CoalesceExpr *) expr; const CoalesceExpr *cexpr = (const CoalesceExpr *) expr;
Oid coalescetype = cexpr->coalescetype; Oid coalescetype = cexpr->coalescetype;
int32 typmod; int32 typmod;
ListCell *arg; ListCell *arg;
@ -433,7 +433,7 @@ exprTypmod(Node *expr)
* If all the alternatives agree on type/typmod, return that * If all the alternatives agree on type/typmod, return that
* typmod, else use -1 * typmod, else use -1
*/ */
MinMaxExpr *mexpr = (MinMaxExpr *) expr; const MinMaxExpr *mexpr = (const MinMaxExpr *) expr;
Oid minmaxtype = mexpr->minmaxtype; Oid minmaxtype = mexpr->minmaxtype;
int32 typmod; int32 typmod;
ListCell *arg; ListCell *arg;
@ -456,13 +456,13 @@ exprTypmod(Node *expr)
} }
break; break;
case T_CoerceToDomain: case T_CoerceToDomain:
return ((CoerceToDomain *) expr)->resulttypmod; return ((const CoerceToDomain *) expr)->resulttypmod;
case T_CoerceToDomainValue: case T_CoerceToDomainValue:
return ((CoerceToDomainValue *) expr)->typeMod; return ((const CoerceToDomainValue *) expr)->typeMod;
case T_SetToDefault: case T_SetToDefault:
return ((SetToDefault *) expr)->typeMod; return ((const SetToDefault *) expr)->typeMod;
case T_PlaceHolderVar: case T_PlaceHolderVar:
return exprTypmod((Node *) ((PlaceHolderVar *) expr)->phexpr); return exprTypmod((Node *) ((const PlaceHolderVar *) expr)->phexpr);
default: default:
break; break;
} }
@ -481,7 +481,7 @@ exprTypmod(Node *expr)
* length coercion by this routine. * length coercion by this routine.
*/ */
bool bool
exprIsLengthCoercion(Node *expr, int32 *coercedTypmod) exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod)
{ {
if (coercedTypmod != NULL) if (coercedTypmod != NULL)
*coercedTypmod = -1; /* default result on failure */ *coercedTypmod = -1; /* default result on failure */
@ -492,7 +492,7 @@ exprIsLengthCoercion(Node *expr, int32 *coercedTypmod)
*/ */
if (expr && IsA(expr, FuncExpr)) if (expr && IsA(expr, FuncExpr))
{ {
FuncExpr *func = (FuncExpr *) expr; const FuncExpr *func = (const FuncExpr *) expr;
int nargs; int nargs;
Const *second_arg; Const *second_arg;
@ -529,7 +529,7 @@ exprIsLengthCoercion(Node *expr, int32 *coercedTypmod)
if (expr && IsA(expr, ArrayCoerceExpr)) if (expr && IsA(expr, ArrayCoerceExpr))
{ {
ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) expr; const ArrayCoerceExpr *acoerce = (const ArrayCoerceExpr *) expr;
/* It's not a length coercion unless there's a nondefault typmod */ /* It's not a length coercion unless there's a nondefault typmod */
if (acoerce->resulttypmod < 0) if (acoerce->resulttypmod < 0)
@ -632,7 +632,7 @@ expression_returns_set_walker(Node *node, void *context)
* or vice versa, the two are different. * or vice versa, the two are different.
*/ */
Oid Oid
exprCollation(Node *expr) exprCollation(const Node *expr)
{ {
Oid coll; Oid coll;
@ -642,37 +642,37 @@ exprCollation(Node *expr)
switch (nodeTag(expr)) switch (nodeTag(expr))
{ {
case T_Var: case T_Var:
coll = ((Var *) expr)->varcollid; coll = ((const Var *) expr)->varcollid;
break; break;
case T_Const: case T_Const:
coll = ((Const *) expr)->constcollid; coll = ((const Const *) expr)->constcollid;
break; break;
case T_Param: case T_Param:
coll = ((Param *) expr)->paramcollid; coll = ((const Param *) expr)->paramcollid;
break; break;
case T_Aggref: case T_Aggref:
coll = ((Aggref *) expr)->aggcollid; coll = ((const Aggref *) expr)->aggcollid;
break; break;
case T_WindowFunc: case T_WindowFunc:
coll = ((WindowFunc *) expr)->wincollid; coll = ((const WindowFunc *) expr)->wincollid;
break; break;
case T_ArrayRef: case T_ArrayRef:
coll = ((ArrayRef *) expr)->refcollid; coll = ((const ArrayRef *) expr)->refcollid;
break; break;
case T_FuncExpr: case T_FuncExpr:
coll = ((FuncExpr *) expr)->funccollid; coll = ((const FuncExpr *) expr)->funccollid;
break; break;
case T_NamedArgExpr: case T_NamedArgExpr:
coll = exprCollation((Node *) ((NamedArgExpr *) expr)->arg); coll = exprCollation((Node *) ((const NamedArgExpr *) expr)->arg);
break; break;
case T_OpExpr: case T_OpExpr:
coll = ((OpExpr *) expr)->opcollid; coll = ((const OpExpr *) expr)->opcollid;
break; break;
case T_DistinctExpr: case T_DistinctExpr:
coll = ((DistinctExpr *) expr)->opcollid; coll = ((const DistinctExpr *) expr)->opcollid;
break; break;
case T_NullIfExpr: case T_NullIfExpr:
coll = ((NullIfExpr *) expr)->opcollid; coll = ((const NullIfExpr *) expr)->opcollid;
break; break;
case T_ScalarArrayOpExpr: case T_ScalarArrayOpExpr:
coll = InvalidOid; /* result is always boolean */ coll = InvalidOid; /* result is always boolean */
@ -682,7 +682,7 @@ exprCollation(Node *expr)
break; break;
case T_SubLink: case T_SubLink:
{ {
SubLink *sublink = (SubLink *) expr; const SubLink *sublink = (const SubLink *) expr;
if (sublink->subLinkType == EXPR_SUBLINK || if (sublink->subLinkType == EXPR_SUBLINK ||
sublink->subLinkType == ARRAY_SUBLINK) sublink->subLinkType == ARRAY_SUBLINK)
@ -708,7 +708,7 @@ exprCollation(Node *expr)
break; break;
case T_SubPlan: case T_SubPlan:
{ {
SubPlan *subplan = (SubPlan *) expr; const SubPlan *subplan = (const SubPlan *) expr;
if (subplan->subLinkType == EXPR_SUBLINK || if (subplan->subLinkType == EXPR_SUBLINK ||
subplan->subLinkType == ARRAY_SUBLINK) subplan->subLinkType == ARRAY_SUBLINK)
@ -726,41 +726,41 @@ exprCollation(Node *expr)
break; break;
case T_AlternativeSubPlan: case T_AlternativeSubPlan:
{ {
AlternativeSubPlan *asplan = (AlternativeSubPlan *) expr; const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
/* subplans should all return the same thing */ /* subplans should all return the same thing */
coll = exprCollation((Node *) linitial(asplan->subplans)); coll = exprCollation((Node *) linitial(asplan->subplans));
} }
break; break;
case T_FieldSelect: case T_FieldSelect:
coll = ((FieldSelect *) expr)->resultcollid; coll = ((const FieldSelect *) expr)->resultcollid;
break; break;
case T_FieldStore: case T_FieldStore:
coll = InvalidOid; /* result is always composite */ coll = InvalidOid; /* result is always composite */
break; break;
case T_RelabelType: case T_RelabelType:
coll = ((RelabelType *) expr)->resultcollid; coll = ((const RelabelType *) expr)->resultcollid;
break; break;
case T_CoerceViaIO: case T_CoerceViaIO:
coll = ((CoerceViaIO *) expr)->resultcollid; coll = ((const CoerceViaIO *) expr)->resultcollid;
break; break;
case T_ArrayCoerceExpr: case T_ArrayCoerceExpr:
coll = ((ArrayCoerceExpr *) expr)->resultcollid; coll = ((const ArrayCoerceExpr *) expr)->resultcollid;
break; break;
case T_ConvertRowtypeExpr: case T_ConvertRowtypeExpr:
coll = InvalidOid; /* result is always composite */ coll = InvalidOid; /* result is always composite */
break; break;
case T_CollateExpr: case T_CollateExpr:
coll = ((CollateExpr *) expr)->collOid; coll = ((const CollateExpr *) expr)->collOid;
break; break;
case T_CaseExpr: case T_CaseExpr:
coll = ((CaseExpr *) expr)->casecollid; coll = ((const CaseExpr *) expr)->casecollid;
break; break;
case T_CaseTestExpr: case T_CaseTestExpr:
coll = ((CaseTestExpr *) expr)->collation; coll = ((const CaseTestExpr *) expr)->collation;
break; break;
case T_ArrayExpr: case T_ArrayExpr:
coll = ((ArrayExpr *) expr)->array_collid; coll = ((const ArrayExpr *) expr)->array_collid;
break; break;
case T_RowExpr: case T_RowExpr:
coll = InvalidOid; /* result is always composite */ coll = InvalidOid; /* result is always composite */
@ -769,10 +769,10 @@ exprCollation(Node *expr)
coll = InvalidOid; /* result is always boolean */ coll = InvalidOid; /* result is always boolean */
break; break;
case T_CoalesceExpr: case T_CoalesceExpr:
coll = ((CoalesceExpr *) expr)->coalescecollid; coll = ((const CoalesceExpr *) expr)->coalescecollid;
break; break;
case T_MinMaxExpr: case T_MinMaxExpr:
coll = ((MinMaxExpr *) expr)->minmaxcollid; coll = ((const MinMaxExpr *) expr)->minmaxcollid;
break; break;
case T_XmlExpr: case T_XmlExpr:
@ -781,7 +781,7 @@ exprCollation(Node *expr)
* collation is always default. The other cases return boolean or * collation is always default. The other cases return boolean or
* XML, which are non-collatable. * XML, which are non-collatable.
*/ */
if (((XmlExpr *) expr)->op == IS_XMLSERIALIZE) if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
coll = DEFAULT_COLLATION_OID; coll = DEFAULT_COLLATION_OID;
else else
coll = InvalidOid; coll = InvalidOid;
@ -793,19 +793,19 @@ exprCollation(Node *expr)
coll = InvalidOid; /* result is always boolean */ coll = InvalidOid; /* result is always boolean */
break; break;
case T_CoerceToDomain: case T_CoerceToDomain:
coll = ((CoerceToDomain *) expr)->resultcollid; coll = ((const CoerceToDomain *) expr)->resultcollid;
break; break;
case T_CoerceToDomainValue: case T_CoerceToDomainValue:
coll = ((CoerceToDomainValue *) expr)->collation; coll = ((const CoerceToDomainValue *) expr)->collation;
break; break;
case T_SetToDefault: case T_SetToDefault:
coll = ((SetToDefault *) expr)->collation; coll = ((const SetToDefault *) expr)->collation;
break; break;
case T_CurrentOfExpr: case T_CurrentOfExpr:
coll = InvalidOid; /* result is always boolean */ coll = InvalidOid; /* result is always boolean */
break; break;
case T_PlaceHolderVar: case T_PlaceHolderVar:
coll = exprCollation((Node *) ((PlaceHolderVar *) expr)->phexpr); coll = exprCollation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
break; break;
default: default:
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr)); elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
@ -822,7 +822,7 @@ exprCollation(Node *expr)
* Result is InvalidOid if the node type doesn't store this information. * Result is InvalidOid if the node type doesn't store this information.
*/ */
Oid Oid
exprInputCollation(Node *expr) exprInputCollation(const Node *expr)
{ {
Oid coll; Oid coll;
@ -832,28 +832,28 @@ exprInputCollation(Node *expr)
switch (nodeTag(expr)) switch (nodeTag(expr))
{ {
case T_Aggref: case T_Aggref:
coll = ((Aggref *) expr)->inputcollid; coll = ((const Aggref *) expr)->inputcollid;
break; break;
case T_WindowFunc: case T_WindowFunc:
coll = ((WindowFunc *) expr)->inputcollid; coll = ((const WindowFunc *) expr)->inputcollid;
break; break;
case T_FuncExpr: case T_FuncExpr:
coll = ((FuncExpr *) expr)->inputcollid; coll = ((const FuncExpr *) expr)->inputcollid;
break; break;
case T_OpExpr: case T_OpExpr:
coll = ((OpExpr *) expr)->inputcollid; coll = ((const OpExpr *) expr)->inputcollid;
break; break;
case T_DistinctExpr: case T_DistinctExpr:
coll = ((DistinctExpr *) expr)->inputcollid; coll = ((const DistinctExpr *) expr)->inputcollid;
break; break;
case T_NullIfExpr: case T_NullIfExpr:
coll = ((NullIfExpr *) expr)->inputcollid; coll = ((const NullIfExpr *) expr)->inputcollid;
break; break;
case T_ScalarArrayOpExpr: case T_ScalarArrayOpExpr:
coll = ((ScalarArrayOpExpr *) expr)->inputcollid; coll = ((const ScalarArrayOpExpr *) expr)->inputcollid;
break; break;
case T_MinMaxExpr: case T_MinMaxExpr:
coll = ((MinMaxExpr *) expr)->inputcollid; coll = ((const MinMaxExpr *) expr)->inputcollid;
break; break;
default: default:
coll = InvalidOid; coll = InvalidOid;
@ -1078,7 +1078,7 @@ exprSetInputCollation(Node *expr, Oid inputcollation)
* known and unknown locations in a tree. * known and unknown locations in a tree.
*/ */
int int
exprLocation(Node *expr) exprLocation(const Node *expr)
{ {
int loc; int loc;
@ -1087,32 +1087,32 @@ exprLocation(Node *expr)
switch (nodeTag(expr)) switch (nodeTag(expr))
{ {
case T_RangeVar: case T_RangeVar:
loc = ((RangeVar *) expr)->location; loc = ((const RangeVar *) expr)->location;
break; break;
case T_Var: case T_Var:
loc = ((Var *) expr)->location; loc = ((const Var *) expr)->location;
break; break;
case T_Const: case T_Const:
loc = ((Const *) expr)->location; loc = ((const Const *) expr)->location;
break; break;
case T_Param: case T_Param:
loc = ((Param *) expr)->location; loc = ((const Param *) expr)->location;
break; break;
case T_Aggref: case T_Aggref:
/* function name should always be the first thing */ /* function name should always be the first thing */
loc = ((Aggref *) expr)->location; loc = ((const Aggref *) expr)->location;
break; break;
case T_WindowFunc: case T_WindowFunc:
/* function name should always be the first thing */ /* function name should always be the first thing */
loc = ((WindowFunc *) expr)->location; loc = ((const WindowFunc *) expr)->location;
break; break;
case T_ArrayRef: case T_ArrayRef:
/* just use array argument's location */ /* just use array argument's location */
loc = exprLocation((Node *) ((ArrayRef *) expr)->refexpr); loc = exprLocation((Node *) ((const ArrayRef *) expr)->refexpr);
break; break;
case T_FuncExpr: case T_FuncExpr:
{ {
FuncExpr *fexpr = (FuncExpr *) expr; const FuncExpr *fexpr = (const FuncExpr *) expr;
/* consider both function name and leftmost arg */ /* consider both function name and leftmost arg */
loc = leftmostLoc(fexpr->location, loc = leftmostLoc(fexpr->location,
@ -1121,7 +1121,7 @@ exprLocation(Node *expr)
break; break;
case T_NamedArgExpr: case T_NamedArgExpr:
{ {
NamedArgExpr *na = (NamedArgExpr *) expr; const NamedArgExpr *na = (const NamedArgExpr *) expr;
/* consider both argument name and value */ /* consider both argument name and value */
loc = leftmostLoc(na->location, loc = leftmostLoc(na->location,
@ -1132,7 +1132,7 @@ exprLocation(Node *expr)
case T_DistinctExpr: /* struct-equivalent to OpExpr */ case T_DistinctExpr: /* struct-equivalent to OpExpr */
case T_NullIfExpr: /* struct-equivalent to OpExpr */ case T_NullIfExpr: /* struct-equivalent to OpExpr */
{ {
OpExpr *opexpr = (OpExpr *) expr; const OpExpr *opexpr = (const OpExpr *) expr;
/* consider both operator name and leftmost arg */ /* consider both operator name and leftmost arg */
loc = leftmostLoc(opexpr->location, loc = leftmostLoc(opexpr->location,
@ -1141,7 +1141,7 @@ exprLocation(Node *expr)
break; break;
case T_ScalarArrayOpExpr: case T_ScalarArrayOpExpr:
{ {
ScalarArrayOpExpr *saopexpr = (ScalarArrayOpExpr *) expr; const ScalarArrayOpExpr *saopexpr = (const ScalarArrayOpExpr *) expr;
/* consider both operator name and leftmost arg */ /* consider both operator name and leftmost arg */
loc = leftmostLoc(saopexpr->location, loc = leftmostLoc(saopexpr->location,
@ -1150,7 +1150,7 @@ exprLocation(Node *expr)
break; break;
case T_BoolExpr: case T_BoolExpr:
{ {
BoolExpr *bexpr = (BoolExpr *) expr; const BoolExpr *bexpr = (const BoolExpr *) expr;
/* /*
* Same as above, to handle either NOT or AND/OR. We can't * Same as above, to handle either NOT or AND/OR. We can't
@ -1163,7 +1163,7 @@ exprLocation(Node *expr)
break; break;
case T_SubLink: case T_SubLink:
{ {
SubLink *sublink = (SubLink *) expr; const SubLink *sublink = (const SubLink *) expr;
/* check the testexpr, if any, and the operator/keyword */ /* check the testexpr, if any, and the operator/keyword */
loc = leftmostLoc(exprLocation(sublink->testexpr), loc = leftmostLoc(exprLocation(sublink->testexpr),
@ -1172,15 +1172,15 @@ exprLocation(Node *expr)
break; break;
case T_FieldSelect: case T_FieldSelect:
/* just use argument's location */ /* just use argument's location */
loc = exprLocation((Node *) ((FieldSelect *) expr)->arg); loc = exprLocation((Node *) ((const FieldSelect *) expr)->arg);
break; break;
case T_FieldStore: case T_FieldStore:
/* just use argument's location */ /* just use argument's location */
loc = exprLocation((Node *) ((FieldStore *) expr)->arg); loc = exprLocation((Node *) ((const FieldStore *) expr)->arg);
break; break;
case T_RelabelType: case T_RelabelType:
{ {
RelabelType *rexpr = (RelabelType *) expr; const RelabelType *rexpr = (const RelabelType *) expr;
/* Much as above */ /* Much as above */
loc = leftmostLoc(rexpr->location, loc = leftmostLoc(rexpr->location,
@ -1189,7 +1189,7 @@ exprLocation(Node *expr)
break; break;
case T_CoerceViaIO: case T_CoerceViaIO:
{ {
CoerceViaIO *cexpr = (CoerceViaIO *) expr; const CoerceViaIO *cexpr = (const CoerceViaIO *) expr;
/* Much as above */ /* Much as above */
loc = leftmostLoc(cexpr->location, loc = leftmostLoc(cexpr->location,
@ -1198,7 +1198,7 @@ exprLocation(Node *expr)
break; break;
case T_ArrayCoerceExpr: case T_ArrayCoerceExpr:
{ {
ArrayCoerceExpr *cexpr = (ArrayCoerceExpr *) expr; const ArrayCoerceExpr *cexpr = (const ArrayCoerceExpr *) expr;
/* Much as above */ /* Much as above */
loc = leftmostLoc(cexpr->location, loc = leftmostLoc(cexpr->location,
@ -1207,7 +1207,7 @@ exprLocation(Node *expr)
break; break;
case T_ConvertRowtypeExpr: case T_ConvertRowtypeExpr:
{ {
ConvertRowtypeExpr *cexpr = (ConvertRowtypeExpr *) expr; const ConvertRowtypeExpr *cexpr = (const ConvertRowtypeExpr *) expr;
/* Much as above */ /* Much as above */
loc = leftmostLoc(cexpr->location, loc = leftmostLoc(cexpr->location,
@ -1216,39 +1216,39 @@ exprLocation(Node *expr)
break; break;
case T_CollateExpr: case T_CollateExpr:
/* just use argument's location */ /* just use argument's location */
loc = exprLocation((Node *) ((CollateExpr *) expr)->arg); loc = exprLocation((Node *) ((const CollateExpr *) expr)->arg);
break; break;
case T_CaseExpr: case T_CaseExpr:
/* CASE keyword should always be the first thing */ /* CASE keyword should always be the first thing */
loc = ((CaseExpr *) expr)->location; loc = ((const CaseExpr *) expr)->location;
break; break;
case T_CaseWhen: case T_CaseWhen:
/* WHEN keyword should always be the first thing */ /* WHEN keyword should always be the first thing */
loc = ((CaseWhen *) expr)->location; loc = ((const CaseWhen *) expr)->location;
break; break;
case T_ArrayExpr: case T_ArrayExpr:
/* the location points at ARRAY or [, which must be leftmost */ /* the location points at ARRAY or [, which must be leftmost */
loc = ((ArrayExpr *) expr)->location; loc = ((const ArrayExpr *) expr)->location;
break; break;
case T_RowExpr: case T_RowExpr:
/* the location points at ROW or (, which must be leftmost */ /* the location points at ROW or (, which must be leftmost */
loc = ((RowExpr *) expr)->location; loc = ((const RowExpr *) expr)->location;
break; break;
case T_RowCompareExpr: case T_RowCompareExpr:
/* just use leftmost argument's location */ /* just use leftmost argument's location */
loc = exprLocation((Node *) ((RowCompareExpr *) expr)->largs); loc = exprLocation((Node *) ((const RowCompareExpr *) expr)->largs);
break; break;
case T_CoalesceExpr: case T_CoalesceExpr:
/* COALESCE keyword should always be the first thing */ /* COALESCE keyword should always be the first thing */
loc = ((CoalesceExpr *) expr)->location; loc = ((const CoalesceExpr *) expr)->location;
break; break;
case T_MinMaxExpr: case T_MinMaxExpr:
/* GREATEST/LEAST keyword should always be the first thing */ /* GREATEST/LEAST keyword should always be the first thing */
loc = ((MinMaxExpr *) expr)->location; loc = ((const MinMaxExpr *) expr)->location;
break; break;
case T_XmlExpr: case T_XmlExpr:
{ {
XmlExpr *xexpr = (XmlExpr *) expr; const XmlExpr *xexpr = (const XmlExpr *) expr;
/* consider both function name and leftmost arg */ /* consider both function name and leftmost arg */
loc = leftmostLoc(xexpr->location, loc = leftmostLoc(xexpr->location,
@ -1257,15 +1257,15 @@ exprLocation(Node *expr)
break; break;
case T_NullTest: case T_NullTest:
/* just use argument's location */ /* just use argument's location */
loc = exprLocation((Node *) ((NullTest *) expr)->arg); loc = exprLocation((Node *) ((const NullTest *) expr)->arg);
break; break;
case T_BooleanTest: case T_BooleanTest:
/* just use argument's location */ /* just use argument's location */
loc = exprLocation((Node *) ((BooleanTest *) expr)->arg); loc = exprLocation((Node *) ((const BooleanTest *) expr)->arg);
break; break;
case T_CoerceToDomain: case T_CoerceToDomain:
{ {
CoerceToDomain *cexpr = (CoerceToDomain *) expr; const CoerceToDomain *cexpr = (const CoerceToDomain *) expr;
/* Much as above */ /* Much as above */
loc = leftmostLoc(cexpr->location, loc = leftmostLoc(cexpr->location,
@ -1273,18 +1273,18 @@ exprLocation(Node *expr)
} }
break; break;
case T_CoerceToDomainValue: case T_CoerceToDomainValue:
loc = ((CoerceToDomainValue *) expr)->location; loc = ((const CoerceToDomainValue *) expr)->location;
break; break;
case T_SetToDefault: case T_SetToDefault:
loc = ((SetToDefault *) expr)->location; loc = ((const SetToDefault *) expr)->location;
break; break;
case T_TargetEntry: case T_TargetEntry:
/* just use argument's location */ /* just use argument's location */
loc = exprLocation((Node *) ((TargetEntry *) expr)->expr); loc = exprLocation((Node *) ((const TargetEntry *) expr)->expr);
break; break;
case T_IntoClause: case T_IntoClause:
/* use the contained RangeVar's location --- close enough */ /* use the contained RangeVar's location --- close enough */
loc = exprLocation((Node *) ((IntoClause *) expr)->rel); loc = exprLocation((Node *) ((const IntoClause *) expr)->rel);
break; break;
case T_List: case T_List:
{ {
@ -1292,7 +1292,7 @@ exprLocation(Node *expr)
ListCell *lc; ListCell *lc;
loc = -1; /* just to suppress compiler warning */ loc = -1; /* just to suppress compiler warning */
foreach(lc, (List *) expr) foreach(lc, (const List *) expr)
{ {
loc = exprLocation((Node *) lfirst(lc)); loc = exprLocation((Node *) lfirst(lc));
if (loc >= 0) if (loc >= 0)
@ -1302,7 +1302,7 @@ exprLocation(Node *expr)
break; break;
case T_A_Expr: case T_A_Expr:
{ {
A_Expr *aexpr = (A_Expr *) expr; const A_Expr *aexpr = (const A_Expr *) expr;
/* use leftmost of operator or left operand (if any) */ /* use leftmost of operator or left operand (if any) */
/* we assume right operand can't be to left of operator */ /* we assume right operand can't be to left of operator */
@ -1311,17 +1311,17 @@ exprLocation(Node *expr)
} }
break; break;
case T_ColumnRef: case T_ColumnRef:
loc = ((ColumnRef *) expr)->location; loc = ((const ColumnRef *) expr)->location;
break; break;
case T_ParamRef: case T_ParamRef:
loc = ((ParamRef *) expr)->location; loc = ((const ParamRef *) expr)->location;
break; break;
case T_A_Const: case T_A_Const:
loc = ((A_Const *) expr)->location; loc = ((const A_Const *) expr)->location;
break; break;
case T_FuncCall: case T_FuncCall:
{ {
FuncCall *fc = (FuncCall *) expr; const FuncCall *fc = (const FuncCall *) expr;
/* consider both function name and leftmost arg */ /* consider both function name and leftmost arg */
/* (we assume any ORDER BY nodes must be to right of name) */ /* (we assume any ORDER BY nodes must be to right of name) */
@ -1331,15 +1331,15 @@ exprLocation(Node *expr)
break; break;
case T_A_ArrayExpr: case T_A_ArrayExpr:
/* the location points at ARRAY or [, which must be leftmost */ /* the location points at ARRAY or [, which must be leftmost */
loc = ((A_ArrayExpr *) expr)->location; loc = ((const A_ArrayExpr *) expr)->location;
break; break;
case T_ResTarget: case T_ResTarget:
/* we need not examine the contained expression (if any) */ /* we need not examine the contained expression (if any) */
loc = ((ResTarget *) expr)->location; loc = ((const ResTarget *) expr)->location;
break; break;
case T_TypeCast: case T_TypeCast:
{ {
TypeCast *tc = (TypeCast *) expr; const TypeCast *tc = (const TypeCast *) expr;
/* /*
* This could represent CAST(), ::, or TypeName 'literal', so * This could represent CAST(), ::, or TypeName 'literal', so
@ -1352,34 +1352,34 @@ exprLocation(Node *expr)
break; break;
case T_CollateClause: case T_CollateClause:
/* just use argument's location */ /* just use argument's location */
loc = exprLocation(((CollateClause *) expr)->arg); loc = exprLocation(((const CollateClause *) expr)->arg);
break; break;
case T_SortBy: case T_SortBy:
/* just use argument's location (ignore operator, if any) */ /* just use argument's location (ignore operator, if any) */
loc = exprLocation(((SortBy *) expr)->node); loc = exprLocation(((const SortBy *) expr)->node);
break; break;
case T_WindowDef: case T_WindowDef:
loc = ((WindowDef *) expr)->location; loc = ((const WindowDef *) expr)->location;
break; break;
case T_TypeName: case T_TypeName:
loc = ((TypeName *) expr)->location; loc = ((const TypeName *) expr)->location;
break; break;
case T_Constraint: case T_Constraint:
loc = ((Constraint *) expr)->location; loc = ((const Constraint *) expr)->location;
break; break;
case T_XmlSerialize: case T_XmlSerialize:
/* XMLSERIALIZE keyword should always be the first thing */ /* XMLSERIALIZE keyword should always be the first thing */
loc = ((XmlSerialize *) expr)->location; loc = ((const XmlSerialize *) expr)->location;
break; break;
case T_WithClause: case T_WithClause:
loc = ((WithClause *) expr)->location; loc = ((const WithClause *) expr)->location;
break; break;
case T_CommonTableExpr: case T_CommonTableExpr:
loc = ((CommonTableExpr *) expr)->location; loc = ((const CommonTableExpr *) expr)->location;
break; break;
case T_PlaceHolderVar: case T_PlaceHolderVar:
/* just use argument's location */ /* just use argument's location */
loc = exprLocation((Node *) ((PlaceHolderVar *) expr)->phexpr); loc = exprLocation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
break; break;
default: default:
/* for any other node type it's just unknown... */ /* for any other node type it's just unknown... */

File diff suppressed because it is too large Load Diff

@ -31,7 +31,7 @@
* print contents of Node to stdout * print contents of Node to stdout
*/ */
void void
print(void *obj) print(const void *obj)
{ {
char *s; char *s;
char *f; char *f;
@ -49,7 +49,7 @@ print(void *obj)
* pretty-print contents of Node to stdout * pretty-print contents of Node to stdout
*/ */
void void
pprint(void *obj) pprint(const void *obj)
{ {
char *s; char *s;
char *f; char *f;
@ -67,7 +67,7 @@ pprint(void *obj)
* send pretty-printed contents of Node to postmaster log * send pretty-printed contents of Node to postmaster log
*/ */
void void
elog_node_display(int lev, const char *title, void *obj, bool pretty) elog_node_display(int lev, const char *title, const void *obj, bool pretty)
{ {
char *s; char *s;
char *f; char *f;
@ -249,9 +249,9 @@ pretty_format_node_dump(const char *dump)
* print contents of range table * print contents of range table
*/ */
void void
print_rt(List *rtable) print_rt(const List *rtable)
{ {
ListCell *l; const ListCell *l;
int i = 1; int i = 1;
printf("resno\trefname \trelid\tinFromCl\n"); printf("resno\trefname \trelid\tinFromCl\n");
@ -304,7 +304,7 @@ print_rt(List *rtable)
* print an expression * print an expression
*/ */
void void
print_expr(Node *expr, List *rtable) print_expr(const Node *expr, const List *rtable)
{ {
if (expr == NULL) if (expr == NULL)
{ {
@ -314,7 +314,7 @@ print_expr(Node *expr, List *rtable)
if (IsA(expr, Var)) if (IsA(expr, Var))
{ {
Var *var = (Var *) expr; const Var *var = (const Var *) expr;
char *relname, char *relname,
*attname; *attname;
@ -348,7 +348,7 @@ print_expr(Node *expr, List *rtable)
} }
else if (IsA(expr, Const)) else if (IsA(expr, Const))
{ {
Const *c = (Const *) expr; const Const *c = (const Const *) expr;
Oid typoutput; Oid typoutput;
bool typIsVarlena; bool typIsVarlena;
char *outputstr; char *outputstr;
@ -368,26 +368,26 @@ print_expr(Node *expr, List *rtable)
} }
else if (IsA(expr, OpExpr)) else if (IsA(expr, OpExpr))
{ {
OpExpr *e = (OpExpr *) expr; const OpExpr *e = (const OpExpr *) expr;
char *opname; char *opname;
opname = get_opname(e->opno); opname = get_opname(e->opno);
if (list_length(e->args) > 1) if (list_length(e->args) > 1)
{ {
print_expr(get_leftop((Expr *) e), rtable); print_expr(get_leftop((const Expr *) e), rtable);
printf(" %s ", ((opname != NULL) ? opname : "(invalid operator)")); printf(" %s ", ((opname != NULL) ? opname : "(invalid operator)"));
print_expr(get_rightop((Expr *) e), rtable); print_expr(get_rightop((const Expr *) e), rtable);
} }
else else
{ {
/* we print prefix and postfix ops the same... */ /* we print prefix and postfix ops the same... */
printf("%s ", ((opname != NULL) ? opname : "(invalid operator)")); printf("%s ", ((opname != NULL) ? opname : "(invalid operator)"));
print_expr(get_leftop((Expr *) e), rtable); print_expr(get_leftop((const Expr *) e), rtable);
} }
} }
else if (IsA(expr, FuncExpr)) else if (IsA(expr, FuncExpr))
{ {
FuncExpr *e = (FuncExpr *) expr; const FuncExpr *e = (const FuncExpr *) expr;
char *funcname; char *funcname;
ListCell *l; ListCell *l;
@ -410,9 +410,9 @@ print_expr(Node *expr, List *rtable)
* pathkeys list of PathKeys * pathkeys list of PathKeys
*/ */
void void
print_pathkeys(List *pathkeys, List *rtable) print_pathkeys(const List *pathkeys, const List *rtable)
{ {
ListCell *i; const ListCell *i;
printf("("); printf("(");
foreach(i, pathkeys) foreach(i, pathkeys)
@ -450,9 +450,9 @@ print_pathkeys(List *pathkeys, List *rtable)
* print targetlist in a more legible way. * print targetlist in a more legible way.
*/ */
void void
print_tl(List *tlist, List *rtable) print_tl(const List *tlist, const List *rtable)
{ {
ListCell *tl; const ListCell *tl;
printf("(\n"); printf("(\n");
foreach(tl, tlist) foreach(tl, tlist)

@ -181,9 +181,9 @@ make_opclause(Oid opno, Oid opresulttype, bool opretset,
* or (op expr) * or (op expr)
*/ */
Node * Node *
get_leftop(Expr *clause) get_leftop(const Expr *clause)
{ {
OpExpr *expr = (OpExpr *) clause; const OpExpr *expr = (const OpExpr *) clause;
if (expr->args != NIL) if (expr->args != NIL)
return linitial(expr->args); return linitial(expr->args);
@ -198,9 +198,9 @@ get_leftop(Expr *clause)
* NB: result will be NULL if applied to a unary op clause. * NB: result will be NULL if applied to a unary op clause.
*/ */
Node * Node *
get_rightop(Expr *clause) get_rightop(const Expr *clause)
{ {
OpExpr *expr = (OpExpr *) clause; const OpExpr *expr = (const OpExpr *) clause;
if (list_length(expr->args) >= 2) if (list_length(expr->args) >= 2)
return lsecond(expr->args); return lsecond(expr->args);

@ -26,17 +26,17 @@
#define QTW_DONT_COPY_QUERY 0x20 /* do not copy top Query */ #define QTW_DONT_COPY_QUERY 0x20 /* do not copy top Query */
extern Oid exprType(Node *expr); extern Oid exprType(const Node *expr);
extern int32 exprTypmod(Node *expr); extern int32 exprTypmod(const Node *expr);
extern bool exprIsLengthCoercion(Node *expr, int32 *coercedTypmod); extern bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod);
extern bool expression_returns_set(Node *clause); extern bool expression_returns_set(Node *clause);
extern Oid exprCollation(Node *expr); extern Oid exprCollation(const Node *expr);
extern Oid exprInputCollation(Node *expr); extern Oid exprInputCollation(const Node *expr);
extern void exprSetCollation(Node *expr, Oid collation); extern void exprSetCollation(Node *expr, Oid collation);
extern void exprSetInputCollation(Node *expr, Oid inputcollation); extern void exprSetInputCollation(Node *expr, Oid inputcollation);
extern int exprLocation(Node *expr); extern int exprLocation(const Node *expr);
extern bool expression_tree_walker(Node *node, bool (*walker) (), extern bool expression_tree_walker(Node *node, bool (*walker) (),
void *context); void *context);

@ -431,7 +431,7 @@ typedef struct Node
NodeTag type; NodeTag type;
} Node; } Node;
#define nodeTag(nodeptr) (((Node*)(nodeptr))->type) #define nodeTag(nodeptr) (((const Node*)(nodeptr))->type)
/* /*
* newNode - * newNode -
@ -487,7 +487,7 @@ extern PGDLLIMPORT Node *newNodeMacroHolder;
/* /*
* nodes/{outfuncs.c,print.c} * nodes/{outfuncs.c,print.c}
*/ */
extern char *nodeToString(void *obj); extern char *nodeToString(const void *obj);
/* /*
* nodes/{readfuncs.c,read.c} * nodes/{readfuncs.c,read.c}
@ -497,12 +497,12 @@ extern void *stringToNode(char *str);
/* /*
* nodes/copyfuncs.c * nodes/copyfuncs.c
*/ */
extern void *copyObject(void *obj); extern void *copyObject(const void *obj);
/* /*
* nodes/equalfuncs.c * nodes/equalfuncs.c
*/ */
extern bool equal(void *a, void *b); extern bool equal(const void *a, const void *b);
/* /*

@ -77,7 +77,7 @@ struct ListCell
#ifdef USE_INLINE #ifdef USE_INLINE
static inline ListCell * static inline ListCell *
list_head(List *l) list_head(const List *l)
{ {
return l ? l->head : NULL; return l ? l->head : NULL;
} }
@ -89,15 +89,15 @@ list_tail(List *l)
} }
static inline int static inline int
list_length(List *l) list_length(const List *l)
{ {
return l ? l->length : 0; return l ? l->length : 0;
} }
#else #else
extern ListCell *list_head(List *l); extern ListCell *list_head(const List *l);
extern ListCell *list_tail(List *l); extern ListCell *list_tail(List *l);
extern int list_length(List *l); extern int list_length(const List *l);
#endif /* USE_INLINE */ #endif /* USE_INLINE */
/* /*
@ -206,14 +206,14 @@ extern List *lcons_oid(Oid datum, List *list);
extern List *list_concat(List *list1, List *list2); extern List *list_concat(List *list1, List *list2);
extern List *list_truncate(List *list, int new_size); extern List *list_truncate(List *list, int new_size);
extern void *list_nth(List *list, int n); extern void *list_nth(const List *list, int n);
extern int list_nth_int(List *list, int n); extern int list_nth_int(const List *list, int n);
extern Oid list_nth_oid(List *list, int n); extern Oid list_nth_oid(const List *list, int n);
extern bool list_member(List *list, void *datum); extern bool list_member(const List *list, const void *datum);
extern bool list_member_ptr(List *list, void *datum); extern bool list_member_ptr(const List *list, const void *datum);
extern bool list_member_int(List *list, int datum); extern bool list_member_int(const List *list, int datum);
extern bool list_member_oid(List *list, Oid datum); extern bool list_member_oid(const List *list, Oid datum);
extern List *list_delete(List *list, void *datum); extern List *list_delete(List *list, void *datum);
extern List *list_delete_ptr(List *list, void *datum); extern List *list_delete_ptr(List *list, void *datum);
@ -222,19 +222,19 @@ extern List *list_delete_oid(List *list, Oid datum);
extern List *list_delete_first(List *list); extern List *list_delete_first(List *list);
extern List *list_delete_cell(List *list, ListCell *cell, ListCell *prev); extern List *list_delete_cell(List *list, ListCell *cell, ListCell *prev);
extern List *list_union(List *list1, List *list2); extern List *list_union(const List *list1, const List *list2);
extern List *list_union_ptr(List *list1, List *list2); extern List *list_union_ptr(const List *list1, const List *list2);
extern List *list_union_int(List *list1, List *list2); extern List *list_union_int(const List *list1, const List *list2);
extern List *list_union_oid(List *list1, List *list2); extern List *list_union_oid(const List *list1, const List *list2);
extern List *list_intersection(List *list1, List *list2); extern List *list_intersection(const List *list1, const List *list2);
/* currently, there's no need for list_intersection_int etc */ /* currently, there's no need for list_intersection_int etc */
extern List *list_difference(List *list1, List *list2); extern List *list_difference(const List *list1, const List *list2);
extern List *list_difference_ptr(List *list1, List *list2); extern List *list_difference_ptr(const List *list1, const List *list2);
extern List *list_difference_int(List *list1, List *list2); extern List *list_difference_int(const List *list1, const List *list2);
extern List *list_difference_oid(List *list1, List *list2); extern List *list_difference_oid(const List *list1, const List *list2);
extern List *list_append_unique(List *list, void *datum); extern List *list_append_unique(List *list, void *datum);
extern List *list_append_unique_ptr(List *list, void *datum); extern List *list_append_unique_ptr(List *list, void *datum);
@ -249,8 +249,8 @@ extern List *list_concat_unique_oid(List *list1, List *list2);
extern void list_free(List *list); extern void list_free(List *list);
extern void list_free_deep(List *list); extern void list_free_deep(List *list);
extern List *list_copy(List *list); extern List *list_copy(const List *list);
extern List *list_copy_tail(List *list, int nskip); extern List *list_copy_tail(const List *list, int nskip);
/* /*
* To ease migration to the new list API, a set of compatibility * To ease migration to the new list API, a set of compatibility

@ -19,16 +19,16 @@
#define nodeDisplay(x) pprint(x) #define nodeDisplay(x) pprint(x)
extern void print(void *obj); extern void print(const void *obj);
extern void pprint(void *obj); extern void pprint(const void *obj);
extern void elog_node_display(int lev, const char *title, extern void elog_node_display(int lev, const char *title,
void *obj, bool pretty); const void *obj, bool pretty);
extern char *format_node_dump(const char *dump); extern char *format_node_dump(const char *dump);
extern char *pretty_format_node_dump(const char *dump); extern char *pretty_format_node_dump(const char *dump);
extern void print_rt(List *rtable); extern void print_rt(const List *rtable);
extern void print_expr(Node *expr, List *rtable); extern void print_expr(const Node *expr, const List *rtable);
extern void print_pathkeys(List *pathkeys, List *rtable); extern void print_pathkeys(const List *pathkeys, const List *rtable);
extern void print_tl(List *tlist, List *rtable); extern void print_tl(const List *tlist, const List *rtable);
extern void print_slot(TupleTableSlot *slot); extern void print_slot(TupleTableSlot *slot);
#endif /* PRINT_H */ #endif /* PRINT_H */

@ -31,8 +31,8 @@ typedef struct
extern Expr *make_opclause(Oid opno, Oid opresulttype, bool opretset, extern Expr *make_opclause(Oid opno, Oid opresulttype, bool opretset,
Expr *leftop, Expr *rightop, Expr *leftop, Expr *rightop,
Oid opcollid, Oid inputcollid); Oid opcollid, Oid inputcollid);
extern Node *get_leftop(Expr *clause); extern Node *get_leftop(const Expr *clause);
extern Node *get_rightop(Expr *clause); extern Node *get_rightop(const Expr *clause);
extern bool not_clause(Node *clause); extern bool not_clause(Node *clause);
extern Expr *make_notclause(Expr *notclause); extern Expr *make_notclause(Expr *notclause);

Loading…
Cancel
Save