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