blob: f761933f05f5c99973ffb73023a2900f7c8a6908 [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
21#include "Scope.h"
22
Andreas Huber881227d2016-08-02 14:20:21 -070023#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070024
25namespace android {
26
Andreas Huber31629bc2016-08-03 09:06:40 -070027struct CompoundField;
Andreas Huberc9410c72016-07-28 12:18:40 -070028
29struct CompoundType : public Scope {
30 enum Style {
31 STYLE_STRUCT,
32 STYLE_UNION,
33 };
34
Yifan Honga4b53d02016-10-31 17:29:10 -070035 CompoundType(Style style, const char *localName, const Location &location);
Andreas Huberc9410c72016-07-28 12:18:40 -070036
Yifan Hong27e85db2016-11-09 15:45:52 -080037 Style style() const;
38
Andreas Huber0d0f9a22016-08-17 10:26:11 -070039 bool setFields(std::vector<CompoundField *> *fields, std::string *errorMsg);
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 Moreland979e0992016-09-07 09:18:08 -070045 std::string getCppType(StorageMode mode,
Steven Moreland979e0992016-09-07 09:18:08 -070046 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070047
Yifan Hong4ed13472016-11-02 10:44:11 -070048 std::string getJavaType(bool forInitializer) const override;
Andreas Huber85eabdb2016-08-25 11:24:49 -070049
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070050 std::string getVtsType() const override;
51
Andreas Huber881227d2016-08-02 14:20:21 -070052 void emitReaderWriter(
53 Formatter &out,
54 const std::string &name,
55 const std::string &parcelObj,
56 bool parcelObjIsPointer,
57 bool isReader,
58 ErrorMode mode) const override;
59
60 void emitReaderWriterEmbedded(
61 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070062 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070063 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070064 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070065 bool nameIsPointer,
66 const std::string &parcelObj,
67 bool parcelObjIsPointer,
68 bool isReader,
69 ErrorMode mode,
70 const std::string &parentName,
71 const std::string &offsetText) const override;
72
Yifan Hongbf459bc2016-08-23 16:50:37 -070073 void emitResolveReferences(
74 Formatter &out,
75 const std::string &name,
76 bool nameIsPointer,
77 const std::string &parcelObj,
78 bool parcelObjIsPointer,
79 bool isReader,
80 ErrorMode mode) const override;
81
82 void emitResolveReferencesEmbedded(
83 Formatter &out,
84 size_t depth,
85 const std::string &name,
86 const std::string &sanitizedName,
87 bool nameIsPointer,
88 const std::string &parcelObj,
89 bool parcelObjIsPointer,
90 bool isReader,
91 ErrorMode mode,
92 const std::string &parentName,
93 const std::string &offsetText) const override;
94
Andreas Huber85eabdb2016-08-25 11:24:49 -070095 void emitJavaReaderWriter(
96 Formatter &out,
97 const std::string &parcelObj,
98 const std::string &argName,
99 bool isReader) const override;
100
101 void emitJavaFieldInitializer(
102 Formatter &out, const std::string &fieldName) const override;
103
104 void emitJavaFieldReaderWriter(
105 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700106 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700107 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700108 const std::string &blobName,
109 const std::string &fieldName,
110 const std::string &offset,
111 bool isReader) const override;
112
Andreas Huber881227d2016-08-02 14:20:21 -0700113 status_t emitTypeDeclarations(Formatter &out) const override;
Yifan Hongc6752dc2016-12-20 14:00:14 -0800114 status_t emitGlobalTypeDeclarations(Formatter &out) const override;
Yifan Hong244e82d2016-11-11 11:13:57 -0800115 status_t emitGlobalHwDeclarations(Formatter &out) const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700116
117 status_t emitTypeDefinitions(
118 Formatter &out, const std::string prefix) const override;
119
Andreas Huber85eabdb2016-08-25 11:24:49 -0700120 status_t emitJavaTypeDeclarations(
121 Formatter &out, bool atTopLevel) const override;
122
Andreas Huber881227d2016-08-02 14:20:21 -0700123 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700124 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700125 bool resultNeedsDeref() const override;
126
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700127 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700128 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700129
Andreas Huber70a59e12016-08-16 12:57:01 -0700130 bool isJavaCompatible() const override;
131
Andreas Huber85eabdb2016-08-25 11:24:49 -0700132 void getAlignmentAndSize(size_t *align, size_t *size) const;
133
Andreas Huberc9410c72016-07-28 12:18:40 -0700134private:
135 Style mStyle;
Andreas Huber881227d2016-08-02 14:20:21 -0700136 std::vector<CompoundField *> *mFields;
137
138 void emitStructReaderWriter(
139 Formatter &out, const std::string &prefix, bool isReader) const;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700140 void emitResolveReferenceDef(
141 Formatter &out, const std::string prefix, bool isReader) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700142
143 DISALLOW_COPY_AND_ASSIGN(CompoundType);
144};
145
Andreas Huber31629bc2016-08-03 09:06:40 -0700146struct CompoundField {
147 CompoundField(const char *name, Type *type);
148
149 std::string name() const;
150 const Type &type() const;
151
152private:
153 std::string mName;
154 Type *mType;
155
156 DISALLOW_COPY_AND_ASSIGN(CompoundField);
157};
158
Andreas Huberc9410c72016-07-28 12:18:40 -0700159} // namespace android
160
161#endif // COMPOUND_TYPE_H_
162