Commit | Line | Data |
---|---|---|
953192ba MD |
1 | /* |
2 | * filter-visitor-ir-check-binary-op-nesting.c | |
3 | * | |
4 | * LTTng filter IR check binary op nesting | |
5 | * | |
ab5be9fa | 6 | * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
953192ba | 7 | * |
ab5be9fa | 8 | * SPDX-License-Identifier: LGPL-2.1-only |
953192ba | 9 | * |
953192ba MD |
10 | */ |
11 | ||
12 | #include <stdio.h> | |
13 | #include <unistd.h> | |
14 | #include <string.h> | |
15 | #include <stdlib.h> | |
16 | #include <assert.h> | |
953192ba | 17 | #include <inttypes.h> |
953192ba | 18 | #include "filter-ast.h" |
95b9bd90 | 19 | #include "filter-parser.h" |
953192ba MD |
20 | #include "filter-ir.h" |
21 | ||
edf4b93e | 22 | #include <common/compat/errno.h> |
a187da1a DG |
23 | #include <common/macros.h> |
24 | ||
953192ba MD |
25 | static |
26 | int check_bin_op_nesting_recursive(struct ir_op *node, int nesting) | |
27 | { | |
28 | switch (node->op) { | |
29 | case IR_OP_UNKNOWN: | |
30 | default: | |
31 | fprintf(stderr, "[error] %s: unknown op type\n", __func__); | |
32 | return -EINVAL; | |
33 | ||
34 | case IR_OP_ROOT: | |
35 | return check_bin_op_nesting_recursive(node->u.root.child, | |
36 | nesting); | |
37 | case IR_OP_LOAD: | |
38 | return 0; | |
39 | case IR_OP_UNARY: | |
40 | return check_bin_op_nesting_recursive(node->u.unary.child, | |
41 | nesting); | |
42 | case IR_OP_BINARY: | |
43 | { | |
44 | int ret; | |
45 | ||
953192ba | 46 | ret = check_bin_op_nesting_recursive(node->u.binary.left, |
29190311 | 47 | nesting + 1); |
953192ba MD |
48 | if (ret) |
49 | return ret; | |
50 | return check_bin_op_nesting_recursive(node->u.binary.right, | |
29190311 | 51 | nesting + 1); |
953192ba MD |
52 | } |
53 | case IR_OP_LOGICAL: | |
54 | { | |
55 | int ret; | |
56 | ||
57 | ret = check_bin_op_nesting_recursive(node->u.logical.left, | |
58 | nesting); | |
59 | if (ret) | |
60 | return ret; | |
61 | return check_bin_op_nesting_recursive(node->u.logical.right, | |
62 | nesting); | |
63 | } | |
64 | } | |
65 | } | |
66 | ||
a187da1a | 67 | LTTNG_HIDDEN |
953192ba MD |
68 | int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx *ctx) |
69 | { | |
70 | return check_bin_op_nesting_recursive(ctx->ir_root, 0); | |
71 | } |