1#include "duckdb/parser/parsed_expression_iterator.hpp"
2
3#include "duckdb/parser/expression/list.hpp"
4
5using namespace duckdb;
6using namespace std;
7
8void ParsedExpressionIterator::EnumerateChildren(const ParsedExpression &expr,
9 function<void(const ParsedExpression &child)> callback) {
10 switch (expr.expression_class) {
11 case ExpressionClass::CASE: {
12 auto &case_expr = (const CaseExpression &)expr;
13 callback(*case_expr.check);
14 callback(*case_expr.result_if_true);
15 callback(*case_expr.result_if_false);
16 break;
17 }
18 case ExpressionClass::CAST: {
19 auto &cast_expr = (const CastExpression &)expr;
20 callback(*cast_expr.child);
21 break;
22 }
23 case ExpressionClass::COLLATE: {
24 auto &cast_expr = (const CollateExpression &)expr;
25 callback(*cast_expr.child);
26 break;
27 }
28 case ExpressionClass::COMPARISON: {
29 auto &comp_expr = (const ComparisonExpression &)expr;
30 callback(*comp_expr.left);
31 callback(*comp_expr.right);
32 break;
33 }
34 case ExpressionClass::CONJUNCTION: {
35 auto &conj_expr = (const ConjunctionExpression &)expr;
36 for (auto &child : conj_expr.children) {
37 callback(*child);
38 }
39 break;
40 }
41 case ExpressionClass::FUNCTION: {
42 auto &func_expr = (const FunctionExpression &)expr;
43 for (auto &child : func_expr.children) {
44 callback(*child);
45 }
46 break;
47 }
48 case ExpressionClass::OPERATOR: {
49 auto &op_expr = (const OperatorExpression &)expr;
50 for (auto &child : op_expr.children) {
51 callback(*child);
52 }
53 break;
54 }
55 case ExpressionClass::SUBQUERY: {
56 auto &subquery_expr = (const SubqueryExpression &)expr;
57 if (subquery_expr.child) {
58 callback(*subquery_expr.child);
59 }
60 break;
61 }
62 case ExpressionClass::WINDOW: {
63 auto &window_expr = (const WindowExpression &)expr;
64 for (auto &partition : window_expr.partitions) {
65 callback(*partition);
66 }
67 for (auto &order : window_expr.orders) {
68 callback(*order.expression);
69 }
70 for (auto &child : window_expr.children) {
71 callback(*child);
72 }
73 if (window_expr.offset_expr) {
74 callback(*window_expr.offset_expr);
75 }
76 if (window_expr.default_expr) {
77 callback(*window_expr.default_expr);
78 }
79 break;
80 }
81 case ExpressionClass::BOUND_EXPRESSION:
82 case ExpressionClass::COLUMN_REF:
83 case ExpressionClass::CONSTANT:
84 case ExpressionClass::DEFAULT:
85 case ExpressionClass::STAR:
86 case ExpressionClass::TABLE_STAR:
87 case ExpressionClass::PARAMETER:
88 // these node types have no children
89 break;
90 default:
91 // called on non ParsedExpression type!
92 throw NotImplementedException("Unimplemented expression class");
93 }
94}
95