042726e9edc35d9dea049b3ee235701b74da0e0d
[babeltrace.git] / formats / ctf / metadata / ctf-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.h>
24
25 // the parameter name (of the reentrant 'yyparse' function)
26 // data is a pointer to a 'SParserParam' structure
27 //#define YYPARSE_PARAM scanner
28
29 // the argument for the 'yylex' function
30 #define YYLEX_PARAM ((struct ctf_scanner *) scanner)->scanner
31
32 struct ctf_node;
33 struct ctf_parser;
34
35 enum node_type {
36 NODE_UNKNOWN = 0,
37 NODE_ROOT,
38
39 NODE_EVENT,
40 NODE_STREAM,
41 NODE_ENV,
42 NODE_TRACE,
43 NODE_CLOCK,
44 NODE_CALLSITE,
45
46 NODE_CTF_EXPRESSION,
47 NODE_UNARY_EXPRESSION,
48
49 NODE_TYPEDEF,
50 NODE_TYPEALIAS_TARGET,
51 NODE_TYPEALIAS_ALIAS,
52 NODE_TYPEALIAS,
53
54 NODE_TYPE_SPECIFIER,
55 NODE_TYPE_SPECIFIER_LIST,
56 NODE_POINTER,
57 NODE_TYPE_DECLARATOR,
58
59 NODE_FLOATING_POINT,
60 NODE_INTEGER,
61 NODE_STRING,
62 NODE_ENUMERATOR,
63 NODE_ENUM,
64 NODE_STRUCT_OR_VARIANT_DECLARATION,
65 NODE_VARIANT,
66 NODE_STRUCT,
67
68 NR_NODE_TYPES,
69 };
70
71 struct ctf_node {
72 /*
73 * Parent node is only set on demand by specific visitor.
74 */
75 struct ctf_node *parent;
76 struct bt_list_head siblings;
77 struct bt_list_head tmp_head;
78 struct bt_list_head gc;
79 unsigned int lineno;
80
81 enum node_type type;
82 union {
83 struct {
84 } unknown;
85 struct {
86 /*
87 * Children nodes are ctf_expression, typedef,
88 * typealias and type_specifier_list.
89 */
90 struct bt_list_head declaration_list;
91 struct bt_list_head trace;
92 struct bt_list_head env;
93 struct bt_list_head stream;
94 struct bt_list_head event;
95 struct bt_list_head clock;
96 struct bt_list_head callsite;
97 } root;
98 struct {
99 /*
100 * Children nodes are ctf_expression, typedef,
101 * typealias and type_specifier_list.
102 */
103 struct bt_list_head declaration_list;
104 } event;
105 struct {
106 /*
107 * Children nodes are ctf_expression, typedef,
108 * typealias and type_specifier_list.
109 */
110 struct bt_list_head declaration_list;
111 } stream;
112 struct {
113 /*
114 * Children nodes are ctf_expression, typedef,
115 * typealias and type_specifier_list.
116 */
117 struct bt_list_head declaration_list;
118 } env;
119 struct {
120 /*
121 * Children nodes are ctf_expression, typedef,
122 * typealias and type_specifier_list.
123 */
124 struct bt_list_head declaration_list;
125 } trace;
126 struct {
127 /*
128 * Children nodes are ctf_expression, typedef,
129 * typealias and type_specifier_list.
130 */
131 struct bt_list_head declaration_list;
132 } clock;
133 struct {
134 /*
135 * Children nodes are ctf_expression, typedef,
136 * typealias and type_specifier_list.
137 */
138 struct bt_list_head declaration_list;
139 } callsite;
140 struct {
141 struct bt_list_head left; /* Should be string */
142 struct bt_list_head right; /* Unary exp. or type */
143 } ctf_expression;
144 struct {
145 enum {
146 UNARY_UNKNOWN = 0,
147 UNARY_STRING,
148 UNARY_SIGNED_CONSTANT,
149 UNARY_UNSIGNED_CONSTANT,
150 UNARY_SBRAC,
151 UNARY_NESTED,
152 } type;
153 union {
154 /*
155 * string for identifier, id_type, keywords,
156 * string literals and character constants.
157 */
158 char *string;
159 int64_t signed_constant;
160 uint64_t unsigned_constant;
161 struct ctf_node *sbrac_exp;
162 struct ctf_node *nested_exp;
163 } u;
164 enum {
165 UNARY_LINK_UNKNOWN = 0,
166 UNARY_DOTLINK,
167 UNARY_ARROWLINK,
168 UNARY_DOTDOTDOT,
169 } link;
170 } unary_expression;
171 struct {
172 struct ctf_node *type_specifier_list;
173 struct bt_list_head type_declarators;
174 } _typedef;
175 /* new type is "alias", existing type "target" */
176 struct {
177 struct ctf_node *type_specifier_list;
178 struct bt_list_head type_declarators;
179 } typealias_target;
180 struct {
181 struct ctf_node *type_specifier_list;
182 struct bt_list_head type_declarators;
183 } typealias_alias;
184 struct {
185 struct ctf_node *target;
186 struct ctf_node *alias;
187 } typealias;
188 struct {
189 enum {
190 TYPESPEC_UNKNOWN = 0,
191 TYPESPEC_VOID,
192 TYPESPEC_CHAR,
193 TYPESPEC_SHORT,
194 TYPESPEC_INT,
195 TYPESPEC_LONG,
196 TYPESPEC_FLOAT,
197 TYPESPEC_DOUBLE,
198 TYPESPEC_SIGNED,
199 TYPESPEC_UNSIGNED,
200 TYPESPEC_BOOL,
201 TYPESPEC_COMPLEX,
202 TYPESPEC_IMAGINARY,
203 TYPESPEC_CONST,
204 TYPESPEC_ID_TYPE,
205 TYPESPEC_FLOATING_POINT,
206 TYPESPEC_INTEGER,
207 TYPESPEC_STRING,
208 TYPESPEC_STRUCT,
209 TYPESPEC_VARIANT,
210 TYPESPEC_ENUM,
211 } type;
212 /* For struct, variant and enum */
213 struct ctf_node *node;
214 const char *id_type;
215 } type_specifier;
216 struct {
217 /* list of type_specifier */
218 struct bt_list_head head;
219 } type_specifier_list;
220 struct {
221 unsigned int const_qualifier;
222 } pointer;
223 struct {
224 struct bt_list_head pointers;
225 enum {
226 TYPEDEC_UNKNOWN = 0,
227 TYPEDEC_ID, /* identifier */
228 TYPEDEC_NESTED, /* (), array or sequence */
229 } type;
230 union {
231 char *id;
232 struct {
233 /* typedec has no pointer list */
234 struct ctf_node *type_declarator;
235 /*
236 * unary expression (value) or
237 * type_specifier_list.
238 */
239 struct bt_list_head length;
240 /* for abstract type declarator */
241 unsigned int abstract_array;
242 } nested;
243 } u;
244 struct ctf_node *bitfield_len;
245 } type_declarator;
246 struct {
247 /* Children nodes are ctf_expression. */
248 struct bt_list_head expressions;
249 } floating_point;
250 struct {
251 /* Children nodes are ctf_expression. */
252 struct bt_list_head expressions;
253 } integer;
254 struct {
255 /* Children nodes are ctf_expression. */
256 struct bt_list_head expressions;
257 } string;
258 struct {
259 char *id;
260 /*
261 * Range list or single value node. Contains unary
262 * expressions.
263 */
264 struct bt_list_head values;
265 } enumerator;
266 struct {
267 char *enum_id;
268 /*
269 * Either NULL, or points to unary expression or
270 * type_specifier_list.
271 */
272 struct ctf_node *container_type;
273 struct bt_list_head enumerator_list;
274 int has_body;
275 } _enum;
276 struct {
277 struct ctf_node *type_specifier_list;
278 struct bt_list_head type_declarators;
279 } struct_or_variant_declaration;
280 struct {
281 char *name;
282 char *choice;
283 /* list of typedef, typealias and declarations */
284 struct bt_list_head declaration_list;
285 int has_body;
286 } variant;
287 struct {
288 char *name;
289 /* list of typedef, typealias and declarations */
290 struct bt_list_head declaration_list;
291 int has_body;
292 struct bt_list_head min_align; /* align() attribute */
293 } _struct;
294 } u;
295 };
296
297 struct ctf_ast {
298 struct ctf_node root;
299 struct bt_list_head allocated_nodes;
300 };
301
302 const char *node_type(struct ctf_node *node);
303
304 struct ctf_trace;
305
306 BT_HIDDEN
307 int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node);
308 BT_HIDDEN
309 int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node);
310 BT_HIDDEN
311 int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node);
312 BT_HIDDEN
313 int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node,
314 struct ctf_trace *trace, int byte_order);
315 BT_HIDDEN
316 int ctf_destroy_metadata(struct ctf_trace *trace);
317
318 #endif /* _CTF_AST_H */
This page took 0.037324 seconds and 3 git commands to generate.