postgresql/src/include/nodes/nodeFuncs.h

160 lines
4.8 KiB
C
Raw Normal View History

/*-------------------------------------------------------------------------
*
* nodeFuncs.h
* Various general-purpose manipulations of Node trees
*
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
2010-09-20 22:08:53 +02:00
* src/include/nodes/nodeFuncs.h
*
*-------------------------------------------------------------------------
*/
#ifndef NODEFUNCS_H
#define NODEFUNCS_H
#include "nodes/parsenodes.h"
/* flags bits for query_tree_walker and query_tree_mutator */
Phase 2 of pgindent updates. Change pg_bsd_indent to follow upstream rules for placement of comments to the right of code, and remove pgindent hack that caused comments following #endif to not obey the general rule. Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using the published version of pg_bsd_indent, but a hacked-up version that tried to minimize the amount of movement of comments to the right of code. The situation of interest is where such a comment has to be moved to the right of its default placement at column 33 because there's code there. BSD indent has always moved right in units of tab stops in such cases --- but in the previous incarnation, indent was working in 8-space tab stops, while now it knows we use 4-space tabs. So the net result is that in about half the cases, such comments are placed one tab stop left of before. This is better all around: it leaves more room on the line for comment text, and it means that in such cases the comment uniformly starts at the next 4-space tab stop after the code, rather than sometimes one and sometimes two tabs after. Also, ensure that comments following #endif are indented the same as comments following other preprocessor commands such as #else. That inconsistency turns out to have been self-inflicted damage from a poorly-thought-through post-indent "fixup" in pgindent. This patch is much less interesting than the first round of indent changes, but also bulkier, so I thought it best to separate the effects. Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
#define QTW_IGNORE_RT_SUBQUERIES 0x01 /* subqueries in rtable */
#define QTW_IGNORE_CTE_SUBQUERIES 0x02 /* subqueries in cteList */
#define QTW_IGNORE_RC_SUBQUERIES 0x03 /* both of above */
#define QTW_IGNORE_JOINALIASES 0x04 /* JOIN alias var lists */
#define QTW_IGNORE_RANGE_TABLE 0x08 /* skip rangetable entirely */
#define QTW_EXAMINE_RTES_BEFORE 0x10 /* examine RTE nodes before their
* contents */
#define QTW_EXAMINE_RTES_AFTER 0x20 /* examine RTE nodes after their
* contents */
#define QTW_DONT_COPY_QUERY 0x40 /* do not copy top Query */
#define QTW_EXAMINE_SORTGROUP 0x80 /* include SortGroupNode lists */
/* callback function for check_functions_in_node */
typedef bool (*check_function_callback) (Oid func_id, void *context);
extern Oid exprType(const Node *expr);
extern int32 exprTypmod(const Node *expr);
extern bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod);
extern Node *relabel_to_typmod(Node *expr, int32 typmod);
extern Node *strip_implicit_coercions(Node *node);
extern bool expression_returns_set(Node *clause);
extern Oid exprCollation(const Node *expr);
extern Oid exprInputCollation(const Node *expr);
extern void exprSetCollation(Node *expr, Oid collation);
extern void exprSetInputCollation(Node *expr, Oid inputcollation);
extern int exprLocation(const Node *expr);
extern void fix_opfuncids(Node *node);
extern void set_opfuncid(OpExpr *opexpr);
extern void set_sa_opfuncid(ScalarArrayOpExpr *opexpr);
/* Is clause a FuncExpr clause? */
static inline bool
is_funcclause(const void *clause)
{
return clause != NULL && IsA(clause, FuncExpr);
}
/* Is clause an OpExpr clause? */
static inline bool
is_opclause(const void *clause)
{
return clause != NULL && IsA(clause, OpExpr);
}
/* Extract left arg of a binary opclause, or only arg of a unary opclause */
static inline Node *
get_leftop(const void *clause)
{
const OpExpr *expr = (const OpExpr *) clause;
if (expr->args != NIL)
return (Node *) linitial(expr->args);
else
return NULL;
}
/* Extract right arg of a binary opclause (NULL if it's a unary opclause) */
static inline Node *
get_rightop(const void *clause)
{
const OpExpr *expr = (const OpExpr *) clause;
if (list_length(expr->args) >= 2)
return (Node *) lsecond(expr->args);
else
return NULL;
}
/* Is clause an AND clause? */
static inline bool
is_andclause(const void *clause)
{
return (clause != NULL &&
IsA(clause, BoolExpr) &&
((const BoolExpr *) clause)->boolop == AND_EXPR);
}
/* Is clause an OR clause? */
static inline bool
is_orclause(const void *clause)
{
return (clause != NULL &&
IsA(clause, BoolExpr) &&
((const BoolExpr *) clause)->boolop == OR_EXPR);
}
/* Is clause a NOT clause? */
static inline bool
is_notclause(const void *clause)
{
return (clause != NULL &&
IsA(clause, BoolExpr) &&
((const BoolExpr *) clause)->boolop == NOT_EXPR);
}
/* Extract argument from a clause known to be a NOT clause */
static inline Expr *
get_notclausearg(const void *notclause)
{
return (Expr *) linitial(((const BoolExpr *) notclause)->args);
}
extern bool check_functions_in_node(Node *node, check_function_callback checker,
void *context);
extern bool expression_tree_walker(Node *node, bool (*walker) (),
2017-06-21 20:39:04 +02:00
void *context);
extern Node *expression_tree_mutator(Node *node, Node *(*mutator) (),
2017-06-21 20:39:04 +02:00
void *context);
extern bool query_tree_walker(Query *query, bool (*walker) (),
2017-06-21 20:39:04 +02:00
void *context, int flags);
extern Query *query_tree_mutator(Query *query, Node *(*mutator) (),
2017-06-21 20:39:04 +02:00
void *context, int flags);
extern bool range_table_walker(List *rtable, bool (*walker) (),
2017-06-21 20:39:04 +02:00
void *context, int flags);
extern List *range_table_mutator(List *rtable, Node *(*mutator) (),
2017-06-21 20:39:04 +02:00
void *context, int flags);
extern bool range_table_entry_walker(RangeTblEntry *rte, bool (*walker) (),
void *context, int flags);
extern bool query_or_expression_tree_walker(Node *node, bool (*walker) (),
2017-06-21 20:39:04 +02:00
void *context, int flags);
extern Node *query_or_expression_tree_mutator(Node *node, Node *(*mutator) (),
2017-06-21 20:39:04 +02:00
void *context, int flags);
extern bool raw_expression_tree_walker(Node *node, bool (*walker) (),
2017-06-21 20:39:04 +02:00
void *context);
struct PlanState;
extern bool planstate_tree_walker(struct PlanState *planstate, bool (*walker) (),
2017-06-21 20:39:04 +02:00
void *context);
Phase 2 of pgindent updates. Change pg_bsd_indent to follow upstream rules for placement of comments to the right of code, and remove pgindent hack that caused comments following #endif to not obey the general rule. Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using the published version of pg_bsd_indent, but a hacked-up version that tried to minimize the amount of movement of comments to the right of code. The situation of interest is where such a comment has to be moved to the right of its default placement at column 33 because there's code there. BSD indent has always moved right in units of tab stops in such cases --- but in the previous incarnation, indent was working in 8-space tab stops, while now it knows we use 4-space tabs. So the net result is that in about half the cases, such comments are placed one tab stop left of before. This is better all around: it leaves more room on the line for comment text, and it means that in such cases the comment uniformly starts at the next 4-space tab stop after the code, rather than sometimes one and sometimes two tabs after. Also, ensure that comments following #endif are indented the same as comments following other preprocessor commands such as #else. That inconsistency turns out to have been self-inflicted damage from a poorly-thought-through post-indent "fixup" in pgindent. This patch is much less interesting than the first round of indent changes, but also bulkier, so I thought it best to separate the effects. Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
#endif /* NODEFUNCS_H */