blob: e905f08bce71aed2e25fddd26caa1cd2ed0a1a33 [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,
60 bool nameIsPointer,
61 const std::string &parcelObj,
62 bool parcelObjIsPointer,
63 bool isReader,
64 ErrorMode mode,
65 const std::string &parentName,
66 const std::string &offsetText) const override;
67
Andreas Huber85eabdb2016-08-25 11:24:49 -070068 void emitJavaReaderWriter(
69 Formatter &out,
70 const std::string &parcelObj,
71 const std::string &argName,
72 bool isReader) const override;
73
74 void emitJavaFieldInitializer(
75 Formatter &out, const std::string &fieldName) const override;
76
77 void emitJavaFieldReaderWriter(
78 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -070079 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -070080 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -070081 const std::string &blobName,
82 const std::string &fieldName,
83 const std::string &offset,
84 bool isReader) const override;
85
Andreas Huber881227d2016-08-02 14:20:21 -070086 status_t emitTypeDeclarations(Formatter &out) const override;
87
88 status_t emitTypeDefinitions(
89 Formatter &out, const std::string prefix) const override;
90
Andreas Huber85eabdb2016-08-25 11:24:49 -070091 status_t emitJavaTypeDeclarations(
92 Formatter &out, bool atTopLevel) const override;
93
Andreas Huber881227d2016-08-02 14:20:21 -070094 bool needsEmbeddedReadWrite() const override;
95 bool resultNeedsDeref() const override;
96
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070097 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070098 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070099
Andreas Huber70a59e12016-08-16 12:57:01 -0700100 bool isJavaCompatible() const override;
101
Andreas Huber85eabdb2016-08-25 11:24:49 -0700102 void getAlignmentAndSize(size_t *align, size_t *size) const;
103
Andreas Huberc9410c72016-07-28 12:18:40 -0700104private:
105 Style mStyle;
Andreas Huber881227d2016-08-02 14:20:21 -0700106 std::vector<CompoundField *> *mFields;
107
108 void emitStructReaderWriter(
109 Formatter &out, const std::string &prefix, bool isReader) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700110
111 DISALLOW_COPY_AND_ASSIGN(CompoundType);
112};
113
Andreas Huber31629bc2016-08-03 09:06:40 -0700114struct CompoundField {
115 CompoundField(const char *name, Type *type);
116
117 std::string name() const;
118 const Type &type() const;
119
120private:
121 std::string mName;
122 Type *mType;
123
124 DISALLOW_COPY_AND_ASSIGN(CompoundField);
125};
126
Andreas Huberc9410c72016-07-28 12:18:40 -0700127} // namespace android
128
129#endif // COMPOUND_TYPE_H_
130