blob: 332badad7e216f76ca8057f25f5a9166b481bfa5 [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 "CompoundType.h"
18
Yifan Hongec102272016-12-20 18:10:07 -080019#include "ArrayType.h"
Andreas Huberf630bc82016-09-09 14:52:25 -070020#include "VectorType.h"
Iliyan Malcheva72e0d22016-09-09 11:03:08 -070021#include <hidl-util/Formatter.h>
Andreas Huber5a545442016-08-03 10:44:56 -070022#include <android-base/logging.h>
23
Andreas Huberc9410c72016-07-28 12:18:40 -070024namespace android {
25
Yifan Honga4b53d02016-10-31 17:29:10 -070026CompoundType::CompoundType(Style style, const char *localName, const Location &location)
27 : Scope(localName, location),
Andreas Huber9ed827c2016-08-22 12:31:13 -070028 mStyle(style),
Andreas Huberc9410c72016-07-28 12:18:40 -070029 mFields(NULL) {
30}
31
Yifan Hong27e85db2016-11-09 15:45:52 -080032CompoundType::Style CompoundType::style() const {
33 return mStyle;
34}
35
Andreas Huber0d0f9a22016-08-17 10:26:11 -070036bool CompoundType::setFields(
37 std::vector<CompoundField *> *fields, std::string *errorMsg) {
Andreas Huberc9410c72016-07-28 12:18:40 -070038 mFields = fields;
Andreas Huber5a545442016-08-03 10:44:56 -070039
40 for (const auto &field : *fields) {
41 const Type &type = field->type();
42
Andreas Huber86a112b2016-10-19 14:25:16 -070043 if (type.isBinder()
44 || (type.isVector()
45 && static_cast<const VectorType *>(
46 &type)->isVectorOfBinders())) {
Andreas Huber0d0f9a22016-08-17 10:26:11 -070047 *errorMsg =
48 "Structs/Unions must not contain references to interfaces.";
Andreas Huberb95ea8a2016-08-15 15:35:42 -070049
50 return false;
51 }
52
Andreas Huber5a545442016-08-03 10:44:56 -070053 if (mStyle == STYLE_UNION) {
54 if (type.needsEmbeddedReadWrite()) {
55 // Can't have those in a union.
56
Andreas Huber0d0f9a22016-08-17 10:26:11 -070057 *errorMsg =
58 "Unions must not contain any types that need fixup.";
Andreas Huber5a545442016-08-03 10:44:56 -070059
60 return false;
61 }
Andreas Huber5a545442016-08-03 10:44:56 -070062 }
63 }
64
65 return true;
Andreas Huberc9410c72016-07-28 12:18:40 -070066}
67
Andreas Huberf630bc82016-09-09 14:52:25 -070068bool CompoundType::isCompoundType() const {
69 return true;
70}
71
Yifan Hongc6752dc2016-12-20 14:00:14 -080072bool CompoundType::canCheckEquality() const {
73 if (mStyle == STYLE_UNION) {
74 return false;
75 }
76 for (const auto &field : *mFields) {
77 if (!field->type().canCheckEquality()) {
78 return false;
79 }
80 }
81 return true;
82}
83
Andreas Huber881227d2016-08-02 14:20:21 -070084std::string CompoundType::getCppType(
Steven Moreland979e0992016-09-07 09:18:08 -070085 StorageMode mode,
Steven Moreland979e0992016-09-07 09:18:08 -070086 bool specifyNamespaces) const {
Steven Moreland979e0992016-09-07 09:18:08 -070087 const std::string base =
88 specifyNamespaces ? fullName() : partialCppName();
Andreas Huber881227d2016-08-02 14:20:21 -070089
90 switch (mode) {
91 case StorageMode_Stack:
92 return base;
93
94 case StorageMode_Argument:
95 return "const " + base + "&";
96
97 case StorageMode_Result:
98 return "const " + base + "*";
99 }
100}
101
Yifan Hong4ed13472016-11-02 10:44:11 -0700102std::string CompoundType::getJavaType(bool /* forInitializer */) const {
Andreas Huber85eabdb2016-08-25 11:24:49 -0700103 return fullJavaName();
104}
105
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700106std::string CompoundType::getVtsType() const {
107 switch (mStyle) {
108 case STYLE_STRUCT:
109 {
110 return "TYPE_STRUCT";
111 }
112 case STYLE_UNION:
113 {
114 return "TYPE_UNION";
115 }
116 }
117}
118
Andreas Huber881227d2016-08-02 14:20:21 -0700119void CompoundType::emitReaderWriter(
120 Formatter &out,
121 const std::string &name,
122 const std::string &parcelObj,
123 bool parcelObjIsPointer,
124 bool isReader,
125 ErrorMode mode) const {
Iliyan Malchev549e2592016-08-10 08:59:12 -0700126 const std::string parentName = "_hidl_" + name + "_parent";
Andreas Huber881227d2016-08-02 14:20:21 -0700127
128 out << "size_t " << parentName << ";\n\n";
129
130 const std::string parcelObjDeref =
131 parcelObj + (parcelObjIsPointer ? "->" : ".");
132
133 if (isReader) {
Martijn Coenen6a082c62017-01-11 12:47:02 +0100134 out << "_hidl_err = "
Andreas Huber881227d2016-08-02 14:20:21 -0700135 << parcelObjDeref
136 << "readBuffer("
137 << "&"
138 << parentName
Martijn Coenen6a082c62017-01-11 12:47:02 +0100139 << ", "
140 << " reinterpret_cast<const void **>("
141 << "&" << name
142 << "));\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700143
Martijn Coenen6a082c62017-01-11 12:47:02 +0100144 handleError(out, mode);
Andreas Huber881227d2016-08-02 14:20:21 -0700145 } else {
Iliyan Malchev549e2592016-08-10 08:59:12 -0700146 out << "_hidl_err = "
Andreas Huber881227d2016-08-02 14:20:21 -0700147 << parcelObjDeref
148 << "writeBuffer(&"
149 << name
150 << ", sizeof("
151 << name
152 << "), &"
153 << parentName
154 << ");\n";
155
156 handleError(out, mode);
157 }
158
159 if (mStyle != STYLE_STRUCT || !needsEmbeddedReadWrite()) {
160 return;
161 }
162
163 emitReaderWriterEmbedded(
164 out,
Andreas Huberf9d49f12016-09-12 14:58:36 -0700165 0 /* depth */,
Andreas Huber881227d2016-08-02 14:20:21 -0700166 name,
Yifan Hongbe2a3732016-10-05 13:33:41 -0700167 name, /* sanitizedName */
Andreas Huber881227d2016-08-02 14:20:21 -0700168 isReader /* nameIsPointer */,
169 parcelObj,
170 parcelObjIsPointer,
171 isReader,
172 mode,
173 parentName,
174 "0 /* parentOffset */");
175}
176
177void CompoundType::emitReaderWriterEmbedded(
178 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -0700179 size_t /* depth */,
Andreas Huber881227d2016-08-02 14:20:21 -0700180 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -0700181 const std::string & /*sanitizedName */,
Andreas Huber881227d2016-08-02 14:20:21 -0700182 bool nameIsPointer,
183 const std::string &parcelObj,
184 bool parcelObjIsPointer,
185 bool isReader,
186 ErrorMode mode,
187 const std::string &parentName,
188 const std::string &offsetText) const {
189 emitReaderWriterEmbeddedForTypeName(
190 out,
191 name,
192 nameIsPointer,
193 parcelObj,
194 parcelObjIsPointer,
195 isReader,
196 mode,
197 parentName,
198 offsetText,
Andreas Huber0e00de42016-08-03 09:56:02 -0700199 fullName(),
Yifan Hong244e82d2016-11-11 11:13:57 -0800200 "" /* childName */,
201 "" /* namespace */);
Andreas Huber881227d2016-08-02 14:20:21 -0700202}
203
Andreas Huber85eabdb2016-08-25 11:24:49 -0700204void CompoundType::emitJavaReaderWriter(
205 Formatter &out,
206 const std::string &parcelObj,
207 const std::string &argName,
208 bool isReader) const {
209 if (isReader) {
210 out << "new " << fullJavaName() << "();\n";
211 }
212
213 out << argName
214 << "."
215 << (isReader ? "readFromParcel" : "writeToParcel")
216 << "("
217 << parcelObj
218 << ");\n";
219}
220
221void CompoundType::emitJavaFieldInitializer(
222 Formatter &out, const std::string &fieldName) const {
223 out << "final "
224 << fullJavaName()
225 << " "
226 << fieldName
227 << " = new "
228 << fullJavaName()
229 << "();\n";
230}
231
232void CompoundType::emitJavaFieldReaderWriter(
233 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700234 size_t /* depth */,
Andreas Huber709b62d2016-09-19 11:21:18 -0700235 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700236 const std::string &blobName,
237 const std::string &fieldName,
238 const std::string &offset,
239 bool isReader) const {
240 if (isReader) {
241 out << fieldName
Andreas Huber709b62d2016-09-19 11:21:18 -0700242 << ".readEmbeddedFromParcel("
243 << parcelName
244 << ", "
Andreas Huber85eabdb2016-08-25 11:24:49 -0700245 << blobName
246 << ", "
247 << offset
248 << ");\n";
249
250 return;
251 }
252
253 out << fieldName
254 << ".writeEmbeddedToBlob("
255 << blobName
256 << ", "
257 << offset
258 << ");\n";
259}
Yifan Hongbf459bc2016-08-23 16:50:37 -0700260void CompoundType::emitResolveReferences(
261 Formatter &out,
262 const std::string &name,
263 bool nameIsPointer,
264 const std::string &parcelObj,
265 bool parcelObjIsPointer,
266 bool isReader,
267 ErrorMode mode) const {
268 emitResolveReferencesEmbedded(
269 out,
270 0 /* depth */,
271 name,
272 name /* sanitizedName */,
273 nameIsPointer,
274 parcelObj,
275 parcelObjIsPointer,
276 isReader,
277 mode,
278 "_hidl_" + name + "_parent",
279 "0 /* parentOffset */");
280}
281
282void CompoundType::emitResolveReferencesEmbedded(
283 Formatter &out,
284 size_t /* depth */,
285 const std::string &name,
286 const std::string &/* sanitizedName */,
287 bool nameIsPointer,
288 const std::string &parcelObj,
289 bool parcelObjIsPointer,
290 bool isReader,
291 ErrorMode mode,
292 const std::string &parentName,
293 const std::string &offsetText) const {
294 CHECK(needsResolveReferences());
295
296 const std::string parcelObjDeref =
297 parcelObjIsPointer ? ("*" + parcelObj) : parcelObj;
298
299 const std::string parcelObjPointer =
300 parcelObjIsPointer ? parcelObj : ("&" + parcelObj);
301
Yifan Hong244e82d2016-11-11 11:13:57 -0800302 const std::string nameDerefed = nameIsPointer ? ("*" + name) : name;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700303 const std::string namePointer = nameIsPointer ? name : ("&" + name);
304
305 out << "_hidl_err = ";
306
307 if (isReader) {
Yifan Hong244e82d2016-11-11 11:13:57 -0800308 out << "readEmbeddedReferenceFromParcel(\n";
Yifan Hongbf459bc2016-08-23 16:50:37 -0700309 } else {
Yifan Hong244e82d2016-11-11 11:13:57 -0800310 out << "writeEmbeddedReferenceToParcel(\n";
Yifan Hongbf459bc2016-08-23 16:50:37 -0700311 }
312
Yifan Hong33223ca2016-12-13 15:07:35 -0800313 out.indent(2, [&]{
Yifan Hong244e82d2016-11-11 11:13:57 -0800314 if (isReader) {
315 out << "const_cast<"
316 << fullName()
317 << " *"
318 << ">("
319 << namePointer
320 << "),\n"
321 << parcelObjDeref;
322 } else {
323 out << nameDerefed
324 << ",\n"
325 << parcelObjPointer;
326 }
327
328 out << ",\n"
Yifan Hong0a68a282016-10-21 16:32:34 -0700329 << parentName
330 << ",\n"
331 << offsetText
332 << ");\n\n";
333 });
Yifan Hongbf459bc2016-08-23 16:50:37 -0700334
335 handleError(out, mode);
336}
Andreas Huber85eabdb2016-08-25 11:24:49 -0700337
Andreas Huber881227d2016-08-02 14:20:21 -0700338status_t CompoundType::emitTypeDeclarations(Formatter &out) const {
339 out << ((mStyle == STYLE_STRUCT) ? "struct" : "union")
340 << " "
Andreas Huber0e00de42016-08-03 09:56:02 -0700341 << localName()
Yifan Hongb1d2ebc2016-12-20 17:18:07 -0800342 << " final {\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700343
344 out.indent();
345
346 Scope::emitTypeDeclarations(out);
347
Andreas Huberca4bc892017-01-09 14:58:12 -0800348 if (!isJavaCompatible()) {
349 for (const auto &field : *mFields) {
350 out << field->type().getCppStackType()
351 << " "
352 << field->name()
353 << ";\n";
354 }
355
356 out.unindent();
357 out << "};\n\n";
358
359 return OK;
Andreas Huber881227d2016-08-02 14:20:21 -0700360 }
361
Andreas Huberca4bc892017-01-09 14:58:12 -0800362 for (int pass = 0; pass < 2; ++pass) {
363 size_t offset = 0;
364 for (const auto &field : *mFields) {
365 size_t fieldAlign, fieldSize;
366 field->type().getAlignmentAndSize(&fieldAlign, &fieldSize);
367
368 size_t pad = offset % fieldAlign;
369 if (pad > 0) {
370 offset += fieldAlign - pad;
371 }
372
373 if (pass == 0) {
374 out << field->type().getCppStackType()
375 << " "
376 << field->name()
377 << " __attribute__ ((aligned("
378 << fieldAlign
379 << ")));\n";
380 } else {
381 out << "static_assert(offsetof("
382 << fullName()
383 << ", "
384 << field->name()
385 << ") == "
386 << offset
387 << ", \"wrong offset\");\n";
388 }
389
390 offset += fieldSize;
391 }
392
393 if (pass == 0) {
394 out.unindent();
395 out << "};\n\n";
396 }
397 }
398
399 size_t structAlign, structSize;
400 getAlignmentAndSize(&structAlign, &structSize);
401
402 out << "static_assert(sizeof("
403 << fullName()
404 << ") == "
405 << structSize
406 << ", \"wrong size\");\n";
407
408 out << "static_assert(__alignof("
409 << fullName()
410 << ") == "
411 << structAlign
412 << ", \"wrong alignment\");\n\n";
Yifan Hong244e82d2016-11-11 11:13:57 -0800413
414 return OK;
415}
416
417
Yifan Hongc6752dc2016-12-20 14:00:14 -0800418status_t CompoundType::emitGlobalTypeDeclarations(Formatter &out) const {
419 Scope::emitGlobalTypeDeclarations(out);
420
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800421 out << "std::string toString("
422 << getCppArgumentType()
Yifan Hong42c68432017-03-13 16:22:03 -0700423 << ");\n\n";
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800424
Yifan Hong42c68432017-03-13 16:22:03 -0700425 if (canCheckEquality()) {
426 out << "bool operator==("
427 << getCppArgumentType() << ", " << getCppArgumentType() << ");\n\n";
428
429 out << "bool operator!=("
430 << getCppArgumentType() << ", " << getCppArgumentType() << ");\n\n";
431 } else {
432 out << "// operator== and operator!= are not generated for " << localName() << "\n\n";
Yifan Hongc6752dc2016-12-20 14:00:14 -0800433 }
434
Yifan Hongc6752dc2016-12-20 14:00:14 -0800435 return OK;
436}
437
Yifan Hong244e82d2016-11-11 11:13:57 -0800438status_t CompoundType::emitGlobalHwDeclarations(Formatter &out) const {
Andreas Huber881227d2016-08-02 14:20:21 -0700439 if (needsEmbeddedReadWrite()) {
Yifan Hong244e82d2016-11-11 11:13:57 -0800440 out << "::android::status_t readEmbeddedFromParcel(\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700441
Yifan Hong0a68a282016-10-21 16:32:34 -0700442 out.indent(2);
Andreas Huber881227d2016-08-02 14:20:21 -0700443
Yifan Hong244e82d2016-11-11 11:13:57 -0800444 out << fullName() << " *obj,\n"
445 << "const ::android::hardware::Parcel &parcel,\n"
446 << "size_t parentHandle,\n"
447 << "size_t parentOffset);\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700448
Yifan Hong0a68a282016-10-21 16:32:34 -0700449 out.unindent(2);
Andreas Huber881227d2016-08-02 14:20:21 -0700450
451 out << "::android::status_t writeEmbeddedToParcel(\n";
452
Yifan Hong0a68a282016-10-21 16:32:34 -0700453 out.indent(2);
Andreas Huber881227d2016-08-02 14:20:21 -0700454
Yifan Hong244e82d2016-11-11 11:13:57 -0800455 out << "const " << fullName() << " &obj,\n"
456 << "::android::hardware::Parcel *parcel,\n"
457 << "size_t parentHandle,\n"
458 << "size_t parentOffset);\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700459
Yifan Hong0a68a282016-10-21 16:32:34 -0700460 out.unindent(2);
Andreas Huber881227d2016-08-02 14:20:21 -0700461 }
462
Yifan Hongbf459bc2016-08-23 16:50:37 -0700463 if(needsResolveReferences()) {
Yifan Hongbf459bc2016-08-23 16:50:37 -0700464 out << "::android::status_t readEmbeddedReferenceFromParcel(\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700465 out.indent(2);
Yifan Hong244e82d2016-11-11 11:13:57 -0800466 out << fullName() << " *obj,\n"
467 << "const ::android::hardware::Parcel &parcel,\n"
468 << "size_t parentHandle, size_t parentOffset);\n\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700469 out.unindent(2);
Yifan Hongbf459bc2016-08-23 16:50:37 -0700470 out << "::android::status_t writeEmbeddedReferenceToParcel(\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700471 out.indent(2);
Yifan Hong244e82d2016-11-11 11:13:57 -0800472 out << "const " << fullName() << " &obj,\n"
473 << "::android::hardware::Parcel *,\n"
474 << "size_t parentHandle, size_t parentOffset);\n\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700475 out.unindent(2);
Yifan Hongbf459bc2016-08-23 16:50:37 -0700476 }
477
Andreas Huber881227d2016-08-02 14:20:21 -0700478 return OK;
479}
480
481status_t CompoundType::emitTypeDefinitions(
482 Formatter &out, const std::string prefix) const {
Steven Morelandb158de12016-10-10 11:59:09 -0700483 std::string space = prefix.empty() ? "" : (prefix + "::");
484 status_t err = Scope::emitTypeDefinitions(out, space + localName());
Andreas Huber881227d2016-08-02 14:20:21 -0700485
486 if (err != OK) {
487 return err;
488 }
489
Yifan Hongbf459bc2016-08-23 16:50:37 -0700490 if (needsEmbeddedReadWrite()) {
491 emitStructReaderWriter(out, prefix, true /* isReader */);
492 emitStructReaderWriter(out, prefix, false /* isReader */);
Andreas Huber881227d2016-08-02 14:20:21 -0700493 }
494
Yifan Hongbf459bc2016-08-23 16:50:37 -0700495 if (needsResolveReferences()) {
496 emitResolveReferenceDef(out, prefix, true /* isReader */);
497 emitResolveReferenceDef(out, prefix, false /* isReader */);
498 }
Andreas Huber881227d2016-08-02 14:20:21 -0700499
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800500 out << "std::string toString("
501 << getCppArgumentType()
502 << (mFields->empty() ? "" : " o")
503 << ") ";
504
505 out.block([&] {
506 // include toString for scalar types
Hridya Valsaraju9ab1e9e2017-03-10 07:52:23 -0800507 out << "using ::android::hardware::toString;\n"
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800508 << "std::string os;\n";
509 out << "os += \"{\";\n";
510
511 for (const CompoundField *field : *mFields) {
512 out << "os += \"";
513 if (field != *(mFields->begin())) {
514 out << ", ";
515 }
516 out << "." << field->name() << " = \";\n";
517 field->type().emitDump(out, "os", "o." + field->name());
518 }
519
520 out << "os += \"}\"; return os;\n";
521 }).endl().endl();
522
Yifan Hong42c68432017-03-13 16:22:03 -0700523 if (canCheckEquality()) {
524 out << "bool operator==("
525 << getCppArgumentType() << " " << (mFields->empty() ? "/* lhs */" : "lhs") << ", "
526 << getCppArgumentType() << " " << (mFields->empty() ? "/* rhs */" : "rhs") << ") ";
527 out.block([&] {
528 for (const auto &field : *mFields) {
529 out.sIf("lhs." + field->name() + " != rhs." + field->name(), [&] {
530 out << "return false;\n";
531 }).endl();
532 }
533 out << "return true;\n";
534 }).endl().endl();
535
536 out << "bool operator!=("
537 << getCppArgumentType() << " lhs," << getCppArgumentType() << " rhs)";
538 out.block([&] {
539 out << "return !(lhs == rhs);\n";
540 }).endl().endl();
541 } else {
542 out << "// operator== and operator!= are not generated for " << localName() << "\n";
543 }
544
Andreas Huber881227d2016-08-02 14:20:21 -0700545 return OK;
546}
547
Andreas Huber85eabdb2016-08-25 11:24:49 -0700548status_t CompoundType::emitJavaTypeDeclarations(
549 Formatter &out, bool atTopLevel) const {
550 out << "public final ";
551
552 if (!atTopLevel) {
553 out << "static ";
554 }
555
556 out << "class "
557 << localName()
558 << " {\n";
559
560 out.indent();
561
562 Scope::emitJavaTypeDeclarations(out, false /* atTopLevel */);
563
564 for (const auto &field : *mFields) {
Andreas Huber85eabdb2016-08-25 11:24:49 -0700565 out << "public ";
566
567 field->type().emitJavaFieldInitializer(out, field->name());
568 }
569
570 if (!mFields->empty()) {
571 out << "\n";
572 }
573
Yifan Hongec102272016-12-20 18:10:07 -0800574 ////////////////////////////////////////////////////////////////////////////
575
576 if (canCheckEquality()) {
Yifan Hong7d1839f2017-02-22 13:24:29 -0800577 out << "@Override\npublic final boolean equals(Object otherObject) ";
Yifan Hongec102272016-12-20 18:10:07 -0800578 out.block([&] {
Yifan Hong7d1839f2017-02-22 13:24:29 -0800579 out.sIf("this == otherObject", [&] {
580 out << "return true;\n";
581 }).endl();
582 out.sIf("otherObject == null", [&] {
583 out << "return false;\n";
584 }).endl();
585 // Class is final, so we only need to check instanceof, not getClass
586 out.sIf("!(otherObject instanceof " + fullJavaName() + ")", [&] {
587 out << "return false;\n";
588 }).endl();
589 out << fullJavaName() << " other = (" << fullJavaName() << ")otherObject;\n";
Yifan Hongec102272016-12-20 18:10:07 -0800590 for (const auto &field : *mFields) {
591 std::string condition = field->type().isScalar()
592 ? "this." + field->name() + " != other." + field->name()
593 : ("!java.util.Objects.deepEquals(this." + field->name()
594 + ", other." + field->name() + ")");
595 out.sIf(condition, [&] {
596 out << "return false;\n";
597 }).endl();
598 }
599 out << "return true;\n";
600 }).endl().endl();
601
Yifan Hong7d1839f2017-02-22 13:24:29 -0800602 out << "@Override\npublic final int hashCode() ";
Yifan Hongec102272016-12-20 18:10:07 -0800603 out.block([&] {
Yifan Hong7d1839f2017-02-22 13:24:29 -0800604 out << "return java.util.Objects.hash(\n";
605 out.indent(2, [&] {
606 bool first = true;
607 for (const auto &field : *mFields) {
608 if (!first) {
609 out << ", \n";
Yifan Hongec102272016-12-20 18:10:07 -0800610 }
Yifan Hong7d1839f2017-02-22 13:24:29 -0800611 first = false;
612 if (field->type().isArray()) {
613 const ArrayType &type = static_cast<const ArrayType &>(field->type());
614 if (type.countDimensions() == 1 &&
615 type.getElementType()->resolveToScalarType() != nullptr) {
616 out << "java.util.Arrays.hashCode(this." << field->name() << ")";
617 } else {
618 out << "java.util.Arrays.deepHashCode(this." << field->name() << ")";
619 }
620 } else {
621 out << "this." << field->name();
622 }
Yifan Hongec102272016-12-20 18:10:07 -0800623 }
Yifan Hong7d1839f2017-02-22 13:24:29 -0800624 });
Yifan Hongec102272016-12-20 18:10:07 -0800625 out << ");\n";
626 }).endl().endl();
Yifan Hong42c68432017-03-13 16:22:03 -0700627 } else {
628 out << "// equals() is not generated for " << localName() << "\n";
Yifan Hongec102272016-12-20 18:10:07 -0800629 }
630
631 ////////////////////////////////////////////////////////////////////////////
632
Yifan Honge45b5302017-02-22 10:49:07 -0800633 out << "@Override\npublic final String toString() ";
634 out.block([&] {
635 out << "java.lang.StringBuilder builder = new java.lang.StringBuilder();\n"
636 << "builder.append(\"{\");\n";
637 for (const auto &field : *mFields) {
638 out << "builder.append(\"";
639 if (field != *(mFields->begin())) {
640 out << ", ";
641 }
642 out << "." << field->name() << " = \");\n";
643 field->type().emitJavaDump(out, "builder", "this." + field->name());
644 }
645 out << "builder.append(\"}\");\nreturn builder.toString();\n";
646 }).endl().endl();
647
648 ////////////////////////////////////////////////////////////////////////////
649
Yifan Hong1af73532016-11-09 14:32:58 -0800650 out << "public final void readFromParcel(android.os.HwParcel parcel) {\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700651 out.indent();
Yifan Hong1af73532016-11-09 14:32:58 -0800652 out << "android.os.HwBlob blob = parcel.readBuffer();\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700653 out << "readEmbeddedFromParcel(parcel, blob, 0 /* parentOffset */);\n";
654 out.unindent();
655 out << "}\n\n";
656
Andreas Huberf630bc82016-09-09 14:52:25 -0700657 ////////////////////////////////////////////////////////////////////////////
658
Yifan Hong1af73532016-11-09 14:32:58 -0800659 out << "public static final java.util.ArrayList<"
Andreas Huberf630bc82016-09-09 14:52:25 -0700660 << localName()
Yifan Hong1af73532016-11-09 14:32:58 -0800661 << "> readVectorFromParcel(android.os.HwParcel parcel) {\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700662 out.indent();
663
Yifan Hong1af73532016-11-09 14:32:58 -0800664 out << "java.util.ArrayList<"
Andreas Huberf630bc82016-09-09 14:52:25 -0700665 << localName()
Yifan Hong1af73532016-11-09 14:32:58 -0800666 << "> _hidl_vec = new java.util.ArrayList();\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700667
Yifan Hong1af73532016-11-09 14:32:58 -0800668 out << "android.os.HwBlob _hidl_blob = parcel.readBuffer();\n\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700669
670 VectorType::EmitJavaFieldReaderWriterForElementType(
Andreas Huber4c865b72016-09-14 15:26:27 -0700671 out,
672 0 /* depth */,
673 this,
Andreas Huber709b62d2016-09-19 11:21:18 -0700674 "parcel",
Andreas Huber4c865b72016-09-14 15:26:27 -0700675 "_hidl_blob",
676 "_hidl_vec",
677 "0",
678 true /* isReader */);
Andreas Huberf630bc82016-09-09 14:52:25 -0700679
Andreas Huber1b6822b2016-10-18 09:28:40 -0700680 out << "\nreturn _hidl_vec;\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700681
682 out.unindent();
683 out << "}\n\n";
684
685 ////////////////////////////////////////////////////////////////////////////
686
Andreas Huber85eabdb2016-08-25 11:24:49 -0700687 out << "public final void readEmbeddedFromParcel(\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700688 out.indent(2);
Yifan Hong1af73532016-11-09 14:32:58 -0800689 out << "android.os.HwParcel parcel, android.os.HwBlob _hidl_blob, long _hidl_offset) {\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700690 out.unindent();
691
692 size_t offset = 0;
693 for (const auto &field : *mFields) {
694 size_t fieldAlign, fieldSize;
695 field->type().getAlignmentAndSize(&fieldAlign, &fieldSize);
696
697 size_t pad = offset % fieldAlign;
698 if (pad > 0) {
699 offset += fieldAlign - pad;
700 }
701
702 field->type().emitJavaFieldReaderWriter(
703 out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700704 0 /* depth */,
Andreas Huber709b62d2016-09-19 11:21:18 -0700705 "parcel",
Andreas Huber85eabdb2016-08-25 11:24:49 -0700706 "_hidl_blob",
707 field->name(),
708 "_hidl_offset + " + std::to_string(offset),
709 true /* isReader */);
710
711 offset += fieldSize;
712 }
713
714 out.unindent();
715 out << "}\n\n";
716
Andreas Huberf630bc82016-09-09 14:52:25 -0700717 ////////////////////////////////////////////////////////////////////////////
718
Andreas Huber709b62d2016-09-19 11:21:18 -0700719 size_t structAlign, structSize;
720 getAlignmentAndSize(&structAlign, &structSize);
721
Yifan Hong1af73532016-11-09 14:32:58 -0800722 out << "public final void writeToParcel(android.os.HwParcel parcel) {\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700723 out.indent();
724
Yifan Hong1af73532016-11-09 14:32:58 -0800725 out << "android.os.HwBlob _hidl_blob = new android.os.HwBlob("
Andreas Huber85eabdb2016-08-25 11:24:49 -0700726 << structSize
727 << " /* size */);\n";
728
729 out << "writeEmbeddedToBlob(_hidl_blob, 0 /* parentOffset */);\n"
730 << "parcel.writeBuffer(_hidl_blob);\n";
731
732 out.unindent();
733 out << "}\n\n";
734
Andreas Huberf630bc82016-09-09 14:52:25 -0700735 ////////////////////////////////////////////////////////////////////////////
736
Andreas Huberf630bc82016-09-09 14:52:25 -0700737 out << "public static final void writeVectorToParcel(\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700738 out.indent(2);
Yifan Hong1af73532016-11-09 14:32:58 -0800739 out << "android.os.HwParcel parcel, java.util.ArrayList<"
Andreas Huberf630bc82016-09-09 14:52:25 -0700740 << localName()
Andreas Huber1b6822b2016-10-18 09:28:40 -0700741 << "> _hidl_vec) {\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700742 out.unindent();
743
Yifan Hong1af73532016-11-09 14:32:58 -0800744 out << "android.os.HwBlob _hidl_blob = new android.os.HwBlob(24 /* sizeof(hidl_vec<T>) */);\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700745
746 VectorType::EmitJavaFieldReaderWriterForElementType(
Andreas Huber4c865b72016-09-14 15:26:27 -0700747 out,
748 0 /* depth */,
749 this,
Andreas Huber709b62d2016-09-19 11:21:18 -0700750 "parcel",
Andreas Huber4c865b72016-09-14 15:26:27 -0700751 "_hidl_blob",
752 "_hidl_vec",
753 "0",
754 false /* isReader */);
Andreas Huberf630bc82016-09-09 14:52:25 -0700755
756 out << "\nparcel.writeBuffer(_hidl_blob);\n";
757
758 out.unindent();
759 out << "}\n\n";
760
761 ////////////////////////////////////////////////////////////////////////////
762
Andreas Huber85eabdb2016-08-25 11:24:49 -0700763 out << "public final void writeEmbeddedToBlob(\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700764 out.indent(2);
Yifan Hong1af73532016-11-09 14:32:58 -0800765 out << "android.os.HwBlob _hidl_blob, long _hidl_offset) {\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700766 out.unindent();
767
768 offset = 0;
769 for (const auto &field : *mFields) {
770 size_t fieldAlign, fieldSize;
771 field->type().getAlignmentAndSize(&fieldAlign, &fieldSize);
772
773 size_t pad = offset % fieldAlign;
774 if (pad > 0) {
775 offset += fieldAlign - pad;
776 }
777
778 field->type().emitJavaFieldReaderWriter(
779 out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700780 0 /* depth */,
Andreas Huber709b62d2016-09-19 11:21:18 -0700781 "parcel",
Andreas Huber85eabdb2016-08-25 11:24:49 -0700782 "_hidl_blob",
783 field->name(),
784 "_hidl_offset + " + std::to_string(offset),
785 false /* isReader */);
786
787 offset += fieldSize;
788 }
789
790 out.unindent();
791 out << "}\n";
792
793 out.unindent();
794 out << "};\n\n";
795
796 return OK;
797}
798
Andreas Huber881227d2016-08-02 14:20:21 -0700799void CompoundType::emitStructReaderWriter(
800 Formatter &out, const std::string &prefix, bool isReader) const {
Yifan Hong244e82d2016-11-11 11:13:57 -0800801
802 std::string space = prefix.empty() ? "" : (prefix + "::");
803
Andreas Huber881227d2016-08-02 14:20:21 -0700804 out << "::android::status_t "
Yifan Hong244e82d2016-11-11 11:13:57 -0800805 << (isReader ? "readEmbeddedFromParcel"
806 : "writeEmbeddedToParcel")
807 << "(\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700808
Yifan Hong0a68a282016-10-21 16:32:34 -0700809 out.indent(2);
Andreas Huber881227d2016-08-02 14:20:21 -0700810
Yifan Hong244e82d2016-11-11 11:13:57 -0800811 bool useName = false;
812 for (const auto &field : *mFields) {
813 if (field->type().useNameInEmitReaderWriterEmbedded(isReader)) {
814 useName = true;
815 break;
816 }
817 }
818 std::string name = useName ? "obj" : "/* obj */";
819 // if not useName, then obj should not be used at all,
820 // then the #error should not be emitted.
821 std::string error = useName ? "" : "\n#error\n";
822
Andreas Huber881227d2016-08-02 14:20:21 -0700823 if (isReader) {
Yifan Hong244e82d2016-11-11 11:13:57 -0800824 out << space << localName() << " *" << name << ",\n";
Andreas Huber8a82ff72016-08-04 10:29:39 -0700825 out << "const ::android::hardware::Parcel &parcel,\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700826 } else {
Yifan Hong244e82d2016-11-11 11:13:57 -0800827 out << "const " << space << localName() << " &" << name << ",\n";
Andreas Huber8a82ff72016-08-04 10:29:39 -0700828 out << "::android::hardware::Parcel *parcel,\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700829 }
830
831 out << "size_t parentHandle,\n"
832 << "size_t parentOffset)";
833
Andreas Huber881227d2016-08-02 14:20:21 -0700834 out << " {\n";
835
Yifan Hong0a68a282016-10-21 16:32:34 -0700836 out.unindent(2);
Andreas Huber881227d2016-08-02 14:20:21 -0700837 out.indent();
838
Iliyan Malchev549e2592016-08-10 08:59:12 -0700839 out << "::android::status_t _hidl_err = ::android::OK;\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700840
841 for (const auto &field : *mFields) {
842 if (!field->type().needsEmbeddedReadWrite()) {
843 continue;
844 }
845
846 field->type().emitReaderWriterEmbedded(
847 out,
Andreas Huberf9d49f12016-09-12 14:58:36 -0700848 0 /* depth */,
Yifan Hong244e82d2016-11-11 11:13:57 -0800849 name + (isReader ? "->" : ".") + field->name() + error,
Yifan Hongbe2a3732016-10-05 13:33:41 -0700850 field->name() /* sanitizedName */,
Andreas Huber881227d2016-08-02 14:20:21 -0700851 false /* nameIsPointer */,
852 "parcel",
853 !isReader /* parcelObjIsPointer */,
854 isReader,
Andreas Huber737080b2016-08-02 15:38:04 -0700855 ErrorMode_Return,
Andreas Huber881227d2016-08-02 14:20:21 -0700856 "parentHandle",
Andreas Huber0e00de42016-08-03 09:56:02 -0700857 "parentOffset + offsetof("
858 + fullName()
859 + ", "
860 + field->name()
861 + ")");
Andreas Huber881227d2016-08-02 14:20:21 -0700862 }
863
Iliyan Malchev549e2592016-08-10 08:59:12 -0700864 out << "return _hidl_err;\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700865
866 out.unindent();
867 out << "}\n\n";
868}
869
Yifan Hongbf459bc2016-08-23 16:50:37 -0700870void CompoundType::emitResolveReferenceDef(
871 Formatter &out, const std::string prefix, bool isReader) const {
Yifan Hong244e82d2016-11-11 11:13:57 -0800872 out << "::android::status_t ";
873 const std::string space(prefix.empty() ? "" : (prefix + "::"));
Yifan Hong00f47172016-09-30 14:40:45 -0700874
875 bool useParent = false;
876 for (const auto &field : *mFields) {
877 if (field->type().useParentInEmitResolveReferencesEmbedded()) {
878 useParent = true;
879 break;
880 }
881 }
882
883 std::string parentHandleName = useParent ? "parentHandle" : "/* parentHandle */";
884 std::string parentOffsetName = useParent ? "parentOffset" : "/* parentOffset */";
885
Yifan Hongbf459bc2016-08-23 16:50:37 -0700886 if (isReader) {
Yifan Hong244e82d2016-11-11 11:13:57 -0800887 out << "readEmbeddedReferenceFromParcel(\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700888 out.indent(2);
Yifan Hong244e82d2016-11-11 11:13:57 -0800889 out << space + localName() + " *obj,\n"
890 << "const ::android::hardware::Parcel &parcel,\n"
Yifan Hong00f47172016-09-30 14:40:45 -0700891 << "size_t " << parentHandleName << ", "
892 << "size_t " << parentOffsetName << ")\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700893 out.unindent(2);
Yifan Hongbf459bc2016-08-23 16:50:37 -0700894 } else {
Yifan Hong244e82d2016-11-11 11:13:57 -0800895 out << "writeEmbeddedReferenceToParcel(\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700896 out.indent(2);
Yifan Hong244e82d2016-11-11 11:13:57 -0800897 out << "const " << space + localName() + " &obj,\n"
898 << "::android::hardware::Parcel *parcel,\n"
Yifan Hong00f47172016-09-30 14:40:45 -0700899 << "size_t " << parentHandleName << ", "
Yifan Hong244e82d2016-11-11 11:13:57 -0800900 << "size_t " << parentOffsetName << ")\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700901 out.unindent(2);
Yifan Hongbf459bc2016-08-23 16:50:37 -0700902 }
903
904 out << " {\n";
905
906 out.indent();
907
908 out << "::android::status_t _hidl_err = ::android::OK;\n\n";
909
Yifan Hong244e82d2016-11-11 11:13:57 -0800910 const std::string nameDeref(isReader ? "obj->" : "obj.");
Yifan Hong00f47172016-09-30 14:40:45 -0700911 // if not useParent, then parentName and offsetText
912 // should not be used at all, then the #error should not be emitted.
913 std::string error = useParent ? "" : "\n#error\n";
914
Yifan Hongbf459bc2016-08-23 16:50:37 -0700915 for (const auto &field : *mFields) {
916 if (!field->type().needsResolveReferences()) {
917 continue;
918 }
919
920 field->type().emitResolveReferencesEmbedded(
921 out,
922 0 /* depth */,
Yifan Hong244e82d2016-11-11 11:13:57 -0800923 nameDeref + field->name(),
Yifan Hongbf459bc2016-08-23 16:50:37 -0700924 field->name() /* sanitizedName */,
925 false, // nameIsPointer
926 "parcel", // const std::string &parcelObj,
927 !isReader, // bool parcelObjIsPointer,
928 isReader, // bool isReader,
929 ErrorMode_Return,
Yifan Hong00f47172016-09-30 14:40:45 -0700930 parentHandleName + error,
931 parentOffsetName
932 + " + offsetof("
Yifan Hongbf459bc2016-08-23 16:50:37 -0700933 + fullName()
934 + ", "
935 + field->name()
Yifan Hong00f47172016-09-30 14:40:45 -0700936 + ")"
937 + error);
Yifan Hongbf459bc2016-08-23 16:50:37 -0700938 }
939
Yifan Hongbf459bc2016-08-23 16:50:37 -0700940 out << "return _hidl_err;\n";
941
942 out.unindent();
943 out << "}\n\n";
944}
945
Andreas Huber881227d2016-08-02 14:20:21 -0700946bool CompoundType::needsEmbeddedReadWrite() const {
947 if (mStyle != STYLE_STRUCT) {
948 return false;
949 }
950
951 for (const auto &field : *mFields) {
952 if (field->type().needsEmbeddedReadWrite()) {
953 return true;
954 }
955 }
956
957 return false;
958}
959
Yifan Hongbf459bc2016-08-23 16:50:37 -0700960bool CompoundType::needsResolveReferences() const {
961 if (mStyle != STYLE_STRUCT) {
962 return false;
963 }
964
965 for (const auto &field : *mFields) {
966 if (field->type().needsResolveReferences()) {
967 return true;
968 }
969 }
970
971 return false;
972}
973
Andreas Huber881227d2016-08-02 14:20:21 -0700974bool CompoundType::resultNeedsDeref() const {
975 return true;
976}
977
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700978status_t CompoundType::emitVtsTypeDeclarations(Formatter &out) const {
Zhuoyao Zhangbf828c82016-10-26 14:15:10 -0700979 out << "name: \"" << fullName() << "\"\n";
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700980 out << "type: " << getVtsType() << "\n";
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700981
982 // Emit declaration for each subtype.
983 for (const auto &type : getSubTypes()) {
984 switch (mStyle) {
985 case STYLE_STRUCT:
986 {
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700987 out << "sub_struct: {\n";
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700988 break;
989 }
990 case STYLE_UNION:
991 {
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700992 out << "sub_union: {\n";
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700993 break;
994 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700995 }
996 out.indent();
997 status_t status(type->emitVtsTypeDeclarations(out));
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700998 if (status != OK) {
999 return status;
1000 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -07001001 out.unindent();
1002 out << "}\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -07001003 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -07001004
1005 // Emit declaration for each field.
1006 for (const auto &field : *mFields) {
1007 switch (mStyle) {
1008 case STYLE_STRUCT:
1009 {
1010 out << "struct_value: {\n";
1011 break;
1012 }
1013 case STYLE_UNION:
1014 {
1015 out << "union_value: {\n";
1016 break;
1017 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -07001018 }
1019 out.indent();
1020 out << "name: \"" << field->name() << "\"\n";
1021 status_t status = field->type().emitVtsAttributeType(out);
1022 if (status != OK) {
1023 return status;
1024 }
1025 out.unindent();
1026 out << "}\n";
1027 }
Zhuoyao Zhang5158db42016-08-10 10:25:20 -07001028
1029 return OK;
1030}
1031
Zhuoyao Zhang864c7712016-08-16 15:35:28 -07001032status_t CompoundType::emitVtsAttributeType(Formatter &out) const {
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -07001033 out << "type: " << getVtsType() << "\n";
Zhuoyao Zhangbf828c82016-10-26 14:15:10 -07001034 out << "predefined_type: \"" << fullName() << "\"\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -07001035 return OK;
1036}
1037
Andreas Huber70a59e12016-08-16 12:57:01 -07001038bool CompoundType::isJavaCompatible() const {
Andreas Huber0fa9e392016-08-31 09:05:44 -07001039 if (mStyle != STYLE_STRUCT || !Scope::isJavaCompatible()) {
1040 return false;
1041 }
1042
1043 for (const auto &field : *mFields) {
1044 if (!field->type().isJavaCompatible()) {
1045 return false;
1046 }
1047 }
1048
1049 return true;
Andreas Huber85eabdb2016-08-25 11:24:49 -07001050}
1051
1052void CompoundType::getAlignmentAndSize(size_t *align, size_t *size) const {
1053 *align = 1;
1054
1055 size_t offset = 0;
1056 for (const auto &field : *mFields) {
1057 // Each field is aligned according to its alignment requirement.
1058 // The surrounding structure's alignment is the maximum of its
1059 // fields' aligments.
1060
1061 size_t fieldAlign, fieldSize;
1062 field->type().getAlignmentAndSize(&fieldAlign, &fieldSize);
1063
1064 size_t pad = offset % fieldAlign;
1065 if (pad > 0) {
1066 offset += fieldAlign - pad;
1067 }
1068
1069 offset += fieldSize;
1070
1071 if (fieldAlign > (*align)) {
1072 *align = fieldAlign;
1073 }
1074 }
1075
1076 // Final padding to account for the structure's alignment.
1077 size_t pad = offset % (*align);
1078 if (pad > 0) {
1079 offset += (*align) - pad;
1080 }
1081
1082 *size = offset;
Andreas Huberca4bc892017-01-09 14:58:12 -08001083
1084 if (*size == 0) {
1085 // An empty struct still occupies a byte of space in C++.
1086 *size = 1;
1087 }
Andreas Huber70a59e12016-08-16 12:57:01 -07001088}
1089
Andreas Huber31629bc2016-08-03 09:06:40 -07001090////////////////////////////////////////////////////////////////////////////////
1091
1092CompoundField::CompoundField(const char *name, Type *type)
1093 : mName(name),
1094 mType(type) {
1095}
1096
1097std::string CompoundField::name() const {
1098 return mName;
1099}
1100
1101const Type &CompoundField::type() const {
1102 return *mType;
1103}
1104
Andreas Huberc9410c72016-07-28 12:18:40 -07001105} // namespace android
1106