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,
103 * Parent node is only set on demand by specific visitor.
105 struct filter_node
*parent
;
106 struct cds_list_head gc
;
113 struct filter_node
*child
;
120 AST_EXP_FLOAT_CONSTANT
,
122 AST_EXP_GLOBAL_IDENTIFIER
,
125 enum ast_link_type post_op
; /* reverse */
126 enum ast_link_type pre_op
; /* forward */
130 double float_constant
;
133 * child can be nested.
135 struct filter_node
*child
;
137 /* prev: backward dot/arrow chain (postfix expression) */
138 struct filter_node
*prev
;
139 /* next: forward dot/arrow chain, generated by a visitor. */
140 struct filter_node
*next
;
141 /* next_bracket: linked bracket chain (prefix expression) */
142 struct filter_node
*next_bracket
;
146 struct filter_node
*lchild
;
147 struct filter_node
*rchild
;
150 enum unary_op_type type
;
151 struct filter_node
*child
;
157 struct filter_node root
;
158 struct cds_list_head allocated_nodes
;
161 const char *node_type(struct filter_node
*node
);
165 struct filter_parser_ctx
{
167 struct filter_ast
*ast
;
168 struct cds_list_head allocated_strings
;
169 struct ir_op
*ir_root
;
170 struct lttng_filter_bytecode_alloc
*bytecode
;
171 struct lttng_filter_bytecode_alloc
*bytecode_reloc
;
174 struct filter_parser_ctx
*filter_parser_ctx_alloc(FILE *input
);
175 void filter_parser_ctx_free(struct filter_parser_ctx
*parser_ctx
);
176 int filter_parser_ctx_append_ast(struct filter_parser_ctx
*parser_ctx
);
179 struct filter_ast
*filter_parser_get_ast(struct filter_parser_ctx
*parser_ctx
)
181 return parser_ctx
->ast
;
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
);
192 int filter_visitor_ir_validate_string(struct filter_parser_ctx
*ctx
);
193 int filter_visitor_ir_normalize_glob_patterns(struct filter_parser_ctx
*ctx
);
194 int filter_visitor_ir_validate_globbing(struct filter_parser_ctx
*ctx
);
196 #endif /* _FILTER_AST_H */