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