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