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