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