Move to kernel style SPDX license identifiers
[lttng-tools.git] / src / lib / lttng-ctl / filter / filter-ast.h
CommitLineData
953192ba
MD
1#ifndef _FILTER_AST_H
2#define _FILTER_AST_H
3
4/*
5 * filter-ast.h
6 *
7 * LTTng filter AST
8 *
ab5be9fa 9 * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
953192ba 10 *
ab5be9fa 11 * SPDX-License-Identifier: LGPL-2.1-only
953192ba 12 *
953192ba
MD
13 */
14
95b9bd90
MD
15/*
16 * Note: filter-ast.h should be included before filter-parser.h.
17 */
18
953192ba
MD
19#include <urcu/list.h>
20#include <stdint.h>
21
22#define printf_debug(fmt, args...) \
23 do { \
24 if (filter_parser_debug) \
25 fprintf(stdout, "[debug] " fmt, ## args); \
26 } while (0)
27
af71d06b
MD
28// the parameter name (of the reentrant 'yyparse' function)
29// data is a pointer to a 'SParserParam' structure
30//#define YYPARSE_PARAM parser_ctx
31
953192ba
MD
32#ifndef YY_TYPEDEF_YY_SCANNER_T
33#define YY_TYPEDEF_YY_SCANNER_T
34typedef void* yyscan_t;
35#endif
36
37extern int filter_parser_debug;
38
39struct filter_node;
40struct filter_parser;
41
42enum node_type {
43 NODE_UNKNOWN = 0,
44 NODE_ROOT,
45
46 NODE_EXPRESSION,
47 NODE_OP,
48 NODE_UNARY_OP,
49
50 NR_NODE_TYPES,
51};
52
53enum op_type {
54 AST_OP_UNKNOWN = 0,
55 AST_OP_MUL,
56 AST_OP_DIV,
57 AST_OP_MOD,
58 AST_OP_PLUS,
59 AST_OP_MINUS,
116d3c01
MD
60 AST_OP_BIT_RSHIFT,
61 AST_OP_BIT_LSHIFT,
953192ba
MD
62 AST_OP_AND,
63 AST_OP_OR,
bff988fa
MD
64 AST_OP_BIT_AND,
65 AST_OP_BIT_OR,
66 AST_OP_BIT_XOR,
953192ba
MD
67
68 AST_OP_EQ,
69 AST_OP_NE,
70 AST_OP_GT,
71 AST_OP_LT,
72 AST_OP_GE,
73 AST_OP_LE,
74};
75
76enum unary_op_type {
77 AST_UNARY_UNKNOWN = 0,
78 AST_UNARY_PLUS,
79 AST_UNARY_MINUS,
80 AST_UNARY_NOT,
bff988fa 81 AST_UNARY_BIT_NOT,
953192ba
MD
82};
83
84enum ast_link_type {
85 AST_LINK_UNKNOWN = 0,
86 AST_LINK_DOT,
87 AST_LINK_RARROW,
661dfdd1 88 AST_LINK_BRACKET,
953192ba
MD
89};
90
91struct filter_node {
92 /*
93 * Parent node is only set on demand by specific visitor.
94 */
95 struct filter_node *parent;
96 struct cds_list_head gc;
97
98 enum node_type type;
99 union {
100 struct {
101 } unknown;
102 struct {
103 struct filter_node *child;
104 } root;
105 struct {
106 enum {
107 AST_EXP_UNKNOWN = 0,
108 AST_EXP_STRING,
109 AST_EXP_CONSTANT,
e90d8561 110 AST_EXP_FLOAT_CONSTANT,
953192ba 111 AST_EXP_IDENTIFIER,
586dc72f 112 AST_EXP_GLOBAL_IDENTIFIER,
953192ba
MD
113 AST_EXP_NESTED,
114 } type;
115 enum ast_link_type post_op; /* reverse */
116 enum ast_link_type pre_op; /* forward */
117 union {
118 char *string;
119 uint64_t constant;
e90d8561 120 double float_constant;
953192ba
MD
121 char *identifier;
122 /*
123 * child can be nested.
124 */
125 struct filter_node *child;
126 } u;
bff988fa 127 /* prev: backward dot/arrow chain (postfix expression) */
953192ba 128 struct filter_node *prev;
bff988fa 129 /* next: forward dot/arrow chain, generated by a visitor. */
953192ba 130 struct filter_node *next;
bff988fa
MD
131 /* next_bracket: linked bracket chain (prefix expression) */
132 struct filter_node *next_bracket;
953192ba
MD
133 } expression;
134 struct {
135 enum op_type type;
136 struct filter_node *lchild;
137 struct filter_node *rchild;
138 } op;
139 struct {
140 enum unary_op_type type;
141 struct filter_node *child;
142 } unary_op;
143 } u;
144};
145
146struct filter_ast {
147 struct filter_node root;
148 struct cds_list_head allocated_nodes;
149};
150
151const char *node_type(struct filter_node *node);
152
153struct ir_op;
953192ba
MD
154
155struct filter_parser_ctx {
156 yyscan_t scanner;
157 struct filter_ast *ast;
158 struct cds_list_head allocated_strings;
159 struct ir_op *ir_root;
53a80697
MD
160 struct lttng_filter_bytecode_alloc *bytecode;
161 struct lttng_filter_bytecode_alloc *bytecode_reloc;
953192ba
MD
162};
163
164struct filter_parser_ctx *filter_parser_ctx_alloc(FILE *input);
165void filter_parser_ctx_free(struct filter_parser_ctx *parser_ctx);
166int filter_parser_ctx_append_ast(struct filter_parser_ctx *parser_ctx);
167
168static inline
169struct filter_ast *filter_parser_get_ast(struct filter_parser_ctx *parser_ctx)
170{
171 return parser_ctx->ast;
172}
173
953192ba
MD
174int filter_visitor_print_xml(struct filter_parser_ctx *ctx, FILE *stream,
175 int indent);
176int filter_visitor_ir_generate(struct filter_parser_ctx *ctx);
177void filter_ir_free(struct filter_parser_ctx *ctx);
178int filter_visitor_bytecode_generate(struct filter_parser_ctx *ctx);
179void filter_bytecode_free(struct filter_parser_ctx *ctx);
180int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx *ctx);
181int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx *ctx);
dcd5daf2 182int filter_visitor_ir_validate_string(struct filter_parser_ctx *ctx);
9f449915
PP
183int filter_visitor_ir_normalize_glob_patterns(struct filter_parser_ctx *ctx);
184int filter_visitor_ir_validate_globbing(struct filter_parser_ctx *ctx);
953192ba
MD
185
186#endif /* _FILTER_AST_H */
This page took 0.070349 seconds and 5 git commands to generate.