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
;
117 AST_EXP_FLOAT_CONSTANT
,
121 enum ast_link_type post_op
; /* reverse */
122 enum ast_link_type pre_op
; /* forward */
126 double float_constant
;
129 * child can be nested.
131 struct filter_node
*child
;
133 /* linked dot/arrow chain */
134 struct filter_node
*prev
;
135 struct filter_node
*next
;
139 struct filter_node
*lchild
;
140 struct filter_node
*rchild
;
143 enum unary_op_type type
;
144 struct filter_node
*child
;
150 struct filter_node root
;
151 struct cds_list_head allocated_nodes
;
154 const char *node_type(struct filter_node
*node
);
158 struct filter_parser_ctx
{
160 struct filter_ast
*ast
;
161 struct cds_list_head allocated_strings
;
162 struct ir_op
*ir_root
;
163 struct lttng_filter_bytecode_alloc
*bytecode
;
164 struct lttng_filter_bytecode_alloc
*bytecode_reloc
;
167 struct filter_parser_ctx
*filter_parser_ctx_alloc(FILE *input
);
168 void filter_parser_ctx_free(struct filter_parser_ctx
*parser_ctx
);
169 int filter_parser_ctx_append_ast(struct filter_parser_ctx
*parser_ctx
);
172 struct filter_ast
*filter_parser_get_ast(struct filter_parser_ctx
*parser_ctx
)
174 return parser_ctx
->ast
;
177 int filter_visitor_set_parent(struct filter_parser_ctx
*ctx
);
178 int filter_visitor_print_xml(struct filter_parser_ctx
*ctx
, FILE *stream
,
180 int filter_visitor_ir_generate(struct filter_parser_ctx
*ctx
);
181 void filter_ir_free(struct filter_parser_ctx
*ctx
);
182 int filter_visitor_bytecode_generate(struct filter_parser_ctx
*ctx
);
183 void filter_bytecode_free(struct filter_parser_ctx
*ctx
);
184 int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx
*ctx
);
185 int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx
*ctx
);
187 #endif /* _FILTER_AST_H */