Commit | Line | Data |
---|---|---|
eb31c5e6 MD |
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 | */ | |
8b9d5b5e | 19 | |
ae5193a6 | 20 | #include <stdint.h> |
34d3acc4 MD |
21 | #include <stdio.h> |
22 | #include <glib.h> | |
fe41395a | 23 | #include <babeltrace/list.h> |
34d3acc4 | 24 | |
9117bff7 MD |
25 | // the parameter name (of the reentrant 'yyparse' function) |
26 | // data is a pointer to a 'SParserParam' structure | |
27 | //#define YYPARSE_PARAM scanner | |
28 | ||
34d3acc4 MD |
29 | struct ctf_node; |
30 | struct ctf_parser; | |
8b9d5b5e | 31 | |
590ca879 EB |
32 | #define FOREACH_CTF_NODES(F) \ |
33 | F(NODE_UNKNOWN) \ | |
34 | F(NODE_ROOT) \ | |
41485b22 | 35 | F(NODE_ERROR) \ |
590ca879 EB |
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) | |
fce8006d | 60 | |
590ca879 EB |
61 | enum node_type { |
62 | #define ENTRY(S) S, | |
63 | FOREACH_CTF_NODES(ENTRY) | |
64 | #undef ENTRY | |
8b9d5b5e MD |
65 | NR_NODE_TYPES, |
66 | }; | |
67 | ||
8b9d5b5e | 68 | struct ctf_node { |
6dc474b8 MD |
69 | /* |
70 | * Parent node is only set on demand by specific visitor. | |
71 | */ | |
8b9d5b5e | 72 | struct ctf_node *parent; |
3122e6f0 JD |
73 | struct bt_list_head siblings; |
74 | struct bt_list_head tmp_head; | |
5c5c3455 | 75 | unsigned int lineno; |
0c880b0a MD |
76 | /* |
77 | * We mark nodes visited in the generate-io-struct phase (last | |
78 | * phase). We only mark the 1-depth level nodes as visited | |
79 | * (never the root node, and not their sub-nodes). This allows | |
80 | * skipping already visited nodes when doing incremental | |
81 | * metadata append. | |
82 | */ | |
83 | int visited; | |
ae5193a6 MD |
84 | |
85 | enum node_type type; | |
86 | union { | |
87 | struct { | |
88 | } unknown; | |
89 | struct { | |
3e11b713 MD |
90 | /* |
91 | * Children nodes are ctf_expression, typedef, | |
92 | * typealias and type_specifier_list. | |
93 | */ | |
3122e6f0 JD |
94 | struct bt_list_head declaration_list; |
95 | struct bt_list_head trace; | |
96 | struct bt_list_head env; | |
97 | struct bt_list_head stream; | |
98 | struct bt_list_head event; | |
99 | struct bt_list_head clock; | |
f133896d | 100 | struct bt_list_head callsite; |
ae5193a6 MD |
101 | } root; |
102 | struct { | |
103 | /* | |
6dc474b8 | 104 | * Children nodes are ctf_expression, typedef, |
3e11b713 | 105 | * typealias and type_specifier_list. |
ae5193a6 | 106 | */ |
3122e6f0 | 107 | struct bt_list_head declaration_list; |
ae5193a6 MD |
108 | } event; |
109 | struct { | |
110 | /* | |
6dc474b8 | 111 | * Children nodes are ctf_expression, typedef, |
3e11b713 | 112 | * typealias and type_specifier_list. |
ae5193a6 | 113 | */ |
3122e6f0 | 114 | struct bt_list_head declaration_list; |
ae5193a6 | 115 | } stream; |
e2c76a4d MD |
116 | struct { |
117 | /* | |
118 | * Children nodes are ctf_expression, typedef, | |
119 | * typealias and type_specifier_list. | |
120 | */ | |
3122e6f0 | 121 | struct bt_list_head declaration_list; |
e2c76a4d | 122 | } env; |
ae5193a6 MD |
123 | struct { |
124 | /* | |
6dc474b8 | 125 | * Children nodes are ctf_expression, typedef, |
3e11b713 | 126 | * typealias and type_specifier_list. |
ae5193a6 | 127 | */ |
3122e6f0 | 128 | struct bt_list_head declaration_list; |
ae5193a6 | 129 | } trace; |
73d15916 MD |
130 | struct { |
131 | /* | |
132 | * Children nodes are ctf_expression, typedef, | |
133 | * typealias and type_specifier_list. | |
134 | */ | |
3122e6f0 | 135 | struct bt_list_head declaration_list; |
73d15916 | 136 | } clock; |
f133896d MD |
137 | struct { |
138 | /* | |
139 | * Children nodes are ctf_expression, typedef, | |
140 | * typealias and type_specifier_list. | |
141 | */ | |
142 | struct bt_list_head declaration_list; | |
143 | } callsite; | |
ae5193a6 | 144 | struct { |
3122e6f0 JD |
145 | struct bt_list_head left; /* Should be string */ |
146 | struct bt_list_head right; /* Unary exp. or type */ | |
6dc474b8 MD |
147 | } ctf_expression; |
148 | struct { | |
ae5193a6 | 149 | enum { |
6dc474b8 MD |
150 | UNARY_UNKNOWN = 0, |
151 | UNARY_STRING, | |
152 | UNARY_SIGNED_CONSTANT, | |
153 | UNARY_UNSIGNED_CONSTANT, | |
154 | UNARY_SBRAC, | |
ae5193a6 MD |
155 | } type; |
156 | union { | |
6dc474b8 MD |
157 | /* |
158 | * string for identifier, id_type, keywords, | |
159 | * string literals and character constants. | |
160 | */ | |
161 | char *string; | |
6dc474b8 | 162 | int64_t signed_constant; |
7de8808c | 163 | uint64_t unsigned_constant; |
6dc474b8 MD |
164 | struct ctf_node *sbrac_exp; |
165 | } u; | |
166 | enum { | |
167 | UNARY_LINK_UNKNOWN = 0, | |
168 | UNARY_DOTLINK, | |
169 | UNARY_ARROWLINK, | |
48a01768 | 170 | UNARY_DOTDOTDOT, |
6dc474b8 MD |
171 | } link; |
172 | } unary_expression; | |
ae5193a6 | 173 | struct { |
3e11b713 | 174 | struct ctf_node *type_specifier_list; |
3122e6f0 | 175 | struct bt_list_head type_declarators; |
ae5193a6 | 176 | } _typedef; |
02b234c4 MD |
177 | /* new type is "alias", existing type "target" */ |
178 | struct { | |
3e11b713 | 179 | struct ctf_node *type_specifier_list; |
3122e6f0 | 180 | struct bt_list_head type_declarators; |
02b234c4 MD |
181 | } typealias_target; |
182 | struct { | |
3e11b713 | 183 | struct ctf_node *type_specifier_list; |
3122e6f0 | 184 | struct bt_list_head type_declarators; |
02b234c4 | 185 | } typealias_alias; |
ae5193a6 | 186 | struct { |
02b234c4 MD |
187 | struct ctf_node *target; |
188 | struct ctf_node *alias; | |
ae5193a6 MD |
189 | } typealias; |
190 | struct { | |
191 | enum { | |
02b234c4 | 192 | TYPESPEC_UNKNOWN = 0, |
ae5193a6 MD |
193 | TYPESPEC_VOID, |
194 | TYPESPEC_CHAR, | |
195 | TYPESPEC_SHORT, | |
196 | TYPESPEC_INT, | |
197 | TYPESPEC_LONG, | |
198 | TYPESPEC_FLOAT, | |
199 | TYPESPEC_DOUBLE, | |
200 | TYPESPEC_SIGNED, | |
201 | TYPESPEC_UNSIGNED, | |
202 | TYPESPEC_BOOL, | |
203 | TYPESPEC_COMPLEX, | |
3888a159 | 204 | TYPESPEC_IMAGINARY, |
6dc474b8 | 205 | TYPESPEC_CONST, |
ae5193a6 | 206 | TYPESPEC_ID_TYPE, |
3e11b713 MD |
207 | TYPESPEC_FLOATING_POINT, |
208 | TYPESPEC_INTEGER, | |
209 | TYPESPEC_STRING, | |
210 | TYPESPEC_STRUCT, | |
211 | TYPESPEC_VARIANT, | |
212 | TYPESPEC_ENUM, | |
ae5193a6 | 213 | } type; |
3e11b713 MD |
214 | /* For struct, variant and enum */ |
215 | struct ctf_node *node; | |
6dc474b8 | 216 | const char *id_type; |
ae5193a6 | 217 | } type_specifier; |
3e11b713 MD |
218 | struct { |
219 | /* list of type_specifier */ | |
3122e6f0 | 220 | struct bt_list_head head; |
3e11b713 | 221 | } type_specifier_list; |
ae5193a6 | 222 | struct { |
6dc474b8 | 223 | unsigned int const_qualifier; |
ae5193a6 MD |
224 | } pointer; |
225 | struct { | |
3122e6f0 | 226 | struct bt_list_head pointers; |
ae5193a6 | 227 | enum { |
02b234c4 | 228 | TYPEDEC_UNKNOWN = 0, |
ae5193a6 | 229 | TYPEDEC_ID, /* identifier */ |
02b234c4 | 230 | TYPEDEC_NESTED, /* (), array or sequence */ |
ae5193a6 MD |
231 | } type; |
232 | union { | |
233 | char *id; | |
ae5193a6 MD |
234 | struct { |
235 | /* typedec has no pointer list */ | |
02b234c4 | 236 | struct ctf_node *type_declarator; |
7d4192cb MD |
237 | /* |
238 | * unary expression (value) or | |
3e11b713 | 239 | * type_specifier_list. |
7d4192cb | 240 | */ |
3122e6f0 | 241 | struct bt_list_head length; |
6dc474b8 MD |
242 | /* for abstract type declarator */ |
243 | unsigned int abstract_array; | |
02b234c4 | 244 | } nested; |
ae5193a6 | 245 | } u; |
6dc474b8 | 246 | struct ctf_node *bitfield_len; |
ae5193a6 MD |
247 | } type_declarator; |
248 | struct { | |
249 | /* Children nodes are ctf_expression. */ | |
3122e6f0 | 250 | struct bt_list_head expressions; |
ae5193a6 MD |
251 | } floating_point; |
252 | struct { | |
253 | /* Children nodes are ctf_expression. */ | |
3122e6f0 | 254 | struct bt_list_head expressions; |
ae5193a6 MD |
255 | } integer; |
256 | struct { | |
257 | /* Children nodes are ctf_expression. */ | |
3122e6f0 | 258 | struct bt_list_head expressions; |
ae5193a6 MD |
259 | } string; |
260 | struct { | |
261 | char *id; | |
67905e42 MD |
262 | /* |
263 | * Range list or single value node. Contains unary | |
264 | * expressions. | |
265 | */ | |
3122e6f0 | 266 | struct bt_list_head values; |
ae5193a6 MD |
267 | } enumerator; |
268 | struct { | |
269 | char *enum_id; | |
7d4192cb | 270 | /* |
3e11b713 MD |
271 | * Either NULL, or points to unary expression or |
272 | * type_specifier_list. | |
7d4192cb | 273 | */ |
3e11b713 | 274 | struct ctf_node *container_type; |
3122e6f0 | 275 | struct bt_list_head enumerator_list; |
add40b62 | 276 | int has_body; |
ae5193a6 MD |
277 | } _enum; |
278 | struct { | |
3e11b713 | 279 | struct ctf_node *type_specifier_list; |
3122e6f0 | 280 | struct bt_list_head type_declarators; |
ae5193a6 MD |
281 | } struct_or_variant_declaration; |
282 | struct { | |
6dc474b8 MD |
283 | char *name; |
284 | char *choice; | |
7de8808c | 285 | /* list of typedef, typealias and declarations */ |
3122e6f0 | 286 | struct bt_list_head declaration_list; |
1ee8e81d | 287 | int has_body; |
ae5193a6 MD |
288 | } variant; |
289 | struct { | |
7de8808c | 290 | char *name; |
6dc474b8 | 291 | /* list of typedef, typealias and declarations */ |
3122e6f0 | 292 | struct bt_list_head declaration_list; |
1ee8e81d | 293 | int has_body; |
3122e6f0 | 294 | struct bt_list_head min_align; /* align() attribute */ |
ae5193a6 MD |
295 | } _struct; |
296 | } u; | |
8b9d5b5e MD |
297 | }; |
298 | ||
34d3acc4 MD |
299 | struct ctf_ast { |
300 | struct ctf_node root; | |
301 | }; | |
8b9d5b5e | 302 | |
34f7b02c MD |
303 | const char *node_type(struct ctf_node *node); |
304 | ||
ab4cf058 MD |
305 | struct ctf_trace; |
306 | ||
2e937fb4 | 307 | BT_HIDDEN |
7de8808c | 308 | int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node); |
2e937fb4 | 309 | BT_HIDDEN |
67905e42 | 310 | int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node); |
2e937fb4 | 311 | BT_HIDDEN |
67905e42 | 312 | int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node); |
2e937fb4 | 313 | BT_HIDDEN |
ab4cf058 MD |
314 | int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, |
315 | struct ctf_trace *trace, int byte_order); | |
2e937fb4 | 316 | BT_HIDDEN |
15d4fe3c | 317 | int ctf_destroy_metadata(struct ctf_trace *trace); |
7de8808c | 318 | |
eb31c5e6 | 319 | #endif /* _CTF_AST_H */ |