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