Will McVicker | d7d18df | 2019-09-12 13:40:50 -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 | |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 17 | %{ |
| 18 | #include "aidl_language.h" |
Jiyong Park | e5c4529 | 2020-05-26 19:06:24 +0900 | [diff] [blame] | 19 | #include "parser.h" |
Dan Willemsen | 609ba6d | 2019-12-30 10:44:00 -0800 | [diff] [blame] | 20 | #include "aidl_language_y-module.h" |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 21 | #include "logging.h" |
Steven Moreland | f04cd5e | 2019-11-10 20:35:29 -0800 | [diff] [blame] | 22 | #include <android-base/parseint.h> |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 23 | #include <set> |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 24 | #include <map> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | |
Casey Dahlin | e8c0d7a | 2015-09-11 15:35:07 -0700 | [diff] [blame] | 29 | int yylex(yy::parser::semantic_type *, yy::parser::location_type *, void *); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 30 | |
Mathew Inwood | adb7467 | 2019-11-29 14:01:53 +0000 | [diff] [blame] | 31 | AidlLocation loc(const yy::parser::location_type& begin, const yy::parser::location_type& end) { |
| 32 | CHECK(begin.begin.filename == begin.end.filename); |
| 33 | CHECK(begin.end.filename == end.begin.filename); |
| 34 | CHECK(end.begin.filename == end.end.filename); |
| 35 | AidlLocation::Point begin_point { |
| 36 | .line = begin.begin.line, |
| 37 | .column = begin.begin.column, |
| 38 | }; |
| 39 | AidlLocation::Point end_point { |
| 40 | .line = end.end.line, |
| 41 | .column = end.end.column, |
| 42 | }; |
Devin Moore | df93ebb | 2020-03-25 14:03:35 -0700 | [diff] [blame] | 43 | return AidlLocation(*begin.begin.filename, begin_point, end_point, AidlLocation::Source::EXTERNAL); |
Mathew Inwood | adb7467 | 2019-11-29 14:01:53 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 46 | AidlLocation loc(const yy::parser::location_type& l) { |
Mathew Inwood | adb7467 | 2019-11-29 14:01:53 +0000 | [diff] [blame] | 47 | return loc(l, l); |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Casey Dahlin | fd2e08a | 2015-09-10 18:29:09 -0700 | [diff] [blame] | 50 | #define lex_scanner ps->Scanner() |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 51 | |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 52 | %} |
| 53 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 54 | %initial-action { |
| 55 | @$.begin.filename = @$.end.filename = |
| 56 | const_cast<std::string *>(&ps->FileName()); |
| 57 | } |
| 58 | |
Casey Dahlin | e250749 | 2015-09-14 17:11:20 -0700 | [diff] [blame] | 59 | %parse-param { Parser* ps } |
Casey Dahlin | fd2e08a | 2015-09-10 18:29:09 -0700 | [diff] [blame] | 60 | %lex-param { void *lex_scanner } |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 61 | |
Steven Moreland | 38a41d1 | 2018-07-10 11:01:07 -0700 | [diff] [blame] | 62 | %glr-parser |
Casey Dahlin | fd2e08a | 2015-09-10 18:29:09 -0700 | [diff] [blame] | 63 | %skeleton "glr.cc" |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 64 | |
Steven Moreland | 38a41d1 | 2018-07-10 11:01:07 -0700 | [diff] [blame] | 65 | %expect-rr 0 |
| 66 | |
Dan Willemsen | 609ba6d | 2019-12-30 10:44:00 -0800 | [diff] [blame] | 67 | %define parse.error verbose |
| 68 | %locations |
Steven Moreland | 2ca4fcb | 2018-06-27 16:01:01 -0700 | [diff] [blame] | 69 | |
Casey Dahlin | e8c0d7a | 2015-09-11 15:35:07 -0700 | [diff] [blame] | 70 | %union { |
Casey Dahlin | cdbbc8c | 2015-10-14 15:31:04 -0700 | [diff] [blame] | 71 | AidlToken* token; |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 72 | char character; |
Casey Dahlin | 0559875 | 2015-10-05 18:18:43 -0700 | [diff] [blame] | 73 | std::string *str; |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 74 | AidlAnnotation* annotation; |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 75 | AidlAnnotationParameter* param; |
| 76 | std::map<std::string, std::shared_ptr<AidlConstantValue>>* param_list; |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 77 | std::vector<AidlAnnotation>* annotation_list; |
Jiyong Park | d59a10d | 2018-07-18 11:12:55 +0900 | [diff] [blame] | 78 | AidlTypeSpecifier* type; |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 79 | AidlArgument* arg; |
Casey Dahlin | fd6fb48 | 2015-09-30 14:48:18 -0700 | [diff] [blame] | 80 | AidlArgument::Direction direction; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 81 | AidlConstantValue* const_expr; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 82 | AidlEnumerator* enumerator; |
| 83 | std::vector<std::unique_ptr<AidlEnumerator>>* enumerators; |
| 84 | AidlEnumDeclaration* enum_decl; |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 85 | std::vector<std::unique_ptr<AidlConstantValue>>* constant_value_list; |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 86 | std::vector<std::unique_ptr<AidlArgument>>* arg_list; |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 87 | AidlVariableDeclaration* variable; |
| 88 | std::vector<std::unique_ptr<AidlVariableDeclaration>>* variable_list; |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 89 | AidlMethod* method; |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 90 | AidlMember* constant; |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 91 | std::vector<std::unique_ptr<AidlMember>>* interface_members; |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 92 | AidlInterface* interface; |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 93 | AidlParcelable* parcelable; |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 94 | AidlDefinedType* declaration; |
Jiyong Park | d59a10d | 2018-07-18 11:12:55 +0900 | [diff] [blame] | 95 | std::vector<std::unique_ptr<AidlTypeSpecifier>>* type_args; |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 96 | std::vector<std::string>* type_params; |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 97 | std::vector<std::unique_ptr<AidlImport>>* imports; |
| 98 | AidlImport* import; |
Jiyong Park | 8e79b7f | 2020-07-20 20:52:38 +0900 | [diff] [blame] | 99 | std::vector<std::unique_ptr<AidlDefinedType>>* declarations; |
Casey Dahlin | e8c0d7a | 2015-09-11 15:35:07 -0700 | [diff] [blame] | 100 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 101 | |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 102 | %destructor { } <character> |
| 103 | %destructor { } <direction> |
| 104 | %destructor { delete ($$); } <*> |
| 105 | |
Steven Moreland | ed90687 | 2018-07-10 11:36:37 -0700 | [diff] [blame] | 106 | %token<token> ANNOTATION "annotation" |
Steven Moreland | 22c7800 | 2018-07-17 10:27:33 -0700 | [diff] [blame] | 107 | %token<token> C_STR "string literal" |
Steven Moreland | 22c7800 | 2018-07-17 10:27:33 -0700 | [diff] [blame] | 108 | %token<token> IDENTIFIER "identifier" |
| 109 | %token<token> INTERFACE "interface" |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 110 | %token<token> PARCELABLE "parcelable" |
Steven Moreland | 22c7800 | 2018-07-17 10:27:33 -0700 | [diff] [blame] | 111 | %token<token> ONEWAY "oneway" |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 112 | %token<token> ENUM "enum" |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 113 | %token<token> CONST "const" |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 114 | |
| 115 | %token<character> CHARVALUE "char literal" |
Steven Moreland | 1c4ba20 | 2018-08-09 10:49:54 -0700 | [diff] [blame] | 116 | %token<token> FLOATVALUE "float literal" |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 117 | %token<token> HEXVALUE "hex literal" |
| 118 | %token<token> INTVALUE "int literal" |
Casey Dahlin | 59401da | 2015-10-09 18:16:45 -0700 | [diff] [blame] | 119 | |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 120 | %token '(' ')' ',' '=' '[' ']' '.' '{' '}' ';' |
Steven Moreland | 2ca4fcb | 2018-06-27 16:01:01 -0700 | [diff] [blame] | 121 | %token UNKNOWN "unrecognized character" |
Steven Moreland | 602b8ae | 2020-05-05 12:14:48 -0700 | [diff] [blame] | 122 | %token CPP_HEADER "cpp_header (which can also be used as an identifier)" |
Steven Moreland | 22c7800 | 2018-07-17 10:27:33 -0700 | [diff] [blame] | 123 | %token IMPORT "import" |
| 124 | %token IN "in" |
| 125 | %token INOUT "inout" |
Steven Moreland | 22c7800 | 2018-07-17 10:27:33 -0700 | [diff] [blame] | 126 | %token OUT "out" |
| 127 | %token PACKAGE "package" |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 128 | %token TRUE_LITERAL "true" |
| 129 | %token FALSE_LITERAL "false" |
Casey Dahlin | e8c0d7a | 2015-09-11 15:35:07 -0700 | [diff] [blame] | 130 | |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 131 | /* Operator precedence and associativity, as per |
| 132 | * http://en.cppreference.com/w/cpp/language/operator_precedence */ |
| 133 | /* Precedence level 13 - 14, LTR, logical operators*/ |
| 134 | %left LOGICAL_OR |
| 135 | %left LOGICAL_AND |
| 136 | /* Precedence level 10 - 12, LTR, bitwise operators*/ |
| 137 | %left '|' |
| 138 | %left '^' |
| 139 | %left '&' |
| 140 | /* Precedence level 9, LTR */ |
| 141 | %left EQUALITY NEQ |
| 142 | /* Precedence level 8, LTR */ |
| 143 | %left '<' '>' LEQ GEQ |
| 144 | /* Precedence level 7, LTR */ |
| 145 | %left LSHIFT RSHIFT |
| 146 | /* Precedence level 6, LTR */ |
| 147 | %left '+' '-' |
| 148 | /* Precedence level 5, LTR */ |
| 149 | %left '*' '/' '%' |
| 150 | /* Precedence level 3, RTL; but we have to use %left here */ |
| 151 | %right UNARY_PLUS UNARY_MINUS '!' '~' |
| 152 | |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 153 | %type<declaration> decl |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 154 | %type<variable_list> variable_decls |
| 155 | %type<variable> variable_decl |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 156 | %type<type_params> optional_type_params |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 157 | %type<interface_members> interface_members |
| 158 | %type<declaration> unannotated_decl |
| 159 | %type<interface> interface_decl |
| 160 | %type<parcelable> parcelable_decl |
Casey Dahlin | e8c0d7a | 2015-09-11 15:35:07 -0700 | [diff] [blame] | 161 | %type<method> method_decl |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 162 | %type<constant> constant_decl |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 163 | %type<enumerator> enumerator |
| 164 | %type<enumerators> enumerators enum_decl_body |
| 165 | %type<enum_decl> enum_decl |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 166 | %type<param> parameter |
| 167 | %type<param_list> parameter_list |
| 168 | %type<param_list> parameter_non_empty_list |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 169 | %type<annotation> annotation |
| 170 | %type<annotation_list>annotation_list |
Casey Dahlin | e8c0d7a | 2015-09-11 15:35:07 -0700 | [diff] [blame] | 171 | %type<type> type |
Steven Moreland | 3be7577 | 2018-08-20 13:27:43 -0700 | [diff] [blame] | 172 | %type<type> unannotated_type |
Steven Moreland | f4cd271 | 2019-10-29 14:11:10 -0700 | [diff] [blame] | 173 | %type<arg_list> arg_list arg_non_empty_list |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 174 | %type<arg> arg |
Casey Dahlin | fd6fb48 | 2015-09-30 14:48:18 -0700 | [diff] [blame] | 175 | %type<direction> direction |
Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 176 | %type<type_args> type_args |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 177 | %type<type_params> type_params |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 178 | %type<const_expr> const_expr |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 179 | %type<constant_value_list> constant_value_list |
| 180 | %type<constant_value_list> constant_value_non_empty_list |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 181 | %type<imports> imports |
| 182 | %type<import> import |
| 183 | %type<declarations> decls |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 184 | %type<token> identifier error qualified_name |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 185 | |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 186 | %% |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 187 | |
Casey Dahlin | 3c6df36 | 2015-10-06 15:48:35 -0700 | [diff] [blame] | 188 | document |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 189 | : package imports decls |
Jiyong Park | 8e79b7f | 2020-07-20 20:52:38 +0900 | [diff] [blame] | 190 | { ps->SetDocument(std::make_unique<AidlDocument>(loc(@1), *$2, std::move(*$3))); |
Jiyong Park | c2a438f | 2020-06-16 10:57:20 +0900 | [diff] [blame] | 191 | delete $2; |
| 192 | delete $3; |
| 193 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 194 | |
Casey Dahlin | bed1e87 | 2015-10-22 17:03:34 -0700 | [diff] [blame] | 195 | /* A couple of tokens that are keywords elsewhere are identifiers when |
| 196 | * occurring in the identifier position. Therefore identifier is a |
| 197 | * non-terminal, which is either an IDENTIFIER token, or one of the |
| 198 | * aforementioned keyword tokens. |
| 199 | */ |
| 200 | identifier |
| 201 | : IDENTIFIER |
| 202 | { $$ = $1; } |
Casey Dahlin | cd63921 | 2015-12-15 12:51:04 -0800 | [diff] [blame] | 203 | | CPP_HEADER |
| 204 | { $$ = new AidlToken("cpp_header", ""); } |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 205 | ; |
Casey Dahlin | bed1e87 | 2015-10-22 17:03:34 -0700 | [diff] [blame] | 206 | |
Casey Dahlin | 3c6df36 | 2015-10-06 15:48:35 -0700 | [diff] [blame] | 207 | package |
| 208 | : {} |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 209 | | PACKAGE qualified_name ';' |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 210 | { ps->SetPackage($2->GetText()); |
| 211 | delete $2; |
| 212 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 213 | |
Casey Dahlin | 3c6df36 | 2015-10-06 15:48:35 -0700 | [diff] [blame] | 214 | imports |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 215 | : { $$ = new std::vector<std::unique_ptr<AidlImport>>(); } |
| 216 | | imports import |
| 217 | { |
| 218 | $$ = $1; |
| 219 | auto it = std::find_if($$->begin(), $$->end(), [&](const auto& i) { |
| 220 | return $2->GetNeededClass() == i->GetNeededClass(); |
| 221 | }); |
| 222 | if (it == $$->end()) { |
| 223 | $$->emplace_back($2); |
Jiyong Park | ec0303f | 2020-07-05 20:56:48 +0900 | [diff] [blame] | 224 | } else { |
| 225 | delete $2; |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 226 | } |
| 227 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 228 | |
Casey Dahlin | 3c6df36 | 2015-10-06 15:48:35 -0700 | [diff] [blame] | 229 | import |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 230 | : IMPORT qualified_name ';' |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 231 | { |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 232 | $$ = new AidlImport(loc(@2), $2->GetText()); |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 233 | delete $2; |
| 234 | }; |
Casey Dahlin | 3c6df36 | 2015-10-06 15:48:35 -0700 | [diff] [blame] | 235 | |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 236 | qualified_name |
Casey Dahlin | bed1e87 | 2015-10-22 17:03:34 -0700 | [diff] [blame] | 237 | : identifier { |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 238 | $$ = $1; |
Casey Dahlin | 3c6df36 | 2015-10-06 15:48:35 -0700 | [diff] [blame] | 239 | } |
Casey Dahlin | bed1e87 | 2015-10-22 17:03:34 -0700 | [diff] [blame] | 240 | | qualified_name '.' identifier |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 241 | { $$ = new AidlToken($1->GetText() + "." + $3->GetText(), $1->GetComments()); |
| 242 | delete $1; |
Andreas Gampe | 9c25c16 | 2017-04-27 13:30:29 -0700 | [diff] [blame] | 243 | delete $3; |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 244 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 245 | |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 246 | decls |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 247 | : decl |
Jiyong Park | 8e79b7f | 2020-07-20 20:52:38 +0900 | [diff] [blame] | 248 | { $$ = new std::vector<std::unique_ptr<AidlDefinedType>>(); |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 249 | if ($1 != nullptr) { |
| 250 | $$->emplace_back($1); |
| 251 | } |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 252 | } |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 253 | | decls decl |
| 254 | { $$ = $1; |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 255 | if ($2 != nullptr) { |
| 256 | $$->emplace_back($2); |
| 257 | } |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 258 | } |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 259 | |
| 260 | decl |
| 261 | : annotation_list unannotated_decl |
| 262 | { |
| 263 | $$ = $2; |
| 264 | |
Steven Moreland | 7b41272 | 2019-10-25 17:46:02 -0700 | [diff] [blame] | 265 | if ($1->size() > 0 && $$ != nullptr) { |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 266 | // copy comments from annotation to decl |
Steven Moreland | 7b41272 | 2019-10-25 17:46:02 -0700 | [diff] [blame] | 267 | $$->SetComments($1->begin()->GetComments()); |
| 268 | $$->Annotate(std::move(*$1)); |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 269 | } |
| 270 | |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 271 | delete $1; |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 272 | } |
| 273 | ; |
| 274 | |
| 275 | unannotated_decl |
| 276 | : parcelable_decl |
| 277 | { $$ = $1; } |
| 278 | | interface_decl |
| 279 | { $$ = $1; } |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 280 | | enum_decl |
| 281 | { $$ = $1; } |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 282 | ; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 283 | |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 284 | type_params |
| 285 | : identifier { |
| 286 | $$ = new std::vector<std::string>(); |
| 287 | $$->emplace_back($1->GetText()); |
Steven Moreland | d12e313 | 2019-12-17 15:44:37 -0800 | [diff] [blame] | 288 | delete $1; |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 289 | } |
| 290 | | type_params ',' identifier { |
| 291 | $1->emplace_back($3->GetText()); |
| 292 | $$ = $1; |
Steven Moreland | d12e313 | 2019-12-17 15:44:37 -0800 | [diff] [blame] | 293 | delete $3; |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 294 | }; |
| 295 | |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 296 | optional_type_params |
| 297 | : /* none */ { $$ = nullptr; } |
| 298 | | '<' type_params '>' { |
| 299 | $$ = $2; |
| 300 | }; |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 301 | |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 302 | parcelable_decl |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 303 | : PARCELABLE qualified_name optional_type_params ';' { |
| 304 | $$ = new AidlParcelable(loc(@2), $2->GetText(), ps->Package(), $1->GetComments(), "", $3); |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 305 | delete $1; |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 306 | delete $2; |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 307 | } |
| 308 | | PARCELABLE qualified_name optional_type_params '{' variable_decls '}' { |
| 309 | $$ = new AidlStructuredParcelable(loc(@2), $2->GetText(), ps->Package(), $1->GetComments(), $5, $3); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 310 | delete $1; |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 311 | delete $2; |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 312 | delete $5; |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 313 | } |
Casey Dahlin | cd63921 | 2015-12-15 12:51:04 -0800 | [diff] [blame] | 314 | | PARCELABLE qualified_name CPP_HEADER C_STR ';' { |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 315 | $$ = new AidlParcelable(loc(@2), $2->GetText(), ps->Package(), $1->GetComments(), $4->GetText()); |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 316 | delete $1; |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 317 | delete $2; |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 318 | delete $4; |
Casey Dahlin | bed1e87 | 2015-10-22 17:03:34 -0700 | [diff] [blame] | 319 | } |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 320 | | PARCELABLE error ';' { |
Steven Moreland | 2ca4fcb | 2018-06-27 16:01:01 -0700 | [diff] [blame] | 321 | ps->AddError(); |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 322 | $$ = nullptr; |
| 323 | delete $1; |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 324 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 325 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 326 | variable_decls |
| 327 | : /* empty */ { |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 328 | $$ = new std::vector<std::unique_ptr<AidlVariableDeclaration>>; |
| 329 | } |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 330 | | variable_decls variable_decl { |
| 331 | $$ = $1; |
| 332 | if ($2 != nullptr) { |
| 333 | $$->push_back(std::unique_ptr<AidlVariableDeclaration>($2)); |
| 334 | } |
| 335 | }; |
| 336 | |
| 337 | variable_decl |
| 338 | : type identifier ';' { |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 339 | $$ = new AidlVariableDeclaration(loc(@2), $1, $2->GetText()); |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 340 | delete $2; |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 341 | } |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 342 | | type identifier '=' const_expr ';' { |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 343 | // TODO(b/123321528): Support enum type default assignments (TestEnum foo = TestEnum.FOO). |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 344 | $$ = new AidlVariableDeclaration(loc(@2), $1, $2->GetText(), $4); |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 345 | delete $2; |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame] | 346 | } |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 347 | | error ';' { |
| 348 | ps->AddError(); |
| 349 | $$ = nullptr; |
| 350 | } |
| 351 | |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 352 | interface_decl |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 353 | : INTERFACE identifier '{' interface_members '}' { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 354 | $$ = new AidlInterface(loc(@1), $2->GetText(), $1->GetComments(), false, $4, ps->Package()); |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 355 | delete $1; |
| 356 | delete $2; |
| 357 | } |
| 358 | | ONEWAY INTERFACE identifier '{' interface_members '}' { |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 359 | $$ = new AidlInterface(loc(@2), $3->GetText(), $1->GetComments(), true, $5, ps->Package()); |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 360 | delete $1; |
Casey Dahlin | cdbbc8c | 2015-10-14 15:31:04 -0700 | [diff] [blame] | 361 | delete $2; |
| 362 | delete $3; |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 363 | } |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 364 | | INTERFACE error '{' interface_members '}' { |
Steven Moreland | 2ca4fcb | 2018-06-27 16:01:01 -0700 | [diff] [blame] | 365 | ps->AddError(); |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 366 | $$ = nullptr; |
| 367 | delete $1; |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 368 | delete $4; |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 369 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 370 | |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 371 | interface_members |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 372 | : |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 373 | { $$ = new std::vector<std::unique_ptr<AidlMember>>(); } |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 374 | | interface_members method_decl |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 375 | { $1->push_back(std::unique_ptr<AidlMember>($2)); $$ = $1; } |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 376 | | interface_members constant_decl |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 377 | { $1->push_back(std::unique_ptr<AidlMember>($2)); $$ = $1; } |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 378 | | interface_members error ';' { |
Steven Moreland | 2ca4fcb | 2018-06-27 16:01:01 -0700 | [diff] [blame] | 379 | ps->AddError(); |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 380 | $$ = $1; |
| 381 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 382 | |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 383 | const_expr |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 384 | : TRUE_LITERAL { $$ = AidlConstantValue::Boolean(loc(@1), true); } |
| 385 | | FALSE_LITERAL { $$ = AidlConstantValue::Boolean(loc(@1), false); } |
| 386 | | CHARVALUE { $$ = AidlConstantValue::Character(loc(@1), $1); } |
| 387 | | INTVALUE { |
| 388 | $$ = AidlConstantValue::Integral(loc(@1), $1->GetText()); |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 389 | if ($$ == nullptr) { |
| 390 | std::cerr << "ERROR: Could not parse integer: " |
| 391 | << $1->GetText() << " at " << @1 << ".\n"; |
| 392 | ps->AddError(); |
| 393 | $$ = AidlConstantValue::Integral(loc(@1), "0"); |
| 394 | } |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 395 | delete $1; |
| 396 | } |
Steven Moreland | 1c4ba20 | 2018-08-09 10:49:54 -0700 | [diff] [blame] | 397 | | FLOATVALUE { |
| 398 | $$ = AidlConstantValue::Floating(loc(@1), $1->GetText()); |
| 399 | delete $1; |
| 400 | } |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 401 | | HEXVALUE { |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 402 | $$ = AidlConstantValue::Integral(loc(@1), $1->GetText()); |
| 403 | if ($$ == nullptr) { |
| 404 | std::cerr << "ERROR: Could not parse hexvalue: " |
| 405 | << $1->GetText() << " at " << @1 << ".\n"; |
| 406 | ps->AddError(); |
| 407 | $$ = AidlConstantValue::Integral(loc(@1), "0"); |
| 408 | } |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 409 | delete $1; |
| 410 | } |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 411 | | C_STR { |
| 412 | $$ = AidlConstantValue::String(loc(@1), $1->GetText()); |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 413 | delete $1; |
| 414 | } |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 415 | | '{' constant_value_list '}' { |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 416 | $$ = AidlConstantValue::Array(loc(@1), std::unique_ptr<vector<unique_ptr<AidlConstantValue>>>($2)); |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 417 | } |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 418 | | const_expr LOGICAL_OR const_expr { |
| 419 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "||", std::unique_ptr<AidlConstantValue>($3)); |
| 420 | } |
| 421 | | const_expr LOGICAL_AND const_expr { |
| 422 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "&&", std::unique_ptr<AidlConstantValue>($3)); |
| 423 | } |
| 424 | | const_expr '|' const_expr { |
| 425 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "|" , std::unique_ptr<AidlConstantValue>($3)); |
| 426 | } |
| 427 | | const_expr '^' const_expr { |
| 428 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "^" , std::unique_ptr<AidlConstantValue>($3)); |
| 429 | } |
| 430 | | const_expr '&' const_expr { |
| 431 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "&" , std::unique_ptr<AidlConstantValue>($3)); |
| 432 | } |
| 433 | | const_expr EQUALITY const_expr { |
| 434 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "==", std::unique_ptr<AidlConstantValue>($3)); |
| 435 | } |
| 436 | | const_expr NEQ const_expr { |
| 437 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "!=", std::unique_ptr<AidlConstantValue>($3)); |
| 438 | } |
| 439 | | const_expr '<' const_expr { |
| 440 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "<" , std::unique_ptr<AidlConstantValue>($3)); |
| 441 | } |
| 442 | | const_expr '>' const_expr { |
| 443 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), ">" , std::unique_ptr<AidlConstantValue>($3)); |
| 444 | } |
| 445 | | const_expr LEQ const_expr { |
| 446 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "<=", std::unique_ptr<AidlConstantValue>($3)); |
| 447 | } |
| 448 | | const_expr GEQ const_expr { |
| 449 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), ">=", std::unique_ptr<AidlConstantValue>($3)); |
| 450 | } |
| 451 | | const_expr LSHIFT const_expr { |
| 452 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "<<", std::unique_ptr<AidlConstantValue>($3)); |
| 453 | } |
| 454 | | const_expr RSHIFT const_expr { |
| 455 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), ">>", std::unique_ptr<AidlConstantValue>($3)); |
| 456 | } |
| 457 | | const_expr '+' const_expr { |
| 458 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "+" , std::unique_ptr<AidlConstantValue>($3)); |
| 459 | } |
| 460 | | const_expr '-' const_expr { |
| 461 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "-" , std::unique_ptr<AidlConstantValue>($3)); |
| 462 | } |
| 463 | | const_expr '*' const_expr { |
| 464 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "*" , std::unique_ptr<AidlConstantValue>($3)); |
| 465 | } |
| 466 | | const_expr '/' const_expr { |
| 467 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "/" , std::unique_ptr<AidlConstantValue>($3)); |
| 468 | } |
| 469 | | const_expr '%' const_expr { |
| 470 | $$ = new AidlBinaryConstExpression(loc(@1), std::unique_ptr<AidlConstantValue>($1), "%" , std::unique_ptr<AidlConstantValue>($3)); |
| 471 | } |
| 472 | | '+' const_expr %prec UNARY_PLUS { |
| 473 | $$ = new AidlUnaryConstExpression(loc(@1), "+", std::unique_ptr<AidlConstantValue>($2)); |
| 474 | } |
| 475 | | '-' const_expr %prec UNARY_MINUS { |
| 476 | $$ = new AidlUnaryConstExpression(loc(@1), "-", std::unique_ptr<AidlConstantValue>($2)); |
| 477 | } |
| 478 | | '!' const_expr { |
| 479 | $$ = new AidlUnaryConstExpression(loc(@1), "!", std::unique_ptr<AidlConstantValue>($2)); |
| 480 | } |
| 481 | | '~' const_expr { |
| 482 | $$ = new AidlUnaryConstExpression(loc(@1), "~", std::unique_ptr<AidlConstantValue>($2)); |
| 483 | } |
| 484 | | '(' const_expr ')' |
| 485 | { |
| 486 | $$ = $2; |
| 487 | } |
| 488 | | '(' error ')' |
| 489 | { |
Steven Moreland | 33d5656 | 2019-10-28 14:58:01 -0700 | [diff] [blame] | 490 | std::cerr << "ERROR: invalid const expression within parenthesis at " << @1 << ".\n"; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 491 | ps->AddError(); |
Steven Moreland | 33d5656 | 2019-10-28 14:58:01 -0700 | [diff] [blame] | 492 | // to avoid segfaults |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 493 | $$ = AidlConstantValue::Integral(loc(@1), "0"); |
| 494 | } |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 495 | ; |
| 496 | |
| 497 | constant_value_list |
| 498 | : /* empty */ { |
| 499 | $$ = new std::vector<std::unique_ptr<AidlConstantValue>>; |
| 500 | } |
| 501 | | constant_value_non_empty_list { |
| 502 | $$ = $1; |
| 503 | } |
Steven Moreland | f9e922f | 2020-07-08 21:15:27 +0000 | [diff] [blame] | 504 | | constant_value_non_empty_list ',' { |
| 505 | $$ = $1; |
| 506 | } |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 507 | ; |
| 508 | |
| 509 | constant_value_non_empty_list |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 510 | : const_expr { |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 511 | $$ = new std::vector<std::unique_ptr<AidlConstantValue>>; |
| 512 | $$->push_back(std::unique_ptr<AidlConstantValue>($1)); |
| 513 | } |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 514 | | constant_value_non_empty_list ',' const_expr { |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 515 | $$ = $1; |
| 516 | $$->push_back(std::unique_ptr<AidlConstantValue>($3)); |
| 517 | } |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 518 | ; |
| 519 | |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 520 | constant_decl |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 521 | : CONST type identifier '=' const_expr ';' { |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 522 | $2->SetComments($1->GetComments()); |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 523 | $$ = new AidlConstantDeclaration(loc(@3), $2, $3->GetText(), $5); |
Jooyung Han | 7953f55 | 2020-02-01 00:38:57 +0900 | [diff] [blame] | 524 | delete $1; |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 525 | delete $3; |
| 526 | } |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 527 | ; |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 528 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 529 | enumerator |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 530 | : identifier '=' const_expr { |
Daniel Norman | 2e4112d | 2019-10-03 10:22:35 -0700 | [diff] [blame] | 531 | $$ = new AidlEnumerator(loc(@1), $1->GetText(), $3, $1->GetComments()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 532 | delete $1; |
| 533 | } |
Daniel Norman | b28684e | 2019-10-17 15:31:39 -0700 | [diff] [blame] | 534 | | identifier { |
| 535 | $$ = new AidlEnumerator(loc(@1), $1->GetText(), nullptr, $1->GetComments()); |
| 536 | delete $1; |
| 537 | } |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 538 | ; |
| 539 | |
| 540 | enumerators |
| 541 | : enumerator { |
| 542 | $$ = new std::vector<std::unique_ptr<AidlEnumerator>>(); |
| 543 | $$->push_back(std::unique_ptr<AidlEnumerator>($1)); |
| 544 | } |
| 545 | | enumerators ',' enumerator { |
| 546 | $1->push_back(std::unique_ptr<AidlEnumerator>($3)); |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 547 | $$ = $1; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 548 | } |
| 549 | ; |
| 550 | |
| 551 | enum_decl_body |
| 552 | : '{' enumerators '}' { $$ = $2; } |
| 553 | | '{' enumerators ',' '}' { $$ = $2; } |
| 554 | ; |
| 555 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 556 | enum_decl |
| 557 | : ENUM identifier enum_decl_body { |
Daniel Norman | 2e4112d | 2019-10-03 10:22:35 -0700 | [diff] [blame] | 558 | $$ = new AidlEnumDeclaration(loc(@2), $2->GetText(), $3, ps->Package(), $1->GetComments()); |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 559 | delete $1; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 560 | delete $2; |
| 561 | delete $3; |
| 562 | } |
| 563 | ; |
| 564 | |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 565 | method_decl |
Casey Dahlin | bed1e87 | 2015-10-22 17:03:34 -0700 | [diff] [blame] | 566 | : type identifier '(' arg_list ')' ';' { |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 567 | $$ = new AidlMethod(loc(@2), false, $1, $2->GetText(), $4, $1->GetComments()); |
Casey Dahlin | cdbbc8c | 2015-10-14 15:31:04 -0700 | [diff] [blame] | 568 | delete $2; |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 569 | } |
Artur Satayev | 91fe871 | 2019-07-29 13:06:01 +0100 | [diff] [blame] | 570 | | annotation_list ONEWAY type identifier '(' arg_list ')' ';' { |
| 571 | const std::string& comments = ($1->size() > 0) ? $1->begin()->GetComments() : $2->GetComments(); |
| 572 | $$ = new AidlMethod(loc(@4), true, $3, $4->GetText(), $6, comments); |
| 573 | $3->Annotate(std::move(*$1)); |
Casey Dahlin | cdbbc8c | 2015-10-14 15:31:04 -0700 | [diff] [blame] | 574 | delete $1; |
Artur Satayev | 91fe871 | 2019-07-29 13:06:01 +0100 | [diff] [blame] | 575 | delete $2; |
| 576 | delete $4; |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 577 | } |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 578 | | type identifier '(' arg_list ')' '=' INTVALUE ';' { |
Steven Moreland | e7d358a | 2020-01-16 16:52:34 -0800 | [diff] [blame] | 579 | int32_t serial = 0; |
Steven Moreland | f04cd5e | 2019-11-10 20:35:29 -0800 | [diff] [blame] | 580 | if (!android::base::ParseInt($7->GetText(), &serial)) { |
| 581 | AIDL_ERROR(loc(@7)) << "Could not parse int value: " << $7->GetText(); |
| 582 | ps->AddError(); |
| 583 | } |
| 584 | $$ = new AidlMethod(loc(@2), false, $1, $2->GetText(), $4, $1->GetComments(), serial); |
Casey Dahlin | cdbbc8c | 2015-10-14 15:31:04 -0700 | [diff] [blame] | 585 | delete $2; |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 586 | delete $7; |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 587 | } |
Artur Satayev | 91fe871 | 2019-07-29 13:06:01 +0100 | [diff] [blame] | 588 | | annotation_list ONEWAY type identifier '(' arg_list ')' '=' INTVALUE ';' { |
| 589 | const std::string& comments = ($1->size() > 0) ? $1->begin()->GetComments() : $2->GetComments(); |
Steven Moreland | e7d358a | 2020-01-16 16:52:34 -0800 | [diff] [blame] | 590 | int32_t serial = 0; |
Steven Moreland | f04cd5e | 2019-11-10 20:35:29 -0800 | [diff] [blame] | 591 | if (!android::base::ParseInt($9->GetText(), &serial)) { |
| 592 | AIDL_ERROR(loc(@9)) << "Could not parse int value: " << $9->GetText(); |
| 593 | ps->AddError(); |
| 594 | } |
| 595 | $$ = new AidlMethod(loc(@4), true, $3, $4->GetText(), $6, comments, serial); |
Artur Satayev | 91fe871 | 2019-07-29 13:06:01 +0100 | [diff] [blame] | 596 | $3->Annotate(std::move(*$1)); |
Casey Dahlin | cdbbc8c | 2015-10-14 15:31:04 -0700 | [diff] [blame] | 597 | delete $1; |
Artur Satayev | 91fe871 | 2019-07-29 13:06:01 +0100 | [diff] [blame] | 598 | delete $2; |
| 599 | delete $4; |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 600 | delete $9; |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 601 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 602 | |
Steven Moreland | f4cd271 | 2019-10-29 14:11:10 -0700 | [diff] [blame] | 603 | arg_non_empty_list |
| 604 | : arg { |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 605 | $$ = new std::vector<std::unique_ptr<AidlArgument>>(); |
| 606 | $$->push_back(std::unique_ptr<AidlArgument>($1)); |
| 607 | } |
Steven Moreland | f4cd271 | 2019-10-29 14:11:10 -0700 | [diff] [blame] | 608 | | arg_non_empty_list ',' arg { |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 609 | $$ = $1; |
| 610 | $$->push_back(std::unique_ptr<AidlArgument>($3)); |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 611 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 612 | |
Steven Moreland | f4cd271 | 2019-10-29 14:11:10 -0700 | [diff] [blame] | 613 | arg_list |
| 614 | : /*empty*/ |
| 615 | { $$ = new std::vector<std::unique_ptr<AidlArgument>>(); } |
| 616 | | arg_non_empty_list { $$ = $1; } |
| 617 | ; |
| 618 | |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 619 | arg |
Casey Dahlin | bed1e87 | 2015-10-22 17:03:34 -0700 | [diff] [blame] | 620 | : direction type identifier { |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 621 | $$ = new AidlArgument(loc(@3), $1, $2, $3->GetText()); |
Casey Dahlin | cdbbc8c | 2015-10-14 15:31:04 -0700 | [diff] [blame] | 622 | delete $3; |
Steven Moreland | 2ca4fcb | 2018-06-27 16:01:01 -0700 | [diff] [blame] | 623 | } |
Casey Dahlin | bed1e87 | 2015-10-22 17:03:34 -0700 | [diff] [blame] | 624 | | type identifier { |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 625 | $$ = new AidlArgument(loc(@2), $1, $2->GetText()); |
Casey Dahlin | cdbbc8c | 2015-10-14 15:31:04 -0700 | [diff] [blame] | 626 | delete $2; |
Steven Moreland | 2ca4fcb | 2018-06-27 16:01:01 -0700 | [diff] [blame] | 627 | } |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 628 | ; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 629 | |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 630 | unannotated_type |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 631 | : qualified_name { |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 632 | $$ = new AidlTypeSpecifier(loc(@1), $1->GetText(), false, nullptr, $1->GetComments()); |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 633 | ps->DeferResolution($$); |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 634 | delete $1; |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 635 | } |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 636 | | qualified_name '[' ']' { |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 637 | $$ = new AidlTypeSpecifier(loc(@1), $1->GetText(), true, nullptr, $1->GetComments()); |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 638 | ps->DeferResolution($$); |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 639 | delete $1; |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 640 | } |
Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 641 | | qualified_name '<' type_args '>' { |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 642 | $$ = new AidlTypeSpecifier(loc(@1), $1->GetText(), false, $3, $1->GetComments()); |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 643 | ps->DeferResolution($$); |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 644 | delete $1; |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 645 | }; |
| 646 | |
| 647 | type |
| 648 | : annotation_list unannotated_type { |
Casey Dahlin | cb5317d | 2015-12-03 15:43:33 -0800 | [diff] [blame] | 649 | $$ = $2; |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 650 | if ($1->size() > 0) { |
| 651 | // copy comments from annotation to type |
| 652 | $2->SetComments($1->begin()->GetComments()); |
| 653 | } |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 654 | $2->Annotate(std::move(*$1)); |
| 655 | delete $1; |
Casey Dahlin | 0559875 | 2015-10-05 18:18:43 -0700 | [diff] [blame] | 656 | }; |
| 657 | |
Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 658 | type_args |
| 659 | : unannotated_type { |
Jiyong Park | d59a10d | 2018-07-18 11:12:55 +0900 | [diff] [blame] | 660 | $$ = new std::vector<std::unique_ptr<AidlTypeSpecifier>>(); |
Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 661 | $$->emplace_back($1); |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 662 | } |
Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 663 | | type_args ',' unannotated_type { |
| 664 | $1->emplace_back($3); |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 665 | $$ = $1; |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 666 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 667 | |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 668 | annotation_list |
Casey Dahlin | e792293 | 2016-02-29 17:23:01 -0800 | [diff] [blame] | 669 | : |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 670 | { $$ = new std::vector<AidlAnnotation>(); } |
Casey Dahlin | e792293 | 2016-02-29 17:23:01 -0800 | [diff] [blame] | 671 | | annotation_list annotation |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 672 | { |
| 673 | if ($2 != nullptr) { |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 674 | $1->emplace_back(std::move(*$2)); |
Steven Moreland | 3be7577 | 2018-08-20 13:27:43 -0700 | [diff] [blame] | 675 | delete $2; |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 676 | } |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 677 | $$ = $1; |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 678 | }; |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 679 | |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 680 | parameter |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 681 | : identifier '=' const_expr { |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 682 | $$ = new AidlAnnotationParameter{$1->GetText(), std::unique_ptr<AidlConstantValue>($3)}; |
| 683 | delete $1; |
| 684 | }; |
| 685 | |
| 686 | parameter_list |
| 687 | : /*empty*/{ |
| 688 | $$ = new std::map<std::string, std::shared_ptr<AidlConstantValue>>(); |
| 689 | } |
| 690 | | parameter_non_empty_list { |
| 691 | $$ = $1; |
| 692 | }; |
| 693 | |
| 694 | parameter_non_empty_list |
| 695 | : parameter { |
| 696 | $$ = new std::map<std::string, std::shared_ptr<AidlConstantValue>>(); |
| 697 | $$->emplace(std::move($1->name), $1->value.release()); |
| 698 | delete $1; |
| 699 | } |
| 700 | | parameter_non_empty_list ',' parameter { |
| 701 | $$ = $1; |
| 702 | if ($$->find($3->name) != $$->end()) { |
| 703 | AIDL_ERROR(loc(@3)) << "Trying to redefine parameter " << $3->name << "."; |
| 704 | ps->AddError(); |
| 705 | } |
| 706 | $$->emplace(std::move($3->name), std::move($3->value)); |
| 707 | delete $3; |
| 708 | }; |
| 709 | |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 710 | annotation |
Steven Moreland | ed90687 | 2018-07-10 11:36:37 -0700 | [diff] [blame] | 711 | : ANNOTATION |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 712 | { |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 713 | $$ = AidlAnnotation::Parse(loc(@1), $1->GetText(), nullptr); |
Steven Moreland | 83e7803 | 2019-10-25 17:07:20 -0700 | [diff] [blame] | 714 | if ($$) { |
| 715 | $$->SetComments($1->GetComments()); |
| 716 | } else { |
Steven Moreland | ed90687 | 2018-07-10 11:36:37 -0700 | [diff] [blame] | 717 | ps->AddError(); |
Steven Moreland | ed90687 | 2018-07-10 11:36:37 -0700 | [diff] [blame] | 718 | } |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 719 | delete $1; |
Steven Moreland | ed90687 | 2018-07-10 11:36:37 -0700 | [diff] [blame] | 720 | }; |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 721 | | ANNOTATION '(' parameter_list ')' { |
Mathew Inwood | adb7467 | 2019-11-29 14:01:53 +0000 | [diff] [blame] | 722 | $$ = AidlAnnotation::Parse(loc(@1, @4), $1->GetText(), $3); |
Steven Moreland | 83e7803 | 2019-10-25 17:07:20 -0700 | [diff] [blame] | 723 | if ($$) { |
| 724 | $$->SetComments($1->GetComments()); |
| 725 | } else { |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 726 | ps->AddError(); |
| 727 | } |
Steven Moreland | b49a33d | 2019-08-21 11:17:32 -0700 | [diff] [blame] | 728 | delete $1; |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 729 | delete $3; |
| 730 | } |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 731 | |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 732 | direction |
| 733 | : IN |
Casey Dahlin | fd6fb48 | 2015-09-30 14:48:18 -0700 | [diff] [blame] | 734 | { $$ = AidlArgument::IN_DIR; } |
| 735 | | OUT |
| 736 | { $$ = AidlArgument::OUT_DIR; } |
| 737 | | INOUT |
| 738 | { $$ = AidlArgument::INOUT_DIR; }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 739 | |
| 740 | %% |
| 741 | |
| 742 | #include <ctype.h> |
| 743 | #include <stdio.h> |
| 744 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 745 | void yy::parser::error(const yy::parser::location_type& l, const std::string& errstr) { |
Steven Moreland | 92c55f1 | 2018-07-31 14:08:37 -0700 | [diff] [blame] | 746 | AIDL_ERROR(loc(l)) << errstr; |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 747 | // parser will return error value |
Casey Dahlin | fd2e08a | 2015-09-10 18:29:09 -0700 | [diff] [blame] | 748 | } |