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