blob: 55c55688d2c4e4834a62bf8e7423edac37c8a11d [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();
Yifan Hong2593f182017-03-27 12:59:54 -0700585 // Though class is final, we use getClass instead of instanceof to be explicit.
586 out.sIf("otherObject.getClass() != " + fullJavaName() + ".class", [&] {
Yifan Hong7d1839f2017-02-22 13:24:29 -0800587 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) {
Yifan Hong2593f182017-03-27 12:59:54 -0700591 std::string condition = (field->type().isScalar() || field->type().isEnum())
Yifan Hongec102272016-12-20 18:10:07 -0800592 ? "this." + field->name() + " != other." + field->name()
Yifan Hong2593f182017-03-27 12:59:54 -0700593 : ("!android.os.HidlSupport.deepEquals(this." + field->name()
Yifan Hongec102272016-12-20 18:10:07 -0800594 + ", 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, [&] {
Yifan Hong7d234ea2017-03-30 15:40:22 -0700606 out.join(mFields->begin(), mFields->end(), ", \n", [&] (const auto &field) {
Yifan Hong2593f182017-03-27 12:59:54 -0700607 out << "android.os.HidlSupport.deepHashCode(this." << field->name() << ")";
Yifan Hong7d234ea2017-03-30 15:40:22 -0700608 });
Yifan Hong7d1839f2017-02-22 13:24:29 -0800609 });
Yifan Hongec102272016-12-20 18:10:07 -0800610 out << ");\n";
611 }).endl().endl();
Yifan Hong42c68432017-03-13 16:22:03 -0700612 } else {
613 out << "// equals() is not generated for " << localName() << "\n";
Yifan Hongec102272016-12-20 18:10:07 -0800614 }
615
616 ////////////////////////////////////////////////////////////////////////////
617
Yifan Honge45b5302017-02-22 10:49:07 -0800618 out << "@Override\npublic final String toString() ";
619 out.block([&] {
620 out << "java.lang.StringBuilder builder = new java.lang.StringBuilder();\n"
621 << "builder.append(\"{\");\n";
622 for (const auto &field : *mFields) {
623 out << "builder.append(\"";
624 if (field != *(mFields->begin())) {
625 out << ", ";
626 }
627 out << "." << field->name() << " = \");\n";
628 field->type().emitJavaDump(out, "builder", "this." + field->name());
629 }
630 out << "builder.append(\"}\");\nreturn builder.toString();\n";
631 }).endl().endl();
632
633 ////////////////////////////////////////////////////////////////////////////
634
Yifan Hong1af73532016-11-09 14:32:58 -0800635 out << "public final void readFromParcel(android.os.HwParcel parcel) {\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700636 out.indent();
Yifan Hong1af73532016-11-09 14:32:58 -0800637 out << "android.os.HwBlob blob = parcel.readBuffer();\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700638 out << "readEmbeddedFromParcel(parcel, blob, 0 /* parentOffset */);\n";
639 out.unindent();
640 out << "}\n\n";
641
Andreas Huberf630bc82016-09-09 14:52:25 -0700642 ////////////////////////////////////////////////////////////////////////////
643
Yifan Hong1af73532016-11-09 14:32:58 -0800644 out << "public static final java.util.ArrayList<"
Andreas Huberf630bc82016-09-09 14:52:25 -0700645 << localName()
Yifan Hong1af73532016-11-09 14:32:58 -0800646 << "> readVectorFromParcel(android.os.HwParcel parcel) {\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700647 out.indent();
648
Yifan Hong1af73532016-11-09 14:32:58 -0800649 out << "java.util.ArrayList<"
Andreas Huberf630bc82016-09-09 14:52:25 -0700650 << localName()
Yifan Hong1af73532016-11-09 14:32:58 -0800651 << "> _hidl_vec = new java.util.ArrayList();\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700652
Yifan Hong1af73532016-11-09 14:32:58 -0800653 out << "android.os.HwBlob _hidl_blob = parcel.readBuffer();\n\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700654
655 VectorType::EmitJavaFieldReaderWriterForElementType(
Andreas Huber4c865b72016-09-14 15:26:27 -0700656 out,
657 0 /* depth */,
658 this,
Andreas Huber709b62d2016-09-19 11:21:18 -0700659 "parcel",
Andreas Huber4c865b72016-09-14 15:26:27 -0700660 "_hidl_blob",
661 "_hidl_vec",
662 "0",
663 true /* isReader */);
Andreas Huberf630bc82016-09-09 14:52:25 -0700664
Andreas Huber1b6822b2016-10-18 09:28:40 -0700665 out << "\nreturn _hidl_vec;\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700666
667 out.unindent();
668 out << "}\n\n";
669
670 ////////////////////////////////////////////////////////////////////////////
671
Andreas Huber85eabdb2016-08-25 11:24:49 -0700672 out << "public final void readEmbeddedFromParcel(\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700673 out.indent(2);
Yifan Hong1af73532016-11-09 14:32:58 -0800674 out << "android.os.HwParcel parcel, android.os.HwBlob _hidl_blob, long _hidl_offset) {\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700675 out.unindent();
676
677 size_t offset = 0;
678 for (const auto &field : *mFields) {
679 size_t fieldAlign, fieldSize;
680 field->type().getAlignmentAndSize(&fieldAlign, &fieldSize);
681
682 size_t pad = offset % fieldAlign;
683 if (pad > 0) {
684 offset += fieldAlign - pad;
685 }
686
687 field->type().emitJavaFieldReaderWriter(
688 out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700689 0 /* depth */,
Andreas Huber709b62d2016-09-19 11:21:18 -0700690 "parcel",
Andreas Huber85eabdb2016-08-25 11:24:49 -0700691 "_hidl_blob",
692 field->name(),
693 "_hidl_offset + " + std::to_string(offset),
694 true /* isReader */);
695
696 offset += fieldSize;
697 }
698
699 out.unindent();
700 out << "}\n\n";
701
Andreas Huberf630bc82016-09-09 14:52:25 -0700702 ////////////////////////////////////////////////////////////////////////////
703
Andreas Huber709b62d2016-09-19 11:21:18 -0700704 size_t structAlign, structSize;
705 getAlignmentAndSize(&structAlign, &structSize);
706
Yifan Hong1af73532016-11-09 14:32:58 -0800707 out << "public final void writeToParcel(android.os.HwParcel parcel) {\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700708 out.indent();
709
Yifan Hong1af73532016-11-09 14:32:58 -0800710 out << "android.os.HwBlob _hidl_blob = new android.os.HwBlob("
Andreas Huber85eabdb2016-08-25 11:24:49 -0700711 << structSize
712 << " /* size */);\n";
713
714 out << "writeEmbeddedToBlob(_hidl_blob, 0 /* parentOffset */);\n"
715 << "parcel.writeBuffer(_hidl_blob);\n";
716
717 out.unindent();
718 out << "}\n\n";
719
Andreas Huberf630bc82016-09-09 14:52:25 -0700720 ////////////////////////////////////////////////////////////////////////////
721
Andreas Huberf630bc82016-09-09 14:52:25 -0700722 out << "public static final void writeVectorToParcel(\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700723 out.indent(2);
Yifan Hong1af73532016-11-09 14:32:58 -0800724 out << "android.os.HwParcel parcel, java.util.ArrayList<"
Andreas Huberf630bc82016-09-09 14:52:25 -0700725 << localName()
Andreas Huber1b6822b2016-10-18 09:28:40 -0700726 << "> _hidl_vec) {\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700727 out.unindent();
728
Yifan Hong1af73532016-11-09 14:32:58 -0800729 out << "android.os.HwBlob _hidl_blob = new android.os.HwBlob(24 /* sizeof(hidl_vec<T>) */);\n";
Andreas Huberf630bc82016-09-09 14:52:25 -0700730
731 VectorType::EmitJavaFieldReaderWriterForElementType(
Andreas Huber4c865b72016-09-14 15:26:27 -0700732 out,
733 0 /* depth */,
734 this,
Andreas Huber709b62d2016-09-19 11:21:18 -0700735 "parcel",
Andreas Huber4c865b72016-09-14 15:26:27 -0700736 "_hidl_blob",
737 "_hidl_vec",
738 "0",
739 false /* isReader */);
Andreas Huberf630bc82016-09-09 14:52:25 -0700740
741 out << "\nparcel.writeBuffer(_hidl_blob);\n";
742
743 out.unindent();
744 out << "}\n\n";
745
746 ////////////////////////////////////////////////////////////////////////////
747
Andreas Huber85eabdb2016-08-25 11:24:49 -0700748 out << "public final void writeEmbeddedToBlob(\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700749 out.indent(2);
Yifan Hong1af73532016-11-09 14:32:58 -0800750 out << "android.os.HwBlob _hidl_blob, long _hidl_offset) {\n";
Andreas Huber85eabdb2016-08-25 11:24:49 -0700751 out.unindent();
752
753 offset = 0;
754 for (const auto &field : *mFields) {
755 size_t fieldAlign, fieldSize;
756 field->type().getAlignmentAndSize(&fieldAlign, &fieldSize);
757
758 size_t pad = offset % fieldAlign;
759 if (pad > 0) {
760 offset += fieldAlign - pad;
761 }
762
763 field->type().emitJavaFieldReaderWriter(
764 out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700765 0 /* depth */,
Andreas Huber709b62d2016-09-19 11:21:18 -0700766 "parcel",
Andreas Huber85eabdb2016-08-25 11:24:49 -0700767 "_hidl_blob",
768 field->name(),
769 "_hidl_offset + " + std::to_string(offset),
770 false /* isReader */);
771
772 offset += fieldSize;
773 }
774
775 out.unindent();
776 out << "}\n";
777
778 out.unindent();
779 out << "};\n\n";
780
781 return OK;
782}
783
Andreas Huber881227d2016-08-02 14:20:21 -0700784void CompoundType::emitStructReaderWriter(
785 Formatter &out, const std::string &prefix, bool isReader) const {
Yifan Hong244e82d2016-11-11 11:13:57 -0800786
787 std::string space = prefix.empty() ? "" : (prefix + "::");
788
Andreas Huber881227d2016-08-02 14:20:21 -0700789 out << "::android::status_t "
Yifan Hong244e82d2016-11-11 11:13:57 -0800790 << (isReader ? "readEmbeddedFromParcel"
791 : "writeEmbeddedToParcel")
792 << "(\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700793
Yifan Hong0a68a282016-10-21 16:32:34 -0700794 out.indent(2);
Andreas Huber881227d2016-08-02 14:20:21 -0700795
Yifan Hong244e82d2016-11-11 11:13:57 -0800796 bool useName = false;
797 for (const auto &field : *mFields) {
798 if (field->type().useNameInEmitReaderWriterEmbedded(isReader)) {
799 useName = true;
800 break;
801 }
802 }
803 std::string name = useName ? "obj" : "/* obj */";
804 // if not useName, then obj should not be used at all,
805 // then the #error should not be emitted.
806 std::string error = useName ? "" : "\n#error\n";
807
Andreas Huber881227d2016-08-02 14:20:21 -0700808 if (isReader) {
Yifan Hong244e82d2016-11-11 11:13:57 -0800809 out << space << localName() << " *" << name << ",\n";
Andreas Huber8a82ff72016-08-04 10:29:39 -0700810 out << "const ::android::hardware::Parcel &parcel,\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700811 } else {
Yifan Hong244e82d2016-11-11 11:13:57 -0800812 out << "const " << space << localName() << " &" << name << ",\n";
Andreas Huber8a82ff72016-08-04 10:29:39 -0700813 out << "::android::hardware::Parcel *parcel,\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700814 }
815
816 out << "size_t parentHandle,\n"
817 << "size_t parentOffset)";
818
Andreas Huber881227d2016-08-02 14:20:21 -0700819 out << " {\n";
820
Yifan Hong0a68a282016-10-21 16:32:34 -0700821 out.unindent(2);
Andreas Huber881227d2016-08-02 14:20:21 -0700822 out.indent();
823
Iliyan Malchev549e2592016-08-10 08:59:12 -0700824 out << "::android::status_t _hidl_err = ::android::OK;\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700825
826 for (const auto &field : *mFields) {
827 if (!field->type().needsEmbeddedReadWrite()) {
828 continue;
829 }
830
831 field->type().emitReaderWriterEmbedded(
832 out,
Andreas Huberf9d49f12016-09-12 14:58:36 -0700833 0 /* depth */,
Yifan Hong244e82d2016-11-11 11:13:57 -0800834 name + (isReader ? "->" : ".") + field->name() + error,
Yifan Hongbe2a3732016-10-05 13:33:41 -0700835 field->name() /* sanitizedName */,
Andreas Huber881227d2016-08-02 14:20:21 -0700836 false /* nameIsPointer */,
837 "parcel",
838 !isReader /* parcelObjIsPointer */,
839 isReader,
Andreas Huber737080b2016-08-02 15:38:04 -0700840 ErrorMode_Return,
Andreas Huber881227d2016-08-02 14:20:21 -0700841 "parentHandle",
Andreas Huber0e00de42016-08-03 09:56:02 -0700842 "parentOffset + offsetof("
843 + fullName()
844 + ", "
845 + field->name()
846 + ")");
Andreas Huber881227d2016-08-02 14:20:21 -0700847 }
848
Iliyan Malchev549e2592016-08-10 08:59:12 -0700849 out << "return _hidl_err;\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700850
851 out.unindent();
852 out << "}\n\n";
853}
854
Yifan Hongbf459bc2016-08-23 16:50:37 -0700855void CompoundType::emitResolveReferenceDef(
856 Formatter &out, const std::string prefix, bool isReader) const {
Yifan Hong244e82d2016-11-11 11:13:57 -0800857 out << "::android::status_t ";
858 const std::string space(prefix.empty() ? "" : (prefix + "::"));
Yifan Hong00f47172016-09-30 14:40:45 -0700859
860 bool useParent = false;
861 for (const auto &field : *mFields) {
862 if (field->type().useParentInEmitResolveReferencesEmbedded()) {
863 useParent = true;
864 break;
865 }
866 }
867
868 std::string parentHandleName = useParent ? "parentHandle" : "/* parentHandle */";
869 std::string parentOffsetName = useParent ? "parentOffset" : "/* parentOffset */";
870
Yifan Hongbf459bc2016-08-23 16:50:37 -0700871 if (isReader) {
Yifan Hong244e82d2016-11-11 11:13:57 -0800872 out << "readEmbeddedReferenceFromParcel(\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700873 out.indent(2);
Yifan Hong244e82d2016-11-11 11:13:57 -0800874 out << space + localName() + " *obj,\n"
875 << "const ::android::hardware::Parcel &parcel,\n"
Yifan Hong00f47172016-09-30 14:40:45 -0700876 << "size_t " << parentHandleName << ", "
877 << "size_t " << parentOffsetName << ")\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700878 out.unindent(2);
Yifan Hongbf459bc2016-08-23 16:50:37 -0700879 } else {
Yifan Hong244e82d2016-11-11 11:13:57 -0800880 out << "writeEmbeddedReferenceToParcel(\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700881 out.indent(2);
Yifan Hong244e82d2016-11-11 11:13:57 -0800882 out << "const " << space + localName() + " &obj,\n"
883 << "::android::hardware::Parcel *parcel,\n"
Yifan Hong00f47172016-09-30 14:40:45 -0700884 << "size_t " << parentHandleName << ", "
Yifan Hong244e82d2016-11-11 11:13:57 -0800885 << "size_t " << parentOffsetName << ")\n";
Yifan Hong0a68a282016-10-21 16:32:34 -0700886 out.unindent(2);
Yifan Hongbf459bc2016-08-23 16:50:37 -0700887 }
888
889 out << " {\n";
890
891 out.indent();
892
893 out << "::android::status_t _hidl_err = ::android::OK;\n\n";
894
Yifan Hong244e82d2016-11-11 11:13:57 -0800895 const std::string nameDeref(isReader ? "obj->" : "obj.");
Yifan Hong00f47172016-09-30 14:40:45 -0700896 // if not useParent, then parentName and offsetText
897 // should not be used at all, then the #error should not be emitted.
898 std::string error = useParent ? "" : "\n#error\n";
899
Yifan Hongbf459bc2016-08-23 16:50:37 -0700900 for (const auto &field : *mFields) {
901 if (!field->type().needsResolveReferences()) {
902 continue;
903 }
904
905 field->type().emitResolveReferencesEmbedded(
906 out,
907 0 /* depth */,
Yifan Hong244e82d2016-11-11 11:13:57 -0800908 nameDeref + field->name(),
Yifan Hongbf459bc2016-08-23 16:50:37 -0700909 field->name() /* sanitizedName */,
910 false, // nameIsPointer
911 "parcel", // const std::string &parcelObj,
912 !isReader, // bool parcelObjIsPointer,
913 isReader, // bool isReader,
914 ErrorMode_Return,
Yifan Hong00f47172016-09-30 14:40:45 -0700915 parentHandleName + error,
916 parentOffsetName
917 + " + offsetof("
Yifan Hongbf459bc2016-08-23 16:50:37 -0700918 + fullName()
919 + ", "
920 + field->name()
Yifan Hong00f47172016-09-30 14:40:45 -0700921 + ")"
922 + error);
Yifan Hongbf459bc2016-08-23 16:50:37 -0700923 }
924
Yifan Hongbf459bc2016-08-23 16:50:37 -0700925 out << "return _hidl_err;\n";
926
927 out.unindent();
928 out << "}\n\n";
929}
930
Andreas Huber881227d2016-08-02 14:20:21 -0700931bool CompoundType::needsEmbeddedReadWrite() const {
932 if (mStyle != STYLE_STRUCT) {
933 return false;
934 }
935
936 for (const auto &field : *mFields) {
937 if (field->type().needsEmbeddedReadWrite()) {
938 return true;
939 }
940 }
941
942 return false;
943}
944
Yifan Hongbf459bc2016-08-23 16:50:37 -0700945bool CompoundType::needsResolveReferences() const {
946 if (mStyle != STYLE_STRUCT) {
947 return false;
948 }
949
950 for (const auto &field : *mFields) {
951 if (field->type().needsResolveReferences()) {
952 return true;
953 }
954 }
955
956 return false;
957}
958
Andreas Huber881227d2016-08-02 14:20:21 -0700959bool CompoundType::resultNeedsDeref() const {
960 return true;
961}
962
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700963status_t CompoundType::emitVtsTypeDeclarations(Formatter &out) const {
Zhuoyao Zhangbf828c82016-10-26 14:15:10 -0700964 out << "name: \"" << fullName() << "\"\n";
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700965 out << "type: " << getVtsType() << "\n";
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700966
967 // Emit declaration for each subtype.
968 for (const auto &type : getSubTypes()) {
969 switch (mStyle) {
970 case STYLE_STRUCT:
971 {
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700972 out << "sub_struct: {\n";
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700973 break;
974 }
975 case STYLE_UNION:
976 {
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700977 out << "sub_union: {\n";
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700978 break;
979 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700980 }
981 out.indent();
982 status_t status(type->emitVtsTypeDeclarations(out));
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700983 if (status != OK) {
984 return status;
985 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700986 out.unindent();
987 out << "}\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700988 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700989
990 // Emit declaration for each field.
991 for (const auto &field : *mFields) {
992 switch (mStyle) {
993 case STYLE_STRUCT:
994 {
995 out << "struct_value: {\n";
996 break;
997 }
998 case STYLE_UNION:
999 {
1000 out << "union_value: {\n";
1001 break;
1002 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -07001003 }
1004 out.indent();
1005 out << "name: \"" << field->name() << "\"\n";
1006 status_t status = field->type().emitVtsAttributeType(out);
1007 if (status != OK) {
1008 return status;
1009 }
1010 out.unindent();
1011 out << "}\n";
1012 }
Zhuoyao Zhang5158db42016-08-10 10:25:20 -07001013
1014 return OK;
1015}
1016
Zhuoyao Zhang864c7712016-08-16 15:35:28 -07001017status_t CompoundType::emitVtsAttributeType(Formatter &out) const {
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -07001018 out << "type: " << getVtsType() << "\n";
Zhuoyao Zhangbf828c82016-10-26 14:15:10 -07001019 out << "predefined_type: \"" << fullName() << "\"\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -07001020 return OK;
1021}
1022
Andreas Huber70a59e12016-08-16 12:57:01 -07001023bool CompoundType::isJavaCompatible() const {
Andreas Huber0fa9e392016-08-31 09:05:44 -07001024 if (mStyle != STYLE_STRUCT || !Scope::isJavaCompatible()) {
1025 return false;
1026 }
1027
1028 for (const auto &field : *mFields) {
1029 if (!field->type().isJavaCompatible()) {
1030 return false;
1031 }
1032 }
1033
1034 return true;
Andreas Huber85eabdb2016-08-25 11:24:49 -07001035}
1036
1037void CompoundType::getAlignmentAndSize(size_t *align, size_t *size) const {
1038 *align = 1;
1039
1040 size_t offset = 0;
1041 for (const auto &field : *mFields) {
1042 // Each field is aligned according to its alignment requirement.
1043 // The surrounding structure's alignment is the maximum of its
1044 // fields' aligments.
1045
1046 size_t fieldAlign, fieldSize;
1047 field->type().getAlignmentAndSize(&fieldAlign, &fieldSize);
1048
1049 size_t pad = offset % fieldAlign;
1050 if (pad > 0) {
1051 offset += fieldAlign - pad;
1052 }
1053
1054 offset += fieldSize;
1055
1056 if (fieldAlign > (*align)) {
1057 *align = fieldAlign;
1058 }
1059 }
1060
1061 // Final padding to account for the structure's alignment.
1062 size_t pad = offset % (*align);
1063 if (pad > 0) {
1064 offset += (*align) - pad;
1065 }
1066
1067 *size = offset;
Andreas Huberca4bc892017-01-09 14:58:12 -08001068
1069 if (*size == 0) {
1070 // An empty struct still occupies a byte of space in C++.
1071 *size = 1;
1072 }
Andreas Huber70a59e12016-08-16 12:57:01 -07001073}
1074
Andreas Huber31629bc2016-08-03 09:06:40 -07001075////////////////////////////////////////////////////////////////////////////////
1076
1077CompoundField::CompoundField(const char *name, Type *type)
1078 : mName(name),
1079 mType(type) {
1080}
1081
1082std::string CompoundField::name() const {
1083 return mName;
1084}
1085
1086const Type &CompoundField::type() const {
1087 return *mType;
1088}
1089
Andreas Huberc9410c72016-07-28 12:18:40 -07001090} // namespace android
1091