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: linked dot/arrow chain (postfix expression) */
138 struct filter_node
*prev
;
139 /* next: linked bracket chain (prefix expression) */
140 struct filter_node
*next
;
144 struct filter_node
*lchild
;
145 struct filter_node
*rchild
;
148 enum unary_op_type type
;
149 struct filter_node
*child
;
155 struct filter_node root
;
156 struct cds_list_head allocated_nodes
;
159 const char *node_type(struct filter_node
*node
);
163 struct filter_parser_ctx
{
165 struct filter_ast
*ast
;
166 struct cds_list_head allocated_strings
;
167 struct ir_op
*ir_root
;
168 struct lttng_filter_bytecode_alloc
*bytecode
;
169 struct lttng_filter_bytecode_alloc
*bytecode_reloc
;
172 struct filter_parser_ctx
*filter_parser_ctx_alloc(FILE *input
);
173 void filter_parser_ctx_free(struct filter_parser_ctx
*parser_ctx
);
174 int filter_parser_ctx_append_ast(struct filter_parser_ctx
*parser_ctx
);
177 struct filter_ast
*filter_parser_get_ast(struct filter_parser_ctx
*parser_ctx
)
179 return parser_ctx
->ast
;
182 int filter_visitor_set_parent(struct filter_parser_ctx
*ctx
);
183 int filter_visitor_print_xml(struct filter_parser_ctx
*ctx
, FILE *stream
,
185 int filter_visitor_ir_generate(struct filter_parser_ctx
*ctx
);
186 void filter_ir_free(struct filter_parser_ctx
*ctx
);
187 int filter_visitor_bytecode_generate(struct filter_parser_ctx
*ctx
);
188 void filter_bytecode_free(struct filter_parser_ctx
*ctx
);
189 int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx
*ctx
);
190 int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx
*ctx
);
191 int filter_visitor_ir_validate_string(struct filter_parser_ctx
*ctx
);
192 int filter_visitor_ir_normalize_glob_patterns(struct filter_parser_ctx
*ctx
);
193 int filter_visitor_ir_validate_globbing(struct filter_parser_ctx
*ctx
);
195 #endif /* _FILTER_AST_H */