blob: 6f6ede74927d71bd4b345847f6cb1b8a516967ac [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;
Andreas Huber2831d512016-08-15 09:33:47 -070046
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070047 std::string getVtsType() const override;
Zhuoyao Zhange9667842017-01-19 12:35:32 -080048 std::string getVtsValueName() const override;
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070049
Andreas Huber881227d2016-08-02 14:20:21 -070050 void emitReaderWriter(
51 Formatter &out,
52 const std::string &name,
53 const std::string &parcelObj,
54 bool parcelObjIsPointer,
55 bool isReader,
56 ErrorMode mode) const override;
57
58 void emitReaderWriterEmbedded(
59 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070060 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070061 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070062 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070063 bool nameIsPointer,
64 const std::string &parcelObj,
65 bool parcelObjIsPointer,
66 bool isReader,
67 ErrorMode mode,
68 const std::string &parentName,
69 const std::string &offsetText) const override;
70
Yifan Hongbf459bc2016-08-23 16:50:37 -070071 void emitResolveReferences(
72 Formatter &out,
73 const std::string &name,
74 bool nameIsPointer,
75 const std::string &parcelObj,
76 bool parcelObjIsPointer,
77 bool isReader,
78 ErrorMode mode) const override;
79
80 void emitResolveReferencesEmbedded(
81 Formatter &out,
82 size_t depth,
83 const std::string &name,
84 const std::string &sanitizedName,
85 bool nameIsPointer,
86 const std::string &parcelObj,
87 bool parcelObjIsPointer,
88 bool isReader,
89 ErrorMode mode,
90 const std::string &parentName,
91 const std::string &offsetText) const override;
92
Yifan Hong00f47172016-09-30 14:40:45 -070093 bool useParentInEmitResolveReferencesEmbedded() const override;
94
Andreas Huberf630bc82016-09-09 14:52:25 -070095 void emitJavaReaderWriter(
96 Formatter &out,
97 const std::string &parcelObj,
98 const std::string &argName,
99 bool isReader) const override;
100
Andreas Huber85eabdb2016-08-25 11:24:49 -0700101 void emitJavaFieldInitializer(
102 Formatter &out, const std::string &fieldName) const override;
103
104 void emitJavaFieldReaderWriter(
105 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700106 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700107 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700108 const std::string &blobName,
109 const std::string &fieldName,
110 const std::string &offset,
111 bool isReader) const override;
112
Andreas Huberf630bc82016-09-09 14:52:25 -0700113 static void EmitJavaFieldReaderWriterForElementType(
114 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700115 size_t depth,
Andreas Huberf630bc82016-09-09 14:52:25 -0700116 const Type *elementType,
Andreas Huber709b62d2016-09-19 11:21:18 -0700117 const std::string &parcelName,
Andreas Huberf630bc82016-09-09 14:52:25 -0700118 const std::string &blobName,
119 const std::string &fieldName,
120 const std::string &offset,
121 bool isReader);
122
Andreas Huber881227d2016-08-02 14:20:21 -0700123 bool needsEmbeddedReadWrite() const override;
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -0700124 bool deepNeedsResolveReferences(std::unordered_set<const Type*>* visited) const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700125 bool resultNeedsDeref() const override;
126
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -0700127 bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override;
128 bool deepContainsPointer(std::unordered_set<const Type*>* visited) const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700129
Andreas Huber85eabdb2016-08-25 11:24:49 -0700130 void getAlignmentAndSize(size_t *align, size_t *size) const override;
Martijn Coenenb2a861c2017-04-18 15:54:25 -0700131 static void getAlignmentAndSizeStatic(size_t *align, size_t *size);
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700132 private:
Yifan Hongbf459bc2016-08-23 16:50:37 -0700133 // Helper method for emitResolveReferences[Embedded].
134 // Pass empty childName and childOffsetText if the original
135 // childHandle is unknown.
136 // For example, given a vec<ref<T>> (T is a simple struct that
137 // contains primitive values only), then the following methods are
138 // invoked:
139 // 1. VectorType::emitResolveReferences
140 // ... which calls the helper with empty childName and childOffsetText
141 // 2. RefType::emitResolveReferencesEmbedded
142 void emitResolveReferencesEmbeddedHelper(
143 Formatter &out,
144 size_t depth,
145 const std::string &name,
146 const std::string &sanitizedName,
147 bool nameIsPointer,
148 const std::string &parcelObj,
149 bool parcelObjIsPointer,
150 bool isReader,
151 ErrorMode mode,
152 const std::string &childName,
153 const std::string &childOffsetText) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700154
Andreas Huber86a112b2016-10-19 14:25:16 -0700155 void emitReaderWriterForVectorOfBinders(
156 Formatter &out,
157 const std::string &name,
158 const std::string &parcelObj,
159 bool parcelObjIsPointer,
160 bool isReader,
161 ErrorMode mode) const;
162
Andreas Huberc9410c72016-07-28 12:18:40 -0700163 DISALLOW_COPY_AND_ASSIGN(VectorType);
164};
165
166} // namespace android
167
168#endif // VECTOR_TYPE_H_
169