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