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