1/*-------------------------------------------------------------------------
2 *
3 * nodeFuncs.h
4 * Various general-purpose manipulations of PGNode trees
5 *
6 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development PGGroup
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * src/include/nodes/nodeFuncs.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#pragma once
14
15#include "nodes/parsenodes.hpp"
16
17namespace duckdb_libpgquery {
18
19/* flags bits for query_tree_walker and query_tree_mutator */
20#define QTW_IGNORE_RT_SUBQUERIES 0x01 /* subqueries in rtable */
21#define QTW_IGNORE_CTE_SUBQUERIES 0x02 /* subqueries in cteList */
22#define QTW_IGNORE_RC_SUBQUERIES 0x03 /* both of above */
23#define QTW_IGNORE_JOINALIASES 0x04 /* JOIN alias var lists */
24#define QTW_IGNORE_RANGE_TABLE 0x08 /* skip rangetable entirely */
25#define QTW_EXAMINE_RTES 0x10 /* examine RTEs */
26#define QTW_DONT_COPY_QUERY 0x20 /* do not copy top PGQuery */
27
28/* callback function for check_functions_in_node */
29typedef bool (*check_function_callback)(PGOid func_id, void *context);
30
31PGOid exprType(const PGNode *expr);
32int32_t exprTypmod(const PGNode *expr);
33bool exprIsLengthCoercion(const PGNode *expr, int32_t *coercedTypmod);
34PGNode *relabel_to_typmod(PGNode *expr, int32_t typmod);
35PGNode *strip_implicit_coercions(PGNode *node);
36bool expression_returns_set(PGNode *clause);
37
38PGOid exprCollation(const PGNode *expr);
39PGOid exprInputCollation(const PGNode *expr);
40void exprSetCollation(PGNode *expr, PGOid collation);
41void exprSetInputCollation(PGNode *expr, PGOid inputcollation);
42
43int exprLocation(const PGNode *expr);
44
45void fix_opfuncids(PGNode *node);
46void set_opfuncid(PGOpExpr *opexpr);
47void set_sa_opfuncid(PGScalarArrayOpExpr *opexpr);
48
49bool check_functions_in_node(PGNode *node, check_function_callback checker, void *context);
50
51bool expression_tree_walker(PGNode *node, bool (*walker)(), void *context);
52PGNode *expression_tree_mutator(PGNode *node, PGNode *(*mutator)(), void *context);
53
54bool query_tree_walker(PGQuery *query, bool (*walker)(), void *context, int flags);
55PGQuery *query_tree_mutator(PGQuery *query, PGNode *(*mutator)(), void *context, int flags);
56
57bool range_table_walker(PGList *rtable, bool (*walker)(), void *context, int flags);
58PGList *range_table_mutator(PGList *rtable, PGNode *(*mutator)(), void *context, int flags);
59
60bool query_or_expression_tree_walker(PGNode *node, bool (*walker)(), void *context, int flags);
61PGNode *query_or_expression_tree_mutator(PGNode *node, PGNode *(*mutator)(), void *context, int flags);
62
63bool raw_expression_tree_walker(PGNode *node, bool (*walker)(), void *context);
64
65struct PlanState;
66bool planstate_tree_walker(struct PlanState *planstate, bool (*walker)(), void *context);
67
68}
69