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