blob: c1d383b6956880b7ed66affadf68e31cf5f525cf [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 Slee7df0e2a2007-02-06 21:03:18 +000073%token tok_xsd_nillable
Mark Slee0d9199e2007-01-31 02:08:30 +000074%token tok_xsd_namespace
Mark Slee21135c32007-02-05 21:52:08 +000075%token tok_xsd_attrs
Mark Slee9cb7c612006-09-01 22:17:45 +000076
Mark Sleef5377b32006-10-10 01:42:59 +000077/**
78 * Base datatype keywords
79 */
80%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +000081%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +000082%token tok_byte
83%token tok_string
Mark Sleeb6200d82007-01-19 19:14:36 +000084%token tok_slist
Mark Slee9cb7c612006-09-01 22:17:45 +000085%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +000086%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +000087%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +000088%token tok_double
Mark Slee31985722006-05-24 21:45:31 +000089
Mark Sleef5377b32006-10-10 01:42:59 +000090/**
91 * Complex type keywords
92 */
Mark Slee31985722006-05-24 21:45:31 +000093%token tok_map
94%token tok_list
95%token tok_set
96
Mark Sleef5377b32006-10-10 01:42:59 +000097/**
98 * Function modifiers
99 */
Mark Slee31985722006-05-24 21:45:31 +0000100%token tok_async
101
Mark Sleef5377b32006-10-10 01:42:59 +0000102/**
103 * Thrift language keywords
104 */
Mark Slee31985722006-05-24 21:45:31 +0000105%token tok_typedef
106%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000107%token tok_xception
108%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000109%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000110%token tok_service
111%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000112%token tok_const
Mark Slee31985722006-05-24 21:45:31 +0000113
Mark Sleef5377b32006-10-10 01:42:59 +0000114/**
115 * Grammar nodes
116 */
117
Mark Slee31985722006-05-24 21:45:31 +0000118%type<ttype> BaseType
Mark Sleee8540632006-05-30 09:24:40 +0000119%type<ttype> ContainerType
120%type<ttype> MapType
121%type<ttype> SetType
122%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000123
Mark Sleef0712dc2006-10-25 19:03:57 +0000124%type<ttype> TypeDefinition
125
Mark Slee31985722006-05-24 21:45:31 +0000126%type<ttypedef> Typedef
127%type<ttype> DefinitionType
128
129%type<tfield> Field
Mark Slee7ff32452007-02-01 05:26:18 +0000130%type<iconst> FieldIdentifier
Mark Slee31985722006-05-24 21:45:31 +0000131%type<ttype> FieldType
Mark Slee7ff32452007-02-01 05:26:18 +0000132%type<tconstv> FieldValue
Mark Sleee8540632006-05-30 09:24:40 +0000133%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000134
135%type<tenum> Enum
136%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000137%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 Slee31985722006-05-24 21:45:31 +0000145
146%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000147%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000148%type<tservice> Service
149
150%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000151%type<ttype> FunctionType
152%type<tservice> FunctionList
153
Mark Slee36bfa2e2007-01-19 20:09:51 +0000154%type<tstruct> Throws
155%type<tservice> Extends
156%type<tbool> Async
157%type<tbool> XsdAll
158%type<tbool> XsdOptional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000159%type<tbool> XsdNillable
Mark Slee21135c32007-02-05 21:52:08 +0000160%type<id> XsdAttributes
Mark Slee36bfa2e2007-01-19 20:09:51 +0000161%type<id> CppType
Mark Slee52f643d2006-08-09 00:03:43 +0000162
ccheeverf53b5cf2007-02-05 20:33:11 +0000163%type<tdoc> DocTextOptional
164
Mark Slee31985722006-05-24 21:45:31 +0000165%%
166
Mark Sleef5377b32006-10-10 01:42:59 +0000167/**
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 Slee31985722006-05-24 21:45:31 +0000174
175Program:
Mark Sleef0712dc2006-10-25 19:03:57 +0000176 HeaderList DefinitionList
177 {
178 pdebug("Program -> Headers DefinitionList");
179 }
180
181HeaderList:
182 HeaderList Header
183 {
184 pdebug("HeaderList -> HeaderList Header");
185 }
186|
187 {
188 pdebug("HeaderList -> ");
189 }
190
191Header:
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 Sleee888b372007-01-12 01:06:24 +0000218| 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 Sleef0712dc2006-10-25 19:03:57 +0000225| 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 Slee0d9199e2007-01-31 02:08:30 +0000232| 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 Sleef0712dc2006-10-25 19:03:57 +0000239
240Include:
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 Slee31985722006-05-24 21:45:31 +0000251
252DefinitionList:
253 DefinitionList Definition
254 {
255 pdebug("DefinitionList -> DefinitionList Definition");
256 }
257|
258 {
259 pdebug("DefinitionList -> ");
260 }
261
262Definition:
Mark Slee30152872006-11-28 01:24:07 +0000263 Const
264 {
265 pdebug("Definition -> Const");
266 if (g_parse_mode == PROGRAM) {
267 g_program->add_const($1);
268 }
269 }
270| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000271 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000272 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 Slee9cb7c612006-09-01 22:17:45 +0000279 }
Mark Slee31985722006-05-24 21:45:31 +0000280| Service
281 {
282 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000283 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 Slee9cb7c612006-09-01 22:17:45 +0000290 }
291
Mark Sleef0712dc2006-10-25 19:03:57 +0000292TypeDefinition:
293 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000294 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000295 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 Slee9cb7c612006-09-01 22:17:45 +0000320 }
Mark Slee31985722006-05-24 21:45:31 +0000321
322Typedef:
ccheeverf53b5cf2007-02-05 20:33:11 +0000323 DocTextOptional tok_typedef DefinitionType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000324 {
325 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000326 t_typedef *td = new t_typedef(g_program, $3, $4);
Mark Slee31985722006-05-24 21:45:31 +0000327 $$ = td;
ccheeverf53b5cf2007-02-05 20:33:11 +0000328 if ($1 != NULL) {
329 td->set_doc($1);
330 }
Mark Slee31985722006-05-24 21:45:31 +0000331 }
332
ccheeverf53b5cf2007-02-05 20:33:11 +0000333DocTextOptional:
334 tok_doctext
335 {
336 pdebug("DocTextOptional -> tok_doctext");
337 $$ = $1;
338 }
339|
340 {
341 $$ = NULL;
342 }
343
344
Mark Slee31985722006-05-24 21:45:31 +0000345Enum:
ccheeverf53b5cf2007-02-05 20:33:11 +0000346 DocTextOptional tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000347 {
348 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
ccheeverf53b5cf2007-02-05 20:33:11 +0000349 $$ = $5;
350 $$->set_name($3);
351 if ($1 != NULL) {
352 $$->set_doc($1);
353 }
Mark Slee31985722006-05-24 21:45:31 +0000354 }
355
Mark Slee207cb462006-11-02 18:43:12 +0000356CommaOrSemicolonOptional:
357 ','
358 {}
359| ';'
360 {}
361|
362 {}
363
Mark Slee31985722006-05-24 21:45:31 +0000364EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000365 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000366 {
367 pdebug("EnumDefList -> EnumDefList EnumDef");
368 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000369 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000370 }
371|
372 {
373 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000374 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000375 }
376
377EnumDef:
ccheeverf53b5cf2007-02-05 20:33:11 +0000378 DocTextOptional tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000379 {
Mark Slee30152872006-11-28 01:24:07 +0000380 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000381 if ($4 < 0) {
382 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000383 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000384 $$ = new t_enum_value($2, $4);
385 if ($1 != NULL) {
386 $$->set_doc($1);
387 }
Mark Slee31985722006-05-24 21:45:31 +0000388 }
389|
ccheeverf53b5cf2007-02-05 20:33:11 +0000390 DocTextOptional tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000391 {
Mark Slee30152872006-11-28 01:24:07 +0000392 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000393 $$ = new t_enum_value($2);
394 if ($1 != NULL) {
395 $$->set_doc($1);
396 }
Mark Slee30152872006-11-28 01:24:07 +0000397 }
398
399Const:
400 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
401 {
402 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000403 if (g_parse_mode == PROGRAM) {
404 $$ = new t_const($2, $3, $5);
405 validate_const_type($$);
406 } else {
407 $$ = NULL;
408 }
Mark Slee30152872006-11-28 01:24:07 +0000409 }
410
411ConstValue:
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 Slee67fc6342006-11-29 03:37:04 +0000430| tok_identifier
431 {
432 pdebug("ConstValue => tok_identifier");
433 $$ = new t_const_value();
434 $$->set_string($1);
435 }
Mark Slee30152872006-11-28 01:24:07 +0000436| ConstList
437 {
438 pdebug("ConstValue => ConstList");
439 $$ = $1;
440 }
441| ConstMap
442 {
443 pdebug("ConstValue => ConstMap");
444 $$ = $1;
445 }
446
447ConstList:
448 '[' ConstListContents ']'
449 {
450 pdebug("ConstList => [ ConstListContents ]");
451 $$ = $2;
452 }
453
454ConstListContents:
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
468ConstMap:
469 '{' ConstMapContents '}'
470 {
471 pdebug("ConstMap => { ConstMapContents }");
472 $$ = $2;
473 }
474
475ConstMapContents:
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 Slee31985722006-05-24 21:45:31 +0000487 }
488
489Struct:
ccheeverf53b5cf2007-02-05 20:33:11 +0000490 DocTextOptional tok_struct tok_identifier XsdAll '{' FieldList '}'
Mark Slee31985722006-05-24 21:45:31 +0000491 {
492 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
ccheeverf53b5cf2007-02-05 20:33:11 +0000493 $6->set_name($3);
494 if ($1 != NULL) {
495 $6->set_doc($1);
496 }
497 $6->set_xsd_all($4);
498 $$ = $6;
Mark Slee9cb7c612006-09-01 22:17:45 +0000499 y_field_val = -1;
500 }
501
Mark Slee36bfa2e2007-01-19 20:09:51 +0000502XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000503 tok_xsd_all
504 {
505 $$ = true;
506 }
507|
508 {
509 $$ = false;
510 }
511
Mark Slee36bfa2e2007-01-19 20:09:51 +0000512XsdOptional:
513 tok_xsd_optional
514 {
515 $$ = true;
516 }
517|
518 {
519 $$ = false;
520 }
521
Mark Slee7df0e2a2007-02-06 21:03:18 +0000522XsdNillable:
523 tok_xsd_nillable
524 {
525 $$ = true;
526 }
527|
528 {
529 $$ = false;
530 }
531
Mark Slee21135c32007-02-05 21:52:08 +0000532XsdAttributes:
533 tok_xsd_attrs tok_identifier
534 {
535 $$ = $2;
536 }
537|
538 {
539 $$ = NULL;
540 }
541
Mark Slee9cb7c612006-09-01 22:17:45 +0000542Xception:
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);
ccheeverf53b5cf2007-02-05 20:33:11 +0000548/*
549 if ($4 != NULL) {
550 $5->set_doc($4);
551 }
552*/
Mark Slee9cb7c612006-09-01 22:17:45 +0000553 $$ = $4;
554 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000555 }
556
557Service:
ccheeverf53b5cf2007-02-05 20:33:11 +0000558 DocTextOptional tok_service tok_identifier Extends '{' FunctionList '}'
Mark Slee31985722006-05-24 21:45:31 +0000559 {
560 pdebug("Service -> tok_service tok_identifier { FunctionList }");
ccheeverf53b5cf2007-02-05 20:33:11 +0000561 $$ = $6;
562 $$->set_name($3);
563 $$->set_extends($4);
564 if ($1 != NULL) {
565 $$->set_doc($1);
566 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000567 }
568
Mark Slee36bfa2e2007-01-19 20:09:51 +0000569Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000570 tok_extends tok_identifier
571 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000572 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000573 $$ = 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 Slee31985722006-05-24 21:45:31 +0000585 }
586
587FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000588 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000589 {
590 pdebug("FunctionList -> FunctionList Function");
591 $$ = $1;
592 $1->add_function($2);
593 }
594|
595 {
596 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000597 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000598 }
599
600Function:
ccheeverf53b5cf2007-02-05 20:33:11 +0000601 DocTextOptional Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000602 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000603 $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 Slee9cb7c612006-09-01 22:17:45 +0000608 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000609 }
610
Mark Slee36bfa2e2007-01-19 20:09:51 +0000611Async:
Mark Slee52f643d2006-08-09 00:03:43 +0000612 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000613 {
Mark Slee52f643d2006-08-09 00:03:43 +0000614 $$ = true;
615 }
616|
617 {
618 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000619 }
620
Mark Slee36bfa2e2007-01-19 20:09:51 +0000621Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000622 tok_throws '(' FieldList ')'
623 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000624 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000625 $$ = $3;
626 }
627|
628 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000629 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000630 }
631
Mark Slee31985722006-05-24 21:45:31 +0000632FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000633 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000634 {
635 pdebug("FieldList -> FieldList , Field");
636 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000637 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000638 }
639|
640 {
641 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000642 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000643 }
644
645Field:
Mark Slee7df0e2a2007-02-06 21:03:18 +0000646 DocTextOptional FieldIdentifier FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000647 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000648 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000649 if ($2 < 0) {
Mark Slee21135c32007-02-05 21:52:08 +0000650 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 +0000651 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000652 $$ = new t_field($3, $4, $2);
653 if ($5 != NULL) {
654 validate_field_value($$, $5);
655 $$->set_value($5);
Mark Slee7ff32452007-02-01 05:26:18 +0000656 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000657 $$->set_xsd_optional($6);
Mark Slee7df0e2a2007-02-06 21:03:18 +0000658 $$->set_xsd_nillable($7);
ccheeverf53b5cf2007-02-05 20:33:11 +0000659 if ($1 != NULL) {
660 $$->set_doc($1);
661 }
Mark Slee7df0e2a2007-02-06 21:03:18 +0000662 if ($8 != NULL) {
663 $$->add_xsd_attr($8);
Mark Slee21135c32007-02-05 21:52:08 +0000664 }
Mark Slee31985722006-05-24 21:45:31 +0000665 }
Mark Slee7ff32452007-02-01 05:26:18 +0000666
667FieldIdentifier:
668 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000669 {
Mark Slee7ff32452007-02-01 05:26:18 +0000670 if ($1 <= 0) {
671 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
672 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000673 }
Mark Slee7ff32452007-02-01 05:26:18 +0000674 $$ = $1;
675 }
676|
677 {
678 $$ = y_field_val--;
679 }
680
681FieldValue:
682 '=' ConstValue
683 {
684 if (g_parse_mode == PROGRAM) {
685 $$ = $2;
686 } else {
687 $$ = NULL;
688 }
689 }
690|
691 {
692 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000693 }
Mark Slee31985722006-05-24 21:45:31 +0000694
695DefinitionType:
696 BaseType
697 {
698 pdebug("DefinitionType -> BaseType");
699 $$ = $1;
700 }
Mark Sleee8540632006-05-30 09:24:40 +0000701| ContainerType
702 {
703 pdebug("DefinitionType -> ContainerType");
704 $$ = $1;
705 }
Mark Slee31985722006-05-24 21:45:31 +0000706
707FunctionType:
708 FieldType
709 {
Mark Sleee8540632006-05-30 09:24:40 +0000710 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000711 $$ = $1;
712 }
713| tok_void
714 {
Mark Sleee8540632006-05-30 09:24:40 +0000715 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000716 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000717 }
718
719FieldType:
720 tok_identifier
721 {
Mark Sleee8540632006-05-30 09:24:40 +0000722 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000723 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 Sleee8540632006-05-30 09:24:40 +0000733 }
Mark Slee31985722006-05-24 21:45:31 +0000734 }
735| BaseType
736 {
Mark Sleee8540632006-05-30 09:24:40 +0000737 pdebug("FieldType -> BaseType");
738 $$ = $1;
739 }
740| ContainerType
741 {
742 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000743 $$ = $1;
744 }
745
746BaseType:
747 tok_string
748 {
749 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000750 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000751 }
Mark Sleeb6200d82007-01-19 19:14:36 +0000752| tok_slist
753 {
754 pdebug("BaseType -> tok_slist");
755 $$ = g_type_slist;
756 }
Mark Slee78f58e22006-09-02 04:17:07 +0000757| tok_bool
758 {
759 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000760 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000761 }
Mark Slee31985722006-05-24 21:45:31 +0000762| tok_byte
763 {
764 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000765 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000766 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000767| tok_i16
768 {
769 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000770 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000771 }
Mark Slee31985722006-05-24 21:45:31 +0000772| tok_i32
773 {
774 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000775 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000776 }
Mark Slee31985722006-05-24 21:45:31 +0000777| tok_i64
778 {
779 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000780 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000781 }
Mark Sleec98d0502006-09-06 02:42:25 +0000782| tok_double
783 {
784 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000785 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000786 }
Mark Slee31985722006-05-24 21:45:31 +0000787
Mark Sleee8540632006-05-30 09:24:40 +0000788ContainerType:
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
805MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000806 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000807 {
808 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000809 $$ = new t_map($4, $6);
810 if ($2 != NULL) {
811 ((t_container*)$$)->set_cpp_name(std::string($2));
812 }
Mark Sleee8540632006-05-30 09:24:40 +0000813 }
814
815SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000816 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000817 {
818 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000819 $$ = new t_set($4);
820 if ($2 != NULL) {
821 ((t_container*)$$)->set_cpp_name(std::string($2));
822 }
Mark Sleee8540632006-05-30 09:24:40 +0000823 }
824
825ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000826 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +0000827 {
828 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +0000829 $$ = new t_list($3);
830 if ($5 != NULL) {
831 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +0000832 }
833 }
834
Mark Slee36bfa2e2007-01-19 20:09:51 +0000835CppType:
Mark Sleef0712dc2006-10-25 19:03:57 +0000836 '[' tok_cpp_type tok_literal ']'
Mark Slee4f8da1d2006-10-12 02:47:27 +0000837 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000838 $$ = $3;
Mark Slee4f8da1d2006-10-12 02:47:27 +0000839 }
840|
841 {
842 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +0000843 }
844
Mark Slee31985722006-05-24 21:45:31 +0000845%%