Add XML dump visitor
[babeltrace.git] / formats / ctf / metadata / ctf-ast.h
1 #ifndef _CTF_PARSER_H
2 #define _CTF_PARSER_H
3
4 #include <stdint.h>
5 #include <helpers/list.h>
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
16 struct ctf_node;
17 struct ctf_parser;
18
19 enum node_type {
20 NODE_UNKNOWN = 0,
21 NODE_ROOT,
22
23 NODE_EVENT,
24 NODE_STREAM,
25 NODE_TRACE,
26
27 NODE_CTF_EXPRESSION,
28 NODE_UNARY_EXPRESSION,
29
30 NODE_TYPEDEF,
31 NODE_TYPEALIAS_TARGET,
32 NODE_TYPEALIAS_ALIAS,
33 NODE_TYPEALIAS,
34
35 NODE_TYPE_SPECIFIER,
36 NODE_POINTER,
37 NODE_TYPE_DECLARATOR,
38
39 NODE_FLOATING_POINT,
40 NODE_INTEGER,
41 NODE_STRING,
42 NODE_ENUMERATOR,
43 NODE_ENUM,
44 NODE_STRUCT_OR_VARIANT_DECLARATION,
45 NODE_VARIANT,
46 NODE_STRUCT,
47
48 NR_NODE_TYPES,
49 };
50
51 struct ctf_node {
52 /*
53 * Parent node is only set on demand by specific visitor.
54 */
55 struct ctf_node *parent;
56 struct cds_list_head siblings;
57 struct cds_list_head gc;
58
59 enum node_type type;
60 union {
61 struct {
62 } unknown;
63 struct {
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;
70 } root;
71 struct {
72 /*
73 * Children nodes are ctf_expression, typedef,
74 * typealias and declaration specifiers.
75 */
76 struct cds_list_head declaration_list;
77 } event;
78 struct {
79 /*
80 * Children nodes are ctf_expression, typedef,
81 * typealias and declaration specifiers.
82 */
83 struct cds_list_head declaration_list;
84 } stream;
85 struct {
86 /*
87 * Children nodes are ctf_expression, typedef,
88 * typealias and declaration specifiers.
89 */
90 struct cds_list_head declaration_list;
91 } trace;
92 struct {
93 struct ctf_node *left; /* Should be string */
94 struct ctf_node *right; /* Unary exp. or type */
95 } ctf_expression;
96 struct {
97 enum {
98 UNARY_UNKNOWN = 0,
99 UNARY_STRING,
100 UNARY_SIGNED_CONSTANT,
101 UNARY_UNSIGNED_CONSTANT,
102 UNARY_SBRAC,
103 } type;
104 union {
105 /*
106 * string for identifier, id_type, keywords,
107 * string literals and character constants.
108 */
109 char *string;
110 int64_t signed_constant;
111 uint64_t unsigned_constant;
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;
120 struct {
121 struct cds_list_head declaration_specifier;
122 struct cds_list_head type_declarators;
123 } _typedef;
124 /* new type is "alias", existing type "target" */
125 struct {
126 struct cds_list_head declaration_specifier;
127 struct cds_list_head type_declarators;
128 } typealias_target;
129 struct {
130 struct cds_list_head declaration_specifier;
131 struct cds_list_head type_declarators;
132 } typealias_alias;
133 struct {
134 struct ctf_node *target;
135 struct ctf_node *alias;
136 } typealias;
137 struct {
138 enum {
139 TYPESPEC_UNKNOWN = 0,
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,
151 TYPESPEC_CONST,
152 TYPESPEC_ID_TYPE,
153 } type;
154 const char *id_type;
155 } type_specifier;
156 struct {
157 unsigned int const_qualifier;
158 } pointer;
159 struct {
160 struct cds_list_head pointers;
161 enum {
162 TYPEDEC_UNKNOWN = 0,
163 TYPEDEC_ID, /* identifier */
164 TYPEDEC_NESTED, /* (), array or sequence */
165 } type;
166 union {
167 char *id;
168 struct {
169 /* typedec has no pointer list */
170 struct ctf_node *type_declarator;
171 /* value or first node of declaration specifier list */
172 struct ctf_node *length;
173 /* for abstract type declarator */
174 unsigned int abstract_array;
175 } nested;
176 } u;
177 struct ctf_node *bitfield_len;
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;
193 /* first node of range list or single node */
194 struct ctf_node *values;
195 } enumerator;
196 struct {
197 char *enum_id;
198 /* NULL, value or declaration specifier */
199 struct ctf_node *container_type;
200 struct cds_list_head enumerator_list;
201 } _enum;
202 struct {
203 struct cds_list_head declaration_specifier;
204 struct cds_list_head type_declarators;
205 } struct_or_variant_declaration;
206 struct {
207 char *name;
208 char *choice;
209 /* list of typedef, typealias and declarations */
210 struct cds_list_head declaration_list;
211 } variant;
212 struct {
213 char *name;
214 /* list of typedef, typealias and declarations */
215 struct cds_list_head declaration_list;
216 } _struct;
217 } u;
218 };
219
220 struct ctf_ast {
221 struct ctf_node root;
222 struct cds_list_head allocated_nodes;
223 };
224
225 int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node);
226
227 #endif /* _CTF_PARSER_H */
This page took 0.036792 seconds and 5 git commands to generate.