blob: c0adbde6f8302e5bd0d3b46f9ef319679864f303 [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
Yifan Hongf24fa852016-09-23 11:03:15 -070035 static ArrayType *AddDimension(ArrayType *base, ConstantExpression *size);
Andreas Huber709b62d2016-09-19 11:21:18 -070036
37 bool isArray() const override;
38
Yifan Hongf24fa852016-09-23 11:03:15 -070039 void addDimension(ConstantExpression *size);
Andreas Huberc9410c72016-07-28 12:18:40 -070040
Steven Moreland979e0992016-09-07 09:18:08 -070041 std::string getCppType(StorageMode mode,
42 std::string *extra,
43 bool specifyNamespaces) const override;
44
45 void addNamedTypesToSet(std::set<const FQName> &set) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070046
Andreas Huber4c865b72016-09-14 15:26:27 -070047 std::string getJavaType(
48 std::string *extra, bool forInitializer) const override;
Andreas Huber2831d512016-08-15 09:33:47 -070049
Andreas Huber881227d2016-08-02 14:20:21 -070050 void emitReaderWriter(
51 Formatter &out,
52 const std::string &name,
53 const std::string &parcelObj,
54 bool parcelObjIsPointer,
55 bool isReader,
56 ErrorMode mode) const override;
57
58 void emitReaderWriterEmbedded(
59 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070060 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070061 const std::string &name,
62 bool nameIsPointer,
63 const std::string &parcelObj,
64 bool parcelObjIsPointer,
65 bool isReader,
66 ErrorMode mode,
67 const std::string &parentName,
68 const std::string &offsetText) const override;
69
70 bool needsEmbeddedReadWrite() const override;
71
Andreas Huber2831d512016-08-15 09:33:47 -070072 void emitJavaReaderWriter(
73 Formatter &out,
74 const std::string &parcelObj,
75 const std::string &argName,
76 bool isReader) const override;
77
Andreas Huber85eabdb2016-08-25 11:24:49 -070078 void emitJavaFieldInitializer(
79 Formatter &out, const std::string &fieldName) const override;
80
81 void emitJavaFieldReaderWriter(
82 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -070083 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -070084 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -070085 const std::string &blobName,
86 const std::string &fieldName,
87 const std::string &offset,
88 bool isReader) const override;
89
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070090 status_t emitVtsTypeDeclarations(Formatter &out) const override;
91
Andreas Huber70a59e12016-08-16 12:57:01 -070092 bool isJavaCompatible() const override;
93
Andreas Huber85eabdb2016-08-25 11:24:49 -070094 void getAlignmentAndSize(size_t *align, size_t *size) const override;
95
Andreas Huberc9410c72016-07-28 12:18:40 -070096private:
97 Type *mElementType;
Andreas Huber709b62d2016-09-19 11:21:18 -070098 std::vector<size_t> mSizes;
Yifan Hongf24fa852016-09-23 11:03:15 -070099 std::vector<std::string> mSizeComments;
Andreas Huberc9410c72016-07-28 12:18:40 -0700100
101 DISALLOW_COPY_AND_ASSIGN(ArrayType);
102};
103
104} // namespace android
105
106#endif // ARRAY_TYPE_H_
107