Cleanup: symbols in parser protected -> hidden
[lttng-tools.git] / src / lib / lttng-ctl / 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 *
9 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License, version 2.1 only,
13 * as published by the Free Software Foundation.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
95b9bd90
MD
25/*
26 * Note: filter-ast.h should be included before filter-parser.h.
27 */
28
953192ba
MD
29#include <urcu/list.h>
30#include <stdint.h>
31
32#define printf_debug(fmt, args...) \
33 do { \
34 if (filter_parser_debug) \
35 fprintf(stdout, "[debug] " fmt, ## args); \
36 } while (0)
37
af71d06b
MD
38// the parameter name (of the reentrant 'yyparse' function)
39// data is a pointer to a 'SParserParam' structure
40//#define YYPARSE_PARAM parser_ctx
41
42// the argument for the 'yylex' function
43#define YYLEX_PARAM ((struct filter_parser_ctx *) parser_ctx)->scanner
44
953192ba
MD
45#ifndef YY_TYPEDEF_YY_SCANNER_T
46#define YY_TYPEDEF_YY_SCANNER_T
47typedef void* yyscan_t;
48#endif
49
50extern int filter_parser_debug;
51
52struct filter_node;
53struct filter_parser;
54
55enum node_type {
56 NODE_UNKNOWN = 0,
57 NODE_ROOT,
58
59 NODE_EXPRESSION,
60 NODE_OP,
61 NODE_UNARY_OP,
62
63 NR_NODE_TYPES,
64};
65
66enum op_type {
67 AST_OP_UNKNOWN = 0,
68 AST_OP_MUL,
69 AST_OP_DIV,
70 AST_OP_MOD,
71 AST_OP_PLUS,
72 AST_OP_MINUS,
73 AST_OP_RSHIFT,
74 AST_OP_LSHIFT,
75 AST_OP_AND,
76 AST_OP_OR,
77 AST_OP_BIN_AND,
78 AST_OP_BIN_OR,
79 AST_OP_BIN_XOR,
80
81 AST_OP_EQ,
82 AST_OP_NE,
83 AST_OP_GT,
84 AST_OP_LT,
85 AST_OP_GE,
86 AST_OP_LE,
87};
88
89enum unary_op_type {
90 AST_UNARY_UNKNOWN = 0,
91 AST_UNARY_PLUS,
92 AST_UNARY_MINUS,
93 AST_UNARY_NOT,
94};
95
96enum ast_link_type {
97 AST_LINK_UNKNOWN = 0,
98 AST_LINK_DOT,
99 AST_LINK_RARROW,
100};
101
102struct filter_node {
103 /*
104 * Parent node is only set on demand by specific visitor.
105 */
106 struct filter_node *parent;
107 struct cds_list_head gc;
108
109 enum node_type type;
110 union {
111 struct {
112 } unknown;
113 struct {
114 struct filter_node *child;
115 } root;
116 struct {
117 enum {
118 AST_EXP_UNKNOWN = 0,
119 AST_EXP_STRING,
120 AST_EXP_CONSTANT,
e90d8561 121 AST_EXP_FLOAT_CONSTANT,
953192ba
MD
122 AST_EXP_IDENTIFIER,
123 AST_EXP_NESTED,
124 } type;
125 enum ast_link_type post_op; /* reverse */
126 enum ast_link_type pre_op; /* forward */
127 union {
128 char *string;
129 uint64_t constant;
e90d8561 130 double float_constant;
953192ba
MD
131 char *identifier;
132 /*
133 * child can be nested.
134 */
135 struct filter_node *child;
136 } u;
137 /* linked dot/arrow chain */
138 struct filter_node *prev;
139 struct filter_node *next;
140 } expression;
141 struct {
142 enum op_type type;
143 struct filter_node *lchild;
144 struct filter_node *rchild;
145 } op;
146 struct {
147 enum unary_op_type type;
148 struct filter_node *child;
149 } unary_op;
150 } u;
151};
152
153struct filter_ast {
154 struct filter_node root;
155 struct cds_list_head allocated_nodes;
156};
157
158const char *node_type(struct filter_node *node);
159
160struct ir_op;
953192ba
MD
161
162struct filter_parser_ctx {
163 yyscan_t scanner;
164 struct filter_ast *ast;
165 struct cds_list_head allocated_strings;
166 struct ir_op *ir_root;
53a80697
MD
167 struct lttng_filter_bytecode_alloc *bytecode;
168 struct lttng_filter_bytecode_alloc *bytecode_reloc;
953192ba
MD
169};
170
171struct filter_parser_ctx *filter_parser_ctx_alloc(FILE *input);
172void filter_parser_ctx_free(struct filter_parser_ctx *parser_ctx);
173int filter_parser_ctx_append_ast(struct filter_parser_ctx *parser_ctx);
174
175static inline
176struct filter_ast *filter_parser_get_ast(struct filter_parser_ctx *parser_ctx)
177{
178 return parser_ctx->ast;
179}
180
181int filter_visitor_set_parent(struct filter_parser_ctx *ctx);
182int filter_visitor_print_xml(struct filter_parser_ctx *ctx, FILE *stream,
183 int indent);
184int filter_visitor_ir_generate(struct filter_parser_ctx *ctx);
185void filter_ir_free(struct filter_parser_ctx *ctx);
186int filter_visitor_bytecode_generate(struct filter_parser_ctx *ctx);
187void filter_bytecode_free(struct filter_parser_ctx *ctx);
188int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx *ctx);
189int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx *ctx);
190
191#endif /* _FILTER_AST_H */
This page took 0.029755 seconds and 4 git commands to generate.