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> | |
953192ba | 16 | #include <inttypes.h> |
c9e313bc | 17 | #include "filter-ast.hpp" |
348ddc5c | 18 | #include "filter-parser.hpp" |
c9e313bc | 19 | #include "filter-ir.hpp" |
953192ba | 20 | |
c9e313bc SM |
21 | #include <common/compat/errno.hpp> |
22 | #include <common/macros.hpp> | |
a187da1a | 23 | |
953192ba MD |
24 | static |
25 | int check_bin_op_nesting_recursive(struct ir_op *node, int nesting) | |
26 | { | |
27 | switch (node->op) { | |
28 | case IR_OP_UNKNOWN: | |
29 | default: | |
30 | fprintf(stderr, "[error] %s: unknown op type\n", __func__); | |
31 | return -EINVAL; | |
32 | ||
33 | case IR_OP_ROOT: | |
34 | return check_bin_op_nesting_recursive(node->u.root.child, | |
35 | nesting); | |
36 | case IR_OP_LOAD: | |
37 | return 0; | |
38 | case IR_OP_UNARY: | |
39 | return check_bin_op_nesting_recursive(node->u.unary.child, | |
40 | nesting); | |
41 | case IR_OP_BINARY: | |
42 | { | |
43 | int ret; | |
44 | ||
953192ba | 45 | ret = check_bin_op_nesting_recursive(node->u.binary.left, |
29190311 | 46 | nesting + 1); |
953192ba MD |
47 | if (ret) |
48 | return ret; | |
49 | return check_bin_op_nesting_recursive(node->u.binary.right, | |
29190311 | 50 | nesting + 1); |
953192ba MD |
51 | } |
52 | case IR_OP_LOGICAL: | |
53 | { | |
54 | int ret; | |
55 | ||
56 | ret = check_bin_op_nesting_recursive(node->u.logical.left, | |
57 | nesting); | |
58 | if (ret) | |
59 | return ret; | |
60 | return check_bin_op_nesting_recursive(node->u.logical.right, | |
61 | nesting); | |
62 | } | |
63 | } | |
64 | } | |
65 | ||
66 | int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx *ctx) | |
67 | { | |
68 | return check_bin_op_nesting_recursive(ctx->ir_root, 0); | |
69 | } |