blob: a301a76b34e4f8a6bb90f9a172e0a81a149268b2 [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;
44
Andreas Huber881227d2016-08-02 14:20:21 -070045 void emitReaderWriter(
46 Formatter &out,
47 const std::string &name,
48 const std::string &parcelObj,
49 bool parcelObjIsPointer,
50 bool isReader,
51 ErrorMode mode) const override;
52
53 void emitReaderWriterEmbedded(
54 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070055 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070056 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070057 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070058 bool nameIsPointer,
59 const std::string &parcelObj,
60 bool parcelObjIsPointer,
61 bool isReader,
62 ErrorMode mode,
63 const std::string &parentName,
64 const std::string &offsetText) const override;
65
Yifan Hongbf459bc2016-08-23 16:50:37 -070066 void emitResolveReferences(
67 Formatter &out,
68 const std::string &name,
69 bool nameIsPointer,
70 const std::string &parcelObj,
71 bool parcelObjIsPointer,
72 bool isReader,
73 ErrorMode mode) const override;
74
75 void emitResolveReferencesEmbedded(
76 Formatter &out,
77 size_t depth,
78 const std::string &name,
79 const std::string &sanitizedName,
80 bool nameIsPointer,
81 const std::string &parcelObj,
82 bool parcelObjIsPointer,
83 bool isReader,
84 ErrorMode mode,
85 const std::string &parentName,
86 const std::string &offsetText) const override;
87
Yifan Hong00f47172016-09-30 14:40:45 -070088 bool useParentInEmitResolveReferencesEmbedded() const override;
89
Andreas Huberf630bc82016-09-09 14:52:25 -070090 void emitJavaReaderWriter(
91 Formatter &out,
92 const std::string &parcelObj,
93 const std::string &argName,
94 bool isReader) const override;
95
Andreas Huber85eabdb2016-08-25 11:24:49 -070096 void emitJavaFieldInitializer(
97 Formatter &out, const std::string &fieldName) const override;
98
99 void emitJavaFieldReaderWriter(
100 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700101 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700102 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700103 const std::string &blobName,
104 const std::string &fieldName,
105 const std::string &offset,
106 bool isReader) const override;
107
Andreas Huberf630bc82016-09-09 14:52:25 -0700108 static void EmitJavaFieldReaderWriterForElementType(
109 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700110 size_t depth,
Andreas Huberf630bc82016-09-09 14:52:25 -0700111 const Type *elementType,
Andreas Huber709b62d2016-09-19 11:21:18 -0700112 const std::string &parcelName,
Andreas Huberf630bc82016-09-09 14:52:25 -0700113 const std::string &blobName,
114 const std::string &fieldName,
115 const std::string &offset,
116 bool isReader);
117
Andreas Huber881227d2016-08-02 14:20:21 -0700118 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700119 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700120 bool resultNeedsDeref() const override;
121
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700122 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700123 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700124
Andreas Huber70a59e12016-08-16 12:57:01 -0700125 bool isJavaCompatible() const override;
126
Andreas Huber85eabdb2016-08-25 11:24:49 -0700127 void getAlignmentAndSize(size_t *align, size_t *size) const override;
128
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700129 private:
Yifan Hongbf459bc2016-08-23 16:50:37 -0700130 // Helper method for emitResolveReferences[Embedded].
131 // Pass empty childName and childOffsetText if the original
132 // childHandle is unknown.
133 // For example, given a vec<ref<T>> (T is a simple struct that
134 // contains primitive values only), then the following methods are
135 // invoked:
136 // 1. VectorType::emitResolveReferences
137 // ... which calls the helper with empty childName and childOffsetText
138 // 2. RefType::emitResolveReferencesEmbedded
139 void emitResolveReferencesEmbeddedHelper(
140 Formatter &out,
141 size_t depth,
142 const std::string &name,
143 const std::string &sanitizedName,
144 bool nameIsPointer,
145 const std::string &parcelObj,
146 bool parcelObjIsPointer,
147 bool isReader,
148 ErrorMode mode,
149 const std::string &childName,
150 const std::string &childOffsetText) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700151
Andreas Huber86a112b2016-10-19 14:25:16 -0700152 void emitReaderWriterForVectorOfBinders(
153 Formatter &out,
154 const std::string &name,
155 const std::string &parcelObj,
156 bool parcelObjIsPointer,
157 bool isReader,
158 ErrorMode mode) const;
159
Andreas Huberc9410c72016-07-28 12:18:40 -0700160 DISALLOW_COPY_AND_ASSIGN(VectorType);
161};
162
163} // namespace android
164
165#endif // VECTOR_TYPE_H_
166