blob: 2ced0716109a2ab3debf53c3d0c7dbf73596f0fa [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
Timur Iskhakov505316c2017-08-05 03:38:59 +000021#include "Reference.h"
Andreas Huberc9410c72016-07-28 12:18:40 -070022#include "Type.h"
23
Andreas Huber709b62d2016-09-19 11:21:18 -070024#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070025
26namespace android {
27
Yifan Hongf24fa852016-09-23 11:03:15 -070028struct ConstantExpression;
29
Andreas Huberc9410c72016-07-28 12:18:40 -070030struct ArrayType : public Type {
Timur Iskhakov63f39902017-08-29 15:47:29 -070031 ArrayType(const Reference<Type>& elementType, ConstantExpression* size, Scope* parent);
Andreas Huber709b62d2016-09-19 11:21:18 -070032
Andreas Huber709b62d2016-09-19 11:21:18 -070033 bool isArray() const override;
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -070034 bool deepCanCheckEquality(std::unordered_set<const Type*>* visited) const override;
Andreas Huber709b62d2016-09-19 11:21:18 -070035
Timur Iskhakov24e605b2017-08-30 14:02:55 -070036 const Type* getElementType() const;
Andreas Huberf03332a2016-09-22 15:35:43 -070037
Yifan Hongbd33e382016-11-02 13:30:17 -070038 void appendDimension(ConstantExpression *size);
Andreas Huberf03332a2016-09-22 15:35:43 -070039 size_t countDimensions() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070040
Steven Moreland0ecc7b82017-07-19 12:59:23 -070041 std::string typeName() const override;
42
Timur Iskhakovb58f4182017-08-29 15:19:24 -070043 std::vector<const Reference<Type>*> getReferences() const override;
Timur Iskhakov33431e62017-08-21 17:31:23 -070044
Timur Iskhakovb58f4182017-08-29 15:19:24 -070045 std::vector<const ConstantExpression*> getConstantExpressions() const override;
Timur Iskhakov891a8662017-08-25 21:53:48 -070046
Timur Iskhakov0737c2a2017-08-31 10:57:28 -070047 // Extends existing array by adding another dimension.
48 status_t resolveInheritance() override;
49
Timur Iskhakovcec46c42017-08-09 00:22:02 -070050 status_t validate() const override;
51
Steven Moreland979e0992016-09-07 09:18:08 -070052 std::string getCppType(StorageMode mode,
Steven Moreland979e0992016-09-07 09:18:08 -070053 bool specifyNamespaces) const override;
54
Yifan Hong30b5d1f2017-04-03 12:19:25 -070055 std::string getInternalDataCppType() const;
56
Yifan Hong4ed13472016-11-02 10:44:11 -070057 std::string getJavaType(bool forInitializer) const override;
Andreas Huber2831d512016-08-15 09:33:47 -070058
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070059 std::string getVtsType() const override;
60
Andreas Huber881227d2016-08-02 14:20:21 -070061 void emitReaderWriter(
62 Formatter &out,
63 const std::string &name,
64 const std::string &parcelObj,
65 bool parcelObjIsPointer,
66 bool isReader,
67 ErrorMode mode) const override;
68
69 void emitReaderWriterEmbedded(
70 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070071 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070072 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070073 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070074 bool nameIsPointer,
75 const std::string &parcelObj,
76 bool parcelObjIsPointer,
77 bool isReader,
78 ErrorMode mode,
79 const std::string &parentName,
80 const std::string &offsetText) const override;
81
Yifan Hongbf459bc2016-08-23 16:50:37 -070082 void emitResolveReferences(
83 Formatter &out,
84 const std::string &name,
85 bool nameIsPointer,
86 const std::string &parcelObj,
87 bool parcelObjIsPointer,
88 bool isReader,
89 ErrorMode mode) const override;
90
91 void emitResolveReferencesEmbedded(
92 Formatter &out,
93 size_t depth,
94 const std::string &name,
95 const std::string &sanitizedName,
96 bool nameIsPointer,
97 const std::string &parcelObj,
98 bool parcelObjIsPointer,
99 bool isReader,
100 ErrorMode mode,
101 const std::string &parentName,
102 const std::string &offsetText) const override;
103
Yifan Honge45b5302017-02-22 10:49:07 -0800104 void emitJavaDump(
105 Formatter &out,
106 const std::string &streamName,
107 const std::string &name) const override;
108
Andreas Huber881227d2016-08-02 14:20:21 -0700109 bool needsEmbeddedReadWrite() const override;
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -0700110 bool deepNeedsResolveReferences(std::unordered_set<const Type*>* visited) const override;
Andreas Huberf03332a2016-09-22 15:35:43 -0700111 bool resultNeedsDeref() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700112
Andreas Huber2831d512016-08-15 09:33:47 -0700113 void emitJavaReaderWriter(
114 Formatter &out,
115 const std::string &parcelObj,
116 const std::string &argName,
117 bool isReader) const override;
118
Andreas Huber85eabdb2016-08-25 11:24:49 -0700119 void emitJavaFieldInitializer(
120 Formatter &out, const std::string &fieldName) const override;
121
Nirav Atre66842a92018-06-28 18:14:13 -0700122 void emitJavaFieldDefaultInitialValue(
123 Formatter &out, const std::string &declaredFieldName) const override;
124
Andreas Huber85eabdb2016-08-25 11:24:49 -0700125 void emitJavaFieldReaderWriter(
126 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700127 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700128 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700129 const std::string &blobName,
130 const std::string &fieldName,
131 const std::string &offset,
132 bool isReader) const override;
133
Steven Moreland6ec9eb92018-02-16 14:21:49 -0800134 void emitVtsTypeDeclarations(Formatter& out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700135
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -0700136 bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override;
137 bool deepContainsPointer(std::unordered_set<const Type*>* visited) const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700138
Andreas Huber85eabdb2016-08-25 11:24:49 -0700139 void getAlignmentAndSize(size_t *align, size_t *size) const override;
140
Timur Iskhakov505316c2017-08-05 03:38:59 +0000141 private:
142 Reference<Type> mElementType;
143 std::vector<ConstantExpression*> mSizes;
Andreas Huberc9410c72016-07-28 12:18:40 -0700144
Yifan Hongbf459bc2016-08-23 16:50:37 -0700145 size_t dimension() const;
146
Andreas Huberc9410c72016-07-28 12:18:40 -0700147 DISALLOW_COPY_AND_ASSIGN(ArrayType);
148};
149
150} // namespace android
151
152#endif // ARRAY_TYPE_H_
153