Build fix: missing cstdlib include in filter-ir.hpp
[lttng-tools.git] / src / common / filter / filter-ir.hpp
1 #ifndef _FILTER_IR_H
2 #define _FILTER_IR_H
3
4 /*
5 * filter-ir.h
6 *
7 * LTTng filter ir
8 *
9 * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * SPDX-License-Identifier: LGPL-2.1-only
12 *
13 */
14
15 #include "filter-ast.hpp"
16
17 #include <cstdlib>
18
19 enum ir_op_signedness {
20 IR_SIGN_UNKNOWN = 0,
21 IR_SIGNED,
22 IR_UNSIGNED,
23 IR_SIGN_DYN, /* signedness determined dynamically */
24 };
25
26 enum ir_data_type {
27 IR_DATA_UNKNOWN = 0,
28 IR_DATA_STRING,
29 IR_DATA_NUMERIC, /* numeric and boolean */
30 IR_DATA_FLOAT,
31 IR_DATA_FIELD_REF,
32 IR_DATA_GET_CONTEXT_REF,
33 IR_DATA_EXPRESSION,
34 };
35
36 static inline
37 const char *ir_data_type_str(enum ir_data_type type)
38 {
39 switch (type) {
40 case IR_DATA_UNKNOWN:
41 return "IR_DATA_UNKNOWN";
42 case IR_DATA_STRING:
43 return "IR_DATA_STRING";
44 case IR_DATA_NUMERIC:
45 return "IR_DATA_NUMERIC";
46 case IR_DATA_FLOAT:
47 return "IR_DATA_FLOAT";
48 case IR_DATA_FIELD_REF:
49 return "IR_DATA_FIELD_REF";
50 case IR_DATA_GET_CONTEXT_REF:
51 return "IR_DATA_GET_CONTEXT_REF";
52 case IR_DATA_EXPRESSION:
53 return "IR_DATA_EXPRESSION";
54 default:
55 abort();
56 }
57 }
58
59 enum ir_op_type {
60 IR_OP_UNKNOWN = 0,
61 IR_OP_ROOT,
62 IR_OP_LOAD,
63 IR_OP_UNARY,
64 IR_OP_BINARY,
65 IR_OP_LOGICAL,
66 };
67
68 static inline
69 const char *ir_op_type_str(enum ir_op_type type)
70 {
71 switch (type) {
72 case IR_OP_UNKNOWN:
73 return "IR_OP_UNKNOWN";
74 case IR_OP_ROOT:
75 return "IR_OP_ROOT";
76 case IR_OP_LOAD:
77 return "IR_OP_LOAD";
78 case IR_OP_UNARY:
79 return "IR_OP_UNARY";
80 case IR_OP_BINARY:
81 return "IR_OP_BINARY";
82 case IR_OP_LOGICAL:
83 return "IR_OP_LOGICAL";
84 default:
85 abort();
86 }
87 }
88
89 /* left or right child */
90 enum ir_side {
91 IR_SIDE_UNKNOWN = 0,
92 IR_LEFT,
93 IR_RIGHT,
94 };
95
96 enum ir_load_string_type {
97 /* Plain, no globbing at all: `hello world`. */
98 IR_LOAD_STRING_TYPE_PLAIN = 0,
99
100 /* Star at the end only: `hello *`. */
101 IR_LOAD_STRING_TYPE_GLOB_STAR_END,
102
103 /* At least one star, anywhere, but not at the end only: `he*wor*`. */
104 IR_LOAD_STRING_TYPE_GLOB_STAR,
105 };
106
107 struct ir_op_root {
108 struct ir_op *child;
109 };
110
111 enum ir_load_expression_type {
112 IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT,
113 IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT,
114 IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT,
115 IR_LOAD_EXPRESSION_GET_SYMBOL,
116 IR_LOAD_EXPRESSION_GET_INDEX,
117 IR_LOAD_EXPRESSION_LOAD_FIELD,
118 };
119
120 static inline
121 const char *ir_load_expression_type_str(enum ir_load_expression_type type)
122 {
123 switch (type) {
124 case IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT:
125 return "IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT";
126 case IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT:
127 return "IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT";
128 case IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT:
129 return "IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT";
130 case IR_LOAD_EXPRESSION_GET_SYMBOL:
131 return "IR_LOAD_EXPRESSION_GET_SYMBOL";
132 case IR_LOAD_EXPRESSION_GET_INDEX:
133 return "IR_LOAD_EXPRESSION_GET_INDEX";
134 case IR_LOAD_EXPRESSION_LOAD_FIELD:
135 return "IR_LOAD_EXPRESSION_LOAD_FIELD";
136 default:
137 abort();
138 }
139 }
140
141 struct ir_load_expression_op {
142 struct ir_load_expression_op *next;
143 enum ir_load_expression_type type;
144 union {
145 char *symbol;
146 uint64_t index;
147 } u;
148 };
149
150 struct ir_load_expression {
151 struct ir_load_expression_op *child;
152 };
153
154 struct ir_op_load {
155 union {
156 struct {
157 enum ir_load_string_type type;
158 char *value;
159 } string;
160 int64_t num;
161 double flt;
162 char *ref;
163 struct ir_load_expression *expression;
164 } u;
165 };
166
167 struct ir_op_unary {
168 enum unary_op_type type;
169 struct ir_op *child;
170 };
171
172 struct ir_op_binary {
173 enum op_type type;
174 struct ir_op *left;
175 struct ir_op *right;
176 };
177
178 struct ir_op_logical {
179 enum op_type type;
180 struct ir_op *left;
181 struct ir_op *right;
182 };
183
184 struct ir_op {
185 /* common to all ops */
186 enum ir_op_type op;
187 enum ir_data_type data_type;
188 enum ir_op_signedness signedness;
189 enum ir_side side;
190
191 union {
192 struct ir_op_root root;
193 struct ir_op_load load;
194 struct ir_op_unary unary;
195 struct ir_op_binary binary;
196 struct ir_op_logical logical;
197 } u;
198 };
199
200 #endif /* _FILTER_IR_H */
This page took 0.037825 seconds and 4 git commands to generate.