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