blob: edb5e1c9b68510c428d2a8ce70c1dfbb5a3a097b [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
Timur Iskhakov40731af2017-08-24 14:18:35 -070021#include <vector>
22
23#include "Reference.h"
Andreas Huberc9410c72016-07-28 12:18:40 -070024#include "Type.h"
25
26namespace android {
27
Yifan Hongbf459bc2016-08-23 16:50:37 -070028struct VectorType : public TemplatedType {
Timur Iskhakov63f39902017-08-29 15:47:29 -070029 VectorType(Scope* parent);
Andreas Huberc9410c72016-07-28 12:18:40 -070030
Andreas Huber86a112b2016-10-19 14:25:16 -070031 bool isVector() const override;
32 bool isVectorOfBinders() const;
Steven Moreland30bb6a82016-11-30 09:18:34 -080033 std::string typeName() const override;
34 bool isCompatibleElementType(Type *elementType) const override;
Andreas Huber86a112b2016-10-19 14:25:16 -070035
Timur Iskhakovb58f4182017-08-29 15:19:24 -070036 std::vector<const Reference<Type>*> getStrongReferences() const override;
Timur Iskhakov40731af2017-08-24 14:18:35 -070037
Yifan Hongc6752dc2016-12-20 14:00:14 -080038 bool canCheckEquality() const override;
39
Andreas Huber4c865b72016-09-14 15:26:27 -070040 std::string getCppType(
41 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070042 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070043
Yifan Hong4ed13472016-11-02 10:44:11 -070044 std::string getJavaType(bool forInitializer) const override;
Andreas Huber2831d512016-08-15 09:33:47 -070045
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070046 std::string getVtsType() const override;
Zhuoyao Zhange9667842017-01-19 12:35:32 -080047 std::string getVtsValueName() const override;
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070048
Andreas Huber881227d2016-08-02 14:20:21 -070049 void emitReaderWriter(
50 Formatter &out,
51 const std::string &name,
52 const std::string &parcelObj,
53 bool parcelObjIsPointer,
54 bool isReader,
55 ErrorMode mode) const override;
56
57 void emitReaderWriterEmbedded(
58 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070059 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070060 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070061 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070062 bool nameIsPointer,
63 const std::string &parcelObj,
64 bool parcelObjIsPointer,
65 bool isReader,
66 ErrorMode mode,
67 const std::string &parentName,
68 const std::string &offsetText) const override;
69
Yifan Hongbf459bc2016-08-23 16:50:37 -070070 void emitResolveReferences(
71 Formatter &out,
72 const std::string &name,
73 bool nameIsPointer,
74 const std::string &parcelObj,
75 bool parcelObjIsPointer,
76 bool isReader,
77 ErrorMode mode) const override;
78
79 void emitResolveReferencesEmbedded(
80 Formatter &out,
81 size_t depth,
82 const std::string &name,
83 const std::string &sanitizedName,
84 bool nameIsPointer,
85 const std::string &parcelObj,
86 bool parcelObjIsPointer,
87 bool isReader,
88 ErrorMode mode,
89 const std::string &parentName,
90 const std::string &offsetText) const override;
91
Yifan Hong00f47172016-09-30 14:40:45 -070092 bool useParentInEmitResolveReferencesEmbedded() const override;
93
Andreas Huberf630bc82016-09-09 14:52:25 -070094 void emitJavaReaderWriter(
95 Formatter &out,
96 const std::string &parcelObj,
97 const std::string &argName,
98 bool isReader) const override;
99
Andreas Huber85eabdb2016-08-25 11:24:49 -0700100 void emitJavaFieldInitializer(
101 Formatter &out, const std::string &fieldName) const override;
102
103 void emitJavaFieldReaderWriter(
104 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700105 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700106 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700107 const std::string &blobName,
108 const std::string &fieldName,
109 const std::string &offset,
110 bool isReader) const override;
111
Andreas Huberf630bc82016-09-09 14:52:25 -0700112 static void EmitJavaFieldReaderWriterForElementType(
113 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700114 size_t depth,
Andreas Huberf630bc82016-09-09 14:52:25 -0700115 const Type *elementType,
Andreas Huber709b62d2016-09-19 11:21:18 -0700116 const std::string &parcelName,
Andreas Huberf630bc82016-09-09 14:52:25 -0700117 const std::string &blobName,
118 const std::string &fieldName,
119 const std::string &offset,
120 bool isReader);
121
Andreas Huber881227d2016-08-02 14:20:21 -0700122 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700123 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700124 bool resultNeedsDeref() const override;
125
Andreas Huber70a59e12016-08-16 12:57:01 -0700126 bool isJavaCompatible() const override;
Andreas Huber60d3b222017-03-30 09:10:56 -0700127 bool containsPointer() const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700128
Andreas Huber85eabdb2016-08-25 11:24:49 -0700129 void getAlignmentAndSize(size_t *align, size_t *size) const override;
Martijn Coenenb2a861c2017-04-18 15:54:25 -0700130 static void getAlignmentAndSizeStatic(size_t *align, size_t *size);
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700131 private:
Yifan Hongbf459bc2016-08-23 16:50:37 -0700132 // Helper method for emitResolveReferences[Embedded].
133 // Pass empty childName and childOffsetText if the original
134 // childHandle is unknown.
135 // For example, given a vec<ref<T>> (T is a simple struct that
136 // contains primitive values only), then the following methods are
137 // invoked:
138 // 1. VectorType::emitResolveReferences
139 // ... which calls the helper with empty childName and childOffsetText
140 // 2. RefType::emitResolveReferencesEmbedded
141 void emitResolveReferencesEmbeddedHelper(
142 Formatter &out,
143 size_t depth,
144 const std::string &name,
145 const std::string &sanitizedName,
146 bool nameIsPointer,
147 const std::string &parcelObj,
148 bool parcelObjIsPointer,
149 bool isReader,
150 ErrorMode mode,
151 const std::string &childName,
152 const std::string &childOffsetText) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700153
Andreas Huber86a112b2016-10-19 14:25:16 -0700154 void emitReaderWriterForVectorOfBinders(
155 Formatter &out,
156 const std::string &name,
157 const std::string &parcelObj,
158 bool parcelObjIsPointer,
159 bool isReader,
160 ErrorMode mode) const;
161
Andreas Huberc9410c72016-07-28 12:18:40 -0700162 DISALLOW_COPY_AND_ASSIGN(VectorType);
163};
164
165} // namespace android
166
167#endif // VECTOR_TYPE_H_
168