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