9 * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * SPDX-License-Identifier: LGPL-2.1-only
16 * Note: filter-ast.h should be included before filter-parser.h.
19 #include <urcu/list.h>
22 #define printf_debug(fmt, args...) \
24 if (filter_parser_debug) \
25 fprintf(stdout, "[debug] " fmt, ## args); \
28 // the parameter name (of the reentrant 'yyparse' function)
29 // data is a pointer to a 'SParserParam' structure
30 //#define YYPARSE_PARAM parser_ctx
32 #ifndef YY_TYPEDEF_YY_SCANNER_T
33 #define YY_TYPEDEF_YY_SCANNER_T
34 typedef void* yyscan_t
;
37 extern int filter_parser_debug
;
77 AST_UNARY_UNKNOWN
= 0,
93 * Parent node is only set on demand by specific visitor.
95 struct filter_node
*parent
;
96 struct cds_list_head gc
;
103 struct filter_node
*child
;
110 AST_EXP_FLOAT_CONSTANT
,
112 AST_EXP_GLOBAL_IDENTIFIER
,
115 enum ast_link_type post_op
; /* reverse */
116 enum ast_link_type pre_op
; /* forward */
120 double float_constant
;
123 * child can be nested.
125 struct filter_node
*child
;
127 /* prev: backward dot/arrow chain (postfix expression) */
128 struct filter_node
*prev
;
129 /* next: forward dot/arrow chain, generated by a visitor. */
130 struct filter_node
*next
;
131 /* next_bracket: linked bracket chain (prefix expression) */
132 struct filter_node
*next_bracket
;
136 struct filter_node
*lchild
;
137 struct filter_node
*rchild
;
140 enum unary_op_type type
;
141 struct filter_node
*child
;
147 struct filter_node root
;
148 struct cds_list_head allocated_nodes
;
151 const char *node_type(struct filter_node
*node
);
155 struct filter_parser_ctx
{
157 struct filter_ast
*ast
;
158 struct cds_list_head allocated_strings
;
159 struct ir_op
*ir_root
;
160 struct lttng_filter_bytecode_alloc
*bytecode
;
161 struct lttng_filter_bytecode_alloc
*bytecode_reloc
;
164 struct filter_parser_ctx
*filter_parser_ctx_alloc(FILE *input
);
165 void filter_parser_ctx_free(struct filter_parser_ctx
*parser_ctx
);
166 int filter_parser_ctx_append_ast(struct filter_parser_ctx
*parser_ctx
);
169 struct filter_ast
*filter_parser_get_ast(struct filter_parser_ctx
*parser_ctx
)
171 return parser_ctx
->ast
;
174 int filter_visitor_print_xml(struct filter_parser_ctx
*ctx
, FILE *stream
,
176 int filter_visitor_ir_generate(struct filter_parser_ctx
*ctx
);
177 void filter_ir_free(struct filter_parser_ctx
*ctx
);
178 int filter_visitor_bytecode_generate(struct filter_parser_ctx
*ctx
);
179 void filter_bytecode_free(struct filter_parser_ctx
*ctx
);
180 int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx
*ctx
);
181 int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx
*ctx
);
182 int filter_visitor_ir_validate_string(struct filter_parser_ctx
*ctx
);
183 int filter_visitor_ir_normalize_glob_patterns(struct filter_parser_ctx
*ctx
);
184 int filter_visitor_ir_validate_globbing(struct filter_parser_ctx
*ctx
);
186 #endif /* _FILTER_AST_H */