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