Clean-up: consumer: consumer_metadata_cache_write is not const-correct
[lttng-tools.git] / src / lib / lttng-ctl / filter / filter-visitor-ir-check-binary-comparator.c
CommitLineData
953192ba
MD
1/*
2 * filter-visitor-ir-check-binary-comparator.c
3 *
4 * LTTng filter IR check binary comparator
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
12#include <stdio.h>
13#include <unistd.h>
14#include <string.h>
15#include <stdlib.h>
16#include <assert.h>
17#include <errno.h>
18#include <inttypes.h>
953192ba 19#include "filter-ast.h"
95b9bd90 20#include "filter-parser.h"
953192ba
MD
21#include "filter-ir.h"
22
23static
24int check_bin_comparator(struct ir_op *node)
25{
26 switch (node->op) {
27 case IR_OP_UNKNOWN:
28 default:
29 fprintf(stderr, "[error] %s: unknown op type\n", __func__);
30 return -EINVAL;
31
32 case IR_OP_ROOT:
33 return check_bin_comparator(node->u.root.child);
34 case IR_OP_LOAD:
35 return 0;
36 case IR_OP_UNARY:
37 return check_bin_comparator(node->u.unary.child);
38 case IR_OP_BINARY:
39 {
40 int ret;
41
42 if (node->u.binary.left->data_type == IR_DATA_STRING
43 || node->u.binary.right->data_type
44 == IR_DATA_STRING) {
45 if (node->u.binary.type != AST_OP_EQ
46 && node->u.binary.type != AST_OP_NE) {
47 fprintf(stderr, "[error] Only '==' and '!=' comparators are allowed for strings\n");
48 return -EINVAL;
49 }
50 }
51
52 ret = check_bin_comparator(node->u.binary.left);
53 if (ret)
54 return ret;
55 return check_bin_comparator(node->u.binary.right);
56 }
57 case IR_OP_LOGICAL:
58 {
59 int ret;
60
61 ret = check_bin_comparator(node->u.logical.left);
62 if (ret)
63 return ret;
64 return check_bin_comparator(node->u.logical.right);
65 }
66 }
67}
68
69int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx *ctx)
70{
71 return check_bin_comparator(ctx->ir_root);
72}
This page took 0.048669 seconds and 4 git commands to generate.