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