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