| 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 | 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_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 | /* |
| 53 | * Parent node is only set on demand by specific visitor. |
| 54 | */ |
| 55 | struct ctf_node *parent; |
| 56 | struct cds_list_head siblings; |
| 57 | struct cds_list_head tmp_head; |
| 58 | struct cds_list_head gc; |
| 59 | |
| 60 | enum node_type type; |
| 61 | union { |
| 62 | struct { |
| 63 | } unknown; |
| 64 | struct { |
| 65 | struct cds_list_head _typedef; |
| 66 | struct cds_list_head typealias; |
| 67 | struct cds_list_head declaration_specifier; |
| 68 | struct cds_list_head trace; |
| 69 | struct cds_list_head stream; |
| 70 | struct cds_list_head event; |
| 71 | } root; |
| 72 | struct { |
| 73 | /* |
| 74 | * Children nodes are ctf_expression, typedef, |
| 75 | * typealias and declaration specifiers. |
| 76 | */ |
| 77 | struct cds_list_head declaration_list; |
| 78 | } event; |
| 79 | struct { |
| 80 | /* |
| 81 | * Children nodes are ctf_expression, typedef, |
| 82 | * typealias and declaration specifiers. |
| 83 | */ |
| 84 | struct cds_list_head declaration_list; |
| 85 | } stream; |
| 86 | struct { |
| 87 | /* |
| 88 | * Children nodes are ctf_expression, typedef, |
| 89 | * typealias and declaration specifiers. |
| 90 | */ |
| 91 | struct cds_list_head declaration_list; |
| 92 | } trace; |
| 93 | struct { |
| 94 | struct cds_list_head left; /* Should be string */ |
| 95 | struct cds_list_head right; /* Unary exp. or type */ |
| 96 | } ctf_expression; |
| 97 | struct { |
| 98 | enum { |
| 99 | UNARY_UNKNOWN = 0, |
| 100 | UNARY_STRING, |
| 101 | UNARY_SIGNED_CONSTANT, |
| 102 | UNARY_UNSIGNED_CONSTANT, |
| 103 | UNARY_SBRAC, |
| 104 | UNARY_NESTED, |
| 105 | } type; |
| 106 | union { |
| 107 | /* |
| 108 | * string for identifier, id_type, keywords, |
| 109 | * string literals and character constants. |
| 110 | */ |
| 111 | char *string; |
| 112 | int64_t signed_constant; |
| 113 | uint64_t unsigned_constant; |
| 114 | struct ctf_node *sbrac_exp; |
| 115 | struct ctf_node *nested_exp; |
| 116 | } u; |
| 117 | enum { |
| 118 | UNARY_LINK_UNKNOWN = 0, |
| 119 | UNARY_DOTLINK, |
| 120 | UNARY_ARROWLINK, |
| 121 | UNARY_DOTDOTDOT, |
| 122 | } link; |
| 123 | } unary_expression; |
| 124 | struct { |
| 125 | struct cds_list_head declaration_specifier; |
| 126 | struct cds_list_head type_declarators; |
| 127 | } _typedef; |
| 128 | /* new type is "alias", existing type "target" */ |
| 129 | struct { |
| 130 | struct cds_list_head declaration_specifier; |
| 131 | struct cds_list_head type_declarators; |
| 132 | } typealias_target; |
| 133 | struct { |
| 134 | struct cds_list_head declaration_specifier; |
| 135 | struct cds_list_head type_declarators; |
| 136 | } typealias_alias; |
| 137 | struct { |
| 138 | struct ctf_node *target; |
| 139 | struct ctf_node *alias; |
| 140 | } typealias; |
| 141 | struct { |
| 142 | enum { |
| 143 | TYPESPEC_UNKNOWN = 0, |
| 144 | TYPESPEC_VOID, |
| 145 | TYPESPEC_CHAR, |
| 146 | TYPESPEC_SHORT, |
| 147 | TYPESPEC_INT, |
| 148 | TYPESPEC_LONG, |
| 149 | TYPESPEC_FLOAT, |
| 150 | TYPESPEC_DOUBLE, |
| 151 | TYPESPEC_SIGNED, |
| 152 | TYPESPEC_UNSIGNED, |
| 153 | TYPESPEC_BOOL, |
| 154 | TYPESPEC_COMPLEX, |
| 155 | TYPESPEC_CONST, |
| 156 | TYPESPEC_ID_TYPE, |
| 157 | } type; |
| 158 | const char *id_type; |
| 159 | } type_specifier; |
| 160 | struct { |
| 161 | unsigned int const_qualifier; |
| 162 | } pointer; |
| 163 | struct { |
| 164 | struct cds_list_head pointers; |
| 165 | enum { |
| 166 | TYPEDEC_UNKNOWN = 0, |
| 167 | TYPEDEC_ID, /* identifier */ |
| 168 | TYPEDEC_NESTED, /* (), array or sequence */ |
| 169 | } type; |
| 170 | union { |
| 171 | char *id; |
| 172 | struct { |
| 173 | /* typedec has no pointer list */ |
| 174 | struct ctf_node *type_declarator; |
| 175 | /* value or first node of declaration specifier list */ |
| 176 | struct ctf_node *length; |
| 177 | /* for abstract type declarator */ |
| 178 | unsigned int abstract_array; |
| 179 | } nested; |
| 180 | } u; |
| 181 | struct ctf_node *bitfield_len; |
| 182 | } type_declarator; |
| 183 | struct { |
| 184 | /* Children nodes are ctf_expression. */ |
| 185 | struct cds_list_head expressions; |
| 186 | } floating_point; |
| 187 | struct { |
| 188 | /* Children nodes are ctf_expression. */ |
| 189 | struct cds_list_head expressions; |
| 190 | } integer; |
| 191 | struct { |
| 192 | /* Children nodes are ctf_expression. */ |
| 193 | struct cds_list_head expressions; |
| 194 | } string; |
| 195 | struct { |
| 196 | char *id; |
| 197 | /* range list or single value node */ |
| 198 | struct cds_list_head values; |
| 199 | } enumerator; |
| 200 | struct { |
| 201 | char *enum_id; |
| 202 | /* NULL, value or declaration specifier */ |
| 203 | struct ctf_node *container_type; |
| 204 | struct cds_list_head enumerator_list; |
| 205 | } _enum; |
| 206 | struct { |
| 207 | struct cds_list_head declaration_specifier; |
| 208 | struct cds_list_head type_declarators; |
| 209 | } struct_or_variant_declaration; |
| 210 | struct { |
| 211 | char *name; |
| 212 | char *choice; |
| 213 | /* list of typedef, typealias and declarations */ |
| 214 | struct cds_list_head declaration_list; |
| 215 | } variant; |
| 216 | struct { |
| 217 | char *name; |
| 218 | /* list of typedef, typealias and declarations */ |
| 219 | struct cds_list_head declaration_list; |
| 220 | } _struct; |
| 221 | } u; |
| 222 | }; |
| 223 | |
| 224 | struct ctf_ast { |
| 225 | struct ctf_node root; |
| 226 | struct cds_list_head allocated_nodes; |
| 227 | }; |
| 228 | |
| 229 | int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node); |
| 230 | |
| 231 | #endif /* _CTF_PARSER_H */ |