EnumType.h revision 19ca75ae47df5cd9447b232c31c5df1d110e85d9
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 17#ifndef ENUM_TYPE_H_ 18 19#define ENUM_TYPE_H_ 20 21#include "ConstantExpression.h" 22#include "NamedType.h" 23 24#include <vector> 25 26namespace android { 27 28struct EnumValue; 29 30struct EnumType : public NamedType { 31 EnumType(const char *localName, 32 std::vector<EnumValue *> *values, 33 Type *storageType = NULL); 34 35 const Type *storageType() const; 36 const std::vector<EnumValue *> &values() const; 37 38 const ScalarType *resolveToScalarType() const override; 39 40 bool isEnum() const override; 41 42 std::string getCppType(StorageMode mode, std::string *extra) const override; 43 44 std::string getJavaType() const override; 45 std::string getJavaSuffix() const override; 46 47 void emitReaderWriter( 48 Formatter &out, 49 const std::string &name, 50 const std::string &parcelObj, 51 bool parcelObjIsPointer, 52 bool isReader, 53 ErrorMode mode) const override; 54 55 void emitJavaFieldReaderWriter( 56 Formatter &out, 57 const std::string &blobName, 58 const std::string &fieldName, 59 const std::string &offset, 60 bool isReader) const override; 61 62 status_t emitTypeDeclarations(Formatter &out) const override; 63 64 status_t emitJavaTypeDeclarations( 65 Formatter &out, bool atTopLevel) const override; 66 67 status_t emitVtsTypeDeclarations(Formatter &out) const override; 68 status_t emitVtsAttributeType(Formatter &out) const override; 69 70 void getAlignmentAndSize(size_t *align, size_t *size) const override; 71 72private: 73 void getTypeChain(std::vector<const EnumType *> *out) const; 74 std::vector<EnumValue *> *mValues; 75 Type *mStorageType; 76 77 DISALLOW_COPY_AND_ASSIGN(EnumType); 78}; 79 80struct EnumValue { 81 EnumValue(const char *name, const ConstantExpression *value = nullptr); 82 83 std::string name() const; 84 const char *value() const; 85 const char *cppValue(ScalarType::Kind castKind) const; 86 const char *javaValue(ScalarType::Kind castKind) const; 87 const char *comment() const; 88 89private: 90 std::string mName; 91 const ConstantExpression *mValue; 92 93 DISALLOW_COPY_AND_ASSIGN(EnumValue); 94}; 95 96} // namespace android 97 98#endif // ENUM_TYPE_H_ 99 100