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    bool isArray() const override;
36    bool canCheckEquality() const override;
37
38    Type *getElementType() const;
39
40    void prependDimension(ConstantExpression *size);
41    void appendDimension(ConstantExpression *size);
42    size_t countDimensions() const;
43
44    std::string typeName() const override;
45
46    std::string getCppType(StorageMode mode,
47                           bool specifyNamespaces) const override;
48
49    std::string getInternalDataCppType() const;
50
51    std::string getJavaType(bool forInitializer) const override;
52
53    std::string getJavaWrapperType() const override;
54
55    std::string getVtsType() const override;
56
57    void emitReaderWriter(
58            Formatter &out,
59            const std::string &name,
60            const std::string &parcelObj,
61            bool parcelObjIsPointer,
62            bool isReader,
63            ErrorMode mode) const override;
64
65    void emitReaderWriterEmbedded(
66            Formatter &out,
67            size_t depth,
68            const std::string &name,
69            const std::string &sanitizedName,
70            bool nameIsPointer,
71            const std::string &parcelObj,
72            bool parcelObjIsPointer,
73            bool isReader,
74            ErrorMode mode,
75            const std::string &parentName,
76            const std::string &offsetText) const override;
77
78    void emitResolveReferences(
79            Formatter &out,
80            const std::string &name,
81            bool nameIsPointer,
82            const std::string &parcelObj,
83            bool parcelObjIsPointer,
84            bool isReader,
85            ErrorMode mode) const override;
86
87    void emitResolveReferencesEmbedded(
88            Formatter &out,
89            size_t depth,
90            const std::string &name,
91            const std::string &sanitizedName,
92            bool nameIsPointer,
93            const std::string &parcelObj,
94            bool parcelObjIsPointer,
95            bool isReader,
96            ErrorMode mode,
97            const std::string &parentName,
98            const std::string &offsetText) const override;
99
100    void emitJavaDump(
101            Formatter &out,
102            const std::string &streamName,
103            const std::string &name) const override;
104
105    bool needsEmbeddedReadWrite() const override;
106    bool needsResolveReferences() const override;
107    bool resultNeedsDeref() const override;
108
109    void emitJavaReaderWriter(
110            Formatter &out,
111            const std::string &parcelObj,
112            const std::string &argName,
113            bool isReader) const override;
114
115    void emitJavaFieldInitializer(
116            Formatter &out, const std::string &fieldName) const override;
117
118    void emitJavaFieldReaderWriter(
119            Formatter &out,
120            size_t depth,
121            const std::string &parcelName,
122            const std::string &blobName,
123            const std::string &fieldName,
124            const std::string &offset,
125            bool isReader) const override;
126
127    status_t emitVtsTypeDeclarations(Formatter &out) const override;
128
129    bool isJavaCompatible() const override;
130    bool containsPointer() const override;
131
132    void getAlignmentAndSize(size_t *align, size_t *size) const override;
133
134private:
135    Type *mElementType;
136    std::vector<ConstantExpression *> mSizes;
137
138    size_t dimension() const;
139
140    DISALLOW_COPY_AND_ASSIGN(ArrayType);
141};
142
143}  // namespace android
144
145#endif  // ARRAY_TYPE_H_
146
147