1 #ifndef _CTF_AST_H 2 #define _CTF_AST_H 3 4 /* 5 * ctf-ast.h 6 * 7 * Copyright 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining a copy 10 * of this software and associated documentation files (the "Software"), to deal 11 * in the Software without restriction, including without limitation the rights 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 * copies of the Software, and to permit persons to whom the Software is 14 * furnished to do so, subject to the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be included in 17 * all copies or substantial portions of the Software. 18 */ 19 20 #include <stdint.h> 21 #include <stdio.h> 22 #include <glib.h> 23 #include <babeltrace/list.h> 24 25 // the parameter name (of the reentrant 'yyparse' function) 26 // data is a pointer to a 'SParserParam' structure 27 //#define YYPARSE_PARAM scanner 28 29 struct ctf_node; 30 struct ctf_parser; 31 32 #define FOREACH_CTF_NODES(F) \ 33 F(NODE_UNKNOWN) \ 34 F(NODE_ROOT) \ 35 F(NODE_ERROR) \ 36 F(NODE_EVENT) \ 37 F(NODE_STREAM) \ 38 F(NODE_ENV) \ 39 F(NODE_TRACE) \ 40 F(NODE_CLOCK) \ 41 F(NODE_CALLSITE) \ 42 F(NODE_CTF_EXPRESSION) \ 43 F(NODE_UNARY_EXPRESSION) \ 44 F(NODE_TYPEDEF) \ 45 F(NODE_TYPEALIAS_TARGET) \ 46 F(NODE_TYPEALIAS_ALIAS) \ 47 F(NODE_TYPEALIAS) \ 48 F(NODE_TYPE_SPECIFIER) \ 49 F(NODE_TYPE_SPECIFIER_LIST) \ 50 F(NODE_POINTER) \ 51 F(NODE_TYPE_DECLARATOR) \ 52 F(NODE_FLOATING_POINT) \ 53 F(NODE_INTEGER) \ 54 F(NODE_STRING) \ 55 F(NODE_ENUMERATOR) \ 56 F(NODE_ENUM) \ 57 F(NODE_STRUCT_OR_VARIANT_DECLARATION) \ 58 F(NODE_VARIANT) \ 59 F(NODE_STRUCT) 60 61 enum node_type { 62 #define ENTRY(S) S, 63 FOREACH_CTF_NODES(ENTRY) 64 #undef ENTRY 65 NR_NODE_TYPES, 66 }; 67 68 struct ctf_node { 69 /* 70 * Parent node is only set on demand by specific visitor. 71 */ 72 struct ctf_node *parent; 73 struct bt_list_head siblings; 74 struct bt_list_head tmp_head; 75 unsigned int lineno; 76 /* 77 * We mark nodes visited in the generate-io-struct phase (last 78 * phase). We only mark the 1-depth level nodes as visited 79 * (never the root node, and not their sub-nodes). This allows 80 * skipping already visited nodes when doing incremental 81 * metadata append. 82 */ 83 int visited; 84 85 enum node_type type; 86 union { 87 struct { 88 } unknown; 89 struct { 90 /* 91 * Children nodes are ctf_expression, typedef, 92 * typealias and type_specifier_list. 93 */ 94 struct bt_list_head declaration_list; 95 struct bt_list_head trace; 96 struct bt_list_head env; 97 struct bt_list_head stream; 98 struct bt_list_head event; 99 struct bt_list_head clock; 100 struct bt_list_head callsite; 101 } root; 102 struct { 103 /* 104 * Children nodes are ctf_expression, typedef, 105 * typealias and type_specifier_list. 106 */ 107 struct bt_list_head declaration_list; 108 } event; 109 struct { 110 /* 111 * Children nodes are ctf_expression, typedef, 112 * typealias and type_specifier_list. 113 */ 114 struct bt_list_head declaration_list; 115 } stream; 116 struct { 117 /* 118 * Children nodes are ctf_expression, typedef, 119 * typealias and type_specifier_list. 120 */ 121 struct bt_list_head declaration_list; 122 } env; 123 struct { 124 /* 125 * Children nodes are ctf_expression, typedef, 126 * typealias and type_specifier_list. 127 */ 128 struct bt_list_head declaration_list; 129 } trace; 130 struct { 131 /* 132 * Children nodes are ctf_expression, typedef, 133 * typealias and type_specifier_list. 134 */ 135 struct bt_list_head declaration_list; 136 } clock; 137 struct { 138 /* 139 * Children nodes are ctf_expression, typedef, 140 * typealias and type_specifier_list. 141 */ 142 struct bt_list_head declaration_list; 143 } callsite; 144 struct { 145 struct bt_list_head left; /* Should be string */ 146 struct bt_list_head right; /* Unary exp. or type */ 147 } ctf_expression; 148 struct { 149 enum { 150 UNARY_UNKNOWN = 0, 151 UNARY_STRING, 152 UNARY_SIGNED_CONSTANT, 153 UNARY_UNSIGNED_CONSTANT, 154 UNARY_SBRAC, 155 } type; 156 union { 157 /* 158 * string for identifier, id_type, keywords, 159 * string literals and character constants. 160 */ 161 char *string; 162 int64_t signed_constant; 163 uint64_t unsigned_constant; 164 struct ctf_node *sbrac_exp; 165 } u; 166 enum { 167 UNARY_LINK_UNKNOWN = 0, 168 UNARY_DOTLINK, 169 UNARY_ARROWLINK, 170 UNARY_DOTDOTDOT, 171 } link; 172 } unary_expression; 173 struct { 174 struct ctf_node *type_specifier_list; 175 struct bt_list_head type_declarators; 176 } _typedef; 177 /* new type is "alias", existing type "target" */ 178 struct { 179 struct ctf_node *type_specifier_list; 180 struct bt_list_head type_declarators; 181 } typealias_target; 182 struct { 183 struct ctf_node *type_specifier_list; 184 struct bt_list_head type_declarators; 185 } typealias_alias; 186 struct { 187 struct ctf_node *target; 188 struct ctf_node *alias; 189 } typealias; 190 struct { 191 enum { 192 TYPESPEC_UNKNOWN = 0, 193 TYPESPEC_VOID, 194 TYPESPEC_CHAR, 195 TYPESPEC_SHORT, 196 TYPESPEC_INT, 197 TYPESPEC_LONG, 198 TYPESPEC_FLOAT, 199 TYPESPEC_DOUBLE, 200 TYPESPEC_SIGNED, 201 TYPESPEC_UNSIGNED, 202 TYPESPEC_BOOL, 203 TYPESPEC_COMPLEX, 204 TYPESPEC_IMAGINARY, 205 TYPESPEC_CONST, 206 TYPESPEC_ID_TYPE, 207 TYPESPEC_FLOATING_POINT, 208 TYPESPEC_INTEGER, 209 TYPESPEC_STRING, 210 TYPESPEC_STRUCT, 211 TYPESPEC_VARIANT, 212 TYPESPEC_ENUM, 213 } type; 214 /* For struct, variant and enum */ 215 struct ctf_node *node; 216 const char *id_type; 217 } type_specifier; 218 struct { 219 /* list of type_specifier */ 220 struct bt_list_head head; 221 } type_specifier_list; 222 struct { 223 unsigned int const_qualifier; 224 } pointer; 225 struct { 226 struct bt_list_head pointers; 227 enum { 228 TYPEDEC_UNKNOWN = 0, 229 TYPEDEC_ID, /* identifier */ 230 TYPEDEC_NESTED, /* (), array or sequence */ 231 } type; 232 union { 233 char *id; 234 struct { 235 /* typedec has no pointer list */ 236 struct ctf_node *type_declarator; 237 /* 238 * unary expression (value) or 239 * type_specifier_list. 240 */ 241 struct bt_list_head length; 242 /* for abstract type declarator */ 243 unsigned int abstract_array; 244 } nested; 245 } u; 246 struct ctf_node *bitfield_len; 247 } type_declarator; 248 struct { 249 /* Children nodes are ctf_expression. */ 250 struct bt_list_head expressions; 251 } floating_point; 252 struct { 253 /* Children nodes are ctf_expression. */ 254 struct bt_list_head expressions; 255 } integer; 256 struct { 257 /* Children nodes are ctf_expression. */ 258 struct bt_list_head expressions; 259 } string; 260 struct { 261 char *id; 262 /* 263 * Range list or single value node. Contains unary 264 * expressions. 265 */ 266 struct bt_list_head values; 267 } enumerator; 268 struct { 269 char *enum_id; 270 /* 271 * Either NULL, or points to unary expression or 272 * type_specifier_list. 273 */ 274 struct ctf_node *container_type; 275 struct bt_list_head enumerator_list; 276 int has_body; 277 } _enum; 278 struct { 279 struct ctf_node *type_specifier_list; 280 struct bt_list_head type_declarators; 281 } struct_or_variant_declaration; 282 struct { 283 char *name; 284 char *choice; 285 /* list of typedef, typealias and declarations */ 286 struct bt_list_head declaration_list; 287 int has_body; 288 } variant; 289 struct { 290 char *name; 291 /* list of typedef, typealias and declarations */ 292 struct bt_list_head declaration_list; 293 int has_body; 294 struct bt_list_head min_align; /* align() attribute */ 295 } _struct; 296 } u; 297 }; 298 299 struct ctf_ast { 300 struct ctf_node root; 301 }; 302 303 const char *node_type(struct ctf_node *node); 304 305 struct ctf_trace; 306 307 BT_HIDDEN 308 int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node); 309 BT_HIDDEN 310 int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node); 311 BT_HIDDEN 312 int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node); 313 BT_HIDDEN 314 int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, 315 struct ctf_trace *trace, int byte_order); 316 BT_HIDDEN 317 int ctf_destroy_metadata(struct ctf_trace *trace); 318 319 #endif /* _CTF_AST_H */ 320