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 | 320e45c | 2008-03-27 21:41:54 +0000 | [diff] [blame] | 280 | /* TODO(dreiss): Get rid of this once everyone is using the new hotness. */ |
David Reiss | c6fc329 | 2007-08-30 00:58:43 +0000 | [diff] [blame] | 281 | | tok_py_module tok_identifier |
| 282 | { |
David Reiss | 320e45c | 2008-03-27 21:41:54 +0000 | [diff] [blame] | 283 | pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead"); |
David Reiss | c6fc329 | 2007-08-30 00:58:43 +0000 | [diff] [blame] | 284 | pdebug("Header -> tok_py_module tok_identifier"); |
| 285 | if (g_parse_mode == PROGRAM) { |
David Reiss | 320e45c | 2008-03-27 21:41:54 +0000 | [diff] [blame] | 286 | g_program->set_namespace("py", $2); |
David Reiss | c6fc329 | 2007-08-30 00:58:43 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 289 | | tok_perl_package tok_identifier |
| 290 | { |
| 291 | pdebug("Header -> tok_perl_namespace tok_identifier"); |
| 292 | if (g_parse_mode == PROGRAM) { |
| 293 | g_program->set_perl_package($2); |
| 294 | } |
| 295 | } |
David Reiss | 6a4b82c | 2008-03-27 21:42:16 +0000 | [diff] [blame^] | 296 | /* TODO(dreiss): Get rid of this once everyone is using the new hotness. */ |
Mark Slee | 58dfb4f | 2007-07-06 02:45:25 +0000 | [diff] [blame] | 297 | | tok_ruby_namespace tok_identifier |
| 298 | { |
David Reiss | 6a4b82c | 2008-03-27 21:42:16 +0000 | [diff] [blame^] | 299 | pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead"); |
Mark Slee | 58dfb4f | 2007-07-06 02:45:25 +0000 | [diff] [blame] | 300 | pdebug("Header -> tok_ruby_namespace tok_identifier"); |
| 301 | if (g_parse_mode == PROGRAM) { |
David Reiss | 6a4b82c | 2008-03-27 21:42:16 +0000 | [diff] [blame^] | 302 | g_program->set_namespace("rb", $2); |
Mark Slee | 58dfb4f | 2007-07-06 02:45:25 +0000 | [diff] [blame] | 303 | } |
| 304 | } |
David Reiss | 3b45501 | 2008-03-27 21:40:46 +0000 | [diff] [blame] | 305 | /* 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] | 306 | | tok_smalltalk_category tok_st_identifier |
| 307 | { |
David Reiss | 3b45501 | 2008-03-27 21:40:46 +0000 | [diff] [blame] | 308 | pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead"); |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 309 | pdebug("Header -> tok_smalltalk_category tok_st_identifier"); |
| 310 | if (g_parse_mode == PROGRAM) { |
David Reiss | 3b45501 | 2008-03-27 21:40:46 +0000 | [diff] [blame] | 311 | g_program->set_namespace("smalltalk.category", $2); |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 312 | } |
| 313 | } |
David Reiss | 3b45501 | 2008-03-27 21:40:46 +0000 | [diff] [blame] | 314 | /* 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] | 315 | | tok_smalltalk_prefix tok_identifier |
| 316 | { |
David Reiss | 3b45501 | 2008-03-27 21:40:46 +0000 | [diff] [blame] | 317 | pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead"); |
David Reiss | 15457c9 | 2007-12-14 07:03:03 +0000 | [diff] [blame] | 318 | pdebug("Header -> tok_smalltalk_prefix tok_identifier"); |
| 319 | if (g_parse_mode == PROGRAM) { |
David Reiss | 3b45501 | 2008-03-27 21:40:46 +0000 | [diff] [blame] | 320 | g_program->set_namespace("smalltalk.prefix", $2); |
David Reiss | 15457c9 | 2007-12-14 07:03:03 +0000 | [diff] [blame] | 321 | } |
| 322 | } |
David Reiss | 771f8c7 | 2008-02-27 01:55:25 +0000 | [diff] [blame] | 323 | /* 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] | 324 | | tok_java_package tok_identifier |
| 325 | { |
David Reiss | 9f64615 | 2008-03-02 21:59:48 +0000 | [diff] [blame] | 326 | pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 327 | pdebug("Header -> tok_java_package tok_identifier"); |
| 328 | if (g_parse_mode == PROGRAM) { |
David Reiss | 771f8c7 | 2008-02-27 01:55:25 +0000 | [diff] [blame] | 329 | g_program->set_namespace("java", $2); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 330 | } |
| 331 | } |
David Reiss | 54b602b | 2008-03-27 21:41:06 +0000 | [diff] [blame] | 332 | /* 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] | 333 | | tok_cocoa_prefix tok_identifier |
| 334 | { |
David Reiss | 54b602b | 2008-03-27 21:41:06 +0000 | [diff] [blame] | 335 | pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead"); |
Mark Slee | 7e9eea4 | 2007-09-10 21:00:23 +0000 | [diff] [blame] | 336 | pdebug("Header -> tok_cocoa_prefix tok_identifier"); |
| 337 | if (g_parse_mode == PROGRAM) { |
David Reiss | 54b602b | 2008-03-27 21:41:06 +0000 | [diff] [blame] | 338 | g_program->set_namespace("cocoa", $2); |
Mark Slee | 7e9eea4 | 2007-09-10 21:00:23 +0000 | [diff] [blame] | 339 | } |
| 340 | } |
Mark Slee | 0d9199e | 2007-01-31 02:08:30 +0000 | [diff] [blame] | 341 | | tok_xsd_namespace tok_literal |
| 342 | { |
| 343 | pdebug("Header -> tok_xsd_namespace tok_literal"); |
| 344 | if (g_parse_mode == PROGRAM) { |
| 345 | g_program->set_xsd_namespace($2); |
| 346 | } |
| 347 | } |
David Reiss | 9d65bf0 | 2008-03-27 21:41:37 +0000 | [diff] [blame] | 348 | /* 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] | 349 | | tok_csharp_namespace tok_identifier |
| 350 | { |
David Reiss | 9d65bf0 | 2008-03-27 21:41:37 +0000 | [diff] [blame] | 351 | pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead"); |
David Reiss | 919ae80 | 2008-03-27 21:41:11 +0000 | [diff] [blame] | 352 | pdebug("Header -> tok_csharp_namespace tok_identifier"); |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 353 | if (g_parse_mode == PROGRAM) { |
David Reiss | 9d65bf0 | 2008-03-27 21:41:37 +0000 | [diff] [blame] | 354 | g_program->set_namespace("csharp", $2); |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 355 | } |
| 356 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 357 | |
| 358 | Include: |
| 359 | tok_include tok_literal |
| 360 | { |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 361 | pdebug("Include -> tok_include tok_literal"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 362 | if (g_parse_mode == INCLUDES) { |
| 363 | std::string path = include_file(std::string($2)); |
| 364 | if (!path.empty()) { |
kholst | 76f2c88 | 2008-01-16 02:47:41 +0000 | [diff] [blame] | 365 | g_program->add_include(path, std::string($2)); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 369 | |
| 370 | DefinitionList: |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 371 | DefinitionList CaptureDocText Definition |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 372 | { |
| 373 | pdebug("DefinitionList -> DefinitionList Definition"); |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 374 | if ($2 != NULL && $3 != NULL) { |
| 375 | $3->set_doc($2); |
| 376 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 377 | } |
| 378 | | |
| 379 | { |
| 380 | pdebug("DefinitionList -> "); |
| 381 | } |
| 382 | |
| 383 | Definition: |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 384 | Const |
| 385 | { |
| 386 | pdebug("Definition -> Const"); |
| 387 | if (g_parse_mode == PROGRAM) { |
| 388 | g_program->add_const($1); |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 389 | } |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 390 | $$ = $1; |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 391 | } |
| 392 | | TypeDefinition |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 393 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 394 | pdebug("Definition -> TypeDefinition"); |
| 395 | if (g_parse_mode == PROGRAM) { |
| 396 | g_scope->add_type($1->get_name(), $1); |
| 397 | if (g_parent_scope != NULL) { |
| 398 | g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1); |
| 399 | } |
| 400 | } |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 401 | $$ = $1; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 402 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 403 | | Service |
| 404 | { |
| 405 | pdebug("Definition -> Service"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 406 | if (g_parse_mode == PROGRAM) { |
| 407 | g_scope->add_service($1->get_name(), $1); |
| 408 | if (g_parent_scope != NULL) { |
| 409 | g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1); |
| 410 | } |
| 411 | g_program->add_service($1); |
| 412 | } |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 413 | $$ = $1; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 414 | } |
| 415 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 416 | TypeDefinition: |
| 417 | Typedef |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 418 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 419 | pdebug("TypeDefinition -> Typedef"); |
| 420 | if (g_parse_mode == PROGRAM) { |
| 421 | g_program->add_typedef($1); |
| 422 | } |
| 423 | } |
| 424 | | Enum |
| 425 | { |
| 426 | pdebug("TypeDefinition -> Enum"); |
| 427 | if (g_parse_mode == PROGRAM) { |
| 428 | g_program->add_enum($1); |
| 429 | } |
| 430 | } |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 431 | | Senum |
| 432 | { |
| 433 | pdebug("TypeDefinition -> Senum"); |
| 434 | if (g_parse_mode == PROGRAM) { |
| 435 | g_program->add_typedef($1); |
| 436 | } |
| 437 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 438 | | Struct |
| 439 | { |
| 440 | pdebug("TypeDefinition -> Struct"); |
| 441 | if (g_parse_mode == PROGRAM) { |
| 442 | g_program->add_struct($1); |
| 443 | } |
| 444 | } |
| 445 | | Xception |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 446 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 447 | pdebug("TypeDefinition -> Xception"); |
| 448 | if (g_parse_mode == PROGRAM) { |
| 449 | g_program->add_xception($1); |
| 450 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 451 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 452 | |
| 453 | Typedef: |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 454 | tok_typedef DefinitionType tok_identifier |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 455 | { |
| 456 | pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier"); |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 457 | t_typedef *td = new t_typedef(g_program, $2, $3); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 458 | $$ = td; |
| 459 | } |
| 460 | |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 461 | CommaOrSemicolonOptional: |
| 462 | ',' |
| 463 | {} |
| 464 | | ';' |
| 465 | {} |
| 466 | | |
| 467 | {} |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 468 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 469 | Enum: |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 470 | tok_enum tok_identifier '{' EnumDefList '}' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 471 | { |
| 472 | pdebug("Enum -> tok_enum tok_identifier { EnumDefList }"); |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 473 | $$ = $4; |
| 474 | $$->set_name($2); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | EnumDefList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 478 | EnumDefList EnumDef |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 479 | { |
| 480 | pdebug("EnumDefList -> EnumDefList EnumDef"); |
| 481 | $$ = $1; |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 482 | $$->append($2); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 483 | } |
| 484 | | |
| 485 | { |
| 486 | pdebug("EnumDefList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 487 | $$ = new t_enum(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | EnumDef: |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 491 | CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 492 | { |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 493 | pdebug("EnumDef -> tok_identifier = tok_int_constant"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 494 | if ($4 < 0) { |
| 495 | pwarning(1, "Negative value supplied for enum %s.\n", $2); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 496 | } |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 497 | $$ = new t_enum_value($2, $4); |
| 498 | if ($1 != NULL) { |
| 499 | $$->set_doc($1); |
| 500 | } |
Mark Slee | d0767c5 | 2007-07-27 22:14:41 +0000 | [diff] [blame] | 501 | if (g_parse_mode == PROGRAM) { |
| 502 | g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4))); |
| 503 | if (g_parent_scope != NULL) { |
| 504 | g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4))); |
| 505 | } |
| 506 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 507 | } |
| 508 | | |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 509 | CaptureDocText tok_identifier CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 510 | { |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 511 | pdebug("EnumDef -> tok_identifier"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 512 | $$ = new t_enum_value($2); |
| 513 | if ($1 != NULL) { |
| 514 | $$->set_doc($1); |
| 515 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 518 | Senum: |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 519 | tok_senum tok_identifier '{' SenumDefList '}' |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 520 | { |
| 521 | pdebug("Senum -> tok_senum tok_identifier { SenumDefList }"); |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 522 | $$ = new t_typedef(g_program, $4, $2); |
Mark Slee | 6a47fed | 2007-02-07 02:40:59 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | SenumDefList: |
| 526 | SenumDefList SenumDef |
| 527 | { |
| 528 | pdebug("SenumDefList -> SenumDefList SenumDef"); |
| 529 | $$ = $1; |
| 530 | $$->add_string_enum_val($2); |
| 531 | } |
| 532 | | |
| 533 | { |
| 534 | pdebug("SenumDefList -> "); |
| 535 | $$ = new t_base_type("string", t_base_type::TYPE_STRING); |
| 536 | $$->set_string_enum(true); |
| 537 | } |
| 538 | |
| 539 | SenumDef: |
| 540 | tok_literal CommaOrSemicolonOptional |
| 541 | { |
| 542 | pdebug("SenumDef -> tok_literal"); |
| 543 | $$ = $1; |
| 544 | } |
| 545 | |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 546 | Const: |
| 547 | tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional |
| 548 | { |
| 549 | pdebug("Const -> tok_const FieldType tok_identifier = ConstValue"); |
Mark Slee | aa7671d | 2006-11-29 03:19:31 +0000 | [diff] [blame] | 550 | if (g_parse_mode == PROGRAM) { |
| 551 | $$ = new t_const($2, $3, $5); |
| 552 | validate_const_type($$); |
Mark Slee | d0767c5 | 2007-07-27 22:14:41 +0000 | [diff] [blame] | 553 | |
| 554 | g_scope->add_constant($3, $$); |
| 555 | if (g_parent_scope != NULL) { |
| 556 | g_parent_scope->add_constant(g_parent_prefix + $3, $$); |
| 557 | } |
| 558 | |
Mark Slee | aa7671d | 2006-11-29 03:19:31 +0000 | [diff] [blame] | 559 | } else { |
| 560 | $$ = NULL; |
| 561 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | ConstValue: |
| 565 | tok_int_constant |
| 566 | { |
| 567 | pdebug("ConstValue => tok_int_constant"); |
| 568 | $$ = new t_const_value(); |
| 569 | $$->set_integer($1); |
| 570 | } |
| 571 | | tok_dub_constant |
| 572 | { |
| 573 | pdebug("ConstValue => tok_dub_constant"); |
| 574 | $$ = new t_const_value(); |
| 575 | $$->set_double($1); |
| 576 | } |
| 577 | | tok_literal |
| 578 | { |
| 579 | pdebug("ConstValue => tok_literal"); |
Mark Slee | d0767c5 | 2007-07-27 22:14:41 +0000 | [diff] [blame] | 580 | $$ = new t_const_value($1); |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 581 | } |
Mark Slee | 67fc634 | 2006-11-29 03:37:04 +0000 | [diff] [blame] | 582 | | tok_identifier |
| 583 | { |
| 584 | pdebug("ConstValue => tok_identifier"); |
Mark Slee | d0767c5 | 2007-07-27 22:14:41 +0000 | [diff] [blame] | 585 | t_const* constant = g_scope->get_constant($1); |
| 586 | if (constant != NULL) { |
| 587 | $$ = constant->get_value(); |
| 588 | } else { |
| 589 | if (g_parse_mode == PROGRAM) { |
| 590 | pwarning(1, "Constant strings should be quoted: %s\n", $1); |
| 591 | } |
| 592 | $$ = new t_const_value($1); |
| 593 | } |
Mark Slee | 67fc634 | 2006-11-29 03:37:04 +0000 | [diff] [blame] | 594 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 595 | | ConstList |
| 596 | { |
| 597 | pdebug("ConstValue => ConstList"); |
| 598 | $$ = $1; |
| 599 | } |
| 600 | | ConstMap |
| 601 | { |
| 602 | pdebug("ConstValue => ConstMap"); |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 603 | $$ = $1; |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | ConstList: |
| 607 | '[' ConstListContents ']' |
| 608 | { |
| 609 | pdebug("ConstList => [ ConstListContents ]"); |
| 610 | $$ = $2; |
| 611 | } |
| 612 | |
| 613 | ConstListContents: |
| 614 | ConstListContents ConstValue CommaOrSemicolonOptional |
| 615 | { |
| 616 | pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional"); |
| 617 | $$ = $1; |
| 618 | $$->add_list($2); |
| 619 | } |
| 620 | | |
| 621 | { |
| 622 | pdebug("ConstListContents =>"); |
| 623 | $$ = new t_const_value(); |
| 624 | $$->set_list(); |
| 625 | } |
| 626 | |
| 627 | ConstMap: |
| 628 | '{' ConstMapContents '}' |
| 629 | { |
| 630 | pdebug("ConstMap => { ConstMapContents }"); |
| 631 | $$ = $2; |
| 632 | } |
| 633 | |
| 634 | ConstMapContents: |
| 635 | ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional |
| 636 | { |
| 637 | pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional"); |
| 638 | $$ = $1; |
| 639 | $$->add_map($2, $4); |
| 640 | } |
| 641 | | |
| 642 | { |
| 643 | pdebug("ConstMapContents =>"); |
| 644 | $$ = new t_const_value(); |
| 645 | $$->set_map(); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | Struct: |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 649 | tok_struct tok_identifier XsdAll '{' FieldList '}' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 650 | { |
| 651 | pdebug("Struct -> tok_struct tok_identifier { FieldList }"); |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 652 | $5->set_name($2); |
| 653 | $5->set_xsd_all($3); |
| 654 | $$ = $5; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 655 | y_field_val = -1; |
| 656 | } |
| 657 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 658 | XsdAll: |
Mark Slee | 782abbb | 2007-01-19 00:17:02 +0000 | [diff] [blame] | 659 | tok_xsd_all |
| 660 | { |
| 661 | $$ = true; |
| 662 | } |
| 663 | | |
| 664 | { |
| 665 | $$ = false; |
| 666 | } |
| 667 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 668 | XsdOptional: |
| 669 | tok_xsd_optional |
| 670 | { |
| 671 | $$ = true; |
| 672 | } |
| 673 | | |
| 674 | { |
| 675 | $$ = false; |
| 676 | } |
| 677 | |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 678 | XsdNillable: |
| 679 | tok_xsd_nillable |
| 680 | { |
| 681 | $$ = true; |
| 682 | } |
| 683 | | |
| 684 | { |
| 685 | $$ = false; |
| 686 | } |
| 687 | |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 688 | XsdAttributes: |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 689 | tok_xsd_attrs '{' FieldList '}' |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 690 | { |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 691 | $$ = $3; |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 692 | } |
| 693 | | |
| 694 | { |
| 695 | $$ = NULL; |
| 696 | } |
| 697 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 698 | Xception: |
| 699 | tok_xception tok_identifier '{' FieldList '}' |
| 700 | { |
| 701 | pdebug("Xception -> tok_xception tok_identifier { FieldList }"); |
| 702 | $4->set_name($2); |
| 703 | $4->set_xception(true); |
| 704 | $$ = $4; |
| 705 | y_field_val = -1; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | Service: |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 709 | tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 710 | { |
| 711 | pdebug("Service -> tok_service tok_identifier { FunctionList }"); |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 712 | $$ = $6; |
David Reiss | cdffe26 | 2007-08-14 17:12:31 +0000 | [diff] [blame] | 713 | $$->set_name($2); |
| 714 | $$->set_extends($3); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 715 | } |
| 716 | |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 717 | FlagArgs: |
| 718 | { |
| 719 | g_arglist = 1; |
| 720 | } |
| 721 | |
| 722 | UnflagArgs: |
| 723 | { |
| 724 | g_arglist = 0; |
| 725 | } |
| 726 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 727 | Extends: |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 728 | tok_extends tok_identifier |
| 729 | { |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 730 | pdebug("Extends -> tok_extends tok_identifier"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 731 | $$ = NULL; |
| 732 | if (g_parse_mode == PROGRAM) { |
| 733 | $$ = g_scope->get_service($2); |
| 734 | if ($$ == NULL) { |
| 735 | yyerror("Service \"%s\" has not been defined.", $2); |
| 736 | exit(1); |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | | |
| 741 | { |
| 742 | $$ = NULL; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | FunctionList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 746 | FunctionList Function |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 747 | { |
| 748 | pdebug("FunctionList -> FunctionList Function"); |
| 749 | $$ = $1; |
| 750 | $1->add_function($2); |
| 751 | } |
| 752 | | |
| 753 | { |
| 754 | pdebug("FunctionList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 755 | $$ = new t_service(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | Function: |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 759 | CaptureDocText Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 760 | { |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 761 | $6->set_name(std::string($4) + "_args"); |
| 762 | $$ = new t_function($3, $4, $6, $8, $2); |
| 763 | if ($1 != NULL) { |
| 764 | $$->set_doc($1); |
| 765 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 766 | y_field_val = -1; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 767 | } |
| 768 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 769 | Async: |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 770 | tok_async |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 771 | { |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 772 | $$ = true; |
| 773 | } |
| 774 | | |
| 775 | { |
| 776 | $$ = false; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 779 | Throws: |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 780 | tok_throws '(' FieldList ')' |
| 781 | { |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 782 | pdebug("Throws -> tok_throws ( FieldList )"); |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 783 | $$ = $3; |
Mark Slee | f07d48e | 2008-02-01 01:36:26 +0000 | [diff] [blame] | 784 | if (g_parse_mode == PROGRAM && !validate_throws($$)) { |
Mark Slee | 91f2b7b | 2008-01-31 01:49:16 +0000 | [diff] [blame] | 785 | yyerror("Throws clause may not contain non-exception types"); |
| 786 | exit(1); |
| 787 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 788 | } |
| 789 | | |
| 790 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 791 | $$ = new t_struct(g_program); |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 794 | FieldList: |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 795 | FieldList Field |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 796 | { |
| 797 | pdebug("FieldList -> FieldList , Field"); |
| 798 | $$ = $1; |
Mark Slee | 6f9ac3f | 2007-11-28 22:28:13 +0000 | [diff] [blame] | 799 | if (!($$->validate_field($2))) { |
| 800 | yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str()); |
| 801 | exit(1); |
| 802 | } |
Mark Slee | 207cb46 | 2006-11-02 18:43:12 +0000 | [diff] [blame] | 803 | $$->append($2); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 804 | } |
| 805 | | |
| 806 | { |
| 807 | pdebug("FieldList -> "); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 808 | $$ = new t_struct(g_program); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | Field: |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 812 | CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 813 | { |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 814 | pdebug("tok_int_constant : Field -> FieldType tok_identifier"); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 815 | if ($2 < 0) { |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 816 | 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] | 817 | } |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 818 | $$ = new t_field($4, $5, $2); |
| 819 | $$->set_req($3); |
| 820 | if ($6 != NULL) { |
| 821 | validate_field_value($$, $6); |
| 822 | $$->set_value($6); |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 823 | } |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 824 | $$->set_xsd_optional($7); |
| 825 | $$->set_xsd_nillable($8); |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 826 | if ($1 != NULL) { |
| 827 | $$->set_doc($1); |
| 828 | } |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 829 | if ($9 != NULL) { |
| 830 | $$->set_xsd_attrs($9); |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 831 | } |
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 | |
| 834 | FieldIdentifier: |
| 835 | tok_int_constant ':' |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 836 | { |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 837 | if ($1 <= 0) { |
| 838 | pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1); |
| 839 | $1 = y_field_val--; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 840 | } |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 841 | $$ = $1; |
| 842 | } |
| 843 | | |
| 844 | { |
| 845 | $$ = y_field_val--; |
| 846 | } |
| 847 | |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 848 | FieldRequiredness: |
| 849 | tok_required |
| 850 | { |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 851 | if (g_arglist) { |
| 852 | if (g_parse_mode == PROGRAM) { |
| 853 | pwarning(1, "required keyword is ignored in argument lists.\n"); |
| 854 | } |
David Reiss | 204420f | 2008-01-11 20:59:03 +0000 | [diff] [blame] | 855 | $$ = t_field::T_OPT_IN_REQ_OUT; |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 856 | } else { |
David Reiss | 204420f | 2008-01-11 20:59:03 +0000 | [diff] [blame] | 857 | $$ = t_field::T_REQUIRED; |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 858 | } |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 859 | } |
| 860 | | tok_optional |
| 861 | { |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 862 | if (g_arglist) { |
| 863 | if (g_parse_mode == PROGRAM) { |
| 864 | pwarning(1, "optional keyword is ignored in argument lists.\n"); |
| 865 | } |
David Reiss | 204420f | 2008-01-11 20:59:03 +0000 | [diff] [blame] | 866 | $$ = t_field::T_OPT_IN_REQ_OUT; |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 867 | } else { |
David Reiss | 204420f | 2008-01-11 20:59:03 +0000 | [diff] [blame] | 868 | $$ = t_field::T_OPTIONAL; |
Mark Slee | 7816572 | 2007-09-10 22:08:49 +0000 | [diff] [blame] | 869 | } |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 870 | } |
| 871 | | |
| 872 | { |
David Reiss | 204420f | 2008-01-11 20:59:03 +0000 | [diff] [blame] | 873 | $$ = t_field::T_OPT_IN_REQ_OUT; |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame] | 874 | } |
| 875 | |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 876 | FieldValue: |
| 877 | '=' ConstValue |
| 878 | { |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 879 | if (g_parse_mode == PROGRAM) { |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 880 | $$ = $2; |
| 881 | } else { |
| 882 | $$ = NULL; |
| 883 | } |
| 884 | } |
| 885 | | |
| 886 | { |
| 887 | $$ = NULL; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 888 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 889 | |
| 890 | DefinitionType: |
| 891 | BaseType |
| 892 | { |
| 893 | pdebug("DefinitionType -> BaseType"); |
| 894 | $$ = $1; |
| 895 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 896 | | ContainerType |
| 897 | { |
| 898 | pdebug("DefinitionType -> ContainerType"); |
| 899 | $$ = $1; |
| 900 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 901 | |
| 902 | FunctionType: |
| 903 | FieldType |
| 904 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 905 | pdebug("FunctionType -> FieldType"); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 906 | $$ = $1; |
| 907 | } |
| 908 | | tok_void |
| 909 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 910 | pdebug("FunctionType -> tok_void"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 911 | $$ = g_type_void; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | FieldType: |
| 915 | tok_identifier |
| 916 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 917 | pdebug("FieldType -> tok_identifier"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 918 | if (g_parse_mode == INCLUDES) { |
| 919 | // Ignore identifiers in include mode |
| 920 | $$ = NULL; |
| 921 | } else { |
| 922 | // Lookup the identifier in the current scope |
| 923 | $$ = g_scope->get_type($1); |
| 924 | if ($$ == NULL) { |
| 925 | yyerror("Type \"%s\" has not been defined.", $1); |
| 926 | exit(1); |
| 927 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 928 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 929 | } |
| 930 | | BaseType |
| 931 | { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 932 | pdebug("FieldType -> BaseType"); |
| 933 | $$ = $1; |
| 934 | } |
| 935 | | ContainerType |
| 936 | { |
| 937 | pdebug("FieldType -> ContainerType"); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 938 | $$ = $1; |
| 939 | } |
| 940 | |
| 941 | BaseType: |
| 942 | tok_string |
| 943 | { |
| 944 | pdebug("BaseType -> tok_string"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 945 | $$ = g_type_string; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 946 | } |
Mark Slee | 8d725a2 | 2007-04-13 01:57:12 +0000 | [diff] [blame] | 947 | | tok_binary |
| 948 | { |
| 949 | pdebug("BaseType -> tok_binary"); |
| 950 | $$ = g_type_binary; |
| 951 | } |
Mark Slee | b6200d8 | 2007-01-19 19:14:36 +0000 | [diff] [blame] | 952 | | tok_slist |
| 953 | { |
| 954 | pdebug("BaseType -> tok_slist"); |
| 955 | $$ = g_type_slist; |
| 956 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 957 | | tok_bool |
| 958 | { |
| 959 | pdebug("BaseType -> tok_bool"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 960 | $$ = g_type_bool; |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 961 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 962 | | tok_byte |
| 963 | { |
| 964 | pdebug("BaseType -> tok_byte"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 965 | $$ = g_type_byte; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 966 | } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 967 | | tok_i16 |
| 968 | { |
| 969 | pdebug("BaseType -> tok_i16"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 970 | $$ = g_type_i16; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 971 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 972 | | tok_i32 |
| 973 | { |
| 974 | pdebug("BaseType -> tok_i32"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 975 | $$ = g_type_i32; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 976 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 977 | | tok_i64 |
| 978 | { |
| 979 | pdebug("BaseType -> tok_i64"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 980 | $$ = g_type_i64; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 981 | } |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 982 | | tok_double |
| 983 | { |
| 984 | pdebug("BaseType -> tok_double"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 985 | $$ = g_type_double; |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 986 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 987 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 988 | ContainerType: |
| 989 | MapType |
| 990 | { |
| 991 | pdebug("ContainerType -> MapType"); |
| 992 | $$ = $1; |
| 993 | } |
| 994 | | SetType |
| 995 | { |
| 996 | pdebug("ContainerType -> SetType"); |
| 997 | $$ = $1; |
| 998 | } |
| 999 | | ListType |
| 1000 | { |
| 1001 | pdebug("ContainerType -> ListType"); |
| 1002 | $$ = $1; |
| 1003 | } |
| 1004 | |
| 1005 | MapType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 1006 | tok_map CppType '<' FieldType ',' FieldType '>' |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1007 | { |
| 1008 | pdebug("MapType -> tok_map <FieldType, FieldType>"); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 1009 | $$ = new t_map($4, $6); |
| 1010 | if ($2 != NULL) { |
| 1011 | ((t_container*)$$)->set_cpp_name(std::string($2)); |
| 1012 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | SetType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 1016 | tok_set CppType '<' FieldType '>' |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1017 | { |
| 1018 | pdebug("SetType -> tok_set<FieldType>"); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 1019 | $$ = new t_set($4); |
| 1020 | if ($2 != NULL) { |
| 1021 | ((t_container*)$$)->set_cpp_name(std::string($2)); |
| 1022 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | ListType: |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 1026 | tok_list '<' FieldType '>' CppType |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1027 | { |
| 1028 | pdebug("ListType -> tok_list<FieldType>"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 1029 | $$ = new t_list($3); |
| 1030 | if ($5 != NULL) { |
| 1031 | ((t_container*)$$)->set_cpp_name(std::string($5)); |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 1035 | CppType: |
Mark Slee | afc7654 | 2007-02-09 21:55:44 +0000 | [diff] [blame] | 1036 | tok_cpp_type tok_literal |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 1037 | { |
Mark Slee | afc7654 | 2007-02-09 21:55:44 +0000 | [diff] [blame] | 1038 | $$ = $2; |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 1039 | } |
| 1040 | | |
| 1041 | { |
| 1042 | $$ = NULL; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1045 | %% |