blob: 654c85affb21d8faf0d649596816826f6918f07b [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 Reiss320e45c2008-03-27 21:41:54 +0000280/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reissc6fc3292007-08-30 00:58:43 +0000281| tok_py_module tok_identifier
282 {
David Reiss320e45c2008-03-27 21:41:54 +0000283 pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead");
David Reissc6fc3292007-08-30 00:58:43 +0000284 pdebug("Header -> tok_py_module tok_identifier");
285 if (g_parse_mode == PROGRAM) {
David Reiss320e45c2008-03-27 21:41:54 +0000286 g_program->set_namespace("py", $2);
David Reissc6fc3292007-08-30 00:58:43 +0000287 }
288 }
David Reiss07ef3a92008-03-27 21:42:39 +0000289/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee27ed6ec2007-08-16 01:26:31 +0000290| tok_perl_package tok_identifier
291 {
David Reiss07ef3a92008-03-27 21:42:39 +0000292 pwarning(1, "'perl_package' is deprecated. Use 'namespace perl' instead");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000293 pdebug("Header -> tok_perl_namespace tok_identifier");
294 if (g_parse_mode == PROGRAM) {
David Reiss07ef3a92008-03-27 21:42:39 +0000295 g_program->set_namespace("perl", $2);
Mark Slee27ed6ec2007-08-16 01:26:31 +0000296 }
297 }
David Reiss6a4b82c2008-03-27 21:42:16 +0000298/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee58dfb4f2007-07-06 02:45:25 +0000299| tok_ruby_namespace tok_identifier
300 {
David Reiss6a4b82c2008-03-27 21:42:16 +0000301 pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead");
Mark Slee58dfb4f2007-07-06 02:45:25 +0000302 pdebug("Header -> tok_ruby_namespace tok_identifier");
303 if (g_parse_mode == PROGRAM) {
David Reiss6a4b82c2008-03-27 21:42:16 +0000304 g_program->set_namespace("rb", $2);
Mark Slee58dfb4f2007-07-06 02:45:25 +0000305 }
306 }
David Reiss3b455012008-03-27 21:40:46 +0000307/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleebd588222007-11-21 08:43:35 +0000308| tok_smalltalk_category tok_st_identifier
309 {
David Reiss3b455012008-03-27 21:40:46 +0000310 pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
Mark Sleebd588222007-11-21 08:43:35 +0000311 pdebug("Header -> tok_smalltalk_category tok_st_identifier");
312 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000313 g_program->set_namespace("smalltalk.category", $2);
Mark Sleebd588222007-11-21 08:43:35 +0000314 }
315 }
David Reiss3b455012008-03-27 21:40:46 +0000316/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss15457c92007-12-14 07:03:03 +0000317| tok_smalltalk_prefix tok_identifier
318 {
David Reiss3b455012008-03-27 21:40:46 +0000319 pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
David Reiss15457c92007-12-14 07:03:03 +0000320 pdebug("Header -> tok_smalltalk_prefix tok_identifier");
321 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000322 g_program->set_namespace("smalltalk.prefix", $2);
David Reiss15457c92007-12-14 07:03:03 +0000323 }
324 }
David Reiss771f8c72008-02-27 01:55:25 +0000325/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000326| tok_java_package tok_identifier
327 {
David Reiss9f646152008-03-02 21:59:48 +0000328 pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000329 pdebug("Header -> tok_java_package tok_identifier");
330 if (g_parse_mode == PROGRAM) {
David Reiss771f8c72008-02-27 01:55:25 +0000331 g_program->set_namespace("java", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000332 }
333 }
David Reiss54b602b2008-03-27 21:41:06 +0000334/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee7e9eea42007-09-10 21:00:23 +0000335| tok_cocoa_prefix tok_identifier
336 {
David Reiss54b602b2008-03-27 21:41:06 +0000337 pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
Mark Slee7e9eea42007-09-10 21:00:23 +0000338 pdebug("Header -> tok_cocoa_prefix tok_identifier");
339 if (g_parse_mode == PROGRAM) {
David Reiss54b602b2008-03-27 21:41:06 +0000340 g_program->set_namespace("cocoa", $2);
Mark Slee7e9eea42007-09-10 21:00:23 +0000341 }
342 }
Mark Slee0d9199e2007-01-31 02:08:30 +0000343| tok_xsd_namespace tok_literal
344 {
345 pdebug("Header -> tok_xsd_namespace tok_literal");
346 if (g_parse_mode == PROGRAM) {
347 g_program->set_xsd_namespace($2);
348 }
349 }
David Reiss9d65bf02008-03-27 21:41:37 +0000350/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss7f42bcf2008-01-11 20:59:12 +0000351| tok_csharp_namespace tok_identifier
352 {
David Reiss9d65bf02008-03-27 21:41:37 +0000353 pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead");
David Reiss919ae802008-03-27 21:41:11 +0000354 pdebug("Header -> tok_csharp_namespace tok_identifier");
David Reiss7f42bcf2008-01-11 20:59:12 +0000355 if (g_parse_mode == PROGRAM) {
David Reiss9d65bf02008-03-27 21:41:37 +0000356 g_program->set_namespace("csharp", $2);
David Reiss7f42bcf2008-01-11 20:59:12 +0000357 }
358 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000359
360Include:
361 tok_include tok_literal
362 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000363 pdebug("Include -> tok_include tok_literal");
Mark Sleef0712dc2006-10-25 19:03:57 +0000364 if (g_parse_mode == INCLUDES) {
365 std::string path = include_file(std::string($2));
366 if (!path.empty()) {
kholst76f2c882008-01-16 02:47:41 +0000367 g_program->add_include(path, std::string($2));
Mark Sleef0712dc2006-10-25 19:03:57 +0000368 }
369 }
370 }
Mark Slee31985722006-05-24 21:45:31 +0000371
372DefinitionList:
David Reisscbd4bac2007-08-14 17:12:33 +0000373 DefinitionList CaptureDocText Definition
Mark Slee31985722006-05-24 21:45:31 +0000374 {
375 pdebug("DefinitionList -> DefinitionList Definition");
David Reisscdffe262007-08-14 17:12:31 +0000376 if ($2 != NULL && $3 != NULL) {
377 $3->set_doc($2);
378 }
Mark Slee31985722006-05-24 21:45:31 +0000379 }
380|
381 {
382 pdebug("DefinitionList -> ");
383 }
384
385Definition:
Mark Slee30152872006-11-28 01:24:07 +0000386 Const
387 {
388 pdebug("Definition -> Const");
389 if (g_parse_mode == PROGRAM) {
390 g_program->add_const($1);
Mark Sleebd588222007-11-21 08:43:35 +0000391 }
David Reisscdffe262007-08-14 17:12:31 +0000392 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000393 }
394| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000395 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000396 pdebug("Definition -> TypeDefinition");
397 if (g_parse_mode == PROGRAM) {
398 g_scope->add_type($1->get_name(), $1);
399 if (g_parent_scope != NULL) {
400 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
401 }
402 }
David Reisscdffe262007-08-14 17:12:31 +0000403 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000404 }
Mark Slee31985722006-05-24 21:45:31 +0000405| Service
406 {
407 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000408 if (g_parse_mode == PROGRAM) {
409 g_scope->add_service($1->get_name(), $1);
410 if (g_parent_scope != NULL) {
411 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
412 }
413 g_program->add_service($1);
414 }
David Reisscdffe262007-08-14 17:12:31 +0000415 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000416 }
417
Mark Sleef0712dc2006-10-25 19:03:57 +0000418TypeDefinition:
419 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000420 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000421 pdebug("TypeDefinition -> Typedef");
422 if (g_parse_mode == PROGRAM) {
423 g_program->add_typedef($1);
424 }
425 }
426| Enum
427 {
428 pdebug("TypeDefinition -> Enum");
429 if (g_parse_mode == PROGRAM) {
430 g_program->add_enum($1);
431 }
432 }
Mark Slee6a47fed2007-02-07 02:40:59 +0000433| Senum
434 {
435 pdebug("TypeDefinition -> Senum");
436 if (g_parse_mode == PROGRAM) {
437 g_program->add_typedef($1);
438 }
439 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000440| Struct
441 {
442 pdebug("TypeDefinition -> Struct");
443 if (g_parse_mode == PROGRAM) {
444 g_program->add_struct($1);
445 }
446 }
447| Xception
Mark Slee27ed6ec2007-08-16 01:26:31 +0000448 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000449 pdebug("TypeDefinition -> Xception");
450 if (g_parse_mode == PROGRAM) {
451 g_program->add_xception($1);
452 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000453 }
Mark Slee31985722006-05-24 21:45:31 +0000454
455Typedef:
Mark Sleebd588222007-11-21 08:43:35 +0000456 tok_typedef DefinitionType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000457 {
458 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
David Reisscdffe262007-08-14 17:12:31 +0000459 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000460 $$ = td;
461 }
462
Mark Slee6a47fed2007-02-07 02:40:59 +0000463CommaOrSemicolonOptional:
464 ','
465 {}
466| ';'
467 {}
468|
469 {}
ccheeverf53b5cf2007-02-05 20:33:11 +0000470
Mark Slee31985722006-05-24 21:45:31 +0000471Enum:
David Reisscdffe262007-08-14 17:12:31 +0000472 tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000473 {
474 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000475 $$ = $4;
476 $$->set_name($2);
Mark Slee31985722006-05-24 21:45:31 +0000477 }
478
479EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000480 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000481 {
482 pdebug("EnumDefList -> EnumDefList EnumDef");
483 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000484 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000485 }
486|
487 {
488 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000489 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000490 }
491
492EnumDef:
David Reisscbd4bac2007-08-14 17:12:33 +0000493 CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000494 {
Mark Slee30152872006-11-28 01:24:07 +0000495 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000496 if ($4 < 0) {
497 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000498 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000499 $$ = new t_enum_value($2, $4);
500 if ($1 != NULL) {
501 $$->set_doc($1);
502 }
Mark Sleed0767c52007-07-27 22:14:41 +0000503 if (g_parse_mode == PROGRAM) {
504 g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4)));
505 if (g_parent_scope != NULL) {
506 g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4)));
507 }
508 }
Mark Slee31985722006-05-24 21:45:31 +0000509 }
510|
David Reisscbd4bac2007-08-14 17:12:33 +0000511 CaptureDocText tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000512 {
Mark Slee30152872006-11-28 01:24:07 +0000513 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000514 $$ = new t_enum_value($2);
515 if ($1 != NULL) {
516 $$->set_doc($1);
517 }
Mark Slee30152872006-11-28 01:24:07 +0000518 }
519
Mark Slee6a47fed2007-02-07 02:40:59 +0000520Senum:
David Reisscdffe262007-08-14 17:12:31 +0000521 tok_senum tok_identifier '{' SenumDefList '}'
Mark Slee6a47fed2007-02-07 02:40:59 +0000522 {
523 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000524 $$ = new t_typedef(g_program, $4, $2);
Mark Slee6a47fed2007-02-07 02:40:59 +0000525 }
526
527SenumDefList:
528 SenumDefList SenumDef
529 {
530 pdebug("SenumDefList -> SenumDefList SenumDef");
531 $$ = $1;
532 $$->add_string_enum_val($2);
533 }
534|
535 {
536 pdebug("SenumDefList -> ");
537 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
538 $$->set_string_enum(true);
539 }
540
541SenumDef:
542 tok_literal CommaOrSemicolonOptional
543 {
544 pdebug("SenumDef -> tok_literal");
545 $$ = $1;
546 }
547
Mark Slee30152872006-11-28 01:24:07 +0000548Const:
549 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
550 {
551 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000552 if (g_parse_mode == PROGRAM) {
553 $$ = new t_const($2, $3, $5);
554 validate_const_type($$);
Mark Sleed0767c52007-07-27 22:14:41 +0000555
556 g_scope->add_constant($3, $$);
557 if (g_parent_scope != NULL) {
558 g_parent_scope->add_constant(g_parent_prefix + $3, $$);
559 }
560
Mark Sleeaa7671d2006-11-29 03:19:31 +0000561 } else {
562 $$ = NULL;
563 }
Mark Slee30152872006-11-28 01:24:07 +0000564 }
565
566ConstValue:
567 tok_int_constant
568 {
569 pdebug("ConstValue => tok_int_constant");
570 $$ = new t_const_value();
571 $$->set_integer($1);
572 }
573| tok_dub_constant
574 {
575 pdebug("ConstValue => tok_dub_constant");
576 $$ = new t_const_value();
577 $$->set_double($1);
578 }
579| tok_literal
580 {
581 pdebug("ConstValue => tok_literal");
Mark Sleed0767c52007-07-27 22:14:41 +0000582 $$ = new t_const_value($1);
Mark Slee30152872006-11-28 01:24:07 +0000583 }
Mark Slee67fc6342006-11-29 03:37:04 +0000584| tok_identifier
585 {
586 pdebug("ConstValue => tok_identifier");
Mark Sleed0767c52007-07-27 22:14:41 +0000587 t_const* constant = g_scope->get_constant($1);
588 if (constant != NULL) {
589 $$ = constant->get_value();
590 } else {
591 if (g_parse_mode == PROGRAM) {
592 pwarning(1, "Constant strings should be quoted: %s\n", $1);
593 }
594 $$ = new t_const_value($1);
595 }
Mark Slee67fc6342006-11-29 03:37:04 +0000596 }
Mark Slee30152872006-11-28 01:24:07 +0000597| ConstList
598 {
599 pdebug("ConstValue => ConstList");
600 $$ = $1;
601 }
602| ConstMap
603 {
604 pdebug("ConstValue => ConstMap");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000605 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000606 }
607
608ConstList:
609 '[' ConstListContents ']'
610 {
611 pdebug("ConstList => [ ConstListContents ]");
612 $$ = $2;
613 }
614
615ConstListContents:
616 ConstListContents ConstValue CommaOrSemicolonOptional
617 {
618 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
619 $$ = $1;
620 $$->add_list($2);
621 }
622|
623 {
624 pdebug("ConstListContents =>");
625 $$ = new t_const_value();
626 $$->set_list();
627 }
628
629ConstMap:
630 '{' ConstMapContents '}'
631 {
632 pdebug("ConstMap => { ConstMapContents }");
633 $$ = $2;
634 }
635
636ConstMapContents:
637 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
638 {
639 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
640 $$ = $1;
641 $$->add_map($2, $4);
642 }
643|
644 {
645 pdebug("ConstMapContents =>");
646 $$ = new t_const_value();
647 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000648 }
649
650Struct:
David Reisscdffe262007-08-14 17:12:31 +0000651 tok_struct tok_identifier XsdAll '{' FieldList '}'
Mark Slee31985722006-05-24 21:45:31 +0000652 {
653 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
David Reisscdffe262007-08-14 17:12:31 +0000654 $5->set_name($2);
655 $5->set_xsd_all($3);
656 $$ = $5;
Mark Slee9cb7c612006-09-01 22:17:45 +0000657 y_field_val = -1;
658 }
659
Mark Slee36bfa2e2007-01-19 20:09:51 +0000660XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000661 tok_xsd_all
662 {
663 $$ = true;
664 }
665|
666 {
667 $$ = false;
668 }
669
Mark Slee36bfa2e2007-01-19 20:09:51 +0000670XsdOptional:
671 tok_xsd_optional
672 {
673 $$ = true;
674 }
675|
676 {
677 $$ = false;
678 }
679
Mark Slee7df0e2a2007-02-06 21:03:18 +0000680XsdNillable:
681 tok_xsd_nillable
682 {
683 $$ = true;
684 }
685|
686 {
687 $$ = false;
688 }
689
Mark Slee21135c32007-02-05 21:52:08 +0000690XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000691 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000692 {
Mark Slee748d83f2007-02-07 01:20:08 +0000693 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000694 }
695|
696 {
697 $$ = NULL;
698 }
699
Mark Slee9cb7c612006-09-01 22:17:45 +0000700Xception:
701 tok_xception tok_identifier '{' FieldList '}'
702 {
703 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
704 $4->set_name($2);
705 $4->set_xception(true);
706 $$ = $4;
707 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000708 }
709
710Service:
Mark Slee78165722007-09-10 22:08:49 +0000711 tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
Mark Slee31985722006-05-24 21:45:31 +0000712 {
713 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Slee78165722007-09-10 22:08:49 +0000714 $$ = $6;
David Reisscdffe262007-08-14 17:12:31 +0000715 $$->set_name($2);
716 $$->set_extends($3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000717 }
718
Mark Slee78165722007-09-10 22:08:49 +0000719FlagArgs:
720 {
721 g_arglist = 1;
722 }
723
724UnflagArgs:
725 {
726 g_arglist = 0;
727 }
728
Mark Slee36bfa2e2007-01-19 20:09:51 +0000729Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000730 tok_extends tok_identifier
731 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000732 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000733 $$ = NULL;
734 if (g_parse_mode == PROGRAM) {
735 $$ = g_scope->get_service($2);
736 if ($$ == NULL) {
737 yyerror("Service \"%s\" has not been defined.", $2);
738 exit(1);
739 }
740 }
741 }
742|
743 {
744 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000745 }
746
747FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000748 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000749 {
750 pdebug("FunctionList -> FunctionList Function");
751 $$ = $1;
752 $1->add_function($2);
753 }
754|
755 {
756 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000757 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000758 }
759
760Function:
David Reisscbd4bac2007-08-14 17:12:33 +0000761 CaptureDocText Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000762 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000763 $6->set_name(std::string($4) + "_args");
764 $$ = new t_function($3, $4, $6, $8, $2);
765 if ($1 != NULL) {
766 $$->set_doc($1);
767 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000768 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000769 }
770
Mark Slee36bfa2e2007-01-19 20:09:51 +0000771Async:
Mark Slee52f643d2006-08-09 00:03:43 +0000772 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000773 {
Mark Slee52f643d2006-08-09 00:03:43 +0000774 $$ = true;
775 }
776|
777 {
778 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000779 }
780
Mark Slee36bfa2e2007-01-19 20:09:51 +0000781Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000782 tok_throws '(' FieldList ')'
783 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000784 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000785 $$ = $3;
Mark Sleef07d48e2008-02-01 01:36:26 +0000786 if (g_parse_mode == PROGRAM && !validate_throws($$)) {
Mark Slee91f2b7b2008-01-31 01:49:16 +0000787 yyerror("Throws clause may not contain non-exception types");
788 exit(1);
789 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000790 }
791|
792 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000793 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000794 }
795
Mark Slee31985722006-05-24 21:45:31 +0000796FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000797 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000798 {
799 pdebug("FieldList -> FieldList , Field");
800 $$ = $1;
Mark Slee6f9ac3f2007-11-28 22:28:13 +0000801 if (!($$->validate_field($2))) {
802 yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
803 exit(1);
804 }
Mark Slee207cb462006-11-02 18:43:12 +0000805 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000806 }
807|
808 {
809 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000810 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000811 }
812
813Field:
David Reiss8320a922007-08-14 19:59:26 +0000814 CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000815 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000816 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000817 if ($2 < 0) {
David Reiss8320a922007-08-14 19:59:26 +0000818 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 +0000819 }
David Reiss8320a922007-08-14 19:59:26 +0000820 $$ = new t_field($4, $5, $2);
821 $$->set_req($3);
822 if ($6 != NULL) {
823 validate_field_value($$, $6);
824 $$->set_value($6);
Mark Slee7ff32452007-02-01 05:26:18 +0000825 }
David Reiss8320a922007-08-14 19:59:26 +0000826 $$->set_xsd_optional($7);
827 $$->set_xsd_nillable($8);
ccheeverf53b5cf2007-02-05 20:33:11 +0000828 if ($1 != NULL) {
829 $$->set_doc($1);
830 }
David Reiss8320a922007-08-14 19:59:26 +0000831 if ($9 != NULL) {
832 $$->set_xsd_attrs($9);
Mark Slee21135c32007-02-05 21:52:08 +0000833 }
Mark Slee31985722006-05-24 21:45:31 +0000834 }
Mark Slee7ff32452007-02-01 05:26:18 +0000835
836FieldIdentifier:
837 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000838 {
Mark Slee7ff32452007-02-01 05:26:18 +0000839 if ($1 <= 0) {
840 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
841 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000842 }
Mark Slee7ff32452007-02-01 05:26:18 +0000843 $$ = $1;
844 }
845|
846 {
847 $$ = y_field_val--;
848 }
849
David Reiss8320a922007-08-14 19:59:26 +0000850FieldRequiredness:
851 tok_required
852 {
Mark Slee78165722007-09-10 22:08:49 +0000853 if (g_arglist) {
854 if (g_parse_mode == PROGRAM) {
855 pwarning(1, "required keyword is ignored in argument lists.\n");
856 }
David Reiss204420f2008-01-11 20:59:03 +0000857 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000858 } else {
David Reiss204420f2008-01-11 20:59:03 +0000859 $$ = t_field::T_REQUIRED;
Mark Slee78165722007-09-10 22:08:49 +0000860 }
David Reiss8320a922007-08-14 19:59:26 +0000861 }
862| tok_optional
863 {
Mark Slee78165722007-09-10 22:08:49 +0000864 if (g_arglist) {
865 if (g_parse_mode == PROGRAM) {
866 pwarning(1, "optional keyword is ignored in argument lists.\n");
867 }
David Reiss204420f2008-01-11 20:59:03 +0000868 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000869 } else {
David Reiss204420f2008-01-11 20:59:03 +0000870 $$ = t_field::T_OPTIONAL;
Mark Slee78165722007-09-10 22:08:49 +0000871 }
David Reiss8320a922007-08-14 19:59:26 +0000872 }
873|
874 {
David Reiss204420f2008-01-11 20:59:03 +0000875 $$ = t_field::T_OPT_IN_REQ_OUT;
David Reiss8320a922007-08-14 19:59:26 +0000876 }
877
Mark Slee7ff32452007-02-01 05:26:18 +0000878FieldValue:
879 '=' ConstValue
880 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000881 if (g_parse_mode == PROGRAM) {
Mark Slee7ff32452007-02-01 05:26:18 +0000882 $$ = $2;
883 } else {
884 $$ = NULL;
885 }
886 }
887|
888 {
889 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000890 }
Mark Slee31985722006-05-24 21:45:31 +0000891
892DefinitionType:
893 BaseType
894 {
895 pdebug("DefinitionType -> BaseType");
896 $$ = $1;
897 }
Mark Sleee8540632006-05-30 09:24:40 +0000898| ContainerType
899 {
900 pdebug("DefinitionType -> ContainerType");
901 $$ = $1;
902 }
Mark Slee31985722006-05-24 21:45:31 +0000903
904FunctionType:
905 FieldType
906 {
Mark Sleee8540632006-05-30 09:24:40 +0000907 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000908 $$ = $1;
909 }
910| tok_void
911 {
Mark Sleee8540632006-05-30 09:24:40 +0000912 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000913 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000914 }
915
916FieldType:
917 tok_identifier
918 {
Mark Sleee8540632006-05-30 09:24:40 +0000919 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000920 if (g_parse_mode == INCLUDES) {
921 // Ignore identifiers in include mode
922 $$ = NULL;
923 } else {
924 // Lookup the identifier in the current scope
925 $$ = g_scope->get_type($1);
926 if ($$ == NULL) {
927 yyerror("Type \"%s\" has not been defined.", $1);
928 exit(1);
929 }
Mark Sleee8540632006-05-30 09:24:40 +0000930 }
Mark Slee31985722006-05-24 21:45:31 +0000931 }
932| BaseType
933 {
Mark Sleee8540632006-05-30 09:24:40 +0000934 pdebug("FieldType -> BaseType");
935 $$ = $1;
936 }
937| ContainerType
938 {
939 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000940 $$ = $1;
941 }
942
943BaseType:
944 tok_string
945 {
946 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000947 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000948 }
Mark Slee8d725a22007-04-13 01:57:12 +0000949| tok_binary
950 {
951 pdebug("BaseType -> tok_binary");
952 $$ = g_type_binary;
953 }
Mark Sleeb6200d82007-01-19 19:14:36 +0000954| tok_slist
955 {
956 pdebug("BaseType -> tok_slist");
957 $$ = g_type_slist;
958 }
Mark Slee78f58e22006-09-02 04:17:07 +0000959| tok_bool
960 {
961 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000962 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000963 }
Mark Slee31985722006-05-24 21:45:31 +0000964| tok_byte
965 {
966 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000967 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000968 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000969| tok_i16
970 {
971 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000972 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000973 }
Mark Slee31985722006-05-24 21:45:31 +0000974| tok_i32
975 {
976 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000977 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000978 }
Mark Slee31985722006-05-24 21:45:31 +0000979| tok_i64
980 {
981 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000982 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000983 }
Mark Sleec98d0502006-09-06 02:42:25 +0000984| tok_double
985 {
986 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000987 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000988 }
Mark Slee31985722006-05-24 21:45:31 +0000989
Mark Sleee8540632006-05-30 09:24:40 +0000990ContainerType:
991 MapType
992 {
993 pdebug("ContainerType -> MapType");
994 $$ = $1;
995 }
996| SetType
997 {
998 pdebug("ContainerType -> SetType");
999 $$ = $1;
1000 }
1001| ListType
1002 {
1003 pdebug("ContainerType -> ListType");
1004 $$ = $1;
1005 }
1006
1007MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001008 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001009 {
1010 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001011 $$ = new t_map($4, $6);
1012 if ($2 != NULL) {
1013 ((t_container*)$$)->set_cpp_name(std::string($2));
1014 }
Mark Sleee8540632006-05-30 09:24:40 +00001015 }
1016
1017SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001018 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001019 {
1020 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001021 $$ = new t_set($4);
1022 if ($2 != NULL) {
1023 ((t_container*)$$)->set_cpp_name(std::string($2));
1024 }
Mark Sleee8540632006-05-30 09:24:40 +00001025 }
1026
1027ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001028 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +00001029 {
1030 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +00001031 $$ = new t_list($3);
1032 if ($5 != NULL) {
1033 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +00001034 }
1035 }
1036
Mark Slee36bfa2e2007-01-19 20:09:51 +00001037CppType:
Mark Sleeafc76542007-02-09 21:55:44 +00001038 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +00001039 {
Mark Sleeafc76542007-02-09 21:55:44 +00001040 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +00001041 }
1042|
1043 {
1044 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +00001045 }
1046
Mark Slee31985722006-05-24 21:45:31 +00001047%%