forked from LineageOS/android_system_tools_hidl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathType.h
274 lines (223 loc) · 8.71 KB
/
Type.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TYPE_H_
#define TYPE_H_
#include <android-base/macros.h>
#include <string>
#include <utils/Errors.h>
#include <vector>
#include <set>
namespace android {
struct Annotation;
struct Formatter;
struct ScalarType;
struct FQName;
struct Type {
Type();
virtual ~Type();
virtual bool isArray() const;
virtual bool isBinder() const;
virtual bool isBitField() const;
virtual bool isCompoundType() const;
virtual bool isEnum() const;
virtual bool isHandle() const;
virtual bool isInterface() const;
virtual bool isNamedType() const;
virtual bool isMemory() const;
virtual bool isPointer() const;
virtual bool isScope() const;
virtual bool isScalar() const;
virtual bool isString() const;
virtual bool isTemplatedType() const;
virtual bool isTypeDef() const;
virtual bool isVector() const;
virtual const ScalarType *resolveToScalarType() const;
virtual std::string typeName() const = 0;
bool isValidEnumStorageType() const;
virtual bool isElidableType() const;
virtual bool canCheckEquality() const;
enum StorageMode {
StorageMode_Stack,
StorageMode_Argument,
StorageMode_Result,
};
// specifyNamespaces: whether to specify namespaces for built-in types
virtual std::string getCppType(
StorageMode mode,
bool specifyNamespaces) const;
std::string decorateCppName(
const std::string &name,
StorageMode mode,
bool specifyNamespaces) const;
std::string getCppStackType(bool specifyNamespaces = true) const;
std::string getCppResultType(bool specifyNamespaces = true) const;
std::string getCppArgumentType(bool specifyNamespaces = true) const;
// For an array type, dimensionality information will be accumulated at the
// end of the returned string.
// if forInitializer == true, actual dimensions are included, i.e. [3][5],
// otherwise (and by default), they are omitted, i.e. [][].
virtual std::string getJavaType(bool forInitializer = false) const;
virtual std::string getJavaWrapperType() const;
virtual std::string getJavaSuffix() const;
virtual std::string getVtsType() const;
virtual std::string getVtsValueName() const;
enum ErrorMode {
ErrorMode_Ignore,
ErrorMode_Goto,
ErrorMode_Break,
ErrorMode_Return,
};
virtual void emitReaderWriter(
Formatter &out,
const std::string &name,
const std::string &parcelObj,
bool parcelObjIsPointer,
bool isReader,
ErrorMode mode) const;
virtual void emitReaderWriterEmbedded(
Formatter &out,
size_t depth,
const std::string &name,
const std::string &sanitizedName,
bool nameIsPointer,
const std::string &parcelObj,
bool parcelObjIsPointer,
bool isReader,
ErrorMode mode,
const std::string &parentName,
const std::string &offsetText) const;
virtual void emitResolveReferences(
Formatter &out,
const std::string &name,
bool nameIsPointer,
const std::string &parcelObj,
bool parcelObjIsPointer,
bool isReader,
ErrorMode mode) const;
virtual void emitResolveReferencesEmbedded(
Formatter &out,
size_t depth,
const std::string &name,
const std::string &sanitizedName,
bool nameIsPointer,
const std::string &parcelObj,
bool parcelObjIsPointer,
bool isReader,
ErrorMode mode,
const std::string &parentName,
const std::string &offsetText) const;
virtual void emitDump(
Formatter &out,
const std::string &streamName,
const std::string &name) const;
virtual void emitJavaDump(
Formatter &out,
const std::string &streamName,
const std::string &name) const;
virtual bool useParentInEmitResolveReferencesEmbedded() const;
virtual bool useNameInEmitReaderWriterEmbedded(bool isReader) const;
virtual void emitJavaReaderWriter(
Formatter &out,
const std::string &parcelObj,
const std::string &argName,
bool isReader) const;
virtual void emitJavaFieldInitializer(
Formatter &out,
const std::string &fieldName) const;
virtual void emitJavaFieldReaderWriter(
Formatter &out,
size_t depth,
const std::string &parcelName,
const std::string &blobName,
const std::string &fieldName,
const std::string &offset,
bool isReader) const;
virtual status_t emitTypeDeclarations(Formatter &out) const;
// Emit any declarations pertaining to this type that have to be
// at global scope, i.e. enum class operators.
virtual status_t emitGlobalTypeDeclarations(Formatter &out) const;
// Emit any declarations pertaining to this type that have to be
// at global scope for transport, e.g. read/writeEmbeddedTo/FromParcel
virtual status_t emitGlobalHwDeclarations(Formatter &out) const;
virtual status_t emitTypeDefinitions(
Formatter &out, const std::string prefix) const;
virtual status_t emitJavaTypeDeclarations(
Formatter &out, bool atTopLevel) const;
virtual bool needsEmbeddedReadWrite() const;
virtual bool needsResolveReferences() const;
virtual bool resultNeedsDeref() const;
// Generates type declaration for vts proto file.
// TODO (b/30844146): make it a pure virtual method.
virtual status_t emitVtsTypeDeclarations(Formatter &out) const;
// Generates type declaration as attribute of method (return value or method
// argument) or attribute of compound type for vts proto file.
virtual status_t emitVtsAttributeType(Formatter &out) const;
// Returns true iff this type is supported through the Java backend.
virtual bool isJavaCompatible() const;
virtual bool containsPointer() const;
virtual void getAlignmentAndSize(size_t *align, size_t *size) const;
void setAnnotations(std::vector<Annotation *> *annotations);
const std::vector<Annotation *> &annotations() const;
virtual void appendToExportedTypesVector(
std::vector<const Type *> *exportedTypes) const;
virtual status_t emitExportedHeader(Formatter &out, bool forJava) const;
protected:
void handleError(Formatter &out, ErrorMode mode) const;
void emitReaderWriterEmbeddedForTypeName(
Formatter &out,
const std::string &name,
bool nameIsPointer,
const std::string &parcelObj,
bool parcelObjIsPointer,
bool isReader,
ErrorMode mode,
const std::string &parentName,
const std::string &offsetText,
const std::string &typeName,
const std::string &childName,
const std::string &funcNamespace) const;
void emitJavaReaderWriterWithSuffix(
Formatter &out,
const std::string &parcelObj,
const std::string &argName,
bool isReader,
const std::string &suffix,
const std::string &extra) const;
void emitDumpWithMethod(
Formatter &out,
const std::string &streamName,
const std::string &methodName,
const std::string &name) const;
private:
std::vector<Annotation *> *mAnnotations;
DISALLOW_COPY_AND_ASSIGN(Type);
};
/* Base type for VectorType and RefType. */
struct TemplatedType : public Type {
void setElementType(Type *elementType);
Type *getElementType() const;
bool isTemplatedType() const override;
virtual bool isCompatibleElementType(Type *elementType) const = 0;
status_t emitVtsTypeDeclarations(Formatter &out) const override;
status_t emitVtsAttributeType(Formatter &out) const override;
protected:
TemplatedType();
Type *mElementType;
private:
DISALLOW_COPY_AND_ASSIGN(TemplatedType);
};
} // namespace android
#endif // TYPE_H_