ArrayType.h revision b58f4185934a93fc511c03a8a970b31c5ea0dfca
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 ARRAY_TYPE_H_ 18 19#define ARRAY_TYPE_H_ 20 21#include "Reference.h" 22#include "Type.h" 23 24#include <vector> 25 26namespace android { 27 28struct ConstantExpression; 29 30struct ArrayType : public Type { 31 // Extends existing array by adding another dimension. 32 ArrayType(ArrayType *srcArray, ConstantExpression *size); 33 34 ArrayType(const Reference<Type>& elementType, ConstantExpression* size); 35 36 bool isArray() const override; 37 bool canCheckEquality() const override; 38 39 Type* getElementType() const; 40 41 void prependDimension(ConstantExpression *size); 42 void appendDimension(ConstantExpression *size); 43 size_t countDimensions() const; 44 45 std::string typeName() const override; 46 47 std::vector<const Reference<Type>*> getReferences() const override; 48 49 std::vector<const ConstantExpression*> getConstantExpressions() const override; 50 51 status_t validate() const override; 52 53 std::string getCppType(StorageMode mode, 54 bool specifyNamespaces) const override; 55 56 std::string getInternalDataCppType() const; 57 58 std::string getJavaType(bool forInitializer) const override; 59 60 std::string getJavaWrapperType() const override; 61 62 std::string getVtsType() const override; 63 64 void emitReaderWriter( 65 Formatter &out, 66 const std::string &name, 67 const std::string &parcelObj, 68 bool parcelObjIsPointer, 69 bool isReader, 70 ErrorMode mode) const override; 71 72 void emitReaderWriterEmbedded( 73 Formatter &out, 74 size_t depth, 75 const std::string &name, 76 const std::string &sanitizedName, 77 bool nameIsPointer, 78 const std::string &parcelObj, 79 bool parcelObjIsPointer, 80 bool isReader, 81 ErrorMode mode, 82 const std::string &parentName, 83 const std::string &offsetText) const override; 84 85 void emitResolveReferences( 86 Formatter &out, 87 const std::string &name, 88 bool nameIsPointer, 89 const std::string &parcelObj, 90 bool parcelObjIsPointer, 91 bool isReader, 92 ErrorMode mode) const override; 93 94 void emitResolveReferencesEmbedded( 95 Formatter &out, 96 size_t depth, 97 const std::string &name, 98 const std::string &sanitizedName, 99 bool nameIsPointer, 100 const std::string &parcelObj, 101 bool parcelObjIsPointer, 102 bool isReader, 103 ErrorMode mode, 104 const std::string &parentName, 105 const std::string &offsetText) const override; 106 107 void emitJavaDump( 108 Formatter &out, 109 const std::string &streamName, 110 const std::string &name) const override; 111 112 bool needsEmbeddedReadWrite() const override; 113 bool needsResolveReferences() const override; 114 bool resultNeedsDeref() const override; 115 116 void emitJavaReaderWriter( 117 Formatter &out, 118 const std::string &parcelObj, 119 const std::string &argName, 120 bool isReader) const override; 121 122 void emitJavaFieldInitializer( 123 Formatter &out, const std::string &fieldName) const override; 124 125 void emitJavaFieldReaderWriter( 126 Formatter &out, 127 size_t depth, 128 const std::string &parcelName, 129 const std::string &blobName, 130 const std::string &fieldName, 131 const std::string &offset, 132 bool isReader) const override; 133 134 status_t emitVtsTypeDeclarations(Formatter &out) const override; 135 136 bool isJavaCompatible() const override; 137 bool containsPointer() const override; 138 139 void getAlignmentAndSize(size_t *align, size_t *size) const override; 140 141 private: 142 Reference<Type> mElementType; 143 std::vector<ConstantExpression*> mSizes; 144 145 size_t dimension() const; 146 147 DISALLOW_COPY_AND_ASSIGN(ArrayType); 148}; 149 150} // namespace android 151 152#endif // ARRAY_TYPE_H_ 153 154