James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 1 | %code requires { |
| 2 | #include "thrift/parse/t_program.h" |
| 3 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 4 | %{ |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 5 | /* |
| 6 | * Licensed to the Apache Software Foundation (ASF) under one |
| 7 | * or more contributor license agreements. See the NOTICE file |
| 8 | * distributed with this work for additional information |
| 9 | * regarding copyright ownership. The ASF licenses this file |
| 10 | * to you under the Apache License, Version 2.0 (the |
| 11 | * "License"); you may not use this file except in compliance |
| 12 | * with the License. You may obtain a copy of the License at |
| 13 | * |
| 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | * |
| 16 | * Unless required by applicable law or agreed to in writing, |
| 17 | * software distributed under the License is distributed on an |
| 18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 19 | * KIND, either express or implied. See the License for the |
| 20 | * specific language governing permissions and limitations |
| 21 | * under the License. |
| 22 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Thrift parser. |
| 26 | * |
| 27 | * This parser is used on a thrift definition file. |
| 28 | * |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 31 | #ifndef __STDC_LIMIT_MACROS |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 32 | #define __STDC_LIMIT_MACROS |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 33 | #endif |
| 34 | #ifndef __STDC_FORMAT_MACROS |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 35 | #define __STDC_FORMAT_MACROS |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 36 | #endif |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 37 | #include <stdio.h> |
James E. King III | 860a5f1 | 2018-03-06 14:23:23 -0500 | [diff] [blame] | 38 | #include <string.h> |
Roger Meier | 12d7053 | 2011-12-14 23:35:28 +0000 | [diff] [blame] | 39 | #ifndef _MSC_VER |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 40 | #include <inttypes.h> |
Roger Meier | 12d7053 | 2011-12-14 23:35:28 +0000 | [diff] [blame] | 41 | #else |
| 42 | #include <stdint.h> |
| 43 | #endif |
David Reiss | 400a543 | 2008-07-25 19:48:39 +0000 | [diff] [blame] | 44 | #include <limits.h> |
Ben Craig | e957675 | 2013-10-11 08:19:16 -0500 | [diff] [blame] | 45 | #ifdef _MSC_VER |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 46 | #include "thrift/windows/config.h" |
Ben Craig | e957675 | 2013-10-11 08:19:16 -0500 | [diff] [blame] | 47 | #endif |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 48 | #include "thrift/main.h" |
| 49 | #include "thrift/common.h" |
| 50 | #include "thrift/globals.h" |
| 51 | #include "thrift/parse/t_program.h" |
| 52 | #include "thrift/parse/t_scope.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 53 | |
Ben Craig | e957675 | 2013-10-11 08:19:16 -0500 | [diff] [blame] | 54 | #ifdef _MSC_VER |
| 55 | //warning C4065: switch statement contains 'default' but no 'case' labels |
| 56 | #pragma warning(disable:4065) |
| 57 | #endif |
| 58 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 59 | /** |
| 60 | * This global variable is used for automatic numbering of field indices etc. |
| 61 | * when parsing the members of a struct. Field values are automatically |
| 62 | * assigned starting from -1 and working their way down. |
| 63 | */ |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 64 | int y_field_val = -1; |
Jens Geyer | ae0b22c | 2014-09-04 23:04:21 +0200 | [diff] [blame] | 65 | /** |
| 66 | * This global variable is used for automatic numbering of enum values. |
| 67 | * y_enum_val is the last value assigned; the next auto-assigned value will be |
| 68 | * y_enum_val+1, and then it continues working upwards. Explicitly specified |
| 69 | * enum values reset y_enum_val to that value. |
| 70 | */ |
| 71 | int32_t y_enum_val = -1; |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 72 | int g_arglist = 0; |
Bryan Duxbury | ab3666e | 2009-09-01 23:03:47 +0000 | [diff] [blame] | 73 | const int struct_is_struct = 0; |
| 74 | const int struct_is_union = 1; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 75 | |
| 76 | %} |
| 77 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 78 | /** |
| 79 | * This structure is used by the parser to hold the data types associated with |
| 80 | * various parse nodes. |
| 81 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 82 | %union { |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 83 | char* id; |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 84 | int64_t iconst; |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 85 | double dconst; |
| 86 | bool tbool; |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 87 | t_doc* tdoc; |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 88 | t_type* ttype; |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 89 | t_base_type* tbase; |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 90 | t_typedef* ttypedef; |
| 91 | t_enum* tenum; |
| 92 | t_enum_value* tenumv; |
| 93 | t_const* tconst; |
| 94 | t_const_value* tconstv; |
| 95 | t_struct* tstruct; |
| 96 | t_service* tservice; |
| 97 | t_function* tfunction; |
| 98 | t_field* tfield; |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 99 | char* dtext; |
Jens Geyer | 154d154 | 2022-09-10 14:30:15 +0200 | [diff] [blame] | 100 | char* keyword; |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 101 | t_field::e_req ereq; |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 102 | t_annotation* tannot; |
Bryan Duxbury | c7206a4 | 2011-08-17 23:17:04 +0000 | [diff] [blame] | 103 | t_field_id tfieldid; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 106 | /** |
| 107 | * Strings identifier |
| 108 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 109 | %token<id> tok_identifier |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 110 | %token<id> tok_literal |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 111 | %token<dtext> tok_doctext |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 112 | |
| 113 | /** |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 114 | * Constant values |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 115 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 116 | %token<iconst> tok_int_constant |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 117 | %token<dconst> tok_dub_constant |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 118 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 119 | /** |
David Reiss | 399442b | 2008-02-20 02:28:05 +0000 | [diff] [blame] | 120 | * Header keywords |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 121 | */ |
Jens Geyer | 154d154 | 2022-09-10 14:30:15 +0200 | [diff] [blame] | 122 | %token<keyword> tok_include |
| 123 | %token<keyword> tok_namespace |
| 124 | %token<keyword> tok_cpp_include |
| 125 | %token<keyword> tok_cpp_type |
| 126 | %token<keyword> tok_xsd_all |
| 127 | %token<keyword> tok_xsd_optional |
| 128 | %token<keyword> tok_xsd_nillable |
| 129 | %token<keyword> tok_xsd_attrs |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 130 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 131 | /** |
| 132 | * Base datatype keywords |
| 133 | */ |
Jens Geyer | 154d154 | 2022-09-10 14:30:15 +0200 | [diff] [blame] | 134 | %token<keyword> tok_void |
| 135 | %token<keyword> tok_bool |
| 136 | %token<keyword> tok_string |
| 137 | %token<keyword> tok_binary |
| 138 | %token<keyword> tok_uuid |
| 139 | %token<keyword> tok_byte |
| 140 | %token<keyword> tok_i8 |
| 141 | %token<keyword> tok_i16 |
| 142 | %token<keyword> tok_i32 |
| 143 | %token<keyword> tok_i64 |
| 144 | %token<keyword> tok_double |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 145 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 146 | /** |
| 147 | * Complex type keywords |
| 148 | */ |
Jens Geyer | 154d154 | 2022-09-10 14:30:15 +0200 | [diff] [blame] | 149 | %token<keyword> tok_map |
| 150 | %token<keyword> tok_list |
| 151 | %token<keyword> tok_set |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 152 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 153 | /** |
| 154 | * Function modifiers |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 155 | */ |
Jens Geyer | 154d154 | 2022-09-10 14:30:15 +0200 | [diff] [blame] | 156 | %token<keyword> tok_oneway |
| 157 | %token<keyword> tok_async |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 158 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 159 | /** |
| 160 | * Thrift language keywords |
| 161 | */ |
Jens Geyer | 154d154 | 2022-09-10 14:30:15 +0200 | [diff] [blame] | 162 | %token<keyword> tok_typedef |
| 163 | %token<keyword> tok_struct |
| 164 | %token<keyword> tok_xception |
| 165 | %token<keyword> tok_throws |
| 166 | %token<keyword> tok_extends |
| 167 | %token<keyword> tok_service |
| 168 | %token<keyword> tok_enum |
| 169 | %token<keyword> tok_const |
| 170 | %token<keyword> tok_required |
| 171 | %token<keyword> tok_optional |
| 172 | %token<keyword> tok_union |
| 173 | %token<keyword> tok_reference |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 174 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 175 | /** |
| 176 | * Grammar nodes |
| 177 | */ |
| 178 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 179 | %type<ttype> BaseType |
David Reiss | c8e3005 | 2009-07-27 17:02:42 +0000 | [diff] [blame] | 180 | %type<ttype> SimpleBaseType |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 181 | %type<ttype> ContainerType |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 182 | %type<ttype> SimpleContainerType |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 183 | %type<ttype> MapType |
| 184 | %type<ttype> SetType |
| 185 | %type<ttype> ListType |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 186 | |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 187 | %type<tdoc> Definition |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 188 | %type<ttype> TypeDefinition |
| 189 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 190 | %type<ttypedef> Typedef |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 191 | |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 192 | %type<ttype> TypeAnnotations |
| 193 | %type<ttype> TypeAnnotationList |
| 194 | %type<tannot> TypeAnnotation |
Jens Geyer | 89847df | 2014-05-02 23:50:04 +0200 | [diff] [blame] | 195 | %type<id> TypeAnnotationValue |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 196 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 197 | %type<tfield> Field |
Bryan Duxbury | c7206a4 | 2011-08-17 23:17:04 +0000 | [diff] [blame] | 198 | %type<tfieldid> FieldIdentifier |
Jens Geyer | 154d154 | 2022-09-10 14:30:15 +0200 | [diff] [blame] | 199 | %type<id> FieldName |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 200 | %type<ereq> FieldRequiredness |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 201 | %type<ttype> FieldType |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 202 | %type<tconstv> FieldValue |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 203 | %type<tstruct> FieldList |
Jens Geyer | 885c679 | 2014-05-02 21:31:55 +0200 | [diff] [blame] | 204 | %type<tbool> FieldReference |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 205 | |
| 206 | %type<tenum> Enum |
| 207 | %type<tenum> EnumDefList |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 208 | %type<tenumv> EnumDef |
Jens Geyer | ae0b22c | 2014-09-04 23:04:21 +0200 | [diff] [blame] | 209 | %type<tenumv> EnumValue |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 210 | |
| 211 | %type<tconst> Const |
| 212 | %type<tconstv> ConstValue |
| 213 | %type<tconstv> ConstList |
| 214 | %type<tconstv> ConstListContents |
| 215 | %type<tconstv> ConstMap |
| 216 | %type<tconstv> ConstMapContents |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 217 | |
Bryan Duxbury | ab3666e | 2009-09-01 23:03:47 +0000 | [diff] [blame] | 218 | %type<iconst> StructHead |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 219 | %type<tstruct> Struct |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 220 | %type<tstruct> Xception |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 221 | %type<tservice> Service |
| 222 | |
| 223 | %type<tfunction> Function |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 224 | %type<ttype> FunctionType |
| 225 | %type<tservice> FunctionList |
| 226 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 227 | %type<tstruct> Throws |
| 228 | %type<tservice> Extends |
David Reiss | 6985a42 | 2009-03-24 20:00:47 +0000 | [diff] [blame] | 229 | %type<tbool> Oneway |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 230 | %type<tbool> XsdAll |
| 231 | %type<tbool> XsdOptional |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 232 | %type<tbool> XsdNillable |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 233 | %type<tstruct> XsdAttributes |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 234 | %type<id> CppType |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 235 | |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 236 | %type<dtext> CaptureDocText |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 237 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 238 | %% |
| 239 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 240 | /** |
| 241 | * Thrift Grammar Implementation. |
| 242 | * |
| 243 | * For the most part this source file works its way top down from what you |
| 244 | * might expect to find in a typical .thrift file, i.e. type definitions and |
| 245 | * namespaces up top followed by service definitions using those types. |
| 246 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 247 | |
| 248 | Program: |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 249 | HeaderList DefinitionList |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 250 | { |
| 251 | pdebug("Program -> Headers DefinitionList"); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 252 | if((g_program_doctext_candidate != nullptr) && (g_program_doctext_status != ALREADY_PROCESSED)) |
Jens Geyer | e8379b5 | 2014-01-25 00:59:45 +0100 | [diff] [blame] | 253 | { |
| 254 | g_program->set_doc(g_program_doctext_candidate); |
| 255 | g_program_doctext_status = ALREADY_PROCESSED; |
David Reiss | c2532a9 | 2007-07-30 23:46:11 +0000 | [diff] [blame] | 256 | } |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 257 | clear_doctext(); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 258 | } |
| 259 | |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 260 | CaptureDocText: |
| 261 | { |
| 262 | if (g_parse_mode == PROGRAM) { |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 263 | $$ = g_doctext; |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 264 | g_doctext = nullptr; |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 265 | } else { |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 266 | $$ = nullptr; |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
| 270 | /* TODO(dreiss): Try to DestroyDocText in all sorts or random places. */ |
| 271 | DestroyDocText: |
| 272 | { |
| 273 | if (g_parse_mode == PROGRAM) { |
| 274 | clear_doctext(); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | /* We have to DestroyDocText here, otherwise it catches the doctext |
| 279 | on the first real element. */ |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 280 | HeaderList: |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 281 | HeaderList DestroyDocText Header |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 282 | { |
| 283 | pdebug("HeaderList -> HeaderList Header"); |
| 284 | } |
| 285 | | |
| 286 | { |
| 287 | pdebug("HeaderList -> "); |
| 288 | } |
| 289 | |
| 290 | Header: |
| 291 | Include |
| 292 | { |
| 293 | pdebug("Header -> Include"); |
| 294 | } |
BCG | cc193c1 | 2015-11-12 21:02:51 -0500 | [diff] [blame] | 295 | | tok_namespace tok_identifier tok_identifier TypeAnnotations |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 296 | { |
David Reiss | 79eca14 | 2008-02-27 01:55:13 +0000 | [diff] [blame] | 297 | pdebug("Header -> tok_namespace tok_identifier tok_identifier"); |
Roger Meier | 4f4b15b | 2014-11-05 16:51:04 +0100 | [diff] [blame] | 298 | declare_valid_program_doctext(); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 299 | if (g_parse_mode == PROGRAM) { |
David Reiss | 79eca14 | 2008-02-27 01:55:13 +0000 | [diff] [blame] | 300 | g_program->set_namespace($2, $3); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 301 | } |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 302 | if ($4 != nullptr) { |
BCG | cc193c1 | 2015-11-12 21:02:51 -0500 | [diff] [blame] | 303 | g_program->set_namespace_annotations($2, $4->annotations_); |
| 304 | delete $4; |
| 305 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 306 | } |
David Reiss | fb790d7 | 2010-09-02 16:41:45 +0000 | [diff] [blame] | 307 | | tok_namespace '*' tok_identifier |
| 308 | { |
| 309 | pdebug("Header -> tok_namespace * tok_identifier"); |
Roger Meier | 4f4b15b | 2014-11-05 16:51:04 +0100 | [diff] [blame] | 310 | declare_valid_program_doctext(); |
David Reiss | fb790d7 | 2010-09-02 16:41:45 +0000 | [diff] [blame] | 311 | if (g_parse_mode == PROGRAM) { |
| 312 | g_program->set_namespace("*", $3); |
| 313 | } |
| 314 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 315 | | tok_cpp_include tok_literal |
| 316 | { |
| 317 | pdebug("Header -> tok_cpp_include tok_literal"); |
Roger Meier | 4f4b15b | 2014-11-05 16:51:04 +0100 | [diff] [blame] | 318 | declare_valid_program_doctext(); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 319 | if (g_parse_mode == PROGRAM) { |
| 320 | g_program->add_cpp_include($2); |
| 321 | } |
| 322 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 323 | |
| 324 | Include: |
| 325 | tok_include tok_literal |
| 326 | { |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 327 | pdebug("Include -> tok_include tok_literal"); |
Roger Meier | 4f4b15b | 2014-11-05 16:51:04 +0100 | [diff] [blame] | 328 | declare_valid_program_doctext(); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 329 | if (g_parse_mode == INCLUDES) { |
| 330 | std::string path = include_file(std::string($2)); |
| 331 | if (!path.empty()) { |
kholst | 76f2c88 | 2008-01-16 02:47:41 +0000 | [diff] [blame] | 332 | g_program->add_include(path, std::string($2)); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 336 | |
| 337 | DefinitionList: |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 338 | DefinitionList CaptureDocText Definition |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 339 | { |
| 340 | pdebug("DefinitionList -> DefinitionList Definition"); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 341 | if ($2 != nullptr && $3 != nullptr) { |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 342 | $3->set_doc($2); |
| 343 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 344 | } |
| 345 | | |
| 346 | { |
| 347 | pdebug("DefinitionList -> "); |
| 348 | } |
| 349 | |
| 350 | Definition: |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 351 | Const |
| 352 | { |
| 353 | pdebug("Definition -> Const"); |
| 354 | if (g_parse_mode == PROGRAM) { |
| 355 | g_program->add_const($1); |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 356 | } |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 357 | $$ = $1; |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 358 | } |
| 359 | | TypeDefinition |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 360 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 361 | pdebug("Definition -> TypeDefinition"); |
| 362 | if (g_parse_mode == PROGRAM) { |
| 363 | g_scope->add_type($1->get_name(), $1); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 364 | if (g_parent_scope != nullptr) { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 365 | g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1); |
| 366 | } |
Roger Meier | ba406d3 | 2013-07-15 22:41:34 +0200 | [diff] [blame] | 367 | if (! g_program->is_unique_typename($1)) { |
| 368 | yyerror("Type \"%s\" is already defined.", $1->get_name().c_str()); |
| 369 | exit(1); |
| 370 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 371 | } |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 372 | $$ = $1; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 373 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 374 | | Service |
| 375 | { |
| 376 | pdebug("Definition -> Service"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 377 | if (g_parse_mode == PROGRAM) { |
| 378 | g_scope->add_service($1->get_name(), $1); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 379 | if (g_parent_scope != nullptr) { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 380 | g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1); |
| 381 | } |
| 382 | g_program->add_service($1); |
Roger Meier | ba406d3 | 2013-07-15 22:41:34 +0200 | [diff] [blame] | 383 | if (! g_program->is_unique_typename($1)) { |
| 384 | yyerror("Type \"%s\" is already defined.", $1->get_name().c_str()); |
| 385 | exit(1); |
| 386 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 387 | } |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 388 | $$ = $1; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 391 | TypeDefinition: |
| 392 | Typedef |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 393 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 394 | pdebug("TypeDefinition -> Typedef"); |
| 395 | if (g_parse_mode == PROGRAM) { |
| 396 | g_program->add_typedef($1); |
| 397 | } |
| 398 | } |
| 399 | | Enum |
| 400 | { |
| 401 | pdebug("TypeDefinition -> Enum"); |
| 402 | if (g_parse_mode == PROGRAM) { |
| 403 | g_program->add_enum($1); |
| 404 | } |
| 405 | } |
| 406 | | Struct |
| 407 | { |
| 408 | pdebug("TypeDefinition -> Struct"); |
| 409 | if (g_parse_mode == PROGRAM) { |
| 410 | g_program->add_struct($1); |
| 411 | } |
| 412 | } |
| 413 | | Xception |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 414 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 415 | pdebug("TypeDefinition -> Xception"); |
| 416 | if (g_parse_mode == PROGRAM) { |
| 417 | g_program->add_xception($1); |
| 418 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 419 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 420 | |
Jens Geyer | 089bcd3 | 2014-09-11 22:36:41 +0200 | [diff] [blame] | 421 | CommaOrSemicolonOptional: |
| 422 | ',' |
| 423 | {} |
| 424 | | ';' |
| 425 | {} |
| 426 | | |
| 427 | {} |
| 428 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 429 | Typedef: |
Jens Geyer | 089bcd3 | 2014-09-11 22:36:41 +0200 | [diff] [blame] | 430 | tok_typedef FieldType tok_identifier TypeAnnotations CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 431 | { |
David Reiss | 4dd7801 | 2010-03-09 05:19:08 +0000 | [diff] [blame] | 432 | pdebug("TypeDef -> tok_typedef FieldType tok_identifier"); |
Jens Geyer | 12c09f4 | 2013-08-25 14:16:27 +0200 | [diff] [blame] | 433 | validate_simple_identifier( $3); |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 434 | t_typedef *td = new t_typedef(g_program, $2, $3); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 435 | $$ = td; |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 436 | if ($4 != nullptr) { |
Roger Meier | 3087738 | 2012-09-17 21:18:05 +0000 | [diff] [blame] | 437 | $$->annotations_ = $4->annotations_; |
| 438 | delete $4; |
| 439 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | Enum: |
Roger Meier | 3087738 | 2012-09-17 21:18:05 +0000 | [diff] [blame] | 443 | tok_enum tok_identifier '{' EnumDefList '}' TypeAnnotations |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 444 | { |
| 445 | pdebug("Enum -> tok_enum tok_identifier { EnumDefList }"); |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 446 | $$ = $4; |
Jens Geyer | 12c09f4 | 2013-08-25 14:16:27 +0200 | [diff] [blame] | 447 | validate_simple_identifier( $2); |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 448 | $$->set_name($2); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 449 | if ($6 != nullptr) { |
Roger Meier | 3087738 | 2012-09-17 21:18:05 +0000 | [diff] [blame] | 450 | $$->annotations_ = $6->annotations_; |
| 451 | delete $6; |
| 452 | } |
Jens Geyer | ae0b22c | 2014-09-04 23:04:21 +0200 | [diff] [blame] | 453 | |
Bryan Duxbury | 9f0a786 | 2010-09-12 14:38:36 +0000 | [diff] [blame] | 454 | // make constants for all the enum values |
| 455 | if (g_parse_mode == PROGRAM) { |
| 456 | const std::vector<t_enum_value*>& enum_values = $$->get_constants(); |
| 457 | std::vector<t_enum_value*>::const_iterator c_iter; |
| 458 | for (c_iter = enum_values.begin(); c_iter != enum_values.end(); ++c_iter) { |
| 459 | std::string const_name = $$->get_name() + "." + (*c_iter)->get_name(); |
| 460 | t_const_value* const_val = new t_const_value((*c_iter)->get_value()); |
| 461 | const_val->set_enum($$); |
| 462 | g_scope->add_constant(const_name, new t_const(g_type_i32, (*c_iter)->get_name(), const_val)); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 463 | if (g_parent_scope != nullptr) { |
Bryan Duxbury | 9f0a786 | 2010-09-12 14:38:36 +0000 | [diff] [blame] | 464 | g_parent_scope->add_constant(g_parent_prefix + const_name, new t_const(g_type_i32, (*c_iter)->get_name(), const_val)); |
| 465 | } |
| 466 | } |
| 467 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | EnumDefList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 471 | EnumDefList EnumDef |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 472 | { |
| 473 | pdebug("EnumDefList -> EnumDefList EnumDef"); |
| 474 | $$ = $1; |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 475 | $$->append($2); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 476 | } |
| 477 | | |
| 478 | { |
| 479 | pdebug("EnumDefList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 480 | $$ = new t_enum(g_program); |
Jens Geyer | ae0b22c | 2014-09-04 23:04:21 +0200 | [diff] [blame] | 481 | y_enum_val = -1; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | EnumDef: |
Jens Geyer | ae0b22c | 2014-09-04 23:04:21 +0200 | [diff] [blame] | 485 | CaptureDocText EnumValue TypeAnnotations CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 486 | { |
Jens Geyer | ae0b22c | 2014-09-04 23:04:21 +0200 | [diff] [blame] | 487 | pdebug("EnumDef -> EnumValue"); |
| 488 | $$ = $2; |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 489 | if ($1 != nullptr) { |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 490 | $$->set_doc($1); |
| 491 | } |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 492 | if ($3 != nullptr) { |
Roger Meier | 3087738 | 2012-09-17 21:18:05 +0000 | [diff] [blame] | 493 | $$->annotations_ = $3->annotations_; |
| 494 | delete $3; |
| 495 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Jens Geyer | ae0b22c | 2014-09-04 23:04:21 +0200 | [diff] [blame] | 498 | EnumValue: |
| 499 | tok_identifier '=' tok_int_constant |
| 500 | { |
| 501 | pdebug("EnumValue -> tok_identifier = tok_int_constant"); |
| 502 | if ($3 < INT32_MIN || $3 > INT32_MAX) { |
| 503 | // Note: this used to be just a warning. However, since thrift always |
| 504 | // treats enums as i32 values, I'm changing it to a fatal error. |
| 505 | // I doubt this will affect many people, but users who run into this |
| 506 | // will have to update their thrift files to manually specify the |
| 507 | // truncated i32 value that thrift has always been using anyway. |
| 508 | failure("64-bit value supplied for enum %s will be truncated.", $1); |
| 509 | } |
| 510 | y_enum_val = static_cast<int32_t>($3); |
| 511 | $$ = new t_enum_value($1, y_enum_val); |
| 512 | } |
| 513 | | |
| 514 | tok_identifier |
| 515 | { |
| 516 | pdebug("EnumValue -> tok_identifier"); |
| 517 | validate_simple_identifier( $1); |
| 518 | if (y_enum_val == INT32_MAX) { |
| 519 | failure("enum value overflow at enum %s", $1); |
| 520 | } |
| 521 | ++y_enum_val; |
| 522 | $$ = new t_enum_value($1, y_enum_val); |
| 523 | } |
| 524 | |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 525 | Const: |
| 526 | tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional |
| 527 | { |
| 528 | pdebug("Const -> tok_const FieldType tok_identifier = ConstValue"); |
Mark Slee | aa7671d | 2006-11-29 03:19:31 +0000 | [diff] [blame] | 529 | if (g_parse_mode == PROGRAM) { |
Jens Geyer | 12c09f4 | 2013-08-25 14:16:27 +0200 | [diff] [blame] | 530 | validate_simple_identifier( $3); |
Bryan Duxbury | 2d80470 | 2009-12-18 19:41:11 +0000 | [diff] [blame] | 531 | g_scope->resolve_const_value($5, $2); |
Mark Slee | aa7671d | 2006-11-29 03:19:31 +0000 | [diff] [blame] | 532 | $$ = new t_const($2, $3, $5); |
| 533 | validate_const_type($$); |
Mark Slee | d0767c5 | 2007-07-27 22:14:41 +0000 | [diff] [blame] | 534 | |
| 535 | g_scope->add_constant($3, $$); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 536 | if (g_parent_scope != nullptr) { |
Mark Slee | d0767c5 | 2007-07-27 22:14:41 +0000 | [diff] [blame] | 537 | g_parent_scope->add_constant(g_parent_prefix + $3, $$); |
| 538 | } |
Mark Slee | aa7671d | 2006-11-29 03:19:31 +0000 | [diff] [blame] | 539 | } else { |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 540 | $$ = nullptr; |
Mark Slee | aa7671d | 2006-11-29 03:19:31 +0000 | [diff] [blame] | 541 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | ConstValue: |
| 545 | tok_int_constant |
| 546 | { |
| 547 | pdebug("ConstValue => tok_int_constant"); |
| 548 | $$ = new t_const_value(); |
| 549 | $$->set_integer($1); |
Roger Meier | 887ff75 | 2011-08-19 11:25:39 +0000 | [diff] [blame] | 550 | if (!g_allow_64bit_consts && ($1 < INT32_MIN || $1 > INT32_MAX)) { |
Roger Meier | 5f2d34e | 2013-11-16 16:43:41 +0100 | [diff] [blame] | 551 | pwarning(1, "64-bit constant \"%" PRIi64"\" may not work in all languages.\n", $1); |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 552 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 553 | } |
| 554 | | tok_dub_constant |
| 555 | { |
| 556 | pdebug("ConstValue => tok_dub_constant"); |
| 557 | $$ = new t_const_value(); |
| 558 | $$->set_double($1); |
| 559 | } |
| 560 | | tok_literal |
| 561 | { |
| 562 | pdebug("ConstValue => tok_literal"); |
Mark Slee | d0767c5 | 2007-07-27 22:14:41 +0000 | [diff] [blame] | 563 | $$ = new t_const_value($1); |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 564 | } |
Mark Slee | 67fc634 | 2006-11-29 03:37:04 +0000 | [diff] [blame] | 565 | | tok_identifier |
| 566 | { |
| 567 | pdebug("ConstValue => tok_identifier"); |
Bryan Duxbury | 2d80470 | 2009-12-18 19:41:11 +0000 | [diff] [blame] | 568 | $$ = new t_const_value(); |
| 569 | $$->set_identifier($1); |
Mark Slee | 67fc634 | 2006-11-29 03:37:04 +0000 | [diff] [blame] | 570 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 571 | | ConstList |
| 572 | { |
| 573 | pdebug("ConstValue => ConstList"); |
| 574 | $$ = $1; |
| 575 | } |
| 576 | | ConstMap |
| 577 | { |
| 578 | pdebug("ConstValue => ConstMap"); |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 579 | $$ = $1; |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | ConstList: |
| 583 | '[' ConstListContents ']' |
| 584 | { |
| 585 | pdebug("ConstList => [ ConstListContents ]"); |
| 586 | $$ = $2; |
| 587 | } |
| 588 | |
| 589 | ConstListContents: |
| 590 | ConstListContents ConstValue CommaOrSemicolonOptional |
| 591 | { |
| 592 | pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional"); |
| 593 | $$ = $1; |
| 594 | $$->add_list($2); |
| 595 | } |
| 596 | | |
| 597 | { |
| 598 | pdebug("ConstListContents =>"); |
| 599 | $$ = new t_const_value(); |
| 600 | $$->set_list(); |
| 601 | } |
| 602 | |
| 603 | ConstMap: |
| 604 | '{' ConstMapContents '}' |
| 605 | { |
| 606 | pdebug("ConstMap => { ConstMapContents }"); |
| 607 | $$ = $2; |
| 608 | } |
| 609 | |
| 610 | ConstMapContents: |
| 611 | ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional |
| 612 | { |
| 613 | pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional"); |
| 614 | $$ = $1; |
| 615 | $$->add_map($2, $4); |
| 616 | } |
| 617 | | |
| 618 | { |
| 619 | pdebug("ConstMapContents =>"); |
| 620 | $$ = new t_const_value(); |
| 621 | $$->set_map(); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Bryan Duxbury | ab3666e | 2009-09-01 23:03:47 +0000 | [diff] [blame] | 624 | StructHead: |
| 625 | tok_struct |
| 626 | { |
| 627 | $$ = struct_is_struct; |
| 628 | } |
| 629 | | tok_union |
| 630 | { |
| 631 | $$ = struct_is_union; |
| 632 | } |
| 633 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 634 | Struct: |
Bryan Duxbury | ab3666e | 2009-09-01 23:03:47 +0000 | [diff] [blame] | 635 | StructHead tok_identifier XsdAll '{' FieldList '}' TypeAnnotations |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 636 | { |
| 637 | pdebug("Struct -> tok_struct tok_identifier { FieldList }"); |
Jens Geyer | 12c09f4 | 2013-08-25 14:16:27 +0200 | [diff] [blame] | 638 | validate_simple_identifier( $2); |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 639 | $5->set_xsd_all($3); |
Bryan Duxbury | ab3666e | 2009-09-01 23:03:47 +0000 | [diff] [blame] | 640 | $5->set_union($1 == struct_is_union); |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 641 | $$ = $5; |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 642 | $$->set_name($2); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 643 | if ($7 != nullptr) { |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 644 | $$->annotations_ = $7->annotations_; |
| 645 | delete $7; |
| 646 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 647 | } |
Ben Craig | e957675 | 2013-10-11 08:19:16 -0500 | [diff] [blame] | 648 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 649 | XsdAll: |
Mark Slee | 782abbb | 2007-01-19 00:17:02 +0000 | [diff] [blame] | 650 | tok_xsd_all |
| 651 | { |
| 652 | $$ = true; |
| 653 | } |
| 654 | | |
| 655 | { |
| 656 | $$ = false; |
| 657 | } |
| 658 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 659 | XsdOptional: |
| 660 | tok_xsd_optional |
| 661 | { |
| 662 | $$ = true; |
| 663 | } |
| 664 | | |
| 665 | { |
| 666 | $$ = false; |
| 667 | } |
| 668 | |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 669 | XsdNillable: |
| 670 | tok_xsd_nillable |
| 671 | { |
| 672 | $$ = true; |
| 673 | } |
| 674 | | |
| 675 | { |
| 676 | $$ = false; |
| 677 | } |
| 678 | |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 679 | XsdAttributes: |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 680 | tok_xsd_attrs '{' FieldList '}' |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 681 | { |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 682 | $$ = $3; |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 683 | } |
| 684 | | |
| 685 | { |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 686 | $$ = nullptr; |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 689 | Xception: |
Roger Meier | 3087738 | 2012-09-17 21:18:05 +0000 | [diff] [blame] | 690 | tok_xception tok_identifier '{' FieldList '}' TypeAnnotations |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 691 | { |
| 692 | pdebug("Xception -> tok_xception tok_identifier { FieldList }"); |
Jens Geyer | 12c09f4 | 2013-08-25 14:16:27 +0200 | [diff] [blame] | 693 | validate_simple_identifier( $2); |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 694 | $4->set_name($2); |
| 695 | $4->set_xception(true); |
| 696 | $$ = $4; |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 697 | if ($6 != nullptr) { |
Roger Meier | 3087738 | 2012-09-17 21:18:05 +0000 | [diff] [blame] | 698 | $$->annotations_ = $6->annotations_; |
| 699 | delete $6; |
| 700 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | Service: |
Roger Meier | 3087738 | 2012-09-17 21:18:05 +0000 | [diff] [blame] | 704 | tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}' TypeAnnotations |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 705 | { |
| 706 | pdebug("Service -> tok_service tok_identifier { FunctionList }"); |
Jens Geyer | 12c09f4 | 2013-08-25 14:16:27 +0200 | [diff] [blame] | 707 | validate_simple_identifier( $2); |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 708 | $$ = $6; |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 709 | $$->set_name($2); |
| 710 | $$->set_extends($3); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 711 | if ($9 != nullptr) { |
Roger Meier | 3087738 | 2012-09-17 21:18:05 +0000 | [diff] [blame] | 712 | $$->annotations_ = $9->annotations_; |
| 713 | delete $9; |
| 714 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 715 | } |
| 716 | |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 717 | FlagArgs: |
| 718 | { |
| 719 | g_arglist = 1; |
| 720 | } |
| 721 | |
| 722 | UnflagArgs: |
| 723 | { |
| 724 | g_arglist = 0; |
| 725 | } |
| 726 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 727 | Extends: |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 728 | tok_extends tok_identifier |
| 729 | { |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 730 | pdebug("Extends -> tok_extends tok_identifier"); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 731 | $$ = nullptr; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 732 | if (g_parse_mode == PROGRAM) { |
| 733 | $$ = g_scope->get_service($2); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 734 | if ($$ == nullptr) { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 735 | yyerror("Service \"%s\" has not been defined.", $2); |
| 736 | exit(1); |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | | |
| 741 | { |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 742 | $$ = nullptr; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | FunctionList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 746 | FunctionList Function |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 747 | { |
| 748 | pdebug("FunctionList -> FunctionList Function"); |
| 749 | $$ = $1; |
| 750 | $1->add_function($2); |
| 751 | } |
| 752 | | |
| 753 | { |
| 754 | pdebug("FunctionList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 755 | $$ = new t_service(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | Function: |
Roger Meier | 3087738 | 2012-09-17 21:18:05 +0000 | [diff] [blame] | 759 | CaptureDocText Oneway FunctionType tok_identifier '(' FieldList ')' Throws TypeAnnotations CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 760 | { |
Jens Geyer | 12c09f4 | 2013-08-25 14:16:27 +0200 | [diff] [blame] | 761 | validate_simple_identifier( $4); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 762 | $6->set_name(std::string($4) + "_args"); |
| 763 | $$ = new t_function($3, $4, $6, $8, $2); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 764 | if ($1 != nullptr) { |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 765 | $$->set_doc($1); |
| 766 | } |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 767 | if ($9 != nullptr) { |
Roger Meier | 3087738 | 2012-09-17 21:18:05 +0000 | [diff] [blame] | 768 | $$->annotations_ = $9->annotations_; |
| 769 | delete $9; |
| 770 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 771 | } |
| 772 | |
David Reiss | 6985a42 | 2009-03-24 20:00:47 +0000 | [diff] [blame] | 773 | Oneway: |
| 774 | tok_oneway |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 775 | { |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 776 | $$ = true; |
| 777 | } |
Jens Geyer | 154d154 | 2022-09-10 14:30:15 +0200 | [diff] [blame] | 778 | | tok_async // deprecated |
| 779 | { |
| 780 | $$ = true; |
| 781 | } |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 782 | | |
| 783 | { |
| 784 | $$ = false; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 787 | Throws: |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 788 | tok_throws '(' FieldList ')' |
| 789 | { |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 790 | pdebug("Throws -> tok_throws ( FieldList )"); |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 791 | $$ = $3; |
Mark Slee | f07d48e | 2008-02-01 01:36:26 +0000 | [diff] [blame] | 792 | if (g_parse_mode == PROGRAM && !validate_throws($$)) { |
Mark Slee | 91f2b7b | 2008-01-31 01:49:16 +0000 | [diff] [blame] | 793 | yyerror("Throws clause may not contain non-exception types"); |
| 794 | exit(1); |
| 795 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 796 | } |
| 797 | | |
| 798 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 799 | $$ = new t_struct(g_program); |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 802 | FieldList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 803 | FieldList Field |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 804 | { |
| 805 | pdebug("FieldList -> FieldList , Field"); |
| 806 | $$ = $1; |
Bryan Duxbury | ff219ac | 2009-04-10 21:51:00 +0000 | [diff] [blame] | 807 | if (!($$->append($2))) { |
Jens Geyer | 3a67c2f | 2013-02-03 22:30:41 +0100 | [diff] [blame] | 808 | yyerror("\"%d: %s\" - field identifier/name has already been used", $2->get_key(), $2->get_name().c_str()); |
Mark Slee | 6f9ac3f | 2007-11-28 22:28:13 +0000 | [diff] [blame] | 809 | exit(1); |
| 810 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 811 | } |
| 812 | | |
| 813 | { |
| 814 | pdebug("FieldList -> "); |
David Reiss | 00a8dd6 | 2009-03-19 08:14:12 +0000 | [diff] [blame] | 815 | y_field_val = -1; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 816 | $$ = new t_struct(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | Field: |
Jens Geyer | 154d154 | 2022-09-10 14:30:15 +0200 | [diff] [blame] | 820 | CaptureDocText FieldIdentifier FieldRequiredness FieldType FieldReference FieldName FieldValue XsdOptional XsdNillable XsdAttributes TypeAnnotations CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 821 | { |
Jens Geyer | 154d154 | 2022-09-10 14:30:15 +0200 | [diff] [blame] | 822 | pdebug("tok_int_constant : Field -> FieldType FieldName"); |
Bryan Duxbury | c7206a4 | 2011-08-17 23:17:04 +0000 | [diff] [blame] | 823 | if ($2.auto_assigned) { |
Jens Geyer | 885c679 | 2014-05-02 21:31:55 +0200 | [diff] [blame] | 824 | pwarning(1, "No field key specified for %s, resulting protocol may have conflicts or not be backwards compatible!\n", $6); |
Bryan Duxbury | a145b4d | 2009-04-03 17:29:25 +0000 | [diff] [blame] | 825 | if (g_strict >= 192) { |
| 826 | yyerror("Implicit field keys are deprecated and not allowed with -strict"); |
| 827 | exit(1); |
| 828 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 829 | } |
Jens Geyer | 885c679 | 2014-05-02 21:31:55 +0200 | [diff] [blame] | 830 | validate_simple_identifier($6); |
| 831 | $$ = new t_field($4, $6, $2.value); |
| 832 | $$->set_reference($5); |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 833 | $$->set_req($3); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 834 | if ($7 != nullptr) { |
Jens Geyer | 885c679 | 2014-05-02 21:31:55 +0200 | [diff] [blame] | 835 | g_scope->resolve_const_value($7, $4); |
| 836 | validate_field_value($$, $7); |
| 837 | $$->set_value($7); |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 838 | } |
Jens Geyer | 885c679 | 2014-05-02 21:31:55 +0200 | [diff] [blame] | 839 | $$->set_xsd_optional($8); |
| 840 | $$->set_xsd_nillable($9); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 841 | if ($1 != nullptr) { |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 842 | $$->set_doc($1); |
| 843 | } |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 844 | if ($10 != nullptr) { |
Jens Geyer | 885c679 | 2014-05-02 21:31:55 +0200 | [diff] [blame] | 845 | $$->set_xsd_attrs($10); |
| 846 | } |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 847 | if ($11 != nullptr) { |
Jens Geyer | 885c679 | 2014-05-02 21:31:55 +0200 | [diff] [blame] | 848 | $$->annotations_ = $11->annotations_; |
| 849 | delete $11; |
David Reiss | 53c10e0 | 2010-03-05 07:51:51 +0000 | [diff] [blame] | 850 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 851 | } |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 852 | |
Jens Geyer | 154d154 | 2022-09-10 14:30:15 +0200 | [diff] [blame] | 853 | FieldName: // identifiers and everything that could be one if it would not be identified as a different token already and excluding the "xsd*" keywords to follow a FieldName |
| 854 | tok_identifier |
| 855 | { |
| 856 | pdebug("FieldName -> tok_identifier"); |
| 857 | $$ = $1; |
| 858 | } |
| 859 | | tok_namespace |
| 860 | { |
| 861 | pdebug("FieldName -> tok_namespace"); |
| 862 | $$ = strdup("namespace"); |
| 863 | } |
| 864 | | tok_cpp_include |
| 865 | { |
| 866 | pdebug("FieldName -> tok_cpp_include"); |
| 867 | $$ = strdup("cpp_include"); |
| 868 | } |
| 869 | /* see THRIFT-5627 "More consistent syntax for cpp_type" -> activate when this issue is resolved |
| 870 | | tok_cpp_type |
| 871 | { |
| 872 | pdebug("FieldName -> tok_cpp_type"); |
| 873 | $$ = $strdup("cpp_type"); |
| 874 | } |
| 875 | */ |
| 876 | | tok_include |
| 877 | { |
| 878 | pdebug("FieldName -> tok_include"); |
| 879 | $$ = strdup("include"); |
| 880 | } |
| 881 | | tok_void |
| 882 | { |
| 883 | pdebug("FieldName -> tok_void"); |
| 884 | $$ = strdup("void"); |
| 885 | } |
| 886 | | tok_bool |
| 887 | { |
| 888 | pdebug("FieldName -> tok_bool"); |
| 889 | $$ = strdup("bool"); |
| 890 | } |
| 891 | | tok_byte |
| 892 | { |
| 893 | pdebug("FieldName -> tok_byte"); |
| 894 | $$ = strdup("byte"); |
| 895 | } |
| 896 | | tok_i8 |
| 897 | { |
| 898 | pdebug("FieldName -> tok_i8"); |
| 899 | $$ = strdup("i8"); |
| 900 | } |
| 901 | | tok_i16 |
| 902 | { |
| 903 | pdebug("FieldName -> tok_i16"); |
| 904 | $$ = strdup("i16"); |
| 905 | } |
| 906 | | tok_i32 |
| 907 | { |
| 908 | pdebug("FieldName -> tok_i32"); |
| 909 | $$ = strdup("i32"); |
| 910 | } |
| 911 | | tok_i64 |
| 912 | { |
| 913 | pdebug("FieldName -> tok_i64"); |
| 914 | $$ = strdup("i64"); |
| 915 | } |
| 916 | | tok_double |
| 917 | { |
| 918 | pdebug("FieldName -> tok_double"); |
| 919 | $$ = strdup("double"); |
| 920 | } |
| 921 | | tok_string |
| 922 | { |
| 923 | pdebug("FieldName -> tok_string"); |
| 924 | $$ = strdup("string"); |
| 925 | } |
| 926 | | tok_binary |
| 927 | { |
| 928 | pdebug("FieldName -> tok_binary"); |
| 929 | $$ = strdup("binary"); |
| 930 | } |
| 931 | | tok_uuid |
| 932 | { |
| 933 | pdebug("FieldName -> tok_uuid"); |
| 934 | $$ = strdup("uuid"); |
| 935 | } |
| 936 | | tok_map |
| 937 | { |
| 938 | pdebug("FieldName -> tok_map"); |
| 939 | $$ = strdup("map"); |
| 940 | } |
| 941 | | tok_list |
| 942 | { |
| 943 | pdebug("FieldName -> tok_list"); |
| 944 | $$ = strdup("list"); |
| 945 | } |
| 946 | | tok_set |
| 947 | { |
| 948 | pdebug("FieldName -> tok_set"); |
| 949 | $$ = strdup("set"); |
| 950 | } |
| 951 | | tok_oneway |
| 952 | { |
| 953 | pdebug("FieldName -> tok_oneway"); |
| 954 | $$ = strdup("oneway"); |
| 955 | } |
| 956 | | tok_async |
| 957 | { |
| 958 | pdebug("FieldName -> tok_async"); |
| 959 | $$ = strdup("async"); |
| 960 | } |
| 961 | | tok_typedef |
| 962 | { |
| 963 | pdebug("FieldName -> tok_typedef"); |
| 964 | $$ = strdup("typedef"); |
| 965 | } |
| 966 | | tok_struct |
| 967 | { |
| 968 | pdebug("FieldName -> tok_struct"); |
| 969 | $$ = strdup("struct"); |
| 970 | } |
| 971 | | tok_union |
| 972 | { |
| 973 | pdebug("FieldName -> tok_union"); |
| 974 | $$ = strdup("union"); |
| 975 | } |
| 976 | | tok_xception |
| 977 | { |
| 978 | pdebug("FieldName -> tok_xception"); |
| 979 | $$ = strdup("exception"); |
| 980 | } |
| 981 | | tok_extends |
| 982 | { |
| 983 | pdebug("FieldName -> tok_extends"); |
| 984 | $$ = strdup("extends"); |
| 985 | } |
| 986 | | tok_throws |
| 987 | { |
| 988 | pdebug("FieldName -> tok_throws"); |
| 989 | $$ = strdup("throws"); |
| 990 | } |
| 991 | | tok_service |
| 992 | { |
| 993 | pdebug("FieldName -> tok_service"); |
| 994 | $$ = strdup("service"); |
| 995 | } |
| 996 | | tok_enum |
| 997 | { |
| 998 | pdebug("FieldName -> tok_enum"); |
| 999 | $$ = strdup("enum"); |
| 1000 | } |
| 1001 | | tok_const |
| 1002 | { |
| 1003 | pdebug("FieldName -> tok_const"); |
| 1004 | $$ = strdup("const"); |
| 1005 | } |
| 1006 | | tok_required |
| 1007 | { |
| 1008 | pdebug("FieldName -> tok_required"); |
| 1009 | $$ = strdup("required"); |
| 1010 | } |
| 1011 | | tok_optional |
| 1012 | { |
| 1013 | pdebug("FieldName -> tok_optional"); |
| 1014 | $$ = strdup("optional"); |
| 1015 | } |
| 1016 | |
| 1017 | |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 1018 | FieldIdentifier: |
| 1019 | tok_int_constant ':' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1020 | { |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 1021 | if ($1 <= 0) { |
Bryan Duxbury | c7206a4 | 2011-08-17 23:17:04 +0000 | [diff] [blame] | 1022 | if (g_allow_neg_field_keys) { |
| 1023 | /* |
| 1024 | * g_allow_neg_field_keys exists to allow users to add explicitly |
| 1025 | * specified key values to old .thrift files without breaking |
| 1026 | * protocol compatibility. |
| 1027 | */ |
| 1028 | if ($1 != y_field_val) { |
| 1029 | /* |
| 1030 | * warn if the user-specified negative value isn't what |
| 1031 | * thrift would have auto-assigned. |
| 1032 | */ |
Roger Meier | 5f2d34e | 2013-11-16 16:43:41 +0100 | [diff] [blame] | 1033 | pwarning(1, "Nonpositive field key (%" PRIi64") differs from what would be " |
Bryan Duxbury | c7206a4 | 2011-08-17 23:17:04 +0000 | [diff] [blame] | 1034 | "auto-assigned by thrift (%d).\n", $1, y_field_val); |
| 1035 | } |
| 1036 | /* |
| 1037 | * Leave $1 as-is, and update y_field_val to be one less than $1. |
| 1038 | * The FieldList parsing will catch any duplicate key values. |
| 1039 | */ |
Ben Craig | e957675 | 2013-10-11 08:19:16 -0500 | [diff] [blame] | 1040 | y_field_val = static_cast<int32_t>($1 - 1); |
| 1041 | $$.value = static_cast<int32_t>($1); |
Bryan Duxbury | c7206a4 | 2011-08-17 23:17:04 +0000 | [diff] [blame] | 1042 | $$.auto_assigned = false; |
| 1043 | } else { |
Ben Craig | e957675 | 2013-10-11 08:19:16 -0500 | [diff] [blame] | 1044 | pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", |
Bryan Duxbury | c7206a4 | 2011-08-17 23:17:04 +0000 | [diff] [blame] | 1045 | $1); |
| 1046 | $$.value = y_field_val--; |
| 1047 | $$.auto_assigned = true; |
| 1048 | } |
| 1049 | } else { |
Ben Craig | e957675 | 2013-10-11 08:19:16 -0500 | [diff] [blame] | 1050 | $$.value = static_cast<int32_t>($1); |
Bryan Duxbury | c7206a4 | 2011-08-17 23:17:04 +0000 | [diff] [blame] | 1051 | $$.auto_assigned = false; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1052 | } |
Jens Geyer | 06340a4 | 2016-03-25 01:34:03 +0200 | [diff] [blame] | 1053 | if( (SHRT_MIN > $$.value) || ($$.value > SHRT_MAX)) { |
| 1054 | pwarning(1, "Field key (%d) exceeds allowed range (%d..%d).\n", |
| 1055 | $$.value, SHRT_MIN, SHRT_MAX); |
| 1056 | } |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 1057 | } |
| 1058 | | |
| 1059 | { |
Bryan Duxbury | c7206a4 | 2011-08-17 23:17:04 +0000 | [diff] [blame] | 1060 | $$.value = y_field_val--; |
| 1061 | $$.auto_assigned = true; |
Jens Geyer | 06340a4 | 2016-03-25 01:34:03 +0200 | [diff] [blame] | 1062 | if( (SHRT_MIN > $$.value) || ($$.value > SHRT_MAX)) { |
| 1063 | pwarning(1, "Field key (%d) exceeds allowed range (%d..%d).\n", |
| 1064 | $$.value, SHRT_MIN, SHRT_MAX); |
| 1065 | } |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
Jens Geyer | 885c679 | 2014-05-02 21:31:55 +0200 | [diff] [blame] | 1068 | FieldReference: |
| 1069 | tok_reference |
| 1070 | { |
| 1071 | $$ = true; |
| 1072 | } |
| 1073 | | |
| 1074 | { |
| 1075 | $$ = false; |
| 1076 | } |
| 1077 | |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 1078 | FieldRequiredness: |
| 1079 | tok_required |
| 1080 | { |
David Reiss | 45603e9 | 2009-09-02 22:15:55 +0000 | [diff] [blame] | 1081 | $$ = t_field::T_REQUIRED; |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 1082 | } |
| 1083 | | tok_optional |
| 1084 | { |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 1085 | if (g_arglist) { |
| 1086 | if (g_parse_mode == PROGRAM) { |
| 1087 | pwarning(1, "optional keyword is ignored in argument lists.\n"); |
| 1088 | } |
David Reiss | 204420f | 2008-01-11 20:59:03 +0000 | [diff] [blame] | 1089 | $$ = t_field::T_OPT_IN_REQ_OUT; |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 1090 | } else { |
David Reiss | 204420f | 2008-01-11 20:59:03 +0000 | [diff] [blame] | 1091 | $$ = t_field::T_OPTIONAL; |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 1092 | } |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 1093 | } |
| 1094 | | |
| 1095 | { |
David Reiss | 204420f | 2008-01-11 20:59:03 +0000 | [diff] [blame] | 1096 | $$ = t_field::T_OPT_IN_REQ_OUT; |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 1099 | FieldValue: |
| 1100 | '=' ConstValue |
| 1101 | { |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 1102 | if (g_parse_mode == PROGRAM) { |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 1103 | $$ = $2; |
| 1104 | } else { |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 1105 | $$ = nullptr; |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | | |
| 1109 | { |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 1110 | $$ = nullptr; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1111 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1112 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1113 | FunctionType: |
| 1114 | FieldType |
| 1115 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1116 | pdebug("FunctionType -> FieldType"); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1117 | $$ = $1; |
| 1118 | } |
| 1119 | | tok_void |
| 1120 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1121 | pdebug("FunctionType -> tok_void"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1122 | $$ = g_type_void; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | FieldType: |
| 1126 | tok_identifier |
| 1127 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1128 | pdebug("FieldType -> tok_identifier"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1129 | if (g_parse_mode == INCLUDES) { |
| 1130 | // Ignore identifiers in include mode |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 1131 | $$ = nullptr; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1132 | } else { |
| 1133 | // Lookup the identifier in the current scope |
| 1134 | $$ = g_scope->get_type($1); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 1135 | if ($$ == nullptr) { |
jfarrell | e0e8316 | 2014-04-08 22:45:01 -0400 | [diff] [blame] | 1136 | /* |
| 1137 | * Either this type isn't yet declared, or it's never |
| 1138 | declared. Either way allow it and we'll figure it out |
| 1139 | during generation. |
| 1140 | */ |
Jens Geyer | d000b24 | 2014-04-13 21:58:47 +0200 | [diff] [blame] | 1141 | $$ = new t_typedef(g_program, $1, true); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1142 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1143 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1144 | } |
| 1145 | | BaseType |
| 1146 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1147 | pdebug("FieldType -> BaseType"); |
| 1148 | $$ = $1; |
| 1149 | } |
| 1150 | | ContainerType |
| 1151 | { |
| 1152 | pdebug("FieldType -> ContainerType"); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1153 | $$ = $1; |
| 1154 | } |
| 1155 | |
David Reiss | c8e3005 | 2009-07-27 17:02:42 +0000 | [diff] [blame] | 1156 | BaseType: SimpleBaseType TypeAnnotations |
| 1157 | { |
| 1158 | pdebug("BaseType -> SimpleBaseType TypeAnnotations"); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 1159 | if ($2 != nullptr) { |
David Reiss | c8e3005 | 2009-07-27 17:02:42 +0000 | [diff] [blame] | 1160 | $$ = new t_base_type(*static_cast<t_base_type*>($1)); |
| 1161 | $$->annotations_ = $2->annotations_; |
| 1162 | delete $2; |
| 1163 | } else { |
| 1164 | $$ = $1; |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | SimpleBaseType: |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1169 | tok_string |
| 1170 | { |
| 1171 | pdebug("BaseType -> tok_string"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1172 | $$ = g_type_string; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1173 | } |
Mark Slee | 8d725a2 | 2007-04-13 01:57:12 +0000 | [diff] [blame] | 1174 | | tok_binary |
| 1175 | { |
| 1176 | pdebug("BaseType -> tok_binary"); |
| 1177 | $$ = g_type_binary; |
| 1178 | } |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 1179 | | tok_uuid |
| 1180 | { |
| 1181 | pdebug("BaseType -> tok_uuid"); |
| 1182 | $$ = g_type_uuid; |
| 1183 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 1184 | | tok_bool |
| 1185 | { |
| 1186 | pdebug("BaseType -> tok_bool"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1187 | $$ = g_type_bool; |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 1188 | } |
Jens Geyer | 154d154 | 2022-09-10 14:30:15 +0200 | [diff] [blame] | 1189 | | tok_byte |
| 1190 | { |
| 1191 | pdebug("BaseType -> tok_byte"); |
| 1192 | $$ = g_type_i8; // byte is signed in Thrift, just an alias for i8 |
| 1193 | } |
Jens Geyer | 40c28d3 | 2015-10-20 23:13:02 +0200 | [diff] [blame] | 1194 | | tok_i8 |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1195 | { |
Jens Geyer | 40c28d3 | 2015-10-20 23:13:02 +0200 | [diff] [blame] | 1196 | pdebug("BaseType -> tok_i8"); |
| 1197 | $$ = g_type_i8; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1198 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 1199 | | tok_i16 |
| 1200 | { |
| 1201 | pdebug("BaseType -> tok_i16"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1202 | $$ = g_type_i16; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 1203 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1204 | | tok_i32 |
| 1205 | { |
| 1206 | pdebug("BaseType -> tok_i32"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1207 | $$ = g_type_i32; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1208 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1209 | | tok_i64 |
| 1210 | { |
| 1211 | pdebug("BaseType -> tok_i64"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1212 | $$ = g_type_i64; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1213 | } |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 1214 | | tok_double |
| 1215 | { |
| 1216 | pdebug("BaseType -> tok_double"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1217 | $$ = g_type_double; |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 1218 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1219 | |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 1220 | ContainerType: SimpleContainerType TypeAnnotations |
| 1221 | { |
| 1222 | pdebug("ContainerType -> SimpleContainerType TypeAnnotations"); |
| 1223 | $$ = $1; |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 1224 | if ($2 != nullptr) { |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 1225 | $$->annotations_ = $2->annotations_; |
| 1226 | delete $2; |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | SimpleContainerType: |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1231 | MapType |
| 1232 | { |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 1233 | pdebug("SimpleContainerType -> MapType"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1234 | $$ = $1; |
| 1235 | } |
| 1236 | | SetType |
| 1237 | { |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 1238 | pdebug("SimpleContainerType -> SetType"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1239 | $$ = $1; |
| 1240 | } |
| 1241 | | ListType |
| 1242 | { |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 1243 | pdebug("SimpleContainerType -> ListType"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1244 | $$ = $1; |
| 1245 | } |
| 1246 | |
| 1247 | MapType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 1248 | tok_map CppType '<' FieldType ',' FieldType '>' |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1249 | { |
| 1250 | pdebug("MapType -> tok_map <FieldType, FieldType>"); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 1251 | $$ = new t_map($4, $6); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 1252 | if ($2 != nullptr) { |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 1253 | ((t_container*)$$)->set_cpp_name(std::string($2)); |
| 1254 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | SetType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 1258 | tok_set CppType '<' FieldType '>' |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1259 | { |
| 1260 | pdebug("SetType -> tok_set<FieldType>"); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 1261 | $$ = new t_set($4); |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 1262 | if ($2 != nullptr) { |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 1263 | ((t_container*)$$)->set_cpp_name(std::string($2)); |
| 1264 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | ListType: |
Jens Geyer | 9b09a11 | 2022-09-14 00:29:07 +0200 | [diff] [blame] | 1268 | tok_list CppType '<' FieldType '>' CppType // the second CppType is for compatibility reasons = deprecated |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1269 | { |
| 1270 | pdebug("ListType -> tok_list<FieldType>"); |
Jens Geyer | 9b09a11 | 2022-09-14 00:29:07 +0200 | [diff] [blame] | 1271 | check_for_list_of_bytes($4); |
| 1272 | $$ = new t_list($4); |
| 1273 | if ($2 != nullptr) { |
| 1274 | ((t_container*)$$)->set_cpp_name(std::string($2)); |
| 1275 | } |
| 1276 | if ($6 != nullptr) { |
| 1277 | ((t_container*)$$)->set_cpp_name(std::string($6)); |
| 1278 | pwarning(1, "The syntax 'list<type> cpp_type \"c++ type\"' is deprecated. Use 'list cpp_type \"c++ type\" <type>' instead.\n"); |
| 1279 | } |
| 1280 | if (($2 != nullptr) && ($6 != nullptr)) { |
| 1281 | pwarning(1, "Two cpp_types clauses at list<%>\n", $2); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 1285 | CppType: |
Mark Slee | afc7654 | 2007-02-09 21:55:44 +0000 | [diff] [blame] | 1286 | tok_cpp_type tok_literal |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 1287 | { |
Mark Slee | afc7654 | 2007-02-09 21:55:44 +0000 | [diff] [blame] | 1288 | $$ = $2; |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 1289 | } |
| 1290 | | |
| 1291 | { |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 1292 | $$ = nullptr; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 1295 | TypeAnnotations: |
| 1296 | '(' TypeAnnotationList ')' |
| 1297 | { |
| 1298 | pdebug("TypeAnnotations -> ( TypeAnnotationList )"); |
| 1299 | $$ = $2; |
| 1300 | } |
| 1301 | | |
| 1302 | { |
zeshuai007 | 26681fb | 2020-06-03 17:24:38 +0800 | [diff] [blame] | 1303 | $$ = nullptr; |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | TypeAnnotationList: |
| 1307 | TypeAnnotationList TypeAnnotation |
| 1308 | { |
| 1309 | pdebug("TypeAnnotationList -> TypeAnnotationList , TypeAnnotation"); |
| 1310 | $$ = $1; |
Simon Wang | d5927a9 | 2021-09-13 19:50:45 +0800 | [diff] [blame] | 1311 | $$->annotations_[$2->key].push_back($2->val); |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 1312 | delete $2; |
| 1313 | } |
| 1314 | | |
| 1315 | { |
| 1316 | /* Just use a dummy structure to hold the annotations. */ |
| 1317 | $$ = new t_struct(g_program); |
| 1318 | } |
| 1319 | |
| 1320 | TypeAnnotation: |
Jens Geyer | 89847df | 2014-05-02 23:50:04 +0200 | [diff] [blame] | 1321 | tok_identifier TypeAnnotationValue CommaOrSemicolonOptional |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 1322 | { |
Jens Geyer | 89847df | 2014-05-02 23:50:04 +0200 | [diff] [blame] | 1323 | pdebug("TypeAnnotation -> TypeAnnotationValue"); |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 1324 | $$ = new t_annotation; |
| 1325 | $$->key = $1; |
Jens Geyer | 89847df | 2014-05-02 23:50:04 +0200 | [diff] [blame] | 1326 | $$->val = $2; |
| 1327 | } |
| 1328 | |
| 1329 | TypeAnnotationValue: |
| 1330 | '=' tok_literal |
| 1331 | { |
| 1332 | pdebug("TypeAnnotationValue -> = tok_literal"); |
| 1333 | $$ = $2; |
| 1334 | } |
| 1335 | | |
| 1336 | { |
| 1337 | pdebug("TypeAnnotationValue ->"); |
| 1338 | $$ = strdup("1"); |
David Reiss | a230999 | 2008-12-10 01:52:48 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Todd Lipcon | 53ae9f3 | 2009-12-07 00:42:38 +0000 | [diff] [blame] | 1341 | %% |