blob: f081a87834b4f85cf94d2b8ab8a6f3a226f48bea [file] [log] [blame]
Will McVickerd7d18df2019-09-12 13:40:50 -07001/*
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 Lesinskiffa16862014-01-23 18:17:42 -080017%{
18#include "aidl_language.h"
Jiyong Parke5c45292020-05-26 19:06:24 +090019#include "parser.h"
Dan Willemsen609ba6d2019-12-30 10:44:00 -080020#include "aidl_language_y-module.h"
Steven Moreland46e9da82018-07-27 15:45:29 -070021#include "logging.h"
Steven Morelandf04cd5e2019-11-10 20:35:29 -080022#include <android-base/parseint.h>
Jiyong Park68bc77a2018-07-19 19:00:45 +090023#include <set>
Andrei Onea9445fc62019-06-27 18:11:59 +010024#include <map>
Adam Lesinskiffa16862014-01-23 18:17:42 -080025#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28
Casey Dahline8c0d7a2015-09-11 15:35:07 -070029int yylex(yy::parser::semantic_type *, yy::parser::location_type *, void *);
Adam Lesinskiffa16862014-01-23 18:17:42 -080030
Mathew Inwoodadb74672019-11-29 14:01:53 +000031AidlLocation 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 Mooredf93ebb2020-03-25 14:03:35 -070043 return AidlLocation(*begin.begin.filename, begin_point, end_point, AidlLocation::Source::EXTERNAL);
Mathew Inwoodadb74672019-11-29 14:01:53 +000044}
45
Steven Moreland46e9da82018-07-27 15:45:29 -070046AidlLocation loc(const yy::parser::location_type& l) {
Mathew Inwoodadb74672019-11-29 14:01:53 +000047 return loc(l, l);
Steven Moreland46e9da82018-07-27 15:45:29 -070048}
49
Casey Dahlinfd2e08a2015-09-10 18:29:09 -070050#define lex_scanner ps->Scanner()
Casey Dahlindd691812015-09-09 17:59:06 -070051
Adam Lesinskiffa16862014-01-23 18:17:42 -080052%}
53
Steven Moreland46e9da82018-07-27 15:45:29 -070054%initial-action {
55 @$.begin.filename = @$.end.filename =
56 const_cast<std::string *>(&ps->FileName());
57}
58
Casey Dahline2507492015-09-14 17:11:20 -070059%parse-param { Parser* ps }
Casey Dahlinfd2e08a2015-09-10 18:29:09 -070060%lex-param { void *lex_scanner }
Casey Dahlindd691812015-09-09 17:59:06 -070061
Steven Moreland38a41d12018-07-10 11:01:07 -070062%glr-parser
Casey Dahlinfd2e08a2015-09-10 18:29:09 -070063%skeleton "glr.cc"
Casey Dahlindd691812015-09-09 17:59:06 -070064
Steven Moreland38a41d12018-07-10 11:01:07 -070065%expect-rr 0
66
Dan Willemsen609ba6d2019-12-30 10:44:00 -080067%define parse.error verbose
68%locations
Steven Moreland2ca4fcb2018-06-27 16:01:01 -070069
Casey Dahline8c0d7a2015-09-11 15:35:07 -070070%union {
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070071 AidlToken* token;
Steven Moreland25294322018-08-07 18:13:55 -070072 char character;
Casey Dahlin05598752015-10-05 18:18:43 -070073 std::string *str;
Jiyong Park68bc77a2018-07-19 19:00:45 +090074 AidlAnnotation* annotation;
Andrei Onea9445fc62019-06-27 18:11:59 +010075 AidlAnnotationParameter* param;
76 std::map<std::string, std::shared_ptr<AidlConstantValue>>* param_list;
Jiyong Parka6605ab2018-11-11 14:30:21 +090077 std::vector<AidlAnnotation>* annotation_list;
Jiyong Parkd59a10d2018-07-18 11:12:55 +090078 AidlTypeSpecifier* type;
Casey Dahlinbc7a50a2015-09-28 19:20:50 -070079 AidlArgument* arg;
Casey Dahlinfd6fb482015-09-30 14:48:18 -070080 AidlArgument::Direction direction;
Will McVickerd7d18df2019-09-12 13:40:50 -070081 AidlConstantValue* const_expr;
Daniel Norman85aed542019-08-21 12:01:14 -070082 AidlEnumerator* enumerator;
83 std::vector<std::unique_ptr<AidlEnumerator>>* enumerators;
84 AidlEnumDeclaration* enum_decl;
Steven Moreland860b1942018-08-16 14:59:28 -070085 std::vector<std::unique_ptr<AidlConstantValue>>* constant_value_list;
Casey Dahlinbc7a50a2015-09-28 19:20:50 -070086 std::vector<std::unique_ptr<AidlArgument>>* arg_list;
Steven Moreland5557f1c2018-07-02 13:50:23 -070087 AidlVariableDeclaration* variable;
88 std::vector<std::unique_ptr<AidlVariableDeclaration>>* variable_list;
Casey Dahlin5c69deb2015-10-01 14:44:12 -070089 AidlMethod* method;
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -070090 AidlMember* constant;
Steven Morelandc258abc2018-07-10 14:03:38 -070091 std::vector<std::unique_ptr<AidlMember>>* interface_members;
Steven Morelandc258abc2018-07-10 14:03:38 -070092 AidlInterface* interface;
Casey Dahlinc1f39b42015-11-24 10:34:34 -080093 AidlParcelable* parcelable;
Steven Morelandc258abc2018-07-10 14:03:38 -070094 AidlDefinedType* declaration;
Jiyong Parkd59a10d2018-07-18 11:12:55 +090095 std::vector<std::unique_ptr<AidlTypeSpecifier>>* type_args;
Jeongik Chadf76dc72019-11-28 00:08:47 +090096 std::vector<std::string>* type_params;
Jiyong Park62515512020-06-08 15:57:11 +090097 std::vector<std::unique_ptr<AidlImport>>* imports;
98 AidlImport* import;
Jiyong Park8e79b7f2020-07-20 20:52:38 +090099 std::vector<std::unique_ptr<AidlDefinedType>>* declarations;
Casey Dahline8c0d7a2015-09-11 15:35:07 -0700100}
Adam Lesinskiffa16862014-01-23 18:17:42 -0800101
Steven Morelandb49a33d2019-08-21 11:17:32 -0700102%destructor { } <character>
103%destructor { } <direction>
104%destructor { delete ($$); } <*>
105
Steven Morelanded906872018-07-10 11:36:37 -0700106%token<token> ANNOTATION "annotation"
Steven Moreland22c78002018-07-17 10:27:33 -0700107%token<token> C_STR "string literal"
Steven Moreland22c78002018-07-17 10:27:33 -0700108%token<token> IDENTIFIER "identifier"
109%token<token> INTERFACE "interface"
Jiyong Parka6605ab2018-11-11 14:30:21 +0900110%token<token> PARCELABLE "parcelable"
Steven Moreland22c78002018-07-17 10:27:33 -0700111%token<token> ONEWAY "oneway"
Steven Morelandb49a33d2019-08-21 11:17:32 -0700112%token<token> ENUM "enum"
Jeongik Cha997281d2020-01-16 15:23:59 +0900113%token<token> CONST "const"
Steven Moreland25294322018-08-07 18:13:55 -0700114
115%token<character> CHARVALUE "char literal"
Steven Moreland1c4ba202018-08-09 10:49:54 -0700116%token<token> FLOATVALUE "float literal"
Steven Moreland25294322018-08-07 18:13:55 -0700117%token<token> HEXVALUE "hex literal"
118%token<token> INTVALUE "int literal"
Casey Dahlin59401da2015-10-09 18:16:45 -0700119
Will McVickerd7d18df2019-09-12 13:40:50 -0700120%token '(' ')' ',' '=' '[' ']' '.' '{' '}' ';'
Steven Moreland2ca4fcb2018-06-27 16:01:01 -0700121%token UNKNOWN "unrecognized character"
Steven Moreland602b8ae2020-05-05 12:14:48 -0700122%token CPP_HEADER "cpp_header (which can also be used as an identifier)"
Steven Moreland22c78002018-07-17 10:27:33 -0700123%token IMPORT "import"
124%token IN "in"
125%token INOUT "inout"
Steven Moreland22c78002018-07-17 10:27:33 -0700126%token OUT "out"
127%token PACKAGE "package"
Steven Moreland25294322018-08-07 18:13:55 -0700128%token TRUE_LITERAL "true"
129%token FALSE_LITERAL "false"
Casey Dahline8c0d7a2015-09-11 15:35:07 -0700130
Will McVickerd7d18df2019-09-12 13:40:50 -0700131/* 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 Morelandc258abc2018-07-10 14:03:38 -0700153%type<declaration> decl
Steven Moreland5557f1c2018-07-02 13:50:23 -0700154%type<variable_list> variable_decls
155%type<variable> variable_decl
Devin Moore53fc99c2020-08-12 08:07:52 -0700156%type<type_params> optional_type_params
Steven Morelandc258abc2018-07-10 14:03:38 -0700157%type<interface_members> interface_members
158%type<declaration> unannotated_decl
159%type<interface> interface_decl
160%type<parcelable> parcelable_decl
Casey Dahline8c0d7a2015-09-11 15:35:07 -0700161%type<method> method_decl
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800162%type<constant> constant_decl
Daniel Norman85aed542019-08-21 12:01:14 -0700163%type<enumerator> enumerator
164%type<enumerators> enumerators enum_decl_body
165%type<enum_decl> enum_decl
Andrei Onea9445fc62019-06-27 18:11:59 +0100166%type<param> parameter
167%type<param_list> parameter_list
168%type<param_list> parameter_non_empty_list
Christopher Wileyec31a052016-01-25 07:28:51 -0800169%type<annotation> annotation
170%type<annotation_list>annotation_list
Casey Dahline8c0d7a2015-09-11 15:35:07 -0700171%type<type> type
Steven Moreland3be75772018-08-20 13:27:43 -0700172%type<type> unannotated_type
Steven Morelandf4cd2712019-10-29 14:11:10 -0700173%type<arg_list> arg_list arg_non_empty_list
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700174%type<arg> arg
Casey Dahlinfd6fb482015-09-30 14:48:18 -0700175%type<direction> direction
Jiyong Parkccf00f82018-07-17 01:39:23 +0900176%type<type_args> type_args
Jeongik Chadf76dc72019-11-28 00:08:47 +0900177%type<type_params> type_params
Will McVickerd7d18df2019-09-12 13:40:50 -0700178%type<const_expr> const_expr
Steven Moreland860b1942018-08-16 14:59:28 -0700179%type<constant_value_list> constant_value_list
180%type<constant_value_list> constant_value_non_empty_list
Jiyong Park62515512020-06-08 15:57:11 +0900181%type<imports> imports
182%type<import> import
183%type<declarations> decls
Jiyong Park18132182020-06-08 20:24:40 +0900184%type<token> identifier error qualified_name
Jiyong Park62515512020-06-08 15:57:11 +0900185
Adam Lesinskiffa16862014-01-23 18:17:42 -0800186%%
Jiyong Park62515512020-06-08 15:57:11 +0900187
Casey Dahlin3c6df362015-10-06 15:48:35 -0700188document
Jiyong Park62515512020-06-08 15:57:11 +0900189 : package imports decls
Jiyong Park8e79b7f2020-07-20 20:52:38 +0900190 { ps->SetDocument(std::make_unique<AidlDocument>(loc(@1), *$2, std::move(*$3)));
Jiyong Parkc2a438f2020-06-16 10:57:20 +0900191 delete $2;
192 delete $3;
193 }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800194
Casey Dahlinbed1e872015-10-22 17:03:34 -0700195/* 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 */
200identifier
201 : IDENTIFIER
202 { $$ = $1; }
Casey Dahlincd639212015-12-15 12:51:04 -0800203 | CPP_HEADER
204 { $$ = new AidlToken("cpp_header", ""); }
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700205 ;
Casey Dahlinbed1e872015-10-22 17:03:34 -0700206
Casey Dahlin3c6df362015-10-06 15:48:35 -0700207package
208 : {}
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700209 | PACKAGE qualified_name ';'
Jiyong Park18132182020-06-08 20:24:40 +0900210 { ps->SetPackage($2->GetText());
211 delete $2;
212 }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800213
Casey Dahlin3c6df362015-10-06 15:48:35 -0700214imports
Jiyong Park62515512020-06-08 15:57:11 +0900215 : { $$ = 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 Parkec0303f2020-07-05 20:56:48 +0900224 } else {
225 delete $2;
Jiyong Park62515512020-06-08 15:57:11 +0900226 }
227 }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800228
Casey Dahlin3c6df362015-10-06 15:48:35 -0700229import
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700230 : IMPORT qualified_name ';'
Jiyong Park62515512020-06-08 15:57:11 +0900231 {
Jiyong Park18132182020-06-08 20:24:40 +0900232 $$ = new AidlImport(loc(@2), $2->GetText());
Steven Moreland46e9da82018-07-27 15:45:29 -0700233 delete $2;
234 };
Casey Dahlin3c6df362015-10-06 15:48:35 -0700235
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700236qualified_name
Casey Dahlinbed1e872015-10-22 17:03:34 -0700237 : identifier {
Jiyong Park18132182020-06-08 20:24:40 +0900238 $$ = $1;
Casey Dahlin3c6df362015-10-06 15:48:35 -0700239 }
Casey Dahlinbed1e872015-10-22 17:03:34 -0700240 | qualified_name '.' identifier
Jiyong Park18132182020-06-08 20:24:40 +0900241 { $$ = new AidlToken($1->GetText() + "." + $3->GetText(), $1->GetComments());
242 delete $1;
Andreas Gampe9c25c162017-04-27 13:30:29 -0700243 delete $3;
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700244 };
Adam Lesinskiffa16862014-01-23 18:17:42 -0800245
Steven Morelandc258abc2018-07-10 14:03:38 -0700246decls
Jiyong Park62515512020-06-08 15:57:11 +0900247 : decl
Jiyong Park8e79b7f2020-07-20 20:52:38 +0900248 { $$ = new std::vector<std::unique_ptr<AidlDefinedType>>();
Jiyong Park18132182020-06-08 20:24:40 +0900249 if ($1 != nullptr) {
250 $$->emplace_back($1);
251 }
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700252 }
Jiyong Park62515512020-06-08 15:57:11 +0900253 | decls decl
254 { $$ = $1;
Jiyong Park18132182020-06-08 20:24:40 +0900255 if ($2 != nullptr) {
256 $$->emplace_back($2);
257 }
Jiyong Park62515512020-06-08 15:57:11 +0900258 }
Steven Morelandc258abc2018-07-10 14:03:38 -0700259
260decl
261 : annotation_list unannotated_decl
262 {
263 $$ = $2;
264
Steven Moreland7b412722019-10-25 17:46:02 -0700265 if ($1->size() > 0 && $$ != nullptr) {
Jiyong Parka6605ab2018-11-11 14:30:21 +0900266 // copy comments from annotation to decl
Steven Moreland7b412722019-10-25 17:46:02 -0700267 $$->SetComments($1->begin()->GetComments());
268 $$->Annotate(std::move(*$1));
Jiyong Parka6605ab2018-11-11 14:30:21 +0900269 }
270
Jiyong Park68bc77a2018-07-19 19:00:45 +0900271 delete $1;
Steven Morelandc258abc2018-07-10 14:03:38 -0700272 }
273 ;
274
275unannotated_decl
276 : parcelable_decl
277 { $$ = $1; }
278 | interface_decl
279 { $$ = $1; }
Daniel Norman85aed542019-08-21 12:01:14 -0700280 | enum_decl
281 { $$ = $1; }
Steven Morelandc258abc2018-07-10 14:03:38 -0700282 ;
Adam Lesinskiffa16862014-01-23 18:17:42 -0800283
Jeongik Chadf76dc72019-11-28 00:08:47 +0900284type_params
285 : identifier {
286 $$ = new std::vector<std::string>();
287 $$->emplace_back($1->GetText());
Steven Morelandd12e3132019-12-17 15:44:37 -0800288 delete $1;
Jeongik Chadf76dc72019-11-28 00:08:47 +0900289 }
290 | type_params ',' identifier {
291 $1->emplace_back($3->GetText());
292 $$ = $1;
Steven Morelandd12e3132019-12-17 15:44:37 -0800293 delete $3;
Jeongik Chadf76dc72019-11-28 00:08:47 +0900294 };
295
Devin Moore53fc99c2020-08-12 08:07:52 -0700296 optional_type_params
297 : /* none */ { $$ = nullptr; }
298 | '<' type_params '>' {
299 $$ = $2;
300 };
Jeongik Chadf76dc72019-11-28 00:08:47 +0900301
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700302parcelable_decl
Devin Moore53fc99c2020-08-12 08:07:52 -0700303 : PARCELABLE qualified_name optional_type_params ';' {
304 $$ = new AidlParcelable(loc(@2), $2->GetText(), ps->Package(), $1->GetComments(), "", $3);
Steven Morelandb49a33d2019-08-21 11:17:32 -0700305 delete $1;
Jiyong Park18132182020-06-08 20:24:40 +0900306 delete $2;
Devin Moore53fc99c2020-08-12 08:07:52 -0700307 }
308 | PARCELABLE qualified_name optional_type_params '{' variable_decls '}' {
309 $$ = new AidlStructuredParcelable(loc(@2), $2->GetText(), ps->Package(), $1->GetComments(), $5, $3);
Jeongik Chadf76dc72019-11-28 00:08:47 +0900310 delete $1;
Jiyong Park18132182020-06-08 20:24:40 +0900311 delete $2;
Devin Moore53fc99c2020-08-12 08:07:52 -0700312 delete $5;
Jeongik Chadf76dc72019-11-28 00:08:47 +0900313 }
Casey Dahlincd639212015-12-15 12:51:04 -0800314 | PARCELABLE qualified_name CPP_HEADER C_STR ';' {
Jiyong Park18132182020-06-08 20:24:40 +0900315 $$ = new AidlParcelable(loc(@2), $2->GetText(), ps->Package(), $1->GetComments(), $4->GetText());
Steven Morelandb49a33d2019-08-21 11:17:32 -0700316 delete $1;
Jiyong Park18132182020-06-08 20:24:40 +0900317 delete $2;
Steven Morelandb49a33d2019-08-21 11:17:32 -0700318 delete $4;
Casey Dahlinbed1e872015-10-22 17:03:34 -0700319 }
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700320 | PARCELABLE error ';' {
Steven Moreland2ca4fcb2018-06-27 16:01:01 -0700321 ps->AddError();
Steven Morelandb49a33d2019-08-21 11:17:32 -0700322 $$ = nullptr;
323 delete $1;
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700324 };
Adam Lesinskiffa16862014-01-23 18:17:42 -0800325
Steven Moreland5557f1c2018-07-02 13:50:23 -0700326variable_decls
327 : /* empty */ {
Steven Moreland860b1942018-08-16 14:59:28 -0700328 $$ = new std::vector<std::unique_ptr<AidlVariableDeclaration>>;
329 }
Steven Moreland5557f1c2018-07-02 13:50:23 -0700330 | variable_decls variable_decl {
331 $$ = $1;
332 if ($2 != nullptr) {
333 $$->push_back(std::unique_ptr<AidlVariableDeclaration>($2));
334 }
335 };
336
337variable_decl
338 : type identifier ';' {
Steven Moreland46e9da82018-07-27 15:45:29 -0700339 $$ = new AidlVariableDeclaration(loc(@2), $1, $2->GetText());
Steven Morelandb49a33d2019-08-21 11:17:32 -0700340 delete $2;
Steven Moreland5557f1c2018-07-02 13:50:23 -0700341 }
Will McVickerd7d18df2019-09-12 13:40:50 -0700342 | type identifier '=' const_expr ';' {
Daniel Norman85aed542019-08-21 12:01:14 -0700343 // TODO(b/123321528): Support enum type default assignments (TestEnum foo = TestEnum.FOO).
Steven Moreland46e9da82018-07-27 15:45:29 -0700344 $$ = new AidlVariableDeclaration(loc(@2), $1, $2->GetText(), $4);
Steven Morelandb49a33d2019-08-21 11:17:32 -0700345 delete $2;
Steven Moreland9ea10e32018-07-19 15:26:09 -0700346 }
Steven Moreland5557f1c2018-07-02 13:50:23 -0700347 | error ';' {
348 ps->AddError();
349 $$ = nullptr;
350 }
351
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700352interface_decl
Steven Morelandc258abc2018-07-10 14:03:38 -0700353 : INTERFACE identifier '{' interface_members '}' {
Jiyong Parkb034bf02018-07-30 17:44:33 +0900354 $$ = new AidlInterface(loc(@1), $2->GetText(), $1->GetComments(), false, $4, ps->Package());
Steven Morelandc258abc2018-07-10 14:03:38 -0700355 delete $1;
356 delete $2;
357 }
358 | ONEWAY INTERFACE identifier '{' interface_members '}' {
Steven Moreland46e9da82018-07-27 15:45:29 -0700359 $$ = new AidlInterface(loc(@2), $3->GetText(), $1->GetComments(), true, $5, ps->Package());
Steven Morelandc258abc2018-07-10 14:03:38 -0700360 delete $1;
Casey Dahlincdbbc8c2015-10-14 15:31:04 -0700361 delete $2;
362 delete $3;
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700363 }
Steven Morelandc258abc2018-07-10 14:03:38 -0700364 | INTERFACE error '{' interface_members '}' {
Steven Moreland2ca4fcb2018-06-27 16:01:01 -0700365 ps->AddError();
Steven Morelandc258abc2018-07-10 14:03:38 -0700366 $$ = nullptr;
367 delete $1;
Steven Morelandc258abc2018-07-10 14:03:38 -0700368 delete $4;
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700369 };
Adam Lesinskiffa16862014-01-23 18:17:42 -0800370
Steven Morelandc258abc2018-07-10 14:03:38 -0700371interface_members
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700372 :
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800373 { $$ = new std::vector<std::unique_ptr<AidlMember>>(); }
Steven Morelandc258abc2018-07-10 14:03:38 -0700374 | interface_members method_decl
Steven Morelandb49a33d2019-08-21 11:17:32 -0700375 { $1->push_back(std::unique_ptr<AidlMember>($2)); $$ = $1; }
Steven Morelandc258abc2018-07-10 14:03:38 -0700376 | interface_members constant_decl
Steven Morelandb49a33d2019-08-21 11:17:32 -0700377 { $1->push_back(std::unique_ptr<AidlMember>($2)); $$ = $1; }
Steven Morelandc258abc2018-07-10 14:03:38 -0700378 | interface_members error ';' {
Steven Moreland2ca4fcb2018-06-27 16:01:01 -0700379 ps->AddError();
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700380 $$ = $1;
381 };
Adam Lesinskiffa16862014-01-23 18:17:42 -0800382
Will McVickerd7d18df2019-09-12 13:40:50 -0700383const_expr
Steven Moreland25294322018-08-07 18:13:55 -0700384 : 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 McVickerd7d18df2019-09-12 13:40:50 -0700389 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 Moreland25294322018-08-07 18:13:55 -0700395 delete $1;
396 }
Steven Moreland1c4ba202018-08-09 10:49:54 -0700397 | FLOATVALUE {
398 $$ = AidlConstantValue::Floating(loc(@1), $1->GetText());
399 delete $1;
400 }
Steven Moreland693640b2018-07-19 13:46:27 -0700401 | HEXVALUE {
Will McVickerd7d18df2019-09-12 13:40:50 -0700402 $$ = 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 Moreland693640b2018-07-19 13:46:27 -0700409 delete $1;
410 }
Will McVickerd7d18df2019-09-12 13:40:50 -0700411 | C_STR {
412 $$ = AidlConstantValue::String(loc(@1), $1->GetText());
Steven Moreland693640b2018-07-19 13:46:27 -0700413 delete $1;
414 }
Steven Moreland860b1942018-08-16 14:59:28 -0700415 | '{' constant_value_list '}' {
Will McVickerd7d18df2019-09-12 13:40:50 -0700416 $$ = AidlConstantValue::Array(loc(@1), std::unique_ptr<vector<unique_ptr<AidlConstantValue>>>($2));
Steven Moreland860b1942018-08-16 14:59:28 -0700417 }
Will McVickerd7d18df2019-09-12 13:40:50 -0700418 | 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 Moreland33d56562019-10-28 14:58:01 -0700490 std::cerr << "ERROR: invalid const expression within parenthesis at " << @1 << ".\n";
Will McVickerd7d18df2019-09-12 13:40:50 -0700491 ps->AddError();
Steven Moreland33d56562019-10-28 14:58:01 -0700492 // to avoid segfaults
Will McVickerd7d18df2019-09-12 13:40:50 -0700493 $$ = AidlConstantValue::Integral(loc(@1), "0");
494 }
Steven Moreland860b1942018-08-16 14:59:28 -0700495 ;
496
497constant_value_list
498 : /* empty */ {
499 $$ = new std::vector<std::unique_ptr<AidlConstantValue>>;
500 }
501 | constant_value_non_empty_list {
502 $$ = $1;
503 }
Steven Morelandf9e922f2020-07-08 21:15:27 +0000504 | constant_value_non_empty_list ',' {
505 $$ = $1;
506 }
Steven Moreland860b1942018-08-16 14:59:28 -0700507 ;
508
509constant_value_non_empty_list
Will McVickerd7d18df2019-09-12 13:40:50 -0700510 : const_expr {
Steven Moreland860b1942018-08-16 14:59:28 -0700511 $$ = new std::vector<std::unique_ptr<AidlConstantValue>>;
512 $$->push_back(std::unique_ptr<AidlConstantValue>($1));
513 }
Will McVickerd7d18df2019-09-12 13:40:50 -0700514 | constant_value_non_empty_list ',' const_expr {
Steven Moreland860b1942018-08-16 14:59:28 -0700515 $$ = $1;
516 $$->push_back(std::unique_ptr<AidlConstantValue>($3));
517 }
Steven Moreland693640b2018-07-19 13:46:27 -0700518 ;
519
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800520constant_decl
Will McVickerd7d18df2019-09-12 13:40:50 -0700521 : CONST type identifier '=' const_expr ';' {
Jeongik Cha997281d2020-01-16 15:23:59 +0900522 $2->SetComments($1->GetComments());
Steven Moreland46e9da82018-07-27 15:45:29 -0700523 $$ = new AidlConstantDeclaration(loc(@3), $2, $3->GetText(), $5);
Jooyung Han7953f552020-02-01 00:38:57 +0900524 delete $1;
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700525 delete $3;
526 }
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700527 ;
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800528
Daniel Norman85aed542019-08-21 12:01:14 -0700529enumerator
Will McVickerd7d18df2019-09-12 13:40:50 -0700530 : identifier '=' const_expr {
Daniel Norman2e4112d2019-10-03 10:22:35 -0700531 $$ = new AidlEnumerator(loc(@1), $1->GetText(), $3, $1->GetComments());
Daniel Norman85aed542019-08-21 12:01:14 -0700532 delete $1;
533 }
Daniel Normanb28684e2019-10-17 15:31:39 -0700534 | identifier {
535 $$ = new AidlEnumerator(loc(@1), $1->GetText(), nullptr, $1->GetComments());
536 delete $1;
537 }
Daniel Norman85aed542019-08-21 12:01:14 -0700538 ;
539
540enumerators
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 Morelandb49a33d2019-08-21 11:17:32 -0700547 $$ = $1;
Daniel Norman85aed542019-08-21 12:01:14 -0700548 }
549 ;
550
551enum_decl_body
552 : '{' enumerators '}' { $$ = $2; }
553 | '{' enumerators ',' '}' { $$ = $2; }
554 ;
555
Daniel Norman85aed542019-08-21 12:01:14 -0700556enum_decl
557 : ENUM identifier enum_decl_body {
Daniel Norman2e4112d2019-10-03 10:22:35 -0700558 $$ = new AidlEnumDeclaration(loc(@2), $2->GetText(), $3, ps->Package(), $1->GetComments());
Steven Morelandb49a33d2019-08-21 11:17:32 -0700559 delete $1;
Daniel Norman85aed542019-08-21 12:01:14 -0700560 delete $2;
561 delete $3;
562 }
563 ;
564
Casey Dahlinf4a93112015-10-05 16:58:09 -0700565method_decl
Casey Dahlinbed1e872015-10-22 17:03:34 -0700566 : type identifier '(' arg_list ')' ';' {
Steven Moreland46e9da82018-07-27 15:45:29 -0700567 $$ = new AidlMethod(loc(@2), false, $1, $2->GetText(), $4, $1->GetComments());
Casey Dahlincdbbc8c2015-10-14 15:31:04 -0700568 delete $2;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700569 }
Artur Satayev91fe8712019-07-29 13:06:01 +0100570 | 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 Dahlincdbbc8c2015-10-14 15:31:04 -0700574 delete $1;
Artur Satayev91fe8712019-07-29 13:06:01 +0100575 delete $2;
576 delete $4;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700577 }
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800578 | type identifier '(' arg_list ')' '=' INTVALUE ';' {
Steven Morelande7d358a2020-01-16 16:52:34 -0800579 int32_t serial = 0;
Steven Morelandf04cd5e2019-11-10 20:35:29 -0800580 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 Dahlincdbbc8c2015-10-14 15:31:04 -0700585 delete $2;
Steven Morelandb49a33d2019-08-21 11:17:32 -0700586 delete $7;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700587 }
Artur Satayev91fe8712019-07-29 13:06:01 +0100588 | annotation_list ONEWAY type identifier '(' arg_list ')' '=' INTVALUE ';' {
589 const std::string& comments = ($1->size() > 0) ? $1->begin()->GetComments() : $2->GetComments();
Steven Morelande7d358a2020-01-16 16:52:34 -0800590 int32_t serial = 0;
Steven Morelandf04cd5e2019-11-10 20:35:29 -0800591 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 Satayev91fe8712019-07-29 13:06:01 +0100596 $3->Annotate(std::move(*$1));
Casey Dahlincdbbc8c2015-10-14 15:31:04 -0700597 delete $1;
Artur Satayev91fe8712019-07-29 13:06:01 +0100598 delete $2;
599 delete $4;
Steven Morelandb49a33d2019-08-21 11:17:32 -0700600 delete $9;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700601 };
Adam Lesinskiffa16862014-01-23 18:17:42 -0800602
Steven Morelandf4cd2712019-10-29 14:11:10 -0700603arg_non_empty_list
604 : arg {
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700605 $$ = new std::vector<std::unique_ptr<AidlArgument>>();
606 $$->push_back(std::unique_ptr<AidlArgument>($1));
607 }
Steven Morelandf4cd2712019-10-29 14:11:10 -0700608 | arg_non_empty_list ',' arg {
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700609 $$ = $1;
610 $$->push_back(std::unique_ptr<AidlArgument>($3));
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700611 };
Adam Lesinskiffa16862014-01-23 18:17:42 -0800612
Steven Morelandf4cd2712019-10-29 14:11:10 -0700613arg_list
614 : /*empty*/
615 { $$ = new std::vector<std::unique_ptr<AidlArgument>>(); }
616 | arg_non_empty_list { $$ = $1; }
617 ;
618
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700619arg
Casey Dahlinbed1e872015-10-22 17:03:34 -0700620 : direction type identifier {
Steven Moreland46e9da82018-07-27 15:45:29 -0700621 $$ = new AidlArgument(loc(@3), $1, $2, $3->GetText());
Casey Dahlincdbbc8c2015-10-14 15:31:04 -0700622 delete $3;
Steven Moreland2ca4fcb2018-06-27 16:01:01 -0700623 }
Casey Dahlinbed1e872015-10-22 17:03:34 -0700624 | type identifier {
Steven Moreland46e9da82018-07-27 15:45:29 -0700625 $$ = new AidlArgument(loc(@2), $1, $2->GetText());
Casey Dahlincdbbc8c2015-10-14 15:31:04 -0700626 delete $2;
Steven Moreland2ca4fcb2018-06-27 16:01:01 -0700627 }
Steven Morelandb49a33d2019-08-21 11:17:32 -0700628 ;
Adam Lesinskiffa16862014-01-23 18:17:42 -0800629
Christopher Wileyec31a052016-01-25 07:28:51 -0800630unannotated_type
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700631 : qualified_name {
Jiyong Park18132182020-06-08 20:24:40 +0900632 $$ = new AidlTypeSpecifier(loc(@1), $1->GetText(), false, nullptr, $1->GetComments());
Jiyong Park1deecc32018-07-17 01:14:41 +0900633 ps->DeferResolution($$);
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700634 delete $1;
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700635 }
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700636 | qualified_name '[' ']' {
Jiyong Park18132182020-06-08 20:24:40 +0900637 $$ = new AidlTypeSpecifier(loc(@1), $1->GetText(), true, nullptr, $1->GetComments());
Jiyong Park1deecc32018-07-17 01:14:41 +0900638 ps->DeferResolution($$);
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700639 delete $1;
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700640 }
Jiyong Parkccf00f82018-07-17 01:39:23 +0900641 | qualified_name '<' type_args '>' {
Jiyong Park18132182020-06-08 20:24:40 +0900642 $$ = new AidlTypeSpecifier(loc(@1), $1->GetText(), false, $3, $1->GetComments());
Jiyong Park1deecc32018-07-17 01:14:41 +0900643 ps->DeferResolution($$);
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700644 delete $1;
Christopher Wileyec31a052016-01-25 07:28:51 -0800645 };
646
647type
648 : annotation_list unannotated_type {
Casey Dahlincb5317d2015-12-03 15:43:33 -0800649 $$ = $2;
Jiyong Parka6605ab2018-11-11 14:30:21 +0900650 if ($1->size() > 0) {
651 // copy comments from annotation to type
652 $2->SetComments($1->begin()->GetComments());
653 }
Jiyong Park68bc77a2018-07-19 19:00:45 +0900654 $2->Annotate(std::move(*$1));
655 delete $1;
Casey Dahlin05598752015-10-05 18:18:43 -0700656 };
657
Jiyong Parkccf00f82018-07-17 01:39:23 +0900658type_args
659 : unannotated_type {
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900660 $$ = new std::vector<std::unique_ptr<AidlTypeSpecifier>>();
Jiyong Parkccf00f82018-07-17 01:39:23 +0900661 $$->emplace_back($1);
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700662 }
Jiyong Parkccf00f82018-07-17 01:39:23 +0900663 | type_args ',' unannotated_type {
664 $1->emplace_back($3);
Steven Morelandb49a33d2019-08-21 11:17:32 -0700665 $$ = $1;
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700666 };
Adam Lesinskiffa16862014-01-23 18:17:42 -0800667
Christopher Wileyec31a052016-01-25 07:28:51 -0800668annotation_list
Casey Dahline7922932016-02-29 17:23:01 -0800669 :
Jiyong Parka6605ab2018-11-11 14:30:21 +0900670 { $$ = new std::vector<AidlAnnotation>(); }
Casey Dahline7922932016-02-29 17:23:01 -0800671 | annotation_list annotation
Jiyong Park68bc77a2018-07-19 19:00:45 +0900672 {
673 if ($2 != nullptr) {
Jiyong Parka6605ab2018-11-11 14:30:21 +0900674 $1->emplace_back(std::move(*$2));
Steven Moreland3be75772018-08-20 13:27:43 -0700675 delete $2;
Jiyong Park68bc77a2018-07-19 19:00:45 +0900676 }
Steven Morelandb49a33d2019-08-21 11:17:32 -0700677 $$ = $1;
Jiyong Park68bc77a2018-07-19 19:00:45 +0900678 };
Christopher Wileyec31a052016-01-25 07:28:51 -0800679
Andrei Onea9445fc62019-06-27 18:11:59 +0100680parameter
Will McVickerd7d18df2019-09-12 13:40:50 -0700681 : identifier '=' const_expr {
Andrei Onea9445fc62019-06-27 18:11:59 +0100682 $$ = new AidlAnnotationParameter{$1->GetText(), std::unique_ptr<AidlConstantValue>($3)};
683 delete $1;
684 };
685
686parameter_list
687 : /*empty*/{
688 $$ = new std::map<std::string, std::shared_ptr<AidlConstantValue>>();
689 }
690 | parameter_non_empty_list {
691 $$ = $1;
692 };
693
694parameter_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 Wileyec31a052016-01-25 07:28:51 -0800710annotation
Steven Morelanded906872018-07-10 11:36:37 -0700711 : ANNOTATION
Jiyong Park68bc77a2018-07-19 19:00:45 +0900712 {
Andrei Onea9445fc62019-06-27 18:11:59 +0100713 $$ = AidlAnnotation::Parse(loc(@1), $1->GetText(), nullptr);
Steven Moreland83e78032019-10-25 17:07:20 -0700714 if ($$) {
715 $$->SetComments($1->GetComments());
716 } else {
Steven Morelanded906872018-07-10 11:36:37 -0700717 ps->AddError();
Steven Morelanded906872018-07-10 11:36:37 -0700718 }
Steven Morelandb49a33d2019-08-21 11:17:32 -0700719 delete $1;
Steven Morelanded906872018-07-10 11:36:37 -0700720 };
Andrei Onea9445fc62019-06-27 18:11:59 +0100721 | ANNOTATION '(' parameter_list ')' {
Mathew Inwoodadb74672019-11-29 14:01:53 +0000722 $$ = AidlAnnotation::Parse(loc(@1, @4), $1->GetText(), $3);
Steven Moreland83e78032019-10-25 17:07:20 -0700723 if ($$) {
724 $$->SetComments($1->GetComments());
725 } else {
Andrei Onea9445fc62019-06-27 18:11:59 +0100726 ps->AddError();
727 }
Steven Morelandb49a33d2019-08-21 11:17:32 -0700728 delete $1;
Andrei Onea9445fc62019-06-27 18:11:59 +0100729 delete $3;
730 }
Christopher Wileyec31a052016-01-25 07:28:51 -0800731
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700732direction
733 : IN
Casey Dahlinfd6fb482015-09-30 14:48:18 -0700734 { $$ = AidlArgument::IN_DIR; }
735 | OUT
736 { $$ = AidlArgument::OUT_DIR; }
737 | INOUT
738 { $$ = AidlArgument::INOUT_DIR; };
Adam Lesinskiffa16862014-01-23 18:17:42 -0800739
740%%
741
742#include <ctype.h>
743#include <stdio.h>
744
Steven Moreland46e9da82018-07-27 15:45:29 -0700745void yy::parser::error(const yy::parser::location_type& l, const std::string& errstr) {
Steven Moreland92c55f12018-07-31 14:08:37 -0700746 AIDL_ERROR(loc(l)) << errstr;
Steven Moreland46e9da82018-07-27 15:45:29 -0700747 // parser will return error value
Casey Dahlinfd2e08a2015-09-10 18:29:09 -0700748}