blob: 333d69daa3a59572ac425bb55c26956dcf5b1db9 [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;
30
Steven Moreland979e0992016-09-07 09:18:08 -070031 void addNamedTypesToSet(std::set<const FQName> &set) const override;
32
Andreas Huber4c865b72016-09-14 15:26:27 -070033 std::string getCppType(
34 StorageMode mode,
35 std::string *extra,
36 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070037
Andreas Huber4c865b72016-09-14 15:26:27 -070038 std::string getJavaType(
39 std::string *extra, 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;
42
Andreas Huber881227d2016-08-02 14:20:21 -070043 void emitReaderWriter(
44 Formatter &out,
45 const std::string &name,
46 const std::string &parcelObj,
47 bool parcelObjIsPointer,
48 bool isReader,
49 ErrorMode mode) const override;
50
51 void emitReaderWriterEmbedded(
52 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070053 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070054 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070055 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070056 bool nameIsPointer,
57 const std::string &parcelObj,
58 bool parcelObjIsPointer,
59 bool isReader,
60 ErrorMode mode,
61 const std::string &parentName,
62 const std::string &offsetText) const override;
63
Yifan Hongbf459bc2016-08-23 16:50:37 -070064 void emitResolveReferences(
65 Formatter &out,
66 const std::string &name,
67 bool nameIsPointer,
68 const std::string &parcelObj,
69 bool parcelObjIsPointer,
70 bool isReader,
71 ErrorMode mode) const override;
72
73 void emitResolveReferencesEmbedded(
74 Formatter &out,
75 size_t depth,
76 const std::string &name,
77 const std::string &sanitizedName,
78 bool nameIsPointer,
79 const std::string &parcelObj,
80 bool parcelObjIsPointer,
81 bool isReader,
82 ErrorMode mode,
83 const std::string &parentName,
84 const std::string &offsetText) const override;
85
Yifan Hong00f47172016-09-30 14:40:45 -070086 bool useParentInEmitResolveReferencesEmbedded() const override;
87
Andreas Huberf630bc82016-09-09 14:52:25 -070088 void emitJavaReaderWriter(
89 Formatter &out,
90 const std::string &parcelObj,
91 const std::string &argName,
92 bool isReader) const override;
93
Andreas Huber85eabdb2016-08-25 11:24:49 -070094 void emitJavaFieldInitializer(
95 Formatter &out, const std::string &fieldName) const override;
96
97 void emitJavaFieldReaderWriter(
98 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -070099 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700100 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700101 const std::string &blobName,
102 const std::string &fieldName,
103 const std::string &offset,
104 bool isReader) const override;
105
Andreas Huberf630bc82016-09-09 14:52:25 -0700106 static void EmitJavaFieldReaderWriterForElementType(
107 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700108 size_t depth,
Andreas Huberf630bc82016-09-09 14:52:25 -0700109 const Type *elementType,
Andreas Huber709b62d2016-09-19 11:21:18 -0700110 const std::string &parcelName,
Andreas Huberf630bc82016-09-09 14:52:25 -0700111 const std::string &blobName,
112 const std::string &fieldName,
113 const std::string &offset,
114 bool isReader);
115
Andreas Huber881227d2016-08-02 14:20:21 -0700116 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700117 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700118 bool resultNeedsDeref() const override;
119
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700120 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700121 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700122
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