blob: c916604d3d54ad2e8ccd83fbe44ed2c041b63cbc [file] [log] [blame]
Mark Slee31985722006-05-24 21:45:31 +00001%{
David Reissea2cba82009-03-30 21:35:00 +00002/*
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 */
Mark Slee31985722006-05-24 21:45:31 +000020
21/**
22 * Thrift parser.
23 *
24 * This parser is used on a thrift definition file.
25 *
Mark Slee31985722006-05-24 21:45:31 +000026 */
27
David Reissf1454162008-06-30 20:45:47 +000028#define __STDC_LIMIT_MACROS
29#define __STDC_FORMAT_MACROS
Mark Slee31985722006-05-24 21:45:31 +000030#include <stdio.h>
David Reissf1454162008-06-30 20:45:47 +000031#include <inttypes.h>
David Reiss400a5432008-07-25 19:48:39 +000032#include <limits.h>
Mark Slee31985722006-05-24 21:45:31 +000033#include "main.h"
34#include "globals.h"
35#include "parse/t_program.h"
Mark Sleef0712dc2006-10-25 19:03:57 +000036#include "parse/t_scope.h"
Mark Slee31985722006-05-24 21:45:31 +000037
Mark Sleef5377b32006-10-10 01:42:59 +000038/**
39 * This global variable is used for automatic numbering of field indices etc.
40 * when parsing the members of a struct. Field values are automatically
41 * assigned starting from -1 and working their way down.
42 */
Mark Slee9cb7c612006-09-01 22:17:45 +000043int y_field_val = -1;
Mark Slee78165722007-09-10 22:08:49 +000044int g_arglist = 0;
Bryan Duxburyab3666e2009-09-01 23:03:47 +000045const int struct_is_struct = 0;
46const int struct_is_union = 1;
Mark Slee31985722006-05-24 21:45:31 +000047
48%}
49
Mark Sleef5377b32006-10-10 01:42:59 +000050/**
51 * This structure is used by the parser to hold the data types associated with
52 * various parse nodes.
53 */
Mark Slee31985722006-05-24 21:45:31 +000054%union {
Mark Slee30152872006-11-28 01:24:07 +000055 char* id;
David Reissf1454162008-06-30 20:45:47 +000056 int64_t iconst;
Mark Slee30152872006-11-28 01:24:07 +000057 double dconst;
58 bool tbool;
David Reisscdffe262007-08-14 17:12:31 +000059 t_doc* tdoc;
Mark Slee30152872006-11-28 01:24:07 +000060 t_type* ttype;
Mark Slee6a47fed2007-02-07 02:40:59 +000061 t_base_type* tbase;
Mark Slee30152872006-11-28 01:24:07 +000062 t_typedef* ttypedef;
63 t_enum* tenum;
64 t_enum_value* tenumv;
65 t_const* tconst;
66 t_const_value* tconstv;
67 t_struct* tstruct;
68 t_service* tservice;
69 t_function* tfunction;
70 t_field* tfield;
David Reisscdffe262007-08-14 17:12:31 +000071 char* dtext;
David Reiss8320a922007-08-14 19:59:26 +000072 t_field::e_req ereq;
David Reissa2309992008-12-10 01:52:48 +000073 t_annotation* tannot;
Bryan Duxburyc7206a42011-08-17 23:17:04 +000074 t_field_id tfieldid;
Mark Slee31985722006-05-24 21:45:31 +000075}
76
Mark Sleef5377b32006-10-10 01:42:59 +000077/**
78 * Strings identifier
79 */
Mark Slee31985722006-05-24 21:45:31 +000080%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000081%token<id> tok_literal
David Reisscdffe262007-08-14 17:12:31 +000082%token<dtext> tok_doctext
Mark Sleebd588222007-11-21 08:43:35 +000083%token<id> tok_st_identifier
Mark Sleef5377b32006-10-10 01:42:59 +000084
85/**
Mark Slee30152872006-11-28 01:24:07 +000086 * Constant values
Mark Sleef5377b32006-10-10 01:42:59 +000087 */
Mark Slee31985722006-05-24 21:45:31 +000088%token<iconst> tok_int_constant
Mark Slee30152872006-11-28 01:24:07 +000089%token<dconst> tok_dub_constant
Mark Slee31985722006-05-24 21:45:31 +000090
Mark Sleef5377b32006-10-10 01:42:59 +000091/**
David Reiss399442b2008-02-20 02:28:05 +000092 * Header keywords
Mark Sleef5377b32006-10-10 01:42:59 +000093 */
Mark Sleef0712dc2006-10-25 19:03:57 +000094%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000095%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000096%token tok_cpp_namespace
97%token tok_cpp_include
98%token tok_cpp_type
Mark Sleee888b372007-01-12 01:06:24 +000099%token tok_php_namespace
David Reissc6fc3292007-08-30 00:58:43 +0000100%token tok_py_module
Mark Slee27ed6ec2007-08-16 01:26:31 +0000101%token tok_perl_package
Mark Sleef0712dc2006-10-25 19:03:57 +0000102%token tok_java_package
Mark Slee782abbb2007-01-19 00:17:02 +0000103%token tok_xsd_all
Mark Slee36bfa2e2007-01-19 20:09:51 +0000104%token tok_xsd_optional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000105%token tok_xsd_nillable
Mark Slee0d9199e2007-01-31 02:08:30 +0000106%token tok_xsd_namespace
Mark Slee21135c32007-02-05 21:52:08 +0000107%token tok_xsd_attrs
Mark Slee58dfb4f2007-07-06 02:45:25 +0000108%token tok_ruby_namespace
Mark Sleebd588222007-11-21 08:43:35 +0000109%token tok_smalltalk_category
David Reiss15457c92007-12-14 07:03:03 +0000110%token tok_smalltalk_prefix
Mark Slee7e9eea42007-09-10 21:00:23 +0000111%token tok_cocoa_prefix
David Reiss7f42bcf2008-01-11 20:59:12 +0000112%token tok_csharp_namespace
Mark Slee9cb7c612006-09-01 22:17:45 +0000113
Mark Sleef5377b32006-10-10 01:42:59 +0000114/**
115 * Base datatype keywords
116 */
117%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +0000118%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +0000119%token tok_byte
120%token tok_string
Mark Slee8d725a22007-04-13 01:57:12 +0000121%token tok_binary
Mark Sleeb6200d82007-01-19 19:14:36 +0000122%token tok_slist
Mark Slee6a47fed2007-02-07 02:40:59 +0000123%token tok_senum
Mark Slee9cb7c612006-09-01 22:17:45 +0000124%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +0000125%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +0000126%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +0000127%token tok_double
Mark Slee31985722006-05-24 21:45:31 +0000128
Mark Sleef5377b32006-10-10 01:42:59 +0000129/**
130 * Complex type keywords
131 */
Mark Slee31985722006-05-24 21:45:31 +0000132%token tok_map
133%token tok_list
134%token tok_set
135
Mark Sleef5377b32006-10-10 01:42:59 +0000136/**
137 * Function modifiers
Mark Slee27ed6ec2007-08-16 01:26:31 +0000138 */
David Reiss6985a422009-03-24 20:00:47 +0000139%token tok_oneway
Mark Slee31985722006-05-24 21:45:31 +0000140
Mark Sleef5377b32006-10-10 01:42:59 +0000141/**
142 * Thrift language keywords
143 */
Mark Slee31985722006-05-24 21:45:31 +0000144%token tok_typedef
145%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000146%token tok_xception
147%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000148%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000149%token tok_service
150%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000151%token tok_const
David Reiss8320a922007-08-14 19:59:26 +0000152%token tok_required
153%token tok_optional
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000154%token tok_union
Mark Slee31985722006-05-24 21:45:31 +0000155
Mark Sleef5377b32006-10-10 01:42:59 +0000156/**
157 * Grammar nodes
158 */
159
Mark Slee31985722006-05-24 21:45:31 +0000160%type<ttype> BaseType
David Reissc8e30052009-07-27 17:02:42 +0000161%type<ttype> SimpleBaseType
Mark Sleee8540632006-05-30 09:24:40 +0000162%type<ttype> ContainerType
David Reissa2309992008-12-10 01:52:48 +0000163%type<ttype> SimpleContainerType
Mark Sleee8540632006-05-30 09:24:40 +0000164%type<ttype> MapType
165%type<ttype> SetType
166%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000167
David Reisscdffe262007-08-14 17:12:31 +0000168%type<tdoc> Definition
Mark Sleef0712dc2006-10-25 19:03:57 +0000169%type<ttype> TypeDefinition
170
Mark Slee31985722006-05-24 21:45:31 +0000171%type<ttypedef> Typedef
Mark Slee31985722006-05-24 21:45:31 +0000172
David Reissa2309992008-12-10 01:52:48 +0000173%type<ttype> TypeAnnotations
174%type<ttype> TypeAnnotationList
175%type<tannot> TypeAnnotation
176
Mark Slee31985722006-05-24 21:45:31 +0000177%type<tfield> Field
Bryan Duxburyc7206a42011-08-17 23:17:04 +0000178%type<tfieldid> FieldIdentifier
David Reiss8320a922007-08-14 19:59:26 +0000179%type<ereq> FieldRequiredness
Mark Slee31985722006-05-24 21:45:31 +0000180%type<ttype> FieldType
Mark Slee7ff32452007-02-01 05:26:18 +0000181%type<tconstv> FieldValue
Mark Sleee8540632006-05-30 09:24:40 +0000182%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000183
184%type<tenum> Enum
185%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000186%type<tenumv> EnumDef
187
Mark Slee6a47fed2007-02-07 02:40:59 +0000188%type<ttypedef> Senum
189%type<tbase> SenumDefList
190%type<id> SenumDef
191
Mark Slee30152872006-11-28 01:24:07 +0000192%type<tconst> Const
193%type<tconstv> ConstValue
194%type<tconstv> ConstList
195%type<tconstv> ConstListContents
196%type<tconstv> ConstMap
197%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000198
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000199%type<iconst> StructHead
Mark Slee31985722006-05-24 21:45:31 +0000200%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000201%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000202%type<tservice> Service
203
204%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000205%type<ttype> FunctionType
206%type<tservice> FunctionList
207
Mark Slee36bfa2e2007-01-19 20:09:51 +0000208%type<tstruct> Throws
209%type<tservice> Extends
David Reiss6985a422009-03-24 20:00:47 +0000210%type<tbool> Oneway
Mark Slee36bfa2e2007-01-19 20:09:51 +0000211%type<tbool> XsdAll
212%type<tbool> XsdOptional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000213%type<tbool> XsdNillable
Mark Slee748d83f2007-02-07 01:20:08 +0000214%type<tstruct> XsdAttributes
Mark Slee36bfa2e2007-01-19 20:09:51 +0000215%type<id> CppType
Mark Slee52f643d2006-08-09 00:03:43 +0000216
David Reisscbd4bac2007-08-14 17:12:33 +0000217%type<dtext> CaptureDocText
ccheeverf53b5cf2007-02-05 20:33:11 +0000218
Mark Slee31985722006-05-24 21:45:31 +0000219%%
220
Mark Sleef5377b32006-10-10 01:42:59 +0000221/**
222 * Thrift Grammar Implementation.
223 *
224 * For the most part this source file works its way top down from what you
225 * might expect to find in a typical .thrift file, i.e. type definitions and
226 * namespaces up top followed by service definitions using those types.
227 */
Mark Slee31985722006-05-24 21:45:31 +0000228
229Program:
David Reisscbd4bac2007-08-14 17:12:33 +0000230 HeaderList DefinitionList
Mark Sleef0712dc2006-10-25 19:03:57 +0000231 {
232 pdebug("Program -> Headers DefinitionList");
David Reisscbd4bac2007-08-14 17:12:33 +0000233 /*
234 TODO(dreiss): Decide whether full-program doctext is worth the trouble.
David Reissc2532a92007-07-30 23:46:11 +0000235 if ($1 != NULL) {
236 g_program->set_doc($1);
237 }
David Reisscbd4bac2007-08-14 17:12:33 +0000238 */
239 clear_doctext();
Mark Sleef0712dc2006-10-25 19:03:57 +0000240 }
241
David Reisscbd4bac2007-08-14 17:12:33 +0000242CaptureDocText:
243 {
244 if (g_parse_mode == PROGRAM) {
Mark Sleebd588222007-11-21 08:43:35 +0000245 $$ = g_doctext;
David Reisscbd4bac2007-08-14 17:12:33 +0000246 g_doctext = NULL;
Mark Slee27ed6ec2007-08-16 01:26:31 +0000247 } else {
David Reisscbd4bac2007-08-14 17:12:33 +0000248 $$ = NULL;
249 }
250 }
251
252/* TODO(dreiss): Try to DestroyDocText in all sorts or random places. */
253DestroyDocText:
254 {
255 if (g_parse_mode == PROGRAM) {
256 clear_doctext();
257 }
258 }
259
260/* We have to DestroyDocText here, otherwise it catches the doctext
261 on the first real element. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000262HeaderList:
David Reisscbd4bac2007-08-14 17:12:33 +0000263 HeaderList DestroyDocText Header
Mark Sleef0712dc2006-10-25 19:03:57 +0000264 {
265 pdebug("HeaderList -> HeaderList Header");
266 }
267|
268 {
269 pdebug("HeaderList -> ");
270 }
271
272Header:
273 Include
274 {
275 pdebug("Header -> Include");
276 }
David Reiss79eca142008-02-27 01:55:13 +0000277| tok_namespace tok_identifier tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +0000278 {
David Reiss79eca142008-02-27 01:55:13 +0000279 pdebug("Header -> tok_namespace tok_identifier tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000280 if (g_parse_mode == PROGRAM) {
David Reiss79eca142008-02-27 01:55:13 +0000281 g_program->set_namespace($2, $3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000282 }
283 }
David Reissfb790d72010-09-02 16:41:45 +0000284| tok_namespace '*' tok_identifier
285 {
286 pdebug("Header -> tok_namespace * tok_identifier");
287 if (g_parse_mode == PROGRAM) {
288 g_program->set_namespace("*", $3);
289 }
290 }
David Reiss9a08dc62008-02-27 01:55:17 +0000291/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000292| tok_cpp_namespace tok_identifier
293 {
David Reiss9a08dc62008-02-27 01:55:17 +0000294 pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000295 pdebug("Header -> tok_cpp_namespace tok_identifier");
296 if (g_parse_mode == PROGRAM) {
David Reiss9a08dc62008-02-27 01:55:17 +0000297 g_program->set_namespace("cpp", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000298 }
299 }
300| tok_cpp_include tok_literal
301 {
302 pdebug("Header -> tok_cpp_include tok_literal");
303 if (g_parse_mode == PROGRAM) {
304 g_program->add_cpp_include($2);
305 }
306 }
Mark Sleee888b372007-01-12 01:06:24 +0000307| tok_php_namespace tok_identifier
308 {
David Reiss554ea6f2009-02-17 20:28:37 +0000309 pwarning(1, "'php_namespace' is deprecated. Use 'namespace php' instead");
Mark Sleee888b372007-01-12 01:06:24 +0000310 pdebug("Header -> tok_php_namespace tok_identifier");
311 if (g_parse_mode == PROGRAM) {
David Reiss554ea6f2009-02-17 20:28:37 +0000312 g_program->set_namespace("php", $2);
Mark Sleee888b372007-01-12 01:06:24 +0000313 }
314 }
David Reiss320e45c2008-03-27 21:41:54 +0000315/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reissc6fc3292007-08-30 00:58:43 +0000316| tok_py_module tok_identifier
317 {
David Reiss320e45c2008-03-27 21:41:54 +0000318 pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead");
David Reissc6fc3292007-08-30 00:58:43 +0000319 pdebug("Header -> tok_py_module tok_identifier");
320 if (g_parse_mode == PROGRAM) {
David Reiss320e45c2008-03-27 21:41:54 +0000321 g_program->set_namespace("py", $2);
David Reissc6fc3292007-08-30 00:58:43 +0000322 }
323 }
David Reiss07ef3a92008-03-27 21:42:39 +0000324/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee27ed6ec2007-08-16 01:26:31 +0000325| tok_perl_package tok_identifier
326 {
David Reiss07ef3a92008-03-27 21:42:39 +0000327 pwarning(1, "'perl_package' is deprecated. Use 'namespace perl' instead");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000328 pdebug("Header -> tok_perl_namespace tok_identifier");
329 if (g_parse_mode == PROGRAM) {
David Reiss07ef3a92008-03-27 21:42:39 +0000330 g_program->set_namespace("perl", $2);
Mark Slee27ed6ec2007-08-16 01:26:31 +0000331 }
332 }
David Reiss6a4b82c2008-03-27 21:42:16 +0000333/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee58dfb4f2007-07-06 02:45:25 +0000334| tok_ruby_namespace tok_identifier
335 {
David Reiss6a4b82c2008-03-27 21:42:16 +0000336 pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead");
Mark Slee58dfb4f2007-07-06 02:45:25 +0000337 pdebug("Header -> tok_ruby_namespace tok_identifier");
338 if (g_parse_mode == PROGRAM) {
David Reiss6a4b82c2008-03-27 21:42:16 +0000339 g_program->set_namespace("rb", $2);
Mark Slee58dfb4f2007-07-06 02:45:25 +0000340 }
341 }
David Reiss3b455012008-03-27 21:40:46 +0000342/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleebd588222007-11-21 08:43:35 +0000343| tok_smalltalk_category tok_st_identifier
344 {
David Reiss3b455012008-03-27 21:40:46 +0000345 pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
Mark Sleebd588222007-11-21 08:43:35 +0000346 pdebug("Header -> tok_smalltalk_category tok_st_identifier");
347 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000348 g_program->set_namespace("smalltalk.category", $2);
Mark Sleebd588222007-11-21 08:43:35 +0000349 }
350 }
David Reiss3b455012008-03-27 21:40:46 +0000351/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss15457c92007-12-14 07:03:03 +0000352| tok_smalltalk_prefix tok_identifier
353 {
David Reiss3b455012008-03-27 21:40:46 +0000354 pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
David Reiss15457c92007-12-14 07:03:03 +0000355 pdebug("Header -> tok_smalltalk_prefix tok_identifier");
356 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000357 g_program->set_namespace("smalltalk.prefix", $2);
David Reiss15457c92007-12-14 07:03:03 +0000358 }
359 }
David Reiss771f8c72008-02-27 01:55:25 +0000360/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000361| tok_java_package tok_identifier
362 {
David Reiss9f646152008-03-02 21:59:48 +0000363 pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000364 pdebug("Header -> tok_java_package tok_identifier");
365 if (g_parse_mode == PROGRAM) {
David Reiss771f8c72008-02-27 01:55:25 +0000366 g_program->set_namespace("java", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000367 }
368 }
David Reiss54b602b2008-03-27 21:41:06 +0000369/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee7e9eea42007-09-10 21:00:23 +0000370| tok_cocoa_prefix tok_identifier
371 {
David Reiss54b602b2008-03-27 21:41:06 +0000372 pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
Mark Slee7e9eea42007-09-10 21:00:23 +0000373 pdebug("Header -> tok_cocoa_prefix tok_identifier");
374 if (g_parse_mode == PROGRAM) {
David Reiss54b602b2008-03-27 21:41:06 +0000375 g_program->set_namespace("cocoa", $2);
Mark Slee7e9eea42007-09-10 21:00:23 +0000376 }
377 }
David Reiss92e10d82009-02-17 20:28:19 +0000378/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee0d9199e2007-01-31 02:08:30 +0000379| tok_xsd_namespace tok_literal
380 {
David Reiss92e10d82009-02-17 20:28:19 +0000381 pwarning(1, "'xsd_namespace' is deprecated. Use 'namespace xsd' instead");
Mark Slee0d9199e2007-01-31 02:08:30 +0000382 pdebug("Header -> tok_xsd_namespace tok_literal");
383 if (g_parse_mode == PROGRAM) {
David Reiss92e10d82009-02-17 20:28:19 +0000384 g_program->set_namespace("cocoa", $2);
Mark Slee0d9199e2007-01-31 02:08:30 +0000385 }
386 }
David Reiss9d65bf02008-03-27 21:41:37 +0000387/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss7f42bcf2008-01-11 20:59:12 +0000388| tok_csharp_namespace tok_identifier
389 {
David Reiss9d65bf02008-03-27 21:41:37 +0000390 pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead");
David Reiss919ae802008-03-27 21:41:11 +0000391 pdebug("Header -> tok_csharp_namespace tok_identifier");
David Reiss7f42bcf2008-01-11 20:59:12 +0000392 if (g_parse_mode == PROGRAM) {
David Reiss9d65bf02008-03-27 21:41:37 +0000393 g_program->set_namespace("csharp", $2);
David Reiss7f42bcf2008-01-11 20:59:12 +0000394 }
395 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000396
397Include:
398 tok_include tok_literal
399 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000400 pdebug("Include -> tok_include tok_literal");
Mark Sleef0712dc2006-10-25 19:03:57 +0000401 if (g_parse_mode == INCLUDES) {
402 std::string path = include_file(std::string($2));
403 if (!path.empty()) {
kholst76f2c882008-01-16 02:47:41 +0000404 g_program->add_include(path, std::string($2));
Mark Sleef0712dc2006-10-25 19:03:57 +0000405 }
406 }
407 }
Mark Slee31985722006-05-24 21:45:31 +0000408
409DefinitionList:
David Reisscbd4bac2007-08-14 17:12:33 +0000410 DefinitionList CaptureDocText Definition
Mark Slee31985722006-05-24 21:45:31 +0000411 {
412 pdebug("DefinitionList -> DefinitionList Definition");
David Reisscdffe262007-08-14 17:12:31 +0000413 if ($2 != NULL && $3 != NULL) {
414 $3->set_doc($2);
415 }
Mark Slee31985722006-05-24 21:45:31 +0000416 }
417|
418 {
419 pdebug("DefinitionList -> ");
420 }
421
422Definition:
Mark Slee30152872006-11-28 01:24:07 +0000423 Const
424 {
425 pdebug("Definition -> Const");
426 if (g_parse_mode == PROGRAM) {
427 g_program->add_const($1);
Mark Sleebd588222007-11-21 08:43:35 +0000428 }
David Reisscdffe262007-08-14 17:12:31 +0000429 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000430 }
431| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000432 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000433 pdebug("Definition -> TypeDefinition");
434 if (g_parse_mode == PROGRAM) {
435 g_scope->add_type($1->get_name(), $1);
436 if (g_parent_scope != NULL) {
437 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
438 }
439 }
David Reisscdffe262007-08-14 17:12:31 +0000440 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000441 }
Mark Slee31985722006-05-24 21:45:31 +0000442| Service
443 {
444 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000445 if (g_parse_mode == PROGRAM) {
446 g_scope->add_service($1->get_name(), $1);
447 if (g_parent_scope != NULL) {
448 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
449 }
450 g_program->add_service($1);
451 }
David Reisscdffe262007-08-14 17:12:31 +0000452 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000453 }
454
Mark Sleef0712dc2006-10-25 19:03:57 +0000455TypeDefinition:
456 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000457 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000458 pdebug("TypeDefinition -> Typedef");
459 if (g_parse_mode == PROGRAM) {
460 g_program->add_typedef($1);
461 }
462 }
463| Enum
464 {
465 pdebug("TypeDefinition -> Enum");
466 if (g_parse_mode == PROGRAM) {
467 g_program->add_enum($1);
468 }
469 }
Mark Slee6a47fed2007-02-07 02:40:59 +0000470| Senum
471 {
472 pdebug("TypeDefinition -> Senum");
473 if (g_parse_mode == PROGRAM) {
474 g_program->add_typedef($1);
475 }
476 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000477| Struct
478 {
479 pdebug("TypeDefinition -> Struct");
480 if (g_parse_mode == PROGRAM) {
481 g_program->add_struct($1);
482 }
483 }
484| Xception
Mark Slee27ed6ec2007-08-16 01:26:31 +0000485 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000486 pdebug("TypeDefinition -> Xception");
487 if (g_parse_mode == PROGRAM) {
488 g_program->add_xception($1);
489 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000490 }
Mark Slee31985722006-05-24 21:45:31 +0000491
492Typedef:
David Reiss4dd78012010-03-09 05:19:08 +0000493 tok_typedef FieldType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000494 {
David Reiss4dd78012010-03-09 05:19:08 +0000495 pdebug("TypeDef -> tok_typedef FieldType tok_identifier");
David Reisscdffe262007-08-14 17:12:31 +0000496 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000497 $$ = td;
498 }
499
Mark Slee6a47fed2007-02-07 02:40:59 +0000500CommaOrSemicolonOptional:
501 ','
502 {}
503| ';'
504 {}
505|
506 {}
ccheeverf53b5cf2007-02-05 20:33:11 +0000507
Mark Slee31985722006-05-24 21:45:31 +0000508Enum:
David Reisscdffe262007-08-14 17:12:31 +0000509 tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000510 {
511 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000512 $$ = $4;
513 $$->set_name($2);
Bryan Duxbury2d804702009-12-18 19:41:11 +0000514 $$->resolve_values();
Bryan Duxbury9f0a7862010-09-12 14:38:36 +0000515 // make constants for all the enum values
516 if (g_parse_mode == PROGRAM) {
517 const std::vector<t_enum_value*>& enum_values = $$->get_constants();
518 std::vector<t_enum_value*>::const_iterator c_iter;
519 for (c_iter = enum_values.begin(); c_iter != enum_values.end(); ++c_iter) {
520 std::string const_name = $$->get_name() + "." + (*c_iter)->get_name();
521 t_const_value* const_val = new t_const_value((*c_iter)->get_value());
522 const_val->set_enum($$);
523 g_scope->add_constant(const_name, new t_const(g_type_i32, (*c_iter)->get_name(), const_val));
524 if (g_parent_scope != NULL) {
525 g_parent_scope->add_constant(g_parent_prefix + const_name, new t_const(g_type_i32, (*c_iter)->get_name(), const_val));
526 }
527 }
528 }
Mark Slee31985722006-05-24 21:45:31 +0000529 }
530
531EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000532 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000533 {
534 pdebug("EnumDefList -> EnumDefList EnumDef");
535 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000536 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000537 }
538|
539 {
540 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000541 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000542 }
543
544EnumDef:
David Reisscbd4bac2007-08-14 17:12:33 +0000545 CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000546 {
Mark Slee30152872006-11-28 01:24:07 +0000547 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000548 if ($4 < 0) {
549 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000550 }
David Reissf1454162008-06-30 20:45:47 +0000551 if ($4 > INT_MAX) {
552 pwarning(1, "64-bit value supplied for enum %s.\n", $2);
553 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000554 $$ = new t_enum_value($2, $4);
555 if ($1 != NULL) {
556 $$->set_doc($1);
557 }
Mark Slee31985722006-05-24 21:45:31 +0000558 }
559|
David Reisscbd4bac2007-08-14 17:12:33 +0000560 CaptureDocText tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000561 {
Mark Slee30152872006-11-28 01:24:07 +0000562 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000563 $$ = new t_enum_value($2);
564 if ($1 != NULL) {
565 $$->set_doc($1);
566 }
Mark Slee30152872006-11-28 01:24:07 +0000567 }
568
Mark Slee6a47fed2007-02-07 02:40:59 +0000569Senum:
David Reisscdffe262007-08-14 17:12:31 +0000570 tok_senum tok_identifier '{' SenumDefList '}'
Mark Slee6a47fed2007-02-07 02:40:59 +0000571 {
572 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000573 $$ = new t_typedef(g_program, $4, $2);
Mark Slee6a47fed2007-02-07 02:40:59 +0000574 }
575
576SenumDefList:
577 SenumDefList SenumDef
578 {
579 pdebug("SenumDefList -> SenumDefList SenumDef");
580 $$ = $1;
581 $$->add_string_enum_val($2);
582 }
583|
584 {
585 pdebug("SenumDefList -> ");
586 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
587 $$->set_string_enum(true);
588 }
589
590SenumDef:
591 tok_literal CommaOrSemicolonOptional
592 {
593 pdebug("SenumDef -> tok_literal");
594 $$ = $1;
595 }
596
Mark Slee30152872006-11-28 01:24:07 +0000597Const:
598 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
599 {
600 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000601 if (g_parse_mode == PROGRAM) {
Bryan Duxbury2d804702009-12-18 19:41:11 +0000602 g_scope->resolve_const_value($5, $2);
Mark Sleeaa7671d2006-11-29 03:19:31 +0000603 $$ = new t_const($2, $3, $5);
604 validate_const_type($$);
Mark Sleed0767c52007-07-27 22:14:41 +0000605
606 g_scope->add_constant($3, $$);
607 if (g_parent_scope != NULL) {
608 g_parent_scope->add_constant(g_parent_prefix + $3, $$);
609 }
Mark Sleeaa7671d2006-11-29 03:19:31 +0000610 } else {
611 $$ = NULL;
612 }
Mark Slee30152872006-11-28 01:24:07 +0000613 }
614
615ConstValue:
616 tok_int_constant
617 {
618 pdebug("ConstValue => tok_int_constant");
619 $$ = new t_const_value();
620 $$->set_integer($1);
Roger Meier887ff752011-08-19 11:25:39 +0000621 if (!g_allow_64bit_consts && ($1 < INT32_MIN || $1 > INT32_MAX)) {
David Reissf1454162008-06-30 20:45:47 +0000622 pwarning(1, "64-bit constant \"%"PRIi64"\" may not work in all languages.\n", $1);
623 }
Mark Slee30152872006-11-28 01:24:07 +0000624 }
625| tok_dub_constant
626 {
627 pdebug("ConstValue => tok_dub_constant");
628 $$ = new t_const_value();
629 $$->set_double($1);
630 }
631| tok_literal
632 {
633 pdebug("ConstValue => tok_literal");
Mark Sleed0767c52007-07-27 22:14:41 +0000634 $$ = new t_const_value($1);
Mark Slee30152872006-11-28 01:24:07 +0000635 }
Mark Slee67fc6342006-11-29 03:37:04 +0000636| tok_identifier
637 {
638 pdebug("ConstValue => tok_identifier");
Bryan Duxbury2d804702009-12-18 19:41:11 +0000639 $$ = new t_const_value();
640 $$->set_identifier($1);
Mark Slee67fc6342006-11-29 03:37:04 +0000641 }
Mark Slee30152872006-11-28 01:24:07 +0000642| ConstList
643 {
644 pdebug("ConstValue => ConstList");
645 $$ = $1;
646 }
647| ConstMap
648 {
649 pdebug("ConstValue => ConstMap");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000650 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000651 }
652
653ConstList:
654 '[' ConstListContents ']'
655 {
656 pdebug("ConstList => [ ConstListContents ]");
657 $$ = $2;
658 }
659
660ConstListContents:
661 ConstListContents ConstValue CommaOrSemicolonOptional
662 {
663 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
664 $$ = $1;
665 $$->add_list($2);
666 }
667|
668 {
669 pdebug("ConstListContents =>");
670 $$ = new t_const_value();
671 $$->set_list();
672 }
673
674ConstMap:
675 '{' ConstMapContents '}'
676 {
677 pdebug("ConstMap => { ConstMapContents }");
678 $$ = $2;
679 }
680
681ConstMapContents:
682 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
683 {
684 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
685 $$ = $1;
686 $$->add_map($2, $4);
687 }
688|
689 {
690 pdebug("ConstMapContents =>");
691 $$ = new t_const_value();
692 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000693 }
694
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000695StructHead:
696 tok_struct
697 {
698 $$ = struct_is_struct;
699 }
700| tok_union
701 {
702 $$ = struct_is_union;
703 }
704
Mark Slee31985722006-05-24 21:45:31 +0000705Struct:
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000706 StructHead tok_identifier XsdAll '{' FieldList '}' TypeAnnotations
Mark Slee31985722006-05-24 21:45:31 +0000707 {
708 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
David Reisscdffe262007-08-14 17:12:31 +0000709 $5->set_xsd_all($3);
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000710 $5->set_union($1 == struct_is_union);
David Reisscdffe262007-08-14 17:12:31 +0000711 $$ = $5;
David Reissa2309992008-12-10 01:52:48 +0000712 $$->set_name($2);
713 if ($7 != NULL) {
714 $$->annotations_ = $7->annotations_;
715 delete $7;
716 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000717 }
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000718
Mark Slee36bfa2e2007-01-19 20:09:51 +0000719XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000720 tok_xsd_all
721 {
722 $$ = true;
723 }
724|
725 {
726 $$ = false;
727 }
728
Mark Slee36bfa2e2007-01-19 20:09:51 +0000729XsdOptional:
730 tok_xsd_optional
731 {
732 $$ = true;
733 }
734|
735 {
736 $$ = false;
737 }
738
Mark Slee7df0e2a2007-02-06 21:03:18 +0000739XsdNillable:
740 tok_xsd_nillable
741 {
742 $$ = true;
743 }
744|
745 {
746 $$ = false;
747 }
748
Mark Slee21135c32007-02-05 21:52:08 +0000749XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000750 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000751 {
Mark Slee748d83f2007-02-07 01:20:08 +0000752 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000753 }
754|
755 {
756 $$ = NULL;
757 }
758
Mark Slee9cb7c612006-09-01 22:17:45 +0000759Xception:
760 tok_xception tok_identifier '{' FieldList '}'
761 {
762 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
763 $4->set_name($2);
764 $4->set_xception(true);
765 $$ = $4;
Mark Slee31985722006-05-24 21:45:31 +0000766 }
767
768Service:
Mark Slee78165722007-09-10 22:08:49 +0000769 tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
Mark Slee31985722006-05-24 21:45:31 +0000770 {
771 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Slee78165722007-09-10 22:08:49 +0000772 $$ = $6;
David Reisscdffe262007-08-14 17:12:31 +0000773 $$->set_name($2);
774 $$->set_extends($3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000775 }
776
Mark Slee78165722007-09-10 22:08:49 +0000777FlagArgs:
778 {
779 g_arglist = 1;
780 }
781
782UnflagArgs:
783 {
784 g_arglist = 0;
785 }
786
Mark Slee36bfa2e2007-01-19 20:09:51 +0000787Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000788 tok_extends tok_identifier
789 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000790 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000791 $$ = NULL;
792 if (g_parse_mode == PROGRAM) {
793 $$ = g_scope->get_service($2);
794 if ($$ == NULL) {
795 yyerror("Service \"%s\" has not been defined.", $2);
796 exit(1);
797 }
798 }
799 }
800|
801 {
802 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000803 }
804
805FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000806 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000807 {
808 pdebug("FunctionList -> FunctionList Function");
809 $$ = $1;
810 $1->add_function($2);
811 }
812|
813 {
814 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000815 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000816 }
817
818Function:
David Reiss6985a422009-03-24 20:00:47 +0000819 CaptureDocText Oneway FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000820 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000821 $6->set_name(std::string($4) + "_args");
822 $$ = new t_function($3, $4, $6, $8, $2);
823 if ($1 != NULL) {
824 $$->set_doc($1);
825 }
Mark Slee31985722006-05-24 21:45:31 +0000826 }
827
David Reiss6985a422009-03-24 20:00:47 +0000828Oneway:
829 tok_oneway
Mark Slee31985722006-05-24 21:45:31 +0000830 {
Mark Slee52f643d2006-08-09 00:03:43 +0000831 $$ = true;
832 }
833|
834 {
835 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000836 }
837
Mark Slee36bfa2e2007-01-19 20:09:51 +0000838Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000839 tok_throws '(' FieldList ')'
840 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000841 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000842 $$ = $3;
Mark Sleef07d48e2008-02-01 01:36:26 +0000843 if (g_parse_mode == PROGRAM && !validate_throws($$)) {
Mark Slee91f2b7b2008-01-31 01:49:16 +0000844 yyerror("Throws clause may not contain non-exception types");
845 exit(1);
846 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000847 }
848|
849 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000850 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000851 }
852
Mark Slee31985722006-05-24 21:45:31 +0000853FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000854 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000855 {
856 pdebug("FieldList -> FieldList , Field");
857 $$ = $1;
Bryan Duxburyff219ac2009-04-10 21:51:00 +0000858 if (!($$->append($2))) {
Mark Slee6f9ac3f2007-11-28 22:28:13 +0000859 yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
860 exit(1);
861 }
Mark Slee31985722006-05-24 21:45:31 +0000862 }
863|
864 {
865 pdebug("FieldList -> ");
David Reiss00a8dd62009-03-19 08:14:12 +0000866 y_field_val = -1;
Mark Sleef0712dc2006-10-25 19:03:57 +0000867 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000868 }
869
870Field:
David Reiss53c10e02010-03-05 07:51:51 +0000871 CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes TypeAnnotations CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000872 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000873 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
Bryan Duxburyc7206a42011-08-17 23:17:04 +0000874 if ($2.auto_assigned) {
David Reissbb461362009-04-02 19:23:59 +0000875 pwarning(1, "No field key specified for %s, resulting protocol may have conflicts or not be backwards compatible!\n", $5);
Bryan Duxburya145b4d2009-04-03 17:29:25 +0000876 if (g_strict >= 192) {
877 yyerror("Implicit field keys are deprecated and not allowed with -strict");
878 exit(1);
879 }
Mark Slee31985722006-05-24 21:45:31 +0000880 }
Bryan Duxburyc7206a42011-08-17 23:17:04 +0000881 $$ = new t_field($4, $5, $2.value);
David Reiss8320a922007-08-14 19:59:26 +0000882 $$->set_req($3);
883 if ($6 != NULL) {
Bryan Duxbury2d804702009-12-18 19:41:11 +0000884 g_scope->resolve_const_value($6, $4);
David Reiss8320a922007-08-14 19:59:26 +0000885 validate_field_value($$, $6);
886 $$->set_value($6);
Mark Slee7ff32452007-02-01 05:26:18 +0000887 }
David Reiss8320a922007-08-14 19:59:26 +0000888 $$->set_xsd_optional($7);
889 $$->set_xsd_nillable($8);
ccheeverf53b5cf2007-02-05 20:33:11 +0000890 if ($1 != NULL) {
891 $$->set_doc($1);
892 }
David Reiss8320a922007-08-14 19:59:26 +0000893 if ($9 != NULL) {
894 $$->set_xsd_attrs($9);
Mark Slee21135c32007-02-05 21:52:08 +0000895 }
David Reiss53c10e02010-03-05 07:51:51 +0000896 if ($10 != NULL) {
897 $$->annotations_ = $10->annotations_;
898 delete $10;
899 }
Mark Slee31985722006-05-24 21:45:31 +0000900 }
Mark Slee7ff32452007-02-01 05:26:18 +0000901
902FieldIdentifier:
903 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000904 {
Mark Slee7ff32452007-02-01 05:26:18 +0000905 if ($1 <= 0) {
Bryan Duxburyc7206a42011-08-17 23:17:04 +0000906 if (g_allow_neg_field_keys) {
907 /*
908 * g_allow_neg_field_keys exists to allow users to add explicitly
909 * specified key values to old .thrift files without breaking
910 * protocol compatibility.
911 */
912 if ($1 != y_field_val) {
913 /*
914 * warn if the user-specified negative value isn't what
915 * thrift would have auto-assigned.
916 */
917 pwarning(1, "Negative field key (%d) differs from what would be "
918 "auto-assigned by thrift (%d).\n", $1, y_field_val);
919 }
920 /*
921 * Leave $1 as-is, and update y_field_val to be one less than $1.
922 * The FieldList parsing will catch any duplicate key values.
923 */
924 y_field_val = $1 - 1;
925 $$.value = $1;
926 $$.auto_assigned = false;
927 } else {
928 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n",
929 $1);
930 $$.value = y_field_val--;
931 $$.auto_assigned = true;
932 }
933 } else {
934 $$.value = $1;
935 $$.auto_assigned = false;
Mark Sleef0712dc2006-10-25 19:03:57 +0000936 }
Mark Slee7ff32452007-02-01 05:26:18 +0000937 }
938|
939 {
Bryan Duxburyc7206a42011-08-17 23:17:04 +0000940 $$.value = y_field_val--;
941 $$.auto_assigned = true;
Mark Slee7ff32452007-02-01 05:26:18 +0000942 }
943
David Reiss8320a922007-08-14 19:59:26 +0000944FieldRequiredness:
945 tok_required
946 {
David Reiss45603e92009-09-02 22:15:55 +0000947 $$ = t_field::T_REQUIRED;
David Reiss8320a922007-08-14 19:59:26 +0000948 }
949| tok_optional
950 {
Mark Slee78165722007-09-10 22:08:49 +0000951 if (g_arglist) {
952 if (g_parse_mode == PROGRAM) {
953 pwarning(1, "optional keyword is ignored in argument lists.\n");
954 }
David Reiss204420f2008-01-11 20:59:03 +0000955 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000956 } else {
David Reiss204420f2008-01-11 20:59:03 +0000957 $$ = t_field::T_OPTIONAL;
Mark Slee78165722007-09-10 22:08:49 +0000958 }
David Reiss8320a922007-08-14 19:59:26 +0000959 }
960|
961 {
David Reiss204420f2008-01-11 20:59:03 +0000962 $$ = t_field::T_OPT_IN_REQ_OUT;
David Reiss8320a922007-08-14 19:59:26 +0000963 }
964
Mark Slee7ff32452007-02-01 05:26:18 +0000965FieldValue:
966 '=' ConstValue
967 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000968 if (g_parse_mode == PROGRAM) {
Mark Slee7ff32452007-02-01 05:26:18 +0000969 $$ = $2;
970 } else {
971 $$ = NULL;
972 }
973 }
974|
975 {
976 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000977 }
Mark Slee31985722006-05-24 21:45:31 +0000978
Mark Slee31985722006-05-24 21:45:31 +0000979FunctionType:
980 FieldType
981 {
Mark Sleee8540632006-05-30 09:24:40 +0000982 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000983 $$ = $1;
984 }
985| tok_void
986 {
Mark Sleee8540632006-05-30 09:24:40 +0000987 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000988 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000989 }
990
991FieldType:
992 tok_identifier
993 {
Mark Sleee8540632006-05-30 09:24:40 +0000994 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000995 if (g_parse_mode == INCLUDES) {
996 // Ignore identifiers in include mode
997 $$ = NULL;
998 } else {
999 // Lookup the identifier in the current scope
1000 $$ = g_scope->get_type($1);
1001 if ($$ == NULL) {
1002 yyerror("Type \"%s\" has not been defined.", $1);
1003 exit(1);
1004 }
Mark Sleee8540632006-05-30 09:24:40 +00001005 }
Mark Slee31985722006-05-24 21:45:31 +00001006 }
1007| BaseType
1008 {
Mark Sleee8540632006-05-30 09:24:40 +00001009 pdebug("FieldType -> BaseType");
1010 $$ = $1;
1011 }
1012| ContainerType
1013 {
1014 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +00001015 $$ = $1;
1016 }
1017
David Reissc8e30052009-07-27 17:02:42 +00001018BaseType: SimpleBaseType TypeAnnotations
1019 {
1020 pdebug("BaseType -> SimpleBaseType TypeAnnotations");
1021 if ($2 != NULL) {
1022 $$ = new t_base_type(*static_cast<t_base_type*>($1));
1023 $$->annotations_ = $2->annotations_;
1024 delete $2;
1025 } else {
1026 $$ = $1;
1027 }
1028 }
1029
1030SimpleBaseType:
Mark Slee31985722006-05-24 21:45:31 +00001031 tok_string
1032 {
1033 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +00001034 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +00001035 }
Mark Slee8d725a22007-04-13 01:57:12 +00001036| tok_binary
1037 {
1038 pdebug("BaseType -> tok_binary");
1039 $$ = g_type_binary;
1040 }
Mark Sleeb6200d82007-01-19 19:14:36 +00001041| tok_slist
1042 {
1043 pdebug("BaseType -> tok_slist");
1044 $$ = g_type_slist;
1045 }
Mark Slee78f58e22006-09-02 04:17:07 +00001046| tok_bool
1047 {
1048 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +00001049 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +00001050 }
Mark Slee31985722006-05-24 21:45:31 +00001051| tok_byte
1052 {
1053 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +00001054 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +00001055 }
Mark Slee9cb7c612006-09-01 22:17:45 +00001056| tok_i16
1057 {
1058 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +00001059 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +00001060 }
Mark Slee31985722006-05-24 21:45:31 +00001061| tok_i32
1062 {
1063 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +00001064 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +00001065 }
Mark Slee31985722006-05-24 21:45:31 +00001066| tok_i64
1067 {
1068 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +00001069 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +00001070 }
Mark Sleec98d0502006-09-06 02:42:25 +00001071| tok_double
1072 {
1073 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +00001074 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +00001075 }
Mark Slee31985722006-05-24 21:45:31 +00001076
David Reissa2309992008-12-10 01:52:48 +00001077ContainerType: SimpleContainerType TypeAnnotations
1078 {
1079 pdebug("ContainerType -> SimpleContainerType TypeAnnotations");
1080 $$ = $1;
1081 if ($2 != NULL) {
1082 $$->annotations_ = $2->annotations_;
1083 delete $2;
1084 }
1085 }
1086
1087SimpleContainerType:
Mark Sleee8540632006-05-30 09:24:40 +00001088 MapType
1089 {
David Reissa2309992008-12-10 01:52:48 +00001090 pdebug("SimpleContainerType -> MapType");
Mark Sleee8540632006-05-30 09:24:40 +00001091 $$ = $1;
1092 }
1093| SetType
1094 {
David Reissa2309992008-12-10 01:52:48 +00001095 pdebug("SimpleContainerType -> SetType");
Mark Sleee8540632006-05-30 09:24:40 +00001096 $$ = $1;
1097 }
1098| ListType
1099 {
David Reissa2309992008-12-10 01:52:48 +00001100 pdebug("SimpleContainerType -> ListType");
Mark Sleee8540632006-05-30 09:24:40 +00001101 $$ = $1;
1102 }
1103
1104MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001105 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001106 {
1107 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001108 $$ = new t_map($4, $6);
1109 if ($2 != NULL) {
1110 ((t_container*)$$)->set_cpp_name(std::string($2));
1111 }
Mark Sleee8540632006-05-30 09:24:40 +00001112 }
1113
1114SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001115 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001116 {
1117 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001118 $$ = new t_set($4);
1119 if ($2 != NULL) {
1120 ((t_container*)$$)->set_cpp_name(std::string($2));
1121 }
Mark Sleee8540632006-05-30 09:24:40 +00001122 }
1123
1124ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001125 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +00001126 {
1127 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +00001128 $$ = new t_list($3);
1129 if ($5 != NULL) {
1130 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +00001131 }
1132 }
1133
Mark Slee36bfa2e2007-01-19 20:09:51 +00001134CppType:
Mark Sleeafc76542007-02-09 21:55:44 +00001135 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +00001136 {
Mark Sleeafc76542007-02-09 21:55:44 +00001137 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +00001138 }
1139|
1140 {
1141 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +00001142 }
1143
David Reissa2309992008-12-10 01:52:48 +00001144TypeAnnotations:
1145 '(' TypeAnnotationList ')'
1146 {
1147 pdebug("TypeAnnotations -> ( TypeAnnotationList )");
1148 $$ = $2;
1149 }
1150|
1151 {
1152 $$ = NULL;
1153 }
1154
1155TypeAnnotationList:
1156 TypeAnnotationList TypeAnnotation
1157 {
1158 pdebug("TypeAnnotationList -> TypeAnnotationList , TypeAnnotation");
1159 $$ = $1;
1160 $$->annotations_[$2->key] = $2->val;
1161 delete $2;
1162 }
1163|
1164 {
1165 /* Just use a dummy structure to hold the annotations. */
1166 $$ = new t_struct(g_program);
1167 }
1168
1169TypeAnnotation:
1170 tok_identifier '=' tok_literal CommaOrSemicolonOptional
1171 {
1172 pdebug("TypeAnnotation -> tok_identifier = tok_literal");
1173 $$ = new t_annotation;
1174 $$->key = $1;
1175 $$->val = $3;
1176 }
1177
Todd Lipcon53ae9f32009-12-07 00:42:38 +00001178%%