Librarify filter in liblttng-ctl and hide symbols
[lttng-tools.git] / src / lib / lttng-ctl / filter / filter-ast.h
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
25 /*
26 * Note: filter-ast.h should be included before filter-parser.h.
27 */
28
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
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
42 // the argument for the 'yylex' function
43 #define YYLEX_PARAM ((struct filter_parser_ctx *) parser_ctx)->scanner
44
45 #ifndef YY_TYPEDEF_YY_SCANNER_T
46 #define YY_TYPEDEF_YY_SCANNER_T
47 typedef void* yyscan_t;
48 #endif
49
50 extern int filter_parser_debug;
51
52 struct filter_node;
53 struct filter_parser;
54
55 enum node_type {
56 NODE_UNKNOWN = 0,
57 NODE_ROOT,
58
59 NODE_EXPRESSION,
60 NODE_OP,
61 NODE_UNARY_OP,
62
63 NR_NODE_TYPES,
64 };
65
66 enum op_type {
67 AST_OP_UNKNOWN = 0,
68 AST_OP_MUL,
69 AST_OP_DIV,
70 AST_OP_MOD,
71 AST_OP_PLUS,
72 AST_OP_MINUS,
73 AST_OP_RSHIFT,
74 AST_OP_LSHIFT,
75 AST_OP_AND,
76 AST_OP_OR,
77 AST_OP_BIN_AND,
78 AST_OP_BIN_OR,
79 AST_OP_BIN_XOR,
80
81 AST_OP_EQ,
82 AST_OP_NE,
83 AST_OP_GT,
84 AST_OP_LT,
85 AST_OP_GE,
86 AST_OP_LE,
87 };
88
89 enum unary_op_type {
90 AST_UNARY_UNKNOWN = 0,
91 AST_UNARY_PLUS,
92 AST_UNARY_MINUS,
93 AST_UNARY_NOT,
94 AST_UNARY_BIN_NOT,
95 };
96
97 enum ast_link_type {
98 AST_LINK_UNKNOWN = 0,
99 AST_LINK_DOT,
100 AST_LINK_RARROW,
101 };
102
103 struct filter_node {
104 /*
105 * Parent node is only set on demand by specific visitor.
106 */
107 struct filter_node *parent;
108 struct cds_list_head gc;
109
110 enum node_type type;
111 union {
112 struct {
113 } unknown;
114 struct {
115 struct filter_node *child;
116 } root;
117 struct {
118 enum {
119 AST_EXP_UNKNOWN = 0,
120 AST_EXP_STRING,
121 AST_EXP_CONSTANT,
122 AST_EXP_FLOAT_CONSTANT,
123 AST_EXP_IDENTIFIER,
124 AST_EXP_NESTED,
125 } type;
126 enum ast_link_type post_op; /* reverse */
127 enum ast_link_type pre_op; /* forward */
128 union {
129 char *string;
130 uint64_t constant;
131 double float_constant;
132 char *identifier;
133 /*
134 * child can be nested.
135 */
136 struct filter_node *child;
137 } u;
138 /* linked dot/arrow chain */
139 struct filter_node *prev;
140 struct filter_node *next;
141 } expression;
142 struct {
143 enum op_type type;
144 struct filter_node *lchild;
145 struct filter_node *rchild;
146 } op;
147 struct {
148 enum unary_op_type type;
149 struct filter_node *child;
150 } unary_op;
151 } u;
152 };
153
154 struct filter_ast {
155 struct filter_node root;
156 struct cds_list_head allocated_nodes;
157 };
158
159 const char *node_type(struct filter_node *node);
160
161 struct ir_op;
162
163 struct filter_parser_ctx {
164 yyscan_t scanner;
165 struct filter_ast *ast;
166 struct cds_list_head allocated_strings;
167 struct ir_op *ir_root;
168 struct lttng_filter_bytecode_alloc *bytecode;
169 struct lttng_filter_bytecode_alloc *bytecode_reloc;
170 };
171
172 struct filter_parser_ctx *filter_parser_ctx_alloc(FILE *input);
173 void filter_parser_ctx_free(struct filter_parser_ctx *parser_ctx);
174 int filter_parser_ctx_append_ast(struct filter_parser_ctx *parser_ctx);
175
176 static inline
177 struct filter_ast *filter_parser_get_ast(struct filter_parser_ctx *parser_ctx)
178 {
179 return parser_ctx->ast;
180 }
181
182 int filter_visitor_set_parent(struct filter_parser_ctx *ctx);
183 int filter_visitor_print_xml(struct filter_parser_ctx *ctx, FILE *stream,
184 int indent);
185 int filter_visitor_ir_generate(struct filter_parser_ctx *ctx);
186 void filter_ir_free(struct filter_parser_ctx *ctx);
187 int filter_visitor_bytecode_generate(struct filter_parser_ctx *ctx);
188 void filter_bytecode_free(struct filter_parser_ctx *ctx);
189 int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx *ctx);
190 int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx *ctx);
191
192 #endif /* _FILTER_AST_H */
This page took 0.033214 seconds and 5 git commands to generate.