MCPcopy Create free account
hub / github.com/apache/cloudberry / expression_tree_mutator

Function expression_tree_mutator

src/backend/nodes/nodeFuncs.c:2764–3570  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2762 */
2763
2764Node *
2765expression_tree_mutator(Node *node,
2766 Node *(*mutator) (),
2767 void *context)
2768{
2769 /*
2770 * The mutator has already decided not to modify the current node, but we
2771 * must call the mutator for any sub-nodes.
2772 */
2773
2774#define FLATCOPY(newnode, node, nodetype) \
2775 ( (newnode) = (nodetype *) palloc(sizeof(nodetype)), \
2776 memcpy((newnode), (node), sizeof(nodetype)) )
2777
2778#define CHECKFLATCOPY(newnode, node, nodetype) \
2779 ( AssertMacro(IsA((node), nodetype)), \
2780 (newnode) = (nodetype *) palloc(sizeof(nodetype)), \
2781 memcpy((newnode), (node), sizeof(nodetype)) )
2782
2783#define MUTATE(newfield, oldfield, fieldtype) \
2784 ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )
2785
2786 if (node == NULL)
2787 return NULL;
2788
2789 /* Guard against stack overflow due to overly complex expressions */
2790 check_stack_depth();
2791
2792 switch (nodeTag(node))
2793 {
2794 /*
2795 * Primitive node types with no expression subnodes. Var and
2796 * Const are frequent enough to deserve special cases, the others
2797 * we just use copyObject for.
2798 */
2799 case T_Var:
2800 {
2801 Var *var = (Var *) node;
2802 Var *newnode;
2803
2804 FLATCOPY(newnode, var, Var);
2805 return (Node *) newnode;
2806 }
2807 break;
2808 case T_Const:
2809 {
2810 Const *oldnode = (Const *) node;
2811 Const *newnode;
2812
2813 FLATCOPY(newnode, oldnode, Const);
2814 /* XXX we don't bother with datumCopy; should we? */
2815 return (Node *) newnode;
2816 }
2817 break;
2818 case T_RangeTblEntry: /* required by ORCA */
2819 return range_table_entry_mutator((RangeTblEntry *)node, mutator, context, 0);
2820 case T_Param:
2821 case T_CaseTestExpr:

Calls 5

check_stack_depthFunction · 0.85
list_copyFunction · 0.85
lappendFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected