Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1 | %{ |
| 2 | |
| 3 | /** |
| 4 | * Thrift parser. |
| 5 | * |
| 6 | * This parser is used on a thrift definition file. |
| 7 | * |
| 8 | * @author Mark Slee <mcslee@facebook.com> |
| 9 | */ |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include "main.h" |
| 13 | #include "globals.h" |
| 14 | #include "parse/t_program.h" |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 15 | #include "parse/t_scope.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 16 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 17 | /** |
| 18 | * This global variable is used for automatic numbering of field indices etc. |
| 19 | * when parsing the members of a struct. Field values are automatically |
| 20 | * assigned starting from -1 and working their way down. |
| 21 | */ |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 22 | int y_field_val = -1; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 23 | |
| 24 | %} |
| 25 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 26 | /** |
| 27 | * This structure is used by the parser to hold the data types associated with |
| 28 | * various parse nodes. |
| 29 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 30 | %union { |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 31 | char* id; |
| 32 | int iconst; |
| 33 | double dconst; |
| 34 | bool tbool; |
| 35 | t_type* ttype; |
| 36 | t_typedef* ttypedef; |
| 37 | t_enum* tenum; |
| 38 | t_enum_value* tenumv; |
| 39 | t_const* tconst; |
| 40 | t_const_value* tconstv; |
| 41 | t_struct* tstruct; |
| 42 | t_service* tservice; |
| 43 | t_function* tfunction; |
| 44 | t_field* tfield; |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 45 | char* tdoc; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 48 | /** |
| 49 | * Strings identifier |
| 50 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 51 | %token<id> tok_identifier |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 52 | %token<id> tok_literal |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 53 | %token<tdoc> tok_doctext |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 54 | |
| 55 | /** |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 56 | * Constant values |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 57 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 58 | %token<iconst> tok_int_constant |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 59 | %token<dconst> tok_dub_constant |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 60 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 61 | /** |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 62 | * Header keywoards |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 63 | */ |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 64 | %token tok_include |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 65 | %token tok_namespace |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 66 | %token tok_cpp_namespace |
| 67 | %token tok_cpp_include |
| 68 | %token tok_cpp_type |
Mark Slee | e888b37 | 2007-01-12 01:06:24 +0000 | [diff] [blame] | 69 | %token tok_php_namespace |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 70 | %token tok_java_package |
Mark Slee | 782abbb | 2007-01-19 00:17:02 +0000 | [diff] [blame] | 71 | %token tok_xsd_all |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 72 | %token tok_xsd_optional |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 73 | %token tok_xsd_nillable |
Mark Slee | 0d9199e | 2007-01-31 02:08:30 +0000 | [diff] [blame] | 74 | %token tok_xsd_namespace |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 75 | %token tok_xsd_attrs |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 76 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 77 | /** |
| 78 | * Base datatype keywords |
| 79 | */ |
| 80 | %token tok_void |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 81 | %token tok_bool |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 82 | %token tok_byte |
| 83 | %token tok_string |
Mark Slee | b6200d8 | 2007-01-19 19:14:36 +0000 | [diff] [blame] | 84 | %token tok_slist |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 85 | %token tok_i16 |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 86 | %token tok_i32 |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 87 | %token tok_i64 |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 88 | %token tok_double |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 89 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 90 | /** |
| 91 | * Complex type keywords |
| 92 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 93 | %token tok_map |
| 94 | %token tok_list |
| 95 | %token tok_set |
| 96 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 97 | /** |
| 98 | * Function modifiers |
| 99 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 100 | %token tok_async |
| 101 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 102 | /** |
| 103 | * Thrift language keywords |
| 104 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 105 | %token tok_typedef |
| 106 | %token tok_struct |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 107 | %token tok_xception |
| 108 | %token tok_throws |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 109 | %token tok_extends |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 110 | %token tok_service |
| 111 | %token tok_enum |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 112 | %token tok_const |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 113 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 114 | /** |
| 115 | * Grammar nodes |
| 116 | */ |
| 117 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 118 | %type<ttype> BaseType |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 119 | %type<ttype> ContainerType |
| 120 | %type<ttype> MapType |
| 121 | %type<ttype> SetType |
| 122 | %type<ttype> ListType |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 123 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 124 | %type<ttype> TypeDefinition |
| 125 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 126 | %type<ttypedef> Typedef |
| 127 | %type<ttype> DefinitionType |
| 128 | |
| 129 | %type<tfield> Field |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 130 | %type<iconst> FieldIdentifier |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 131 | %type<ttype> FieldType |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 132 | %type<tconstv> FieldValue |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 133 | %type<tstruct> FieldList |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 134 | |
| 135 | %type<tenum> Enum |
| 136 | %type<tenum> EnumDefList |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 137 | %type<tenumv> EnumDef |
| 138 | |
| 139 | %type<tconst> Const |
| 140 | %type<tconstv> ConstValue |
| 141 | %type<tconstv> ConstList |
| 142 | %type<tconstv> ConstListContents |
| 143 | %type<tconstv> ConstMap |
| 144 | %type<tconstv> ConstMapContents |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 145 | |
| 146 | %type<tstruct> Struct |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 147 | %type<tstruct> Xception |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 148 | %type<tservice> Service |
| 149 | |
| 150 | %type<tfunction> Function |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 151 | %type<ttype> FunctionType |
| 152 | %type<tservice> FunctionList |
| 153 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 154 | %type<tstruct> Throws |
| 155 | %type<tservice> Extends |
| 156 | %type<tbool> Async |
| 157 | %type<tbool> XsdAll |
| 158 | %type<tbool> XsdOptional |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 159 | %type<tbool> XsdNillable |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame^] | 160 | %type<tstruct> XsdAttributes |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 161 | %type<id> CppType |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 162 | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 163 | %type<tdoc> DocTextOptional |
| 164 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 165 | %% |
| 166 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 167 | /** |
| 168 | * Thrift Grammar Implementation. |
| 169 | * |
| 170 | * For the most part this source file works its way top down from what you |
| 171 | * might expect to find in a typical .thrift file, i.e. type definitions and |
| 172 | * namespaces up top followed by service definitions using those types. |
| 173 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 174 | |
| 175 | Program: |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 176 | HeaderList DefinitionList |
| 177 | { |
| 178 | pdebug("Program -> Headers DefinitionList"); |
| 179 | } |
| 180 | |
| 181 | HeaderList: |
| 182 | HeaderList Header |
| 183 | { |
| 184 | pdebug("HeaderList -> HeaderList Header"); |
| 185 | } |
| 186 | | |
| 187 | { |
| 188 | pdebug("HeaderList -> "); |
| 189 | } |
| 190 | |
| 191 | Header: |
| 192 | Include |
| 193 | { |
| 194 | pdebug("Header -> Include"); |
| 195 | } |
| 196 | | tok_namespace tok_identifier |
| 197 | { |
| 198 | pwarning(1, "'namespace' is deprecated. Use 'cpp_namespace' and/or 'java_package' instead"); |
| 199 | if (g_parse_mode == PROGRAM) { |
| 200 | g_program->set_cpp_namespace($2); |
| 201 | g_program->set_java_package($2); |
| 202 | } |
| 203 | } |
| 204 | | tok_cpp_namespace tok_identifier |
| 205 | { |
| 206 | pdebug("Header -> tok_cpp_namespace tok_identifier"); |
| 207 | if (g_parse_mode == PROGRAM) { |
| 208 | g_program->set_cpp_namespace($2); |
| 209 | } |
| 210 | } |
| 211 | | tok_cpp_include tok_literal |
| 212 | { |
| 213 | pdebug("Header -> tok_cpp_include tok_literal"); |
| 214 | if (g_parse_mode == PROGRAM) { |
| 215 | g_program->add_cpp_include($2); |
| 216 | } |
| 217 | } |
Mark Slee | e888b37 | 2007-01-12 01:06:24 +0000 | [diff] [blame] | 218 | | tok_php_namespace tok_identifier |
| 219 | { |
| 220 | pdebug("Header -> tok_php_namespace tok_identifier"); |
| 221 | if (g_parse_mode == PROGRAM) { |
| 222 | g_program->set_php_namespace($2); |
| 223 | } |
| 224 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 225 | | tok_java_package tok_identifier |
| 226 | { |
| 227 | pdebug("Header -> tok_java_package tok_identifier"); |
| 228 | if (g_parse_mode == PROGRAM) { |
| 229 | g_program->set_java_package($2); |
| 230 | } |
| 231 | } |
Mark Slee | 0d9199e | 2007-01-31 02:08:30 +0000 | [diff] [blame] | 232 | | tok_xsd_namespace tok_literal |
| 233 | { |
| 234 | pdebug("Header -> tok_xsd_namespace tok_literal"); |
| 235 | if (g_parse_mode == PROGRAM) { |
| 236 | g_program->set_xsd_namespace($2); |
| 237 | } |
| 238 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 239 | |
| 240 | Include: |
| 241 | tok_include tok_literal |
| 242 | { |
| 243 | pdebug("Include -> tok_include tok_literal"); |
| 244 | if (g_parse_mode == INCLUDES) { |
| 245 | std::string path = include_file(std::string($2)); |
| 246 | if (!path.empty()) { |
| 247 | g_program->add_include(path); |
| 248 | } |
| 249 | } |
| 250 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 251 | |
| 252 | DefinitionList: |
| 253 | DefinitionList Definition |
| 254 | { |
| 255 | pdebug("DefinitionList -> DefinitionList Definition"); |
| 256 | } |
| 257 | | |
| 258 | { |
| 259 | pdebug("DefinitionList -> "); |
| 260 | } |
| 261 | |
| 262 | Definition: |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 263 | Const |
| 264 | { |
| 265 | pdebug("Definition -> Const"); |
| 266 | if (g_parse_mode == PROGRAM) { |
| 267 | g_program->add_const($1); |
| 268 | } |
| 269 | } |
| 270 | | TypeDefinition |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 271 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 272 | pdebug("Definition -> TypeDefinition"); |
| 273 | if (g_parse_mode == PROGRAM) { |
| 274 | g_scope->add_type($1->get_name(), $1); |
| 275 | if (g_parent_scope != NULL) { |
| 276 | g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1); |
| 277 | } |
| 278 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 279 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 280 | | Service |
| 281 | { |
| 282 | pdebug("Definition -> Service"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 283 | if (g_parse_mode == PROGRAM) { |
| 284 | g_scope->add_service($1->get_name(), $1); |
| 285 | if (g_parent_scope != NULL) { |
| 286 | g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1); |
| 287 | } |
| 288 | g_program->add_service($1); |
| 289 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 292 | TypeDefinition: |
| 293 | Typedef |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 294 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 295 | pdebug("TypeDefinition -> Typedef"); |
| 296 | if (g_parse_mode == PROGRAM) { |
| 297 | g_program->add_typedef($1); |
| 298 | } |
| 299 | } |
| 300 | | Enum |
| 301 | { |
| 302 | pdebug("TypeDefinition -> Enum"); |
| 303 | if (g_parse_mode == PROGRAM) { |
| 304 | g_program->add_enum($1); |
| 305 | } |
| 306 | } |
| 307 | | Struct |
| 308 | { |
| 309 | pdebug("TypeDefinition -> Struct"); |
| 310 | if (g_parse_mode == PROGRAM) { |
| 311 | g_program->add_struct($1); |
| 312 | } |
| 313 | } |
| 314 | | Xception |
| 315 | { |
| 316 | pdebug("TypeDefinition -> Xception"); |
| 317 | if (g_parse_mode == PROGRAM) { |
| 318 | g_program->add_xception($1); |
| 319 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 320 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 321 | |
| 322 | Typedef: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 323 | DocTextOptional tok_typedef DefinitionType tok_identifier |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 324 | { |
| 325 | pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 326 | t_typedef *td = new t_typedef(g_program, $3, $4); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 327 | $$ = td; |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 328 | if ($1 != NULL) { |
| 329 | td->set_doc($1); |
| 330 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 331 | } |
| 332 | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 333 | DocTextOptional: |
| 334 | tok_doctext |
| 335 | { |
| 336 | pdebug("DocTextOptional -> tok_doctext"); |
| 337 | $$ = $1; |
| 338 | } |
| 339 | | |
| 340 | { |
| 341 | $$ = NULL; |
| 342 | } |
| 343 | |
| 344 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 345 | Enum: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 346 | DocTextOptional tok_enum tok_identifier '{' EnumDefList '}' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 347 | { |
| 348 | pdebug("Enum -> tok_enum tok_identifier { EnumDefList }"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 349 | $$ = $5; |
| 350 | $$->set_name($3); |
| 351 | if ($1 != NULL) { |
| 352 | $$->set_doc($1); |
| 353 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 356 | CommaOrSemicolonOptional: |
| 357 | ',' |
| 358 | {} |
| 359 | | ';' |
| 360 | {} |
| 361 | | |
| 362 | {} |
| 363 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 364 | EnumDefList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 365 | EnumDefList EnumDef |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 366 | { |
| 367 | pdebug("EnumDefList -> EnumDefList EnumDef"); |
| 368 | $$ = $1; |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 369 | $$->append($2); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 370 | } |
| 371 | | |
| 372 | { |
| 373 | pdebug("EnumDefList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 374 | $$ = new t_enum(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | EnumDef: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 378 | DocTextOptional tok_identifier '=' tok_int_constant CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 379 | { |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 380 | pdebug("EnumDef -> tok_identifier = tok_int_constant"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 381 | if ($4 < 0) { |
| 382 | pwarning(1, "Negative value supplied for enum %s.\n", $2); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 383 | } |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 384 | $$ = new t_enum_value($2, $4); |
| 385 | if ($1 != NULL) { |
| 386 | $$->set_doc($1); |
| 387 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 388 | } |
| 389 | | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 390 | DocTextOptional tok_identifier CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 391 | { |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 392 | pdebug("EnumDef -> tok_identifier"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 393 | $$ = new t_enum_value($2); |
| 394 | if ($1 != NULL) { |
| 395 | $$->set_doc($1); |
| 396 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | Const: |
| 400 | tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional |
| 401 | { |
| 402 | pdebug("Const -> tok_const FieldType tok_identifier = ConstValue"); |
Mark Slee | aa7671d | 2006-11-29 03:19:31 +0000 | [diff] [blame] | 403 | if (g_parse_mode == PROGRAM) { |
| 404 | $$ = new t_const($2, $3, $5); |
| 405 | validate_const_type($$); |
| 406 | } else { |
| 407 | $$ = NULL; |
| 408 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | ConstValue: |
| 412 | tok_int_constant |
| 413 | { |
| 414 | pdebug("ConstValue => tok_int_constant"); |
| 415 | $$ = new t_const_value(); |
| 416 | $$->set_integer($1); |
| 417 | } |
| 418 | | tok_dub_constant |
| 419 | { |
| 420 | pdebug("ConstValue => tok_dub_constant"); |
| 421 | $$ = new t_const_value(); |
| 422 | $$->set_double($1); |
| 423 | } |
| 424 | | tok_literal |
| 425 | { |
| 426 | pdebug("ConstValue => tok_literal"); |
| 427 | $$ = new t_const_value(); |
| 428 | $$->set_string($1); |
| 429 | } |
Mark Slee | 67fc634 | 2006-11-29 03:37:04 +0000 | [diff] [blame] | 430 | | tok_identifier |
| 431 | { |
| 432 | pdebug("ConstValue => tok_identifier"); |
| 433 | $$ = new t_const_value(); |
| 434 | $$->set_string($1); |
| 435 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 436 | | ConstList |
| 437 | { |
| 438 | pdebug("ConstValue => ConstList"); |
| 439 | $$ = $1; |
| 440 | } |
| 441 | | ConstMap |
| 442 | { |
| 443 | pdebug("ConstValue => ConstMap"); |
| 444 | $$ = $1; |
| 445 | } |
| 446 | |
| 447 | ConstList: |
| 448 | '[' ConstListContents ']' |
| 449 | { |
| 450 | pdebug("ConstList => [ ConstListContents ]"); |
| 451 | $$ = $2; |
| 452 | } |
| 453 | |
| 454 | ConstListContents: |
| 455 | ConstListContents ConstValue CommaOrSemicolonOptional |
| 456 | { |
| 457 | pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional"); |
| 458 | $$ = $1; |
| 459 | $$->add_list($2); |
| 460 | } |
| 461 | | |
| 462 | { |
| 463 | pdebug("ConstListContents =>"); |
| 464 | $$ = new t_const_value(); |
| 465 | $$->set_list(); |
| 466 | } |
| 467 | |
| 468 | ConstMap: |
| 469 | '{' ConstMapContents '}' |
| 470 | { |
| 471 | pdebug("ConstMap => { ConstMapContents }"); |
| 472 | $$ = $2; |
| 473 | } |
| 474 | |
| 475 | ConstMapContents: |
| 476 | ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional |
| 477 | { |
| 478 | pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional"); |
| 479 | $$ = $1; |
| 480 | $$->add_map($2, $4); |
| 481 | } |
| 482 | | |
| 483 | { |
| 484 | pdebug("ConstMapContents =>"); |
| 485 | $$ = new t_const_value(); |
| 486 | $$->set_map(); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | Struct: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 490 | DocTextOptional tok_struct tok_identifier XsdAll '{' FieldList '}' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 491 | { |
| 492 | pdebug("Struct -> tok_struct tok_identifier { FieldList }"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 493 | $6->set_name($3); |
| 494 | if ($1 != NULL) { |
| 495 | $6->set_doc($1); |
| 496 | } |
| 497 | $6->set_xsd_all($4); |
| 498 | $$ = $6; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 499 | y_field_val = -1; |
| 500 | } |
| 501 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 502 | XsdAll: |
Mark Slee | 782abbb | 2007-01-19 00:17:02 +0000 | [diff] [blame] | 503 | tok_xsd_all |
| 504 | { |
| 505 | $$ = true; |
| 506 | } |
| 507 | | |
| 508 | { |
| 509 | $$ = false; |
| 510 | } |
| 511 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 512 | XsdOptional: |
| 513 | tok_xsd_optional |
| 514 | { |
| 515 | $$ = true; |
| 516 | } |
| 517 | | |
| 518 | { |
| 519 | $$ = false; |
| 520 | } |
| 521 | |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 522 | XsdNillable: |
| 523 | tok_xsd_nillable |
| 524 | { |
| 525 | $$ = true; |
| 526 | } |
| 527 | | |
| 528 | { |
| 529 | $$ = false; |
| 530 | } |
| 531 | |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 532 | XsdAttributes: |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame^] | 533 | tok_xsd_attrs '{' FieldList '}' |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 534 | { |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame^] | 535 | $$ = $3; |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 536 | } |
| 537 | | |
| 538 | { |
| 539 | $$ = NULL; |
| 540 | } |
| 541 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 542 | Xception: |
| 543 | tok_xception tok_identifier '{' FieldList '}' |
| 544 | { |
| 545 | pdebug("Xception -> tok_xception tok_identifier { FieldList }"); |
| 546 | $4->set_name($2); |
| 547 | $4->set_xception(true); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 548 | /* |
| 549 | if ($4 != NULL) { |
| 550 | $5->set_doc($4); |
| 551 | } |
| 552 | */ |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 553 | $$ = $4; |
| 554 | y_field_val = -1; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | Service: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 558 | DocTextOptional tok_service tok_identifier Extends '{' FunctionList '}' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 559 | { |
| 560 | pdebug("Service -> tok_service tok_identifier { FunctionList }"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 561 | $$ = $6; |
| 562 | $$->set_name($3); |
| 563 | $$->set_extends($4); |
| 564 | if ($1 != NULL) { |
| 565 | $$->set_doc($1); |
| 566 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 569 | Extends: |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 570 | tok_extends tok_identifier |
| 571 | { |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 572 | pdebug("Extends -> tok_extends tok_identifier"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 573 | $$ = NULL; |
| 574 | if (g_parse_mode == PROGRAM) { |
| 575 | $$ = g_scope->get_service($2); |
| 576 | if ($$ == NULL) { |
| 577 | yyerror("Service \"%s\" has not been defined.", $2); |
| 578 | exit(1); |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | | |
| 583 | { |
| 584 | $$ = NULL; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | FunctionList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 588 | FunctionList Function |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 589 | { |
| 590 | pdebug("FunctionList -> FunctionList Function"); |
| 591 | $$ = $1; |
| 592 | $1->add_function($2); |
| 593 | } |
| 594 | | |
| 595 | { |
| 596 | pdebug("FunctionList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 597 | $$ = new t_service(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | Function: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 601 | DocTextOptional Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 602 | { |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 603 | $6->set_name(std::string($4) + "_args"); |
| 604 | $$ = new t_function($3, $4, $6, $8, $2); |
| 605 | if ($1 != NULL) { |
| 606 | $$->set_doc($1); |
| 607 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 608 | y_field_val = -1; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 611 | Async: |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 612 | tok_async |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 613 | { |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 614 | $$ = true; |
| 615 | } |
| 616 | | |
| 617 | { |
| 618 | $$ = false; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 619 | } |
| 620 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 621 | Throws: |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 622 | tok_throws '(' FieldList ')' |
| 623 | { |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 624 | pdebug("Throws -> tok_throws ( FieldList )"); |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 625 | $$ = $3; |
| 626 | } |
| 627 | | |
| 628 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 629 | $$ = new t_struct(g_program); |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 632 | FieldList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 633 | FieldList Field |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 634 | { |
| 635 | pdebug("FieldList -> FieldList , Field"); |
| 636 | $$ = $1; |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 637 | $$->append($2); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 638 | } |
| 639 | | |
| 640 | { |
| 641 | pdebug("FieldList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 642 | $$ = new t_struct(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | Field: |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 646 | DocTextOptional FieldIdentifier FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 647 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 648 | pdebug("tok_int_constant : Field -> FieldType tok_identifier"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 649 | if ($2 < 0) { |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 650 | pwarning(2, "No field key specified for %s, resulting protocol may have conflicts or not be backwards compatible!\n", $4); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 651 | } |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 652 | $$ = new t_field($3, $4, $2); |
| 653 | if ($5 != NULL) { |
| 654 | validate_field_value($$, $5); |
| 655 | $$->set_value($5); |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 656 | } |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 657 | $$->set_xsd_optional($6); |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 658 | $$->set_xsd_nillable($7); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 659 | if ($1 != NULL) { |
| 660 | $$->set_doc($1); |
| 661 | } |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 662 | if ($8 != NULL) { |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame^] | 663 | $$->set_xsd_attrs($8); |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 664 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 665 | } |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 666 | |
| 667 | FieldIdentifier: |
| 668 | tok_int_constant ':' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 669 | { |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 670 | if ($1 <= 0) { |
| 671 | pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1); |
| 672 | $1 = y_field_val--; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 673 | } |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 674 | $$ = $1; |
| 675 | } |
| 676 | | |
| 677 | { |
| 678 | $$ = y_field_val--; |
| 679 | } |
| 680 | |
| 681 | FieldValue: |
| 682 | '=' ConstValue |
| 683 | { |
| 684 | if (g_parse_mode == PROGRAM) { |
| 685 | $$ = $2; |
| 686 | } else { |
| 687 | $$ = NULL; |
| 688 | } |
| 689 | } |
| 690 | | |
| 691 | { |
| 692 | $$ = NULL; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 693 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 694 | |
| 695 | DefinitionType: |
| 696 | BaseType |
| 697 | { |
| 698 | pdebug("DefinitionType -> BaseType"); |
| 699 | $$ = $1; |
| 700 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 701 | | ContainerType |
| 702 | { |
| 703 | pdebug("DefinitionType -> ContainerType"); |
| 704 | $$ = $1; |
| 705 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 706 | |
| 707 | FunctionType: |
| 708 | FieldType |
| 709 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 710 | pdebug("FunctionType -> FieldType"); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 711 | $$ = $1; |
| 712 | } |
| 713 | | tok_void |
| 714 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 715 | pdebug("FunctionType -> tok_void"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 716 | $$ = g_type_void; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | FieldType: |
| 720 | tok_identifier |
| 721 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 722 | pdebug("FieldType -> tok_identifier"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 723 | if (g_parse_mode == INCLUDES) { |
| 724 | // Ignore identifiers in include mode |
| 725 | $$ = NULL; |
| 726 | } else { |
| 727 | // Lookup the identifier in the current scope |
| 728 | $$ = g_scope->get_type($1); |
| 729 | if ($$ == NULL) { |
| 730 | yyerror("Type \"%s\" has not been defined.", $1); |
| 731 | exit(1); |
| 732 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 733 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 734 | } |
| 735 | | BaseType |
| 736 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 737 | pdebug("FieldType -> BaseType"); |
| 738 | $$ = $1; |
| 739 | } |
| 740 | | ContainerType |
| 741 | { |
| 742 | pdebug("FieldType -> ContainerType"); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 743 | $$ = $1; |
| 744 | } |
| 745 | |
| 746 | BaseType: |
| 747 | tok_string |
| 748 | { |
| 749 | pdebug("BaseType -> tok_string"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 750 | $$ = g_type_string; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 751 | } |
Mark Slee | b6200d8 | 2007-01-19 19:14:36 +0000 | [diff] [blame] | 752 | | tok_slist |
| 753 | { |
| 754 | pdebug("BaseType -> tok_slist"); |
| 755 | $$ = g_type_slist; |
| 756 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 757 | | tok_bool |
| 758 | { |
| 759 | pdebug("BaseType -> tok_bool"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 760 | $$ = g_type_bool; |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 761 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 762 | | tok_byte |
| 763 | { |
| 764 | pdebug("BaseType -> tok_byte"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 765 | $$ = g_type_byte; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 766 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 767 | | tok_i16 |
| 768 | { |
| 769 | pdebug("BaseType -> tok_i16"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 770 | $$ = g_type_i16; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 771 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 772 | | tok_i32 |
| 773 | { |
| 774 | pdebug("BaseType -> tok_i32"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 775 | $$ = g_type_i32; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 776 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 777 | | tok_i64 |
| 778 | { |
| 779 | pdebug("BaseType -> tok_i64"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 780 | $$ = g_type_i64; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 781 | } |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 782 | | tok_double |
| 783 | { |
| 784 | pdebug("BaseType -> tok_double"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 785 | $$ = g_type_double; |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 786 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 787 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 788 | ContainerType: |
| 789 | MapType |
| 790 | { |
| 791 | pdebug("ContainerType -> MapType"); |
| 792 | $$ = $1; |
| 793 | } |
| 794 | | SetType |
| 795 | { |
| 796 | pdebug("ContainerType -> SetType"); |
| 797 | $$ = $1; |
| 798 | } |
| 799 | | ListType |
| 800 | { |
| 801 | pdebug("ContainerType -> ListType"); |
| 802 | $$ = $1; |
| 803 | } |
| 804 | |
| 805 | MapType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 806 | tok_map CppType '<' FieldType ',' FieldType '>' |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 807 | { |
| 808 | pdebug("MapType -> tok_map <FieldType, FieldType>"); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 809 | $$ = new t_map($4, $6); |
| 810 | if ($2 != NULL) { |
| 811 | ((t_container*)$$)->set_cpp_name(std::string($2)); |
| 812 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | SetType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 816 | tok_set CppType '<' FieldType '>' |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 817 | { |
| 818 | pdebug("SetType -> tok_set<FieldType>"); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 819 | $$ = new t_set($4); |
| 820 | if ($2 != NULL) { |
| 821 | ((t_container*)$$)->set_cpp_name(std::string($2)); |
| 822 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | ListType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 826 | tok_list '<' FieldType '>' CppType |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 827 | { |
| 828 | pdebug("ListType -> tok_list<FieldType>"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 829 | $$ = new t_list($3); |
| 830 | if ($5 != NULL) { |
| 831 | ((t_container*)$$)->set_cpp_name(std::string($5)); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 835 | CppType: |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 836 | '[' tok_cpp_type tok_literal ']' |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 837 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 838 | $$ = $3; |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 839 | } |
| 840 | | |
| 841 | { |
| 842 | $$ = NULL; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 843 | } |
| 844 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 845 | %% |