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