blob: f736cd66b76f14ad2d062f0154d4861acc685685 [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(),
Andreas Huber881227d2016-08-02 14:20:21 -070034 mStorageType(
35 storageType != NULL
36 ? storageType
37 : new ScalarType(ScalarType::KIND_INT32)) {
Andreas Huberc9410c72016-07-28 12:18:40 -070038}
39
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070040const Type *EnumType::storageType() const {
41 return mStorageType;
42}
43
44const std::vector<EnumValue *> &EnumType::values() const {
Yifan Hongf24fa852016-09-23 11:03:15 -070045 return mValues;
46}
47
48void EnumType::addValue(EnumValue *value) {
49 CHECK(value != nullptr);
50
51 EnumValue *prev = nullptr;
52 std::vector<const EnumType *> chain;
53 getTypeChain(&chain);
54 for (auto it = chain.begin(); it != chain.end(); ++it) {
55 const auto &type = *it;
56 if(!type->values().empty()) {
57 prev = type->values().back();
58 break;
59 }
60 }
61
62 value->autofill(prev, resolveToScalarType());
63 mValues.push_back(value);
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070064}
65
Andreas Huber737080b2016-08-02 15:38:04 -070066const ScalarType *EnumType::resolveToScalarType() const {
67 return mStorageType->resolveToScalarType();
68}
69
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070070bool EnumType::isEnum() const {
71 return true;
72}
73
Steven Moreland979e0992016-09-07 09:18:08 -070074std::string EnumType::getCppType(StorageMode,
Steven Moreland979e0992016-09-07 09:18:08 -070075 bool specifyNamespaces) const {
Steven Moreland979e0992016-09-07 09:18:08 -070076 return specifyNamespaces ? fullName() : partialCppName();
Andreas Huber881227d2016-08-02 14:20:21 -070077}
78
Yifan Hong4ed13472016-11-02 10:44:11 -070079std::string EnumType::getJavaType(bool forInitializer) const {
80 return mStorageType->resolveToScalarType()->getJavaType(forInitializer);
Andreas Huber2831d512016-08-15 09:33:47 -070081}
82
83std::string EnumType::getJavaSuffix() const {
84 return mStorageType->resolveToScalarType()->getJavaSuffix();
85}
86
Andreas Hubera3558b32016-09-14 09:12:42 -070087std::string EnumType::getJavaWrapperType() const {
88 return mStorageType->resolveToScalarType()->getJavaWrapperType();
89}
90
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070091std::string EnumType::getVtsType() const {
92 return "TYPE_ENUM";
93}
94
Yifan Hongf24fa852016-09-23 11:03:15 -070095LocalIdentifier *EnumType::lookupIdentifier(const std::string &name) const {
96 std::vector<const EnumType *> chain;
97 getTypeChain(&chain);
98 for (auto it = chain.begin(); it != chain.end(); ++it) {
99 const auto &type = *it;
100 for(EnumValue *v : type->values()) {
101 if(v->name() == name) {
102 return v;
103 }
104 }
105 }
106 return nullptr;
107}
108
Andreas Huber881227d2016-08-02 14:20:21 -0700109void EnumType::emitReaderWriter(
110 Formatter &out,
111 const std::string &name,
112 const std::string &parcelObj,
113 bool parcelObjIsPointer,
114 bool isReader,
115 ErrorMode mode) const {
Andreas Huber737080b2016-08-02 15:38:04 -0700116 const ScalarType *scalarType = mStorageType->resolveToScalarType();
117 CHECK(scalarType != NULL);
118
119 scalarType->emitReaderWriterWithCast(
120 out,
121 name,
122 parcelObj,
123 parcelObjIsPointer,
124 isReader,
125 mode,
126 true /* needsCast */);
Andreas Huber881227d2016-08-02 14:20:21 -0700127}
128
Andreas Huber85eabdb2016-08-25 11:24:49 -0700129void EnumType::emitJavaFieldReaderWriter(
130 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700131 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700132 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700133 const std::string &blobName,
134 const std::string &fieldName,
135 const std::string &offset,
136 bool isReader) const {
137 return mStorageType->emitJavaFieldReaderWriter(
Andreas Huber709b62d2016-09-19 11:21:18 -0700138 out, depth, parcelName, blobName, fieldName, offset, isReader);
Andreas Huber85eabdb2016-08-25 11:24:49 -0700139}
140
Andreas Huber881227d2016-08-02 14:20:21 -0700141status_t EnumType::emitTypeDeclarations(Formatter &out) const {
Andreas Huber737080b2016-08-02 15:38:04 -0700142 const ScalarType *scalarType = mStorageType->resolveToScalarType();
Andreas Hubere3f769a2016-10-10 10:54:44 -0700143 CHECK(scalarType != nullptr);
Andreas Huber737080b2016-08-02 15:38:04 -0700144
Yifan Hong3b320f82016-11-01 15:15:54 -0700145 const std::string storageType = scalarType->getCppStackType();
Andreas Huber881227d2016-08-02 14:20:21 -0700146
147 out << "enum class "
Andreas Huber0e00de42016-08-03 09:56:02 -0700148 << localName()
Andreas Huber881227d2016-08-02 14:20:21 -0700149 << " : "
Andreas Hubere3f769a2016-10-10 10:54:44 -0700150 << storageType
Andreas Huber881227d2016-08-02 14:20:21 -0700151 << " {\n";
152
153 out.indent();
154
Andreas Huber8d3ac0c2016-08-04 14:49:23 -0700155 std::vector<const EnumType *> chain;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700156 getTypeChain(&chain);
Andreas Huber8d3ac0c2016-08-04 14:49:23 -0700157
158 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
159 const auto &type = *it;
160
161 for (const auto &entry : type->values()) {
162 out << entry->name();
163
Yifan Hongfc610cd2016-09-22 13:34:45 -0700164 std::string value = entry->cppValue(scalarType->getKind());
Yifan Hongf24fa852016-09-23 11:03:15 -0700165 CHECK(!value.empty()); // use autofilled values for c++.
166 out << " = " << value;
Andreas Huber8d3ac0c2016-08-04 14:49:23 -0700167
Yifan Hong57886972016-08-17 10:42:15 -0700168 out << ",";
169
Yifan Hongfc610cd2016-09-22 13:34:45 -0700170 std::string comment = entry->comment();
171 if (!comment.empty() && comment != value) {
Yifan Hong57886972016-08-17 10:42:15 -0700172 out << " // " << comment;
173 }
174
175 out << "\n";
Andreas Huber8d3ac0c2016-08-04 14:49:23 -0700176 }
Andreas Huber881227d2016-08-02 14:20:21 -0700177 }
178
179 out.unindent();
180 out << "};\n\n";
181
182 return OK;
183}
184
Jayant Chowdhary2820f8a2016-11-10 12:29:09 -0800185void EnumType::emitEnumBitwiseOperator(
186 Formatter &out,
187 bool mutating,
188 const std::string &op) const {
Andreas Hubere3f769a2016-10-10 10:54:44 -0700189 const ScalarType *scalarType = mStorageType->resolveToScalarType();
190 CHECK(scalarType != nullptr);
191
Yifan Hong3b320f82016-11-01 15:15:54 -0700192 const std::string storageType = scalarType->getCppStackType();
Andreas Hubere3f769a2016-10-10 10:54:44 -0700193
194 out << "inline "
Jayant Chowdhary2820f8a2016-11-10 12:29:09 -0800195 << (mutating ? fullName() : storageType)
Andreas Hubere3f769a2016-10-10 10:54:44 -0700196 << (mutating ? " &" : "")
Jayant Chowdhary2820f8a2016-11-10 12:29:09 -0800197 << " operator"
198 << op
Andreas Hubere3f769a2016-10-10 10:54:44 -0700199 << (mutating ? "=" : "")
200 << "(\n";
201
202 out.indent();
203 out.indent();
204
205 out << fullName()
206 << (mutating ? " &" : " ")
207 << "lhs, "
208 << fullName()
209 << " rhs) {\n";
210 out.unindent();
211
212 if (mutating) {
213 out << "lhs = ";
214 } else {
215 out << "return ";
216 }
217 out << "static_cast<"
Jayant Chowdhary2820f8a2016-11-10 12:29:09 -0800218 << (mutating ? fullName() : storageType)
Andreas Hubere3f769a2016-10-10 10:54:44 -0700219 << ">(\n";
220 out.indent();
221 out.indent();
222 out << "static_cast<"
223 << storageType
Jayant Chowdhary2820f8a2016-11-10 12:29:09 -0800224 << ">(lhs) "
225 << op
226 <<" static_cast<"
Andreas Hubere3f769a2016-10-10 10:54:44 -0700227 << storageType
228 << ">(rhs));\n";
229 out.unindent();
230 out.unindent();
231
232 if (mutating) {
233 out << "return lhs;\n";
234 }
235
236 out.unindent();
237
238 out << "}\n\n";
239}
240
241status_t EnumType::emitGlobalTypeDeclarations(Formatter &out) const {
Jayant Chowdhary2820f8a2016-11-10 12:29:09 -0800242 emitEnumBitwiseOperator(out, false /* mutating */, "|");
243 emitEnumBitwiseOperator(out, true /* mutating */, "|");
244 emitEnumBitwiseOperator(out, false /* mutating */, "&");
245 emitEnumBitwiseOperator(out, true /* mutating */, "&");
Andreas Hubere3f769a2016-10-10 10:54:44 -0700246
247 return OK;
248}
249
Andreas Huber85eabdb2016-08-25 11:24:49 -0700250status_t EnumType::emitJavaTypeDeclarations(Formatter &out, bool) const {
Andreas Huber2831d512016-08-15 09:33:47 -0700251 const ScalarType *scalarType = mStorageType->resolveToScalarType();
252 CHECK(scalarType != NULL);
253
254 out << "public final class "
255 << localName()
256 << " {\n";
257
258 out.indent();
259
Andreas Huber4c865b72016-09-14 15:26:27 -0700260 const std::string typeName =
Yifan Hong4ed13472016-11-02 10:44:11 -0700261 scalarType->getJavaType(false /* forInitializer */);
Andreas Huber2831d512016-08-15 09:33:47 -0700262
263 std::vector<const EnumType *> chain;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700264 getTypeChain(&chain);
Andreas Huber2831d512016-08-15 09:33:47 -0700265
266 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
267 const auto &type = *it;
268
269 for (const auto &entry : type->values()) {
270 out << "public static final "
271 << typeName
272 << " "
Andreas Huberab647c02016-09-14 09:44:00 -0700273 << entry->name()
274 << " = ";
Andreas Huber2831d512016-08-15 09:33:47 -0700275
Yifan Hongf24fa852016-09-23 11:03:15 -0700276 // javaValue will make the number signed.
Yifan Hongfc610cd2016-09-22 13:34:45 -0700277 std::string value = entry->javaValue(scalarType->getKind());
Yifan Hongf24fa852016-09-23 11:03:15 -0700278 CHECK(!value.empty()); // use autofilled values for java.
279 out << value;
Andreas Huber2831d512016-08-15 09:33:47 -0700280
Yifan Hong19ca75a2016-08-31 10:20:03 -0700281 out << ";";
282
Yifan Hongfc610cd2016-09-22 13:34:45 -0700283 std::string comment = entry->comment();
284 if (!comment.empty() && comment != value) {
Yifan Hong19ca75a2016-08-31 10:20:03 -0700285 out << " // " << comment;
286 }
287
288 out << "\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700289 }
290 }
291
292 out.unindent();
293 out << "};\n\n";
294
295 return OK;
296}
297
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700298status_t EnumType::emitVtsTypeDeclarations(Formatter &out) const {
Yifan Hongc07b2022016-11-08 12:44:24 -0800299 const ScalarType *scalarType = mStorageType->resolveToScalarType();
300
Zhuoyao Zhangbf828c82016-10-26 14:15:10 -0700301 out << "name: \"" << fullName() << "\"\n";
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700302 out << "type: " << getVtsType() << "\n";
303 out << "enum_value: {\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700304 out.indent();
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700305
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700306 out << "scalar_type: \""
Yifan Hongc07b2022016-11-08 12:44:24 -0800307 << scalarType->getVtsScalarType()
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700308 << "\"\n\n";
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700309 std::vector<const EnumType *> chain;
310 getTypeChain(&chain);
311
312 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
313 const auto &type = *it;
314
315 for (const auto &entry : type->values()) {
316 out << "enumerator: \"" << entry->name() << "\"\n";
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700317 out << "scalar_value: {\n";
318 out.indent();
Yifan Hongc07b2022016-11-08 12:44:24 -0800319 // use autofilled values for vts.
320 std::string value = entry->value(scalarType->getKind());
321 CHECK(!value.empty());
322 out << mStorageType->resolveToScalarType()->getVtsScalarType()
323 << ": "
324 << value
325 << "\n";
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700326 out.unindent();
327 out << "}\n";
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700328 }
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700329 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700330
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700331 out.unindent();
332 out << "}\n";
333 return OK;
334}
335
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700336status_t EnumType::emitVtsAttributeType(Formatter &out) const {
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700337 out << "type: " << getVtsType() << "\n";
Zhuoyao Zhangbf828c82016-10-26 14:15:10 -0700338 out << "predefined_type: \"" << fullName() << "\"\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700339 return OK;
340}
341
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700342void EnumType::getTypeChain(std::vector<const EnumType *> *out) const {
343 out->clear();
344 const EnumType *type = this;
345 for (;;) {
346 out->push_back(type);
347
348 const Type *superType = type->storageType();
349 if (superType == NULL || !superType->isEnum()) {
350 break;
351 }
352
353 type = static_cast<const EnumType *>(superType);
354 }
355}
356
Andreas Huber85eabdb2016-08-25 11:24:49 -0700357void EnumType::getAlignmentAndSize(size_t *align, size_t *size) const {
358 mStorageType->getAlignmentAndSize(align, size);
359}
360
Andreas Huber019d21d2016-10-03 12:59:47 -0700361const Annotation *EnumType::findExportAnnotation() const {
362 for (const auto &annotation : annotations()) {
363 if (annotation->name() == "export") {
364 return annotation;
365 }
366 }
367
368 return nullptr;
369}
370
371void EnumType::appendToExportedTypesVector(
372 std::vector<const Type *> *exportedTypes) const {
373 if (findExportAnnotation() != nullptr) {
374 exportedTypes->push_back(this);
375 }
376}
377
Andreas Huber1c507272016-10-05 14:33:21 -0700378status_t EnumType::emitExportedHeader(Formatter &out, bool forJava) const {
Andreas Huber019d21d2016-10-03 12:59:47 -0700379 const Annotation *annotation = findExportAnnotation();
380 CHECK(annotation != nullptr);
381
382 std::string name = localName();
383
384 const AnnotationParam *nameParam = annotation->getParam("name");
385 if (nameParam != nullptr) {
386 CHECK_EQ(nameParam->getValues()->size(), 1u);
387
388 std::string quotedString = nameParam->getValues()->at(0);
389 name = quotedString.substr(1, quotedString.size() - 2);
390 }
391
Andreas Huberb0627fb2016-10-10 09:39:28 -0700392 std::string valuePrefix;
Andreas Huberb0627fb2016-10-10 09:39:28 -0700393 const AnnotationParam *prefixParam = annotation->getParam("value_prefix");
394 if (prefixParam != nullptr) {
395 CHECK_EQ(prefixParam->getValues()->size(), 1u);
396
397 std::string quotedString = prefixParam->getValues()->at(0);
398 valuePrefix = quotedString.substr(1, quotedString.size() - 2);
399 }
400
Steven Moreland73cdc882016-11-21 16:43:50 -0800401 std::string valueSuffix;
402 const AnnotationParam *suffixParam = annotation->getParam("value_suffix");
403 if (suffixParam != nullptr) {
404 CHECK_EQ(suffixParam->getValues()->size(), 1u);
405
406 std::string quotedString = suffixParam->getValues()->at(0);
407 valueSuffix = quotedString.substr(1, quotedString.size() - 2);
408 }
409
Andreas Huber019d21d2016-10-03 12:59:47 -0700410 const ScalarType *scalarType = mStorageType->resolveToScalarType();
Andreas Huber1c507272016-10-05 14:33:21 -0700411 CHECK(scalarType != nullptr);
Andreas Huber019d21d2016-10-03 12:59:47 -0700412
Andreas Huber1c507272016-10-05 14:33:21 -0700413 if (forJava) {
414 if (!name.empty()) {
415 out << "public final class "
416 << name
417 << " {\n";
418
419 out.indent();
420 } else {
421 out << "// Values declared in " << localName() << " follow.\n";
422 }
423
Andreas Huber1c507272016-10-05 14:33:21 -0700424 const std::string typeName =
Yifan Hong4ed13472016-11-02 10:44:11 -0700425 scalarType->getJavaType(false /* forInitializer */);
Andreas Huber1c507272016-10-05 14:33:21 -0700426
427 std::vector<const EnumType *> chain;
428 getTypeChain(&chain);
429
430 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
431 const auto &type = *it;
432
433 for (const auto &entry : type->values()) {
434 out << "public static final "
435 << typeName
436 << " "
437 << valuePrefix
438 << entry->name()
Steven Moreland73cdc882016-11-21 16:43:50 -0800439 << valueSuffix
Andreas Huber1c507272016-10-05 14:33:21 -0700440 << " = ";
441
442 // javaValue will make the number signed.
443 std::string value = entry->javaValue(scalarType->getKind());
444 CHECK(!value.empty()); // use autofilled values for java.
445 out << value;
446
447 out << ";";
448
449 std::string comment = entry->comment();
450 if (!comment.empty() && comment != value) {
451 out << " // " << comment;
452 }
453
454 out << "\n";
455 }
456 }
457
458 if (!name.empty()) {
459 out.unindent();
460 out << "};\n";
461 }
462 out << "\n";
463
464 return OK;
465 }
Andreas Huber019d21d2016-10-03 12:59:47 -0700466
467 if (!name.empty()) {
468 out << "typedef ";
469 }
470
471 out << "enum {\n";
472
473 out.indent();
474
475 std::vector<const EnumType *> chain;
476 getTypeChain(&chain);
477
478 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
479 const auto &type = *it;
480
481 for (const auto &entry : type->values()) {
Steven Moreland73cdc882016-11-21 16:43:50 -0800482 out << valuePrefix << entry->name() << valueSuffix;
Andreas Huber019d21d2016-10-03 12:59:47 -0700483
484 std::string value = entry->cppValue(scalarType->getKind());
485 CHECK(!value.empty()); // use autofilled values for c++.
486 out << " = " << value;
487
488 out << ",";
489
490 std::string comment = entry->comment();
491 if (!comment.empty() && comment != value) {
492 out << " // " << comment;
493 }
494
495 out << "\n";
496 }
497 }
498
499 out.unindent();
500 out << "}";
501
502 if (!name.empty()) {
503 out << " " << name;
504 }
505
506 out << ";\n\n";
507
508 return OK;
509}
510
Andreas Huber31629bc2016-08-03 09:06:40 -0700511////////////////////////////////////////////////////////////////////////////////
512
Yifan Hongf24fa852016-09-23 11:03:15 -0700513EnumValue::EnumValue(const char *name, ConstantExpression *value)
Andreas Huber31629bc2016-08-03 09:06:40 -0700514 : mName(name),
Yifan Hongf24fa852016-09-23 11:03:15 -0700515 mValue(value),
516 mIsAutoFill(false) {
Andreas Huber31629bc2016-08-03 09:06:40 -0700517}
518
519std::string EnumValue::name() const {
520 return mName;
521}
522
Yifan Hongc07b2022016-11-08 12:44:24 -0800523std::string EnumValue::value(ScalarType::Kind castKind) const {
Yifan Hongf24fa852016-09-23 11:03:15 -0700524 CHECK(mValue != nullptr);
Yifan Hongc07b2022016-11-08 12:44:24 -0800525 return mValue->value(castKind);
Yifan Hong57886972016-08-17 10:42:15 -0700526}
527
Yifan Hongfc610cd2016-09-22 13:34:45 -0700528std::string EnumValue::cppValue(ScalarType::Kind castKind) const {
Yifan Hongf24fa852016-09-23 11:03:15 -0700529 CHECK(mValue != nullptr);
530 return mValue->cppValue(castKind);
Yifan Hong57886972016-08-17 10:42:15 -0700531}
Yifan Hongfc610cd2016-09-22 13:34:45 -0700532std::string EnumValue::javaValue(ScalarType::Kind castKind) const {
Yifan Hongf24fa852016-09-23 11:03:15 -0700533 CHECK(mValue != nullptr);
534 return mValue->javaValue(castKind);
Yifan Hong19ca75a2016-08-31 10:20:03 -0700535}
Yifan Hong57886972016-08-17 10:42:15 -0700536
Yifan Hongfc610cd2016-09-22 13:34:45 -0700537std::string EnumValue::comment() const {
Yifan Hongf24fa852016-09-23 11:03:15 -0700538 CHECK(mValue != nullptr);
539 return mValue->description();
540}
541
542ConstantExpression *EnumValue::constExpr() const {
543 CHECK(mValue != nullptr);
544 return mValue;
545}
546
547void EnumValue::autofill(const EnumValue *prev, const ScalarType *type) {
548 if(mValue != nullptr)
549 return;
550 mIsAutoFill = true;
551 ConstantExpression *value = new ConstantExpression();
552 if(prev == nullptr) {
553 *value = ConstantExpression::Zero(type->getKind());
554 } else {
555 CHECK(prev->mValue != nullptr);
556 *value = prev->mValue->addOne();
557 }
558 mValue = value;
559}
560
561bool EnumValue::isAutoFill() const {
562 return mIsAutoFill;
563}
564
565bool EnumValue::isEnumValue() const {
566 return true;
Andreas Huber31629bc2016-08-03 09:06:40 -0700567}
568
Andreas Huberc9410c72016-07-28 12:18:40 -0700569} // namespace android
570