blob: cdedee07ffb557c4cbd3cc8edf53f1ce5c235bf1 [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
Mark Slee31985722006-05-24 21:45:31 +0000171
David Reissa2309992008-12-10 01:52:48 +0000172%type<ttype> TypeAnnotations
173%type<ttype> TypeAnnotationList
174%type<tannot> TypeAnnotation
175
Mark Slee31985722006-05-24 21:45:31 +0000176%type<tfield> Field
Mark Slee7ff32452007-02-01 05:26:18 +0000177%type<iconst> FieldIdentifier
David Reiss8320a922007-08-14 19:59:26 +0000178%type<ereq> FieldRequiredness
Mark Slee31985722006-05-24 21:45:31 +0000179%type<ttype> FieldType
Mark Slee7ff32452007-02-01 05:26:18 +0000180%type<tconstv> FieldValue
Mark Sleee8540632006-05-30 09:24:40 +0000181%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000182
183%type<tenum> Enum
184%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000185%type<tenumv> EnumDef
186
Mark Slee6a47fed2007-02-07 02:40:59 +0000187%type<ttypedef> Senum
188%type<tbase> SenumDefList
189%type<id> SenumDef
190
Mark Slee30152872006-11-28 01:24:07 +0000191%type<tconst> Const
192%type<tconstv> ConstValue
193%type<tconstv> ConstList
194%type<tconstv> ConstListContents
195%type<tconstv> ConstMap
196%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000197
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000198%type<iconst> StructHead
Mark Slee31985722006-05-24 21:45:31 +0000199%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000200%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000201%type<tservice> Service
202
203%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000204%type<ttype> FunctionType
205%type<tservice> FunctionList
206
Mark Slee36bfa2e2007-01-19 20:09:51 +0000207%type<tstruct> Throws
208%type<tservice> Extends
David Reiss6985a422009-03-24 20:00:47 +0000209%type<tbool> Oneway
Mark Slee36bfa2e2007-01-19 20:09:51 +0000210%type<tbool> XsdAll
211%type<tbool> XsdOptional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000212%type<tbool> XsdNillable
Mark Slee748d83f2007-02-07 01:20:08 +0000213%type<tstruct> XsdAttributes
Mark Slee36bfa2e2007-01-19 20:09:51 +0000214%type<id> CppType
Mark Slee52f643d2006-08-09 00:03:43 +0000215
David Reisscbd4bac2007-08-14 17:12:33 +0000216%type<dtext> CaptureDocText
ccheeverf53b5cf2007-02-05 20:33:11 +0000217
Mark Slee31985722006-05-24 21:45:31 +0000218%%
219
Mark Sleef5377b32006-10-10 01:42:59 +0000220/**
221 * Thrift Grammar Implementation.
222 *
223 * For the most part this source file works its way top down from what you
224 * might expect to find in a typical .thrift file, i.e. type definitions and
225 * namespaces up top followed by service definitions using those types.
226 */
Mark Slee31985722006-05-24 21:45:31 +0000227
228Program:
David Reisscbd4bac2007-08-14 17:12:33 +0000229 HeaderList DefinitionList
Mark Sleef0712dc2006-10-25 19:03:57 +0000230 {
231 pdebug("Program -> Headers DefinitionList");
David Reisscbd4bac2007-08-14 17:12:33 +0000232 /*
233 TODO(dreiss): Decide whether full-program doctext is worth the trouble.
David Reissc2532a92007-07-30 23:46:11 +0000234 if ($1 != NULL) {
235 g_program->set_doc($1);
236 }
David Reisscbd4bac2007-08-14 17:12:33 +0000237 */
238 clear_doctext();
Mark Sleef0712dc2006-10-25 19:03:57 +0000239 }
240
David Reisscbd4bac2007-08-14 17:12:33 +0000241CaptureDocText:
242 {
243 if (g_parse_mode == PROGRAM) {
Mark Sleebd588222007-11-21 08:43:35 +0000244 $$ = g_doctext;
David Reisscbd4bac2007-08-14 17:12:33 +0000245 g_doctext = NULL;
Mark Slee27ed6ec2007-08-16 01:26:31 +0000246 } else {
David Reisscbd4bac2007-08-14 17:12:33 +0000247 $$ = NULL;
248 }
249 }
250
251/* TODO(dreiss): Try to DestroyDocText in all sorts or random places. */
252DestroyDocText:
253 {
254 if (g_parse_mode == PROGRAM) {
255 clear_doctext();
256 }
257 }
258
259/* We have to DestroyDocText here, otherwise it catches the doctext
260 on the first real element. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000261HeaderList:
David Reisscbd4bac2007-08-14 17:12:33 +0000262 HeaderList DestroyDocText Header
Mark Sleef0712dc2006-10-25 19:03:57 +0000263 {
264 pdebug("HeaderList -> HeaderList Header");
265 }
266|
267 {
268 pdebug("HeaderList -> ");
269 }
270
271Header:
272 Include
273 {
274 pdebug("Header -> Include");
275 }
David Reiss79eca142008-02-27 01:55:13 +0000276| tok_namespace tok_identifier tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +0000277 {
David Reiss79eca142008-02-27 01:55:13 +0000278 pdebug("Header -> tok_namespace tok_identifier tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000279 if (g_parse_mode == PROGRAM) {
David Reiss79eca142008-02-27 01:55:13 +0000280 g_program->set_namespace($2, $3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000281 }
282 }
David Reissfb790d72010-09-02 16:41:45 +0000283| tok_namespace '*' tok_identifier
284 {
285 pdebug("Header -> tok_namespace * tok_identifier");
286 if (g_parse_mode == PROGRAM) {
287 g_program->set_namespace("*", $3);
288 }
289 }
David Reiss9a08dc62008-02-27 01:55:17 +0000290/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000291| tok_cpp_namespace tok_identifier
292 {
David Reiss9a08dc62008-02-27 01:55:17 +0000293 pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000294 pdebug("Header -> tok_cpp_namespace tok_identifier");
295 if (g_parse_mode == PROGRAM) {
David Reiss9a08dc62008-02-27 01:55:17 +0000296 g_program->set_namespace("cpp", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000297 }
298 }
299| tok_cpp_include tok_literal
300 {
301 pdebug("Header -> tok_cpp_include tok_literal");
302 if (g_parse_mode == PROGRAM) {
303 g_program->add_cpp_include($2);
304 }
305 }
Mark Sleee888b372007-01-12 01:06:24 +0000306| tok_php_namespace tok_identifier
307 {
David Reiss554ea6f2009-02-17 20:28:37 +0000308 pwarning(1, "'php_namespace' is deprecated. Use 'namespace php' instead");
Mark Sleee888b372007-01-12 01:06:24 +0000309 pdebug("Header -> tok_php_namespace tok_identifier");
310 if (g_parse_mode == PROGRAM) {
David Reiss554ea6f2009-02-17 20:28:37 +0000311 g_program->set_namespace("php", $2);
Mark Sleee888b372007-01-12 01:06:24 +0000312 }
313 }
David Reiss320e45c2008-03-27 21:41:54 +0000314/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reissc6fc3292007-08-30 00:58:43 +0000315| tok_py_module tok_identifier
316 {
David Reiss320e45c2008-03-27 21:41:54 +0000317 pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead");
David Reissc6fc3292007-08-30 00:58:43 +0000318 pdebug("Header -> tok_py_module tok_identifier");
319 if (g_parse_mode == PROGRAM) {
David Reiss320e45c2008-03-27 21:41:54 +0000320 g_program->set_namespace("py", $2);
David Reissc6fc3292007-08-30 00:58:43 +0000321 }
322 }
David Reiss07ef3a92008-03-27 21:42:39 +0000323/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee27ed6ec2007-08-16 01:26:31 +0000324| tok_perl_package tok_identifier
325 {
David Reiss07ef3a92008-03-27 21:42:39 +0000326 pwarning(1, "'perl_package' is deprecated. Use 'namespace perl' instead");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000327 pdebug("Header -> tok_perl_namespace tok_identifier");
328 if (g_parse_mode == PROGRAM) {
David Reiss07ef3a92008-03-27 21:42:39 +0000329 g_program->set_namespace("perl", $2);
Mark Slee27ed6ec2007-08-16 01:26:31 +0000330 }
331 }
David Reiss6a4b82c2008-03-27 21:42:16 +0000332/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee58dfb4f2007-07-06 02:45:25 +0000333| tok_ruby_namespace tok_identifier
334 {
David Reiss6a4b82c2008-03-27 21:42:16 +0000335 pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead");
Mark Slee58dfb4f2007-07-06 02:45:25 +0000336 pdebug("Header -> tok_ruby_namespace tok_identifier");
337 if (g_parse_mode == PROGRAM) {
David Reiss6a4b82c2008-03-27 21:42:16 +0000338 g_program->set_namespace("rb", $2);
Mark Slee58dfb4f2007-07-06 02:45:25 +0000339 }
340 }
David Reiss3b455012008-03-27 21:40:46 +0000341/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleebd588222007-11-21 08:43:35 +0000342| tok_smalltalk_category tok_st_identifier
343 {
David Reiss3b455012008-03-27 21:40:46 +0000344 pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
Mark Sleebd588222007-11-21 08:43:35 +0000345 pdebug("Header -> tok_smalltalk_category tok_st_identifier");
346 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000347 g_program->set_namespace("smalltalk.category", $2);
Mark Sleebd588222007-11-21 08:43:35 +0000348 }
349 }
David Reiss3b455012008-03-27 21:40:46 +0000350/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss15457c92007-12-14 07:03:03 +0000351| tok_smalltalk_prefix tok_identifier
352 {
David Reiss3b455012008-03-27 21:40:46 +0000353 pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
David Reiss15457c92007-12-14 07:03:03 +0000354 pdebug("Header -> tok_smalltalk_prefix tok_identifier");
355 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000356 g_program->set_namespace("smalltalk.prefix", $2);
David Reiss15457c92007-12-14 07:03:03 +0000357 }
358 }
David Reiss771f8c72008-02-27 01:55:25 +0000359/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000360| tok_java_package tok_identifier
361 {
David Reiss9f646152008-03-02 21:59:48 +0000362 pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000363 pdebug("Header -> tok_java_package tok_identifier");
364 if (g_parse_mode == PROGRAM) {
David Reiss771f8c72008-02-27 01:55:25 +0000365 g_program->set_namespace("java", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000366 }
367 }
David Reiss54b602b2008-03-27 21:41:06 +0000368/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee7e9eea42007-09-10 21:00:23 +0000369| tok_cocoa_prefix tok_identifier
370 {
David Reiss54b602b2008-03-27 21:41:06 +0000371 pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
Mark Slee7e9eea42007-09-10 21:00:23 +0000372 pdebug("Header -> tok_cocoa_prefix tok_identifier");
373 if (g_parse_mode == PROGRAM) {
David Reiss54b602b2008-03-27 21:41:06 +0000374 g_program->set_namespace("cocoa", $2);
Mark Slee7e9eea42007-09-10 21:00:23 +0000375 }
376 }
David Reiss92e10d82009-02-17 20:28:19 +0000377/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee0d9199e2007-01-31 02:08:30 +0000378| tok_xsd_namespace tok_literal
379 {
David Reiss92e10d82009-02-17 20:28:19 +0000380 pwarning(1, "'xsd_namespace' is deprecated. Use 'namespace xsd' instead");
Mark Slee0d9199e2007-01-31 02:08:30 +0000381 pdebug("Header -> tok_xsd_namespace tok_literal");
382 if (g_parse_mode == PROGRAM) {
David Reiss92e10d82009-02-17 20:28:19 +0000383 g_program->set_namespace("cocoa", $2);
Mark Slee0d9199e2007-01-31 02:08:30 +0000384 }
385 }
David Reiss9d65bf02008-03-27 21:41:37 +0000386/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss7f42bcf2008-01-11 20:59:12 +0000387| tok_csharp_namespace tok_identifier
388 {
David Reiss9d65bf02008-03-27 21:41:37 +0000389 pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead");
David Reiss919ae802008-03-27 21:41:11 +0000390 pdebug("Header -> tok_csharp_namespace tok_identifier");
David Reiss7f42bcf2008-01-11 20:59:12 +0000391 if (g_parse_mode == PROGRAM) {
David Reiss9d65bf02008-03-27 21:41:37 +0000392 g_program->set_namespace("csharp", $2);
David Reiss7f42bcf2008-01-11 20:59:12 +0000393 }
394 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000395
396Include:
397 tok_include tok_literal
398 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000399 pdebug("Include -> tok_include tok_literal");
Mark Sleef0712dc2006-10-25 19:03:57 +0000400 if (g_parse_mode == INCLUDES) {
401 std::string path = include_file(std::string($2));
402 if (!path.empty()) {
kholst76f2c882008-01-16 02:47:41 +0000403 g_program->add_include(path, std::string($2));
Mark Sleef0712dc2006-10-25 19:03:57 +0000404 }
405 }
406 }
Mark Slee31985722006-05-24 21:45:31 +0000407
408DefinitionList:
David Reisscbd4bac2007-08-14 17:12:33 +0000409 DefinitionList CaptureDocText Definition
Mark Slee31985722006-05-24 21:45:31 +0000410 {
411 pdebug("DefinitionList -> DefinitionList Definition");
David Reisscdffe262007-08-14 17:12:31 +0000412 if ($2 != NULL && $3 != NULL) {
413 $3->set_doc($2);
414 }
Mark Slee31985722006-05-24 21:45:31 +0000415 }
416|
417 {
418 pdebug("DefinitionList -> ");
419 }
420
421Definition:
Mark Slee30152872006-11-28 01:24:07 +0000422 Const
423 {
424 pdebug("Definition -> Const");
425 if (g_parse_mode == PROGRAM) {
426 g_program->add_const($1);
Mark Sleebd588222007-11-21 08:43:35 +0000427 }
David Reisscdffe262007-08-14 17:12:31 +0000428 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000429 }
430| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000431 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000432 pdebug("Definition -> TypeDefinition");
433 if (g_parse_mode == PROGRAM) {
434 g_scope->add_type($1->get_name(), $1);
435 if (g_parent_scope != NULL) {
436 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
437 }
438 }
David Reisscdffe262007-08-14 17:12:31 +0000439 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000440 }
Mark Slee31985722006-05-24 21:45:31 +0000441| Service
442 {
443 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000444 if (g_parse_mode == PROGRAM) {
445 g_scope->add_service($1->get_name(), $1);
446 if (g_parent_scope != NULL) {
447 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
448 }
449 g_program->add_service($1);
450 }
David Reisscdffe262007-08-14 17:12:31 +0000451 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000452 }
453
Mark Sleef0712dc2006-10-25 19:03:57 +0000454TypeDefinition:
455 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000456 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000457 pdebug("TypeDefinition -> Typedef");
458 if (g_parse_mode == PROGRAM) {
459 g_program->add_typedef($1);
460 }
461 }
462| Enum
463 {
464 pdebug("TypeDefinition -> Enum");
465 if (g_parse_mode == PROGRAM) {
466 g_program->add_enum($1);
467 }
468 }
Mark Slee6a47fed2007-02-07 02:40:59 +0000469| Senum
470 {
471 pdebug("TypeDefinition -> Senum");
472 if (g_parse_mode == PROGRAM) {
473 g_program->add_typedef($1);
474 }
475 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000476| Struct
477 {
478 pdebug("TypeDefinition -> Struct");
479 if (g_parse_mode == PROGRAM) {
480 g_program->add_struct($1);
481 }
482 }
483| Xception
Mark Slee27ed6ec2007-08-16 01:26:31 +0000484 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000485 pdebug("TypeDefinition -> Xception");
486 if (g_parse_mode == PROGRAM) {
487 g_program->add_xception($1);
488 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000489 }
Mark Slee31985722006-05-24 21:45:31 +0000490
491Typedef:
David Reiss4dd78012010-03-09 05:19:08 +0000492 tok_typedef FieldType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000493 {
David Reiss4dd78012010-03-09 05:19:08 +0000494 pdebug("TypeDef -> tok_typedef FieldType tok_identifier");
David Reisscdffe262007-08-14 17:12:31 +0000495 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000496 $$ = td;
497 }
498
Mark Slee6a47fed2007-02-07 02:40:59 +0000499CommaOrSemicolonOptional:
500 ','
501 {}
502| ';'
503 {}
504|
505 {}
ccheeverf53b5cf2007-02-05 20:33:11 +0000506
Mark Slee31985722006-05-24 21:45:31 +0000507Enum:
David Reisscdffe262007-08-14 17:12:31 +0000508 tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000509 {
510 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000511 $$ = $4;
512 $$->set_name($2);
Bryan Duxbury2d804702009-12-18 19:41:11 +0000513 $$->resolve_values();
Mark Slee31985722006-05-24 21:45:31 +0000514 }
515
516EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000517 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000518 {
519 pdebug("EnumDefList -> EnumDefList EnumDef");
520 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000521 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000522 }
523|
524 {
525 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000526 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000527 }
528
529EnumDef:
David Reisscbd4bac2007-08-14 17:12:33 +0000530 CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000531 {
Mark Slee30152872006-11-28 01:24:07 +0000532 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000533 if ($4 < 0) {
534 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000535 }
David Reissf1454162008-06-30 20:45:47 +0000536 if ($4 > INT_MAX) {
537 pwarning(1, "64-bit value supplied for enum %s.\n", $2);
538 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000539 $$ = new t_enum_value($2, $4);
540 if ($1 != NULL) {
541 $$->set_doc($1);
542 }
Mark Sleed0767c52007-07-27 22:14:41 +0000543 if (g_parse_mode == PROGRAM) {
544 g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4)));
545 if (g_parent_scope != NULL) {
546 g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4)));
547 }
548 }
Mark Slee31985722006-05-24 21:45:31 +0000549 }
550|
David Reisscbd4bac2007-08-14 17:12:33 +0000551 CaptureDocText tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000552 {
Mark Slee30152872006-11-28 01:24:07 +0000553 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000554 $$ = new t_enum_value($2);
555 if ($1 != NULL) {
556 $$->set_doc($1);
557 }
Mark Slee30152872006-11-28 01:24:07 +0000558 }
559
Mark Slee6a47fed2007-02-07 02:40:59 +0000560Senum:
David Reisscdffe262007-08-14 17:12:31 +0000561 tok_senum tok_identifier '{' SenumDefList '}'
Mark Slee6a47fed2007-02-07 02:40:59 +0000562 {
563 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000564 $$ = new t_typedef(g_program, $4, $2);
Mark Slee6a47fed2007-02-07 02:40:59 +0000565 }
566
567SenumDefList:
568 SenumDefList SenumDef
569 {
570 pdebug("SenumDefList -> SenumDefList SenumDef");
571 $$ = $1;
572 $$->add_string_enum_val($2);
573 }
574|
575 {
576 pdebug("SenumDefList -> ");
577 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
578 $$->set_string_enum(true);
579 }
580
581SenumDef:
582 tok_literal CommaOrSemicolonOptional
583 {
584 pdebug("SenumDef -> tok_literal");
585 $$ = $1;
586 }
587
Mark Slee30152872006-11-28 01:24:07 +0000588Const:
589 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
590 {
591 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000592 if (g_parse_mode == PROGRAM) {
Bryan Duxbury2d804702009-12-18 19:41:11 +0000593 g_scope->resolve_const_value($5, $2);
Mark Sleeaa7671d2006-11-29 03:19:31 +0000594 $$ = new t_const($2, $3, $5);
595 validate_const_type($$);
Mark Sleed0767c52007-07-27 22:14:41 +0000596
597 g_scope->add_constant($3, $$);
598 if (g_parent_scope != NULL) {
599 g_parent_scope->add_constant(g_parent_prefix + $3, $$);
600 }
Mark Sleeaa7671d2006-11-29 03:19:31 +0000601 } else {
602 $$ = NULL;
603 }
Mark Slee30152872006-11-28 01:24:07 +0000604 }
605
606ConstValue:
607 tok_int_constant
608 {
609 pdebug("ConstValue => tok_int_constant");
610 $$ = new t_const_value();
611 $$->set_integer($1);
David Reissf1454162008-06-30 20:45:47 +0000612 if ($1 < INT32_MIN || $1 > INT32_MAX) {
613 pwarning(1, "64-bit constant \"%"PRIi64"\" may not work in all languages.\n", $1);
614 }
Mark Slee30152872006-11-28 01:24:07 +0000615 }
616| tok_dub_constant
617 {
618 pdebug("ConstValue => tok_dub_constant");
619 $$ = new t_const_value();
620 $$->set_double($1);
621 }
622| tok_literal
623 {
624 pdebug("ConstValue => tok_literal");
Mark Sleed0767c52007-07-27 22:14:41 +0000625 $$ = new t_const_value($1);
Mark Slee30152872006-11-28 01:24:07 +0000626 }
Mark Slee67fc6342006-11-29 03:37:04 +0000627| tok_identifier
628 {
629 pdebug("ConstValue => tok_identifier");
Bryan Duxbury2d804702009-12-18 19:41:11 +0000630 $$ = new t_const_value();
631 $$->set_identifier($1);
Mark Slee67fc6342006-11-29 03:37:04 +0000632 }
Mark Slee30152872006-11-28 01:24:07 +0000633| ConstList
634 {
635 pdebug("ConstValue => ConstList");
636 $$ = $1;
637 }
638| ConstMap
639 {
640 pdebug("ConstValue => ConstMap");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000641 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000642 }
643
644ConstList:
645 '[' ConstListContents ']'
646 {
647 pdebug("ConstList => [ ConstListContents ]");
648 $$ = $2;
649 }
650
651ConstListContents:
652 ConstListContents ConstValue CommaOrSemicolonOptional
653 {
654 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
655 $$ = $1;
656 $$->add_list($2);
657 }
658|
659 {
660 pdebug("ConstListContents =>");
661 $$ = new t_const_value();
662 $$->set_list();
663 }
664
665ConstMap:
666 '{' ConstMapContents '}'
667 {
668 pdebug("ConstMap => { ConstMapContents }");
669 $$ = $2;
670 }
671
672ConstMapContents:
673 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
674 {
675 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
676 $$ = $1;
677 $$->add_map($2, $4);
678 }
679|
680 {
681 pdebug("ConstMapContents =>");
682 $$ = new t_const_value();
683 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000684 }
685
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000686StructHead:
687 tok_struct
688 {
689 $$ = struct_is_struct;
690 }
691| tok_union
692 {
693 $$ = struct_is_union;
694 }
695
Mark Slee31985722006-05-24 21:45:31 +0000696Struct:
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000697 StructHead tok_identifier XsdAll '{' FieldList '}' TypeAnnotations
Mark Slee31985722006-05-24 21:45:31 +0000698 {
699 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
David Reisscdffe262007-08-14 17:12:31 +0000700 $5->set_xsd_all($3);
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000701 $5->set_union($1 == struct_is_union);
David Reisscdffe262007-08-14 17:12:31 +0000702 $$ = $5;
David Reissa2309992008-12-10 01:52:48 +0000703 $$->set_name($2);
704 if ($7 != NULL) {
705 $$->annotations_ = $7->annotations_;
706 delete $7;
707 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000708 }
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000709
Mark Slee36bfa2e2007-01-19 20:09:51 +0000710XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000711 tok_xsd_all
712 {
713 $$ = true;
714 }
715|
716 {
717 $$ = false;
718 }
719
Mark Slee36bfa2e2007-01-19 20:09:51 +0000720XsdOptional:
721 tok_xsd_optional
722 {
723 $$ = true;
724 }
725|
726 {
727 $$ = false;
728 }
729
Mark Slee7df0e2a2007-02-06 21:03:18 +0000730XsdNillable:
731 tok_xsd_nillable
732 {
733 $$ = true;
734 }
735|
736 {
737 $$ = false;
738 }
739
Mark Slee21135c32007-02-05 21:52:08 +0000740XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000741 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000742 {
Mark Slee748d83f2007-02-07 01:20:08 +0000743 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000744 }
745|
746 {
747 $$ = NULL;
748 }
749
Mark Slee9cb7c612006-09-01 22:17:45 +0000750Xception:
751 tok_xception tok_identifier '{' FieldList '}'
752 {
753 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
754 $4->set_name($2);
755 $4->set_xception(true);
756 $$ = $4;
Mark Slee31985722006-05-24 21:45:31 +0000757 }
758
759Service:
Mark Slee78165722007-09-10 22:08:49 +0000760 tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
Mark Slee31985722006-05-24 21:45:31 +0000761 {
762 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Slee78165722007-09-10 22:08:49 +0000763 $$ = $6;
David Reisscdffe262007-08-14 17:12:31 +0000764 $$->set_name($2);
765 $$->set_extends($3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000766 }
767
Mark Slee78165722007-09-10 22:08:49 +0000768FlagArgs:
769 {
770 g_arglist = 1;
771 }
772
773UnflagArgs:
774 {
775 g_arglist = 0;
776 }
777
Mark Slee36bfa2e2007-01-19 20:09:51 +0000778Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000779 tok_extends tok_identifier
780 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000781 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000782 $$ = NULL;
783 if (g_parse_mode == PROGRAM) {
784 $$ = g_scope->get_service($2);
785 if ($$ == NULL) {
786 yyerror("Service \"%s\" has not been defined.", $2);
787 exit(1);
788 }
789 }
790 }
791|
792 {
793 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000794 }
795
796FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000797 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000798 {
799 pdebug("FunctionList -> FunctionList Function");
800 $$ = $1;
801 $1->add_function($2);
802 }
803|
804 {
805 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000806 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000807 }
808
809Function:
David Reiss6985a422009-03-24 20:00:47 +0000810 CaptureDocText Oneway FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000811 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000812 $6->set_name(std::string($4) + "_args");
813 $$ = new t_function($3, $4, $6, $8, $2);
814 if ($1 != NULL) {
815 $$->set_doc($1);
816 }
Mark Slee31985722006-05-24 21:45:31 +0000817 }
818
David Reiss6985a422009-03-24 20:00:47 +0000819Oneway:
820 tok_oneway
Mark Slee31985722006-05-24 21:45:31 +0000821 {
Mark Slee52f643d2006-08-09 00:03:43 +0000822 $$ = true;
823 }
824|
825 {
826 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000827 }
828
Mark Slee36bfa2e2007-01-19 20:09:51 +0000829Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000830 tok_throws '(' FieldList ')'
831 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000832 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000833 $$ = $3;
Mark Sleef07d48e2008-02-01 01:36:26 +0000834 if (g_parse_mode == PROGRAM && !validate_throws($$)) {
Mark Slee91f2b7b2008-01-31 01:49:16 +0000835 yyerror("Throws clause may not contain non-exception types");
836 exit(1);
837 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000838 }
839|
840 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000841 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000842 }
843
Mark Slee31985722006-05-24 21:45:31 +0000844FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000845 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000846 {
847 pdebug("FieldList -> FieldList , Field");
848 $$ = $1;
Bryan Duxburyff219ac2009-04-10 21:51:00 +0000849 if (!($$->append($2))) {
Mark Slee6f9ac3f2007-11-28 22:28:13 +0000850 yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
851 exit(1);
852 }
Mark Slee31985722006-05-24 21:45:31 +0000853 }
854|
855 {
856 pdebug("FieldList -> ");
David Reiss00a8dd62009-03-19 08:14:12 +0000857 y_field_val = -1;
Mark Sleef0712dc2006-10-25 19:03:57 +0000858 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000859 }
860
861Field:
David Reiss53c10e02010-03-05 07:51:51 +0000862 CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes TypeAnnotations CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000863 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000864 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000865 if ($2 < 0) {
David Reissbb461362009-04-02 19:23:59 +0000866 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 +0000867 if (g_strict >= 192) {
868 yyerror("Implicit field keys are deprecated and not allowed with -strict");
869 exit(1);
870 }
Mark Slee31985722006-05-24 21:45:31 +0000871 }
David Reiss8320a922007-08-14 19:59:26 +0000872 $$ = new t_field($4, $5, $2);
873 $$->set_req($3);
874 if ($6 != NULL) {
Bryan Duxbury2d804702009-12-18 19:41:11 +0000875 g_scope->resolve_const_value($6, $4);
David Reiss8320a922007-08-14 19:59:26 +0000876 validate_field_value($$, $6);
877 $$->set_value($6);
Mark Slee7ff32452007-02-01 05:26:18 +0000878 }
David Reiss8320a922007-08-14 19:59:26 +0000879 $$->set_xsd_optional($7);
880 $$->set_xsd_nillable($8);
ccheeverf53b5cf2007-02-05 20:33:11 +0000881 if ($1 != NULL) {
882 $$->set_doc($1);
883 }
David Reiss8320a922007-08-14 19:59:26 +0000884 if ($9 != NULL) {
885 $$->set_xsd_attrs($9);
Mark Slee21135c32007-02-05 21:52:08 +0000886 }
David Reiss53c10e02010-03-05 07:51:51 +0000887 if ($10 != NULL) {
888 $$->annotations_ = $10->annotations_;
889 delete $10;
890 }
Mark Slee31985722006-05-24 21:45:31 +0000891 }
Mark Slee7ff32452007-02-01 05:26:18 +0000892
893FieldIdentifier:
894 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000895 {
Mark Slee7ff32452007-02-01 05:26:18 +0000896 if ($1 <= 0) {
897 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
898 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000899 }
Mark Slee7ff32452007-02-01 05:26:18 +0000900 $$ = $1;
901 }
902|
903 {
904 $$ = y_field_val--;
905 }
906
David Reiss8320a922007-08-14 19:59:26 +0000907FieldRequiredness:
908 tok_required
909 {
David Reiss45603e92009-09-02 22:15:55 +0000910 $$ = t_field::T_REQUIRED;
David Reiss8320a922007-08-14 19:59:26 +0000911 }
912| tok_optional
913 {
Mark Slee78165722007-09-10 22:08:49 +0000914 if (g_arglist) {
915 if (g_parse_mode == PROGRAM) {
916 pwarning(1, "optional keyword is ignored in argument lists.\n");
917 }
David Reiss204420f2008-01-11 20:59:03 +0000918 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000919 } else {
David Reiss204420f2008-01-11 20:59:03 +0000920 $$ = t_field::T_OPTIONAL;
Mark Slee78165722007-09-10 22:08:49 +0000921 }
David Reiss8320a922007-08-14 19:59:26 +0000922 }
923|
924 {
David Reiss204420f2008-01-11 20:59:03 +0000925 $$ = t_field::T_OPT_IN_REQ_OUT;
David Reiss8320a922007-08-14 19:59:26 +0000926 }
927
Mark Slee7ff32452007-02-01 05:26:18 +0000928FieldValue:
929 '=' ConstValue
930 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000931 if (g_parse_mode == PROGRAM) {
Mark Slee7ff32452007-02-01 05:26:18 +0000932 $$ = $2;
933 } else {
934 $$ = NULL;
935 }
936 }
937|
938 {
939 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000940 }
Mark Slee31985722006-05-24 21:45:31 +0000941
Mark Slee31985722006-05-24 21:45:31 +0000942FunctionType:
943 FieldType
944 {
Mark Sleee8540632006-05-30 09:24:40 +0000945 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000946 $$ = $1;
947 }
948| tok_void
949 {
Mark Sleee8540632006-05-30 09:24:40 +0000950 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000951 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000952 }
953
954FieldType:
955 tok_identifier
956 {
Mark Sleee8540632006-05-30 09:24:40 +0000957 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000958 if (g_parse_mode == INCLUDES) {
959 // Ignore identifiers in include mode
960 $$ = NULL;
961 } else {
962 // Lookup the identifier in the current scope
963 $$ = g_scope->get_type($1);
964 if ($$ == NULL) {
965 yyerror("Type \"%s\" has not been defined.", $1);
966 exit(1);
967 }
Mark Sleee8540632006-05-30 09:24:40 +0000968 }
Mark Slee31985722006-05-24 21:45:31 +0000969 }
970| BaseType
971 {
Mark Sleee8540632006-05-30 09:24:40 +0000972 pdebug("FieldType -> BaseType");
973 $$ = $1;
974 }
975| ContainerType
976 {
977 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000978 $$ = $1;
979 }
980
David Reissc8e30052009-07-27 17:02:42 +0000981BaseType: SimpleBaseType TypeAnnotations
982 {
983 pdebug("BaseType -> SimpleBaseType TypeAnnotations");
984 if ($2 != NULL) {
985 $$ = new t_base_type(*static_cast<t_base_type*>($1));
986 $$->annotations_ = $2->annotations_;
987 delete $2;
988 } else {
989 $$ = $1;
990 }
991 }
992
993SimpleBaseType:
Mark Slee31985722006-05-24 21:45:31 +0000994 tok_string
995 {
996 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000997 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000998 }
Mark Slee8d725a22007-04-13 01:57:12 +0000999| tok_binary
1000 {
1001 pdebug("BaseType -> tok_binary");
1002 $$ = g_type_binary;
1003 }
Mark Sleeb6200d82007-01-19 19:14:36 +00001004| tok_slist
1005 {
1006 pdebug("BaseType -> tok_slist");
1007 $$ = g_type_slist;
1008 }
Mark Slee78f58e22006-09-02 04:17:07 +00001009| tok_bool
1010 {
1011 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +00001012 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +00001013 }
Mark Slee31985722006-05-24 21:45:31 +00001014| tok_byte
1015 {
1016 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +00001017 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +00001018 }
Mark Slee9cb7c612006-09-01 22:17:45 +00001019| tok_i16
1020 {
1021 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +00001022 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +00001023 }
Mark Slee31985722006-05-24 21:45:31 +00001024| tok_i32
1025 {
1026 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +00001027 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +00001028 }
Mark Slee31985722006-05-24 21:45:31 +00001029| tok_i64
1030 {
1031 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +00001032 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +00001033 }
Mark Sleec98d0502006-09-06 02:42:25 +00001034| tok_double
1035 {
1036 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +00001037 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +00001038 }
Mark Slee31985722006-05-24 21:45:31 +00001039
David Reissa2309992008-12-10 01:52:48 +00001040ContainerType: SimpleContainerType TypeAnnotations
1041 {
1042 pdebug("ContainerType -> SimpleContainerType TypeAnnotations");
1043 $$ = $1;
1044 if ($2 != NULL) {
1045 $$->annotations_ = $2->annotations_;
1046 delete $2;
1047 }
1048 }
1049
1050SimpleContainerType:
Mark Sleee8540632006-05-30 09:24:40 +00001051 MapType
1052 {
David Reissa2309992008-12-10 01:52:48 +00001053 pdebug("SimpleContainerType -> MapType");
Mark Sleee8540632006-05-30 09:24:40 +00001054 $$ = $1;
1055 }
1056| SetType
1057 {
David Reissa2309992008-12-10 01:52:48 +00001058 pdebug("SimpleContainerType -> SetType");
Mark Sleee8540632006-05-30 09:24:40 +00001059 $$ = $1;
1060 }
1061| ListType
1062 {
David Reissa2309992008-12-10 01:52:48 +00001063 pdebug("SimpleContainerType -> ListType");
Mark Sleee8540632006-05-30 09:24:40 +00001064 $$ = $1;
1065 }
1066
1067MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001068 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001069 {
1070 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001071 $$ = new t_map($4, $6);
1072 if ($2 != NULL) {
1073 ((t_container*)$$)->set_cpp_name(std::string($2));
1074 }
Mark Sleee8540632006-05-30 09:24:40 +00001075 }
1076
1077SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001078 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001079 {
1080 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001081 $$ = new t_set($4);
1082 if ($2 != NULL) {
1083 ((t_container*)$$)->set_cpp_name(std::string($2));
1084 }
Mark Sleee8540632006-05-30 09:24:40 +00001085 }
1086
1087ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001088 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +00001089 {
1090 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +00001091 $$ = new t_list($3);
1092 if ($5 != NULL) {
1093 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +00001094 }
1095 }
1096
Mark Slee36bfa2e2007-01-19 20:09:51 +00001097CppType:
Mark Sleeafc76542007-02-09 21:55:44 +00001098 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +00001099 {
Mark Sleeafc76542007-02-09 21:55:44 +00001100 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +00001101 }
1102|
1103 {
1104 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +00001105 }
1106
David Reissa2309992008-12-10 01:52:48 +00001107TypeAnnotations:
1108 '(' TypeAnnotationList ')'
1109 {
1110 pdebug("TypeAnnotations -> ( TypeAnnotationList )");
1111 $$ = $2;
1112 }
1113|
1114 {
1115 $$ = NULL;
1116 }
1117
1118TypeAnnotationList:
1119 TypeAnnotationList TypeAnnotation
1120 {
1121 pdebug("TypeAnnotationList -> TypeAnnotationList , TypeAnnotation");
1122 $$ = $1;
1123 $$->annotations_[$2->key] = $2->val;
1124 delete $2;
1125 }
1126|
1127 {
1128 /* Just use a dummy structure to hold the annotations. */
1129 $$ = new t_struct(g_program);
1130 }
1131
1132TypeAnnotation:
1133 tok_identifier '=' tok_literal CommaOrSemicolonOptional
1134 {
1135 pdebug("TypeAnnotation -> tok_identifier = tok_literal");
1136 $$ = new t_annotation;
1137 $$->key = $1;
1138 $$->val = $3;
1139 }
1140
Todd Lipcon53ae9f32009-12-07 00:42:38 +00001141%%