blob: c267ba918ae13c88903cae3bf4f6169f60914b9d [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
Steven Moreland979e0992016-09-07 09:18:08 -070035 void addNamedTypesToSet(std::set<const FQName> &set) const override;
36
Andreas Huber4c865b72016-09-14 15:26:27 -070037 std::string getCppType(
38 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070039 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070040
Yifan Hong4ed13472016-11-02 10:44:11 -070041 std::string getJavaType(bool forInitializer) const override;
Andreas Huber2831d512016-08-15 09:33:47 -070042
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070043 std::string getVtsType() const override;
Zhuoyao Zhange9667842017-01-19 12:35:32 -080044 std::string getVtsValueName() const override;
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070045
Andreas Huber881227d2016-08-02 14:20:21 -070046 void emitReaderWriter(
47 Formatter &out,
48 const std::string &name,
49 const std::string &parcelObj,
50 bool parcelObjIsPointer,
51 bool isReader,
52 ErrorMode mode) const override;
53
54 void emitReaderWriterEmbedded(
55 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070056 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070057 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070058 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070059 bool nameIsPointer,
60 const std::string &parcelObj,
61 bool parcelObjIsPointer,
62 bool isReader,
63 ErrorMode mode,
64 const std::string &parentName,
65 const std::string &offsetText) const override;
66
Yifan Hongbf459bc2016-08-23 16:50:37 -070067 void emitResolveReferences(
68 Formatter &out,
69 const std::string &name,
70 bool nameIsPointer,
71 const std::string &parcelObj,
72 bool parcelObjIsPointer,
73 bool isReader,
74 ErrorMode mode) const override;
75
76 void emitResolveReferencesEmbedded(
77 Formatter &out,
78 size_t depth,
79 const std::string &name,
80 const std::string &sanitizedName,
81 bool nameIsPointer,
82 const std::string &parcelObj,
83 bool parcelObjIsPointer,
84 bool isReader,
85 ErrorMode mode,
86 const std::string &parentName,
87 const std::string &offsetText) const override;
88
Yifan Hong00f47172016-09-30 14:40:45 -070089 bool useParentInEmitResolveReferencesEmbedded() const override;
90
Andreas Huberf630bc82016-09-09 14:52:25 -070091 void emitJavaReaderWriter(
92 Formatter &out,
93 const std::string &parcelObj,
94 const std::string &argName,
95 bool isReader) const override;
96
Andreas Huber85eabdb2016-08-25 11:24:49 -070097 void emitJavaFieldInitializer(
98 Formatter &out, const std::string &fieldName) const override;
99
100 void emitJavaFieldReaderWriter(
101 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700102 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700103 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700104 const std::string &blobName,
105 const std::string &fieldName,
106 const std::string &offset,
107 bool isReader) const override;
108
Andreas Huberf630bc82016-09-09 14:52:25 -0700109 static void EmitJavaFieldReaderWriterForElementType(
110 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700111 size_t depth,
Andreas Huberf630bc82016-09-09 14:52:25 -0700112 const Type *elementType,
Andreas Huber709b62d2016-09-19 11:21:18 -0700113 const std::string &parcelName,
Andreas Huberf630bc82016-09-09 14:52:25 -0700114 const std::string &blobName,
115 const std::string &fieldName,
116 const std::string &offset,
117 bool isReader);
118
Andreas Huber881227d2016-08-02 14:20:21 -0700119 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700120 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700121 bool resultNeedsDeref() 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
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700127 private:
Yifan Hongbf459bc2016-08-23 16:50:37 -0700128 // Helper method for emitResolveReferences[Embedded].
129 // Pass empty childName and childOffsetText if the original
130 // childHandle is unknown.
131 // For example, given a vec<ref<T>> (T is a simple struct that
132 // contains primitive values only), then the following methods are
133 // invoked:
134 // 1. VectorType::emitResolveReferences
135 // ... which calls the helper with empty childName and childOffsetText
136 // 2. RefType::emitResolveReferencesEmbedded
137 void emitResolveReferencesEmbeddedHelper(
138 Formatter &out,
139 size_t depth,
140 const std::string &name,
141 const std::string &sanitizedName,
142 bool nameIsPointer,
143 const std::string &parcelObj,
144 bool parcelObjIsPointer,
145 bool isReader,
146 ErrorMode mode,
147 const std::string &childName,
148 const std::string &childOffsetText) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700149
Andreas Huber86a112b2016-10-19 14:25:16 -0700150 void emitReaderWriterForVectorOfBinders(
151 Formatter &out,
152 const std::string &name,
153 const std::string &parcelObj,
154 bool parcelObjIsPointer,
155 bool isReader,
156 ErrorMode mode) const;
157
Andreas Huberc9410c72016-07-28 12:18:40 -0700158 DISALLOW_COPY_AND_ASSIGN(VectorType);
159};
160
161} // namespace android
162
163#endif // VECTOR_TYPE_H_
164