blob: b6b2d144a286042cdbd60d9d82d84b27a4184ff0 [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 Huber85eabdb2016-08-25 11:24:49 -070080 const std::string &blobName,
81 const std::string &fieldName,
82 const std::string &offset,
83 bool isReader) const override;
84
Andreas Huber881227d2016-08-02 14:20:21 -070085 status_t emitTypeDeclarations(Formatter &out) const override;
86
87 status_t emitTypeDefinitions(
88 Formatter &out, const std::string prefix) const override;
89
Andreas Huber85eabdb2016-08-25 11:24:49 -070090 status_t emitJavaTypeDeclarations(
91 Formatter &out, bool atTopLevel) const override;
92
Andreas Huber881227d2016-08-02 14:20:21 -070093 bool needsEmbeddedReadWrite() const override;
94 bool resultNeedsDeref() const override;
95
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070096 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070097 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070098
Andreas Huber70a59e12016-08-16 12:57:01 -070099 bool isJavaCompatible() const override;
100
Andreas Huber85eabdb2016-08-25 11:24:49 -0700101 void getAlignmentAndSize(size_t *align, size_t *size) const;
102
Andreas Huberc9410c72016-07-28 12:18:40 -0700103private:
104 Style mStyle;
Andreas Huber881227d2016-08-02 14:20:21 -0700105 std::vector<CompoundField *> *mFields;
106
107 void emitStructReaderWriter(
108 Formatter &out, const std::string &prefix, bool isReader) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700109
110 DISALLOW_COPY_AND_ASSIGN(CompoundType);
111};
112
Andreas Huber31629bc2016-08-03 09:06:40 -0700113struct CompoundField {
114 CompoundField(const char *name, Type *type);
115
116 std::string name() const;
117 const Type &type() const;
118
119private:
120 std::string mName;
121 Type *mType;
122
123 DISALLOW_COPY_AND_ASSIGN(CompoundField);
124};
125
Andreas Huberc9410c72016-07-28 12:18:40 -0700126} // namespace android
127
128#endif // COMPOUND_TYPE_H_
129