Remove nested expressions
[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 #define FOREACH_CTF_NODES(F) \
36 F(NODE_UNKNOWN) \
37 F(NODE_ROOT) \
38 F(NODE_ERROR) \
39 F(NODE_EVENT) \
40 F(NODE_STREAM) \
41 F(NODE_ENV) \
42 F(NODE_TRACE) \
43 F(NODE_CLOCK) \
44 F(NODE_CALLSITE) \
45 F(NODE_CTF_EXPRESSION) \
46 F(NODE_UNARY_EXPRESSION) \
47 F(NODE_TYPEDEF) \
48 F(NODE_TYPEALIAS_TARGET) \
49 F(NODE_TYPEALIAS_ALIAS) \
50 F(NODE_TYPEALIAS) \
51 F(NODE_TYPE_SPECIFIER) \
52 F(NODE_TYPE_SPECIFIER_LIST) \
53 F(NODE_POINTER) \
54 F(NODE_TYPE_DECLARATOR) \
55 F(NODE_FLOATING_POINT) \
56 F(NODE_INTEGER) \
57 F(NODE_STRING) \
58 F(NODE_ENUMERATOR) \
59 F(NODE_ENUM) \
60 F(NODE_STRUCT_OR_VARIANT_DECLARATION) \
61 F(NODE_VARIANT) \
62 F(NODE_STRUCT)
63
64 enum node_type {
65 #define ENTRY(S) S,
66 FOREACH_CTF_NODES(ENTRY)
67 #undef ENTRY
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 } type;
152 union {
153 /*
154 * string for identifier, id_type, keywords,
155 * string literals and character constants.
156 */
157 char *string;
158 int64_t signed_constant;
159 uint64_t unsigned_constant;
160 struct ctf_node *sbrac_exp;
161 } u;
162 enum {
163 UNARY_LINK_UNKNOWN = 0,
164 UNARY_DOTLINK,
165 UNARY_ARROWLINK,
166 UNARY_DOTDOTDOT,
167 } link;
168 } unary_expression;
169 struct {
170 struct ctf_node *type_specifier_list;
171 struct bt_list_head type_declarators;
172 } _typedef;
173 /* new type is "alias", existing type "target" */
174 struct {
175 struct ctf_node *type_specifier_list;
176 struct bt_list_head type_declarators;
177 } typealias_target;
178 struct {
179 struct ctf_node *type_specifier_list;
180 struct bt_list_head type_declarators;
181 } typealias_alias;
182 struct {
183 struct ctf_node *target;
184 struct ctf_node *alias;
185 } typealias;
186 struct {
187 enum {
188 TYPESPEC_UNKNOWN = 0,
189 TYPESPEC_VOID,
190 TYPESPEC_CHAR,
191 TYPESPEC_SHORT,
192 TYPESPEC_INT,
193 TYPESPEC_LONG,
194 TYPESPEC_FLOAT,
195 TYPESPEC_DOUBLE,
196 TYPESPEC_SIGNED,
197 TYPESPEC_UNSIGNED,
198 TYPESPEC_BOOL,
199 TYPESPEC_COMPLEX,
200 TYPESPEC_IMAGINARY,
201 TYPESPEC_CONST,
202 TYPESPEC_ID_TYPE,
203 TYPESPEC_FLOATING_POINT,
204 TYPESPEC_INTEGER,
205 TYPESPEC_STRING,
206 TYPESPEC_STRUCT,
207 TYPESPEC_VARIANT,
208 TYPESPEC_ENUM,
209 } type;
210 /* For struct, variant and enum */
211 struct ctf_node *node;
212 const char *id_type;
213 } type_specifier;
214 struct {
215 /* list of type_specifier */
216 struct bt_list_head head;
217 } type_specifier_list;
218 struct {
219 unsigned int const_qualifier;
220 } pointer;
221 struct {
222 struct bt_list_head pointers;
223 enum {
224 TYPEDEC_UNKNOWN = 0,
225 TYPEDEC_ID, /* identifier */
226 TYPEDEC_NESTED, /* (), array or sequence */
227 } type;
228 union {
229 char *id;
230 struct {
231 /* typedec has no pointer list */
232 struct ctf_node *type_declarator;
233 /*
234 * unary expression (value) or
235 * type_specifier_list.
236 */
237 struct bt_list_head length;
238 /* for abstract type declarator */
239 unsigned int abstract_array;
240 } nested;
241 } u;
242 struct ctf_node *bitfield_len;
243 } type_declarator;
244 struct {
245 /* Children nodes are ctf_expression. */
246 struct bt_list_head expressions;
247 } floating_point;
248 struct {
249 /* Children nodes are ctf_expression. */
250 struct bt_list_head expressions;
251 } integer;
252 struct {
253 /* Children nodes are ctf_expression. */
254 struct bt_list_head expressions;
255 } string;
256 struct {
257 char *id;
258 /*
259 * Range list or single value node. Contains unary
260 * expressions.
261 */
262 struct bt_list_head values;
263 } enumerator;
264 struct {
265 char *enum_id;
266 /*
267 * Either NULL, or points to unary expression or
268 * type_specifier_list.
269 */
270 struct ctf_node *container_type;
271 struct bt_list_head enumerator_list;
272 int has_body;
273 } _enum;
274 struct {
275 struct ctf_node *type_specifier_list;
276 struct bt_list_head type_declarators;
277 } struct_or_variant_declaration;
278 struct {
279 char *name;
280 char *choice;
281 /* list of typedef, typealias and declarations */
282 struct bt_list_head declaration_list;
283 int has_body;
284 } variant;
285 struct {
286 char *name;
287 /* list of typedef, typealias and declarations */
288 struct bt_list_head declaration_list;
289 int has_body;
290 struct bt_list_head min_align; /* align() attribute */
291 } _struct;
292 } u;
293 };
294
295 struct ctf_ast {
296 struct ctf_node root;
297 struct bt_list_head allocated_nodes;
298 };
299
300 const char *node_type(struct ctf_node *node);
301
302 struct ctf_trace;
303
304 BT_HIDDEN
305 int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node);
306 BT_HIDDEN
307 int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node);
308 BT_HIDDEN
309 int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node);
310 BT_HIDDEN
311 int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node,
312 struct ctf_trace *trace, int byte_order);
313 BT_HIDDEN
314 int ctf_destroy_metadata(struct ctf_trace *trace);
315
316 #endif /* _CTF_AST_H */
This page took 0.035811 seconds and 4 git commands to generate.