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