blob: d636a2bdcbfd099e7878d14e9e4fb58977c77743 [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 "EnumType.h"
18
Andreas Huber019d21d2016-10-03 12:59:47 -070019#include "Annotation.h"
Andreas Huber881227d2016-08-02 14:20:21 -070020#include "ScalarType.h"
Andreas Huberc9410c72016-07-28 12:18:40 -070021
Iliyan Malcheva72e0d22016-09-09 11:03:08 -070022#include <inttypes.h>
23#include <hidl-util/Formatter.h>
Andreas Huber737080b2016-08-02 15:38:04 -070024#include <android-base/logging.h>
25
Andreas Huberc9410c72016-07-28 12:18:40 -070026namespace android {
27
Andreas Huberc9410c72016-07-28 12:18:40 -070028EnumType::EnumType(
Andreas Huber9ed827c2016-08-22 12:31:13 -070029 const char *localName,
Yifan Honga4b53d02016-10-31 17:29:10 -070030 const Location &location,
Andreas Huber9ed827c2016-08-22 12:31:13 -070031 Type *storageType)
Yifan Honga4b53d02016-10-31 17:29:10 -070032 : Scope(localName, location),
Yifan Hongf24fa852016-09-23 11:03:15 -070033 mValues(),
Steven Moreland1c71fd52016-11-29 14:03:33 -080034 mStorageType(storageType) {
Andreas Huberc9410c72016-07-28 12:18:40 -070035}
36
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070037const Type *EnumType::storageType() const {
38 return mStorageType;
39}
40
41const std::vector<EnumValue *> &EnumType::values() const {
Yifan Hongf24fa852016-09-23 11:03:15 -070042 return mValues;
43}
44
45void EnumType::addValue(EnumValue *value) {
46 CHECK(value != nullptr);
47
48 EnumValue *prev = nullptr;
49 std::vector<const EnumType *> chain;
50 getTypeChain(&chain);
51 for (auto it = chain.begin(); it != chain.end(); ++it) {
52 const auto &type = *it;
53 if(!type->values().empty()) {
54 prev = type->values().back();
55 break;
56 }
57 }
58
59 value->autofill(prev, resolveToScalarType());
60 mValues.push_back(value);
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070061}
62
Andreas Huber737080b2016-08-02 15:38:04 -070063const ScalarType *EnumType::resolveToScalarType() const {
64 return mStorageType->resolveToScalarType();
65}
66
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070067bool EnumType::isEnum() const {
68 return true;
69}
70
Steven Moreland979e0992016-09-07 09:18:08 -070071std::string EnumType::getCppType(StorageMode,
Steven Moreland979e0992016-09-07 09:18:08 -070072 bool specifyNamespaces) const {
Steven Moreland979e0992016-09-07 09:18:08 -070073 return specifyNamespaces ? fullName() : partialCppName();
Andreas Huber881227d2016-08-02 14:20:21 -070074}
75
Yifan Hong4ed13472016-11-02 10:44:11 -070076std::string EnumType::getJavaType(bool forInitializer) const {
77 return mStorageType->resolveToScalarType()->getJavaType(forInitializer);
Andreas Huber2831d512016-08-15 09:33:47 -070078}
79
80std::string EnumType::getJavaSuffix() const {
81 return mStorageType->resolveToScalarType()->getJavaSuffix();
82}
83
Andreas Hubera3558b32016-09-14 09:12:42 -070084std::string EnumType::getJavaWrapperType() const {
85 return mStorageType->resolveToScalarType()->getJavaWrapperType();
86}
87
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070088std::string EnumType::getVtsType() const {
89 return "TYPE_ENUM";
90}
91
Yifan Hongf24fa852016-09-23 11:03:15 -070092LocalIdentifier *EnumType::lookupIdentifier(const std::string &name) const {
93 std::vector<const EnumType *> chain;
94 getTypeChain(&chain);
95 for (auto it = chain.begin(); it != chain.end(); ++it) {
96 const auto &type = *it;
97 for(EnumValue *v : type->values()) {
98 if(v->name() == name) {
99 return v;
100 }
101 }
102 }
103 return nullptr;
104}
105
Andreas Huber881227d2016-08-02 14:20:21 -0700106void EnumType::emitReaderWriter(
107 Formatter &out,
108 const std::string &name,
109 const std::string &parcelObj,
110 bool parcelObjIsPointer,
111 bool isReader,
112 ErrorMode mode) const {
Andreas Huber737080b2016-08-02 15:38:04 -0700113 const ScalarType *scalarType = mStorageType->resolveToScalarType();
114 CHECK(scalarType != NULL);
115
116 scalarType->emitReaderWriterWithCast(
117 out,
118 name,
119 parcelObj,
120 parcelObjIsPointer,
121 isReader,
122 mode,
123 true /* needsCast */);
Andreas Huber881227d2016-08-02 14:20:21 -0700124}
125
Andreas Huber85eabdb2016-08-25 11:24:49 -0700126void EnumType::emitJavaFieldReaderWriter(
127 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700128 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700129 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700130 const std::string &blobName,
131 const std::string &fieldName,
132 const std::string &offset,
133 bool isReader) const {
134 return mStorageType->emitJavaFieldReaderWriter(
Andreas Huber709b62d2016-09-19 11:21:18 -0700135 out, depth, parcelName, blobName, fieldName, offset, isReader);
Andreas Huber85eabdb2016-08-25 11:24:49 -0700136}
137
Andreas Huber881227d2016-08-02 14:20:21 -0700138status_t EnumType::emitTypeDeclarations(Formatter &out) const {
Andreas Huber737080b2016-08-02 15:38:04 -0700139 const ScalarType *scalarType = mStorageType->resolveToScalarType();
Andreas Hubere3f769a2016-10-10 10:54:44 -0700140 CHECK(scalarType != nullptr);
Andreas Huber737080b2016-08-02 15:38:04 -0700141
Yifan Hong3b320f82016-11-01 15:15:54 -0700142 const std::string storageType = scalarType->getCppStackType();
Andreas Huber881227d2016-08-02 14:20:21 -0700143
144 out << "enum class "
Andreas Huber0e00de42016-08-03 09:56:02 -0700145 << localName()
Andreas Huber881227d2016-08-02 14:20:21 -0700146 << " : "
Andreas Hubere3f769a2016-10-10 10:54:44 -0700147 << storageType
Andreas Huber881227d2016-08-02 14:20:21 -0700148 << " {\n";
149
150 out.indent();
151
Andreas Huber8d3ac0c2016-08-04 14:49:23 -0700152 std::vector<const EnumType *> chain;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700153 getTypeChain(&chain);
Andreas Huber8d3ac0c2016-08-04 14:49:23 -0700154
155 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
156 const auto &type = *it;
157
158 for (const auto &entry : type->values()) {
159 out << entry->name();
160
Yifan Hongfc610cd2016-09-22 13:34:45 -0700161 std::string value = entry->cppValue(scalarType->getKind());
Yifan Hongf24fa852016-09-23 11:03:15 -0700162 CHECK(!value.empty()); // use autofilled values for c++.
163 out << " = " << value;
Andreas Huber8d3ac0c2016-08-04 14:49:23 -0700164
Yifan Hong57886972016-08-17 10:42:15 -0700165 out << ",";
166
Yifan Hongfc610cd2016-09-22 13:34:45 -0700167 std::string comment = entry->comment();
168 if (!comment.empty() && comment != value) {
Yifan Hong57886972016-08-17 10:42:15 -0700169 out << " // " << comment;
170 }
171
172 out << "\n";
Andreas Huber8d3ac0c2016-08-04 14:49:23 -0700173 }
Andreas Huber881227d2016-08-02 14:20:21 -0700174 }
175
176 out.unindent();
177 out << "};\n\n";
178
179 return OK;
180}
181
Jayant Chowdhary2820f8a2016-11-10 12:29:09 -0800182void EnumType::emitEnumBitwiseOperator(
183 Formatter &out,
184 bool mutating,
185 const std::string &op) const {
Andreas Hubere3f769a2016-10-10 10:54:44 -0700186 const ScalarType *scalarType = mStorageType->resolveToScalarType();
187 CHECK(scalarType != nullptr);
188
Yifan Hong3b320f82016-11-01 15:15:54 -0700189 const std::string storageType = scalarType->getCppStackType();
Andreas Hubere3f769a2016-10-10 10:54:44 -0700190
191 out << "inline "
Jayant Chowdhary2820f8a2016-11-10 12:29:09 -0800192 << (mutating ? fullName() : storageType)
Andreas Hubere3f769a2016-10-10 10:54:44 -0700193 << (mutating ? " &" : "")
Jayant Chowdhary2820f8a2016-11-10 12:29:09 -0800194 << " operator"
195 << op
Andreas Hubere3f769a2016-10-10 10:54:44 -0700196 << (mutating ? "=" : "")
197 << "(\n";
198
199 out.indent();
200 out.indent();
201
202 out << fullName()
203 << (mutating ? " &" : " ")
204 << "lhs, "
205 << fullName()
206 << " rhs) {\n";
207 out.unindent();
208
209 if (mutating) {
210 out << "lhs = ";
211 } else {
212 out << "return ";
213 }
214 out << "static_cast<"
Jayant Chowdhary2820f8a2016-11-10 12:29:09 -0800215 << (mutating ? fullName() : storageType)
Andreas Hubere3f769a2016-10-10 10:54:44 -0700216 << ">(\n";
217 out.indent();
218 out.indent();
219 out << "static_cast<"
220 << storageType
Jayant Chowdhary2820f8a2016-11-10 12:29:09 -0800221 << ">(lhs) "
222 << op
223 <<" static_cast<"
Andreas Hubere3f769a2016-10-10 10:54:44 -0700224 << storageType
225 << ">(rhs));\n";
226 out.unindent();
227 out.unindent();
228
229 if (mutating) {
230 out << "return lhs;\n";
231 }
232
233 out.unindent();
234
235 out << "}\n\n";
236}
237
238status_t EnumType::emitGlobalTypeDeclarations(Formatter &out) const {
Jayant Chowdhary2820f8a2016-11-10 12:29:09 -0800239 emitEnumBitwiseOperator(out, false /* mutating */, "|");
240 emitEnumBitwiseOperator(out, true /* mutating */, "|");
241 emitEnumBitwiseOperator(out, false /* mutating */, "&");
242 emitEnumBitwiseOperator(out, true /* mutating */, "&");
Andreas Hubere3f769a2016-10-10 10:54:44 -0700243
244 return OK;
245}
246
Andreas Huber85eabdb2016-08-25 11:24:49 -0700247status_t EnumType::emitJavaTypeDeclarations(Formatter &out, bool) const {
Andreas Huber2831d512016-08-15 09:33:47 -0700248 const ScalarType *scalarType = mStorageType->resolveToScalarType();
249 CHECK(scalarType != NULL);
250
251 out << "public final class "
252 << localName()
253 << " {\n";
254
255 out.indent();
256
Andreas Huber4c865b72016-09-14 15:26:27 -0700257 const std::string typeName =
Yifan Hong4ed13472016-11-02 10:44:11 -0700258 scalarType->getJavaType(false /* forInitializer */);
Andreas Huber2831d512016-08-15 09:33:47 -0700259
260 std::vector<const EnumType *> chain;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700261 getTypeChain(&chain);
Andreas Huber2831d512016-08-15 09:33:47 -0700262
263 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
264 const auto &type = *it;
265
266 for (const auto &entry : type->values()) {
267 out << "public static final "
268 << typeName
269 << " "
Andreas Huberab647c02016-09-14 09:44:00 -0700270 << entry->name()
271 << " = ";
Andreas Huber2831d512016-08-15 09:33:47 -0700272
Yifan Hongf24fa852016-09-23 11:03:15 -0700273 // javaValue will make the number signed.
Yifan Hongfc610cd2016-09-22 13:34:45 -0700274 std::string value = entry->javaValue(scalarType->getKind());
Yifan Hongf24fa852016-09-23 11:03:15 -0700275 CHECK(!value.empty()); // use autofilled values for java.
276 out << value;
Andreas Huber2831d512016-08-15 09:33:47 -0700277
Yifan Hong19ca75a2016-08-31 10:20:03 -0700278 out << ";";
279
Yifan Hongfc610cd2016-09-22 13:34:45 -0700280 std::string comment = entry->comment();
281 if (!comment.empty() && comment != value) {
Yifan Hong19ca75a2016-08-31 10:20:03 -0700282 out << " // " << comment;
283 }
284
285 out << "\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700286 }
287 }
288
289 out.unindent();
290 out << "};\n\n";
291
292 return OK;
293}
294
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700295status_t EnumType::emitVtsTypeDeclarations(Formatter &out) const {
Yifan Hongc07b2022016-11-08 12:44:24 -0800296 const ScalarType *scalarType = mStorageType->resolveToScalarType();
297
Zhuoyao Zhangbf828c82016-10-26 14:15:10 -0700298 out << "name: \"" << fullName() << "\"\n";
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700299 out << "type: " << getVtsType() << "\n";
300 out << "enum_value: {\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700301 out.indent();
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700302
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700303 out << "scalar_type: \""
Yifan Hongc07b2022016-11-08 12:44:24 -0800304 << scalarType->getVtsScalarType()
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700305 << "\"\n\n";
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700306 std::vector<const EnumType *> chain;
307 getTypeChain(&chain);
308
309 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
310 const auto &type = *it;
311
312 for (const auto &entry : type->values()) {
313 out << "enumerator: \"" << entry->name() << "\"\n";
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700314 out << "scalar_value: {\n";
315 out.indent();
Yifan Hongc07b2022016-11-08 12:44:24 -0800316 // use autofilled values for vts.
317 std::string value = entry->value(scalarType->getKind());
318 CHECK(!value.empty());
319 out << mStorageType->resolveToScalarType()->getVtsScalarType()
320 << ": "
321 << value
322 << "\n";
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700323 out.unindent();
324 out << "}\n";
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700325 }
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700326 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700327
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700328 out.unindent();
329 out << "}\n";
330 return OK;
331}
332
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700333status_t EnumType::emitVtsAttributeType(Formatter &out) const {
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700334 out << "type: " << getVtsType() << "\n";
Zhuoyao Zhangbf828c82016-10-26 14:15:10 -0700335 out << "predefined_type: \"" << fullName() << "\"\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700336 return OK;
337}
338
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700339void EnumType::getTypeChain(std::vector<const EnumType *> *out) const {
340 out->clear();
341 const EnumType *type = this;
342 for (;;) {
343 out->push_back(type);
344
345 const Type *superType = type->storageType();
346 if (superType == NULL || !superType->isEnum()) {
347 break;
348 }
349
350 type = static_cast<const EnumType *>(superType);
351 }
352}
353
Andreas Huber85eabdb2016-08-25 11:24:49 -0700354void EnumType::getAlignmentAndSize(size_t *align, size_t *size) const {
355 mStorageType->getAlignmentAndSize(align, size);
356}
357
Andreas Huber019d21d2016-10-03 12:59:47 -0700358const Annotation *EnumType::findExportAnnotation() const {
359 for (const auto &annotation : annotations()) {
360 if (annotation->name() == "export") {
361 return annotation;
362 }
363 }
364
365 return nullptr;
366}
367
368void EnumType::appendToExportedTypesVector(
369 std::vector<const Type *> *exportedTypes) const {
370 if (findExportAnnotation() != nullptr) {
371 exportedTypes->push_back(this);
372 }
373}
374
Andreas Huber1c507272016-10-05 14:33:21 -0700375status_t EnumType::emitExportedHeader(Formatter &out, bool forJava) const {
Andreas Huber019d21d2016-10-03 12:59:47 -0700376 const Annotation *annotation = findExportAnnotation();
377 CHECK(annotation != nullptr);
378
379 std::string name = localName();
380
381 const AnnotationParam *nameParam = annotation->getParam("name");
382 if (nameParam != nullptr) {
383 CHECK_EQ(nameParam->getValues()->size(), 1u);
384
385 std::string quotedString = nameParam->getValues()->at(0);
386 name = quotedString.substr(1, quotedString.size() - 2);
387 }
388
Andreas Huberb0627fb2016-10-10 09:39:28 -0700389 std::string valuePrefix;
Andreas Huberb0627fb2016-10-10 09:39:28 -0700390 const AnnotationParam *prefixParam = annotation->getParam("value_prefix");
391 if (prefixParam != nullptr) {
392 CHECK_EQ(prefixParam->getValues()->size(), 1u);
393
394 std::string quotedString = prefixParam->getValues()->at(0);
395 valuePrefix = quotedString.substr(1, quotedString.size() - 2);
396 }
397
Steven Moreland73cdc882016-11-21 16:43:50 -0800398 std::string valueSuffix;
399 const AnnotationParam *suffixParam = annotation->getParam("value_suffix");
400 if (suffixParam != nullptr) {
401 CHECK_EQ(suffixParam->getValues()->size(), 1u);
402
403 std::string quotedString = suffixParam->getValues()->at(0);
404 valueSuffix = quotedString.substr(1, quotedString.size() - 2);
405 }
406
Andreas Huber019d21d2016-10-03 12:59:47 -0700407 const ScalarType *scalarType = mStorageType->resolveToScalarType();
Andreas Huber1c507272016-10-05 14:33:21 -0700408 CHECK(scalarType != nullptr);
Andreas Huber019d21d2016-10-03 12:59:47 -0700409
Andreas Huber1c507272016-10-05 14:33:21 -0700410 if (forJava) {
411 if (!name.empty()) {
412 out << "public final class "
413 << name
414 << " {\n";
415
416 out.indent();
417 } else {
418 out << "// Values declared in " << localName() << " follow.\n";
419 }
420
Andreas Huber1c507272016-10-05 14:33:21 -0700421 const std::string typeName =
Yifan Hong4ed13472016-11-02 10:44:11 -0700422 scalarType->getJavaType(false /* forInitializer */);
Andreas Huber1c507272016-10-05 14:33:21 -0700423
424 std::vector<const EnumType *> chain;
425 getTypeChain(&chain);
426
427 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
428 const auto &type = *it;
429
430 for (const auto &entry : type->values()) {
431 out << "public static final "
432 << typeName
433 << " "
434 << valuePrefix
435 << entry->name()
Steven Moreland73cdc882016-11-21 16:43:50 -0800436 << valueSuffix
Andreas Huber1c507272016-10-05 14:33:21 -0700437 << " = ";
438
439 // javaValue will make the number signed.
440 std::string value = entry->javaValue(scalarType->getKind());
441 CHECK(!value.empty()); // use autofilled values for java.
442 out << value;
443
444 out << ";";
445
446 std::string comment = entry->comment();
447 if (!comment.empty() && comment != value) {
448 out << " // " << comment;
449 }
450
451 out << "\n";
452 }
453 }
454
455 if (!name.empty()) {
456 out.unindent();
457 out << "};\n";
458 }
459 out << "\n";
460
461 return OK;
462 }
Andreas Huber019d21d2016-10-03 12:59:47 -0700463
464 if (!name.empty()) {
465 out << "typedef ";
466 }
467
468 out << "enum {\n";
469
470 out.indent();
471
472 std::vector<const EnumType *> chain;
473 getTypeChain(&chain);
474
475 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
476 const auto &type = *it;
477
478 for (const auto &entry : type->values()) {
Steven Moreland73cdc882016-11-21 16:43:50 -0800479 out << valuePrefix << entry->name() << valueSuffix;
Andreas Huber019d21d2016-10-03 12:59:47 -0700480
481 std::string value = entry->cppValue(scalarType->getKind());
482 CHECK(!value.empty()); // use autofilled values for c++.
483 out << " = " << value;
484
485 out << ",";
486
487 std::string comment = entry->comment();
488 if (!comment.empty() && comment != value) {
489 out << " // " << comment;
490 }
491
492 out << "\n";
493 }
494 }
495
496 out.unindent();
497 out << "}";
498
499 if (!name.empty()) {
500 out << " " << name;
501 }
502
503 out << ";\n\n";
504
505 return OK;
506}
507
Andreas Huber31629bc2016-08-03 09:06:40 -0700508////////////////////////////////////////////////////////////////////////////////
509
Yifan Hongf24fa852016-09-23 11:03:15 -0700510EnumValue::EnumValue(const char *name, ConstantExpression *value)
Andreas Huber31629bc2016-08-03 09:06:40 -0700511 : mName(name),
Yifan Hongf24fa852016-09-23 11:03:15 -0700512 mValue(value),
513 mIsAutoFill(false) {
Andreas Huber31629bc2016-08-03 09:06:40 -0700514}
515
516std::string EnumValue::name() const {
517 return mName;
518}
519
Yifan Hongc07b2022016-11-08 12:44:24 -0800520std::string EnumValue::value(ScalarType::Kind castKind) const {
Yifan Hongf24fa852016-09-23 11:03:15 -0700521 CHECK(mValue != nullptr);
Yifan Hongc07b2022016-11-08 12:44:24 -0800522 return mValue->value(castKind);
Yifan Hong57886972016-08-17 10:42:15 -0700523}
524
Yifan Hongfc610cd2016-09-22 13:34:45 -0700525std::string EnumValue::cppValue(ScalarType::Kind castKind) const {
Yifan Hongf24fa852016-09-23 11:03:15 -0700526 CHECK(mValue != nullptr);
527 return mValue->cppValue(castKind);
Yifan Hong57886972016-08-17 10:42:15 -0700528}
Yifan Hongfc610cd2016-09-22 13:34:45 -0700529std::string EnumValue::javaValue(ScalarType::Kind castKind) const {
Yifan Hongf24fa852016-09-23 11:03:15 -0700530 CHECK(mValue != nullptr);
531 return mValue->javaValue(castKind);
Yifan Hong19ca75a2016-08-31 10:20:03 -0700532}
Yifan Hong57886972016-08-17 10:42:15 -0700533
Yifan Hongfc610cd2016-09-22 13:34:45 -0700534std::string EnumValue::comment() const {
Yifan Hongf24fa852016-09-23 11:03:15 -0700535 CHECK(mValue != nullptr);
536 return mValue->description();
537}
538
539ConstantExpression *EnumValue::constExpr() const {
540 CHECK(mValue != nullptr);
541 return mValue;
542}
543
544void EnumValue::autofill(const EnumValue *prev, const ScalarType *type) {
545 if(mValue != nullptr)
546 return;
547 mIsAutoFill = true;
548 ConstantExpression *value = new ConstantExpression();
549 if(prev == nullptr) {
550 *value = ConstantExpression::Zero(type->getKind());
551 } else {
552 CHECK(prev->mValue != nullptr);
553 *value = prev->mValue->addOne();
554 }
555 mValue = value;
556}
557
558bool EnumValue::isAutoFill() const {
559 return mIsAutoFill;
560}
561
562bool EnumValue::isEnumValue() const {
563 return true;
Andreas Huber31629bc2016-08-03 09:06:40 -0700564}
565
Andreas Huberc9410c72016-07-28 12:18:40 -0700566} // namespace android
567