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