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