Rename C++ header files to .hpp
[lttng-tools.git] / src / common / filter / filter-visitor-ir-check-binary-comparator.cpp
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>
953192ba 16#include <inttypes.h>
edf4b93e 17
c9e313bc 18#include <common/compat/errno.hpp>
edf4b93e 19
c9e313bc 20#include "filter-ast.hpp"
348ddc5c 21#include "filter-parser.hpp"
c9e313bc 22#include "filter-ir.hpp"
953192ba
MD
23
24static
25int 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
70int 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.05994 seconds and 4 git commands to generate.