blob: d555f53e0a3facbe5a80bd124e5919f2263685f7 [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 }
Mark Slee27ed6ec2007-08-16 01:26:31 +0000289| tok_perl_package tok_identifier
290 {
291 pdebug("Header -> tok_perl_namespace tok_identifier");
292 if (g_parse_mode == PROGRAM) {
293 g_program->set_perl_package($2);
294 }
295 }
David Reiss6a4b82c2008-03-27 21:42:16 +0000296/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee58dfb4f2007-07-06 02:45:25 +0000297| tok_ruby_namespace tok_identifier
298 {
David Reiss6a4b82c2008-03-27 21:42:16 +0000299 pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead");
Mark Slee58dfb4f2007-07-06 02:45:25 +0000300 pdebug("Header -> tok_ruby_namespace tok_identifier");
301 if (g_parse_mode == PROGRAM) {
David Reiss6a4b82c2008-03-27 21:42:16 +0000302 g_program->set_namespace("rb", $2);
Mark Slee58dfb4f2007-07-06 02:45:25 +0000303 }
304 }
David Reiss3b455012008-03-27 21:40:46 +0000305/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleebd588222007-11-21 08:43:35 +0000306| tok_smalltalk_category tok_st_identifier
307 {
David Reiss3b455012008-03-27 21:40:46 +0000308 pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
Mark Sleebd588222007-11-21 08:43:35 +0000309 pdebug("Header -> tok_smalltalk_category tok_st_identifier");
310 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000311 g_program->set_namespace("smalltalk.category", $2);
Mark Sleebd588222007-11-21 08:43:35 +0000312 }
313 }
David Reiss3b455012008-03-27 21:40:46 +0000314/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss15457c92007-12-14 07:03:03 +0000315| tok_smalltalk_prefix tok_identifier
316 {
David Reiss3b455012008-03-27 21:40:46 +0000317 pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
David Reiss15457c92007-12-14 07:03:03 +0000318 pdebug("Header -> tok_smalltalk_prefix tok_identifier");
319 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000320 g_program->set_namespace("smalltalk.prefix", $2);
David Reiss15457c92007-12-14 07:03:03 +0000321 }
322 }
David Reiss771f8c72008-02-27 01:55:25 +0000323/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000324| tok_java_package tok_identifier
325 {
David Reiss9f646152008-03-02 21:59:48 +0000326 pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000327 pdebug("Header -> tok_java_package tok_identifier");
328 if (g_parse_mode == PROGRAM) {
David Reiss771f8c72008-02-27 01:55:25 +0000329 g_program->set_namespace("java", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000330 }
331 }
David Reiss54b602b2008-03-27 21:41:06 +0000332/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee7e9eea42007-09-10 21:00:23 +0000333| tok_cocoa_prefix tok_identifier
334 {
David Reiss54b602b2008-03-27 21:41:06 +0000335 pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
Mark Slee7e9eea42007-09-10 21:00:23 +0000336 pdebug("Header -> tok_cocoa_prefix tok_identifier");
337 if (g_parse_mode == PROGRAM) {
David Reiss54b602b2008-03-27 21:41:06 +0000338 g_program->set_namespace("cocoa", $2);
Mark Slee7e9eea42007-09-10 21:00:23 +0000339 }
340 }
Mark Slee0d9199e2007-01-31 02:08:30 +0000341| tok_xsd_namespace tok_literal
342 {
343 pdebug("Header -> tok_xsd_namespace tok_literal");
344 if (g_parse_mode == PROGRAM) {
345 g_program->set_xsd_namespace($2);
346 }
347 }
David Reiss9d65bf02008-03-27 21:41:37 +0000348/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss7f42bcf2008-01-11 20:59:12 +0000349| tok_csharp_namespace tok_identifier
350 {
David Reiss9d65bf02008-03-27 21:41:37 +0000351 pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead");
David Reiss919ae802008-03-27 21:41:11 +0000352 pdebug("Header -> tok_csharp_namespace tok_identifier");
David Reiss7f42bcf2008-01-11 20:59:12 +0000353 if (g_parse_mode == PROGRAM) {
David Reiss9d65bf02008-03-27 21:41:37 +0000354 g_program->set_namespace("csharp", $2);
David Reiss7f42bcf2008-01-11 20:59:12 +0000355 }
356 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000357
358Include:
359 tok_include tok_literal
360 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000361 pdebug("Include -> tok_include tok_literal");
Mark Sleef0712dc2006-10-25 19:03:57 +0000362 if (g_parse_mode == INCLUDES) {
363 std::string path = include_file(std::string($2));
364 if (!path.empty()) {
kholst76f2c882008-01-16 02:47:41 +0000365 g_program->add_include(path, std::string($2));
Mark Sleef0712dc2006-10-25 19:03:57 +0000366 }
367 }
368 }
Mark Slee31985722006-05-24 21:45:31 +0000369
370DefinitionList:
David Reisscbd4bac2007-08-14 17:12:33 +0000371 DefinitionList CaptureDocText Definition
Mark Slee31985722006-05-24 21:45:31 +0000372 {
373 pdebug("DefinitionList -> DefinitionList Definition");
David Reisscdffe262007-08-14 17:12:31 +0000374 if ($2 != NULL && $3 != NULL) {
375 $3->set_doc($2);
376 }
Mark Slee31985722006-05-24 21:45:31 +0000377 }
378|
379 {
380 pdebug("DefinitionList -> ");
381 }
382
383Definition:
Mark Slee30152872006-11-28 01:24:07 +0000384 Const
385 {
386 pdebug("Definition -> Const");
387 if (g_parse_mode == PROGRAM) {
388 g_program->add_const($1);
Mark Sleebd588222007-11-21 08:43:35 +0000389 }
David Reisscdffe262007-08-14 17:12:31 +0000390 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000391 }
392| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000393 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000394 pdebug("Definition -> TypeDefinition");
395 if (g_parse_mode == PROGRAM) {
396 g_scope->add_type($1->get_name(), $1);
397 if (g_parent_scope != NULL) {
398 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
399 }
400 }
David Reisscdffe262007-08-14 17:12:31 +0000401 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000402 }
Mark Slee31985722006-05-24 21:45:31 +0000403| Service
404 {
405 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000406 if (g_parse_mode == PROGRAM) {
407 g_scope->add_service($1->get_name(), $1);
408 if (g_parent_scope != NULL) {
409 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
410 }
411 g_program->add_service($1);
412 }
David Reisscdffe262007-08-14 17:12:31 +0000413 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000414 }
415
Mark Sleef0712dc2006-10-25 19:03:57 +0000416TypeDefinition:
417 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000418 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000419 pdebug("TypeDefinition -> Typedef");
420 if (g_parse_mode == PROGRAM) {
421 g_program->add_typedef($1);
422 }
423 }
424| Enum
425 {
426 pdebug("TypeDefinition -> Enum");
427 if (g_parse_mode == PROGRAM) {
428 g_program->add_enum($1);
429 }
430 }
Mark Slee6a47fed2007-02-07 02:40:59 +0000431| Senum
432 {
433 pdebug("TypeDefinition -> Senum");
434 if (g_parse_mode == PROGRAM) {
435 g_program->add_typedef($1);
436 }
437 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000438| Struct
439 {
440 pdebug("TypeDefinition -> Struct");
441 if (g_parse_mode == PROGRAM) {
442 g_program->add_struct($1);
443 }
444 }
445| Xception
Mark Slee27ed6ec2007-08-16 01:26:31 +0000446 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000447 pdebug("TypeDefinition -> Xception");
448 if (g_parse_mode == PROGRAM) {
449 g_program->add_xception($1);
450 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000451 }
Mark Slee31985722006-05-24 21:45:31 +0000452
453Typedef:
Mark Sleebd588222007-11-21 08:43:35 +0000454 tok_typedef DefinitionType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000455 {
456 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
David Reisscdffe262007-08-14 17:12:31 +0000457 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000458 $$ = td;
459 }
460
Mark Slee6a47fed2007-02-07 02:40:59 +0000461CommaOrSemicolonOptional:
462 ','
463 {}
464| ';'
465 {}
466|
467 {}
ccheeverf53b5cf2007-02-05 20:33:11 +0000468
Mark Slee31985722006-05-24 21:45:31 +0000469Enum:
David Reisscdffe262007-08-14 17:12:31 +0000470 tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000471 {
472 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000473 $$ = $4;
474 $$->set_name($2);
Mark Slee31985722006-05-24 21:45:31 +0000475 }
476
477EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000478 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000479 {
480 pdebug("EnumDefList -> EnumDefList EnumDef");
481 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000482 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000483 }
484|
485 {
486 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000487 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000488 }
489
490EnumDef:
David Reisscbd4bac2007-08-14 17:12:33 +0000491 CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000492 {
Mark Slee30152872006-11-28 01:24:07 +0000493 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000494 if ($4 < 0) {
495 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000496 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000497 $$ = new t_enum_value($2, $4);
498 if ($1 != NULL) {
499 $$->set_doc($1);
500 }
Mark Sleed0767c52007-07-27 22:14:41 +0000501 if (g_parse_mode == PROGRAM) {
502 g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4)));
503 if (g_parent_scope != NULL) {
504 g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4)));
505 }
506 }
Mark Slee31985722006-05-24 21:45:31 +0000507 }
508|
David Reisscbd4bac2007-08-14 17:12:33 +0000509 CaptureDocText tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000510 {
Mark Slee30152872006-11-28 01:24:07 +0000511 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000512 $$ = new t_enum_value($2);
513 if ($1 != NULL) {
514 $$->set_doc($1);
515 }
Mark Slee30152872006-11-28 01:24:07 +0000516 }
517
Mark Slee6a47fed2007-02-07 02:40:59 +0000518Senum:
David Reisscdffe262007-08-14 17:12:31 +0000519 tok_senum tok_identifier '{' SenumDefList '}'
Mark Slee6a47fed2007-02-07 02:40:59 +0000520 {
521 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000522 $$ = new t_typedef(g_program, $4, $2);
Mark Slee6a47fed2007-02-07 02:40:59 +0000523 }
524
525SenumDefList:
526 SenumDefList SenumDef
527 {
528 pdebug("SenumDefList -> SenumDefList SenumDef");
529 $$ = $1;
530 $$->add_string_enum_val($2);
531 }
532|
533 {
534 pdebug("SenumDefList -> ");
535 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
536 $$->set_string_enum(true);
537 }
538
539SenumDef:
540 tok_literal CommaOrSemicolonOptional
541 {
542 pdebug("SenumDef -> tok_literal");
543 $$ = $1;
544 }
545
Mark Slee30152872006-11-28 01:24:07 +0000546Const:
547 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
548 {
549 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000550 if (g_parse_mode == PROGRAM) {
551 $$ = new t_const($2, $3, $5);
552 validate_const_type($$);
Mark Sleed0767c52007-07-27 22:14:41 +0000553
554 g_scope->add_constant($3, $$);
555 if (g_parent_scope != NULL) {
556 g_parent_scope->add_constant(g_parent_prefix + $3, $$);
557 }
558
Mark Sleeaa7671d2006-11-29 03:19:31 +0000559 } else {
560 $$ = NULL;
561 }
Mark Slee30152872006-11-28 01:24:07 +0000562 }
563
564ConstValue:
565 tok_int_constant
566 {
567 pdebug("ConstValue => tok_int_constant");
568 $$ = new t_const_value();
569 $$->set_integer($1);
570 }
571| tok_dub_constant
572 {
573 pdebug("ConstValue => tok_dub_constant");
574 $$ = new t_const_value();
575 $$->set_double($1);
576 }
577| tok_literal
578 {
579 pdebug("ConstValue => tok_literal");
Mark Sleed0767c52007-07-27 22:14:41 +0000580 $$ = new t_const_value($1);
Mark Slee30152872006-11-28 01:24:07 +0000581 }
Mark Slee67fc6342006-11-29 03:37:04 +0000582| tok_identifier
583 {
584 pdebug("ConstValue => tok_identifier");
Mark Sleed0767c52007-07-27 22:14:41 +0000585 t_const* constant = g_scope->get_constant($1);
586 if (constant != NULL) {
587 $$ = constant->get_value();
588 } else {
589 if (g_parse_mode == PROGRAM) {
590 pwarning(1, "Constant strings should be quoted: %s\n", $1);
591 }
592 $$ = new t_const_value($1);
593 }
Mark Slee67fc6342006-11-29 03:37:04 +0000594 }
Mark Slee30152872006-11-28 01:24:07 +0000595| ConstList
596 {
597 pdebug("ConstValue => ConstList");
598 $$ = $1;
599 }
600| ConstMap
601 {
602 pdebug("ConstValue => ConstMap");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000603 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000604 }
605
606ConstList:
607 '[' ConstListContents ']'
608 {
609 pdebug("ConstList => [ ConstListContents ]");
610 $$ = $2;
611 }
612
613ConstListContents:
614 ConstListContents ConstValue CommaOrSemicolonOptional
615 {
616 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
617 $$ = $1;
618 $$->add_list($2);
619 }
620|
621 {
622 pdebug("ConstListContents =>");
623 $$ = new t_const_value();
624 $$->set_list();
625 }
626
627ConstMap:
628 '{' ConstMapContents '}'
629 {
630 pdebug("ConstMap => { ConstMapContents }");
631 $$ = $2;
632 }
633
634ConstMapContents:
635 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
636 {
637 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
638 $$ = $1;
639 $$->add_map($2, $4);
640 }
641|
642 {
643 pdebug("ConstMapContents =>");
644 $$ = new t_const_value();
645 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000646 }
647
648Struct:
David Reisscdffe262007-08-14 17:12:31 +0000649 tok_struct tok_identifier XsdAll '{' FieldList '}'
Mark Slee31985722006-05-24 21:45:31 +0000650 {
651 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
David Reisscdffe262007-08-14 17:12:31 +0000652 $5->set_name($2);
653 $5->set_xsd_all($3);
654 $$ = $5;
Mark Slee9cb7c612006-09-01 22:17:45 +0000655 y_field_val = -1;
656 }
657
Mark Slee36bfa2e2007-01-19 20:09:51 +0000658XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000659 tok_xsd_all
660 {
661 $$ = true;
662 }
663|
664 {
665 $$ = false;
666 }
667
Mark Slee36bfa2e2007-01-19 20:09:51 +0000668XsdOptional:
669 tok_xsd_optional
670 {
671 $$ = true;
672 }
673|
674 {
675 $$ = false;
676 }
677
Mark Slee7df0e2a2007-02-06 21:03:18 +0000678XsdNillable:
679 tok_xsd_nillable
680 {
681 $$ = true;
682 }
683|
684 {
685 $$ = false;
686 }
687
Mark Slee21135c32007-02-05 21:52:08 +0000688XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000689 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000690 {
Mark Slee748d83f2007-02-07 01:20:08 +0000691 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000692 }
693|
694 {
695 $$ = NULL;
696 }
697
Mark Slee9cb7c612006-09-01 22:17:45 +0000698Xception:
699 tok_xception tok_identifier '{' FieldList '}'
700 {
701 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
702 $4->set_name($2);
703 $4->set_xception(true);
704 $$ = $4;
705 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000706 }
707
708Service:
Mark Slee78165722007-09-10 22:08:49 +0000709 tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
Mark Slee31985722006-05-24 21:45:31 +0000710 {
711 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Slee78165722007-09-10 22:08:49 +0000712 $$ = $6;
David Reisscdffe262007-08-14 17:12:31 +0000713 $$->set_name($2);
714 $$->set_extends($3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000715 }
716
Mark Slee78165722007-09-10 22:08:49 +0000717FlagArgs:
718 {
719 g_arglist = 1;
720 }
721
722UnflagArgs:
723 {
724 g_arglist = 0;
725 }
726
Mark Slee36bfa2e2007-01-19 20:09:51 +0000727Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000728 tok_extends tok_identifier
729 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000730 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000731 $$ = NULL;
732 if (g_parse_mode == PROGRAM) {
733 $$ = g_scope->get_service($2);
734 if ($$ == NULL) {
735 yyerror("Service \"%s\" has not been defined.", $2);
736 exit(1);
737 }
738 }
739 }
740|
741 {
742 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000743 }
744
745FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000746 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000747 {
748 pdebug("FunctionList -> FunctionList Function");
749 $$ = $1;
750 $1->add_function($2);
751 }
752|
753 {
754 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000755 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000756 }
757
758Function:
David Reisscbd4bac2007-08-14 17:12:33 +0000759 CaptureDocText Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000760 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000761 $6->set_name(std::string($4) + "_args");
762 $$ = new t_function($3, $4, $6, $8, $2);
763 if ($1 != NULL) {
764 $$->set_doc($1);
765 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000766 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000767 }
768
Mark Slee36bfa2e2007-01-19 20:09:51 +0000769Async:
Mark Slee52f643d2006-08-09 00:03:43 +0000770 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000771 {
Mark Slee52f643d2006-08-09 00:03:43 +0000772 $$ = true;
773 }
774|
775 {
776 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000777 }
778
Mark Slee36bfa2e2007-01-19 20:09:51 +0000779Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000780 tok_throws '(' FieldList ')'
781 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000782 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000783 $$ = $3;
Mark Sleef07d48e2008-02-01 01:36:26 +0000784 if (g_parse_mode == PROGRAM && !validate_throws($$)) {
Mark Slee91f2b7b2008-01-31 01:49:16 +0000785 yyerror("Throws clause may not contain non-exception types");
786 exit(1);
787 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000788 }
789|
790 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000791 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000792 }
793
Mark Slee31985722006-05-24 21:45:31 +0000794FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000795 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000796 {
797 pdebug("FieldList -> FieldList , Field");
798 $$ = $1;
Mark Slee6f9ac3f2007-11-28 22:28:13 +0000799 if (!($$->validate_field($2))) {
800 yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
801 exit(1);
802 }
Mark Slee207cb462006-11-02 18:43:12 +0000803 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000804 }
805|
806 {
807 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000808 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000809 }
810
811Field:
David Reiss8320a922007-08-14 19:59:26 +0000812 CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000813 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000814 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000815 if ($2 < 0) {
David Reiss8320a922007-08-14 19:59:26 +0000816 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 +0000817 }
David Reiss8320a922007-08-14 19:59:26 +0000818 $$ = new t_field($4, $5, $2);
819 $$->set_req($3);
820 if ($6 != NULL) {
821 validate_field_value($$, $6);
822 $$->set_value($6);
Mark Slee7ff32452007-02-01 05:26:18 +0000823 }
David Reiss8320a922007-08-14 19:59:26 +0000824 $$->set_xsd_optional($7);
825 $$->set_xsd_nillable($8);
ccheeverf53b5cf2007-02-05 20:33:11 +0000826 if ($1 != NULL) {
827 $$->set_doc($1);
828 }
David Reiss8320a922007-08-14 19:59:26 +0000829 if ($9 != NULL) {
830 $$->set_xsd_attrs($9);
Mark Slee21135c32007-02-05 21:52:08 +0000831 }
Mark Slee31985722006-05-24 21:45:31 +0000832 }
Mark Slee7ff32452007-02-01 05:26:18 +0000833
834FieldIdentifier:
835 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000836 {
Mark Slee7ff32452007-02-01 05:26:18 +0000837 if ($1 <= 0) {
838 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
839 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000840 }
Mark Slee7ff32452007-02-01 05:26:18 +0000841 $$ = $1;
842 }
843|
844 {
845 $$ = y_field_val--;
846 }
847
David Reiss8320a922007-08-14 19:59:26 +0000848FieldRequiredness:
849 tok_required
850 {
Mark Slee78165722007-09-10 22:08:49 +0000851 if (g_arglist) {
852 if (g_parse_mode == PROGRAM) {
853 pwarning(1, "required keyword is ignored in argument lists.\n");
854 }
David Reiss204420f2008-01-11 20:59:03 +0000855 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000856 } else {
David Reiss204420f2008-01-11 20:59:03 +0000857 $$ = t_field::T_REQUIRED;
Mark Slee78165722007-09-10 22:08:49 +0000858 }
David Reiss8320a922007-08-14 19:59:26 +0000859 }
860| tok_optional
861 {
Mark Slee78165722007-09-10 22:08:49 +0000862 if (g_arglist) {
863 if (g_parse_mode == PROGRAM) {
864 pwarning(1, "optional keyword is ignored in argument lists.\n");
865 }
David Reiss204420f2008-01-11 20:59:03 +0000866 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000867 } else {
David Reiss204420f2008-01-11 20:59:03 +0000868 $$ = t_field::T_OPTIONAL;
Mark Slee78165722007-09-10 22:08:49 +0000869 }
David Reiss8320a922007-08-14 19:59:26 +0000870 }
871|
872 {
David Reiss204420f2008-01-11 20:59:03 +0000873 $$ = t_field::T_OPT_IN_REQ_OUT;
David Reiss8320a922007-08-14 19:59:26 +0000874 }
875
Mark Slee7ff32452007-02-01 05:26:18 +0000876FieldValue:
877 '=' ConstValue
878 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000879 if (g_parse_mode == PROGRAM) {
Mark Slee7ff32452007-02-01 05:26:18 +0000880 $$ = $2;
881 } else {
882 $$ = NULL;
883 }
884 }
885|
886 {
887 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000888 }
Mark Slee31985722006-05-24 21:45:31 +0000889
890DefinitionType:
891 BaseType
892 {
893 pdebug("DefinitionType -> BaseType");
894 $$ = $1;
895 }
Mark Sleee8540632006-05-30 09:24:40 +0000896| ContainerType
897 {
898 pdebug("DefinitionType -> ContainerType");
899 $$ = $1;
900 }
Mark Slee31985722006-05-24 21:45:31 +0000901
902FunctionType:
903 FieldType
904 {
Mark Sleee8540632006-05-30 09:24:40 +0000905 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000906 $$ = $1;
907 }
908| tok_void
909 {
Mark Sleee8540632006-05-30 09:24:40 +0000910 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000911 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000912 }
913
914FieldType:
915 tok_identifier
916 {
Mark Sleee8540632006-05-30 09:24:40 +0000917 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000918 if (g_parse_mode == INCLUDES) {
919 // Ignore identifiers in include mode
920 $$ = NULL;
921 } else {
922 // Lookup the identifier in the current scope
923 $$ = g_scope->get_type($1);
924 if ($$ == NULL) {
925 yyerror("Type \"%s\" has not been defined.", $1);
926 exit(1);
927 }
Mark Sleee8540632006-05-30 09:24:40 +0000928 }
Mark Slee31985722006-05-24 21:45:31 +0000929 }
930| BaseType
931 {
Mark Sleee8540632006-05-30 09:24:40 +0000932 pdebug("FieldType -> BaseType");
933 $$ = $1;
934 }
935| ContainerType
936 {
937 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000938 $$ = $1;
939 }
940
941BaseType:
942 tok_string
943 {
944 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000945 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000946 }
Mark Slee8d725a22007-04-13 01:57:12 +0000947| tok_binary
948 {
949 pdebug("BaseType -> tok_binary");
950 $$ = g_type_binary;
951 }
Mark Sleeb6200d82007-01-19 19:14:36 +0000952| tok_slist
953 {
954 pdebug("BaseType -> tok_slist");
955 $$ = g_type_slist;
956 }
Mark Slee78f58e22006-09-02 04:17:07 +0000957| tok_bool
958 {
959 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000960 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000961 }
Mark Slee31985722006-05-24 21:45:31 +0000962| tok_byte
963 {
964 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000965 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000966 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000967| tok_i16
968 {
969 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000970 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000971 }
Mark Slee31985722006-05-24 21:45:31 +0000972| tok_i32
973 {
974 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000975 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000976 }
Mark Slee31985722006-05-24 21:45:31 +0000977| tok_i64
978 {
979 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000980 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000981 }
Mark Sleec98d0502006-09-06 02:42:25 +0000982| tok_double
983 {
984 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000985 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000986 }
Mark Slee31985722006-05-24 21:45:31 +0000987
Mark Sleee8540632006-05-30 09:24:40 +0000988ContainerType:
989 MapType
990 {
991 pdebug("ContainerType -> MapType");
992 $$ = $1;
993 }
994| SetType
995 {
996 pdebug("ContainerType -> SetType");
997 $$ = $1;
998 }
999| ListType
1000 {
1001 pdebug("ContainerType -> ListType");
1002 $$ = $1;
1003 }
1004
1005MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001006 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001007 {
1008 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001009 $$ = new t_map($4, $6);
1010 if ($2 != NULL) {
1011 ((t_container*)$$)->set_cpp_name(std::string($2));
1012 }
Mark Sleee8540632006-05-30 09:24:40 +00001013 }
1014
1015SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001016 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001017 {
1018 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001019 $$ = new t_set($4);
1020 if ($2 != NULL) {
1021 ((t_container*)$$)->set_cpp_name(std::string($2));
1022 }
Mark Sleee8540632006-05-30 09:24:40 +00001023 }
1024
1025ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001026 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +00001027 {
1028 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +00001029 $$ = new t_list($3);
1030 if ($5 != NULL) {
1031 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +00001032 }
1033 }
1034
Mark Slee36bfa2e2007-01-19 20:09:51 +00001035CppType:
Mark Sleeafc76542007-02-09 21:55:44 +00001036 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +00001037 {
Mark Sleeafc76542007-02-09 21:55:44 +00001038 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +00001039 }
1040|
1041 {
1042 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +00001043 }
1044
Mark Slee31985722006-05-24 21:45:31 +00001045%%