Andreas Huber | 1aec397 | 2016-08-26 09:26:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 17 | %{ |
| 18 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 19 | #include "Annotation.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 20 | #include "AST.h" |
| 21 | #include "ArrayType.h" |
| 22 | #include "CompoundType.h" |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 23 | #include "ConstantExpression.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 24 | #include "EnumType.h" |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 25 | #include "FQName.h" |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 26 | #include "GenericBinder.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 27 | #include "Interface.h" |
| 28 | #include "Method.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 29 | #include "VectorType.h" |
| 30 | |
| 31 | #include "hidl-gen_y.h" |
| 32 | |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 33 | #include <android-base/logging.h> |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 34 | #include <stdio.h> |
| 35 | |
| 36 | using namespace android; |
| 37 | |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 38 | extern int yylex(yy::parser::semantic_type *, yy::parser::location_type *, void *); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 39 | |
| 40 | #define scanner ast->scanner() |
| 41 | |
| 42 | %} |
| 43 | |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 44 | %initial-action { |
| 45 | // Initialize the initial location. |
| 46 | @$.begin.filename = @$.end.filename = |
| 47 | const_cast<std::string *>(&ast->getFilename()); |
| 48 | } |
| 49 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 50 | %parse-param { android::AST *ast } |
| 51 | %lex-param { void *scanner } |
| 52 | %pure-parser |
Steven Moreland | 4ab9b79 | 2016-09-26 14:14:07 -0700 | [diff] [blame] | 53 | %glr-parser |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 54 | %skeleton "glr.cc" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 55 | |
Steven Moreland | 4ab9b79 | 2016-09-26 14:14:07 -0700 | [diff] [blame] | 56 | %expect-rr 0 |
| 57 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 58 | %token<str> ENUM |
| 59 | %token<str> EXTENDS |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 60 | %token<str> FQNAME |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 61 | %token<str> GENERATES |
| 62 | %token<str> IDENTIFIER |
| 63 | %token<str> IMPORT |
| 64 | %token<str> INTEGER |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 65 | %token<str> FLOAT |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 66 | %token<str> INTERFACE |
| 67 | %token<str> PACKAGE |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 68 | %token<type> SCALAR |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 69 | %token<str> STRUCT |
| 70 | %token<str> STRING_LITERAL |
| 71 | %token<str> TYPEDEF |
| 72 | %token<str> UNION |
| 73 | %token<str> VEC |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 74 | %token<void> ONEWAY |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 75 | |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 76 | /* Operator precedence and associativity, as per |
| 77 | * http://en.cppreference.com/w/cpp/language/operator_precedence */ |
| 78 | /* Precedence level 15 ternary operator */ |
| 79 | %right '?' ':' |
| 80 | /* Precedence level 13 - 14, LTR, logical operators*/ |
| 81 | %left LOGICAL_OR |
| 82 | %left LOGICAL_AND |
| 83 | /* Precedence level 10 - 12, LTR, bitwise operators*/ |
| 84 | %left '|' |
| 85 | %left '^' |
| 86 | %left '&' |
| 87 | /* Precedence level 9, LTR */ |
| 88 | %left EQUALITY NEQ |
| 89 | /* Precedence level 8, LTR */ |
| 90 | %left '<' '>' LEQ GEQ |
| 91 | /* Precedence level 7, LTR */ |
| 92 | %left LSHIFT RSHIFT |
| 93 | /* Precedence level 6, LTR */ |
| 94 | %left '+' '-' |
| 95 | /* Precedence level 5, LTR */ |
| 96 | %left '*' '/' '%' |
| 97 | /* Precedence level 3, RTL; but we have to use %left here */ |
| 98 | %left UNARY_MINUS UNARY_PLUS '!' '~' |
| 99 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 100 | %type<str> optIdentifier package |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 101 | %type<fqName> fqname |
| 102 | %type<type> fqtype |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 103 | |
| 104 | %type<type> type opt_storage_type |
| 105 | %type<type> enum_declaration |
| 106 | %type<type> struct_or_union_declaration |
| 107 | %type<type> opt_extends |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame^] | 108 | %type<type> type_declaration_body interface_declaration typedef_declaration |
| 109 | %type<type> named_struct_or_union_declaration named_enum_declaration |
| 110 | %type<type> compound_declaration annotated_compound_declaration |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 111 | |
| 112 | %type<field> field_declaration |
| 113 | %type<fields> field_declarations struct_or_union_body |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 114 | %type<constantExpression> const_expr |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 115 | %type<enumValue> enum_value |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 116 | %type<enumValues> enum_values enum_declaration_body |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 117 | %type<typedVars> typed_vars |
| 118 | %type<typedVar> typed_var |
| 119 | %type<method> method_declaration |
| 120 | %type<compoundStyle> struct_or_union_keyword |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 121 | %type<stringVec> annotation_string_values annotation_string_value |
| 122 | %type<constExprVec> annotation_const_expr_values annotation_const_expr_value |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 123 | %type<annotationParam> annotation_param |
| 124 | %type<annotationParams> opt_annotation_params annotation_params |
| 125 | %type<annotation> annotation |
| 126 | %type<annotations> opt_annotations |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 127 | |
| 128 | %start program |
| 129 | |
| 130 | %union { |
| 131 | const char *str; |
| 132 | android::Type *type; |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 133 | android::FQName *fqName; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 134 | android::CompoundType *compoundType; |
| 135 | android::CompoundField *field; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 136 | std::vector<android::CompoundField *> *fields; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 137 | android::EnumValue *enumValue; |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 138 | android::ConstantExpression *constantExpression; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 139 | std::vector<android::EnumValue *> *enumValues; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 140 | android::TypedVar *typedVar; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 141 | std::vector<android::TypedVar *> *typedVars; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 142 | android::Method *method; |
| 143 | android::CompoundType::Style compoundStyle; |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 144 | std::vector<std::string> *stringVec; |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 145 | std::vector<android::ConstantExpression *> *constExprVec; |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 146 | android::AnnotationParam *annotationParam; |
| 147 | android::AnnotationParamVector *annotationParams; |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 148 | android::Annotation *annotation; |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 149 | std::vector<android::Annotation *> *annotations; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | %% |
| 153 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 154 | opt_annotations |
| 155 | : /* empty */ |
| 156 | { |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 157 | $$ = new std::vector<Annotation *>; |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 158 | } |
| 159 | | opt_annotations annotation |
| 160 | { |
| 161 | $$ = $1; |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 162 | $$->push_back($2); |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 163 | } |
| 164 | ; |
| 165 | |
| 166 | annotation |
| 167 | : '@' IDENTIFIER opt_annotation_params |
| 168 | { |
| 169 | $$ = new Annotation($2, $3); |
| 170 | } |
| 171 | ; |
| 172 | |
| 173 | opt_annotation_params |
| 174 | : /* empty */ |
| 175 | { |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 176 | $$ = new AnnotationParamVector; |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 177 | } |
| 178 | | '(' annotation_params ')' |
| 179 | { |
| 180 | $$ = $2; |
| 181 | } |
| 182 | ; |
| 183 | |
| 184 | annotation_params |
| 185 | : annotation_param |
| 186 | { |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 187 | $$ = new AnnotationParamVector; |
| 188 | $$->push_back($1); |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 189 | } |
| 190 | | annotation_params ',' annotation_param |
| 191 | { |
| 192 | $$ = $1; |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 193 | $$->push_back($3); |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 194 | } |
| 195 | ; |
| 196 | |
| 197 | annotation_param |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 198 | : IDENTIFIER '=' annotation_string_value |
| 199 | { |
| 200 | $$ = new AnnotationParam($1, $3); |
| 201 | } |
| 202 | | IDENTIFIER '=' annotation_const_expr_value |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 203 | { |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 204 | $$ = new AnnotationParam($1, $3); |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 205 | } |
| 206 | ; |
| 207 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 208 | annotation_string_value |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 209 | : STRING_LITERAL |
| 210 | { |
| 211 | $$ = new std::vector<std::string>; |
| 212 | $$->push_back($1); |
| 213 | } |
| 214 | | '{' annotation_string_values '}' { $$ = $2; } |
| 215 | ; |
| 216 | |
| 217 | annotation_string_values |
| 218 | : STRING_LITERAL |
| 219 | { |
| 220 | $$ = new std::vector<std::string>; |
| 221 | $$->push_back($1); |
| 222 | } |
| 223 | | annotation_string_values ',' STRING_LITERAL |
| 224 | { |
| 225 | $$ = $1; |
| 226 | $$->push_back($3); |
| 227 | } |
| 228 | ; |
| 229 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 230 | annotation_const_expr_value |
| 231 | : const_expr |
| 232 | { |
| 233 | $$ = new std::vector<ConstantExpression *>; |
| 234 | $$->push_back($1); |
| 235 | } |
| 236 | | '{' annotation_const_expr_values '}' { $$ = $2; } |
| 237 | ; |
| 238 | |
| 239 | annotation_const_expr_values |
| 240 | : const_expr |
| 241 | { |
| 242 | $$ = new std::vector<ConstantExpression *>; |
| 243 | $$->push_back($1); |
| 244 | } |
| 245 | | annotation_const_expr_values ',' const_expr |
| 246 | { |
| 247 | $$ = $1; |
| 248 | $$->push_back($3); |
| 249 | } |
| 250 | ; |
| 251 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 252 | program |
Andreas Huber | da51b8e | 2016-07-28 16:00:57 -0700 | [diff] [blame] | 253 | : package imports body |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 254 | ; |
| 255 | |
| 256 | fqname |
| 257 | : FQNAME |
| 258 | { |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 259 | $$ = new FQName($1); |
| 260 | if(!$$->isValid()) { |
| 261 | std::cerr << "ERROR: FQName '" << $1 << "' is not valid at " |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 262 | << @1 |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 263 | << ".\n"; |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 264 | YYERROR; |
| 265 | } |
| 266 | } |
| 267 | | IDENTIFIER |
| 268 | { |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 269 | $$ = new FQName($1); |
| 270 | if(!$$->isValid()) { |
| 271 | std::cerr << "ERROR: FQName '" << $1 << "' is not valid at " |
| 272 | << @1 |
| 273 | << ".\n"; |
| 274 | YYERROR; |
| 275 | } |
| 276 | } |
| 277 | ; |
| 278 | |
| 279 | fqtype |
| 280 | : fqname |
| 281 | { |
| 282 | $$ = ast->lookupType(*($1)); |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 283 | if ($$ == NULL) { |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 284 | std::cerr << "ERROR: Failed to lookup type '" << $1->string() << "' at " |
| 285 | << @1 |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 286 | << "\n"; |
| 287 | |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 288 | YYERROR; |
| 289 | } |
| 290 | } |
| 291 | | SCALAR |
| 292 | ; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 293 | |
| 294 | package |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 295 | : PACKAGE FQNAME ';' |
Andreas Huber | eb1081f | 2016-07-28 13:13:24 -0700 | [diff] [blame] | 296 | { |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 297 | if (!ast->setPackage($2)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 298 | std::cerr << "ERROR: Malformed package identifier '" |
| 299 | << $2 |
| 300 | << "' at " |
| 301 | << @2 |
| 302 | << "\n"; |
| 303 | |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 304 | YYERROR; |
| 305 | } |
Andreas Huber | eb1081f | 2016-07-28 13:13:24 -0700 | [diff] [blame] | 306 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 307 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 308 | imports |
| 309 | : /* empty */ |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 310 | | imports IMPORT FQNAME ';' |
Andreas Huber | eb1081f | 2016-07-28 13:13:24 -0700 | [diff] [blame] | 311 | { |
Andreas Huber | 68f2459 | 2016-07-29 14:53:48 -0700 | [diff] [blame] | 312 | if (!ast->addImport($3)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 313 | std::cerr << "ERROR: Unable to import '" << $3 << "' at " << @3 |
| 314 | << "\n"; |
Andreas Huber | 68f2459 | 2016-07-29 14:53:48 -0700 | [diff] [blame] | 315 | |
| 316 | YYERROR; |
| 317 | } |
Andreas Huber | eb1081f | 2016-07-28 13:13:24 -0700 | [diff] [blame] | 318 | } |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 319 | | imports IMPORT IDENTIFIER ';' |
| 320 | { |
Andreas Huber | 68f2459 | 2016-07-29 14:53:48 -0700 | [diff] [blame] | 321 | if (!ast->addImport($3)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 322 | std::cerr << "ERROR: Unable to import '" << $3 << "' at " << @3 |
| 323 | << "\n"; |
Andreas Huber | 68f2459 | 2016-07-29 14:53:48 -0700 | [diff] [blame] | 324 | |
| 325 | YYERROR; |
| 326 | } |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 327 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 328 | ; |
| 329 | |
| 330 | opt_extends |
| 331 | : /* empty */ { $$ = NULL; } |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 332 | | EXTENDS fqtype { $$ = $2; } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 333 | |
| 334 | body |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame^] | 335 | : type_declarations |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 336 | ; |
| 337 | |
| 338 | interface_declarations |
| 339 | : /* empty */ |
| 340 | | interface_declarations type_declaration |
| 341 | | interface_declarations method_declaration |
| 342 | { |
| 343 | Interface *iface = static_cast<Interface *>(ast->scope()); |
| 344 | iface->addMethod($2); |
| 345 | } |
| 346 | ; |
| 347 | |
| 348 | type_declarations |
Andreas Huber | a2723d2 | 2016-07-29 15:36:07 -0700 | [diff] [blame] | 349 | : /* empty */ |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 350 | | type_declarations type_declaration |
| 351 | ; |
| 352 | |
| 353 | type_declaration |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame^] | 354 | : opt_annotations type_declaration_body |
| 355 | { |
| 356 | if ($2 != nullptr) { |
| 357 | $2->setAnnotations($1); |
| 358 | } else if (!$1->empty()) { |
| 359 | // Since typedefs are always resolved to their target it makes |
| 360 | // little sense to annotate them and have their annotations |
| 361 | // impose semantics other than their target type. |
| 362 | std::cerr << "ERROR: typedefs cannot be annotated. at " << @2 |
| 363 | << "\n"; |
| 364 | |
| 365 | YYERROR; |
| 366 | } |
| 367 | } |
| 368 | ; |
| 369 | |
| 370 | type_declaration_body |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 371 | : named_struct_or_union_declaration ';' |
| 372 | | named_enum_declaration ';' |
| 373 | | typedef_declaration ';' |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame^] | 374 | | interface_declaration ';' |
| 375 | ; |
| 376 | |
| 377 | interface_declaration |
| 378 | : INTERFACE IDENTIFIER opt_extends |
| 379 | { |
| 380 | if ($3 != NULL && !$3->isInterface()) { |
| 381 | std::cerr << "ERROR: You can only extend interfaces. at" << @3 |
| 382 | << "\n"; |
| 383 | |
| 384 | YYERROR; |
| 385 | } |
| 386 | |
| 387 | if ($2[0] != 'I') { |
| 388 | std::cerr << "ERROR: All interface names must start with an 'I' " |
| 389 | << "prefix. at " << @2 << "\n"; |
| 390 | |
| 391 | YYERROR; |
| 392 | } |
| 393 | |
| 394 | Interface *iface = new Interface($2, static_cast<Interface *>($3)); |
| 395 | |
| 396 | // Register interface immediately so it can be referenced inside |
| 397 | // definition. |
| 398 | std::string errorMsg; |
| 399 | if (!ast->addScopedType(iface, &errorMsg)) { |
| 400 | std::cerr << "ERROR: " << errorMsg << " at " << @2 << "\n"; |
| 401 | YYERROR; |
| 402 | } |
| 403 | |
| 404 | ast->enterScope(iface); |
| 405 | } |
| 406 | '{' interface_declarations '}' |
| 407 | { |
| 408 | Interface *iface = static_cast<Interface *>(ast->scope()); |
| 409 | |
| 410 | ast->leaveScope(); |
| 411 | |
| 412 | $$ = iface; |
| 413 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 414 | ; |
| 415 | |
| 416 | typedef_declaration |
| 417 | : TYPEDEF type IDENTIFIER |
| 418 | { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 419 | std::string errorMsg; |
Andreas Huber | 39fa718 | 2016-08-19 14:27:33 -0700 | [diff] [blame] | 420 | if (!ast->addTypeDef($3, $2, &errorMsg)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 421 | std::cerr << "ERROR: " << errorMsg << " at " << @3 << "\n"; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 422 | YYERROR; |
| 423 | } |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame^] | 424 | |
| 425 | $$ = nullptr; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 426 | } |
| 427 | ; |
| 428 | |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 429 | const_expr |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 430 | : INTEGER { $$ = new ConstantExpression($1); } |
Yifan Hong | b44a6c8 | 2016-09-22 15:50:18 -0700 | [diff] [blame] | 431 | | fqname |
| 432 | { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 433 | if(!$1->isValidValueName()) { |
| 434 | std::cerr << "ERROR: '" << $1->string() |
| 435 | << "' does not refer to an enum value at " |
| 436 | << @1 << ".\n"; |
| 437 | YYERROR; |
| 438 | } |
| 439 | if($1->isIdentifier()) { |
| 440 | std::string identifier = $1->name(); |
| 441 | LocalIdentifier *iden = ast->scope()->lookupIdentifier(identifier); |
| 442 | if(!iden) { |
Steven Moreland | c5908e6 | 2016-09-27 14:02:50 -0700 | [diff] [blame] | 443 | std::cerr << "ERROR: at " << @1 << ", identifier " << $1->string() |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 444 | << " could not be found.\n"; |
| 445 | YYERROR; |
| 446 | } |
| 447 | if(!iden->isEnumValue()) { |
Steven Moreland | c5908e6 | 2016-09-27 14:02:50 -0700 | [diff] [blame] | 448 | std::cerr << "ERROR: at " << @1 << ", identifier " << $1->string() |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 449 | << " is not an enum value.\n"; |
| 450 | YYERROR; |
| 451 | } |
| 452 | $$ = new ConstantExpression( |
| 453 | *(static_cast<EnumValue *>(iden)->constExpr()), $1->string()); |
| 454 | } else { |
| 455 | std::string errorMsg; |
| 456 | EnumValue *v = ast->lookupEnumValue(*($1), &errorMsg); |
| 457 | if(v == nullptr) { |
| 458 | std::cerr << "ERROR: " << errorMsg << " at " << @1 << ".\n"; |
| 459 | YYERROR; |
| 460 | } |
| 461 | $$ = new ConstantExpression(*(v->constExpr()), $1->string()); |
| 462 | } |
Yifan Hong | b44a6c8 | 2016-09-22 15:50:18 -0700 | [diff] [blame] | 463 | } |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 464 | | const_expr '?' const_expr ':' const_expr |
| 465 | { |
Yifan Hong | b44a6c8 | 2016-09-22 15:50:18 -0700 | [diff] [blame] | 466 | $$ = new ConstantExpression($1, $3, $5); |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 467 | } |
| 468 | | const_expr LOGICAL_OR const_expr { $$ = new ConstantExpression($1, "||", $3); } |
| 469 | | const_expr LOGICAL_AND const_expr { $$ = new ConstantExpression($1, "&&", $3); } |
| 470 | | const_expr '|' const_expr { $$ = new ConstantExpression($1, "|" , $3); } |
| 471 | | const_expr '^' const_expr { $$ = new ConstantExpression($1, "^" , $3); } |
| 472 | | const_expr '&' const_expr { $$ = new ConstantExpression($1, "&" , $3); } |
| 473 | | const_expr EQUALITY const_expr { $$ = new ConstantExpression($1, "==", $3); } |
| 474 | | const_expr NEQ const_expr { $$ = new ConstantExpression($1, "!=", $3); } |
| 475 | | const_expr '<' const_expr { $$ = new ConstantExpression($1, "<" , $3); } |
| 476 | | const_expr '>' const_expr { $$ = new ConstantExpression($1, ">" , $3); } |
| 477 | | const_expr LEQ const_expr { $$ = new ConstantExpression($1, "<=", $3); } |
| 478 | | const_expr GEQ const_expr { $$ = new ConstantExpression($1, ">=", $3); } |
| 479 | | const_expr LSHIFT const_expr { $$ = new ConstantExpression($1, "<<", $3); } |
| 480 | | const_expr RSHIFT const_expr { $$ = new ConstantExpression($1, ">>", $3); } |
| 481 | | const_expr '+' const_expr { $$ = new ConstantExpression($1, "+" , $3); } |
| 482 | | const_expr '-' const_expr { $$ = new ConstantExpression($1, "-" , $3); } |
| 483 | | const_expr '*' const_expr { $$ = new ConstantExpression($1, "*" , $3); } |
| 484 | | const_expr '/' const_expr { $$ = new ConstantExpression($1, "/" , $3); } |
| 485 | | const_expr '%' const_expr { $$ = new ConstantExpression($1, "%" , $3); } |
| 486 | | '+' const_expr %prec UNARY_PLUS { $$ = new ConstantExpression("+", $2); } |
| 487 | | '-' const_expr %prec UNARY_MINUS { $$ = new ConstantExpression("-", $2); } |
| 488 | | '!' const_expr { $$ = new ConstantExpression("!", $2); } |
| 489 | | '~' const_expr { $$ = new ConstantExpression("~", $2); } |
| 490 | | '(' const_expr ')' { $$ = $2; } |
| 491 | ; |
| 492 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 493 | method_declaration |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 494 | : opt_annotations IDENTIFIER '(' typed_vars ')' ';' |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 495 | { |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 496 | $$ = new Method($2, $4, new std::vector<TypedVar *>, false, $1); |
| 497 | } |
| 498 | | opt_annotations ONEWAY IDENTIFIER '(' typed_vars ')' ';' |
| 499 | { |
| 500 | $$ = new Method($3, $5, new std::vector<TypedVar *>, true, $1); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 501 | } |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 502 | | opt_annotations IDENTIFIER '(' typed_vars ')' GENERATES '(' typed_vars ')' ';' |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 503 | { |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 504 | $$ = new Method($2, $4, $8, false, $1); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 505 | } |
| 506 | ; |
| 507 | |
| 508 | typed_vars |
| 509 | : /* empty */ |
| 510 | { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 511 | $$ = new std::vector<TypedVar *>; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 512 | } |
| 513 | | typed_var |
| 514 | { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 515 | $$ = new std::vector<TypedVar *>; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 516 | $$->push_back($1); |
| 517 | } |
| 518 | | typed_vars ',' typed_var |
| 519 | { |
| 520 | $$ = $1; |
| 521 | $$->push_back($3); |
| 522 | } |
| 523 | ; |
| 524 | |
| 525 | typed_var : type IDENTIFIER { $$ = new TypedVar($2, $1); } |
| 526 | ; |
| 527 | |
| 528 | |
| 529 | struct_or_union_keyword |
| 530 | : STRUCT { $$ = CompoundType::STYLE_STRUCT; } |
| 531 | | UNION { $$ = CompoundType::STYLE_UNION; } |
| 532 | ; |
| 533 | |
| 534 | named_struct_or_union_declaration |
| 535 | : struct_or_union_keyword IDENTIFIER |
| 536 | { |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 537 | CompoundType *container = new CompoundType($1, $2); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 538 | ast->enterScope(container); |
| 539 | } |
| 540 | struct_or_union_body |
| 541 | { |
| 542 | CompoundType *container = static_cast<CompoundType *>(ast->scope()); |
| 543 | |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 544 | std::string errorMsg; |
| 545 | if (!container->setFields($4, &errorMsg)) { |
| 546 | std::cerr << "ERROR: " << errorMsg << " at " << @4 << "\n"; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 547 | YYERROR; |
| 548 | } |
| 549 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 550 | ast->leaveScope(); |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 551 | |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 552 | if (!ast->addScopedType(container, &errorMsg)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 553 | std::cerr << "ERROR: " << errorMsg << " at " << @2 << "\n"; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 554 | YYERROR; |
| 555 | } |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame^] | 556 | |
| 557 | $$ = container; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 558 | } |
| 559 | ; |
| 560 | |
| 561 | struct_or_union_declaration |
| 562 | : struct_or_union_keyword optIdentifier |
| 563 | { |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 564 | const char *localName = $2; |
| 565 | std::string anonName; |
| 566 | if (localName == nullptr) { |
| 567 | anonName = ast->scope()->pickUniqueAnonymousName(); |
| 568 | localName = anonName.c_str(); |
| 569 | } |
| 570 | |
| 571 | CompoundType *container = new CompoundType($1, localName); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 572 | ast->enterScope(container); |
| 573 | } |
| 574 | struct_or_union_body |
| 575 | { |
| 576 | CompoundType *container = static_cast<CompoundType *>(ast->scope()); |
| 577 | |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 578 | std::string errorMsg; |
| 579 | if (!container->setFields($4, &errorMsg)) { |
| 580 | std::cerr << "ERROR: " << errorMsg << " at " << @4 << "\n"; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 581 | YYERROR; |
| 582 | } |
| 583 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 584 | ast->leaveScope(); |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 585 | |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 586 | if (!ast->addScopedType(container, &errorMsg)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 587 | std::cerr << "ERROR: " << errorMsg << " at " << @2 << "\n"; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 588 | YYERROR; |
| 589 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 590 | |
Andreas Huber | fd4afab | 2016-08-03 13:02:57 -0700 | [diff] [blame] | 591 | $$ = container->ref(); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 592 | } |
| 593 | ; |
| 594 | |
| 595 | struct_or_union_body |
| 596 | : '{' field_declarations '}' { $$ = $2; } |
| 597 | ; |
| 598 | |
| 599 | field_declarations |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 600 | : /* empty */ { $$ = new std::vector<CompoundField *>; } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 601 | | field_declarations field_declaration |
| 602 | { |
| 603 | $$ = $1; |
| 604 | |
| 605 | if ($2 != NULL) { |
| 606 | $$->push_back($2); |
| 607 | } |
| 608 | } |
| 609 | ; |
| 610 | |
| 611 | field_declaration |
| 612 | : type IDENTIFIER ';' { $$ = new CompoundField($2, $1); } |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame^] | 613 | | annotated_compound_declaration ';' { $$ = NULL; } |
| 614 | ; |
| 615 | |
| 616 | annotated_compound_declaration |
| 617 | : opt_annotations compound_declaration |
| 618 | { |
| 619 | $2->setAnnotations($1); |
| 620 | $$ = $2; |
| 621 | } |
| 622 | ; |
| 623 | |
| 624 | compound_declaration |
| 625 | : struct_or_union_declaration { $$ = $1; } |
| 626 | | enum_declaration { $$ = $1; } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 627 | ; |
| 628 | |
| 629 | opt_storage_type |
| 630 | : /* empty */ { $$ = NULL; } |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 631 | | ':' fqtype |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 632 | { |
| 633 | $$ = $2; |
| 634 | |
| 635 | if ($$ != NULL && !$$->isValidEnumStorageType()) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 636 | std::cerr << "ERROR: Invalid enum storage type specified. at " |
| 637 | << @2 << "\n"; |
| 638 | |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 639 | YYABORT; |
| 640 | } |
| 641 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 642 | ; |
| 643 | |
| 644 | opt_comma |
| 645 | : /* empty */ |
| 646 | | ',' |
| 647 | ; |
| 648 | |
| 649 | named_enum_declaration |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 650 | : ENUM IDENTIFIER opt_storage_type |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 651 | { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 652 | ast->enterScope(new EnumType($2, $3)); |
| 653 | } |
| 654 | enum_declaration_body |
| 655 | { |
| 656 | EnumType *enumType = static_cast<EnumType *>(ast->scope()); |
| 657 | ast->leaveScope(); |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 658 | |
| 659 | std::string errorMsg; |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 660 | if (!ast->addScopedType(enumType, &errorMsg)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 661 | std::cerr << "ERROR: " << errorMsg << " at " << @2 << "\n"; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 662 | YYERROR; |
| 663 | } |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame^] | 664 | |
| 665 | $$ = enumType; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 666 | } |
| 667 | ; |
| 668 | |
| 669 | enum_declaration |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 670 | : ENUM |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 671 | { |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 672 | std::string anonName = ast->scope()->pickUniqueAnonymousName(); |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 673 | ast->enterScope(new EnumType(anonName.c_str())); |
| 674 | } |
| 675 | enum_declaration_body |
| 676 | { |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 677 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 678 | EnumType *enumType = static_cast<EnumType *>(ast->scope()); |
| 679 | ast->leaveScope(); |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 680 | |
| 681 | std::string errorMsg; |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 682 | if (!ast->addScopedType(enumType, &errorMsg)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 683 | // This should never fail. |
| 684 | std::cerr << "ERROR: " << errorMsg << "\n"; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 685 | YYERROR; |
| 686 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 687 | |
Andreas Huber | fd4afab | 2016-08-03 13:02:57 -0700 | [diff] [blame] | 688 | $$ = enumType->ref(); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 689 | } |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 690 | | ENUM IDENTIFIER opt_storage_type |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 691 | { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 692 | ast->enterScope(new EnumType($2, $3)); |
| 693 | } |
| 694 | enum_declaration_body |
| 695 | { |
| 696 | EnumType *enumType = static_cast<EnumType *>(ast->scope()); |
| 697 | ast->leaveScope(); |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 698 | |
| 699 | std::string errorMsg; |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 700 | if (!ast->addScopedType(enumType, &errorMsg)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 701 | std::cerr << "ERROR: " << errorMsg << " at " << @2 << "\n"; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 702 | YYERROR; |
| 703 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 704 | |
Andreas Huber | fd4afab | 2016-08-03 13:02:57 -0700 | [diff] [blame] | 705 | $$ = enumType->ref(); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 706 | } |
| 707 | ; |
| 708 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 709 | enum_declaration_body |
| 710 | : '{' enum_values opt_comma '}' { $$ = $2; } |
| 711 | ; |
| 712 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 713 | enum_value |
| 714 | : IDENTIFIER { $$ = new EnumValue($1); } |
Yifan Hong | 5788697 | 2016-08-17 10:42:15 -0700 | [diff] [blame] | 715 | | IDENTIFIER '=' const_expr { $$ = new EnumValue($1, $3); } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 716 | ; |
| 717 | |
| 718 | enum_values |
| 719 | : /* empty */ |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 720 | { /* do nothing */ } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 721 | | enum_value |
| 722 | { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 723 | static_cast<EnumType *>(ast->scope())->addValue($1); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 724 | } |
| 725 | | enum_values ',' enum_value |
| 726 | { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 727 | static_cast<EnumType *>(ast->scope())->addValue($3); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 728 | } |
| 729 | ; |
| 730 | |
| 731 | type |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 732 | : fqtype { $$ = $1; } |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 733 | | fqtype '[' const_expr ']' |
Andreas Huber | b95ea8a | 2016-08-15 15:35:42 -0700 | [diff] [blame] | 734 | { |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 735 | if ($1->isBinder()) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 736 | std::cerr << "ERROR: Arrays of interface types are not supported." |
| 737 | << " at " << @1 << "\n"; |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 738 | |
Andreas Huber | b95ea8a | 2016-08-15 15:35:42 -0700 | [diff] [blame] | 739 | YYERROR; |
| 740 | } |
| 741 | |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 742 | if ($1->isArray()) { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 743 | $$ = new ArrayType(static_cast<ArrayType *>($1), $3); |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 744 | } else { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 745 | $$ = new ArrayType($1, $3); |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 746 | } |
Andreas Huber | b95ea8a | 2016-08-15 15:35:42 -0700 | [diff] [blame] | 747 | } |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 748 | | VEC '<' fqtype '>' |
Andreas Huber | b95ea8a | 2016-08-15 15:35:42 -0700 | [diff] [blame] | 749 | { |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 750 | if ($3->isBinder()) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 751 | std::cerr << "ERROR: Vectors of interface types are not " |
| 752 | << "supported. at " << @3 << "\n"; |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 753 | |
Andreas Huber | b95ea8a | 2016-08-15 15:35:42 -0700 | [diff] [blame] | 754 | YYERROR; |
| 755 | } |
| 756 | |
| 757 | $$ = new VectorType($3); |
| 758 | } |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame^] | 759 | | annotated_compound_declaration { $$ = $1; } |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 760 | | INTERFACE { $$ = new GenericBinder; } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 761 | ; |
| 762 | |
| 763 | optIdentifier |
| 764 | : /* empty */ { $$ = NULL; } |
| 765 | | IDENTIFIER { $$ = $1; } |
| 766 | ; |
| 767 | |
| 768 | %% |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 769 | |
| 770 | #include <android-base/logging.h> |
| 771 | |
| 772 | void yy::parser::error( |
| 773 | const yy::parser::location_type &where, |
| 774 | const std::string &errstr) { |
| 775 | std::cerr << "ERROR: " << errstr << " at " << where << "\n"; |
| 776 | } |
| 777 | |