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