Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1 | %{ |
Mark Slee | e9ce01c | 2007-05-16 02:29:53 +0000 | [diff] [blame] | 2 | // Copyright (c) 2006- Facebook |
| 3 | // Distributed under the Thrift Software License |
| 4 | // |
| 5 | // See accompanying file LICENSE or visit the Thrift site at: |
| 6 | // http://developers.facebook.com/thrift/ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 7 | |
| 8 | /** |
| 9 | * Thrift parser. |
| 10 | * |
| 11 | * This parser is used on a thrift definition file. |
| 12 | * |
| 13 | * @author Mark Slee <mcslee@facebook.com> |
| 14 | */ |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | #include "main.h" |
| 18 | #include "globals.h" |
| 19 | #include "parse/t_program.h" |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 20 | #include "parse/t_scope.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 21 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 22 | /** |
| 23 | * This global variable is used for automatic numbering of field indices etc. |
| 24 | * when parsing the members of a struct. Field values are automatically |
| 25 | * assigned starting from -1 and working their way down. |
| 26 | */ |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 27 | int y_field_val = -1; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 28 | |
| 29 | %} |
| 30 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 31 | /** |
| 32 | * This structure is used by the parser to hold the data types associated with |
| 33 | * various parse nodes. |
| 34 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 35 | %union { |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 36 | char* id; |
| 37 | int iconst; |
| 38 | double dconst; |
| 39 | bool tbool; |
| 40 | t_type* ttype; |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 41 | t_base_type* tbase; |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 42 | t_typedef* ttypedef; |
| 43 | t_enum* tenum; |
| 44 | t_enum_value* tenumv; |
| 45 | t_const* tconst; |
| 46 | t_const_value* tconstv; |
| 47 | t_struct* tstruct; |
| 48 | t_service* tservice; |
| 49 | t_function* tfunction; |
| 50 | t_field* tfield; |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 51 | char* tdoc; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 54 | /** |
| 55 | * Strings identifier |
| 56 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 57 | %token<id> tok_identifier |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 58 | %token<id> tok_literal |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 59 | %token<tdoc> tok_doctext |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 60 | |
| 61 | /** |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 62 | * Constant values |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 63 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 64 | %token<iconst> tok_int_constant |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 65 | %token<dconst> tok_dub_constant |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 66 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 67 | /** |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 68 | * Header keywoards |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 69 | */ |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 70 | %token tok_include |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 71 | %token tok_namespace |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 72 | %token tok_cpp_namespace |
| 73 | %token tok_cpp_include |
| 74 | %token tok_cpp_type |
Mark Slee | e888b37 | 2007-01-12 01:06:24 +0000 | [diff] [blame] | 75 | %token tok_php_namespace |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 76 | %token tok_java_package |
Mark Slee | 782abbb | 2007-01-19 00:17:02 +0000 | [diff] [blame] | 77 | %token tok_xsd_all |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 78 | %token tok_xsd_optional |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 79 | %token tok_xsd_nillable |
Mark Slee | 0d9199e | 2007-01-31 02:08:30 +0000 | [diff] [blame] | 80 | %token tok_xsd_namespace |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 81 | %token tok_xsd_attrs |
Mark Slee | 58dfb4f | 2007-07-06 02:45:25 +0000 | [diff] [blame] | 82 | %token tok_ruby_namespace |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 83 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 84 | /** |
| 85 | * Base datatype keywords |
| 86 | */ |
| 87 | %token tok_void |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 88 | %token tok_bool |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 89 | %token tok_byte |
| 90 | %token tok_string |
Mark Slee | 8d725a2 | 2007-04-13 01:57:12 +0000 | [diff] [blame] | 91 | %token tok_binary |
Mark Slee | b6200d8 | 2007-01-19 19:14:36 +0000 | [diff] [blame] | 92 | %token tok_slist |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 93 | %token tok_senum |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 94 | %token tok_i16 |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 95 | %token tok_i32 |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 96 | %token tok_i64 |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 97 | %token tok_double |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 98 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 99 | /** |
| 100 | * Complex type keywords |
| 101 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 102 | %token tok_map |
| 103 | %token tok_list |
| 104 | %token tok_set |
| 105 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 106 | /** |
| 107 | * Function modifiers |
| 108 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 109 | %token tok_async |
| 110 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 111 | /** |
| 112 | * Thrift language keywords |
| 113 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 114 | %token tok_typedef |
| 115 | %token tok_struct |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 116 | %token tok_xception |
| 117 | %token tok_throws |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 118 | %token tok_extends |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 119 | %token tok_service |
| 120 | %token tok_enum |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 121 | %token tok_const |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 122 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 123 | /** |
| 124 | * Grammar nodes |
| 125 | */ |
| 126 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 127 | %type<ttype> BaseType |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 128 | %type<ttype> ContainerType |
| 129 | %type<ttype> MapType |
| 130 | %type<ttype> SetType |
| 131 | %type<ttype> ListType |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 132 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 133 | %type<ttype> TypeDefinition |
| 134 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 135 | %type<ttypedef> Typedef |
| 136 | %type<ttype> DefinitionType |
| 137 | |
| 138 | %type<tfield> Field |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 139 | %type<iconst> FieldIdentifier |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 140 | %type<ttype> FieldType |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 141 | %type<tconstv> FieldValue |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 142 | %type<tstruct> FieldList |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 143 | |
| 144 | %type<tenum> Enum |
| 145 | %type<tenum> EnumDefList |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 146 | %type<tenumv> EnumDef |
| 147 | |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 148 | %type<ttypedef> Senum |
| 149 | %type<tbase> SenumDefList |
| 150 | %type<id> SenumDef |
| 151 | |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 152 | %type<tconst> Const |
| 153 | %type<tconstv> ConstValue |
| 154 | %type<tconstv> ConstList |
| 155 | %type<tconstv> ConstListContents |
| 156 | %type<tconstv> ConstMap |
| 157 | %type<tconstv> ConstMapContents |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 158 | |
| 159 | %type<tstruct> Struct |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 160 | %type<tstruct> Xception |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 161 | %type<tservice> Service |
| 162 | |
| 163 | %type<tfunction> Function |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 164 | %type<ttype> FunctionType |
| 165 | %type<tservice> FunctionList |
| 166 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 167 | %type<tstruct> Throws |
| 168 | %type<tservice> Extends |
| 169 | %type<tbool> Async |
| 170 | %type<tbool> XsdAll |
| 171 | %type<tbool> XsdOptional |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 172 | %type<tbool> XsdNillable |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 173 | %type<tstruct> XsdAttributes |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 174 | %type<id> CppType |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 175 | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 176 | %type<tdoc> DocTextOptional |
| 177 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 178 | %% |
| 179 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 180 | /** |
| 181 | * Thrift Grammar Implementation. |
| 182 | * |
| 183 | * For the most part this source file works its way top down from what you |
| 184 | * might expect to find in a typical .thrift file, i.e. type definitions and |
| 185 | * namespaces up top followed by service definitions using those types. |
| 186 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 187 | |
| 188 | Program: |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 189 | HeaderList DefinitionList |
| 190 | { |
| 191 | pdebug("Program -> Headers DefinitionList"); |
| 192 | } |
| 193 | |
| 194 | HeaderList: |
| 195 | HeaderList Header |
| 196 | { |
| 197 | pdebug("HeaderList -> HeaderList Header"); |
| 198 | } |
| 199 | | |
| 200 | { |
| 201 | pdebug("HeaderList -> "); |
| 202 | } |
| 203 | |
| 204 | Header: |
| 205 | Include |
| 206 | { |
| 207 | pdebug("Header -> Include"); |
| 208 | } |
| 209 | | tok_namespace tok_identifier |
| 210 | { |
| 211 | pwarning(1, "'namespace' is deprecated. Use 'cpp_namespace' and/or 'java_package' instead"); |
| 212 | if (g_parse_mode == PROGRAM) { |
| 213 | g_program->set_cpp_namespace($2); |
| 214 | g_program->set_java_package($2); |
| 215 | } |
| 216 | } |
| 217 | | tok_cpp_namespace tok_identifier |
| 218 | { |
| 219 | pdebug("Header -> tok_cpp_namespace tok_identifier"); |
| 220 | if (g_parse_mode == PROGRAM) { |
| 221 | g_program->set_cpp_namespace($2); |
| 222 | } |
| 223 | } |
| 224 | | tok_cpp_include tok_literal |
| 225 | { |
| 226 | pdebug("Header -> tok_cpp_include tok_literal"); |
| 227 | if (g_parse_mode == PROGRAM) { |
| 228 | g_program->add_cpp_include($2); |
| 229 | } |
| 230 | } |
Mark Slee | e888b37 | 2007-01-12 01:06:24 +0000 | [diff] [blame] | 231 | | tok_php_namespace tok_identifier |
| 232 | { |
| 233 | pdebug("Header -> tok_php_namespace tok_identifier"); |
| 234 | if (g_parse_mode == PROGRAM) { |
| 235 | g_program->set_php_namespace($2); |
| 236 | } |
| 237 | } |
Mark Slee | 58dfb4f | 2007-07-06 02:45:25 +0000 | [diff] [blame] | 238 | | tok_ruby_namespace tok_identifier |
| 239 | { |
| 240 | pdebug("Header -> tok_ruby_namespace tok_identifier"); |
| 241 | if (g_parse_mode == PROGRAM) { |
| 242 | g_program->set_ruby_namespace($2); |
| 243 | } |
| 244 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 245 | | tok_java_package tok_identifier |
| 246 | { |
| 247 | pdebug("Header -> tok_java_package tok_identifier"); |
| 248 | if (g_parse_mode == PROGRAM) { |
| 249 | g_program->set_java_package($2); |
| 250 | } |
| 251 | } |
Mark Slee | 0d9199e | 2007-01-31 02:08:30 +0000 | [diff] [blame] | 252 | | tok_xsd_namespace tok_literal |
| 253 | { |
| 254 | pdebug("Header -> tok_xsd_namespace tok_literal"); |
| 255 | if (g_parse_mode == PROGRAM) { |
| 256 | g_program->set_xsd_namespace($2); |
| 257 | } |
| 258 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 259 | |
| 260 | Include: |
| 261 | tok_include tok_literal |
| 262 | { |
| 263 | pdebug("Include -> tok_include tok_literal"); |
| 264 | if (g_parse_mode == INCLUDES) { |
| 265 | std::string path = include_file(std::string($2)); |
| 266 | if (!path.empty()) { |
| 267 | g_program->add_include(path); |
| 268 | } |
| 269 | } |
| 270 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 271 | |
| 272 | DefinitionList: |
| 273 | DefinitionList Definition |
| 274 | { |
| 275 | pdebug("DefinitionList -> DefinitionList Definition"); |
| 276 | } |
| 277 | | |
| 278 | { |
| 279 | pdebug("DefinitionList -> "); |
| 280 | } |
| 281 | |
| 282 | Definition: |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 283 | Const |
| 284 | { |
| 285 | pdebug("Definition -> Const"); |
| 286 | if (g_parse_mode == PROGRAM) { |
| 287 | g_program->add_const($1); |
| 288 | } |
| 289 | } |
| 290 | | TypeDefinition |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 291 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 292 | pdebug("Definition -> TypeDefinition"); |
| 293 | if (g_parse_mode == PROGRAM) { |
| 294 | g_scope->add_type($1->get_name(), $1); |
| 295 | if (g_parent_scope != NULL) { |
| 296 | g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1); |
| 297 | } |
| 298 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 299 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 300 | | Service |
| 301 | { |
| 302 | pdebug("Definition -> Service"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 303 | if (g_parse_mode == PROGRAM) { |
| 304 | g_scope->add_service($1->get_name(), $1); |
| 305 | if (g_parent_scope != NULL) { |
| 306 | g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1); |
| 307 | } |
| 308 | g_program->add_service($1); |
| 309 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 312 | TypeDefinition: |
| 313 | Typedef |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 314 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 315 | pdebug("TypeDefinition -> Typedef"); |
| 316 | if (g_parse_mode == PROGRAM) { |
| 317 | g_program->add_typedef($1); |
| 318 | } |
| 319 | } |
| 320 | | Enum |
| 321 | { |
| 322 | pdebug("TypeDefinition -> Enum"); |
| 323 | if (g_parse_mode == PROGRAM) { |
| 324 | g_program->add_enum($1); |
| 325 | } |
| 326 | } |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 327 | | Senum |
| 328 | { |
| 329 | pdebug("TypeDefinition -> Senum"); |
| 330 | if (g_parse_mode == PROGRAM) { |
| 331 | g_program->add_typedef($1); |
| 332 | } |
| 333 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 334 | | Struct |
| 335 | { |
| 336 | pdebug("TypeDefinition -> Struct"); |
| 337 | if (g_parse_mode == PROGRAM) { |
| 338 | g_program->add_struct($1); |
| 339 | } |
| 340 | } |
| 341 | | Xception |
| 342 | { |
| 343 | pdebug("TypeDefinition -> Xception"); |
| 344 | if (g_parse_mode == PROGRAM) { |
| 345 | g_program->add_xception($1); |
| 346 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 347 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 348 | |
| 349 | Typedef: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 350 | DocTextOptional tok_typedef DefinitionType tok_identifier |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 351 | { |
| 352 | pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 353 | t_typedef *td = new t_typedef(g_program, $3, $4); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 354 | $$ = td; |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 355 | if ($1 != NULL) { |
| 356 | td->set_doc($1); |
| 357 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 358 | } |
| 359 | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 360 | DocTextOptional: |
| 361 | tok_doctext |
| 362 | { |
| 363 | pdebug("DocTextOptional -> tok_doctext"); |
| 364 | $$ = $1; |
| 365 | } |
| 366 | | |
| 367 | { |
| 368 | $$ = NULL; |
| 369 | } |
| 370 | |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 371 | CommaOrSemicolonOptional: |
| 372 | ',' |
| 373 | {} |
| 374 | | ';' |
| 375 | {} |
| 376 | | |
| 377 | {} |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 378 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 379 | Enum: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 380 | DocTextOptional tok_enum tok_identifier '{' EnumDefList '}' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 381 | { |
| 382 | pdebug("Enum -> tok_enum tok_identifier { EnumDefList }"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 383 | $$ = $5; |
| 384 | $$->set_name($3); |
| 385 | if ($1 != NULL) { |
| 386 | $$->set_doc($1); |
| 387 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | EnumDefList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 391 | EnumDefList EnumDef |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 392 | { |
| 393 | pdebug("EnumDefList -> EnumDefList EnumDef"); |
| 394 | $$ = $1; |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 395 | $$->append($2); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 396 | } |
| 397 | | |
| 398 | { |
| 399 | pdebug("EnumDefList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 400 | $$ = new t_enum(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | EnumDef: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 404 | DocTextOptional tok_identifier '=' tok_int_constant CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 405 | { |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 406 | pdebug("EnumDef -> tok_identifier = tok_int_constant"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 407 | if ($4 < 0) { |
| 408 | pwarning(1, "Negative value supplied for enum %s.\n", $2); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 409 | } |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 410 | $$ = new t_enum_value($2, $4); |
| 411 | if ($1 != NULL) { |
| 412 | $$->set_doc($1); |
| 413 | } |
Mark Slee | d0767c5 | 2007-07-27 22:14:41 +0000 | [diff] [blame^] | 414 | if (g_parse_mode == PROGRAM) { |
| 415 | g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4))); |
| 416 | if (g_parent_scope != NULL) { |
| 417 | g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4))); |
| 418 | } |
| 419 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 420 | } |
| 421 | | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 422 | DocTextOptional tok_identifier CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 423 | { |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 424 | pdebug("EnumDef -> tok_identifier"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 425 | $$ = new t_enum_value($2); |
| 426 | if ($1 != NULL) { |
| 427 | $$->set_doc($1); |
| 428 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 431 | Senum: |
| 432 | DocTextOptional tok_senum tok_identifier '{' SenumDefList '}' |
| 433 | { |
| 434 | pdebug("Senum -> tok_senum tok_identifier { SenumDefList }"); |
| 435 | $$ = new t_typedef(g_program, $5, $3); |
| 436 | if ($1 != NULL) { |
| 437 | $$->set_doc($1); |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | SenumDefList: |
| 442 | SenumDefList SenumDef |
| 443 | { |
| 444 | pdebug("SenumDefList -> SenumDefList SenumDef"); |
| 445 | $$ = $1; |
| 446 | $$->add_string_enum_val($2); |
| 447 | } |
| 448 | | |
| 449 | { |
| 450 | pdebug("SenumDefList -> "); |
| 451 | $$ = new t_base_type("string", t_base_type::TYPE_STRING); |
| 452 | $$->set_string_enum(true); |
| 453 | } |
| 454 | |
| 455 | SenumDef: |
| 456 | tok_literal CommaOrSemicolonOptional |
| 457 | { |
| 458 | pdebug("SenumDef -> tok_literal"); |
| 459 | $$ = $1; |
| 460 | } |
| 461 | |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 462 | Const: |
| 463 | tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional |
| 464 | { |
| 465 | pdebug("Const -> tok_const FieldType tok_identifier = ConstValue"); |
Mark Slee | aa7671d | 2006-11-29 03:19:31 +0000 | [diff] [blame] | 466 | if (g_parse_mode == PROGRAM) { |
| 467 | $$ = new t_const($2, $3, $5); |
| 468 | validate_const_type($$); |
Mark Slee | d0767c5 | 2007-07-27 22:14:41 +0000 | [diff] [blame^] | 469 | |
| 470 | g_scope->add_constant($3, $$); |
| 471 | if (g_parent_scope != NULL) { |
| 472 | g_parent_scope->add_constant(g_parent_prefix + $3, $$); |
| 473 | } |
| 474 | |
Mark Slee | aa7671d | 2006-11-29 03:19:31 +0000 | [diff] [blame] | 475 | } else { |
| 476 | $$ = NULL; |
| 477 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | ConstValue: |
| 481 | tok_int_constant |
| 482 | { |
| 483 | pdebug("ConstValue => tok_int_constant"); |
| 484 | $$ = new t_const_value(); |
| 485 | $$->set_integer($1); |
| 486 | } |
| 487 | | tok_dub_constant |
| 488 | { |
| 489 | pdebug("ConstValue => tok_dub_constant"); |
| 490 | $$ = new t_const_value(); |
| 491 | $$->set_double($1); |
| 492 | } |
| 493 | | tok_literal |
| 494 | { |
| 495 | pdebug("ConstValue => tok_literal"); |
Mark Slee | d0767c5 | 2007-07-27 22:14:41 +0000 | [diff] [blame^] | 496 | $$ = new t_const_value($1); |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 497 | } |
Mark Slee | 67fc634 | 2006-11-29 03:37:04 +0000 | [diff] [blame] | 498 | | tok_identifier |
| 499 | { |
| 500 | pdebug("ConstValue => tok_identifier"); |
Mark Slee | d0767c5 | 2007-07-27 22:14:41 +0000 | [diff] [blame^] | 501 | t_const* constant = g_scope->get_constant($1); |
| 502 | if (constant != NULL) { |
| 503 | $$ = constant->get_value(); |
| 504 | } else { |
| 505 | if (g_parse_mode == PROGRAM) { |
| 506 | pwarning(1, "Constant strings should be quoted: %s\n", $1); |
| 507 | } |
| 508 | $$ = new t_const_value($1); |
| 509 | } |
Mark Slee | 67fc634 | 2006-11-29 03:37:04 +0000 | [diff] [blame] | 510 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 511 | | ConstList |
| 512 | { |
| 513 | pdebug("ConstValue => ConstList"); |
| 514 | $$ = $1; |
| 515 | } |
| 516 | | ConstMap |
| 517 | { |
| 518 | pdebug("ConstValue => ConstMap"); |
| 519 | $$ = $1; |
| 520 | } |
| 521 | |
| 522 | ConstList: |
| 523 | '[' ConstListContents ']' |
| 524 | { |
| 525 | pdebug("ConstList => [ ConstListContents ]"); |
| 526 | $$ = $2; |
| 527 | } |
| 528 | |
| 529 | ConstListContents: |
| 530 | ConstListContents ConstValue CommaOrSemicolonOptional |
| 531 | { |
| 532 | pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional"); |
| 533 | $$ = $1; |
| 534 | $$->add_list($2); |
| 535 | } |
| 536 | | |
| 537 | { |
| 538 | pdebug("ConstListContents =>"); |
| 539 | $$ = new t_const_value(); |
| 540 | $$->set_list(); |
| 541 | } |
| 542 | |
| 543 | ConstMap: |
| 544 | '{' ConstMapContents '}' |
| 545 | { |
| 546 | pdebug("ConstMap => { ConstMapContents }"); |
| 547 | $$ = $2; |
| 548 | } |
| 549 | |
| 550 | ConstMapContents: |
| 551 | ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional |
| 552 | { |
| 553 | pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional"); |
| 554 | $$ = $1; |
| 555 | $$->add_map($2, $4); |
| 556 | } |
| 557 | | |
| 558 | { |
| 559 | pdebug("ConstMapContents =>"); |
| 560 | $$ = new t_const_value(); |
| 561 | $$->set_map(); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | Struct: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 565 | DocTextOptional tok_struct tok_identifier XsdAll '{' FieldList '}' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 566 | { |
| 567 | pdebug("Struct -> tok_struct tok_identifier { FieldList }"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 568 | $6->set_name($3); |
| 569 | if ($1 != NULL) { |
| 570 | $6->set_doc($1); |
| 571 | } |
| 572 | $6->set_xsd_all($4); |
| 573 | $$ = $6; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 574 | y_field_val = -1; |
| 575 | } |
| 576 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 577 | XsdAll: |
Mark Slee | 782abbb | 2007-01-19 00:17:02 +0000 | [diff] [blame] | 578 | tok_xsd_all |
| 579 | { |
| 580 | $$ = true; |
| 581 | } |
| 582 | | |
| 583 | { |
| 584 | $$ = false; |
| 585 | } |
| 586 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 587 | XsdOptional: |
| 588 | tok_xsd_optional |
| 589 | { |
| 590 | $$ = true; |
| 591 | } |
| 592 | | |
| 593 | { |
| 594 | $$ = false; |
| 595 | } |
| 596 | |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 597 | XsdNillable: |
| 598 | tok_xsd_nillable |
| 599 | { |
| 600 | $$ = true; |
| 601 | } |
| 602 | | |
| 603 | { |
| 604 | $$ = false; |
| 605 | } |
| 606 | |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 607 | XsdAttributes: |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 608 | tok_xsd_attrs '{' FieldList '}' |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 609 | { |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 610 | $$ = $3; |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 611 | } |
| 612 | | |
| 613 | { |
| 614 | $$ = NULL; |
| 615 | } |
| 616 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 617 | Xception: |
| 618 | tok_xception tok_identifier '{' FieldList '}' |
| 619 | { |
| 620 | pdebug("Xception -> tok_xception tok_identifier { FieldList }"); |
| 621 | $4->set_name($2); |
| 622 | $4->set_xception(true); |
| 623 | $$ = $4; |
| 624 | y_field_val = -1; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | Service: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 628 | DocTextOptional tok_service tok_identifier Extends '{' FunctionList '}' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 629 | { |
| 630 | pdebug("Service -> tok_service tok_identifier { FunctionList }"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 631 | $$ = $6; |
| 632 | $$->set_name($3); |
| 633 | $$->set_extends($4); |
| 634 | if ($1 != NULL) { |
| 635 | $$->set_doc($1); |
| 636 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 639 | Extends: |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 640 | tok_extends tok_identifier |
| 641 | { |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 642 | pdebug("Extends -> tok_extends tok_identifier"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 643 | $$ = NULL; |
| 644 | if (g_parse_mode == PROGRAM) { |
| 645 | $$ = g_scope->get_service($2); |
| 646 | if ($$ == NULL) { |
| 647 | yyerror("Service \"%s\" has not been defined.", $2); |
| 648 | exit(1); |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | | |
| 653 | { |
| 654 | $$ = NULL; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | FunctionList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 658 | FunctionList Function |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 659 | { |
| 660 | pdebug("FunctionList -> FunctionList Function"); |
| 661 | $$ = $1; |
| 662 | $1->add_function($2); |
| 663 | } |
| 664 | | |
| 665 | { |
| 666 | pdebug("FunctionList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 667 | $$ = new t_service(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | Function: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 671 | DocTextOptional Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 672 | { |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 673 | $6->set_name(std::string($4) + "_args"); |
| 674 | $$ = new t_function($3, $4, $6, $8, $2); |
| 675 | if ($1 != NULL) { |
| 676 | $$->set_doc($1); |
| 677 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 678 | y_field_val = -1; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 679 | } |
| 680 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 681 | Async: |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 682 | tok_async |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 683 | { |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 684 | $$ = true; |
| 685 | } |
| 686 | | |
| 687 | { |
| 688 | $$ = false; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 691 | Throws: |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 692 | tok_throws '(' FieldList ')' |
| 693 | { |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 694 | pdebug("Throws -> tok_throws ( FieldList )"); |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 695 | $$ = $3; |
| 696 | } |
| 697 | | |
| 698 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 699 | $$ = new t_struct(g_program); |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 702 | FieldList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 703 | FieldList Field |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 704 | { |
| 705 | pdebug("FieldList -> FieldList , Field"); |
| 706 | $$ = $1; |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 707 | $$->append($2); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 708 | } |
| 709 | | |
| 710 | { |
| 711 | pdebug("FieldList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 712 | $$ = new t_struct(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | Field: |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 716 | DocTextOptional FieldIdentifier FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 717 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 718 | pdebug("tok_int_constant : Field -> FieldType tok_identifier"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 719 | if ($2 < 0) { |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 720 | pwarning(2, "No field key specified for %s, resulting protocol may have conflicts or not be backwards compatible!\n", $4); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 721 | } |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 722 | $$ = new t_field($3, $4, $2); |
| 723 | if ($5 != NULL) { |
| 724 | validate_field_value($$, $5); |
| 725 | $$->set_value($5); |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 726 | } |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 727 | $$->set_xsd_optional($6); |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 728 | $$->set_xsd_nillable($7); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 729 | if ($1 != NULL) { |
| 730 | $$->set_doc($1); |
| 731 | } |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 732 | if ($8 != NULL) { |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 733 | $$->set_xsd_attrs($8); |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 734 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 735 | } |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 736 | |
| 737 | FieldIdentifier: |
| 738 | tok_int_constant ':' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 739 | { |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 740 | if ($1 <= 0) { |
| 741 | pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1); |
| 742 | $1 = y_field_val--; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 743 | } |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 744 | $$ = $1; |
| 745 | } |
| 746 | | |
| 747 | { |
| 748 | $$ = y_field_val--; |
| 749 | } |
| 750 | |
| 751 | FieldValue: |
| 752 | '=' ConstValue |
| 753 | { |
| 754 | if (g_parse_mode == PROGRAM) { |
| 755 | $$ = $2; |
| 756 | } else { |
| 757 | $$ = NULL; |
| 758 | } |
| 759 | } |
| 760 | | |
| 761 | { |
| 762 | $$ = NULL; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 763 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 764 | |
| 765 | DefinitionType: |
| 766 | BaseType |
| 767 | { |
| 768 | pdebug("DefinitionType -> BaseType"); |
| 769 | $$ = $1; |
| 770 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 771 | | ContainerType |
| 772 | { |
| 773 | pdebug("DefinitionType -> ContainerType"); |
| 774 | $$ = $1; |
| 775 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 776 | |
| 777 | FunctionType: |
| 778 | FieldType |
| 779 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 780 | pdebug("FunctionType -> FieldType"); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 781 | $$ = $1; |
| 782 | } |
| 783 | | tok_void |
| 784 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 785 | pdebug("FunctionType -> tok_void"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 786 | $$ = g_type_void; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | FieldType: |
| 790 | tok_identifier |
| 791 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 792 | pdebug("FieldType -> tok_identifier"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 793 | if (g_parse_mode == INCLUDES) { |
| 794 | // Ignore identifiers in include mode |
| 795 | $$ = NULL; |
| 796 | } else { |
| 797 | // Lookup the identifier in the current scope |
| 798 | $$ = g_scope->get_type($1); |
| 799 | if ($$ == NULL) { |
| 800 | yyerror("Type \"%s\" has not been defined.", $1); |
| 801 | exit(1); |
| 802 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 803 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 804 | } |
| 805 | | BaseType |
| 806 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 807 | pdebug("FieldType -> BaseType"); |
| 808 | $$ = $1; |
| 809 | } |
| 810 | | ContainerType |
| 811 | { |
| 812 | pdebug("FieldType -> ContainerType"); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 813 | $$ = $1; |
| 814 | } |
| 815 | |
| 816 | BaseType: |
| 817 | tok_string |
| 818 | { |
| 819 | pdebug("BaseType -> tok_string"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 820 | $$ = g_type_string; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 821 | } |
Mark Slee | 8d725a2 | 2007-04-13 01:57:12 +0000 | [diff] [blame] | 822 | | tok_binary |
| 823 | { |
| 824 | pdebug("BaseType -> tok_binary"); |
| 825 | $$ = g_type_binary; |
| 826 | } |
Mark Slee | b6200d8 | 2007-01-19 19:14:36 +0000 | [diff] [blame] | 827 | | tok_slist |
| 828 | { |
| 829 | pdebug("BaseType -> tok_slist"); |
| 830 | $$ = g_type_slist; |
| 831 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 832 | | tok_bool |
| 833 | { |
| 834 | pdebug("BaseType -> tok_bool"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 835 | $$ = g_type_bool; |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 836 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 837 | | tok_byte |
| 838 | { |
| 839 | pdebug("BaseType -> tok_byte"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 840 | $$ = g_type_byte; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 841 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 842 | | tok_i16 |
| 843 | { |
| 844 | pdebug("BaseType -> tok_i16"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 845 | $$ = g_type_i16; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 846 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 847 | | tok_i32 |
| 848 | { |
| 849 | pdebug("BaseType -> tok_i32"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 850 | $$ = g_type_i32; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 851 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 852 | | tok_i64 |
| 853 | { |
| 854 | pdebug("BaseType -> tok_i64"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 855 | $$ = g_type_i64; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 856 | } |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 857 | | tok_double |
| 858 | { |
| 859 | pdebug("BaseType -> tok_double"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 860 | $$ = g_type_double; |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 861 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 862 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 863 | ContainerType: |
| 864 | MapType |
| 865 | { |
| 866 | pdebug("ContainerType -> MapType"); |
| 867 | $$ = $1; |
| 868 | } |
| 869 | | SetType |
| 870 | { |
| 871 | pdebug("ContainerType -> SetType"); |
| 872 | $$ = $1; |
| 873 | } |
| 874 | | ListType |
| 875 | { |
| 876 | pdebug("ContainerType -> ListType"); |
| 877 | $$ = $1; |
| 878 | } |
| 879 | |
| 880 | MapType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 881 | tok_map CppType '<' FieldType ',' FieldType '>' |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 882 | { |
| 883 | pdebug("MapType -> tok_map <FieldType, FieldType>"); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 884 | $$ = new t_map($4, $6); |
| 885 | if ($2 != NULL) { |
| 886 | ((t_container*)$$)->set_cpp_name(std::string($2)); |
| 887 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | SetType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 891 | tok_set CppType '<' FieldType '>' |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 892 | { |
| 893 | pdebug("SetType -> tok_set<FieldType>"); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 894 | $$ = new t_set($4); |
| 895 | if ($2 != NULL) { |
| 896 | ((t_container*)$$)->set_cpp_name(std::string($2)); |
| 897 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | ListType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 901 | tok_list '<' FieldType '>' CppType |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 902 | { |
| 903 | pdebug("ListType -> tok_list<FieldType>"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 904 | $$ = new t_list($3); |
| 905 | if ($5 != NULL) { |
| 906 | ((t_container*)$$)->set_cpp_name(std::string($5)); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 907 | } |
| 908 | } |
| 909 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 910 | CppType: |
Mark Slee | afc7654 | 2007-02-09 21:55:44 +0000 | [diff] [blame] | 911 | tok_cpp_type tok_literal |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 912 | { |
Mark Slee | afc7654 | 2007-02-09 21:55:44 +0000 | [diff] [blame] | 913 | $$ = $2; |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 914 | } |
| 915 | | |
| 916 | { |
| 917 | $$ = NULL; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 918 | } |
| 919 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 920 | %% |