40298b8e506821cb520f444d06115bf752e647ac
[babeltrace.git] / formats / ctf / metadata / ctf-ast.h
1 #ifndef _CTF_PARSER_H
2 #define _CTF_PARSER_H
3
4 #include <stdint.h>
5 #include <stdio.h>
6 #include <glib.h>
7 #include <babeltrace/list.h>
8
9 // the parameter name (of the reentrant 'yyparse' function)
10 // data is a pointer to a 'SParserParam' structure
11 //#define YYPARSE_PARAM scanner
12
13 // the argument for the 'yylex' function
14 #define YYLEX_PARAM ((struct ctf_scanner *) scanner)->scanner
15
16 struct ctf_node;
17 struct ctf_parser;
18
19 enum node_type {
20 NODE_UNKNOWN = 0,
21 NODE_ROOT,
22
23 NODE_EVENT,
24 NODE_STREAM,
25 NODE_TRACE,
26 NODE_CLOCK,
27
28 NODE_CTF_EXPRESSION,
29 NODE_UNARY_EXPRESSION,
30
31 NODE_TYPEDEF,
32 NODE_TYPEALIAS_TARGET,
33 NODE_TYPEALIAS_ALIAS,
34 NODE_TYPEALIAS,
35
36 NODE_TYPE_SPECIFIER,
37 NODE_TYPE_SPECIFIER_LIST,
38 NODE_POINTER,
39 NODE_TYPE_DECLARATOR,
40
41 NODE_FLOATING_POINT,
42 NODE_INTEGER,
43 NODE_STRING,
44 NODE_ENUMERATOR,
45 NODE_ENUM,
46 NODE_STRUCT_OR_VARIANT_DECLARATION,
47 NODE_VARIANT,
48 NODE_STRUCT,
49
50 NR_NODE_TYPES,
51 };
52
53 struct ctf_node {
54 /*
55 * Parent node is only set on demand by specific visitor.
56 */
57 struct ctf_node *parent;
58 struct cds_list_head siblings;
59 struct cds_list_head tmp_head;
60 struct cds_list_head gc;
61
62 enum node_type type;
63 union {
64 struct {
65 } unknown;
66 struct {
67 /*
68 * Children nodes are ctf_expression, typedef,
69 * typealias and type_specifier_list.
70 */
71 struct cds_list_head declaration_list;
72 struct cds_list_head trace;
73 struct cds_list_head stream;
74 struct cds_list_head event;
75 struct cds_list_head clock;
76 } root;
77 struct {
78 /*
79 * Children nodes are ctf_expression, typedef,
80 * typealias and type_specifier_list.
81 */
82 struct cds_list_head declaration_list;
83 } event;
84 struct {
85 /*
86 * Children nodes are ctf_expression, typedef,
87 * typealias and type_specifier_list.
88 */
89 struct cds_list_head declaration_list;
90 } stream;
91 struct {
92 /*
93 * Children nodes are ctf_expression, typedef,
94 * typealias and type_specifier_list.
95 */
96 struct cds_list_head declaration_list;
97 } trace;
98 struct {
99 /*
100 * Children nodes are ctf_expression, typedef,
101 * typealias and type_specifier_list.
102 */
103 struct cds_list_head declaration_list;
104 } clock;
105 struct {
106 struct cds_list_head left; /* Should be string */
107 struct cds_list_head right; /* Unary exp. or type */
108 } ctf_expression;
109 struct {
110 enum {
111 UNARY_UNKNOWN = 0,
112 UNARY_STRING,
113 UNARY_SIGNED_CONSTANT,
114 UNARY_UNSIGNED_CONSTANT,
115 UNARY_SBRAC,
116 UNARY_NESTED,
117 } type;
118 union {
119 /*
120 * string for identifier, id_type, keywords,
121 * string literals and character constants.
122 */
123 char *string;
124 int64_t signed_constant;
125 uint64_t unsigned_constant;
126 struct ctf_node *sbrac_exp;
127 struct ctf_node *nested_exp;
128 } u;
129 enum {
130 UNARY_LINK_UNKNOWN = 0,
131 UNARY_DOTLINK,
132 UNARY_ARROWLINK,
133 UNARY_DOTDOTDOT,
134 } link;
135 } unary_expression;
136 struct {
137 struct ctf_node *type_specifier_list;
138 struct cds_list_head type_declarators;
139 } _typedef;
140 /* new type is "alias", existing type "target" */
141 struct {
142 struct ctf_node *type_specifier_list;
143 struct cds_list_head type_declarators;
144 } typealias_target;
145 struct {
146 struct ctf_node *type_specifier_list;
147 struct cds_list_head type_declarators;
148 } typealias_alias;
149 struct {
150 struct ctf_node *target;
151 struct ctf_node *alias;
152 } typealias;
153 struct {
154 enum {
155 TYPESPEC_UNKNOWN = 0,
156 TYPESPEC_VOID,
157 TYPESPEC_CHAR,
158 TYPESPEC_SHORT,
159 TYPESPEC_INT,
160 TYPESPEC_LONG,
161 TYPESPEC_FLOAT,
162 TYPESPEC_DOUBLE,
163 TYPESPEC_SIGNED,
164 TYPESPEC_UNSIGNED,
165 TYPESPEC_BOOL,
166 TYPESPEC_COMPLEX,
167 TYPESPEC_IMAGINARY,
168 TYPESPEC_CONST,
169 TYPESPEC_ID_TYPE,
170 TYPESPEC_FLOATING_POINT,
171 TYPESPEC_INTEGER,
172 TYPESPEC_STRING,
173 TYPESPEC_STRUCT,
174 TYPESPEC_VARIANT,
175 TYPESPEC_ENUM,
176 } type;
177 /* For struct, variant and enum */
178 struct ctf_node *node;
179 const char *id_type;
180 } type_specifier;
181 struct {
182 /* list of type_specifier */
183 struct cds_list_head head;
184 } type_specifier_list;
185 struct {
186 unsigned int const_qualifier;
187 } pointer;
188 struct {
189 struct cds_list_head pointers;
190 enum {
191 TYPEDEC_UNKNOWN = 0,
192 TYPEDEC_ID, /* identifier */
193 TYPEDEC_NESTED, /* (), array or sequence */
194 } type;
195 union {
196 char *id;
197 struct {
198 /* typedec has no pointer list */
199 struct ctf_node *type_declarator;
200 /*
201 * unary expression (value) or
202 * type_specifier_list.
203 */
204 struct cds_list_head length;
205 /* for abstract type declarator */
206 unsigned int abstract_array;
207 } nested;
208 } u;
209 struct ctf_node *bitfield_len;
210 } type_declarator;
211 struct {
212 /* Children nodes are ctf_expression. */
213 struct cds_list_head expressions;
214 } floating_point;
215 struct {
216 /* Children nodes are ctf_expression. */
217 struct cds_list_head expressions;
218 } integer;
219 struct {
220 /* Children nodes are ctf_expression. */
221 struct cds_list_head expressions;
222 } string;
223 struct {
224 char *id;
225 /*
226 * Range list or single value node. Contains unary
227 * expressions.
228 */
229 struct cds_list_head values;
230 } enumerator;
231 struct {
232 char *enum_id;
233 /*
234 * Either NULL, or points to unary expression or
235 * type_specifier_list.
236 */
237 struct ctf_node *container_type;
238 struct cds_list_head enumerator_list;
239 int has_body;
240 } _enum;
241 struct {
242 struct ctf_node *type_specifier_list;
243 struct cds_list_head type_declarators;
244 } struct_or_variant_declaration;
245 struct {
246 char *name;
247 char *choice;
248 /* list of typedef, typealias and declarations */
249 struct cds_list_head declaration_list;
250 int has_body;
251 } variant;
252 struct {
253 char *name;
254 /* list of typedef, typealias and declarations */
255 struct cds_list_head declaration_list;
256 int has_body;
257 struct cds_list_head min_align; /* align() attribute */
258 } _struct;
259 } u;
260 };
261
262 struct ctf_ast {
263 struct ctf_node root;
264 struct cds_list_head allocated_nodes;
265 };
266
267 const char *node_type(struct ctf_node *node);
268
269 struct ctf_trace;
270
271 int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node);
272 int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node);
273 int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node);
274 int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node,
275 struct ctf_trace *trace, int byte_order);
276
277 #endif /* _CTF_PARSER_H */
This page took 0.034295 seconds and 3 git commands to generate.