blob: e46c09a1280a575c140c120acaf219fbfd7dbab1 [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
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
Andreas Huberc9410c72016-07-28 12:18:40 -070017#ifndef ARRAY_TYPE_H_
18
19#define ARRAY_TYPE_H_
20
21#include "Type.h"
22
Andreas Huber709b62d2016-09-19 11:21:18 -070023#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070024
25namespace android {
26
Yifan Hongf24fa852016-09-23 11:03:15 -070027struct ConstantExpression;
28
Andreas Huberc9410c72016-07-28 12:18:40 -070029struct ArrayType : public Type {
Andreas Huber709b62d2016-09-19 11:21:18 -070030 // Extends existing array by adding another dimension.
Yifan Hongf24fa852016-09-23 11:03:15 -070031 ArrayType(ArrayType *srcArray, ConstantExpression *size);
Andreas Huber709b62d2016-09-19 11:21:18 -070032
Yifan Hongf24fa852016-09-23 11:03:15 -070033 ArrayType(Type *elementType, ConstantExpression *size);
Andreas Huber709b62d2016-09-19 11:21:18 -070034
Andreas Huber709b62d2016-09-19 11:21:18 -070035 bool isArray() const override;
36
Andreas Huberf03332a2016-09-22 15:35:43 -070037 Type *getElementType() const;
38
Yifan Hongbd33e382016-11-02 13:30:17 -070039 void prependDimension(ConstantExpression *size);
40 void appendDimension(ConstantExpression *size);
Andreas Huberf03332a2016-09-22 15:35:43 -070041 size_t countDimensions() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070042
Steven Moreland979e0992016-09-07 09:18:08 -070043 std::string getCppType(StorageMode mode,
44 std::string *extra,
45 bool specifyNamespaces) const override;
46
47 void addNamedTypesToSet(std::set<const FQName> &set) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070048
Andreas Huber4c865b72016-09-14 15:26:27 -070049 std::string getJavaType(
50 std::string *extra, bool forInitializer) const override;
Andreas Huber2831d512016-08-15 09:33:47 -070051
Andreas Huberf03332a2016-09-22 15:35:43 -070052 std::string getJavaWrapperType() const override;
53
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070054 std::string getVtsType() const override;
55
Andreas Huber881227d2016-08-02 14:20:21 -070056 void emitReaderWriter(
57 Formatter &out,
58 const std::string &name,
59 const std::string &parcelObj,
60 bool parcelObjIsPointer,
61 bool isReader,
62 ErrorMode mode) const override;
63
64 void emitReaderWriterEmbedded(
65 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070066 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070067 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070068 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070069 bool nameIsPointer,
70 const std::string &parcelObj,
71 bool parcelObjIsPointer,
72 bool isReader,
73 ErrorMode mode,
74 const std::string &parentName,
75 const std::string &offsetText) const override;
76
Yifan Hongbf459bc2016-08-23 16:50:37 -070077 void emitResolveReferences(
78 Formatter &out,
79 const std::string &name,
80 bool nameIsPointer,
81 const std::string &parcelObj,
82 bool parcelObjIsPointer,
83 bool isReader,
84 ErrorMode mode) const override;
85
86 void emitResolveReferencesEmbedded(
87 Formatter &out,
88 size_t depth,
89 const std::string &name,
90 const std::string &sanitizedName,
91 bool nameIsPointer,
92 const std::string &parcelObj,
93 bool parcelObjIsPointer,
94 bool isReader,
95 ErrorMode mode,
96 const std::string &parentName,
97 const std::string &offsetText) const override;
98
Andreas Huber881227d2016-08-02 14:20:21 -070099 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700100 bool needsResolveReferences() const override;
Andreas Huberf03332a2016-09-22 15:35:43 -0700101 bool resultNeedsDeref() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700102
Andreas Huber2831d512016-08-15 09:33:47 -0700103 void emitJavaReaderWriter(
104 Formatter &out,
105 const std::string &parcelObj,
106 const std::string &argName,
107 bool isReader) const override;
108
Andreas Huber85eabdb2016-08-25 11:24:49 -0700109 void emitJavaFieldInitializer(
110 Formatter &out, const std::string &fieldName) const override;
111
112 void emitJavaFieldReaderWriter(
113 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700114 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700115 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700116 const std::string &blobName,
117 const std::string &fieldName,
118 const std::string &offset,
119 bool isReader) const override;
120
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700121 status_t emitVtsTypeDeclarations(Formatter &out) const override;
122
Andreas Huber70a59e12016-08-16 12:57:01 -0700123 bool isJavaCompatible() const override;
124
Andreas Huber85eabdb2016-08-25 11:24:49 -0700125 void getAlignmentAndSize(size_t *align, size_t *size) const override;
126
Andreas Huberc9410c72016-07-28 12:18:40 -0700127private:
128 Type *mElementType;
Yifan Hong5706a432016-11-02 09:44:18 -0700129 std::vector<ConstantExpression *> mSizes;
Andreas Huberc9410c72016-07-28 12:18:40 -0700130
Yifan Hongbf459bc2016-08-23 16:50:37 -0700131 size_t dimension() const;
132
Andreas Huberc9410c72016-07-28 12:18:40 -0700133 DISALLOW_COPY_AND_ASSIGN(ArrayType);
134};
135
136} // namespace android
137
138#endif // ARRAY_TYPE_H_
139