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