blob: a53d0023cff6f520980f12eb50a7b68804cdf22d [file] [log] [blame]
Mark Slee31985722006-05-24 21:45:31 +00001%{
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 Sleef0712dc2006-10-25 19:03:57 +000015#include "parse/t_scope.h"
Mark Slee31985722006-05-24 21:45:31 +000016
Mark Sleef5377b32006-10-10 01:42:59 +000017/**
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 Slee9cb7c612006-09-01 22:17:45 +000022int y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +000023
24%}
25
Mark Sleef5377b32006-10-10 01:42:59 +000026/**
27 * This structure is used by the parser to hold the data types associated with
28 * various parse nodes.
29 */
Mark Slee31985722006-05-24 21:45:31 +000030%union {
Mark Slee30152872006-11-28 01:24:07 +000031 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;
ccheeverf53b5cf2007-02-05 20:33:11 +000045 char* tdoc;
Mark Slee31985722006-05-24 21:45:31 +000046}
47
Mark Sleef5377b32006-10-10 01:42:59 +000048/**
49 * Strings identifier
50 */
Mark Slee31985722006-05-24 21:45:31 +000051%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000052%token<id> tok_literal
ccheeverf53b5cf2007-02-05 20:33:11 +000053%token<tdoc> tok_doctext
Mark Sleef5377b32006-10-10 01:42:59 +000054
55/**
Mark Slee30152872006-11-28 01:24:07 +000056 * Constant values
Mark Sleef5377b32006-10-10 01:42:59 +000057 */
Mark Slee31985722006-05-24 21:45:31 +000058%token<iconst> tok_int_constant
Mark Slee30152872006-11-28 01:24:07 +000059%token<dconst> tok_dub_constant
Mark Slee31985722006-05-24 21:45:31 +000060
Mark Sleef5377b32006-10-10 01:42:59 +000061/**
Mark Sleef0712dc2006-10-25 19:03:57 +000062 * Header keywoards
Mark Sleef5377b32006-10-10 01:42:59 +000063 */
Mark Sleef0712dc2006-10-25 19:03:57 +000064%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000065%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000066%token tok_cpp_namespace
67%token tok_cpp_include
68%token tok_cpp_type
Mark Sleee888b372007-01-12 01:06:24 +000069%token tok_php_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000070%token tok_java_package
Mark Slee782abbb2007-01-19 00:17:02 +000071%token tok_xsd_all
Mark Slee36bfa2e2007-01-19 20:09:51 +000072%token tok_xsd_optional
Mark Slee0d9199e2007-01-31 02:08:30 +000073%token tok_xsd_namespace
Mark Slee21135c32007-02-05 21:52:08 +000074%token tok_xsd_attrs
Mark Slee9cb7c612006-09-01 22:17:45 +000075
Mark Sleef5377b32006-10-10 01:42:59 +000076/**
77 * Base datatype keywords
78 */
79%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +000080%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +000081%token tok_byte
82%token tok_string
Mark Sleeb6200d82007-01-19 19:14:36 +000083%token tok_slist
Mark Slee9cb7c612006-09-01 22:17:45 +000084%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +000085%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +000086%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +000087%token tok_double
Mark Slee31985722006-05-24 21:45:31 +000088
Mark Sleef5377b32006-10-10 01:42:59 +000089/**
90 * Complex type keywords
91 */
Mark Slee31985722006-05-24 21:45:31 +000092%token tok_map
93%token tok_list
94%token tok_set
95
Mark Sleef5377b32006-10-10 01:42:59 +000096/**
97 * Function modifiers
98 */
Mark Slee31985722006-05-24 21:45:31 +000099%token tok_async
100
Mark Sleef5377b32006-10-10 01:42:59 +0000101/**
102 * Thrift language keywords
103 */
Mark Slee31985722006-05-24 21:45:31 +0000104%token tok_typedef
105%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000106%token tok_xception
107%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000108%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000109%token tok_service
110%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000111%token tok_const
Mark Slee31985722006-05-24 21:45:31 +0000112
Mark Sleef5377b32006-10-10 01:42:59 +0000113/**
114 * Grammar nodes
115 */
116
Mark Slee31985722006-05-24 21:45:31 +0000117%type<ttype> BaseType
Mark Sleee8540632006-05-30 09:24:40 +0000118%type<ttype> ContainerType
119%type<ttype> MapType
120%type<ttype> SetType
121%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000122
Mark Sleef0712dc2006-10-25 19:03:57 +0000123%type<ttype> TypeDefinition
124
Mark Slee31985722006-05-24 21:45:31 +0000125%type<ttypedef> Typedef
126%type<ttype> DefinitionType
127
128%type<tfield> Field
Mark Slee7ff32452007-02-01 05:26:18 +0000129%type<iconst> FieldIdentifier
Mark Slee31985722006-05-24 21:45:31 +0000130%type<ttype> FieldType
Mark Slee7ff32452007-02-01 05:26:18 +0000131%type<tconstv> FieldValue
Mark Sleee8540632006-05-30 09:24:40 +0000132%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000133
134%type<tenum> Enum
135%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000136%type<tenumv> EnumDef
137
138%type<tconst> Const
139%type<tconstv> ConstValue
140%type<tconstv> ConstList
141%type<tconstv> ConstListContents
142%type<tconstv> ConstMap
143%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000144
145%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000146%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000147%type<tservice> Service
148
149%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000150%type<ttype> FunctionType
151%type<tservice> FunctionList
152
Mark Slee36bfa2e2007-01-19 20:09:51 +0000153%type<tstruct> Throws
154%type<tservice> Extends
155%type<tbool> Async
156%type<tbool> XsdAll
157%type<tbool> XsdOptional
Mark Slee21135c32007-02-05 21:52:08 +0000158%type<id> XsdAttributes
Mark Slee36bfa2e2007-01-19 20:09:51 +0000159%type<id> CppType
Mark Slee52f643d2006-08-09 00:03:43 +0000160
ccheeverf53b5cf2007-02-05 20:33:11 +0000161%type<tdoc> DocTextOptional
162
Mark Slee31985722006-05-24 21:45:31 +0000163%%
164
Mark Sleef5377b32006-10-10 01:42:59 +0000165/**
166 * Thrift Grammar Implementation.
167 *
168 * For the most part this source file works its way top down from what you
169 * might expect to find in a typical .thrift file, i.e. type definitions and
170 * namespaces up top followed by service definitions using those types.
171 */
Mark Slee31985722006-05-24 21:45:31 +0000172
173Program:
Mark Sleef0712dc2006-10-25 19:03:57 +0000174 HeaderList DefinitionList
175 {
176 pdebug("Program -> Headers DefinitionList");
177 }
178
179HeaderList:
180 HeaderList Header
181 {
182 pdebug("HeaderList -> HeaderList Header");
183 }
184|
185 {
186 pdebug("HeaderList -> ");
187 }
188
189Header:
190 Include
191 {
192 pdebug("Header -> Include");
193 }
194| tok_namespace tok_identifier
195 {
196 pwarning(1, "'namespace' is deprecated. Use 'cpp_namespace' and/or 'java_package' instead");
197 if (g_parse_mode == PROGRAM) {
198 g_program->set_cpp_namespace($2);
199 g_program->set_java_package($2);
200 }
201 }
202| tok_cpp_namespace tok_identifier
203 {
204 pdebug("Header -> tok_cpp_namespace tok_identifier");
205 if (g_parse_mode == PROGRAM) {
206 g_program->set_cpp_namespace($2);
207 }
208 }
209| tok_cpp_include tok_literal
210 {
211 pdebug("Header -> tok_cpp_include tok_literal");
212 if (g_parse_mode == PROGRAM) {
213 g_program->add_cpp_include($2);
214 }
215 }
Mark Sleee888b372007-01-12 01:06:24 +0000216| tok_php_namespace tok_identifier
217 {
218 pdebug("Header -> tok_php_namespace tok_identifier");
219 if (g_parse_mode == PROGRAM) {
220 g_program->set_php_namespace($2);
221 }
222 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000223| tok_java_package tok_identifier
224 {
225 pdebug("Header -> tok_java_package tok_identifier");
226 if (g_parse_mode == PROGRAM) {
227 g_program->set_java_package($2);
228 }
229 }
Mark Slee0d9199e2007-01-31 02:08:30 +0000230| tok_xsd_namespace tok_literal
231 {
232 pdebug("Header -> tok_xsd_namespace tok_literal");
233 if (g_parse_mode == PROGRAM) {
234 g_program->set_xsd_namespace($2);
235 }
236 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000237
238Include:
239 tok_include tok_literal
240 {
241 pdebug("Include -> tok_include tok_literal");
242 if (g_parse_mode == INCLUDES) {
243 std::string path = include_file(std::string($2));
244 if (!path.empty()) {
245 g_program->add_include(path);
246 }
247 }
248 }
Mark Slee31985722006-05-24 21:45:31 +0000249
250DefinitionList:
251 DefinitionList Definition
252 {
253 pdebug("DefinitionList -> DefinitionList Definition");
254 }
255|
256 {
257 pdebug("DefinitionList -> ");
258 }
259
260Definition:
Mark Slee30152872006-11-28 01:24:07 +0000261 Const
262 {
263 pdebug("Definition -> Const");
264 if (g_parse_mode == PROGRAM) {
265 g_program->add_const($1);
266 }
267 }
268| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000269 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000270 pdebug("Definition -> TypeDefinition");
271 if (g_parse_mode == PROGRAM) {
272 g_scope->add_type($1->get_name(), $1);
273 if (g_parent_scope != NULL) {
274 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
275 }
276 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000277 }
Mark Slee31985722006-05-24 21:45:31 +0000278| Service
279 {
280 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000281 if (g_parse_mode == PROGRAM) {
282 g_scope->add_service($1->get_name(), $1);
283 if (g_parent_scope != NULL) {
284 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
285 }
286 g_program->add_service($1);
287 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000288 }
289
Mark Sleef0712dc2006-10-25 19:03:57 +0000290TypeDefinition:
291 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000292 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000293 pdebug("TypeDefinition -> Typedef");
294 if (g_parse_mode == PROGRAM) {
295 g_program->add_typedef($1);
296 }
297 }
298| Enum
299 {
300 pdebug("TypeDefinition -> Enum");
301 if (g_parse_mode == PROGRAM) {
302 g_program->add_enum($1);
303 }
304 }
305| Struct
306 {
307 pdebug("TypeDefinition -> Struct");
308 if (g_parse_mode == PROGRAM) {
309 g_program->add_struct($1);
310 }
311 }
312| Xception
313 {
314 pdebug("TypeDefinition -> Xception");
315 if (g_parse_mode == PROGRAM) {
316 g_program->add_xception($1);
317 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000318 }
Mark Slee31985722006-05-24 21:45:31 +0000319
320Typedef:
ccheeverf53b5cf2007-02-05 20:33:11 +0000321 DocTextOptional tok_typedef DefinitionType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000322 {
323 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000324 t_typedef *td = new t_typedef(g_program, $3, $4);
Mark Slee31985722006-05-24 21:45:31 +0000325 $$ = td;
ccheeverf53b5cf2007-02-05 20:33:11 +0000326 if ($1 != NULL) {
327 td->set_doc($1);
328 }
Mark Slee31985722006-05-24 21:45:31 +0000329 }
330
ccheeverf53b5cf2007-02-05 20:33:11 +0000331DocTextOptional:
332 tok_doctext
333 {
334 pdebug("DocTextOptional -> tok_doctext");
335 $$ = $1;
336 }
337|
338 {
339 $$ = NULL;
340 }
341
342
Mark Slee31985722006-05-24 21:45:31 +0000343Enum:
ccheeverf53b5cf2007-02-05 20:33:11 +0000344 DocTextOptional tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000345 {
346 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
ccheeverf53b5cf2007-02-05 20:33:11 +0000347 $$ = $5;
348 $$->set_name($3);
349 if ($1 != NULL) {
350 $$->set_doc($1);
351 }
Mark Slee31985722006-05-24 21:45:31 +0000352 }
353
Mark Slee207cb462006-11-02 18:43:12 +0000354CommaOrSemicolonOptional:
355 ','
356 {}
357| ';'
358 {}
359|
360 {}
361
Mark Slee31985722006-05-24 21:45:31 +0000362EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000363 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000364 {
365 pdebug("EnumDefList -> EnumDefList EnumDef");
366 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000367 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000368 }
369|
370 {
371 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000372 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000373 }
374
375EnumDef:
ccheeverf53b5cf2007-02-05 20:33:11 +0000376 DocTextOptional tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000377 {
Mark Slee30152872006-11-28 01:24:07 +0000378 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000379 if ($4 < 0) {
380 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000381 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000382 $$ = new t_enum_value($2, $4);
383 if ($1 != NULL) {
384 $$->set_doc($1);
385 }
Mark Slee31985722006-05-24 21:45:31 +0000386 }
387|
ccheeverf53b5cf2007-02-05 20:33:11 +0000388 DocTextOptional tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000389 {
Mark Slee30152872006-11-28 01:24:07 +0000390 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000391 $$ = new t_enum_value($2);
392 if ($1 != NULL) {
393 $$->set_doc($1);
394 }
Mark Slee30152872006-11-28 01:24:07 +0000395 }
396
397Const:
398 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
399 {
400 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000401 if (g_parse_mode == PROGRAM) {
402 $$ = new t_const($2, $3, $5);
403 validate_const_type($$);
404 } else {
405 $$ = NULL;
406 }
Mark Slee30152872006-11-28 01:24:07 +0000407 }
408
409ConstValue:
410 tok_int_constant
411 {
412 pdebug("ConstValue => tok_int_constant");
413 $$ = new t_const_value();
414 $$->set_integer($1);
415 }
416| tok_dub_constant
417 {
418 pdebug("ConstValue => tok_dub_constant");
419 $$ = new t_const_value();
420 $$->set_double($1);
421 }
422| tok_literal
423 {
424 pdebug("ConstValue => tok_literal");
425 $$ = new t_const_value();
426 $$->set_string($1);
427 }
Mark Slee67fc6342006-11-29 03:37:04 +0000428| tok_identifier
429 {
430 pdebug("ConstValue => tok_identifier");
431 $$ = new t_const_value();
432 $$->set_string($1);
433 }
Mark Slee30152872006-11-28 01:24:07 +0000434| ConstList
435 {
436 pdebug("ConstValue => ConstList");
437 $$ = $1;
438 }
439| ConstMap
440 {
441 pdebug("ConstValue => ConstMap");
442 $$ = $1;
443 }
444
445ConstList:
446 '[' ConstListContents ']'
447 {
448 pdebug("ConstList => [ ConstListContents ]");
449 $$ = $2;
450 }
451
452ConstListContents:
453 ConstListContents ConstValue CommaOrSemicolonOptional
454 {
455 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
456 $$ = $1;
457 $$->add_list($2);
458 }
459|
460 {
461 pdebug("ConstListContents =>");
462 $$ = new t_const_value();
463 $$->set_list();
464 }
465
466ConstMap:
467 '{' ConstMapContents '}'
468 {
469 pdebug("ConstMap => { ConstMapContents }");
470 $$ = $2;
471 }
472
473ConstMapContents:
474 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
475 {
476 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
477 $$ = $1;
478 $$->add_map($2, $4);
479 }
480|
481 {
482 pdebug("ConstMapContents =>");
483 $$ = new t_const_value();
484 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000485 }
486
487Struct:
ccheeverf53b5cf2007-02-05 20:33:11 +0000488 DocTextOptional tok_struct tok_identifier XsdAll '{' FieldList '}'
Mark Slee31985722006-05-24 21:45:31 +0000489 {
490 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
ccheeverf53b5cf2007-02-05 20:33:11 +0000491 $6->set_name($3);
492 if ($1 != NULL) {
493 $6->set_doc($1);
494 }
495 $6->set_xsd_all($4);
496 $$ = $6;
Mark Slee9cb7c612006-09-01 22:17:45 +0000497 y_field_val = -1;
498 }
499
Mark Slee36bfa2e2007-01-19 20:09:51 +0000500XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000501 tok_xsd_all
502 {
503 $$ = true;
504 }
505|
506 {
507 $$ = false;
508 }
509
Mark Slee36bfa2e2007-01-19 20:09:51 +0000510XsdOptional:
511 tok_xsd_optional
512 {
513 $$ = true;
514 }
515|
516 {
517 $$ = false;
518 }
519
Mark Slee21135c32007-02-05 21:52:08 +0000520XsdAttributes:
521 tok_xsd_attrs tok_identifier
522 {
523 $$ = $2;
524 }
525|
526 {
527 $$ = NULL;
528 }
529
Mark Slee9cb7c612006-09-01 22:17:45 +0000530Xception:
531 tok_xception tok_identifier '{' FieldList '}'
532 {
533 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
534 $4->set_name($2);
535 $4->set_xception(true);
ccheeverf53b5cf2007-02-05 20:33:11 +0000536/*
537 if ($4 != NULL) {
538 $5->set_doc($4);
539 }
540*/
Mark Slee9cb7c612006-09-01 22:17:45 +0000541 $$ = $4;
542 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000543 }
544
545Service:
ccheeverf53b5cf2007-02-05 20:33:11 +0000546 DocTextOptional tok_service tok_identifier Extends '{' FunctionList '}'
Mark Slee31985722006-05-24 21:45:31 +0000547 {
548 pdebug("Service -> tok_service tok_identifier { FunctionList }");
ccheeverf53b5cf2007-02-05 20:33:11 +0000549 $$ = $6;
550 $$->set_name($3);
551 $$->set_extends($4);
552 if ($1 != NULL) {
553 $$->set_doc($1);
554 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000555 }
556
Mark Slee36bfa2e2007-01-19 20:09:51 +0000557Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000558 tok_extends tok_identifier
559 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000560 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000561 $$ = NULL;
562 if (g_parse_mode == PROGRAM) {
563 $$ = g_scope->get_service($2);
564 if ($$ == NULL) {
565 yyerror("Service \"%s\" has not been defined.", $2);
566 exit(1);
567 }
568 }
569 }
570|
571 {
572 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000573 }
574
575FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000576 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000577 {
578 pdebug("FunctionList -> FunctionList Function");
579 $$ = $1;
580 $1->add_function($2);
581 }
582|
583 {
584 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000585 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000586 }
587
588Function:
ccheeverf53b5cf2007-02-05 20:33:11 +0000589 DocTextOptional Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000590 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000591 $6->set_name(std::string($4) + "_args");
592 $$ = new t_function($3, $4, $6, $8, $2);
593 if ($1 != NULL) {
594 $$->set_doc($1);
595 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000596 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000597 }
598
Mark Slee36bfa2e2007-01-19 20:09:51 +0000599Async:
Mark Slee52f643d2006-08-09 00:03:43 +0000600 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000601 {
Mark Slee52f643d2006-08-09 00:03:43 +0000602 $$ = true;
603 }
604|
605 {
606 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000607 }
608
Mark Slee36bfa2e2007-01-19 20:09:51 +0000609Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000610 tok_throws '(' FieldList ')'
611 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000612 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000613 $$ = $3;
614 }
615|
616 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000617 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000618 }
619
Mark Slee31985722006-05-24 21:45:31 +0000620FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000621 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000622 {
623 pdebug("FieldList -> FieldList , Field");
624 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000625 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000626 }
627|
628 {
629 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000630 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000631 }
632
633Field:
Mark Slee21135c32007-02-05 21:52:08 +0000634 DocTextOptional FieldIdentifier FieldType tok_identifier FieldValue XsdOptional XsdAttributes CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000635 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000636 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000637 if ($2 < 0) {
Mark Slee21135c32007-02-05 21:52:08 +0000638 pwarning(2, "No field key specified for %s, resulting protocol may have conflicts or not be backwards compatible!\n", $4);
Mark Slee31985722006-05-24 21:45:31 +0000639 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000640 $$ = new t_field($3, $4, $2);
641 if ($5 != NULL) {
642 validate_field_value($$, $5);
643 $$->set_value($5);
Mark Slee7ff32452007-02-01 05:26:18 +0000644 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000645 $$->set_xsd_optional($6);
646 if ($1 != NULL) {
647 $$->set_doc($1);
648 }
Mark Slee21135c32007-02-05 21:52:08 +0000649 if ($7 != NULL) {
650 $$->add_xsd_attr($7);
651 }
Mark Slee31985722006-05-24 21:45:31 +0000652 }
Mark Slee7ff32452007-02-01 05:26:18 +0000653
654FieldIdentifier:
655 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000656 {
Mark Slee7ff32452007-02-01 05:26:18 +0000657 if ($1 <= 0) {
658 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
659 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000660 }
Mark Slee7ff32452007-02-01 05:26:18 +0000661 $$ = $1;
662 }
663|
664 {
665 $$ = y_field_val--;
666 }
667
668FieldValue:
669 '=' ConstValue
670 {
671 if (g_parse_mode == PROGRAM) {
672 $$ = $2;
673 } else {
674 $$ = NULL;
675 }
676 }
677|
678 {
679 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000680 }
Mark Slee31985722006-05-24 21:45:31 +0000681
682DefinitionType:
683 BaseType
684 {
685 pdebug("DefinitionType -> BaseType");
686 $$ = $1;
687 }
Mark Sleee8540632006-05-30 09:24:40 +0000688| ContainerType
689 {
690 pdebug("DefinitionType -> ContainerType");
691 $$ = $1;
692 }
Mark Slee31985722006-05-24 21:45:31 +0000693
694FunctionType:
695 FieldType
696 {
Mark Sleee8540632006-05-30 09:24:40 +0000697 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000698 $$ = $1;
699 }
700| tok_void
701 {
Mark Sleee8540632006-05-30 09:24:40 +0000702 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000703 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000704 }
705
706FieldType:
707 tok_identifier
708 {
Mark Sleee8540632006-05-30 09:24:40 +0000709 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000710 if (g_parse_mode == INCLUDES) {
711 // Ignore identifiers in include mode
712 $$ = NULL;
713 } else {
714 // Lookup the identifier in the current scope
715 $$ = g_scope->get_type($1);
716 if ($$ == NULL) {
717 yyerror("Type \"%s\" has not been defined.", $1);
718 exit(1);
719 }
Mark Sleee8540632006-05-30 09:24:40 +0000720 }
Mark Slee31985722006-05-24 21:45:31 +0000721 }
722| BaseType
723 {
Mark Sleee8540632006-05-30 09:24:40 +0000724 pdebug("FieldType -> BaseType");
725 $$ = $1;
726 }
727| ContainerType
728 {
729 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000730 $$ = $1;
731 }
732
733BaseType:
734 tok_string
735 {
736 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000737 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000738 }
Mark Sleeb6200d82007-01-19 19:14:36 +0000739| tok_slist
740 {
741 pdebug("BaseType -> tok_slist");
742 $$ = g_type_slist;
743 }
Mark Slee78f58e22006-09-02 04:17:07 +0000744| tok_bool
745 {
746 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000747 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000748 }
Mark Slee31985722006-05-24 21:45:31 +0000749| tok_byte
750 {
751 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000752 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000753 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000754| tok_i16
755 {
756 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000757 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000758 }
Mark Slee31985722006-05-24 21:45:31 +0000759| tok_i32
760 {
761 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000762 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000763 }
Mark Slee31985722006-05-24 21:45:31 +0000764| tok_i64
765 {
766 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000767 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000768 }
Mark Sleec98d0502006-09-06 02:42:25 +0000769| tok_double
770 {
771 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000772 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000773 }
Mark Slee31985722006-05-24 21:45:31 +0000774
Mark Sleee8540632006-05-30 09:24:40 +0000775ContainerType:
776 MapType
777 {
778 pdebug("ContainerType -> MapType");
779 $$ = $1;
780 }
781| SetType
782 {
783 pdebug("ContainerType -> SetType");
784 $$ = $1;
785 }
786| ListType
787 {
788 pdebug("ContainerType -> ListType");
789 $$ = $1;
790 }
791
792MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000793 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000794 {
795 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000796 $$ = new t_map($4, $6);
797 if ($2 != NULL) {
798 ((t_container*)$$)->set_cpp_name(std::string($2));
799 }
Mark Sleee8540632006-05-30 09:24:40 +0000800 }
801
802SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000803 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000804 {
805 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000806 $$ = new t_set($4);
807 if ($2 != NULL) {
808 ((t_container*)$$)->set_cpp_name(std::string($2));
809 }
Mark Sleee8540632006-05-30 09:24:40 +0000810 }
811
812ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000813 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +0000814 {
815 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +0000816 $$ = new t_list($3);
817 if ($5 != NULL) {
818 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +0000819 }
820 }
821
Mark Slee36bfa2e2007-01-19 20:09:51 +0000822CppType:
Mark Sleef0712dc2006-10-25 19:03:57 +0000823 '[' tok_cpp_type tok_literal ']'
Mark Slee4f8da1d2006-10-12 02:47:27 +0000824 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000825 $$ = $3;
Mark Slee4f8da1d2006-10-12 02:47:27 +0000826 }
827|
828 {
829 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +0000830 }
831
Mark Slee31985722006-05-24 21:45:31 +0000832%%