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