blob: c5db20b31147826528833b4bc15fccc00f3e294d [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;
Mark Slee31985722006-05-24 21:45:31 +000045}
46
Mark Sleef5377b32006-10-10 01:42:59 +000047/**
48 * Strings identifier
49 */
Mark Slee31985722006-05-24 21:45:31 +000050%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000051%token<id> tok_literal
Mark Sleef5377b32006-10-10 01:42:59 +000052
53/**
Mark Slee30152872006-11-28 01:24:07 +000054 * Constant values
Mark Sleef5377b32006-10-10 01:42:59 +000055 */
Mark Slee31985722006-05-24 21:45:31 +000056%token<iconst> tok_int_constant
Mark Slee30152872006-11-28 01:24:07 +000057%token<dconst> tok_dub_constant
Mark Slee31985722006-05-24 21:45:31 +000058
Mark Sleef5377b32006-10-10 01:42:59 +000059/**
Mark Sleef0712dc2006-10-25 19:03:57 +000060 * Header keywoards
Mark Sleef5377b32006-10-10 01:42:59 +000061 */
Mark Sleef0712dc2006-10-25 19:03:57 +000062%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000063%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000064%token tok_cpp_namespace
65%token tok_cpp_include
66%token tok_cpp_type
67%token tok_java_package
Mark Slee9cb7c612006-09-01 22:17:45 +000068
Mark Sleef5377b32006-10-10 01:42:59 +000069/**
70 * Base datatype keywords
71 */
72%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +000073%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +000074%token tok_byte
75%token tok_string
Mark Slee9cb7c612006-09-01 22:17:45 +000076%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +000077%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +000078%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +000079%token tok_double
Mark Slee31985722006-05-24 21:45:31 +000080
Mark Sleef5377b32006-10-10 01:42:59 +000081/**
82 * Complex type keywords
83 */
Mark Slee31985722006-05-24 21:45:31 +000084%token tok_map
85%token tok_list
86%token tok_set
87
Mark Sleef5377b32006-10-10 01:42:59 +000088/**
89 * Function modifiers
90 */
Mark Slee31985722006-05-24 21:45:31 +000091%token tok_async
92
Mark Sleef5377b32006-10-10 01:42:59 +000093/**
94 * Thrift language keywords
95 */
Mark Slee31985722006-05-24 21:45:31 +000096%token tok_typedef
97%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +000098%token tok_xception
99%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000100%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000101%token tok_service
102%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000103%token tok_const
Mark Slee31985722006-05-24 21:45:31 +0000104
Mark Sleef5377b32006-10-10 01:42:59 +0000105/**
106 * Grammar nodes
107 */
108
Mark Slee31985722006-05-24 21:45:31 +0000109%type<ttype> BaseType
Mark Sleee8540632006-05-30 09:24:40 +0000110%type<ttype> ContainerType
111%type<ttype> MapType
112%type<ttype> SetType
113%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000114
Mark Sleef0712dc2006-10-25 19:03:57 +0000115%type<ttype> TypeDefinition
116
Mark Slee31985722006-05-24 21:45:31 +0000117%type<ttypedef> Typedef
118%type<ttype> DefinitionType
119
120%type<tfield> Field
121%type<ttype> FieldType
Mark Sleee8540632006-05-30 09:24:40 +0000122%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000123
124%type<tenum> Enum
125%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000126%type<tenumv> EnumDef
127
128%type<tconst> Const
129%type<tconstv> ConstValue
130%type<tconstv> ConstList
131%type<tconstv> ConstListContents
132%type<tconstv> ConstMap
133%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000134
135%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000136%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000137%type<tservice> Service
138
139%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000140%type<ttype> FunctionType
141%type<tservice> FunctionList
142
Mark Sleef5377b32006-10-10 01:42:59 +0000143%type<tstruct> ThrowsOptional
Mark Sleef0712dc2006-10-25 19:03:57 +0000144%type<tservice> ExtendsOptional
Mark Slee52f643d2006-08-09 00:03:43 +0000145%type<tbool> AsyncOptional
Mark Slee4f8da1d2006-10-12 02:47:27 +0000146%type<id> CppTypeOptional
Mark Slee52f643d2006-08-09 00:03:43 +0000147
Mark Slee31985722006-05-24 21:45:31 +0000148%%
149
Mark Sleef5377b32006-10-10 01:42:59 +0000150/**
151 * Thrift Grammar Implementation.
152 *
153 * For the most part this source file works its way top down from what you
154 * might expect to find in a typical .thrift file, i.e. type definitions and
155 * namespaces up top followed by service definitions using those types.
156 */
Mark Slee31985722006-05-24 21:45:31 +0000157
158Program:
Mark Sleef0712dc2006-10-25 19:03:57 +0000159 HeaderList DefinitionList
160 {
161 pdebug("Program -> Headers DefinitionList");
162 }
163
164HeaderList:
165 HeaderList Header
166 {
167 pdebug("HeaderList -> HeaderList Header");
168 }
169|
170 {
171 pdebug("HeaderList -> ");
172 }
173
174Header:
175 Include
176 {
177 pdebug("Header -> Include");
178 }
179| tok_namespace tok_identifier
180 {
181 pwarning(1, "'namespace' is deprecated. Use 'cpp_namespace' and/or 'java_package' instead");
182 if (g_parse_mode == PROGRAM) {
183 g_program->set_cpp_namespace($2);
184 g_program->set_java_package($2);
185 }
186 }
187| tok_cpp_namespace tok_identifier
188 {
189 pdebug("Header -> tok_cpp_namespace tok_identifier");
190 if (g_parse_mode == PROGRAM) {
191 g_program->set_cpp_namespace($2);
192 }
193 }
194| tok_cpp_include tok_literal
195 {
196 pdebug("Header -> tok_cpp_include tok_literal");
197 if (g_parse_mode == PROGRAM) {
198 g_program->add_cpp_include($2);
199 }
200 }
201| tok_java_package tok_identifier
202 {
203 pdebug("Header -> tok_java_package tok_identifier");
204 if (g_parse_mode == PROGRAM) {
205 g_program->set_java_package($2);
206 }
207 }
208
209Include:
210 tok_include tok_literal
211 {
212 pdebug("Include -> tok_include tok_literal");
213 if (g_parse_mode == INCLUDES) {
214 std::string path = include_file(std::string($2));
215 if (!path.empty()) {
216 g_program->add_include(path);
217 }
218 }
219 }
Mark Slee31985722006-05-24 21:45:31 +0000220
221DefinitionList:
222 DefinitionList Definition
223 {
224 pdebug("DefinitionList -> DefinitionList Definition");
225 }
226|
227 {
228 pdebug("DefinitionList -> ");
229 }
230
231Definition:
Mark Slee30152872006-11-28 01:24:07 +0000232 Const
233 {
234 pdebug("Definition -> Const");
235 if (g_parse_mode == PROGRAM) {
236 g_program->add_const($1);
237 }
238 }
239| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000240 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000241 pdebug("Definition -> TypeDefinition");
242 if (g_parse_mode == PROGRAM) {
243 g_scope->add_type($1->get_name(), $1);
244 if (g_parent_scope != NULL) {
245 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
246 }
247 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000248 }
Mark Slee31985722006-05-24 21:45:31 +0000249| Service
250 {
251 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000252 if (g_parse_mode == PROGRAM) {
253 g_scope->add_service($1->get_name(), $1);
254 if (g_parent_scope != NULL) {
255 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
256 }
257 g_program->add_service($1);
258 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000259 }
260
Mark Sleef0712dc2006-10-25 19:03:57 +0000261TypeDefinition:
262 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000263 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000264 pdebug("TypeDefinition -> Typedef");
265 if (g_parse_mode == PROGRAM) {
266 g_program->add_typedef($1);
267 }
268 }
269| Enum
270 {
271 pdebug("TypeDefinition -> Enum");
272 if (g_parse_mode == PROGRAM) {
273 g_program->add_enum($1);
274 }
275 }
276| Struct
277 {
278 pdebug("TypeDefinition -> Struct");
279 if (g_parse_mode == PROGRAM) {
280 g_program->add_struct($1);
281 }
282 }
283| Xception
284 {
285 pdebug("TypeDefinition -> Xception");
286 if (g_parse_mode == PROGRAM) {
287 g_program->add_xception($1);
288 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000289 }
Mark Slee31985722006-05-24 21:45:31 +0000290
291Typedef:
292 tok_typedef DefinitionType tok_identifier
293 {
294 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000295 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000296 $$ = td;
297 }
298
299Enum:
300 tok_enum tok_identifier '{' EnumDefList '}'
301 {
302 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
303 $$ = $4;
304 $$->set_name($2);
305 }
306
Mark Slee207cb462006-11-02 18:43:12 +0000307CommaOrSemicolonOptional:
308 ','
309 {}
310| ';'
311 {}
312|
313 {}
314
Mark Slee31985722006-05-24 21:45:31 +0000315EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000316 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000317 {
318 pdebug("EnumDefList -> EnumDefList EnumDef");
319 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000320 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000321 }
322|
323 {
324 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000325 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000326 }
327
328EnumDef:
Mark Slee207cb462006-11-02 18:43:12 +0000329 tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000330 {
Mark Slee30152872006-11-28 01:24:07 +0000331 pdebug("EnumDef -> tok_identifier = tok_int_constant");
Mark Slee31985722006-05-24 21:45:31 +0000332 if ($3 < 0) {
Mark Sleef0712dc2006-10-25 19:03:57 +0000333 pwarning(1, "Negative value supplied for enum %s.\n", $1);
Mark Slee31985722006-05-24 21:45:31 +0000334 }
Mark Slee30152872006-11-28 01:24:07 +0000335 $$ = new t_enum_value($1, $3);
Mark Slee31985722006-05-24 21:45:31 +0000336 }
337|
Mark Slee04cc6052006-11-15 21:25:34 +0000338 tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000339 {
Mark Slee30152872006-11-28 01:24:07 +0000340 pdebug("EnumDef -> tok_identifier");
341 $$ = new t_enum_value($1);
342 }
343
344Const:
345 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
346 {
347 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000348 if (g_parse_mode == PROGRAM) {
349 $$ = new t_const($2, $3, $5);
350 validate_const_type($$);
351 } else {
352 $$ = NULL;
353 }
Mark Slee30152872006-11-28 01:24:07 +0000354 }
355
356ConstValue:
357 tok_int_constant
358 {
359 pdebug("ConstValue => tok_int_constant");
360 $$ = new t_const_value();
361 $$->set_integer($1);
362 }
363| tok_dub_constant
364 {
365 pdebug("ConstValue => tok_dub_constant");
366 $$ = new t_const_value();
367 $$->set_double($1);
368 }
369| tok_literal
370 {
371 pdebug("ConstValue => tok_literal");
372 $$ = new t_const_value();
373 $$->set_string($1);
374 }
375| ConstList
376 {
377 pdebug("ConstValue => ConstList");
378 $$ = $1;
379 }
380| ConstMap
381 {
382 pdebug("ConstValue => ConstMap");
383 $$ = $1;
384 }
385
386ConstList:
387 '[' ConstListContents ']'
388 {
389 pdebug("ConstList => [ ConstListContents ]");
390 $$ = $2;
391 }
392
393ConstListContents:
394 ConstListContents ConstValue CommaOrSemicolonOptional
395 {
396 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
397 $$ = $1;
398 $$->add_list($2);
399 }
400|
401 {
402 pdebug("ConstListContents =>");
403 $$ = new t_const_value();
404 $$->set_list();
405 }
406
407ConstMap:
408 '{' ConstMapContents '}'
409 {
410 pdebug("ConstMap => { ConstMapContents }");
411 $$ = $2;
412 }
413
414ConstMapContents:
415 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
416 {
417 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
418 $$ = $1;
419 $$->add_map($2, $4);
420 }
421|
422 {
423 pdebug("ConstMapContents =>");
424 $$ = new t_const_value();
425 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000426 }
427
428Struct:
429 tok_struct tok_identifier '{' FieldList '}'
430 {
431 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
Mark Sleee8540632006-05-30 09:24:40 +0000432 $4->set_name($2);
433 $$ = $4;
Mark Slee9cb7c612006-09-01 22:17:45 +0000434 y_field_val = -1;
435 }
436
437Xception:
438 tok_xception tok_identifier '{' FieldList '}'
439 {
440 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
441 $4->set_name($2);
442 $4->set_xception(true);
443 $$ = $4;
444 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000445 }
446
447Service:
Mark Sleef0712dc2006-10-25 19:03:57 +0000448 tok_service tok_identifier ExtendsOptional '{' FunctionList '}'
Mark Slee31985722006-05-24 21:45:31 +0000449 {
450 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Sleef0712dc2006-10-25 19:03:57 +0000451 $$ = $5;
Mark Slee31985722006-05-24 21:45:31 +0000452 $$->set_name($2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000453 $$->set_extends($3);
454 }
455
456ExtendsOptional:
457 tok_extends tok_identifier
458 {
459 pdebug("ExtendsOptional -> tok_extends tok_identifier");
460 $$ = NULL;
461 if (g_parse_mode == PROGRAM) {
462 $$ = g_scope->get_service($2);
463 if ($$ == NULL) {
464 yyerror("Service \"%s\" has not been defined.", $2);
465 exit(1);
466 }
467 }
468 }
469|
470 {
471 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000472 }
473
474FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000475 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000476 {
477 pdebug("FunctionList -> FunctionList Function");
478 $$ = $1;
479 $1->add_function($2);
480 }
481|
482 {
483 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000484 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000485 }
486
487Function:
Mark Slee207cb462006-11-02 18:43:12 +0000488 AsyncOptional FunctionType tok_identifier '(' FieldList ')' ThrowsOptional CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000489 {
Mark Sleeb15a68b2006-06-07 06:46:24 +0000490 $5->set_name(std::string($3) + "_args");
Mark Slee4e755ca2006-09-12 00:46:08 +0000491 $$ = new t_function($2, $3, $5, $7, $1);
Mark Slee9cb7c612006-09-01 22:17:45 +0000492 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000493 }
494
Mark Slee52f643d2006-08-09 00:03:43 +0000495AsyncOptional:
496 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000497 {
Mark Slee52f643d2006-08-09 00:03:43 +0000498 $$ = true;
499 }
500|
501 {
502 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000503 }
504
Mark Slee9cb7c612006-09-01 22:17:45 +0000505ThrowsOptional:
506 tok_throws '(' FieldList ')'
507 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000508 pdebug("ThrowsOptional -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000509 $$ = $3;
510 }
511|
512 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000513 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000514 }
515
Mark Slee31985722006-05-24 21:45:31 +0000516FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000517 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000518 {
519 pdebug("FieldList -> FieldList , Field");
520 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000521 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000522 }
523|
524 {
525 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000526 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000527 }
528
529Field:
Mark Slee207cb462006-11-02 18:43:12 +0000530 tok_int_constant ':' FieldType tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000531 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000532 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
533 if ($1 <= 0) {
534 pwarning(1, "Nonpositive value (%d) not allowed as a field key for '%s'.\n", $1, $4);
535 $1 = y_field_val--;
Mark Slee31985722006-05-24 21:45:31 +0000536 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000537 $$ = new t_field($3, $4, $1);
Mark Slee31985722006-05-24 21:45:31 +0000538 }
Mark Slee2329a832006-11-09 00:23:30 +0000539| FieldType tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000540 {
Mark Sleee8540632006-05-30 09:24:40 +0000541 pdebug("Field -> FieldType tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000542 pwarning(2, "No field key specified for '%s', resulting protocol may have conflicts or not be backwards compatible!\n", $2);
Mark Slee9cb7c612006-09-01 22:17:45 +0000543 $$ = new t_field($1, $2, y_field_val--);
Mark Slee31985722006-05-24 21:45:31 +0000544 }
Mark Slee2329a832006-11-09 00:23:30 +0000545| FieldType tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Sleef0712dc2006-10-25 19:03:57 +0000546 {
Mark Slee2329a832006-11-09 00:23:30 +0000547 pwarning(1, "Trailing = id notation is deprecated. Use 'Id: Type Name' notation instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000548 pdebug("Field -> FieldType tok_identifier = tok_int_constant");
549 if ($4 <= 0) {
550 pwarning(1, "Nonpositive value (%d) not allowed as a field key for '%s'.\n", $4, $2);
551 $4 = y_field_val--;
552 }
553 $$ = new t_field($1, $2, $4);
554 }
Mark Slee31985722006-05-24 21:45:31 +0000555
556DefinitionType:
557 BaseType
558 {
559 pdebug("DefinitionType -> BaseType");
560 $$ = $1;
561 }
Mark Sleee8540632006-05-30 09:24:40 +0000562| ContainerType
563 {
564 pdebug("DefinitionType -> ContainerType");
565 $$ = $1;
566 }
Mark Slee31985722006-05-24 21:45:31 +0000567
568FunctionType:
569 FieldType
570 {
Mark Sleee8540632006-05-30 09:24:40 +0000571 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000572 $$ = $1;
573 }
574| tok_void
575 {
Mark Sleee8540632006-05-30 09:24:40 +0000576 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000577 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000578 }
579
580FieldType:
581 tok_identifier
582 {
Mark Sleee8540632006-05-30 09:24:40 +0000583 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000584 if (g_parse_mode == INCLUDES) {
585 // Ignore identifiers in include mode
586 $$ = NULL;
587 } else {
588 // Lookup the identifier in the current scope
589 $$ = g_scope->get_type($1);
590 if ($$ == NULL) {
591 yyerror("Type \"%s\" has not been defined.", $1);
592 exit(1);
593 }
Mark Sleee8540632006-05-30 09:24:40 +0000594 }
Mark Slee31985722006-05-24 21:45:31 +0000595 }
596| BaseType
597 {
Mark Sleee8540632006-05-30 09:24:40 +0000598 pdebug("FieldType -> BaseType");
599 $$ = $1;
600 }
601| ContainerType
602 {
603 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000604 $$ = $1;
605 }
606
607BaseType:
608 tok_string
609 {
610 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000611 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000612 }
Mark Slee78f58e22006-09-02 04:17:07 +0000613| tok_bool
614 {
615 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000616 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000617 }
Mark Slee31985722006-05-24 21:45:31 +0000618| tok_byte
619 {
620 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000621 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000622 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000623| tok_i16
624 {
625 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000626 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000627 }
Mark Slee31985722006-05-24 21:45:31 +0000628| tok_i32
629 {
630 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000631 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000632 }
Mark Slee31985722006-05-24 21:45:31 +0000633| tok_i64
634 {
635 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000636 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000637 }
Mark Sleec98d0502006-09-06 02:42:25 +0000638| tok_double
639 {
640 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000641 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000642 }
Mark Slee31985722006-05-24 21:45:31 +0000643
Mark Sleee8540632006-05-30 09:24:40 +0000644ContainerType:
645 MapType
646 {
647 pdebug("ContainerType -> MapType");
648 $$ = $1;
649 }
650| SetType
651 {
652 pdebug("ContainerType -> SetType");
653 $$ = $1;
654 }
655| ListType
656 {
657 pdebug("ContainerType -> ListType");
658 $$ = $1;
659 }
660
661MapType:
Mark Slee4f8da1d2006-10-12 02:47:27 +0000662 tok_map CppTypeOptional '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000663 {
664 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000665 $$ = new t_map($4, $6);
666 if ($2 != NULL) {
667 ((t_container*)$$)->set_cpp_name(std::string($2));
668 }
Mark Sleee8540632006-05-30 09:24:40 +0000669 }
670
671SetType:
Mark Slee4f8da1d2006-10-12 02:47:27 +0000672 tok_set CppTypeOptional '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000673 {
674 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000675 $$ = new t_set($4);
676 if ($2 != NULL) {
677 ((t_container*)$$)->set_cpp_name(std::string($2));
678 }
Mark Sleee8540632006-05-30 09:24:40 +0000679 }
680
681ListType:
Mark Sleef0712dc2006-10-25 19:03:57 +0000682 tok_list '<' FieldType '>' CppTypeOptional
Mark Sleee8540632006-05-30 09:24:40 +0000683 {
684 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +0000685 $$ = new t_list($3);
686 if ($5 != NULL) {
687 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +0000688 }
689 }
690
691CppTypeOptional:
Mark Sleef0712dc2006-10-25 19:03:57 +0000692 '[' tok_cpp_type tok_literal ']'
Mark Slee4f8da1d2006-10-12 02:47:27 +0000693 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000694 $$ = $3;
Mark Slee4f8da1d2006-10-12 02:47:27 +0000695 }
696|
697 {
698 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +0000699 }
700
Mark Slee31985722006-05-24 21:45:31 +0000701%%