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 // the argument for the 'yylex' function
43 #define YYLEX_PARAM ((struct filter_parser_ctx *) parser_ctx)->scanner
45 #ifndef YY_TYPEDEF_YY_SCANNER_T
46 #define YY_TYPEDEF_YY_SCANNER_T
47 typedef void* yyscan_t
;
50 extern int filter_parser_debug
;
90 AST_UNARY_UNKNOWN
= 0,
105 * Parent node is only set on demand by specific visitor.
107 struct filter_node
*parent
;
108 struct cds_list_head gc
;
115 struct filter_node
*child
;
122 AST_EXP_FLOAT_CONSTANT
,
124 AST_EXP_GLOBAL_IDENTIFIER
,
127 enum ast_link_type post_op
; /* reverse */
128 enum ast_link_type pre_op
; /* forward */
132 double float_constant
;
135 * child can be nested.
137 struct filter_node
*child
;
139 /* linked dot/arrow chain */
140 struct filter_node
*prev
;
141 struct filter_node
*next
;
145 struct filter_node
*lchild
;
146 struct filter_node
*rchild
;
149 enum unary_op_type type
;
150 struct filter_node
*child
;
156 struct filter_node root
;
157 struct cds_list_head allocated_nodes
;
160 const char *node_type(struct filter_node
*node
);
164 struct filter_parser_ctx
{
166 struct filter_ast
*ast
;
167 struct cds_list_head allocated_strings
;
168 struct ir_op
*ir_root
;
169 struct lttng_filter_bytecode_alloc
*bytecode
;
170 struct lttng_filter_bytecode_alloc
*bytecode_reloc
;
173 struct filter_parser_ctx
*filter_parser_ctx_alloc(FILE *input
);
174 void filter_parser_ctx_free(struct filter_parser_ctx
*parser_ctx
);
175 int filter_parser_ctx_append_ast(struct filter_parser_ctx
*parser_ctx
);
178 struct filter_ast
*filter_parser_get_ast(struct filter_parser_ctx
*parser_ctx
)
180 return parser_ctx
->ast
;
183 int filter_visitor_set_parent(struct filter_parser_ctx
*ctx
);
184 int filter_visitor_print_xml(struct filter_parser_ctx
*ctx
, FILE *stream
,
186 int filter_visitor_ir_generate(struct filter_parser_ctx
*ctx
);
187 void filter_ir_free(struct filter_parser_ctx
*ctx
);
188 int filter_visitor_bytecode_generate(struct filter_parser_ctx
*ctx
);
189 void filter_bytecode_free(struct filter_parser_ctx
*ctx
);
190 int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx
*ctx
);
191 int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx
*ctx
);
193 #endif /* _FILTER_AST_H */