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