blob: e5f1736a9f5604568a97683ec59cb3e93ad63159 [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
David Reissf1454162008-06-30 20:45:47 +000016#define __STDC_LIMIT_MACROS
17#define __STDC_FORMAT_MACROS
Mark Slee31985722006-05-24 21:45:31 +000018#include <stdio.h>
David Reissf1454162008-06-30 20:45:47 +000019#include <inttypes.h>
David Reiss400a5432008-07-25 19:48:39 +000020#include <limits.h>
Mark Slee31985722006-05-24 21:45:31 +000021#include "main.h"
22#include "globals.h"
23#include "parse/t_program.h"
Mark Sleef0712dc2006-10-25 19:03:57 +000024#include "parse/t_scope.h"
Mark Slee31985722006-05-24 21:45:31 +000025
Mark Sleef5377b32006-10-10 01:42:59 +000026/**
27 * This global variable is used for automatic numbering of field indices etc.
28 * when parsing the members of a struct. Field values are automatically
29 * assigned starting from -1 and working their way down.
30 */
Mark Slee9cb7c612006-09-01 22:17:45 +000031int y_field_val = -1;
Mark Slee78165722007-09-10 22:08:49 +000032int g_arglist = 0;
Mark Slee31985722006-05-24 21:45:31 +000033
34%}
35
Mark Sleef5377b32006-10-10 01:42:59 +000036/**
37 * This structure is used by the parser to hold the data types associated with
38 * various parse nodes.
39 */
Mark Slee31985722006-05-24 21:45:31 +000040%union {
Mark Slee30152872006-11-28 01:24:07 +000041 char* id;
David Reissf1454162008-06-30 20:45:47 +000042 int64_t iconst;
Mark Slee30152872006-11-28 01:24:07 +000043 double dconst;
44 bool tbool;
David Reisscdffe262007-08-14 17:12:31 +000045 t_doc* tdoc;
Mark Slee30152872006-11-28 01:24:07 +000046 t_type* ttype;
Mark Slee6a47fed2007-02-07 02:40:59 +000047 t_base_type* tbase;
Mark Slee30152872006-11-28 01:24:07 +000048 t_typedef* ttypedef;
49 t_enum* tenum;
50 t_enum_value* tenumv;
51 t_const* tconst;
52 t_const_value* tconstv;
53 t_struct* tstruct;
54 t_service* tservice;
55 t_function* tfunction;
56 t_field* tfield;
David Reisscdffe262007-08-14 17:12:31 +000057 char* dtext;
David Reiss8320a922007-08-14 19:59:26 +000058 t_field::e_req ereq;
Mark Slee31985722006-05-24 21:45:31 +000059}
60
Mark Sleef5377b32006-10-10 01:42:59 +000061/**
62 * Strings identifier
63 */
Mark Slee31985722006-05-24 21:45:31 +000064%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000065%token<id> tok_literal
David Reisscdffe262007-08-14 17:12:31 +000066%token<dtext> tok_doctext
Mark Sleebd588222007-11-21 08:43:35 +000067%token<id> tok_st_identifier
Mark Sleef5377b32006-10-10 01:42:59 +000068
69/**
Mark Slee30152872006-11-28 01:24:07 +000070 * Constant values
Mark Sleef5377b32006-10-10 01:42:59 +000071 */
Mark Slee31985722006-05-24 21:45:31 +000072%token<iconst> tok_int_constant
Mark Slee30152872006-11-28 01:24:07 +000073%token<dconst> tok_dub_constant
Mark Slee31985722006-05-24 21:45:31 +000074
Mark Sleef5377b32006-10-10 01:42:59 +000075/**
David Reiss399442b2008-02-20 02:28:05 +000076 * Header keywords
Mark Sleef5377b32006-10-10 01:42:59 +000077 */
Mark Sleef0712dc2006-10-25 19:03:57 +000078%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000079%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000080%token tok_cpp_namespace
81%token tok_cpp_include
82%token tok_cpp_type
Mark Sleee888b372007-01-12 01:06:24 +000083%token tok_php_namespace
David Reissc6fc3292007-08-30 00:58:43 +000084%token tok_py_module
Mark Slee27ed6ec2007-08-16 01:26:31 +000085%token tok_perl_package
Mark Sleef0712dc2006-10-25 19:03:57 +000086%token tok_java_package
Mark Slee782abbb2007-01-19 00:17:02 +000087%token tok_xsd_all
Mark Slee36bfa2e2007-01-19 20:09:51 +000088%token tok_xsd_optional
Mark Slee7df0e2a2007-02-06 21:03:18 +000089%token tok_xsd_nillable
Mark Slee0d9199e2007-01-31 02:08:30 +000090%token tok_xsd_namespace
Mark Slee21135c32007-02-05 21:52:08 +000091%token tok_xsd_attrs
Mark Slee58dfb4f2007-07-06 02:45:25 +000092%token tok_ruby_namespace
Mark Sleebd588222007-11-21 08:43:35 +000093%token tok_smalltalk_category
David Reiss15457c92007-12-14 07:03:03 +000094%token tok_smalltalk_prefix
Mark Slee7e9eea42007-09-10 21:00:23 +000095%token tok_cocoa_prefix
David Reiss7f42bcf2008-01-11 20:59:12 +000096%token tok_csharp_namespace
Mark Slee9cb7c612006-09-01 22:17:45 +000097
Mark Sleef5377b32006-10-10 01:42:59 +000098/**
99 * Base datatype keywords
100 */
101%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +0000102%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +0000103%token tok_byte
104%token tok_string
Mark Slee8d725a22007-04-13 01:57:12 +0000105%token tok_binary
Mark Sleeb6200d82007-01-19 19:14:36 +0000106%token tok_slist
Mark Slee6a47fed2007-02-07 02:40:59 +0000107%token tok_senum
Mark Slee9cb7c612006-09-01 22:17:45 +0000108%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +0000109%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +0000110%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +0000111%token tok_double
Mark Slee31985722006-05-24 21:45:31 +0000112
Mark Sleef5377b32006-10-10 01:42:59 +0000113/**
114 * Complex type keywords
115 */
Mark Slee31985722006-05-24 21:45:31 +0000116%token tok_map
117%token tok_list
118%token tok_set
119
Mark Sleef5377b32006-10-10 01:42:59 +0000120/**
121 * Function modifiers
Mark Slee27ed6ec2007-08-16 01:26:31 +0000122 */
Mark Slee31985722006-05-24 21:45:31 +0000123%token tok_async
124
Mark Sleef5377b32006-10-10 01:42:59 +0000125/**
126 * Thrift language keywords
127 */
Mark Slee31985722006-05-24 21:45:31 +0000128%token tok_typedef
129%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000130%token tok_xception
131%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000132%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000133%token tok_service
134%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000135%token tok_const
David Reiss8320a922007-08-14 19:59:26 +0000136%token tok_required
137%token tok_optional
Mark Slee31985722006-05-24 21:45:31 +0000138
Mark Sleef5377b32006-10-10 01:42:59 +0000139/**
140 * Grammar nodes
141 */
142
Mark Slee31985722006-05-24 21:45:31 +0000143%type<ttype> BaseType
Mark Sleee8540632006-05-30 09:24:40 +0000144%type<ttype> ContainerType
145%type<ttype> MapType
146%type<ttype> SetType
147%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000148
David Reisscdffe262007-08-14 17:12:31 +0000149%type<tdoc> Definition
Mark Sleef0712dc2006-10-25 19:03:57 +0000150%type<ttype> TypeDefinition
151
Mark Slee31985722006-05-24 21:45:31 +0000152%type<ttypedef> Typedef
153%type<ttype> DefinitionType
154
155%type<tfield> Field
Mark Slee7ff32452007-02-01 05:26:18 +0000156%type<iconst> FieldIdentifier
David Reiss8320a922007-08-14 19:59:26 +0000157%type<ereq> FieldRequiredness
Mark Slee31985722006-05-24 21:45:31 +0000158%type<ttype> FieldType
Mark Slee7ff32452007-02-01 05:26:18 +0000159%type<tconstv> FieldValue
Mark Sleee8540632006-05-30 09:24:40 +0000160%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000161
162%type<tenum> Enum
163%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000164%type<tenumv> EnumDef
165
Mark Slee6a47fed2007-02-07 02:40:59 +0000166%type<ttypedef> Senum
167%type<tbase> SenumDefList
168%type<id> SenumDef
169
Mark Slee30152872006-11-28 01:24:07 +0000170%type<tconst> Const
171%type<tconstv> ConstValue
172%type<tconstv> ConstList
173%type<tconstv> ConstListContents
174%type<tconstv> ConstMap
175%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000176
177%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000178%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000179%type<tservice> Service
180
181%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000182%type<ttype> FunctionType
183%type<tservice> FunctionList
184
Mark Slee36bfa2e2007-01-19 20:09:51 +0000185%type<tstruct> Throws
186%type<tservice> Extends
187%type<tbool> Async
188%type<tbool> XsdAll
189%type<tbool> XsdOptional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000190%type<tbool> XsdNillable
Mark Slee748d83f2007-02-07 01:20:08 +0000191%type<tstruct> XsdAttributes
Mark Slee36bfa2e2007-01-19 20:09:51 +0000192%type<id> CppType
Mark Slee52f643d2006-08-09 00:03:43 +0000193
David Reisscbd4bac2007-08-14 17:12:33 +0000194%type<dtext> CaptureDocText
ccheeverf53b5cf2007-02-05 20:33:11 +0000195
Mark Slee31985722006-05-24 21:45:31 +0000196%%
197
Mark Sleef5377b32006-10-10 01:42:59 +0000198/**
199 * Thrift Grammar Implementation.
200 *
201 * For the most part this source file works its way top down from what you
202 * might expect to find in a typical .thrift file, i.e. type definitions and
203 * namespaces up top followed by service definitions using those types.
204 */
Mark Slee31985722006-05-24 21:45:31 +0000205
206Program:
David Reisscbd4bac2007-08-14 17:12:33 +0000207 HeaderList DefinitionList
Mark Sleef0712dc2006-10-25 19:03:57 +0000208 {
209 pdebug("Program -> Headers DefinitionList");
David Reisscbd4bac2007-08-14 17:12:33 +0000210 /*
211 TODO(dreiss): Decide whether full-program doctext is worth the trouble.
David Reissc2532a92007-07-30 23:46:11 +0000212 if ($1 != NULL) {
213 g_program->set_doc($1);
214 }
David Reisscbd4bac2007-08-14 17:12:33 +0000215 */
216 clear_doctext();
Mark Sleef0712dc2006-10-25 19:03:57 +0000217 }
218
David Reisscbd4bac2007-08-14 17:12:33 +0000219CaptureDocText:
220 {
221 if (g_parse_mode == PROGRAM) {
Mark Sleebd588222007-11-21 08:43:35 +0000222 $$ = g_doctext;
David Reisscbd4bac2007-08-14 17:12:33 +0000223 g_doctext = NULL;
Mark Slee27ed6ec2007-08-16 01:26:31 +0000224 } else {
David Reisscbd4bac2007-08-14 17:12:33 +0000225 $$ = NULL;
226 }
227 }
228
229/* TODO(dreiss): Try to DestroyDocText in all sorts or random places. */
230DestroyDocText:
231 {
232 if (g_parse_mode == PROGRAM) {
233 clear_doctext();
234 }
235 }
236
237/* We have to DestroyDocText here, otherwise it catches the doctext
238 on the first real element. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000239HeaderList:
David Reisscbd4bac2007-08-14 17:12:33 +0000240 HeaderList DestroyDocText Header
Mark Sleef0712dc2006-10-25 19:03:57 +0000241 {
242 pdebug("HeaderList -> HeaderList Header");
243 }
244|
245 {
246 pdebug("HeaderList -> ");
247 }
248
249Header:
250 Include
251 {
252 pdebug("Header -> Include");
253 }
David Reiss79eca142008-02-27 01:55:13 +0000254| tok_namespace tok_identifier tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +0000255 {
David Reiss79eca142008-02-27 01:55:13 +0000256 pdebug("Header -> tok_namespace tok_identifier tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000257 if (g_parse_mode == PROGRAM) {
David Reiss79eca142008-02-27 01:55:13 +0000258 g_program->set_namespace($2, $3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000259 }
260 }
David Reiss9a08dc62008-02-27 01:55:17 +0000261/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000262| tok_cpp_namespace tok_identifier
263 {
David Reiss9a08dc62008-02-27 01:55:17 +0000264 pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000265 pdebug("Header -> tok_cpp_namespace tok_identifier");
266 if (g_parse_mode == PROGRAM) {
David Reiss9a08dc62008-02-27 01:55:17 +0000267 g_program->set_namespace("cpp", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000268 }
269 }
270| tok_cpp_include tok_literal
271 {
272 pdebug("Header -> tok_cpp_include tok_literal");
273 if (g_parse_mode == PROGRAM) {
274 g_program->add_cpp_include($2);
275 }
276 }
Mark Sleee888b372007-01-12 01:06:24 +0000277| tok_php_namespace tok_identifier
278 {
279 pdebug("Header -> tok_php_namespace tok_identifier");
280 if (g_parse_mode == PROGRAM) {
281 g_program->set_php_namespace($2);
282 }
283 }
David Reiss320e45c2008-03-27 21:41:54 +0000284/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reissc6fc3292007-08-30 00:58:43 +0000285| tok_py_module tok_identifier
286 {
David Reiss320e45c2008-03-27 21:41:54 +0000287 pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead");
David Reissc6fc3292007-08-30 00:58:43 +0000288 pdebug("Header -> tok_py_module tok_identifier");
289 if (g_parse_mode == PROGRAM) {
David Reiss320e45c2008-03-27 21:41:54 +0000290 g_program->set_namespace("py", $2);
David Reissc6fc3292007-08-30 00:58:43 +0000291 }
292 }
David Reiss07ef3a92008-03-27 21:42:39 +0000293/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee27ed6ec2007-08-16 01:26:31 +0000294| tok_perl_package tok_identifier
295 {
David Reiss07ef3a92008-03-27 21:42:39 +0000296 pwarning(1, "'perl_package' is deprecated. Use 'namespace perl' instead");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000297 pdebug("Header -> tok_perl_namespace tok_identifier");
298 if (g_parse_mode == PROGRAM) {
David Reiss07ef3a92008-03-27 21:42:39 +0000299 g_program->set_namespace("perl", $2);
Mark Slee27ed6ec2007-08-16 01:26:31 +0000300 }
301 }
David Reiss6a4b82c2008-03-27 21:42:16 +0000302/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee58dfb4f2007-07-06 02:45:25 +0000303| tok_ruby_namespace tok_identifier
304 {
David Reiss6a4b82c2008-03-27 21:42:16 +0000305 pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead");
Mark Slee58dfb4f2007-07-06 02:45:25 +0000306 pdebug("Header -> tok_ruby_namespace tok_identifier");
307 if (g_parse_mode == PROGRAM) {
David Reiss6a4b82c2008-03-27 21:42:16 +0000308 g_program->set_namespace("rb", $2);
Mark Slee58dfb4f2007-07-06 02:45:25 +0000309 }
310 }
David Reiss3b455012008-03-27 21:40:46 +0000311/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleebd588222007-11-21 08:43:35 +0000312| tok_smalltalk_category tok_st_identifier
313 {
David Reiss3b455012008-03-27 21:40:46 +0000314 pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
Mark Sleebd588222007-11-21 08:43:35 +0000315 pdebug("Header -> tok_smalltalk_category tok_st_identifier");
316 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000317 g_program->set_namespace("smalltalk.category", $2);
Mark Sleebd588222007-11-21 08:43:35 +0000318 }
319 }
David Reiss3b455012008-03-27 21:40:46 +0000320/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss15457c92007-12-14 07:03:03 +0000321| tok_smalltalk_prefix tok_identifier
322 {
David Reiss3b455012008-03-27 21:40:46 +0000323 pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
David Reiss15457c92007-12-14 07:03:03 +0000324 pdebug("Header -> tok_smalltalk_prefix tok_identifier");
325 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000326 g_program->set_namespace("smalltalk.prefix", $2);
David Reiss15457c92007-12-14 07:03:03 +0000327 }
328 }
David Reiss771f8c72008-02-27 01:55:25 +0000329/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000330| tok_java_package tok_identifier
331 {
David Reiss9f646152008-03-02 21:59:48 +0000332 pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000333 pdebug("Header -> tok_java_package tok_identifier");
334 if (g_parse_mode == PROGRAM) {
David Reiss771f8c72008-02-27 01:55:25 +0000335 g_program->set_namespace("java", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000336 }
337 }
David Reiss54b602b2008-03-27 21:41:06 +0000338/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee7e9eea42007-09-10 21:00:23 +0000339| tok_cocoa_prefix tok_identifier
340 {
David Reiss54b602b2008-03-27 21:41:06 +0000341 pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
Mark Slee7e9eea42007-09-10 21:00:23 +0000342 pdebug("Header -> tok_cocoa_prefix tok_identifier");
343 if (g_parse_mode == PROGRAM) {
David Reiss54b602b2008-03-27 21:41:06 +0000344 g_program->set_namespace("cocoa", $2);
Mark Slee7e9eea42007-09-10 21:00:23 +0000345 }
346 }
Mark Slee0d9199e2007-01-31 02:08:30 +0000347| tok_xsd_namespace tok_literal
348 {
349 pdebug("Header -> tok_xsd_namespace tok_literal");
350 if (g_parse_mode == PROGRAM) {
351 g_program->set_xsd_namespace($2);
352 }
353 }
David Reiss9d65bf02008-03-27 21:41:37 +0000354/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss7f42bcf2008-01-11 20:59:12 +0000355| tok_csharp_namespace tok_identifier
356 {
David Reiss9d65bf02008-03-27 21:41:37 +0000357 pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead");
David Reiss919ae802008-03-27 21:41:11 +0000358 pdebug("Header -> tok_csharp_namespace tok_identifier");
David Reiss7f42bcf2008-01-11 20:59:12 +0000359 if (g_parse_mode == PROGRAM) {
David Reiss9d65bf02008-03-27 21:41:37 +0000360 g_program->set_namespace("csharp", $2);
David Reiss7f42bcf2008-01-11 20:59:12 +0000361 }
362 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000363
364Include:
365 tok_include tok_literal
366 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000367 pdebug("Include -> tok_include tok_literal");
Mark Sleef0712dc2006-10-25 19:03:57 +0000368 if (g_parse_mode == INCLUDES) {
369 std::string path = include_file(std::string($2));
370 if (!path.empty()) {
kholst76f2c882008-01-16 02:47:41 +0000371 g_program->add_include(path, std::string($2));
Mark Sleef0712dc2006-10-25 19:03:57 +0000372 }
373 }
374 }
Mark Slee31985722006-05-24 21:45:31 +0000375
376DefinitionList:
David Reisscbd4bac2007-08-14 17:12:33 +0000377 DefinitionList CaptureDocText Definition
Mark Slee31985722006-05-24 21:45:31 +0000378 {
379 pdebug("DefinitionList -> DefinitionList Definition");
David Reisscdffe262007-08-14 17:12:31 +0000380 if ($2 != NULL && $3 != NULL) {
381 $3->set_doc($2);
382 }
Mark Slee31985722006-05-24 21:45:31 +0000383 }
384|
385 {
386 pdebug("DefinitionList -> ");
387 }
388
389Definition:
Mark Slee30152872006-11-28 01:24:07 +0000390 Const
391 {
392 pdebug("Definition -> Const");
393 if (g_parse_mode == PROGRAM) {
394 g_program->add_const($1);
Mark Sleebd588222007-11-21 08:43:35 +0000395 }
David Reisscdffe262007-08-14 17:12:31 +0000396 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000397 }
398| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000399 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000400 pdebug("Definition -> TypeDefinition");
401 if (g_parse_mode == PROGRAM) {
402 g_scope->add_type($1->get_name(), $1);
403 if (g_parent_scope != NULL) {
404 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
405 }
406 }
David Reisscdffe262007-08-14 17:12:31 +0000407 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000408 }
Mark Slee31985722006-05-24 21:45:31 +0000409| Service
410 {
411 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000412 if (g_parse_mode == PROGRAM) {
413 g_scope->add_service($1->get_name(), $1);
414 if (g_parent_scope != NULL) {
415 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
416 }
417 g_program->add_service($1);
418 }
David Reisscdffe262007-08-14 17:12:31 +0000419 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000420 }
421
Mark Sleef0712dc2006-10-25 19:03:57 +0000422TypeDefinition:
423 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000424 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000425 pdebug("TypeDefinition -> Typedef");
426 if (g_parse_mode == PROGRAM) {
427 g_program->add_typedef($1);
428 }
429 }
430| Enum
431 {
432 pdebug("TypeDefinition -> Enum");
433 if (g_parse_mode == PROGRAM) {
434 g_program->add_enum($1);
435 }
436 }
Mark Slee6a47fed2007-02-07 02:40:59 +0000437| Senum
438 {
439 pdebug("TypeDefinition -> Senum");
440 if (g_parse_mode == PROGRAM) {
441 g_program->add_typedef($1);
442 }
443 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000444| Struct
445 {
446 pdebug("TypeDefinition -> Struct");
447 if (g_parse_mode == PROGRAM) {
448 g_program->add_struct($1);
449 }
450 }
451| Xception
Mark Slee27ed6ec2007-08-16 01:26:31 +0000452 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000453 pdebug("TypeDefinition -> Xception");
454 if (g_parse_mode == PROGRAM) {
455 g_program->add_xception($1);
456 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000457 }
Mark Slee31985722006-05-24 21:45:31 +0000458
459Typedef:
Mark Sleebd588222007-11-21 08:43:35 +0000460 tok_typedef DefinitionType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000461 {
462 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
David Reisscdffe262007-08-14 17:12:31 +0000463 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000464 $$ = td;
465 }
466
Mark Slee6a47fed2007-02-07 02:40:59 +0000467CommaOrSemicolonOptional:
468 ','
469 {}
470| ';'
471 {}
472|
473 {}
ccheeverf53b5cf2007-02-05 20:33:11 +0000474
Mark Slee31985722006-05-24 21:45:31 +0000475Enum:
David Reisscdffe262007-08-14 17:12:31 +0000476 tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000477 {
478 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000479 $$ = $4;
480 $$->set_name($2);
Mark Slee31985722006-05-24 21:45:31 +0000481 }
482
483EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000484 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000485 {
486 pdebug("EnumDefList -> EnumDefList EnumDef");
487 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000488 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000489 }
490|
491 {
492 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000493 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000494 }
495
496EnumDef:
David Reisscbd4bac2007-08-14 17:12:33 +0000497 CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000498 {
Mark Slee30152872006-11-28 01:24:07 +0000499 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000500 if ($4 < 0) {
501 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000502 }
David Reissf1454162008-06-30 20:45:47 +0000503 if ($4 > INT_MAX) {
504 pwarning(1, "64-bit value supplied for enum %s.\n", $2);
505 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000506 $$ = new t_enum_value($2, $4);
507 if ($1 != NULL) {
508 $$->set_doc($1);
509 }
Mark Sleed0767c52007-07-27 22:14:41 +0000510 if (g_parse_mode == PROGRAM) {
511 g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4)));
512 if (g_parent_scope != NULL) {
513 g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4)));
514 }
515 }
Mark Slee31985722006-05-24 21:45:31 +0000516 }
517|
David Reisscbd4bac2007-08-14 17:12:33 +0000518 CaptureDocText tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000519 {
Mark Slee30152872006-11-28 01:24:07 +0000520 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000521 $$ = new t_enum_value($2);
522 if ($1 != NULL) {
523 $$->set_doc($1);
524 }
Mark Slee30152872006-11-28 01:24:07 +0000525 }
526
Mark Slee6a47fed2007-02-07 02:40:59 +0000527Senum:
David Reisscdffe262007-08-14 17:12:31 +0000528 tok_senum tok_identifier '{' SenumDefList '}'
Mark Slee6a47fed2007-02-07 02:40:59 +0000529 {
530 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000531 $$ = new t_typedef(g_program, $4, $2);
Mark Slee6a47fed2007-02-07 02:40:59 +0000532 }
533
534SenumDefList:
535 SenumDefList SenumDef
536 {
537 pdebug("SenumDefList -> SenumDefList SenumDef");
538 $$ = $1;
539 $$->add_string_enum_val($2);
540 }
541|
542 {
543 pdebug("SenumDefList -> ");
544 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
545 $$->set_string_enum(true);
546 }
547
548SenumDef:
549 tok_literal CommaOrSemicolonOptional
550 {
551 pdebug("SenumDef -> tok_literal");
552 $$ = $1;
553 }
554
Mark Slee30152872006-11-28 01:24:07 +0000555Const:
556 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
557 {
558 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000559 if (g_parse_mode == PROGRAM) {
560 $$ = new t_const($2, $3, $5);
561 validate_const_type($$);
Mark Sleed0767c52007-07-27 22:14:41 +0000562
563 g_scope->add_constant($3, $$);
564 if (g_parent_scope != NULL) {
565 g_parent_scope->add_constant(g_parent_prefix + $3, $$);
566 }
567
Mark Sleeaa7671d2006-11-29 03:19:31 +0000568 } else {
569 $$ = NULL;
570 }
Mark Slee30152872006-11-28 01:24:07 +0000571 }
572
573ConstValue:
574 tok_int_constant
575 {
576 pdebug("ConstValue => tok_int_constant");
577 $$ = new t_const_value();
578 $$->set_integer($1);
David Reissf1454162008-06-30 20:45:47 +0000579 if ($1 < INT32_MIN || $1 > INT32_MAX) {
580 pwarning(1, "64-bit constant \"%"PRIi64"\" may not work in all languages.\n", $1);
581 }
Mark Slee30152872006-11-28 01:24:07 +0000582 }
583| tok_dub_constant
584 {
585 pdebug("ConstValue => tok_dub_constant");
586 $$ = new t_const_value();
587 $$->set_double($1);
588 }
589| tok_literal
590 {
591 pdebug("ConstValue => tok_literal");
Mark Sleed0767c52007-07-27 22:14:41 +0000592 $$ = new t_const_value($1);
Mark Slee30152872006-11-28 01:24:07 +0000593 }
Mark Slee67fc6342006-11-29 03:37:04 +0000594| tok_identifier
595 {
596 pdebug("ConstValue => tok_identifier");
Mark Sleed0767c52007-07-27 22:14:41 +0000597 t_const* constant = g_scope->get_constant($1);
598 if (constant != NULL) {
599 $$ = constant->get_value();
600 } else {
601 if (g_parse_mode == PROGRAM) {
602 pwarning(1, "Constant strings should be quoted: %s\n", $1);
603 }
604 $$ = new t_const_value($1);
605 }
Mark Slee67fc6342006-11-29 03:37:04 +0000606 }
Mark Slee30152872006-11-28 01:24:07 +0000607| ConstList
608 {
609 pdebug("ConstValue => ConstList");
610 $$ = $1;
611 }
612| ConstMap
613 {
614 pdebug("ConstValue => ConstMap");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000615 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000616 }
617
618ConstList:
619 '[' ConstListContents ']'
620 {
621 pdebug("ConstList => [ ConstListContents ]");
622 $$ = $2;
623 }
624
625ConstListContents:
626 ConstListContents ConstValue CommaOrSemicolonOptional
627 {
628 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
629 $$ = $1;
630 $$->add_list($2);
631 }
632|
633 {
634 pdebug("ConstListContents =>");
635 $$ = new t_const_value();
636 $$->set_list();
637 }
638
639ConstMap:
640 '{' ConstMapContents '}'
641 {
642 pdebug("ConstMap => { ConstMapContents }");
643 $$ = $2;
644 }
645
646ConstMapContents:
647 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
648 {
649 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
650 $$ = $1;
651 $$->add_map($2, $4);
652 }
653|
654 {
655 pdebug("ConstMapContents =>");
656 $$ = new t_const_value();
657 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000658 }
659
660Struct:
David Reisscdffe262007-08-14 17:12:31 +0000661 tok_struct tok_identifier XsdAll '{' FieldList '}'
Mark Slee31985722006-05-24 21:45:31 +0000662 {
663 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
David Reisscdffe262007-08-14 17:12:31 +0000664 $5->set_name($2);
665 $5->set_xsd_all($3);
666 $$ = $5;
Mark Slee9cb7c612006-09-01 22:17:45 +0000667 y_field_val = -1;
668 }
669
Mark Slee36bfa2e2007-01-19 20:09:51 +0000670XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000671 tok_xsd_all
672 {
673 $$ = true;
674 }
675|
676 {
677 $$ = false;
678 }
679
Mark Slee36bfa2e2007-01-19 20:09:51 +0000680XsdOptional:
681 tok_xsd_optional
682 {
683 $$ = true;
684 }
685|
686 {
687 $$ = false;
688 }
689
Mark Slee7df0e2a2007-02-06 21:03:18 +0000690XsdNillable:
691 tok_xsd_nillable
692 {
693 $$ = true;
694 }
695|
696 {
697 $$ = false;
698 }
699
Mark Slee21135c32007-02-05 21:52:08 +0000700XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000701 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000702 {
Mark Slee748d83f2007-02-07 01:20:08 +0000703 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000704 }
705|
706 {
707 $$ = NULL;
708 }
709
Mark Slee9cb7c612006-09-01 22:17:45 +0000710Xception:
711 tok_xception tok_identifier '{' FieldList '}'
712 {
713 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
714 $4->set_name($2);
715 $4->set_xception(true);
716 $$ = $4;
717 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000718 }
719
720Service:
Mark Slee78165722007-09-10 22:08:49 +0000721 tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
Mark Slee31985722006-05-24 21:45:31 +0000722 {
723 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Slee78165722007-09-10 22:08:49 +0000724 $$ = $6;
David Reisscdffe262007-08-14 17:12:31 +0000725 $$->set_name($2);
726 $$->set_extends($3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000727 }
728
Mark Slee78165722007-09-10 22:08:49 +0000729FlagArgs:
730 {
731 g_arglist = 1;
732 }
733
734UnflagArgs:
735 {
736 g_arglist = 0;
737 }
738
Mark Slee36bfa2e2007-01-19 20:09:51 +0000739Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000740 tok_extends tok_identifier
741 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000742 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000743 $$ = NULL;
744 if (g_parse_mode == PROGRAM) {
745 $$ = g_scope->get_service($2);
746 if ($$ == NULL) {
747 yyerror("Service \"%s\" has not been defined.", $2);
748 exit(1);
749 }
750 }
751 }
752|
753 {
754 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000755 }
756
757FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000758 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000759 {
760 pdebug("FunctionList -> FunctionList Function");
761 $$ = $1;
762 $1->add_function($2);
763 }
764|
765 {
766 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000767 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000768 }
769
770Function:
David Reisscbd4bac2007-08-14 17:12:33 +0000771 CaptureDocText Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000772 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000773 $6->set_name(std::string($4) + "_args");
774 $$ = new t_function($3, $4, $6, $8, $2);
775 if ($1 != NULL) {
776 $$->set_doc($1);
777 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000778 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000779 }
780
Mark Slee36bfa2e2007-01-19 20:09:51 +0000781Async:
Mark Slee52f643d2006-08-09 00:03:43 +0000782 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000783 {
Mark Slee52f643d2006-08-09 00:03:43 +0000784 $$ = true;
785 }
786|
787 {
788 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000789 }
790
Mark Slee36bfa2e2007-01-19 20:09:51 +0000791Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000792 tok_throws '(' FieldList ')'
793 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000794 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000795 $$ = $3;
Mark Sleef07d48e2008-02-01 01:36:26 +0000796 if (g_parse_mode == PROGRAM && !validate_throws($$)) {
Mark Slee91f2b7b2008-01-31 01:49:16 +0000797 yyerror("Throws clause may not contain non-exception types");
798 exit(1);
799 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000800 }
801|
802 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000803 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000804 }
805
Mark Slee31985722006-05-24 21:45:31 +0000806FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000807 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000808 {
809 pdebug("FieldList -> FieldList , Field");
810 $$ = $1;
Mark Slee6f9ac3f2007-11-28 22:28:13 +0000811 if (!($$->validate_field($2))) {
812 yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
813 exit(1);
814 }
Mark Slee207cb462006-11-02 18:43:12 +0000815 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000816 }
817|
818 {
819 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000820 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000821 }
822
823Field:
David Reiss8320a922007-08-14 19:59:26 +0000824 CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000825 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000826 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000827 if ($2 < 0) {
David Reiss8320a922007-08-14 19:59:26 +0000828 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 +0000829 }
David Reiss8320a922007-08-14 19:59:26 +0000830 $$ = new t_field($4, $5, $2);
831 $$->set_req($3);
832 if ($6 != NULL) {
833 validate_field_value($$, $6);
834 $$->set_value($6);
Mark Slee7ff32452007-02-01 05:26:18 +0000835 }
David Reiss8320a922007-08-14 19:59:26 +0000836 $$->set_xsd_optional($7);
837 $$->set_xsd_nillable($8);
ccheeverf53b5cf2007-02-05 20:33:11 +0000838 if ($1 != NULL) {
839 $$->set_doc($1);
840 }
David Reiss8320a922007-08-14 19:59:26 +0000841 if ($9 != NULL) {
842 $$->set_xsd_attrs($9);
Mark Slee21135c32007-02-05 21:52:08 +0000843 }
Mark Slee31985722006-05-24 21:45:31 +0000844 }
Mark Slee7ff32452007-02-01 05:26:18 +0000845
846FieldIdentifier:
847 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000848 {
Mark Slee7ff32452007-02-01 05:26:18 +0000849 if ($1 <= 0) {
850 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
851 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000852 }
Mark Slee7ff32452007-02-01 05:26:18 +0000853 $$ = $1;
854 }
855|
856 {
857 $$ = y_field_val--;
858 }
859
David Reiss8320a922007-08-14 19:59:26 +0000860FieldRequiredness:
861 tok_required
862 {
Mark Slee78165722007-09-10 22:08:49 +0000863 if (g_arglist) {
864 if (g_parse_mode == PROGRAM) {
865 pwarning(1, "required keyword is ignored in argument lists.\n");
866 }
David Reiss204420f2008-01-11 20:59:03 +0000867 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000868 } else {
David Reiss204420f2008-01-11 20:59:03 +0000869 $$ = t_field::T_REQUIRED;
Mark Slee78165722007-09-10 22:08:49 +0000870 }
David Reiss8320a922007-08-14 19:59:26 +0000871 }
872| tok_optional
873 {
Mark Slee78165722007-09-10 22:08:49 +0000874 if (g_arglist) {
875 if (g_parse_mode == PROGRAM) {
876 pwarning(1, "optional keyword is ignored in argument lists.\n");
877 }
David Reiss204420f2008-01-11 20:59:03 +0000878 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000879 } else {
David Reiss204420f2008-01-11 20:59:03 +0000880 $$ = t_field::T_OPTIONAL;
Mark Slee78165722007-09-10 22:08:49 +0000881 }
David Reiss8320a922007-08-14 19:59:26 +0000882 }
883|
884 {
David Reiss204420f2008-01-11 20:59:03 +0000885 $$ = t_field::T_OPT_IN_REQ_OUT;
David Reiss8320a922007-08-14 19:59:26 +0000886 }
887
Mark Slee7ff32452007-02-01 05:26:18 +0000888FieldValue:
889 '=' ConstValue
890 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000891 if (g_parse_mode == PROGRAM) {
Mark Slee7ff32452007-02-01 05:26:18 +0000892 $$ = $2;
893 } else {
894 $$ = NULL;
895 }
896 }
897|
898 {
899 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000900 }
Mark Slee31985722006-05-24 21:45:31 +0000901
902DefinitionType:
903 BaseType
904 {
905 pdebug("DefinitionType -> BaseType");
906 $$ = $1;
907 }
Mark Sleee8540632006-05-30 09:24:40 +0000908| ContainerType
909 {
910 pdebug("DefinitionType -> ContainerType");
911 $$ = $1;
912 }
Mark Slee31985722006-05-24 21:45:31 +0000913
914FunctionType:
915 FieldType
916 {
Mark Sleee8540632006-05-30 09:24:40 +0000917 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000918 $$ = $1;
919 }
920| tok_void
921 {
Mark Sleee8540632006-05-30 09:24:40 +0000922 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000923 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000924 }
925
926FieldType:
927 tok_identifier
928 {
Mark Sleee8540632006-05-30 09:24:40 +0000929 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000930 if (g_parse_mode == INCLUDES) {
931 // Ignore identifiers in include mode
932 $$ = NULL;
933 } else {
934 // Lookup the identifier in the current scope
935 $$ = g_scope->get_type($1);
936 if ($$ == NULL) {
937 yyerror("Type \"%s\" has not been defined.", $1);
938 exit(1);
939 }
Mark Sleee8540632006-05-30 09:24:40 +0000940 }
Mark Slee31985722006-05-24 21:45:31 +0000941 }
942| BaseType
943 {
Mark Sleee8540632006-05-30 09:24:40 +0000944 pdebug("FieldType -> BaseType");
945 $$ = $1;
946 }
947| ContainerType
948 {
949 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000950 $$ = $1;
951 }
952
953BaseType:
954 tok_string
955 {
956 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000957 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000958 }
Mark Slee8d725a22007-04-13 01:57:12 +0000959| tok_binary
960 {
961 pdebug("BaseType -> tok_binary");
962 $$ = g_type_binary;
963 }
Mark Sleeb6200d82007-01-19 19:14:36 +0000964| tok_slist
965 {
966 pdebug("BaseType -> tok_slist");
967 $$ = g_type_slist;
968 }
Mark Slee78f58e22006-09-02 04:17:07 +0000969| tok_bool
970 {
971 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000972 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000973 }
Mark Slee31985722006-05-24 21:45:31 +0000974| tok_byte
975 {
976 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000977 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000978 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000979| tok_i16
980 {
981 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000982 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000983 }
Mark Slee31985722006-05-24 21:45:31 +0000984| tok_i32
985 {
986 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000987 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000988 }
Mark Slee31985722006-05-24 21:45:31 +0000989| tok_i64
990 {
991 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000992 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000993 }
Mark Sleec98d0502006-09-06 02:42:25 +0000994| tok_double
995 {
996 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000997 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000998 }
Mark Slee31985722006-05-24 21:45:31 +0000999
Mark Sleee8540632006-05-30 09:24:40 +00001000ContainerType:
1001 MapType
1002 {
1003 pdebug("ContainerType -> MapType");
1004 $$ = $1;
1005 }
1006| SetType
1007 {
1008 pdebug("ContainerType -> SetType");
1009 $$ = $1;
1010 }
1011| ListType
1012 {
1013 pdebug("ContainerType -> ListType");
1014 $$ = $1;
1015 }
1016
1017MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001018 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001019 {
1020 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001021 $$ = new t_map($4, $6);
1022 if ($2 != NULL) {
1023 ((t_container*)$$)->set_cpp_name(std::string($2));
1024 }
Mark Sleee8540632006-05-30 09:24:40 +00001025 }
1026
1027SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001028 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001029 {
1030 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001031 $$ = new t_set($4);
1032 if ($2 != NULL) {
1033 ((t_container*)$$)->set_cpp_name(std::string($2));
1034 }
Mark Sleee8540632006-05-30 09:24:40 +00001035 }
1036
1037ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001038 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +00001039 {
1040 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +00001041 $$ = new t_list($3);
1042 if ($5 != NULL) {
1043 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +00001044 }
1045 }
1046
Mark Slee36bfa2e2007-01-19 20:09:51 +00001047CppType:
Mark Sleeafc76542007-02-09 21:55:44 +00001048 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +00001049 {
Mark Sleeafc76542007-02-09 21:55:44 +00001050 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +00001051 }
1052|
1053 {
1054 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +00001055 }
1056
Mark Slee31985722006-05-24 21:45:31 +00001057%%