blob: b71fd7ea235f490a6d94a96247b96b24d00ca571 [file] [log] [blame]
Mark Slee31985722006-05-24 21:45:31 +00001%{
Mark Sleee9ce01c2007-05-16 02:29:53 +00002// Copyright (c) 2006- Facebook
3// Distributed under the Thrift Software License
4//
5// See accompanying file LICENSE or visit the Thrift site at:
6// http://developers.facebook.com/thrift/
Mark Slee31985722006-05-24 21:45:31 +00007
8/**
9 * Thrift parser.
10 *
11 * This parser is used on a thrift definition file.
12 *
13 * @author Mark Slee <mcslee@facebook.com>
14 */
15
David Reissf1454162008-06-30 20:45:47 +000016#define __STDC_LIMIT_MACROS
17#define __STDC_FORMAT_MACROS
Mark Slee31985722006-05-24 21:45:31 +000018#include <stdio.h>
David Reissf1454162008-06-30 20:45:47 +000019#include <inttypes.h>
David Reiss400a5432008-07-25 19:48:39 +000020#include <limits.h>
Mark Slee31985722006-05-24 21:45:31 +000021#include "main.h"
22#include "globals.h"
23#include "parse/t_program.h"
Mark Sleef0712dc2006-10-25 19:03:57 +000024#include "parse/t_scope.h"
Mark Slee31985722006-05-24 21:45:31 +000025
Mark Sleef5377b32006-10-10 01:42:59 +000026/**
27 * This global variable is used for automatic numbering of field indices etc.
28 * when parsing the members of a struct. Field values are automatically
29 * assigned starting from -1 and working their way down.
30 */
Mark Slee9cb7c612006-09-01 22:17:45 +000031int y_field_val = -1;
Mark Slee78165722007-09-10 22:08:49 +000032int g_arglist = 0;
Mark Slee31985722006-05-24 21:45:31 +000033
34%}
35
Mark Sleef5377b32006-10-10 01:42:59 +000036/**
37 * This structure is used by the parser to hold the data types associated with
38 * various parse nodes.
39 */
Mark Slee31985722006-05-24 21:45:31 +000040%union {
Mark Slee30152872006-11-28 01:24:07 +000041 char* id;
David Reissf1454162008-06-30 20:45:47 +000042 int64_t iconst;
Mark Slee30152872006-11-28 01:24:07 +000043 double dconst;
44 bool tbool;
David Reisscdffe262007-08-14 17:12:31 +000045 t_doc* tdoc;
Mark Slee30152872006-11-28 01:24:07 +000046 t_type* ttype;
Mark Slee6a47fed2007-02-07 02:40:59 +000047 t_base_type* tbase;
Mark Slee30152872006-11-28 01:24:07 +000048 t_typedef* ttypedef;
49 t_enum* tenum;
50 t_enum_value* tenumv;
51 t_const* tconst;
52 t_const_value* tconstv;
53 t_struct* tstruct;
54 t_service* tservice;
55 t_function* tfunction;
56 t_field* tfield;
David Reisscdffe262007-08-14 17:12:31 +000057 char* dtext;
David Reiss8320a922007-08-14 19:59:26 +000058 t_field::e_req ereq;
David Reissa2309992008-12-10 01:52:48 +000059 t_annotation* tannot;
Mark Slee31985722006-05-24 21:45:31 +000060}
61
Mark Sleef5377b32006-10-10 01:42:59 +000062/**
63 * Strings identifier
64 */
Mark Slee31985722006-05-24 21:45:31 +000065%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000066%token<id> tok_literal
David Reisscdffe262007-08-14 17:12:31 +000067%token<dtext> tok_doctext
Mark Sleebd588222007-11-21 08:43:35 +000068%token<id> tok_st_identifier
Mark Sleef5377b32006-10-10 01:42:59 +000069
70/**
Mark Slee30152872006-11-28 01:24:07 +000071 * Constant values
Mark Sleef5377b32006-10-10 01:42:59 +000072 */
Mark Slee31985722006-05-24 21:45:31 +000073%token<iconst> tok_int_constant
Mark Slee30152872006-11-28 01:24:07 +000074%token<dconst> tok_dub_constant
Mark Slee31985722006-05-24 21:45:31 +000075
Mark Sleef5377b32006-10-10 01:42:59 +000076/**
David Reiss399442b2008-02-20 02:28:05 +000077 * Header keywords
Mark Sleef5377b32006-10-10 01:42:59 +000078 */
Mark Sleef0712dc2006-10-25 19:03:57 +000079%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000080%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000081%token tok_cpp_namespace
82%token tok_cpp_include
83%token tok_cpp_type
Mark Sleee888b372007-01-12 01:06:24 +000084%token tok_php_namespace
David Reissc6fc3292007-08-30 00:58:43 +000085%token tok_py_module
Mark Slee27ed6ec2007-08-16 01:26:31 +000086%token tok_perl_package
Mark Sleef0712dc2006-10-25 19:03:57 +000087%token tok_java_package
Mark Slee782abbb2007-01-19 00:17:02 +000088%token tok_xsd_all
Mark Slee36bfa2e2007-01-19 20:09:51 +000089%token tok_xsd_optional
Mark Slee7df0e2a2007-02-06 21:03:18 +000090%token tok_xsd_nillable
Mark Slee0d9199e2007-01-31 02:08:30 +000091%token tok_xsd_namespace
Mark Slee21135c32007-02-05 21:52:08 +000092%token tok_xsd_attrs
Mark Slee58dfb4f2007-07-06 02:45:25 +000093%token tok_ruby_namespace
Mark Sleebd588222007-11-21 08:43:35 +000094%token tok_smalltalk_category
David Reiss15457c92007-12-14 07:03:03 +000095%token tok_smalltalk_prefix
Mark Slee7e9eea42007-09-10 21:00:23 +000096%token tok_cocoa_prefix
David Reiss7f42bcf2008-01-11 20:59:12 +000097%token tok_csharp_namespace
Mark Slee9cb7c612006-09-01 22:17:45 +000098
Mark Sleef5377b32006-10-10 01:42:59 +000099/**
100 * Base datatype keywords
101 */
102%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +0000103%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +0000104%token tok_byte
105%token tok_string
Mark Slee8d725a22007-04-13 01:57:12 +0000106%token tok_binary
Mark Sleeb6200d82007-01-19 19:14:36 +0000107%token tok_slist
Mark Slee6a47fed2007-02-07 02:40:59 +0000108%token tok_senum
Mark Slee9cb7c612006-09-01 22:17:45 +0000109%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +0000110%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +0000111%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +0000112%token tok_double
Mark Slee31985722006-05-24 21:45:31 +0000113
Mark Sleef5377b32006-10-10 01:42:59 +0000114/**
115 * Complex type keywords
116 */
Mark Slee31985722006-05-24 21:45:31 +0000117%token tok_map
118%token tok_list
119%token tok_set
120
Mark Sleef5377b32006-10-10 01:42:59 +0000121/**
122 * Function modifiers
Mark Slee27ed6ec2007-08-16 01:26:31 +0000123 */
Mark Slee31985722006-05-24 21:45:31 +0000124%token tok_async
125
Mark Sleef5377b32006-10-10 01:42:59 +0000126/**
127 * Thrift language keywords
128 */
Mark Slee31985722006-05-24 21:45:31 +0000129%token tok_typedef
130%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000131%token tok_xception
132%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000133%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000134%token tok_service
135%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000136%token tok_const
David Reiss8320a922007-08-14 19:59:26 +0000137%token tok_required
138%token tok_optional
Mark Slee31985722006-05-24 21:45:31 +0000139
Mark Sleef5377b32006-10-10 01:42:59 +0000140/**
141 * Grammar nodes
142 */
143
Mark Slee31985722006-05-24 21:45:31 +0000144%type<ttype> BaseType
Mark Sleee8540632006-05-30 09:24:40 +0000145%type<ttype> ContainerType
David Reissa2309992008-12-10 01:52:48 +0000146%type<ttype> SimpleContainerType
Mark Sleee8540632006-05-30 09:24:40 +0000147%type<ttype> MapType
148%type<ttype> SetType
149%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000150
David Reisscdffe262007-08-14 17:12:31 +0000151%type<tdoc> Definition
Mark Sleef0712dc2006-10-25 19:03:57 +0000152%type<ttype> TypeDefinition
153
Mark Slee31985722006-05-24 21:45:31 +0000154%type<ttypedef> Typedef
155%type<ttype> DefinitionType
156
David Reissa2309992008-12-10 01:52:48 +0000157%type<ttype> TypeAnnotations
158%type<ttype> TypeAnnotationList
159%type<tannot> TypeAnnotation
160
Mark Slee31985722006-05-24 21:45:31 +0000161%type<tfield> Field
Mark Slee7ff32452007-02-01 05:26:18 +0000162%type<iconst> FieldIdentifier
David Reiss8320a922007-08-14 19:59:26 +0000163%type<ereq> FieldRequiredness
Mark Slee31985722006-05-24 21:45:31 +0000164%type<ttype> FieldType
Mark Slee7ff32452007-02-01 05:26:18 +0000165%type<tconstv> FieldValue
Mark Sleee8540632006-05-30 09:24:40 +0000166%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000167
168%type<tenum> Enum
169%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000170%type<tenumv> EnumDef
171
Mark Slee6a47fed2007-02-07 02:40:59 +0000172%type<ttypedef> Senum
173%type<tbase> SenumDefList
174%type<id> SenumDef
175
Mark Slee30152872006-11-28 01:24:07 +0000176%type<tconst> Const
177%type<tconstv> ConstValue
178%type<tconstv> ConstList
179%type<tconstv> ConstListContents
180%type<tconstv> ConstMap
181%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000182
183%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000184%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000185%type<tservice> Service
186
187%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000188%type<ttype> FunctionType
189%type<tservice> FunctionList
190
Mark Slee36bfa2e2007-01-19 20:09:51 +0000191%type<tstruct> Throws
192%type<tservice> Extends
193%type<tbool> Async
194%type<tbool> XsdAll
195%type<tbool> XsdOptional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000196%type<tbool> XsdNillable
Mark Slee748d83f2007-02-07 01:20:08 +0000197%type<tstruct> XsdAttributes
Mark Slee36bfa2e2007-01-19 20:09:51 +0000198%type<id> CppType
Mark Slee52f643d2006-08-09 00:03:43 +0000199
David Reisscbd4bac2007-08-14 17:12:33 +0000200%type<dtext> CaptureDocText
ccheeverf53b5cf2007-02-05 20:33:11 +0000201
Mark Slee31985722006-05-24 21:45:31 +0000202%%
203
Mark Sleef5377b32006-10-10 01:42:59 +0000204/**
205 * Thrift Grammar Implementation.
206 *
207 * For the most part this source file works its way top down from what you
208 * might expect to find in a typical .thrift file, i.e. type definitions and
209 * namespaces up top followed by service definitions using those types.
210 */
Mark Slee31985722006-05-24 21:45:31 +0000211
212Program:
David Reisscbd4bac2007-08-14 17:12:33 +0000213 HeaderList DefinitionList
Mark Sleef0712dc2006-10-25 19:03:57 +0000214 {
215 pdebug("Program -> Headers DefinitionList");
David Reisscbd4bac2007-08-14 17:12:33 +0000216 /*
217 TODO(dreiss): Decide whether full-program doctext is worth the trouble.
David Reissc2532a92007-07-30 23:46:11 +0000218 if ($1 != NULL) {
219 g_program->set_doc($1);
220 }
David Reisscbd4bac2007-08-14 17:12:33 +0000221 */
222 clear_doctext();
Mark Sleef0712dc2006-10-25 19:03:57 +0000223 }
224
David Reisscbd4bac2007-08-14 17:12:33 +0000225CaptureDocText:
226 {
227 if (g_parse_mode == PROGRAM) {
Mark Sleebd588222007-11-21 08:43:35 +0000228 $$ = g_doctext;
David Reisscbd4bac2007-08-14 17:12:33 +0000229 g_doctext = NULL;
Mark Slee27ed6ec2007-08-16 01:26:31 +0000230 } else {
David Reisscbd4bac2007-08-14 17:12:33 +0000231 $$ = NULL;
232 }
233 }
234
235/* TODO(dreiss): Try to DestroyDocText in all sorts or random places. */
236DestroyDocText:
237 {
238 if (g_parse_mode == PROGRAM) {
239 clear_doctext();
240 }
241 }
242
243/* We have to DestroyDocText here, otherwise it catches the doctext
244 on the first real element. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000245HeaderList:
David Reisscbd4bac2007-08-14 17:12:33 +0000246 HeaderList DestroyDocText Header
Mark Sleef0712dc2006-10-25 19:03:57 +0000247 {
248 pdebug("HeaderList -> HeaderList Header");
249 }
250|
251 {
252 pdebug("HeaderList -> ");
253 }
254
255Header:
256 Include
257 {
258 pdebug("Header -> Include");
259 }
David Reiss79eca142008-02-27 01:55:13 +0000260| tok_namespace tok_identifier tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +0000261 {
David Reiss79eca142008-02-27 01:55:13 +0000262 pdebug("Header -> tok_namespace tok_identifier tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000263 if (g_parse_mode == PROGRAM) {
David Reiss79eca142008-02-27 01:55:13 +0000264 g_program->set_namespace($2, $3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000265 }
266 }
David Reiss9a08dc62008-02-27 01:55:17 +0000267/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000268| tok_cpp_namespace tok_identifier
269 {
David Reiss9a08dc62008-02-27 01:55:17 +0000270 pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000271 pdebug("Header -> tok_cpp_namespace tok_identifier");
272 if (g_parse_mode == PROGRAM) {
David Reiss9a08dc62008-02-27 01:55:17 +0000273 g_program->set_namespace("cpp", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000274 }
275 }
276| tok_cpp_include tok_literal
277 {
278 pdebug("Header -> tok_cpp_include tok_literal");
279 if (g_parse_mode == PROGRAM) {
280 g_program->add_cpp_include($2);
281 }
282 }
Mark Sleee888b372007-01-12 01:06:24 +0000283| tok_php_namespace tok_identifier
284 {
David Reiss554ea6f2009-02-17 20:28:37 +0000285 pwarning(1, "'php_namespace' is deprecated. Use 'namespace php' instead");
Mark Sleee888b372007-01-12 01:06:24 +0000286 pdebug("Header -> tok_php_namespace tok_identifier");
287 if (g_parse_mode == PROGRAM) {
David Reiss554ea6f2009-02-17 20:28:37 +0000288 g_program->set_namespace("php", $2);
Mark Sleee888b372007-01-12 01:06:24 +0000289 }
290 }
David Reiss320e45c2008-03-27 21:41:54 +0000291/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reissc6fc3292007-08-30 00:58:43 +0000292| tok_py_module tok_identifier
293 {
David Reiss320e45c2008-03-27 21:41:54 +0000294 pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead");
David Reissc6fc3292007-08-30 00:58:43 +0000295 pdebug("Header -> tok_py_module tok_identifier");
296 if (g_parse_mode == PROGRAM) {
David Reiss320e45c2008-03-27 21:41:54 +0000297 g_program->set_namespace("py", $2);
David Reissc6fc3292007-08-30 00:58:43 +0000298 }
299 }
David Reiss07ef3a92008-03-27 21:42:39 +0000300/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee27ed6ec2007-08-16 01:26:31 +0000301| tok_perl_package tok_identifier
302 {
David Reiss07ef3a92008-03-27 21:42:39 +0000303 pwarning(1, "'perl_package' is deprecated. Use 'namespace perl' instead");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000304 pdebug("Header -> tok_perl_namespace tok_identifier");
305 if (g_parse_mode == PROGRAM) {
David Reiss07ef3a92008-03-27 21:42:39 +0000306 g_program->set_namespace("perl", $2);
Mark Slee27ed6ec2007-08-16 01:26:31 +0000307 }
308 }
David Reiss6a4b82c2008-03-27 21:42:16 +0000309/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee58dfb4f2007-07-06 02:45:25 +0000310| tok_ruby_namespace tok_identifier
311 {
David Reiss6a4b82c2008-03-27 21:42:16 +0000312 pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead");
Mark Slee58dfb4f2007-07-06 02:45:25 +0000313 pdebug("Header -> tok_ruby_namespace tok_identifier");
314 if (g_parse_mode == PROGRAM) {
David Reiss6a4b82c2008-03-27 21:42:16 +0000315 g_program->set_namespace("rb", $2);
Mark Slee58dfb4f2007-07-06 02:45:25 +0000316 }
317 }
David Reiss3b455012008-03-27 21:40:46 +0000318/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleebd588222007-11-21 08:43:35 +0000319| tok_smalltalk_category tok_st_identifier
320 {
David Reiss3b455012008-03-27 21:40:46 +0000321 pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
Mark Sleebd588222007-11-21 08:43:35 +0000322 pdebug("Header -> tok_smalltalk_category tok_st_identifier");
323 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000324 g_program->set_namespace("smalltalk.category", $2);
Mark Sleebd588222007-11-21 08:43:35 +0000325 }
326 }
David Reiss3b455012008-03-27 21:40:46 +0000327/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss15457c92007-12-14 07:03:03 +0000328| tok_smalltalk_prefix tok_identifier
329 {
David Reiss3b455012008-03-27 21:40:46 +0000330 pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
David Reiss15457c92007-12-14 07:03:03 +0000331 pdebug("Header -> tok_smalltalk_prefix tok_identifier");
332 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000333 g_program->set_namespace("smalltalk.prefix", $2);
David Reiss15457c92007-12-14 07:03:03 +0000334 }
335 }
David Reiss771f8c72008-02-27 01:55:25 +0000336/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000337| tok_java_package tok_identifier
338 {
David Reiss9f646152008-03-02 21:59:48 +0000339 pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000340 pdebug("Header -> tok_java_package tok_identifier");
341 if (g_parse_mode == PROGRAM) {
David Reiss771f8c72008-02-27 01:55:25 +0000342 g_program->set_namespace("java", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000343 }
344 }
David Reiss54b602b2008-03-27 21:41:06 +0000345/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee7e9eea42007-09-10 21:00:23 +0000346| tok_cocoa_prefix tok_identifier
347 {
David Reiss54b602b2008-03-27 21:41:06 +0000348 pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
Mark Slee7e9eea42007-09-10 21:00:23 +0000349 pdebug("Header -> tok_cocoa_prefix tok_identifier");
350 if (g_parse_mode == PROGRAM) {
David Reiss54b602b2008-03-27 21:41:06 +0000351 g_program->set_namespace("cocoa", $2);
Mark Slee7e9eea42007-09-10 21:00:23 +0000352 }
353 }
David Reiss92e10d82009-02-17 20:28:19 +0000354/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee0d9199e2007-01-31 02:08:30 +0000355| tok_xsd_namespace tok_literal
356 {
David Reiss92e10d82009-02-17 20:28:19 +0000357 pwarning(1, "'xsd_namespace' is deprecated. Use 'namespace xsd' instead");
Mark Slee0d9199e2007-01-31 02:08:30 +0000358 pdebug("Header -> tok_xsd_namespace tok_literal");
359 if (g_parse_mode == PROGRAM) {
David Reiss92e10d82009-02-17 20:28:19 +0000360 g_program->set_namespace("cocoa", $2);
Mark Slee0d9199e2007-01-31 02:08:30 +0000361 }
362 }
David Reiss9d65bf02008-03-27 21:41:37 +0000363/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss7f42bcf2008-01-11 20:59:12 +0000364| tok_csharp_namespace tok_identifier
365 {
David Reiss9d65bf02008-03-27 21:41:37 +0000366 pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead");
David Reiss919ae802008-03-27 21:41:11 +0000367 pdebug("Header -> tok_csharp_namespace tok_identifier");
David Reiss7f42bcf2008-01-11 20:59:12 +0000368 if (g_parse_mode == PROGRAM) {
David Reiss9d65bf02008-03-27 21:41:37 +0000369 g_program->set_namespace("csharp", $2);
David Reiss7f42bcf2008-01-11 20:59:12 +0000370 }
371 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000372
373Include:
374 tok_include tok_literal
375 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000376 pdebug("Include -> tok_include tok_literal");
Mark Sleef0712dc2006-10-25 19:03:57 +0000377 if (g_parse_mode == INCLUDES) {
378 std::string path = include_file(std::string($2));
379 if (!path.empty()) {
kholst76f2c882008-01-16 02:47:41 +0000380 g_program->add_include(path, std::string($2));
Mark Sleef0712dc2006-10-25 19:03:57 +0000381 }
382 }
383 }
Mark Slee31985722006-05-24 21:45:31 +0000384
385DefinitionList:
David Reisscbd4bac2007-08-14 17:12:33 +0000386 DefinitionList CaptureDocText Definition
Mark Slee31985722006-05-24 21:45:31 +0000387 {
388 pdebug("DefinitionList -> DefinitionList Definition");
David Reisscdffe262007-08-14 17:12:31 +0000389 if ($2 != NULL && $3 != NULL) {
390 $3->set_doc($2);
391 }
Mark Slee31985722006-05-24 21:45:31 +0000392 }
393|
394 {
395 pdebug("DefinitionList -> ");
396 }
397
398Definition:
Mark Slee30152872006-11-28 01:24:07 +0000399 Const
400 {
401 pdebug("Definition -> Const");
402 if (g_parse_mode == PROGRAM) {
403 g_program->add_const($1);
Mark Sleebd588222007-11-21 08:43:35 +0000404 }
David Reisscdffe262007-08-14 17:12:31 +0000405 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000406 }
407| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000408 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000409 pdebug("Definition -> TypeDefinition");
410 if (g_parse_mode == PROGRAM) {
411 g_scope->add_type($1->get_name(), $1);
412 if (g_parent_scope != NULL) {
413 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
414 }
415 }
David Reisscdffe262007-08-14 17:12:31 +0000416 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000417 }
Mark Slee31985722006-05-24 21:45:31 +0000418| Service
419 {
420 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000421 if (g_parse_mode == PROGRAM) {
422 g_scope->add_service($1->get_name(), $1);
423 if (g_parent_scope != NULL) {
424 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
425 }
426 g_program->add_service($1);
427 }
David Reisscdffe262007-08-14 17:12:31 +0000428 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000429 }
430
Mark Sleef0712dc2006-10-25 19:03:57 +0000431TypeDefinition:
432 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000433 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000434 pdebug("TypeDefinition -> Typedef");
435 if (g_parse_mode == PROGRAM) {
436 g_program->add_typedef($1);
437 }
438 }
439| Enum
440 {
441 pdebug("TypeDefinition -> Enum");
442 if (g_parse_mode == PROGRAM) {
443 g_program->add_enum($1);
444 }
445 }
Mark Slee6a47fed2007-02-07 02:40:59 +0000446| Senum
447 {
448 pdebug("TypeDefinition -> Senum");
449 if (g_parse_mode == PROGRAM) {
450 g_program->add_typedef($1);
451 }
452 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000453| Struct
454 {
455 pdebug("TypeDefinition -> Struct");
456 if (g_parse_mode == PROGRAM) {
457 g_program->add_struct($1);
458 }
459 }
460| Xception
Mark Slee27ed6ec2007-08-16 01:26:31 +0000461 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000462 pdebug("TypeDefinition -> Xception");
463 if (g_parse_mode == PROGRAM) {
464 g_program->add_xception($1);
465 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000466 }
Mark Slee31985722006-05-24 21:45:31 +0000467
468Typedef:
Mark Sleebd588222007-11-21 08:43:35 +0000469 tok_typedef DefinitionType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000470 {
471 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
David Reisscdffe262007-08-14 17:12:31 +0000472 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000473 $$ = td;
474 }
475
Mark Slee6a47fed2007-02-07 02:40:59 +0000476CommaOrSemicolonOptional:
477 ','
478 {}
479| ';'
480 {}
481|
482 {}
ccheeverf53b5cf2007-02-05 20:33:11 +0000483
Mark Slee31985722006-05-24 21:45:31 +0000484Enum:
David Reisscdffe262007-08-14 17:12:31 +0000485 tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000486 {
487 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000488 $$ = $4;
489 $$->set_name($2);
Mark Slee31985722006-05-24 21:45:31 +0000490 }
491
492EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000493 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000494 {
495 pdebug("EnumDefList -> EnumDefList EnumDef");
496 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000497 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000498 }
499|
500 {
501 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000502 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000503 }
504
505EnumDef:
David Reisscbd4bac2007-08-14 17:12:33 +0000506 CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000507 {
Mark Slee30152872006-11-28 01:24:07 +0000508 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000509 if ($4 < 0) {
510 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000511 }
David Reissf1454162008-06-30 20:45:47 +0000512 if ($4 > INT_MAX) {
513 pwarning(1, "64-bit value supplied for enum %s.\n", $2);
514 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000515 $$ = new t_enum_value($2, $4);
516 if ($1 != NULL) {
517 $$->set_doc($1);
518 }
Mark Sleed0767c52007-07-27 22:14:41 +0000519 if (g_parse_mode == PROGRAM) {
520 g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4)));
521 if (g_parent_scope != NULL) {
522 g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4)));
523 }
524 }
Mark Slee31985722006-05-24 21:45:31 +0000525 }
526|
David Reisscbd4bac2007-08-14 17:12:33 +0000527 CaptureDocText tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000528 {
Mark Slee30152872006-11-28 01:24:07 +0000529 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000530 $$ = new t_enum_value($2);
531 if ($1 != NULL) {
532 $$->set_doc($1);
533 }
Mark Slee30152872006-11-28 01:24:07 +0000534 }
535
Mark Slee6a47fed2007-02-07 02:40:59 +0000536Senum:
David Reisscdffe262007-08-14 17:12:31 +0000537 tok_senum tok_identifier '{' SenumDefList '}'
Mark Slee6a47fed2007-02-07 02:40:59 +0000538 {
539 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000540 $$ = new t_typedef(g_program, $4, $2);
Mark Slee6a47fed2007-02-07 02:40:59 +0000541 }
542
543SenumDefList:
544 SenumDefList SenumDef
545 {
546 pdebug("SenumDefList -> SenumDefList SenumDef");
547 $$ = $1;
548 $$->add_string_enum_val($2);
549 }
550|
551 {
552 pdebug("SenumDefList -> ");
553 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
554 $$->set_string_enum(true);
555 }
556
557SenumDef:
558 tok_literal CommaOrSemicolonOptional
559 {
560 pdebug("SenumDef -> tok_literal");
561 $$ = $1;
562 }
563
Mark Slee30152872006-11-28 01:24:07 +0000564Const:
565 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
566 {
567 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000568 if (g_parse_mode == PROGRAM) {
569 $$ = new t_const($2, $3, $5);
570 validate_const_type($$);
Mark Sleed0767c52007-07-27 22:14:41 +0000571
572 g_scope->add_constant($3, $$);
573 if (g_parent_scope != NULL) {
574 g_parent_scope->add_constant(g_parent_prefix + $3, $$);
575 }
576
Mark Sleeaa7671d2006-11-29 03:19:31 +0000577 } else {
578 $$ = NULL;
579 }
Mark Slee30152872006-11-28 01:24:07 +0000580 }
581
582ConstValue:
583 tok_int_constant
584 {
585 pdebug("ConstValue => tok_int_constant");
586 $$ = new t_const_value();
587 $$->set_integer($1);
David Reissf1454162008-06-30 20:45:47 +0000588 if ($1 < INT32_MIN || $1 > INT32_MAX) {
589 pwarning(1, "64-bit constant \"%"PRIi64"\" may not work in all languages.\n", $1);
590 }
Mark Slee30152872006-11-28 01:24:07 +0000591 }
592| tok_dub_constant
593 {
594 pdebug("ConstValue => tok_dub_constant");
595 $$ = new t_const_value();
596 $$->set_double($1);
597 }
598| tok_literal
599 {
600 pdebug("ConstValue => tok_literal");
Mark Sleed0767c52007-07-27 22:14:41 +0000601 $$ = new t_const_value($1);
Mark Slee30152872006-11-28 01:24:07 +0000602 }
Mark Slee67fc6342006-11-29 03:37:04 +0000603| tok_identifier
604 {
605 pdebug("ConstValue => tok_identifier");
Mark Sleed0767c52007-07-27 22:14:41 +0000606 t_const* constant = g_scope->get_constant($1);
607 if (constant != NULL) {
608 $$ = constant->get_value();
609 } else {
610 if (g_parse_mode == PROGRAM) {
611 pwarning(1, "Constant strings should be quoted: %s\n", $1);
612 }
613 $$ = new t_const_value($1);
614 }
Mark Slee67fc6342006-11-29 03:37:04 +0000615 }
Mark Slee30152872006-11-28 01:24:07 +0000616| ConstList
617 {
618 pdebug("ConstValue => ConstList");
619 $$ = $1;
620 }
621| ConstMap
622 {
623 pdebug("ConstValue => ConstMap");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000624 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000625 }
626
627ConstList:
628 '[' ConstListContents ']'
629 {
630 pdebug("ConstList => [ ConstListContents ]");
631 $$ = $2;
632 }
633
634ConstListContents:
635 ConstListContents ConstValue CommaOrSemicolonOptional
636 {
637 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
638 $$ = $1;
639 $$->add_list($2);
640 }
641|
642 {
643 pdebug("ConstListContents =>");
644 $$ = new t_const_value();
645 $$->set_list();
646 }
647
648ConstMap:
649 '{' ConstMapContents '}'
650 {
651 pdebug("ConstMap => { ConstMapContents }");
652 $$ = $2;
653 }
654
655ConstMapContents:
656 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
657 {
658 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
659 $$ = $1;
660 $$->add_map($2, $4);
661 }
662|
663 {
664 pdebug("ConstMapContents =>");
665 $$ = new t_const_value();
666 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000667 }
668
669Struct:
David Reissa2309992008-12-10 01:52:48 +0000670 tok_struct tok_identifier XsdAll '{' FieldList '}' TypeAnnotations
Mark Slee31985722006-05-24 21:45:31 +0000671 {
672 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
David Reisscdffe262007-08-14 17:12:31 +0000673 $5->set_xsd_all($3);
674 $$ = $5;
David Reissa2309992008-12-10 01:52:48 +0000675 $$->set_name($2);
676 if ($7 != NULL) {
677 $$->annotations_ = $7->annotations_;
678 delete $7;
679 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000680 y_field_val = -1;
681 }
682
Mark Slee36bfa2e2007-01-19 20:09:51 +0000683XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000684 tok_xsd_all
685 {
686 $$ = true;
687 }
688|
689 {
690 $$ = false;
691 }
692
Mark Slee36bfa2e2007-01-19 20:09:51 +0000693XsdOptional:
694 tok_xsd_optional
695 {
696 $$ = true;
697 }
698|
699 {
700 $$ = false;
701 }
702
Mark Slee7df0e2a2007-02-06 21:03:18 +0000703XsdNillable:
704 tok_xsd_nillable
705 {
706 $$ = true;
707 }
708|
709 {
710 $$ = false;
711 }
712
Mark Slee21135c32007-02-05 21:52:08 +0000713XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000714 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000715 {
Mark Slee748d83f2007-02-07 01:20:08 +0000716 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000717 }
718|
719 {
720 $$ = NULL;
721 }
722
Mark Slee9cb7c612006-09-01 22:17:45 +0000723Xception:
724 tok_xception tok_identifier '{' FieldList '}'
725 {
726 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
727 $4->set_name($2);
728 $4->set_xception(true);
729 $$ = $4;
730 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000731 }
732
733Service:
Mark Slee78165722007-09-10 22:08:49 +0000734 tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
Mark Slee31985722006-05-24 21:45:31 +0000735 {
736 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Slee78165722007-09-10 22:08:49 +0000737 $$ = $6;
David Reisscdffe262007-08-14 17:12:31 +0000738 $$->set_name($2);
739 $$->set_extends($3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000740 }
741
Mark Slee78165722007-09-10 22:08:49 +0000742FlagArgs:
743 {
744 g_arglist = 1;
745 }
746
747UnflagArgs:
748 {
749 g_arglist = 0;
750 }
751
Mark Slee36bfa2e2007-01-19 20:09:51 +0000752Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000753 tok_extends tok_identifier
754 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000755 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000756 $$ = NULL;
757 if (g_parse_mode == PROGRAM) {
758 $$ = g_scope->get_service($2);
759 if ($$ == NULL) {
760 yyerror("Service \"%s\" has not been defined.", $2);
761 exit(1);
762 }
763 }
764 }
765|
766 {
767 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000768 }
769
770FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000771 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000772 {
773 pdebug("FunctionList -> FunctionList Function");
774 $$ = $1;
775 $1->add_function($2);
776 }
777|
778 {
779 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000780 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000781 }
782
783Function:
David Reisscbd4bac2007-08-14 17:12:33 +0000784 CaptureDocText Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000785 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000786 $6->set_name(std::string($4) + "_args");
787 $$ = new t_function($3, $4, $6, $8, $2);
788 if ($1 != NULL) {
789 $$->set_doc($1);
790 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000791 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000792 }
793
Mark Slee36bfa2e2007-01-19 20:09:51 +0000794Async:
Mark Slee52f643d2006-08-09 00:03:43 +0000795 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000796 {
Mark Slee52f643d2006-08-09 00:03:43 +0000797 $$ = true;
798 }
799|
800 {
801 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000802 }
803
Mark Slee36bfa2e2007-01-19 20:09:51 +0000804Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000805 tok_throws '(' FieldList ')'
806 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000807 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000808 $$ = $3;
Mark Sleef07d48e2008-02-01 01:36:26 +0000809 if (g_parse_mode == PROGRAM && !validate_throws($$)) {
Mark Slee91f2b7b2008-01-31 01:49:16 +0000810 yyerror("Throws clause may not contain non-exception types");
811 exit(1);
812 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000813 }
814|
815 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000816 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000817 }
818
Mark Slee31985722006-05-24 21:45:31 +0000819FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000820 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000821 {
822 pdebug("FieldList -> FieldList , Field");
823 $$ = $1;
Mark Slee6f9ac3f2007-11-28 22:28:13 +0000824 if (!($$->validate_field($2))) {
825 yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
826 exit(1);
827 }
Mark Slee207cb462006-11-02 18:43:12 +0000828 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000829 }
830|
831 {
832 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000833 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000834 }
835
836Field:
David Reiss8320a922007-08-14 19:59:26 +0000837 CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000838 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000839 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000840 if ($2 < 0) {
David Reiss8320a922007-08-14 19:59:26 +0000841 pwarning(2, "No field key specified for %s, resulting protocol may have conflicts or not be backwards compatible!\n", $5);
Mark Slee31985722006-05-24 21:45:31 +0000842 }
David Reiss8320a922007-08-14 19:59:26 +0000843 $$ = new t_field($4, $5, $2);
844 $$->set_req($3);
845 if ($6 != NULL) {
846 validate_field_value($$, $6);
847 $$->set_value($6);
Mark Slee7ff32452007-02-01 05:26:18 +0000848 }
David Reiss8320a922007-08-14 19:59:26 +0000849 $$->set_xsd_optional($7);
850 $$->set_xsd_nillable($8);
ccheeverf53b5cf2007-02-05 20:33:11 +0000851 if ($1 != NULL) {
852 $$->set_doc($1);
853 }
David Reiss8320a922007-08-14 19:59:26 +0000854 if ($9 != NULL) {
855 $$->set_xsd_attrs($9);
Mark Slee21135c32007-02-05 21:52:08 +0000856 }
Mark Slee31985722006-05-24 21:45:31 +0000857 }
Mark Slee7ff32452007-02-01 05:26:18 +0000858
859FieldIdentifier:
860 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000861 {
Mark Slee7ff32452007-02-01 05:26:18 +0000862 if ($1 <= 0) {
863 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
864 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000865 }
Mark Slee7ff32452007-02-01 05:26:18 +0000866 $$ = $1;
867 }
868|
869 {
870 $$ = y_field_val--;
871 }
872
David Reiss8320a922007-08-14 19:59:26 +0000873FieldRequiredness:
874 tok_required
875 {
Mark Slee78165722007-09-10 22:08:49 +0000876 if (g_arglist) {
877 if (g_parse_mode == PROGRAM) {
878 pwarning(1, "required keyword is ignored in argument lists.\n");
879 }
David Reiss204420f2008-01-11 20:59:03 +0000880 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000881 } else {
David Reiss204420f2008-01-11 20:59:03 +0000882 $$ = t_field::T_REQUIRED;
Mark Slee78165722007-09-10 22:08:49 +0000883 }
David Reiss8320a922007-08-14 19:59:26 +0000884 }
885| tok_optional
886 {
Mark Slee78165722007-09-10 22:08:49 +0000887 if (g_arglist) {
888 if (g_parse_mode == PROGRAM) {
889 pwarning(1, "optional keyword is ignored in argument lists.\n");
890 }
David Reiss204420f2008-01-11 20:59:03 +0000891 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000892 } else {
David Reiss204420f2008-01-11 20:59:03 +0000893 $$ = t_field::T_OPTIONAL;
Mark Slee78165722007-09-10 22:08:49 +0000894 }
David Reiss8320a922007-08-14 19:59:26 +0000895 }
896|
897 {
David Reiss204420f2008-01-11 20:59:03 +0000898 $$ = t_field::T_OPT_IN_REQ_OUT;
David Reiss8320a922007-08-14 19:59:26 +0000899 }
900
Mark Slee7ff32452007-02-01 05:26:18 +0000901FieldValue:
902 '=' ConstValue
903 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000904 if (g_parse_mode == PROGRAM) {
Mark Slee7ff32452007-02-01 05:26:18 +0000905 $$ = $2;
906 } else {
907 $$ = NULL;
908 }
909 }
910|
911 {
912 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000913 }
Mark Slee31985722006-05-24 21:45:31 +0000914
915DefinitionType:
916 BaseType
917 {
918 pdebug("DefinitionType -> BaseType");
919 $$ = $1;
920 }
Mark Sleee8540632006-05-30 09:24:40 +0000921| ContainerType
922 {
923 pdebug("DefinitionType -> ContainerType");
924 $$ = $1;
925 }
Mark Slee31985722006-05-24 21:45:31 +0000926
927FunctionType:
928 FieldType
929 {
Mark Sleee8540632006-05-30 09:24:40 +0000930 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000931 $$ = $1;
932 }
933| tok_void
934 {
Mark Sleee8540632006-05-30 09:24:40 +0000935 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000936 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000937 }
938
939FieldType:
940 tok_identifier
941 {
Mark Sleee8540632006-05-30 09:24:40 +0000942 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000943 if (g_parse_mode == INCLUDES) {
944 // Ignore identifiers in include mode
945 $$ = NULL;
946 } else {
947 // Lookup the identifier in the current scope
948 $$ = g_scope->get_type($1);
949 if ($$ == NULL) {
950 yyerror("Type \"%s\" has not been defined.", $1);
951 exit(1);
952 }
Mark Sleee8540632006-05-30 09:24:40 +0000953 }
Mark Slee31985722006-05-24 21:45:31 +0000954 }
955| BaseType
956 {
Mark Sleee8540632006-05-30 09:24:40 +0000957 pdebug("FieldType -> BaseType");
958 $$ = $1;
959 }
960| ContainerType
961 {
962 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000963 $$ = $1;
964 }
965
966BaseType:
967 tok_string
968 {
969 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000970 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000971 }
Mark Slee8d725a22007-04-13 01:57:12 +0000972| tok_binary
973 {
974 pdebug("BaseType -> tok_binary");
975 $$ = g_type_binary;
976 }
Mark Sleeb6200d82007-01-19 19:14:36 +0000977| tok_slist
978 {
979 pdebug("BaseType -> tok_slist");
980 $$ = g_type_slist;
981 }
Mark Slee78f58e22006-09-02 04:17:07 +0000982| tok_bool
983 {
984 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000985 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000986 }
Mark Slee31985722006-05-24 21:45:31 +0000987| tok_byte
988 {
989 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000990 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000991 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000992| tok_i16
993 {
994 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000995 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000996 }
Mark Slee31985722006-05-24 21:45:31 +0000997| tok_i32
998 {
999 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +00001000 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +00001001 }
Mark Slee31985722006-05-24 21:45:31 +00001002| tok_i64
1003 {
1004 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +00001005 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +00001006 }
Mark Sleec98d0502006-09-06 02:42:25 +00001007| tok_double
1008 {
1009 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +00001010 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +00001011 }
Mark Slee31985722006-05-24 21:45:31 +00001012
David Reissa2309992008-12-10 01:52:48 +00001013ContainerType: SimpleContainerType TypeAnnotations
1014 {
1015 pdebug("ContainerType -> SimpleContainerType TypeAnnotations");
1016 $$ = $1;
1017 if ($2 != NULL) {
1018 $$->annotations_ = $2->annotations_;
1019 delete $2;
1020 }
1021 }
1022
1023SimpleContainerType:
Mark Sleee8540632006-05-30 09:24:40 +00001024 MapType
1025 {
David Reissa2309992008-12-10 01:52:48 +00001026 pdebug("SimpleContainerType -> MapType");
Mark Sleee8540632006-05-30 09:24:40 +00001027 $$ = $1;
1028 }
1029| SetType
1030 {
David Reissa2309992008-12-10 01:52:48 +00001031 pdebug("SimpleContainerType -> SetType");
Mark Sleee8540632006-05-30 09:24:40 +00001032 $$ = $1;
1033 }
1034| ListType
1035 {
David Reissa2309992008-12-10 01:52:48 +00001036 pdebug("SimpleContainerType -> ListType");
Mark Sleee8540632006-05-30 09:24:40 +00001037 $$ = $1;
1038 }
1039
1040MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001041 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001042 {
1043 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001044 $$ = new t_map($4, $6);
1045 if ($2 != NULL) {
1046 ((t_container*)$$)->set_cpp_name(std::string($2));
1047 }
Mark Sleee8540632006-05-30 09:24:40 +00001048 }
1049
1050SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001051 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001052 {
1053 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001054 $$ = new t_set($4);
1055 if ($2 != NULL) {
1056 ((t_container*)$$)->set_cpp_name(std::string($2));
1057 }
Mark Sleee8540632006-05-30 09:24:40 +00001058 }
1059
1060ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001061 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +00001062 {
1063 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +00001064 $$ = new t_list($3);
1065 if ($5 != NULL) {
1066 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +00001067 }
1068 }
1069
Mark Slee36bfa2e2007-01-19 20:09:51 +00001070CppType:
Mark Sleeafc76542007-02-09 21:55:44 +00001071 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +00001072 {
Mark Sleeafc76542007-02-09 21:55:44 +00001073 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +00001074 }
1075|
1076 {
1077 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +00001078 }
1079
David Reissa2309992008-12-10 01:52:48 +00001080TypeAnnotations:
1081 '(' TypeAnnotationList ')'
1082 {
1083 pdebug("TypeAnnotations -> ( TypeAnnotationList )");
1084 $$ = $2;
1085 }
1086|
1087 {
1088 $$ = NULL;
1089 }
1090
1091TypeAnnotationList:
1092 TypeAnnotationList TypeAnnotation
1093 {
1094 pdebug("TypeAnnotationList -> TypeAnnotationList , TypeAnnotation");
1095 $$ = $1;
1096 $$->annotations_[$2->key] = $2->val;
1097 delete $2;
1098 }
1099|
1100 {
1101 /* Just use a dummy structure to hold the annotations. */
1102 $$ = new t_struct(g_program);
1103 }
1104
1105TypeAnnotation:
1106 tok_identifier '=' tok_literal CommaOrSemicolonOptional
1107 {
1108 pdebug("TypeAnnotation -> tok_identifier = tok_literal");
1109 $$ = new t_annotation;
1110 $$->key = $1;
1111 $$->val = $3;
1112 }
1113
Mark Slee31985722006-05-24 21:45:31 +00001114%%