union: java backend
union is a parcelable which can hold only a single field with a tag.
Example:
union Union {
int n;
String s;
}
In Java, you can instantiate it with
- default constructor: init with first field
- value constructor: Union.n(42) or Union.s("abc")
You can query "tag" before getting the contents from it.
It also supports getter/setter.
Example:
void foo(Union u) {
if (u.getTag() == Union.n) { // query
int n = u.getN(); // getter
...
}
u.setS("abc"); // setter
}
Bug: 150948558
Test: atest aidl_integration_test
Change-Id: I5c2d87e09462c0d3c6617d73fdf0e49c281d551e
diff --git a/aidl_language_l.ll b/aidl_language_l.ll
index 7646f3f..a41b96a 100644
--- a/aidl_language_l.ll
+++ b/aidl_language_l.ll
@@ -124,6 +124,9 @@
enum { yylval->token = new AidlToken("enum", extra_text);
return yy::parser::token::ENUM;
}
+union { yylval->token = new AidlToken("union", extra_text);
+ return yy::parser::token::UNION;
+ }
/* scalars */
{identifier} { yylval->token = new AidlToken(yytext, extra_text);