blob: f4ff6ef9f25d0640f00b6527e04d100ca2dc84a0 [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>
Mark Slee31985722006-05-24 21:45:31 +000020#include "main.h"
21#include "globals.h"
22#include "parse/t_program.h"
Mark Sleef0712dc2006-10-25 19:03:57 +000023#include "parse/t_scope.h"
Mark Slee31985722006-05-24 21:45:31 +000024
Mark Sleef5377b32006-10-10 01:42:59 +000025/**
26 * This global variable is used for automatic numbering of field indices etc.
27 * when parsing the members of a struct. Field values are automatically
28 * assigned starting from -1 and working their way down.
29 */
Mark Slee9cb7c612006-09-01 22:17:45 +000030int y_field_val = -1;
Mark Slee78165722007-09-10 22:08:49 +000031int g_arglist = 0;
Mark Slee31985722006-05-24 21:45:31 +000032
33%}
34
Mark Sleef5377b32006-10-10 01:42:59 +000035/**
36 * This structure is used by the parser to hold the data types associated with
37 * various parse nodes.
38 */
Mark Slee31985722006-05-24 21:45:31 +000039%union {
Mark Slee30152872006-11-28 01:24:07 +000040 char* id;
David Reissf1454162008-06-30 20:45:47 +000041 int64_t iconst;
Mark Slee30152872006-11-28 01:24:07 +000042 double dconst;
43 bool tbool;
David Reisscdffe262007-08-14 17:12:31 +000044 t_doc* tdoc;
Mark Slee30152872006-11-28 01:24:07 +000045 t_type* ttype;
Mark Slee6a47fed2007-02-07 02:40:59 +000046 t_base_type* tbase;
Mark Slee30152872006-11-28 01:24:07 +000047 t_typedef* ttypedef;
48 t_enum* tenum;
49 t_enum_value* tenumv;
50 t_const* tconst;
51 t_const_value* tconstv;
52 t_struct* tstruct;
53 t_service* tservice;
54 t_function* tfunction;
55 t_field* tfield;
David Reisscdffe262007-08-14 17:12:31 +000056 char* dtext;
David Reiss8320a922007-08-14 19:59:26 +000057 t_field::e_req ereq;
Mark Slee31985722006-05-24 21:45:31 +000058}
59
Mark Sleef5377b32006-10-10 01:42:59 +000060/**
61 * Strings identifier
62 */
Mark Slee31985722006-05-24 21:45:31 +000063%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000064%token<id> tok_literal
David Reisscdffe262007-08-14 17:12:31 +000065%token<dtext> tok_doctext
Mark Sleebd588222007-11-21 08:43:35 +000066%token<id> tok_st_identifier
Mark Sleef5377b32006-10-10 01:42:59 +000067
68/**
Mark Slee30152872006-11-28 01:24:07 +000069 * Constant values
Mark Sleef5377b32006-10-10 01:42:59 +000070 */
Mark Slee31985722006-05-24 21:45:31 +000071%token<iconst> tok_int_constant
Mark Slee30152872006-11-28 01:24:07 +000072%token<dconst> tok_dub_constant
Mark Slee31985722006-05-24 21:45:31 +000073
Mark Sleef5377b32006-10-10 01:42:59 +000074/**
David Reiss399442b2008-02-20 02:28:05 +000075 * Header keywords
Mark Sleef5377b32006-10-10 01:42:59 +000076 */
Mark Sleef0712dc2006-10-25 19:03:57 +000077%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000078%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000079%token tok_cpp_namespace
80%token tok_cpp_include
81%token tok_cpp_type
Mark Sleee888b372007-01-12 01:06:24 +000082%token tok_php_namespace
David Reissc6fc3292007-08-30 00:58:43 +000083%token tok_py_module
Mark Slee27ed6ec2007-08-16 01:26:31 +000084%token tok_perl_package
Mark Sleef0712dc2006-10-25 19:03:57 +000085%token tok_java_package
Mark Slee782abbb2007-01-19 00:17:02 +000086%token tok_xsd_all
Mark Slee36bfa2e2007-01-19 20:09:51 +000087%token tok_xsd_optional
Mark Slee7df0e2a2007-02-06 21:03:18 +000088%token tok_xsd_nillable
Mark Slee0d9199e2007-01-31 02:08:30 +000089%token tok_xsd_namespace
Mark Slee21135c32007-02-05 21:52:08 +000090%token tok_xsd_attrs
Mark Slee58dfb4f2007-07-06 02:45:25 +000091%token tok_ruby_namespace
Mark Sleebd588222007-11-21 08:43:35 +000092%token tok_smalltalk_category
David Reiss15457c92007-12-14 07:03:03 +000093%token tok_smalltalk_prefix
Mark Slee7e9eea42007-09-10 21:00:23 +000094%token tok_cocoa_prefix
David Reiss7f42bcf2008-01-11 20:59:12 +000095%token tok_csharp_namespace
Mark Slee9cb7c612006-09-01 22:17:45 +000096
Mark Sleef5377b32006-10-10 01:42:59 +000097/**
98 * Base datatype keywords
99 */
100%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +0000101%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +0000102%token tok_byte
103%token tok_string
Mark Slee8d725a22007-04-13 01:57:12 +0000104%token tok_binary
Mark Sleeb6200d82007-01-19 19:14:36 +0000105%token tok_slist
Mark Slee6a47fed2007-02-07 02:40:59 +0000106%token tok_senum
Mark Slee9cb7c612006-09-01 22:17:45 +0000107%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +0000108%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +0000109%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +0000110%token tok_double
Mark Slee31985722006-05-24 21:45:31 +0000111
Mark Sleef5377b32006-10-10 01:42:59 +0000112/**
113 * Complex type keywords
114 */
Mark Slee31985722006-05-24 21:45:31 +0000115%token tok_map
116%token tok_list
117%token tok_set
118
Mark Sleef5377b32006-10-10 01:42:59 +0000119/**
120 * Function modifiers
Mark Slee27ed6ec2007-08-16 01:26:31 +0000121 */
Mark Slee31985722006-05-24 21:45:31 +0000122%token tok_async
123
Mark Sleef5377b32006-10-10 01:42:59 +0000124/**
125 * Thrift language keywords
126 */
Mark Slee31985722006-05-24 21:45:31 +0000127%token tok_typedef
128%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000129%token tok_xception
130%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000131%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000132%token tok_service
133%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000134%token tok_const
David Reiss8320a922007-08-14 19:59:26 +0000135%token tok_required
136%token tok_optional
Mark Slee31985722006-05-24 21:45:31 +0000137
Mark Sleef5377b32006-10-10 01:42:59 +0000138/**
139 * Grammar nodes
140 */
141
Mark Slee31985722006-05-24 21:45:31 +0000142%type<ttype> BaseType
Mark Sleee8540632006-05-30 09:24:40 +0000143%type<ttype> ContainerType
144%type<ttype> MapType
145%type<ttype> SetType
146%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000147
David Reisscdffe262007-08-14 17:12:31 +0000148%type<tdoc> Definition
Mark Sleef0712dc2006-10-25 19:03:57 +0000149%type<ttype> TypeDefinition
150
Mark Slee31985722006-05-24 21:45:31 +0000151%type<ttypedef> Typedef
152%type<ttype> DefinitionType
153
154%type<tfield> Field
Mark Slee7ff32452007-02-01 05:26:18 +0000155%type<iconst> FieldIdentifier
David Reiss8320a922007-08-14 19:59:26 +0000156%type<ereq> FieldRequiredness
Mark Slee31985722006-05-24 21:45:31 +0000157%type<ttype> FieldType
Mark Slee7ff32452007-02-01 05:26:18 +0000158%type<tconstv> FieldValue
Mark Sleee8540632006-05-30 09:24:40 +0000159%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000160
161%type<tenum> Enum
162%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000163%type<tenumv> EnumDef
164
Mark Slee6a47fed2007-02-07 02:40:59 +0000165%type<ttypedef> Senum
166%type<tbase> SenumDefList
167%type<id> SenumDef
168
Mark Slee30152872006-11-28 01:24:07 +0000169%type<tconst> Const
170%type<tconstv> ConstValue
171%type<tconstv> ConstList
172%type<tconstv> ConstListContents
173%type<tconstv> ConstMap
174%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000175
176%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000177%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000178%type<tservice> Service
179
180%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000181%type<ttype> FunctionType
182%type<tservice> FunctionList
183
Mark Slee36bfa2e2007-01-19 20:09:51 +0000184%type<tstruct> Throws
185%type<tservice> Extends
186%type<tbool> Async
187%type<tbool> XsdAll
188%type<tbool> XsdOptional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000189%type<tbool> XsdNillable
Mark Slee748d83f2007-02-07 01:20:08 +0000190%type<tstruct> XsdAttributes
Mark Slee36bfa2e2007-01-19 20:09:51 +0000191%type<id> CppType
Mark Slee52f643d2006-08-09 00:03:43 +0000192
David Reisscbd4bac2007-08-14 17:12:33 +0000193%type<dtext> CaptureDocText
ccheeverf53b5cf2007-02-05 20:33:11 +0000194
Mark Slee31985722006-05-24 21:45:31 +0000195%%
196
Mark Sleef5377b32006-10-10 01:42:59 +0000197/**
198 * Thrift Grammar Implementation.
199 *
200 * For the most part this source file works its way top down from what you
201 * might expect to find in a typical .thrift file, i.e. type definitions and
202 * namespaces up top followed by service definitions using those types.
203 */
Mark Slee31985722006-05-24 21:45:31 +0000204
205Program:
David Reisscbd4bac2007-08-14 17:12:33 +0000206 HeaderList DefinitionList
Mark Sleef0712dc2006-10-25 19:03:57 +0000207 {
208 pdebug("Program -> Headers DefinitionList");
David Reisscbd4bac2007-08-14 17:12:33 +0000209 /*
210 TODO(dreiss): Decide whether full-program doctext is worth the trouble.
David Reissc2532a92007-07-30 23:46:11 +0000211 if ($1 != NULL) {
212 g_program->set_doc($1);
213 }
David Reisscbd4bac2007-08-14 17:12:33 +0000214 */
215 clear_doctext();
Mark Sleef0712dc2006-10-25 19:03:57 +0000216 }
217
David Reisscbd4bac2007-08-14 17:12:33 +0000218CaptureDocText:
219 {
220 if (g_parse_mode == PROGRAM) {
Mark Sleebd588222007-11-21 08:43:35 +0000221 $$ = g_doctext;
David Reisscbd4bac2007-08-14 17:12:33 +0000222 g_doctext = NULL;
Mark Slee27ed6ec2007-08-16 01:26:31 +0000223 } else {
David Reisscbd4bac2007-08-14 17:12:33 +0000224 $$ = NULL;
225 }
226 }
227
228/* TODO(dreiss): Try to DestroyDocText in all sorts or random places. */
229DestroyDocText:
230 {
231 if (g_parse_mode == PROGRAM) {
232 clear_doctext();
233 }
234 }
235
236/* We have to DestroyDocText here, otherwise it catches the doctext
237 on the first real element. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000238HeaderList:
David Reisscbd4bac2007-08-14 17:12:33 +0000239 HeaderList DestroyDocText Header
Mark Sleef0712dc2006-10-25 19:03:57 +0000240 {
241 pdebug("HeaderList -> HeaderList Header");
242 }
243|
244 {
245 pdebug("HeaderList -> ");
246 }
247
248Header:
249 Include
250 {
251 pdebug("Header -> Include");
252 }
David Reiss79eca142008-02-27 01:55:13 +0000253| tok_namespace tok_identifier tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +0000254 {
David Reiss79eca142008-02-27 01:55:13 +0000255 pdebug("Header -> tok_namespace tok_identifier tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000256 if (g_parse_mode == PROGRAM) {
David Reiss79eca142008-02-27 01:55:13 +0000257 g_program->set_namespace($2, $3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000258 }
259 }
David Reiss9a08dc62008-02-27 01:55:17 +0000260/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000261| tok_cpp_namespace tok_identifier
262 {
David Reiss9a08dc62008-02-27 01:55:17 +0000263 pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000264 pdebug("Header -> tok_cpp_namespace tok_identifier");
265 if (g_parse_mode == PROGRAM) {
David Reiss9a08dc62008-02-27 01:55:17 +0000266 g_program->set_namespace("cpp", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000267 }
268 }
269| tok_cpp_include tok_literal
270 {
271 pdebug("Header -> tok_cpp_include tok_literal");
272 if (g_parse_mode == PROGRAM) {
273 g_program->add_cpp_include($2);
274 }
275 }
Mark Sleee888b372007-01-12 01:06:24 +0000276| tok_php_namespace tok_identifier
277 {
278 pdebug("Header -> tok_php_namespace tok_identifier");
279 if (g_parse_mode == PROGRAM) {
280 g_program->set_php_namespace($2);
281 }
282 }
David Reiss320e45c2008-03-27 21:41:54 +0000283/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reissc6fc3292007-08-30 00:58:43 +0000284| tok_py_module tok_identifier
285 {
David Reiss320e45c2008-03-27 21:41:54 +0000286 pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead");
David Reissc6fc3292007-08-30 00:58:43 +0000287 pdebug("Header -> tok_py_module tok_identifier");
288 if (g_parse_mode == PROGRAM) {
David Reiss320e45c2008-03-27 21:41:54 +0000289 g_program->set_namespace("py", $2);
David Reissc6fc3292007-08-30 00:58:43 +0000290 }
291 }
David Reiss07ef3a92008-03-27 21:42:39 +0000292/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee27ed6ec2007-08-16 01:26:31 +0000293| tok_perl_package tok_identifier
294 {
David Reiss07ef3a92008-03-27 21:42:39 +0000295 pwarning(1, "'perl_package' is deprecated. Use 'namespace perl' instead");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000296 pdebug("Header -> tok_perl_namespace tok_identifier");
297 if (g_parse_mode == PROGRAM) {
David Reiss07ef3a92008-03-27 21:42:39 +0000298 g_program->set_namespace("perl", $2);
Mark Slee27ed6ec2007-08-16 01:26:31 +0000299 }
300 }
David Reiss6a4b82c2008-03-27 21:42:16 +0000301/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee58dfb4f2007-07-06 02:45:25 +0000302| tok_ruby_namespace tok_identifier
303 {
David Reiss6a4b82c2008-03-27 21:42:16 +0000304 pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead");
Mark Slee58dfb4f2007-07-06 02:45:25 +0000305 pdebug("Header -> tok_ruby_namespace tok_identifier");
306 if (g_parse_mode == PROGRAM) {
David Reiss6a4b82c2008-03-27 21:42:16 +0000307 g_program->set_namespace("rb", $2);
Mark Slee58dfb4f2007-07-06 02:45:25 +0000308 }
309 }
David Reiss3b455012008-03-27 21:40:46 +0000310/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleebd588222007-11-21 08:43:35 +0000311| tok_smalltalk_category tok_st_identifier
312 {
David Reiss3b455012008-03-27 21:40:46 +0000313 pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
Mark Sleebd588222007-11-21 08:43:35 +0000314 pdebug("Header -> tok_smalltalk_category tok_st_identifier");
315 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000316 g_program->set_namespace("smalltalk.category", $2);
Mark Sleebd588222007-11-21 08:43:35 +0000317 }
318 }
David Reiss3b455012008-03-27 21:40:46 +0000319/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss15457c92007-12-14 07:03:03 +0000320| tok_smalltalk_prefix tok_identifier
321 {
David Reiss3b455012008-03-27 21:40:46 +0000322 pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
David Reiss15457c92007-12-14 07:03:03 +0000323 pdebug("Header -> tok_smalltalk_prefix tok_identifier");
324 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000325 g_program->set_namespace("smalltalk.prefix", $2);
David Reiss15457c92007-12-14 07:03:03 +0000326 }
327 }
David Reiss771f8c72008-02-27 01:55:25 +0000328/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000329| tok_java_package tok_identifier
330 {
David Reiss9f646152008-03-02 21:59:48 +0000331 pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000332 pdebug("Header -> tok_java_package tok_identifier");
333 if (g_parse_mode == PROGRAM) {
David Reiss771f8c72008-02-27 01:55:25 +0000334 g_program->set_namespace("java", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000335 }
336 }
David Reiss54b602b2008-03-27 21:41:06 +0000337/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee7e9eea42007-09-10 21:00:23 +0000338| tok_cocoa_prefix tok_identifier
339 {
David Reiss54b602b2008-03-27 21:41:06 +0000340 pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
Mark Slee7e9eea42007-09-10 21:00:23 +0000341 pdebug("Header -> tok_cocoa_prefix tok_identifier");
342 if (g_parse_mode == PROGRAM) {
David Reiss54b602b2008-03-27 21:41:06 +0000343 g_program->set_namespace("cocoa", $2);
Mark Slee7e9eea42007-09-10 21:00:23 +0000344 }
345 }
Mark Slee0d9199e2007-01-31 02:08:30 +0000346| tok_xsd_namespace tok_literal
347 {
348 pdebug("Header -> tok_xsd_namespace tok_literal");
349 if (g_parse_mode == PROGRAM) {
350 g_program->set_xsd_namespace($2);
351 }
352 }
David Reiss9d65bf02008-03-27 21:41:37 +0000353/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss7f42bcf2008-01-11 20:59:12 +0000354| tok_csharp_namespace tok_identifier
355 {
David Reiss9d65bf02008-03-27 21:41:37 +0000356 pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead");
David Reiss919ae802008-03-27 21:41:11 +0000357 pdebug("Header -> tok_csharp_namespace tok_identifier");
David Reiss7f42bcf2008-01-11 20:59:12 +0000358 if (g_parse_mode == PROGRAM) {
David Reiss9d65bf02008-03-27 21:41:37 +0000359 g_program->set_namespace("csharp", $2);
David Reiss7f42bcf2008-01-11 20:59:12 +0000360 }
361 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000362
363Include:
364 tok_include tok_literal
365 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000366 pdebug("Include -> tok_include tok_literal");
Mark Sleef0712dc2006-10-25 19:03:57 +0000367 if (g_parse_mode == INCLUDES) {
368 std::string path = include_file(std::string($2));
369 if (!path.empty()) {
kholst76f2c882008-01-16 02:47:41 +0000370 g_program->add_include(path, std::string($2));
Mark Sleef0712dc2006-10-25 19:03:57 +0000371 }
372 }
373 }
Mark Slee31985722006-05-24 21:45:31 +0000374
375DefinitionList:
David Reisscbd4bac2007-08-14 17:12:33 +0000376 DefinitionList CaptureDocText Definition
Mark Slee31985722006-05-24 21:45:31 +0000377 {
378 pdebug("DefinitionList -> DefinitionList Definition");
David Reisscdffe262007-08-14 17:12:31 +0000379 if ($2 != NULL && $3 != NULL) {
380 $3->set_doc($2);
381 }
Mark Slee31985722006-05-24 21:45:31 +0000382 }
383|
384 {
385 pdebug("DefinitionList -> ");
386 }
387
388Definition:
Mark Slee30152872006-11-28 01:24:07 +0000389 Const
390 {
391 pdebug("Definition -> Const");
392 if (g_parse_mode == PROGRAM) {
393 g_program->add_const($1);
Mark Sleebd588222007-11-21 08:43:35 +0000394 }
David Reisscdffe262007-08-14 17:12:31 +0000395 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000396 }
397| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000398 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000399 pdebug("Definition -> TypeDefinition");
400 if (g_parse_mode == PROGRAM) {
401 g_scope->add_type($1->get_name(), $1);
402 if (g_parent_scope != NULL) {
403 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
404 }
405 }
David Reisscdffe262007-08-14 17:12:31 +0000406 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000407 }
Mark Slee31985722006-05-24 21:45:31 +0000408| Service
409 {
410 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000411 if (g_parse_mode == PROGRAM) {
412 g_scope->add_service($1->get_name(), $1);
413 if (g_parent_scope != NULL) {
414 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
415 }
416 g_program->add_service($1);
417 }
David Reisscdffe262007-08-14 17:12:31 +0000418 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000419 }
420
Mark Sleef0712dc2006-10-25 19:03:57 +0000421TypeDefinition:
422 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000423 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000424 pdebug("TypeDefinition -> Typedef");
425 if (g_parse_mode == PROGRAM) {
426 g_program->add_typedef($1);
427 }
428 }
429| Enum
430 {
431 pdebug("TypeDefinition -> Enum");
432 if (g_parse_mode == PROGRAM) {
433 g_program->add_enum($1);
434 }
435 }
Mark Slee6a47fed2007-02-07 02:40:59 +0000436| Senum
437 {
438 pdebug("TypeDefinition -> Senum");
439 if (g_parse_mode == PROGRAM) {
440 g_program->add_typedef($1);
441 }
442 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000443| Struct
444 {
445 pdebug("TypeDefinition -> Struct");
446 if (g_parse_mode == PROGRAM) {
447 g_program->add_struct($1);
448 }
449 }
450| Xception
Mark Slee27ed6ec2007-08-16 01:26:31 +0000451 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000452 pdebug("TypeDefinition -> Xception");
453 if (g_parse_mode == PROGRAM) {
454 g_program->add_xception($1);
455 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000456 }
Mark Slee31985722006-05-24 21:45:31 +0000457
458Typedef:
Mark Sleebd588222007-11-21 08:43:35 +0000459 tok_typedef DefinitionType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000460 {
461 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
David Reisscdffe262007-08-14 17:12:31 +0000462 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000463 $$ = td;
464 }
465
Mark Slee6a47fed2007-02-07 02:40:59 +0000466CommaOrSemicolonOptional:
467 ','
468 {}
469| ';'
470 {}
471|
472 {}
ccheeverf53b5cf2007-02-05 20:33:11 +0000473
Mark Slee31985722006-05-24 21:45:31 +0000474Enum:
David Reisscdffe262007-08-14 17:12:31 +0000475 tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000476 {
477 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000478 $$ = $4;
479 $$->set_name($2);
Mark Slee31985722006-05-24 21:45:31 +0000480 }
481
482EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000483 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000484 {
485 pdebug("EnumDefList -> EnumDefList EnumDef");
486 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000487 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000488 }
489|
490 {
491 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000492 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000493 }
494
495EnumDef:
David Reisscbd4bac2007-08-14 17:12:33 +0000496 CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000497 {
Mark Slee30152872006-11-28 01:24:07 +0000498 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000499 if ($4 < 0) {
500 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000501 }
David Reissf1454162008-06-30 20:45:47 +0000502 if ($4 > INT_MAX) {
503 pwarning(1, "64-bit value supplied for enum %s.\n", $2);
504 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000505 $$ = new t_enum_value($2, $4);
506 if ($1 != NULL) {
507 $$->set_doc($1);
508 }
Mark Sleed0767c52007-07-27 22:14:41 +0000509 if (g_parse_mode == PROGRAM) {
510 g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4)));
511 if (g_parent_scope != NULL) {
512 g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4)));
513 }
514 }
Mark Slee31985722006-05-24 21:45:31 +0000515 }
516|
David Reisscbd4bac2007-08-14 17:12:33 +0000517 CaptureDocText tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000518 {
Mark Slee30152872006-11-28 01:24:07 +0000519 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000520 $$ = new t_enum_value($2);
521 if ($1 != NULL) {
522 $$->set_doc($1);
523 }
Mark Slee30152872006-11-28 01:24:07 +0000524 }
525
Mark Slee6a47fed2007-02-07 02:40:59 +0000526Senum:
David Reisscdffe262007-08-14 17:12:31 +0000527 tok_senum tok_identifier '{' SenumDefList '}'
Mark Slee6a47fed2007-02-07 02:40:59 +0000528 {
529 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000530 $$ = new t_typedef(g_program, $4, $2);
Mark Slee6a47fed2007-02-07 02:40:59 +0000531 }
532
533SenumDefList:
534 SenumDefList SenumDef
535 {
536 pdebug("SenumDefList -> SenumDefList SenumDef");
537 $$ = $1;
538 $$->add_string_enum_val($2);
539 }
540|
541 {
542 pdebug("SenumDefList -> ");
543 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
544 $$->set_string_enum(true);
545 }
546
547SenumDef:
548 tok_literal CommaOrSemicolonOptional
549 {
550 pdebug("SenumDef -> tok_literal");
551 $$ = $1;
552 }
553
Mark Slee30152872006-11-28 01:24:07 +0000554Const:
555 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
556 {
557 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000558 if (g_parse_mode == PROGRAM) {
559 $$ = new t_const($2, $3, $5);
560 validate_const_type($$);
Mark Sleed0767c52007-07-27 22:14:41 +0000561
562 g_scope->add_constant($3, $$);
563 if (g_parent_scope != NULL) {
564 g_parent_scope->add_constant(g_parent_prefix + $3, $$);
565 }
566
Mark Sleeaa7671d2006-11-29 03:19:31 +0000567 } else {
568 $$ = NULL;
569 }
Mark Slee30152872006-11-28 01:24:07 +0000570 }
571
572ConstValue:
573 tok_int_constant
574 {
575 pdebug("ConstValue => tok_int_constant");
576 $$ = new t_const_value();
577 $$->set_integer($1);
David Reissf1454162008-06-30 20:45:47 +0000578 if ($1 < INT32_MIN || $1 > INT32_MAX) {
579 pwarning(1, "64-bit constant \"%"PRIi64"\" may not work in all languages.\n", $1);
580 }
Mark Slee30152872006-11-28 01:24:07 +0000581 }
582| tok_dub_constant
583 {
584 pdebug("ConstValue => tok_dub_constant");
585 $$ = new t_const_value();
586 $$->set_double($1);
587 }
588| tok_literal
589 {
590 pdebug("ConstValue => tok_literal");
Mark Sleed0767c52007-07-27 22:14:41 +0000591 $$ = new t_const_value($1);
Mark Slee30152872006-11-28 01:24:07 +0000592 }
Mark Slee67fc6342006-11-29 03:37:04 +0000593| tok_identifier
594 {
595 pdebug("ConstValue => tok_identifier");
Mark Sleed0767c52007-07-27 22:14:41 +0000596 t_const* constant = g_scope->get_constant($1);
597 if (constant != NULL) {
598 $$ = constant->get_value();
599 } else {
600 if (g_parse_mode == PROGRAM) {
601 pwarning(1, "Constant strings should be quoted: %s\n", $1);
602 }
603 $$ = new t_const_value($1);
604 }
Mark Slee67fc6342006-11-29 03:37:04 +0000605 }
Mark Slee30152872006-11-28 01:24:07 +0000606| ConstList
607 {
608 pdebug("ConstValue => ConstList");
609 $$ = $1;
610 }
611| ConstMap
612 {
613 pdebug("ConstValue => ConstMap");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000614 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000615 }
616
617ConstList:
618 '[' ConstListContents ']'
619 {
620 pdebug("ConstList => [ ConstListContents ]");
621 $$ = $2;
622 }
623
624ConstListContents:
625 ConstListContents ConstValue CommaOrSemicolonOptional
626 {
627 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
628 $$ = $1;
629 $$->add_list($2);
630 }
631|
632 {
633 pdebug("ConstListContents =>");
634 $$ = new t_const_value();
635 $$->set_list();
636 }
637
638ConstMap:
639 '{' ConstMapContents '}'
640 {
641 pdebug("ConstMap => { ConstMapContents }");
642 $$ = $2;
643 }
644
645ConstMapContents:
646 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
647 {
648 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
649 $$ = $1;
650 $$->add_map($2, $4);
651 }
652|
653 {
654 pdebug("ConstMapContents =>");
655 $$ = new t_const_value();
656 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000657 }
658
659Struct:
David Reisscdffe262007-08-14 17:12:31 +0000660 tok_struct tok_identifier XsdAll '{' FieldList '}'
Mark Slee31985722006-05-24 21:45:31 +0000661 {
662 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
David Reisscdffe262007-08-14 17:12:31 +0000663 $5->set_name($2);
664 $5->set_xsd_all($3);
665 $$ = $5;
Mark Slee9cb7c612006-09-01 22:17:45 +0000666 y_field_val = -1;
667 }
668
Mark Slee36bfa2e2007-01-19 20:09:51 +0000669XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000670 tok_xsd_all
671 {
672 $$ = true;
673 }
674|
675 {
676 $$ = false;
677 }
678
Mark Slee36bfa2e2007-01-19 20:09:51 +0000679XsdOptional:
680 tok_xsd_optional
681 {
682 $$ = true;
683 }
684|
685 {
686 $$ = false;
687 }
688
Mark Slee7df0e2a2007-02-06 21:03:18 +0000689XsdNillable:
690 tok_xsd_nillable
691 {
692 $$ = true;
693 }
694|
695 {
696 $$ = false;
697 }
698
Mark Slee21135c32007-02-05 21:52:08 +0000699XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000700 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000701 {
Mark Slee748d83f2007-02-07 01:20:08 +0000702 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000703 }
704|
705 {
706 $$ = NULL;
707 }
708
Mark Slee9cb7c612006-09-01 22:17:45 +0000709Xception:
710 tok_xception tok_identifier '{' FieldList '}'
711 {
712 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
713 $4->set_name($2);
714 $4->set_xception(true);
715 $$ = $4;
716 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000717 }
718
719Service:
Mark Slee78165722007-09-10 22:08:49 +0000720 tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
Mark Slee31985722006-05-24 21:45:31 +0000721 {
722 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Slee78165722007-09-10 22:08:49 +0000723 $$ = $6;
David Reisscdffe262007-08-14 17:12:31 +0000724 $$->set_name($2);
725 $$->set_extends($3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000726 }
727
Mark Slee78165722007-09-10 22:08:49 +0000728FlagArgs:
729 {
730 g_arglist = 1;
731 }
732
733UnflagArgs:
734 {
735 g_arglist = 0;
736 }
737
Mark Slee36bfa2e2007-01-19 20:09:51 +0000738Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000739 tok_extends tok_identifier
740 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000741 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000742 $$ = NULL;
743 if (g_parse_mode == PROGRAM) {
744 $$ = g_scope->get_service($2);
745 if ($$ == NULL) {
746 yyerror("Service \"%s\" has not been defined.", $2);
747 exit(1);
748 }
749 }
750 }
751|
752 {
753 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000754 }
755
756FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000757 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000758 {
759 pdebug("FunctionList -> FunctionList Function");
760 $$ = $1;
761 $1->add_function($2);
762 }
763|
764 {
765 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000766 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000767 }
768
769Function:
David Reisscbd4bac2007-08-14 17:12:33 +0000770 CaptureDocText Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000771 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000772 $6->set_name(std::string($4) + "_args");
773 $$ = new t_function($3, $4, $6, $8, $2);
774 if ($1 != NULL) {
775 $$->set_doc($1);
776 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000777 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000778 }
779
Mark Slee36bfa2e2007-01-19 20:09:51 +0000780Async:
Mark Slee52f643d2006-08-09 00:03:43 +0000781 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000782 {
Mark Slee52f643d2006-08-09 00:03:43 +0000783 $$ = true;
784 }
785|
786 {
787 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000788 }
789
Mark Slee36bfa2e2007-01-19 20:09:51 +0000790Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000791 tok_throws '(' FieldList ')'
792 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000793 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000794 $$ = $3;
Mark Sleef07d48e2008-02-01 01:36:26 +0000795 if (g_parse_mode == PROGRAM && !validate_throws($$)) {
Mark Slee91f2b7b2008-01-31 01:49:16 +0000796 yyerror("Throws clause may not contain non-exception types");
797 exit(1);
798 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000799 }
800|
801 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000802 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000803 }
804
Mark Slee31985722006-05-24 21:45:31 +0000805FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000806 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000807 {
808 pdebug("FieldList -> FieldList , Field");
809 $$ = $1;
Mark Slee6f9ac3f2007-11-28 22:28:13 +0000810 if (!($$->validate_field($2))) {
811 yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
812 exit(1);
813 }
Mark Slee207cb462006-11-02 18:43:12 +0000814 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000815 }
816|
817 {
818 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000819 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000820 }
821
822Field:
David Reiss8320a922007-08-14 19:59:26 +0000823 CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000824 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000825 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000826 if ($2 < 0) {
David Reiss8320a922007-08-14 19:59:26 +0000827 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 +0000828 }
David Reiss8320a922007-08-14 19:59:26 +0000829 $$ = new t_field($4, $5, $2);
830 $$->set_req($3);
831 if ($6 != NULL) {
832 validate_field_value($$, $6);
833 $$->set_value($6);
Mark Slee7ff32452007-02-01 05:26:18 +0000834 }
David Reiss8320a922007-08-14 19:59:26 +0000835 $$->set_xsd_optional($7);
836 $$->set_xsd_nillable($8);
ccheeverf53b5cf2007-02-05 20:33:11 +0000837 if ($1 != NULL) {
838 $$->set_doc($1);
839 }
David Reiss8320a922007-08-14 19:59:26 +0000840 if ($9 != NULL) {
841 $$->set_xsd_attrs($9);
Mark Slee21135c32007-02-05 21:52:08 +0000842 }
Mark Slee31985722006-05-24 21:45:31 +0000843 }
Mark Slee7ff32452007-02-01 05:26:18 +0000844
845FieldIdentifier:
846 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000847 {
Mark Slee7ff32452007-02-01 05:26:18 +0000848 if ($1 <= 0) {
849 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
850 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000851 }
Mark Slee7ff32452007-02-01 05:26:18 +0000852 $$ = $1;
853 }
854|
855 {
856 $$ = y_field_val--;
857 }
858
David Reiss8320a922007-08-14 19:59:26 +0000859FieldRequiredness:
860 tok_required
861 {
Mark Slee78165722007-09-10 22:08:49 +0000862 if (g_arglist) {
863 if (g_parse_mode == PROGRAM) {
864 pwarning(1, "required 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_REQUIRED;
Mark Slee78165722007-09-10 22:08:49 +0000869 }
David Reiss8320a922007-08-14 19:59:26 +0000870 }
871| tok_optional
872 {
Mark Slee78165722007-09-10 22:08:49 +0000873 if (g_arglist) {
874 if (g_parse_mode == PROGRAM) {
875 pwarning(1, "optional keyword is ignored in argument lists.\n");
876 }
David Reiss204420f2008-01-11 20:59:03 +0000877 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000878 } else {
David Reiss204420f2008-01-11 20:59:03 +0000879 $$ = t_field::T_OPTIONAL;
Mark Slee78165722007-09-10 22:08:49 +0000880 }
David Reiss8320a922007-08-14 19:59:26 +0000881 }
882|
883 {
David Reiss204420f2008-01-11 20:59:03 +0000884 $$ = t_field::T_OPT_IN_REQ_OUT;
David Reiss8320a922007-08-14 19:59:26 +0000885 }
886
Mark Slee7ff32452007-02-01 05:26:18 +0000887FieldValue:
888 '=' ConstValue
889 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000890 if (g_parse_mode == PROGRAM) {
Mark Slee7ff32452007-02-01 05:26:18 +0000891 $$ = $2;
892 } else {
893 $$ = NULL;
894 }
895 }
896|
897 {
898 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000899 }
Mark Slee31985722006-05-24 21:45:31 +0000900
901DefinitionType:
902 BaseType
903 {
904 pdebug("DefinitionType -> BaseType");
905 $$ = $1;
906 }
Mark Sleee8540632006-05-30 09:24:40 +0000907| ContainerType
908 {
909 pdebug("DefinitionType -> ContainerType");
910 $$ = $1;
911 }
Mark Slee31985722006-05-24 21:45:31 +0000912
913FunctionType:
914 FieldType
915 {
Mark Sleee8540632006-05-30 09:24:40 +0000916 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000917 $$ = $1;
918 }
919| tok_void
920 {
Mark Sleee8540632006-05-30 09:24:40 +0000921 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000922 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000923 }
924
925FieldType:
926 tok_identifier
927 {
Mark Sleee8540632006-05-30 09:24:40 +0000928 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000929 if (g_parse_mode == INCLUDES) {
930 // Ignore identifiers in include mode
931 $$ = NULL;
932 } else {
933 // Lookup the identifier in the current scope
934 $$ = g_scope->get_type($1);
935 if ($$ == NULL) {
936 yyerror("Type \"%s\" has not been defined.", $1);
937 exit(1);
938 }
Mark Sleee8540632006-05-30 09:24:40 +0000939 }
Mark Slee31985722006-05-24 21:45:31 +0000940 }
941| BaseType
942 {
Mark Sleee8540632006-05-30 09:24:40 +0000943 pdebug("FieldType -> BaseType");
944 $$ = $1;
945 }
946| ContainerType
947 {
948 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000949 $$ = $1;
950 }
951
952BaseType:
953 tok_string
954 {
955 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000956 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000957 }
Mark Slee8d725a22007-04-13 01:57:12 +0000958| tok_binary
959 {
960 pdebug("BaseType -> tok_binary");
961 $$ = g_type_binary;
962 }
Mark Sleeb6200d82007-01-19 19:14:36 +0000963| tok_slist
964 {
965 pdebug("BaseType -> tok_slist");
966 $$ = g_type_slist;
967 }
Mark Slee78f58e22006-09-02 04:17:07 +0000968| tok_bool
969 {
970 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000971 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000972 }
Mark Slee31985722006-05-24 21:45:31 +0000973| tok_byte
974 {
975 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000976 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000977 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000978| tok_i16
979 {
980 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000981 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000982 }
Mark Slee31985722006-05-24 21:45:31 +0000983| tok_i32
984 {
985 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000986 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000987 }
Mark Slee31985722006-05-24 21:45:31 +0000988| tok_i64
989 {
990 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000991 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000992 }
Mark Sleec98d0502006-09-06 02:42:25 +0000993| tok_double
994 {
995 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000996 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000997 }
Mark Slee31985722006-05-24 21:45:31 +0000998
Mark Sleee8540632006-05-30 09:24:40 +0000999ContainerType:
1000 MapType
1001 {
1002 pdebug("ContainerType -> MapType");
1003 $$ = $1;
1004 }
1005| SetType
1006 {
1007 pdebug("ContainerType -> SetType");
1008 $$ = $1;
1009 }
1010| ListType
1011 {
1012 pdebug("ContainerType -> ListType");
1013 $$ = $1;
1014 }
1015
1016MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001017 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001018 {
1019 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001020 $$ = new t_map($4, $6);
1021 if ($2 != NULL) {
1022 ((t_container*)$$)->set_cpp_name(std::string($2));
1023 }
Mark Sleee8540632006-05-30 09:24:40 +00001024 }
1025
1026SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001027 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001028 {
1029 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001030 $$ = new t_set($4);
1031 if ($2 != NULL) {
1032 ((t_container*)$$)->set_cpp_name(std::string($2));
1033 }
Mark Sleee8540632006-05-30 09:24:40 +00001034 }
1035
1036ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001037 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +00001038 {
1039 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +00001040 $$ = new t_list($3);
1041 if ($5 != NULL) {
1042 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +00001043 }
1044 }
1045
Mark Slee36bfa2e2007-01-19 20:09:51 +00001046CppType:
Mark Sleeafc76542007-02-09 21:55:44 +00001047 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +00001048 {
Mark Sleeafc76542007-02-09 21:55:44 +00001049 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +00001050 }
1051|
1052 {
1053 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +00001054 }
1055
Mark Slee31985722006-05-24 21:45:31 +00001056%%