blob: 91ac811fc3cb5f6dfb4668f72329550386ed7192 [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,
Andreas Huber4c865b72016-09-14 15:26:27 -070035 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070036
Yifan Hong4ed13472016-11-02 10:44:11 -070037 std::string getJavaType(bool forInitializer) const override;
Andreas Huber2831d512016-08-15 09:33:47 -070038
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070039 std::string getVtsType() const override;
40
Andreas Huber881227d2016-08-02 14:20:21 -070041 void emitReaderWriter(
42 Formatter &out,
43 const std::string &name,
44 const std::string &parcelObj,
45 bool parcelObjIsPointer,
46 bool isReader,
47 ErrorMode mode) const override;
48
49 void emitReaderWriterEmbedded(
50 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070051 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070052 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070053 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070054 bool nameIsPointer,
55 const std::string &parcelObj,
56 bool parcelObjIsPointer,
57 bool isReader,
58 ErrorMode mode,
59 const std::string &parentName,
60 const std::string &offsetText) const override;
61
Yifan Hongbf459bc2016-08-23 16:50:37 -070062 void emitResolveReferences(
63 Formatter &out,
64 const std::string &name,
65 bool nameIsPointer,
66 const std::string &parcelObj,
67 bool parcelObjIsPointer,
68 bool isReader,
69 ErrorMode mode) const override;
70
71 void emitResolveReferencesEmbedded(
72 Formatter &out,
73 size_t depth,
74 const std::string &name,
75 const std::string &sanitizedName,
76 bool nameIsPointer,
77 const std::string &parcelObj,
78 bool parcelObjIsPointer,
79 bool isReader,
80 ErrorMode mode,
81 const std::string &parentName,
82 const std::string &offsetText) const override;
83
Yifan Hong00f47172016-09-30 14:40:45 -070084 bool useParentInEmitResolveReferencesEmbedded() const override;
85
Andreas Huberf630bc82016-09-09 14:52:25 -070086 void emitJavaReaderWriter(
87 Formatter &out,
88 const std::string &parcelObj,
89 const std::string &argName,
90 bool isReader) const override;
91
Andreas Huber85eabdb2016-08-25 11:24:49 -070092 void emitJavaFieldInitializer(
93 Formatter &out, const std::string &fieldName) const override;
94
95 void emitJavaFieldReaderWriter(
96 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -070097 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -070098 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -070099 const std::string &blobName,
100 const std::string &fieldName,
101 const std::string &offset,
102 bool isReader) const override;
103
Andreas Huberf630bc82016-09-09 14:52:25 -0700104 static void EmitJavaFieldReaderWriterForElementType(
105 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700106 size_t depth,
Andreas Huberf630bc82016-09-09 14:52:25 -0700107 const Type *elementType,
Andreas Huber709b62d2016-09-19 11:21:18 -0700108 const std::string &parcelName,
Andreas Huberf630bc82016-09-09 14:52:25 -0700109 const std::string &blobName,
110 const std::string &fieldName,
111 const std::string &offset,
112 bool isReader);
113
Andreas Huber881227d2016-08-02 14:20:21 -0700114 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700115 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700116 bool resultNeedsDeref() const override;
117
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700118 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700119 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700120
Andreas Huber70a59e12016-08-16 12:57:01 -0700121 bool isJavaCompatible() const override;
122
Andreas Huber85eabdb2016-08-25 11:24:49 -0700123 void getAlignmentAndSize(size_t *align, size_t *size) const override;
124
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700125 private:
Yifan Hongbf459bc2016-08-23 16:50:37 -0700126 // Helper method for emitResolveReferences[Embedded].
127 // Pass empty childName and childOffsetText if the original
128 // childHandle is unknown.
129 // For example, given a vec<ref<T>> (T is a simple struct that
130 // contains primitive values only), then the following methods are
131 // invoked:
132 // 1. VectorType::emitResolveReferences
133 // ... which calls the helper with empty childName and childOffsetText
134 // 2. RefType::emitResolveReferencesEmbedded
135 void emitResolveReferencesEmbeddedHelper(
136 Formatter &out,
137 size_t depth,
138 const std::string &name,
139 const std::string &sanitizedName,
140 bool nameIsPointer,
141 const std::string &parcelObj,
142 bool parcelObjIsPointer,
143 bool isReader,
144 ErrorMode mode,
145 const std::string &childName,
146 const std::string &childOffsetText) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700147
Andreas Huber86a112b2016-10-19 14:25:16 -0700148 void emitReaderWriterForVectorOfBinders(
149 Formatter &out,
150 const std::string &name,
151 const std::string &parcelObj,
152 bool parcelObjIsPointer,
153 bool isReader,
154 ErrorMode mode) const;
155
Andreas Huberc9410c72016-07-28 12:18:40 -0700156 DISALLOW_COPY_AND_ASSIGN(VectorType);
157};
158
159} // namespace android
160
161#endif // VECTOR_TYPE_H_
162