| 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 | // the argument for the 'yylex' function |
| 30 | #define YYLEX_PARAM ((struct ctf_scanner *) scanner)->scanner |
| 31 | |
| 32 | struct ctf_node; |
| 33 | struct ctf_parser; |
| 34 | |
| 35 | #define FOREACH_CTF_NODES(F) \ |
| 36 | F(NODE_UNKNOWN) \ |
| 37 | F(NODE_ROOT) \ |
| 38 | F(NODE_EVENT) \ |
| 39 | F(NODE_STREAM) \ |
| 40 | F(NODE_ENV) \ |
| 41 | F(NODE_TRACE) \ |
| 42 | F(NODE_CLOCK) \ |
| 43 | F(NODE_CALLSITE) \ |
| 44 | F(NODE_CTF_EXPRESSION) \ |
| 45 | F(NODE_UNARY_EXPRESSION) \ |
| 46 | F(NODE_TYPEDEF) \ |
| 47 | F(NODE_TYPEALIAS_TARGET) \ |
| 48 | F(NODE_TYPEALIAS_ALIAS) \ |
| 49 | F(NODE_TYPEALIAS) \ |
| 50 | F(NODE_TYPE_SPECIFIER) \ |
| 51 | F(NODE_TYPE_SPECIFIER_LIST) \ |
| 52 | F(NODE_POINTER) \ |
| 53 | F(NODE_TYPE_DECLARATOR) \ |
| 54 | F(NODE_FLOATING_POINT) \ |
| 55 | F(NODE_INTEGER) \ |
| 56 | F(NODE_STRING) \ |
| 57 | F(NODE_ENUMERATOR) \ |
| 58 | F(NODE_ENUM) \ |
| 59 | F(NODE_STRUCT_OR_VARIANT_DECLARATION) \ |
| 60 | F(NODE_VARIANT) \ |
| 61 | F(NODE_STRUCT) |
| 62 | |
| 63 | enum node_type { |
| 64 | #define ENTRY(S) S, |
| 65 | FOREACH_CTF_NODES(ENTRY) |
| 66 | #undef ENTRY |
| 67 | NR_NODE_TYPES, |
| 68 | }; |
| 69 | |
| 70 | struct ctf_node { |
| 71 | /* |
| 72 | * Parent node is only set on demand by specific visitor. |
| 73 | */ |
| 74 | struct ctf_node *parent; |
| 75 | struct bt_list_head siblings; |
| 76 | struct bt_list_head tmp_head; |
| 77 | struct bt_list_head gc; |
| 78 | unsigned int lineno; |
| 79 | |
| 80 | enum node_type type; |
| 81 | union { |
| 82 | struct { |
| 83 | } unknown; |
| 84 | struct { |
| 85 | /* |
| 86 | * Children nodes are ctf_expression, typedef, |
| 87 | * typealias and type_specifier_list. |
| 88 | */ |
| 89 | struct bt_list_head declaration_list; |
| 90 | struct bt_list_head trace; |
| 91 | struct bt_list_head env; |
| 92 | struct bt_list_head stream; |
| 93 | struct bt_list_head event; |
| 94 | struct bt_list_head clock; |
| 95 | struct bt_list_head callsite; |
| 96 | } root; |
| 97 | struct { |
| 98 | /* |
| 99 | * Children nodes are ctf_expression, typedef, |
| 100 | * typealias and type_specifier_list. |
| 101 | */ |
| 102 | struct bt_list_head declaration_list; |
| 103 | } event; |
| 104 | struct { |
| 105 | /* |
| 106 | * Children nodes are ctf_expression, typedef, |
| 107 | * typealias and type_specifier_list. |
| 108 | */ |
| 109 | struct bt_list_head declaration_list; |
| 110 | } stream; |
| 111 | struct { |
| 112 | /* |
| 113 | * Children nodes are ctf_expression, typedef, |
| 114 | * typealias and type_specifier_list. |
| 115 | */ |
| 116 | struct bt_list_head declaration_list; |
| 117 | } env; |
| 118 | struct { |
| 119 | /* |
| 120 | * Children nodes are ctf_expression, typedef, |
| 121 | * typealias and type_specifier_list. |
| 122 | */ |
| 123 | struct bt_list_head declaration_list; |
| 124 | } trace; |
| 125 | struct { |
| 126 | /* |
| 127 | * Children nodes are ctf_expression, typedef, |
| 128 | * typealias and type_specifier_list. |
| 129 | */ |
| 130 | struct bt_list_head declaration_list; |
| 131 | } clock; |
| 132 | struct { |
| 133 | /* |
| 134 | * Children nodes are ctf_expression, typedef, |
| 135 | * typealias and type_specifier_list. |
| 136 | */ |
| 137 | struct bt_list_head declaration_list; |
| 138 | } callsite; |
| 139 | struct { |
| 140 | struct bt_list_head left; /* Should be string */ |
| 141 | struct bt_list_head right; /* Unary exp. or type */ |
| 142 | } ctf_expression; |
| 143 | struct { |
| 144 | enum { |
| 145 | UNARY_UNKNOWN = 0, |
| 146 | UNARY_STRING, |
| 147 | UNARY_SIGNED_CONSTANT, |
| 148 | UNARY_UNSIGNED_CONSTANT, |
| 149 | UNARY_SBRAC, |
| 150 | UNARY_NESTED, |
| 151 | } type; |
| 152 | union { |
| 153 | /* |
| 154 | * string for identifier, id_type, keywords, |
| 155 | * string literals and character constants. |
| 156 | */ |
| 157 | char *string; |
| 158 | int64_t signed_constant; |
| 159 | uint64_t unsigned_constant; |
| 160 | struct ctf_node *sbrac_exp; |
| 161 | struct ctf_node *nested_exp; |
| 162 | } u; |
| 163 | enum { |
| 164 | UNARY_LINK_UNKNOWN = 0, |
| 165 | UNARY_DOTLINK, |
| 166 | UNARY_ARROWLINK, |
| 167 | UNARY_DOTDOTDOT, |
| 168 | } link; |
| 169 | } unary_expression; |
| 170 | struct { |
| 171 | struct ctf_node *type_specifier_list; |
| 172 | struct bt_list_head type_declarators; |
| 173 | } _typedef; |
| 174 | /* new type is "alias", existing type "target" */ |
| 175 | struct { |
| 176 | struct ctf_node *type_specifier_list; |
| 177 | struct bt_list_head type_declarators; |
| 178 | } typealias_target; |
| 179 | struct { |
| 180 | struct ctf_node *type_specifier_list; |
| 181 | struct bt_list_head type_declarators; |
| 182 | } typealias_alias; |
| 183 | struct { |
| 184 | struct ctf_node *target; |
| 185 | struct ctf_node *alias; |
| 186 | } typealias; |
| 187 | struct { |
| 188 | enum { |
| 189 | TYPESPEC_UNKNOWN = 0, |
| 190 | TYPESPEC_VOID, |
| 191 | TYPESPEC_CHAR, |
| 192 | TYPESPEC_SHORT, |
| 193 | TYPESPEC_INT, |
| 194 | TYPESPEC_LONG, |
| 195 | TYPESPEC_FLOAT, |
| 196 | TYPESPEC_DOUBLE, |
| 197 | TYPESPEC_SIGNED, |
| 198 | TYPESPEC_UNSIGNED, |
| 199 | TYPESPEC_BOOL, |
| 200 | TYPESPEC_COMPLEX, |
| 201 | TYPESPEC_IMAGINARY, |
| 202 | TYPESPEC_CONST, |
| 203 | TYPESPEC_ID_TYPE, |
| 204 | TYPESPEC_FLOATING_POINT, |
| 205 | TYPESPEC_INTEGER, |
| 206 | TYPESPEC_STRING, |
| 207 | TYPESPEC_STRUCT, |
| 208 | TYPESPEC_VARIANT, |
| 209 | TYPESPEC_ENUM, |
| 210 | } type; |
| 211 | /* For struct, variant and enum */ |
| 212 | struct ctf_node *node; |
| 213 | const char *id_type; |
| 214 | } type_specifier; |
| 215 | struct { |
| 216 | /* list of type_specifier */ |
| 217 | struct bt_list_head head; |
| 218 | } type_specifier_list; |
| 219 | struct { |
| 220 | unsigned int const_qualifier; |
| 221 | } pointer; |
| 222 | struct { |
| 223 | struct bt_list_head pointers; |
| 224 | enum { |
| 225 | TYPEDEC_UNKNOWN = 0, |
| 226 | TYPEDEC_ID, /* identifier */ |
| 227 | TYPEDEC_NESTED, /* (), array or sequence */ |
| 228 | } type; |
| 229 | union { |
| 230 | char *id; |
| 231 | struct { |
| 232 | /* typedec has no pointer list */ |
| 233 | struct ctf_node *type_declarator; |
| 234 | /* |
| 235 | * unary expression (value) or |
| 236 | * type_specifier_list. |
| 237 | */ |
| 238 | struct bt_list_head length; |
| 239 | /* for abstract type declarator */ |
| 240 | unsigned int abstract_array; |
| 241 | } nested; |
| 242 | } u; |
| 243 | struct ctf_node *bitfield_len; |
| 244 | } type_declarator; |
| 245 | struct { |
| 246 | /* Children nodes are ctf_expression. */ |
| 247 | struct bt_list_head expressions; |
| 248 | } floating_point; |
| 249 | struct { |
| 250 | /* Children nodes are ctf_expression. */ |
| 251 | struct bt_list_head expressions; |
| 252 | } integer; |
| 253 | struct { |
| 254 | /* Children nodes are ctf_expression. */ |
| 255 | struct bt_list_head expressions; |
| 256 | } string; |
| 257 | struct { |
| 258 | char *id; |
| 259 | /* |
| 260 | * Range list or single value node. Contains unary |
| 261 | * expressions. |
| 262 | */ |
| 263 | struct bt_list_head values; |
| 264 | } enumerator; |
| 265 | struct { |
| 266 | char *enum_id; |
| 267 | /* |
| 268 | * Either NULL, or points to unary expression or |
| 269 | * type_specifier_list. |
| 270 | */ |
| 271 | struct ctf_node *container_type; |
| 272 | struct bt_list_head enumerator_list; |
| 273 | int has_body; |
| 274 | } _enum; |
| 275 | struct { |
| 276 | struct ctf_node *type_specifier_list; |
| 277 | struct bt_list_head type_declarators; |
| 278 | } struct_or_variant_declaration; |
| 279 | struct { |
| 280 | char *name; |
| 281 | char *choice; |
| 282 | /* list of typedef, typealias and declarations */ |
| 283 | struct bt_list_head declaration_list; |
| 284 | int has_body; |
| 285 | } variant; |
| 286 | struct { |
| 287 | char *name; |
| 288 | /* list of typedef, typealias and declarations */ |
| 289 | struct bt_list_head declaration_list; |
| 290 | int has_body; |
| 291 | struct bt_list_head min_align; /* align() attribute */ |
| 292 | } _struct; |
| 293 | } u; |
| 294 | }; |
| 295 | |
| 296 | struct ctf_ast { |
| 297 | struct ctf_node root; |
| 298 | struct bt_list_head allocated_nodes; |
| 299 | }; |
| 300 | |
| 301 | const char *node_type(struct ctf_node *node); |
| 302 | |
| 303 | struct ctf_trace; |
| 304 | |
| 305 | BT_HIDDEN |
| 306 | int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node); |
| 307 | BT_HIDDEN |
| 308 | int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node); |
| 309 | BT_HIDDEN |
| 310 | int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node); |
| 311 | BT_HIDDEN |
| 312 | int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, |
| 313 | struct ctf_trace *trace, int byte_order); |
| 314 | BT_HIDDEN |
| 315 | int ctf_destroy_metadata(struct ctf_trace *trace); |
| 316 | |
| 317 | #endif /* _CTF_AST_H */ |