Andreas Huber | 1aec397 | 2016-08-26 09:26:32 -0700 | [diff] [blame] | 1 | /* |
| 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 Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 17 | #include "EnumType.h" |
| 18 | |
Andreas Huber | 019d21d | 2016-10-03 12:59:47 -0700 | [diff] [blame] | 19 | #include "Annotation.h" |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 20 | #include "ScalarType.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 21 | |
Iliyan Malchev | a72e0d2 | 2016-09-09 11:03:08 -0700 | [diff] [blame] | 22 | #include <inttypes.h> |
| 23 | #include <hidl-util/Formatter.h> |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 24 | #include <android-base/logging.h> |
| 25 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 26 | namespace android { |
| 27 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 28 | EnumType::EnumType( |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 29 | const char *localName, |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 30 | Type *storageType) |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 31 | : Scope(localName), |
| 32 | mValues(), |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 33 | mStorageType( |
| 34 | storageType != NULL |
| 35 | ? storageType |
| 36 | : new ScalarType(ScalarType::KIND_INT32)) { |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 39 | const Type *EnumType::storageType() const { |
| 40 | return mStorageType; |
| 41 | } |
| 42 | |
| 43 | const std::vector<EnumValue *> &EnumType::values() const { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 44 | return mValues; |
| 45 | } |
| 46 | |
| 47 | void EnumType::addValue(EnumValue *value) { |
| 48 | CHECK(value != nullptr); |
| 49 | |
| 50 | EnumValue *prev = nullptr; |
| 51 | std::vector<const EnumType *> chain; |
| 52 | getTypeChain(&chain); |
| 53 | for (auto it = chain.begin(); it != chain.end(); ++it) { |
| 54 | const auto &type = *it; |
| 55 | if(!type->values().empty()) { |
| 56 | prev = type->values().back(); |
| 57 | break; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | value->autofill(prev, resolveToScalarType()); |
| 62 | mValues.push_back(value); |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 65 | const ScalarType *EnumType::resolveToScalarType() const { |
| 66 | return mStorageType->resolveToScalarType(); |
| 67 | } |
| 68 | |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 69 | bool EnumType::isEnum() const { |
| 70 | return true; |
| 71 | } |
| 72 | |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 73 | std::string EnumType::getCppType(StorageMode, |
| 74 | std::string *extra, |
| 75 | bool specifyNamespaces) const { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 76 | extra->clear(); |
| 77 | |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 78 | return specifyNamespaces ? fullName() : partialCppName(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Andreas Huber | 4c865b7 | 2016-09-14 15:26:27 -0700 | [diff] [blame] | 81 | std::string EnumType::getJavaType( |
| 82 | std::string *extra, bool forInitializer) const { |
| 83 | return mStorageType->resolveToScalarType()->getJavaType( |
| 84 | extra, forInitializer); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | std::string EnumType::getJavaSuffix() const { |
| 88 | return mStorageType->resolveToScalarType()->getJavaSuffix(); |
| 89 | } |
| 90 | |
Andreas Huber | a3558b3 | 2016-09-14 09:12:42 -0700 | [diff] [blame] | 91 | std::string EnumType::getJavaWrapperType() const { |
| 92 | return mStorageType->resolveToScalarType()->getJavaWrapperType(); |
| 93 | } |
| 94 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 95 | LocalIdentifier *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 Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 109 | void 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 Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 116 | 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 Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 129 | void EnumType::emitJavaFieldReaderWriter( |
| 130 | Formatter &out, |
Andreas Huber | 4c865b7 | 2016-09-14 15:26:27 -0700 | [diff] [blame] | 131 | size_t depth, |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 132 | const std::string &parcelName, |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 133 | const std::string &blobName, |
| 134 | const std::string &fieldName, |
| 135 | const std::string &offset, |
| 136 | bool isReader) const { |
| 137 | return mStorageType->emitJavaFieldReaderWriter( |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 138 | out, depth, parcelName, blobName, fieldName, offset, isReader); |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 141 | status_t EnumType::emitTypeDeclarations(Formatter &out) const { |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 142 | const ScalarType *scalarType = mStorageType->resolveToScalarType(); |
| 143 | CHECK(scalarType != NULL); |
| 144 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 145 | std::string extra; |
| 146 | |
| 147 | out << "enum class " |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 148 | << localName() |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 149 | << " : " |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 150 | << ((Type *)scalarType)->getCppType(&extra) |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 151 | << " {\n"; |
| 152 | |
| 153 | out.indent(); |
| 154 | |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 155 | std::vector<const EnumType *> chain; |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 156 | getTypeChain(&chain); |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 157 | |
| 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 Hong | fc610cd | 2016-09-22 13:34:45 -0700 | [diff] [blame] | 164 | std::string value = entry->cppValue(scalarType->getKind()); |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 165 | CHECK(!value.empty()); // use autofilled values for c++. |
| 166 | out << " = " << value; |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 167 | |
Yifan Hong | 5788697 | 2016-08-17 10:42:15 -0700 | [diff] [blame] | 168 | out << ","; |
| 169 | |
Yifan Hong | fc610cd | 2016-09-22 13:34:45 -0700 | [diff] [blame] | 170 | std::string comment = entry->comment(); |
| 171 | if (!comment.empty() && comment != value) { |
Yifan Hong | 5788697 | 2016-08-17 10:42:15 -0700 | [diff] [blame] | 172 | out << " // " << comment; |
| 173 | } |
| 174 | |
| 175 | out << "\n"; |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 176 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | out.unindent(); |
| 180 | out << "};\n\n"; |
| 181 | |
| 182 | return OK; |
| 183 | } |
| 184 | |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 185 | status_t EnumType::emitJavaTypeDeclarations(Formatter &out, bool) const { |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 186 | const ScalarType *scalarType = mStorageType->resolveToScalarType(); |
| 187 | CHECK(scalarType != NULL); |
| 188 | |
| 189 | out << "public final class " |
| 190 | << localName() |
| 191 | << " {\n"; |
| 192 | |
| 193 | out.indent(); |
| 194 | |
Andreas Huber | 4c865b7 | 2016-09-14 15:26:27 -0700 | [diff] [blame] | 195 | std::string extra; // unused, because ScalarType leaves this empty. |
| 196 | const std::string typeName = |
| 197 | scalarType->getJavaType(&extra, false /* forInitializer */); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 198 | |
| 199 | std::vector<const EnumType *> chain; |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 200 | getTypeChain(&chain); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 201 | |
| 202 | for (auto it = chain.rbegin(); it != chain.rend(); ++it) { |
| 203 | const auto &type = *it; |
| 204 | |
| 205 | for (const auto &entry : type->values()) { |
| 206 | out << "public static final " |
| 207 | << typeName |
| 208 | << " " |
Andreas Huber | ab647c0 | 2016-09-14 09:44:00 -0700 | [diff] [blame] | 209 | << entry->name() |
| 210 | << " = "; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 211 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 212 | // javaValue will make the number signed. |
Yifan Hong | fc610cd | 2016-09-22 13:34:45 -0700 | [diff] [blame] | 213 | std::string value = entry->javaValue(scalarType->getKind()); |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 214 | CHECK(!value.empty()); // use autofilled values for java. |
| 215 | out << value; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 216 | |
Yifan Hong | 19ca75a | 2016-08-31 10:20:03 -0700 | [diff] [blame] | 217 | out << ";"; |
| 218 | |
Yifan Hong | fc610cd | 2016-09-22 13:34:45 -0700 | [diff] [blame] | 219 | std::string comment = entry->comment(); |
| 220 | if (!comment.empty() && comment != value) { |
Yifan Hong | 19ca75a | 2016-08-31 10:20:03 -0700 | [diff] [blame] | 221 | out << " // " << comment; |
| 222 | } |
| 223 | |
| 224 | out << "\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
| 228 | out.unindent(); |
| 229 | out << "};\n\n"; |
| 230 | |
| 231 | return OK; |
| 232 | } |
| 233 | |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 234 | status_t EnumType::emitVtsTypeDeclarations(Formatter &out) const { |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 235 | out << "name: \"" << localName() << "\"\n" |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 236 | << "type: TYPE_ENUM\n" |
| 237 | << "enum_value: {\n"; |
| 238 | out.indent(); |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 239 | |
| 240 | std::vector<const EnumType *> chain; |
| 241 | getTypeChain(&chain); |
| 242 | |
| 243 | for (auto it = chain.rbegin(); it != chain.rend(); ++it) { |
| 244 | const auto &type = *it; |
| 245 | |
| 246 | for (const auto &entry : type->values()) { |
| 247 | out << "enumerator: \"" << entry->name() << "\"\n"; |
| 248 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 249 | if (!entry->isAutoFill()) { |
| 250 | // don't autofill values for vts. |
| 251 | std::string value = entry->value(); |
| 252 | CHECK(!value.empty()); |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 253 | out << "value: " << value << "\n"; |
| 254 | } |
| 255 | } |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 256 | } |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 257 | |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 258 | out.unindent(); |
| 259 | out << "}\n"; |
| 260 | return OK; |
| 261 | } |
| 262 | |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 263 | status_t EnumType::emitVtsAttributeType(Formatter &out) const { |
Zhuoyao Zhang | 1993352 | 2016-08-29 15:06:38 -0700 | [diff] [blame] | 264 | out << "type: TYPE_ENUM\n" |
| 265 | << "predefined_type: \"" |
| 266 | << localName() |
| 267 | << "\"\n"; |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 268 | return OK; |
| 269 | } |
| 270 | |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 271 | void EnumType::getTypeChain(std::vector<const EnumType *> *out) const { |
| 272 | out->clear(); |
| 273 | const EnumType *type = this; |
| 274 | for (;;) { |
| 275 | out->push_back(type); |
| 276 | |
| 277 | const Type *superType = type->storageType(); |
| 278 | if (superType == NULL || !superType->isEnum()) { |
| 279 | break; |
| 280 | } |
| 281 | |
| 282 | type = static_cast<const EnumType *>(superType); |
| 283 | } |
| 284 | } |
| 285 | |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 286 | void EnumType::getAlignmentAndSize(size_t *align, size_t *size) const { |
| 287 | mStorageType->getAlignmentAndSize(align, size); |
| 288 | } |
| 289 | |
Andreas Huber | 019d21d | 2016-10-03 12:59:47 -0700 | [diff] [blame] | 290 | const Annotation *EnumType::findExportAnnotation() const { |
| 291 | for (const auto &annotation : annotations()) { |
| 292 | if (annotation->name() == "export") { |
| 293 | return annotation; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | return nullptr; |
| 298 | } |
| 299 | |
| 300 | void EnumType::appendToExportedTypesVector( |
| 301 | std::vector<const Type *> *exportedTypes) const { |
| 302 | if (findExportAnnotation() != nullptr) { |
| 303 | exportedTypes->push_back(this); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | status_t EnumType::emitExportedHeader(Formatter &out) const { |
| 308 | const Annotation *annotation = findExportAnnotation(); |
| 309 | CHECK(annotation != nullptr); |
| 310 | |
| 311 | std::string name = localName(); |
| 312 | |
| 313 | const AnnotationParam *nameParam = annotation->getParam("name"); |
| 314 | if (nameParam != nullptr) { |
| 315 | CHECK_EQ(nameParam->getValues()->size(), 1u); |
| 316 | |
| 317 | std::string quotedString = nameParam->getValues()->at(0); |
| 318 | name = quotedString.substr(1, quotedString.size() - 2); |
| 319 | } |
| 320 | |
| 321 | const ScalarType *scalarType = mStorageType->resolveToScalarType(); |
| 322 | CHECK(scalarType != NULL); |
| 323 | |
| 324 | std::string extra; |
| 325 | |
| 326 | if (!name.empty()) { |
| 327 | out << "typedef "; |
| 328 | } |
| 329 | |
| 330 | out << "enum {\n"; |
| 331 | |
| 332 | out.indent(); |
| 333 | |
| 334 | std::vector<const EnumType *> chain; |
| 335 | getTypeChain(&chain); |
| 336 | |
| 337 | for (auto it = chain.rbegin(); it != chain.rend(); ++it) { |
| 338 | const auto &type = *it; |
| 339 | |
| 340 | for (const auto &entry : type->values()) { |
| 341 | out << entry->name(); |
| 342 | |
| 343 | std::string value = entry->cppValue(scalarType->getKind()); |
| 344 | CHECK(!value.empty()); // use autofilled values for c++. |
| 345 | out << " = " << value; |
| 346 | |
| 347 | out << ","; |
| 348 | |
| 349 | std::string comment = entry->comment(); |
| 350 | if (!comment.empty() && comment != value) { |
| 351 | out << " // " << comment; |
| 352 | } |
| 353 | |
| 354 | out << "\n"; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | out.unindent(); |
| 359 | out << "}"; |
| 360 | |
| 361 | if (!name.empty()) { |
| 362 | out << " " << name; |
| 363 | } |
| 364 | |
| 365 | out << ";\n\n"; |
| 366 | |
| 367 | return OK; |
| 368 | } |
| 369 | |
Andreas Huber | 31629bc | 2016-08-03 09:06:40 -0700 | [diff] [blame] | 370 | //////////////////////////////////////////////////////////////////////////////// |
| 371 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 372 | EnumValue::EnumValue(const char *name, ConstantExpression *value) |
Andreas Huber | 31629bc | 2016-08-03 09:06:40 -0700 | [diff] [blame] | 373 | : mName(name), |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 374 | mValue(value), |
| 375 | mIsAutoFill(false) { |
Andreas Huber | 31629bc | 2016-08-03 09:06:40 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | std::string EnumValue::name() const { |
| 379 | return mName; |
| 380 | } |
| 381 | |
Yifan Hong | fc610cd | 2016-09-22 13:34:45 -0700 | [diff] [blame] | 382 | std::string EnumValue::value() const { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 383 | CHECK(mValue != nullptr); |
| 384 | return mValue->value(); |
Yifan Hong | 5788697 | 2016-08-17 10:42:15 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Yifan Hong | fc610cd | 2016-09-22 13:34:45 -0700 | [diff] [blame] | 387 | std::string EnumValue::cppValue(ScalarType::Kind castKind) const { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 388 | CHECK(mValue != nullptr); |
| 389 | return mValue->cppValue(castKind); |
Yifan Hong | 5788697 | 2016-08-17 10:42:15 -0700 | [diff] [blame] | 390 | } |
Yifan Hong | fc610cd | 2016-09-22 13:34:45 -0700 | [diff] [blame] | 391 | std::string EnumValue::javaValue(ScalarType::Kind castKind) const { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 392 | CHECK(mValue != nullptr); |
| 393 | return mValue->javaValue(castKind); |
Yifan Hong | 19ca75a | 2016-08-31 10:20:03 -0700 | [diff] [blame] | 394 | } |
Yifan Hong | 5788697 | 2016-08-17 10:42:15 -0700 | [diff] [blame] | 395 | |
Yifan Hong | fc610cd | 2016-09-22 13:34:45 -0700 | [diff] [blame] | 396 | std::string EnumValue::comment() const { |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 397 | CHECK(mValue != nullptr); |
| 398 | return mValue->description(); |
| 399 | } |
| 400 | |
| 401 | ConstantExpression *EnumValue::constExpr() const { |
| 402 | CHECK(mValue != nullptr); |
| 403 | return mValue; |
| 404 | } |
| 405 | |
| 406 | void EnumValue::autofill(const EnumValue *prev, const ScalarType *type) { |
| 407 | if(mValue != nullptr) |
| 408 | return; |
| 409 | mIsAutoFill = true; |
| 410 | ConstantExpression *value = new ConstantExpression(); |
| 411 | if(prev == nullptr) { |
| 412 | *value = ConstantExpression::Zero(type->getKind()); |
| 413 | } else { |
| 414 | CHECK(prev->mValue != nullptr); |
| 415 | *value = prev->mValue->addOne(); |
| 416 | } |
| 417 | mValue = value; |
| 418 | } |
| 419 | |
| 420 | bool EnumValue::isAutoFill() const { |
| 421 | return mIsAutoFill; |
| 422 | } |
| 423 | |
| 424 | bool EnumValue::isEnumValue() const { |
| 425 | return true; |
Andreas Huber | 31629bc | 2016-08-03 09:06:40 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 428 | } // namespace android |
| 429 | |