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 | 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 | /* | |
99 | * Children nodes are ctf_expression, typedef, | |
100 | * typealias and type_specifier_list. | |
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 | /* | |
112 | * Children nodes are ctf_expression, typedef, | |
113 | * typealias and type_specifier_list. | |
114 | */ | |
115 | struct bt_list_head declaration_list; | |
116 | } event; | |
117 | struct { | |
118 | /* | |
119 | * Children nodes are ctf_expression, typedef, | |
120 | * typealias and type_specifier_list. | |
121 | */ | |
122 | struct bt_list_head declaration_list; | |
123 | } stream; | |
124 | struct { | |
125 | /* | |
126 | * Children nodes are ctf_expression, typedef, | |
127 | * typealias and type_specifier_list. | |
128 | */ | |
129 | struct bt_list_head declaration_list; | |
130 | } env; | |
131 | struct { | |
132 | /* | |
133 | * Children nodes are ctf_expression, typedef, | |
134 | * typealias and type_specifier_list. | |
135 | */ | |
136 | struct bt_list_head declaration_list; | |
137 | } trace; | |
138 | struct { | |
139 | /* | |
140 | * Children nodes are ctf_expression, typedef, | |
141 | * typealias and type_specifier_list. | |
142 | */ | |
143 | struct bt_list_head declaration_list; | |
144 | } clock; | |
145 | struct { | |
146 | /* | |
147 | * Children nodes are ctf_expression, typedef, | |
148 | * typealias and type_specifier_list. | |
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 { | |
182 | struct ctf_node *type_specifier_list; | |
183 | struct bt_list_head type_declarators; | |
184 | } _typedef; | |
185 | /* new type is "alias", existing type "target" */ | |
186 | struct { | |
187 | struct ctf_node *type_specifier_list; | |
188 | struct bt_list_head type_declarators; | |
189 | } typealias_target; | |
190 | struct { | |
191 | struct ctf_node *type_specifier_list; | |
192 | struct bt_list_head type_declarators; | |
193 | } typealias_alias; | |
194 | struct { | |
195 | struct ctf_node *target; | |
196 | struct ctf_node *alias; | |
197 | } typealias; | |
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; | |
225 | } type_specifier; | |
226 | struct { | |
227 | /* list of type_specifier */ | |
228 | struct bt_list_head head; | |
229 | } type_specifier_list; | |
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 */ | |
244 | struct ctf_node *type_declarator; | |
245 | /* | |
246 | * unary expression (value) or | |
247 | * type_specifier_list. | |
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; | |
255 | } type_declarator; | |
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 | |
280 | * type_specifier_list. | |
281 | */ | |
282 | struct ctf_node *container_type; | |
283 | struct bt_list_head enumerator_list; | |
284 | int has_body; | |
285 | } _enum; | |
286 | struct { | |
287 | struct ctf_node *type_specifier_list; | |
288 | struct bt_list_head type_declarators; | |
289 | } struct_or_variant_declaration; | |
290 | struct { | |
291 | char *name; | |
292 | char *choice; | |
293 | /* list of typedef, typealias and declarations */ | |
294 | struct bt_list_head declaration_list; | |
295 | int has_body; | |
296 | } variant; | |
297 | struct { | |
298 | char *name; | |
299 | /* list of typedef, typealias and declarations */ | |
300 | struct bt_list_head declaration_list; | |
301 | int has_body; | |
302 | struct bt_list_head min_align; /* align() attribute */ | |
303 | } _struct; | |
304 | } u; | |
305 | }; | |
306 | ||
307 | struct ctf_ast { | |
308 | struct ctf_node root; | |
309 | }; | |
310 | ||
311 | const char *node_type(struct ctf_node *node); | |
312 | ||
1e649dff | 313 | BT_HIDDEN |
55314f2a | 314 | struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create( |
a2a54545 PP |
315 | const struct ctf_metadata_decoder_config *config, |
316 | const char *name); | |
1e649dff PP |
317 | |
318 | void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor); | |
e98a2d6e PP |
319 | |
320 | BT_HIDDEN | |
44c440bc PP |
321 | struct bt_trace *ctf_visitor_generate_ir_get_ir_trace( |
322 | struct ctf_visitor_generate_ir *visitor); | |
323 | ||
324 | BT_HIDDEN | |
325 | struct ctf_trace_class *ctf_visitor_generate_ir_borrow_ctf_trace_class( | |
1e649dff | 326 | struct ctf_visitor_generate_ir *visitor); |
e98a2d6e PP |
327 | |
328 | BT_HIDDEN | |
1e649dff PP |
329 | int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, |
330 | struct ctf_node *node); | |
e98a2d6e PP |
331 | |
332 | BT_HIDDEN | |
55314f2a | 333 | int ctf_visitor_semantic_check(int depth, struct ctf_node *node); |
e98a2d6e PP |
334 | |
335 | BT_HIDDEN | |
55314f2a | 336 | int ctf_visitor_parent_links(int depth, struct ctf_node *node); |
e98a2d6e PP |
337 | |
338 | #endif /* _CTF_AST_H */ |