ctf plugin: add CTF metadata decoder API
[babeltrace.git] / plugins / ctf / common / metadata / ast.h
CommitLineData
e98a2d6e
PP
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 */
19
20#include <stdint.h>
21#include <stdio.h>
22#include <glib.h>
23#include <babeltrace/list.h>
24#include <babeltrace/ctf-ir/trace.h>
1e649dff 25#include <babeltrace/babeltrace-internal.h>
e98a2d6e
PP
26
27// the parameter name (of the reentrant 'yyparse' function)
28// data is a pointer to a 'SParserParam' structure
29//#define YYPARSE_PARAM scanner
30
31struct ctf_node;
32struct ctf_parser;
1e649dff
PP
33struct ctf_visitor_generate_ir;
34
35#define EINCOMPLETE 1000
e98a2d6e
PP
36
37#define FOREACH_CTF_NODES(F) \
38 F(NODE_UNKNOWN) \
39 F(NODE_ROOT) \
40 F(NODE_ERROR) \
41 F(NODE_EVENT) \
42 F(NODE_STREAM) \
43 F(NODE_ENV) \
44 F(NODE_TRACE) \
45 F(NODE_CLOCK) \
46 F(NODE_CALLSITE) \
47 F(NODE_CTF_EXPRESSION) \
48 F(NODE_UNARY_EXPRESSION) \
49 F(NODE_TYPEDEF) \
50 F(NODE_TYPEALIAS_TARGET) \
51 F(NODE_TYPEALIAS_ALIAS) \
52 F(NODE_TYPEALIAS) \
53 F(NODE_TYPE_SPECIFIER) \
54 F(NODE_TYPE_SPECIFIER_LIST) \
55 F(NODE_POINTER) \
56 F(NODE_TYPE_DECLARATOR) \
57 F(NODE_FLOATING_POINT) \
58 F(NODE_INTEGER) \
59 F(NODE_STRING) \
60 F(NODE_ENUMERATOR) \
61 F(NODE_ENUM) \
62 F(NODE_STRUCT_OR_VARIANT_DECLARATION) \
63 F(NODE_VARIANT) \
64 F(NODE_STRUCT)
65
66enum node_type {
67#define ENTRY(S) S,
68 FOREACH_CTF_NODES(ENTRY)
69#undef ENTRY
70 NR_NODE_TYPES,
71};
72
73struct ctf_node {
74 /*
75 * Parent node is only set on demand by specific visitor.
76 */
77 struct ctf_node *parent;
78 struct bt_list_head siblings;
79 struct bt_list_head tmp_head;
80 unsigned int lineno;
81 /*
82 * We mark nodes visited in the generate-ir phase (last
83 * phase). We only mark the 1-depth level nodes as visited
84 * (never the root node, and not their sub-nodes). This allows
85 * skipping already visited nodes when doing incremental
86 * metadata append.
87 */
88 int visited;
89
90 enum node_type type;
91 union {
92 struct {
93 } unknown;
94 struct {
95 /*
96 * Children nodes are ctf_expression, typedef,
97 * typealias and type_specifier_list.
98 */
99 struct bt_list_head declaration_list;
100 struct bt_list_head trace;
101 struct bt_list_head env;
102 struct bt_list_head stream;
103 struct bt_list_head event;
104 struct bt_list_head clock;
105 struct bt_list_head callsite;
106 } root;
107 struct {
108 /*
109 * Children nodes are ctf_expression, typedef,
110 * typealias and type_specifier_list.
111 */
112 struct bt_list_head declaration_list;
113 } event;
114 struct {
115 /*
116 * Children nodes are ctf_expression, typedef,
117 * typealias and type_specifier_list.
118 */
119 struct bt_list_head declaration_list;
120 } stream;
121 struct {
122 /*
123 * Children nodes are ctf_expression, typedef,
124 * typealias and type_specifier_list.
125 */
126 struct bt_list_head declaration_list;
127 } env;
128 struct {
129 /*
130 * Children nodes are ctf_expression, typedef,
131 * typealias and type_specifier_list.
132 */
133 struct bt_list_head declaration_list;
134 } trace;
135 struct {
136 /*
137 * Children nodes are ctf_expression, typedef,
138 * typealias and type_specifier_list.
139 */
140 struct bt_list_head declaration_list;
141 } clock;
142 struct {
143 /*
144 * Children nodes are ctf_expression, typedef,
145 * typealias and type_specifier_list.
146 */
147 struct bt_list_head declaration_list;
148 } callsite;
149 struct {
150 struct bt_list_head left; /* Should be string */
151 struct bt_list_head right; /* Unary exp. or type */
152 } ctf_expression;
153 struct {
154 enum {
155 UNARY_UNKNOWN = 0,
156 UNARY_STRING,
157 UNARY_SIGNED_CONSTANT,
158 UNARY_UNSIGNED_CONSTANT,
159 UNARY_SBRAC,
160 } type;
161 union {
162 /*
163 * string for identifier, id_type, keywords,
164 * string literals and character constants.
165 */
166 char *string;
167 int64_t signed_constant;
168 uint64_t unsigned_constant;
169 struct ctf_node *sbrac_exp;
170 } u;
171 enum {
172 UNARY_LINK_UNKNOWN = 0,
173 UNARY_DOTLINK,
174 UNARY_ARROWLINK,
175 UNARY_DOTDOTDOT,
176 } link;
177 } unary_expression;
178 struct {
179 struct ctf_node *type_specifier_list;
180 struct bt_list_head type_declarators;
181 } _typedef;
182 /* new type is "alias", existing type "target" */
183 struct {
184 struct ctf_node *type_specifier_list;
185 struct bt_list_head type_declarators;
186 } typealias_target;
187 struct {
188 struct ctf_node *type_specifier_list;
189 struct bt_list_head type_declarators;
190 } typealias_alias;
191 struct {
192 struct ctf_node *target;
193 struct ctf_node *alias;
194 } typealias;
195 struct {
196 enum {
197 TYPESPEC_UNKNOWN = 0,
198 TYPESPEC_VOID,
199 TYPESPEC_CHAR,
200 TYPESPEC_SHORT,
201 TYPESPEC_INT,
202 TYPESPEC_LONG,
203 TYPESPEC_FLOAT,
204 TYPESPEC_DOUBLE,
205 TYPESPEC_SIGNED,
206 TYPESPEC_UNSIGNED,
207 TYPESPEC_BOOL,
208 TYPESPEC_COMPLEX,
209 TYPESPEC_IMAGINARY,
210 TYPESPEC_CONST,
211 TYPESPEC_ID_TYPE,
212 TYPESPEC_FLOATING_POINT,
213 TYPESPEC_INTEGER,
214 TYPESPEC_STRING,
215 TYPESPEC_STRUCT,
216 TYPESPEC_VARIANT,
217 TYPESPEC_ENUM,
218 } type;
219 /* For struct, variant and enum */
220 struct ctf_node *node;
221 const char *id_type;
222 } type_specifier;
223 struct {
224 /* list of type_specifier */
225 struct bt_list_head head;
226 } type_specifier_list;
227 struct {
228 unsigned int const_qualifier;
229 } pointer;
230 struct {
231 struct bt_list_head pointers;
232 enum {
233 TYPEDEC_UNKNOWN = 0,
234 TYPEDEC_ID, /* identifier */
235 TYPEDEC_NESTED, /* (), array or sequence */
236 } type;
237 union {
238 char *id;
239 struct {
240 /* typedec has no pointer list */
241 struct ctf_node *type_declarator;
242 /*
243 * unary expression (value) or
244 * type_specifier_list.
245 */
246 struct bt_list_head length;
247 /* for abstract type declarator */
248 unsigned int abstract_array;
249 } nested;
250 } u;
251 struct ctf_node *bitfield_len;
252 } type_declarator;
253 struct {
254 /* Children nodes are ctf_expression. */
255 struct bt_list_head expressions;
256 } floating_point;
257 struct {
258 /* Children nodes are ctf_expression. */
259 struct bt_list_head expressions;
260 } integer;
261 struct {
262 /* Children nodes are ctf_expression. */
263 struct bt_list_head expressions;
264 } string;
265 struct {
266 char *id;
267 /*
268 * Range list or single value node. Contains unary
269 * expressions.
270 */
271 struct bt_list_head values;
272 } enumerator;
273 struct {
274 char *enum_id;
275 /*
276 * Either NULL, or points to unary expression or
277 * type_specifier_list.
278 */
279 struct ctf_node *container_type;
280 struct bt_list_head enumerator_list;
281 int has_body;
282 } _enum;
283 struct {
284 struct ctf_node *type_specifier_list;
285 struct bt_list_head type_declarators;
286 } struct_or_variant_declaration;
287 struct {
288 char *name;
289 char *choice;
290 /* list of typedef, typealias and declarations */
291 struct bt_list_head declaration_list;
292 int has_body;
293 } variant;
294 struct {
295 char *name;
296 /* list of typedef, typealias and declarations */
297 struct bt_list_head declaration_list;
298 int has_body;
299 struct bt_list_head min_align; /* align() attribute */
300 } _struct;
301 } u;
302};
303
304struct ctf_ast {
305 struct ctf_node root;
306};
307
308const char *node_type(struct ctf_node *node);
309
1e649dff
PP
310BT_HIDDEN
311struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create(FILE *efd,
312 uint64_t clock_class_offset_ns);
313
314void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor);
e98a2d6e
PP
315
316BT_HIDDEN
1e649dff
PP
317struct bt_ctf_trace *ctf_visitor_generate_ir_get_trace(
318 struct ctf_visitor_generate_ir *visitor);
e98a2d6e
PP
319
320BT_HIDDEN
1e649dff
PP
321int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
322 struct ctf_node *node);
e98a2d6e
PP
323
324BT_HIDDEN
1e649dff 325int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node);
e98a2d6e
PP
326
327BT_HIDDEN
1e649dff 328int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node);
e98a2d6e
PP
329
330#endif /* _CTF_AST_H */
This page took 0.036749 seconds and 4 git commands to generate.