lib: add aliases for Babeltrace structure types
[babeltrace.git] / plugins / ctf / common / metadata / ast.h
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>
23 #include <babeltrace/list-internal.h>
24 #include <babeltrace/babeltrace.h>
25 #include <babeltrace/babeltrace-internal.h>
26
27 #include "decoder.h"
28 #include "ctf-meta.h"
29
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;
36 struct ctf_visitor_generate_ir;
37
38 #define EINCOMPLETE 1000
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, field_class_def,
100 * field_class_alias and field_class_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, field_class_def,
113 * field_class_alias and field_class_specifier_list.
114 */
115 struct bt_list_head declaration_list;
116 } event;
117 struct {
118 /*
119 * Children nodes are ctf_expression, field_class_def,
120 * field_class_alias and field_class_specifier_list.
121 */
122 struct bt_list_head declaration_list;
123 } stream;
124 struct {
125 /*
126 * Children nodes are ctf_expression, field_class_def,
127 * field_class_alias and field_class_specifier_list.
128 */
129 struct bt_list_head declaration_list;
130 } env;
131 struct {
132 /*
133 * Children nodes are ctf_expression, field_class_def,
134 * field_class_alias and field_class_specifier_list.
135 */
136 struct bt_list_head declaration_list;
137 } trace;
138 struct {
139 /*
140 * Children nodes are ctf_expression, field_class_def,
141 * field_class_alias and field_class_specifier_list.
142 */
143 struct bt_list_head declaration_list;
144 } clock;
145 struct {
146 /*
147 * Children nodes are ctf_expression, field_class_def,
148 * field_class_alias and field_class_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 *field_class_specifier_list;
183 struct bt_list_head field_class_declarators;
184 } field_class_def;
185 /* new type is "alias", existing type "target" */
186 struct {
187 struct ctf_node *field_class_specifier_list;
188 struct bt_list_head field_class_declarators;
189 } field_class_alias_target;
190 struct {
191 struct ctf_node *field_class_specifier_list;
192 struct bt_list_head field_class_declarators;
193 } field_class_alias_name;
194 struct {
195 struct ctf_node *target;
196 struct ctf_node *alias;
197 } field_class_alias;
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 } field_class_specifier;
226 struct {
227 /* list of field_class_specifier */
228 struct bt_list_head head;
229 } field_class_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 *field_class_declarator;
245 /*
246 * unary expression (value) or
247 * field_class_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 } field_class_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 * field_class_specifier_list.
281 */
282 struct ctf_node *container_field_class;
283 struct bt_list_head enumerator_list;
284 int has_body;
285 } _enum;
286 struct {
287 struct ctf_node *field_class_specifier_list;
288 struct bt_list_head field_class_declarators;
289 } struct_or_variant_declaration;
290 struct {
291 char *name;
292 char *choice;
293 /*
294 * list of field_class_def, field_class_alias and
295 * declarations
296 */
297 struct bt_list_head declaration_list;
298 int has_body;
299 } variant;
300 struct {
301 char *name;
302 /*
303 * list of field_class_def, field_class_alias and
304 * declarations
305 */
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
319 BT_HIDDEN
320 struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create(
321 const struct ctf_metadata_decoder_config *config);
322
323 void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor);
324
325 BT_HIDDEN
326 bt_trace_class *ctf_visitor_generate_ir_get_ir_trace_class(
327 struct ctf_visitor_generate_ir *visitor);
328
329 BT_HIDDEN
330 struct ctf_trace_class *ctf_visitor_generate_ir_borrow_ctf_trace_class(
331 struct ctf_visitor_generate_ir *visitor);
332
333 BT_HIDDEN
334 int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
335 struct ctf_node *node);
336
337 BT_HIDDEN
338 int ctf_visitor_semantic_check(int depth, struct ctf_node *node);
339
340 BT_HIDDEN
341 int ctf_visitor_parent_links(int depth, struct ctf_node *node);
342
343 #endif /* _CTF_AST_H */
This page took 0.045114 seconds and 4 git commands to generate.