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