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