blob: 6c55a55ad9bd87238c78aa6fb85f4025935ec87f [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
Steven Moreland979e0992016-09-07 09:18:08 -070039 std::string getCppType(StorageMode mode,
40 std::string *extra,
41 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070042
Andreas Huber85eabdb2016-08-25 11:24:49 -070043 std::string getJavaType() const override;
44
Andreas Huber881227d2016-08-02 14:20:21 -070045 void emitReaderWriter(
46 Formatter &out,
47 const std::string &name,
48 const std::string &parcelObj,
49 bool parcelObjIsPointer,
50 bool isReader,
51 ErrorMode mode) const override;
52
53 void emitReaderWriterEmbedded(
54 Formatter &out,
55 const std::string &name,
56 bool nameIsPointer,
57 const std::string &parcelObj,
58 bool parcelObjIsPointer,
59 bool isReader,
60 ErrorMode mode,
61 const std::string &parentName,
62 const std::string &offsetText) const override;
63
Andreas Huber85eabdb2016-08-25 11:24:49 -070064 void emitJavaReaderWriter(
65 Formatter &out,
66 const std::string &parcelObj,
67 const std::string &argName,
68 bool isReader) const override;
69
70 void emitJavaFieldInitializer(
71 Formatter &out, const std::string &fieldName) const override;
72
73 void emitJavaFieldReaderWriter(
74 Formatter &out,
75 const std::string &blobName,
76 const std::string &fieldName,
77 const std::string &offset,
78 bool isReader) const override;
79
Andreas Huber881227d2016-08-02 14:20:21 -070080 status_t emitTypeDeclarations(Formatter &out) const override;
81
82 status_t emitTypeDefinitions(
83 Formatter &out, const std::string prefix) const override;
84
Andreas Huber85eabdb2016-08-25 11:24:49 -070085 status_t emitJavaTypeDeclarations(
86 Formatter &out, bool atTopLevel) const override;
87
Andreas Huber881227d2016-08-02 14:20:21 -070088 bool needsEmbeddedReadWrite() const override;
89 bool resultNeedsDeref() const override;
90
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070091 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070092 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070093
Andreas Huber70a59e12016-08-16 12:57:01 -070094 bool isJavaCompatible() const override;
95
Andreas Huber85eabdb2016-08-25 11:24:49 -070096 void getAlignmentAndSize(size_t *align, size_t *size) const;
97
Andreas Huberc9410c72016-07-28 12:18:40 -070098private:
99 Style mStyle;
Andreas Huber881227d2016-08-02 14:20:21 -0700100 std::vector<CompoundField *> *mFields;
101
102 void emitStructReaderWriter(
103 Formatter &out, const std::string &prefix, bool isReader) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700104
105 DISALLOW_COPY_AND_ASSIGN(CompoundType);
106};
107
Andreas Huber31629bc2016-08-03 09:06:40 -0700108struct CompoundField {
109 CompoundField(const char *name, Type *type);
110
111 std::string name() const;
112 const Type &type() const;
113
114private:
115 std::string mName;
116 Type *mType;
117
118 DISALLOW_COPY_AND_ASSIGN(CompoundField);
119};
120
Andreas Huberc9410c72016-07-28 12:18:40 -0700121} // namespace android
122
123#endif // COMPOUND_TYPE_H_
124