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