blob: 2c13a335f171298507d999e057759426eaf2f0a7 [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
Andreas Huberf03332a2016-09-22 15:35:43 -070059 std::string getJavaWrapperType() const override;
60
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070061 std::string getVtsType() const override;
62
Andreas Huber881227d2016-08-02 14:20:21 -070063 void emitReaderWriter(
64 Formatter &out,
65 const std::string &name,
66 const std::string &parcelObj,
67 bool parcelObjIsPointer,
68 bool isReader,
69 ErrorMode mode) const override;
70
71 void emitReaderWriterEmbedded(
72 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070073 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070074 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070075 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070076 bool nameIsPointer,
77 const std::string &parcelObj,
78 bool parcelObjIsPointer,
79 bool isReader,
80 ErrorMode mode,
81 const std::string &parentName,
82 const std::string &offsetText) const override;
83
Yifan Hongbf459bc2016-08-23 16:50:37 -070084 void emitResolveReferences(
85 Formatter &out,
86 const std::string &name,
87 bool nameIsPointer,
88 const std::string &parcelObj,
89 bool parcelObjIsPointer,
90 bool isReader,
91 ErrorMode mode) const override;
92
93 void emitResolveReferencesEmbedded(
94 Formatter &out,
95 size_t depth,
96 const std::string &name,
97 const std::string &sanitizedName,
98 bool nameIsPointer,
99 const std::string &parcelObj,
100 bool parcelObjIsPointer,
101 bool isReader,
102 ErrorMode mode,
103 const std::string &parentName,
104 const std::string &offsetText) const override;
105
Yifan Honge45b5302017-02-22 10:49:07 -0800106 void emitJavaDump(
107 Formatter &out,
108 const std::string &streamName,
109 const std::string &name) const override;
110
Andreas Huber881227d2016-08-02 14:20:21 -0700111 bool needsEmbeddedReadWrite() const override;
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -0700112 bool deepNeedsResolveReferences(std::unordered_set<const Type*>* visited) const override;
Andreas Huberf03332a2016-09-22 15:35:43 -0700113 bool resultNeedsDeref() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700114
Andreas Huber2831d512016-08-15 09:33:47 -0700115 void emitJavaReaderWriter(
116 Formatter &out,
117 const std::string &parcelObj,
118 const std::string &argName,
119 bool isReader) const override;
120
Andreas Huber85eabdb2016-08-25 11:24:49 -0700121 void emitJavaFieldInitializer(
122 Formatter &out, const std::string &fieldName) const override;
123
124 void emitJavaFieldReaderWriter(
125 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700126 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700127 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700128 const std::string &blobName,
129 const std::string &fieldName,
130 const std::string &offset,
131 bool isReader) const override;
132
Steven Moreland368e4602018-02-16 14:21:49 -0800133 void emitVtsTypeDeclarations(Formatter& out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700134
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -0700135 bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override;
136 bool deepContainsPointer(std::unordered_set<const Type*>* visited) const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700137
Andreas Huber85eabdb2016-08-25 11:24:49 -0700138 void getAlignmentAndSize(size_t *align, size_t *size) const override;
139
Timur Iskhakov505316c2017-08-05 03:38:59 +0000140 private:
141 Reference<Type> mElementType;
142 std::vector<ConstantExpression*> mSizes;
Andreas Huberc9410c72016-07-28 12:18:40 -0700143
Yifan Hongbf459bc2016-08-23 16:50:37 -0700144 size_t dimension() const;
145
Andreas Huberc9410c72016-07-28 12:18:40 -0700146 DISALLOW_COPY_AND_ASSIGN(ArrayType);
147};
148
149} // namespace android
150
151#endif // ARRAY_TYPE_H_
152