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" |
| 25 | #include "Interface.h" |
Yifan Hong | a4b53d0 | 2016-10-31 17:29:10 -0700 | [diff] [blame] | 26 | #include "Location.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 27 | #include "Method.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 28 | #include "VectorType.h" |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 29 | #include "RefType.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 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> |
Steven Moreland | 7ae3d54 | 2017-01-18 16:46:01 -0800 | [diff] [blame] | 34 | #include <hidl-util/FQName.h> |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 35 | #include <hidl-util/StringHelper.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 | |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 51 | bool isValidInterfaceField(const char *identifier, std::string *errorMsg) { |
| 52 | static const std::vector<std::string> reserved({ |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 53 | // Injected names to C++ interfaces by auto-generated code |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 54 | "isRemote", "descriptor", "hidlStaticBlock", "onTransact", |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 55 | "castFrom", "Proxy", "Stub", "getService", |
| 56 | |
| 57 | // Injected names to Java interfaces by auto-generated code |
| 58 | "asInterface", "castFrom", "getService", "toString", |
Yifan Hong | b16199d | 2016-12-09 14:49:46 -0800 | [diff] [blame] | 59 | |
| 60 | // Inherited methods from IBase is detected in addMethod. Not added here |
| 61 | // because we need hidl-gen to compile IBase. |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 62 | |
| 63 | // Inherited names by interfaces from IInterface / IBinder |
| 64 | "onAsBinder", "asBinder", "queryLocalInterface", "getInterfaceDescriptor", "isBinderAlive", |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 65 | "pingBinder", "dump", "transact", "checkSubclass", "attachObject", "findObject", |
| 66 | "detachObject", "localBinder", "remoteBinder", "mImpl", |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 67 | |
| 68 | // Inherited names from HidlInstrumentor |
| 69 | "InstrumentationEvent", "configureInstrumentation", "registerInstrumentationCallbacks", |
| 70 | "isInstrumentationLib", "mInstrumentationCal1lbacks", "mEnableInstrumentation", |
| 71 | "mInstrumentationLibPackage", "mInterfaceName", |
| 72 | |
| 73 | // Collide with names in BsFoo |
| 74 | "mImpl", "addOnewayTask", "mOnewayQueue", |
| 75 | |
| 76 | // Inherited names from Java IHwInterface |
| 77 | "asBinder", |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 78 | }); |
| 79 | std::string idstr(identifier); |
| 80 | if (std::find(reserved.begin(), reserved.end(), idstr) != reserved.end()) { |
| 81 | *errorMsg = idstr + " cannot be a name inside an interface"; |
| 82 | return false; |
| 83 | } |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | bool isValidStructField(const char *identifier, std::string *errorMsg) { |
| 88 | static const std::vector<std::string> reserved({ |
| 89 | // Injected names to structs and unions by auto-generated code |
| 90 | "readEmbeddedFromParcel", "writeEmbeddedToParcel", "readVectorFromParcel", |
| 91 | "writeVectorToParcel", "writeEmbeddedToBlob", |
| 92 | }); |
| 93 | std::string idstr(identifier); |
| 94 | if (std::find(reserved.begin(), reserved.end(), idstr) != reserved.end()) { |
| 95 | *errorMsg = idstr + " cannot be a name inside an struct or union"; |
| 96 | return false; |
| 97 | } |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | bool isValidIdentifier(const char *identifier, std::string *errorMsg) { |
| 102 | static const std::vector<std::string> keywords({ |
| 103 | "uint8_t", "uint16_t", "uint32_t", "uint64_t", |
| 104 | "int8_t", "int16_t", "int32_t", "int64_t", "bool", "float", "double", |
| 105 | "interface", "struct", "union", "string", "vec", "enum", "ref", "handle", |
| 106 | "package", "import", "typedef", "generates", "oneway", "extends", |
Hridya Valsaraju | a32bde8 | 2016-12-27 11:47:46 -0800 | [diff] [blame] | 107 | "fmq_sync", "fmq_unsync", |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 108 | }); |
| 109 | static const std::vector<std::string> cppKeywords({ |
| 110 | "alignas", "alignof", "and", "and_eq", "asm", "atomic_cancel", "atomic_commit", |
| 111 | "atomic_noexcept", "auto", "bitand", "bitor", "bool", "break", "case", "catch", |
| 112 | "char", "char16_t", "char32_t", "class", "compl", "concept", "const", "constexpr", |
| 113 | "const_cast", "continue", "decltype", "default", "delete", "do", "double", |
| 114 | "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "float", |
| 115 | "for", "friend", "goto", "if", "inline", "int", "import", "long", "module", "mutable", |
| 116 | "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", |
| 117 | "private", "protected", "public", "register", "reinterpret_cast", "requires", "return", |
| 118 | "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", |
| 119 | "switch", "synchronized", "template", "this", "thread_local", "throw", "true", "try", |
| 120 | "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", |
| 121 | "volatile", "wchar_t", "while", "xor", "xor_eq", |
| 122 | }); |
| 123 | static const std::vector<std::string> javaKeywords({ |
| 124 | "abstract", "continue", "for", "new", "switch", "assert", "default", "goto", "package", |
| 125 | "synchronized", "boolean", "do", "if", "private", "this", "break", "double", |
| 126 | "implements", "protected", "throw", "byte", "else", "import", "public", "throws", |
| 127 | "case", "enum", "instanceof", "return", "transient", "catch", "extends", "int", |
| 128 | "short", "try", "char", "final", "interface", "static", "void", "class", "finally", |
| 129 | "long", "strictfp", "volatile", "const", "float", "native", "super", "while", |
| 130 | }); |
| 131 | static const std::vector<std::string> cppCollide({ |
| 132 | "size_t", "offsetof", |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 133 | }); |
| 134 | |
| 135 | // errors |
| 136 | std::string idstr(identifier); |
| 137 | if (std::find(keywords.begin(), keywords.end(), idstr) != keywords.end()) { |
| 138 | *errorMsg = idstr + " is a HIDL keyword " |
| 139 | "and is therefore not a valid identifier"; |
| 140 | return false; |
| 141 | } |
| 142 | if (std::find(cppKeywords.begin(), cppKeywords.end(), idstr) != cppKeywords.end()) { |
| 143 | *errorMsg = idstr + " is a C++ keyword " |
| 144 | "and is therefore not a valid identifier"; |
| 145 | return false; |
| 146 | } |
| 147 | if (std::find(javaKeywords.begin(), javaKeywords.end(), idstr) != javaKeywords.end()) { |
| 148 | *errorMsg = idstr + " is a Java keyword " |
| 149 | "and is therefore not a valid identifier"; |
| 150 | return false; |
| 151 | } |
| 152 | if (std::find(cppCollide.begin(), cppCollide.end(), idstr) != cppCollide.end()) { |
| 153 | *errorMsg = idstr + " collides with reserved names in C++ code " |
| 154 | "and is therefore not a valid identifier"; |
| 155 | return false; |
| 156 | } |
| 157 | if (StringHelper::StartsWith(idstr, "_hidl_")) { |
| 158 | *errorMsg = idstr + " starts with _hidl_ " |
| 159 | "and is therefore not a valid identifier"; |
| 160 | return false; |
| 161 | } |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 162 | if (StringHelper::StartsWith(idstr, "hidl_")) { |
| 163 | *errorMsg = idstr + " starts with hidl_ " |
| 164 | "and is therefore not a valid identifier"; |
| 165 | return false; |
| 166 | } |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 167 | if (StringHelper::EndsWith(idstr, "_cb")) { |
| 168 | *errorMsg = idstr + " ends with _cb " |
| 169 | "and is therefore not a valid identifier"; |
| 170 | return false; |
| 171 | } |
| 172 | |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 173 | return true; |
| 174 | } |
| 175 | |
| 176 | // Return true if identifier is an acceptable name for an UDT. |
| 177 | bool isValidTypeName(const char *identifier, std::string *errorMsg) { |
| 178 | if (!isValidIdentifier(identifier, errorMsg)) { |
| 179 | return false; |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 180 | } |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 181 | |
| 182 | std::string idstr(identifier); |
| 183 | if (idstr == "toString") { |
| 184 | *errorMsg = idstr + " is not a valid type name"; |
| 185 | return false; |
| 186 | } |
| 187 | |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 188 | return true; |
| 189 | } |
Yifan Hong | a4b53d0 | 2016-10-31 17:29:10 -0700 | [diff] [blame] | 190 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 191 | %} |
| 192 | |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 193 | %initial-action { |
| 194 | // Initialize the initial location. |
| 195 | @$.begin.filename = @$.end.filename = |
| 196 | const_cast<std::string *>(&ast->getFilename()); |
| 197 | } |
| 198 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 199 | %parse-param { android::AST *ast } |
| 200 | %lex-param { void *scanner } |
| 201 | %pure-parser |
Steven Moreland | 4ab9b79 | 2016-09-26 14:14:07 -0700 | [diff] [blame] | 202 | %glr-parser |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 203 | %skeleton "glr.cc" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 204 | |
Steven Moreland | 4ab9b79 | 2016-09-26 14:14:07 -0700 | [diff] [blame] | 205 | %expect-rr 0 |
| 206 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 207 | %token<str> ENUM |
| 208 | %token<str> EXTENDS |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 209 | %token<str> FQNAME |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 210 | %token<str> GENERATES |
| 211 | %token<str> IDENTIFIER |
| 212 | %token<str> IMPORT |
| 213 | %token<str> INTEGER |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 214 | %token<str> FLOAT |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 215 | %token<str> INTERFACE |
| 216 | %token<str> PACKAGE |
Hridya Valsaraju | cd91bf6 | 2016-10-25 12:41:04 -0700 | [diff] [blame] | 217 | %token<type> TYPE |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 218 | %token<str> STRUCT |
| 219 | %token<str> STRING_LITERAL |
| 220 | %token<str> TYPEDEF |
| 221 | %token<str> UNION |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 222 | %token<templatedType> TEMPLATED |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 223 | %token<void> ONEWAY |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 224 | |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 225 | /* Operator precedence and associativity, as per |
| 226 | * http://en.cppreference.com/w/cpp/language/operator_precedence */ |
| 227 | /* Precedence level 15 ternary operator */ |
| 228 | %right '?' ':' |
| 229 | /* Precedence level 13 - 14, LTR, logical operators*/ |
| 230 | %left LOGICAL_OR |
| 231 | %left LOGICAL_AND |
| 232 | /* Precedence level 10 - 12, LTR, bitwise operators*/ |
| 233 | %left '|' |
| 234 | %left '^' |
| 235 | %left '&' |
| 236 | /* Precedence level 9, LTR */ |
| 237 | %left EQUALITY NEQ |
| 238 | /* Precedence level 8, LTR */ |
| 239 | %left '<' '>' LEQ GEQ |
| 240 | /* Precedence level 7, LTR */ |
| 241 | %left LSHIFT RSHIFT |
| 242 | /* Precedence level 6, LTR */ |
| 243 | %left '+' '-' |
| 244 | /* Precedence level 5, LTR */ |
| 245 | %left '*' '/' '%' |
| 246 | /* Precedence level 3, RTL; but we have to use %left here */ |
| 247 | %left UNARY_MINUS UNARY_PLUS '!' '~' |
| 248 | |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 249 | %type<str> error_stmt opt_error_stmt error |
Yifan Hong | 6a2fedf | 2016-10-11 13:44:07 -0700 | [diff] [blame] | 250 | %type<str> package |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 251 | %type<fqName> fqname |
| 252 | %type<type> fqtype |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 253 | %type<str> valid_identifier valid_type_name |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 254 | |
Steven Moreland | 1c71fd5 | 2016-11-29 14:03:33 -0800 | [diff] [blame] | 255 | %type<type> type enum_storage_type |
Yifan Hong | bd33e38 | 2016-11-02 13:30:17 -0700 | [diff] [blame] | 256 | %type<type> array_type_base |
| 257 | %type<arrayType> array_type |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 258 | %type<type> opt_extends |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 259 | %type<type> type_declaration type_declaration_body interface_declaration typedef_declaration |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 260 | %type<type> named_struct_or_union_declaration named_enum_declaration |
| 261 | %type<type> compound_declaration annotated_compound_declaration |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 262 | |
| 263 | %type<field> field_declaration |
| 264 | %type<fields> field_declarations struct_or_union_body |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 265 | %type<constantExpression> const_expr |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 266 | %type<enumValue> enum_value |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 267 | %type<enumValues> enum_values enum_declaration_body |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 268 | %type<typedVars> typed_vars |
| 269 | %type<typedVar> typed_var |
| 270 | %type<method> method_declaration |
| 271 | %type<compoundStyle> struct_or_union_keyword |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 272 | %type<stringVec> annotation_string_values annotation_string_value |
| 273 | %type<constExprVec> annotation_const_expr_values annotation_const_expr_value |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 274 | %type<annotationParam> annotation_param |
| 275 | %type<annotationParams> opt_annotation_params annotation_params |
| 276 | %type<annotation> annotation |
| 277 | %type<annotations> opt_annotations |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 278 | |
| 279 | %start program |
| 280 | |
| 281 | %union { |
| 282 | const char *str; |
| 283 | android::Type *type; |
Yifan Hong | bd33e38 | 2016-11-02 13:30:17 -0700 | [diff] [blame] | 284 | android::ArrayType *arrayType; |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 285 | android::TemplatedType *templatedType; |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 286 | android::FQName *fqName; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 287 | android::CompoundType *compoundType; |
| 288 | android::CompoundField *field; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 289 | std::vector<android::CompoundField *> *fields; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 290 | android::EnumValue *enumValue; |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 291 | android::ConstantExpression *constantExpression; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 292 | std::vector<android::EnumValue *> *enumValues; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 293 | android::TypedVar *typedVar; |
Yifan Hong | 7763ab3 | 2016-12-13 17:42:11 -0800 | [diff] [blame] | 294 | android::TypedVarVector *typedVars; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 295 | android::Method *method; |
| 296 | android::CompoundType::Style compoundStyle; |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 297 | std::vector<std::string> *stringVec; |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 298 | std::vector<android::ConstantExpression *> *constExprVec; |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 299 | android::AnnotationParam *annotationParam; |
| 300 | android::AnnotationParamVector *annotationParams; |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 301 | android::Annotation *annotation; |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 302 | std::vector<android::Annotation *> *annotations; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | %% |
| 306 | |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 307 | valid_identifier |
| 308 | : IDENTIFIER |
| 309 | { |
| 310 | std::string errorMsg; |
| 311 | if (!isValidIdentifier($1, &errorMsg)) { |
| 312 | std::cerr << "ERROR: " << errorMsg << " at " << @1 << "\n"; |
| 313 | YYERROR; |
| 314 | } |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 315 | $$ = $1; |
| 316 | } |
| 317 | ; |
| 318 | |
| 319 | valid_type_name |
| 320 | : IDENTIFIER |
| 321 | { |
| 322 | std::string errorMsg; |
| 323 | if (!isValidTypeName($1, &errorMsg)) { |
| 324 | std::cerr << "ERROR: " << errorMsg << " at " << @1 << "\n"; |
| 325 | YYERROR; |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 326 | } |
| 327 | $$ = $1; |
| 328 | } |
| 329 | ; |
| 330 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 331 | opt_annotations |
| 332 | : /* empty */ |
| 333 | { |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 334 | $$ = new std::vector<Annotation *>; |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 335 | } |
| 336 | | opt_annotations annotation |
| 337 | { |
| 338 | $$ = $1; |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 339 | $$->push_back($2); |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 340 | } |
| 341 | ; |
| 342 | |
| 343 | annotation |
| 344 | : '@' IDENTIFIER opt_annotation_params |
| 345 | { |
| 346 | $$ = new Annotation($2, $3); |
| 347 | } |
| 348 | ; |
| 349 | |
| 350 | opt_annotation_params |
| 351 | : /* empty */ |
| 352 | { |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 353 | $$ = new AnnotationParamVector; |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 354 | } |
| 355 | | '(' annotation_params ')' |
| 356 | { |
| 357 | $$ = $2; |
| 358 | } |
| 359 | ; |
| 360 | |
| 361 | annotation_params |
| 362 | : annotation_param |
| 363 | { |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 364 | $$ = new AnnotationParamVector; |
| 365 | $$->push_back($1); |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 366 | } |
| 367 | | annotation_params ',' annotation_param |
| 368 | { |
| 369 | $$ = $1; |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 370 | $$->push_back($3); |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 371 | } |
| 372 | ; |
| 373 | |
| 374 | annotation_param |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 375 | : IDENTIFIER '=' annotation_string_value |
| 376 | { |
| 377 | $$ = new AnnotationParam($1, $3); |
| 378 | } |
| 379 | | IDENTIFIER '=' annotation_const_expr_value |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 380 | { |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 381 | $$ = new AnnotationParam($1, $3); |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 382 | } |
| 383 | ; |
| 384 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 385 | annotation_string_value |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 386 | : STRING_LITERAL |
| 387 | { |
| 388 | $$ = new std::vector<std::string>; |
| 389 | $$->push_back($1); |
| 390 | } |
| 391 | | '{' annotation_string_values '}' { $$ = $2; } |
| 392 | ; |
| 393 | |
| 394 | annotation_string_values |
| 395 | : STRING_LITERAL |
| 396 | { |
| 397 | $$ = new std::vector<std::string>; |
| 398 | $$->push_back($1); |
| 399 | } |
| 400 | | annotation_string_values ',' STRING_LITERAL |
| 401 | { |
| 402 | $$ = $1; |
| 403 | $$->push_back($3); |
| 404 | } |
| 405 | ; |
| 406 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 407 | annotation_const_expr_value |
| 408 | : const_expr |
| 409 | { |
| 410 | $$ = new std::vector<ConstantExpression *>; |
| 411 | $$->push_back($1); |
| 412 | } |
| 413 | | '{' annotation_const_expr_values '}' { $$ = $2; } |
| 414 | ; |
| 415 | |
| 416 | annotation_const_expr_values |
| 417 | : const_expr |
| 418 | { |
| 419 | $$ = new std::vector<ConstantExpression *>; |
| 420 | $$->push_back($1); |
| 421 | } |
| 422 | | annotation_const_expr_values ',' const_expr |
| 423 | { |
| 424 | $$ = $1; |
| 425 | $$->push_back($3); |
| 426 | } |
| 427 | ; |
| 428 | |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 429 | error_stmt |
| 430 | : error ';' |
| 431 | { |
| 432 | $$ = $1; |
| 433 | ast->addSyntaxError(); |
| 434 | // std::cerr << "WARNING: skipping errors until " << @2 << ".\n"; |
| 435 | } |
| 436 | ; |
| 437 | |
| 438 | opt_error_stmt |
| 439 | : /* empty */ { $$ = NULL; } |
| 440 | | error_stmt { $$ = $1; } |
| 441 | ; |
| 442 | |
| 443 | require_semicolon |
| 444 | : ';' |
| 445 | | /* empty */ |
| 446 | { |
| 447 | std::cerr << "ERROR: missing ; at " << @$ << "\n"; |
| 448 | ast->addSyntaxError(); |
| 449 | } |
| 450 | ; |
| 451 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 452 | program |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 453 | : opt_error_stmt |
| 454 | package |
| 455 | imports |
| 456 | body |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 457 | ; |
| 458 | |
| 459 | fqname |
| 460 | : FQNAME |
| 461 | { |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 462 | $$ = new FQName($1); |
| 463 | if(!$$->isValid()) { |
| 464 | std::cerr << "ERROR: FQName '" << $1 << "' is not valid at " |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 465 | << @1 |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 466 | << ".\n"; |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 467 | YYERROR; |
| 468 | } |
| 469 | } |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 470 | | valid_type_name |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 471 | { |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 472 | $$ = new FQName($1); |
| 473 | if(!$$->isValid()) { |
| 474 | std::cerr << "ERROR: FQName '" << $1 << "' is not valid at " |
| 475 | << @1 |
| 476 | << ".\n"; |
| 477 | YYERROR; |
| 478 | } |
| 479 | } |
| 480 | ; |
| 481 | |
| 482 | fqtype |
| 483 | : fqname |
| 484 | { |
| 485 | $$ = ast->lookupType(*($1)); |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 486 | if ($$ == NULL) { |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 487 | std::cerr << "ERROR: Failed to lookup type '" << $1->string() << "' at " |
| 488 | << @1 |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 489 | << "\n"; |
| 490 | |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 491 | YYERROR; |
| 492 | } |
| 493 | } |
Hridya Valsaraju | cd91bf6 | 2016-10-25 12:41:04 -0700 | [diff] [blame] | 494 | | TYPE |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 495 | ; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 496 | |
| 497 | package |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 498 | : PACKAGE FQNAME require_semicolon |
Andreas Huber | eb1081f | 2016-07-28 13:13:24 -0700 | [diff] [blame] | 499 | { |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 500 | if (!ast->setPackage($2)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 501 | std::cerr << "ERROR: Malformed package identifier '" |
| 502 | << $2 |
| 503 | << "' at " |
| 504 | << @2 |
| 505 | << "\n"; |
| 506 | |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 507 | YYERROR; |
| 508 | } |
Andreas Huber | eb1081f | 2016-07-28 13:13:24 -0700 | [diff] [blame] | 509 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 510 | |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 511 | import_stmt |
| 512 | : IMPORT FQNAME require_semicolon |
| 513 | { |
| 514 | if (!ast->addImport($2)) { |
| 515 | std::cerr << "ERROR: Unable to import '" << $2 << "' at " << @2 |
| 516 | << "\n"; |
| 517 | ast->addSyntaxError(); |
| 518 | } |
| 519 | } |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 520 | | IMPORT valid_type_name require_semicolon |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 521 | { |
| 522 | if (!ast->addImport($2)) { |
| 523 | std::cerr << "ERROR: Unable to import '" << $2 << "' at " << @2 |
| 524 | << "\n"; |
| 525 | ast->addSyntaxError(); |
| 526 | } |
| 527 | } |
| 528 | | IMPORT error_stmt |
| 529 | ; |
| 530 | |
| 531 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 532 | imports |
| 533 | : /* empty */ |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 534 | | imports import_stmt |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 535 | ; |
| 536 | |
| 537 | opt_extends |
| 538 | : /* empty */ { $$ = NULL; } |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 539 | | EXTENDS fqtype { $$ = $2; } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 540 | |
| 541 | body |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 542 | : type_declarations |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 543 | ; |
| 544 | |
| 545 | interface_declarations |
| 546 | : /* empty */ |
| 547 | | interface_declarations type_declaration |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 548 | { |
| 549 | std::string errorMsg; |
| 550 | if ($2 != nullptr && |
| 551 | $2->isNamedType() && |
| 552 | !isValidInterfaceField(static_cast<NamedType *>($2)->localName().c_str(), |
| 553 | &errorMsg)) { |
| 554 | std::cerr << "ERROR: " << errorMsg << " at " |
| 555 | << @2 << "\n"; |
| 556 | YYERROR; |
| 557 | } |
| 558 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 559 | | interface_declarations method_declaration |
| 560 | { |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 561 | std::string errorMsg; |
| 562 | if ($2 != nullptr && |
| 563 | !isValidInterfaceField($2->name().c_str(), &errorMsg)) { |
| 564 | std::cerr << "ERROR: " << errorMsg << " at " |
| 565 | << @2 << "\n"; |
| 566 | YYERROR; |
| 567 | } |
| 568 | |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 569 | if ($2 != nullptr) { |
| 570 | if (!ast->scope()->isInterface()) { |
| 571 | std::cerr << "ERROR: unknown error in interface declaration at " |
| 572 | << @2 << "\n"; |
| 573 | YYERROR; |
| 574 | } |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 575 | |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 576 | Interface *iface = static_cast<Interface *>(ast->scope()); |
| 577 | if (!iface->addMethod($2)) { |
| 578 | std::cerr << "ERROR: Unable to add method '" << $2->name() |
| 579 | << "' at " << @2 << "\n"; |
| 580 | |
| 581 | YYERROR; |
| 582 | } |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 583 | } |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 584 | // ignore if $2 is nullptr (from error recovery) |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 585 | } |
| 586 | ; |
| 587 | |
| 588 | type_declarations |
Andreas Huber | a2723d2 | 2016-07-29 15:36:07 -0700 | [diff] [blame] | 589 | : /* empty */ |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 590 | | error_stmt |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 591 | | type_declarations type_declaration |
| 592 | ; |
| 593 | |
| 594 | type_declaration |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 595 | : opt_annotations type_declaration_body |
| 596 | { |
| 597 | if ($2 != nullptr) { |
| 598 | $2->setAnnotations($1); |
| 599 | } else if (!$1->empty()) { |
| 600 | // Since typedefs are always resolved to their target it makes |
| 601 | // little sense to annotate them and have their annotations |
| 602 | // impose semantics other than their target type. |
| 603 | std::cerr << "ERROR: typedefs cannot be annotated. at " << @2 |
| 604 | << "\n"; |
| 605 | |
| 606 | YYERROR; |
| 607 | } |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 608 | $$ = $2; |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 609 | } |
| 610 | ; |
| 611 | |
| 612 | type_declaration_body |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 613 | : named_struct_or_union_declaration require_semicolon |
| 614 | | named_enum_declaration require_semicolon |
| 615 | | typedef_declaration require_semicolon |
| 616 | | interface_declaration require_semicolon |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 617 | ; |
| 618 | |
| 619 | interface_declaration |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 620 | : INTERFACE valid_type_name opt_extends |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 621 | { |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 622 | Type *parent = $3; |
| 623 | |
| 624 | if (ast->package() != gIBasePackageFqName) { |
| 625 | if (!ast->addImport(gIBaseFqName.string().c_str())) { |
| 626 | std::cerr << "ERROR: Unable to automatically import '" |
| 627 | << gIBaseFqName.string() |
| 628 | << "' at " << @$ |
| 629 | << "\n"; |
| 630 | YYERROR; |
| 631 | } |
| 632 | if (parent == nullptr) { |
| 633 | parent = ast->lookupType(gIBaseFqName); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | if (parent != NULL && !parent->isInterface()) { |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 638 | std::cerr << "ERROR: You can only extend interfaces. at " << @3 |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 639 | << "\n"; |
| 640 | |
| 641 | YYERROR; |
| 642 | } |
| 643 | |
| 644 | if ($2[0] != 'I') { |
| 645 | std::cerr << "ERROR: All interface names must start with an 'I' " |
| 646 | << "prefix. at " << @2 << "\n"; |
| 647 | |
| 648 | YYERROR; |
| 649 | } |
| 650 | |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 651 | Interface *iface = new Interface($2, convertYYLoc(@2), static_cast<Interface *>(parent)); |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 652 | |
| 653 | // Register interface immediately so it can be referenced inside |
| 654 | // definition. |
| 655 | std::string errorMsg; |
| 656 | if (!ast->addScopedType(iface, &errorMsg)) { |
| 657 | std::cerr << "ERROR: " << errorMsg << " at " << @2 << "\n"; |
| 658 | YYERROR; |
| 659 | } |
| 660 | |
| 661 | ast->enterScope(iface); |
| 662 | } |
| 663 | '{' interface_declarations '}' |
| 664 | { |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 665 | if (!ast->scope()->isInterface()) { |
| 666 | std::cerr << "ERROR: unknown error in interface declaration at " |
| 667 | << @5 << "\n"; |
| 668 | YYERROR; |
| 669 | } |
| 670 | |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 671 | Interface *iface = static_cast<Interface *>(ast->scope()); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 672 | if (!iface->addAllReservedMethods()) { |
| 673 | std::cerr << "ERROR: unknown error in adding reserved methods at " |
| 674 | << @5 << "\n"; |
| 675 | YYERROR; |
| 676 | } |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 677 | |
| 678 | ast->leaveScope(); |
| 679 | |
| 680 | $$ = iface; |
| 681 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 682 | ; |
| 683 | |
| 684 | typedef_declaration |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 685 | : TYPEDEF type valid_type_name |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 686 | { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 687 | std::string errorMsg; |
Yifan Hong | a4b53d0 | 2016-10-31 17:29:10 -0700 | [diff] [blame] | 688 | if (!ast->addTypeDef($3, $2, convertYYLoc(@3), &errorMsg)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 689 | std::cerr << "ERROR: " << errorMsg << " at " << @3 << "\n"; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 690 | YYERROR; |
| 691 | } |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 692 | |
| 693 | $$ = nullptr; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 694 | } |
| 695 | ; |
| 696 | |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 697 | const_expr |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 698 | : INTEGER { $$ = new ConstantExpression($1); } |
Yifan Hong | b44a6c8 | 2016-09-22 15:50:18 -0700 | [diff] [blame] | 699 | | fqname |
| 700 | { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 701 | if(!$1->isValidValueName()) { |
| 702 | std::cerr << "ERROR: '" << $1->string() |
| 703 | << "' does not refer to an enum value at " |
| 704 | << @1 << ".\n"; |
| 705 | YYERROR; |
| 706 | } |
| 707 | if($1->isIdentifier()) { |
| 708 | std::string identifier = $1->name(); |
| 709 | LocalIdentifier *iden = ast->scope()->lookupIdentifier(identifier); |
| 710 | if(!iden) { |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 711 | std::cerr << "ERROR: identifier " << $1->string() |
| 712 | << " could not be found at " << @1 << ".\n"; |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 713 | YYERROR; |
| 714 | } |
| 715 | if(!iden->isEnumValue()) { |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 716 | std::cerr << "ERROR: identifier " << $1->string() |
| 717 | << " is not an enum value at " << @1 << ".\n"; |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 718 | YYERROR; |
| 719 | } |
| 720 | $$ = new ConstantExpression( |
| 721 | *(static_cast<EnumValue *>(iden)->constExpr()), $1->string()); |
| 722 | } else { |
| 723 | std::string errorMsg; |
| 724 | EnumValue *v = ast->lookupEnumValue(*($1), &errorMsg); |
| 725 | if(v == nullptr) { |
| 726 | std::cerr << "ERROR: " << errorMsg << " at " << @1 << ".\n"; |
| 727 | YYERROR; |
| 728 | } |
| 729 | $$ = new ConstantExpression(*(v->constExpr()), $1->string()); |
| 730 | } |
Yifan Hong | b44a6c8 | 2016-09-22 15:50:18 -0700 | [diff] [blame] | 731 | } |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 732 | | const_expr '?' const_expr ':' const_expr |
| 733 | { |
Yifan Hong | b44a6c8 | 2016-09-22 15:50:18 -0700 | [diff] [blame] | 734 | $$ = new ConstantExpression($1, $3, $5); |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 735 | } |
| 736 | | const_expr LOGICAL_OR const_expr { $$ = new ConstantExpression($1, "||", $3); } |
| 737 | | const_expr LOGICAL_AND const_expr { $$ = new ConstantExpression($1, "&&", $3); } |
| 738 | | const_expr '|' const_expr { $$ = new ConstantExpression($1, "|" , $3); } |
| 739 | | const_expr '^' const_expr { $$ = new ConstantExpression($1, "^" , $3); } |
| 740 | | const_expr '&' const_expr { $$ = new ConstantExpression($1, "&" , $3); } |
| 741 | | const_expr EQUALITY const_expr { $$ = new ConstantExpression($1, "==", $3); } |
| 742 | | const_expr NEQ const_expr { $$ = new ConstantExpression($1, "!=", $3); } |
| 743 | | const_expr '<' const_expr { $$ = new ConstantExpression($1, "<" , $3); } |
| 744 | | const_expr '>' const_expr { $$ = new ConstantExpression($1, ">" , $3); } |
| 745 | | const_expr LEQ const_expr { $$ = new ConstantExpression($1, "<=", $3); } |
| 746 | | const_expr GEQ const_expr { $$ = new ConstantExpression($1, ">=", $3); } |
| 747 | | const_expr LSHIFT const_expr { $$ = new ConstantExpression($1, "<<", $3); } |
| 748 | | const_expr RSHIFT const_expr { $$ = new ConstantExpression($1, ">>", $3); } |
| 749 | | const_expr '+' const_expr { $$ = new ConstantExpression($1, "+" , $3); } |
| 750 | | const_expr '-' const_expr { $$ = new ConstantExpression($1, "-" , $3); } |
| 751 | | const_expr '*' const_expr { $$ = new ConstantExpression($1, "*" , $3); } |
| 752 | | const_expr '/' const_expr { $$ = new ConstantExpression($1, "/" , $3); } |
| 753 | | const_expr '%' const_expr { $$ = new ConstantExpression($1, "%" , $3); } |
| 754 | | '+' const_expr %prec UNARY_PLUS { $$ = new ConstantExpression("+", $2); } |
| 755 | | '-' const_expr %prec UNARY_MINUS { $$ = new ConstantExpression("-", $2); } |
| 756 | | '!' const_expr { $$ = new ConstantExpression("!", $2); } |
| 757 | | '~' const_expr { $$ = new ConstantExpression("~", $2); } |
| 758 | | '(' const_expr ')' { $$ = $2; } |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 759 | | '(' error ')' |
| 760 | { |
| 761 | ast->addSyntaxError(); |
| 762 | // to avoid segfaults |
| 763 | $$ = new ConstantExpression(ConstantExpression::Zero(ScalarType::KIND_INT32)); |
| 764 | } |
Yifan Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 765 | ; |
| 766 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 767 | method_declaration |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 768 | : error_stmt { $$ = nullptr; } |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 769 | | opt_annotations valid_identifier '(' typed_vars ')' require_semicolon |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 770 | { |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 771 | $$ = new Method($2, $4, new std::vector<TypedVar *>, false, $1); |
| 772 | } |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 773 | | opt_annotations ONEWAY valid_identifier '(' typed_vars ')' require_semicolon |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 774 | { |
| 775 | $$ = new Method($3, $5, new std::vector<TypedVar *>, true, $1); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 776 | } |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 777 | | opt_annotations valid_identifier '(' typed_vars ')' GENERATES '(' typed_vars ')' require_semicolon |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 778 | { |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 779 | $$ = new Method($2, $4, $8, false, $1); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 780 | } |
| 781 | ; |
| 782 | |
| 783 | typed_vars |
| 784 | : /* empty */ |
| 785 | { |
Yifan Hong | 7763ab3 | 2016-12-13 17:42:11 -0800 | [diff] [blame] | 786 | $$ = new TypedVarVector(); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 787 | } |
| 788 | | typed_var |
| 789 | { |
Yifan Hong | 7763ab3 | 2016-12-13 17:42:11 -0800 | [diff] [blame] | 790 | $$ = new TypedVarVector(); |
| 791 | if (!$$->add($1)) { |
| 792 | std::cerr << "ERROR: duplicated argument or result name " |
| 793 | << $1->name() << " at " << @1 << "\n"; |
| 794 | ast->addSyntaxError(); |
| 795 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 796 | } |
| 797 | | typed_vars ',' typed_var |
| 798 | { |
| 799 | $$ = $1; |
Yifan Hong | 7763ab3 | 2016-12-13 17:42:11 -0800 | [diff] [blame] | 800 | if (!$$->add($3)) { |
| 801 | std::cerr << "ERROR: duplicated argument or result name " |
| 802 | << $3->name() << " at " << @3 << "\n"; |
| 803 | ast->addSyntaxError(); |
| 804 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 805 | } |
| 806 | ; |
| 807 | |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 808 | typed_var : type valid_identifier { $$ = new TypedVar($2, $1); } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 809 | ; |
| 810 | |
| 811 | |
| 812 | struct_or_union_keyword |
| 813 | : STRUCT { $$ = CompoundType::STYLE_STRUCT; } |
| 814 | | UNION { $$ = CompoundType::STYLE_UNION; } |
| 815 | ; |
| 816 | |
| 817 | named_struct_or_union_declaration |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 818 | : struct_or_union_keyword valid_type_name |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 819 | { |
Yifan Hong | a4b53d0 | 2016-10-31 17:29:10 -0700 | [diff] [blame] | 820 | CompoundType *container = new CompoundType($1, $2, convertYYLoc(@2)); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 821 | ast->enterScope(container); |
| 822 | } |
| 823 | struct_or_union_body |
| 824 | { |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 825 | if (!ast->scope()->isCompoundType()) { |
| 826 | std::cerr << "ERROR: unknown error in struct or union declaration at " |
| 827 | << @4 << "\n"; |
| 828 | YYERROR; |
| 829 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 830 | CompoundType *container = static_cast<CompoundType *>(ast->scope()); |
| 831 | |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 832 | std::string errorMsg; |
| 833 | if (!container->setFields($4, &errorMsg)) { |
| 834 | std::cerr << "ERROR: " << errorMsg << " at " << @4 << "\n"; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 835 | YYERROR; |
| 836 | } |
| 837 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 838 | ast->leaveScope(); |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 839 | |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 840 | if (!ast->addScopedType(container, &errorMsg)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 841 | std::cerr << "ERROR: " << errorMsg << " at " << @2 << "\n"; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 842 | YYERROR; |
| 843 | } |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 844 | |
| 845 | $$ = container; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 846 | } |
| 847 | ; |
| 848 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 849 | struct_or_union_body |
| 850 | : '{' field_declarations '}' { $$ = $2; } |
| 851 | ; |
| 852 | |
| 853 | field_declarations |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 854 | : /* empty */ { $$ = new std::vector<CompoundField *>; } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 855 | | field_declarations field_declaration |
| 856 | { |
| 857 | $$ = $1; |
| 858 | |
| 859 | if ($2 != NULL) { |
| 860 | $$->push_back($2); |
| 861 | } |
| 862 | } |
| 863 | ; |
| 864 | |
| 865 | field_declaration |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 866 | : error_stmt { $$ = nullptr; } |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 867 | | type valid_identifier require_semicolon |
| 868 | { |
| 869 | std::string errorMsg; |
| 870 | if (ast->scope()->isCompoundType() && |
| 871 | static_cast<CompoundType *>(ast->scope())->style() == CompoundType::STYLE_STRUCT && |
| 872 | !isValidStructField($2, &errorMsg)) { |
| 873 | std::cerr << "ERROR: " << errorMsg << " at " |
| 874 | << @2 << "\n"; |
| 875 | YYERROR; |
| 876 | } |
| 877 | $$ = new CompoundField($2, $1); |
| 878 | } |
| 879 | | annotated_compound_declaration ';' |
| 880 | { |
| 881 | std::string errorMsg; |
| 882 | if (ast->scope()->isCompoundType() && |
| 883 | static_cast<CompoundType *>(ast->scope())->style() == CompoundType::STYLE_STRUCT && |
| 884 | $1 != nullptr && |
| 885 | $1->isNamedType() && |
| 886 | !isValidStructField(static_cast<NamedType *>($1)->localName().c_str(), &errorMsg)) { |
| 887 | std::cerr << "ERROR: " << errorMsg << " at " |
| 888 | << @2 << "\n"; |
| 889 | YYERROR; |
| 890 | } |
| 891 | $$ = NULL; |
| 892 | } |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 893 | ; |
| 894 | |
| 895 | annotated_compound_declaration |
| 896 | : opt_annotations compound_declaration |
| 897 | { |
| 898 | $2->setAnnotations($1); |
| 899 | $$ = $2; |
| 900 | } |
| 901 | ; |
| 902 | |
| 903 | compound_declaration |
Yifan Hong | a285501 | 2016-10-11 13:36:54 -0700 | [diff] [blame] | 904 | : named_struct_or_union_declaration { $$ = $1; } |
Yifan Hong | 6a2fedf | 2016-10-11 13:44:07 -0700 | [diff] [blame] | 905 | | named_enum_declaration { $$ = $1; } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 906 | ; |
| 907 | |
Steven Moreland | 1c71fd5 | 2016-11-29 14:03:33 -0800 | [diff] [blame] | 908 | enum_storage_type |
| 909 | : ':' fqtype |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 910 | { |
| 911 | $$ = $2; |
| 912 | |
| 913 | if ($$ != NULL && !$$->isValidEnumStorageType()) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 914 | std::cerr << "ERROR: Invalid enum storage type specified. at " |
| 915 | << @2 << "\n"; |
| 916 | |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 917 | YYERROR; |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 918 | } |
| 919 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 920 | ; |
| 921 | |
| 922 | opt_comma |
| 923 | : /* empty */ |
| 924 | | ',' |
| 925 | ; |
| 926 | |
| 927 | named_enum_declaration |
Yifan Hong | f3d3c73 | 2017-05-08 17:27:54 -0700 | [diff] [blame] | 928 | : ENUM valid_type_name enum_storage_type |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 929 | { |
Yifan Hong | a4b53d0 | 2016-10-31 17:29:10 -0700 | [diff] [blame] | 930 | ast->enterScope(new EnumType($2, convertYYLoc(@2), $3)); |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 931 | } |
| 932 | enum_declaration_body |
| 933 | { |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 934 | if (!ast->scope()->isEnum()) { |
| 935 | std::cerr << "ERROR: unknown error in enum declaration at " |
| 936 | << @5 << "\n"; |
| 937 | YYERROR; |
| 938 | } |
| 939 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 940 | EnumType *enumType = static_cast<EnumType *>(ast->scope()); |
| 941 | ast->leaveScope(); |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 942 | |
| 943 | std::string errorMsg; |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 944 | if (!ast->addScopedType(enumType, &errorMsg)) { |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 945 | std::cerr << "ERROR: " << errorMsg << " at " << @2 << "\n"; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 946 | YYERROR; |
| 947 | } |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 948 | |
| 949 | $$ = enumType; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 950 | } |
| 951 | ; |
| 952 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 953 | enum_declaration_body |
| 954 | : '{' enum_values opt_comma '}' { $$ = $2; } |
| 955 | ; |
| 956 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 957 | enum_value |
Yifan Hong | 27e85db | 2016-11-09 15:45:52 -0800 | [diff] [blame] | 958 | : valid_identifier { $$ = new EnumValue($1); } |
| 959 | | valid_identifier '=' const_expr { $$ = new EnumValue($1, $3); } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 960 | ; |
| 961 | |
| 962 | enum_values |
| 963 | : /* empty */ |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 964 | { /* do nothing */ } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 965 | | enum_value |
| 966 | { |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 967 | if (!ast->scope()->isEnum()) { |
| 968 | std::cerr << "ERROR: unknown error in enum declaration at " |
| 969 | << @1 << "\n"; |
| 970 | YYERROR; |
| 971 | } |
| 972 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 973 | static_cast<EnumType *>(ast->scope())->addValue($1); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 974 | } |
| 975 | | enum_values ',' enum_value |
| 976 | { |
Yifan Hong | be627b3 | 2016-10-28 18:38:56 -0700 | [diff] [blame] | 977 | if (!ast->scope()->isEnum()) { |
| 978 | std::cerr << "ERROR: unknown error in enum declaration at " |
| 979 | << @3 << "\n"; |
| 980 | YYERROR; |
| 981 | } |
| 982 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 983 | static_cast<EnumType *>(ast->scope())->addValue($3); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 984 | } |
| 985 | ; |
| 986 | |
Yifan Hong | bd33e38 | 2016-11-02 13:30:17 -0700 | [diff] [blame] | 987 | array_type_base |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 988 | : fqtype { $$ = $1; } |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 989 | | TEMPLATED '<' type '>' |
Andreas Huber | b95ea8a | 2016-08-15 15:35:42 -0700 | [diff] [blame] | 990 | { |
Steven Moreland | 30bb6a8 | 2016-11-30 09:18:34 -0800 | [diff] [blame] | 991 | if (!$1->isCompatibleElementType($3)) { |
| 992 | std::cerr << "ERROR: " << $1->typeName() << " of " << $3->typeName() |
| 993 | << " is not supported. at " << @3 << "\n"; |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 994 | |
Andreas Huber | b95ea8a | 2016-08-15 15:35:42 -0700 | [diff] [blame] | 995 | YYERROR; |
| 996 | } |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 997 | $1->setElementType($3); |
| 998 | $$ = $1; |
| 999 | } |
| 1000 | | TEMPLATED '<' TEMPLATED '<' type RSHIFT |
| 1001 | { |
Steven Moreland | 30bb6a8 | 2016-11-30 09:18:34 -0800 | [diff] [blame] | 1002 | if (!$3->isCompatibleElementType($5)) { |
| 1003 | std::cerr << "ERROR: " << $3->typeName() << " of " << $5->typeName() |
| 1004 | << " is not supported. at " << @3 << "\n"; |
Andreas Huber | b95ea8a | 2016-08-15 15:35:42 -0700 | [diff] [blame] | 1005 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1006 | YYERROR; |
| 1007 | } |
| 1008 | $3->setElementType($5); |
Steven Moreland | 30bb6a8 | 2016-11-30 09:18:34 -0800 | [diff] [blame] | 1009 | if (!$1->isCompatibleElementType($3)) { |
| 1010 | std::cerr << "ERROR: " << $1->typeName() << " of " << $3->typeName() |
| 1011 | << " is not supported. at " << @3 << "\n"; |
| 1012 | |
| 1013 | YYERROR; |
| 1014 | } |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1015 | $1->setElementType($3); |
| 1016 | $$ = $1; |
Andreas Huber | b95ea8a | 2016-08-15 15:35:42 -0700 | [diff] [blame] | 1017 | } |
Yifan Hong | bd33e38 | 2016-11-02 13:30:17 -0700 | [diff] [blame] | 1018 | ; |
| 1019 | |
| 1020 | array_type |
| 1021 | : array_type_base '[' const_expr ']' |
| 1022 | { |
| 1023 | if ($1->isBinder()) { |
| 1024 | std::cerr << "ERROR: Arrays of interface types are not supported." |
| 1025 | << " at " << @1 << "\n"; |
| 1026 | |
| 1027 | YYERROR; |
| 1028 | } |
| 1029 | if ($1->isArray()) { |
| 1030 | $$ = new ArrayType(static_cast<ArrayType *>($1), $3); |
| 1031 | } else { |
| 1032 | $$ = new ArrayType($1, $3); |
| 1033 | } |
| 1034 | } |
| 1035 | | array_type '[' const_expr ']' |
| 1036 | { |
| 1037 | $$ = $1; |
| 1038 | $$->appendDimension($3); |
| 1039 | } |
| 1040 | ; |
| 1041 | |
| 1042 | type |
| 1043 | : array_type_base { $$ = $1; } |
| 1044 | | array_type { $$ = $1; } |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 1045 | | annotated_compound_declaration { $$ = $1; } |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 1046 | | INTERFACE |
| 1047 | { |
| 1048 | // "interface" is a synonym of android.hidl.base@1.0::IBase |
| 1049 | $$ = ast->lookupType(gIBaseFqName); |
| 1050 | if ($$ == nullptr) { |
| 1051 | std::cerr << "FATAL: Cannot find " |
| 1052 | << gIBaseFqName.string() |
| 1053 | << " at " << @1 << "\n"; |
| 1054 | |
| 1055 | YYERROR; |
| 1056 | } |
| 1057 | } |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 1058 | ; |
| 1059 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 1060 | %% |
Andreas Huber | 0d0f9a2 | 2016-08-17 10:26:11 -0700 | [diff] [blame] | 1061 | |
| 1062 | #include <android-base/logging.h> |
| 1063 | |
| 1064 | void yy::parser::error( |
| 1065 | const yy::parser::location_type &where, |
| 1066 | const std::string &errstr) { |
| 1067 | std::cerr << "ERROR: " << errstr << " at " << where << "\n"; |
| 1068 | } |
| 1069 | |