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