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 | * | |
6 | * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
7 | * | |
8 | * This library is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU Lesser General Public License, version 2.1 only, | |
10 | * as published by the Free Software Foundation. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public License | |
18 | * along with this library; if not, write to the Free Software Foundation, | |
19 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | */ | |
21 | ||
22 | #include <stdio.h> | |
23 | #include <unistd.h> | |
24 | #include <string.h> | |
25 | #include <stdlib.h> | |
26 | #include <assert.h> | |
27 | #include <errno.h> | |
28 | #include <inttypes.h> | |
953192ba | 29 | #include "filter-ast.h" |
95b9bd90 | 30 | #include "filter-parser.h" |
953192ba MD |
31 | #include "filter-ir.h" |
32 | ||
a187da1a DG |
33 | #include <common/macros.h> |
34 | ||
953192ba MD |
35 | static |
36 | int check_bin_op_nesting_recursive(struct ir_op *node, int nesting) | |
37 | { | |
38 | switch (node->op) { | |
39 | case IR_OP_UNKNOWN: | |
40 | default: | |
41 | fprintf(stderr, "[error] %s: unknown op type\n", __func__); | |
42 | return -EINVAL; | |
43 | ||
44 | case IR_OP_ROOT: | |
45 | return check_bin_op_nesting_recursive(node->u.root.child, | |
46 | nesting); | |
47 | case IR_OP_LOAD: | |
48 | return 0; | |
49 | case IR_OP_UNARY: | |
50 | return check_bin_op_nesting_recursive(node->u.unary.child, | |
51 | nesting); | |
52 | case IR_OP_BINARY: | |
53 | { | |
54 | int ret; | |
55 | ||
56 | if (nesting > 0) { | |
57 | fprintf(stderr, "[error] Nesting of binary operators is not allowed, except for logical operators.\n"); | |
58 | return -EINVAL; | |
59 | } | |
60 | ret = check_bin_op_nesting_recursive(node->u.binary.left, | |
29190311 | 61 | nesting + 1); |
953192ba MD |
62 | if (ret) |
63 | return ret; | |
64 | return check_bin_op_nesting_recursive(node->u.binary.right, | |
29190311 | 65 | nesting + 1); |
953192ba MD |
66 | } |
67 | case IR_OP_LOGICAL: | |
68 | { | |
69 | int ret; | |
70 | ||
71 | ret = check_bin_op_nesting_recursive(node->u.logical.left, | |
72 | nesting); | |
73 | if (ret) | |
74 | return ret; | |
75 | return check_bin_op_nesting_recursive(node->u.logical.right, | |
76 | nesting); | |
77 | } | |
78 | } | |
79 | } | |
80 | ||
a187da1a | 81 | LTTNG_HIDDEN |
953192ba MD |
82 | int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx *ctx) |
83 | { | |
84 | return check_bin_op_nesting_recursive(ctx->ir_root, 0); | |
85 | } |