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