blob: 743fa2c7cf421e278cdedb3f671c19934fd1c6aa [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 *
Mark Slee31985722006-05-24 21:45:31 +000013 */
14
David Reissf1454162008-06-30 20:45:47 +000015#define __STDC_LIMIT_MACROS
16#define __STDC_FORMAT_MACROS
Mark Slee31985722006-05-24 21:45:31 +000017#include <stdio.h>
David Reissf1454162008-06-30 20:45:47 +000018#include <inttypes.h>
David Reiss400a5432008-07-25 19:48:39 +000019#include <limits.h>
Mark Slee31985722006-05-24 21:45:31 +000020#include "main.h"
21#include "globals.h"
22#include "parse/t_program.h"
Mark Sleef0712dc2006-10-25 19:03:57 +000023#include "parse/t_scope.h"
Mark Slee31985722006-05-24 21:45:31 +000024
Mark Sleef5377b32006-10-10 01:42:59 +000025/**
26 * This global variable is used for automatic numbering of field indices etc.
27 * when parsing the members of a struct. Field values are automatically
28 * assigned starting from -1 and working their way down.
29 */
Mark Slee9cb7c612006-09-01 22:17:45 +000030int y_field_val = -1;
Mark Slee78165722007-09-10 22:08:49 +000031int g_arglist = 0;
Mark Slee31985722006-05-24 21:45:31 +000032
33%}
34
Mark Sleef5377b32006-10-10 01:42:59 +000035/**
36 * This structure is used by the parser to hold the data types associated with
37 * various parse nodes.
38 */
Mark Slee31985722006-05-24 21:45:31 +000039%union {
Mark Slee30152872006-11-28 01:24:07 +000040 char* id;
David Reissf1454162008-06-30 20:45:47 +000041 int64_t iconst;
Mark Slee30152872006-11-28 01:24:07 +000042 double dconst;
43 bool tbool;
David Reisscdffe262007-08-14 17:12:31 +000044 t_doc* tdoc;
Mark Slee30152872006-11-28 01:24:07 +000045 t_type* ttype;
Mark Slee6a47fed2007-02-07 02:40:59 +000046 t_base_type* tbase;
Mark Slee30152872006-11-28 01:24:07 +000047 t_typedef* ttypedef;
48 t_enum* tenum;
49 t_enum_value* tenumv;
50 t_const* tconst;
51 t_const_value* tconstv;
52 t_struct* tstruct;
53 t_service* tservice;
54 t_function* tfunction;
55 t_field* tfield;
David Reisscdffe262007-08-14 17:12:31 +000056 char* dtext;
David Reiss8320a922007-08-14 19:59:26 +000057 t_field::e_req ereq;
David Reissa2309992008-12-10 01:52:48 +000058 t_annotation* tannot;
Mark Slee31985722006-05-24 21:45:31 +000059}
60
Mark Sleef5377b32006-10-10 01:42:59 +000061/**
62 * Strings identifier
63 */
Mark Slee31985722006-05-24 21:45:31 +000064%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000065%token<id> tok_literal
David Reisscdffe262007-08-14 17:12:31 +000066%token<dtext> tok_doctext
Mark Sleebd588222007-11-21 08:43:35 +000067%token<id> tok_st_identifier
Mark Sleef5377b32006-10-10 01:42:59 +000068
69/**
Mark Slee30152872006-11-28 01:24:07 +000070 * Constant values
Mark Sleef5377b32006-10-10 01:42:59 +000071 */
Mark Slee31985722006-05-24 21:45:31 +000072%token<iconst> tok_int_constant
Mark Slee30152872006-11-28 01:24:07 +000073%token<dconst> tok_dub_constant
Mark Slee31985722006-05-24 21:45:31 +000074
Mark Sleef5377b32006-10-10 01:42:59 +000075/**
David Reiss399442b2008-02-20 02:28:05 +000076 * Header keywords
Mark Sleef5377b32006-10-10 01:42:59 +000077 */
Mark Sleef0712dc2006-10-25 19:03:57 +000078%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000079%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000080%token tok_cpp_namespace
81%token tok_cpp_include
82%token tok_cpp_type
Mark Sleee888b372007-01-12 01:06:24 +000083%token tok_php_namespace
David Reissc6fc3292007-08-30 00:58:43 +000084%token tok_py_module
Mark Slee27ed6ec2007-08-16 01:26:31 +000085%token tok_perl_package
Mark Sleef0712dc2006-10-25 19:03:57 +000086%token tok_java_package
Mark Slee782abbb2007-01-19 00:17:02 +000087%token tok_xsd_all
Mark Slee36bfa2e2007-01-19 20:09:51 +000088%token tok_xsd_optional
Mark Slee7df0e2a2007-02-06 21:03:18 +000089%token tok_xsd_nillable
Mark Slee0d9199e2007-01-31 02:08:30 +000090%token tok_xsd_namespace
Mark Slee21135c32007-02-05 21:52:08 +000091%token tok_xsd_attrs
Mark Slee58dfb4f2007-07-06 02:45:25 +000092%token tok_ruby_namespace
Mark Sleebd588222007-11-21 08:43:35 +000093%token tok_smalltalk_category
David Reiss15457c92007-12-14 07:03:03 +000094%token tok_smalltalk_prefix
Mark Slee7e9eea42007-09-10 21:00:23 +000095%token tok_cocoa_prefix
David Reiss7f42bcf2008-01-11 20:59:12 +000096%token tok_csharp_namespace
Mark Slee9cb7c612006-09-01 22:17:45 +000097
Mark Sleef5377b32006-10-10 01:42:59 +000098/**
99 * Base datatype keywords
100 */
101%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +0000102%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +0000103%token tok_byte
104%token tok_string
Mark Slee8d725a22007-04-13 01:57:12 +0000105%token tok_binary
Mark Sleeb6200d82007-01-19 19:14:36 +0000106%token tok_slist
Mark Slee6a47fed2007-02-07 02:40:59 +0000107%token tok_senum
Mark Slee9cb7c612006-09-01 22:17:45 +0000108%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +0000109%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +0000110%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +0000111%token tok_double
Mark Slee31985722006-05-24 21:45:31 +0000112
Mark Sleef5377b32006-10-10 01:42:59 +0000113/**
114 * Complex type keywords
115 */
Mark Slee31985722006-05-24 21:45:31 +0000116%token tok_map
117%token tok_list
118%token tok_set
119
Mark Sleef5377b32006-10-10 01:42:59 +0000120/**
121 * Function modifiers
Mark Slee27ed6ec2007-08-16 01:26:31 +0000122 */
Mark Slee31985722006-05-24 21:45:31 +0000123%token tok_async
124
Mark Sleef5377b32006-10-10 01:42:59 +0000125/**
126 * Thrift language keywords
127 */
Mark Slee31985722006-05-24 21:45:31 +0000128%token tok_typedef
129%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000130%token tok_xception
131%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000132%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000133%token tok_service
134%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000135%token tok_const
David Reiss8320a922007-08-14 19:59:26 +0000136%token tok_required
137%token tok_optional
Mark Slee31985722006-05-24 21:45:31 +0000138
Mark Sleef5377b32006-10-10 01:42:59 +0000139/**
140 * Grammar nodes
141 */
142
Mark Slee31985722006-05-24 21:45:31 +0000143%type<ttype> BaseType
Mark Sleee8540632006-05-30 09:24:40 +0000144%type<ttype> ContainerType
David Reissa2309992008-12-10 01:52:48 +0000145%type<ttype> SimpleContainerType
Mark Sleee8540632006-05-30 09:24:40 +0000146%type<ttype> MapType
147%type<ttype> SetType
148%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000149
David Reisscdffe262007-08-14 17:12:31 +0000150%type<tdoc> Definition
Mark Sleef0712dc2006-10-25 19:03:57 +0000151%type<ttype> TypeDefinition
152
Mark Slee31985722006-05-24 21:45:31 +0000153%type<ttypedef> Typedef
154%type<ttype> DefinitionType
155
David Reissa2309992008-12-10 01:52:48 +0000156%type<ttype> TypeAnnotations
157%type<ttype> TypeAnnotationList
158%type<tannot> TypeAnnotation
159
Mark Slee31985722006-05-24 21:45:31 +0000160%type<tfield> Field
Mark Slee7ff32452007-02-01 05:26:18 +0000161%type<iconst> FieldIdentifier
David Reiss8320a922007-08-14 19:59:26 +0000162%type<ereq> FieldRequiredness
Mark Slee31985722006-05-24 21:45:31 +0000163%type<ttype> FieldType
Mark Slee7ff32452007-02-01 05:26:18 +0000164%type<tconstv> FieldValue
Mark Sleee8540632006-05-30 09:24:40 +0000165%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000166
167%type<tenum> Enum
168%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000169%type<tenumv> EnumDef
170
Mark Slee6a47fed2007-02-07 02:40:59 +0000171%type<ttypedef> Senum
172%type<tbase> SenumDefList
173%type<id> SenumDef
174
Mark Slee30152872006-11-28 01:24:07 +0000175%type<tconst> Const
176%type<tconstv> ConstValue
177%type<tconstv> ConstList
178%type<tconstv> ConstListContents
179%type<tconstv> ConstMap
180%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000181
182%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000183%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000184%type<tservice> Service
185
186%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000187%type<ttype> FunctionType
188%type<tservice> FunctionList
189
Mark Slee36bfa2e2007-01-19 20:09:51 +0000190%type<tstruct> Throws
191%type<tservice> Extends
192%type<tbool> Async
193%type<tbool> XsdAll
194%type<tbool> XsdOptional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000195%type<tbool> XsdNillable
Mark Slee748d83f2007-02-07 01:20:08 +0000196%type<tstruct> XsdAttributes
Mark Slee36bfa2e2007-01-19 20:09:51 +0000197%type<id> CppType
Mark Slee52f643d2006-08-09 00:03:43 +0000198
David Reisscbd4bac2007-08-14 17:12:33 +0000199%type<dtext> CaptureDocText
ccheeverf53b5cf2007-02-05 20:33:11 +0000200
Mark Slee31985722006-05-24 21:45:31 +0000201%%
202
Mark Sleef5377b32006-10-10 01:42:59 +0000203/**
204 * Thrift Grammar Implementation.
205 *
206 * For the most part this source file works its way top down from what you
207 * might expect to find in a typical .thrift file, i.e. type definitions and
208 * namespaces up top followed by service definitions using those types.
209 */
Mark Slee31985722006-05-24 21:45:31 +0000210
211Program:
David Reisscbd4bac2007-08-14 17:12:33 +0000212 HeaderList DefinitionList
Mark Sleef0712dc2006-10-25 19:03:57 +0000213 {
214 pdebug("Program -> Headers DefinitionList");
David Reisscbd4bac2007-08-14 17:12:33 +0000215 /*
216 TODO(dreiss): Decide whether full-program doctext is worth the trouble.
David Reissc2532a92007-07-30 23:46:11 +0000217 if ($1 != NULL) {
218 g_program->set_doc($1);
219 }
David Reisscbd4bac2007-08-14 17:12:33 +0000220 */
221 clear_doctext();
Mark Sleef0712dc2006-10-25 19:03:57 +0000222 }
223
David Reisscbd4bac2007-08-14 17:12:33 +0000224CaptureDocText:
225 {
226 if (g_parse_mode == PROGRAM) {
Mark Sleebd588222007-11-21 08:43:35 +0000227 $$ = g_doctext;
David Reisscbd4bac2007-08-14 17:12:33 +0000228 g_doctext = NULL;
Mark Slee27ed6ec2007-08-16 01:26:31 +0000229 } else {
David Reisscbd4bac2007-08-14 17:12:33 +0000230 $$ = NULL;
231 }
232 }
233
234/* TODO(dreiss): Try to DestroyDocText in all sorts or random places. */
235DestroyDocText:
236 {
237 if (g_parse_mode == PROGRAM) {
238 clear_doctext();
239 }
240 }
241
242/* We have to DestroyDocText here, otherwise it catches the doctext
243 on the first real element. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000244HeaderList:
David Reisscbd4bac2007-08-14 17:12:33 +0000245 HeaderList DestroyDocText Header
Mark Sleef0712dc2006-10-25 19:03:57 +0000246 {
247 pdebug("HeaderList -> HeaderList Header");
248 }
249|
250 {
251 pdebug("HeaderList -> ");
252 }
253
254Header:
255 Include
256 {
257 pdebug("Header -> Include");
258 }
David Reiss79eca142008-02-27 01:55:13 +0000259| tok_namespace tok_identifier tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +0000260 {
David Reiss79eca142008-02-27 01:55:13 +0000261 pdebug("Header -> tok_namespace tok_identifier tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000262 if (g_parse_mode == PROGRAM) {
David Reiss79eca142008-02-27 01:55:13 +0000263 g_program->set_namespace($2, $3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000264 }
265 }
David Reiss9a08dc62008-02-27 01:55:17 +0000266/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000267| tok_cpp_namespace tok_identifier
268 {
David Reiss9a08dc62008-02-27 01:55:17 +0000269 pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000270 pdebug("Header -> tok_cpp_namespace tok_identifier");
271 if (g_parse_mode == PROGRAM) {
David Reiss9a08dc62008-02-27 01:55:17 +0000272 g_program->set_namespace("cpp", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000273 }
274 }
275| tok_cpp_include tok_literal
276 {
277 pdebug("Header -> tok_cpp_include tok_literal");
278 if (g_parse_mode == PROGRAM) {
279 g_program->add_cpp_include($2);
280 }
281 }
Mark Sleee888b372007-01-12 01:06:24 +0000282| tok_php_namespace tok_identifier
283 {
David Reiss554ea6f2009-02-17 20:28:37 +0000284 pwarning(1, "'php_namespace' is deprecated. Use 'namespace php' instead");
Mark Sleee888b372007-01-12 01:06:24 +0000285 pdebug("Header -> tok_php_namespace tok_identifier");
286 if (g_parse_mode == PROGRAM) {
David Reiss554ea6f2009-02-17 20:28:37 +0000287 g_program->set_namespace("php", $2);
Mark Sleee888b372007-01-12 01:06:24 +0000288 }
289 }
David Reiss320e45c2008-03-27 21:41:54 +0000290/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reissc6fc3292007-08-30 00:58:43 +0000291| tok_py_module tok_identifier
292 {
David Reiss320e45c2008-03-27 21:41:54 +0000293 pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead");
David Reissc6fc3292007-08-30 00:58:43 +0000294 pdebug("Header -> tok_py_module tok_identifier");
295 if (g_parse_mode == PROGRAM) {
David Reiss320e45c2008-03-27 21:41:54 +0000296 g_program->set_namespace("py", $2);
David Reissc6fc3292007-08-30 00:58:43 +0000297 }
298 }
David Reiss07ef3a92008-03-27 21:42:39 +0000299/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee27ed6ec2007-08-16 01:26:31 +0000300| tok_perl_package tok_identifier
301 {
David Reiss07ef3a92008-03-27 21:42:39 +0000302 pwarning(1, "'perl_package' is deprecated. Use 'namespace perl' instead");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000303 pdebug("Header -> tok_perl_namespace tok_identifier");
304 if (g_parse_mode == PROGRAM) {
David Reiss07ef3a92008-03-27 21:42:39 +0000305 g_program->set_namespace("perl", $2);
Mark Slee27ed6ec2007-08-16 01:26:31 +0000306 }
307 }
David Reiss6a4b82c2008-03-27 21:42:16 +0000308/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee58dfb4f2007-07-06 02:45:25 +0000309| tok_ruby_namespace tok_identifier
310 {
David Reiss6a4b82c2008-03-27 21:42:16 +0000311 pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead");
Mark Slee58dfb4f2007-07-06 02:45:25 +0000312 pdebug("Header -> tok_ruby_namespace tok_identifier");
313 if (g_parse_mode == PROGRAM) {
David Reiss6a4b82c2008-03-27 21:42:16 +0000314 g_program->set_namespace("rb", $2);
Mark Slee58dfb4f2007-07-06 02:45:25 +0000315 }
316 }
David Reiss3b455012008-03-27 21:40:46 +0000317/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleebd588222007-11-21 08:43:35 +0000318| tok_smalltalk_category tok_st_identifier
319 {
David Reiss3b455012008-03-27 21:40:46 +0000320 pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
Mark Sleebd588222007-11-21 08:43:35 +0000321 pdebug("Header -> tok_smalltalk_category tok_st_identifier");
322 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000323 g_program->set_namespace("smalltalk.category", $2);
Mark Sleebd588222007-11-21 08:43:35 +0000324 }
325 }
David Reiss3b455012008-03-27 21:40:46 +0000326/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss15457c92007-12-14 07:03:03 +0000327| tok_smalltalk_prefix tok_identifier
328 {
David Reiss3b455012008-03-27 21:40:46 +0000329 pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
David Reiss15457c92007-12-14 07:03:03 +0000330 pdebug("Header -> tok_smalltalk_prefix tok_identifier");
331 if (g_parse_mode == PROGRAM) {
David Reiss3b455012008-03-27 21:40:46 +0000332 g_program->set_namespace("smalltalk.prefix", $2);
David Reiss15457c92007-12-14 07:03:03 +0000333 }
334 }
David Reiss771f8c72008-02-27 01:55:25 +0000335/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Sleef0712dc2006-10-25 19:03:57 +0000336| tok_java_package tok_identifier
337 {
David Reiss9f646152008-03-02 21:59:48 +0000338 pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000339 pdebug("Header -> tok_java_package tok_identifier");
340 if (g_parse_mode == PROGRAM) {
David Reiss771f8c72008-02-27 01:55:25 +0000341 g_program->set_namespace("java", $2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000342 }
343 }
David Reiss54b602b2008-03-27 21:41:06 +0000344/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee7e9eea42007-09-10 21:00:23 +0000345| tok_cocoa_prefix tok_identifier
346 {
David Reiss54b602b2008-03-27 21:41:06 +0000347 pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
Mark Slee7e9eea42007-09-10 21:00:23 +0000348 pdebug("Header -> tok_cocoa_prefix tok_identifier");
349 if (g_parse_mode == PROGRAM) {
David Reiss54b602b2008-03-27 21:41:06 +0000350 g_program->set_namespace("cocoa", $2);
Mark Slee7e9eea42007-09-10 21:00:23 +0000351 }
352 }
David Reiss92e10d82009-02-17 20:28:19 +0000353/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
Mark Slee0d9199e2007-01-31 02:08:30 +0000354| tok_xsd_namespace tok_literal
355 {
David Reiss92e10d82009-02-17 20:28:19 +0000356 pwarning(1, "'xsd_namespace' is deprecated. Use 'namespace xsd' instead");
Mark Slee0d9199e2007-01-31 02:08:30 +0000357 pdebug("Header -> tok_xsd_namespace tok_literal");
358 if (g_parse_mode == PROGRAM) {
David Reiss92e10d82009-02-17 20:28:19 +0000359 g_program->set_namespace("cocoa", $2);
Mark Slee0d9199e2007-01-31 02:08:30 +0000360 }
361 }
David Reiss9d65bf02008-03-27 21:41:37 +0000362/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
David Reiss7f42bcf2008-01-11 20:59:12 +0000363| tok_csharp_namespace tok_identifier
364 {
David Reiss9d65bf02008-03-27 21:41:37 +0000365 pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead");
David Reiss919ae802008-03-27 21:41:11 +0000366 pdebug("Header -> tok_csharp_namespace tok_identifier");
David Reiss7f42bcf2008-01-11 20:59:12 +0000367 if (g_parse_mode == PROGRAM) {
David Reiss9d65bf02008-03-27 21:41:37 +0000368 g_program->set_namespace("csharp", $2);
David Reiss7f42bcf2008-01-11 20:59:12 +0000369 }
370 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000371
372Include:
373 tok_include tok_literal
374 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000375 pdebug("Include -> tok_include tok_literal");
Mark Sleef0712dc2006-10-25 19:03:57 +0000376 if (g_parse_mode == INCLUDES) {
377 std::string path = include_file(std::string($2));
378 if (!path.empty()) {
kholst76f2c882008-01-16 02:47:41 +0000379 g_program->add_include(path, std::string($2));
Mark Sleef0712dc2006-10-25 19:03:57 +0000380 }
381 }
382 }
Mark Slee31985722006-05-24 21:45:31 +0000383
384DefinitionList:
David Reisscbd4bac2007-08-14 17:12:33 +0000385 DefinitionList CaptureDocText Definition
Mark Slee31985722006-05-24 21:45:31 +0000386 {
387 pdebug("DefinitionList -> DefinitionList Definition");
David Reisscdffe262007-08-14 17:12:31 +0000388 if ($2 != NULL && $3 != NULL) {
389 $3->set_doc($2);
390 }
Mark Slee31985722006-05-24 21:45:31 +0000391 }
392|
393 {
394 pdebug("DefinitionList -> ");
395 }
396
397Definition:
Mark Slee30152872006-11-28 01:24:07 +0000398 Const
399 {
400 pdebug("Definition -> Const");
401 if (g_parse_mode == PROGRAM) {
402 g_program->add_const($1);
Mark Sleebd588222007-11-21 08:43:35 +0000403 }
David Reisscdffe262007-08-14 17:12:31 +0000404 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000405 }
406| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000407 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000408 pdebug("Definition -> TypeDefinition");
409 if (g_parse_mode == PROGRAM) {
410 g_scope->add_type($1->get_name(), $1);
411 if (g_parent_scope != NULL) {
412 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
413 }
414 }
David Reisscdffe262007-08-14 17:12:31 +0000415 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000416 }
Mark Slee31985722006-05-24 21:45:31 +0000417| Service
418 {
419 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000420 if (g_parse_mode == PROGRAM) {
421 g_scope->add_service($1->get_name(), $1);
422 if (g_parent_scope != NULL) {
423 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
424 }
425 g_program->add_service($1);
426 }
David Reisscdffe262007-08-14 17:12:31 +0000427 $$ = $1;
Mark Slee9cb7c612006-09-01 22:17:45 +0000428 }
429
Mark Sleef0712dc2006-10-25 19:03:57 +0000430TypeDefinition:
431 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000432 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000433 pdebug("TypeDefinition -> Typedef");
434 if (g_parse_mode == PROGRAM) {
435 g_program->add_typedef($1);
436 }
437 }
438| Enum
439 {
440 pdebug("TypeDefinition -> Enum");
441 if (g_parse_mode == PROGRAM) {
442 g_program->add_enum($1);
443 }
444 }
Mark Slee6a47fed2007-02-07 02:40:59 +0000445| Senum
446 {
447 pdebug("TypeDefinition -> Senum");
448 if (g_parse_mode == PROGRAM) {
449 g_program->add_typedef($1);
450 }
451 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000452| Struct
453 {
454 pdebug("TypeDefinition -> Struct");
455 if (g_parse_mode == PROGRAM) {
456 g_program->add_struct($1);
457 }
458 }
459| Xception
Mark Slee27ed6ec2007-08-16 01:26:31 +0000460 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000461 pdebug("TypeDefinition -> Xception");
462 if (g_parse_mode == PROGRAM) {
463 g_program->add_xception($1);
464 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000465 }
Mark Slee31985722006-05-24 21:45:31 +0000466
467Typedef:
Mark Sleebd588222007-11-21 08:43:35 +0000468 tok_typedef DefinitionType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000469 {
470 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
David Reisscdffe262007-08-14 17:12:31 +0000471 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000472 $$ = td;
473 }
474
Mark Slee6a47fed2007-02-07 02:40:59 +0000475CommaOrSemicolonOptional:
476 ','
477 {}
478| ';'
479 {}
480|
481 {}
ccheeverf53b5cf2007-02-05 20:33:11 +0000482
Mark Slee31985722006-05-24 21:45:31 +0000483Enum:
David Reisscdffe262007-08-14 17:12:31 +0000484 tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000485 {
486 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000487 $$ = $4;
488 $$->set_name($2);
Mark Slee31985722006-05-24 21:45:31 +0000489 }
490
491EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000492 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000493 {
494 pdebug("EnumDefList -> EnumDefList EnumDef");
495 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000496 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000497 }
498|
499 {
500 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000501 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000502 }
503
504EnumDef:
David Reisscbd4bac2007-08-14 17:12:33 +0000505 CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000506 {
Mark Slee30152872006-11-28 01:24:07 +0000507 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000508 if ($4 < 0) {
509 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000510 }
David Reissf1454162008-06-30 20:45:47 +0000511 if ($4 > INT_MAX) {
512 pwarning(1, "64-bit value supplied for enum %s.\n", $2);
513 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000514 $$ = new t_enum_value($2, $4);
515 if ($1 != NULL) {
516 $$->set_doc($1);
517 }
Mark Sleed0767c52007-07-27 22:14:41 +0000518 if (g_parse_mode == PROGRAM) {
519 g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4)));
520 if (g_parent_scope != NULL) {
521 g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4)));
522 }
523 }
Mark Slee31985722006-05-24 21:45:31 +0000524 }
525|
David Reisscbd4bac2007-08-14 17:12:33 +0000526 CaptureDocText tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000527 {
Mark Slee30152872006-11-28 01:24:07 +0000528 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000529 $$ = new t_enum_value($2);
530 if ($1 != NULL) {
531 $$->set_doc($1);
532 }
Mark Slee30152872006-11-28 01:24:07 +0000533 }
534
Mark Slee6a47fed2007-02-07 02:40:59 +0000535Senum:
David Reisscdffe262007-08-14 17:12:31 +0000536 tok_senum tok_identifier '{' SenumDefList '}'
Mark Slee6a47fed2007-02-07 02:40:59 +0000537 {
538 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
David Reisscdffe262007-08-14 17:12:31 +0000539 $$ = new t_typedef(g_program, $4, $2);
Mark Slee6a47fed2007-02-07 02:40:59 +0000540 }
541
542SenumDefList:
543 SenumDefList SenumDef
544 {
545 pdebug("SenumDefList -> SenumDefList SenumDef");
546 $$ = $1;
547 $$->add_string_enum_val($2);
548 }
549|
550 {
551 pdebug("SenumDefList -> ");
552 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
553 $$->set_string_enum(true);
554 }
555
556SenumDef:
557 tok_literal CommaOrSemicolonOptional
558 {
559 pdebug("SenumDef -> tok_literal");
560 $$ = $1;
561 }
562
Mark Slee30152872006-11-28 01:24:07 +0000563Const:
564 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
565 {
566 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000567 if (g_parse_mode == PROGRAM) {
568 $$ = new t_const($2, $3, $5);
569 validate_const_type($$);
Mark Sleed0767c52007-07-27 22:14:41 +0000570
571 g_scope->add_constant($3, $$);
572 if (g_parent_scope != NULL) {
573 g_parent_scope->add_constant(g_parent_prefix + $3, $$);
574 }
575
Mark Sleeaa7671d2006-11-29 03:19:31 +0000576 } else {
577 $$ = NULL;
578 }
Mark Slee30152872006-11-28 01:24:07 +0000579 }
580
581ConstValue:
582 tok_int_constant
583 {
584 pdebug("ConstValue => tok_int_constant");
585 $$ = new t_const_value();
586 $$->set_integer($1);
David Reissf1454162008-06-30 20:45:47 +0000587 if ($1 < INT32_MIN || $1 > INT32_MAX) {
588 pwarning(1, "64-bit constant \"%"PRIi64"\" may not work in all languages.\n", $1);
589 }
Mark Slee30152872006-11-28 01:24:07 +0000590 }
591| tok_dub_constant
592 {
593 pdebug("ConstValue => tok_dub_constant");
594 $$ = new t_const_value();
595 $$->set_double($1);
596 }
597| tok_literal
598 {
599 pdebug("ConstValue => tok_literal");
Mark Sleed0767c52007-07-27 22:14:41 +0000600 $$ = new t_const_value($1);
Mark Slee30152872006-11-28 01:24:07 +0000601 }
Mark Slee67fc6342006-11-29 03:37:04 +0000602| tok_identifier
603 {
604 pdebug("ConstValue => tok_identifier");
Mark Sleed0767c52007-07-27 22:14:41 +0000605 t_const* constant = g_scope->get_constant($1);
606 if (constant != NULL) {
607 $$ = constant->get_value();
608 } else {
609 if (g_parse_mode == PROGRAM) {
610 pwarning(1, "Constant strings should be quoted: %s\n", $1);
611 }
612 $$ = new t_const_value($1);
613 }
Mark Slee67fc6342006-11-29 03:37:04 +0000614 }
Mark Slee30152872006-11-28 01:24:07 +0000615| ConstList
616 {
617 pdebug("ConstValue => ConstList");
618 $$ = $1;
619 }
620| ConstMap
621 {
622 pdebug("ConstValue => ConstMap");
Mark Slee27ed6ec2007-08-16 01:26:31 +0000623 $$ = $1;
Mark Slee30152872006-11-28 01:24:07 +0000624 }
625
626ConstList:
627 '[' ConstListContents ']'
628 {
629 pdebug("ConstList => [ ConstListContents ]");
630 $$ = $2;
631 }
632
633ConstListContents:
634 ConstListContents ConstValue CommaOrSemicolonOptional
635 {
636 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
637 $$ = $1;
638 $$->add_list($2);
639 }
640|
641 {
642 pdebug("ConstListContents =>");
643 $$ = new t_const_value();
644 $$->set_list();
645 }
646
647ConstMap:
648 '{' ConstMapContents '}'
649 {
650 pdebug("ConstMap => { ConstMapContents }");
651 $$ = $2;
652 }
653
654ConstMapContents:
655 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
656 {
657 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
658 $$ = $1;
659 $$->add_map($2, $4);
660 }
661|
662 {
663 pdebug("ConstMapContents =>");
664 $$ = new t_const_value();
665 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000666 }
667
668Struct:
David Reissa2309992008-12-10 01:52:48 +0000669 tok_struct tok_identifier XsdAll '{' FieldList '}' TypeAnnotations
Mark Slee31985722006-05-24 21:45:31 +0000670 {
671 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
David Reisscdffe262007-08-14 17:12:31 +0000672 $5->set_xsd_all($3);
673 $$ = $5;
David Reissa2309992008-12-10 01:52:48 +0000674 $$->set_name($2);
675 if ($7 != NULL) {
676 $$->annotations_ = $7->annotations_;
677 delete $7;
678 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000679 }
680
Mark Slee36bfa2e2007-01-19 20:09:51 +0000681XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000682 tok_xsd_all
683 {
684 $$ = true;
685 }
686|
687 {
688 $$ = false;
689 }
690
Mark Slee36bfa2e2007-01-19 20:09:51 +0000691XsdOptional:
692 tok_xsd_optional
693 {
694 $$ = true;
695 }
696|
697 {
698 $$ = false;
699 }
700
Mark Slee7df0e2a2007-02-06 21:03:18 +0000701XsdNillable:
702 tok_xsd_nillable
703 {
704 $$ = true;
705 }
706|
707 {
708 $$ = false;
709 }
710
Mark Slee21135c32007-02-05 21:52:08 +0000711XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000712 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000713 {
Mark Slee748d83f2007-02-07 01:20:08 +0000714 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000715 }
716|
717 {
718 $$ = NULL;
719 }
720
Mark Slee9cb7c612006-09-01 22:17:45 +0000721Xception:
722 tok_xception tok_identifier '{' FieldList '}'
723 {
724 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
725 $4->set_name($2);
726 $4->set_xception(true);
727 $$ = $4;
Mark Slee31985722006-05-24 21:45:31 +0000728 }
729
730Service:
Mark Slee78165722007-09-10 22:08:49 +0000731 tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
Mark Slee31985722006-05-24 21:45:31 +0000732 {
733 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Slee78165722007-09-10 22:08:49 +0000734 $$ = $6;
David Reisscdffe262007-08-14 17:12:31 +0000735 $$->set_name($2);
736 $$->set_extends($3);
Mark Sleef0712dc2006-10-25 19:03:57 +0000737 }
738
Mark Slee78165722007-09-10 22:08:49 +0000739FlagArgs:
740 {
741 g_arglist = 1;
742 }
743
744UnflagArgs:
745 {
746 g_arglist = 0;
747 }
748
Mark Slee36bfa2e2007-01-19 20:09:51 +0000749Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000750 tok_extends tok_identifier
751 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000752 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000753 $$ = NULL;
754 if (g_parse_mode == PROGRAM) {
755 $$ = g_scope->get_service($2);
756 if ($$ == NULL) {
757 yyerror("Service \"%s\" has not been defined.", $2);
758 exit(1);
759 }
760 }
761 }
762|
763 {
764 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000765 }
766
767FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000768 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000769 {
770 pdebug("FunctionList -> FunctionList Function");
771 $$ = $1;
772 $1->add_function($2);
773 }
774|
775 {
776 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000777 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000778 }
779
780Function:
David Reisscbd4bac2007-08-14 17:12:33 +0000781 CaptureDocText Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000782 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000783 $6->set_name(std::string($4) + "_args");
784 $$ = new t_function($3, $4, $6, $8, $2);
785 if ($1 != NULL) {
786 $$->set_doc($1);
787 }
Mark Slee31985722006-05-24 21:45:31 +0000788 }
789
Mark Slee36bfa2e2007-01-19 20:09:51 +0000790Async:
Mark Slee52f643d2006-08-09 00:03:43 +0000791 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000792 {
Mark Slee52f643d2006-08-09 00:03:43 +0000793 $$ = true;
794 }
795|
796 {
797 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000798 }
799
Mark Slee36bfa2e2007-01-19 20:09:51 +0000800Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000801 tok_throws '(' FieldList ')'
802 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000803 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000804 $$ = $3;
Mark Sleef07d48e2008-02-01 01:36:26 +0000805 if (g_parse_mode == PROGRAM && !validate_throws($$)) {
Mark Slee91f2b7b2008-01-31 01:49:16 +0000806 yyerror("Throws clause may not contain non-exception types");
807 exit(1);
808 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000809 }
810|
811 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000812 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000813 }
814
Mark Slee31985722006-05-24 21:45:31 +0000815FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000816 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000817 {
818 pdebug("FieldList -> FieldList , Field");
819 $$ = $1;
Mark Slee6f9ac3f2007-11-28 22:28:13 +0000820 if (!($$->validate_field($2))) {
821 yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
822 exit(1);
823 }
Mark Slee207cb462006-11-02 18:43:12 +0000824 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000825 }
826|
827 {
828 pdebug("FieldList -> ");
David Reiss00a8dd62009-03-19 08:14:12 +0000829 y_field_val = -1;
Mark Sleef0712dc2006-10-25 19:03:57 +0000830 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000831 }
832
833Field:
David Reiss8320a922007-08-14 19:59:26 +0000834 CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000835 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000836 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000837 if ($2 < 0) {
David Reiss8320a922007-08-14 19:59:26 +0000838 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 +0000839 }
David Reiss8320a922007-08-14 19:59:26 +0000840 $$ = new t_field($4, $5, $2);
841 $$->set_req($3);
842 if ($6 != NULL) {
843 validate_field_value($$, $6);
844 $$->set_value($6);
Mark Slee7ff32452007-02-01 05:26:18 +0000845 }
David Reiss8320a922007-08-14 19:59:26 +0000846 $$->set_xsd_optional($7);
847 $$->set_xsd_nillable($8);
ccheeverf53b5cf2007-02-05 20:33:11 +0000848 if ($1 != NULL) {
849 $$->set_doc($1);
850 }
David Reiss8320a922007-08-14 19:59:26 +0000851 if ($9 != NULL) {
852 $$->set_xsd_attrs($9);
Mark Slee21135c32007-02-05 21:52:08 +0000853 }
Mark Slee31985722006-05-24 21:45:31 +0000854 }
Mark Slee7ff32452007-02-01 05:26:18 +0000855
856FieldIdentifier:
857 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000858 {
Mark Slee7ff32452007-02-01 05:26:18 +0000859 if ($1 <= 0) {
860 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
861 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000862 }
Mark Slee7ff32452007-02-01 05:26:18 +0000863 $$ = $1;
864 }
865|
866 {
867 $$ = y_field_val--;
868 }
869
David Reiss8320a922007-08-14 19:59:26 +0000870FieldRequiredness:
871 tok_required
872 {
Mark Slee78165722007-09-10 22:08:49 +0000873 if (g_arglist) {
874 if (g_parse_mode == PROGRAM) {
875 pwarning(1, "required keyword is ignored in argument lists.\n");
876 }
David Reiss204420f2008-01-11 20:59:03 +0000877 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000878 } else {
David Reiss204420f2008-01-11 20:59:03 +0000879 $$ = t_field::T_REQUIRED;
Mark Slee78165722007-09-10 22:08:49 +0000880 }
David Reiss8320a922007-08-14 19:59:26 +0000881 }
882| tok_optional
883 {
Mark Slee78165722007-09-10 22:08:49 +0000884 if (g_arglist) {
885 if (g_parse_mode == PROGRAM) {
886 pwarning(1, "optional keyword is ignored in argument lists.\n");
887 }
David Reiss204420f2008-01-11 20:59:03 +0000888 $$ = t_field::T_OPT_IN_REQ_OUT;
Mark Slee78165722007-09-10 22:08:49 +0000889 } else {
David Reiss204420f2008-01-11 20:59:03 +0000890 $$ = t_field::T_OPTIONAL;
Mark Slee78165722007-09-10 22:08:49 +0000891 }
David Reiss8320a922007-08-14 19:59:26 +0000892 }
893|
894 {
David Reiss204420f2008-01-11 20:59:03 +0000895 $$ = t_field::T_OPT_IN_REQ_OUT;
David Reiss8320a922007-08-14 19:59:26 +0000896 }
897
Mark Slee7ff32452007-02-01 05:26:18 +0000898FieldValue:
899 '=' ConstValue
900 {
Mark Slee27ed6ec2007-08-16 01:26:31 +0000901 if (g_parse_mode == PROGRAM) {
Mark Slee7ff32452007-02-01 05:26:18 +0000902 $$ = $2;
903 } else {
904 $$ = NULL;
905 }
906 }
907|
908 {
909 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000910 }
Mark Slee31985722006-05-24 21:45:31 +0000911
912DefinitionType:
913 BaseType
914 {
915 pdebug("DefinitionType -> BaseType");
916 $$ = $1;
917 }
Mark Sleee8540632006-05-30 09:24:40 +0000918| ContainerType
919 {
920 pdebug("DefinitionType -> ContainerType");
921 $$ = $1;
922 }
Mark Slee31985722006-05-24 21:45:31 +0000923
924FunctionType:
925 FieldType
926 {
Mark Sleee8540632006-05-30 09:24:40 +0000927 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000928 $$ = $1;
929 }
930| tok_void
931 {
Mark Sleee8540632006-05-30 09:24:40 +0000932 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000933 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000934 }
935
936FieldType:
937 tok_identifier
938 {
Mark Sleee8540632006-05-30 09:24:40 +0000939 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000940 if (g_parse_mode == INCLUDES) {
941 // Ignore identifiers in include mode
942 $$ = NULL;
943 } else {
944 // Lookup the identifier in the current scope
945 $$ = g_scope->get_type($1);
946 if ($$ == NULL) {
947 yyerror("Type \"%s\" has not been defined.", $1);
948 exit(1);
949 }
Mark Sleee8540632006-05-30 09:24:40 +0000950 }
Mark Slee31985722006-05-24 21:45:31 +0000951 }
952| BaseType
953 {
Mark Sleee8540632006-05-30 09:24:40 +0000954 pdebug("FieldType -> BaseType");
955 $$ = $1;
956 }
957| ContainerType
958 {
959 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000960 $$ = $1;
961 }
962
963BaseType:
964 tok_string
965 {
966 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000967 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000968 }
Mark Slee8d725a22007-04-13 01:57:12 +0000969| tok_binary
970 {
971 pdebug("BaseType -> tok_binary");
972 $$ = g_type_binary;
973 }
Mark Sleeb6200d82007-01-19 19:14:36 +0000974| tok_slist
975 {
976 pdebug("BaseType -> tok_slist");
977 $$ = g_type_slist;
978 }
Mark Slee78f58e22006-09-02 04:17:07 +0000979| tok_bool
980 {
981 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000982 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000983 }
Mark Slee31985722006-05-24 21:45:31 +0000984| tok_byte
985 {
986 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000987 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000988 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000989| tok_i16
990 {
991 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000992 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000993 }
Mark Slee31985722006-05-24 21:45:31 +0000994| tok_i32
995 {
996 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000997 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000998 }
Mark Slee31985722006-05-24 21:45:31 +0000999| tok_i64
1000 {
1001 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +00001002 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +00001003 }
Mark Sleec98d0502006-09-06 02:42:25 +00001004| tok_double
1005 {
1006 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +00001007 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +00001008 }
Mark Slee31985722006-05-24 21:45:31 +00001009
David Reissa2309992008-12-10 01:52:48 +00001010ContainerType: SimpleContainerType TypeAnnotations
1011 {
1012 pdebug("ContainerType -> SimpleContainerType TypeAnnotations");
1013 $$ = $1;
1014 if ($2 != NULL) {
1015 $$->annotations_ = $2->annotations_;
1016 delete $2;
1017 }
1018 }
1019
1020SimpleContainerType:
Mark Sleee8540632006-05-30 09:24:40 +00001021 MapType
1022 {
David Reissa2309992008-12-10 01:52:48 +00001023 pdebug("SimpleContainerType -> MapType");
Mark Sleee8540632006-05-30 09:24:40 +00001024 $$ = $1;
1025 }
1026| SetType
1027 {
David Reissa2309992008-12-10 01:52:48 +00001028 pdebug("SimpleContainerType -> SetType");
Mark Sleee8540632006-05-30 09:24:40 +00001029 $$ = $1;
1030 }
1031| ListType
1032 {
David Reissa2309992008-12-10 01:52:48 +00001033 pdebug("SimpleContainerType -> ListType");
Mark Sleee8540632006-05-30 09:24:40 +00001034 $$ = $1;
1035 }
1036
1037MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001038 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001039 {
1040 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001041 $$ = new t_map($4, $6);
1042 if ($2 != NULL) {
1043 ((t_container*)$$)->set_cpp_name(std::string($2));
1044 }
Mark Sleee8540632006-05-30 09:24:40 +00001045 }
1046
1047SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001048 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +00001049 {
1050 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +00001051 $$ = new t_set($4);
1052 if ($2 != NULL) {
1053 ((t_container*)$$)->set_cpp_name(std::string($2));
1054 }
Mark Sleee8540632006-05-30 09:24:40 +00001055 }
1056
1057ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +00001058 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +00001059 {
1060 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +00001061 $$ = new t_list($3);
1062 if ($5 != NULL) {
1063 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +00001064 }
1065 }
1066
Mark Slee36bfa2e2007-01-19 20:09:51 +00001067CppType:
Mark Sleeafc76542007-02-09 21:55:44 +00001068 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +00001069 {
Mark Sleeafc76542007-02-09 21:55:44 +00001070 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +00001071 }
1072|
1073 {
1074 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +00001075 }
1076
David Reissa2309992008-12-10 01:52:48 +00001077TypeAnnotations:
1078 '(' TypeAnnotationList ')'
1079 {
1080 pdebug("TypeAnnotations -> ( TypeAnnotationList )");
1081 $$ = $2;
1082 }
1083|
1084 {
1085 $$ = NULL;
1086 }
1087
1088TypeAnnotationList:
1089 TypeAnnotationList TypeAnnotation
1090 {
1091 pdebug("TypeAnnotationList -> TypeAnnotationList , TypeAnnotation");
1092 $$ = $1;
1093 $$->annotations_[$2->key] = $2->val;
1094 delete $2;
1095 }
1096|
1097 {
1098 /* Just use a dummy structure to hold the annotations. */
1099 $$ = new t_struct(g_program);
1100 }
1101
1102TypeAnnotation:
1103 tok_identifier '=' tok_literal CommaOrSemicolonOptional
1104 {
1105 pdebug("TypeAnnotation -> tok_identifier = tok_literal");
1106 $$ = new t_annotation;
1107 $$->key = $1;
1108 $$->val = $3;
1109 }
1110
Mark Slee31985722006-05-24 21:45:31 +00001111%%