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