Add XML dump visitor
[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>
8b9d5b5e 5#include <helpers/list.h>
34d3acc4
MD
6#include <stdio.h>
7#include <glib.h>
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;
8b9d5b5e 57 struct cds_list_head gc;
ae5193a6
MD
58
59 enum node_type type;
60 union {
61 struct {
62 } unknown;
63 struct {
02b234c4
MD
64 struct cds_list_head _typedef;
65 struct cds_list_head typealias;
66 struct cds_list_head declaration_specifier;
67 struct cds_list_head trace;
68 struct cds_list_head stream;
69 struct cds_list_head event;
ae5193a6
MD
70 } root;
71 struct {
72 /*
6dc474b8
MD
73 * Children nodes are ctf_expression, typedef,
74 * typealias and declaration specifiers.
ae5193a6 75 */
6dc474b8 76 struct cds_list_head declaration_list;
ae5193a6
MD
77 } event;
78 struct {
79 /*
6dc474b8
MD
80 * Children nodes are ctf_expression, typedef,
81 * typealias and declaration specifiers.
ae5193a6 82 */
6dc474b8 83 struct cds_list_head declaration_list;
ae5193a6
MD
84 } stream;
85 struct {
86 /*
6dc474b8
MD
87 * Children nodes are ctf_expression, typedef,
88 * typealias and declaration specifiers.
ae5193a6 89 */
6dc474b8 90 struct cds_list_head declaration_list;
ae5193a6
MD
91 } trace;
92 struct {
6dc474b8
MD
93 struct ctf_node *left; /* Should be string */
94 struct ctf_node *right; /* Unary exp. or type */
95 } ctf_expression;
96 struct {
ae5193a6 97 enum {
6dc474b8
MD
98 UNARY_UNKNOWN = 0,
99 UNARY_STRING,
100 UNARY_SIGNED_CONSTANT,
101 UNARY_UNSIGNED_CONSTANT,
102 UNARY_SBRAC,
ae5193a6
MD
103 } type;
104 union {
6dc474b8
MD
105 /*
106 * string for identifier, id_type, keywords,
107 * string literals and character constants.
108 */
109 char *string;
6dc474b8 110 int64_t signed_constant;
7de8808c 111 uint64_t unsigned_constant;
6dc474b8
MD
112 struct ctf_node *sbrac_exp;
113 } u;
114 enum {
115 UNARY_LINK_UNKNOWN = 0,
116 UNARY_DOTLINK,
117 UNARY_ARROWLINK,
118 } link;
119 } unary_expression;
ae5193a6 120 struct {
6dc474b8 121 struct cds_list_head declaration_specifier;
02b234c4 122 struct cds_list_head type_declarators;
ae5193a6 123 } _typedef;
02b234c4
MD
124 /* new type is "alias", existing type "target" */
125 struct {
6dc474b8 126 struct cds_list_head declaration_specifier;
02b234c4
MD
127 struct cds_list_head type_declarators;
128 } typealias_target;
129 struct {
6dc474b8 130 struct cds_list_head declaration_specifier;
02b234c4
MD
131 struct cds_list_head type_declarators;
132 } typealias_alias;
ae5193a6 133 struct {
02b234c4
MD
134 struct ctf_node *target;
135 struct ctf_node *alias;
ae5193a6
MD
136 } typealias;
137 struct {
138 enum {
02b234c4 139 TYPESPEC_UNKNOWN = 0,
ae5193a6
MD
140 TYPESPEC_VOID,
141 TYPESPEC_CHAR,
142 TYPESPEC_SHORT,
143 TYPESPEC_INT,
144 TYPESPEC_LONG,
145 TYPESPEC_FLOAT,
146 TYPESPEC_DOUBLE,
147 TYPESPEC_SIGNED,
148 TYPESPEC_UNSIGNED,
149 TYPESPEC_BOOL,
150 TYPESPEC_COMPLEX,
6dc474b8 151 TYPESPEC_CONST,
ae5193a6 152 TYPESPEC_ID_TYPE,
ae5193a6 153 } type;
6dc474b8 154 const char *id_type;
ae5193a6
MD
155 } type_specifier;
156 struct {
6dc474b8 157 unsigned int const_qualifier;
ae5193a6
MD
158 } pointer;
159 struct {
160 struct cds_list_head pointers;
161 enum {
02b234c4 162 TYPEDEC_UNKNOWN = 0,
ae5193a6 163 TYPEDEC_ID, /* identifier */
02b234c4 164 TYPEDEC_NESTED, /* (), array or sequence */
ae5193a6
MD
165 } type;
166 union {
167 char *id;
ae5193a6
MD
168 struct {
169 /* typedec has no pointer list */
02b234c4 170 struct ctf_node *type_declarator;
6dc474b8
MD
171 /* value or first node of declaration specifier list */
172 struct ctf_node *length;
173 /* for abstract type declarator */
174 unsigned int abstract_array;
02b234c4 175 } nested;
ae5193a6 176 } u;
6dc474b8 177 struct ctf_node *bitfield_len;
ae5193a6
MD
178 } type_declarator;
179 struct {
180 /* Children nodes are ctf_expression. */
181 struct cds_list_head expressions;
182 } floating_point;
183 struct {
184 /* Children nodes are ctf_expression. */
185 struct cds_list_head expressions;
186 } integer;
187 struct {
188 /* Children nodes are ctf_expression. */
189 struct cds_list_head expressions;
190 } string;
191 struct {
192 char *id;
6dc474b8
MD
193 /* first node of range list or single node */
194 struct ctf_node *values;
ae5193a6
MD
195 } enumerator;
196 struct {
197 char *enum_id;
6dc474b8
MD
198 /* NULL, value or declaration specifier */
199 struct ctf_node *container_type;
ae5193a6
MD
200 struct cds_list_head enumerator_list;
201 } _enum;
202 struct {
6dc474b8 203 struct cds_list_head declaration_specifier;
02b234c4 204 struct cds_list_head type_declarators;
ae5193a6
MD
205 } struct_or_variant_declaration;
206 struct {
6dc474b8
MD
207 char *name;
208 char *choice;
7de8808c
MD
209 /* list of typedef, typealias and declarations */
210 struct cds_list_head declaration_list;
ae5193a6
MD
211 } variant;
212 struct {
7de8808c 213 char *name;
6dc474b8 214 /* list of typedef, typealias and declarations */
ae5193a6
MD
215 struct cds_list_head declaration_list;
216 } _struct;
217 } u;
8b9d5b5e
MD
218};
219
34d3acc4
MD
220struct ctf_ast {
221 struct ctf_node root;
02b234c4 222 struct cds_list_head allocated_nodes;
34d3acc4 223};
8b9d5b5e 224
7de8808c
MD
225int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node);
226
8b9d5b5e 227#endif /* _CTF_PARSER_H */
This page took 0.032958 seconds and 4 git commands to generate.