blob: e86835556b45a3d0f7787908cd24619489d69734 [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
21#include "Type.h"
22
23namespace android {
24
Yifan Hongbf459bc2016-08-23 16:50:37 -070025struct VectorType : public TemplatedType {
26 VectorType();
Andreas Huberc9410c72016-07-28 12:18:40 -070027
Andreas Huber86a112b2016-10-19 14:25:16 -070028 bool isVector() const override;
29 bool isVectorOfBinders() const;
Steven Moreland30bb6a82016-11-30 09:18:34 -080030 std::string typeName() const override;
31 bool isCompatibleElementType(Type *elementType) const override;
Andreas Huber86a112b2016-10-19 14:25:16 -070032
Yifan Hongc6752dc2016-12-20 14:00:14 -080033 bool canCheckEquality() const override;
34
Andreas Huber4c865b72016-09-14 15:26:27 -070035 std::string getCppType(
36 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070037 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070038
Yifan Hong4ed13472016-11-02 10:44:11 -070039 std::string getJavaType(bool forInitializer) const override;
Andreas Huber2831d512016-08-15 09:33:47 -070040
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070041 std::string getVtsType() const override;
Zhuoyao Zhange9667842017-01-19 12:35:32 -080042 std::string getVtsValueName() const override;
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070043
Andreas Huber881227d2016-08-02 14:20:21 -070044 void emitReaderWriter(
45 Formatter &out,
46 const std::string &name,
47 const std::string &parcelObj,
48 bool parcelObjIsPointer,
49 bool isReader,
50 ErrorMode mode) const override;
51
52 void emitReaderWriterEmbedded(
53 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070054 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070055 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070056 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070057 bool nameIsPointer,
58 const std::string &parcelObj,
59 bool parcelObjIsPointer,
60 bool isReader,
61 ErrorMode mode,
62 const std::string &parentName,
63 const std::string &offsetText) const override;
64
Yifan Hongbf459bc2016-08-23 16:50:37 -070065 void emitResolveReferences(
66 Formatter &out,
67 const std::string &name,
68 bool nameIsPointer,
69 const std::string &parcelObj,
70 bool parcelObjIsPointer,
71 bool isReader,
72 ErrorMode mode) const override;
73
74 void emitResolveReferencesEmbedded(
75 Formatter &out,
76 size_t depth,
77 const std::string &name,
78 const std::string &sanitizedName,
79 bool nameIsPointer,
80 const std::string &parcelObj,
81 bool parcelObjIsPointer,
82 bool isReader,
83 ErrorMode mode,
84 const std::string &parentName,
85 const std::string &offsetText) const override;
86
Yifan Hong00f47172016-09-30 14:40:45 -070087 bool useParentInEmitResolveReferencesEmbedded() const override;
88
Andreas Huberf630bc82016-09-09 14:52:25 -070089 void emitJavaReaderWriter(
90 Formatter &out,
91 const std::string &parcelObj,
92 const std::string &argName,
93 bool isReader) const override;
94
Andreas Huber85eabdb2016-08-25 11:24:49 -070095 void emitJavaFieldInitializer(
96 Formatter &out, const std::string &fieldName) const override;
97
98 void emitJavaFieldReaderWriter(
99 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700100 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700101 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700102 const std::string &blobName,
103 const std::string &fieldName,
104 const std::string &offset,
105 bool isReader) const override;
106
Andreas Huberf630bc82016-09-09 14:52:25 -0700107 static void EmitJavaFieldReaderWriterForElementType(
108 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700109 size_t depth,
Andreas Huberf630bc82016-09-09 14:52:25 -0700110 const Type *elementType,
Andreas Huber709b62d2016-09-19 11:21:18 -0700111 const std::string &parcelName,
Andreas Huberf630bc82016-09-09 14:52:25 -0700112 const std::string &blobName,
113 const std::string &fieldName,
114 const std::string &offset,
115 bool isReader);
116
Andreas Huber881227d2016-08-02 14:20:21 -0700117 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700118 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700119 bool resultNeedsDeref() const override;
120
Andreas Huber70a59e12016-08-16 12:57:01 -0700121 bool isJavaCompatible() const override;
Andreas Huber60d3b222017-03-30 09:10:56 -0700122 bool containsPointer() const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700123
Andreas Huber85eabdb2016-08-25 11:24:49 -0700124 void getAlignmentAndSize(size_t *align, size_t *size) const override;
Martijn Coenenb2a861c2017-04-18 15:54:25 -0700125 static void getAlignmentAndSizeStatic(size_t *align, size_t *size);
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700126 private:
Yifan Hongbf459bc2016-08-23 16:50:37 -0700127 // Helper method for emitResolveReferences[Embedded].
128 // Pass empty childName and childOffsetText if the original
129 // childHandle is unknown.
130 // For example, given a vec<ref<T>> (T is a simple struct that
131 // contains primitive values only), then the following methods are
132 // invoked:
133 // 1. VectorType::emitResolveReferences
134 // ... which calls the helper with empty childName and childOffsetText
135 // 2. RefType::emitResolveReferencesEmbedded
136 void emitResolveReferencesEmbeddedHelper(
137 Formatter &out,
138 size_t depth,
139 const std::string &name,
140 const std::string &sanitizedName,
141 bool nameIsPointer,
142 const std::string &parcelObj,
143 bool parcelObjIsPointer,
144 bool isReader,
145 ErrorMode mode,
146 const std::string &childName,
147 const std::string &childOffsetText) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700148
Andreas Huber86a112b2016-10-19 14:25:16 -0700149 void emitReaderWriterForVectorOfBinders(
150 Formatter &out,
151 const std::string &name,
152 const std::string &parcelObj,
153 bool parcelObjIsPointer,
154 bool isReader,
155 ErrorMode mode) const;
156
Andreas Huberc9410c72016-07-28 12:18:40 -0700157 DISALLOW_COPY_AND_ASSIGN(VectorType);
158};
159
160} // namespace android
161
162#endif // VECTOR_TYPE_H_
163