blob: cc889c93656ab0cfd74245cb0a86e37e960ed9f0 [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 VECTOR_TYPE_H_
18
19#define VECTOR_TYPE_H_
20
Timur Iskhakov40731af2017-08-24 14:18:35 -070021#include <vector>
22
23#include "Reference.h"
Andreas Huberc9410c72016-07-28 12:18:40 -070024#include "Type.h"
25
26namespace android {
27
Yifan Hongbf459bc2016-08-23 16:50:37 -070028struct VectorType : public TemplatedType {
Timur Iskhakov63f39902017-08-29 15:47:29 -070029 VectorType(Scope* parent);
Andreas Huberc9410c72016-07-28 12:18:40 -070030
Andreas Huber86a112b2016-10-19 14:25:16 -070031 bool isVector() const override;
32 bool isVectorOfBinders() const;
Timur Iskhakov24e605b2017-08-30 14:02:55 -070033
Timur Iskhakov3f1d26e2017-08-30 15:35:53 -070034 std::string templatedTypeName() const override;
Timur Iskhakov24e605b2017-08-30 14:02:55 -070035 bool isCompatibleElementType(const Type* elementType) const override;
Andreas Huber86a112b2016-10-19 14:25:16 -070036
Timur Iskhakovb58f4182017-08-29 15:19:24 -070037 std::vector<const Reference<Type>*> getStrongReferences() const override;
Timur Iskhakov40731af2017-08-24 14:18:35 -070038
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -070039 bool deepCanCheckEquality(std::unordered_set<const Type*>* visited) const override;
Yifan Hongc6752dc2016-12-20 14:00:14 -080040
Andreas Huber4c865b72016-09-14 15:26:27 -070041 std::string getCppType(
42 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070043 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070044
Yifan Hong4ed13472016-11-02 10:44:11 -070045 std::string getJavaType(bool forInitializer) const override;
Nirav Atre66842a92018-06-28 18:14:13 -070046 std::string getJavaTypeClass() const override;
Andreas Huber2831d512016-08-15 09:33:47 -070047
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070048 std::string getVtsType() const override;
Zhuoyao Zhange9667842017-01-19 12:35:32 -080049 std::string getVtsValueName() const override;
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070050
Andreas Huber881227d2016-08-02 14:20:21 -070051 void emitReaderWriter(
52 Formatter &out,
53 const std::string &name,
54 const std::string &parcelObj,
55 bool parcelObjIsPointer,
56 bool isReader,
57 ErrorMode mode) const override;
58
59 void emitReaderWriterEmbedded(
60 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070061 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070062 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070063 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070064 bool nameIsPointer,
65 const std::string &parcelObj,
66 bool parcelObjIsPointer,
67 bool isReader,
68 ErrorMode mode,
69 const std::string &parentName,
70 const std::string &offsetText) const override;
71
Yifan Hongbf459bc2016-08-23 16:50:37 -070072 void emitResolveReferences(
73 Formatter &out,
74 const std::string &name,
75 bool nameIsPointer,
76 const std::string &parcelObj,
77 bool parcelObjIsPointer,
78 bool isReader,
79 ErrorMode mode) const override;
80
81 void emitResolveReferencesEmbedded(
82 Formatter &out,
83 size_t depth,
84 const std::string &name,
85 const std::string &sanitizedName,
86 bool nameIsPointer,
87 const std::string &parcelObj,
88 bool parcelObjIsPointer,
89 bool isReader,
90 ErrorMode mode,
91 const std::string &parentName,
92 const std::string &offsetText) const override;
93
Yifan Hong00f47172016-09-30 14:40:45 -070094 bool useParentInEmitResolveReferencesEmbedded() const override;
95
Andreas Huberf630bc82016-09-09 14:52:25 -070096 void emitJavaReaderWriter(
97 Formatter &out,
98 const std::string &parcelObj,
99 const std::string &argName,
100 bool isReader) const override;
101
Andreas Huber85eabdb2016-08-25 11:24:49 -0700102 void emitJavaFieldInitializer(
103 Formatter &out, const std::string &fieldName) const override;
104
Nirav Atre66842a92018-06-28 18:14:13 -0700105 void emitJavaFieldDefaultInitialValue(
106 Formatter &out, const std::string &declaredFieldName) const override;
107
Andreas Huber85eabdb2016-08-25 11:24:49 -0700108 void emitJavaFieldReaderWriter(
109 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700110 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700111 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700112 const std::string &blobName,
113 const std::string &fieldName,
114 const std::string &offset,
115 bool isReader) const override;
116
Andreas Huberf630bc82016-09-09 14:52:25 -0700117 static void EmitJavaFieldReaderWriterForElementType(
118 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700119 size_t depth,
Andreas Huberf630bc82016-09-09 14:52:25 -0700120 const Type *elementType,
Andreas Huber709b62d2016-09-19 11:21:18 -0700121 const std::string &parcelName,
Andreas Huberf630bc82016-09-09 14:52:25 -0700122 const std::string &blobName,
123 const std::string &fieldName,
124 const std::string &offset,
125 bool isReader);
126
Andreas Huber881227d2016-08-02 14:20:21 -0700127 bool needsEmbeddedReadWrite() const override;
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -0700128 bool deepNeedsResolveReferences(std::unordered_set<const Type*>* visited) const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700129 bool resultNeedsDeref() const override;
130
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -0700131 bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override;
132 bool deepContainsPointer(std::unordered_set<const Type*>* visited) const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700133
Andreas Huber85eabdb2016-08-25 11:24:49 -0700134 void getAlignmentAndSize(size_t *align, size_t *size) const override;
Martijn Coenenb2a861c2017-04-18 15:54:25 -0700135 static void getAlignmentAndSizeStatic(size_t *align, size_t *size);
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700136 private:
Yifan Hongbf459bc2016-08-23 16:50:37 -0700137 // Helper method for emitResolveReferences[Embedded].
138 // Pass empty childName and childOffsetText if the original
139 // childHandle is unknown.
140 // For example, given a vec<ref<T>> (T is a simple struct that
141 // contains primitive values only), then the following methods are
142 // invoked:
143 // 1. VectorType::emitResolveReferences
144 // ... which calls the helper with empty childName and childOffsetText
145 // 2. RefType::emitResolveReferencesEmbedded
146 void emitResolveReferencesEmbeddedHelper(
147 Formatter &out,
148 size_t depth,
149 const std::string &name,
150 const std::string &sanitizedName,
151 bool nameIsPointer,
152 const std::string &parcelObj,
153 bool parcelObjIsPointer,
154 bool isReader,
155 ErrorMode mode,
156 const std::string &childName,
157 const std::string &childOffsetText) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700158
Andreas Huber86a112b2016-10-19 14:25:16 -0700159 void emitReaderWriterForVectorOfBinders(
160 Formatter &out,
161 const std::string &name,
162 const std::string &parcelObj,
163 bool parcelObjIsPointer,
164 bool isReader,
165 ErrorMode mode) const;
166
Andreas Huberc9410c72016-07-28 12:18:40 -0700167 DISALLOW_COPY_AND_ASSIGN(VectorType);
168};
169
170} // namespace android
171
172#endif // VECTOR_TYPE_H_
173