blob: 026e5c3a68d9eb81511513b719601cd093f76fc3 [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;
Mark Slee31985722006-05-24 21:45:31 +000045
46%}
47
Mark Sleef5377b32006-10-10 01:42:59 +000048/**
49 * This structure is used by the parser to hold the data types associated with
50 * various parse nodes.
51 */
Mark Slee31985722006-05-24 21:45:31 +000052%union {
Mark Slee30152872006-11-28 01:24:07 +000053 char* id;
David Reissf1454162008-06-30 20:45:47 +000054 int64_t iconst;
Mark Slee30152872006-11-28 01:24:07 +000055 double dconst;
56 bool tbool;
David Reisscdffe262007-08-14 17:12:31 +000057 t_doc* tdoc;
Mark Slee30152872006-11-28 01:24:07 +000058 t_type* ttype;
Mark Slee6a47fed2007-02-07 02:40:59 +000059 t_base_type* tbase;
Mark Slee30152872006-11-28 01:24:07 +000060 t_typedef* ttypedef;
61 t_enum* tenum;
62 t_enum_value* tenumv;
63 t_const* tconst;
64 t_const_value* tconstv;
65 t_struct* tstruct;
66 t_service* tservice;
67 t_function* tfunction;
68 t_field* tfield;
David Reisscdffe262007-08-14 17:12:31 +000069 char* dtext;
David Reiss8320a922007-08-14 19:59:26 +000070 t_field::e_req ereq;
David Reissa2309992008-12-10 01:52:48 +000071 t_annotation* tannot;
Mark Slee31985722006-05-24 21:45:31 +000072}
73
Mark Sleef5377b32006-10-10 01:42:59 +000074/**
75 * Strings identifier
76 */
Mark Slee31985722006-05-24 21:45:31 +000077%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000078%token<id> tok_literal
David Reisscdffe262007-08-14 17:12:31 +000079%token<dtext> tok_doctext
Mark Sleebd588222007-11-21 08:43:35 +000080%token<id> tok_st_identifier
Mark Sleef5377b32006-10-10 01:42:59 +000081
82/**
Mark Slee30152872006-11-28 01:24:07 +000083 * Constant values
Mark Sleef5377b32006-10-10 01:42:59 +000084 */
Mark Slee31985722006-05-24 21:45:31 +000085%token<iconst> tok_int_constant
Mark Slee30152872006-11-28 01:24:07 +000086%token<dconst> tok_dub_constant
Mark Slee31985722006-05-24 21:45:31 +000087
Mark Sleef5377b32006-10-10 01:42:59 +000088/**
David Reiss399442b2008-02-20 02:28:05 +000089 * Header keywords
Mark Sleef5377b32006-10-10 01:42:59 +000090 */
Mark Sleef0712dc2006-10-25 19:03:57 +000091%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000092%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000093%token tok_cpp_namespace
94%token tok_cpp_include
95%token tok_cpp_type
Mark Sleee888b372007-01-12 01:06:24 +000096%token tok_php_namespace
David Reissc6fc3292007-08-30 00:58:43 +000097%token tok_py_module
Mark Slee27ed6ec2007-08-16 01:26:31 +000098%token tok_perl_package
Mark Sleef0712dc2006-10-25 19:03:57 +000099%token tok_java_package
Mark Slee782abbb2007-01-19 00:17:02 +0000100%token tok_xsd_all
Mark Slee36bfa2e2007-01-19 20:09:51 +0000101%token tok_xsd_optional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000102%token tok_xsd_nillable
Mark Slee0d9199e2007-01-31 02:08:30 +0000103%token tok_xsd_namespace
Mark Slee21135c32007-02-05 21:52:08 +0000104%token tok_xsd_attrs
Mark Slee58dfb4f2007-07-06 02:45:25 +0000105%token tok_ruby_namespace
Mark Sleebd588222007-11-21 08:43:35 +0000106%token tok_smalltalk_category
David Reiss15457c92007-12-14 07:03:03 +0000107%token tok_smalltalk_prefix
Mark Slee7e9eea42007-09-10 21:00:23 +0000108%token tok_cocoa_prefix
David Reiss7f42bcf2008-01-11 20:59:12 +0000109%token tok_csharp_namespace
Mark Slee9cb7c612006-09-01 22:17:45 +0000110
Mark Sleef5377b32006-10-10 01:42:59 +0000111/**
112 * Base datatype keywords
113 */
114%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +0000115%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +0000116%token tok_byte
117%token tok_string
Mark Slee8d725a22007-04-13 01:57:12 +0000118%token tok_binary
Mark Sleeb6200d82007-01-19 19:14:36 +0000119%token tok_slist
Mark Slee6a47fed2007-02-07 02:40:59 +0000120%token tok_senum
Mark Slee9cb7c612006-09-01 22:17:45 +0000121%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +0000122%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +0000123%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +0000124%token tok_double
Mark Slee31985722006-05-24 21:45:31 +0000125
Mark Sleef5377b32006-10-10 01:42:59 +0000126/**
127 * Complex type keywords
128 */
Mark Slee31985722006-05-24 21:45:31 +0000129%token tok_map
130%token tok_list
131%token tok_set
132
Mark Sleef5377b32006-10-10 01:42:59 +0000133/**
134 * Function modifiers
Mark Slee27ed6ec2007-08-16 01:26:31 +0000135 */
David Reiss6985a422009-03-24 20:00:47 +0000136%token tok_oneway
Mark Slee31985722006-05-24 21:45:31 +0000137
Mark Sleef5377b32006-10-10 01:42:59 +0000138/**
139 * Thrift language keywords
140 */
Mark Slee31985722006-05-24 21:45:31 +0000141%token tok_typedef
142%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000143%token tok_xception
144%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000145%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000146%token tok_service
147%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000148%token tok_const
David Reiss8320a922007-08-14 19:59:26 +0000149%token tok_required
150%token tok_optional
Mark Slee31985722006-05-24 21:45:31 +0000151
Mark Sleef5377b32006-10-10 01:42:59 +0000152/**
153 * Grammar nodes
154 */
155
Mark Slee31985722006-05-24 21:45:31 +0000156%type<ttype> BaseType
David Reissc8e30052009-07-27 17:02:42 +0000157%type<ttype> SimpleBaseType
Mark Sleee8540632006-05-30 09:24:40 +0000158%type<ttype> ContainerType
David Reissa2309992008-12-10 01:52:48 +0000159%type<ttype> SimpleContainerType
Mark Sleee8540632006-05-30 09:24:40 +0000160%type<ttype> MapType
161%type<ttype> SetType
162%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000163
David Reisscdffe262007-08-14 17:12:31 +0000164%type<tdoc> Definition
Mark Sleef0712dc2006-10-25 19:03:57 +0000165%type<ttype> TypeDefinition
166
Mark Slee31985722006-05-24 21:45:31 +0000167%type<ttypedef> Typedef
168%type<ttype> DefinitionType
169
David Reissa2309992008-12-10 01:52:48 +0000170%type<ttype> TypeAnnotations
171%type<ttype> TypeAnnotationList
172%type<tannot> TypeAnnotation
173
Mark Slee31985722006-05-24 21:45:31 +0000174%type<tfield> Field
Mark Slee7ff32452007-02-01 05:26:18 +0000175%type<iconst> FieldIdentifier
David Reiss8320a922007-08-14 19:59:26 +0000176%type<ereq> FieldRequiredness
Mark Slee31985722006-05-24 21:45:31 +0000177%type<ttype> FieldType
Mark Slee7ff32452007-02-01 05:26:18 +0000178%type<tconstv> FieldValue
Mark Sleee8540632006-05-30 09:24:40 +0000179%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000180
181%type<tenum> Enum
182%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000183%type<tenumv> EnumDef
184
Mark Slee6a47fed2007-02-07 02:40:59 +0000185%type<ttypedef> Senum
186%type<tbase> SenumDefList
187%type<id> SenumDef
188
Mark Slee30152872006-11-28 01:24:07 +0000189%type<tconst> Const
190%type<tconstv> ConstValue
191%type<tconstv> ConstList
192%type<tconstv> ConstListContents
193%type<tconstv> ConstMap
194%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000195
196%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000197%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000198%type<tservice> Service
199
200%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000201%type<ttype> FunctionType
202%type<tservice> FunctionList
203
Mark Slee36bfa2e2007-01-19 20:09:51 +0000204%type<tstruct> Throws
205%type<tservice> Extends
David Reiss6985a422009-03-24 20:00:47 +0000206%type<tbool> Oneway
Mark Slee36bfa2e2007-01-19 20:09:51 +0000207%type<tbool> XsdAll
208%type<tbool> XsdOptional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000209%type<tbool> XsdNillable
Mark Slee748d83f2007-02-07 01:20:08 +0000210%type<tstruct> XsdAttributes
Mark Slee36bfa2e2007-01-19 20:09:51 +0000211%type<id> CppType
Mark Slee52f643d2006-08-09 00:03:43 +0000212
David Reisscbd4bac2007-08-14 17:12:33 +0000213%type<dtext> CaptureDocText
ccheeverf53b5cf2007-02-05 20:33:11 +0000214
Mark Slee31985722006-05-24 21:45:31 +0000215%%
216
Mark Sleef5377b32006-10-10 01:42:59 +0000217/**
218 * Thrift Grammar Implementation.
219 *
220 * For the most part this source file works its way top down from what you
221 * might expect to find in a typical .thrift file, i.e. type definitions and
222 * namespaces up top followed by service definitions using those types.
223 */
Mark Slee31985722006-05-24 21:45:31 +0000224
225Program:
David Reisscbd4bac2007-08-14 17:12:33 +0000226 HeaderList DefinitionList
Mark Sleef0712dc2006-10-25 19:03:57 +0000227 {
228 pdebug("Program -> Headers DefinitionList");
David Reisscbd4bac2007-08-14 17:12:33 +0000229 /*
230 TODO(dreiss): Decide whether full-program doctext is worth the trouble.
David Reissc2532a92007-07-30 23:46:11 +0000231 if ($1 != NULL) {
232 g_program->set_doc($1);
233 }
David Reisscbd4bac2007-08-14 17:12:33 +0000234 */
235 clear_doctext();
Mark Sleef0712dc2006-10-25 19:03:57 +0000236 }
237
David Reisscbd4bac2007-08-14 17:12:33 +0000238CaptureDocText:
239 {
240 if (g_parse_mode == PROGRAM) {
Mark Sleebd588222007-11-21 08:43:35 +0000241 $$ = g_doctext;
David Reisscbd4bac2007-08-14 17:12:33 +0000242 g_doctext = NULL;
Mark Slee27ed6ec2007-08-16 01:26:31 +0000243 } else {
David Reisscbd4bac2007-08-14 17:12:33 +0000244 $$ = NULL;
245 }
246 }
247
248/* TODO(dreiss): Try to DestroyDocText in all sorts or random places. */
249DestroyDocText:
250 {
251 if (g_parse_mode == PROGRAM) {
252 clear_doctext();
253 }
254 }
255
256/* We have to DestroyDocText here, otherwise it catches the doctext
257 on the first real element. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000258HeaderList:
David Reisscbd4bac2007-08-14 17:12:33 +0000259 HeaderList DestroyDocText Header
Mark Sleef0712dc2006-10-25 19:03:57 +0000260 {
261 pdebug("HeaderList -> HeaderList Header");
262 }
263|
264 {
265 pdebug("HeaderList -> ");
266 }
267
268Header:
269 Include
270 {
271 pdebug("Header -> Include");
272 }
David Reiss79eca142008-02-27 01:55:13 +0000273| tok_namespace tok_identifier tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +0000274 {
David Reiss79eca142008-02-27 01:55:13 +0000275 pdebug("Header -> tok_namespace tok_identifier tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000276 if (g_parse_mode == PROGRAM) {
David Reiss79eca142008-02-27 01:55:13 +0000277 g_program->set_namespace($2, $3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000278 }
279 }
David Reiss9a08dc62008-02-27 01:55:17 +0000280/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000281| tok_cpp_namespace tok_identifier
282 {
David Reiss9a08dc62008-02-27 01:55:17 +0000283 pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000284 pdebug("Header -> tok_cpp_namespace tok_identifier");
285 if (g_parse_mode == PROGRAM) {
David Reiss9a08dc62008-02-27 01:55:17 +0000286 g_program->set_namespace("cpp", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000287 }
288 }
289| tok_cpp_include tok_literal
290 {
291 pdebug("Header -> tok_cpp_include tok_literal");
292 if (g_parse_mode == PROGRAM) {
293 g_program->add_cpp_include($2);
294 }
295 }
Mark Sleee888b372007-01-12 01:06:24 +0000296| tok_php_namespace tok_identifier
297 {
David Reiss554ea6f2009-02-17 20:28:37 +0000298 pwarning(1, "'php_namespace' is deprecated. Use 'namespace php' instead");
Mark Sleee888b372007-01-12 01:06:24 +0000299 pdebug("Header -> tok_php_namespace tok_identifier");
300 if (g_parse_mode == PROGRAM) {
David Reiss554ea6f2009-02-17 20:28:37 +0000301 g_program->set_namespace("php", $2);
Mark Sleee888b372007-01-12 01:06:24 +0000302 }
303 }
David Reiss320e45c2008-03-27 21:41:54 +0000304/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reissc6fc3292007-08-30 00:58:43 +0000305| tok_py_module tok_identifier
306 {
David Reiss320e45c2008-03-27 21:41:54 +0000307 pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead");
David Reissc6fc3292007-08-30 00:58:43 +0000308 pdebug("Header -> tok_py_module tok_identifier");
309 if (g_parse_mode == PROGRAM) {
David Reiss320e45c2008-03-27 21:41:54 +0000310 g_program->set_namespace("py", $2);
David Reissc6fc3292007-08-30 00:58:43 +0000311 }
312 }
David Reiss07ef3a92008-03-27 21:42:39 +0000313/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee27ed6ec2007-08-16 01:26:31 +0000314| tok_perl_package tok_identifier
315 {
David Reiss07ef3a92008-03-27 21:42:39 +0000316 pwarning(1, "'perl_package' is deprecated. Use 'namespace perl' instead");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000317 pdebug("Header -> tok_perl_namespace tok_identifier");
318 if (g_parse_mode == PROGRAM) {
David Reiss07ef3a92008-03-27 21:42:39 +0000319 g_program->set_namespace("perl", $2);
Mark Slee27ed6ec2007-08-16 01:26:31 +0000320 }
321 }
David Reiss6a4b82c2008-03-27 21:42:16 +0000322/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee58dfb4f2007-07-06 02:45:25 +0000323| tok_ruby_namespace tok_identifier
324 {
David Reiss6a4b82c2008-03-27 21:42:16 +0000325 pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead");
Mark Slee58dfb4f2007-07-06 02:45:25 +0000326 pdebug("Header -> tok_ruby_namespace tok_identifier");
327 if (g_parse_mode == PROGRAM) {
David Reiss6a4b82c2008-03-27 21:42:16 +0000328 g_program->set_namespace("rb", $2);
Mark Slee58dfb4f2007-07-06 02:45:25 +0000329 }
330 }
David Reiss3b455012008-03-27 21:40:46 +0000331/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleebd588222007-11-21 08:43:35 +0000332| tok_smalltalk_category tok_st_identifier
333 {
David Reiss3b455012008-03-27 21:40:46 +0000334 pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
Mark Sleebd588222007-11-21 08:43:35 +0000335 pdebug("Header -> tok_smalltalk_category tok_st_identifier");
336 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000337 g_program->set_namespace("smalltalk.category", $2);
Mark Sleebd588222007-11-21 08:43:35 +0000338 }
339 }
David Reiss3b455012008-03-27 21:40:46 +0000340/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss15457c92007-12-14 07:03:03 +0000341| tok_smalltalk_prefix tok_identifier
342 {
David Reiss3b455012008-03-27 21:40:46 +0000343 pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
David Reiss15457c92007-12-14 07:03:03 +0000344 pdebug("Header -> tok_smalltalk_prefix tok_identifier");
345 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000346 g_program->set_namespace("smalltalk.prefix", $2);
David Reiss15457c92007-12-14 07:03:03 +0000347 }
348 }
David Reiss771f8c72008-02-27 01:55:25 +0000349/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000350| tok_java_package tok_identifier
351 {
David Reiss9f646152008-03-02 21:59:48 +0000352 pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000353 pdebug("Header -> tok_java_package tok_identifier");
354 if (g_parse_mode == PROGRAM) {
David Reiss771f8c72008-02-27 01:55:25 +0000355 g_program->set_namespace("java", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000356 }
357 }
David Reiss54b602b2008-03-27 21:41:06 +0000358/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee7e9eea42007-09-10 21:00:23 +0000359| tok_cocoa_prefix tok_identifier
360 {
David Reiss54b602b2008-03-27 21:41:06 +0000361 pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
Mark Slee7e9eea42007-09-10 21:00:23 +0000362 pdebug("Header -> tok_cocoa_prefix tok_identifier");
363 if (g_parse_mode == PROGRAM) {
David Reiss54b602b2008-03-27 21:41:06 +0000364 g_program->set_namespace("cocoa", $2);
Mark Slee7e9eea42007-09-10 21:00:23 +0000365 }
366 }
David Reiss92e10d82009-02-17 20:28:19 +0000367/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee0d9199e2007-01-31 02:08:30 +0000368| tok_xsd_namespace tok_literal
369 {
David Reiss92e10d82009-02-17 20:28:19 +0000370 pwarning(1, "'xsd_namespace' is deprecated. Use 'namespace xsd' instead");
Mark Slee0d9199e2007-01-31 02:08:30 +0000371 pdebug("Header -> tok_xsd_namespace tok_literal");
372 if (g_parse_mode == PROGRAM) {
David Reiss92e10d82009-02-17 20:28:19 +0000373 g_program->set_namespace("cocoa", $2);
Mark Slee0d9199e2007-01-31 02:08:30 +0000374 }
375 }
David Reiss9d65bf02008-03-27 21:41:37 +0000376/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss7f42bcf2008-01-11 20:59:12 +0000377| tok_csharp_namespace tok_identifier
378 {
David Reiss9d65bf02008-03-27 21:41:37 +0000379 pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead");
David Reiss919ae802008-03-27 21:41:11 +0000380 pdebug("Header -> tok_csharp_namespace tok_identifier");
David Reiss7f42bcf2008-01-11 20:59:12 +0000381 if (g_parse_mode == PROGRAM) {
David Reiss9d65bf02008-03-27 21:41:37 +0000382 g_program->set_namespace("csharp", $2);
David Reiss7f42bcf2008-01-11 20:59:12 +0000383 }
384 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000385
386Include:
387 tok_include tok_literal
388 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000389 pdebug("Include -> tok_include tok_literal");
Mark Sleef0712dc2006-10-25 19:03:57 +0000390 if (g_parse_mode == INCLUDES) {
391 std::string path = include_file(std::string($2));
392 if (!path.empty()) {
kholst76f2c882008-01-16 02:47:41 +0000393 g_program->add_include(path, std::string($2));
Mark Sleef0712dc2006-10-25 19:03:57 +0000394 }
395 }
396 }
Mark Slee31985722006-05-24 21:45:31 +0000397
398DefinitionList:
David Reisscbd4bac2007-08-14 17:12:33 +0000399 DefinitionList CaptureDocText Definition
Mark Slee31985722006-05-24 21:45:31 +0000400 {
401 pdebug("DefinitionList -> DefinitionList Definition");
David Reisscdffe262007-08-14 17:12:31 +0000402 if ($2 != NULL && $3 != NULL) {
403 $3->set_doc($2);
404 }
Mark Slee31985722006-05-24 21:45:31 +0000405 }
406|
407 {
408 pdebug("DefinitionList -> ");
409 }
410
411Definition:
Mark Slee30152872006-11-28 01:24:07 +0000412 Const
413 {
414 pdebug("Definition -> Const");
415 if (g_parse_mode == PROGRAM) {
416 g_program->add_const($1);
Mark Sleebd588222007-11-21 08:43:35 +0000417 }
David Reisscdffe262007-08-14 17:12:31 +0000418 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000419 }
420| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000421 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000422 pdebug("Definition -> TypeDefinition");
423 if (g_parse_mode == PROGRAM) {
424 g_scope->add_type($1->get_name(), $1);
425 if (g_parent_scope != NULL) {
426 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
427 }
428 }
David Reisscdffe262007-08-14 17:12:31 +0000429 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000430 }
Mark Slee31985722006-05-24 21:45:31 +0000431| Service
432 {
433 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000434 if (g_parse_mode == PROGRAM) {
435 g_scope->add_service($1->get_name(), $1);
436 if (g_parent_scope != NULL) {
437 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
438 }
439 g_program->add_service($1);
440 }
David Reisscdffe262007-08-14 17:12:31 +0000441 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000442 }
443
Mark Sleef0712dc2006-10-25 19:03:57 +0000444TypeDefinition:
445 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000446 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000447 pdebug("TypeDefinition -> Typedef");
448 if (g_parse_mode == PROGRAM) {
449 g_program->add_typedef($1);
450 }
451 }
452| Enum
453 {
454 pdebug("TypeDefinition -> Enum");
455 if (g_parse_mode == PROGRAM) {
456 g_program->add_enum($1);
457 }
458 }
Mark Slee6a47fed2007-02-07 02:40:59 +0000459| Senum
460 {
461 pdebug("TypeDefinition -> Senum");
462 if (g_parse_mode == PROGRAM) {
463 g_program->add_typedef($1);
464 }
465 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000466| Struct
467 {
468 pdebug("TypeDefinition -> Struct");
469 if (g_parse_mode == PROGRAM) {
470 g_program->add_struct($1);
471 }
472 }
473| Xception
Mark Slee27ed6ec2007-08-16 01:26:31 +0000474 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000475 pdebug("TypeDefinition -> Xception");
476 if (g_parse_mode == PROGRAM) {
477 g_program->add_xception($1);
478 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000479 }
Mark Slee31985722006-05-24 21:45:31 +0000480
481Typedef:
Mark Sleebd588222007-11-21 08:43:35 +0000482 tok_typedef DefinitionType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000483 {
484 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
David Reisscdffe262007-08-14 17:12:31 +0000485 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000486 $$ = td;
487 }
488
Mark Slee6a47fed2007-02-07 02:40:59 +0000489CommaOrSemicolonOptional:
490 ','
491 {}
492| ';'
493 {}
494|
495 {}
ccheeverf53b5cf2007-02-05 20:33:11 +0000496
Mark Slee31985722006-05-24 21:45:31 +0000497Enum:
David Reisscdffe262007-08-14 17:12:31 +0000498 tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000499 {
500 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000501 $$ = $4;
502 $$->set_name($2);
Mark Slee31985722006-05-24 21:45:31 +0000503 }
504
505EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000506 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000507 {
508 pdebug("EnumDefList -> EnumDefList EnumDef");
509 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000510 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000511 }
512|
513 {
514 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000515 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000516 }
517
518EnumDef:
David Reisscbd4bac2007-08-14 17:12:33 +0000519 CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000520 {
Mark Slee30152872006-11-28 01:24:07 +0000521 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000522 if ($4 < 0) {
523 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000524 }
David Reissf1454162008-06-30 20:45:47 +0000525 if ($4 > INT_MAX) {
526 pwarning(1, "64-bit value supplied for enum %s.\n", $2);
527 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000528 $$ = new t_enum_value($2, $4);
529 if ($1 != NULL) {
530 $$->set_doc($1);
531 }
Mark Sleed0767c52007-07-27 22:14:41 +0000532 if (g_parse_mode == PROGRAM) {
533 g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4)));
534 if (g_parent_scope != NULL) {
535 g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4)));
536 }
537 }
Mark Slee31985722006-05-24 21:45:31 +0000538 }
539|
David Reisscbd4bac2007-08-14 17:12:33 +0000540 CaptureDocText tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000541 {
Mark Slee30152872006-11-28 01:24:07 +0000542 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000543 $$ = new t_enum_value($2);
544 if ($1 != NULL) {
545 $$->set_doc($1);
546 }
Mark Slee30152872006-11-28 01:24:07 +0000547 }
548
Mark Slee6a47fed2007-02-07 02:40:59 +0000549Senum:
David Reisscdffe262007-08-14 17:12:31 +0000550 tok_senum tok_identifier '{' SenumDefList '}'
Mark Slee6a47fed2007-02-07 02:40:59 +0000551 {
552 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000553 $$ = new t_typedef(g_program, $4, $2);
Mark Slee6a47fed2007-02-07 02:40:59 +0000554 }
555
556SenumDefList:
557 SenumDefList SenumDef
558 {
559 pdebug("SenumDefList -> SenumDefList SenumDef");
560 $$ = $1;
561 $$->add_string_enum_val($2);
562 }
563|
564 {
565 pdebug("SenumDefList -> ");
566 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
567 $$->set_string_enum(true);
568 }
569
570SenumDef:
571 tok_literal CommaOrSemicolonOptional
572 {
573 pdebug("SenumDef -> tok_literal");
574 $$ = $1;
575 }
576
Mark Slee30152872006-11-28 01:24:07 +0000577Const:
578 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
579 {
580 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000581 if (g_parse_mode == PROGRAM) {
582 $$ = new t_const($2, $3, $5);
583 validate_const_type($$);
Mark Sleed0767c52007-07-27 22:14:41 +0000584
585 g_scope->add_constant($3, $$);
586 if (g_parent_scope != NULL) {
587 g_parent_scope->add_constant(g_parent_prefix + $3, $$);
588 }
589
Mark Sleeaa7671d2006-11-29 03:19:31 +0000590 } else {
591 $$ = NULL;
592 }
Mark Slee30152872006-11-28 01:24:07 +0000593 }
594
595ConstValue:
596 tok_int_constant
597 {
598 pdebug("ConstValue => tok_int_constant");
599 $$ = new t_const_value();
600 $$->set_integer($1);
David Reissf1454162008-06-30 20:45:47 +0000601 if ($1 < INT32_MIN || $1 > INT32_MAX) {
602 pwarning(1, "64-bit constant \"%"PRIi64"\" may not work in all languages.\n", $1);
603 }
Mark Slee30152872006-11-28 01:24:07 +0000604 }
605| tok_dub_constant
606 {
607 pdebug("ConstValue => tok_dub_constant");
608 $$ = new t_const_value();
609 $$->set_double($1);
610 }
611| tok_literal
612 {
613 pdebug("ConstValue => tok_literal");
Mark Sleed0767c52007-07-27 22:14:41 +0000614 $$ = new t_const_value($1);
Mark Slee30152872006-11-28 01:24:07 +0000615 }
Mark Slee67fc6342006-11-29 03:37:04 +0000616| tok_identifier
617 {
618 pdebug("ConstValue => tok_identifier");
Mark Sleed0767c52007-07-27 22:14:41 +0000619 t_const* constant = g_scope->get_constant($1);
620 if (constant != NULL) {
621 $$ = constant->get_value();
622 } else {
623 if (g_parse_mode == PROGRAM) {
624 pwarning(1, "Constant strings should be quoted: %s\n", $1);
625 }
626 $$ = new t_const_value($1);
627 }
Mark Slee67fc6342006-11-29 03:37:04 +0000628 }
Mark Slee30152872006-11-28 01:24:07 +0000629| ConstList
630 {
631 pdebug("ConstValue => ConstList");
632 $$ = $1;
633 }
634| ConstMap
635 {
636 pdebug("ConstValue => ConstMap");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000637 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000638 }
639
640ConstList:
641 '[' ConstListContents ']'
642 {
643 pdebug("ConstList => [ ConstListContents ]");
644 $$ = $2;
645 }
646
647ConstListContents:
648 ConstListContents ConstValue CommaOrSemicolonOptional
649 {
650 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
651 $$ = $1;
652 $$->add_list($2);
653 }
654|
655 {
656 pdebug("ConstListContents =>");
657 $$ = new t_const_value();
658 $$->set_list();
659 }
660
661ConstMap:
662 '{' ConstMapContents '}'
663 {
664 pdebug("ConstMap => { ConstMapContents }");
665 $$ = $2;
666 }
667
668ConstMapContents:
669 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
670 {
671 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
672 $$ = $1;
673 $$->add_map($2, $4);
674 }
675|
676 {
677 pdebug("ConstMapContents =>");
678 $$ = new t_const_value();
679 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000680 }
681
682Struct:
David Reissa2309992008-12-10 01:52:48 +0000683 tok_struct tok_identifier XsdAll '{' FieldList '}' TypeAnnotations
Mark Slee31985722006-05-24 21:45:31 +0000684 {
685 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
David Reisscdffe262007-08-14 17:12:31 +0000686 $5->set_xsd_all($3);
687 $$ = $5;
David Reissa2309992008-12-10 01:52:48 +0000688 $$->set_name($2);
689 if ($7 != NULL) {
690 $$->annotations_ = $7->annotations_;
691 delete $7;
692 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000693 }
694
Mark Slee36bfa2e2007-01-19 20:09:51 +0000695XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000696 tok_xsd_all
697 {
698 $$ = true;
699 }
700|
701 {
702 $$ = false;
703 }
704
Mark Slee36bfa2e2007-01-19 20:09:51 +0000705XsdOptional:
706 tok_xsd_optional
707 {
708 $$ = true;
709 }
710|
711 {
712 $$ = false;
713 }
714
Mark Slee7df0e2a2007-02-06 21:03:18 +0000715XsdNillable:
716 tok_xsd_nillable
717 {
718 $$ = true;
719 }
720|
721 {
722 $$ = false;
723 }
724
Mark Slee21135c32007-02-05 21:52:08 +0000725XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000726 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000727 {
Mark Slee748d83f2007-02-07 01:20:08 +0000728 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000729 }
730|
731 {
732 $$ = NULL;
733 }
734
Mark Slee9cb7c612006-09-01 22:17:45 +0000735Xception:
736 tok_xception tok_identifier '{' FieldList '}'
737 {
738 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
739 $4->set_name($2);
740 $4->set_xception(true);
741 $$ = $4;
Mark Slee31985722006-05-24 21:45:31 +0000742 }
743
744Service:
Mark Slee78165722007-09-10 22:08:49 +0000745 tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
Mark Slee31985722006-05-24 21:45:31 +0000746 {
747 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Slee78165722007-09-10 22:08:49 +0000748 $$ = $6;
David Reisscdffe262007-08-14 17:12:31 +0000749 $$->set_name($2);
750 $$->set_extends($3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000751 }
752
Mark Slee78165722007-09-10 22:08:49 +0000753FlagArgs:
754 {
755 g_arglist = 1;
756 }
757
758UnflagArgs:
759 {
760 g_arglist = 0;
761 }
762
Mark Slee36bfa2e2007-01-19 20:09:51 +0000763Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000764 tok_extends tok_identifier
765 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000766 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000767 $$ = NULL;
768 if (g_parse_mode == PROGRAM) {
769 $$ = g_scope->get_service($2);
770 if ($$ == NULL) {
771 yyerror("Service \"%s\" has not been defined.", $2);
772 exit(1);
773 }
774 }
775 }
776|
777 {
778 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000779 }
780
781FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000782 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000783 {
784 pdebug("FunctionList -> FunctionList Function");
785 $$ = $1;
786 $1->add_function($2);
787 }
788|
789 {
790 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000791 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000792 }
793
794Function:
David Reiss6985a422009-03-24 20:00:47 +0000795 CaptureDocText Oneway FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000796 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000797 $6->set_name(std::string($4) + "_args");
798 $$ = new t_function($3, $4, $6, $8, $2);
799 if ($1 != NULL) {
800 $$->set_doc($1);
801 }
Mark Slee31985722006-05-24 21:45:31 +0000802 }
803
David Reiss6985a422009-03-24 20:00:47 +0000804Oneway:
805 tok_oneway
Mark Slee31985722006-05-24 21:45:31 +0000806 {
Mark Slee52f643d2006-08-09 00:03:43 +0000807 $$ = true;
808 }
809|
810 {
811 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000812 }
813
Mark Slee36bfa2e2007-01-19 20:09:51 +0000814Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000815 tok_throws '(' FieldList ')'
816 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000817 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000818 $$ = $3;
Mark Sleef07d48e2008-02-01 01:36:26 +0000819 if (g_parse_mode == PROGRAM && !validate_throws($$)) {
Mark Slee91f2b7b2008-01-31 01:49:16 +0000820 yyerror("Throws clause may not contain non-exception types");
821 exit(1);
822 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000823 }
824|
825 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000826 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000827 }
828
Mark Slee31985722006-05-24 21:45:31 +0000829FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000830 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000831 {
832 pdebug("FieldList -> FieldList , Field");
833 $$ = $1;
Bryan Duxburyff219ac2009-04-10 21:51:00 +0000834 if (!($$->append($2))) {
Mark Slee6f9ac3f2007-11-28 22:28:13 +0000835 yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
836 exit(1);
837 }
Mark Slee31985722006-05-24 21:45:31 +0000838 }
839|
840 {
841 pdebug("FieldList -> ");
David Reiss00a8dd62009-03-19 08:14:12 +0000842 y_field_val = -1;
Mark Sleef0712dc2006-10-25 19:03:57 +0000843 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000844 }
845
846Field:
David Reiss8320a922007-08-14 19:59:26 +0000847 CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000848 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000849 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000850 if ($2 < 0) {
David Reissbb461362009-04-02 19:23:59 +0000851 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 +0000852 if (g_strict >= 192) {
853 yyerror("Implicit field keys are deprecated and not allowed with -strict");
854 exit(1);
855 }
Mark Slee31985722006-05-24 21:45:31 +0000856 }
David Reiss8320a922007-08-14 19:59:26 +0000857 $$ = new t_field($4, $5, $2);
858 $$->set_req($3);
859 if ($6 != NULL) {
860 validate_field_value($$, $6);
861 $$->set_value($6);
Mark Slee7ff32452007-02-01 05:26:18 +0000862 }
David Reiss8320a922007-08-14 19:59:26 +0000863 $$->set_xsd_optional($7);
864 $$->set_xsd_nillable($8);
ccheeverf53b5cf2007-02-05 20:33:11 +0000865 if ($1 != NULL) {
866 $$->set_doc($1);
867 }
David Reiss8320a922007-08-14 19:59:26 +0000868 if ($9 != NULL) {
869 $$->set_xsd_attrs($9);
Mark Slee21135c32007-02-05 21:52:08 +0000870 }
Mark Slee31985722006-05-24 21:45:31 +0000871 }
Mark Slee7ff32452007-02-01 05:26:18 +0000872
873FieldIdentifier:
874 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000875 {
Mark Slee7ff32452007-02-01 05:26:18 +0000876 if ($1 <= 0) {
877 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
878 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000879 }
Mark Slee7ff32452007-02-01 05:26:18 +0000880 $$ = $1;
881 }
882|
883 {
884 $$ = y_field_val--;
885 }
886
David Reiss8320a922007-08-14 19:59:26 +0000887FieldRequiredness:
888 tok_required
889 {
Mark Slee78165722007-09-10 22:08:49 +0000890 if (g_arglist) {
891 if (g_parse_mode == PROGRAM) {
892 pwarning(1, "required keyword is ignored in argument lists.\n");
893 }
David Reiss204420f2008-01-11 20:59:03 +0000894 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000895 } else {
David Reiss204420f2008-01-11 20:59:03 +0000896 $$ = t_field::T_REQUIRED;
Mark Slee78165722007-09-10 22:08:49 +0000897 }
David Reiss8320a922007-08-14 19:59:26 +0000898 }
899| tok_optional
900 {
Mark Slee78165722007-09-10 22:08:49 +0000901 if (g_arglist) {
902 if (g_parse_mode == PROGRAM) {
903 pwarning(1, "optional keyword is ignored in argument lists.\n");
904 }
David Reiss204420f2008-01-11 20:59:03 +0000905 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000906 } else {
David Reiss204420f2008-01-11 20:59:03 +0000907 $$ = t_field::T_OPTIONAL;
Mark Slee78165722007-09-10 22:08:49 +0000908 }
David Reiss8320a922007-08-14 19:59:26 +0000909 }
910|
911 {
David Reiss204420f2008-01-11 20:59:03 +0000912 $$ = t_field::T_OPT_IN_REQ_OUT;
David Reiss8320a922007-08-14 19:59:26 +0000913 }
914
Mark Slee7ff32452007-02-01 05:26:18 +0000915FieldValue:
916 '=' ConstValue
917 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000918 if (g_parse_mode == PROGRAM) {
Mark Slee7ff32452007-02-01 05:26:18 +0000919 $$ = $2;
920 } else {
921 $$ = NULL;
922 }
923 }
924|
925 {
926 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000927 }
Mark Slee31985722006-05-24 21:45:31 +0000928
929DefinitionType:
930 BaseType
931 {
932 pdebug("DefinitionType -> BaseType");
933 $$ = $1;
934 }
Mark Sleee8540632006-05-30 09:24:40 +0000935| ContainerType
936 {
937 pdebug("DefinitionType -> ContainerType");
938 $$ = $1;
939 }
Mark Slee31985722006-05-24 21:45:31 +0000940
941FunctionType:
942 FieldType
943 {
Mark Sleee8540632006-05-30 09:24:40 +0000944 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000945 $$ = $1;
946 }
947| tok_void
948 {
Mark Sleee8540632006-05-30 09:24:40 +0000949 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000950 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000951 }
952
953FieldType:
954 tok_identifier
955 {
Mark Sleee8540632006-05-30 09:24:40 +0000956 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000957 if (g_parse_mode == INCLUDES) {
958 // Ignore identifiers in include mode
959 $$ = NULL;
960 } else {
961 // Lookup the identifier in the current scope
962 $$ = g_scope->get_type($1);
963 if ($$ == NULL) {
964 yyerror("Type \"%s\" has not been defined.", $1);
965 exit(1);
966 }
Mark Sleee8540632006-05-30 09:24:40 +0000967 }
Mark Slee31985722006-05-24 21:45:31 +0000968 }
969| BaseType
970 {
Mark Sleee8540632006-05-30 09:24:40 +0000971 pdebug("FieldType -> BaseType");
972 $$ = $1;
973 }
974| ContainerType
975 {
976 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000977 $$ = $1;
978 }
979
David Reissc8e30052009-07-27 17:02:42 +0000980BaseType: SimpleBaseType TypeAnnotations
981 {
982 pdebug("BaseType -> SimpleBaseType TypeAnnotations");
983 if ($2 != NULL) {
984 $$ = new t_base_type(*static_cast<t_base_type*>($1));
985 $$->annotations_ = $2->annotations_;
986 delete $2;
987 } else {
988 $$ = $1;
989 }
990 }
991
992SimpleBaseType:
Mark Slee31985722006-05-24 21:45:31 +0000993 tok_string
994 {
995 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000996 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000997 }
Mark Slee8d725a22007-04-13 01:57:12 +0000998| tok_binary
999 {
1000 pdebug("BaseType -> tok_binary");
1001 $$ = g_type_binary;
1002 }
Mark Sleeb6200d82007-01-19 19:14:36 +00001003| tok_slist
1004 {
1005 pdebug("BaseType -> tok_slist");
1006 $$ = g_type_slist;
1007 }
Mark Slee78f58e22006-09-02 04:17:07 +00001008| tok_bool
1009 {
1010 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +00001011 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +00001012 }
Mark Slee31985722006-05-24 21:45:31 +00001013| tok_byte
1014 {
1015 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +00001016 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +00001017 }
Mark Slee9cb7c612006-09-01 22:17:45 +00001018| tok_i16
1019 {
1020 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +00001021 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +00001022 }
Mark Slee31985722006-05-24 21:45:31 +00001023| tok_i32
1024 {
1025 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +00001026 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +00001027 }
Mark Slee31985722006-05-24 21:45:31 +00001028| tok_i64
1029 {
1030 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +00001031 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +00001032 }
Mark Sleec98d0502006-09-06 02:42:25 +00001033| tok_double
1034 {
1035 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +00001036 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +00001037 }
Mark Slee31985722006-05-24 21:45:31 +00001038
David Reissa2309992008-12-10 01:52:48 +00001039ContainerType: SimpleContainerType TypeAnnotations
1040 {
1041 pdebug("ContainerType -> SimpleContainerType TypeAnnotations");
1042 $$ = $1;
1043 if ($2 != NULL) {
1044 $$->annotations_ = $2->annotations_;
1045 delete $2;
1046 }
1047 }
1048
1049SimpleContainerType:
Mark Sleee8540632006-05-30 09:24:40 +00001050 MapType
1051 {
David Reissa2309992008-12-10 01:52:48 +00001052 pdebug("SimpleContainerType -> MapType");
Mark Sleee8540632006-05-30 09:24:40 +00001053 $$ = $1;
1054 }
1055| SetType
1056 {
David Reissa2309992008-12-10 01:52:48 +00001057 pdebug("SimpleContainerType -> SetType");
Mark Sleee8540632006-05-30 09:24:40 +00001058 $$ = $1;
1059 }
1060| ListType
1061 {
David Reissa2309992008-12-10 01:52:48 +00001062 pdebug("SimpleContainerType -> ListType");
Mark Sleee8540632006-05-30 09:24:40 +00001063 $$ = $1;
1064 }
1065
1066MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001067 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001068 {
1069 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001070 $$ = new t_map($4, $6);
1071 if ($2 != NULL) {
1072 ((t_container*)$$)->set_cpp_name(std::string($2));
1073 }
Mark Sleee8540632006-05-30 09:24:40 +00001074 }
1075
1076SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001077 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001078 {
1079 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001080 $$ = new t_set($4);
1081 if ($2 != NULL) {
1082 ((t_container*)$$)->set_cpp_name(std::string($2));
1083 }
Mark Sleee8540632006-05-30 09:24:40 +00001084 }
1085
1086ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001087 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +00001088 {
1089 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +00001090 $$ = new t_list($3);
1091 if ($5 != NULL) {
1092 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +00001093 }
1094 }
1095
Mark Slee36bfa2e2007-01-19 20:09:51 +00001096CppType:
Mark Sleeafc76542007-02-09 21:55:44 +00001097 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +00001098 {
Mark Sleeafc76542007-02-09 21:55:44 +00001099 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +00001100 }
1101|
1102 {
1103 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +00001104 }
1105
David Reissa2309992008-12-10 01:52:48 +00001106TypeAnnotations:
1107 '(' TypeAnnotationList ')'
1108 {
1109 pdebug("TypeAnnotations -> ( TypeAnnotationList )");
1110 $$ = $2;
1111 }
1112|
1113 {
1114 $$ = NULL;
1115 }
1116
1117TypeAnnotationList:
1118 TypeAnnotationList TypeAnnotation
1119 {
1120 pdebug("TypeAnnotationList -> TypeAnnotationList , TypeAnnotation");
1121 $$ = $1;
1122 $$->annotations_[$2->key] = $2->val;
1123 delete $2;
1124 }
1125|
1126 {
1127 /* Just use a dummy structure to hold the annotations. */
1128 $$ = new t_struct(g_program);
1129 }
1130
1131TypeAnnotation:
1132 tok_identifier '=' tok_literal CommaOrSemicolonOptional
1133 {
1134 pdebug("TypeAnnotation -> tok_identifier = tok_literal");
1135 $$ = new t_annotation;
1136 $$->key = $1;
1137 $$->val = $3;
1138 }
1139
Mark Slee31985722006-05-24 21:45:31 +00001140%%