9 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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.
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.
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
25 #include <urcu/list.h>
28 #define printf_debug(fmt, args...) \
30 if (filter_parser_debug) \
31 fprintf(stdout, "[debug] " fmt, ## args); \
34 // the parameter name (of the reentrant 'yyparse' function)
35 // data is a pointer to a 'SParserParam' structure
36 //#define YYPARSE_PARAM parser_ctx
38 // the argument for the 'yylex' function
39 #define YYLEX_PARAM ((struct filter_parser_ctx *) parser_ctx)->scanner
41 #ifndef YY_TYPEDEF_YY_SCANNER_T
42 #define YY_TYPEDEF_YY_SCANNER_T
43 typedef void* yyscan_t
;
46 extern int filter_parser_debug
;
86 AST_UNARY_UNKNOWN
= 0,
100 * Parent node is only set on demand by specific visitor.
102 struct filter_node
*parent
;
103 struct cds_list_head gc
;
110 struct filter_node
*child
;
120 enum ast_link_type post_op
; /* reverse */
121 enum ast_link_type pre_op
; /* forward */
127 * child can be nested.
129 struct filter_node
*child
;
131 /* linked dot/arrow chain */
132 struct filter_node
*prev
;
133 struct filter_node
*next
;
137 struct filter_node
*lchild
;
138 struct filter_node
*rchild
;
141 enum unary_op_type type
;
142 struct filter_node
*child
;
148 struct filter_node root
;
149 struct cds_list_head allocated_nodes
;
152 const char *node_type(struct filter_node
*node
);
156 struct filter_parser_ctx
{
158 struct filter_ast
*ast
;
159 struct cds_list_head allocated_strings
;
160 struct ir_op
*ir_root
;
161 struct lttng_filter_bytecode_alloc
*bytecode
;
162 struct lttng_filter_bytecode_alloc
*bytecode_reloc
;
165 struct filter_parser_ctx
*filter_parser_ctx_alloc(FILE *input
);
166 void filter_parser_ctx_free(struct filter_parser_ctx
*parser_ctx
);
167 int filter_parser_ctx_append_ast(struct filter_parser_ctx
*parser_ctx
);
170 struct filter_ast
*filter_parser_get_ast(struct filter_parser_ctx
*parser_ctx
)
172 return parser_ctx
->ast
;
175 int filter_visitor_set_parent(struct filter_parser_ctx
*ctx
);
176 int filter_visitor_print_xml(struct filter_parser_ctx
*ctx
, FILE *stream
,
178 int filter_visitor_ir_generate(struct filter_parser_ctx
*ctx
);
179 void filter_ir_free(struct filter_parser_ctx
*ctx
);
180 int filter_visitor_bytecode_generate(struct filter_parser_ctx
*ctx
);
181 void filter_bytecode_free(struct filter_parser_ctx
*ctx
);
182 int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx
*ctx
);
183 int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx
*ctx
);
185 #endif /* _FILTER_AST_H */