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