Fix: validate that array expression contains constant
[lttng-tools.git] / src / common / filter / filter-visitor-ir-check-binary-op-nesting.c
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 * SPDX-License-Identifier: LGPL-2.1-only
9 *
10 */
11
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <string.h>
15 #include <stdlib.h>
16 #include <assert.h>
17 #include <inttypes.h>
18 #include "filter-ast.h"
19 #include "filter-parser.h"
20 #include "filter-ir.h"
21
22 #include <common/compat/errno.h>
23 #include <common/macros.h>
24
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
46 ret = check_bin_op_nesting_recursive(node->u.binary.left,
47 nesting + 1);
48 if (ret)
49 return ret;
50 return check_bin_op_nesting_recursive(node->u.binary.right,
51 nesting + 1);
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
67 LTTNG_HIDDEN
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 }
This page took 0.029586 seconds and 4 git commands to generate.