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