Run clang-format on the whole tree
[lttng-tools.git] / src / common / filter / filter-visitor-ir-check-binary-op-nesting.cpp
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 "filter-ast.hpp"
13 #include "filter-ir.hpp"
14 #include "filter-parser.hpp"
15
16 #include <common/compat/errno.hpp>
17 #include <common/macros.hpp>
18
19 #include <inttypes.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24
25 static 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, nesting);
35 case IR_OP_LOAD:
36 return 0;
37 case IR_OP_UNARY:
38 return check_bin_op_nesting_recursive(node->u.unary.child, nesting);
39 case IR_OP_BINARY:
40 {
41 int ret;
42
43 ret = check_bin_op_nesting_recursive(node->u.binary.left, nesting + 1);
44 if (ret)
45 return ret;
46 return check_bin_op_nesting_recursive(node->u.binary.right, nesting + 1);
47 }
48 case IR_OP_LOGICAL:
49 {
50 int ret;
51
52 ret = check_bin_op_nesting_recursive(node->u.logical.left, nesting);
53 if (ret)
54 return ret;
55 return check_bin_op_nesting_recursive(node->u.logical.right, nesting);
56 }
57 }
58 }
59
60 int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx *ctx)
61 {
62 return check_bin_op_nesting_recursive(ctx->ir_root, 0);
63 }
This page took 0.031904 seconds and 5 git commands to generate.