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 COMPOUND_TYPE_H_ 18 19 #define COMPOUND_TYPE_H_ 20 21 #include "Scope.h" 22 23 #include <vector> 24 25 namespace android { 26 27 struct CompoundField; 28 29 struct CompoundType : public Scope { 30 enum Style { 31 STYLE_STRUCT, 32 STYLE_UNION, 33 }; 34 35 CompoundType(Style style, const char *localName, const Location &location); 36 37 Style style() const; 38 39 bool setFields(std::vector<CompoundField *> *fields, std::string *errorMsg); 40 41 bool isCompoundType() const override; 42 43 bool canCheckEquality() const override; 44 45 std::string getCppType(StorageMode mode, 46 bool specifyNamespaces) const override; 47 48 std::string getJavaType(bool forInitializer) const override; 49 50 std::string getVtsType() const override; 51 52 void emitReaderWriter( 53 Formatter &out, 54 const std::string &name, 55 const std::string &parcelObj, 56 bool parcelObjIsPointer, 57 bool isReader, 58 ErrorMode mode) const override; 59 60 void emitReaderWriterEmbedded( 61 Formatter &out, 62 size_t depth, 63 const std::string &name, 64 const std::string &sanitizedName, 65 bool nameIsPointer, 66 const std::string &parcelObj, 67 bool parcelObjIsPointer, 68 bool isReader, 69 ErrorMode mode, 70 const std::string &parentName, 71 const std::string &offsetText) const override; 72 73 void emitResolveReferences( 74 Formatter &out, 75 const std::string &name, 76 bool nameIsPointer, 77 const std::string &parcelObj, 78 bool parcelObjIsPointer, 79 bool isReader, 80 ErrorMode mode) const override; 81 82 void emitResolveReferencesEmbedded( 83 Formatter &out, 84 size_t depth, 85 const std::string &name, 86 const std::string &sanitizedName, 87 bool nameIsPointer, 88 const std::string &parcelObj, 89 bool parcelObjIsPointer, 90 bool isReader, 91 ErrorMode mode, 92 const std::string &parentName, 93 const std::string &offsetText) 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 status_t emitTypeDeclarations(Formatter &out) const override; 114 status_t emitGlobalTypeDeclarations(Formatter &out) const override; 115 status_t emitGlobalHwDeclarations(Formatter &out) const override; 116 117 status_t emitTypeDefinitions( 118 Formatter &out, const std::string prefix) const override; 119 120 status_t emitJavaTypeDeclarations( 121 Formatter &out, bool atTopLevel) const override; 122 123 bool needsEmbeddedReadWrite() const override; 124 bool needsResolveReferences() const override; 125 bool resultNeedsDeref() const override; 126 127 status_t emitVtsTypeDeclarations(Formatter &out) const override; 128 status_t emitVtsAttributeType(Formatter &out) const override; 129 130 bool isJavaCompatible() const override; 131 bool containsPointer() const override; 132 133 void getAlignmentAndSize(size_t *align, size_t *size) const; 134 135 private: 136 Style mStyle; 137 std::vector<CompoundField *> *mFields; 138 139 void emitStructReaderWriter( 140 Formatter &out, const std::string &prefix, bool isReader) const; 141 void emitResolveReferenceDef( 142 Formatter &out, const std::string prefix, bool isReader) const; 143 144 DISALLOW_COPY_AND_ASSIGN(CompoundType); 145 }; 146 147 struct CompoundField { 148 CompoundField(const char *name, Type *type); 149 150 std::string name() const; 151 const Type &type() const; 152 153 private: 154 std::string mName; 155 Type *mType; 156 157 DISALLOW_COPY_AND_ASSIGN(CompoundField); 158 }; 159 160 } // namespace android 161 162 #endif // COMPOUND_TYPE_H_ 163 164