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
26 * Note: filter-ast.h should be included before filter-parser.h.
29 #include <urcu/list.h>
32 #define printf_debug(fmt, args...) \
34 if (filter_parser_debug) \
35 fprintf(stdout, "[debug] " fmt, ## args); \
38 // the parameter name (of the reentrant 'yyparse' function)
39 // data is a pointer to a 'SParserParam' structure
40 //#define YYPARSE_PARAM parser_ctx
42 #ifndef YY_TYPEDEF_YY_SCANNER_T
43 #define YY_TYPEDEF_YY_SCANNER_T
44 typedef void* yyscan_t
;
47 extern int filter_parser_debug
;
87 AST_UNARY_UNKNOWN
= 0,
102 * Parent node is only set on demand by specific visitor.
104 struct filter_node
*parent
;
105 struct cds_list_head gc
;
112 struct filter_node
*child
;
119 AST_EXP_FLOAT_CONSTANT
,
121 AST_EXP_GLOBAL_IDENTIFIER
,
124 enum ast_link_type post_op
; /* reverse */
125 enum ast_link_type pre_op
; /* forward */
129 double float_constant
;
132 * child can be nested.
134 struct filter_node
*child
;
136 /* linked dot/arrow chain */
137 struct filter_node
*prev
;
138 struct filter_node
*next
;
142 struct filter_node
*lchild
;
143 struct filter_node
*rchild
;
146 enum unary_op_type type
;
147 struct filter_node
*child
;
153 struct filter_node root
;
154 struct cds_list_head allocated_nodes
;
157 const char *node_type(struct filter_node
*node
);
161 struct filter_parser_ctx
{
163 struct filter_ast
*ast
;
164 struct cds_list_head allocated_strings
;
165 struct ir_op
*ir_root
;
166 struct lttng_filter_bytecode_alloc
*bytecode
;
167 struct lttng_filter_bytecode_alloc
*bytecode_reloc
;
170 struct filter_parser_ctx
*filter_parser_ctx_alloc(FILE *input
);
171 void filter_parser_ctx_free(struct filter_parser_ctx
*parser_ctx
);
172 int filter_parser_ctx_append_ast(struct filter_parser_ctx
*parser_ctx
);
175 struct filter_ast
*filter_parser_get_ast(struct filter_parser_ctx
*parser_ctx
)
177 return parser_ctx
->ast
;
180 int filter_visitor_set_parent(struct filter_parser_ctx
*ctx
);
181 int filter_visitor_print_xml(struct filter_parser_ctx
*ctx
, FILE *stream
,
183 int filter_visitor_ir_generate(struct filter_parser_ctx
*ctx
);
184 void filter_ir_free(struct filter_parser_ctx
*ctx
);
185 int filter_visitor_bytecode_generate(struct filter_parser_ctx
*ctx
);
186 void filter_bytecode_free(struct filter_parser_ctx
*ctx
);
187 int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx
*ctx
);
188 int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx
*ctx
);
190 #endif /* _FILTER_AST_H */