blob: e093777ea4212a449c29ee1bae1ef2e0eb1afc6e [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
Steven Moreland979e0992016-09-07 09:18:08 -070028 void addNamedTypesToSet(std::set<const FQName> &set) const override;
29
Andreas Huber4c865b72016-09-14 15:26:27 -070030 std::string getCppType(
31 StorageMode mode,
32 std::string *extra,
33 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070034
Andreas Huber4c865b72016-09-14 15:26:27 -070035 std::string getJavaType(
36 std::string *extra, bool forInitializer) const override;
Andreas Huber2831d512016-08-15 09:33:47 -070037
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070038 std::string getVtsType() const override;
39
Andreas Huber881227d2016-08-02 14:20:21 -070040 void emitReaderWriter(
41 Formatter &out,
42 const std::string &name,
43 const std::string &parcelObj,
44 bool parcelObjIsPointer,
45 bool isReader,
46 ErrorMode mode) const override;
47
48 void emitReaderWriterEmbedded(
49 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070050 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070051 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070052 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070053 bool nameIsPointer,
54 const std::string &parcelObj,
55 bool parcelObjIsPointer,
56 bool isReader,
57 ErrorMode mode,
58 const std::string &parentName,
59 const std::string &offsetText) const override;
60
Yifan Hongbf459bc2016-08-23 16:50:37 -070061 void emitResolveReferences(
62 Formatter &out,
63 const std::string &name,
64 bool nameIsPointer,
65 const std::string &parcelObj,
66 bool parcelObjIsPointer,
67 bool isReader,
68 ErrorMode mode) const override;
69
70 void emitResolveReferencesEmbedded(
71 Formatter &out,
72 size_t depth,
73 const std::string &name,
74 const std::string &sanitizedName,
75 bool nameIsPointer,
76 const std::string &parcelObj,
77 bool parcelObjIsPointer,
78 bool isReader,
79 ErrorMode mode,
80 const std::string &parentName,
81 const std::string &offsetText) const override;
82
Yifan Hong00f47172016-09-30 14:40:45 -070083 bool useParentInEmitResolveReferencesEmbedded() const override;
84
Andreas Huberf630bc82016-09-09 14:52:25 -070085 void emitJavaReaderWriter(
86 Formatter &out,
87 const std::string &parcelObj,
88 const std::string &argName,
89 bool isReader) const override;
90
Andreas Huber85eabdb2016-08-25 11:24:49 -070091 void emitJavaFieldInitializer(
92 Formatter &out, const std::string &fieldName) const override;
93
94 void emitJavaFieldReaderWriter(
95 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -070096 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -070097 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -070098 const std::string &blobName,
99 const std::string &fieldName,
100 const std::string &offset,
101 bool isReader) const override;
102
Andreas Huberf630bc82016-09-09 14:52:25 -0700103 static void EmitJavaFieldReaderWriterForElementType(
104 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700105 size_t depth,
Andreas Huberf630bc82016-09-09 14:52:25 -0700106 const Type *elementType,
Andreas Huber709b62d2016-09-19 11:21:18 -0700107 const std::string &parcelName,
Andreas Huberf630bc82016-09-09 14:52:25 -0700108 const std::string &blobName,
109 const std::string &fieldName,
110 const std::string &offset,
111 bool isReader);
112
Andreas Huber881227d2016-08-02 14:20:21 -0700113 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700114 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700115 bool resultNeedsDeref() const override;
116
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700117 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700118 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700119
Andreas Huber70a59e12016-08-16 12:57:01 -0700120 bool isJavaCompatible() const override;
121
Andreas Huber85eabdb2016-08-25 11:24:49 -0700122 void getAlignmentAndSize(size_t *align, size_t *size) const override;
123
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700124 private:
Yifan Hongbf459bc2016-08-23 16:50:37 -0700125 // Helper method for emitResolveReferences[Embedded].
126 // Pass empty childName and childOffsetText if the original
127 // childHandle is unknown.
128 // For example, given a vec<ref<T>> (T is a simple struct that
129 // contains primitive values only), then the following methods are
130 // invoked:
131 // 1. VectorType::emitResolveReferences
132 // ... which calls the helper with empty childName and childOffsetText
133 // 2. RefType::emitResolveReferencesEmbedded
134 void emitResolveReferencesEmbeddedHelper(
135 Formatter &out,
136 size_t depth,
137 const std::string &name,
138 const std::string &sanitizedName,
139 bool nameIsPointer,
140 const std::string &parcelObj,
141 bool parcelObjIsPointer,
142 bool isReader,
143 ErrorMode mode,
144 const std::string &childName,
145 const std::string &childOffsetText) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700146
147 DISALLOW_COPY_AND_ASSIGN(VectorType);
148};
149
150} // namespace android
151
152#endif // VECTOR_TYPE_H_
153