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