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