blob: 3d34a9fafa956a4eab56969292c3159a3f09ab3c [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -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
Andreas Huberc9410c72016-07-28 12:18:40 -070017#include "ArrayType.h"
18
Iliyan Malcheva72e0d22016-09-09 11:03:08 -070019#include <hidl-util/Formatter.h>
Andreas Huber881227d2016-08-02 14:20:21 -070020#include <android-base/logging.h>
21
Yifan Hongf24fa852016-09-23 11:03:15 -070022#include "ConstantExpression.h"
23
Andreas Huberc9410c72016-07-28 12:18:40 -070024namespace android {
25
Yifan Hongf24fa852016-09-23 11:03:15 -070026ArrayType::ArrayType(ArrayType *srcArray, ConstantExpression *size)
Andreas Huber709b62d2016-09-19 11:21:18 -070027 : mElementType(srcArray->mElementType),
Yifan Hong5706a432016-11-02 09:44:18 -070028 mSizes(srcArray->mSizes) {
Yifan Hongbd33e382016-11-02 13:30:17 -070029 prependDimension(size);
Andreas Huber709b62d2016-09-19 11:21:18 -070030}
31
Yifan Hongf24fa852016-09-23 11:03:15 -070032ArrayType::ArrayType(Type *elementType, ConstantExpression *size)
Andreas Huber709b62d2016-09-19 11:21:18 -070033 : mElementType(elementType) {
Yifan Hongbd33e382016-11-02 13:30:17 -070034 prependDimension(size);
Andreas Huber709b62d2016-09-19 11:21:18 -070035}
36
Yifan Hongbd33e382016-11-02 13:30:17 -070037void ArrayType::prependDimension(ConstantExpression *size) {
Yifan Hong5706a432016-11-02 09:44:18 -070038 mSizes.insert(mSizes.begin(), size);
Andreas Huberc9410c72016-07-28 12:18:40 -070039}
40
Yifan Hongbd33e382016-11-02 13:30:17 -070041void ArrayType::appendDimension(ConstantExpression *size) {
Yifan Hong5706a432016-11-02 09:44:18 -070042 mSizes.push_back(size);
Yifan Hongbd33e382016-11-02 13:30:17 -070043}
44
Andreas Huberf03332a2016-09-22 15:35:43 -070045size_t ArrayType::countDimensions() const {
46 return mSizes.size();
47}
48
Steven Moreland979e0992016-09-07 09:18:08 -070049void ArrayType::addNamedTypesToSet(std::set<const FQName> &set) const {
50 mElementType->addNamedTypesToSet(set);
51}
52
Andreas Huber709b62d2016-09-19 11:21:18 -070053bool ArrayType::isArray() const {
54 return true;
55}
56
Yifan Hongc6752dc2016-12-20 14:00:14 -080057bool ArrayType::canCheckEquality() const {
58 return mElementType->canCheckEquality();
59}
60
Andreas Huberf03332a2016-09-22 15:35:43 -070061Type *ArrayType::getElementType() const {
62 return mElementType;
63}
64
Steven Moreland979e0992016-09-07 09:18:08 -070065std::string ArrayType::getCppType(StorageMode mode,
Steven Moreland979e0992016-09-07 09:18:08 -070066 bool specifyNamespaces) const {
Yifan Hong3b320f82016-11-01 15:15:54 -070067 const std::string base = mElementType->getCppStackType(specifyNamespaces);
Andreas Huber881227d2016-08-02 14:20:21 -070068
Steven Morelandc46e9842016-11-02 13:21:26 -070069 std::string space = specifyNamespaces ? "::android::hardware::" : "";
70 std::string arrayType = space + "hidl_array<" + base;
Andreas Huberf03332a2016-09-22 15:35:43 -070071
72 for (size_t i = 0; i < mSizes.size(); ++i) {
73 arrayType += ", ";
Yifan Hong5706a432016-11-02 09:44:18 -070074 arrayType += mSizes[i]->cppValue();
Andreas Huberf03332a2016-09-22 15:35:43 -070075
Yifan Hong5706a432016-11-02 09:44:18 -070076 if (!mSizes[i]->descriptionIsTrivial()) {
77 arrayType += " /* ";
78 arrayType += mSizes[i]->description();
79 arrayType += " */";
80 }
Andreas Huber709b62d2016-09-19 11:21:18 -070081 }
82
Andreas Huberf03332a2016-09-22 15:35:43 -070083 arrayType += ">";
Andreas Huber881227d2016-08-02 14:20:21 -070084
85 switch (mode) {
86 case StorageMode_Stack:
Andreas Huberf03332a2016-09-22 15:35:43 -070087 return arrayType;
Andreas Huber881227d2016-08-02 14:20:21 -070088
89 case StorageMode_Argument:
Andreas Huberf03332a2016-09-22 15:35:43 -070090 return "const " + arrayType + "&";
91
Andreas Huber881227d2016-08-02 14:20:21 -070092 case StorageMode_Result:
Andreas Huberf03332a2016-09-22 15:35:43 -070093 return "const " + arrayType + "*";
Andreas Huber881227d2016-08-02 14:20:21 -070094 }
Andreas Huberf03332a2016-09-22 15:35:43 -070095
96 CHECK(!"Should not be here");
Andreas Huber881227d2016-08-02 14:20:21 -070097}
98
Yifan Hongf509cb02017-04-03 12:19:25 -070099std::string ArrayType::getInternalDataCppType() const {
100 std::string result = mElementType->getCppStackType();
101 for (size_t i = 0; i < mSizes.size(); ++i) {
102 result += "[";
103 result += mSizes[i]->cppValue();
104 result += "]";
105 }
106 return result;
107}
108
Yifan Hong4ed13472016-11-02 10:44:11 -0700109std::string ArrayType::getJavaType(bool forInitializer) const {
110 std::string base =
111 mElementType->getJavaType(forInitializer);
Andreas Huber709b62d2016-09-19 11:21:18 -0700112
Yifan Hongf24fa852016-09-23 11:03:15 -0700113 for (size_t i = 0; i < mSizes.size(); ++i) {
Yifan Hong4ed13472016-11-02 10:44:11 -0700114 base += "[";
Andreas Huber709b62d2016-09-19 11:21:18 -0700115
116 if (forInitializer) {
Yifan Hong4ed13472016-11-02 10:44:11 -0700117 base += mSizes[i]->javaValue();
Andreas Huber709b62d2016-09-19 11:21:18 -0700118 }
119
Yifan Hong5706a432016-11-02 09:44:18 -0700120 if (!forInitializer || !mSizes[i]->descriptionIsTrivial()) {
121 if (forInitializer)
Yifan Hong4ed13472016-11-02 10:44:11 -0700122 base += " ";
123 base += "/* " + mSizes[i]->description() + " */";
Yifan Hong5706a432016-11-02 09:44:18 -0700124 }
Yifan Hongf24fa852016-09-23 11:03:15 -0700125
Yifan Hong4ed13472016-11-02 10:44:11 -0700126 base += "]";
Andreas Huber4c865b72016-09-14 15:26:27 -0700127 }
Andreas Huber4c865b72016-09-14 15:26:27 -0700128
129 return base;
Andreas Huber2831d512016-08-15 09:33:47 -0700130}
131
Andreas Huberf03332a2016-09-22 15:35:43 -0700132std::string ArrayType::getJavaWrapperType() const {
133 return mElementType->getJavaWrapperType();
134}
135
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700136std::string ArrayType::getVtsType() const {
137 return "TYPE_ARRAY";
138}
139
Andreas Huber881227d2016-08-02 14:20:21 -0700140void ArrayType::emitReaderWriter(
141 Formatter &out,
142 const std::string &name,
143 const std::string &parcelObj,
144 bool parcelObjIsPointer,
145 bool isReader,
146 ErrorMode mode) const {
Yifan Hong3b320f82016-11-01 15:15:54 -0700147 std::string baseType = mElementType->getCppStackType();
Andreas Huber881227d2016-08-02 14:20:21 -0700148
Iliyan Malchev549e2592016-08-10 08:59:12 -0700149 const std::string parentName = "_hidl_" + name + "_parent";
Andreas Huber881227d2016-08-02 14:20:21 -0700150
151 out << "size_t " << parentName << ";\n\n";
152
153 const std::string parcelObjDeref =
154 parcelObj + (parcelObjIsPointer ? "->" : ".");
155
156 if (isReader) {
Martijn Coenen6a082c62017-01-11 12:47:02 +0100157 out << "_hidl_err = "
Andreas Huber881227d2016-08-02 14:20:21 -0700158 << parcelObjDeref
159 << "readBuffer(&"
160 << parentName
Martijn Coenen6a082c62017-01-11 12:47:02 +0100161 << ", "
162 << " reinterpret_cast<const void **>("
163 << "&" << name
164 << "));\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700165
Martijn Coenen6a082c62017-01-11 12:47:02 +0100166 handleError(out, mode);
Andreas Huber881227d2016-08-02 14:20:21 -0700167 } else {
Andreas Huberf03332a2016-09-22 15:35:43 -0700168 size_t numArrayElements = 1;
169 for (auto size : mSizes) {
Yifan Hong5706a432016-11-02 09:44:18 -0700170 numArrayElements *= size->castSizeT();
Andreas Huberf03332a2016-09-22 15:35:43 -0700171 }
172
Iliyan Malchev549e2592016-08-10 08:59:12 -0700173 out << "_hidl_err = "
Andreas Huber881227d2016-08-02 14:20:21 -0700174 << parcelObjDeref
175 << "writeBuffer("
176 << name
Andreas Huberf03332a2016-09-22 15:35:43 -0700177 << ".data(), "
178 << numArrayElements
179 << " * sizeof("
Andreas Huber881227d2016-08-02 14:20:21 -0700180 << baseType
181 << "), &"
182 << parentName
183 << ");\n";
184
185 handleError(out, mode);
186 }
187
188 emitReaderWriterEmbedded(
189 out,
Andreas Huberf9d49f12016-09-12 14:58:36 -0700190 0 /* depth */,
Andreas Huber881227d2016-08-02 14:20:21 -0700191 name,
Yifan Hongbe2a3732016-10-05 13:33:41 -0700192 name /* sanitizedName */,
Andreas Huber881227d2016-08-02 14:20:21 -0700193 isReader /* nameIsPointer */,
194 parcelObj,
195 parcelObjIsPointer,
196 isReader,
197 mode,
198 parentName,
199 "0 /* parentOffset */");
200}
201
202void ArrayType::emitReaderWriterEmbedded(
203 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -0700204 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -0700205 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -0700206 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -0700207 bool nameIsPointer,
208 const std::string &parcelObj,
209 bool parcelObjIsPointer,
210 bool isReader,
211 ErrorMode mode,
212 const std::string &parentName,
213 const std::string &offsetText) const {
214 if (!mElementType->needsEmbeddedReadWrite()) {
215 return;
216 }
217
218 const std::string nameDeref = name + (nameIsPointer ? "->" : ".");
219
Yifan Hong3b320f82016-11-01 15:15:54 -0700220 std::string baseType = mElementType->getCppStackType();
Andreas Huber881227d2016-08-02 14:20:21 -0700221
Andreas Huberf9d49f12016-09-12 14:58:36 -0700222 std::string iteratorName = "_hidl_index_" + std::to_string(depth);
223
224 out << "for (size_t "
225 << iteratorName
226 << " = 0; "
227 << iteratorName
228 << " < "
Yifan Hongbf459bc2016-08-23 16:50:37 -0700229 << dimension()
Andreas Huberf9d49f12016-09-12 14:58:36 -0700230 << "; ++"
231 << iteratorName
232 << ") {\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700233
234 out.indent();
235
236 mElementType->emitReaderWriterEmbedded(
237 out,
Andreas Huberf9d49f12016-09-12 14:58:36 -0700238 depth + 1,
Andreas Huberf03332a2016-09-22 15:35:43 -0700239 nameDeref + "data()[" + iteratorName + "]",
Yifan Hongbe2a3732016-10-05 13:33:41 -0700240 sanitizedName + "_indexed",
Andreas Huber881227d2016-08-02 14:20:21 -0700241 false /* nameIsPointer */,
242 parcelObj,
243 parcelObjIsPointer,
244 isReader,
245 mode,
246 parentName,
Andreas Huberf9d49f12016-09-12 14:58:36 -0700247 offsetText
248 + " + " + iteratorName + " * sizeof("
249 + baseType
Andreas Huberf9d49f12016-09-12 14:58:36 -0700250 + ")");
Andreas Huber881227d2016-08-02 14:20:21 -0700251
252 out.unindent();
253
254 out << "}\n\n";
255}
256
Yifan Hongbf459bc2016-08-23 16:50:37 -0700257void ArrayType::emitResolveReferences(
258 Formatter &out,
259 const std::string &name,
260 bool nameIsPointer,
261 const std::string &parcelObj,
262 bool parcelObjIsPointer,
263 bool isReader,
264 ErrorMode mode) const {
265 emitResolveReferencesEmbedded(
266 out,
267 0 /* depth */,
268 name,
269 name /* sanitizedName */,
270 nameIsPointer,
271 parcelObj,
272 parcelObjIsPointer,
273 isReader,
274 mode,
275 "_hidl_" + name + "_parent",
276 "0 /* parentOffset */");
277}
278
279void ArrayType::emitResolveReferencesEmbedded(
280 Formatter &out,
281 size_t depth,
282 const std::string &name,
283 const std::string &sanitizedName,
284 bool nameIsPointer,
285 const std::string &parcelObj,
286 bool parcelObjIsPointer,
287 bool isReader,
288 ErrorMode mode,
289 const std::string &parentName,
290 const std::string &offsetText) const {
291 CHECK(needsResolveReferences() && mElementType->needsResolveReferences());
292
293 const std::string nameDeref = name + (nameIsPointer ? "->" : ".");
294
Yifan Hong3b320f82016-11-01 15:15:54 -0700295 std::string baseType = mElementType->getCppStackType();
Yifan Hongbf459bc2016-08-23 16:50:37 -0700296
297 std::string iteratorName = "_hidl_index_" + std::to_string(depth);
298
299 out << "for (size_t "
300 << iteratorName
301 << " = 0; "
302 << iteratorName
303 << " < "
304 << dimension()
305 << "; ++"
306 << iteratorName
307 << ") {\n";
308
309 out.indent();
310
311 mElementType->emitResolveReferencesEmbedded(
312 out,
313 depth + 1,
314 nameDeref + "data()[" + iteratorName + "]",
315 sanitizedName + "_indexed",
316 false /* nameIsPointer */,
317 parcelObj,
318 parcelObjIsPointer,
319 isReader,
320 mode,
321 parentName,
322 offsetText + " + " + iteratorName + " * sizeof("
323 + baseType
324 + ")");
325
326 out.unindent();
327
328 out << "}\n\n";
329}
330
Yifan Honge45b5302017-02-22 10:49:07 -0800331void ArrayType::emitJavaDump(
332 Formatter &out,
333 const std::string &streamName,
334 const std::string &name) const {
335 out << streamName << ".append(java.util.Arrays."
336 << (countDimensions() > 1 ? "deepToString" : "toString")
337 << "("
338 << name << "));\n";
339}
340
341
Andreas Huber881227d2016-08-02 14:20:21 -0700342bool ArrayType::needsEmbeddedReadWrite() const {
343 return mElementType->needsEmbeddedReadWrite();
344}
345
Yifan Hongbf459bc2016-08-23 16:50:37 -0700346bool ArrayType::needsResolveReferences() const {
347 return mElementType->needsResolveReferences();
348}
349
Andreas Huberf03332a2016-09-22 15:35:43 -0700350bool ArrayType::resultNeedsDeref() const {
351 return true;
352}
353
Andreas Huber2831d512016-08-15 09:33:47 -0700354void ArrayType::emitJavaReaderWriter(
355 Formatter &out,
356 const std::string &parcelObj,
357 const std::string &argName,
358 bool isReader) const {
Andreas Huber709b62d2016-09-19 11:21:18 -0700359 if (isReader) {
Andreas Huber709b62d2016-09-19 11:21:18 -0700360 out << "new "
Yifan Hong4ed13472016-11-02 10:44:11 -0700361 << getJavaType(true /* forInitializer */)
Andreas Huber709b62d2016-09-19 11:21:18 -0700362 << ";\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700363 }
364
Andreas Huber709b62d2016-09-19 11:21:18 -0700365 out << "{\n";
366 out.indent();
367
Yifan Hong1af73532016-11-09 14:32:58 -0800368 out << "android.os.HwBlob _hidl_blob = ";
Andreas Huber709b62d2016-09-19 11:21:18 -0700369
370 if (isReader) {
371 out << parcelObj
372 << ".readBuffer();\n";
373 } else {
374 size_t align, size;
375 getAlignmentAndSize(&align, &size);
376
Yifan Hong1af73532016-11-09 14:32:58 -0800377 out << "new android.os.HwBlob("
Andreas Huber709b62d2016-09-19 11:21:18 -0700378 << size
379 << " /* size */);\n";
380 }
381
382 emitJavaFieldReaderWriter(
Andreas Huber2831d512016-08-15 09:33:47 -0700383 out,
Andreas Huber709b62d2016-09-19 11:21:18 -0700384 0 /* depth */,
Andreas Huber2831d512016-08-15 09:33:47 -0700385 parcelObj,
Andreas Huber709b62d2016-09-19 11:21:18 -0700386 "_hidl_blob",
Andreas Huber2831d512016-08-15 09:33:47 -0700387 argName,
Andreas Huber709b62d2016-09-19 11:21:18 -0700388 "0 /* offset */",
389 isReader);
390
391 if (!isReader) {
392 out << parcelObj << ".writeBuffer(_hidl_blob);\n";
393 }
394
395 out.unindent();
396 out << "}\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700397}
398
Andreas Huber85eabdb2016-08-25 11:24:49 -0700399void ArrayType::emitJavaFieldInitializer(
400 Formatter &out, const std::string &fieldName) const {
Yifan Hong4ed13472016-11-02 10:44:11 -0700401 std::string typeName = getJavaType(false /* forInitializer */);
402 std::string initName = getJavaType(true /* forInitializer */);
Andreas Huber4c865b72016-09-14 15:26:27 -0700403
Andreas Hubercd5e6662016-08-30 15:02:59 -0700404 out << "final "
Andreas Huber4c865b72016-09-14 15:26:27 -0700405 << typeName
Andreas Huber4c865b72016-09-14 15:26:27 -0700406 << " "
Andreas Huber85eabdb2016-08-25 11:24:49 -0700407 << fieldName
408 << " = new "
Yifan Hong4ed13472016-11-02 10:44:11 -0700409 << initName
Andreas Huber4c865b72016-09-14 15:26:27 -0700410 << ";\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700411}
412
413void ArrayType::emitJavaFieldReaderWriter(
414 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700415 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700416 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700417 const std::string &blobName,
418 const std::string &fieldName,
419 const std::string &offset,
420 bool isReader) const {
Andreas Huber90e8fc22016-09-21 16:36:15 -0700421 out << "{\n";
422 out.indent();
423
Andreas Huber709b62d2016-09-19 11:21:18 -0700424 std::string offsetName = "_hidl_array_offset_" + std::to_string(depth);
425 out << "long " << offsetName << " = " << offset << ";\n";
Andreas Huber4c865b72016-09-14 15:26:27 -0700426
Andreas Huber709b62d2016-09-19 11:21:18 -0700427 std::string indexString;
428 for (size_t dim = 0; dim < mSizes.size(); ++dim) {
429 std::string iteratorName =
430 "_hidl_index_" + std::to_string(depth) + "_" + std::to_string(dim);
Andreas Huber85eabdb2016-08-25 11:24:49 -0700431
Andreas Huber709b62d2016-09-19 11:21:18 -0700432 out << "for (int "
433 << iteratorName
434 << " = 0; "
435 << iteratorName
436 << " < "
Yifan Hong5706a432016-11-02 09:44:18 -0700437 << mSizes[dim]->javaValue()
Andreas Huber709b62d2016-09-19 11:21:18 -0700438 << "; ++"
439 << iteratorName
440 << ") {\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700441
Andreas Huber709b62d2016-09-19 11:21:18 -0700442 out.indent();
443
444 indexString += "[" + iteratorName + "]";
445 }
446
447 if (isReader && mElementType->isCompoundType()) {
Andreas Huber709b62d2016-09-19 11:21:18 -0700448 std::string typeName =
Yifan Hong4ed13472016-11-02 10:44:11 -0700449 mElementType->getJavaType(false /* forInitializer */);
Andreas Huber709b62d2016-09-19 11:21:18 -0700450
451 out << fieldName
452 << indexString
453 << " = new "
454 << typeName
455 << "();\n";
456 }
Andreas Huber85eabdb2016-08-25 11:24:49 -0700457
458 mElementType->emitJavaFieldReaderWriter(
459 out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700460 depth + 1,
Andreas Huber709b62d2016-09-19 11:21:18 -0700461 parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700462 blobName,
Andreas Huber709b62d2016-09-19 11:21:18 -0700463 fieldName + indexString,
464 offsetName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700465 isReader);
466
Andreas Huber709b62d2016-09-19 11:21:18 -0700467 size_t elementAlign, elementSize;
468 mElementType->getAlignmentAndSize(&elementAlign, &elementSize);
469
470 out << offsetName << " += " << std::to_string(elementSize) << ";\n";
471
472 for (size_t dim = 0; dim < mSizes.size(); ++dim) {
473 out.unindent();
474 out << "}\n";
475 }
Andreas Huber90e8fc22016-09-21 16:36:15 -0700476
477 out.unindent();
478 out << "}\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700479}
480
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700481status_t ArrayType::emitVtsTypeDeclarations(Formatter &out) const {
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700482 out << "type: " << getVtsType() << "\n";
Zhuoyao Zhang3b23fa32017-01-23 18:19:15 -0800483 out << "vector_size: " << mSizes[0]->value() << "\n";
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700484 out << "vector_value: {\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700485 out.indent();
Zhuoyao Zhangeb355ee2016-10-20 16:00:40 -0700486 // Simple array case.
487 if (mSizes.size() == 1) {
488 status_t err = mElementType->emitVtsTypeDeclarations(out);
489 if (err != OK) {
490 return err;
491 }
492 } else { // Multi-dimension array case.
493 for (size_t index = 1; index < mSizes.size(); index++) {
494 out << "type: " << getVtsType() << "\n";
Zhuoyao Zhang3b23fa32017-01-23 18:19:15 -0800495 out << "vector_size: " << mSizes[index]->value() << "\n";
Zhuoyao Zhangeb355ee2016-10-20 16:00:40 -0700496 out << "vector_value: {\n";
497 out.indent();
Zhuoyao Zhangeb355ee2016-10-20 16:00:40 -0700498 if (index == mSizes.size() - 1) {
499 status_t err = mElementType->emitVtsTypeDeclarations(out);
500 if (err != OK) {
501 return err;
502 }
503 }
504 }
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700505 }
Zhuoyao Zhangeb355ee2016-10-20 16:00:40 -0700506 for (size_t index = 0; index < mSizes.size(); index++) {
507 out.unindent();
508 out << "}\n";
509 }
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700510 return OK;
511}
512
Andreas Huber70a59e12016-08-16 12:57:01 -0700513bool ArrayType::isJavaCompatible() const {
514 return mElementType->isJavaCompatible();
515}
516
Andreas Huber2639fa32017-03-30 09:10:56 -0700517bool ArrayType::containsPointer() const {
518 return mElementType->containsPointer();
519}
520
Andreas Huber85eabdb2016-08-25 11:24:49 -0700521void ArrayType::getAlignmentAndSize(size_t *align, size_t *size) const {
522 mElementType->getAlignmentAndSize(align, size);
523
Andreas Huber709b62d2016-09-19 11:21:18 -0700524 for (auto sizeInDimension : mSizes) {
Yifan Hong5706a432016-11-02 09:44:18 -0700525 (*size) *= sizeInDimension->castSizeT();
Andreas Huber709b62d2016-09-19 11:21:18 -0700526 }
Andreas Huber85eabdb2016-08-25 11:24:49 -0700527}
528
Yifan Hongbf459bc2016-08-23 16:50:37 -0700529size_t ArrayType::dimension() const {
530 size_t numArrayElements = 1;
531 for (auto size : mSizes) {
Yifan Hong5706a432016-11-02 09:44:18 -0700532 numArrayElements *= size->castSizeT();
Yifan Hongbf459bc2016-08-23 16:50:37 -0700533 }
534 return numArrayElements;
535}
536
Andreas Huberc9410c72016-07-28 12:18:40 -0700537} // namespace android
538