| 1 | #ifndef _CTF_PARSER_H |
| 2 | #define _CTF_PARSER_H |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | #include <helpers/list.h> |
| 6 | #include <stdio.h> |
| 7 | #include <glib.h> |
| 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; |
| 18 | |
| 19 | enum node_type { |
| 20 | NODE_UNKNOWN = 0, |
| 21 | NODE_ROOT, |
| 22 | |
| 23 | NODE_EVENT, |
| 24 | NODE_STREAM, |
| 25 | NODE_TRACE, |
| 26 | |
| 27 | NODE_CTF_EXPRESSION, |
| 28 | |
| 29 | NODE_TYPEDEF, |
| 30 | NODE_TYPEALIAS_TARGET, |
| 31 | NODE_TYPEALIAS_ALIAS, |
| 32 | NODE_TYPEALIAS, |
| 33 | |
| 34 | NODE_TYPE_SPECIFIER, |
| 35 | NODE_DECLARATION_SPECIFIER, |
| 36 | NODE_POINTER, |
| 37 | NODE_TYPE_DECLARATOR, |
| 38 | |
| 39 | NODE_FLOATING_POINT, |
| 40 | NODE_INTEGER, |
| 41 | NODE_STRING, |
| 42 | NODE_ENUMERATOR, |
| 43 | NODE_ENUM, |
| 44 | NODE_STRUCT_OR_VARIANT_DECLARATION, |
| 45 | NODE_VARIANT, |
| 46 | NODE_STRUCT, |
| 47 | |
| 48 | NR_NODE_TYPES, |
| 49 | }; |
| 50 | |
| 51 | struct ctf_node { |
| 52 | struct ctf_node *parent; |
| 53 | struct cds_list_head siblings; |
| 54 | struct cds_list_head gc; |
| 55 | |
| 56 | enum node_type type; |
| 57 | union { |
| 58 | struct { |
| 59 | } unknown; |
| 60 | struct { |
| 61 | struct cds_list_head _typedef; |
| 62 | struct cds_list_head typealias; |
| 63 | struct cds_list_head declaration_specifier; |
| 64 | struct cds_list_head trace; |
| 65 | struct cds_list_head stream; |
| 66 | struct cds_list_head event; |
| 67 | } root; |
| 68 | struct { |
| 69 | /* |
| 70 | * Children nodes are ctf_expression, typedef or |
| 71 | * typealias. |
| 72 | */ |
| 73 | struct cds_list_head _typedef; |
| 74 | struct cds_list_head typealias; |
| 75 | struct cds_list_head ctf_expression; |
| 76 | struct cds_list_head declaration_specifier; |
| 77 | } event; |
| 78 | struct { |
| 79 | /* |
| 80 | * Children nodes are ctf_expression, typedef or |
| 81 | * typealias. |
| 82 | */ |
| 83 | struct cds_list_head _typedef; |
| 84 | struct cds_list_head typealias; |
| 85 | struct cds_list_head ctf_expression; |
| 86 | struct cds_list_head declaration_specifier; |
| 87 | } stream; |
| 88 | struct { |
| 89 | /* |
| 90 | * Children nodes are ctf_expression, typedef or |
| 91 | * typealias. |
| 92 | */ |
| 93 | struct cds_list_head _typedef; |
| 94 | struct cds_list_head typealias; |
| 95 | struct cds_list_head ctf_expression; |
| 96 | struct cds_list_head declaration_specifier; |
| 97 | } trace; |
| 98 | struct { |
| 99 | char *left_id; |
| 100 | enum { |
| 101 | EXP_UNKNOWN = 0, |
| 102 | EXP_ID, |
| 103 | EXP_TYPE, |
| 104 | } type; |
| 105 | union { |
| 106 | char *id; |
| 107 | struct ctf_node *type; |
| 108 | } right; |
| 109 | } ctf_expression; |
| 110 | struct { |
| 111 | struct ctf_node *declaration_specifier; |
| 112 | struct cds_list_head type_declarators; |
| 113 | } _typedef; |
| 114 | /* new type is "alias", existing type "target" */ |
| 115 | struct { |
| 116 | struct ctf_node *declaration_specifier; |
| 117 | struct cds_list_head type_declarators; |
| 118 | } typealias_target; |
| 119 | struct { |
| 120 | struct ctf_node *declaration_specifier; |
| 121 | struct cds_list_head type_declarators; |
| 122 | } typealias_alias; |
| 123 | struct { |
| 124 | struct ctf_node *target; |
| 125 | struct ctf_node *alias; |
| 126 | } typealias; |
| 127 | struct { |
| 128 | enum { |
| 129 | TYPESPEC_UNKNOWN = 0, |
| 130 | TYPESPEC_VOID, |
| 131 | TYPESPEC_CHAR, |
| 132 | TYPESPEC_SHORT, |
| 133 | TYPESPEC_INT, |
| 134 | TYPESPEC_LONG, |
| 135 | TYPESPEC_FLOAT, |
| 136 | TYPESPEC_DOUBLE, |
| 137 | TYPESPEC_SIGNED, |
| 138 | TYPESPEC_UNSIGNED, |
| 139 | TYPESPEC_BOOL, |
| 140 | TYPESPEC_COMPLEX, |
| 141 | TYPESPEC_ID_TYPE, |
| 142 | |
| 143 | TYPESPEC_FLOATING_POINT, |
| 144 | TYPESPEC_INTEGER, |
| 145 | TYPESPEC_STRING, |
| 146 | TYPESPEC_ENUM, |
| 147 | TYPESPEC_VARIANT, |
| 148 | TYPESPEC_STRUCT, |
| 149 | } type; |
| 150 | union { |
| 151 | struct ctf_node *floating_point; |
| 152 | struct ctf_node *integer; |
| 153 | struct ctf_node *string; |
| 154 | struct ctf_node *_enum; |
| 155 | struct ctf_node *variant; |
| 156 | struct ctf_node *_struct; |
| 157 | } u; |
| 158 | } type_specifier; |
| 159 | struct { |
| 160 | /* drop "const" specifier */ |
| 161 | /* Children nodes are type_specifiers */ |
| 162 | struct cds_list_head type_specifiers; |
| 163 | } declaration_specifier; |
| 164 | struct { |
| 165 | } pointer; |
| 166 | struct { |
| 167 | struct cds_list_head pointers; |
| 168 | enum { |
| 169 | TYPEDEC_UNKNOWN = 0, |
| 170 | TYPEDEC_ID, /* identifier */ |
| 171 | TYPEDEC_NESTED, /* (), array or sequence */ |
| 172 | } type; |
| 173 | union { |
| 174 | char *id; |
| 175 | struct { |
| 176 | /* typedec has no pointer list */ |
| 177 | struct ctf_node *type_declarator; |
| 178 | struct { |
| 179 | enum { |
| 180 | TYPEDEC_TYPE_UNKNOWN = 0, |
| 181 | TYPEDEC_TYPE_VALUE, /* must be > 0 */ |
| 182 | TYPEDEC_TYPE_TYPE, |
| 183 | } type; |
| 184 | union { |
| 185 | uint64_t value; |
| 186 | struct ctf_node *declaration_specifier; |
| 187 | } u; |
| 188 | } length; |
| 189 | } nested; |
| 190 | } u; |
| 191 | } type_declarator; |
| 192 | struct { |
| 193 | /* Children nodes are ctf_expression. */ |
| 194 | struct cds_list_head expressions; |
| 195 | } floating_point; |
| 196 | struct { |
| 197 | /* Children nodes are ctf_expression. */ |
| 198 | struct cds_list_head expressions; |
| 199 | } integer; |
| 200 | struct { |
| 201 | /* Children nodes are ctf_expression. */ |
| 202 | struct cds_list_head expressions; |
| 203 | } string; |
| 204 | struct { |
| 205 | char *id; |
| 206 | union { /* inclusive start/end of range */ |
| 207 | struct { |
| 208 | int64_t start, end; |
| 209 | } _signed; |
| 210 | struct { |
| 211 | uint64_t start, end; |
| 212 | } _unsigned; |
| 213 | } u; |
| 214 | } enumerator; |
| 215 | struct { |
| 216 | char *enum_id; |
| 217 | struct { |
| 218 | enum { |
| 219 | ENUM_TYPE_UNKNOWN = 0, |
| 220 | ENUM_TYPE_VALUE, /* must be > 0 */ |
| 221 | ENUM_TYPE_TYPE, |
| 222 | } type; |
| 223 | union { |
| 224 | uint64_t value; |
| 225 | struct ctf_node *declaration_specifier; |
| 226 | } u; |
| 227 | } container_type; |
| 228 | struct cds_list_head enumerator_list; |
| 229 | } _enum; |
| 230 | struct { |
| 231 | struct ctf_node *declaration_specifier; |
| 232 | struct cds_list_head type_declarators; |
| 233 | } struct_or_variant_declaration; |
| 234 | struct { |
| 235 | struct cds_list_head _typedef; |
| 236 | struct cds_list_head typealias; |
| 237 | struct cds_list_head declaration_list; |
| 238 | } variant; |
| 239 | struct { |
| 240 | struct cds_list_head _typedef; |
| 241 | struct cds_list_head typealias; |
| 242 | struct cds_list_head declaration_list; |
| 243 | } _struct; |
| 244 | } u; |
| 245 | }; |
| 246 | |
| 247 | struct ctf_ast { |
| 248 | struct ctf_node root; |
| 249 | struct cds_list_head allocated_nodes; |
| 250 | }; |
| 251 | |
| 252 | #endif /* _CTF_PARSER_H */ |