blob: fda49cddf9e70ff38524dd4f1f7b498d96af014b [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();
Bryan Duxbury9f0a7862010-09-12 14:38:36 +0000514 // make constants for all the enum values
515 if (g_parse_mode == PROGRAM) {
516 const std::vector<t_enum_value*>& enum_values = $$->get_constants();
517 std::vector<t_enum_value*>::const_iterator c_iter;
518 for (c_iter = enum_values.begin(); c_iter != enum_values.end(); ++c_iter) {
519 std::string const_name = $$->get_name() + "." + (*c_iter)->get_name();
520 t_const_value* const_val = new t_const_value((*c_iter)->get_value());
521 const_val->set_enum($$);
522 g_scope->add_constant(const_name, new t_const(g_type_i32, (*c_iter)->get_name(), const_val));
523 if (g_parent_scope != NULL) {
524 g_parent_scope->add_constant(g_parent_prefix + const_name, new t_const(g_type_i32, (*c_iter)->get_name(), const_val));
525 }
526 }
527 }
Mark Slee31985722006-05-24 21:45:31 +0000528 }
529
530EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000531 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000532 {
533 pdebug("EnumDefList -> EnumDefList EnumDef");
534 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000535 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000536 }
537|
538 {
539 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000540 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000541 }
542
543EnumDef:
David Reisscbd4bac2007-08-14 17:12:33 +0000544 CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000545 {
Mark Slee30152872006-11-28 01:24:07 +0000546 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000547 if ($4 < 0) {
548 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000549 }
David Reissf1454162008-06-30 20:45:47 +0000550 if ($4 > INT_MAX) {
551 pwarning(1, "64-bit value supplied for enum %s.\n", $2);
552 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000553 $$ = new t_enum_value($2, $4);
554 if ($1 != NULL) {
555 $$->set_doc($1);
556 }
Mark Slee31985722006-05-24 21:45:31 +0000557 }
558|
David Reisscbd4bac2007-08-14 17:12:33 +0000559 CaptureDocText tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000560 {
Mark Slee30152872006-11-28 01:24:07 +0000561 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000562 $$ = new t_enum_value($2);
563 if ($1 != NULL) {
564 $$->set_doc($1);
565 }
Mark Slee30152872006-11-28 01:24:07 +0000566 }
567
Mark Slee6a47fed2007-02-07 02:40:59 +0000568Senum:
David Reisscdffe262007-08-14 17:12:31 +0000569 tok_senum tok_identifier '{' SenumDefList '}'
Mark Slee6a47fed2007-02-07 02:40:59 +0000570 {
571 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000572 $$ = new t_typedef(g_program, $4, $2);
Mark Slee6a47fed2007-02-07 02:40:59 +0000573 }
574
575SenumDefList:
576 SenumDefList SenumDef
577 {
578 pdebug("SenumDefList -> SenumDefList SenumDef");
579 $$ = $1;
580 $$->add_string_enum_val($2);
581 }
582|
583 {
584 pdebug("SenumDefList -> ");
585 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
586 $$->set_string_enum(true);
587 }
588
589SenumDef:
590 tok_literal CommaOrSemicolonOptional
591 {
592 pdebug("SenumDef -> tok_literal");
593 $$ = $1;
594 }
595
Mark Slee30152872006-11-28 01:24:07 +0000596Const:
597 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
598 {
599 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000600 if (g_parse_mode == PROGRAM) {
Bryan Duxbury2d804702009-12-18 19:41:11 +0000601 g_scope->resolve_const_value($5, $2);
Mark Sleeaa7671d2006-11-29 03:19:31 +0000602 $$ = new t_const($2, $3, $5);
603 validate_const_type($$);
Mark Sleed0767c52007-07-27 22:14:41 +0000604
605 g_scope->add_constant($3, $$);
606 if (g_parent_scope != NULL) {
607 g_parent_scope->add_constant(g_parent_prefix + $3, $$);
608 }
Mark Sleeaa7671d2006-11-29 03:19:31 +0000609 } else {
610 $$ = NULL;
611 }
Mark Slee30152872006-11-28 01:24:07 +0000612 }
613
614ConstValue:
615 tok_int_constant
616 {
617 pdebug("ConstValue => tok_int_constant");
618 $$ = new t_const_value();
619 $$->set_integer($1);
David Reissf1454162008-06-30 20:45:47 +0000620 if ($1 < INT32_MIN || $1 > INT32_MAX) {
621 pwarning(1, "64-bit constant \"%"PRIi64"\" may not work in all languages.\n", $1);
622 }
Mark Slee30152872006-11-28 01:24:07 +0000623 }
624| tok_dub_constant
625 {
626 pdebug("ConstValue => tok_dub_constant");
627 $$ = new t_const_value();
628 $$->set_double($1);
629 }
630| tok_literal
631 {
632 pdebug("ConstValue => tok_literal");
Mark Sleed0767c52007-07-27 22:14:41 +0000633 $$ = new t_const_value($1);
Mark Slee30152872006-11-28 01:24:07 +0000634 }
Mark Slee67fc6342006-11-29 03:37:04 +0000635| tok_identifier
636 {
637 pdebug("ConstValue => tok_identifier");
Bryan Duxbury2d804702009-12-18 19:41:11 +0000638 $$ = new t_const_value();
639 $$->set_identifier($1);
Mark Slee67fc6342006-11-29 03:37:04 +0000640 }
Mark Slee30152872006-11-28 01:24:07 +0000641| ConstList
642 {
643 pdebug("ConstValue => ConstList");
644 $$ = $1;
645 }
646| ConstMap
647 {
648 pdebug("ConstValue => ConstMap");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000649 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000650 }
651
652ConstList:
653 '[' ConstListContents ']'
654 {
655 pdebug("ConstList => [ ConstListContents ]");
656 $$ = $2;
657 }
658
659ConstListContents:
660 ConstListContents ConstValue CommaOrSemicolonOptional
661 {
662 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
663 $$ = $1;
664 $$->add_list($2);
665 }
666|
667 {
668 pdebug("ConstListContents =>");
669 $$ = new t_const_value();
670 $$->set_list();
671 }
672
673ConstMap:
674 '{' ConstMapContents '}'
675 {
676 pdebug("ConstMap => { ConstMapContents }");
677 $$ = $2;
678 }
679
680ConstMapContents:
681 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
682 {
683 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
684 $$ = $1;
685 $$->add_map($2, $4);
686 }
687|
688 {
689 pdebug("ConstMapContents =>");
690 $$ = new t_const_value();
691 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000692 }
693
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000694StructHead:
695 tok_struct
696 {
697 $$ = struct_is_struct;
698 }
699| tok_union
700 {
701 $$ = struct_is_union;
702 }
703
Mark Slee31985722006-05-24 21:45:31 +0000704Struct:
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000705 StructHead tok_identifier XsdAll '{' FieldList '}' TypeAnnotations
Mark Slee31985722006-05-24 21:45:31 +0000706 {
707 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
David Reisscdffe262007-08-14 17:12:31 +0000708 $5->set_xsd_all($3);
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000709 $5->set_union($1 == struct_is_union);
David Reisscdffe262007-08-14 17:12:31 +0000710 $$ = $5;
David Reissa2309992008-12-10 01:52:48 +0000711 $$->set_name($2);
712 if ($7 != NULL) {
713 $$->annotations_ = $7->annotations_;
714 delete $7;
715 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000716 }
Bryan Duxburyab3666e2009-09-01 23:03:47 +0000717
Mark Slee36bfa2e2007-01-19 20:09:51 +0000718XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000719 tok_xsd_all
720 {
721 $$ = true;
722 }
723|
724 {
725 $$ = false;
726 }
727
Mark Slee36bfa2e2007-01-19 20:09:51 +0000728XsdOptional:
729 tok_xsd_optional
730 {
731 $$ = true;
732 }
733|
734 {
735 $$ = false;
736 }
737
Mark Slee7df0e2a2007-02-06 21:03:18 +0000738XsdNillable:
739 tok_xsd_nillable
740 {
741 $$ = true;
742 }
743|
744 {
745 $$ = false;
746 }
747
Mark Slee21135c32007-02-05 21:52:08 +0000748XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000749 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000750 {
Mark Slee748d83f2007-02-07 01:20:08 +0000751 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000752 }
753|
754 {
755 $$ = NULL;
756 }
757
Mark Slee9cb7c612006-09-01 22:17:45 +0000758Xception:
759 tok_xception tok_identifier '{' FieldList '}'
760 {
761 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
762 $4->set_name($2);
763 $4->set_xception(true);
764 $$ = $4;
Mark Slee31985722006-05-24 21:45:31 +0000765 }
766
767Service:
Mark Slee78165722007-09-10 22:08:49 +0000768 tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
Mark Slee31985722006-05-24 21:45:31 +0000769 {
770 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Slee78165722007-09-10 22:08:49 +0000771 $$ = $6;
David Reisscdffe262007-08-14 17:12:31 +0000772 $$->set_name($2);
773 $$->set_extends($3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000774 }
775
Mark Slee78165722007-09-10 22:08:49 +0000776FlagArgs:
777 {
778 g_arglist = 1;
779 }
780
781UnflagArgs:
782 {
783 g_arglist = 0;
784 }
785
Mark Slee36bfa2e2007-01-19 20:09:51 +0000786Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000787 tok_extends tok_identifier
788 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000789 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000790 $$ = NULL;
791 if (g_parse_mode == PROGRAM) {
792 $$ = g_scope->get_service($2);
793 if ($$ == NULL) {
794 yyerror("Service \"%s\" has not been defined.", $2);
795 exit(1);
796 }
797 }
798 }
799|
800 {
801 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000802 }
803
804FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000805 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000806 {
807 pdebug("FunctionList -> FunctionList Function");
808 $$ = $1;
809 $1->add_function($2);
810 }
811|
812 {
813 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000814 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000815 }
816
817Function:
David Reiss6985a422009-03-24 20:00:47 +0000818 CaptureDocText Oneway FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000819 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000820 $6->set_name(std::string($4) + "_args");
821 $$ = new t_function($3, $4, $6, $8, $2);
822 if ($1 != NULL) {
823 $$->set_doc($1);
824 }
Mark Slee31985722006-05-24 21:45:31 +0000825 }
826
David Reiss6985a422009-03-24 20:00:47 +0000827Oneway:
828 tok_oneway
Mark Slee31985722006-05-24 21:45:31 +0000829 {
Mark Slee52f643d2006-08-09 00:03:43 +0000830 $$ = true;
831 }
832|
833 {
834 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000835 }
836
Mark Slee36bfa2e2007-01-19 20:09:51 +0000837Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000838 tok_throws '(' FieldList ')'
839 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000840 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000841 $$ = $3;
Mark Sleef07d48e2008-02-01 01:36:26 +0000842 if (g_parse_mode == PROGRAM && !validate_throws($$)) {
Mark Slee91f2b7b2008-01-31 01:49:16 +0000843 yyerror("Throws clause may not contain non-exception types");
844 exit(1);
845 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000846 }
847|
848 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000849 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000850 }
851
Mark Slee31985722006-05-24 21:45:31 +0000852FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000853 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000854 {
855 pdebug("FieldList -> FieldList , Field");
856 $$ = $1;
Bryan Duxburyff219ac2009-04-10 21:51:00 +0000857 if (!($$->append($2))) {
Mark Slee6f9ac3f2007-11-28 22:28:13 +0000858 yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
859 exit(1);
860 }
Mark Slee31985722006-05-24 21:45:31 +0000861 }
862|
863 {
864 pdebug("FieldList -> ");
David Reiss00a8dd62009-03-19 08:14:12 +0000865 y_field_val = -1;
Mark Sleef0712dc2006-10-25 19:03:57 +0000866 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000867 }
868
869Field:
David Reiss53c10e02010-03-05 07:51:51 +0000870 CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes TypeAnnotations CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000871 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000872 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000873 if ($2 < 0) {
David Reissbb461362009-04-02 19:23:59 +0000874 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 +0000875 if (g_strict >= 192) {
876 yyerror("Implicit field keys are deprecated and not allowed with -strict");
877 exit(1);
878 }
Mark Slee31985722006-05-24 21:45:31 +0000879 }
David Reiss8320a922007-08-14 19:59:26 +0000880 $$ = new t_field($4, $5, $2);
881 $$->set_req($3);
882 if ($6 != NULL) {
Bryan Duxbury2d804702009-12-18 19:41:11 +0000883 g_scope->resolve_const_value($6, $4);
David Reiss8320a922007-08-14 19:59:26 +0000884 validate_field_value($$, $6);
885 $$->set_value($6);
Mark Slee7ff32452007-02-01 05:26:18 +0000886 }
David Reiss8320a922007-08-14 19:59:26 +0000887 $$->set_xsd_optional($7);
888 $$->set_xsd_nillable($8);
ccheeverf53b5cf2007-02-05 20:33:11 +0000889 if ($1 != NULL) {
890 $$->set_doc($1);
891 }
David Reiss8320a922007-08-14 19:59:26 +0000892 if ($9 != NULL) {
893 $$->set_xsd_attrs($9);
Mark Slee21135c32007-02-05 21:52:08 +0000894 }
David Reiss53c10e02010-03-05 07:51:51 +0000895 if ($10 != NULL) {
896 $$->annotations_ = $10->annotations_;
897 delete $10;
898 }
Mark Slee31985722006-05-24 21:45:31 +0000899 }
Mark Slee7ff32452007-02-01 05:26:18 +0000900
901FieldIdentifier:
902 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000903 {
Mark Slee7ff32452007-02-01 05:26:18 +0000904 if ($1 <= 0) {
905 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
906 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000907 }
Mark Slee7ff32452007-02-01 05:26:18 +0000908 $$ = $1;
909 }
910|
911 {
912 $$ = y_field_val--;
913 }
914
David Reiss8320a922007-08-14 19:59:26 +0000915FieldRequiredness:
916 tok_required
917 {
David Reiss45603e92009-09-02 22:15:55 +0000918 $$ = t_field::T_REQUIRED;
David Reiss8320a922007-08-14 19:59:26 +0000919 }
920| tok_optional
921 {
Mark Slee78165722007-09-10 22:08:49 +0000922 if (g_arglist) {
923 if (g_parse_mode == PROGRAM) {
924 pwarning(1, "optional keyword is ignored in argument lists.\n");
925 }
David Reiss204420f2008-01-11 20:59:03 +0000926 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000927 } else {
David Reiss204420f2008-01-11 20:59:03 +0000928 $$ = t_field::T_OPTIONAL;
Mark Slee78165722007-09-10 22:08:49 +0000929 }
David Reiss8320a922007-08-14 19:59:26 +0000930 }
931|
932 {
David Reiss204420f2008-01-11 20:59:03 +0000933 $$ = t_field::T_OPT_IN_REQ_OUT;
David Reiss8320a922007-08-14 19:59:26 +0000934 }
935
Mark Slee7ff32452007-02-01 05:26:18 +0000936FieldValue:
937 '=' ConstValue
938 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000939 if (g_parse_mode == PROGRAM) {
Mark Slee7ff32452007-02-01 05:26:18 +0000940 $$ = $2;
941 } else {
942 $$ = NULL;
943 }
944 }
945|
946 {
947 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000948 }
Mark Slee31985722006-05-24 21:45:31 +0000949
Mark Slee31985722006-05-24 21:45:31 +0000950FunctionType:
951 FieldType
952 {
Mark Sleee8540632006-05-30 09:24:40 +0000953 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000954 $$ = $1;
955 }
956| tok_void
957 {
Mark Sleee8540632006-05-30 09:24:40 +0000958 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000959 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000960 }
961
962FieldType:
963 tok_identifier
964 {
Mark Sleee8540632006-05-30 09:24:40 +0000965 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000966 if (g_parse_mode == INCLUDES) {
967 // Ignore identifiers in include mode
968 $$ = NULL;
969 } else {
970 // Lookup the identifier in the current scope
971 $$ = g_scope->get_type($1);
972 if ($$ == NULL) {
973 yyerror("Type \"%s\" has not been defined.", $1);
974 exit(1);
975 }
Mark Sleee8540632006-05-30 09:24:40 +0000976 }
Mark Slee31985722006-05-24 21:45:31 +0000977 }
978| BaseType
979 {
Mark Sleee8540632006-05-30 09:24:40 +0000980 pdebug("FieldType -> BaseType");
981 $$ = $1;
982 }
983| ContainerType
984 {
985 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000986 $$ = $1;
987 }
988
David Reissc8e30052009-07-27 17:02:42 +0000989BaseType: SimpleBaseType TypeAnnotations
990 {
991 pdebug("BaseType -> SimpleBaseType TypeAnnotations");
992 if ($2 != NULL) {
993 $$ = new t_base_type(*static_cast<t_base_type*>($1));
994 $$->annotations_ = $2->annotations_;
995 delete $2;
996 } else {
997 $$ = $1;
998 }
999 }
1000
1001SimpleBaseType:
Mark Slee31985722006-05-24 21:45:31 +00001002 tok_string
1003 {
1004 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +00001005 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +00001006 }
Mark Slee8d725a22007-04-13 01:57:12 +00001007| tok_binary
1008 {
1009 pdebug("BaseType -> tok_binary");
1010 $$ = g_type_binary;
1011 }
Mark Sleeb6200d82007-01-19 19:14:36 +00001012| tok_slist
1013 {
1014 pdebug("BaseType -> tok_slist");
1015 $$ = g_type_slist;
1016 }
Mark Slee78f58e22006-09-02 04:17:07 +00001017| tok_bool
1018 {
1019 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +00001020 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +00001021 }
Mark Slee31985722006-05-24 21:45:31 +00001022| tok_byte
1023 {
1024 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +00001025 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +00001026 }
Mark Slee9cb7c612006-09-01 22:17:45 +00001027| tok_i16
1028 {
1029 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +00001030 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +00001031 }
Mark Slee31985722006-05-24 21:45:31 +00001032| tok_i32
1033 {
1034 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +00001035 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +00001036 }
Mark Slee31985722006-05-24 21:45:31 +00001037| tok_i64
1038 {
1039 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +00001040 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +00001041 }
Mark Sleec98d0502006-09-06 02:42:25 +00001042| tok_double
1043 {
1044 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +00001045 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +00001046 }
Mark Slee31985722006-05-24 21:45:31 +00001047
David Reissa2309992008-12-10 01:52:48 +00001048ContainerType: SimpleContainerType TypeAnnotations
1049 {
1050 pdebug("ContainerType -> SimpleContainerType TypeAnnotations");
1051 $$ = $1;
1052 if ($2 != NULL) {
1053 $$->annotations_ = $2->annotations_;
1054 delete $2;
1055 }
1056 }
1057
1058SimpleContainerType:
Mark Sleee8540632006-05-30 09:24:40 +00001059 MapType
1060 {
David Reissa2309992008-12-10 01:52:48 +00001061 pdebug("SimpleContainerType -> MapType");
Mark Sleee8540632006-05-30 09:24:40 +00001062 $$ = $1;
1063 }
1064| SetType
1065 {
David Reissa2309992008-12-10 01:52:48 +00001066 pdebug("SimpleContainerType -> SetType");
Mark Sleee8540632006-05-30 09:24:40 +00001067 $$ = $1;
1068 }
1069| ListType
1070 {
David Reissa2309992008-12-10 01:52:48 +00001071 pdebug("SimpleContainerType -> ListType");
Mark Sleee8540632006-05-30 09:24:40 +00001072 $$ = $1;
1073 }
1074
1075MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001076 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001077 {
1078 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001079 $$ = new t_map($4, $6);
1080 if ($2 != NULL) {
1081 ((t_container*)$$)->set_cpp_name(std::string($2));
1082 }
Mark Sleee8540632006-05-30 09:24:40 +00001083 }
1084
1085SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001086 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001087 {
1088 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001089 $$ = new t_set($4);
1090 if ($2 != NULL) {
1091 ((t_container*)$$)->set_cpp_name(std::string($2));
1092 }
Mark Sleee8540632006-05-30 09:24:40 +00001093 }
1094
1095ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001096 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +00001097 {
1098 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +00001099 $$ = new t_list($3);
1100 if ($5 != NULL) {
1101 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +00001102 }
1103 }
1104
Mark Slee36bfa2e2007-01-19 20:09:51 +00001105CppType:
Mark Sleeafc76542007-02-09 21:55:44 +00001106 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +00001107 {
Mark Sleeafc76542007-02-09 21:55:44 +00001108 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +00001109 }
1110|
1111 {
1112 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +00001113 }
1114
David Reissa2309992008-12-10 01:52:48 +00001115TypeAnnotations:
1116 '(' TypeAnnotationList ')'
1117 {
1118 pdebug("TypeAnnotations -> ( TypeAnnotationList )");
1119 $$ = $2;
1120 }
1121|
1122 {
1123 $$ = NULL;
1124 }
1125
1126TypeAnnotationList:
1127 TypeAnnotationList TypeAnnotation
1128 {
1129 pdebug("TypeAnnotationList -> TypeAnnotationList , TypeAnnotation");
1130 $$ = $1;
1131 $$->annotations_[$2->key] = $2->val;
1132 delete $2;
1133 }
1134|
1135 {
1136 /* Just use a dummy structure to hold the annotations. */
1137 $$ = new t_struct(g_program);
1138 }
1139
1140TypeAnnotation:
1141 tok_identifier '=' tok_literal CommaOrSemicolonOptional
1142 {
1143 pdebug("TypeAnnotation -> tok_identifier = tok_literal");
1144 $$ = new t_annotation;
1145 $$->key = $1;
1146 $$->val = $3;
1147 }
1148
Todd Lipcon53ae9f32009-12-07 00:42:38 +00001149%%