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 VECTOR_TYPE_H_ 18 19 #define VECTOR_TYPE_H_ 20 21 #include <vector> 22 23 #include "Reference.h" 24 #include "Type.h" 25 26 namespace android { 27 28 struct VectorType : public TemplatedType { 29 VectorType(Scope* parent); 30 31 bool isVector() const override; 32 bool isVectorOfBinders() const; 33 34 std::string templatedTypeName() const override; 35 bool isCompatibleElementType(const Type* elementType) const override; 36 37 std::vector<const Reference<Type>*> getStrongReferences() const override; 38 39 bool deepCanCheckEquality(std::unordered_set<const Type*>* visited) const override; 40 41 std::string getCppType( 42 StorageMode mode, 43 bool specifyNamespaces) const override; 44 45 std::string getJavaType(bool forInitializer) const override; 46 47 std::string getVtsType() const override; 48 std::string getVtsValueName() const override; 49 50 void emitReaderWriter( 51 Formatter &out, 52 const std::string &name, 53 const std::string &parcelObj, 54 bool parcelObjIsPointer, 55 bool isReader, 56 ErrorMode mode) const override; 57 58 void emitReaderWriterEmbedded( 59 Formatter &out, 60 size_t depth, 61 const std::string &name, 62 const std::string &sanitizedName, 63 bool nameIsPointer, 64 const std::string &parcelObj, 65 bool parcelObjIsPointer, 66 bool isReader, 67 ErrorMode mode, 68 const std::string &parentName, 69 const std::string &offsetText) const override; 70 71 void emitResolveReferences( 72 Formatter &out, 73 const std::string &name, 74 bool nameIsPointer, 75 const std::string &parcelObj, 76 bool parcelObjIsPointer, 77 bool isReader, 78 ErrorMode mode) const override; 79 80 void emitResolveReferencesEmbedded( 81 Formatter &out, 82 size_t depth, 83 const std::string &name, 84 const std::string &sanitizedName, 85 bool nameIsPointer, 86 const std::string &parcelObj, 87 bool parcelObjIsPointer, 88 bool isReader, 89 ErrorMode mode, 90 const std::string &parentName, 91 const std::string &offsetText) const override; 92 93 bool useParentInEmitResolveReferencesEmbedded() const override; 94 95 void emitJavaReaderWriter( 96 Formatter &out, 97 const std::string &parcelObj, 98 const std::string &argName, 99 bool isReader) const override; 100 101 void emitJavaFieldInitializer( 102 Formatter &out, const std::string &fieldName) const override; 103 104 void emitJavaFieldReaderWriter( 105 Formatter &out, 106 size_t depth, 107 const std::string &parcelName, 108 const std::string &blobName, 109 const std::string &fieldName, 110 const std::string &offset, 111 bool isReader) const override; 112 113 static void EmitJavaFieldReaderWriterForElementType( 114 Formatter &out, 115 size_t depth, 116 const Type *elementType, 117 const std::string &parcelName, 118 const std::string &blobName, 119 const std::string &fieldName, 120 const std::string &offset, 121 bool isReader); 122 123 bool needsEmbeddedReadWrite() const override; 124 bool deepNeedsResolveReferences(std::unordered_set<const Type*>* visited) const override; 125 bool resultNeedsDeref() const override; 126 127 bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override; 128 bool deepContainsPointer(std::unordered_set<const Type*>* visited) const override; 129 130 void getAlignmentAndSize(size_t *align, size_t *size) const override; 131 static void getAlignmentAndSizeStatic(size_t *align, size_t *size); 132 private: 133 // Helper method for emitResolveReferences[Embedded]. 134 // Pass empty childName and childOffsetText if the original 135 // childHandle is unknown. 136 // For example, given a vec<ref<T>> (T is a simple struct that 137 // contains primitive values only), then the following methods are 138 // invoked: 139 // 1. VectorType::emitResolveReferences 140 // ... which calls the helper with empty childName and childOffsetText 141 // 2. RefType::emitResolveReferencesEmbedded 142 void emitResolveReferencesEmbeddedHelper( 143 Formatter &out, 144 size_t depth, 145 const std::string &name, 146 const std::string &sanitizedName, 147 bool nameIsPointer, 148 const std::string &parcelObj, 149 bool parcelObjIsPointer, 150 bool isReader, 151 ErrorMode mode, 152 const std::string &childName, 153 const std::string &childOffsetText) const; 154 155 void emitReaderWriterForVectorOfBinders( 156 Formatter &out, 157 const std::string &name, 158 const std::string &parcelObj, 159 bool parcelObjIsPointer, 160 bool isReader, 161 ErrorMode mode) const; 162 163 DISALLOW_COPY_AND_ASSIGN(VectorType); 164 }; 165 166 } // namespace android 167 168 #endif // VECTOR_TYPE_H_ 169 170