blob: 0fc90dac8b579365f1da91433307f69add75a8a9 [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;
Mark Slee31985722006-05-24 21:45:31 +000074}
75
Mark Sleef5377b32006-10-10 01:42:59 +000076/**
77 * Strings identifier
78 */
Mark Slee31985722006-05-24 21:45:31 +000079%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000080%token<id> tok_literal
David Reisscdffe262007-08-14 17:12:31 +000081%token<dtext> tok_doctext
Mark Sleebd588222007-11-21 08:43:35 +000082%token<id> tok_st_identifier
Mark Sleef5377b32006-10-10 01:42:59 +000083
84/**
Mark Slee30152872006-11-28 01:24:07 +000085 * Constant values
Mark Sleef5377b32006-10-10 01:42:59 +000086 */
Mark Slee31985722006-05-24 21:45:31 +000087%token<iconst> tok_int_constant
Mark Slee30152872006-11-28 01:24:07 +000088%token<dconst> tok_dub_constant
Mark Slee31985722006-05-24 21:45:31 +000089
Mark Sleef5377b32006-10-10 01:42:59 +000090/**
David Reiss399442b2008-02-20 02:28:05 +000091 * Header keywords
Mark Sleef5377b32006-10-10 01:42:59 +000092 */
Mark Sleef0712dc2006-10-25 19:03:57 +000093%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000094%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000095%token tok_cpp_namespace
96%token tok_cpp_include
97%token tok_cpp_type
Mark Sleee888b372007-01-12 01:06:24 +000098%token tok_php_namespace
David Reissc6fc3292007-08-30 00:58:43 +000099%token tok_py_module
Mark Slee27ed6ec2007-08-16 01:26:31 +0000100%token tok_perl_package
Mark Sleef0712dc2006-10-25 19:03:57 +0000101%token tok_java_package
Mark Slee782abbb2007-01-19 00:17:02 +0000102%token tok_xsd_all
Mark Slee36bfa2e2007-01-19 20:09:51 +0000103%token tok_xsd_optional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000104%token tok_xsd_nillable
Mark Slee0d9199e2007-01-31 02:08:30 +0000105%token tok_xsd_namespace
Mark Slee21135c32007-02-05 21:52:08 +0000106%token tok_xsd_attrs
Mark Slee58dfb4f2007-07-06 02:45:25 +0000107%token tok_ruby_namespace
Mark Sleebd588222007-11-21 08:43:35 +0000108%token tok_smalltalk_category
David Reiss15457c92007-12-14 07:03:03 +0000109%token tok_smalltalk_prefix
Mark Slee7e9eea42007-09-10 21:00:23 +0000110%token tok_cocoa_prefix
David Reiss7f42bcf2008-01-11 20:59:12 +0000111%token tok_csharp_namespace
Mark Slee9cb7c612006-09-01 22:17:45 +0000112
Mark Sleef5377b32006-10-10 01:42:59 +0000113/**
114 * Base datatype keywords
115 */
116%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +0000117%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +0000118%token tok_byte
119%token tok_string
Mark Slee8d725a22007-04-13 01:57:12 +0000120%token tok_binary
Mark Sleeb6200d82007-01-19 19:14:36 +0000121%token tok_slist
Mark Slee6a47fed2007-02-07 02:40:59 +0000122%token tok_senum
Mark Slee9cb7c612006-09-01 22:17:45 +0000123%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +0000124%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +0000125%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +0000126%token tok_double
Mark Slee31985722006-05-24 21:45:31 +0000127
Mark Sleef5377b32006-10-10 01:42:59 +0000128/**
129 * Complex type keywords
130 */
Mark Slee31985722006-05-24 21:45:31 +0000131%token tok_map
132%token tok_list
133%token tok_set
134
Mark Sleef5377b32006-10-10 01:42:59 +0000135/**
136 * Function modifiers
Mark Slee27ed6ec2007-08-16 01:26:31 +0000137 */
David Reiss6985a422009-03-24 20:00:47 +0000138%token tok_oneway
Mark Slee31985722006-05-24 21:45:31 +0000139
Mark Sleef5377b32006-10-10 01:42:59 +0000140/**
141 * Thrift language keywords
142 */
Mark Slee31985722006-05-24 21:45:31 +0000143%token tok_typedef
144%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000145%token tok_xception
146%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000147%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000148%token tok_service
149%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000150%token tok_const
David Reiss8320a922007-08-14 19:59:26 +0000151%token tok_required
152%token tok_optional
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000153%token tok_union
Mark Slee31985722006-05-24 21:45:31 +0000154
Mark Sleef5377b32006-10-10 01:42:59 +0000155/**
156 * Grammar nodes
157 */
158
Mark Slee31985722006-05-24 21:45:31 +0000159%type<ttype> BaseType
David Reissc8e30052009-07-27 17:02:42 +0000160%type<ttype> SimpleBaseType
Mark Sleee8540632006-05-30 09:24:40 +0000161%type<ttype> ContainerType
David Reissa2309992008-12-10 01:52:48 +0000162%type<ttype> SimpleContainerType
Mark Sleee8540632006-05-30 09:24:40 +0000163%type<ttype> MapType
164%type<ttype> SetType
165%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000166
David Reisscdffe262007-08-14 17:12:31 +0000167%type<tdoc> Definition
Mark Sleef0712dc2006-10-25 19:03:57 +0000168%type<ttype> TypeDefinition
169
Mark Slee31985722006-05-24 21:45:31 +0000170%type<ttypedef> Typedef
171%type<ttype> DefinitionType
172
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
Mark Slee7ff32452007-02-01 05:26:18 +0000178%type<iconst> 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 Reiss9a08dc62008-02-27 01:55:17 +0000284/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000285| tok_cpp_namespace tok_identifier
286 {
David Reiss9a08dc62008-02-27 01:55:17 +0000287 pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000288 pdebug("Header -> tok_cpp_namespace tok_identifier");
289 if (g_parse_mode == PROGRAM) {
David Reiss9a08dc62008-02-27 01:55:17 +0000290 g_program->set_namespace("cpp", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000291 }
292 }
293| tok_cpp_include tok_literal
294 {
295 pdebug("Header -> tok_cpp_include tok_literal");
296 if (g_parse_mode == PROGRAM) {
297 g_program->add_cpp_include($2);
298 }
299 }
Mark Sleee888b372007-01-12 01:06:24 +0000300| tok_php_namespace tok_identifier
301 {
David Reiss554ea6f2009-02-17 20:28:37 +0000302 pwarning(1, "'php_namespace' is deprecated. Use 'namespace php' instead");
Mark Sleee888b372007-01-12 01:06:24 +0000303 pdebug("Header -> tok_php_namespace tok_identifier");
304 if (g_parse_mode == PROGRAM) {
David Reiss554ea6f2009-02-17 20:28:37 +0000305 g_program->set_namespace("php", $2);
Mark Sleee888b372007-01-12 01:06:24 +0000306 }
307 }
David Reiss320e45c2008-03-27 21:41:54 +0000308/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reissc6fc3292007-08-30 00:58:43 +0000309| tok_py_module tok_identifier
310 {
David Reiss320e45c2008-03-27 21:41:54 +0000311 pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead");
David Reissc6fc3292007-08-30 00:58:43 +0000312 pdebug("Header -> tok_py_module tok_identifier");
313 if (g_parse_mode == PROGRAM) {
David Reiss320e45c2008-03-27 21:41:54 +0000314 g_program->set_namespace("py", $2);
David Reissc6fc3292007-08-30 00:58:43 +0000315 }
316 }
David Reiss07ef3a92008-03-27 21:42:39 +0000317/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee27ed6ec2007-08-16 01:26:31 +0000318| tok_perl_package tok_identifier
319 {
David Reiss07ef3a92008-03-27 21:42:39 +0000320 pwarning(1, "'perl_package' is deprecated. Use 'namespace perl' instead");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000321 pdebug("Header -> tok_perl_namespace tok_identifier");
322 if (g_parse_mode == PROGRAM) {
David Reiss07ef3a92008-03-27 21:42:39 +0000323 g_program->set_namespace("perl", $2);
Mark Slee27ed6ec2007-08-16 01:26:31 +0000324 }
325 }
David Reiss6a4b82c2008-03-27 21:42:16 +0000326/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee58dfb4f2007-07-06 02:45:25 +0000327| tok_ruby_namespace tok_identifier
328 {
David Reiss6a4b82c2008-03-27 21:42:16 +0000329 pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead");
Mark Slee58dfb4f2007-07-06 02:45:25 +0000330 pdebug("Header -> tok_ruby_namespace tok_identifier");
331 if (g_parse_mode == PROGRAM) {
David Reiss6a4b82c2008-03-27 21:42:16 +0000332 g_program->set_namespace("rb", $2);
Mark Slee58dfb4f2007-07-06 02:45:25 +0000333 }
334 }
David Reiss3b455012008-03-27 21:40:46 +0000335/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleebd588222007-11-21 08:43:35 +0000336| tok_smalltalk_category tok_st_identifier
337 {
David Reiss3b455012008-03-27 21:40:46 +0000338 pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
Mark Sleebd588222007-11-21 08:43:35 +0000339 pdebug("Header -> tok_smalltalk_category tok_st_identifier");
340 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000341 g_program->set_namespace("smalltalk.category", $2);
Mark Sleebd588222007-11-21 08:43:35 +0000342 }
343 }
David Reiss3b455012008-03-27 21:40:46 +0000344/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss15457c92007-12-14 07:03:03 +0000345| tok_smalltalk_prefix tok_identifier
346 {
David Reiss3b455012008-03-27 21:40:46 +0000347 pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
David Reiss15457c92007-12-14 07:03:03 +0000348 pdebug("Header -> tok_smalltalk_prefix tok_identifier");
349 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000350 g_program->set_namespace("smalltalk.prefix", $2);
David Reiss15457c92007-12-14 07:03:03 +0000351 }
352 }
David Reiss771f8c72008-02-27 01:55:25 +0000353/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000354| tok_java_package tok_identifier
355 {
David Reiss9f646152008-03-02 21:59:48 +0000356 pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000357 pdebug("Header -> tok_java_package tok_identifier");
358 if (g_parse_mode == PROGRAM) {
David Reiss771f8c72008-02-27 01:55:25 +0000359 g_program->set_namespace("java", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000360 }
361 }
David Reiss54b602b2008-03-27 21:41:06 +0000362/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee7e9eea42007-09-10 21:00:23 +0000363| tok_cocoa_prefix tok_identifier
364 {
David Reiss54b602b2008-03-27 21:41:06 +0000365 pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
Mark Slee7e9eea42007-09-10 21:00:23 +0000366 pdebug("Header -> tok_cocoa_prefix tok_identifier");
367 if (g_parse_mode == PROGRAM) {
David Reiss54b602b2008-03-27 21:41:06 +0000368 g_program->set_namespace("cocoa", $2);
Mark Slee7e9eea42007-09-10 21:00:23 +0000369 }
370 }
David Reiss92e10d82009-02-17 20:28:19 +0000371/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee0d9199e2007-01-31 02:08:30 +0000372| tok_xsd_namespace tok_literal
373 {
David Reiss92e10d82009-02-17 20:28:19 +0000374 pwarning(1, "'xsd_namespace' is deprecated. Use 'namespace xsd' instead");
Mark Slee0d9199e2007-01-31 02:08:30 +0000375 pdebug("Header -> tok_xsd_namespace tok_literal");
376 if (g_parse_mode == PROGRAM) {
David Reiss92e10d82009-02-17 20:28:19 +0000377 g_program->set_namespace("cocoa", $2);
Mark Slee0d9199e2007-01-31 02:08:30 +0000378 }
379 }
David Reiss9d65bf02008-03-27 21:41:37 +0000380/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss7f42bcf2008-01-11 20:59:12 +0000381| tok_csharp_namespace tok_identifier
382 {
David Reiss9d65bf02008-03-27 21:41:37 +0000383 pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead");
David Reiss919ae802008-03-27 21:41:11 +0000384 pdebug("Header -> tok_csharp_namespace tok_identifier");
David Reiss7f42bcf2008-01-11 20:59:12 +0000385 if (g_parse_mode == PROGRAM) {
David Reiss9d65bf02008-03-27 21:41:37 +0000386 g_program->set_namespace("csharp", $2);
David Reiss7f42bcf2008-01-11 20:59:12 +0000387 }
388 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000389
390Include:
391 tok_include tok_literal
392 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000393 pdebug("Include -> tok_include tok_literal");
Mark Sleef0712dc2006-10-25 19:03:57 +0000394 if (g_parse_mode == INCLUDES) {
395 std::string path = include_file(std::string($2));
396 if (!path.empty()) {
kholst76f2c882008-01-16 02:47:41 +0000397 g_program->add_include(path, std::string($2));
Mark Sleef0712dc2006-10-25 19:03:57 +0000398 }
399 }
400 }
Mark Slee31985722006-05-24 21:45:31 +0000401
402DefinitionList:
David Reisscbd4bac2007-08-14 17:12:33 +0000403 DefinitionList CaptureDocText Definition
Mark Slee31985722006-05-24 21:45:31 +0000404 {
405 pdebug("DefinitionList -> DefinitionList Definition");
David Reisscdffe262007-08-14 17:12:31 +0000406 if ($2 != NULL && $3 != NULL) {
407 $3->set_doc($2);
408 }
Mark Slee31985722006-05-24 21:45:31 +0000409 }
410|
411 {
412 pdebug("DefinitionList -> ");
413 }
414
415Definition:
Mark Slee30152872006-11-28 01:24:07 +0000416 Const
417 {
418 pdebug("Definition -> Const");
419 if (g_parse_mode == PROGRAM) {
420 g_program->add_const($1);
Mark Sleebd588222007-11-21 08:43:35 +0000421 }
David Reisscdffe262007-08-14 17:12:31 +0000422 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000423 }
424| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000425 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000426 pdebug("Definition -> TypeDefinition");
427 if (g_parse_mode == PROGRAM) {
428 g_scope->add_type($1->get_name(), $1);
429 if (g_parent_scope != NULL) {
430 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
431 }
432 }
David Reisscdffe262007-08-14 17:12:31 +0000433 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000434 }
Mark Slee31985722006-05-24 21:45:31 +0000435| Service
436 {
437 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000438 if (g_parse_mode == PROGRAM) {
439 g_scope->add_service($1->get_name(), $1);
440 if (g_parent_scope != NULL) {
441 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
442 }
443 g_program->add_service($1);
444 }
David Reisscdffe262007-08-14 17:12:31 +0000445 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000446 }
447
Mark Sleef0712dc2006-10-25 19:03:57 +0000448TypeDefinition:
449 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000450 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000451 pdebug("TypeDefinition -> Typedef");
452 if (g_parse_mode == PROGRAM) {
453 g_program->add_typedef($1);
454 }
455 }
456| Enum
457 {
458 pdebug("TypeDefinition -> Enum");
459 if (g_parse_mode == PROGRAM) {
460 g_program->add_enum($1);
461 }
462 }
Mark Slee6a47fed2007-02-07 02:40:59 +0000463| Senum
464 {
465 pdebug("TypeDefinition -> Senum");
466 if (g_parse_mode == PROGRAM) {
467 g_program->add_typedef($1);
468 }
469 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000470| Struct
471 {
472 pdebug("TypeDefinition -> Struct");
473 if (g_parse_mode == PROGRAM) {
474 g_program->add_struct($1);
475 }
476 }
477| Xception
Mark Slee27ed6ec2007-08-16 01:26:31 +0000478 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000479 pdebug("TypeDefinition -> Xception");
480 if (g_parse_mode == PROGRAM) {
481 g_program->add_xception($1);
482 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000483 }
Mark Slee31985722006-05-24 21:45:31 +0000484
485Typedef:
Mark Sleebd588222007-11-21 08:43:35 +0000486 tok_typedef DefinitionType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000487 {
488 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
David Reisscdffe262007-08-14 17:12:31 +0000489 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000490 $$ = td;
491 }
492
Mark Slee6a47fed2007-02-07 02:40:59 +0000493CommaOrSemicolonOptional:
494 ','
495 {}
496| ';'
497 {}
498|
499 {}
ccheeverf53b5cf2007-02-05 20:33:11 +0000500
Mark Slee31985722006-05-24 21:45:31 +0000501Enum:
David Reisscdffe262007-08-14 17:12:31 +0000502 tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000503 {
504 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000505 $$ = $4;
506 $$->set_name($2);
Bryan Duxbury2d804702009-12-18 19:41:11 +0000507 $$->resolve_values();
Mark Slee31985722006-05-24 21:45:31 +0000508 }
509
510EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000511 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000512 {
513 pdebug("EnumDefList -> EnumDefList EnumDef");
514 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000515 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000516 }
517|
518 {
519 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000520 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000521 }
522
523EnumDef:
David Reisscbd4bac2007-08-14 17:12:33 +0000524 CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000525 {
Mark Slee30152872006-11-28 01:24:07 +0000526 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000527 if ($4 < 0) {
528 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000529 }
David Reissf1454162008-06-30 20:45:47 +0000530 if ($4 > INT_MAX) {
531 pwarning(1, "64-bit value supplied for enum %s.\n", $2);
532 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000533 $$ = new t_enum_value($2, $4);
534 if ($1 != NULL) {
535 $$->set_doc($1);
536 }
Mark Sleed0767c52007-07-27 22:14:41 +0000537 if (g_parse_mode == PROGRAM) {
538 g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4)));
539 if (g_parent_scope != NULL) {
540 g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4)));
541 }
542 }
Mark Slee31985722006-05-24 21:45:31 +0000543 }
544|
David Reisscbd4bac2007-08-14 17:12:33 +0000545 CaptureDocText tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000546 {
Mark Slee30152872006-11-28 01:24:07 +0000547 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000548 $$ = new t_enum_value($2);
549 if ($1 != NULL) {
550 $$->set_doc($1);
551 }
Mark Slee30152872006-11-28 01:24:07 +0000552 }
553
Mark Slee6a47fed2007-02-07 02:40:59 +0000554Senum:
David Reisscdffe262007-08-14 17:12:31 +0000555 tok_senum tok_identifier '{' SenumDefList '}'
Mark Slee6a47fed2007-02-07 02:40:59 +0000556 {
557 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000558 $$ = new t_typedef(g_program, $4, $2);
Mark Slee6a47fed2007-02-07 02:40:59 +0000559 }
560
561SenumDefList:
562 SenumDefList SenumDef
563 {
564 pdebug("SenumDefList -> SenumDefList SenumDef");
565 $$ = $1;
566 $$->add_string_enum_val($2);
567 }
568|
569 {
570 pdebug("SenumDefList -> ");
571 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
572 $$->set_string_enum(true);
573 }
574
575SenumDef:
576 tok_literal CommaOrSemicolonOptional
577 {
578 pdebug("SenumDef -> tok_literal");
579 $$ = $1;
580 }
581
Mark Slee30152872006-11-28 01:24:07 +0000582Const:
583 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
584 {
585 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000586 if (g_parse_mode == PROGRAM) {
Bryan Duxbury2d804702009-12-18 19:41:11 +0000587 g_scope->resolve_const_value($5, $2);
Mark Sleeaa7671d2006-11-29 03:19:31 +0000588 $$ = new t_const($2, $3, $5);
589 validate_const_type($$);
Mark Sleed0767c52007-07-27 22:14:41 +0000590
591 g_scope->add_constant($3, $$);
592 if (g_parent_scope != NULL) {
593 g_parent_scope->add_constant(g_parent_prefix + $3, $$);
594 }
Mark Sleeaa7671d2006-11-29 03:19:31 +0000595 } else {
596 $$ = NULL;
597 }
Mark Slee30152872006-11-28 01:24:07 +0000598 }
599
600ConstValue:
601 tok_int_constant
602 {
603 pdebug("ConstValue => tok_int_constant");
604 $$ = new t_const_value();
605 $$->set_integer($1);
David Reissf1454162008-06-30 20:45:47 +0000606 if ($1 < INT32_MIN || $1 > INT32_MAX) {
607 pwarning(1, "64-bit constant \"%"PRIi64"\" may not work in all languages.\n", $1);
608 }
Mark Slee30152872006-11-28 01:24:07 +0000609 }
610| tok_dub_constant
611 {
612 pdebug("ConstValue => tok_dub_constant");
613 $$ = new t_const_value();
614 $$->set_double($1);
615 }
616| tok_literal
617 {
618 pdebug("ConstValue => tok_literal");
Mark Sleed0767c52007-07-27 22:14:41 +0000619 $$ = new t_const_value($1);
Mark Slee30152872006-11-28 01:24:07 +0000620 }
Mark Slee67fc6342006-11-29 03:37:04 +0000621| tok_identifier
622 {
623 pdebug("ConstValue => tok_identifier");
Bryan Duxbury2d804702009-12-18 19:41:11 +0000624 $$ = new t_const_value();
625 $$->set_identifier($1);
Mark Slee67fc6342006-11-29 03:37:04 +0000626 }
Mark Slee30152872006-11-28 01:24:07 +0000627| ConstList
628 {
629 pdebug("ConstValue => ConstList");
630 $$ = $1;
631 }
632| ConstMap
633 {
634 pdebug("ConstValue => ConstMap");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000635 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000636 }
637
638ConstList:
639 '[' ConstListContents ']'
640 {
641 pdebug("ConstList => [ ConstListContents ]");
642 $$ = $2;
643 }
644
645ConstListContents:
646 ConstListContents ConstValue CommaOrSemicolonOptional
647 {
648 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
649 $$ = $1;
650 $$->add_list($2);
651 }
652|
653 {
654 pdebug("ConstListContents =>");
655 $$ = new t_const_value();
656 $$->set_list();
657 }
658
659ConstMap:
660 '{' ConstMapContents '}'
661 {
662 pdebug("ConstMap => { ConstMapContents }");
663 $$ = $2;
664 }
665
666ConstMapContents:
667 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
668 {
669 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
670 $$ = $1;
671 $$->add_map($2, $4);
672 }
673|
674 {
675 pdebug("ConstMapContents =>");
676 $$ = new t_const_value();
677 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000678 }
679
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000680StructHead:
681 tok_struct
682 {
683 $$ = struct_is_struct;
684 }
685| tok_union
686 {
687 $$ = struct_is_union;
688 }
689
Mark Slee31985722006-05-24 21:45:31 +0000690Struct:
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000691 StructHead tok_identifier XsdAll '{' FieldList '}' TypeAnnotations
Mark Slee31985722006-05-24 21:45:31 +0000692 {
693 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
David Reisscdffe262007-08-14 17:12:31 +0000694 $5->set_xsd_all($3);
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000695 $5->set_union($1 == struct_is_union);
David Reisscdffe262007-08-14 17:12:31 +0000696 $$ = $5;
David Reissa2309992008-12-10 01:52:48 +0000697 $$->set_name($2);
698 if ($7 != NULL) {
699 $$->annotations_ = $7->annotations_;
700 delete $7;
701 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000702 }
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000703
Mark Slee36bfa2e2007-01-19 20:09:51 +0000704XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000705 tok_xsd_all
706 {
707 $$ = true;
708 }
709|
710 {
711 $$ = false;
712 }
713
Mark Slee36bfa2e2007-01-19 20:09:51 +0000714XsdOptional:
715 tok_xsd_optional
716 {
717 $$ = true;
718 }
719|
720 {
721 $$ = false;
722 }
723
Mark Slee7df0e2a2007-02-06 21:03:18 +0000724XsdNillable:
725 tok_xsd_nillable
726 {
727 $$ = true;
728 }
729|
730 {
731 $$ = false;
732 }
733
Mark Slee21135c32007-02-05 21:52:08 +0000734XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000735 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000736 {
Mark Slee748d83f2007-02-07 01:20:08 +0000737 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000738 }
739|
740 {
741 $$ = NULL;
742 }
743
Mark Slee9cb7c612006-09-01 22:17:45 +0000744Xception:
745 tok_xception tok_identifier '{' FieldList '}'
746 {
747 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
748 $4->set_name($2);
749 $4->set_xception(true);
750 $$ = $4;
Mark Slee31985722006-05-24 21:45:31 +0000751 }
752
753Service:
Mark Slee78165722007-09-10 22:08:49 +0000754 tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
Mark Slee31985722006-05-24 21:45:31 +0000755 {
756 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Slee78165722007-09-10 22:08:49 +0000757 $$ = $6;
David Reisscdffe262007-08-14 17:12:31 +0000758 $$->set_name($2);
759 $$->set_extends($3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000760 }
761
Mark Slee78165722007-09-10 22:08:49 +0000762FlagArgs:
763 {
764 g_arglist = 1;
765 }
766
767UnflagArgs:
768 {
769 g_arglist = 0;
770 }
771
Mark Slee36bfa2e2007-01-19 20:09:51 +0000772Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000773 tok_extends tok_identifier
774 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000775 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000776 $$ = NULL;
777 if (g_parse_mode == PROGRAM) {
778 $$ = g_scope->get_service($2);
779 if ($$ == NULL) {
780 yyerror("Service \"%s\" has not been defined.", $2);
781 exit(1);
782 }
783 }
784 }
785|
786 {
787 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000788 }
789
790FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000791 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000792 {
793 pdebug("FunctionList -> FunctionList Function");
794 $$ = $1;
795 $1->add_function($2);
796 }
797|
798 {
799 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000800 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000801 }
802
803Function:
David Reiss6985a422009-03-24 20:00:47 +0000804 CaptureDocText Oneway FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000805 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000806 $6->set_name(std::string($4) + "_args");
807 $$ = new t_function($3, $4, $6, $8, $2);
808 if ($1 != NULL) {
809 $$->set_doc($1);
810 }
Mark Slee31985722006-05-24 21:45:31 +0000811 }
812
David Reiss6985a422009-03-24 20:00:47 +0000813Oneway:
814 tok_oneway
Mark Slee31985722006-05-24 21:45:31 +0000815 {
Mark Slee52f643d2006-08-09 00:03:43 +0000816 $$ = true;
817 }
818|
819 {
820 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000821 }
822
Mark Slee36bfa2e2007-01-19 20:09:51 +0000823Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000824 tok_throws '(' FieldList ')'
825 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000826 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000827 $$ = $3;
Mark Sleef07d48e2008-02-01 01:36:26 +0000828 if (g_parse_mode == PROGRAM && !validate_throws($$)) {
Mark Slee91f2b7b2008-01-31 01:49:16 +0000829 yyerror("Throws clause may not contain non-exception types");
830 exit(1);
831 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000832 }
833|
834 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000835 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000836 }
837
Mark Slee31985722006-05-24 21:45:31 +0000838FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000839 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000840 {
841 pdebug("FieldList -> FieldList , Field");
842 $$ = $1;
Bryan Duxburyff219ac2009-04-10 21:51:00 +0000843 if (!($$->append($2))) {
Mark Slee6f9ac3f2007-11-28 22:28:13 +0000844 yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
845 exit(1);
846 }
Mark Slee31985722006-05-24 21:45:31 +0000847 }
848|
849 {
850 pdebug("FieldList -> ");
David Reiss00a8dd62009-03-19 08:14:12 +0000851 y_field_val = -1;
Mark Sleef0712dc2006-10-25 19:03:57 +0000852 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000853 }
854
855Field:
David Reiss8320a922007-08-14 19:59:26 +0000856 CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000857 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000858 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000859 if ($2 < 0) {
David Reissbb461362009-04-02 19:23:59 +0000860 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 +0000861 if (g_strict >= 192) {
862 yyerror("Implicit field keys are deprecated and not allowed with -strict");
863 exit(1);
864 }
Mark Slee31985722006-05-24 21:45:31 +0000865 }
David Reiss8320a922007-08-14 19:59:26 +0000866 $$ = new t_field($4, $5, $2);
867 $$->set_req($3);
868 if ($6 != NULL) {
Bryan Duxbury2d804702009-12-18 19:41:11 +0000869 g_scope->resolve_const_value($6, $4);
David Reiss8320a922007-08-14 19:59:26 +0000870 validate_field_value($$, $6);
871 $$->set_value($6);
Mark Slee7ff32452007-02-01 05:26:18 +0000872 }
David Reiss8320a922007-08-14 19:59:26 +0000873 $$->set_xsd_optional($7);
874 $$->set_xsd_nillable($8);
ccheeverf53b5cf2007-02-05 20:33:11 +0000875 if ($1 != NULL) {
876 $$->set_doc($1);
877 }
David Reiss8320a922007-08-14 19:59:26 +0000878 if ($9 != NULL) {
879 $$->set_xsd_attrs($9);
Mark Slee21135c32007-02-05 21:52:08 +0000880 }
Mark Slee31985722006-05-24 21:45:31 +0000881 }
Mark Slee7ff32452007-02-01 05:26:18 +0000882
883FieldIdentifier:
884 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000885 {
Mark Slee7ff32452007-02-01 05:26:18 +0000886 if ($1 <= 0) {
887 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
888 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000889 }
Mark Slee7ff32452007-02-01 05:26:18 +0000890 $$ = $1;
891 }
892|
893 {
894 $$ = y_field_val--;
895 }
896
David Reiss8320a922007-08-14 19:59:26 +0000897FieldRequiredness:
898 tok_required
899 {
David Reiss45603e92009-09-02 22:15:55 +0000900 $$ = t_field::T_REQUIRED;
David Reiss8320a922007-08-14 19:59:26 +0000901 }
902| tok_optional
903 {
Mark Slee78165722007-09-10 22:08:49 +0000904 if (g_arglist) {
905 if (g_parse_mode == PROGRAM) {
906 pwarning(1, "optional keyword is ignored in argument lists.\n");
907 }
David Reiss204420f2008-01-11 20:59:03 +0000908 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000909 } else {
David Reiss204420f2008-01-11 20:59:03 +0000910 $$ = t_field::T_OPTIONAL;
Mark Slee78165722007-09-10 22:08:49 +0000911 }
David Reiss8320a922007-08-14 19:59:26 +0000912 }
913|
914 {
David Reiss204420f2008-01-11 20:59:03 +0000915 $$ = t_field::T_OPT_IN_REQ_OUT;
David Reiss8320a922007-08-14 19:59:26 +0000916 }
917
Mark Slee7ff32452007-02-01 05:26:18 +0000918FieldValue:
919 '=' ConstValue
920 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000921 if (g_parse_mode == PROGRAM) {
Mark Slee7ff32452007-02-01 05:26:18 +0000922 $$ = $2;
923 } else {
924 $$ = NULL;
925 }
926 }
927|
928 {
929 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000930 }
Mark Slee31985722006-05-24 21:45:31 +0000931
932DefinitionType:
933 BaseType
934 {
935 pdebug("DefinitionType -> BaseType");
936 $$ = $1;
937 }
Mark Sleee8540632006-05-30 09:24:40 +0000938| ContainerType
939 {
940 pdebug("DefinitionType -> ContainerType");
941 $$ = $1;
942 }
Mark Slee31985722006-05-24 21:45:31 +0000943
944FunctionType:
945 FieldType
946 {
Mark Sleee8540632006-05-30 09:24:40 +0000947 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000948 $$ = $1;
949 }
950| tok_void
951 {
Mark Sleee8540632006-05-30 09:24:40 +0000952 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000953 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000954 }
955
956FieldType:
957 tok_identifier
958 {
Mark Sleee8540632006-05-30 09:24:40 +0000959 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000960 if (g_parse_mode == INCLUDES) {
961 // Ignore identifiers in include mode
962 $$ = NULL;
963 } else {
964 // Lookup the identifier in the current scope
965 $$ = g_scope->get_type($1);
966 if ($$ == NULL) {
967 yyerror("Type \"%s\" has not been defined.", $1);
968 exit(1);
969 }
Mark Sleee8540632006-05-30 09:24:40 +0000970 }
Mark Slee31985722006-05-24 21:45:31 +0000971 }
972| BaseType
973 {
Mark Sleee8540632006-05-30 09:24:40 +0000974 pdebug("FieldType -> BaseType");
975 $$ = $1;
976 }
977| ContainerType
978 {
979 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000980 $$ = $1;
981 }
982
David Reissc8e30052009-07-27 17:02:42 +0000983BaseType: SimpleBaseType TypeAnnotations
984 {
985 pdebug("BaseType -> SimpleBaseType TypeAnnotations");
986 if ($2 != NULL) {
987 $$ = new t_base_type(*static_cast<t_base_type*>($1));
988 $$->annotations_ = $2->annotations_;
989 delete $2;
990 } else {
991 $$ = $1;
992 }
993 }
994
995SimpleBaseType:
Mark Slee31985722006-05-24 21:45:31 +0000996 tok_string
997 {
998 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000999 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +00001000 }
Mark Slee8d725a22007-04-13 01:57:12 +00001001| tok_binary
1002 {
1003 pdebug("BaseType -> tok_binary");
1004 $$ = g_type_binary;
1005 }
Mark Sleeb6200d82007-01-19 19:14:36 +00001006| tok_slist
1007 {
1008 pdebug("BaseType -> tok_slist");
1009 $$ = g_type_slist;
1010 }
Mark Slee78f58e22006-09-02 04:17:07 +00001011| tok_bool
1012 {
1013 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +00001014 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +00001015 }
Mark Slee31985722006-05-24 21:45:31 +00001016| tok_byte
1017 {
1018 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +00001019 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +00001020 }
Mark Slee9cb7c612006-09-01 22:17:45 +00001021| tok_i16
1022 {
1023 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +00001024 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +00001025 }
Mark Slee31985722006-05-24 21:45:31 +00001026| tok_i32
1027 {
1028 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +00001029 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +00001030 }
Mark Slee31985722006-05-24 21:45:31 +00001031| tok_i64
1032 {
1033 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +00001034 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +00001035 }
Mark Sleec98d0502006-09-06 02:42:25 +00001036| tok_double
1037 {
1038 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +00001039 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +00001040 }
Mark Slee31985722006-05-24 21:45:31 +00001041
David Reissa2309992008-12-10 01:52:48 +00001042ContainerType: SimpleContainerType TypeAnnotations
1043 {
1044 pdebug("ContainerType -> SimpleContainerType TypeAnnotations");
1045 $$ = $1;
1046 if ($2 != NULL) {
1047 $$->annotations_ = $2->annotations_;
1048 delete $2;
1049 }
1050 }
1051
1052SimpleContainerType:
Mark Sleee8540632006-05-30 09:24:40 +00001053 MapType
1054 {
David Reissa2309992008-12-10 01:52:48 +00001055 pdebug("SimpleContainerType -> MapType");
Mark Sleee8540632006-05-30 09:24:40 +00001056 $$ = $1;
1057 }
1058| SetType
1059 {
David Reissa2309992008-12-10 01:52:48 +00001060 pdebug("SimpleContainerType -> SetType");
Mark Sleee8540632006-05-30 09:24:40 +00001061 $$ = $1;
1062 }
1063| ListType
1064 {
David Reissa2309992008-12-10 01:52:48 +00001065 pdebug("SimpleContainerType -> ListType");
Mark Sleee8540632006-05-30 09:24:40 +00001066 $$ = $1;
1067 }
1068
1069MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001070 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001071 {
1072 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001073 $$ = new t_map($4, $6);
1074 if ($2 != NULL) {
1075 ((t_container*)$$)->set_cpp_name(std::string($2));
1076 }
Mark Sleee8540632006-05-30 09:24:40 +00001077 }
1078
1079SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001080 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001081 {
1082 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001083 $$ = new t_set($4);
1084 if ($2 != NULL) {
1085 ((t_container*)$$)->set_cpp_name(std::string($2));
1086 }
Mark Sleee8540632006-05-30 09:24:40 +00001087 }
1088
1089ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001090 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +00001091 {
1092 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +00001093 $$ = new t_list($3);
1094 if ($5 != NULL) {
1095 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +00001096 }
1097 }
1098
Mark Slee36bfa2e2007-01-19 20:09:51 +00001099CppType:
Mark Sleeafc76542007-02-09 21:55:44 +00001100 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +00001101 {
Mark Sleeafc76542007-02-09 21:55:44 +00001102 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +00001103 }
1104|
1105 {
1106 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +00001107 }
1108
David Reissa2309992008-12-10 01:52:48 +00001109TypeAnnotations:
1110 '(' TypeAnnotationList ')'
1111 {
1112 pdebug("TypeAnnotations -> ( TypeAnnotationList )");
1113 $$ = $2;
1114 }
1115|
1116 {
1117 $$ = NULL;
1118 }
1119
1120TypeAnnotationList:
1121 TypeAnnotationList TypeAnnotation
1122 {
1123 pdebug("TypeAnnotationList -> TypeAnnotationList , TypeAnnotation");
1124 $$ = $1;
1125 $$->annotations_[$2->key] = $2->val;
1126 delete $2;
1127 }
1128|
1129 {
1130 /* Just use a dummy structure to hold the annotations. */
1131 $$ = new t_struct(g_program);
1132 }
1133
1134TypeAnnotation:
1135 tok_identifier '=' tok_literal CommaOrSemicolonOptional
1136 {
1137 pdebug("TypeAnnotation -> tok_identifier = tok_literal");
1138 $$ = new t_annotation;
1139 $$->key = $1;
1140 $$->val = $3;
1141 }
1142
Todd Lipcon53ae9f32009-12-07 00:42:38 +00001143%%