Filter: Implement rshift, lshift, bit not operators
[lttng-tools.git] / src / lib / lttng-ctl / filter / filter-ast.h
CommitLineData
953192ba
MD
1#ifndef _FILTER_AST_H
2#define _FILTER_AST_H
3
4/*
5 * filter-ast.h
6 *
7 * LTTng filter AST
8 *
9 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License, version 2.1 only,
13 * as published by the Free Software Foundation.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
95b9bd90
MD
25/*
26 * Note: filter-ast.h should be included before filter-parser.h.
27 */
28
953192ba
MD
29#include <urcu/list.h>
30#include <stdint.h>
31
32#define printf_debug(fmt, args...) \
33 do { \
34 if (filter_parser_debug) \
35 fprintf(stdout, "[debug] " fmt, ## args); \
36 } while (0)
37
af71d06b
MD
38// the parameter name (of the reentrant 'yyparse' function)
39// data is a pointer to a 'SParserParam' structure
40//#define YYPARSE_PARAM parser_ctx
41
953192ba
MD
42#ifndef YY_TYPEDEF_YY_SCANNER_T
43#define YY_TYPEDEF_YY_SCANNER_T
44typedef void* yyscan_t;
45#endif
46
47extern int filter_parser_debug;
48
49struct filter_node;
50struct filter_parser;
51
52enum node_type {
53 NODE_UNKNOWN = 0,
54 NODE_ROOT,
55
56 NODE_EXPRESSION,
57 NODE_OP,
58 NODE_UNARY_OP,
59
60 NR_NODE_TYPES,
61};
62
63enum op_type {
64 AST_OP_UNKNOWN = 0,
65 AST_OP_MUL,
66 AST_OP_DIV,
67 AST_OP_MOD,
68 AST_OP_PLUS,
69 AST_OP_MINUS,
116d3c01
MD
70 AST_OP_BIT_RSHIFT,
71 AST_OP_BIT_LSHIFT,
953192ba
MD
72 AST_OP_AND,
73 AST_OP_OR,
bff988fa
MD
74 AST_OP_BIT_AND,
75 AST_OP_BIT_OR,
76 AST_OP_BIT_XOR,
953192ba
MD
77
78 AST_OP_EQ,
79 AST_OP_NE,
80 AST_OP_GT,
81 AST_OP_LT,
82 AST_OP_GE,
83 AST_OP_LE,
84};
85
86enum unary_op_type {
87 AST_UNARY_UNKNOWN = 0,
88 AST_UNARY_PLUS,
89 AST_UNARY_MINUS,
90 AST_UNARY_NOT,
bff988fa 91 AST_UNARY_BIT_NOT,
953192ba
MD
92};
93
94enum ast_link_type {
95 AST_LINK_UNKNOWN = 0,
96 AST_LINK_DOT,
97 AST_LINK_RARROW,
661dfdd1 98 AST_LINK_BRACKET,
953192ba
MD
99};
100
101struct filter_node {
102 /*
103 * Parent node is only set on demand by specific visitor.
104 */
105 struct filter_node *parent;
106 struct cds_list_head gc;
107
108 enum node_type type;
109 union {
110 struct {
111 } unknown;
112 struct {
113 struct filter_node *child;
114 } root;
115 struct {
116 enum {
117 AST_EXP_UNKNOWN = 0,
118 AST_EXP_STRING,
119 AST_EXP_CONSTANT,
e90d8561 120 AST_EXP_FLOAT_CONSTANT,
953192ba 121 AST_EXP_IDENTIFIER,
586dc72f 122 AST_EXP_GLOBAL_IDENTIFIER,
953192ba
MD
123 AST_EXP_NESTED,
124 } type;
125 enum ast_link_type post_op; /* reverse */
126 enum ast_link_type pre_op; /* forward */
127 union {
128 char *string;
129 uint64_t constant;
e90d8561 130 double float_constant;
953192ba
MD
131 char *identifier;
132 /*
133 * child can be nested.
134 */
135 struct filter_node *child;
136 } u;
bff988fa 137 /* prev: backward dot/arrow chain (postfix expression) */
953192ba 138 struct filter_node *prev;
bff988fa 139 /* next: forward dot/arrow chain, generated by a visitor. */
953192ba 140 struct filter_node *next;
bff988fa
MD
141 /* next_bracket: linked bracket chain (prefix expression) */
142 struct filter_node *next_bracket;
953192ba
MD
143 } expression;
144 struct {
145 enum op_type type;
146 struct filter_node *lchild;
147 struct filter_node *rchild;
148 } op;
149 struct {
150 enum unary_op_type type;
151 struct filter_node *child;
152 } unary_op;
153 } u;
154};
155
156struct filter_ast {
157 struct filter_node root;
158 struct cds_list_head allocated_nodes;
159};
160
161const char *node_type(struct filter_node *node);
162
163struct ir_op;
953192ba
MD
164
165struct filter_parser_ctx {
166 yyscan_t scanner;
167 struct filter_ast *ast;
168 struct cds_list_head allocated_strings;
169 struct ir_op *ir_root;
53a80697
MD
170 struct lttng_filter_bytecode_alloc *bytecode;
171 struct lttng_filter_bytecode_alloc *bytecode_reloc;
953192ba
MD
172};
173
174struct filter_parser_ctx *filter_parser_ctx_alloc(FILE *input);
175void filter_parser_ctx_free(struct filter_parser_ctx *parser_ctx);
176int filter_parser_ctx_append_ast(struct filter_parser_ctx *parser_ctx);
177
178static inline
179struct filter_ast *filter_parser_get_ast(struct filter_parser_ctx *parser_ctx)
180{
181 return parser_ctx->ast;
182}
183
953192ba
MD
184int filter_visitor_print_xml(struct filter_parser_ctx *ctx, FILE *stream,
185 int indent);
186int filter_visitor_ir_generate(struct filter_parser_ctx *ctx);
187void filter_ir_free(struct filter_parser_ctx *ctx);
188int filter_visitor_bytecode_generate(struct filter_parser_ctx *ctx);
189void filter_bytecode_free(struct filter_parser_ctx *ctx);
190int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx *ctx);
191int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx *ctx);
dcd5daf2 192int filter_visitor_ir_validate_string(struct filter_parser_ctx *ctx);
9f449915
PP
193int filter_visitor_ir_normalize_glob_patterns(struct filter_parser_ctx *ctx);
194int filter_visitor_ir_validate_globbing(struct filter_parser_ctx *ctx);
953192ba
MD
195
196#endif /* _FILTER_AST_H */
This page took 0.046354 seconds and 4 git commands to generate.