blob: 5cd6efa1e69a7e6ec51b518dd2028d4fc1210e91 [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
Andreas Huber9ed827c2016-08-22 12:31:13 -070035 CompoundType(Style style, const char *localName);
Andreas Huberc9410c72016-07-28 12:18:40 -070036
Andreas Huber0d0f9a22016-08-17 10:26:11 -070037 bool setFields(std::vector<CompoundField *> *fields, std::string *errorMsg);
Andreas Huberc9410c72016-07-28 12:18:40 -070038
Andreas Huberf630bc82016-09-09 14:52:25 -070039 bool isCompoundType() const override;
40
Steven Moreland979e0992016-09-07 09:18:08 -070041 std::string getCppType(StorageMode mode,
42 std::string *extra,
43 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070044
Andreas Huber4c865b72016-09-14 15:26:27 -070045 std::string getJavaType(
46 std::string *extra, bool forInitializer) const override;
Andreas Huber85eabdb2016-08-25 11:24:49 -070047
Andreas Huber881227d2016-08-02 14:20:21 -070048 void emitReaderWriter(
49 Formatter &out,
50 const std::string &name,
51 const std::string &parcelObj,
52 bool parcelObjIsPointer,
53 bool isReader,
54 ErrorMode mode) const override;
55
56 void emitReaderWriterEmbedded(
57 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070058 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070059 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070060 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070061 bool nameIsPointer,
62 const std::string &parcelObj,
63 bool parcelObjIsPointer,
64 bool isReader,
65 ErrorMode mode,
66 const std::string &parentName,
67 const std::string &offsetText) const override;
68
Yifan Hongbf459bc2016-08-23 16:50:37 -070069 void emitResolveReferences(
70 Formatter &out,
71 const std::string &name,
72 bool nameIsPointer,
73 const std::string &parcelObj,
74 bool parcelObjIsPointer,
75 bool isReader,
76 ErrorMode mode) const override;
77
78 void emitResolveReferencesEmbedded(
79 Formatter &out,
80 size_t depth,
81 const std::string &name,
82 const std::string &sanitizedName,
83 bool nameIsPointer,
84 const std::string &parcelObj,
85 bool parcelObjIsPointer,
86 bool isReader,
87 ErrorMode mode,
88 const std::string &parentName,
89 const std::string &offsetText) const override;
90
Andreas Huber85eabdb2016-08-25 11:24:49 -070091 void emitJavaReaderWriter(
92 Formatter &out,
93 const std::string &parcelObj,
94 const std::string &argName,
95 bool isReader) const override;
96
97 void emitJavaFieldInitializer(
98 Formatter &out, const std::string &fieldName) const override;
99
100 void emitJavaFieldReaderWriter(
101 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700102 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700103 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700104 const std::string &blobName,
105 const std::string &fieldName,
106 const std::string &offset,
107 bool isReader) const override;
108
Andreas Huber881227d2016-08-02 14:20:21 -0700109 status_t emitTypeDeclarations(Formatter &out) const override;
110
111 status_t emitTypeDefinitions(
112 Formatter &out, const std::string prefix) const override;
113
Andreas Huber85eabdb2016-08-25 11:24:49 -0700114 status_t emitJavaTypeDeclarations(
115 Formatter &out, bool atTopLevel) const override;
116
Andreas Huber881227d2016-08-02 14:20:21 -0700117 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700118 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700119 bool resultNeedsDeref() const override;
120
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700121 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700122 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700123
Andreas Huber70a59e12016-08-16 12:57:01 -0700124 bool isJavaCompatible() const override;
125
Andreas Huber85eabdb2016-08-25 11:24:49 -0700126 void getAlignmentAndSize(size_t *align, size_t *size) const;
127
Andreas Huberc9410c72016-07-28 12:18:40 -0700128private:
129 Style mStyle;
Andreas Huber881227d2016-08-02 14:20:21 -0700130 std::vector<CompoundField *> *mFields;
131
132 void emitStructReaderWriter(
133 Formatter &out, const std::string &prefix, bool isReader) const;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700134 void emitResolveReferenceDef(
135 Formatter &out, const std::string prefix, bool isReader) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700136
137 DISALLOW_COPY_AND_ASSIGN(CompoundType);
138};
139
Andreas Huber31629bc2016-08-03 09:06:40 -0700140struct CompoundField {
141 CompoundField(const char *name, Type *type);
142
143 std::string name() const;
144 const Type &type() const;
145
146private:
147 std::string mName;
148 Type *mType;
149
150 DISALLOW_COPY_AND_ASSIGN(CompoundField);
151};
152
Andreas Huberc9410c72016-07-28 12:18:40 -0700153} // namespace android
154
155#endif // COMPOUND_TYPE_H_
156