| 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 <inttypes.h> |
| 17 | #include "filter-ast.h" |
| 18 | #include "filter-parser.h" |
| 19 | #include "filter-ir.h" |
| 20 | |
| 21 | #include <common/compat/errno.h> |
| 22 | #include <common/macros.h> |
| 23 | |
| 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 | |
| 45 | ret = check_bin_op_nesting_recursive(node->u.binary.left, |
| 46 | nesting + 1); |
| 47 | if (ret) |
| 48 | return ret; |
| 49 | return check_bin_op_nesting_recursive(node->u.binary.right, |
| 50 | nesting + 1); |
| 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 | LTTNG_HIDDEN |
| 67 | int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx *ctx) |
| 68 | { |
| 69 | return check_bin_op_nesting_recursive(ctx->ir_root, 0); |
| 70 | } |