blob: 33f2db6166c3792f13a2e01c14c9391c32baf7ea [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 ARRAY_TYPE_H_
18
19#define ARRAY_TYPE_H_
20
21#include "Type.h"
22
Andreas Huber709b62d2016-09-19 11:21:18 -070023#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070024
25namespace android {
26
Yifan Hongf24fa852016-09-23 11:03:15 -070027struct ConstantExpression;
28
Andreas Huberc9410c72016-07-28 12:18:40 -070029struct ArrayType : public Type {
Andreas Huber709b62d2016-09-19 11:21:18 -070030 // Extends existing array by adding another dimension.
Yifan Hongf24fa852016-09-23 11:03:15 -070031 ArrayType(ArrayType *srcArray, ConstantExpression *size);
Andreas Huber709b62d2016-09-19 11:21:18 -070032
Yifan Hongf24fa852016-09-23 11:03:15 -070033 ArrayType(Type *elementType, ConstantExpression *size);
Andreas Huber709b62d2016-09-19 11:21:18 -070034
Andreas Huber709b62d2016-09-19 11:21:18 -070035 bool isArray() const override;
Yifan Hongc6752dc2016-12-20 14:00:14 -080036 bool canCheckEquality() const override;
Andreas Huber709b62d2016-09-19 11:21:18 -070037
Andreas Huberf03332a2016-09-22 15:35:43 -070038 Type *getElementType() const;
39
Yifan Hongbd33e382016-11-02 13:30:17 -070040 void prependDimension(ConstantExpression *size);
41 void appendDimension(ConstantExpression *size);
Andreas Huberf03332a2016-09-22 15:35:43 -070042 size_t countDimensions() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070043
Steven Moreland979e0992016-09-07 09:18:08 -070044 std::string getCppType(StorageMode mode,
Steven Moreland979e0992016-09-07 09:18:08 -070045 bool specifyNamespaces) const override;
46
Yifan Hong30b5d1f2017-04-03 12:19:25 -070047 std::string getInternalDataCppType() const;
48
Yifan Hong4ed13472016-11-02 10:44:11 -070049 std::string getJavaType(bool forInitializer) const override;
Andreas Huber2831d512016-08-15 09:33:47 -070050
Andreas Huberf03332a2016-09-22 15:35:43 -070051 std::string getJavaWrapperType() const override;
52
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070053 std::string getVtsType() const override;
54
Andreas Huber881227d2016-08-02 14:20:21 -070055 void emitReaderWriter(
56 Formatter &out,
57 const std::string &name,
58 const std::string &parcelObj,
59 bool parcelObjIsPointer,
60 bool isReader,
61 ErrorMode mode) const override;
62
63 void emitReaderWriterEmbedded(
64 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070065 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070066 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070067 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070068 bool nameIsPointer,
69 const std::string &parcelObj,
70 bool parcelObjIsPointer,
71 bool isReader,
72 ErrorMode mode,
73 const std::string &parentName,
74 const std::string &offsetText) const override;
75
Yifan Hongbf459bc2016-08-23 16:50:37 -070076 void emitResolveReferences(
77 Formatter &out,
78 const std::string &name,
79 bool nameIsPointer,
80 const std::string &parcelObj,
81 bool parcelObjIsPointer,
82 bool isReader,
83 ErrorMode mode) const override;
84
85 void emitResolveReferencesEmbedded(
86 Formatter &out,
87 size_t depth,
88 const std::string &name,
89 const std::string &sanitizedName,
90 bool nameIsPointer,
91 const std::string &parcelObj,
92 bool parcelObjIsPointer,
93 bool isReader,
94 ErrorMode mode,
95 const std::string &parentName,
96 const std::string &offsetText) const override;
97
Yifan Honge45b5302017-02-22 10:49:07 -080098 void emitJavaDump(
99 Formatter &out,
100 const std::string &streamName,
101 const std::string &name) const override;
102
Andreas Huber881227d2016-08-02 14:20:21 -0700103 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700104 bool needsResolveReferences() const override;
Andreas Huberf03332a2016-09-22 15:35:43 -0700105 bool resultNeedsDeref() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700106
Andreas Huber2831d512016-08-15 09:33:47 -0700107 void emitJavaReaderWriter(
108 Formatter &out,
109 const std::string &parcelObj,
110 const std::string &argName,
111 bool isReader) const override;
112
Andreas Huber85eabdb2016-08-25 11:24:49 -0700113 void emitJavaFieldInitializer(
114 Formatter &out, const std::string &fieldName) const override;
115
116 void emitJavaFieldReaderWriter(
117 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700118 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700119 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700120 const std::string &blobName,
121 const std::string &fieldName,
122 const std::string &offset,
123 bool isReader) const override;
124
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700125 status_t emitVtsTypeDeclarations(Formatter &out) const override;
126
Andreas Huber70a59e12016-08-16 12:57:01 -0700127 bool isJavaCompatible() const override;
Andreas Huber60d3b222017-03-30 09:10:56 -0700128 bool containsPointer() const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700129
Andreas Huber85eabdb2016-08-25 11:24:49 -0700130 void getAlignmentAndSize(size_t *align, size_t *size) const override;
131
Andreas Huberc9410c72016-07-28 12:18:40 -0700132private:
133 Type *mElementType;
Yifan Hong5706a432016-11-02 09:44:18 -0700134 std::vector<ConstantExpression *> mSizes;
Andreas Huberc9410c72016-07-28 12:18:40 -0700135
Yifan Hongbf459bc2016-08-23 16:50:37 -0700136 size_t dimension() const;
137
Andreas Huberc9410c72016-07-28 12:18:40 -0700138 DISALLOW_COPY_AND_ASSIGN(ArrayType);
139};
140
141} // namespace android
142
143#endif // ARRAY_TYPE_H_
144