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