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