Commit | Line | Data |
---|---|---|
e98a2d6e PP |
1 | #ifndef _CTF_AST_H |
2 | #define _CTF_AST_H | |
3 | ||
4 | /* | |
5 | * ctf-ast.h | |
6 | * | |
7 | * Copyright 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | * | |
9 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
10 | * of this software and associated documentation files (the "Software"), to deal | |
11 | * in the Software without restriction, including without limitation the rights | |
12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
13 | * copies of the Software, and to permit persons to whom the Software is | |
14 | * furnished to do so, subject to the following conditions: | |
15 | * | |
16 | * The above copyright notice and this permission notice shall be included in | |
17 | * all copies or substantial portions of the Software. | |
18 | */ | |
19 | ||
20 | #include <stdint.h> | |
21 | #include <stdio.h> | |
22 | #include <glib.h> | |
3d9990ac | 23 | #include <babeltrace/list-internal.h> |
9d408fca | 24 | #include <babeltrace/babeltrace.h> |
1e649dff | 25 | #include <babeltrace/babeltrace-internal.h> |
e98a2d6e | 26 | |
a2a54545 PP |
27 | #include "decoder.h" |
28 | ||
e98a2d6e PP |
29 | // the parameter name (of the reentrant 'yyparse' function) |
30 | // data is a pointer to a 'SParserParam' structure | |
31 | //#define YYPARSE_PARAM scanner | |
32 | ||
33 | struct ctf_node; | |
34 | struct ctf_parser; | |
1e649dff PP |
35 | struct ctf_visitor_generate_ir; |
36 | ||
37 | #define EINCOMPLETE 1000 | |
e98a2d6e PP |
38 | |
39 | #define FOREACH_CTF_NODES(F) \ | |
40 | F(NODE_UNKNOWN) \ | |
41 | F(NODE_ROOT) \ | |
42 | F(NODE_ERROR) \ | |
43 | F(NODE_EVENT) \ | |
44 | F(NODE_STREAM) \ | |
45 | F(NODE_ENV) \ | |
46 | F(NODE_TRACE) \ | |
47 | F(NODE_CLOCK) \ | |
48 | F(NODE_CALLSITE) \ | |
49 | F(NODE_CTF_EXPRESSION) \ | |
50 | F(NODE_UNARY_EXPRESSION) \ | |
51 | F(NODE_TYPEDEF) \ | |
52 | F(NODE_TYPEALIAS_TARGET) \ | |
53 | F(NODE_TYPEALIAS_ALIAS) \ | |
54 | F(NODE_TYPEALIAS) \ | |
55 | F(NODE_TYPE_SPECIFIER) \ | |
56 | F(NODE_TYPE_SPECIFIER_LIST) \ | |
57 | F(NODE_POINTER) \ | |
58 | F(NODE_TYPE_DECLARATOR) \ | |
59 | F(NODE_FLOATING_POINT) \ | |
60 | F(NODE_INTEGER) \ | |
61 | F(NODE_STRING) \ | |
62 | F(NODE_ENUMERATOR) \ | |
63 | F(NODE_ENUM) \ | |
64 | F(NODE_STRUCT_OR_VARIANT_DECLARATION) \ | |
65 | F(NODE_VARIANT) \ | |
66 | F(NODE_STRUCT) | |
67 | ||
68 | enum node_type { | |
69 | #define ENTRY(S) S, | |
70 | FOREACH_CTF_NODES(ENTRY) | |
71 | #undef ENTRY | |
72 | NR_NODE_TYPES, | |
73 | }; | |
74 | ||
75 | struct ctf_node { | |
76 | /* | |
77 | * Parent node is only set on demand by specific visitor. | |
78 | */ | |
79 | struct ctf_node *parent; | |
80 | struct bt_list_head siblings; | |
81 | struct bt_list_head tmp_head; | |
82 | unsigned int lineno; | |
83 | /* | |
84 | * We mark nodes visited in the generate-ir phase (last | |
85 | * phase). We only mark the 1-depth level nodes as visited | |
86 | * (never the root node, and not their sub-nodes). This allows | |
87 | * skipping already visited nodes when doing incremental | |
88 | * metadata append. | |
89 | */ | |
90 | int visited; | |
91 | ||
92 | enum node_type type; | |
93 | union { | |
94 | struct { | |
95 | } unknown; | |
96 | struct { | |
97 | /* | |
98 | * Children nodes are ctf_expression, typedef, | |
99 | * typealias and type_specifier_list. | |
100 | */ | |
101 | struct bt_list_head declaration_list; | |
102 | struct bt_list_head trace; | |
103 | struct bt_list_head env; | |
104 | struct bt_list_head stream; | |
105 | struct bt_list_head event; | |
106 | struct bt_list_head clock; | |
107 | struct bt_list_head callsite; | |
108 | } root; | |
109 | struct { | |
110 | /* | |
111 | * Children nodes are ctf_expression, typedef, | |
112 | * typealias and type_specifier_list. | |
113 | */ | |
114 | struct bt_list_head declaration_list; | |
115 | } event; | |
116 | struct { | |
117 | /* | |
118 | * Children nodes are ctf_expression, typedef, | |
119 | * typealias and type_specifier_list. | |
120 | */ | |
121 | struct bt_list_head declaration_list; | |
122 | } stream; | |
123 | struct { | |
124 | /* | |
125 | * Children nodes are ctf_expression, typedef, | |
126 | * typealias and type_specifier_list. | |
127 | */ | |
128 | struct bt_list_head declaration_list; | |
129 | } env; | |
130 | struct { | |
131 | /* | |
132 | * Children nodes are ctf_expression, typedef, | |
133 | * typealias and type_specifier_list. | |
134 | */ | |
135 | struct bt_list_head declaration_list; | |
136 | } trace; | |
137 | struct { | |
138 | /* | |
139 | * Children nodes are ctf_expression, typedef, | |
140 | * typealias and type_specifier_list. | |
141 | */ | |
142 | struct bt_list_head declaration_list; | |
143 | } clock; | |
144 | struct { | |
145 | /* | |
146 | * Children nodes are ctf_expression, typedef, | |
147 | * typealias and type_specifier_list. | |
148 | */ | |
149 | struct bt_list_head declaration_list; | |
150 | } callsite; | |
151 | struct { | |
152 | struct bt_list_head left; /* Should be string */ | |
153 | struct bt_list_head right; /* Unary exp. or type */ | |
154 | } ctf_expression; | |
155 | struct { | |
156 | enum { | |
157 | UNARY_UNKNOWN = 0, | |
158 | UNARY_STRING, | |
159 | UNARY_SIGNED_CONSTANT, | |
160 | UNARY_UNSIGNED_CONSTANT, | |
161 | UNARY_SBRAC, | |
162 | } type; | |
163 | union { | |
164 | /* | |
165 | * string for identifier, id_type, keywords, | |
166 | * string literals and character constants. | |
167 | */ | |
168 | char *string; | |
169 | int64_t signed_constant; | |
170 | uint64_t unsigned_constant; | |
171 | struct ctf_node *sbrac_exp; | |
172 | } u; | |
173 | enum { | |
174 | UNARY_LINK_UNKNOWN = 0, | |
175 | UNARY_DOTLINK, | |
176 | UNARY_ARROWLINK, | |
177 | UNARY_DOTDOTDOT, | |
178 | } link; | |
179 | } unary_expression; | |
180 | struct { | |
181 | struct ctf_node *type_specifier_list; | |
182 | struct bt_list_head type_declarators; | |
183 | } _typedef; | |
184 | /* new type is "alias", existing type "target" */ | |
185 | struct { | |
186 | struct ctf_node *type_specifier_list; | |
187 | struct bt_list_head type_declarators; | |
188 | } typealias_target; | |
189 | struct { | |
190 | struct ctf_node *type_specifier_list; | |
191 | struct bt_list_head type_declarators; | |
192 | } typealias_alias; | |
193 | struct { | |
194 | struct ctf_node *target; | |
195 | struct ctf_node *alias; | |
196 | } typealias; | |
197 | struct { | |
198 | enum { | |
199 | TYPESPEC_UNKNOWN = 0, | |
200 | TYPESPEC_VOID, | |
201 | TYPESPEC_CHAR, | |
202 | TYPESPEC_SHORT, | |
203 | TYPESPEC_INT, | |
204 | TYPESPEC_LONG, | |
205 | TYPESPEC_FLOAT, | |
206 | TYPESPEC_DOUBLE, | |
207 | TYPESPEC_SIGNED, | |
208 | TYPESPEC_UNSIGNED, | |
209 | TYPESPEC_BOOL, | |
210 | TYPESPEC_COMPLEX, | |
211 | TYPESPEC_IMAGINARY, | |
212 | TYPESPEC_CONST, | |
213 | TYPESPEC_ID_TYPE, | |
214 | TYPESPEC_FLOATING_POINT, | |
215 | TYPESPEC_INTEGER, | |
216 | TYPESPEC_STRING, | |
217 | TYPESPEC_STRUCT, | |
218 | TYPESPEC_VARIANT, | |
219 | TYPESPEC_ENUM, | |
220 | } type; | |
221 | /* For struct, variant and enum */ | |
222 | struct ctf_node *node; | |
223 | const char *id_type; | |
224 | } type_specifier; | |
225 | struct { | |
226 | /* list of type_specifier */ | |
227 | struct bt_list_head head; | |
228 | } type_specifier_list; | |
229 | struct { | |
230 | unsigned int const_qualifier; | |
231 | } pointer; | |
232 | struct { | |
233 | struct bt_list_head pointers; | |
234 | enum { | |
235 | TYPEDEC_UNKNOWN = 0, | |
236 | TYPEDEC_ID, /* identifier */ | |
237 | TYPEDEC_NESTED, /* (), array or sequence */ | |
238 | } type; | |
239 | union { | |
240 | char *id; | |
241 | struct { | |
242 | /* typedec has no pointer list */ | |
243 | struct ctf_node *type_declarator; | |
244 | /* | |
245 | * unary expression (value) or | |
246 | * type_specifier_list. | |
247 | */ | |
248 | struct bt_list_head length; | |
249 | /* for abstract type declarator */ | |
250 | unsigned int abstract_array; | |
251 | } nested; | |
252 | } u; | |
253 | struct ctf_node *bitfield_len; | |
254 | } type_declarator; | |
255 | struct { | |
256 | /* Children nodes are ctf_expression. */ | |
257 | struct bt_list_head expressions; | |
258 | } floating_point; | |
259 | struct { | |
260 | /* Children nodes are ctf_expression. */ | |
261 | struct bt_list_head expressions; | |
262 | } integer; | |
263 | struct { | |
264 | /* Children nodes are ctf_expression. */ | |
265 | struct bt_list_head expressions; | |
266 | } string; | |
267 | struct { | |
268 | char *id; | |
269 | /* | |
270 | * Range list or single value node. Contains unary | |
271 | * expressions. | |
272 | */ | |
273 | struct bt_list_head values; | |
274 | } enumerator; | |
275 | struct { | |
276 | char *enum_id; | |
277 | /* | |
278 | * Either NULL, or points to unary expression or | |
279 | * type_specifier_list. | |
280 | */ | |
281 | struct ctf_node *container_type; | |
282 | struct bt_list_head enumerator_list; | |
283 | int has_body; | |
284 | } _enum; | |
285 | struct { | |
286 | struct ctf_node *type_specifier_list; | |
287 | struct bt_list_head type_declarators; | |
288 | } struct_or_variant_declaration; | |
289 | struct { | |
290 | char *name; | |
291 | char *choice; | |
292 | /* list of typedef, typealias and declarations */ | |
293 | struct bt_list_head declaration_list; | |
294 | int has_body; | |
295 | } variant; | |
296 | struct { | |
297 | char *name; | |
298 | /* list of typedef, typealias and declarations */ | |
299 | struct bt_list_head declaration_list; | |
300 | int has_body; | |
301 | struct bt_list_head min_align; /* align() attribute */ | |
302 | } _struct; | |
303 | } u; | |
304 | }; | |
305 | ||
306 | struct ctf_ast { | |
307 | struct ctf_node root; | |
308 | }; | |
309 | ||
310 | const char *node_type(struct ctf_node *node); | |
311 | ||
1e649dff | 312 | BT_HIDDEN |
55314f2a | 313 | struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create( |
a2a54545 PP |
314 | const struct ctf_metadata_decoder_config *config, |
315 | const char *name); | |
1e649dff PP |
316 | |
317 | void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor); | |
e98a2d6e PP |
318 | |
319 | BT_HIDDEN | |
50842bdc | 320 | struct bt_trace *ctf_visitor_generate_ir_get_trace( |
1e649dff | 321 | struct ctf_visitor_generate_ir *visitor); |
e98a2d6e PP |
322 | |
323 | BT_HIDDEN | |
1e649dff PP |
324 | int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, |
325 | struct ctf_node *node); | |
e98a2d6e PP |
326 | |
327 | BT_HIDDEN | |
55314f2a | 328 | int ctf_visitor_semantic_check(int depth, struct ctf_node *node); |
e98a2d6e PP |
329 | |
330 | BT_HIDDEN | |
55314f2a | 331 | int ctf_visitor_parent_links(int depth, struct ctf_node *node); |
e98a2d6e PP |
332 | |
333 | #endif /* _CTF_AST_H */ |