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