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