Fix: free all the metadata-related memory
[babeltrace.git] / formats / ctf / metadata / ctf-ast.h
CommitLineData
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
32struct ctf_node;
33struct ctf_parser;
8b9d5b5e
MD
34
35enum 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,
f133896d 44 NODE_CALLSITE,
8b9d5b5e 45
fce8006d 46 NODE_CTF_EXPRESSION,
6dc474b8 47 NODE_UNARY_EXPRESSION,
fce8006d
MD
48
49 NODE_TYPEDEF,
02b234c4
MD
50 NODE_TYPEALIAS_TARGET,
51 NODE_TYPEALIAS_ALIAS,
fce8006d
MD
52 NODE_TYPEALIAS,
53
ae5193a6 54 NODE_TYPE_SPECIFIER,
3e11b713 55 NODE_TYPE_SPECIFIER_LIST,
ae5193a6 56 NODE_POINTER,
fce8006d
MD
57 NODE_TYPE_DECLARATOR,
58
59 NODE_FLOATING_POINT,
60 NODE_INTEGER,
61 NODE_STRING,
ae5193a6 62 NODE_ENUMERATOR,
fce8006d 63 NODE_ENUM,
ae5193a6 64 NODE_STRUCT_OR_VARIANT_DECLARATION,
fce8006d
MD
65 NODE_VARIANT,
66 NODE_STRUCT,
67
8b9d5b5e
MD
68 NR_NODE_TYPES,
69};
70
8b9d5b5e 71struct 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;
78 struct bt_list_head gc;
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,
48a01768 150 UNARY_NESTED,
ae5193a6
MD
151 } type;
152 union {
6dc474b8
MD
153 /*
154 * string for identifier, id_type, keywords,
155 * string literals and character constants.
156 */
157 char *string;
6dc474b8 158 int64_t signed_constant;
7de8808c 159 uint64_t unsigned_constant;
6dc474b8 160 struct ctf_node *sbrac_exp;
48a01768 161 struct ctf_node *nested_exp;
6dc474b8
MD
162 } u;
163 enum {
164 UNARY_LINK_UNKNOWN = 0,
165 UNARY_DOTLINK,
166 UNARY_ARROWLINK,
48a01768 167 UNARY_DOTDOTDOT,
6dc474b8
MD
168 } link;
169 } unary_expression;
ae5193a6 170 struct {
3e11b713 171 struct ctf_node *type_specifier_list;
3122e6f0 172 struct bt_list_head type_declarators;
ae5193a6 173 } _typedef;
02b234c4
MD
174 /* new type is "alias", existing type "target" */
175 struct {
3e11b713 176 struct ctf_node *type_specifier_list;
3122e6f0 177 struct bt_list_head type_declarators;
02b234c4
MD
178 } typealias_target;
179 struct {
3e11b713 180 struct ctf_node *type_specifier_list;
3122e6f0 181 struct bt_list_head type_declarators;
02b234c4 182 } typealias_alias;
ae5193a6 183 struct {
02b234c4
MD
184 struct ctf_node *target;
185 struct ctf_node *alias;
ae5193a6
MD
186 } typealias;
187 struct {
188 enum {
02b234c4 189 TYPESPEC_UNKNOWN = 0,
ae5193a6
MD
190 TYPESPEC_VOID,
191 TYPESPEC_CHAR,
192 TYPESPEC_SHORT,
193 TYPESPEC_INT,
194 TYPESPEC_LONG,
195 TYPESPEC_FLOAT,
196 TYPESPEC_DOUBLE,
197 TYPESPEC_SIGNED,
198 TYPESPEC_UNSIGNED,
199 TYPESPEC_BOOL,
200 TYPESPEC_COMPLEX,
3888a159 201 TYPESPEC_IMAGINARY,
6dc474b8 202 TYPESPEC_CONST,
ae5193a6 203 TYPESPEC_ID_TYPE,
3e11b713
MD
204 TYPESPEC_FLOATING_POINT,
205 TYPESPEC_INTEGER,
206 TYPESPEC_STRING,
207 TYPESPEC_STRUCT,
208 TYPESPEC_VARIANT,
209 TYPESPEC_ENUM,
ae5193a6 210 } type;
3e11b713
MD
211 /* For struct, variant and enum */
212 struct ctf_node *node;
6dc474b8 213 const char *id_type;
ae5193a6 214 } type_specifier;
3e11b713
MD
215 struct {
216 /* list of type_specifier */
3122e6f0 217 struct bt_list_head head;
3e11b713 218 } type_specifier_list;
ae5193a6 219 struct {
6dc474b8 220 unsigned int const_qualifier;
ae5193a6
MD
221 } pointer;
222 struct {
3122e6f0 223 struct bt_list_head pointers;
ae5193a6 224 enum {
02b234c4 225 TYPEDEC_UNKNOWN = 0,
ae5193a6 226 TYPEDEC_ID, /* identifier */
02b234c4 227 TYPEDEC_NESTED, /* (), array or sequence */
ae5193a6
MD
228 } type;
229 union {
230 char *id;
ae5193a6
MD
231 struct {
232 /* typedec has no pointer list */
02b234c4 233 struct ctf_node *type_declarator;
7d4192cb
MD
234 /*
235 * unary expression (value) or
3e11b713 236 * type_specifier_list.
7d4192cb 237 */
3122e6f0 238 struct bt_list_head length;
6dc474b8
MD
239 /* for abstract type declarator */
240 unsigned int abstract_array;
02b234c4 241 } nested;
ae5193a6 242 } u;
6dc474b8 243 struct ctf_node *bitfield_len;
ae5193a6
MD
244 } type_declarator;
245 struct {
246 /* Children nodes are ctf_expression. */
3122e6f0 247 struct bt_list_head expressions;
ae5193a6
MD
248 } floating_point;
249 struct {
250 /* Children nodes are ctf_expression. */
3122e6f0 251 struct bt_list_head expressions;
ae5193a6
MD
252 } integer;
253 struct {
254 /* Children nodes are ctf_expression. */
3122e6f0 255 struct bt_list_head expressions;
ae5193a6
MD
256 } string;
257 struct {
258 char *id;
67905e42
MD
259 /*
260 * Range list or single value node. Contains unary
261 * expressions.
262 */
3122e6f0 263 struct bt_list_head values;
ae5193a6
MD
264 } enumerator;
265 struct {
266 char *enum_id;
7d4192cb 267 /*
3e11b713
MD
268 * Either NULL, or points to unary expression or
269 * type_specifier_list.
7d4192cb 270 */
3e11b713 271 struct ctf_node *container_type;
3122e6f0 272 struct bt_list_head enumerator_list;
add40b62 273 int has_body;
ae5193a6
MD
274 } _enum;
275 struct {
3e11b713 276 struct ctf_node *type_specifier_list;
3122e6f0 277 struct bt_list_head type_declarators;
ae5193a6
MD
278 } struct_or_variant_declaration;
279 struct {
6dc474b8
MD
280 char *name;
281 char *choice;
7de8808c 282 /* list of typedef, typealias and declarations */
3122e6f0 283 struct bt_list_head declaration_list;
1ee8e81d 284 int has_body;
ae5193a6
MD
285 } variant;
286 struct {
7de8808c 287 char *name;
6dc474b8 288 /* list of typedef, typealias and declarations */
3122e6f0 289 struct bt_list_head declaration_list;
1ee8e81d 290 int has_body;
3122e6f0 291 struct bt_list_head min_align; /* align() attribute */
ae5193a6
MD
292 } _struct;
293 } u;
8b9d5b5e
MD
294};
295
34d3acc4
MD
296struct ctf_ast {
297 struct ctf_node root;
3122e6f0 298 struct bt_list_head allocated_nodes;
34d3acc4 299};
8b9d5b5e 300
34f7b02c
MD
301const char *node_type(struct ctf_node *node);
302
ab4cf058
MD
303struct ctf_trace;
304
7de8808c 305int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node);
67905e42
MD
306int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node);
307int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node);
ab4cf058
MD
308int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node,
309 struct ctf_trace *trace, int byte_order);
15d4fe3c 310int ctf_destroy_metadata(struct ctf_trace *trace);
7de8808c 311
eb31c5e6 312#endif /* _CTF_AST_H */
This page took 0.043083 seconds and 4 git commands to generate.