Filter: add floating point support
[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
25#include <urcu/list.h>
26#include <stdint.h>
27
28#define printf_debug(fmt, args...) \
29 do { \
30 if (filter_parser_debug) \
31 fprintf(stdout, "[debug] " fmt, ## args); \
32 } while (0)
33
34// the parameter name (of the reentrant 'yyparse' function)
35// data is a pointer to a 'SParserParam' structure
36//#define YYPARSE_PARAM parser_ctx
37
38// the argument for the 'yylex' function
39#define YYLEX_PARAM ((struct filter_parser_ctx *) parser_ctx)->scanner
40
41#ifndef YY_TYPEDEF_YY_SCANNER_T
42#define YY_TYPEDEF_YY_SCANNER_T
43typedef void* yyscan_t;
44#endif
45
46extern int filter_parser_debug;
47
48struct filter_node;
49struct filter_parser;
50
51enum node_type {
52 NODE_UNKNOWN = 0,
53 NODE_ROOT,
54
55 NODE_EXPRESSION,
56 NODE_OP,
57 NODE_UNARY_OP,
58
59 NR_NODE_TYPES,
60};
61
62enum op_type {
63 AST_OP_UNKNOWN = 0,
64 AST_OP_MUL,
65 AST_OP_DIV,
66 AST_OP_MOD,
67 AST_OP_PLUS,
68 AST_OP_MINUS,
69 AST_OP_RSHIFT,
70 AST_OP_LSHIFT,
71 AST_OP_AND,
72 AST_OP_OR,
73 AST_OP_BIN_AND,
74 AST_OP_BIN_OR,
75 AST_OP_BIN_XOR,
76
77 AST_OP_EQ,
78 AST_OP_NE,
79 AST_OP_GT,
80 AST_OP_LT,
81 AST_OP_GE,
82 AST_OP_LE,
83};
84
85enum unary_op_type {
86 AST_UNARY_UNKNOWN = 0,
87 AST_UNARY_PLUS,
88 AST_UNARY_MINUS,
89 AST_UNARY_NOT,
90};
91
92enum ast_link_type {
93 AST_LINK_UNKNOWN = 0,
94 AST_LINK_DOT,
95 AST_LINK_RARROW,
96};
97
98struct filter_node {
99 /*
100 * Parent node is only set on demand by specific visitor.
101 */
102 struct filter_node *parent;
103 struct cds_list_head gc;
104
105 enum node_type type;
106 union {
107 struct {
108 } unknown;
109 struct {
110 struct filter_node *child;
111 } root;
112 struct {
113 enum {
114 AST_EXP_UNKNOWN = 0,
115 AST_EXP_STRING,
116 AST_EXP_CONSTANT,
e90d8561 117 AST_EXP_FLOAT_CONSTANT,
953192ba
MD
118 AST_EXP_IDENTIFIER,
119 AST_EXP_NESTED,
120 } type;
121 enum ast_link_type post_op; /* reverse */
122 enum ast_link_type pre_op; /* forward */
123 union {
124 char *string;
125 uint64_t constant;
e90d8561 126 double float_constant;
953192ba
MD
127 char *identifier;
128 /*
129 * child can be nested.
130 */
131 struct filter_node *child;
132 } u;
133 /* linked dot/arrow chain */
134 struct filter_node *prev;
135 struct filter_node *next;
136 } expression;
137 struct {
138 enum op_type type;
139 struct filter_node *lchild;
140 struct filter_node *rchild;
141 } op;
142 struct {
143 enum unary_op_type type;
144 struct filter_node *child;
145 } unary_op;
146 } u;
147};
148
149struct filter_ast {
150 struct filter_node root;
151 struct cds_list_head allocated_nodes;
152};
153
154const char *node_type(struct filter_node *node);
155
156struct ir_op;
953192ba
MD
157
158struct filter_parser_ctx {
159 yyscan_t scanner;
160 struct filter_ast *ast;
161 struct cds_list_head allocated_strings;
162 struct ir_op *ir_root;
53a80697
MD
163 struct lttng_filter_bytecode_alloc *bytecode;
164 struct lttng_filter_bytecode_alloc *bytecode_reloc;
953192ba
MD
165};
166
167struct filter_parser_ctx *filter_parser_ctx_alloc(FILE *input);
168void filter_parser_ctx_free(struct filter_parser_ctx *parser_ctx);
169int filter_parser_ctx_append_ast(struct filter_parser_ctx *parser_ctx);
170
171static inline
172struct filter_ast *filter_parser_get_ast(struct filter_parser_ctx *parser_ctx)
173{
174 return parser_ctx->ast;
175}
176
177int filter_visitor_set_parent(struct filter_parser_ctx *ctx);
178int filter_visitor_print_xml(struct filter_parser_ctx *ctx, FILE *stream,
179 int indent);
180int filter_visitor_ir_generate(struct filter_parser_ctx *ctx);
181void filter_ir_free(struct filter_parser_ctx *ctx);
182int filter_visitor_bytecode_generate(struct filter_parser_ctx *ctx);
183void filter_bytecode_free(struct filter_parser_ctx *ctx);
184int filter_visitor_ir_check_binary_op_nesting(struct filter_parser_ctx *ctx);
185int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx *ctx);
186
187#endif /* _FILTER_AST_H */
This page took 0.02913 seconds and 4 git commands to generate.