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