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