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