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>
23 #if defined(__cplusplus)
27 #define printf_debug(fmt, args...) \
29 if (filter_parser_debug) \
30 fprintf(stdout, "[debug] " fmt, ## args); \
33 // the parameter name (of the reentrant 'yyparse' function)
34 // data is a pointer to a 'SParserParam' structure
35 //#define YYPARSE_PARAM parser_ctx
37 #ifndef YY_TYPEDEF_YY_SCANNER_T
38 #define YY_TYPEDEF_YY_SCANNER_T
39 typedef void* yyscan_t
;
42 extern int filter_parser_debug
;
82 AST_UNARY_UNKNOWN
= 0,
98 * Parent node is only set on demand by specific visitor.
100 struct filter_node
*parent
;
101 struct cds_list_head gc
;
106 /* Avoid -Wextern-c-compat warning with clang++. */
110 struct filter_node
*child
;
117 AST_EXP_FLOAT_CONSTANT
,
119 AST_EXP_GLOBAL_IDENTIFIER
,
122 enum ast_link_type post_op
; /* reverse */
123 enum ast_link_type pre_op
; /* forward */
127 double float_constant
;
128 const char *identifier
;
130 * child can be nested.
132 struct filter_node
*child
;
134 /* prev: backward dot/arrow chain (postfix expression) */
135 struct filter_node
*prev
;
136 /* next: forward dot/arrow chain, generated by a visitor. */
137 struct filter_node
*next
;
138 /* next_bracket: linked bracket chain (prefix expression) */
139 struct filter_node
*next_bracket
;
143 struct filter_node
*lchild
;
144 struct filter_node
*rchild
;
147 enum unary_op_type type
;
148 struct filter_node
*child
;
154 struct filter_node root
;
155 struct cds_list_head allocated_nodes
;
158 const char *node_type(struct filter_node
*node
);
162 struct filter_parser_ctx
{
164 struct filter_ast
*ast
;
165 struct cds_list_head allocated_strings
;
166 struct ir_op
*ir_root
;
167 struct lttng_bytecode_alloc
*bytecode
;
168 struct lttng_bytecode_alloc
*bytecode_reloc
;
171 struct filter_parser_ctx
*filter_parser_ctx_alloc(FILE *input
);
172 void filter_parser_ctx_free(struct filter_parser_ctx
*parser_ctx
);
173 int filter_parser_ctx_append_ast(struct filter_parser_ctx
*parser_ctx
);
174 int filter_parser_ctx_create_from_filter_expression(
175 const char *filter_expression
, struct filter_parser_ctx
**ctxp
);
178 struct filter_ast
*filter_parser_get_ast(struct filter_parser_ctx
*parser_ctx
)
180 return parser_ctx
->ast
;
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 #if defined(__cplusplus)
199 #endif /* _FILTER_AST_H */