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,
100 AST_EXP_FLOAT_CONSTANT
,
102 AST_EXP_GLOBAL_IDENTIFIER
,
108 * Parent node is only set on demand by specific visitor.
110 struct filter_node
*parent
;
111 struct cds_list_head gc
;
116 /* Avoid -Wextern-c-compat warning with clang++. */
120 struct filter_node
*child
;
123 enum ast_expt_type type
;
124 enum ast_link_type post_op
; /* reverse */
125 enum ast_link_type pre_op
; /* forward */
129 double float_constant
;
130 const char *identifier
;
132 * child can be nested.
134 struct filter_node
*child
;
136 /* prev: backward dot/arrow chain (postfix expression) */
137 struct filter_node
*prev
;
138 /* next: forward dot/arrow chain, generated by a visitor. */
139 struct filter_node
*next
;
140 /* next_bracket: linked bracket chain (prefix expression) */
141 struct filter_node
*next_bracket
;
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_bytecode_alloc
*bytecode
;
170 struct lttng_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
);
176 int filter_parser_ctx_create_from_filter_expression(
177 const char *filter_expression
, struct filter_parser_ctx
**ctxp
);
180 struct filter_ast
*filter_parser_get_ast(struct filter_parser_ctx
*parser_ctx
)
182 return parser_ctx
->ast
;
185 int filter_visitor_print_xml(struct filter_parser_ctx
*ctx
, FILE *stream
,
187 int filter_visitor_ir_generate(struct filter_parser_ctx
*ctx
);
188 void filter_ir_free(struct filter_parser_ctx
*ctx
);
189 int filter_visitor_bytecode_generate(struct filter_parser_ctx
*ctx
);
190 void filter_bytecode_free(struct filter_parser_ctx
*ctx
);
191 int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx
*ctx
);
192 int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx
*ctx
);
193 int filter_visitor_ir_validate_string(struct filter_parser_ctx
*ctx
);
194 int filter_visitor_ir_normalize_glob_patterns(struct filter_parser_ctx
*ctx
);
195 int filter_visitor_ir_validate_globbing(struct filter_parser_ctx
*ctx
);
197 #if defined(__cplusplus)
201 #endif /* _FILTER_AST_H */