Fix array size orders.
Note that the following code in HIDL:
typedef int32_t[3] ThreeInts;
struct T {
ThreeInts[5] matrix5x3;
int32_t[3][5] matrix3x5;
}
will generate this C++ code:
struct T {
hidl_array<int32_t, 5, 3> matrix5x3; // notice 3 is after 5
hidl_array<int32_t, 3, 5> matrix3x5;
}
and this Java code:
public final static class T {
public final int[][] matrix5x3 = new int[5][3];
public final int[][] matrix3x5 = new int[3][5];
}
Bug: 31438033
Test: hidl_test
Test: hidl_test_java
Change-Id: I3ac91c461293848e6efb3ae8c11a6a8d932ed79a
diff --git a/hidl-gen_y.yy b/hidl-gen_y.yy
index 8937da4..f5c9406 100644
--- a/hidl-gen_y.yy
+++ b/hidl-gen_y.yy
@@ -112,6 +112,8 @@
%type<type> fqtype
%type<type> type opt_storage_type
+%type<type> array_type_base
+%type<arrayType> array_type
%type<type> opt_extends
%type<type> type_declaration_body interface_declaration typedef_declaration
%type<type> named_struct_or_union_declaration named_enum_declaration
@@ -138,6 +140,7 @@
%union {
const char *str;
android::Type *type;
+ android::ArrayType *arrayType;
android::TemplatedType *templatedType;
android::FQName *fqName;
android::CompoundType *compoundType;
@@ -668,23 +671,8 @@
}
;
-type
+array_type_base
: fqtype { $$ = $1; }
- | type '[' const_expr ']'
- {
- if ($1->isBinder()) {
- std::cerr << "ERROR: Arrays of interface types are not supported."
- << " at " << @1 << "\n";
-
- YYERROR;
- }
-
- if ($1->isArray()) {
- $$ = new ArrayType(static_cast<ArrayType *>($1), $3);
- } else {
- $$ = new ArrayType($1, $3);
- }
- }
| TEMPLATED '<' type '>'
{
if (!$1->isVector() && $3->isBinder()) {
@@ -708,6 +696,33 @@
$1->setElementType($3);
$$ = $1;
}
+ ;
+
+array_type
+ : array_type_base '[' const_expr ']'
+ {
+ if ($1->isBinder()) {
+ std::cerr << "ERROR: Arrays of interface types are not supported."
+ << " at " << @1 << "\n";
+
+ YYERROR;
+ }
+ if ($1->isArray()) {
+ $$ = new ArrayType(static_cast<ArrayType *>($1), $3);
+ } else {
+ $$ = new ArrayType($1, $3);
+ }
+ }
+ | array_type '[' const_expr ']'
+ {
+ $$ = $1;
+ $$->appendDimension($3);
+ }
+ ;
+
+type
+ : array_type_base { $$ = $1; }
+ | array_type { $$ = $1; }
| annotated_compound_declaration { $$ = $1; }
| INTERFACE { $$ = new GenericBinder; }
;