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