ctf visitor generate I/O struct: visit typedef/typealias
[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;
6dc474b8
MD
176 /* value or first node of declaration specifier list */
177 struct ctf_node *length;
178 /* for abstract type declarator */
179 unsigned int abstract_array;
02b234c4 180 } nested;
ae5193a6 181 } u;
6dc474b8 182 struct ctf_node *bitfield_len;
ae5193a6
MD
183 } type_declarator;
184 struct {
185 /* Children nodes are ctf_expression. */
186 struct cds_list_head expressions;
187 } floating_point;
188 struct {
189 /* Children nodes are ctf_expression. */
190 struct cds_list_head expressions;
191 } integer;
192 struct {
193 /* Children nodes are ctf_expression. */
194 struct cds_list_head expressions;
195 } string;
196 struct {
197 char *id;
67905e42
MD
198 /*
199 * Range list or single value node. Contains unary
200 * expressions.
201 */
48a01768 202 struct cds_list_head values;
ae5193a6
MD
203 } enumerator;
204 struct {
205 char *enum_id;
6dc474b8
MD
206 /* NULL, value or declaration specifier */
207 struct ctf_node *container_type;
ae5193a6
MD
208 struct cds_list_head enumerator_list;
209 } _enum;
210 struct {
6dc474b8 211 struct cds_list_head declaration_specifier;
02b234c4 212 struct cds_list_head type_declarators;
ae5193a6
MD
213 } struct_or_variant_declaration;
214 struct {
6dc474b8
MD
215 char *name;
216 char *choice;
7de8808c
MD
217 /* list of typedef, typealias and declarations */
218 struct cds_list_head declaration_list;
1ee8e81d 219 int has_body;
ae5193a6
MD
220 } variant;
221 struct {
7de8808c 222 char *name;
6dc474b8 223 /* list of typedef, typealias and declarations */
ae5193a6 224 struct cds_list_head declaration_list;
1ee8e81d 225 int has_body;
ae5193a6
MD
226 } _struct;
227 } u;
8b9d5b5e
MD
228};
229
34d3acc4
MD
230struct ctf_ast {
231 struct ctf_node root;
02b234c4 232 struct cds_list_head allocated_nodes;
34d3acc4 233};
8b9d5b5e 234
34f7b02c
MD
235const char *node_type(struct ctf_node *node);
236
7de8808c 237int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node);
67905e42
MD
238int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node);
239int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node);
7de8808c 240
8b9d5b5e 241#endif /* _CTF_PARSER_H */
This page took 0.03422 seconds and 4 git commands to generate.