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