Force usage of assert() condition when NDEBUG is defined
[lttng-tools.git] / src / common / filter / filter-visitor-ir-check-binary-comparator.c
1 /*
2 * filter-visitor-ir-check-binary-comparator.c
3 *
4 * LTTng filter IR check binary comparator
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
18 #include <common/compat/errno.h>
19
20 #include "filter-ast.h"
21 #include "filter-parser.h"
22 #include "filter-ir.h"
23
24 static
25 int check_bin_comparator(struct ir_op *node)
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_comparator(node->u.root.child);
35 case IR_OP_LOAD:
36 return 0;
37 case IR_OP_UNARY:
38 return check_bin_comparator(node->u.unary.child);
39 case IR_OP_BINARY:
40 {
41 int ret;
42
43 if (node->u.binary.left->data_type == IR_DATA_STRING
44 || node->u.binary.right->data_type
45 == IR_DATA_STRING) {
46 if (node->u.binary.type != AST_OP_EQ
47 && node->u.binary.type != AST_OP_NE) {
48 fprintf(stderr, "[error] Only '==' and '!=' comparators are allowed for strings\n");
49 return -EINVAL;
50 }
51 }
52
53 ret = check_bin_comparator(node->u.binary.left);
54 if (ret)
55 return ret;
56 return check_bin_comparator(node->u.binary.right);
57 }
58 case IR_OP_LOGICAL:
59 {
60 int ret;
61
62 ret = check_bin_comparator(node->u.logical.left);
63 if (ret)
64 return ret;
65 return check_bin_comparator(node->u.logical.right);
66 }
67 }
68 }
69
70 int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx *ctx)
71 {
72 return check_bin_comparator(ctx->ir_root);
73 }
This page took 0.03103 seconds and 4 git commands to generate.