EnumType.h revision c07b202bc91024356c50ded5a65d69f03b92e557
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 "Scope.h" 23 24#include <vector> 25 26namespace android { 27 28struct EnumValue; 29 30struct EnumType : public Scope { 31 EnumType(const char *localName, 32 const Location &location, 33 Type *storageType = NULL); 34 35 const Type *storageType() const; 36 const std::vector<EnumValue *> &values() const; 37 void addValue(EnumValue *value); 38 39 LocalIdentifier *lookupIdentifier(const std::string &name) const override; 40 41 const ScalarType *resolveToScalarType() const override; 42 43 bool isEnum() const override; 44 45 std::string getCppType(StorageMode mode, 46 bool specifyNamespaces) const override; 47 48 std::string getJavaType(bool forInitializer) const override; 49 50 std::string getJavaSuffix() const override; 51 52 std::string getJavaWrapperType() const override; 53 54 std::string getVtsType() const override; 55 56 void emitReaderWriter( 57 Formatter &out, 58 const std::string &name, 59 const std::string &parcelObj, 60 bool parcelObjIsPointer, 61 bool isReader, 62 ErrorMode mode) const override; 63 64 void emitJavaFieldReaderWriter( 65 Formatter &out, 66 size_t depth, 67 const std::string &parcelName, 68 const std::string &blobName, 69 const std::string &fieldName, 70 const std::string &offset, 71 bool isReader) const override; 72 73 status_t emitTypeDeclarations(Formatter &out) const override; 74 status_t emitGlobalTypeDeclarations(Formatter &out) const override; 75 76 status_t emitJavaTypeDeclarations( 77 Formatter &out, bool atTopLevel) const override; 78 79 status_t emitVtsTypeDeclarations(Formatter &out) const override; 80 status_t emitVtsAttributeType(Formatter &out) const override; 81 82 void getAlignmentAndSize(size_t *align, size_t *size) const override; 83 84 void appendToExportedTypesVector( 85 std::vector<const Type *> *exportedTypes) const override; 86 87 status_t emitExportedHeader(Formatter &out, bool forJava) const override; 88 89private: 90 void getTypeChain(std::vector<const EnumType *> *out) const; 91 const Annotation *findExportAnnotation() const; 92 93 void emitEnumBitwiseOrOperator(Formatter &out, bool mutating) const; 94 95 std::vector<EnumValue *> mValues; 96 Type *mStorageType; 97 98 DISALLOW_COPY_AND_ASSIGN(EnumType); 99}; 100 101struct EnumValue : public LocalIdentifier { 102 EnumValue(const char *name, ConstantExpression *value = nullptr); 103 104 std::string name() const; 105 std::string value(ScalarType::Kind castKind) const; 106 std::string cppValue(ScalarType::Kind castKind) const; 107 std::string javaValue(ScalarType::Kind castKind) const; 108 std::string comment() const; 109 void autofill(const EnumValue *prev, const ScalarType *type); 110 ConstantExpression *constExpr() const; 111 112 bool isAutoFill() const; 113 bool isEnumValue() const override; 114 115 116 std::string mName; 117 ConstantExpression *mValue; 118 bool mIsAutoFill; 119 120 DISALLOW_COPY_AND_ASSIGN(EnumValue); 121}; 122 123} // namespace android 124 125#endif // ENUM_TYPE_H_ 126 127