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