ArrayType.h revision f24fa85b362d7eb66c7b880f48e1e2e9916bc8a9
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 static ArrayType *AddDimension(ArrayType *base, ConstantExpression *size); 36 37 bool isArray() const override; 38 39 void addDimension(ConstantExpression *size); 40 41 std::string getCppType(StorageMode mode, 42 std::string *extra, 43 bool specifyNamespaces) const override; 44 45 void addNamedTypesToSet(std::set<const FQName> &set) const override; 46 47 std::string getJavaType( 48 std::string *extra, bool forInitializer) 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 bool nameIsPointer, 63 const std::string &parcelObj, 64 bool parcelObjIsPointer, 65 bool isReader, 66 ErrorMode mode, 67 const std::string &parentName, 68 const std::string &offsetText) const override; 69 70 bool needsEmbeddedReadWrite() const override; 71 72 void emitJavaReaderWriter( 73 Formatter &out, 74 const std::string &parcelObj, 75 const std::string &argName, 76 bool isReader) const override; 77 78 void emitJavaFieldInitializer( 79 Formatter &out, const std::string &fieldName) const override; 80 81 void emitJavaFieldReaderWriter( 82 Formatter &out, 83 size_t depth, 84 const std::string &parcelName, 85 const std::string &blobName, 86 const std::string &fieldName, 87 const std::string &offset, 88 bool isReader) const override; 89 90 status_t emitVtsTypeDeclarations(Formatter &out) const override; 91 92 bool isJavaCompatible() const override; 93 94 void getAlignmentAndSize(size_t *align, size_t *size) const override; 95 96private: 97 Type *mElementType; 98 std::vector<size_t> mSizes; 99 std::vector<std::string> mSizeComments; 100 101 DISALLOW_COPY_AND_ASSIGN(ArrayType); 102}; 103 104} // namespace android 105 106#endif // ARRAY_TYPE_H_ 107 108