blob: df558d7bef38eba981418798bc347ff0a001a950 [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
Steven Moreland979e0992016-09-07 09:18:08 -070043 std::string getCppType(StorageMode mode,
Steven Moreland979e0992016-09-07 09:18:08 -070044 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070045
Yifan Hong4ed13472016-11-02 10:44:11 -070046 std::string getJavaType(bool forInitializer) const override;
Andreas Huber85eabdb2016-08-25 11:24:49 -070047
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070048 std::string getVtsType() const override;
49
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,
Yifan Hongbe2a3732016-10-05 13:33:41 -070062 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070063 bool nameIsPointer,
64 const std::string &parcelObj,
65 bool parcelObjIsPointer,
66 bool isReader,
67 ErrorMode mode,
68 const std::string &parentName,
69 const std::string &offsetText) const override;
70
Yifan Hongbf459bc2016-08-23 16:50:37 -070071 void emitResolveReferences(
72 Formatter &out,
73 const std::string &name,
74 bool nameIsPointer,
75 const std::string &parcelObj,
76 bool parcelObjIsPointer,
77 bool isReader,
78 ErrorMode mode) const override;
79
80 void emitResolveReferencesEmbedded(
81 Formatter &out,
82 size_t depth,
83 const std::string &name,
84 const std::string &sanitizedName,
85 bool nameIsPointer,
86 const std::string &parcelObj,
87 bool parcelObjIsPointer,
88 bool isReader,
89 ErrorMode mode,
90 const std::string &parentName,
91 const std::string &offsetText) const override;
92
Andreas Huber85eabdb2016-08-25 11:24:49 -070093 void emitJavaReaderWriter(
94 Formatter &out,
95 const std::string &parcelObj,
96 const std::string &argName,
97 bool isReader) const override;
98
99 void emitJavaFieldInitializer(
100 Formatter &out, const std::string &fieldName) const override;
101
102 void emitJavaFieldReaderWriter(
103 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700104 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700105 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700106 const std::string &blobName,
107 const std::string &fieldName,
108 const std::string &offset,
109 bool isReader) const override;
110
Andreas Huber881227d2016-08-02 14:20:21 -0700111 status_t emitTypeDeclarations(Formatter &out) const override;
Yifan Hong244e82d2016-11-11 11:13:57 -0800112 status_t emitGlobalHwDeclarations(Formatter &out) const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700113
114 status_t emitTypeDefinitions(
115 Formatter &out, const std::string prefix) const override;
116
Andreas Huber85eabdb2016-08-25 11:24:49 -0700117 status_t emitJavaTypeDeclarations(
118 Formatter &out, bool atTopLevel) const override;
119
Andreas Huber881227d2016-08-02 14:20:21 -0700120 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700121 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700122 bool resultNeedsDeref() const override;
123
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700124 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700125 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700126
Andreas Huber70a59e12016-08-16 12:57:01 -0700127 bool isJavaCompatible() const override;
128
Andreas Huber85eabdb2016-08-25 11:24:49 -0700129 void getAlignmentAndSize(size_t *align, size_t *size) const;
130
Andreas Huberc9410c72016-07-28 12:18:40 -0700131private:
132 Style mStyle;
Andreas Huber881227d2016-08-02 14:20:21 -0700133 std::vector<CompoundField *> *mFields;
134
135 void emitStructReaderWriter(
136 Formatter &out, const std::string &prefix, bool isReader) const;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700137 void emitResolveReferenceDef(
138 Formatter &out, const std::string prefix, bool isReader) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700139
140 DISALLOW_COPY_AND_ASSIGN(CompoundType);
141};
142
Andreas Huber31629bc2016-08-03 09:06:40 -0700143struct CompoundField {
144 CompoundField(const char *name, Type *type);
145
146 std::string name() const;
147 const Type &type() const;
148
149private:
150 std::string mName;
151 Type *mType;
152
153 DISALLOW_COPY_AND_ASSIGN(CompoundField);
154};
155
Andreas Huberc9410c72016-07-28 12:18:40 -0700156} // namespace android
157
158#endif // COMPOUND_TYPE_H_
159