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 | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 414 | } |
| 415 | | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 416 | DocTextOptional tok_identifier CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 417 | { |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 418 | pdebug("EnumDef -> tok_identifier"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 419 | $$ = new t_enum_value($2); |
| 420 | if ($1 != NULL) { |
| 421 | $$->set_doc($1); |
| 422 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 425 | Senum: |
| 426 | DocTextOptional tok_senum tok_identifier '{' SenumDefList '}' |
| 427 | { |
| 428 | pdebug("Senum -> tok_senum tok_identifier { SenumDefList }"); |
| 429 | $$ = new t_typedef(g_program, $5, $3); |
| 430 | if ($1 != NULL) { |
| 431 | $$->set_doc($1); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | SenumDefList: |
| 436 | SenumDefList SenumDef |
| 437 | { |
| 438 | pdebug("SenumDefList -> SenumDefList SenumDef"); |
| 439 | $$ = $1; |
| 440 | $$->add_string_enum_val($2); |
| 441 | } |
| 442 | | |
| 443 | { |
| 444 | pdebug("SenumDefList -> "); |
| 445 | $$ = new t_base_type("string", t_base_type::TYPE_STRING); |
| 446 | $$->set_string_enum(true); |
| 447 | } |
| 448 | |
| 449 | SenumDef: |
| 450 | tok_literal CommaOrSemicolonOptional |
| 451 | { |
| 452 | pdebug("SenumDef -> tok_literal"); |
| 453 | $$ = $1; |
| 454 | } |
| 455 | |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 456 | Const: |
| 457 | tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional |
| 458 | { |
| 459 | pdebug("Const -> tok_const FieldType tok_identifier = ConstValue"); |
Mark Slee | aa7671d | 2006-11-29 03:19:31 +0000 | [diff] [blame] | 460 | if (g_parse_mode == PROGRAM) { |
| 461 | $$ = new t_const($2, $3, $5); |
| 462 | validate_const_type($$); |
| 463 | } else { |
| 464 | $$ = NULL; |
| 465 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | ConstValue: |
| 469 | tok_int_constant |
| 470 | { |
| 471 | pdebug("ConstValue => tok_int_constant"); |
| 472 | $$ = new t_const_value(); |
| 473 | $$->set_integer($1); |
| 474 | } |
| 475 | | tok_dub_constant |
| 476 | { |
| 477 | pdebug("ConstValue => tok_dub_constant"); |
| 478 | $$ = new t_const_value(); |
| 479 | $$->set_double($1); |
| 480 | } |
| 481 | | tok_literal |
| 482 | { |
| 483 | pdebug("ConstValue => tok_literal"); |
| 484 | $$ = new t_const_value(); |
| 485 | $$->set_string($1); |
| 486 | } |
Mark Slee | 67fc634 | 2006-11-29 03:37:04 +0000 | [diff] [blame] | 487 | | tok_identifier |
| 488 | { |
| 489 | pdebug("ConstValue => tok_identifier"); |
| 490 | $$ = new t_const_value(); |
| 491 | $$->set_string($1); |
| 492 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 493 | | ConstList |
| 494 | { |
| 495 | pdebug("ConstValue => ConstList"); |
| 496 | $$ = $1; |
| 497 | } |
| 498 | | ConstMap |
| 499 | { |
| 500 | pdebug("ConstValue => ConstMap"); |
| 501 | $$ = $1; |
| 502 | } |
| 503 | |
| 504 | ConstList: |
| 505 | '[' ConstListContents ']' |
| 506 | { |
| 507 | pdebug("ConstList => [ ConstListContents ]"); |
| 508 | $$ = $2; |
| 509 | } |
| 510 | |
| 511 | ConstListContents: |
| 512 | ConstListContents ConstValue CommaOrSemicolonOptional |
| 513 | { |
| 514 | pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional"); |
| 515 | $$ = $1; |
| 516 | $$->add_list($2); |
| 517 | } |
| 518 | | |
| 519 | { |
| 520 | pdebug("ConstListContents =>"); |
| 521 | $$ = new t_const_value(); |
| 522 | $$->set_list(); |
| 523 | } |
| 524 | |
| 525 | ConstMap: |
| 526 | '{' ConstMapContents '}' |
| 527 | { |
| 528 | pdebug("ConstMap => { ConstMapContents }"); |
| 529 | $$ = $2; |
| 530 | } |
| 531 | |
| 532 | ConstMapContents: |
| 533 | ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional |
| 534 | { |
| 535 | pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional"); |
| 536 | $$ = $1; |
| 537 | $$->add_map($2, $4); |
| 538 | } |
| 539 | | |
| 540 | { |
| 541 | pdebug("ConstMapContents =>"); |
| 542 | $$ = new t_const_value(); |
| 543 | $$->set_map(); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | Struct: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 547 | DocTextOptional tok_struct tok_identifier XsdAll '{' FieldList '}' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 548 | { |
| 549 | pdebug("Struct -> tok_struct tok_identifier { FieldList }"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 550 | $6->set_name($3); |
| 551 | if ($1 != NULL) { |
| 552 | $6->set_doc($1); |
| 553 | } |
| 554 | $6->set_xsd_all($4); |
| 555 | $$ = $6; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 556 | y_field_val = -1; |
| 557 | } |
| 558 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 559 | XsdAll: |
Mark Slee | 782abbb | 2007-01-19 00:17:02 +0000 | [diff] [blame] | 560 | tok_xsd_all |
| 561 | { |
| 562 | $$ = true; |
| 563 | } |
| 564 | | |
| 565 | { |
| 566 | $$ = false; |
| 567 | } |
| 568 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 569 | XsdOptional: |
| 570 | tok_xsd_optional |
| 571 | { |
| 572 | $$ = true; |
| 573 | } |
| 574 | | |
| 575 | { |
| 576 | $$ = false; |
| 577 | } |
| 578 | |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 579 | XsdNillable: |
| 580 | tok_xsd_nillable |
| 581 | { |
| 582 | $$ = true; |
| 583 | } |
| 584 | | |
| 585 | { |
| 586 | $$ = false; |
| 587 | } |
| 588 | |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 589 | XsdAttributes: |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 590 | tok_xsd_attrs '{' FieldList '}' |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 591 | { |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 592 | $$ = $3; |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 593 | } |
| 594 | | |
| 595 | { |
| 596 | $$ = NULL; |
| 597 | } |
| 598 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 599 | Xception: |
| 600 | tok_xception tok_identifier '{' FieldList '}' |
| 601 | { |
| 602 | pdebug("Xception -> tok_xception tok_identifier { FieldList }"); |
| 603 | $4->set_name($2); |
| 604 | $4->set_xception(true); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 605 | /* |
| 606 | if ($4 != NULL) { |
| 607 | $5->set_doc($4); |
| 608 | } |
| 609 | */ |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 610 | $$ = $4; |
| 611 | y_field_val = -1; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | Service: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 615 | DocTextOptional tok_service tok_identifier Extends '{' FunctionList '}' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 616 | { |
| 617 | pdebug("Service -> tok_service tok_identifier { FunctionList }"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 618 | $$ = $6; |
| 619 | $$->set_name($3); |
| 620 | $$->set_extends($4); |
| 621 | if ($1 != NULL) { |
| 622 | $$->set_doc($1); |
| 623 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 626 | Extends: |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 627 | tok_extends tok_identifier |
| 628 | { |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 629 | pdebug("Extends -> tok_extends tok_identifier"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 630 | $$ = NULL; |
| 631 | if (g_parse_mode == PROGRAM) { |
| 632 | $$ = g_scope->get_service($2); |
| 633 | if ($$ == NULL) { |
| 634 | yyerror("Service \"%s\" has not been defined.", $2); |
| 635 | exit(1); |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | | |
| 640 | { |
| 641 | $$ = NULL; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | FunctionList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 645 | FunctionList Function |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 646 | { |
| 647 | pdebug("FunctionList -> FunctionList Function"); |
| 648 | $$ = $1; |
| 649 | $1->add_function($2); |
| 650 | } |
| 651 | | |
| 652 | { |
| 653 | pdebug("FunctionList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 654 | $$ = new t_service(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | Function: |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 658 | DocTextOptional Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 659 | { |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 660 | $6->set_name(std::string($4) + "_args"); |
| 661 | $$ = new t_function($3, $4, $6, $8, $2); |
| 662 | if ($1 != NULL) { |
| 663 | $$->set_doc($1); |
| 664 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 665 | y_field_val = -1; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 668 | Async: |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 669 | tok_async |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 670 | { |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 671 | $$ = true; |
| 672 | } |
| 673 | | |
| 674 | { |
| 675 | $$ = false; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 678 | Throws: |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 679 | tok_throws '(' FieldList ')' |
| 680 | { |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 681 | pdebug("Throws -> tok_throws ( FieldList )"); |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 682 | $$ = $3; |
| 683 | } |
| 684 | | |
| 685 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 686 | $$ = new t_struct(g_program); |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 689 | FieldList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 690 | FieldList Field |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 691 | { |
| 692 | pdebug("FieldList -> FieldList , Field"); |
| 693 | $$ = $1; |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 694 | $$->append($2); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 695 | } |
| 696 | | |
| 697 | { |
| 698 | pdebug("FieldList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 699 | $$ = new t_struct(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | Field: |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 703 | DocTextOptional FieldIdentifier FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 704 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 705 | pdebug("tok_int_constant : Field -> FieldType tok_identifier"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 706 | if ($2 < 0) { |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 707 | 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] | 708 | } |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 709 | $$ = new t_field($3, $4, $2); |
| 710 | if ($5 != NULL) { |
| 711 | validate_field_value($$, $5); |
| 712 | $$->set_value($5); |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 713 | } |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 714 | $$->set_xsd_optional($6); |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 715 | $$->set_xsd_nillable($7); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 716 | if ($1 != NULL) { |
| 717 | $$->set_doc($1); |
| 718 | } |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 719 | if ($8 != NULL) { |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 720 | $$->set_xsd_attrs($8); |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 721 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 722 | } |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 723 | |
| 724 | FieldIdentifier: |
| 725 | tok_int_constant ':' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 726 | { |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 727 | if ($1 <= 0) { |
| 728 | pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1); |
| 729 | $1 = y_field_val--; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 730 | } |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 731 | $$ = $1; |
| 732 | } |
| 733 | | |
| 734 | { |
| 735 | $$ = y_field_val--; |
| 736 | } |
| 737 | |
| 738 | FieldValue: |
| 739 | '=' ConstValue |
| 740 | { |
| 741 | if (g_parse_mode == PROGRAM) { |
| 742 | $$ = $2; |
| 743 | } else { |
| 744 | $$ = NULL; |
| 745 | } |
| 746 | } |
| 747 | | |
| 748 | { |
| 749 | $$ = NULL; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 750 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 751 | |
| 752 | DefinitionType: |
| 753 | BaseType |
| 754 | { |
| 755 | pdebug("DefinitionType -> BaseType"); |
| 756 | $$ = $1; |
| 757 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 758 | | ContainerType |
| 759 | { |
| 760 | pdebug("DefinitionType -> ContainerType"); |
| 761 | $$ = $1; |
| 762 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 763 | |
| 764 | FunctionType: |
| 765 | FieldType |
| 766 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 767 | pdebug("FunctionType -> FieldType"); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 768 | $$ = $1; |
| 769 | } |
| 770 | | tok_void |
| 771 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 772 | pdebug("FunctionType -> tok_void"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 773 | $$ = g_type_void; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | FieldType: |
| 777 | tok_identifier |
| 778 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 779 | pdebug("FieldType -> tok_identifier"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 780 | if (g_parse_mode == INCLUDES) { |
| 781 | // Ignore identifiers in include mode |
| 782 | $$ = NULL; |
| 783 | } else { |
| 784 | // Lookup the identifier in the current scope |
| 785 | $$ = g_scope->get_type($1); |
| 786 | if ($$ == NULL) { |
| 787 | yyerror("Type \"%s\" has not been defined.", $1); |
| 788 | exit(1); |
| 789 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 790 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 791 | } |
| 792 | | BaseType |
| 793 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 794 | pdebug("FieldType -> BaseType"); |
| 795 | $$ = $1; |
| 796 | } |
| 797 | | ContainerType |
| 798 | { |
| 799 | pdebug("FieldType -> ContainerType"); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 800 | $$ = $1; |
| 801 | } |
| 802 | |
| 803 | BaseType: |
| 804 | tok_string |
| 805 | { |
| 806 | pdebug("BaseType -> tok_string"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 807 | $$ = g_type_string; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 808 | } |
Mark Slee | 8d725a2 | 2007-04-13 01:57:12 +0000 | [diff] [blame] | 809 | | tok_binary |
| 810 | { |
| 811 | pdebug("BaseType -> tok_binary"); |
| 812 | $$ = g_type_binary; |
| 813 | } |
Mark Slee | b6200d8 | 2007-01-19 19:14:36 +0000 | [diff] [blame] | 814 | | tok_slist |
| 815 | { |
| 816 | pdebug("BaseType -> tok_slist"); |
| 817 | $$ = g_type_slist; |
| 818 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 819 | | tok_bool |
| 820 | { |
| 821 | pdebug("BaseType -> tok_bool"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 822 | $$ = g_type_bool; |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 823 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 824 | | tok_byte |
| 825 | { |
| 826 | pdebug("BaseType -> tok_byte"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 827 | $$ = g_type_byte; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 828 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 829 | | tok_i16 |
| 830 | { |
| 831 | pdebug("BaseType -> tok_i16"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 832 | $$ = g_type_i16; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 833 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 834 | | tok_i32 |
| 835 | { |
| 836 | pdebug("BaseType -> tok_i32"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 837 | $$ = g_type_i32; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 838 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 839 | | tok_i64 |
| 840 | { |
| 841 | pdebug("BaseType -> tok_i64"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 842 | $$ = g_type_i64; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 843 | } |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 844 | | tok_double |
| 845 | { |
| 846 | pdebug("BaseType -> tok_double"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 847 | $$ = g_type_double; |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 848 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 849 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 850 | ContainerType: |
| 851 | MapType |
| 852 | { |
| 853 | pdebug("ContainerType -> MapType"); |
| 854 | $$ = $1; |
| 855 | } |
| 856 | | SetType |
| 857 | { |
| 858 | pdebug("ContainerType -> SetType"); |
| 859 | $$ = $1; |
| 860 | } |
| 861 | | ListType |
| 862 | { |
| 863 | pdebug("ContainerType -> ListType"); |
| 864 | $$ = $1; |
| 865 | } |
| 866 | |
| 867 | MapType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 868 | tok_map CppType '<' FieldType ',' FieldType '>' |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 869 | { |
| 870 | pdebug("MapType -> tok_map <FieldType, FieldType>"); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 871 | $$ = new t_map($4, $6); |
| 872 | if ($2 != NULL) { |
| 873 | ((t_container*)$$)->set_cpp_name(std::string($2)); |
| 874 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | SetType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 878 | tok_set CppType '<' FieldType '>' |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 879 | { |
| 880 | pdebug("SetType -> tok_set<FieldType>"); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 881 | $$ = new t_set($4); |
| 882 | if ($2 != NULL) { |
| 883 | ((t_container*)$$)->set_cpp_name(std::string($2)); |
| 884 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | ListType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 888 | tok_list '<' FieldType '>' CppType |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 889 | { |
| 890 | pdebug("ListType -> tok_list<FieldType>"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 891 | $$ = new t_list($3); |
| 892 | if ($5 != NULL) { |
| 893 | ((t_container*)$$)->set_cpp_name(std::string($5)); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 897 | CppType: |
Mark Slee | afc7654 | 2007-02-09 21:55:44 +0000 | [diff] [blame] | 898 | tok_cpp_type tok_literal |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 899 | { |
Mark Slee | afc7654 | 2007-02-09 21:55:44 +0000 | [diff] [blame] | 900 | $$ = $2; |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 901 | } |
| 902 | | |
| 903 | { |
| 904 | $$ = NULL; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 905 | } |
| 906 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 907 | %% |