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 #define printf_debug(fmt, args...) \
25 if (filter_parser_debug) \
26 fprintf(stdout, "[debug] " fmt, ## args); \
29 // the parameter name (of the reentrant 'yyparse' function)
30 // data is a pointer to a 'SParserParam' structure
31 //#define YYPARSE_PARAM parser_ctx
33 #ifndef YY_TYPEDEF_YY_SCANNER_T
34 #define YY_TYPEDEF_YY_SCANNER_T
35 typedef void* yyscan_t
;
38 extern int filter_parser_debug
;
78 AST_UNARY_UNKNOWN
= 0,
96 AST_EXP_FLOAT_CONSTANT
,
98 AST_EXP_GLOBAL_IDENTIFIER
,
104 * Parent node is only set on demand by specific visitor.
106 struct filter_node
*parent
;
107 struct cds_list_head gc
;
112 /* Avoid -Wextern-c-compat warning with clang++. */
116 struct filter_node
*child
;
119 enum ast_expt_type type
;
120 enum ast_link_type post_op
; /* reverse */
121 enum ast_link_type pre_op
; /* forward */
125 double float_constant
;
126 const char *identifier
;
128 * child can be nested.
130 struct filter_node
*child
;
132 /* prev: backward dot/arrow chain (postfix expression) */
133 struct filter_node
*prev
;
134 /* next: forward dot/arrow chain, generated by a visitor. */
135 struct filter_node
*next
;
136 /* next_bracket: linked bracket chain (prefix expression) */
137 struct filter_node
*next_bracket
;
141 struct filter_node
*lchild
;
142 struct filter_node
*rchild
;
145 enum unary_op_type type
;
146 struct filter_node
*child
;
152 struct filter_node root
;
153 struct cds_list_head allocated_nodes
;
156 const char *node_type(struct filter_node
*node
);
160 struct filter_parser_ctx
{
162 struct filter_ast
*ast
;
163 struct cds_list_head allocated_strings
;
164 struct ir_op
*ir_root
;
165 struct lttng_bytecode_alloc
*bytecode
;
166 struct lttng_bytecode_alloc
*bytecode_reloc
;
169 struct filter_parser_ctx
*filter_parser_ctx_alloc(FILE *input
);
170 void filter_parser_ctx_free(struct filter_parser_ctx
*parser_ctx
);
171 int filter_parser_ctx_append_ast(struct filter_parser_ctx
*parser_ctx
);
172 int filter_parser_ctx_create_from_filter_expression(
173 const char *filter_expression
, struct filter_parser_ctx
**ctxp
);
176 struct filter_ast
*filter_parser_get_ast(struct filter_parser_ctx
*parser_ctx
)
178 return parser_ctx
->ast
;
181 int filter_visitor_print_xml(struct filter_parser_ctx
*ctx
, FILE *stream
,
183 int filter_visitor_ir_generate(struct filter_parser_ctx
*ctx
);
184 void filter_ir_free(struct filter_parser_ctx
*ctx
);
185 int filter_visitor_bytecode_generate(struct filter_parser_ctx
*ctx
);
186 void filter_bytecode_free(struct filter_parser_ctx
*ctx
);
187 int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx
*ctx
);
188 int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx
*ctx
);
189 int filter_visitor_ir_validate_string(struct filter_parser_ctx
*ctx
);
190 int filter_visitor_ir_normalize_glob_patterns(struct filter_parser_ctx
*ctx
);
191 int filter_visitor_ir_validate_globbing(struct filter_parser_ctx
*ctx
);
193 #endif /* _FILTER_AST_H */