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