blob: 61febebcbeeccd6735cf47cb05daaac8a31b8d52 [file] [log] [blame]
Mark Slee31985722006-05-24 21:45:31 +00001%{
Mark Sleee9ce01c2007-05-16 02:29:53 +00002// Copyright (c) 2006- Facebook
3// Distributed under the Thrift Software License
4//
5// See accompanying file LICENSE or visit the Thrift site at:
6// http://developers.facebook.com/thrift/
Mark Slee31985722006-05-24 21:45:31 +00007
8/**
9 * Thrift parser.
10 *
11 * This parser is used on a thrift definition file.
12 *
13 * @author Mark Slee <mcslee@facebook.com>
14 */
15
16#include <stdio.h>
17#include "main.h"
18#include "globals.h"
19#include "parse/t_program.h"
Mark Sleef0712dc2006-10-25 19:03:57 +000020#include "parse/t_scope.h"
Mark Slee31985722006-05-24 21:45:31 +000021
Mark Sleef5377b32006-10-10 01:42:59 +000022/**
23 * This global variable is used for automatic numbering of field indices etc.
24 * when parsing the members of a struct. Field values are automatically
25 * assigned starting from -1 and working their way down.
26 */
Mark Slee9cb7c612006-09-01 22:17:45 +000027int y_field_val = -1;
Mark Slee78165722007-09-10 22:08:49 +000028int g_arglist = 0;
Mark Slee31985722006-05-24 21:45:31 +000029
30%}
31
Mark Sleef5377b32006-10-10 01:42:59 +000032/**
33 * This structure is used by the parser to hold the data types associated with
34 * various parse nodes.
35 */
Mark Slee31985722006-05-24 21:45:31 +000036%union {
Mark Slee30152872006-11-28 01:24:07 +000037 char* id;
38 int iconst;
39 double dconst;
40 bool tbool;
David Reisscdffe262007-08-14 17:12:31 +000041 t_doc* tdoc;
Mark Slee30152872006-11-28 01:24:07 +000042 t_type* ttype;
Mark Slee6a47fed2007-02-07 02:40:59 +000043 t_base_type* tbase;
Mark Slee30152872006-11-28 01:24:07 +000044 t_typedef* ttypedef;
45 t_enum* tenum;
46 t_enum_value* tenumv;
47 t_const* tconst;
48 t_const_value* tconstv;
49 t_struct* tstruct;
50 t_service* tservice;
51 t_function* tfunction;
52 t_field* tfield;
David Reisscdffe262007-08-14 17:12:31 +000053 char* dtext;
David Reiss8320a922007-08-14 19:59:26 +000054 t_field::e_req ereq;
Mark Slee31985722006-05-24 21:45:31 +000055}
56
Mark Sleef5377b32006-10-10 01:42:59 +000057/**
58 * Strings identifier
59 */
Mark Slee31985722006-05-24 21:45:31 +000060%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000061%token<id> tok_literal
David Reisscdffe262007-08-14 17:12:31 +000062%token<dtext> tok_doctext
Mark Sleebd588222007-11-21 08:43:35 +000063%token<id> tok_st_identifier
Mark Sleef5377b32006-10-10 01:42:59 +000064
65/**
Mark Slee30152872006-11-28 01:24:07 +000066 * Constant values
Mark Sleef5377b32006-10-10 01:42:59 +000067 */
Mark Slee31985722006-05-24 21:45:31 +000068%token<iconst> tok_int_constant
Mark Slee30152872006-11-28 01:24:07 +000069%token<dconst> tok_dub_constant
Mark Slee31985722006-05-24 21:45:31 +000070
Mark Sleef5377b32006-10-10 01:42:59 +000071/**
David Reiss399442b2008-02-20 02:28:05 +000072 * Header keywords
Mark Sleef5377b32006-10-10 01:42:59 +000073 */
Mark Sleef0712dc2006-10-25 19:03:57 +000074%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000075%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000076%token tok_cpp_namespace
77%token tok_cpp_include
78%token tok_cpp_type
Mark Sleee888b372007-01-12 01:06:24 +000079%token tok_php_namespace
David Reissc6fc3292007-08-30 00:58:43 +000080%token tok_py_module
Mark Slee27ed6ec2007-08-16 01:26:31 +000081%token tok_perl_package
Mark Sleef0712dc2006-10-25 19:03:57 +000082%token tok_java_package
Mark Slee782abbb2007-01-19 00:17:02 +000083%token tok_xsd_all
Mark Slee36bfa2e2007-01-19 20:09:51 +000084%token tok_xsd_optional
Mark Slee7df0e2a2007-02-06 21:03:18 +000085%token tok_xsd_nillable
Mark Slee0d9199e2007-01-31 02:08:30 +000086%token tok_xsd_namespace
Mark Slee21135c32007-02-05 21:52:08 +000087%token tok_xsd_attrs
Mark Slee58dfb4f2007-07-06 02:45:25 +000088%token tok_ruby_namespace
Mark Sleebd588222007-11-21 08:43:35 +000089%token tok_smalltalk_category
David Reiss15457c92007-12-14 07:03:03 +000090%token tok_smalltalk_prefix
Mark Slee7e9eea42007-09-10 21:00:23 +000091%token tok_cocoa_prefix
David Reiss7f42bcf2008-01-11 20:59:12 +000092%token tok_csharp_namespace
Mark Slee9cb7c612006-09-01 22:17:45 +000093
Mark Sleef5377b32006-10-10 01:42:59 +000094/**
95 * Base datatype keywords
96 */
97%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +000098%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +000099%token tok_byte
100%token tok_string
Mark Slee8d725a22007-04-13 01:57:12 +0000101%token tok_binary
Mark Sleeb6200d82007-01-19 19:14:36 +0000102%token tok_slist
Mark Slee6a47fed2007-02-07 02:40:59 +0000103%token tok_senum
Mark Slee9cb7c612006-09-01 22:17:45 +0000104%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +0000105%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +0000106%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +0000107%token tok_double
Mark Slee31985722006-05-24 21:45:31 +0000108
Mark Sleef5377b32006-10-10 01:42:59 +0000109/**
110 * Complex type keywords
111 */
Mark Slee31985722006-05-24 21:45:31 +0000112%token tok_map
113%token tok_list
114%token tok_set
115
Mark Sleef5377b32006-10-10 01:42:59 +0000116/**
117 * Function modifiers
Mark Slee27ed6ec2007-08-16 01:26:31 +0000118 */
Mark Slee31985722006-05-24 21:45:31 +0000119%token tok_async
120
Mark Sleef5377b32006-10-10 01:42:59 +0000121/**
122 * Thrift language keywords
123 */
Mark Slee31985722006-05-24 21:45:31 +0000124%token tok_typedef
125%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000126%token tok_xception
127%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000128%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000129%token tok_service
130%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000131%token tok_const
David Reiss8320a922007-08-14 19:59:26 +0000132%token tok_required
133%token tok_optional
Mark Slee31985722006-05-24 21:45:31 +0000134
Mark Sleef5377b32006-10-10 01:42:59 +0000135/**
136 * Grammar nodes
137 */
138
Mark Slee31985722006-05-24 21:45:31 +0000139%type<ttype> BaseType
Mark Sleee8540632006-05-30 09:24:40 +0000140%type<ttype> ContainerType
141%type<ttype> MapType
142%type<ttype> SetType
143%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000144
David Reisscdffe262007-08-14 17:12:31 +0000145%type<tdoc> Definition
Mark Sleef0712dc2006-10-25 19:03:57 +0000146%type<ttype> TypeDefinition
147
Mark Slee31985722006-05-24 21:45:31 +0000148%type<ttypedef> Typedef
149%type<ttype> DefinitionType
150
151%type<tfield> Field
Mark Slee7ff32452007-02-01 05:26:18 +0000152%type<iconst> FieldIdentifier
David Reiss8320a922007-08-14 19:59:26 +0000153%type<ereq> FieldRequiredness
Mark Slee31985722006-05-24 21:45:31 +0000154%type<ttype> FieldType
Mark Slee7ff32452007-02-01 05:26:18 +0000155%type<tconstv> FieldValue
Mark Sleee8540632006-05-30 09:24:40 +0000156%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000157
158%type<tenum> Enum
159%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000160%type<tenumv> EnumDef
161
Mark Slee6a47fed2007-02-07 02:40:59 +0000162%type<ttypedef> Senum
163%type<tbase> SenumDefList
164%type<id> SenumDef
165
Mark Slee30152872006-11-28 01:24:07 +0000166%type<tconst> Const
167%type<tconstv> ConstValue
168%type<tconstv> ConstList
169%type<tconstv> ConstListContents
170%type<tconstv> ConstMap
171%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000172
173%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000174%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000175%type<tservice> Service
176
177%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000178%type<ttype> FunctionType
179%type<tservice> FunctionList
180
Mark Slee36bfa2e2007-01-19 20:09:51 +0000181%type<tstruct> Throws
182%type<tservice> Extends
183%type<tbool> Async
184%type<tbool> XsdAll
185%type<tbool> XsdOptional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000186%type<tbool> XsdNillable
Mark Slee748d83f2007-02-07 01:20:08 +0000187%type<tstruct> XsdAttributes
Mark Slee36bfa2e2007-01-19 20:09:51 +0000188%type<id> CppType
Mark Slee52f643d2006-08-09 00:03:43 +0000189
David Reisscbd4bac2007-08-14 17:12:33 +0000190%type<dtext> CaptureDocText
ccheeverf53b5cf2007-02-05 20:33:11 +0000191
Mark Slee31985722006-05-24 21:45:31 +0000192%%
193
Mark Sleef5377b32006-10-10 01:42:59 +0000194/**
195 * Thrift Grammar Implementation.
196 *
197 * For the most part this source file works its way top down from what you
198 * might expect to find in a typical .thrift file, i.e. type definitions and
199 * namespaces up top followed by service definitions using those types.
200 */
Mark Slee31985722006-05-24 21:45:31 +0000201
202Program:
David Reisscbd4bac2007-08-14 17:12:33 +0000203 HeaderList DefinitionList
Mark Sleef0712dc2006-10-25 19:03:57 +0000204 {
205 pdebug("Program -> Headers DefinitionList");
David Reisscbd4bac2007-08-14 17:12:33 +0000206 /*
207 TODO(dreiss): Decide whether full-program doctext is worth the trouble.
David Reissc2532a92007-07-30 23:46:11 +0000208 if ($1 != NULL) {
209 g_program->set_doc($1);
210 }
David Reisscbd4bac2007-08-14 17:12:33 +0000211 */
212 clear_doctext();
Mark Sleef0712dc2006-10-25 19:03:57 +0000213 }
214
David Reisscbd4bac2007-08-14 17:12:33 +0000215CaptureDocText:
216 {
217 if (g_parse_mode == PROGRAM) {
Mark Sleebd588222007-11-21 08:43:35 +0000218 $$ = g_doctext;
David Reisscbd4bac2007-08-14 17:12:33 +0000219 g_doctext = NULL;
Mark Slee27ed6ec2007-08-16 01:26:31 +0000220 } else {
David Reisscbd4bac2007-08-14 17:12:33 +0000221 $$ = NULL;
222 }
223 }
224
225/* TODO(dreiss): Try to DestroyDocText in all sorts or random places. */
226DestroyDocText:
227 {
228 if (g_parse_mode == PROGRAM) {
229 clear_doctext();
230 }
231 }
232
233/* We have to DestroyDocText here, otherwise it catches the doctext
234 on the first real element. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000235HeaderList:
David Reisscbd4bac2007-08-14 17:12:33 +0000236 HeaderList DestroyDocText Header
Mark Sleef0712dc2006-10-25 19:03:57 +0000237 {
238 pdebug("HeaderList -> HeaderList Header");
239 }
240|
241 {
242 pdebug("HeaderList -> ");
243 }
244
245Header:
246 Include
247 {
248 pdebug("Header -> Include");
249 }
David Reiss79eca142008-02-27 01:55:13 +0000250| tok_namespace tok_identifier tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +0000251 {
David Reiss79eca142008-02-27 01:55:13 +0000252 pdebug("Header -> tok_namespace tok_identifier tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000253 if (g_parse_mode == PROGRAM) {
David Reiss79eca142008-02-27 01:55:13 +0000254 g_program->set_namespace($2, $3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000255 }
256 }
David Reiss9a08dc62008-02-27 01:55:17 +0000257/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000258| tok_cpp_namespace tok_identifier
259 {
David Reiss9a08dc62008-02-27 01:55:17 +0000260 pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000261 pdebug("Header -> tok_cpp_namespace tok_identifier");
262 if (g_parse_mode == PROGRAM) {
David Reiss9a08dc62008-02-27 01:55:17 +0000263 g_program->set_namespace("cpp", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000264 }
265 }
266| tok_cpp_include tok_literal
267 {
268 pdebug("Header -> tok_cpp_include tok_literal");
269 if (g_parse_mode == PROGRAM) {
270 g_program->add_cpp_include($2);
271 }
272 }
Mark Sleee888b372007-01-12 01:06:24 +0000273| tok_php_namespace tok_identifier
274 {
275 pdebug("Header -> tok_php_namespace tok_identifier");
276 if (g_parse_mode == PROGRAM) {
277 g_program->set_php_namespace($2);
278 }
279 }
David Reissc6fc3292007-08-30 00:58:43 +0000280| tok_py_module tok_identifier
281 {
282 pdebug("Header -> tok_py_module tok_identifier");
283 if (g_parse_mode == PROGRAM) {
284 g_program->set_py_module($2);
285 }
286 }
Mark Slee27ed6ec2007-08-16 01:26:31 +0000287| tok_perl_package tok_identifier
288 {
289 pdebug("Header -> tok_perl_namespace tok_identifier");
290 if (g_parse_mode == PROGRAM) {
291 g_program->set_perl_package($2);
292 }
293 }
Mark Slee58dfb4f2007-07-06 02:45:25 +0000294| tok_ruby_namespace tok_identifier
295 {
296 pdebug("Header -> tok_ruby_namespace tok_identifier");
297 if (g_parse_mode == PROGRAM) {
298 g_program->set_ruby_namespace($2);
299 }
300 }
David Reiss3b455012008-03-27 21:40:46 +0000301/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleebd588222007-11-21 08:43:35 +0000302| tok_smalltalk_category tok_st_identifier
303 {
David Reiss3b455012008-03-27 21:40:46 +0000304 pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
Mark Sleebd588222007-11-21 08:43:35 +0000305 pdebug("Header -> tok_smalltalk_category tok_st_identifier");
306 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000307 g_program->set_namespace("smalltalk.category", $2);
Mark Sleebd588222007-11-21 08:43:35 +0000308 }
309 }
David Reiss3b455012008-03-27 21:40:46 +0000310/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss15457c92007-12-14 07:03:03 +0000311| tok_smalltalk_prefix tok_identifier
312 {
David Reiss3b455012008-03-27 21:40:46 +0000313 pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
David Reiss15457c92007-12-14 07:03:03 +0000314 pdebug("Header -> tok_smalltalk_prefix tok_identifier");
315 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000316 g_program->set_namespace("smalltalk.prefix", $2);
David Reiss15457c92007-12-14 07:03:03 +0000317 }
318 }
David Reiss771f8c72008-02-27 01:55:25 +0000319/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000320| tok_java_package tok_identifier
321 {
David Reiss9f646152008-03-02 21:59:48 +0000322 pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000323 pdebug("Header -> tok_java_package tok_identifier");
324 if (g_parse_mode == PROGRAM) {
David Reiss771f8c72008-02-27 01:55:25 +0000325 g_program->set_namespace("java", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000326 }
327 }
David Reiss54b602b2008-03-27 21:41:06 +0000328/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee7e9eea42007-09-10 21:00:23 +0000329| tok_cocoa_prefix tok_identifier
330 {
David Reiss54b602b2008-03-27 21:41:06 +0000331 pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
Mark Slee7e9eea42007-09-10 21:00:23 +0000332 pdebug("Header -> tok_cocoa_prefix tok_identifier");
333 if (g_parse_mode == PROGRAM) {
David Reiss54b602b2008-03-27 21:41:06 +0000334 g_program->set_namespace("cocoa", $2);
Mark Slee7e9eea42007-09-10 21:00:23 +0000335 }
336 }
Mark Slee0d9199e2007-01-31 02:08:30 +0000337| tok_xsd_namespace tok_literal
338 {
339 pdebug("Header -> tok_xsd_namespace tok_literal");
340 if (g_parse_mode == PROGRAM) {
341 g_program->set_xsd_namespace($2);
342 }
343 }
David Reiss7f42bcf2008-01-11 20:59:12 +0000344| tok_csharp_namespace tok_identifier
345 {
David Reiss919ae802008-03-27 21:41:11 +0000346 pdebug("Header -> tok_csharp_namespace tok_identifier");
David Reiss7f42bcf2008-01-11 20:59:12 +0000347 if (g_parse_mode == PROGRAM) {
348 g_program->set_csharp_namespace($2);
349 }
350 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000351
352Include:
353 tok_include tok_literal
354 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000355 pdebug("Include -> tok_include tok_literal");
Mark Sleef0712dc2006-10-25 19:03:57 +0000356 if (g_parse_mode == INCLUDES) {
357 std::string path = include_file(std::string($2));
358 if (!path.empty()) {
kholst76f2c882008-01-16 02:47:41 +0000359 g_program->add_include(path, std::string($2));
Mark Sleef0712dc2006-10-25 19:03:57 +0000360 }
361 }
362 }
Mark Slee31985722006-05-24 21:45:31 +0000363
364DefinitionList:
David Reisscbd4bac2007-08-14 17:12:33 +0000365 DefinitionList CaptureDocText Definition
Mark Slee31985722006-05-24 21:45:31 +0000366 {
367 pdebug("DefinitionList -> DefinitionList Definition");
David Reisscdffe262007-08-14 17:12:31 +0000368 if ($2 != NULL && $3 != NULL) {
369 $3->set_doc($2);
370 }
Mark Slee31985722006-05-24 21:45:31 +0000371 }
372|
373 {
374 pdebug("DefinitionList -> ");
375 }
376
377Definition:
Mark Slee30152872006-11-28 01:24:07 +0000378 Const
379 {
380 pdebug("Definition -> Const");
381 if (g_parse_mode == PROGRAM) {
382 g_program->add_const($1);
Mark Sleebd588222007-11-21 08:43:35 +0000383 }
David Reisscdffe262007-08-14 17:12:31 +0000384 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000385 }
386| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000387 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000388 pdebug("Definition -> TypeDefinition");
389 if (g_parse_mode == PROGRAM) {
390 g_scope->add_type($1->get_name(), $1);
391 if (g_parent_scope != NULL) {
392 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
393 }
394 }
David Reisscdffe262007-08-14 17:12:31 +0000395 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000396 }
Mark Slee31985722006-05-24 21:45:31 +0000397| Service
398 {
399 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000400 if (g_parse_mode == PROGRAM) {
401 g_scope->add_service($1->get_name(), $1);
402 if (g_parent_scope != NULL) {
403 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
404 }
405 g_program->add_service($1);
406 }
David Reisscdffe262007-08-14 17:12:31 +0000407 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000408 }
409
Mark Sleef0712dc2006-10-25 19:03:57 +0000410TypeDefinition:
411 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000412 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000413 pdebug("TypeDefinition -> Typedef");
414 if (g_parse_mode == PROGRAM) {
415 g_program->add_typedef($1);
416 }
417 }
418| Enum
419 {
420 pdebug("TypeDefinition -> Enum");
421 if (g_parse_mode == PROGRAM) {
422 g_program->add_enum($1);
423 }
424 }
Mark Slee6a47fed2007-02-07 02:40:59 +0000425| Senum
426 {
427 pdebug("TypeDefinition -> Senum");
428 if (g_parse_mode == PROGRAM) {
429 g_program->add_typedef($1);
430 }
431 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000432| Struct
433 {
434 pdebug("TypeDefinition -> Struct");
435 if (g_parse_mode == PROGRAM) {
436 g_program->add_struct($1);
437 }
438 }
439| Xception
Mark Slee27ed6ec2007-08-16 01:26:31 +0000440 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000441 pdebug("TypeDefinition -> Xception");
442 if (g_parse_mode == PROGRAM) {
443 g_program->add_xception($1);
444 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000445 }
Mark Slee31985722006-05-24 21:45:31 +0000446
447Typedef:
Mark Sleebd588222007-11-21 08:43:35 +0000448 tok_typedef DefinitionType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000449 {
450 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
David Reisscdffe262007-08-14 17:12:31 +0000451 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000452 $$ = td;
453 }
454
Mark Slee6a47fed2007-02-07 02:40:59 +0000455CommaOrSemicolonOptional:
456 ','
457 {}
458| ';'
459 {}
460|
461 {}
ccheeverf53b5cf2007-02-05 20:33:11 +0000462
Mark Slee31985722006-05-24 21:45:31 +0000463Enum:
David Reisscdffe262007-08-14 17:12:31 +0000464 tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000465 {
466 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000467 $$ = $4;
468 $$->set_name($2);
Mark Slee31985722006-05-24 21:45:31 +0000469 }
470
471EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000472 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000473 {
474 pdebug("EnumDefList -> EnumDefList EnumDef");
475 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000476 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000477 }
478|
479 {
480 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000481 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000482 }
483
484EnumDef:
David Reisscbd4bac2007-08-14 17:12:33 +0000485 CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000486 {
Mark Slee30152872006-11-28 01:24:07 +0000487 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000488 if ($4 < 0) {
489 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000490 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000491 $$ = new t_enum_value($2, $4);
492 if ($1 != NULL) {
493 $$->set_doc($1);
494 }
Mark Sleed0767c52007-07-27 22:14:41 +0000495 if (g_parse_mode == PROGRAM) {
496 g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4)));
497 if (g_parent_scope != NULL) {
498 g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4)));
499 }
500 }
Mark Slee31985722006-05-24 21:45:31 +0000501 }
502|
David Reisscbd4bac2007-08-14 17:12:33 +0000503 CaptureDocText tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000504 {
Mark Slee30152872006-11-28 01:24:07 +0000505 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000506 $$ = new t_enum_value($2);
507 if ($1 != NULL) {
508 $$->set_doc($1);
509 }
Mark Slee30152872006-11-28 01:24:07 +0000510 }
511
Mark Slee6a47fed2007-02-07 02:40:59 +0000512Senum:
David Reisscdffe262007-08-14 17:12:31 +0000513 tok_senum tok_identifier '{' SenumDefList '}'
Mark Slee6a47fed2007-02-07 02:40:59 +0000514 {
515 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000516 $$ = new t_typedef(g_program, $4, $2);
Mark Slee6a47fed2007-02-07 02:40:59 +0000517 }
518
519SenumDefList:
520 SenumDefList SenumDef
521 {
522 pdebug("SenumDefList -> SenumDefList SenumDef");
523 $$ = $1;
524 $$->add_string_enum_val($2);
525 }
526|
527 {
528 pdebug("SenumDefList -> ");
529 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
530 $$->set_string_enum(true);
531 }
532
533SenumDef:
534 tok_literal CommaOrSemicolonOptional
535 {
536 pdebug("SenumDef -> tok_literal");
537 $$ = $1;
538 }
539
Mark Slee30152872006-11-28 01:24:07 +0000540Const:
541 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
542 {
543 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000544 if (g_parse_mode == PROGRAM) {
545 $$ = new t_const($2, $3, $5);
546 validate_const_type($$);
Mark Sleed0767c52007-07-27 22:14:41 +0000547
548 g_scope->add_constant($3, $$);
549 if (g_parent_scope != NULL) {
550 g_parent_scope->add_constant(g_parent_prefix + $3, $$);
551 }
552
Mark Sleeaa7671d2006-11-29 03:19:31 +0000553 } else {
554 $$ = NULL;
555 }
Mark Slee30152872006-11-28 01:24:07 +0000556 }
557
558ConstValue:
559 tok_int_constant
560 {
561 pdebug("ConstValue => tok_int_constant");
562 $$ = new t_const_value();
563 $$->set_integer($1);
564 }
565| tok_dub_constant
566 {
567 pdebug("ConstValue => tok_dub_constant");
568 $$ = new t_const_value();
569 $$->set_double($1);
570 }
571| tok_literal
572 {
573 pdebug("ConstValue => tok_literal");
Mark Sleed0767c52007-07-27 22:14:41 +0000574 $$ = new t_const_value($1);
Mark Slee30152872006-11-28 01:24:07 +0000575 }
Mark Slee67fc6342006-11-29 03:37:04 +0000576| tok_identifier
577 {
578 pdebug("ConstValue => tok_identifier");
Mark Sleed0767c52007-07-27 22:14:41 +0000579 t_const* constant = g_scope->get_constant($1);
580 if (constant != NULL) {
581 $$ = constant->get_value();
582 } else {
583 if (g_parse_mode == PROGRAM) {
584 pwarning(1, "Constant strings should be quoted: %s\n", $1);
585 }
586 $$ = new t_const_value($1);
587 }
Mark Slee67fc6342006-11-29 03:37:04 +0000588 }
Mark Slee30152872006-11-28 01:24:07 +0000589| ConstList
590 {
591 pdebug("ConstValue => ConstList");
592 $$ = $1;
593 }
594| ConstMap
595 {
596 pdebug("ConstValue => ConstMap");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000597 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000598 }
599
600ConstList:
601 '[' ConstListContents ']'
602 {
603 pdebug("ConstList => [ ConstListContents ]");
604 $$ = $2;
605 }
606
607ConstListContents:
608 ConstListContents ConstValue CommaOrSemicolonOptional
609 {
610 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
611 $$ = $1;
612 $$->add_list($2);
613 }
614|
615 {
616 pdebug("ConstListContents =>");
617 $$ = new t_const_value();
618 $$->set_list();
619 }
620
621ConstMap:
622 '{' ConstMapContents '}'
623 {
624 pdebug("ConstMap => { ConstMapContents }");
625 $$ = $2;
626 }
627
628ConstMapContents:
629 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
630 {
631 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
632 $$ = $1;
633 $$->add_map($2, $4);
634 }
635|
636 {
637 pdebug("ConstMapContents =>");
638 $$ = new t_const_value();
639 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000640 }
641
642Struct:
David Reisscdffe262007-08-14 17:12:31 +0000643 tok_struct tok_identifier XsdAll '{' FieldList '}'
Mark Slee31985722006-05-24 21:45:31 +0000644 {
645 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
David Reisscdffe262007-08-14 17:12:31 +0000646 $5->set_name($2);
647 $5->set_xsd_all($3);
648 $$ = $5;
Mark Slee9cb7c612006-09-01 22:17:45 +0000649 y_field_val = -1;
650 }
651
Mark Slee36bfa2e2007-01-19 20:09:51 +0000652XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000653 tok_xsd_all
654 {
655 $$ = true;
656 }
657|
658 {
659 $$ = false;
660 }
661
Mark Slee36bfa2e2007-01-19 20:09:51 +0000662XsdOptional:
663 tok_xsd_optional
664 {
665 $$ = true;
666 }
667|
668 {
669 $$ = false;
670 }
671
Mark Slee7df0e2a2007-02-06 21:03:18 +0000672XsdNillable:
673 tok_xsd_nillable
674 {
675 $$ = true;
676 }
677|
678 {
679 $$ = false;
680 }
681
Mark Slee21135c32007-02-05 21:52:08 +0000682XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000683 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000684 {
Mark Slee748d83f2007-02-07 01:20:08 +0000685 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000686 }
687|
688 {
689 $$ = NULL;
690 }
691
Mark Slee9cb7c612006-09-01 22:17:45 +0000692Xception:
693 tok_xception tok_identifier '{' FieldList '}'
694 {
695 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
696 $4->set_name($2);
697 $4->set_xception(true);
698 $$ = $4;
699 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000700 }
701
702Service:
Mark Slee78165722007-09-10 22:08:49 +0000703 tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
Mark Slee31985722006-05-24 21:45:31 +0000704 {
705 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Slee78165722007-09-10 22:08:49 +0000706 $$ = $6;
David Reisscdffe262007-08-14 17:12:31 +0000707 $$->set_name($2);
708 $$->set_extends($3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000709 }
710
Mark Slee78165722007-09-10 22:08:49 +0000711FlagArgs:
712 {
713 g_arglist = 1;
714 }
715
716UnflagArgs:
717 {
718 g_arglist = 0;
719 }
720
Mark Slee36bfa2e2007-01-19 20:09:51 +0000721Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000722 tok_extends tok_identifier
723 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000724 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000725 $$ = NULL;
726 if (g_parse_mode == PROGRAM) {
727 $$ = g_scope->get_service($2);
728 if ($$ == NULL) {
729 yyerror("Service \"%s\" has not been defined.", $2);
730 exit(1);
731 }
732 }
733 }
734|
735 {
736 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000737 }
738
739FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000740 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000741 {
742 pdebug("FunctionList -> FunctionList Function");
743 $$ = $1;
744 $1->add_function($2);
745 }
746|
747 {
748 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000749 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000750 }
751
752Function:
David Reisscbd4bac2007-08-14 17:12:33 +0000753 CaptureDocText Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000754 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000755 $6->set_name(std::string($4) + "_args");
756 $$ = new t_function($3, $4, $6, $8, $2);
757 if ($1 != NULL) {
758 $$->set_doc($1);
759 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000760 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000761 }
762
Mark Slee36bfa2e2007-01-19 20:09:51 +0000763Async:
Mark Slee52f643d2006-08-09 00:03:43 +0000764 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000765 {
Mark Slee52f643d2006-08-09 00:03:43 +0000766 $$ = true;
767 }
768|
769 {
770 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000771 }
772
Mark Slee36bfa2e2007-01-19 20:09:51 +0000773Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000774 tok_throws '(' FieldList ')'
775 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000776 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000777 $$ = $3;
Mark Sleef07d48e2008-02-01 01:36:26 +0000778 if (g_parse_mode == PROGRAM && !validate_throws($$)) {
Mark Slee91f2b7b2008-01-31 01:49:16 +0000779 yyerror("Throws clause may not contain non-exception types");
780 exit(1);
781 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000782 }
783|
784 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000785 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000786 }
787
Mark Slee31985722006-05-24 21:45:31 +0000788FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000789 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000790 {
791 pdebug("FieldList -> FieldList , Field");
792 $$ = $1;
Mark Slee6f9ac3f2007-11-28 22:28:13 +0000793 if (!($$->validate_field($2))) {
794 yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
795 exit(1);
796 }
Mark Slee207cb462006-11-02 18:43:12 +0000797 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000798 }
799|
800 {
801 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000802 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000803 }
804
805Field:
David Reiss8320a922007-08-14 19:59:26 +0000806 CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000807 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000808 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000809 if ($2 < 0) {
David Reiss8320a922007-08-14 19:59:26 +0000810 pwarning(2, "No field key specified for %s, resulting protocol may have conflicts or not be backwards compatible!\n", $5);
Mark Slee31985722006-05-24 21:45:31 +0000811 }
David Reiss8320a922007-08-14 19:59:26 +0000812 $$ = new t_field($4, $5, $2);
813 $$->set_req($3);
814 if ($6 != NULL) {
815 validate_field_value($$, $6);
816 $$->set_value($6);
Mark Slee7ff32452007-02-01 05:26:18 +0000817 }
David Reiss8320a922007-08-14 19:59:26 +0000818 $$->set_xsd_optional($7);
819 $$->set_xsd_nillable($8);
ccheeverf53b5cf2007-02-05 20:33:11 +0000820 if ($1 != NULL) {
821 $$->set_doc($1);
822 }
David Reiss8320a922007-08-14 19:59:26 +0000823 if ($9 != NULL) {
824 $$->set_xsd_attrs($9);
Mark Slee21135c32007-02-05 21:52:08 +0000825 }
Mark Slee31985722006-05-24 21:45:31 +0000826 }
Mark Slee7ff32452007-02-01 05:26:18 +0000827
828FieldIdentifier:
829 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000830 {
Mark Slee7ff32452007-02-01 05:26:18 +0000831 if ($1 <= 0) {
832 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
833 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000834 }
Mark Slee7ff32452007-02-01 05:26:18 +0000835 $$ = $1;
836 }
837|
838 {
839 $$ = y_field_val--;
840 }
841
David Reiss8320a922007-08-14 19:59:26 +0000842FieldRequiredness:
843 tok_required
844 {
Mark Slee78165722007-09-10 22:08:49 +0000845 if (g_arglist) {
846 if (g_parse_mode == PROGRAM) {
847 pwarning(1, "required keyword is ignored in argument lists.\n");
848 }
David Reiss204420f2008-01-11 20:59:03 +0000849 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000850 } else {
David Reiss204420f2008-01-11 20:59:03 +0000851 $$ = t_field::T_REQUIRED;
Mark Slee78165722007-09-10 22:08:49 +0000852 }
David Reiss8320a922007-08-14 19:59:26 +0000853 }
854| tok_optional
855 {
Mark Slee78165722007-09-10 22:08:49 +0000856 if (g_arglist) {
857 if (g_parse_mode == PROGRAM) {
858 pwarning(1, "optional keyword is ignored in argument lists.\n");
859 }
David Reiss204420f2008-01-11 20:59:03 +0000860 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000861 } else {
David Reiss204420f2008-01-11 20:59:03 +0000862 $$ = t_field::T_OPTIONAL;
Mark Slee78165722007-09-10 22:08:49 +0000863 }
David Reiss8320a922007-08-14 19:59:26 +0000864 }
865|
866 {
David Reiss204420f2008-01-11 20:59:03 +0000867 $$ = t_field::T_OPT_IN_REQ_OUT;
David Reiss8320a922007-08-14 19:59:26 +0000868 }
869
Mark Slee7ff32452007-02-01 05:26:18 +0000870FieldValue:
871 '=' ConstValue
872 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000873 if (g_parse_mode == PROGRAM) {
Mark Slee7ff32452007-02-01 05:26:18 +0000874 $$ = $2;
875 } else {
876 $$ = NULL;
877 }
878 }
879|
880 {
881 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000882 }
Mark Slee31985722006-05-24 21:45:31 +0000883
884DefinitionType:
885 BaseType
886 {
887 pdebug("DefinitionType -> BaseType");
888 $$ = $1;
889 }
Mark Sleee8540632006-05-30 09:24:40 +0000890| ContainerType
891 {
892 pdebug("DefinitionType -> ContainerType");
893 $$ = $1;
894 }
Mark Slee31985722006-05-24 21:45:31 +0000895
896FunctionType:
897 FieldType
898 {
Mark Sleee8540632006-05-30 09:24:40 +0000899 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000900 $$ = $1;
901 }
902| tok_void
903 {
Mark Sleee8540632006-05-30 09:24:40 +0000904 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000905 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000906 }
907
908FieldType:
909 tok_identifier
910 {
Mark Sleee8540632006-05-30 09:24:40 +0000911 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000912 if (g_parse_mode == INCLUDES) {
913 // Ignore identifiers in include mode
914 $$ = NULL;
915 } else {
916 // Lookup the identifier in the current scope
917 $$ = g_scope->get_type($1);
918 if ($$ == NULL) {
919 yyerror("Type \"%s\" has not been defined.", $1);
920 exit(1);
921 }
Mark Sleee8540632006-05-30 09:24:40 +0000922 }
Mark Slee31985722006-05-24 21:45:31 +0000923 }
924| BaseType
925 {
Mark Sleee8540632006-05-30 09:24:40 +0000926 pdebug("FieldType -> BaseType");
927 $$ = $1;
928 }
929| ContainerType
930 {
931 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000932 $$ = $1;
933 }
934
935BaseType:
936 tok_string
937 {
938 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000939 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000940 }
Mark Slee8d725a22007-04-13 01:57:12 +0000941| tok_binary
942 {
943 pdebug("BaseType -> tok_binary");
944 $$ = g_type_binary;
945 }
Mark Sleeb6200d82007-01-19 19:14:36 +0000946| tok_slist
947 {
948 pdebug("BaseType -> tok_slist");
949 $$ = g_type_slist;
950 }
Mark Slee78f58e22006-09-02 04:17:07 +0000951| tok_bool
952 {
953 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000954 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000955 }
Mark Slee31985722006-05-24 21:45:31 +0000956| tok_byte
957 {
958 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000959 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000960 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000961| tok_i16
962 {
963 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000964 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000965 }
Mark Slee31985722006-05-24 21:45:31 +0000966| tok_i32
967 {
968 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000969 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000970 }
Mark Slee31985722006-05-24 21:45:31 +0000971| tok_i64
972 {
973 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000974 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000975 }
Mark Sleec98d0502006-09-06 02:42:25 +0000976| tok_double
977 {
978 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000979 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000980 }
Mark Slee31985722006-05-24 21:45:31 +0000981
Mark Sleee8540632006-05-30 09:24:40 +0000982ContainerType:
983 MapType
984 {
985 pdebug("ContainerType -> MapType");
986 $$ = $1;
987 }
988| SetType
989 {
990 pdebug("ContainerType -> SetType");
991 $$ = $1;
992 }
993| ListType
994 {
995 pdebug("ContainerType -> ListType");
996 $$ = $1;
997 }
998
999MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001000 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001001 {
1002 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001003 $$ = new t_map($4, $6);
1004 if ($2 != NULL) {
1005 ((t_container*)$$)->set_cpp_name(std::string($2));
1006 }
Mark Sleee8540632006-05-30 09:24:40 +00001007 }
1008
1009SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001010 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001011 {
1012 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001013 $$ = new t_set($4);
1014 if ($2 != NULL) {
1015 ((t_container*)$$)->set_cpp_name(std::string($2));
1016 }
Mark Sleee8540632006-05-30 09:24:40 +00001017 }
1018
1019ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001020 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +00001021 {
1022 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +00001023 $$ = new t_list($3);
1024 if ($5 != NULL) {
1025 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +00001026 }
1027 }
1028
Mark Slee36bfa2e2007-01-19 20:09:51 +00001029CppType:
Mark Sleeafc76542007-02-09 21:55:44 +00001030 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +00001031 {
Mark Sleeafc76542007-02-09 21:55:44 +00001032 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +00001033 }
1034|
1035 {
1036 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +00001037 }
1038
Mark Slee31985722006-05-24 21:45:31 +00001039%%