blob: 1bf9a54442bbe21dab507d242178e7bc18f72752 [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
Andreas Huber4c865b72016-09-14 15:26:27 -070037 std::string getJavaType(
38 std::string *extra, bool forInitializer) const override;
Andreas Huber2831d512016-08-15 09:33:47 -070039
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070040 std::string getVtsType() const override;
41
Andreas Huber881227d2016-08-02 14:20:21 -070042 void emitReaderWriter(
43 Formatter &out,
44 const std::string &name,
45 const std::string &parcelObj,
46 bool parcelObjIsPointer,
47 bool isReader,
48 ErrorMode mode) const override;
49
50 void emitReaderWriterEmbedded(
51 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070052 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070053 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070054 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070055 bool nameIsPointer,
56 const std::string &parcelObj,
57 bool parcelObjIsPointer,
58 bool isReader,
59 ErrorMode mode,
60 const std::string &parentName,
61 const std::string &offsetText) const override;
62
Yifan Hongbf459bc2016-08-23 16:50:37 -070063 void emitResolveReferences(
64 Formatter &out,
65 const std::string &name,
66 bool nameIsPointer,
67 const std::string &parcelObj,
68 bool parcelObjIsPointer,
69 bool isReader,
70 ErrorMode mode) const override;
71
72 void emitResolveReferencesEmbedded(
73 Formatter &out,
74 size_t depth,
75 const std::string &name,
76 const std::string &sanitizedName,
77 bool nameIsPointer,
78 const std::string &parcelObj,
79 bool parcelObjIsPointer,
80 bool isReader,
81 ErrorMode mode,
82 const std::string &parentName,
83 const std::string &offsetText) const override;
84
Yifan Hong00f47172016-09-30 14:40:45 -070085 bool useParentInEmitResolveReferencesEmbedded() const override;
86
Andreas Huberf630bc82016-09-09 14:52:25 -070087 void emitJavaReaderWriter(
88 Formatter &out,
89 const std::string &parcelObj,
90 const std::string &argName,
91 bool isReader) const override;
92
Andreas Huber85eabdb2016-08-25 11:24:49 -070093 void emitJavaFieldInitializer(
94 Formatter &out, const std::string &fieldName) const override;
95
96 void emitJavaFieldReaderWriter(
97 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -070098 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -070099 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700100 const std::string &blobName,
101 const std::string &fieldName,
102 const std::string &offset,
103 bool isReader) const override;
104
Andreas Huberf630bc82016-09-09 14:52:25 -0700105 static void EmitJavaFieldReaderWriterForElementType(
106 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700107 size_t depth,
Andreas Huberf630bc82016-09-09 14:52:25 -0700108 const Type *elementType,
Andreas Huber709b62d2016-09-19 11:21:18 -0700109 const std::string &parcelName,
Andreas Huberf630bc82016-09-09 14:52:25 -0700110 const std::string &blobName,
111 const std::string &fieldName,
112 const std::string &offset,
113 bool isReader);
114
Andreas Huber881227d2016-08-02 14:20:21 -0700115 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700116 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700117 bool resultNeedsDeref() const override;
118
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700119 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700120 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700121
Andreas Huber70a59e12016-08-16 12:57:01 -0700122 bool isJavaCompatible() const override;
123
Andreas Huber85eabdb2016-08-25 11:24:49 -0700124 void getAlignmentAndSize(size_t *align, size_t *size) const override;
125
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