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