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