blob: 97b83a0ae7078c2dc9a602f9d3d33df67a3741a3 [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 {
Andreas Huber709b62d2016-09-19 11:21:18 -070031 // Extends existing array by adding another dimension.
Yifan Hongf24fa852016-09-23 11:03:15 -070032 ArrayType(ArrayType *srcArray, ConstantExpression *size);
Andreas Huber709b62d2016-09-19 11:21:18 -070033
Timur Iskhakov505316c2017-08-05 03:38:59 +000034 ArrayType(const Reference<Type>& elementType, ConstantExpression* size);
Andreas Huber709b62d2016-09-19 11:21:18 -070035
Andreas Huber709b62d2016-09-19 11:21:18 -070036 bool isArray() const override;
Yifan Hongc6752dc2016-12-20 14:00:14 -080037 bool canCheckEquality() const override;
Andreas Huber709b62d2016-09-19 11:21:18 -070038
Timur Iskhakov505316c2017-08-05 03:38:59 +000039 Type* getElementType() const;
Andreas Huberf03332a2016-09-22 15:35:43 -070040
Yifan Hongbd33e382016-11-02 13:30:17 -070041 void prependDimension(ConstantExpression *size);
42 void appendDimension(ConstantExpression *size);
Andreas Huberf03332a2016-09-22 15:35:43 -070043 size_t countDimensions() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070044
Steven Moreland0ecc7b82017-07-19 12:59:23 -070045 std::string typeName() const override;
46
Timur Iskhakov33431e62017-08-21 17:31:23 -070047 std::vector<Reference<Type>> getReferences() const override;
48
Timur Iskhakov891a8662017-08-25 21:53:48 -070049 std::vector<ConstantExpression*> getConstantExpressions() const override;
50
Timur Iskhakovcec46c42017-08-09 00:22:02 -070051 status_t validate() const override;
52
Steven Moreland979e0992016-09-07 09:18:08 -070053 std::string getCppType(StorageMode mode,
Steven Moreland979e0992016-09-07 09:18:08 -070054 bool specifyNamespaces) const override;
55
Yifan Hong30b5d1f2017-04-03 12:19:25 -070056 std::string getInternalDataCppType() const;
57
Yifan Hong4ed13472016-11-02 10:44:11 -070058 std::string getJavaType(bool forInitializer) const override;
Andreas Huber2831d512016-08-15 09:33:47 -070059
Andreas Huberf03332a2016-09-22 15:35:43 -070060 std::string getJavaWrapperType() const override;
61
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070062 std::string getVtsType() const override;
63
Andreas Huber881227d2016-08-02 14:20:21 -070064 void emitReaderWriter(
65 Formatter &out,
66 const std::string &name,
67 const std::string &parcelObj,
68 bool parcelObjIsPointer,
69 bool isReader,
70 ErrorMode mode) const override;
71
72 void emitReaderWriterEmbedded(
73 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070074 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070075 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070076 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070077 bool nameIsPointer,
78 const std::string &parcelObj,
79 bool parcelObjIsPointer,
80 bool isReader,
81 ErrorMode mode,
82 const std::string &parentName,
83 const std::string &offsetText) const override;
84
Yifan Hongbf459bc2016-08-23 16:50:37 -070085 void emitResolveReferences(
86 Formatter &out,
87 const std::string &name,
88 bool nameIsPointer,
89 const std::string &parcelObj,
90 bool parcelObjIsPointer,
91 bool isReader,
92 ErrorMode mode) const override;
93
94 void emitResolveReferencesEmbedded(
95 Formatter &out,
96 size_t depth,
97 const std::string &name,
98 const std::string &sanitizedName,
99 bool nameIsPointer,
100 const std::string &parcelObj,
101 bool parcelObjIsPointer,
102 bool isReader,
103 ErrorMode mode,
104 const std::string &parentName,
105 const std::string &offsetText) const override;
106
Yifan Honge45b5302017-02-22 10:49:07 -0800107 void emitJavaDump(
108 Formatter &out,
109 const std::string &streamName,
110 const std::string &name) const override;
111
Andreas Huber881227d2016-08-02 14:20:21 -0700112 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700113 bool needsResolveReferences() const override;
Andreas Huberf03332a2016-09-22 15:35:43 -0700114 bool resultNeedsDeref() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700115
Andreas Huber2831d512016-08-15 09:33:47 -0700116 void emitJavaReaderWriter(
117 Formatter &out,
118 const std::string &parcelObj,
119 const std::string &argName,
120 bool isReader) const override;
121
Andreas Huber85eabdb2016-08-25 11:24:49 -0700122 void emitJavaFieldInitializer(
123 Formatter &out, const std::string &fieldName) const override;
124
125 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
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700134 status_t emitVtsTypeDeclarations(Formatter &out) const override;
135
Andreas Huber70a59e12016-08-16 12:57:01 -0700136 bool isJavaCompatible() const override;
Andreas Huber60d3b222017-03-30 09:10:56 -0700137 bool containsPointer() 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