port: FreeBSD has no ENODATA, alias it to ENOATTR
[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 <assert.h>
17 #include <inttypes.h>
18
19 #include <common/compat/errno.h>
20
21 #include "filter-ast.h"
22 #include "filter-parser.h"
23 #include "filter-ir.h"
24
25 static
26 int check_bin_comparator(struct ir_op *node)
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_comparator(node->u.root.child);
36 case IR_OP_LOAD:
37 return 0;
38 case IR_OP_UNARY:
39 return check_bin_comparator(node->u.unary.child);
40 case IR_OP_BINARY:
41 {
42 int ret;
43
44 if (node->u.binary.left->data_type == IR_DATA_STRING
45 || node->u.binary.right->data_type
46 == IR_DATA_STRING) {
47 if (node->u.binary.type != AST_OP_EQ
48 && node->u.binary.type != AST_OP_NE) {
49 fprintf(stderr, "[error] Only '==' and '!=' comparators are allowed for strings\n");
50 return -EINVAL;
51 }
52 }
53
54 ret = check_bin_comparator(node->u.binary.left);
55 if (ret)
56 return ret;
57 return check_bin_comparator(node->u.binary.right);
58 }
59 case IR_OP_LOGICAL:
60 {
61 int ret;
62
63 ret = check_bin_comparator(node->u.logical.left);
64 if (ret)
65 return ret;
66 return check_bin_comparator(node->u.logical.right);
67 }
68 }
69 }
70
71 int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx *ctx)
72 {
73 return check_bin_comparator(ctx->ir_root);
74 }
This page took 0.030082 seconds and 4 git commands to generate.