blob: 0e61c2848fae0b2d7f888e98b0e09e1c6d76579f [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 COMPOUND_TYPE_H_
18
19#define COMPOUND_TYPE_H_
20
Timur Iskhakov505316c2017-08-05 03:38:59 +000021#include "Reference.h"
Andreas Huberc9410c72016-07-28 12:18:40 -070022#include "Scope.h"
23
Andreas Huber881227d2016-08-02 14:20:21 -070024#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070025
26namespace android {
27
Andreas Huberc9410c72016-07-28 12:18:40 -070028struct CompoundType : public Scope {
29 enum Style {
30 STYLE_STRUCT,
31 STYLE_UNION,
32 };
33
Timur Iskhakov565b0132017-09-06 18:07:11 -070034 CompoundType(Style style, const char* localName, const FQName& fullName,
35 const Location& location, Scope* parent);
Andreas Huberc9410c72016-07-28 12:18:40 -070036
Yifan Hong27e85db2016-11-09 15:45:52 -080037 Style style() const;
38
Timur Iskhakovcec46c42017-08-09 00:22:02 -070039 void setFields(std::vector<NamedReference<Type>*>* fields);
Andreas Huberc9410c72016-07-28 12:18:40 -070040
Andreas Huberf630bc82016-09-09 14:52:25 -070041 bool isCompoundType() const override;
42
Yifan Hongc6752dc2016-12-20 14:00:14 -080043 bool canCheckEquality() const override;
44
Steven Moreland0ecc7b82017-07-19 12:59:23 -070045 std::string typeName() const override;
46
Timur Iskhakovb58f4182017-08-29 15:19:24 -070047 std::vector<const Reference<Type>*> getReferences() const override;
Timur Iskhakov33431e62017-08-21 17:31:23 -070048
Timur Iskhakovcec46c42017-08-09 00:22:02 -070049 status_t validate() const override;
50 status_t validateUniqueNames() const;
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;
Andreas Huber881227d2016-08-02 14:20:21 -070054
Yifan Hong4ed13472016-11-02 10:44:11 -070055 std::string getJavaType(bool forInitializer) const override;
Andreas Huber85eabdb2016-08-25 11:24:49 -070056
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070057 std::string getVtsType() const override;
58
Andreas Huber881227d2016-08-02 14:20:21 -070059 void emitReaderWriter(
60 Formatter &out,
61 const std::string &name,
62 const std::string &parcelObj,
63 bool parcelObjIsPointer,
64 bool isReader,
65 ErrorMode mode) const override;
66
67 void emitReaderWriterEmbedded(
68 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070069 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070070 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070071 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070072 bool nameIsPointer,
73 const std::string &parcelObj,
74 bool parcelObjIsPointer,
75 bool isReader,
76 ErrorMode mode,
77 const std::string &parentName,
78 const std::string &offsetText) const override;
79
Yifan Hongbf459bc2016-08-23 16:50:37 -070080 void emitResolveReferences(
81 Formatter &out,
82 const std::string &name,
83 bool nameIsPointer,
84 const std::string &parcelObj,
85 bool parcelObjIsPointer,
86 bool isReader,
87 ErrorMode mode) const override;
88
89 void emitResolveReferencesEmbedded(
90 Formatter &out,
91 size_t depth,
92 const std::string &name,
93 const std::string &sanitizedName,
94 bool nameIsPointer,
95 const std::string &parcelObj,
96 bool parcelObjIsPointer,
97 bool isReader,
98 ErrorMode mode,
99 const std::string &parentName,
100 const std::string &offsetText) const override;
101
Andreas Huber85eabdb2016-08-25 11:24:49 -0700102 void emitJavaReaderWriter(
103 Formatter &out,
104 const std::string &parcelObj,
105 const std::string &argName,
106 bool isReader) const override;
107
108 void emitJavaFieldInitializer(
109 Formatter &out, const std::string &fieldName) const override;
110
111 void emitJavaFieldReaderWriter(
112 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700113 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700114 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700115 const std::string &blobName,
116 const std::string &fieldName,
117 const std::string &offset,
118 bool isReader) const override;
119
Andreas Huber881227d2016-08-02 14:20:21 -0700120 status_t emitTypeDeclarations(Formatter &out) const override;
Timur Iskhakovfd3f2502017-09-05 16:25:02 -0700121 void emitTypeForwardDeclaration(Formatter& out) const override;
Yifan Hongc6752dc2016-12-20 14:00:14 -0800122 status_t emitGlobalTypeDeclarations(Formatter &out) const override;
Yifan Hong244e82d2016-11-11 11:13:57 -0800123 status_t emitGlobalHwDeclarations(Formatter &out) const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700124
Chih-Hung Hsieh8c90cc52017-08-03 14:51:13 -0700125 status_t emitTypeDefinitions(Formatter& out, const std::string& prefix) const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700126
Andreas Huber85eabdb2016-08-25 11:24:49 -0700127 status_t emitJavaTypeDeclarations(
128 Formatter &out, bool atTopLevel) const override;
129
Andreas Huber881227d2016-08-02 14:20:21 -0700130 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700131 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700132 bool resultNeedsDeref() const override;
133
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700134 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700135 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700136
Andreas Huber70a59e12016-08-16 12:57:01 -0700137 bool isJavaCompatible() const override;
Andreas Huber60d3b222017-03-30 09:10:56 -0700138 bool containsPointer() const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700139
Andreas Huber85eabdb2016-08-25 11:24:49 -0700140 void getAlignmentAndSize(size_t *align, size_t *size) const;
141
Andreas Huberc9410c72016-07-28 12:18:40 -0700142private:
143 Style mStyle;
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700144 std::vector<NamedReference<Type>*>* mFields;
Andreas Huber881227d2016-08-02 14:20:21 -0700145
146 void emitStructReaderWriter(
147 Formatter &out, const std::string &prefix, bool isReader) const;
Chih-Hung Hsieh8c90cc52017-08-03 14:51:13 -0700148 void emitResolveReferenceDef(Formatter& out, const std::string& prefix, bool isReader) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700149
150 DISALLOW_COPY_AND_ASSIGN(CompoundType);
151};
152
Andreas Huberc9410c72016-07-28 12:18:40 -0700153} // namespace android
154
155#endif // COMPOUND_TYPE_H_
156