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,
94 * Parent node is only set on demand by specific visitor.
96 struct filter_node
*parent
;
97 struct cds_list_head gc
;
104 struct filter_node
*child
;
111 AST_EXP_FLOAT_CONSTANT
,
113 AST_EXP_GLOBAL_IDENTIFIER
,
116 enum ast_link_type post_op
; /* reverse */
117 enum ast_link_type pre_op
; /* forward */
121 double float_constant
;
122 const char *identifier
;
124 * child can be nested.
126 struct filter_node
*child
;
128 /* prev: backward dot/arrow chain (postfix expression) */
129 struct filter_node
*prev
;
130 /* next: forward dot/arrow chain, generated by a visitor. */
131 struct filter_node
*next
;
132 /* next_bracket: linked bracket chain (prefix expression) */
133 struct filter_node
*next_bracket
;
137 struct filter_node
*lchild
;
138 struct filter_node
*rchild
;
141 enum unary_op_type type
;
142 struct filter_node
*child
;
148 struct filter_node root
;
149 struct cds_list_head allocated_nodes
;
152 const char *node_type(struct filter_node
*node
);
156 struct filter_parser_ctx
{
158 struct filter_ast
*ast
;
159 struct cds_list_head allocated_strings
;
160 struct ir_op
*ir_root
;
161 struct lttng_bytecode_alloc
*bytecode
;
162 struct lttng_bytecode_alloc
*bytecode_reloc
;
165 struct filter_parser_ctx
*filter_parser_ctx_alloc(FILE *input
);
166 void filter_parser_ctx_free(struct filter_parser_ctx
*parser_ctx
);
167 int filter_parser_ctx_append_ast(struct filter_parser_ctx
*parser_ctx
);
168 int filter_parser_ctx_create_from_filter_expression(
169 const char *filter_expression
, struct filter_parser_ctx
**ctxp
);
172 struct filter_ast
*filter_parser_get_ast(struct filter_parser_ctx
*parser_ctx
)
174 return parser_ctx
->ast
;
177 int filter_visitor_print_xml(struct filter_parser_ctx
*ctx
, FILE *stream
,
179 int filter_visitor_ir_generate(struct filter_parser_ctx
*ctx
);
180 void filter_ir_free(struct filter_parser_ctx
*ctx
);
181 int filter_visitor_bytecode_generate(struct filter_parser_ctx
*ctx
);
182 void filter_bytecode_free(struct filter_parser_ctx
*ctx
);
183 int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx
*ctx
);
184 int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx
*ctx
);
185 int filter_visitor_ir_validate_string(struct filter_parser_ctx
*ctx
);
186 int filter_visitor_ir_normalize_glob_patterns(struct filter_parser_ctx
*ctx
);
187 int filter_visitor_ir_validate_globbing(struct filter_parser_ctx
*ctx
);
189 #endif /* _FILTER_AST_H */